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

tdeio/kssl

  • tdeio
  • kssl
ksslcertchain.cpp
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
47class KSSLCertChainPrivate {
48public:
49 KSSLCertChainPrivate() {
50 kossl = KOSSL::self();
51 }
52
53 ~KSSLCertChainPrivate() {
54 }
55
56 KOSSL *kossl;
57};
58
59KSSLCertChain::KSSLCertChain() {
60 d = new KSSLCertChainPrivate;
61 _chain = NULL;
62}
63
64
65KSSLCertChain::~KSSLCertChain() {
66#ifdef KSSL_HAVE_SSL
67 if (_chain) {
68 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
69
70 for (;;) {
71 X509* x5 = reinterpret_cast<X509*>(d->kossl->OPENSSL_sk_pop(x));
72 if (!x5) break;
73 d->kossl->X509_free(x5);
74 }
75 d->kossl->OPENSSL_sk_free(x);
76 }
77#endif
78 delete d;
79}
80
81
82bool KSSLCertChain::isValid() {
83 return (_chain && depth() > 0);
84}
85
86
87KSSLCertChain *KSSLCertChain::replicate() {
88KSSLCertChain *x = new KSSLCertChain;
89TQPtrList<KSSLCertificate> ch = getChain();
90
91 x->setChain(ch); // this will do a deep copy for us
92 ch.setAutoDelete(true);
93return x;
94}
95
96
97int KSSLCertChain::depth() {
98#ifdef KSSL_HAVE_SSL
99 return d->kossl->OPENSSL_sk_num((STACK_OF(X509)*)_chain);
100#endif
101return 0;
102}
103
104
105TQPtrList<KSSLCertificate> KSSLCertChain::getChain() {
106TQPtrList<KSSLCertificate> cl;
107if (!_chain) return cl;
108#ifdef KSSL_HAVE_SSL
109STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
110
111 for (int i = 0; i < d->kossl->OPENSSL_sk_num(x); i++) {
112 X509* x5 = reinterpret_cast<X509*>(d->kossl->OPENSSL_sk_value(x, i));
113 if (!x5) continue;
114 KSSLCertificate *nc = new KSSLCertificate;
115 nc->setCert(d->kossl->X509_dup(x5));
116 cl.append(nc);
117 }
118
119#endif
120return cl;
121}
122
123
124void KSSLCertChain::setChain(TQPtrList<KSSLCertificate>& chain) {
125#ifdef KSSL_HAVE_SSL
126if (_chain) {
127 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
128
129 for (;;) {
130 X509* x5 = reinterpret_cast<X509*>(d->kossl->OPENSSL_sk_pop(x));
131 if (!x5) break;
132 d->kossl->X509_free(x5);
133 }
134 d->kossl->OPENSSL_sk_free(x);
135 _chain = NULL;
136}
137
138 if (chain.count() == 0) return;
139 _chain = reinterpret_cast<STACK_OF(X509)*>(d->kossl->OPENSSL_sk_new(NULL));
140 for (KSSLCertificate *x = chain.first(); x != 0; x = chain.next()) {
141 d->kossl->OPENSSL_sk_push((STACK_OF(X509) *)_chain, d->kossl->X509_dup(x->getCert()));
142 }
143
144#endif
145}
146
147
148void KSSLCertChain::setChain(void *stack_of_x509) {
149#ifdef KSSL_HAVE_SSL
150 if (_chain) {
151 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
152
153 for (;;) {
154 X509* x5 = reinterpret_cast<X509*>(d->kossl->OPENSSL_sk_pop(x));
155 if (!x5) break;
156 d->kossl->X509_free(x5);
157 }
158 d->kossl->OPENSSL_sk_free(x);
159 _chain = NULL;
160 }
161
162 if (!stack_of_x509) return;
163
164 _chain = reinterpret_cast<STACK_OF(X509)*>(d->kossl->OPENSSL_sk_new(NULL));
165 STACK_OF(X509) *x = (STACK_OF(X509) *)stack_of_x509;
166
167 for (int i = 0; i < d->kossl->OPENSSL_sk_num(x); i++) {
168 X509* x5 = reinterpret_cast<X509*>(d->kossl->OPENSSL_sk_value(x, i));
169 if (!x5) continue;
170 d->kossl->OPENSSL_sk_push((STACK_OF(X509)*)_chain,d->kossl->X509_dup(x5));
171 }
172
173#else
174 _chain = NULL;
175#endif
176}
177
178
179void KSSLCertChain::setChain(TQStringList chain) {
180 setCertChain(chain);
181}
182
183void KSSLCertChain::setCertChain(const TQStringList& chain) {
184 TQPtrList<KSSLCertificate> cl;
185 cl.setAutoDelete(true);
186 for (TQStringList::ConstIterator s = chain.begin(); s != chain.end(); ++s) {
187 KSSLCertificate *c = KSSLCertificate::fromString((*s).local8Bit());
188 if (c) {
189 cl.append(c);
190 }
191 }
192 setChain(cl);
193}
194
KSSLCertChain
KDE Certificate Chain Representation Class.
Definition: ksslcertchain.h:45
KSSLCertChain::KSSLCertChain
KSSLCertChain()
Construct a KSSLCertChain object.
Definition: ksslcertchain.cpp:59
KSSLCertChain::getChain
TQPtrList< KSSLCertificate > getChain()
Obtain a copy of the certificate chain.
Definition: ksslcertchain.cpp:105
KSSLCertChain::setChain
void setChain(void *stack_of_x509)
Set the raw chain from OpenSSL.
Definition: ksslcertchain.cpp:148
KSSLCertChain::isValid
bool isValid()
Determine if this represents a valid certificate chain.
Definition: ksslcertchain.cpp:82
KSSLCertChain::~KSSLCertChain
~KSSLCertChain()
Destroy this KSSLCertChain object.
Definition: ksslcertchain.cpp:65
KSSLCertChain::replicate
KSSLCertChain * replicate()
Do a deep copy of the certificate chain.
Definition: ksslcertchain.cpp:87
KSSLCertChain::depth
int depth()
Determine the number of entries (depth) of the chain.
Definition: ksslcertchain.cpp:97
KSSLCertChain::setCertChain
void setCertChain(const TQStringList &chain)
Set the certificate chain as a list of base64 encoded X.509 certificates.
Definition: ksslcertchain.cpp:183
KSSLCertificate
KDE X.509 Certificate.
Definition: ksslcertificate.h:77
KSSLCertificate::fromString
static KSSLCertificate * fromString(TQCString cert)
Create an X.509 certificate from a base64 encoded string.
Definition: ksslcertificate.cpp:151
KSSLCertificate::setCert
bool setCert(TQString &cert)
Re-set the certificate from a base64 string.
Definition: ksslcertificate.cpp:1151

tdeio/kssl

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

tdeio/kssl

Skip menu "tdeio/kssl"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/kssl by doxygen 1.9.4
This website is maintained by Timothy Pearson.