Provide new API: QSslCertificate::isSelfSigned()
Change-Id: I382a017a0b865b849667301aff8b2f87b676ecc6 Reviewed-by: Richard J. Moore <rich@kde.org>bb10
parent
f3bc9f5c5c
commit
ae7bbe3400
|
|
@ -264,6 +264,21 @@ bool QSslCertificate::isBlacklisted() const
|
|||
return QSslCertificatePrivate::isBlacklisted(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns \c true if this certificate is self signed; otherwise
|
||||
returns \c false.
|
||||
|
||||
A certificate is considered self-signed its issuer and subject
|
||||
are identical.
|
||||
*/
|
||||
bool QSslCertificate::isSelfSigned() const
|
||||
{
|
||||
if (!d->x509)
|
||||
return false;
|
||||
|
||||
return (q_X509_check_issued(d->x509, d->x509) == X509_V_OK);
|
||||
}
|
||||
|
||||
/*!
|
||||
Clears the contents of this certificate, making it a null
|
||||
certificate.
|
||||
|
|
|
|||
|
|
@ -105,6 +105,7 @@ public:
|
|||
}
|
||||
#endif
|
||||
bool isBlacklisted() const;
|
||||
bool isSelfSigned() const;
|
||||
void clear();
|
||||
|
||||
// Certificate info
|
||||
|
|
|
|||
|
|
@ -316,6 +316,7 @@ DEFINEFUNC2(int, ASN1_STRING_print, BIO *a, a, const ASN1_STRING *b, b, return 0
|
|||
#else
|
||||
DEFINEFUNC2(int, ASN1_STRING_print, BIO *a, a, ASN1_STRING *b, b, return 0, return)
|
||||
#endif
|
||||
DEFINEFUNC2(int, X509_check_issued, X509 *a, a, X509 *b, b, return -1, return)
|
||||
DEFINEFUNC(X509_NAME *, X509_get_issuer_name, X509 *a, a, return 0, return)
|
||||
DEFINEFUNC(X509_NAME *, X509_get_subject_name, X509 *a, a, return 0, return)
|
||||
DEFINEFUNC(int, X509_verify_cert, X509_STORE_CTX *a, a, return -1, return)
|
||||
|
|
@ -819,6 +820,7 @@ bool q_resolveOpenSslSymbols()
|
|||
RESOLVEFUNC(BASIC_CONSTRAINTS_free)
|
||||
RESOLVEFUNC(AUTHORITY_KEYID_free)
|
||||
RESOLVEFUNC(ASN1_STRING_print)
|
||||
RESOLVEFUNC(X509_check_issued)
|
||||
RESOLVEFUNC(X509_get_issuer_name)
|
||||
RESOLVEFUNC(X509_get_subject_name)
|
||||
RESOLVEFUNC(X509_verify_cert)
|
||||
|
|
|
|||
|
|
@ -407,6 +407,7 @@ int q_ASN1_STRING_print(BIO *a, const ASN1_STRING *b);
|
|||
#else
|
||||
int q_ASN1_STRING_print(BIO *a, ASN1_STRING *b);
|
||||
#endif
|
||||
int q_X509_check_issued(X509 *a, X509 *b);
|
||||
X509_NAME *q_X509_get_issuer_name(X509 *a);
|
||||
X509_NAME *q_X509_get_subject_name(X509 *a);
|
||||
int q_X509_verify_cert(X509_STORE_CTX *ctx);
|
||||
|
|
|
|||
|
|
@ -104,6 +104,7 @@ private slots:
|
|||
void largeSerialNumber();
|
||||
void largeExpirationDate();
|
||||
void blacklistedCertificates();
|
||||
void selfsignedCertificates();
|
||||
void toText();
|
||||
void multipleCommonNames();
|
||||
void subjectAndIssuerAttributes();
|
||||
|
|
@ -846,6 +847,13 @@ void tst_QSslCertificate::blacklistedCertificates()
|
|||
}
|
||||
}
|
||||
|
||||
void tst_QSslCertificate::selfsignedCertificates()
|
||||
{
|
||||
QVERIFY(QSslCertificate::fromPath(testDataDir + "/certificates/cert-ss.pem").first().isSelfSigned());
|
||||
QVERIFY(!QSslCertificate::fromPath(testDataDir + "/certificates/cert.pem").first().isSelfSigned());
|
||||
QVERIFY(!QSslCertificate().isSelfSigned());
|
||||
}
|
||||
|
||||
void tst_QSslCertificate::toText()
|
||||
{
|
||||
QList<QSslCertificate> certList =
|
||||
|
|
|
|||
Loading…
Reference in New Issue