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)

Patch from @RVJB, based on unix patches - minor mod by ken -- builds against openssl 1.1.1

  • src/network/ssl/qsslcertificate.cpp

    diff --git src/network/ssl/qsslcertificate.cpp src/network/ssl/qsslcertificate.cpp
    index 0f2314e2..9e22cbe0 100644
    void QSslCertificate::clear() 
    259259QByteArray QSslCertificate::version() const
    260260{
    261261    QMutexLocker lock(QMutexPool::globalInstanceGet(d.data()));
    262     if (d->versionString.isEmpty() && d->x509)
     262    if (d->versionString.isEmpty() && d->x509) {
    263263        d->versionString =
     264#if OPENSSL_VERSION_NUMBER < 0x10100000L
    264265            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    }
    266270    return d->versionString;
    267271}
    268272
    QByteArray QSslCertificate::serialNumber() const 
    276280{
    277281    QMutexLocker lock(QMutexPool::globalInstanceGet(d.data()));
    278282    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);
    280284        // if we cannot convert to a long, just output the hexadecimal number
    281285        if (serialNumber->length > 4) {
    282286            QByteArray hexString;
    QSslKey QSslCertificate::publicKey() const 
    489493    QSslKey key;
    490494
    491495    key.d->type = QSsl::PublicKey;
     496#if OPENSSL_VERSION_NUMBER < 0x10100000L
    492497    X509_PUBKEY *xkey = d->x509->cert_info->key;
     498#else
     499    X509_PUBKEY *xkey = q_X509_get_X509_PUBKEY(d->x509);
     500#endif
    493501    EVP_PKEY *pkey = q_X509_PUBKEY_get(xkey);
    494502    Q_ASSERT(pkey);
    495503
    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) {
    497511        key.d->rsa = q_EVP_PKEY_get1_RSA(pkey);
    498512        key.d->algorithm = QSsl::Rsa;
    499513        key.d->isNull = false;
    500     } else if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_DSA) {
     514    } else if (key_id == EVP_PKEY_DSA) {
    501515        key.d->dsa = q_EVP_PKEY_get1_DSA(pkey);
    502516        key.d->algorithm = QSsl::Dsa;
    503517        key.d->isNull = false;
    504     } else if (q_EVP_PKEY_type(pkey->type) == EVP_PKEY_DH) {
     518    } else if (key_id == EVP_PKEY_DH) {
    505519        // DH unsupported
    506520    } else {
    507521        // error?
    508522    }
    509 
    510523    q_EVP_PKEY_free(pkey);
    511524    return key;
    512525}
    static QMap<QString, QString> _q_mapFromX509Name(X509_NAME *name) 
    687700        unsigned char *data = 0;
    688701        int size = q_ASN1_STRING_to_UTF8(&data, q_X509_NAME_ENTRY_get_data(e));
    689702        info[QString::fromUtf8(obj)] = QString::fromUtf8((char*)data, size);
    690         q_CRYPTO_free(data);
     703        q_OPENSSL_free(data);
    691704    }
    692705    return info;
    693706}
  • 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 
    321321{
    322322    if (d->isNull)
    323323        return -1;
     324#if OPENSSL_VERSION_NUMBER < 0x10100000L
    324325    return (d->algorithm == QSsl::Rsa)
    325326           ? 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
    326337}
    327338
    328339/*!
  • 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; 
    9393bool QSslSocketPrivate::s_loadedCiphersAndCerts = false;
    9494bool QSslSocketPrivate::s_loadRootCertsOnDemand = false;
    9595
     96#if OPENSSL_VERSION_NUMBER < 0x10100000L
    9697/* \internal
    9798
    9899    From OpenSSL's thread(3) manual page:
    static unsigned long id_function() 
    174175}
    175176} // extern "C"
    176177
     178#endif //OPENSSL_VERSION_NUMBER >= 0x10100000L
     179
    177180QSslSocketBackendPrivate::QSslSocketBackendPrivate()
    178181    : ssl(0),
    179182      ctx(0),
    QSslCipher QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(SSL_CIPHER *ciph 
    222225            ciph.d->encryptionMethod = descriptionList.at(4).mid(4);
    223226        ciph.d->exportable = (descriptionList.size() > 6 && descriptionList.at(6) == QLatin1String("export"));
    224227
     228#if OPENSSL_VERSION_NUMBER < 0x10100000L
    225229        ciph.d->bits = cipher->strength_bits;
    226230        ciph.d->supportedBits = cipher->alg_bits;
    227 
     231#else
     232        ciph.d->bits = q_SSL_CIPHER_get_bits(cipher, &ciph.d->supportedBits);
     233#endif
    228234    }
    229235    return ciph;
    230236}
    init_context: 
    367373        //
    368374        // See also: QSslContext::fromConfiguration()
    369375        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());
    371377        }
    372378    }
    373379
    void QSslSocketBackendPrivate::destroySslContext() 
    504510*/
    505511void QSslSocketPrivate::deinitialize()
    506512{
     513#if OPENSSL_VERSION_NUMBER < 0x10100000L
    507514    q_CRYPTO_set_id_callback(0);
    508515    q_CRYPTO_set_locking_callback(0);
     516#endif
    509517}
    510518
    511519/*!
    bool QSslSocketPrivate::ensureLibraryLoaded() 
    526534        return false;
    527535
    528536    // Check if the library itself needs to be initialized.
     537#if OPENSSL_VERSION_NUMBER < 0x10100000L
    529538    QMutexLocker locker(openssl_locks()->initLock());
     539#endif
    530540    if (!s_libraryLoaded) {
    531541        s_libraryLoaded = true;
    532542
    533543        // Initialize OpenSSL.
     544#if OPENSSL_VERSION_NUMBER < 0x10100000L
    534545        q_CRYPTO_set_id_callback(id_function);
    535546        q_CRYPTO_set_locking_callback(locking_function);
     547#endif
    536548        if (q_SSL_library_init() != 1)
    537549            return false;
    538550        q_SSL_load_error_strings();
    bool QSslSocketPrivate::ensureLibraryLoaded() 
    571583
    572584void QSslSocketPrivate::ensureCiphersAndCertsLoaded()
    573585{
    574     QMutexLocker locker(openssl_locks()->initLock());
     586#if OPENSSL_VERSION_NUMBER < 0x10100000L
     587        QMutexLocker locker(openssl_locks()->initLock());
     588#endif
    575589    if (s_loadedCiphersAndCerts)
    576590        return;
    577591    s_loadedCiphersAndCerts = true;
    void QSslSocketPrivate::resetDefaultCiphers() 
    663677    STACK_OF(SSL_CIPHER) *supportedCiphers = q_SSL_get_ciphers(mySsl);
    664678    for (int i = 0; i < q_sk_SSL_CIPHER_num(supportedCiphers); ++i) {
    665679        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
    667684                QSslCipher ciph = QSslSocketBackendPrivate::QSslCipher_from_SSL_CIPHER(cipher);
    668685                if (!ciph.isNull()) {
    669686                    if (!ciph.name().toLower().startsWith(QLatin1String("adh")))
    670687                        ciphers << ciph;
    671688                }
     689#if OPENSSL_VERSION_NUMBER < 0x10100000L
    672690            }
     691#endif
    673692        }
    674693    }
    675694
  • 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
     
    8484#include <openssl/tls1.h>
    8585#endif
    8686
     87#if OPENSSL_VERSION_NUMBER >= 0x10100000L
     88#define OPENSSL_NO_SSL2
     89#endif
     90
    8791#if OPENSSL_VERSION_NUMBER >= 0x10000000L
    8892typedef _STACK STACK;
    8993#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) 
    111111DEFINEFUNC2(int, ASN1_STRING_to_UTF8, unsigned char **a, a, ASN1_STRING *b, b, return 0, return);
    112112DEFINEFUNC4(long, BIO_ctrl, BIO *a, a, int b, b, long c, c, void *d, d, return -1, return)
    113113DEFINEFUNC(int, BIO_free, BIO *a, a, return 0, return)
     114#if OPENSSL_VERSION_NUMBER >= 0x10100000L
     115DEFINEFUNC(BIO *, BIO_new, const BIO_METHOD *a, a, return 0, return)
     116#else
    114117DEFINEFUNC(BIO *, BIO_new, BIO_METHOD *a, a, return 0, return)
     118#endif
    115119DEFINEFUNC2(BIO *, BIO_new_mem_buf, void *a, a, int b, b, return 0, return)
    116120DEFINEFUNC3(int, BIO_read, BIO *a, a, void *b, b, int c, c, return -1, return)
     121#if OPENSSL_VERSION_NUMBER >= 0x10100000L
     122DEFINEFUNC(const BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return)
     123#else
    117124DEFINEFUNC(BIO_METHOD *, BIO_s_mem, void, DUMMYARG, return 0, return)
     125#endif
    118126DEFINEFUNC3(int, BIO_write, BIO *a, a, const void *b, b, int c, c, return -1, return)
    119127DEFINEFUNC(int, BN_num_bits, const BIGNUM *a, a, return 0, return)
    120128DEFINEFUNC(int, CRYPTO_num_locks, DUMMYARG, DUMMYARG, return 0, return)
    121129DEFINEFUNC(void, CRYPTO_set_locking_callback, void (*a)(int, int, const char *, int), a, return, DUMMYARG)
    122130DEFINEFUNC(void, CRYPTO_set_id_callback, unsigned long (*a)(), a, return, DUMMYARG)
    123 DEFINEFUNC(void, CRYPTO_free, void *a, a, return, DUMMYARG)
     131DEFINEFUNC(void, OPENSSL_free, void *a, a, return, DUMMYARG)
    124132DEFINEFUNC(void, DSA_free, DSA *a, a, return, DUMMYARG)
    125133#if  OPENSSL_VERSION_NUMBER < 0x00908000L
    126134DEFINEFUNC3(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 
    290298DEFINEFUNC(void, OPENSSL_add_all_algorithms_conf, void, DUMMYARG, return, DUMMYARG)
    291299DEFINEFUNC3(int, SSL_CTX_load_verify_locations, SSL_CTX *ctx, ctx, const char *CAfile, CAfile, const char *CApath, CApath, return 0, return)
    292300DEFINEFUNC(long, SSLeay, void, DUMMYARG, return 0, return)
     301DEFINEFUNC(X509_STORE *, SSL_CTX_get_cert_store, const SSL_CTX *ctx, ctx, return 0, return)
     302
     303DEFINEFUNC(ASN1_INTEGER *, X509_get_serialNumber, X509 *x, x, return 0, return)
     304#if OPENSSL_VERSION_NUMBER >= 0x10100000L
     305DEFINEFUNC(int, EVP_PKEY_id, const EVP_PKEY *pkey, pkey, return 0, return)
     306DEFINEFUNC(int, EVP_PKEY_base_id, const EVP_PKEY *pkey, pkey, return 0, return)
     307DEFINEFUNC2(int, SSL_CIPHER_get_bits, const SSL_CIPHER *cipher, cipher, int *alg_bits, alg_bits, return 0, return)
     308DEFINEFUNC2(long, SSL_CTX_set_options, SSL_CTX *ctx, ctx, long options, options, return 0, return)
     309DEFINEFUNC(long, X509_get_version, X509 *x, x, return 0, return)
     310DEFINEFUNC(X509_PUBKEY *, X509_get_X509_PUBKEY, X509 *x, x, return 0, return)
     311DEFINEFUNC(int, RSA_bits,  const RSA *rsa, rsa, return 0, return)
     312DEFINEFUNC(int, DSA_security_bits, const DSA *dsa, dsa, return 0, return)
     313DEFINEFUNC(ASN1_TIME *, X509_get_notAfter, X509 *x, x, return 0, return)
     314DEFINEFUNC(ASN1_TIME *, X509_get_notBefore, X509 *x, x, return 0, return)
     315DEFINEFUNC4(void, DSA_get0_pqg, const DSA *d, d, const BIGNUM **p, p, const BIGNUM **q, q, const BIGNUM **g, g, return, return)
     316#endif
    293317
    294318#ifdef Q_OS_SYMBIAN
    295319#define RESOLVEFUNC(func, ordinal, lib) \
    bool q_resolveOpenSslSymbols() 
    801825    RESOLVEFUNC(SSL_CTX_use_PrivateKey)
    802826    RESOLVEFUNC(SSL_CTX_use_RSAPrivateKey)
    803827    RESOLVEFUNC(SSL_CTX_use_PrivateKey_file)
     828    RESOLVEFUNC(SSL_CTX_get_cert_store)
    804829    RESOLVEFUNC(SSL_accept)
    805830    RESOLVEFUNC(SSL_clear)
    806831    RESOLVEFUNC(SSL_connect)
    bool q_resolveOpenSslSymbols() 
    823848    RESOLVEFUNC(SSL_set_connect_state)
    824849    RESOLVEFUNC(SSL_shutdown)
    825850    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
    826868#ifndef OPENSSL_NO_SSL2
    827869    RESOLVEFUNC(SSLv2_client_method)
    828870#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
     
    5959QT_BEGIN_NAMESPACE
    6060
    6161#define DUMMYARG
     62#ifndef OPENSSL_NO_SSL2
     63#define OPENSSL_NO_SSL2 1
     64#endif
    6265
    6366#if !defined QT_LINKED_OPENSSL
    6467// **************** Shared declarations ******************
    int q_ASN1_STRING_length(ASN1_STRING *a); 
    207210int q_ASN1_STRING_to_UTF8(unsigned char **a, ASN1_STRING *b);
    208211long q_BIO_ctrl(BIO *a, int b, long c, void *d);
    209212int q_BIO_free(BIO *a);
     213#if OPENSSL_VERSION_NUMBER >= 0x10100000L
     214BIO *q_BIO_new(const BIO_METHOD *a);
     215#else
    210216BIO *q_BIO_new(BIO_METHOD *a);
     217#endif
    211218BIO *q_BIO_new_mem_buf(void *a, int b);
    212219int q_BIO_read(BIO *a, void *b, int c);
     220#if OPENSSL_VERSION_NUMBER >= 0x10100000L
     221const BIO_METHOD *q_BIO_s_mem();
     222#else
    213223BIO_METHOD *q_BIO_s_mem();
     224#endif
    214225int q_BIO_write(BIO *a, const void *b, int c);
    215226int q_BN_num_bits(const BIGNUM *a);
    216227int q_CRYPTO_num_locks();
    217228void q_CRYPTO_set_locking_callback(void (*a)(int, int, const char *, int));
    218229void q_CRYPTO_set_id_callback(unsigned long (*a)());
    219 void q_CRYPTO_free(void *a);
     230void q_OPENSSL_free(void *a);
    220231void q_DSA_free(DSA *a);
    221232#if OPENSSL_VERSION_NUMBER >= 0x00908000L
    222233// 0.9.8 broke SC and BC by changing this function's signature.
    void q_SSL_set_accept_state(SSL *a); 
    326337void q_SSL_set_connect_state(SSL *a);
    327338int q_SSL_shutdown(SSL *a);
    328339#if OPENSSL_VERSION_NUMBER >= 0x10000000L
    329 const SSL_METHOD *q_SSLv2_client_method();
    330340const SSL_METHOD *q_SSLv3_client_method();
    331341const SSL_METHOD *q_SSLv23_client_method();
    332342const SSL_METHOD *q_TLSv1_client_method();
    const SSL_METHOD *q_SSLv3_server_method(); 
    335345const SSL_METHOD *q_SSLv23_server_method();
    336346const SSL_METHOD *q_TLSv1_server_method();
    337347#else
    338 SSL_METHOD *q_SSLv2_client_method();
    339348SSL_METHOD *q_SSLv3_client_method();
    340349SSL_METHOD *q_SSLv23_client_method();
    341350SSL_METHOD *q_TLSv1_client_method();
    DSA *q_d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); 
    399408                PEM_ASN1_write_bio((int (*)(void*, unsigned char**))q_i2d_DSAPrivateKey,PEM_STRING_DSA,\
    400409                        bp,(char *)x,enc,kstr,klen,cb,u)
    401410#endif
     411
     412X509_STORE * q_SSL_CTX_get_cert_store(const SSL_CTX *ctx);
     413ASN1_INTEGER * q_X509_get_serialNumber(X509 *x);
     414
     415#if OPENSSL_VERSION_NUMBER < 0x10100000L
    402416#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
     419int q_EVP_PKEY_id(const EVP_PKEY *pkey);
     420int q_EVP_PKEY_base_id(const EVP_PKEY *pkey);
     421int q_SSL_CIPHER_get_bits(const SSL_CIPHER *cipher, int *alg_bits);
     422long q_SSL_CTX_set_options(SSL_CTX *ctx, long options);
     423long q_X509_get_version(X509 *x);
     424X509_PUBKEY * q_X509_get_X509_PUBKEY(X509 *x);
     425int q_RSA_bits(const RSA *rsa);
     426int q_DSA_security_bits(const DSA *dsa);
     427void q_DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g);
     428#endif
     429
    403430#define q_SKM_sk_num(type, st) ((int (*)(const STACK_OF(type) *))q_sk_num)(st)
    404431#define q_SKM_sk_value(type, st,i) ((type * (*)(const STACK_OF(type) *, int))q_sk_value)(st, i)
    405432#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); 
    410437#define q_sk_SSL_CIPHER_value(st, i) q_SKM_sk_value(SSL_CIPHER, (st), (i))
    411438#define q_SSL_CTX_add_extra_chain_cert(ctx,x509) \
    412439        q_SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
     440
     441#if OPENSSL_VERSION_NUMBER < 0x10100000L
    413442#define q_X509_get_notAfter(x) X509_get_notAfter(x)
    414443#define q_X509_get_notBefore(x) X509_get_notBefore(x)
     444#else
     445ASN1_TIME *q_X509_get_notAfter(X509 *x);
     446ASN1_TIME *q_X509_get_notBefore(X509 *x);
     447#endif
     448
    415449#define q_EVP_PKEY_assign_RSA(pkey,rsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_RSA,\
    416450                                        (char *)(rsa))
    417451#define q_EVP_PKEY_assign_DSA(pkey,dsa) q_EVP_PKEY_assign((pkey),EVP_PKEY_DSA,\