Extend the test for QSslKey
Check if QSslKey::handle() returns data representing the same key information as that passed to the constructor. Task-number: QTBUG-64495 Change-Id: I1a91264e6f6d92d259b51fca9de00fcbfd5cc845 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
This commit is contained in:
parent
785d2b9d07
commit
c6153660e4
@ -82,6 +82,7 @@ Q_AUTOTEST_EXPORT const BIO_METHOD *q_BIO_s_mem();
|
|||||||
|
|
||||||
int q_DSA_bits(DSA *a);
|
int q_DSA_bits(DSA *a);
|
||||||
int q_EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c);
|
int q_EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *c);
|
||||||
|
Q_AUTOTEST_EXPORT int q_EVP_PKEY_up_ref(EVP_PKEY *a);
|
||||||
int q_EVP_PKEY_base_id(EVP_PKEY *a);
|
int q_EVP_PKEY_base_id(EVP_PKEY *a);
|
||||||
int q_RSA_bits(RSA *a);
|
int q_RSA_bits(RSA *a);
|
||||||
Q_AUTOTEST_EXPORT int q_OPENSSL_sk_num(OPENSSL_STACK *a);
|
Q_AUTOTEST_EXPORT int q_OPENSSL_sk_num(OPENSSL_STACK *a);
|
||||||
|
@ -150,6 +150,7 @@ DEFINEFUNC(BIO *, BIO_new, const BIO_METHOD *a, a, return nullptr, return)
|
|||||||
DEFINEFUNC(const BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return nullptr, return)
|
DEFINEFUNC(const BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return nullptr, return)
|
||||||
DEFINEFUNC2(int, BN_is_word, BIGNUM *a, a, BN_ULONG w, w, return 0, return)
|
DEFINEFUNC2(int, BN_is_word, BIGNUM *a, a, BN_ULONG w, w, return 0, return)
|
||||||
DEFINEFUNC(int, EVP_CIPHER_CTX_reset, EVP_CIPHER_CTX *c, c, return 0, return)
|
DEFINEFUNC(int, EVP_CIPHER_CTX_reset, EVP_CIPHER_CTX *c, c, return 0, return)
|
||||||
|
DEFINEFUNC(int, EVP_PKEY_up_ref, EVP_PKEY *a, a, return 0, return)
|
||||||
DEFINEFUNC(int, EVP_PKEY_base_id, EVP_PKEY *a, a, return NID_undef, return)
|
DEFINEFUNC(int, EVP_PKEY_base_id, EVP_PKEY *a, a, return NID_undef, return)
|
||||||
DEFINEFUNC(int, RSA_bits, RSA *a, a, return 0, return)
|
DEFINEFUNC(int, RSA_bits, RSA *a, a, return 0, return)
|
||||||
DEFINEFUNC(int, DSA_bits, DSA *a, a, return 0, return)
|
DEFINEFUNC(int, DSA_bits, DSA *a, a, return 0, return)
|
||||||
@ -366,6 +367,7 @@ DEFINEFUNC2(int, EVP_PKEY_set1_DH, EVP_PKEY *a, a, DH *b, b, return -1, return)
|
|||||||
#ifndef OPENSSL_NO_EC
|
#ifndef OPENSSL_NO_EC
|
||||||
DEFINEFUNC2(int, EVP_PKEY_set1_EC_KEY, EVP_PKEY *a, a, EC_KEY *b, b, return -1, return)
|
DEFINEFUNC2(int, EVP_PKEY_set1_EC_KEY, EVP_PKEY *a, a, EC_KEY *b, b, return -1, return)
|
||||||
#endif
|
#endif
|
||||||
|
DEFINEFUNC2(int, EVP_PKEY_cmp, const EVP_PKEY *a, a, const EVP_PKEY *b, b, return -1, return)
|
||||||
DEFINEFUNC(void, EVP_PKEY_free, EVP_PKEY *a, a, return, DUMMYARG)
|
DEFINEFUNC(void, EVP_PKEY_free, EVP_PKEY *a, a, return, DUMMYARG)
|
||||||
DEFINEFUNC(DSA *, EVP_PKEY_get1_DSA, EVP_PKEY *a, a, return nullptr, return)
|
DEFINEFUNC(DSA *, EVP_PKEY_get1_DSA, EVP_PKEY *a, a, return nullptr, return)
|
||||||
DEFINEFUNC(RSA *, EVP_PKEY_get1_RSA, EVP_PKEY *a, a, return nullptr, return)
|
DEFINEFUNC(RSA *, EVP_PKEY_get1_RSA, EVP_PKEY *a, a, return nullptr, return)
|
||||||
@ -955,6 +957,7 @@ bool q_resolveOpenSslSymbols()
|
|||||||
RESOLVEFUNC(OPENSSL_init_crypto)
|
RESOLVEFUNC(OPENSSL_init_crypto)
|
||||||
RESOLVEFUNC(ASN1_STRING_get0_data)
|
RESOLVEFUNC(ASN1_STRING_get0_data)
|
||||||
RESOLVEFUNC(EVP_CIPHER_CTX_reset)
|
RESOLVEFUNC(EVP_CIPHER_CTX_reset)
|
||||||
|
RESOLVEFUNC(EVP_PKEY_up_ref)
|
||||||
RESOLVEFUNC(EVP_PKEY_base_id)
|
RESOLVEFUNC(EVP_PKEY_base_id)
|
||||||
RESOLVEFUNC(RSA_bits)
|
RESOLVEFUNC(RSA_bits)
|
||||||
RESOLVEFUNC(OPENSSL_sk_new_null)
|
RESOLVEFUNC(OPENSSL_sk_new_null)
|
||||||
@ -1184,6 +1187,7 @@ bool q_resolveOpenSslSymbols()
|
|||||||
#ifndef OPENSSL_NO_EC
|
#ifndef OPENSSL_NO_EC
|
||||||
RESOLVEFUNC(EVP_PKEY_set1_EC_KEY)
|
RESOLVEFUNC(EVP_PKEY_set1_EC_KEY)
|
||||||
#endif
|
#endif
|
||||||
|
RESOLVEFUNC(EVP_PKEY_cmp)
|
||||||
RESOLVEFUNC(EVP_PKEY_free)
|
RESOLVEFUNC(EVP_PKEY_free)
|
||||||
RESOLVEFUNC(EVP_PKEY_get1_DSA)
|
RESOLVEFUNC(EVP_PKEY_get1_DSA)
|
||||||
RESOLVEFUNC(EVP_PKEY_get1_RSA)
|
RESOLVEFUNC(EVP_PKEY_get1_RSA)
|
||||||
|
@ -284,11 +284,12 @@ const EVP_CIPHER *q_EVP_rc2_cbc();
|
|||||||
Q_AUTOTEST_EXPORT const EVP_MD *q_EVP_sha1();
|
Q_AUTOTEST_EXPORT const EVP_MD *q_EVP_sha1();
|
||||||
int q_EVP_PKEY_assign(EVP_PKEY *a, int b, char *c);
|
int q_EVP_PKEY_assign(EVP_PKEY *a, int b, char *c);
|
||||||
Q_AUTOTEST_EXPORT int q_EVP_PKEY_set1_RSA(EVP_PKEY *a, RSA *b);
|
Q_AUTOTEST_EXPORT int q_EVP_PKEY_set1_RSA(EVP_PKEY *a, RSA *b);
|
||||||
int q_EVP_PKEY_set1_DSA(EVP_PKEY *a, DSA *b);
|
Q_AUTOTEST_EXPORT int q_EVP_PKEY_set1_DSA(EVP_PKEY *a, DSA *b);
|
||||||
int q_EVP_PKEY_set1_DH(EVP_PKEY *a, DH *b);
|
Q_AUTOTEST_EXPORT int q_EVP_PKEY_set1_DH(EVP_PKEY *a, DH *b);
|
||||||
#ifndef OPENSSL_NO_EC
|
#ifndef OPENSSL_NO_EC
|
||||||
int q_EVP_PKEY_set1_EC_KEY(EVP_PKEY *a, EC_KEY *b);
|
Q_AUTOTEST_EXPORT int q_EVP_PKEY_set1_EC_KEY(EVP_PKEY *a, EC_KEY *b);
|
||||||
#endif
|
#endif
|
||||||
|
Q_AUTOTEST_EXPORT int q_EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||||
Q_AUTOTEST_EXPORT void q_EVP_PKEY_free(EVP_PKEY *a);
|
Q_AUTOTEST_EXPORT void q_EVP_PKEY_free(EVP_PKEY *a);
|
||||||
RSA *q_EVP_PKEY_get1_RSA(EVP_PKEY *a);
|
RSA *q_EVP_PKEY_get1_RSA(EVP_PKEY *a);
|
||||||
DSA *q_EVP_PKEY_get1_DSA(EVP_PKEY *a);
|
DSA *q_EVP_PKEY_get1_DSA(EVP_PKEY *a);
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <QtTest/QtTest>
|
#include <QtTest/QtTest>
|
||||||
#include <qsslkey.h>
|
#include <qsslkey.h>
|
||||||
#include <qsslsocket.h>
|
#include <qsslsocket.h>
|
||||||
|
#include <QScopeGuard>
|
||||||
|
|
||||||
#include <QtNetwork/qhostaddress.h>
|
#include <QtNetwork/qhostaddress.h>
|
||||||
#include <QtNetwork/qnetworkproxy.h>
|
#include <QtNetwork/qnetworkproxy.h>
|
||||||
@ -233,15 +234,50 @@ void tst_QSslKey::constructorHandle()
|
|||||||
QByteArray passphrase;
|
QByteArray passphrase;
|
||||||
if (QByteArray(QTest::currentDataTag()).contains("-pkcs8-"))
|
if (QByteArray(QTest::currentDataTag()).contains("-pkcs8-"))
|
||||||
passphrase = "1234";
|
passphrase = "1234";
|
||||||
|
|
||||||
BIO* bio = q_BIO_new(q_BIO_s_mem());
|
BIO* bio = q_BIO_new(q_BIO_s_mem());
|
||||||
q_BIO_write(bio, pem.constData(), pem.length());
|
q_BIO_write(bio, pem.constData(), pem.length());
|
||||||
QSslKey key(func(bio, nullptr, nullptr, static_cast<void *>(passphrase.data())), type);
|
EVP_PKEY *origin = func(bio, nullptr, nullptr, static_cast<void *>(passphrase.data()));
|
||||||
|
#if QT_CONFIG(opensslv11)
|
||||||
|
q_EVP_PKEY_up_ref(origin);
|
||||||
|
#endif
|
||||||
|
QSslKey key(origin, type);
|
||||||
|
#if !QT_CONFIG(opensslv11)
|
||||||
|
q_BIO_write(bio, pem.constData(), pem.length());
|
||||||
|
origin = func(bio, nullptr, nullptr, static_cast<void *>(passphrase.data()));
|
||||||
|
#endif
|
||||||
q_BIO_free(bio);
|
q_BIO_free(bio);
|
||||||
|
|
||||||
|
EVP_PKEY *handle = q_EVP_PKEY_new();
|
||||||
|
switch (algorithm) {
|
||||||
|
case QSsl::Rsa:
|
||||||
|
q_EVP_PKEY_set1_RSA(handle, static_cast<RSA *>(key.handle()));
|
||||||
|
break;
|
||||||
|
case QSsl::Dsa:
|
||||||
|
q_EVP_PKEY_set1_DSA(handle, static_cast<DSA *>(key.handle()));
|
||||||
|
break;
|
||||||
|
case QSsl::Dh:
|
||||||
|
q_EVP_PKEY_set1_DH(handle, static_cast<DH *>(key.handle()));
|
||||||
|
break;
|
||||||
|
#ifndef OPENSSL_NO_EC
|
||||||
|
case QSsl::Ec:
|
||||||
|
q_EVP_PKEY_set1_EC_KEY(handle, static_cast<EC_KEY *>(key.handle()));
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto cleanup = qScopeGuard([origin, handle] {
|
||||||
|
q_EVP_PKEY_free(origin);
|
||||||
|
q_EVP_PKEY_free(handle);
|
||||||
|
});
|
||||||
|
|
||||||
QVERIFY(!key.isNull());
|
QVERIFY(!key.isNull());
|
||||||
QCOMPARE(key.algorithm(), algorithm);
|
QCOMPARE(key.algorithm(), algorithm);
|
||||||
QCOMPARE(key.type(), type);
|
QCOMPARE(key.type(), type);
|
||||||
QCOMPARE(key.length(), length);
|
QCOMPARE(key.length(), length);
|
||||||
|
QCOMPARE(q_EVP_PKEY_cmp(origin, handle), 1);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user