diff --git a/src/crypto/include/scy/crypto/hash.h b/src/crypto/include/scy/crypto/hash.h index a93fdde9c..29a28a973 100644 --- a/src/crypto/include/scy/crypto/hash.h +++ b/src/crypto/include/scy/crypto/hash.h @@ -53,7 +53,12 @@ class Crypto_API Hash protected: Hash& operator=(Hash const&); - EVP_MD_CTX _ctx; +#if OPENSSL_VERSION_NUMBER < 0x10100000L + EVP_MD_CTX _ctx; +#else + EVP_MD_CTX* _ctxPtr; +#endif + const EVP_MD* _md; crypto::ByteVec _digest; std::string _algorithm; diff --git a/src/crypto/src/crypto.cpp b/src/crypto/src/crypto.cpp index 729fa615c..6113c02fc 100644 --- a/src/crypto/src/crypto.cpp +++ b/src/crypto/src/crypto.cpp @@ -120,7 +120,9 @@ void init() if (++_refCount == 1) { #if OPENSSL_VERSION_NUMBER >= 0x0907000L + #if OPENSSL_VERSION_NUMBER < 0x10100000L OPENSSL_config(NULL); + #endif #endif SSL_library_init(); SSL_load_error_strings(); diff --git a/src/crypto/src/hash.cpp b/src/crypto/src/hash.cpp index 1a0fad345..bdaad9f31 100644 --- a/src/crypto/src/hash.cpp +++ b/src/crypto/src/hash.cpp @@ -32,7 +32,11 @@ Hash::Hash(const std::string& algorithm) if (!_md) throw std::runtime_error("Algorithm not supported: " + algorithm); +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_DigestInit(&_ctx, _md); +#else + EVP_DigestInit(_ctxPtr, _md); +#endif } @@ -40,7 +44,11 @@ Hash::~Hash() { crypto::uninitializeEngine(); +#if OPENSSL_VERSION_NUMBER < 0x10100000L EVP_MD_CTX_cleanup(&_ctx); +#else + EVP_MD_CTX_free(_ctxPtr); +#endif //EVP_MD_CTX_free(_ctx); } @@ -49,15 +57,26 @@ void Hash::reset() { //EVP_MD_CTX_free(_ctx); //_ctx = EVP_MD_CTX_new(); +#if OPENSSL_VERSION_NUMBER < 0x10100000L internal::api(EVP_MD_CTX_cleanup(&_ctx)); internal::api(EVP_DigestInit(&_ctx, _md)); +#else + internal::api(EVP_MD_CTX_cleanup(_ctxPtr)); + internal::api(EVP_DigestInit(_ctxPtr, _md)); +#endif + _digest.clear(); } void Hash::update(const void* data, size_t length) { +#if OPENSSL_VERSION_NUMBER < 0x10100000L internal::api(EVP_DigestUpdate(&_ctx, data, length)); +#else + internal::api(EVP_DigestUpdate(_ctxPtr, data, length)); +#endif + } @@ -79,7 +98,11 @@ const ByteVec& Hash::digest() if (_digest.size() == 0) { _digest.resize(EVP_MAX_MD_SIZE); // TODO: Get actual algorithm size unsigned int len = 0; + #if OPENSSL_VERSION_NUMBER < 0x10100000L internal::api(EVP_DigestFinal(&_ctx, &_digest[0], &len)); + #else + internal::api(EVP_DigestFinal(_ctxPtr, &_digest[0], &len)); + #endif _digest.resize(len); } return _digest; diff --git a/src/crypto/src/x509certificate.cpp b/src/crypto/src/x509certificate.cpp index 76f5e799b..f7b202cc8 100644 --- a/src/crypto/src/x509certificate.cpp +++ b/src/crypto/src/x509certificate.cpp @@ -58,9 +58,13 @@ X509Certificate::X509Certificate(X509* pCert, bool shared) { assert(_certificate); - if (shared) + if (shared) { + #if OPENSSL_VERSION_NUMBER < 0x10100000L _certificate->references++; - // X509_up_ref(_certificate); // OpenSSL >= 1.1.0 + #else + X509_up_ref(_certificate); // OpenSSL >= 1.1.0 + #endif + } init(); } @@ -241,8 +245,14 @@ void X509Certificate::extractNames(std::string& cmnName, for (int i = 0; i < sk_GENERAL_NAME_num(names); ++i) { const GENERAL_NAME* name = sk_GENERAL_NAME_value(names, i); if (name->type == GEN_DNS) { - const char* data = + #if OPENSSL_VERSION_NUMBER < 0x10100000L + const char* data = reinterpret_cast(ASN1_STRING_data(name->d.ia5)); + #else + const char* data = + reinterpret_cast(ASN1_STRING_get0_data(name->d.ia5)); + #endif + size_t len = ASN1_STRING_length(name->d.ia5); domainNames.insert(std::string(data, len)); } @@ -310,4 +320,4 @@ const X509* X509Certificate::certificate() const } // namespace scy -/// @\} \ No newline at end of file +/// @\}