You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1096 lines
31 KiB

  1. From 071fec7181255b9234add44865a435dfdefee520 Mon Sep 17 00:00:00 2001
  2. In-Reply-To: <20180528120513.560-1-cote2004-github@yahoo.com>
  3. References: <20180528120513.560-1-cote2004-github@yahoo.com>
  4. From: Eneas U de Queiroz <cote2004-github@yahoo.com>
  5. Date: Wed, 30 May 2018 15:42:20 -0300
  6. Subject: [PATCH v2 1/1] ipsec-tools: add openssl 1.1 support
  7. To: equeiroz@troianet.com.br
  8. This patch updates the calls to openssl 1.1 API, and adds a
  9. compatibility layer so it compiles with (at least) openssl 1.0.2, I
  10. haven't tested it with lower versions, but all that's needed is to edit
  11. the openssl_compat.* files and add the missing functions there--they're
  12. usually trivial.
  13. Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
  14. ---
  15. src/racoon/Makefile.am | 10 +--
  16. src/racoon/algorithm.c | 6 +-
  17. src/racoon/cfparse.y | 2 +-
  18. src/racoon/crypto_openssl.c | 197 +++++++++++++++++++++-------------------
  19. src/racoon/crypto_openssl.h | 2 +-
  20. src/racoon/eaytest.c | 7 +-
  21. src/racoon/ipsec_doi.c | 2 +-
  22. src/racoon/openssl_compat.c | 213 ++++++++++++++++++++++++++++++++++++++++++++
  23. src/racoon/openssl_compat.h | 45 ++++++++++
  24. src/racoon/plainrsa-gen.c | 41 +++++----
  25. src/racoon/prsa_par.y | 28 ++++--
  26. src/racoon/rsalist.c | 5 +-
  27. 12 files changed, 431 insertions(+), 127 deletions(-)
  28. create mode 100644 src/racoon/openssl_compat.c
  29. create mode 100644 src/racoon/openssl_compat.h
  30. diff --git a/src/racoon/Makefile.am b/src/racoon/Makefile.am
  31. index dbaded9..4c585f3 100644
  32. --- a/src/racoon/Makefile.am
  33. +++ b/src/racoon/Makefile.am
  34. @@ -4,7 +4,7 @@ sbin_PROGRAMS = racoon racoonctl plainrsa-gen
  35. noinst_PROGRAMS = eaytest
  36. include_racoon_HEADERS = racoonctl.h var.h vmbuf.h misc.h gcmalloc.h admin.h \
  37. schedule.h sockmisc.h isakmp_var.h isakmp.h isakmp_xauth.h \
  38. - isakmp_cfg.h isakmp_unity.h ipsec_doi.h evt.h
  39. + isakmp_cfg.h isakmp_unity.h ipsec_doi.h evt.h openssl_compat.h
  40. lib_LTLIBRARIES = libracoon.la
  41. adminsockdir=${localstatedir}/racoon
  42. @@ -32,7 +32,7 @@ racoon_SOURCES = \
  43. gssapi.c dnssec.c getcertsbyname.c privsep.c \
  44. pfkey.c admin.c evt.c ipsec_doi.c oakley.c grabmyaddr.c vendorid.c \
  45. policy.c localconf.c remoteconf.c crypto_openssl.c algorithm.c \
  46. - proposal.c sainfo.c strnames.c \
  47. + openssl_compat.c proposal.c sainfo.c strnames.c \
  48. plog.c logger.c schedule.c str2val.c \
  49. safefile.c backupsa.c genlist.c rsalist.c \
  50. cftoken.l cfparse.y prsa_tok.l prsa_par.y
  51. @@ -51,12 +51,12 @@ libracoon_la_SOURCES = kmpstat.c vmbuf.c sockmisc.c misc.c
  52. libracoon_la_CFLAGS = -DNOUSE_PRIVSEP $(AM_CFLAGS)
  53. plainrsa_gen_SOURCES = plainrsa-gen.c plog.c \
  54. - crypto_openssl.c logger.c
  55. + crypto_openssl.c logger.c openssl_compat.c
  56. EXTRA_plainrsa_gen_SOURCES = $(MISSING_ALGOS)
  57. plainrsa_gen_LDADD = $(CRYPTOBJS) vmbuf.o misc.o
  58. plainrsa_gen_DEPENDENCIES = $(CRYPTOBJS) vmbuf.o misc.o
  59. -eaytest_SOURCES = eaytest.c plog.c logger.c
  60. +eaytest_SOURCES = eaytest.c plog.c logger.c openssl_compat.c
  61. EXTRA_eaytest_SOURCES = missing/crypto/sha2/sha2.c
  62. eaytest_LDADD = crypto_openssl_test.o vmbuf.o str2val.o misc_noplog.o \
  63. $(CRYPTOBJS)
  64. @@ -75,7 +75,7 @@ noinst_HEADERS = \
  65. debugrm.h isakmp.h misc.h sainfo.h \
  66. dhgroup.h isakmp_agg.h netdb_dnssec.h schedule.h \
  67. isakmp_cfg.h isakmp_xauth.h isakmp_unity.h isakmp_frag.h \
  68. - throttle.h privsep.h \
  69. + throttle.h privsep.h openssl_compat.h \
  70. cfparse_proto.h cftoken_proto.h genlist.h rsalist.h \
  71. missing/crypto/sha2/sha2.h missing/crypto/rijndael/rijndael_local.h \
  72. missing/crypto/rijndael/rijndael-api-fst.h \
  73. diff --git a/src/racoon/algorithm.c b/src/racoon/algorithm.c
  74. index 3fd50f6..66c874b 100644
  75. --- a/src/racoon/algorithm.c
  76. +++ b/src/racoon/algorithm.c
  77. @@ -128,7 +128,7 @@ static struct enc_algorithm oakley_encdef[] = {
  78. { "aes", algtype_aes, OAKLEY_ATTR_ENC_ALG_AES, 16,
  79. eay_aes_encrypt, eay_aes_decrypt,
  80. eay_aes_weakkey, eay_aes_keylen, },
  81. -#ifdef HAVE_OPENSSL_CAMELLIA_H
  82. +#if defined(HAVE_OPENSSL_CAMELLIA_H) && ! defined(OPENSSL_NO_CAMELLIA)
  83. { "camellia", algtype_camellia, OAKLEY_ATTR_ENC_ALG_CAMELLIA, 16,
  84. eay_camellia_encrypt, eay_camellia_decrypt,
  85. eay_camellia_weakkey, eay_camellia_keylen, },
  86. @@ -168,7 +168,7 @@ static struct enc_algorithm ipsec_encdef[] = {
  87. { "twofish", algtype_twofish, IPSECDOI_ESP_TWOFISH, 16,
  88. NULL, NULL,
  89. NULL, eay_twofish_keylen, },
  90. -#ifdef HAVE_OPENSSL_IDEA_H
  91. +#if defined(HAVE_OPENSSL_IDEA_H) && ! defined(OPENSSL_NO_IDEA)
  92. { "3idea", algtype_3idea, IPSECDOI_ESP_3IDEA, 8,
  93. NULL, NULL,
  94. NULL, NULL, },
  95. @@ -179,7 +179,7 @@ static struct enc_algorithm ipsec_encdef[] = {
  96. { "rc4", algtype_rc4, IPSECDOI_ESP_RC4, 8,
  97. NULL, NULL,
  98. NULL, NULL, },
  99. -#ifdef HAVE_OPENSSL_CAMELLIA_H
  100. +#if defined(HAVE_OPENSSL_CAMELLIA_H) && ! defined(OPENSSL_NO_CAMELLIA)
  101. { "camellia", algtype_camellia, IPSECDOI_ESP_CAMELLIA, 16,
  102. NULL, NULL,
  103. NULL, eay_camellia_keylen, },
  104. diff --git a/src/racoon/cfparse.y b/src/racoon/cfparse.y
  105. index 0d9bd67..8415752 100644
  106. --- a/src/racoon/cfparse.y
  107. +++ b/src/racoon/cfparse.y
  108. @@ -2564,7 +2564,7 @@ set_isakmp_proposal(rmconf)
  109. plog(LLV_DEBUG2, LOCATION, NULL,
  110. "encklen=%d\n", s->encklen);
  111. - memset(types, 0, ARRAYLEN(types));
  112. + memset(types, 0, sizeof types);
  113. types[algclass_isakmp_enc] = s->algclass[algclass_isakmp_enc];
  114. types[algclass_isakmp_hash] = s->algclass[algclass_isakmp_hash];
  115. types[algclass_isakmp_dh] = s->algclass[algclass_isakmp_dh];
  116. diff --git a/src/racoon/crypto_openssl.c b/src/racoon/crypto_openssl.c
  117. index 55b076a..8fb358f 100644
  118. --- a/src/racoon/crypto_openssl.c
  119. +++ b/src/racoon/crypto_openssl.c
  120. @@ -90,6 +90,7 @@
  121. #endif
  122. #endif
  123. #include "plog.h"
  124. +#include "openssl_compat.h"
  125. #define USE_NEW_DES_API
  126. @@ -316,9 +317,12 @@ eay_cmp_asn1dn(n1, n2)
  127. i = idx+1;
  128. goto end;
  129. }
  130. - if ((ea->value->length == 1 && ea->value->data[0] == '*') ||
  131. - (eb->value->length == 1 && eb->value->data[0] == '*')) {
  132. - if (OBJ_cmp(ea->object,eb->object)) {
  133. + ASN1_STRING *sa = X509_NAME_ENTRY_get_data(ea);
  134. + ASN1_STRING *sb = X509_NAME_ENTRY_get_data(eb);
  135. + if ((ASN1_STRING_length(sa) == 1 && ASN1_STRING_get0_data(sa)[0] == '*') ||
  136. + (ASN1_STRING_length(sb) == 1 && ASN1_STRING_get0_data(sb)[0] == '*')) {
  137. + if (OBJ_cmp(X509_NAME_ENTRY_get_object(ea),
  138. + X509_NAME_ENTRY_get_object(eb))) {
  139. i = idx+1;
  140. goto end;
  141. }
  142. @@ -430,7 +434,7 @@ cb_check_cert_local(ok, ctx)
  143. if (!ok) {
  144. X509_NAME_oneline(
  145. - X509_get_subject_name(ctx->current_cert),
  146. + X509_get_subject_name(X509_STORE_CTX_get_current_cert(ctx)),
  147. buf,
  148. 256);
  149. /*
  150. @@ -438,7 +442,8 @@ cb_check_cert_local(ok, ctx)
  151. * ok if they are self signed. But we should still warn
  152. * the user.
  153. */
  154. - switch (ctx->error) {
  155. + int ctx_error = X509_STORE_CTX_get_error(ctx);
  156. + switch (ctx_error) {
  157. case X509_V_ERR_CERT_HAS_EXPIRED:
  158. case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
  159. case X509_V_ERR_INVALID_CA:
  160. @@ -453,9 +458,9 @@ cb_check_cert_local(ok, ctx)
  161. }
  162. plog(log_tag, LOCATION, NULL,
  163. "%s(%d) at depth:%d SubjectName:%s\n",
  164. - X509_verify_cert_error_string(ctx->error),
  165. - ctx->error,
  166. - ctx->error_depth,
  167. + X509_verify_cert_error_string(ctx_error),
  168. + ctx_error,
  169. + X509_STORE_CTX_get_error_depth(ctx),
  170. buf);
  171. }
  172. ERR_clear_error();
  173. @@ -477,10 +482,11 @@ cb_check_cert_remote(ok, ctx)
  174. if (!ok) {
  175. X509_NAME_oneline(
  176. - X509_get_subject_name(ctx->current_cert),
  177. + X509_get_subject_name(X509_STORE_CTX_get_current_cert(ctx)),
  178. buf,
  179. 256);
  180. - switch (ctx->error) {
  181. + int ctx_error=X509_STORE_CTX_get_error(ctx);
  182. + switch (ctx_error) {
  183. case X509_V_ERR_UNABLE_TO_GET_CRL:
  184. ok = 1;
  185. log_tag = LLV_WARNING;
  186. @@ -490,9 +496,9 @@ cb_check_cert_remote(ok, ctx)
  187. }
  188. plog(log_tag, LOCATION, NULL,
  189. "%s(%d) at depth:%d SubjectName:%s\n",
  190. - X509_verify_cert_error_string(ctx->error),
  191. - ctx->error,
  192. - ctx->error_depth,
  193. + X509_verify_cert_error_string(ctx_error),
  194. + ctx_error,
  195. + X509_STORE_CTX_get_error_depth(ctx),
  196. buf);
  197. }
  198. ERR_clear_error();
  199. @@ -516,14 +522,15 @@ eay_get_x509asn1subjectname(cert)
  200. if (x509 == NULL)
  201. goto error;
  202. + X509_NAME *subject_name = X509_get_subject_name(x509);
  203. /* get the length of the name */
  204. - len = i2d_X509_NAME(x509->cert_info->subject, NULL);
  205. + len = i2d_X509_NAME(subject_name, NULL);
  206. name = vmalloc(len);
  207. if (!name)
  208. goto error;
  209. /* get the name */
  210. bp = (unsigned char *) name->v;
  211. - len = i2d_X509_NAME(x509->cert_info->subject, &bp);
  212. + len = i2d_X509_NAME(subject_name, &bp);
  213. X509_free(x509);
  214. @@ -661,15 +668,16 @@ eay_get_x509asn1issuername(cert)
  215. if (x509 == NULL)
  216. goto error;
  217. + X509_NAME *issuer_name = X509_get_issuer_name(x509);
  218. /* get the length of the name */
  219. - len = i2d_X509_NAME(x509->cert_info->issuer, NULL);
  220. + len = i2d_X509_NAME(issuer_name, NULL);
  221. name = vmalloc(len);
  222. if (name == NULL)
  223. goto error;
  224. /* get the name */
  225. bp = (unsigned char *) name->v;
  226. - len = i2d_X509_NAME(x509->cert_info->issuer, &bp);
  227. + len = i2d_X509_NAME(issuer_name, &bp);
  228. X509_free(x509);
  229. @@ -850,7 +858,7 @@ eay_check_x509sign(source, sig, cert)
  230. return -1;
  231. }
  232. - res = eay_rsa_verify(source, sig, evp->pkey.rsa);
  233. + res = eay_rsa_verify(source, sig, EVP_PKEY_get0_RSA(evp));
  234. EVP_PKEY_free(evp);
  235. X509_free(x509);
  236. @@ -992,7 +1000,7 @@ eay_get_x509sign(src, privkey)
  237. if (evp == NULL)
  238. return NULL;
  239. - sig = eay_rsa_sign(src, evp->pkey.rsa);
  240. + sig = eay_rsa_sign(src, EVP_PKEY_get0_RSA(evp));
  241. EVP_PKEY_free(evp);
  242. @@ -1079,7 +1087,11 @@ eay_strerror()
  243. int line, flags;
  244. unsigned long es;
  245. +#if OPENSSL_VERSION_NUMBER >= 0x10100000L
  246. + es = 0; /* even when allowed by OPENSSL_API_COMPAT, it is defined as 0 */
  247. +#else
  248. es = CRYPTO_thread_id();
  249. +#endif
  250. while ((l = ERR_get_error_line_data(&file, &line, &data, &flags)) != 0){
  251. n = snprintf(ebuf + len, sizeof(ebuf) - len,
  252. @@ -1100,7 +1112,7 @@ vchar_t *
  253. evp_crypt(vchar_t *data, vchar_t *key, vchar_t *iv, const EVP_CIPHER *e, int enc)
  254. {
  255. vchar_t *res;
  256. - EVP_CIPHER_CTX ctx;
  257. + EVP_CIPHER_CTX *ctx;
  258. if (!e)
  259. return NULL;
  260. @@ -1111,7 +1123,7 @@ evp_crypt(vchar_t *data, vchar_t *key, vchar_t *iv, const EVP_CIPHER *e, int enc
  261. if ((res = vmalloc(data->l)) == NULL)
  262. return NULL;
  263. - EVP_CIPHER_CTX_init(&ctx);
  264. + ctx = EVP_CIPHER_CTX_new();
  265. switch(EVP_CIPHER_nid(e)){
  266. case NID_bf_cbc:
  267. @@ -1125,54 +1137,41 @@ evp_crypt(vchar_t *data, vchar_t *key, vchar_t *iv, const EVP_CIPHER *e, int enc
  268. /* XXX: can we do that also for algos with a fixed key size ?
  269. */
  270. /* init context without key/iv
  271. - */
  272. - if (!EVP_CipherInit(&ctx, e, NULL, NULL, enc))
  273. - {
  274. - OpenSSL_BUG();
  275. - vfree(res);
  276. - return NULL;
  277. - }
  278. + */
  279. + if (!EVP_CipherInit(ctx, e, NULL, NULL, enc))
  280. + goto out;
  281. - /* update key size
  282. - */
  283. - if (!EVP_CIPHER_CTX_set_key_length(&ctx, key->l))
  284. - {
  285. - OpenSSL_BUG();
  286. - vfree(res);
  287. - return NULL;
  288. - }
  289. -
  290. - /* finalize context init with desired key size
  291. - */
  292. - if (!EVP_CipherInit(&ctx, NULL, (u_char *) key->v,
  293. + /* update key size
  294. + */
  295. + if (!EVP_CIPHER_CTX_set_key_length(ctx, key->l))
  296. + goto out;
  297. +
  298. + /* finalize context init with desired key size
  299. + */
  300. + if (!EVP_CipherInit(ctx, NULL, (u_char *) key->v,
  301. (u_char *) iv->v, enc))
  302. - {
  303. - OpenSSL_BUG();
  304. - vfree(res);
  305. - return NULL;
  306. - }
  307. + goto out;
  308. break;
  309. default:
  310. - if (!EVP_CipherInit(&ctx, e, (u_char *) key->v,
  311. - (u_char *) iv->v, enc)) {
  312. - OpenSSL_BUG();
  313. - vfree(res);
  314. - return NULL;
  315. - }
  316. + if (!EVP_CipherInit(ctx, e, (u_char *) key->v,
  317. + (u_char *) iv->v, enc))
  318. + goto out;
  319. }
  320. /* disable openssl padding */
  321. - EVP_CIPHER_CTX_set_padding(&ctx, 0);
  322. + EVP_CIPHER_CTX_set_padding(ctx, 0);
  323. - if (!EVP_Cipher(&ctx, (u_char *) res->v, (u_char *) data->v, data->l)) {
  324. - OpenSSL_BUG();
  325. - vfree(res);
  326. - return NULL;
  327. - }
  328. + if (!EVP_Cipher(ctx, (u_char *) res->v, (u_char *) data->v, data->l))
  329. + goto out;
  330. - EVP_CIPHER_CTX_cleanup(&ctx);
  331. + EVP_CIPHER_CTX_free(ctx);
  332. return res;
  333. +out:
  334. + EVP_CIPHER_CTX_free(ctx);
  335. + OpenSSL_BUG();
  336. + vfree(res);
  337. + return NULL;
  338. }
  339. int
  340. @@ -1230,7 +1229,7 @@ eay_des_keylen(len)
  341. return evp_keylen(len, EVP_des_cbc());
  342. }
  343. -#ifdef HAVE_OPENSSL_IDEA_H
  344. +#if defined(HAVE_OPENSSL_IDEA_H) && ! defined(OPENSSL_NO_IDEA)
  345. /*
  346. * IDEA-CBC
  347. */
  348. @@ -1587,7 +1586,7 @@ eay_aes_keylen(len)
  349. return len;
  350. }
  351. -#if defined(HAVE_OPENSSL_CAMELLIA_H)
  352. +#if defined(HAVE_OPENSSL_CAMELLIA_H) && ! defined(OPENSSL_NO_CAMELLIA)
  353. /*
  354. * CAMELLIA-CBC
  355. */
  356. @@ -1680,9 +1679,9 @@ eay_hmac_init(key, md)
  357. vchar_t *key;
  358. const EVP_MD *md;
  359. {
  360. - HMAC_CTX *c = racoon_malloc(sizeof(*c));
  361. + HMAC_CTX *c = HMAC_CTX_new();
  362. - HMAC_Init(c, key->v, key->l, md);
  363. + HMAC_Init_ex(c, key->v, key->l, md, NULL);
  364. return (caddr_t)c;
  365. }
  366. @@ -1761,8 +1760,7 @@ eay_hmacsha2_512_final(c)
  367. HMAC_Final((HMAC_CTX *)c, (unsigned char *) res->v, &l);
  368. res->l = l;
  369. - HMAC_cleanup((HMAC_CTX *)c);
  370. - (void)racoon_free(c);
  371. + HMAC_CTX_free((HMAC_CTX *)c);
  372. if (SHA512_DIGEST_LENGTH != res->l) {
  373. plog(LLV_ERROR, LOCATION, NULL,
  374. @@ -1811,8 +1809,7 @@ eay_hmacsha2_384_final(c)
  375. HMAC_Final((HMAC_CTX *)c, (unsigned char *) res->v, &l);
  376. res->l = l;
  377. - HMAC_cleanup((HMAC_CTX *)c);
  378. - (void)racoon_free(c);
  379. + HMAC_CTX_free((HMAC_CTX *)c);
  380. if (SHA384_DIGEST_LENGTH != res->l) {
  381. plog(LLV_ERROR, LOCATION, NULL,
  382. @@ -1861,8 +1858,7 @@ eay_hmacsha2_256_final(c)
  383. HMAC_Final((HMAC_CTX *)c, (unsigned char *) res->v, &l);
  384. res->l = l;
  385. - HMAC_cleanup((HMAC_CTX *)c);
  386. - (void)racoon_free(c);
  387. + HMAC_CTX_free((HMAC_CTX *)c);
  388. if (SHA256_DIGEST_LENGTH != res->l) {
  389. plog(LLV_ERROR, LOCATION, NULL,
  390. @@ -1912,8 +1908,7 @@ eay_hmacsha1_final(c)
  391. HMAC_Final((HMAC_CTX *)c, (unsigned char *) res->v, &l);
  392. res->l = l;
  393. - HMAC_cleanup((HMAC_CTX *)c);
  394. - (void)racoon_free(c);
  395. + HMAC_CTX_free((HMAC_CTX *)c);
  396. if (SHA_DIGEST_LENGTH != res->l) {
  397. plog(LLV_ERROR, LOCATION, NULL,
  398. @@ -1962,8 +1957,7 @@ eay_hmacmd5_final(c)
  399. HMAC_Final((HMAC_CTX *)c, (unsigned char *) res->v, &l);
  400. res->l = l;
  401. - HMAC_cleanup((HMAC_CTX *)c);
  402. - (void)racoon_free(c);
  403. + HMAC_CTX_free((HMAC_CTX *)c);
  404. if (MD5_DIGEST_LENGTH != res->l) {
  405. plog(LLV_ERROR, LOCATION, NULL,
  406. @@ -2266,6 +2260,7 @@ eay_dh_generate(prime, g, publen, pub, priv)
  407. u_int32_t g;
  408. {
  409. BIGNUM *p = NULL;
  410. + BIGNUM *BNg = NULL;
  411. DH *dh = NULL;
  412. int error = -1;
  413. @@ -2276,25 +2271,28 @@ eay_dh_generate(prime, g, publen, pub, priv)
  414. if ((dh = DH_new()) == NULL)
  415. goto end;
  416. - dh->p = p;
  417. - p = NULL; /* p is now part of dh structure */
  418. - dh->g = NULL;
  419. - if ((dh->g = BN_new()) == NULL)
  420. + if ((BNg = BN_new()) == NULL)
  421. goto end;
  422. - if (!BN_set_word(dh->g, g))
  423. + if (!BN_set_word(BNg, g))
  424. goto end;
  425. + if (! DH_set0_pqg(dh, p, NULL, BNg))
  426. + goto end;
  427. + BNg = NULL;
  428. + p = NULL; /* p is now part of dh structure */
  429. if (publen != 0)
  430. - dh->length = publen;
  431. + DH_set_length(dh, publen);
  432. /* generate public and private number */
  433. if (!DH_generate_key(dh))
  434. goto end;
  435. /* copy results to buffers */
  436. - if (eay_bn2v(pub, dh->pub_key) < 0)
  437. + BIGNUM *pub_key, *priv_key;
  438. + DH_get0_key(dh, (const BIGNUM**) &pub_key, (const BIGNUM**) &priv_key);
  439. + if (eay_bn2v(pub, pub_key) < 0)
  440. goto end;
  441. - if (eay_bn2v(priv, dh->priv_key) < 0) {
  442. + if (eay_bn2v(priv, priv_key) < 0) {
  443. vfree(*pub);
  444. goto end;
  445. }
  446. @@ -2306,6 +2304,8 @@ end:
  447. DH_free(dh);
  448. if (p != 0)
  449. BN_free(p);
  450. + if (BNg != 0)
  451. + BN_free(BNg);
  452. return(error);
  453. }
  454. @@ -2319,6 +2319,10 @@ eay_dh_compute(prime, g, pub, priv, pub2, key)
  455. int l;
  456. unsigned char *v = NULL;
  457. int error = -1;
  458. + BIGNUM *p = BN_new();
  459. + BIGNUM *BNg = BN_new();
  460. + BIGNUM *pub_key = BN_new();
  461. + BIGNUM *priv_key = BN_new();
  462. /* make public number to compute */
  463. if (eay_v2bn(&dh_pub, pub2) < 0)
  464. @@ -2327,19 +2331,21 @@ eay_dh_compute(prime, g, pub, priv, pub2, key)
  465. /* make DH structure */
  466. if ((dh = DH_new()) == NULL)
  467. goto end;
  468. - if (eay_v2bn(&dh->p, prime) < 0)
  469. + if (p == NULL || BNg == NULL || pub_key == NULL || priv_key == NULL)
  470. goto end;
  471. - if (eay_v2bn(&dh->pub_key, pub) < 0)
  472. +
  473. + if (eay_v2bn(&p, prime) < 0)
  474. goto end;
  475. - if (eay_v2bn(&dh->priv_key, priv) < 0)
  476. + if (eay_v2bn(&pub_key, pub) < 0)
  477. goto end;
  478. - dh->length = pub2->l * 8;
  479. -
  480. - dh->g = NULL;
  481. - if ((dh->g = BN_new()) == NULL)
  482. + if (eay_v2bn(&priv_key, priv) < 0)
  483. goto end;
  484. - if (!BN_set_word(dh->g, g))
  485. + if (!BN_set_word(BNg, g))
  486. goto end;
  487. + DH_set0_key(dh, pub_key, priv_key);
  488. + DH_set_length(dh, pub2->l * 8);
  489. + DH_set0_pqg(dh, p, NULL, BNg);
  490. + pub_key = priv_key = p = BNg = NULL;
  491. if ((v = racoon_calloc(prime->l, sizeof(u_char))) == NULL)
  492. goto end;
  493. @@ -2350,6 +2356,14 @@ eay_dh_compute(prime, g, pub, priv, pub2, key)
  494. error = 0;
  495. end:
  496. + if (p != NULL)
  497. + BN_free(p);
  498. + if (BNg != NULL)
  499. + BN_free(BNg);
  500. + if (pub_key != NULL)
  501. + BN_free(pub_key);
  502. + if (priv_key != NULL)
  503. + BN_free(priv_key);
  504. if (dh_pub != NULL)
  505. BN_free(dh_pub);
  506. if (dh != NULL)
  507. @@ -2400,12 +2414,14 @@ eay_bn2v(var, bn)
  508. void
  509. eay_init()
  510. {
  511. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  512. OpenSSL_add_all_algorithms();
  513. ERR_load_crypto_strings();
  514. #ifdef HAVE_OPENSSL_ENGINE_H
  515. ENGINE_load_builtin_engines();
  516. ENGINE_register_all_complete();
  517. #endif
  518. +#endif
  519. }
  520. vchar_t *
  521. @@ -2504,8 +2520,7 @@ binbuf_pubkey2rsa(vchar_t *binbuf)
  522. goto out;
  523. }
  524. - rsa_pub->n = mod;
  525. - rsa_pub->e = exp;
  526. + RSA_set0_key(rsa_pub, mod, exp, NULL);
  527. out:
  528. return rsa_pub;
  529. @@ -2582,5 +2597,5 @@ eay_random()
  530. const char *
  531. eay_version()
  532. {
  533. - return SSLeay_version(SSLEAY_VERSION);
  534. + return OpenSSL_version(OPENSSL_VERSION);
  535. }
  536. diff --git a/src/racoon/crypto_openssl.h b/src/racoon/crypto_openssl.h
  537. index 66fac73..ee5b765 100644
  538. --- a/src/racoon/crypto_openssl.h
  539. +++ b/src/racoon/crypto_openssl.h
  540. @@ -124,7 +124,7 @@ extern vchar_t *eay_aes_decrypt __P((vchar_t *, vchar_t *, vchar_t *));
  541. extern int eay_aes_weakkey __P((vchar_t *));
  542. extern int eay_aes_keylen __P((int));
  543. -#if defined(HAVE_OPENSSL_CAMELLIA_H)
  544. +#if defined(HAVE_OPENSSL_CAMELLIA_H) && ! defined(OPENSSL_NO_CAMELLIA)
  545. /* Camellia */
  546. extern vchar_t *eay_camellia_encrypt __P((vchar_t *, vchar_t *, vchar_t *));
  547. extern vchar_t *eay_camellia_decrypt __P((vchar_t *, vchar_t *, vchar_t *));
  548. diff --git a/src/racoon/eaytest.c b/src/racoon/eaytest.c
  549. index 1474bdc..ae09db3 100644
  550. --- a/src/racoon/eaytest.c
  551. +++ b/src/racoon/eaytest.c
  552. @@ -62,6 +62,7 @@
  553. #include "dhgroup.h"
  554. #include "crypto_openssl.h"
  555. #include "gnuc.h"
  556. +#include "openssl_compat.h"
  557. #include "package_version.h"
  558. @@ -103,7 +104,7 @@ rsa_verify_with_pubkey(src, sig, pubkey_txt)
  559. printf ("PEM_read_PUBKEY(): %s\n", eay_strerror());
  560. return -1;
  561. }
  562. - error = eay_check_rsasign(src, sig, evp->pkey.rsa);
  563. + error = eay_check_rsasign(src, sig, EVP_PKEY_get0_RSA(evp));
  564. return error;
  565. }
  566. @@ -698,7 +699,7 @@ ciphertest(ac, av)
  567. eay_cast_encrypt, eay_cast_decrypt) < 0)
  568. return -1;
  569. -#ifdef HAVE_OPENSSL_IDEA_H
  570. +#if defined(HAVE_OPENSSL_IDEA_H) && ! defined(OPENSSL_NO_IDEA)
  571. if (ciphertest_1 ("IDEA",
  572. &data, 8,
  573. &key, key.l,
  574. @@ -715,7 +716,7 @@ ciphertest(ac, av)
  575. eay_rc5_encrypt, eay_rc5_decrypt) < 0)
  576. return -1;
  577. #endif
  578. -#if defined(HAVE_OPENSSL_CAMELLIA_H)
  579. +#if defined(HAVE_OPENSSL_CAMELLIA_H) && ! defined(OPENSSL_NO_CAMELLIA)
  580. if (ciphertest_1 ("CAMELLIA",
  581. &data, 16,
  582. &key, key.l,
  583. diff --git a/src/racoon/ipsec_doi.c b/src/racoon/ipsec_doi.c
  584. index 84a4c71..b52469f 100644
  585. --- a/src/racoon/ipsec_doi.c
  586. +++ b/src/racoon/ipsec_doi.c
  587. @@ -715,7 +715,7 @@ out:
  588. /* key length must not be specified on some algorithms */
  589. if (keylen) {
  590. if (sa->enctype == OAKLEY_ATTR_ENC_ALG_DES
  591. -#ifdef HAVE_OPENSSL_IDEA_H
  592. +#if defined(HAVE_OPENSSL_IDEA_H) && ! defined(OPENSSL_NO_IDEA)
  593. || sa->enctype == OAKLEY_ATTR_ENC_ALG_IDEA
  594. #endif
  595. || sa->enctype == OAKLEY_ATTR_ENC_ALG_3DES) {
  596. diff --git a/src/racoon/openssl_compat.c b/src/racoon/openssl_compat.c
  597. new file mode 100644
  598. index 0000000..864b5fb
  599. --- /dev/null
  600. +++ b/src/racoon/openssl_compat.c
  601. @@ -0,0 +1,213 @@
  602. +/*
  603. + * Copyright 2016 The OpenSSL Project Authors. All Rights Reserved.
  604. + *
  605. + * Licensed under the OpenSSL license (the "License"). You may not use
  606. + * this file except in compliance with the License. You can obtain a copy
  607. + * in the file LICENSE in the source distribution or at
  608. + * https://www.openssl.org/source/license.html
  609. + */
  610. +
  611. +#include "openssl_compat.h"
  612. +
  613. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  614. +
  615. +#include <string.h>
  616. +
  617. +static void *OPENSSL_zalloc(size_t num)
  618. +{
  619. + void *ret = OPENSSL_malloc(num);
  620. +
  621. + if (ret != NULL)
  622. + memset(ret, 0, num);
  623. + return ret;
  624. +}
  625. +
  626. +int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
  627. +{
  628. + /* If the fields n and e in r are NULL, the corresponding input
  629. + * parameters MUST be non-NULL for n and e. d may be
  630. + * left NULL (in case only the public key is used).
  631. + */
  632. + if ((r->n == NULL && n == NULL)
  633. + || (r->e == NULL && e == NULL))
  634. + return 0;
  635. +
  636. + if (n != NULL) {
  637. + BN_free(r->n);
  638. + r->n = n;
  639. + }
  640. + if (e != NULL) {
  641. + BN_free(r->e);
  642. + r->e = e;
  643. + }
  644. + if (d != NULL) {
  645. + BN_free(r->d);
  646. + r->d = d;
  647. + }
  648. +
  649. + return 1;
  650. +}
  651. +
  652. +int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
  653. +{
  654. + /* If the fields p and q in r are NULL, the corresponding input
  655. + * parameters MUST be non-NULL.
  656. + */
  657. + if ((r->p == NULL && p == NULL)
  658. + || (r->q == NULL && q == NULL))
  659. + return 0;
  660. +
  661. + if (p != NULL) {
  662. + BN_free(r->p);
  663. + r->p = p;
  664. + }
  665. + if (q != NULL) {
  666. + BN_free(r->q);
  667. + r->q = q;
  668. + }
  669. +
  670. + return 1;
  671. +}
  672. +
  673. +int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
  674. +{
  675. + /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
  676. + * parameters MUST be non-NULL.
  677. + */
  678. + if ((r->dmp1 == NULL && dmp1 == NULL)
  679. + || (r->dmq1 == NULL && dmq1 == NULL)
  680. + || (r->iqmp == NULL && iqmp == NULL))
  681. + return 0;
  682. +
  683. + if (dmp1 != NULL) {
  684. + BN_free(r->dmp1);
  685. + r->dmp1 = dmp1;
  686. + }
  687. + if (dmq1 != NULL) {
  688. + BN_free(r->dmq1);
  689. + r->dmq1 = dmq1;
  690. + }
  691. + if (iqmp != NULL) {
  692. + BN_free(r->iqmp);
  693. + r->iqmp = iqmp;
  694. + }
  695. +
  696. + return 1;
  697. +}
  698. +
  699. +void RSA_get0_key(const RSA *r,
  700. + const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
  701. +{
  702. + if (n != NULL)
  703. + *n = r->n;
  704. + if (e != NULL)
  705. + *e = r->e;
  706. + if (d != NULL)
  707. + *d = r->d;
  708. +}
  709. +
  710. +void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
  711. +{
  712. + if (p != NULL)
  713. + *p = r->p;
  714. + if (q != NULL)
  715. + *q = r->q;
  716. +}
  717. +
  718. +void RSA_get0_crt_params(const RSA *r,
  719. + const BIGNUM **dmp1, const BIGNUM **dmq1,
  720. + const BIGNUM **iqmp)
  721. +{
  722. + if (dmp1 != NULL)
  723. + *dmp1 = r->dmp1;
  724. + if (dmq1 != NULL)
  725. + *dmq1 = r->dmq1;
  726. + if (iqmp != NULL)
  727. + *iqmp = r->iqmp;
  728. +}
  729. +
  730. +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
  731. +{
  732. + /* If the fields p and g in d are NULL, the corresponding input
  733. + * parameters MUST be non-NULL. q may remain NULL.
  734. + */
  735. + if ((dh->p == NULL && p == NULL)
  736. + || (dh->g == NULL && g == NULL))
  737. + return 0;
  738. +
  739. + if (p != NULL) {
  740. + BN_free(dh->p);
  741. + dh->p = p;
  742. + }
  743. + if (q != NULL) {
  744. + BN_free(dh->q);
  745. + dh->q = q;
  746. + }
  747. + if (g != NULL) {
  748. + BN_free(dh->g);
  749. + dh->g = g;
  750. + }
  751. +
  752. + if (q != NULL) {
  753. + dh->length = BN_num_bits(q);
  754. + }
  755. +
  756. + return 1;
  757. +}
  758. +
  759. +void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
  760. +{
  761. + if (pub_key != NULL)
  762. + *pub_key = dh->pub_key;
  763. + if (priv_key != NULL)
  764. + *priv_key = dh->priv_key;
  765. +}
  766. +
  767. +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
  768. +{
  769. + /* If the field pub_key in dh is NULL, the corresponding input
  770. + * parameters MUST be non-NULL. The priv_key field may
  771. + * be left NULL.
  772. + */
  773. + if (dh->pub_key == NULL && pub_key == NULL)
  774. + return 0;
  775. +
  776. + if (pub_key != NULL) {
  777. + BN_free(dh->pub_key);
  778. + dh->pub_key = pub_key;
  779. + }
  780. + if (priv_key != NULL) {
  781. + BN_free(dh->priv_key);
  782. + dh->priv_key = priv_key;
  783. + }
  784. +
  785. + return 1;
  786. +}
  787. +
  788. +int DH_set_length(DH *dh, long length)
  789. +{
  790. + dh->length = length;
  791. + return 1;
  792. +}
  793. +
  794. +HMAC_CTX *HMAC_CTX_new(void)
  795. +{
  796. + return OPENSSL_zalloc(sizeof(HMAC_CTX));
  797. +}
  798. +
  799. +void HMAC_CTX_free(HMAC_CTX *ctx)
  800. +{
  801. + HMAC_CTX_cleanup(ctx);
  802. + OPENSSL_free(ctx);
  803. +}
  804. +
  805. +RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
  806. +{
  807. + if (pkey->type != EVP_PKEY_RSA) {
  808. + return NULL;
  809. + }
  810. + return pkey->pkey.rsa;
  811. +}
  812. +
  813. +
  814. +#endif /* OPENSSL_VERSION_NUMBER */
  815. diff --git a/src/racoon/openssl_compat.h b/src/racoon/openssl_compat.h
  816. new file mode 100644
  817. index 0000000..9e152c2
  818. --- /dev/null
  819. +++ b/src/racoon/openssl_compat.h
  820. @@ -0,0 +1,45 @@
  821. +#ifndef OPENSSL_COMPAT_H
  822. +#define OPENSSL_COMPAT_H
  823. +
  824. +#include <openssl/opensslv.h>
  825. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  826. +
  827. +#include <openssl/rsa.h>
  828. +#include <openssl/dh.h>
  829. +#include <openssl/evp.h>
  830. +#include <openssl/hmac.h>
  831. +
  832. +int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d);
  833. +int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q);
  834. +int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp);
  835. +void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d);
  836. +void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q);
  837. +void RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp);
  838. +
  839. +int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g);
  840. +void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key);
  841. +int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key);
  842. +int DH_set_length(DH *dh, long length);
  843. +
  844. +HMAC_CTX *HMAC_CTX_new(void);
  845. +void HMAC_CTX_free(HMAC_CTX* ctx);
  846. +
  847. +RSA *EVP_PKEY_get0_RSA(EVP_PKEY *pkey);
  848. +
  849. +#define ASN1_STRING_length(s) s->length
  850. +#define ASN1_STRING_get0_data(s) s->data
  851. +
  852. +#define X509_get_subject_name(x) x->cert_info->subject
  853. +#define X509_get_issuer_name(x) x->cert_info->issuer
  854. +#define X509_NAME_ENTRY_get_data(n) n->value
  855. +#define X509_NAME_ENTRY_get_object(n) n->object
  856. +#define X509_STORE_CTX_get_current_cert(ctx) ctx->current_cert
  857. +#define X509_STORE_CTX_get_error(ctx) ctx->error
  858. +#define X509_STORE_CTX_get_error_depth(ctx) ctx->error_depth
  859. +
  860. +#define OPENSSL_VERSION SSLEAY_VERSION
  861. +#define OpenSSL_version SSLeay_version
  862. +
  863. +#endif /* OPENSSL_VERSION_NUMBER */
  864. +
  865. +#endif /* OPENSSL_COMPAT_H */
  866. diff --git a/src/racoon/plainrsa-gen.c b/src/racoon/plainrsa-gen.c
  867. index cad1861..b949b08 100644
  868. --- a/src/racoon/plainrsa-gen.c
  869. +++ b/src/racoon/plainrsa-gen.c
  870. @@ -60,6 +60,7 @@
  871. #include "vmbuf.h"
  872. #include "plog.h"
  873. #include "crypto_openssl.h"
  874. +#include "openssl_compat.h"
  875. #include "package_version.h"
  876. @@ -90,12 +91,14 @@ mix_b64_pubkey(const RSA *key)
  877. char *binbuf;
  878. long binlen, ret;
  879. vchar_t *res;
  880. -
  881. - binlen = 1 + BN_num_bytes(key->e) + BN_num_bytes(key->n);
  882. + const BIGNUM *e, *n;
  883. +
  884. + RSA_get0_key(key, &n, &e, NULL);
  885. + binlen = 1 + BN_num_bytes(e) + BN_num_bytes(n);
  886. binbuf = malloc(binlen);
  887. memset(binbuf, 0, binlen);
  888. - binbuf[0] = BN_bn2bin(key->e, (unsigned char *) &binbuf[1]);
  889. - ret = BN_bn2bin(key->n, (unsigned char *) (&binbuf[binbuf[0] + 1]));
  890. + binbuf[0] = BN_bn2bin(e, (unsigned char *) &binbuf[1]);
  891. + ret = BN_bn2bin(n, (unsigned char *) (&binbuf[binbuf[0] + 1]));
  892. if (1 + binbuf[0] + ret != binlen) {
  893. plog(LLV_ERROR, LOCATION, NULL,
  894. "Pubkey generation failed. This is really strange...\n");
  895. @@ -131,16 +134,20 @@ print_rsa_key(FILE *fp, const RSA *key)
  896. fprintf(fp, "# : PUB 0s%s\n", pubkey64->v);
  897. fprintf(fp, ": RSA\t{\n");
  898. - fprintf(fp, "\t# RSA %d bits\n", BN_num_bits(key->n));
  899. + const BIGNUM *n, *e, *d, *p, *q, *dmp1, *dmq1, *iqmp;
  900. + RSA_get0_key(key, &n, &e, &d);
  901. + RSA_get0_factors(key, &p, &q);
  902. + RSA_get0_crt_params(key, &dmp1, &dmq1, &iqmp);
  903. + fprintf(fp, "\t# RSA %d bits\n", BN_num_bits(n));
  904. fprintf(fp, "\t# pubkey=0s%s\n", pubkey64->v);
  905. - fprintf(fp, "\tModulus: 0x%s\n", lowercase(BN_bn2hex(key->n)));
  906. - fprintf(fp, "\tPublicExponent: 0x%s\n", lowercase(BN_bn2hex(key->e)));
  907. - fprintf(fp, "\tPrivateExponent: 0x%s\n", lowercase(BN_bn2hex(key->d)));
  908. - fprintf(fp, "\tPrime1: 0x%s\n", lowercase(BN_bn2hex(key->p)));
  909. - fprintf(fp, "\tPrime2: 0x%s\n", lowercase(BN_bn2hex(key->q)));
  910. - fprintf(fp, "\tExponent1: 0x%s\n", lowercase(BN_bn2hex(key->dmp1)));
  911. - fprintf(fp, "\tExponent2: 0x%s\n", lowercase(BN_bn2hex(key->dmq1)));
  912. - fprintf(fp, "\tCoefficient: 0x%s\n", lowercase(BN_bn2hex(key->iqmp)));
  913. + fprintf(fp, "\tModulus: 0x%s\n", lowercase(BN_bn2hex(n)));
  914. + fprintf(fp, "\tPublicExponent: 0x%s\n", lowercase(BN_bn2hex(e)));
  915. + fprintf(fp, "\tPrivateExponent: 0x%s\n", lowercase(BN_bn2hex(d)));
  916. + fprintf(fp, "\tPrime1: 0x%s\n", lowercase(BN_bn2hex(p)));
  917. + fprintf(fp, "\tPrime2: 0x%s\n", lowercase(BN_bn2hex(q)));
  918. + fprintf(fp, "\tExponent1: 0x%s\n", lowercase(BN_bn2hex(dmp1)));
  919. + fprintf(fp, "\tExponent2: 0x%s\n", lowercase(BN_bn2hex(dmq1)));
  920. + fprintf(fp, "\tCoefficient: 0x%s\n", lowercase(BN_bn2hex(iqmp)));
  921. fprintf(fp, " }\n");
  922. vfree(pubkey64);
  923. @@ -203,11 +210,13 @@ int
  924. gen_rsa_key(FILE *fp, size_t bits, unsigned long exp)
  925. {
  926. int ret;
  927. - RSA *key;
  928. + RSA *key = RSA_new();
  929. + BIGNUM *e = BN_new();
  930. - key = RSA_generate_key(bits, exp, NULL, NULL);
  931. - if (!key) {
  932. + BN_set_word(e, exp);
  933. + if (! RSA_generate_key_ex(key, bits, e, NULL)) {
  934. fprintf(stderr, "RSA_generate_key(): %s\n", eay_strerror());
  935. + RSA_free(key);
  936. return -1;
  937. }
  938. diff --git a/src/racoon/prsa_par.y b/src/racoon/prsa_par.y
  939. index 1987e4d..27ce4c6 100644
  940. --- a/src/racoon/prsa_par.y
  941. +++ b/src/racoon/prsa_par.y
  942. @@ -68,6 +68,7 @@
  943. #include "isakmp_var.h"
  944. #include "handler.h"
  945. #include "crypto_openssl.h"
  946. +#include "openssl_compat.h"
  947. #include "sockmisc.h"
  948. #include "rsalist.h"
  949. @@ -85,7 +86,18 @@ char *prsa_cur_fname = NULL;
  950. struct genlist *prsa_cur_list = NULL;
  951. enum rsa_key_type prsa_cur_type = RSA_TYPE_ANY;
  952. -static RSA *rsa_cur;
  953. +struct my_rsa_st {
  954. + BIGNUM *n;
  955. + BIGNUM *e;
  956. + BIGNUM *d;
  957. + BIGNUM *p;
  958. + BIGNUM *q;
  959. + BIGNUM *dmp1;
  960. + BIGNUM *dmq1;
  961. + BIGNUM *iqmp;
  962. +};
  963. +
  964. +static struct my_rsa_st *rsa_cur;
  965. void
  966. prsaerror(const char *s, ...)
  967. @@ -201,8 +213,12 @@ rsa_statement:
  968. rsa_cur->iqmp = NULL;
  969. }
  970. }
  971. - $$ = rsa_cur;
  972. - rsa_cur = RSA_new();
  973. + RSA * rsa_tmp = RSA_new();
  974. + RSA_set0_key(rsa_tmp, rsa_cur->n, rsa_cur->e, rsa_cur->d);
  975. + RSA_set0_factors(rsa_tmp, rsa_cur->p, rsa_cur->q);
  976. + RSA_set0_crt_params(rsa_tmp, rsa_cur->dmp1, rsa_cur->dmq1, rsa_cur->iqmp);
  977. + $$ = rsa_tmp;
  978. + memset(rsa_cur, 0, sizeof(struct my_rsa_st));
  979. }
  980. | TAG_PUB BASE64
  981. {
  982. @@ -351,10 +367,12 @@ prsa_parse_file(struct genlist *list, char *fname, enum rsa_key_type type)
  983. prsa_cur_fname = fname;
  984. prsa_cur_list = list;
  985. prsa_cur_type = type;
  986. - rsa_cur = RSA_new();
  987. + rsa_cur = malloc(sizeof(struct my_rsa_st));
  988. + memset(rsa_cur, 0, sizeof(struct my_rsa_st));
  989. ret = prsaparse();
  990. if (rsa_cur) {
  991. - RSA_free(rsa_cur);
  992. + memset(rsa_cur, 0, sizeof(struct my_rsa_st));
  993. + free(rsa_cur);
  994. rsa_cur = NULL;
  995. }
  996. fclose (fp);
  997. diff --git a/src/racoon/rsalist.c b/src/racoon/rsalist.c
  998. index f152c82..96e8363 100644
  999. --- a/src/racoon/rsalist.c
  1000. +++ b/src/racoon/rsalist.c
  1001. @@ -52,6 +52,7 @@
  1002. #include "genlist.h"
  1003. #include "remoteconf.h"
  1004. #include "crypto_openssl.h"
  1005. +#include "openssl_compat.h"
  1006. #ifndef LIST_FIRST
  1007. #define LIST_FIRST(head) ((head)->lh_first)
  1008. @@ -98,7 +99,9 @@ rsa_key_dup(struct rsa_key *key)
  1009. return NULL;
  1010. if (key->rsa) {
  1011. - new->rsa = key->rsa->d != NULL ? RSAPrivateKey_dup(key->rsa) : RSAPublicKey_dup(key->rsa);
  1012. + const BIGNUM *d;
  1013. + RSA_get0_key(key->rsa, NULL, NULL, &d);
  1014. + new->rsa = (d != NULL ? RSAPrivateKey_dup(key->rsa) : RSAPublicKey_dup(key->rsa));
  1015. if (new->rsa == NULL)
  1016. goto dup_error;
  1017. }
  1018. --
  1019. 2.16.1