Ticket #58205: patch-ken-rjvb-qt4-openssl111.diff
File patch-ken-rjvb-qt4-openssl111.diff, 15.7 KB (added by kencu (Ken), 5 years ago) |
---|
-
src/network/ssl/qsslcertificate.cpp
diff --git src/network/ssl/qsslcertificate.cpp src/network/ssl/qsslcertificate.cpp index 0f2314e2..9e22cbe0 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 #if OPENSSL_VERSION_NUMBER < 0x10100000L 264 265 QByteArray::number(qlonglong(q_ASN1_INTEGER_get(d->x509->cert_info->version)) + 1); 265 266 #else 267 QByteArray::number(qlonglong(q_X509_get_version(d->x509)) + 1); 268 #endif 269 } 266 270 return d->versionString; 267 271 } 268 272 … … QByteArray QSslCertificate::serialNumber() const 276 280 { 277 281 QMutexLocker lock(QMutexPool::globalInstanceGet(d.data())); 278 282 if (d->serialNumberString.isEmpty() && d->x509) { 279 ASN1_INTEGER *serialNumber = d->x509->cert_info->serialNumber;283 ASN1_INTEGER *serialNumber = q_X509_get_serialNumber(d->x509); 280 284 // if we cannot convert to a long, just output the hexadecimal number 281 285 if (serialNumber->length > 4) { 282 286 QByteArray hexString; … … QSslKey QSslCertificate::publicKey() const 489 493 QSslKey key; 490 494 491 495 key.d->type = QSsl::PublicKey; 496 #if OPENSSL_VERSION_NUMBER < 0x10100000L 492 497 X509_PUBKEY *xkey = d->x509->cert_info->key; 498 #else 499 X509_PUBKEY *xkey = q_X509_get_X509_PUBKEY(d->x509); 500 #endif 493 501 EVP_PKEY *pkey = q_X509_PUBKEY_get(xkey); 494 502 Q_ASSERT(pkey); 495 503 496 if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_RSA) { 504 int key_id; 505 #if OPENSSL_VERSION_NUMBER < 0x10100000L 506 key_id = q_EVP_PKEY_type(pkey->type); 507 #else 508 key_id = q_EVP_PKEY_base_id(pkey); 509 #endif 510 if (key_id == EVP_PKEY_RSA) { 497 511 key.d->rsa = q_EVP_PKEY_get1_RSA(pkey); 498 512 key.d->algorithm = QSsl::Rsa; 499 513 key.d->isNull = false; 500 } else if ( q_EVP_PKEY_type(pkey->type)== EVP_PKEY_DSA) {514 } else if (key_id == EVP_PKEY_DSA) { 501 515 key.d->dsa = q_EVP_PKEY_get1_DSA(pkey); 502 516 key.d->algorithm = QSsl::Dsa; 503 517 key.d->isNull = false; 504 } else if ( q_EVP_PKEY_type(pkey->type)== EVP_PKEY_DH) {518 } else if (key_id == EVP_PKEY_DH) { 505 519 // DH unsupported 506 520 } else { 507 521 // error? 508 522 } 509 510 523 q_EVP_PKEY_free(pkey); 511 524 return key; 512 525 } … … static QMap<QString, QString> _q_mapFromX509Name(X509_NAME *name) 687 700 unsigned char *data = 0; 688 701 int size = q_ASN1_STRING_to_UTF8(&data, q_X509_NAME_ENTRY_get_data(e)); 689 702 info[QString::fromUtf8(obj)] = QString::fromUtf8((char*)data, size); 690 q_ CRYPTO_free(data);703 q_OPENSSL_free(data); 691 704 } 692 705 return info; 693 706 } -
src/network/ssl/qsslkey.cpp
diff --git src/network/ssl/qsslkey.cpp src/network/ssl/qsslkey.cpp index 437a177b..73753206 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 8eba0761..91d06ff0 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: 367 373 // 368 374 // See also: QSslContext::fromConfiguration() 369 375 if (caCertificate.expiryDate() >= QDateTime::currentDateTime()) { 370 q_X509_STORE_add_cert(ctx->cert_store, (X509 *)caCertificate.handle());376 q_X509_STORE_add_cert(q_SSL_CTX_get_cert_store(ctx), (X509 *)caCertificate.handle()); 371 377 } 372 378 } 373 379 … … void QSslSocketBackendPrivate::destroySslContext() 504 510 */ 505 511 void QSslSocketPrivate::deinitialize() 506 512 { 513 #if OPENSSL_VERSION_NUMBER < 0x10100000L 507 514 q_CRYPTO_set_id_callback(0); 508 515 q_CRYPTO_set_locking_callback(0); 516 #endif 509 517 } 510 518 511 519 /*! … … bool QSslSocketPrivate::ensureLibraryLoaded() 526 534 return false; 527 535 528 536 // Check if the library itself needs to be initialized. 537 #if OPENSSL_VERSION_NUMBER < 0x10100000L 529 538 QMutexLocker locker(openssl_locks()->initLock()); 539 #endif 530 540 if (!s_libraryLoaded) { 531 541 s_libraryLoaded = true; 532 542 533 543 // Initialize OpenSSL. 544 #if OPENSSL_VERSION_NUMBER < 0x10100000L 534 545 q_CRYPTO_set_id_callback(id_function); 535 546 q_CRYPTO_set_locking_callback(locking_function); 547 #endif 536 548 if (q_SSL_library_init() != 1) 537 549 return false; 538 550 q_SSL_load_error_strings(); … … bool QSslSocketPrivate::ensureLibraryLoaded() 571 583 572 584 void QSslSocketPrivate::ensureCiphersAndCertsLoaded() 573 585 { 574 QMutexLocker locker(openssl_locks()->initLock()); 586 #if OPENSSL_VERSION_NUMBER < 0x10100000L 587 QMutexLocker locker(openssl_locks()->initLock()); 588 #endif 575 589 if (s_loadedCiphersAndCerts) 576 590 return; 577 591 s_loadedCiphersAndCerts = true; … … void QSslSocketPrivate::resetDefaultCiphers() 663 677 STACK_OF(SSL_CIPHER) *supportedCiphers = q_SSL_get_ciphers(mySsl); 664 678 for (int i = 0; i < q_sk_SSL_CIPHER_num(supportedCiphers); ++i) { 665 679 if (SSL_CIPHER *cipher = q_sk_SSL_CIPHER_value(supportedCiphers, i)) { 666 if (cipher->valid) { 680 681 #if OPENSSL_VERSION_NUMBER < 0x10100000L 682 if (cipher->valid) { 683 #endif 667 684 QSslCipher ciph = QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(cipher); 668 685 if (!ciph.isNull()) { 669 686 if (!ciph.name().toLower().startsWith(QLatin1String("adh"))) 670 687 ciphers << ciph; 671 688 } 689 #if OPENSSL_VERSION_NUMBER < 0x10100000L 672 690 } 691 #endif 673 692 } 674 693 } 675 694 -
src/network/ssl/qsslsocket_openssl_p.h
diff --git src/network/ssl/qsslsocket_openssl_p.h src/network/ssl/qsslsocket_openssl_p.h index 3b266cbf..a0fe2248 100644
84 84 #include <openssl/tls1.h> 85 85 #endif 86 86 87 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 88 #define OPENSSL_NO_SSL2 89 #endif 90 87 91 #if OPENSSL_VERSION_NUMBER >= 0x10000000L 88 92 typedef _STACK STACK; 89 93 #endif -
src/network/ssl/qsslsocket_openssl_symbols.cpp
diff --git src/network/ssl/qsslsocket_openssl_symbols.cpp src/network/ssl/qsslsocket_openssl_symbols.cpp index b20baa27..507fc3e2 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 290 298 DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG) 291 299 DEFINEFUNC3(int, SSL_CTX_load_verify_locations, SSL_CTX *ctx, ctx, const char *CAfile, CAfile, const char *CApath, CApath, return 0, return) 292 300 DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return) 301 DEFINEFUNC(X509_STORE *, SSL_CTX_get_cert_store, const SSL_CTX *ctx, ctx, return 0, return) 302 303 DEFINEFUNC(ASN1_INTEGER *, X509_get_serialNumber, X509 *x, x, return 0, return) 304 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 305 DEFINEFUNC(int, EVP_PKEY_id, const EVP_PKEY *pkey, pkey, return 0, return) 306 DEFINEFUNC(int, EVP_PKEY_base_id, const EVP_PKEY *pkey, pkey, return 0, return) 307 DEFINEFUNC2(int, SSL_CIPHER_get_bits, const SSL_CIPHER *cipher, cipher, int *alg_bits, alg_bits, return 0, return) 308 DEFINEFUNC2(long, SSL_CTX_set_options, SSL_CTX *ctx, ctx, long options, options, return 0, return) 309 DEFINEFUNC(long, X509_get_version, X509 *x, x, return 0, return) 310 DEFINEFUNC(X509_PUBKEY *, X509_get_X509_PUBKEY, X509 *x, x, return 0, return) 311 DEFINEFUNC(int, RSA_bits, const RSA *rsa, rsa, return 0, return) 312 DEFINEFUNC(int, DSA_security_bits, const DSA *dsa, dsa, return 0, return) 313 DEFINEFUNC(ASN1_TIME *, X509_get_notAfter, X509 *x, x, return 0, return) 314 DEFINEFUNC(ASN1_TIME *, X509_get_notBefore, X509 *x, x, return 0, return) 315 DEFINEFUNC4(void, DSA_get0_pqg, const DSA *d, d, const BIGNUM **p, p, const BIGNUM **q, q, const BIGNUM **g, g, return, return) 316 #endif 293 317 294 318 #ifdef Q_OS_SYMBIAN 295 319 #define RESOLVEFUNC(func, ordinal, lib) \ … … bool q_resolveOpenSslSymbols() 801 825 RESOLVEFUNC(SSL_CTX_use_PrivateKey) 802 826 RESOLVEFUNC(SSL_CTX_use_RSAPrivateKey) 803 827 RESOLVEFUNC(SSL_CTX_use_PrivateKey_file) 828 RESOLVEFUNC(SSL_CTX_get_cert_store) 804 829 RESOLVEFUNC(SSL_accept) 805 830 RESOLVEFUNC(SSL_clear) 806 831 RESOLVEFUNC(SSL_connect) … … bool q_resolveOpenSslSymbols() 823 848 RESOLVEFUNC(SSL_set_connect_state) 824 849 RESOLVEFUNC(SSL_shutdown) 825 850 RESOLVEFUNC(SSL_write) 851 852 RESOLVEFUNC(X509_get_serialNumber) 853 #if OPENSSL_VERSION_NUMBER >= 0x10100000L 854 RESOLVEFUNC(SSL_CTX_ctrl) 855 RESOLVEFUNC(EVP_PKEY_id) 856 RESOLVEFUNC(EVP_PKEY_base_id) 857 RESOLVEFUNC(SSL_CIPHER_get_bits) 858 RESOLVEFUNC(SSL_CTX_set_options) 859 RESOLVEFUNC(X509_get_version) 860 RESOLVEFUNC(X509_get_X509_PUBKEY) 861 RESOLVEFUNC(RSA_bits) 862 RESOLVEFUNC(DSA_security_bits) 863 RESOLVEFUNC(DSA_get0_pqg) 864 RESOLVEFUNC(X509_get_notAfter) 865 RESOLVEFUNC(X509_get_notBefore) 866 #endif 867 826 868 #ifndef OPENSSL_NO_SSL2 827 869 RESOLVEFUNC(SSLv2_client_method) 828 870 #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 2bfe0632..3054df01 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,\