From 40a3a264d7527e24dc17019aa0d0fdd16143a3f0 Mon Sep 17 00:00:00 2001
From: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
Date: Mon, 13 Feb 2017 16:07:20 +0100
Subject: [PATCH] TITAN is now compatible with OpenSSL 1.1.0d 26 Jan 2017 (Bug
 512119)

Change-Id: I3e5231fcc257baf804ea8ade2997bf22b62e1472
Signed-off-by: BenceJanosSzabo <bence.janos.szabo@ericsson.com>
---
 common/Makefile          |  1 +
 common/license.c         | 57 +++++++++++++++++++++++++++++++++++++---
 common/openssl_version.c | 14 +++++++++-
 3 files changed, 67 insertions(+), 5 deletions(-)

diff --git a/common/Makefile b/common/Makefile
index 663d21283..fd72070b1 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -119,6 +119,7 @@ config_preproc_p.tab.cc config_preproc_p.tab.hh: config_preproc_p.y
 ifdef OPENSSL_DIR
 ifneq ($(OPENSSL_DIR), default)
 license.o license.d: CPPFLAGS := $(CPPFLAGS) -I$(OPENSSL_DIR)/include
+openssl_version.o openssl_version.d: CPPFLAGS := $(CPPFLAGS) -I$(OPENSSL_DIR)/include
 endif
 endif
 
diff --git a/common/license.c b/common/license.c
index 7aa9efb2c..54d53ba00 100644
--- a/common/license.c
+++ b/common/license.c
@@ -73,6 +73,57 @@ static const unsigned char dsa_p[] = { 0x90, 0x63, 0x82, 0xae, 0x72, 0x71, 0xac,
     dsa_g[] = { 0x40, 0x6d, 0xfb, 0x6d, 0xb6, 0x6, 0x32, 0xcc, 0xf0, 0xe9, 0x84, 0x16, 0x1e, 0xe1, 0x21, 0xcd, 0x34, 0xe7, 0xbb, 0x6c, 0x98, 0xff, 0xa9, 0xb9, 0xae, 0xe4, 0x6a, 0x61, 0x51, 0xf8, 0x66, 0x83, 0xa4, 0x34, 0x63, 0x81, 0xc4, 0x5f, 0xee, 0x85, 0x74, 0xee, 0x2a, 0x63, 0x9d, 0xcf, 0x97, 0x50, 0xb8, 0x9f, 0x76, 0xd9, 0xe, 0x58,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b, 0x1c, 0xb1, 0x5d, 0xa1, 0xef, 0x50, 0xc3, 0x75, 0xff, 0x2, 0x24, 0x8c, 0xd7, 0x3b, 0x91, 0x77, 0xef, 0x94, 0x76 };
 
+
+
+// Backward compatibility with older openssl versions
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+
+static int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
+{
+   /* If the fields p, q and g in d are NULL, the corresponding input
+    * parameters MUST be non-NULL.
+    */
+   if ((d->p == NULL && p == NULL)
+       || (d->q == NULL && q == NULL)
+       || (d->g == NULL && g == NULL))
+       return 0;
+   if (p != NULL) {
+       BN_free(d->p);
+       d->p = p;
+   }
+   if (q != NULL) {
+       BN_free(d->q);
+       d->q = q;
+   }
+   if (g != NULL) {
+       BN_free(d->g);
+       d->g = g;
+   }
+   return 1;
+}
+
+static int DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
+{
+   /* If the field pub_key in d is NULL, the corresponding input
+    * parameters MUST be non-NULL.  The priv_key field may
+    * be left NULL.
+    */
+   if (d->pub_key == NULL && pub_key == NULL)
+       return 0;
+   if (pub_key != NULL) {
+       BN_free(d->pub_key);
+       d->pub_key = pub_key;
+   }
+   if (priv_key != NULL) {
+       BN_free(d->priv_key);
+       d->priv_key = priv_key;
+   }
+   return 1;
+}
+
+#endif
+
+
 /** Big-endian decoding of a 4-byte integer */
 static unsigned int decode_int(const unsigned char *from)
 {
@@ -156,10 +207,8 @@ static void check_license_signature(license_raw *lptr)
     SHA1_Update(&sha_ctx, lptr, sizeof(*lptr) - sizeof(lptr->dsa_signature));
     SHA1_Final(message_digest, &sha_ctx);
 
-    dsa->p = BN_bin2bn(dsa_p, sizeof(dsa_p), NULL);
-    dsa->q = BN_bin2bn(dsa_q, sizeof(dsa_q), NULL);
-    dsa->g = BN_bin2bn(dsa_g, sizeof(dsa_g), NULL);
-    dsa->pub_key = BN_bin2bn(dsa_pub_key, sizeof(dsa_pub_key), NULL);
+    DSA_set0_pqg(dsa, BN_bin2bn(dsa_p, sizeof(dsa_p), NULL), BN_bin2bn(dsa_q, sizeof(dsa_q), NULL), BN_bin2bn(dsa_g, sizeof(dsa_g), NULL));
+    DSA_set0_key(dsa, BN_bin2bn(dsa_pub_key, sizeof(dsa_pub_key), NULL), NULL);
 
   // calculate the right len of the signiture
   DSA_SIG *temp_sig=DSA_SIG_new();
diff --git a/common/openssl_version.c b/common/openssl_version.c
index 7542c0fe0..1110cb72a 100644
--- a/common/openssl_version.c
+++ b/common/openssl_version.c
@@ -13,6 +13,18 @@
 #include "openssl_version.h"
 #include <openssl/crypto.h>
 
+
+// Backward compatibility with older openssl versions
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+
 const char * openssl_version_str(void) {
-  return SSLeay_version(SSLEAY_VERSION);
+	return SSLeay_version(SSLEAY_VERSION);
 }
+
+#else
+
+const char * openssl_version_str(void) {
+	return OpenSSL_version(OPENSSL_VERSION);
+}
+
+#endif
\ No newline at end of file
-- 
GitLab