• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KIO

  • sources
  • kde-4.12
  • kdelibs
  • kio
  • kssl
ksslcertchain.cpp
Go to the documentation of this file.
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 
21 #include "ksslcertchain.h"
22 
23 #include <config.h>
24 #include <ksslconfig.h>
25 
26 #include "kssldefs.h"
27 #include "ksslcertificate.h"
28 
29 // this hack provided by Malte Starostik to avoid glibc/openssl bug
30 // on some systems
31 #ifdef KSSL_HAVE_SSL
32 #define crypt _openssl_crypt
33 #include <openssl/ssl.h>
34 #include <openssl/x509.h>
35 #include <openssl/x509v3.h>
36 #include <openssl/x509_vfy.h>
37 #include <openssl/pem.h>
38 #include <openssl/stack.h>
39 #include <openssl/safestack.h>
40 #undef crypt
41 #endif
42 
43 #include <kopenssl.h>
44 #include <kdebug.h>
45 #include <QtCore/QStringList>
46 
47 #ifdef KSSL_HAVE_SSL
48 #define sk_new d->kossl->sk_new
49 #define sk_push d->kossl->sk_push
50 #define sk_free d->kossl->sk_free
51 #define sk_value d->kossl->sk_value
52 #define sk_num d->kossl->sk_num
53 #define sk_dup d->kossl->sk_dup
54 #define sk_pop d->kossl->sk_pop
55 #endif
56 
57 class KSSLCertChainPrivate {
58 public:
59  KSSLCertChainPrivate() {
60  kossl = KOSSL::self();
61  }
62 
63  ~KSSLCertChainPrivate() {
64  }
65 
66  KOSSL *kossl;
67 };
68 
69 KSSLCertChain::KSSLCertChain()
70  :d(new KSSLCertChainPrivate)
71 {
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  QList<KSSLCertificate *> ch = getChain();
101  x->setChain(ch); // this will do a deep copy for us
102  qDeleteAll(ch);
103  return x;
104 }
105 
106 
107 int KSSLCertChain::depth() {
108 #ifdef KSSL_HAVE_SSL
109  return sk_X509_num((STACK_OF(X509)*)_chain);
110 #endif
111 return 0;
112 }
113 
114 void *KSSLCertChain::rawChain()
115 {
116  return _chain;
117 }
118 
119 
120 QList<KSSLCertificate *> KSSLCertChain::getChain() const {
121  QList<KSSLCertificate *> cl;
122  if (!_chain) return cl;
123 #ifdef KSSL_HAVE_SSL
124  STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
125 
126  for (int i = 0; i < sk_X509_num(x); i++) {
127  X509* x5 = sk_X509_value(x, i);
128  if (!x5) continue;
129  KSSLCertificate *nc = new KSSLCertificate;
130  nc->setCert(d->kossl->X509_dup(x5));
131  cl.append(nc);
132  }
133 
134 #endif
135  return cl;
136 }
137 
138 
139 void KSSLCertChain::setChain(const QList<KSSLCertificate *>& chain) {
140 #ifdef KSSL_HAVE_SSL
141  if (_chain) {
142  STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
143 
144  for (;;) {
145  X509* x5 = sk_X509_pop(x);
146  if (!x5) break;
147  d->kossl->X509_free(x5);
148  }
149  sk_X509_free(x);
150  _chain = NULL;
151  }
152 
153  if (chain.isEmpty()) return;
154  _chain = (void *)sk_new(NULL);
155  foreach (KSSLCertificate *x, chain) {
156  sk_X509_push((STACK_OF(X509)*)_chain, d->kossl->X509_dup(x->getCert()));
157  }
158 
159 #endif
160 }
161 
162 
163 void KSSLCertChain::setChain(void *stack_of_x509) {
164 #ifdef KSSL_HAVE_SSL
165 if (_chain) {
166  STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
167 
168  for (;;) {
169  X509* x5 = sk_X509_pop(x);
170  if (!x5) break;
171  d->kossl->X509_free(x5);
172  }
173  sk_X509_free(x);
174  _chain = NULL;
175 }
176 
177 if (!stack_of_x509) return;
178 
179 _chain = (void *)sk_new(NULL);
180 STACK_OF(X509) *x = (STACK_OF(X509) *)stack_of_x509;
181 
182  for (int i = 0; i < sk_X509_num(x); i++) {
183  X509* x5 = sk_X509_value(x, i);
184  if (!x5) continue;
185  sk_X509_push((STACK_OF(X509)*)_chain,d->kossl->X509_dup(x5));
186  }
187 
188 #else
189 _chain = NULL;
190 #endif
191 }
192 
193 
194 void KSSLCertChain::setCertChain(const QStringList& chain) {
195  QList<KSSLCertificate *> cl;
196  for (QStringList::ConstIterator s = chain.begin(); s != chain.end(); ++s) {
197  KSSLCertificate *c = KSSLCertificate::fromString((*s).toLocal8Bit());
198  if (c) {
199  cl.append(c);
200  }
201  }
202  setChain(cl);
203 }
204 
205 
206 #ifdef KSSL_HAVE_SSL
207 #undef sk_new
208 #undef sk_push
209 #undef sk_free
210 #undef sk_value
211 #undef sk_num
212 #undef sk_dup
213 #undef sk_pop
214 #endif
215 
KSSLCertChain::KSSLCertChain
KSSLCertChain()
Construct a KSSLCertChain object.
Definition: ksslcertchain.cpp:69
kssldefs.h
kdebug.h
ksslcertificate.h
KSSLCertChain::~KSSLCertChain
~KSSLCertChain()
Destroy this KSSLCertChain object.
Definition: ksslcertchain.cpp:76
KSSLCertificate
KDE X.509 Certificate.
Definition: ksslcertificate.h:74
KSSLCertChain::getChain
QList< KSSLCertificate * > getChain() const
Obtain a copy of the certificate chain.
Definition: ksslcertchain.cpp:120
KSSLCertChain::rawChain
void * rawChain()
Read the raw chain in OpenSSL format.
Definition: ksslcertchain.cpp:114
KSSLCertChain::setChain
void setChain(void *stack_of_x509)
Set the raw chain from OpenSSL.
Definition: ksslcertchain.cpp:163
KSSLCertChain
KDE Certificate Chain Representation Class.
Definition: ksslcertchain.h:43
KSSLCertificate::getCert
X509 * getCert()
Definition: ksslcertificate.cpp:569
STACK_OF
#define STACK_OF(x)
Definition: ksslpkcs12.h:46
KSSLCertChain::setCertChain
void setCertChain(const QStringList &chain)
Set the certificate chain as a list of base64 encoded X.509 certificates.
Definition: ksslcertchain.cpp:194
QStringList
KOSSL
#define KOSSL
Definition: kopenssl.h:25
KSSLCertChain::replicate
KSSLCertChain * replicate()
Do a deep copy of the certificate chain.
Definition: ksslcertchain.cpp:98
KSSLCertChain::depth
int depth()
Determine the number of entries (depth) of the chain.
Definition: ksslcertchain.cpp:107
KSSLCertificate::fromString
static KSSLCertificate * fromString(const QByteArray &cert)
Create an X.509 certificate from a base64 encoded string.
Definition: ksslcertificate.cpp:145
KSSLCertChain::isValid
bool isValid()
Determine if this represents a valid certificate chain.
Definition: ksslcertchain.cpp:93
kopenssl.h
sk_new
#define sk_new
Definition: ksmimecrypto.cpp:41
ksslcertchain.h
KSSLCertificate::setCert
bool setCert(const QString &cert)
Re-set the certificate from a base64 string.
Definition: ksslcertificate.cpp:1261
QList
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:02 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal