25#include <ksslconfig.h>
30#include <QtCore/QString>
31#include <QtCore/QStringList>
32#include <QtCore/QFile>
42#include <QtCore/QDate>
54#define crypt _openssl_crypt
55#include <openssl/ssl.h>
56#include <openssl/x509.h>
57#include <openssl/x509v3.h>
58#include <openssl/x509_vfy.h>
59#include <openssl/pem.h>
60#include <openssl/asn1.h>
70static char hv[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F'};
73class KSSLCertificatePrivate {
75 KSSLCertificatePrivate() {
76 kossl = KOSSL::self();
80 ~KSSLCertificatePrivate() {
90 KSSLX509V3 _extensions;
95 d =
new KSSLCertificatePrivate;
96 d->m_stateCached =
false;
105 d =
new KSSLCertificatePrivate;
106 d->m_stateCached =
false;
122 d->kossl->X509_free(d->m_cert);
139 n->
setCert(KOSSL::self()->X509_dup(x5));
149 if (cert.isEmpty()) {
153 QByteArray qba = QByteArray::fromBase64(cert);
154 unsigned char *qbap =
reinterpret_cast<unsigned char *
>(qba.data());
155 X509 *x5c = KOSSL::self()->d2i_X509(NULL, &qbap, qba.size());
172 char *t = d->kossl->X509_NAME_oneline(d->kossl->X509_get_subject_name(d->m_cert), 0, 0);
177 d->kossl->OPENSSL_free(t);
187 ASN1_INTEGER *aint = d->kossl->X509_get_serialNumber(d->m_cert);
189 rc = ASN1_INTEGER_QString(aint);
204 const X509_ALGOR *algor;
205 const ASN1_BIT_STRING *sig;
206 d->kossl->X509_get0_signature(&sig, &algor, d->m_cert);
207 i = d->kossl->OBJ_obj2nid(algor->algorithm);
208 rc =
i18n(
"Signature Algorithm: ");
209 rc += (i == NID_undef)?
i18n(
"Unknown"):QString(d->kossl->OBJ_nid2ln(i));
212 rc +=
i18n(
"Signature Contents:");
213 n = ASN1_STRING_length(sig);
214 s = (
char *)ASN1_STRING_get0_data(sig);
215 for (i = 0; i < n; ++i) {
222 rc.append(QChar(
hv[(s[i]&0xf0)>>4]));
223 rc.append(QChar(
hv[s[i]&0x0f]));
239 STACK *s = d->kossl->X509_get1_email(d->m_cert);
240 const int size = d->kossl->OPENSSL_sk_num(s);
242 for(
int n=0; n < size; n++) {
243 to.append(d->kossl->OPENSSL_sk_value(s,n));
245 d->kossl->X509_email_free(s);
258 int pos = k.lastIndexOf(
'(');
260 unsigned int len = k.length();
261 if (k.at(len-1) ==
')') {
262 rc = k.mid(pos+1, len-pos-2);
274 unsigned char md[EVP_MAX_MD_SIZE];
276 if (!d->kossl->X509_digest(d->m_cert, d->kossl->EVP_md5(), md, &n)) {
280 for (
unsigned int j = 0; j < n; j++) {
284 rc.append(QChar(
hv[(md[j]&0xf0)>>4]));
285 rc.append(QChar(
hv[md[j]&0x0f]));
300 unsigned char md[EVP_MAX_MD_SIZE];
302 if (!d->kossl->X509_digest(d->m_cert, d->kossl->EVP_md5(), md, &n)) {
306 for (
unsigned int j = 0; j < n; j++) {
307 rc.append(QLatin1Char(
hv[(md[j]&0xf0)>>4]));
308 rc.append(QLatin1Char(
hv[md[j]&0x0f]));
322 EVP_PKEY *pkey = d->kossl->X509_get_pubkey(d->m_cert);
325 if (d->kossl->EVP_PKEY_base_id(pkey) == EVP_PKEY_RSA) {
331 if (d->kossl->EVP_PKEY_base_id(pkey) == EVP_PKEY_DSA) {
337 d->kossl->EVP_PKEY_free(pkey);
351 EVP_PKEY *pkey = d->kossl->X509_get_pubkey(d->m_cert);
353 rc =
i18nc(
"Unknown",
"Unknown key algorithm");
355 if (d->kossl->EVP_PKEY_base_id(pkey) == EVP_PKEY_RSA) {
357 d->kossl->RSA_get0_key(d->kossl->EVP_PKEY_get0_RSA(pkey), &n, &e, NULL);
358 x = d->kossl->BN_bn2hex(n);
359 rc =
i18n(
"Key type: RSA (%1 bit)", strlen(x)*4) +
'\n';
361 rc +=
i18n(
"Modulus: ");
362 for (
unsigned int i = 0; i < strlen(x); i++) {
363 if (i%40 != 0 && i%2 == 0) {
366 else if (i%40 == 0) {
372 d->kossl->OPENSSL_free(x);
374 x = d->kossl->BN_bn2hex(e);
375 rc +=
i18n(
"Exponent: 0x") + QLatin1String(x) +
377 d->kossl->OPENSSL_free(x);
381 if (d->kossl->EVP_PKEY_base_id(pkey) == EVP_PKEY_DSA) {
382 DSA *dsa = d->kossl->EVP_PKEY_get0_DSA(pkey);
383 const BIGNUM *p, *q, *g;
384 d->kossl->DSA_get0_pqg(dsa, &p, &q, &g);
385 x = d->kossl->BN_bn2hex(p);
387 rc =
i18n(
"Key type: DSA (%1 bit)", strlen(x)*4) +
'\n';
389 rc +=
i18n(
"Prime: ");
390 for (
unsigned int i = 0; i < strlen(x); i++) {
391 if (i%40 != 0 && i%2 == 0) {
394 else if (i%40 == 0) {
400 d->kossl->OPENSSL_free(x);
402 x = d->kossl->BN_bn2hex(q);
403 rc +=
i18n(
"160 bit prime factor: ");
404 for (
unsigned int i = 0; i < strlen(x); i++) {
405 if (i%40 != 0 && i%2 == 0) {
408 else if (i%40 == 0) {
414 d->kossl->OPENSSL_free(x);
416 x = d->kossl->BN_bn2hex(g);
417 rc += QString(
"g: ");
418 for (
unsigned int i = 0; i < strlen(x); i++) {
419 if (i%40 != 0 && i%2 == 0) {
422 else if (i%40 == 0) {
428 d->kossl->OPENSSL_free(x);
430 const BIGNUM *pub_key;
431 d->kossl->DSA_get0_key(dsa, &pub_key, NULL);
432 x = d->kossl->BN_bn2hex(pub_key);
433 rc +=
i18n(
"Public key: ");
434 for (
unsigned int i = 0; i < strlen(x); i++) {
435 if (i%40 != 0 && i%2 == 0) {
438 else if (i%40 == 0) {
444 d->kossl->OPENSSL_free(x);
447 d->kossl->EVP_PKEY_free(pkey);
460 char *t = d->kossl->X509_NAME_oneline(d->kossl->X509_get_issuer_name(d->m_cert), 0, 0);
467 d->kossl->OPENSSL_free(t);
475 d->_chain.setChain(c);
477 d->m_stateCached =
false;
485 d->_extensions.flags = 0;
486 d->kossl->X509_check_purpose(c, -1, 0);
489 kDebug(7029) <<
"---------------- Certificate ------------------"
494 for (
int j = 0; j < d->kossl->X509_PURPOSE_get_count(); j++) {
495 X509_PURPOSE *ptmp = d->kossl->X509_PURPOSE_get0(j);
496 int id = d->kossl->X509_PURPOSE_get_id(ptmp);
497 for (
int ca = 0; ca < 2; ca++) {
498 int idret = d->kossl->X509_check_purpose(c,
id, ca);
499 if (idret == 1 || idret == 2) {
502 d->_extensions.flags |= (1L <<(
id-1));
504 else d->_extensions.flags |= (1L <<(16+
id-1));
507 d->_extensions.flags &= ~(1L <<(
id-1));
509 else d->_extensions.flags &= ~(1L <<(16+
id-1));
515 kDebug(7029) <<
"flags: " << QString::number(c->ex_flags, 2)
516 <<
"\nkeyusage: " << QString::number(c->ex_kusage, 2)
517 <<
"\nxkeyusage: " << QString::number(c->ex_xkusage, 2)
518 <<
"\nnscert: " << QString::number(c->ex_nscert, 2)
520 if (c->ex_flags & EXFLAG_KUSAGE)
521 kDebug(7029) <<
" --- Key Usage extensions found";
522 else kDebug(7029) <<
" --- Key Usage extensions NOT found";
524 if (c->ex_flags & EXFLAG_XKUSAGE)
525 kDebug(7029) <<
" --- Extended key usage extensions found";
526 else kDebug(7029) <<
" --- Extended key usage extensions NOT found";
528 if (c->ex_flags & EXFLAG_NSCERT)
529 kDebug(7029) <<
" --- NS extensions found";
530 else kDebug(7029) <<
" --- NS extensions NOT found";
532 if (d->_extensions.certTypeSSLCA())
533 kDebug(7029) <<
"NOTE: this is an SSL CA file.";
534 else kDebug(7029) <<
"NOTE: this is NOT an SSL CA file.";
536 if (d->_extensions.certTypeEmailCA())
537 kDebug(7029) <<
"NOTE: this is an EMAIL CA file.";
538 else kDebug(7029) <<
"NOTE: this is NOT an EMAIL CA file.";
540 if (d->_extensions.certTypeCodeCA())
541 kDebug(7029) <<
"NOTE: this is a CODE CA file.";
542 else kDebug(7029) <<
"NOTE: this is NOT a CODE CA file.";
544 if (d->_extensions.certTypeSSLClient())
545 kDebug(7029) <<
"NOTE: this is an SSL client.";
546 else kDebug(7029) <<
"NOTE: this is NOT an SSL client.";
548 if (d->_extensions.certTypeSSLServer())
549 kDebug(7029) <<
"NOTE: this is an SSL server.";
550 else kDebug(7029) <<
"NOTE: this is NOT an SSL server.";
552 if (d->_extensions.certTypeNSSSLServer())
553 kDebug(7029) <<
"NOTE: this is a NETSCAPE SSL server.";
554 else kDebug(7029) <<
"NOTE: this is NOT a NETSCAPE SSL server.";
556 if (d->_extensions.certTypeSMIME())
557 kDebug(7029) <<
"NOTE: this is an SMIME certificate.";
558 else kDebug(7029) <<
"NOTE: this is NOT an SMIME certificate.";
560 if (d->_extensions.certTypeSMIMEEncrypt())
561 kDebug(7029) <<
"NOTE: this is an SMIME encrypt cert.";
562 else kDebug(7029) <<
"NOTE: this is NOT an SMIME encrypt cert.";
564 if (d->_extensions.certTypeSMIMESign())
565 kDebug(7029) <<
"NOTE: this is an SMIME sign cert.";
566 else kDebug(7029) <<
"NOTE: this is NOT an SMIME sign cert.";
568 if (d->_extensions.certTypeCRLSign())
569 kDebug(7029) <<
"NOTE: this is a CRL signer.";
570 else kDebug(7029) <<
"NOTE: this is NOT a CRL signer.";
572 kDebug(7029) <<
"-----------------------------------------------"
577 d->m_stateCached =
false;
591#include "ksslcallback.c"
608 rc = X509_PURPOSE_SSL_SERVER;
610 rc = X509_PURPOSE_SSL_CLIENT;
612 rc = X509_PURPOSE_SMIME_ENCRYPT;
614 rc = X509_PURPOSE_SMIME_SIGN;
616 rc = X509_PURPOSE_ANY;
631 if (result.isEmpty()) {
635 return result.first();
651 if (ca || (d->_lastPurpose != purpose)) {
652 d->m_stateCached =
false;
655 if (!d->m_stateCached) {
656 d->_lastPurpose = purpose;
660 X509_STORE *certStore;
661 X509_LOOKUP *certLookup;
662 X509_STORE_CTX *certStoreCTX;
670 if (d->m_stateCached) {
671 errors << d->m_stateCache;
684 for (QStringList::ConstIterator j = qsl.begin(); j != qsl.end(); ++j) {
686 QString _j = (*j) +
"ca-bundle.crt";
687 if (-1 == KDE_stat(_j.toLatin1().constData(), &sb)) {
691 certStore = d->kossl->X509_STORE_new();
697 d->kossl->X509_STORE_set_verify_cb(certStore, X509Callback);
699 certLookup = d->kossl->X509_STORE_add_lookup(certStore, d->kossl->X509_LOOKUP_file());
702 d->kossl->X509_STORE_free(certStore);
706 if (!d->kossl->X509_LOOKUP_load_file(certLookup, _j.toLatin1().constData(), X509_FILETYPE_PEM)) {
708 kDebug(7029) <<
"KSSL couldn't read CA root: "
711 d->kossl->X509_STORE_free(certStore);
716 certStoreCTX = d->kossl->X509_STORE_CTX_new();
721 kDebug(7029) <<
"KSSL couldn't create an X509 store context.";
722 d->kossl->X509_STORE_free(certStore);
726 d->kossl->X509_STORE_CTX_init(certStoreCTX, certStore, d->m_cert, NULL);
727 if (d->_chain.isValid()) {
728 d->kossl->X509_STORE_CTX_set_chain(certStoreCTX, (
STACK_OF(X509)*)d->_chain.rawChain());
734 d->kossl->X509_STORE_CTX_set_purpose(certStoreCTX, purposeToOpenSSL(purpose));
736 KSSL_X509CallBack_ca = ca ? ca->d->m_cert : 0;
737 KSSL_X509CallBack_ca_found =
false;
739 d->kossl->X509_STORE_CTX_set_error(certStoreCTX, X509_V_OK);
740 rc = d->kossl->X509_verify_cert(certStoreCTX);
741 int errcode = d->kossl->X509_STORE_CTX_get_error(certStoreCTX);
742 if (ca && !KSSL_X509CallBack_ca_found) {
751 d->kossl->X509_STORE_CTX_set_purpose(certStoreCTX,
752 X509_PURPOSE_NS_SSL_SERVER);
754 d->kossl->X509_STORE_CTX_set_error(certStoreCTX, X509_V_OK);
755 rc = d->kossl->X509_verify_cert(certStoreCTX);
756 errcode = d->kossl->X509_STORE_CTX_get_error(certStoreCTX);
759 d->kossl->X509_STORE_CTX_free(certStoreCTX);
760 d->kossl->X509_STORE_free(certStore);
772 d->m_stateCached =
true;
773 d->m_stateCache = ksslv;
795 d->m_stateCached =
false;
816 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
821 case X509_V_ERR_UNABLE_TO_GET_CRL:
826 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
831 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
836 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
841 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
846 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
851 case X509_V_ERR_CERT_NOT_YET_VALID:
856 case X509_V_ERR_CERT_HAS_EXPIRED:
858 kDebug(7029) <<
"KSSL apparently this is expired. Not after: "
863 case X509_V_ERR_CRL_NOT_YET_VALID:
868 case X509_V_ERR_CRL_HAS_EXPIRED:
873 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
878 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
883 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
888 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
893 case X509_V_ERR_OUT_OF_MEM:
898 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
903 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
908 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
913 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
918 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
923 case X509_V_ERR_CERT_REVOKED:
928 case X509_V_ERR_INVALID_CA:
933 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
938 case X509_V_ERR_INVALID_PURPOSE:
943 case X509_V_ERR_CERT_UNTRUSTED:
948 case X509_V_ERR_CERT_REJECTED:
953 case X509_V_ERR_SUBJECT_ISSUER_MISMATCH:
958 case X509_V_ERR_AKID_SKID_MISMATCH:
963 case X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH:
968 case X509_V_ERR_KEYUSAGE_NO_CERTSIGN:
974 case X509_V_ERR_APPLICATION_VERIFICATION:
984 d->m_stateCache = rc;
985 d->m_stateCached =
true;
993 return ASN1_UTCTIME_QString(d->kossl->X509_getm_notBefore(d->m_cert));
1002 return ASN1_UTCTIME_QString(d->kossl->X509_getm_notAfter(d->m_cert));
1011 return ASN1_UTCTIME_QDateTime(d->kossl->X509_getm_notBefore(d->m_cert), NULL);
1013 return QDateTime::currentDateTime();
1020 return ASN1_UTCTIME_QDateTime(d->kossl->X509_getm_notAfter(d->m_cert), NULL);
1022 return QDateTime::currentDateTime();
1028#ifndef KSSL_HAVE_SSL
1055 return toDer().toBase64();
1063 return i18n(
"The certificate is valid.");
1065 return i18n(
"Retrieval of the issuer certificate failed. This means the CA's (Certificate Authority) certificate can not be found.");
1067 return i18n(
"Retrieval of the CRL (Certificate Revocation List) failed. This means the CA's (Certificate Authority) CRL can not be found.");
1069 return i18n(
"The decryption of the certificate's signature failed. This means it could not even be calculated as opposed to just not matching the expected result.");
1071 return i18n(
"The decryption of the CRL's (Certificate Revocation List) signature failed. This means it could not even be calculated as opposed to just not matching the expected result.");
1073 return i18n(
"The decoding of the public key of the issuer failed. This means that the CA's (Certificate Authority) certificate can not be used to verify the certificate you wanted to use.");
1075 return i18n(
"The certificate's signature is invalid. This means that the certificate can not be verified.");
1077 return i18n(
"The CRL's (Certificate Revocation List) signature is invalid. This means that the CRL can not be verified.");
1079 return i18n(
"The certificate is not valid, yet.");
1081 return i18n(
"The certificate is not valid, any more.");
1083 return i18n(
"The CRL (Certificate Revocation List) is not valid, yet.");
1085 return i18n(
"The CRL (Certificate Revocation List) is not valid, yet.");
1087 return i18n(
"The time format of the certificate's 'notBefore' field is invalid.");
1089 return i18n(
"The time format of the certificate's 'notAfter' field is invalid.");
1091 return i18n(
"The time format of the CRL's (Certificate Revocation List) 'lastUpdate' field is invalid.");
1093 return i18n(
"The time format of the CRL's (Certificate Revocation List) 'nextUpdate' field is invalid.");
1095 return i18n(
"The OpenSSL process ran out of memory.");
1097 return i18n(
"The certificate is self-signed and not in the list of trusted certificates. If you want to accept this certificate, import it into the list of trusted certificates.");
1100 return i18n(
"The certificate is self-signed. While the trust chain could be built up, the root CA's (Certificate Authority) certificate can not be found.");
1102 return i18n(
"The CA's (Certificate Authority) certificate can not be found. Most likely, your trust chain is broken.");
1104 return i18n(
"The certificate can not be verified as it is the only certificate in the trust chain and not self-signed. If you self-sign the certificate, make sure to import it into the list of trusted certificates.");
1106 return i18n(
"The certificate chain is longer than the maximum depth specified.");
1109 return i18n(
"The certificate has been revoked.");
1111 return i18n(
"The certificate's CA (Certificate Authority) is invalid.");
1113 return i18n(
"The length of the trust chain exceeded one of the CA's (Certificate Authority) 'pathlength' parameters, making all subsequent signatures invalid.");
1115 return i18n(
"The certificate has not been signed for the purpose you tried to use it for. This means the CA (Certificate Authority) does not allow this usage.");
1118 return i18n(
"The root CA (Certificate Authority) is not trusted for the purpose you tried to use this certificate for.");
1121 return i18n(
"The root CA (Certificate Authority) has been marked to be rejected for the purpose you tried to use it for.");
1123 return i18n(
"The certificate's CA (Certificate Authority) does not match the CA name of the certificate.");
1125 return i18n(
"The CA (Certificate Authority) certificate's key ID does not match the key ID in the 'Issuer' section of the certificate you are trying to use.");
1127 return i18n(
"The CA (Certificate Authority) certificate's key ID and name do not match the key ID and name in the 'Issuer' section of the certificate you are trying to use.");
1129 return i18n(
"The certificate's CA (Certificate Authority) is not allowed to sign certificates.");
1131 return i18n(
"OpenSSL could not be verified.");
1136 return i18n(
"The signature test for this certificate failed. This could mean that the signature of this certificate or any in its trust path are invalid, could not be decoded or that the CRL (Certificate Revocation List) could not be verified. If you see this message, please let the author of the software you are using know that he or she should use the new, more specific error messages.");
1138 return i18n(
"This certificate, any in its trust path or its CA's (Certificate Authority) CRL (Certificate Revocation List) is not valid. Any of them could not be valid yet or not valid any more. If you see this message, please let the author of the software you are using know that he or she should use the new, more specific error messages.");
1144 return i18n(
"Certificate signing authority root files could not be found so the certificate is not verified.");
1146 return i18n(
"SSL support was not found.");
1148 return i18n(
"Private key test failed.");
1150 return i18n(
"The certificate has not been issued for this host.");
1152 return i18n(
"This certificate is not relevant.");
1157 return i18n(
"The certificate is invalid.");
1164 int certlen = d->kossl->i2d_X509(
getCert(), NULL);
1168 char *cert =
new char[certlen];
1169 unsigned char *p = (
unsigned char *)cert;
1171 d->kossl->i2d_X509(
getCert(), &p);
1174 qba = QByteArray(cert, certlen);
1186const char *
header =
"-----BEGIN CERTIFICATE-----\n";
1187const char *footer =
"-----END CERTIFICATE-----\n";
1191 unsigned int xx = thecert.length() - 1;
1192 for (
unsigned int i = 0; i < xx/64; i++) {
1193 thecert.insert(64*(i+1)+i,
'\n');
1198 if (thecert[thecert.length()-1] !=
'\n') {
1202 thecert.append(footer);
1204 qba = thecert.toLocal8Bit();
1209#define NETSCAPE_CERT_HDR "certificate"
1212#if OPENSSL_VERSION_NUMBER < 0x00909000L
1214typedef struct NETSCAPE_X509_st
1216 ASN1_OCTET_STRING *
header;
1226#if KSSL_HAVE_SSL && OPENSSL_VERSION_NUMBER < 0x10100000L
1228 ASN1_OCTET_STRING hdr;
1231 FILE *ktf_fs = fopen(ktf.fileName().toLatin1(),
"r+");
1238 d->kossl->ASN1_item_i2d_fp(ktf_fs,(
unsigned char *)&nx);
1241 QFile qf(ktf.fileName());
1242 if (qf.open(QIODevice::ReadOnly)) {
1256 FILE *ktf_fs = fopen(ktf.fileName().toLatin1(),
"r+");
1258 d->kossl->X509_print(ktf_fs,
getCert());
1261 QFile qf(ktf.fileName());
1262 if (!qf.open(QIODevice::ReadOnly) )
1264 char *buf =
new char[qf.size()+1];
1265 qf.read(buf, qf.size());
1276 QByteArray qba, qbb = cert.toLocal8Bit();
1277 qba = QByteArray::fromBase64(qbb);
1278 unsigned char *qbap =
reinterpret_cast<unsigned char *
>(qba.data());
1279 X509 *x5c = KOSSL::self()->d2i_X509(NULL, &qbap, qba.size());
1290 return d->_extensions;
1295 return d->_extensions.certTypeCA();
1303 names = (
STACK_OF(GENERAL_NAME)*)d->kossl->X509_get_ext_d2i(d->m_cert, NID_subject_alt_name, 0, 0);
1309 int cnt = d->kossl->OPENSSL_sk_num((STACK *)names);
1311 for (
int i = 0; i < cnt; i++) {
1312 const GENERAL_NAME *val = (
const GENERAL_NAME *)d->kossl->OPENSSL_sk_value(names, i);
1313 if (val->type != GEN_DNS) {
1317 QString s = (
const char *)d->kossl->ASN1_STRING_data(val->d.ia5);
1320 s.length() == d->kossl->ASN1_STRING_length(val->d.ia5)) {
1324 d->kossl->OPENSSL_sk_free(names);
1339 s << const_cast<KSSLCertificate&>(r).toString() << qsl;
1351 if (r.
setCert(cert) && !qsl.isEmpty()) {
KSSLCertChain * replicate()
Do a deep copy of the certificate chain.
void setCertChain(const QStringList &chain)
Set the certificate chain as a list of base64 encoded X.509 certificates.
void * rawChain()
Read the raw chain in OpenSSL format.
KSSLCertificate(const KSSLCertificate &x)
Copy constructor.
KSSLX509V3 & x509V3Extensions()
Access the X.509v3 parameters.
KSSLValidation
Result of the validate() call.
@ KeyMayNotSignCertificate
@ CertificateFieldNotAfterErroneous
@ CRLFieldLastUpdateErroneous
@ CRLFieldNextUpdateErroneous
@ CertificateChainTooLong
@ CertificateFieldNotBeforeErroneous
@ DecryptCertificateSignatureFailed
@ GetIssuerCertLocallyFailed
@ DecodeIssuerPublicKeyFailed
@ CertificateSignatureFailed
@ AuthAndSubjectKeyIDMismatched
@ IssuerSubjectMismatched
@ DecryptCRLSignatureFailed
@ AuthAndSubjectKeyIDAndNameMismatched
@ VerifyLeafSignatureFailed
@ ApplicationVerificationFailed
QString getSignatureText() const
Get the signature.
KSSLValidation revalidate()
Check if this is a valid certificate.
QString getIssuer() const
Get the issuer of the certificate (X.509 map).
bool isValid()
Check if this is a valid certificate.
QString getKeyType() const
Get the key type (RSA, DSA, etc).
QString getNotBefore() const
Get the date that the certificate becomes valid on.
QString getSerialNumber() const
Get the serial number of the certificate.
QList< KSSLValidation > KSSLValidationList
friend class KSSLCertChain
KSSLValidation processError(int ec)
static QString verifyText(KSSLValidation x)
Obtain the localized message that corresponds to a validation result.
KSSLValidationList validateVerbose(KSSLPurpose p)
Check if this is a valid certificate.
QString getSubject() const
Get the subject of the certificate (X.509 map).
QByteArray toDer()
Convert the certificate to DER (ASN.1) format.
QDateTime getQDTNotAfter() const
Get the date that the certificate is valid until.
QByteArray toNetscape()
Convert the certificate to Netscape format.
QString getPublicKeyText() const
Get the public key.
KSSLValidation validate()
Check if this is a valid certificate.
void getEmails(QStringList &to) const
FIXME: document.
QStringList subjAltNames() const
The alternate subject name.
QString toString()
Convert this certificate to a string.
static KSSLCertificate * fromX509(X509 *x5)
Create an X.509 certificate from the internal representation.
~KSSLCertificate()
Destroy this X.509 certificate.
QString getNotAfter() const
Get the date that the certificate is valid until.
static KSSLCertificate * fromString(const QByteArray &cert)
Create an X.509 certificate from a base64 encoded string.
static QString getMD5DigestFromKDEKey(const QString &k)
Aegypten semantics force us to search by MD5Digest only.
QDateTime getQDTNotBefore() const
Get the date that the certificate becomes valid on.
QByteArray toPem()
Convert the certificate to PEM (base64) format.
QString getMD5DigestText() const
Get the MD5 digest of the certificate.
QString getMD5Digest() const
Get the MD5 digest of the certificate.
KSSLCertChain & chain()
Get a reference to the certificate chain.
KSSLCertificate * replicate()
Explicitly make a copy of this certificate.
bool isSigner()
Check if this is a signer certificate.
QString getKDEKey() const
KDEKey is a concatenation "Subject (MD5)", mostly needed for SMIME.
QString toText()
Convert the certificate to OpenSSL plain text format.
bool setCert(const QString &cert)
Re-set the certificate from a base64 string.
bool addResourceType(const char *type, const char *basetype, const char *relativename, bool priority=true)
QStringList resourceDirs(const char *type) const
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QString i18n(const char *text)
QString i18nc(const char *ctxt, const char *text)
QDataStream & operator>>(QDataStream &s, KSSLCertificate &r)
#define NETSCAPE_CERT_HDR
QDataStream & operator<<(QDataStream &s, const KSSLCertificate &r)
int operator==(KSSLCertificate &x, KSSLCertificate &y)