• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kio/kssl
 

kio/kssl

  • kio
  • kssl
ksslcertchain.cc
1 /* This file is part of the KDE project
2  *
3  * Copyright (C) 2001 George Staikos <staikos@kde.org>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23 
24 #include "kssldefs.h"
25 #include "ksslcertificate.h"
26 #include "ksslcertchain.h"
27 
28 // this hack provided by Malte Starostik to avoid glibc/openssl bug
29 // on some systems
30 #ifdef KSSL_HAVE_SSL
31 #define crypt _openssl_crypt
32 #include <openssl/ssl.h>
33 #include <openssl/x509.h>
34 #include <openssl/x509v3.h>
35 #include <openssl/x509_vfy.h>
36 #include <openssl/pem.h>
37 #include <openssl/stack.h>
38 #include <openssl/safestack.h>
39 #undef crypt
40 #endif
41 
42 #include <kopenssl.h>
43 #include <kdebug.h>
44 #include <tqstringlist.h>
45 
46 
47 
48 #ifdef KSSL_HAVE_SSL
49 #define sk_new d->kossl->sk_new
50 #define sk_push d->kossl->sk_push
51 #define sk_free d->kossl->sk_free
52 #define sk_value d->kossl->sk_value
53 #define sk_num d->kossl->sk_num
54 #define sk_dup d->kossl->sk_dup
55 #define sk_pop d->kossl->sk_pop
56 #endif
57 
58 class KSSLCertChainPrivate {
59 public:
60  KSSLCertChainPrivate() {
61  kossl = KOSSL::self();
62  }
63 
64  ~KSSLCertChainPrivate() {
65  }
66 
67  KOSSL *kossl;
68 };
69 
70 KSSLCertChain::KSSLCertChain() {
71  d = new KSSLCertChainPrivate;
72  _chain = NULL;
73 }
74 
75 
76 KSSLCertChain::~KSSLCertChain() {
77 #ifdef KSSL_HAVE_SSL
78  if (_chain) {
79  STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
80 
81  for (;;) {
82  X509* x5 = sk_X509_pop(x);
83  if (!x5) break;
84  d->kossl->X509_free(x5);
85  }
86  sk_X509_free(x);
87  }
88 #endif
89  delete d;
90 }
91 
92 
93 bool KSSLCertChain::isValid() {
94  return (_chain && depth() > 0);
95 }
96 
97 
98 KSSLCertChain *KSSLCertChain::replicate() {
99 KSSLCertChain *x = new KSSLCertChain;
100 TQPtrList<KSSLCertificate> ch = getChain();
101 
102  x->setChain(ch); // this will do a deep copy for us
103  ch.setAutoDelete(true);
104 return x;
105 }
106 
107 
108 int KSSLCertChain::depth() {
109 #ifdef KSSL_HAVE_SSL
110  return sk_X509_num((STACK_OF(X509)*)_chain);
111 #endif
112 return 0;
113 }
114 
115 
116 TQPtrList<KSSLCertificate> KSSLCertChain::getChain() {
117 TQPtrList<KSSLCertificate> cl;
118 if (!_chain) return cl;
119 #ifdef KSSL_HAVE_SSL
120 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
121 
122  for (int i = 0; i < sk_X509_num(x); i++) {
123  X509* x5 = sk_X509_value(x, i);
124  if (!x5) continue;
125  KSSLCertificate *nc = new KSSLCertificate;
126  nc->setCert(d->kossl->X509_dup(x5));
127  cl.append(nc);
128  }
129 
130 #endif
131 return cl;
132 }
133 
134 
135 void KSSLCertChain::setChain(TQPtrList<KSSLCertificate>& chain) {
136 #ifdef KSSL_HAVE_SSL
137 if (_chain) {
138  STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
139 
140  for (;;) {
141  X509* x5 = sk_X509_pop(x);
142  if (!x5) break;
143  d->kossl->X509_free(x5);
144  }
145  sk_X509_free(x);
146  _chain = NULL;
147 }
148 
149  if (chain.count() == 0) return;
150  _chain = (void *)sk_new(NULL);
151  for (KSSLCertificate *x = chain.first(); x != 0; x = chain.next()) {
152  sk_X509_push((STACK_OF(X509)*)_chain, d->kossl->X509_dup(x->getCert()));
153  }
154 
155 #endif
156 }
157 
158 
159 void KSSLCertChain::setChain(void *stack_of_x509) {
160 #ifdef KSSL_HAVE_SSL
161 if (_chain) {
162  STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
163 
164  for (;;) {
165  X509* x5 = sk_X509_pop(x);
166  if (!x5) break;
167  d->kossl->X509_free(x5);
168  }
169  sk_X509_free(x);
170  _chain = NULL;
171 }
172 
173 if (!stack_of_x509) return;
174 
175 _chain = (void *)sk_new(NULL);
176 STACK_OF(X509) *x = (STACK_OF(X509) *)stack_of_x509;
177 
178  for (int i = 0; i < sk_X509_num(x); i++) {
179  X509* x5 = sk_X509_value(x, i);
180  if (!x5) continue;
181  sk_X509_push((STACK_OF(X509)*)_chain,d->kossl->X509_dup(x5));
182  }
183 
184 #else
185 _chain = NULL;
186 #endif
187 }
188 
189 
190 void KSSLCertChain::setChain(TQStringList chain) {
191  setCertChain(chain);
192 }
193 
194 void KSSLCertChain::setCertChain(const TQStringList& chain) {
195  TQPtrList<KSSLCertificate> cl;
196  cl.setAutoDelete(true);
197  for (TQStringList::ConstIterator s = chain.begin(); s != chain.end(); ++s) {
198  KSSLCertificate *c = KSSLCertificate::fromString((*s).local8Bit());
199  if (c) {
200  cl.append(c);
201  }
202  }
203  setChain(cl);
204 }
205 
206 
207 #ifdef KSSL_HAVE_SSL
208 #undef sk_new
209 #undef sk_push
210 #undef sk_free
211 #undef sk_value
212 #undef sk_num
213 #undef sk_dup
214 #undef sk_pop
215 #endif
216 

kio/kssl

Skip menu "kio/kssl"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kio/kssl

Skip menu "kio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/kssl by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |