25 #include "ksslcertificate.h"
26 #include "ksslcertchain.h"
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>
44 #include <tqstringlist.h>
47 class KSSLCertChainPrivate {
49 KSSLCertChainPrivate() {
50 kossl = KOSSL::self();
53 ~KSSLCertChainPrivate() {
60 d =
new KSSLCertChainPrivate;
68 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
71 X509* x5 =
reinterpret_cast<X509*
>(d->kossl->OPENSSL_sk_pop(x));
73 d->kossl->X509_free(x5);
75 d->kossl->OPENSSL_sk_free(x);
83 return (_chain &&
depth() > 0);
89 TQPtrList<KSSLCertificate> ch =
getChain();
92 ch.setAutoDelete(
true);
99 return d->kossl->OPENSSL_sk_num((STACK_OF(X509)*)_chain);
106 TQPtrList<KSSLCertificate> cl;
107 if (!_chain)
return cl;
109 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
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));
115 nc->
setCert(d->kossl->X509_dup(x5));
127 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
130 X509* x5 =
reinterpret_cast<X509*
>(d->kossl->OPENSSL_sk_pop(x));
132 d->kossl->X509_free(x5);
134 d->kossl->OPENSSL_sk_free(x);
138 if (chain.count() == 0)
return;
139 _chain =
reinterpret_cast<STACK_OF(X509)*
>(d->kossl->OPENSSL_sk_new(NULL));
141 d->kossl->OPENSSL_sk_push((STACK_OF(X509) *)_chain, d->kossl->X509_dup(x->getCert()));
151 STACK_OF(X509) *x = (STACK_OF(X509) *)_chain;
154 X509* x5 =
reinterpret_cast<X509*
>(d->kossl->OPENSSL_sk_pop(x));
156 d->kossl->X509_free(x5);
158 d->kossl->OPENSSL_sk_free(x);
162 if (!stack_of_x509)
return;
164 _chain =
reinterpret_cast<STACK_OF(X509)*
>(d->kossl->OPENSSL_sk_new(NULL));
165 STACK_OF(X509) *x = (STACK_OF(X509) *)stack_of_x509;
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));
170 d->kossl->OPENSSL_sk_push((STACK_OF(X509)*)_chain,d->kossl->X509_dup(x5));
184 TQPtrList<KSSLCertificate> cl;
185 cl.setAutoDelete(
true);
186 for (TQStringList::ConstIterator s = chain.begin(); s != chain.end(); ++s) {
KDE Certificate Chain Representation Class.
KSSLCertChain()
Construct a KSSLCertChain object.
TQPtrList< KSSLCertificate > getChain()
Obtain a copy of the certificate chain.
void setChain(void *stack_of_x509)
Set the raw chain from OpenSSL.
bool isValid()
Determine if this represents a valid certificate chain.
~KSSLCertChain()
Destroy this KSSLCertChain object.
KSSLCertChain * replicate()
Do a deep copy of the certificate chain.
int depth()
Determine the number of entries (depth) of the chain.
void setCertChain(const TQStringList &chain)
Set the certificate chain as a list of base64 encoded X.509 certificates.
static KSSLCertificate * fromString(TQCString cert)
Create an X.509 certificate from a base64 encoded string.
bool setCert(TQString &cert)
Re-set the certificate from a base64 string.