From f5ac099e948ea354deac75ff9fa09d51453476e1 Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Wed, 12 May 2021 08:41:34 +0200 Subject: [PATCH] Adaptions to stay OpenSSL 3.0 compatible --- lib/pkcs11.cpp | 9 +++------ lib/pki_evp.cpp | 8 ++------ lib/pki_key.cpp | 14 +++++++------- lib/pki_scard.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/lib/pkcs11.cpp b/lib/pkcs11.cpp index e7e17089..22e7f012 100644 --- a/lib/pkcs11.cpp +++ b/lib/pkcs11.cpp @@ -840,8 +840,7 @@ EVP_PKEY *pkcs11::getPrivateKey(EVP_PKEY *pub, CK_OBJECT_HANDLE obj) switch (EVP_PKEY_type(keytype)) { case EVP_PKEY_RSA: - rsa = EVP_PKEY_get0_RSA(pub); - rsa = RSAPublicKey_dup(rsa); + rsa = RSAPublicKey_dup(EVP_PKEY_get0_RSA(pub)); openssl_error(); if (!rsa_meth) { #if OPENSSL_VERSION_NUMBER >= 0x1010000L @@ -865,8 +864,7 @@ EVP_PKEY *pkcs11::getPrivateKey(EVP_PKEY *pub, CK_OBJECT_HANDLE obj) EVP_PKEY_assign_RSA(evp, rsa); break; case EVP_PKEY_DSA: - dsa = EVP_PKEY_get0_DSA(pub); - dsa = DSAparams_dup(dsa); + dsa = DSAparams_dup(EVP_PKEY_get0_DSA(pub)); openssl_error(); if (!dsa_meth) { #if OPENSSL_VERSION_NUMBER >= 0x10100000L @@ -889,8 +887,7 @@ EVP_PKEY *pkcs11::getPrivateKey(EVP_PKEY *pub, CK_OBJECT_HANDLE obj) break; #if !defined(OPENSSL_NO_EC) && OPENSSL_VERSION_NUMBER >= 0x10100000L case EVP_PKEY_EC: - ec = EVP_PKEY_get0_EC_KEY(pub); - ec = EC_KEY_dup(ec); + ec = EC_KEY_dup(EVP_PKEY_get0_EC_KEY(pub)); openssl_error(); if (!ec_key_meth) { ec_key_meth = setup_ec_key_meth(); diff --git a/lib/pki_evp.cpp b/lib/pki_evp.cpp index 5b959ddc..d2974d6f 100644 --- a/lib/pki_evp.cpp +++ b/lib/pki_evp.cpp @@ -282,8 +282,8 @@ void pki_evp::fromPEMbyteArray(const QByteArray &ba, const QString &name) static void search_ec_oid(EVP_PKEY *pkey) { #ifndef OPENSSL_NO_EC - EC_KEY *ec; EC_GROUP *builtin; + const EC_KEY *ec; const EC_GROUP *ec_group; int keytype = EVP_PKEY_id(pkey); @@ -620,10 +620,6 @@ EVP_PKEY *pki_evp::legacyDecryptKey(QByteArray &myencKey, EVP_CIPHER_CTX_free(ctx); pki_openssl_error(); - if (EVP_PKEY_type(getKeyType()) == EVP_PKEY_RSA) { - RSA *rsa = EVP_PKEY_get0_RSA(tmpkey); - RSA_blinding_on(rsa, NULL); - } myencKey.fill(0); return tmpkey; } @@ -930,7 +926,7 @@ bool pki_evp::verify_priv(EVP_PKEY *pkey) const EVP_MD_CTX_free(ctx); #endif if (EVP_PKEY_id(pkey) == EVP_PKEY_RSA && EVP_PKEY_isPrivKey(pkey)) { - RSA *rsa = EVP_PKEY_get0_RSA(pkey); + const RSA *rsa = EVP_PKEY_get0_RSA(pkey); if (RSA_check_key(rsa) != 1) verify = false; } diff --git a/lib/pki_key.cpp b/lib/pki_key.cpp index 1201433b..cce08d8a 100644 --- a/lib/pki_key.cpp +++ b/lib/pki_key.cpp @@ -197,7 +197,7 @@ QString pki_key::length() const if (EVP_PKEY_id(key) == EVP_PKEY_DSA) { const BIGNUM *p = NULL; - DSA *dsa = EVP_PKEY_get0_DSA(key); + const DSA *dsa = EVP_PKEY_get0_DSA(key); if (dsa) DSA_get0_pqg(dsa, &p, NULL, NULL); dsa_unset = p == NULL; @@ -299,7 +299,7 @@ QString pki_key::modulus() const if (getKeyType() == EVP_PKEY_RSA) { const BIGNUM *n = NULL; - RSA *rsa = EVP_PKEY_get0_RSA(key); + const RSA *rsa = EVP_PKEY_get0_RSA(key); RSA_get0_key(rsa, &n, NULL, NULL); return BN2QString(n); } @@ -310,7 +310,7 @@ QString pki_key::pubEx() const { if (getKeyType() == EVP_PKEY_RSA) { const BIGNUM *e = NULL; - RSA *rsa = EVP_PKEY_get0_RSA(key); + const RSA *rsa = EVP_PKEY_get0_RSA(key); RSA_get0_key(rsa, NULL, &e, NULL); return BN2QString(e); } @@ -321,7 +321,7 @@ QString pki_key::subprime() const { if (getKeyType() == EVP_PKEY_DSA) { const BIGNUM *q = NULL; - DSA *dsa = EVP_PKEY_get0_DSA(key); + const DSA *dsa = EVP_PKEY_get0_DSA(key); if (dsa) DSA_get0_pqg(dsa, NULL, &q, NULL); return BN2QString(q); @@ -333,7 +333,7 @@ QString pki_key::pubkey() const { if (getKeyType() == EVP_PKEY_DSA) { const BIGNUM *pubkey = NULL; - DSA *dsa = EVP_PKEY_get0_DSA(key); + const DSA *dsa = EVP_PKEY_get0_DSA(key); if (dsa) DSA_get0_key(dsa, &pubkey, NULL); return BN2QString(pubkey); @@ -766,7 +766,7 @@ QByteArray pki_key::SSH2publicQByteArray(bool raw) const txt = "ssh-rsa"; ssh_key_QBA2data(txt, &data); { - RSA *rsa = EVP_PKEY_get0_RSA(key); + const RSA *rsa = EVP_PKEY_get0_RSA(key); const BIGNUM *n, *e; RSA_get0_key(rsa, &n, &e, NULL); ssh_key_bn2data(e, &data); @@ -777,7 +777,7 @@ QByteArray pki_key::SSH2publicQByteArray(bool raw) const txt = "ssh-dss"; ssh_key_QBA2data(txt, &data); { - DSA *dsa = EVP_PKEY_get0_DSA(key); + const DSA *dsa = EVP_PKEY_get0_DSA(key); const BIGNUM *p, *q, *g, *pubkey; DSA_get0_pqg(dsa, &p, &q, &g); DSA_get0_key(dsa, &pubkey, NULL); diff --git a/lib/pki_scard.cpp b/lib/pki_scard.cpp index 33751d41..89d8d3a1 100644 --- a/lib/pki_scard.cpp +++ b/lib/pki_scard.cpp @@ -293,10 +293,10 @@ void pki_scard::deleteFromToken() pk11_attlist pki_scard::objectAttributesNoId(EVP_PKEY *pk, bool priv) const { QByteArray ba; - RSA *rsa; - DSA *dsa; + const RSA *rsa; + const DSA *dsa; #ifndef OPENSSL_NO_EC - EC_KEY *ec; + const EC_KEY *ec; #endif const BIGNUM *n = NULL; const BIGNUM *e = NULL; @@ -401,10 +401,10 @@ int pki_scard::renameOnToken(const slotid &slot, const QString &name) void pki_scard::store_token(const slotid &slot, EVP_PKEY *pkey) { QByteArray ba; - RSA *rsa; - DSA *dsa; + const RSA *rsa; + const DSA *dsa; #ifndef OPENSSL_NO_EC - EC_KEY *ec; + const EC_KEY *ec; #endif pk11_attlist pub_atts; pk11_attlist priv_atts;