wip in progress.

This commit is contained in:
NADAL Jean-Baptiste
2019-12-11 18:57:59 +01:00
parent 214b09e6d3
commit bde9ffd991
9 changed files with 309 additions and 35 deletions

141
patches/libsourcey.patch Normal file
View File

@@ -0,0 +1,141 @@
diff --git a/src/crypto/include/scy/crypto/hash.h b/src/crypto/include/scy/crypto/hash.h
index a93fdde9..1d65c374 100644
--- a/src/crypto/include/scy/crypto/hash.h
+++ b/src/crypto/include/scy/crypto/hash.h
@@ -53,7 +53,11 @@ public:
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 729fa615..6113c02f 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 1a0fad34..d132be3b 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,24 @@ 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_reset(_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 +96,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 76f5e799..d362fada 100644
--- a/src/crypto/src/x509certificate.cpp
+++ b/src/crypto/src/x509certificate.cpp
@@ -58,10 +58,14 @@ 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,15 @@ 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<char*>(ASN1_STRING_data(name->d.ia5));
+ #else
+ const char* data =
+ reinterpret_cast<const char*>(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 +321,4 @@ const X509* X509Certificate::certificate() const
} // namespace scy
-/// @\}
\ No newline at end of file
+/// @\}