Ticket #58218: patch-support-openssl11.diff
File patch-support-openssl11.diff, 16.0 KB (added by RJVB (René Bertin), 6 years ago) |
---|
-
src/network/ssl/qsslcertificate.cpp
Description: Compile with openssl-1.1.0 * Most changes are related to openssl structures are now opaque. * The network/ssl threading setup has been disabled because the old openssl threading model has been removed and is apparently no longer needed. * A number of new functions had to be imported (see changes to src/network/ssl/qsslsocket_openssl_symbols.cpp) Author: Gert Wollny <gw.fossdev@gmail.com> Last-Update: 2016-06-28 Bug-Debian: http://bugs.debian.org/828522 diff --git src/network/ssl/qsslcertificate.cpp src/network/ssl/qsslcertificate.cpp index 0f2314e2cf78a9a1646a1eb928d7c2f4ee175219..96f6de4324af51e97d0338bdd4a8fff7d3e81e1d 100644
void QSslCertificate::clear() 259 259 QByteArray QSslCertificate::version() const 260 260 { 261 261 QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); 262 if (d->versionString.isEmpty() && d->x509) 262 if (d->versionString.isEmpty() && d->x509) { 263 263 d->versionString = 264 QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->version)) + 1);265 264 QByteArray::number(qlonglong(q_X509_get_version(d->x509)) + 1); 265 } 266 266 return d->versionString; 267 267 } 268 268 … … QByteArray QSslCertificate::serialNumber() const 276 276 { 277 277 QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); 278 278 if (d->serialNumberString.isEmpty() && d->x509) { 279 ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber;279 ASN1_INTEGER *serialNumber = q_X509_get_serialNumber(d->x509); 280 280 // if we cannot convert to a long, just output the hexadecimal number 281 281 if (serialNumber->length > 4) { 282 282 QByteArray hexString; … … QSslKey QSslCertificate::publicKey() const 489 489 QSslKey key; 490 490 491 491 key.d->type = QSsl::PublicKey; 492 #if OPENSSL_VERSION_NUMBER < 0x10100000L 492 493 X509_PUBKEY *xkey = d->x509->cert_info->key; 494 #else 495 X509_PUBKEY *xkey = q_X509_get_X509_PUBKEY(d->x509); 496 #endif 493 497 EVP_PKEY *pkey = q_X509_PUBKEY_get(xkey); 494 498 Q_ASSERT(pkey); 495 499 496 if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA) { 500 int key_id; 501 #if OPENSSL_VERSION_NUMBER < 0x10100000L 502 key_id = q_EVP_PKEY_type(pkey->type); 503 #else 504 key_id = q_EVP_PKEY_base_id(pkey); 505 #endif 506 if (key_id == EVP_PKEY_RSA) { 497 507 key.d->rsa = q_EVP_PKEY_get1_RSA(pkey); 498 508 key.d->algorithm = QSsl::Rsa; 499 509 key.d->isNull = false; 500 } else if ( q_EVP_PKEY_type(pkey->type)== EVP_PKEY_DSA) {510 } else if (key_id == EVP_PKEY_DSA) { 501 511 key.d->dsa = q_EVP_PKEY_get1_DSA(pkey); 502 512 key.d->algorithm = QSsl::Dsa; 503 513 key.d->isNull = false; 504 } else if ( q_EVP_PKEY_type(pkey->type)== EVP_PKEY_DH) {514 } else if (key_id == EVP_PKEY_DH) { 505 515 // DH unsupported 506 516 } else { 507 517 // error? 508 518 } 509 510 519 q_EVP_PKEY_free(pkey); 511 520 return key; 512 521 } … … static QMap<QString, QString> _q_mapFromX509Name(X509_NAME *name) 687 696 unsigned char *data = 0; 688 697 int size = q_ASN1_STRING_to_UTF8(&data, q_X509_NAME_ENTRY_get_data(e)); 689 698 info[QString::fromUtf8(obj)] = QString::fromUtf8((char*)data, size); 690 q_ CRYPTO_free(data);699 q_OPENSSL_free(data); 691 700 } 692 701 return info; 693 702 } -
src/network/ssl/qsslkey.cpp
diff --git src/network/ssl/qsslkey.cpp src/network/ssl/qsslkey.cpp index 437a177b97f6794f15c630b5edd75627fc9abe6d..7375320603b5738562b65052cbf10f89885afebb 100644
int QSslKey::length() const 321 321 { 322 322 if (d->isNull) 323 323 return -1; 324 #if OPENSSL_VERSION_NUMBER < 0x10100000L 324 325 return (d->algorithm == QSsl::Rsa) 325 326 ? q_BN_num_bits(d->rsa->n) : q_BN_num_bits(d->dsa->p); 327 #else 328 if (d->algorithm == QSsl::Rsa) { 329 return q_RSA_bits(d->rsa); 330 }else{ 331 const BIGNUM *p = NULL; 332 q_DSA_get0_pqg(d->dsa, &p, NULL, NULL); 333 return q_BN_num_bits(p); 334 } 335 #endif 336 326 337 } 327 338 328 339 /*! -
src/network/ssl/qsslsocket_openssl.cpp
diff --git src/network/ssl/qsslsocket_openssl.cpp src/network/ssl/qsslsocket_openssl.cpp index ce98494521b7e245e5aacf5693cbc5b4872d65f8..c1ec979d8c902b2535114f196caa6e38d0dcc2cf 100644
bool QSslSocketPrivate::s_libraryLoaded = false; 93 93 bool QSslSocketPrivate::s_loadedCiphersAndCerts = false; 94 94 bool QSslSocketPrivate::s_loadRootCertsOnDemand = false; 95 95 96 #if OPENSSL_VERSION_NUMBER < 0x10100000L 96 97 /* \internal 97 98 98 99 From OpenSSL's thread(3) manual page: … … static unsigned long id_function() 174 175 } 175 176 } // extern "C" 176 177 178 #endif //OPENSSL_VERSION_NUMBER >= 0x10100000L 179 177 180 QSslSocketBackendPrivate::QSslSocketBackendPrivate() 178 181 : ssl(0), 179 182 ctx(0), … … QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(SSL_CIPHER *ciph 222 225 ciph.d->encryptionMethod = descriptionList.at(4).mid(4); 223 226 ciph.d->exportable = (descriptionList.size() > 6 && descriptionList.at(6) == QLatin1String("export")); 224 227 228 #if OPENSSL_VERSION_NUMBER < 0x10100000L 225 229 ciph.d->bits = cipher->strength_bits; 226 230 ciph.d->supportedBits = cipher->alg_bits; 227 231 #else 232 ciph.d->bits = q_SSL_CIPHER_get_bits(cipher, &ciph.d->supportedBits); 233 #endif 228 234 } 229 235 return ciph; 230 236 } … … init_context: 363 369 // 364 370 // See also: QSslContext::fromConfiguration() 365 371 if (caCertificate.expiryDate() >= QDateTime::currentDateTime()) { 366 q_X509_STORE_add_cert(ctx->cert_store, (X509 *)caCertificate.handle());372 q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(ctx), (X509 *)caCertificate.handle()); 367 373 } 368 374 } 369 375 … … void QSslSocketBackendPrivate::destroySslContext() 500 506 */ 501 507 void QSslSocketPrivate::deinitialize() 502 508 { 509 #if OPENSSL_VERSION_NUMBER < 0x10100000L 503 510 q_CRYPTO_set_id_callback(0); 504 511 q_CRYPTO_set_locking_callback(0); 512 #endif 505 513 } 506 514 507 515 /*! … … bool QSslSocketPrivate::ensureLibraryLoaded() 522 530 return false; 523 531 524 532 // Check if the library itself needs to be initialized. 533 #if OPENSSL_VERSION_NUMBER < 0x10100000L 525 534 QMutexLocker locker(openssl_locks()->initLock()); 535 #endif 526 536 if (!s_libraryLoaded) { 527 537 s_libraryLoaded = true; 528 538 529 539 // Initialize OpenSSL. 540 #if OPENSSL_VERSION_NUMBER < 0x10100000L 530 541 q_CRYPTO_set_id_callback(id_function); 531 542 q_CRYPTO_set_locking_callback(locking_function); 543 #endif 532 544 if (q_SSL_library_init() != 1) 533 545 return false; 534 546 q_SSL_load_error_strings(); … … bool QSslSocketPrivate::ensureLibraryLoaded() 567 579 568 580 void QSslSocketPrivate::ensureCiphersAndCertsLoaded() 569 581 { 570 QMutexLocker locker(openssl_locks()->initLock()); 582 #if OPENSSL_VERSION_NUMBER < 0x10100000L 583 QMutexLocker locker(openssl_locks()->initLock()); 584 #endif 571 585 if (s_loadedCiphersAndCerts) 572 586 return; 573 587 s_loadedCiphersAndCerts = true; … … void QSslSocketPrivate::resetDefaultCiphers() 659 673 STACK_OF(SSL_CIPHER) *supportedCiphers = q_SSL_get_ciphers(mySsl); 660 674 for (int i = 0; i < q_sk_SSL_CIPHER_num(supportedCiphers); ++i) { 661 675 if (SSL_CIPHER *cipher = q_sk_SSL_CIPHER_value(supportedCiphers, i)) { 662 if (cipher->valid) { 676 677 #if OPENSSL_VERSION_NUMBER < 0x10100000L 678 if (cipher->valid) { 679 #endif 663 680 QSslCipher ciph = QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(cipher); 664 681 if (!ciph.isNull()) { 665 682 if (!ciph.name().toLower().startsWith(QLatin1String("adh"))) 666 683 ciphers << ciph; 667 684 } 685 #if OPENSSL_VERSION_NUMBER < 0x10100000L 668 686 } 687 #endif 669 688 } 670 689 } 671 690 -
src/network/ssl/qsslsocket_openssl_symbols.cpp
diff --git src/network/ssl/qsslsocket_openssl_symbols.cpp src/network/ssl/qsslsocket_openssl_symbols.cpp index 3ee710605ce48103d78adbebda7ca888cc57ce61..24d25ffe65218db2191abe585ee95b4a8faf1500 100644
DEFINEFUNC(int, ASN1_STRING_length, ASN1_STRING *a, a, return 0, return) 111 111 DEFINEFUNC2(int, ASN1_STRING_to_UTF8, unsigned char **a, a, ASN1_STRING *b, b, return 0, return); 112 112 DEFINEFUNC4(long, BIO_ctrl, BIO *a, a, int b, b, long c, c, void *d, d, return -1, return) 113 113 DEFINEFUNC(int, BIO_free, BIO *a, a, return 0, return) 114 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 115 DEFINEFUNC(BIO *, BIO_new, const BIO_METHOD *a, a, return 0, return) 116 #else 114 117 DEFINEFUNC(BIO *, BIO_new, BIO_METHOD *a, a, return 0, return) 118 #endif 115 119 DEFINEFUNC2(BIO *, BIO_new_mem_buf, void *a, a, int b, b, return 0, return) 116 120 DEFINEFUNC3(int, BIO_read, BIO *a, a, void *b, b, int c, c, return -1, return) 121 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 122 DEFINEFUNC(const BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return) 123 #else 117 124 DEFINEFUNC(BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return) 125 #endif 118 126 DEFINEFUNC3(int, BIO_write, BIO *a, a, const void *b, b, int c, c, return -1, return) 119 127 DEFINEFUNC(int, BN_num_bits, const BIGNUM *a, a, return 0, return) 120 128 DEFINEFUNC(int, CRYPTO_num_locks, DUMMYARG, DUMMYARG, return 0, return) 121 129 DEFINEFUNC(void, CRYPTO_set_locking_callback, void (*a)(int, int, const char *, int), a, return, DUMMYARG) 122 130 DEFINEFUNC(void, CRYPTO_set_id_callback, unsigned long (*a)(), a, return, DUMMYARG) 123 DEFINEFUNC(void, CRYPTO_free, void *a, a, return, DUMMYARG)131 DEFINEFUNC(void, OPENSSL_free, void *a, a, return, DUMMYARG) 124 132 DEFINEFUNC(void, DSA_free, DSA *a, a, return, DUMMYARG) 125 133 #if OPENSSL_VERSION_NUMBER < 0x00908000L 126 134 DEFINEFUNC3(X509 *, d2i_X509, X509 **a, a, unsigned char **b, b, long c, c, return 0, return) … … DEFINEFUNC(void, OPENSSL_add_all_algorithms_noconf, void, DUMMYARG, return, DUMM 286 294 DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG) 287 295 DEFINEFUNC3(int, SSL_CTX_load_verify_locations, SSL_CTX *ctx, ctx, const char *CAfile, CAfile, const char *CApath, CApath, return 0, return) 288 296 DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return) 297 DEFINEFUNC(X509_STORE *, SSL_CTX_get_cert_store, const SSL_CTX *ctx, ctx, return 0, return) 298 299 DEFINEFUNC(ASN1_INTEGER *, X509_get_serialNumber, X509 *x, x, return 0, return) 300 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 301 DEFINEFUNC(int, EVP_PKEY_id, const EVP_PKEY *pkey, pkey, return 0, return) 302 DEFINEFUNC(int, EVP_PKEY_base_id, const EVP_PKEY *pkey, pkey, return 0, return) 303 DEFINEFUNC2(int, SSL_CIPHER_get_bits, const SSL_CIPHER *cipher, cipher, int *alg_bits, alg_bits, return 0, return) 304 DEFINEFUNC2(long, SSL_CTX_set_options, SSL_CTX *ctx, ctx, long options, options, return 0, return) 305 DEFINEFUNC(long, X509_get_version, X509 *x, x, return 0, return) 306 DEFINEFUNC(X509_PUBKEY *, X509_get_X509_PUBKEY, X509 *x, x, return 0, return) 307 DEFINEFUNC(int, RSA_bits, const RSA *rsa, rsa, return 0, return) 308 DEFINEFUNC(int, DSA_security_bits, const DSA *dsa, dsa, return 0, return) 309 DEFINEFUNC(ASN1_TIME *, X509_get_notAfter, X509 *x, x, return 0, return) 310 DEFINEFUNC(ASN1_TIME *, X509_get_notBefore, X509 *x, x, return 0, return) 311 DEFINEFUNC4(void, DSA_get0_pqg, const DSA *d, d, const BIGNUM **p, p, const BIGNUM **q, q, const BIGNUM **g, g, return, return) 312 #endif 289 313 290 314 #ifdef Q_OS_SYMBIAN 291 315 #define RESOLVEFUNC(func, ordinal, lib) \ … … bool q_resolveOpenSslSymbols() 797 821 RESOLVEFUNC(SSL_CTX_use_PrivateKey) 798 822 RESOLVEFUNC(SSL_CTX_use_RSAPrivateKey) 799 823 RESOLVEFUNC(SSL_CTX_use_PrivateKey_file) 824 RESOLVEFUNC(SSL_CTX_get_cert_store) 800 825 RESOLVEFUNC(SSL_accept) 801 826 RESOLVEFUNC(SSL_clear) 802 827 RESOLVEFUNC(SSL_connect) … … bool q_resolveOpenSslSymbols() 819 844 RESOLVEFUNC(SSL_set_connect_state) 820 845 RESOLVEFUNC(SSL_shutdown) 821 846 RESOLVEFUNC(SSL_write) 847 848 RESOLVEFUNC(X509_get_serialNumber) 849 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 850 RESOLVEFUNC(SSL_CTX_ctrl) 851 RESOLVEFUNC(EVP_PKEY_id) 852 RESOLVEFUNC(EVP_PKEY_base_id) 853 RESOLVEFUNC(SSL_CIPHER_get_bits) 854 RESOLVEFUNC(SSL_CTX_set_options) 855 RESOLVEFUNC(X509_get_version) 856 RESOLVEFUNC(X509_get_X509_PUBKEY) 857 RESOLVEFUNC(RSA_bits) 858 RESOLVEFUNC(DSA_security_bits) 859 RESOLVEFUNC(DSA_get0_pqg) 860 RESOLVEFUNC(X509_get_notAfter) 861 RESOLVEFUNC(X509_get_notBefore) 862 #endif 863 822 864 #ifndef OPENSSL_NO_SSL2 823 865 RESOLVEFUNC(SSLv2_client_method) 824 866 #endif -
src/network/ssl/qsslsocket_openssl_symbols_p.h
diff --git src/network/ssl/qsslsocket_openssl_symbols_p.h src/network/ssl/qsslsocket_openssl_symbols_p.h index 2bfe0632edf54d01a8ebc4e4f8e692ca21219599..3054df01e5c03a373b93dd6ae136fc7f8fbe9224 100644
59 59 QT_BEGIN_NAMESPACE 60 60 61 61 #define DUMMYARG 62 #ifndef OPENSSL_NO_SSL2 63 #define OPENSSL_NO_SSL2 1 64 #endif 62 65 63 66 #if !defined QT_LINKED_OPENSSL 64 67 // **************** Shared declarations ****************** … … int q_ASN1_STRING_length(ASN1_STRING *a); 207 210 int q_ASN1_STRING_to_UTF8(unsigned char **a, ASN1_STRING *b); 208 211 long q_BIO_ctrl(BIO *a, int b, long c, void *d); 209 212 int q_BIO_free(BIO *a); 213 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 214 BIO *q_BIO_new(const BIO_METHOD *a); 215 #else 210 216 BIO *q_BIO_new(BIO_METHOD *a); 217 #endif 211 218 BIO *q_BIO_new_mem_buf(void *a, int b); 212 219 int q_BIO_read(BIO *a, void *b, int c); 220 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 221 const BIO_METHOD *q_BIO_s_mem(); 222 #else 213 223 BIO_METHOD *q_BIO_s_mem(); 224 #endif 214 225 int q_BIO_write(BIO *a, const void *b, int c); 215 226 int q_BN_num_bits(const BIGNUM *a); 216 227 int q_CRYPTO_num_locks(); 217 228 void q_CRYPTO_set_locking_callback(void (*a)(int, int, const char *, int)); 218 229 void q_CRYPTO_set_id_callback(unsigned long (*a)()); 219 void q_ CRYPTO_free(void *a);230 void q_OPENSSL_free(void *a); 220 231 void q_DSA_free(DSA *a); 221 232 #if OPENSSL_VERSION_NUMBER >= 0x00908000L 222 233 // 0.9.8 broke SC and BC by changing this function's signature. … … void q_SSL_set_accept_state(SSL *a); 326 337 void q_SSL_set_connect_state(SSL *a); 327 338 int q_SSL_shutdown(SSL *a); 328 339 #if OPENSSL_VERSION_NUMBER >= 0x10000000L 329 const SSL_METHOD *q_SSLv2_client_method();330 340 const SSL_METHOD *q_SSLv3_client_method(); 331 341 const SSL_METHOD *q_SSLv23_client_method(); 332 342 const SSL_METHOD *q_TLSv1_client_method(); … … const SSL_METHOD *q_SSLv3_server_method(); 335 345 const SSL_METHOD *q_SSLv23_server_method(); 336 346 const SSL_METHOD *q_TLSv1_server_method(); 337 347 #else 338 SSL_METHOD *q_SSLv2_client_method();339 348 SSL_METHOD *q_SSLv3_client_method(); 340 349 SSL_METHOD *q_SSLv23_client_method(); 341 350 SSL_METHOD *q_TLSv1_client_method(); … … DSA *q_d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); 399 408 PEM_ASN1_write_bio((int (*)(void*, unsigned char**))q_i2d_DSAPrivateKey,PEM_STRING_DSA,\ 400 409 bp,(char *)x,enc,kstr,klen,cb,u) 401 410 #endif 411 412 X509_STORE * q_SSL_CTX_get_cert_store(const SSL_CTX *ctx); 413 ASN1_INTEGER * q_X509_get_serialNumber(X509 *x); 414 415 #if OPENSSL_VERSION_NUMBER < 0x10100000L 402 416 #define q_SSL_CTX_set_options(ctx,op) q_SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL) 417 #define q_X509_get_version(x) X509_get_version(x) 418 #else 419 int q_EVP_PKEY_id(const EVP_PKEY *pkey); 420 int q_EVP_PKEY_base_id(const EVP_PKEY *pkey); 421 int q_SSL_CIPHER_get_bits(const SSL_CIPHER *cipher, int *alg_bits); 422 long q_SSL_CTX_set_options(SSL_CTX *ctx, long options); 423 long q_X509_get_version(X509 *x); 424 X509_PUBKEY * q_X509_get_X509_PUBKEY(X509 *x); 425 int q_RSA_bits(const RSA *rsa); 426 int q_DSA_security_bits(const DSA *dsa); 427 void q_DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g); 428 #endif 429 403 430 #define q_SKM_sk_num(type, st) ((int (*)(const STACK_OF(type) *))q_sk_num)(st) 404 431 #define q_SKM_sk_value(type, st,i) ((type * (*)(const STACK_OF(type) *, int))q_sk_value)(st, i) 405 432 #define q_sk_GENERAL_NAME_num(st) q_SKM_sk_num(GENERAL_NAME, (st)) … … DSA *q_d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); 410 437 #define q_sk_SSL_CIPHER_value(st, i) q_SKM_sk_value(SSL_CIPHER, (st), (i)) 411 438 #define q_SSL_CTX_add_extra_chain_cert(ctx,x509) \ 412 439 q_SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509) 440 441 #if OPENSSL_VERSION_NUMBER < 0x10100000L 413 442 #define q_X509_get_notAfter(x) X509_get_notAfter(x) 414 443 #define q_X509_get_notBefore(x) X509_get_notBefore(x) 444 #else 445 ASN1_TIME *q_X509_get_notAfter(X509 *x); 446 ASN1_TIME *q_X509_get_notBefore(X509 *x); 447 #endif 448 415 449 #define q_EVP_PKEY_assign_RSA(pkey,rsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\ 416 450 (char *)(rsa)) 417 451 #define q_EVP_PKEY_assign_DSA(pkey,dsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\