openssl-1.0.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. From 46b84175dfac14a92fd6bcf3b03bc3c3715ab6cb Mon Sep 17 00:00:00 2001
  2. From: nahi <nahi@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>
  3. Date: Sat, 6 Mar 2010 21:47:30 +0000
  4. Subject: [PATCH] backport the commit from trunk:
  5. Sun Feb 28 11:49:35 2010 NARUSE, Yui <naruse@ruby-lang.org>
  6. * openssl/ossl.c (OSSL_IMPL_SK2ARY): for OpenSSL 1.0.
  7. patched by Jeroen van Meeuwen at [ruby-core:25210]
  8. fixed by Nobuyoshi Nakada [ruby-core:25238],
  9. Hongli Lai [ruby-core:27417],
  10. and Motohiro KOSAKI [ruby-core:28063]
  11. * ext/openssl/ossl_ssl.c (ossl_ssl_method_tab),
  12. (ossl_ssl_cipher_to_ary): constified.
  13. * ext/openssl/ossl_pkcs7.c (pkcs7_get_certs, pkcs7_get_crls):
  14. split pkcs7_get_certs_or_crls.
  15. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@26838 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  16. ---
  17. ext/openssl/ossl.c | 6 +++---
  18. ext/openssl/ossl.h | 7 +++++++
  19. ext/openssl/ossl_pkcs7.c | 40 ++++++++++++++++++++++++++++++----------
  20. ext/openssl/ossl_ssl.c | 4 ++--
  21. ext/openssl/ossl_x509attr.c | 5 +++--
  22. ext/openssl/ossl_x509crl.c | 4 ++--
  23. 6 files changed, 47 insertions(+), 19 deletions(-)
  24. diff --git a/ext/openssl/ossl.c b/ext/openssl/ossl.c
  25. index d4a2dc1..85ba654 100644
  26. --- a/ext/openssl/ossl.c
  27. +++ b/ext/openssl/ossl.c
  28. @@ -92,7 +92,7 @@ ossl_x509_ary2sk(VALUE ary)
  29. #define OSSL_IMPL_SK2ARY(name, type) \
  30. VALUE \
  31. -ossl_##name##_sk2ary(STACK *sk) \
  32. +ossl_##name##_sk2ary(STACK_OF(type) *sk) \
  33. { \
  34. type *t; \
  35. int i, num; \
  36. @@ -102,7 +102,7 @@ ossl_##name##_sk2ary(STACK *sk) \
  37. OSSL_Debug("empty sk!"); \
  38. return Qnil; \
  39. } \
  40. - num = sk_num(sk); \
  41. + num = sk_##type##_num(sk); \
  42. if (num < 0) { \
  43. OSSL_Debug("items in sk < -1???"); \
  44. return rb_ary_new(); \
  45. @@ -110,7 +110,7 @@ ossl_##name##_sk2ary(STACK *sk) \
  46. ary = rb_ary_new2(num); \
  47. \
  48. for (i=0; i<num; i++) { \
  49. - t = (type *)sk_value(sk, i); \
  50. + t = sk_##type##_value(sk, i); \
  51. rb_ary_push(ary, ossl_##name##_new(t)); \
  52. } \
  53. return ary; \
  54. diff --git a/ext/openssl/ossl.h b/ext/openssl/ossl.h
  55. index 9215dc4..d0edb7d 100644
  56. --- a/ext/openssl/ossl.h
  57. +++ b/ext/openssl/ossl.h
  58. @@ -108,6 +108,13 @@ extern VALUE eOSSLError;
  59. } while (0)
  60. /*
  61. + * Compatibility
  62. + */
  63. +#if OPENSSL_VERSION_NUMBER >= 0x10000000L
  64. +#define STACK _STACK
  65. +#endif
  66. +
  67. +/*
  68. * String to HEXString conversion
  69. */
  70. int string2hex(const unsigned char *, int, char **, int *);
  71. diff --git a/ext/openssl/ossl_pkcs7.c b/ext/openssl/ossl_pkcs7.c
  72. index fe1ef7c..b0cc656 100644
  73. --- a/ext/openssl/ossl_pkcs7.c
  74. +++ b/ext/openssl/ossl_pkcs7.c
  75. @@ -572,12 +572,11 @@ ossl_pkcs7_add_certificate(VALUE self, VALUE cert)
  76. return self;
  77. }
  78. -static STACK *
  79. -pkcs7_get_certs_or_crls(VALUE self, int want_certs)
  80. +static STACK_OF(X509) *
  81. +pkcs7_get_certs(VALUE self)
  82. {
  83. PKCS7 *pkcs7;
  84. STACK_OF(X509) *certs;
  85. - STACK_OF(X509_CRL) *crls;
  86. int i;
  87. GetPKCS7(self, pkcs7);
  88. @@ -585,17 +584,38 @@ pkcs7_get_certs_or_crls(VALUE self, int want_certs)
  89. switch(i){
  90. case NID_pkcs7_signed:
  91. certs = pkcs7->d.sign->cert;
  92. - crls = pkcs7->d.sign->crl;
  93. break;
  94. case NID_pkcs7_signedAndEnveloped:
  95. certs = pkcs7->d.signed_and_enveloped->cert;
  96. + break;
  97. + default:
  98. + certs = NULL;
  99. + }
  100. +
  101. + return certs;
  102. +}
  103. +
  104. +static STACK_OF(X509_CRL) *
  105. +pkcs7_get_crls(VALUE self)
  106. +{
  107. + PKCS7 *pkcs7;
  108. + STACK_OF(X509_CRL) *crls;
  109. + int i;
  110. +
  111. + GetPKCS7(self, pkcs7);
  112. + i = OBJ_obj2nid(pkcs7->type);
  113. + switch(i){
  114. + case NID_pkcs7_signed:
  115. + crls = pkcs7->d.sign->crl;
  116. + break;
  117. + case NID_pkcs7_signedAndEnveloped:
  118. crls = pkcs7->d.signed_and_enveloped->crl;
  119. break;
  120. default:
  121. - certs = crls = NULL;
  122. + crls = NULL;
  123. }
  124. - return want_certs ? certs : crls;
  125. + return crls;
  126. }
  127. static VALUE
  128. @@ -610,7 +630,7 @@ ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
  129. STACK_OF(X509) *certs;
  130. X509 *cert;
  131. - certs = pkcs7_get_certs_or_crls(self, 1);
  132. + certs = pkcs7_get_certs(self);
  133. while((cert = sk_X509_pop(certs))) X509_free(cert);
  134. rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self);
  135. @@ -620,7 +640,7 @@ ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
  136. static VALUE
  137. ossl_pkcs7_get_certificates(VALUE self)
  138. {
  139. - return ossl_x509_sk2ary(pkcs7_get_certs_or_crls(self, 1));
  140. + return ossl_x509_sk2ary(pkcs7_get_certs(self));
  141. }
  142. static VALUE
  143. @@ -650,7 +670,7 @@ ossl_pkcs7_set_crls(VALUE self, VALUE ary)
  144. STACK_OF(X509_CRL) *crls;
  145. X509_CRL *crl;
  146. - crls = pkcs7_get_certs_or_crls(self, 0);
  147. + crls = pkcs7_get_crls(self);
  148. while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
  149. rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self);
  150. @@ -660,7 +680,7 @@ ossl_pkcs7_set_crls(VALUE self, VALUE ary)
  151. static VALUE
  152. ossl_pkcs7_get_crls(VALUE self)
  153. {
  154. - return ossl_x509crl_sk2ary(pkcs7_get_certs_or_crls(self, 0));
  155. + return ossl_x509crl_sk2ary(pkcs7_get_crls(self));
  156. }
  157. static VALUE
  158. diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
  159. index 432ca21..facf6ca 100644
  160. --- a/ext/openssl/ossl_ssl.c
  161. +++ b/ext/openssl/ossl_ssl.c
  162. @@ -1291,10 +1291,10 @@ ossl_ssl_get_peer_cert_chain(VALUE self)
  163. }
  164. chain = SSL_get_peer_cert_chain(ssl);
  165. if(!chain) return Qnil;
  166. - num = sk_num(chain);
  167. + num = sk_X509_num(chain);
  168. ary = rb_ary_new2(num);
  169. for (i = 0; i < num; i++){
  170. - cert = (X509*)sk_value(chain, i);
  171. + cert = sk_X509_value(chain, i);
  172. rb_ary_push(ary, ossl_x509_new(cert));
  173. }
  174. diff --git a/ext/openssl/ossl_x509attr.c b/ext/openssl/ossl_x509attr.c
  175. index 1f817cd..2a4c481 100644
  176. --- a/ext/openssl/ossl_x509attr.c
  177. +++ b/ext/openssl/ossl_x509attr.c
  178. @@ -218,8 +218,9 @@ ossl_x509attr_get_value(VALUE self)
  179. ossl_str_adjust(str, p);
  180. }
  181. else{
  182. - length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, NULL,
  183. - i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
  184. + length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set,
  185. + (unsigned char **) NULL, i2d_ASN1_TYPE,
  186. + V_ASN1_SET, V_ASN1_UNIVERSAL, 0);
  187. str = rb_str_new(0, length);
  188. p = (unsigned char *)RSTRING_PTR(str);
  189. i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, &p,
  190. diff --git a/ext/openssl/ossl_x509crl.c b/ext/openssl/ossl_x509crl.c
  191. index 1be9640..818fdba 100644
  192. --- a/ext/openssl/ossl_x509crl.c
  193. +++ b/ext/openssl/ossl_x509crl.c
  194. @@ -264,7 +264,7 @@ ossl_x509crl_get_revoked(VALUE self)
  195. VALUE ary, revoked;
  196. GetX509CRL(self, crl);
  197. - num = sk_X509_CRL_num(X509_CRL_get_REVOKED(crl));
  198. + num = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
  199. if (num < 0) {
  200. OSSL_Debug("num < 0???");
  201. return rb_ary_new();
  202. @@ -272,7 +272,7 @@ ossl_x509crl_get_revoked(VALUE self)
  203. ary = rb_ary_new2(num);
  204. for(i=0; i<num; i++) {
  205. /* NO DUP - don't free! */
  206. - rev = (X509_REVOKED *)sk_X509_CRL_value(X509_CRL_get_REVOKED(crl), i);
  207. + rev = sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
  208. revoked = ossl_x509revoked_new(rev);
  209. rb_ary_push(ary, revoked);
  210. }
  211. --
  212. 1.7.0.3