0001-Adapt-to-OpenSSL-1.1.0.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. From b3747e625780be90dcff11c2d9e91048016bb4d0 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
  3. Date: Thu, 13 Oct 2016 18:14:17 +0200
  4. Subject: [PATCH] Adapt to OpenSSL 1.1.0
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. OpenSSL 1.1.0 hid structure internals and provided methods for getting
  9. and settting the internal values. This patch modifes the code so that
  10. it can be built with OpenSSL 1.1.0 as well as with the older one.
  11. CPAN RT#117481
  12. Signed-off-by: Petr Písař <ppisar@redhat.com>
  13. ---
  14. RSA.xs | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
  15. 1 file changed, 73 insertions(+), 16 deletions(-)
  16. diff --git a/RSA.xs b/RSA.xs
  17. index de512e7..9bf6f01 100644
  18. --- a/RSA.xs
  19. +++ b/RSA.xs
  20. @@ -49,7 +49,13 @@ void croakSsl(char* p_file, int p_line)
  21. char _is_private(rsaData* p_rsa)
  22. {
  23. - return(p_rsa->rsa->d != NULL);
  24. + const BIGNUM *d;
  25. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  26. + d = p_rsa->rsa->d;
  27. +#else
  28. + RSA_get0_key(p_rsa->rsa, NULL, NULL, &d);
  29. +#endif
  30. + return(d != NULL);
  31. }
  32. SV* make_rsa_obj(SV* p_proto, RSA* p_rsa)
  33. @@ -136,7 +142,7 @@ unsigned char* get_message_digest(SV* text_SV, int hash_method)
  34. }
  35. }
  36. -SV* bn2sv(BIGNUM* p_bn)
  37. +SV* bn2sv(const BIGNUM* p_bn)
  38. {
  39. return p_bn != NULL
  40. ? sv_2mortal(newSViv((IV) BN_dup(p_bn)))
  41. @@ -317,6 +323,9 @@ _new_key_from_parameters(proto, n, e, d, p, q)
  42. BN_CTX* ctx;
  43. BIGNUM* p_minus_1 = NULL;
  44. BIGNUM* q_minus_1 = NULL;
  45. + BIGNUM* dmp1 = NULL;
  46. + BIGNUM* dmq1 = NULL;
  47. + BIGNUM* iqmp = NULL;
  48. int error;
  49. CODE:
  50. {
  51. @@ -325,8 +334,10 @@ _new_key_from_parameters(proto, n, e, d, p, q)
  52. croak("At least a modulous and public key must be provided");
  53. }
  54. CHECK_OPEN_SSL(rsa = RSA_new());
  55. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  56. rsa->n = n;
  57. rsa->e = e;
  58. +#endif
  59. if (p || q)
  60. {
  61. error = 0;
  62. @@ -341,8 +352,12 @@ _new_key_from_parameters(proto, n, e, d, p, q)
  63. q = BN_new();
  64. THROW(BN_div(q, NULL, n, p, ctx));
  65. }
  66. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  67. rsa->p = p;
  68. rsa->q = q;
  69. +#else
  70. + THROW(RSA_set0_factors(rsa, p, q));
  71. +#endif
  72. THROW(p_minus_1 = BN_new());
  73. THROW(BN_sub(p_minus_1, p, BN_value_one()));
  74. THROW(q_minus_1 = BN_new());
  75. @@ -353,17 +368,32 @@ _new_key_from_parameters(proto, n, e, d, p, q)
  76. THROW(BN_mul(d, p_minus_1, q_minus_1, ctx));
  77. THROW(BN_mod_inverse(d, e, d, ctx));
  78. }
  79. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  80. rsa->d = d;
  81. - THROW(rsa->dmp1 = BN_new());
  82. - THROW(BN_mod(rsa->dmp1, d, p_minus_1, ctx));
  83. - THROW(rsa->dmq1 = BN_new());
  84. - THROW(BN_mod(rsa->dmq1, d, q_minus_1, ctx));
  85. - THROW(rsa->iqmp = BN_new());
  86. - THROW(BN_mod_inverse(rsa->iqmp, q, p, ctx));
  87. +#else
  88. + THROW(RSA_set0_key(rsa, n, e, d));
  89. +#endif
  90. + THROW(dmp1 = BN_new());
  91. + THROW(BN_mod(dmp1, d, p_minus_1, ctx));
  92. + THROW(dmq1 = BN_new());
  93. + THROW(BN_mod(dmq1, d, q_minus_1, ctx));
  94. + THROW(iqmp = BN_new());
  95. + THROW(BN_mod_inverse(iqmp, q, p, ctx));
  96. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  97. + rsa->dmp1 = dmp1;
  98. + rsa->dmq1 = dmq1;
  99. + rsa->iqmp = iqmp;
  100. +#else
  101. + THROW(RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp));
  102. +#endif
  103. + dmp1 = dmq1 = iqmp = NULL;
  104. THROW(RSA_check_key(rsa) == 1);
  105. err:
  106. if (p_minus_1) BN_clear_free(p_minus_1);
  107. if (q_minus_1) BN_clear_free(q_minus_1);
  108. + if (dmp1) BN_clear_free(dmp1);
  109. + if (dmq1) BN_clear_free(dmq1);
  110. + if (iqmp) BN_clear_free(iqmp);
  111. if (ctx) BN_CTX_free(ctx);
  112. if (error)
  113. {
  114. @@ -373,7 +403,11 @@ _new_key_from_parameters(proto, n, e, d, p, q)
  115. }
  116. else
  117. {
  118. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  119. rsa->d = d;
  120. +#else
  121. + CHECK_OPEN_SSL(RSA_set0_key(rsa, n, e, d));
  122. +#endif
  123. }
  124. RETVAL = make_rsa_obj(proto, rsa);
  125. }
  126. @@ -383,18 +417,41 @@ _new_key_from_parameters(proto, n, e, d, p, q)
  127. void
  128. _get_key_parameters(p_rsa)
  129. rsaData* p_rsa;
  130. +PREINIT:
  131. + const BIGNUM* n;
  132. + const BIGNUM* e;
  133. + const BIGNUM* d;
  134. + const BIGNUM* p;
  135. + const BIGNUM* q;
  136. + const BIGNUM* dmp1;
  137. + const BIGNUM* dmq1;
  138. + const BIGNUM* iqmp;
  139. PPCODE:
  140. {
  141. RSA* rsa;
  142. rsa = p_rsa->rsa;
  143. - XPUSHs(bn2sv(rsa->n));
  144. - XPUSHs(bn2sv(rsa->e));
  145. - XPUSHs(bn2sv(rsa->d));
  146. - XPUSHs(bn2sv(rsa->p));
  147. - XPUSHs(bn2sv(rsa->q));
  148. - XPUSHs(bn2sv(rsa->dmp1));
  149. - XPUSHs(bn2sv(rsa->dmq1));
  150. - XPUSHs(bn2sv(rsa->iqmp));
  151. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  152. + n = rsa->n;
  153. + e = rsa->e;
  154. + d = rsa->d;
  155. + p = rsa->p;
  156. + q = rsa->q;
  157. + dmp1 = rsa->dmp1;
  158. + dmq1 = rsa->dmq1;
  159. + iqmp = rsa->iqmp;
  160. +#else
  161. + RSA_get0_key(rsa, &n, &e, &d);
  162. + RSA_get0_factors(rsa, &p, &q);
  163. + RSA_get0_crt_params(rsa, &dmp1, &dmq1, &iqmp);
  164. +#endif
  165. + XPUSHs(bn2sv(n));
  166. + XPUSHs(bn2sv(e));
  167. + XPUSHs(bn2sv(d));
  168. + XPUSHs(bn2sv(p));
  169. + XPUSHs(bn2sv(q));
  170. + XPUSHs(bn2sv(dmp1));
  171. + XPUSHs(bn2sv(dmq1));
  172. + XPUSHs(bn2sv(iqmp));
  173. }
  174. SV*
  175. --
  176. 2.7.4