#3563: Remove support for OpenSSL < 1.0

This commit is contained in:
Günter Obiltschnig
2022-04-16 08:05:12 +02:00
parent 0af3f699af
commit e99f4fd31a
6 changed files with 21 additions and 29 deletions

View File

@@ -48,6 +48,11 @@
#endif #endif
#if OPENSSL_VERSION_NUMBER < 0x10000000L
#error "OpenSSL version too old. At least OpenSSL 1.0.0 is required."
#endif
enum RSAPaddingMode enum RSAPaddingMode
/// The padding mode used for RSA public key encryption. /// The padding mode used for RSA public key encryption.
{ {

View File

@@ -21,9 +21,7 @@
#include "Poco/StreamCopier.h" #include "Poco/StreamCopier.h"
#include <sstream> #include <sstream>
#include <openssl/evp.h> #include <openssl/evp.h>
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
#include <openssl/bn.h> #include <openssl/bn.h>
#endif
namespace Poco { namespace Poco {
@@ -78,8 +76,8 @@ ECKeyImpl::ECKeyImpl(int curve):
} }
ECKeyImpl::ECKeyImpl(const std::string& publicKeyFile, ECKeyImpl::ECKeyImpl(const std::string& publicKeyFile,
const std::string& privateKeyFile, const std::string& privateKeyFile,
const std::string& privateKeyPassphrase): KeyPairImpl("ec", KT_EC_IMPL), _pEC(0) const std::string& privateKeyPassphrase): KeyPairImpl("ec", KT_EC_IMPL), _pEC(0)
{ {
if (EVPPKey::loadKey(&_pEC, PEM_read_PrivateKey, EVP_PKEY_get1_EC_KEY, privateKeyFile, privateKeyPassphrase)) if (EVPPKey::loadKey(&_pEC, PEM_read_PrivateKey, EVP_PKEY_get1_EC_KEY, privateKeyFile, privateKeyPassphrase))

View File

@@ -20,11 +20,9 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#include <openssl/crypto.h> #include <openssl/crypto.h>
#include <openssl/err.h> #include <openssl/err.h>
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
#include <openssl/conf.h> #include <openssl/conf.h>
#endif
#if defined(POCO_OS_FAMILY_WINDOWS) #if defined(POCO_OS_FAMILY_WINDOWS)
#define POCO_STR_HELPER(x) #x #define POCO_STR_HELPER(x) #x
#define POCO_STR(x) POCO_STR_HELPER(x) #define POCO_STR(x) POCO_STR_HELPER(x)
@@ -98,7 +96,7 @@ void OpenSSLInitializer::initialize()
{ {
#if OPENSSL_VERSION_NUMBER >= 0x10100000L #if OPENSSL_VERSION_NUMBER >= 0x10100000L
CONF_modules_load(NULL, NULL, 0); CONF_modules_load(NULL, NULL, 0);
#elif OPENSSL_VERSION_NUMBER >= 0x0907000L #else
OPENSSL_config(NULL); OPENSSL_config(NULL);
#endif #endif

View File

@@ -21,9 +21,7 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
#include <openssl/bn.h> #include <openssl/bn.h>
#endif
namespace Poco { namespace Poco {
@@ -66,7 +64,6 @@ RSAKeyImpl::RSAKeyImpl(const PKCS12Container& cont):
RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent): KeyPairImpl("rsa", KT_RSA_IMPL), RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent): KeyPairImpl("rsa", KT_RSA_IMPL),
_pRSA(0) _pRSA(0)
{ {
#if OPENSSL_VERSION_NUMBER >= 0x00908000L
_pRSA = RSA_new(); _pRSA = RSA_new();
int ret = 0; int ret = 0;
BIGNUM* bn = 0; BIGNUM* bn = 0;
@@ -83,15 +80,11 @@ RSAKeyImpl::RSAKeyImpl(int keyLength, unsigned long exponent): KeyPairImpl("rsa"
throw; throw;
} }
if (!ret) throw Poco::InvalidArgumentException("Failed to create RSA context"); if (!ret) throw Poco::InvalidArgumentException("Failed to create RSA context");
#else
_pRSA = RSA_generate_key(keyLength, exponent, 0, 0);
if (!_pRSA) throw Poco::InvalidArgumentException("Failed to create RSA context");
#endif
} }
RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile, RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile,
const std::string& privateKeyFile, const std::string& privateKeyFile,
const std::string& privateKeyPassphrase): KeyPairImpl("rsa", KT_RSA_IMPL), const std::string& privateKeyPassphrase): KeyPairImpl("rsa", KT_RSA_IMPL),
_pRSA(0) _pRSA(0)
{ {
@@ -109,7 +102,7 @@ RSAKeyImpl::RSAKeyImpl(const std::string& publicKeyFile,
if (!pubKey) if (!pubKey)
{ {
int rc = BIO_reset(bio); int rc = BIO_reset(bio);
// BIO_reset() normally returns 1 for success and 0 or -1 for failure. // BIO_reset() normally returns 1 for success and 0 or -1 for failure.
// File BIOs are an exception, they return 0 for success and -1 for failure. // File BIOs are an exception, they return 0 for success and -1 for failure.
if (rc != 0) throw Poco::FileException("Failed to load public key", publicKeyFile); if (rc != 0) throw Poco::FileException("Failed to load public key", publicKeyFile);
pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0); pubKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
@@ -174,7 +167,7 @@ RSAKeyImpl::RSAKeyImpl(std::istream* pPublicKeyStream,
if (!publicKey) if (!publicKey)
{ {
int rc = BIO_reset(bio); int rc = BIO_reset(bio);
// BIO_reset() normally returns 1 for success and 0 or -1 for failure. // BIO_reset() normally returns 1 for success and 0 or -1 for failure.
// File BIOs are an exception, they return 0 for success and -1 for failure. // File BIOs are an exception, they return 0 for success and -1 for failure.
if (rc != 1) throw Poco::FileException("Failed to load public key"); if (rc != 1) throw Poco::FileException("Failed to load public key");
publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0); publicKey = PEM_read_bio_RSA_PUBKEY(bio, &_pRSA, 0, 0);
@@ -293,7 +286,7 @@ void RSAKeyImpl::save(const std::string& publicKeyFile,
} }
BIO_free(bio); BIO_free(bio);
} }
if (!privateKeyFile.empty()) if (!privateKeyFile.empty())
{ {
BIO* bio = BIO_new(BIO_s_file()); BIO* bio = BIO_new(BIO_s_file());
@@ -306,8 +299,8 @@ void RSAKeyImpl::save(const std::string& publicKeyFile,
if (privateKeyPassphrase.empty()) if (privateKeyPassphrase.empty())
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0); rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0);
else else
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(), rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(),
reinterpret_cast<unsigned char*>(const_cast<char*>(privateKeyPassphrase.c_str())), reinterpret_cast<unsigned char*>(const_cast<char*>(privateKeyPassphrase.c_str())),
static_cast<int>(privateKeyPassphrase.length()), 0, 0); static_cast<int>(privateKeyPassphrase.length()), 0, 0);
if (!rc) throw Poco::FileException("Failed to write private key to file", privateKeyFile); if (!rc) throw Poco::FileException("Failed to write private key to file", privateKeyFile);
} }
@@ -350,10 +343,10 @@ void RSAKeyImpl::save(std::ostream* pPublicKeyStream,
if (privateKeyPassphrase.empty()) if (privateKeyPassphrase.empty())
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0); rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, 0, 0, 0, 0, 0);
else else
rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(), rc = PEM_write_bio_RSAPrivateKey(bio, _pRSA, EVP_des_ede3_cbc(),
reinterpret_cast<unsigned char*>(const_cast<char*>(privateKeyPassphrase.c_str())), reinterpret_cast<unsigned char*>(const_cast<char*>(privateKeyPassphrase.c_str())),
static_cast<int>(privateKeyPassphrase.length()), 0, 0); static_cast<int>(privateKeyPassphrase.length()), 0, 0);
if (!rc) if (!rc)
{ {
BIO_free(bio); BIO_free(bio);
throw Poco::FileException("Failed to write private key to stream"); throw Poco::FileException("Failed to write private key to stream");

View File

@@ -812,7 +812,7 @@ void Context::initECDH(const std::string& curve)
throw SSLContextException("Cannot set ECDH groups", groups); throw SSLContextException("Cannot set ECDH groups", groups);
} }
SSL_CTX_set_options(_pSSLContext, SSL_OP_SINGLE_ECDH_USE); SSL_CTX_set_options(_pSSLContext, SSL_OP_SINGLE_ECDH_USE);
#elif OPENSSL_VERSION_NUMBER >= 0x0090800fL #else
int nid = 0; int nid = 0;
if (!curve.empty()) if (!curve.empty())
{ {

View File

@@ -157,12 +157,10 @@ void SecureSocketImpl::connectSSL(bool performHandshake)
} }
SSL_set_bio(_pSSL, pBIO, pBIO); SSL_set_bio(_pSSL, pBIO, pBIO);
#if OPENSSL_VERSION_NUMBER >= 0x0908060L && !defined(OPENSSL_NO_TLSEXT)
if (!_peerHostName.empty()) if (!_peerHostName.empty())
{ {
SSL_set_tlsext_host_name(_pSSL, _peerHostName.c_str()); SSL_set_tlsext_host_name(_pSSL, _peerHostName.c_str());
} }
#endif
#if OPENSSL_VERSION_NUMBER >= 0x10001000L #if OPENSSL_VERSION_NUMBER >= 0x10001000L
if(_pContext->ocspStaplingResponseVerificationEnabled()) if(_pContext->ocspStaplingResponseVerificationEnabled())