Skip to content

Commit a12405a

Browse files
committed
Fix OpenSSL 1.1.0 compatibility issue in sign_tool and urts_sim
Signed-off-by: Zhang Lili Z <[email protected]>
1 parent 3f132c6 commit a12405a

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

sdk/sign_tool/SignTool/parse_key_file.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@
4747
#include <assert.h>
4848
#include <openssl/pem.h>
4949

50+
51+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
52+
void RSA_get0_key(const RSA *rsa, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
53+
{
54+
assert(rsa != NULL);
55+
56+
if(n != NULL)
57+
*n = rsa->n;
58+
if(e != NULL)
59+
*e = rsa->e;
60+
if(d != NULL)
61+
*d = rsa->d;
62+
}
63+
#endif
64+
65+
5066
//parse_key_file():
5167
// parse the RSA key file
5268
//Return Value:
@@ -100,13 +116,15 @@ bool parse_key_file(int mode, const char *key_path, RSA **prsa, int *pkey_type)
100116
}
101117

102118
// Check the key size and exponent
103-
if(BN_num_bytes(rsa->n) != N_SIZE_IN_BYTES)
119+
const BIGNUM *n = NULL, *e = NULL;
120+
RSA_get0_key(rsa, &n, &e, NULL);
121+
if(BN_num_bytes(n) != N_SIZE_IN_BYTES)
104122
{
105123
se_trace(SE_TRACE_ERROR, INVALID_KEYSIZE_ERROR);
106124
RSA_free(rsa);
107125
return false;
108126
}
109-
char *p = BN_bn2dec(rsa->e);
127+
char *p = BN_bn2dec(e);
110128
if(memcmp(p, "3", 2))
111129
{
112130
se_trace(SE_TRACE_ERROR, INVALID_EXPONENT_ERROR);

sdk/sign_tool/SignTool/parse_key_file.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#ifndef _PARSE_KEY_FILE_H_
3535
#define _PARSE_KEY_FILE_H_
3636

37+
#include <openssl/rsa.h>
3738

3839
#define N_SIZE_IN_BYTES 384
3940
#define E_SIZE_IN_BYTES 4
@@ -47,7 +48,9 @@ typedef enum _key_type_t
4748
PUBLIC_KEY
4849
} key_type_t;
4950

50-
#include <openssl/rsa.h>
51+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
52+
void RSA_get0_key(const RSA *rsa, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
53+
#endif
5154

5255
bool parse_key_file(int mode, const char *key_path, RSA **prsa, int *pkey_type);
5356

sdk/sign_tool/SignTool/sign_tool.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include <openssl/rsa.h>
4848
#include <openssl/evp.h>
4949
#include <openssl/err.h>
50+
#include <openssl/crypto.h>
5051

5152
#include "metadata.h"
5253
#include "manage_metadata.h"
@@ -245,8 +246,10 @@ static bool fill_enclave_css(const RSA *rsa, const char **path,
245246
//if rsa is not NULL, fill the public key part
246247
if(rsa)
247248
{
248-
int exponent_size = BN_num_bytes(rsa->e);
249-
int modulus_size = BN_num_bytes(rsa->n);
249+
const BIGNUM *e = NULL, *n = NULL;
250+
RSA_get0_key(rsa, &n, &e, NULL);
251+
int exponent_size = BN_num_bytes(e);
252+
int modulus_size = BN_num_bytes(n);
250253

251254
if(modulus_size > SE_KEY_SIZE)
252255
return false;
@@ -260,12 +263,12 @@ static bool fill_enclave_css(const RSA *rsa, const char **path,
260263
exponent_size = (uint32_t)(ROUND_TO(exponent_size, sizeof(uint32_t)) / sizeof(uint32_t));
261264
modulus_size = (uint32_t)(ROUND_TO(modulus_size, sizeof(uint32_t)) / sizeof(uint32_t));
262265

263-
if(BN_bn2bin(rsa->n, modulus) != SE_KEY_SIZE)
266+
if(BN_bn2bin(n, modulus) != SE_KEY_SIZE)
264267
{
265268
free(modulus);
266269
return false;
267270
}
268-
if(BN_bn2bin(rsa->e, (unsigned char *)&css->key.exponent) != 1)
271+
if(BN_bn2bin(e, (unsigned char *)&css->key.exponent) != 1)
269272
{
270273
free(modulus);
271274
return false;
@@ -1024,8 +1027,12 @@ int main(int argc, char* argv[])
10241027
RSA *rsa = NULL;
10251028
memset(&metadata_raw, 0, sizeof(metadata_raw));
10261029

1030+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
10271031
OpenSSL_add_all_algorithms();
10281032
ERR_load_crypto_strings();
1033+
#else
1034+
OPENSSL_init_crypto(0, NULL);
1035+
#endif
10291036

10301037

10311038
//Parse command line
@@ -1124,10 +1131,11 @@ int main(int argc, char* argv[])
11241131
if(res == -1 && path[DUMPFILE])
11251132
remove(path[DUMPFILE]);
11261133

1134+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
11271135
EVP_cleanup();
11281136
CRYPTO_cleanup_all_ex_data();
11291137
ERR_remove_thread_state(NULL);
11301138
ERR_free_strings();
1131-
1139+
#endif
11321140
return res;
11331141
}

sdk/simulation/urtssim/enclave_creator_sim.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,28 @@
4747

4848
#include <openssl/evp.h>
4949
#include <openssl/err.h>
50-
50+
#include <openssl/crypto.h>
5151

5252
__attribute__((constructor))
5353
static void init_openssl(void)
5454
{
55+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
5556
OpenSSL_add_all_algorithms();
5657
ERR_load_crypto_strings();
58+
#else
59+
OPENSSL_init_crypto(0, NULL);
60+
#endif
5761
}
5862

5963
__attribute__((destructor))
6064
static void cleanup_openssl(void)
6165
{
66+
#if OPENSSL_VERSION_NUMBER < 0x10100000L
6267
EVP_cleanup();
6368
CRYPTO_cleanup_all_ex_data();
6469
ERR_remove_thread_state(NULL);
6570
ERR_free_strings();
71+
#endif
6672
}
6773

6874

0 commit comments

Comments
 (0)