ruby-changes:14967
From: nahi <ko1@a...>
Date: Sun, 7 Mar 2010 06:48:01 +0900 (JST)
Subject: [ruby-changes:14967] Ruby:r26838 (ruby_1_8): backport the commit from trunk:
nahi 2010-03-07 06:47:30 +0900 (Sun, 07 Mar 2010) New Revision: 26838 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=26838 Log: backport the commit from trunk: Sun Feb 28 11:49:35 2010 NARUSE, Yui <naruse@r...> * openssl/ossl.c (OSSL_IMPL_SK2ARY): for OpenSSL 1.0. patched by Jeroen van Meeuwen at [ruby-core:25210] fixed by Nobuyoshi Nakada [ruby-core:25238], Hongli Lai [ruby-core:27417], and Motohiro KOSAKI [ruby-core:28063] * ext/openssl/ossl_ssl.c (ossl_ssl_method_tab), (ossl_ssl_cipher_to_ary): constified. * ext/openssl/ossl_pkcs7.c (pkcs7_get_certs, pkcs7_get_crls): split pkcs7_get_certs_or_crls. Modified files: branches/ruby_1_8/ChangeLog branches/ruby_1_8/ext/openssl/ossl.c branches/ruby_1_8/ext/openssl/ossl.h branches/ruby_1_8/ext/openssl/ossl_pkcs7.c branches/ruby_1_8/ext/openssl/ossl_ssl.c branches/ruby_1_8/ext/openssl/ossl_x509attr.c branches/ruby_1_8/ext/openssl/ossl_x509crl.c Index: ruby_1_8/ext/openssl/ossl_x509attr.c =================================================================== --- ruby_1_8/ext/openssl/ossl_x509attr.c (revision 26837) +++ ruby_1_8/ext/openssl/ossl_x509attr.c (revision 26838) @@ -218,8 +218,9 @@ ossl_str_adjust(str, p); } else{ - length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, NULL, - i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0); + length = i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, + (unsigned char **) NULL, i2d_ASN1_TYPE, + V_ASN1_SET, V_ASN1_UNIVERSAL, 0); str = rb_str_new(0, length); p = (unsigned char *)RSTRING_PTR(str); i2d_ASN1_SET_OF_ASN1_TYPE(attr->value.set, &p, Index: ruby_1_8/ext/openssl/ossl_ssl.c =================================================================== --- ruby_1_8/ext/openssl/ossl_ssl.c (revision 26837) +++ ruby_1_8/ext/openssl/ossl_ssl.c (revision 26838) @@ -1291,10 +1291,10 @@ } chain = SSL_get_peer_cert_chain(ssl); if(!chain) return Qnil; - num = sk_num(chain); + num = sk_X509_num(chain); ary = rb_ary_new2(num); for (i = 0; i < num; i++){ - cert = (X509*)sk_value(chain, i); + cert = sk_X509_value(chain, i); rb_ary_push(ary, ossl_x509_new(cert)); } Index: ruby_1_8/ext/openssl/ossl.c =================================================================== --- ruby_1_8/ext/openssl/ossl.c (revision 26837) +++ ruby_1_8/ext/openssl/ossl.c (revision 26838) @@ -92,7 +92,7 @@ #define OSSL_IMPL_SK2ARY(name, type) \ VALUE \ -ossl_##name##_sk2ary(STACK *sk) \ +ossl_##name##_sk2ary(STACK_OF(type) *sk) \ { \ type *t; \ int i, num; \ @@ -102,7 +102,7 @@ OSSL_Debug("empty sk!"); \ return Qnil; \ } \ - num = sk_num(sk); \ + num = sk_##type##_num(sk); \ if (num < 0) { \ OSSL_Debug("items in sk < -1???"); \ return rb_ary_new(); \ @@ -110,7 +110,7 @@ ary = rb_ary_new2(num); \ \ for (i=0; i<num; i++) { \ - t = (type *)sk_value(sk, i); \ + t = sk_##type##_value(sk, i); \ rb_ary_push(ary, ossl_##name##_new(t)); \ } \ return ary; \ Index: ruby_1_8/ext/openssl/ossl.h =================================================================== --- ruby_1_8/ext/openssl/ossl.h (revision 26837) +++ ruby_1_8/ext/openssl/ossl.h (revision 26838) @@ -108,6 +108,13 @@ } while (0) /* + * Compatibility + */ +#if OPENSSL_VERSION_NUMBER >= 0x10000000L +#define STACK _STACK +#endif + +/* * String to HEXString conversion */ int string2hex(const unsigned char *, int, char **, int *); Index: ruby_1_8/ext/openssl/ossl_x509crl.c =================================================================== --- ruby_1_8/ext/openssl/ossl_x509crl.c (revision 26837) +++ ruby_1_8/ext/openssl/ossl_x509crl.c (revision 26838) @@ -264,7 +264,7 @@ VALUE ary, revoked; GetX509CRL(self, crl); - num = sk_X509_CRL_num(X509_CRL_get_REVOKED(crl)); + num = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl)); if (num < 0) { OSSL_Debug("num < 0???"); return rb_ary_new(); @@ -272,7 +272,7 @@ ary = rb_ary_new2(num); for(i=0; i<num; i++) { /* NO DUP - don't free! */ - rev = (X509_REVOKED *)sk_X509_CRL_value(X509_CRL_get_REVOKED(crl), i); + rev = sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i); revoked = ossl_x509revoked_new(rev); rb_ary_push(ary, revoked); } Index: ruby_1_8/ext/openssl/ossl_pkcs7.c =================================================================== --- ruby_1_8/ext/openssl/ossl_pkcs7.c (revision 26837) +++ ruby_1_8/ext/openssl/ossl_pkcs7.c (revision 26838) @@ -572,11 +572,33 @@ return self; } -static STACK * -pkcs7_get_certs_or_crls(VALUE self, int want_certs) +static STACK_OF(X509) * +pkcs7_get_certs(VALUE self) { PKCS7 *pkcs7; STACK_OF(X509) *certs; + int i; + + GetPKCS7(self, pkcs7); + i = OBJ_obj2nid(pkcs7->type); + switch(i){ + case NID_pkcs7_signed: + certs = pkcs7->d.sign->cert; + break; + case NID_pkcs7_signedAndEnveloped: + certs = pkcs7->d.signed_and_enveloped->cert; + break; + default: + certs = NULL; + } + + return certs; +} + +static STACK_OF(X509_CRL) * +pkcs7_get_crls(VALUE self) +{ + PKCS7 *pkcs7; STACK_OF(X509_CRL) *crls; int i; @@ -584,18 +606,16 @@ i = OBJ_obj2nid(pkcs7->type); switch(i){ case NID_pkcs7_signed: - certs = pkcs7->d.sign->cert; crls = pkcs7->d.sign->crl; break; case NID_pkcs7_signedAndEnveloped: - certs = pkcs7->d.signed_and_enveloped->cert; crls = pkcs7->d.signed_and_enveloped->crl; break; default: - certs = crls = NULL; + crls = NULL; } - return want_certs ? certs : crls; + return crls; } static VALUE @@ -610,7 +630,7 @@ STACK_OF(X509) *certs; X509 *cert; - certs = pkcs7_get_certs_or_crls(self, 1); + certs = pkcs7_get_certs(self); while((cert = sk_X509_pop(certs))) X509_free(cert); rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self); @@ -620,7 +640,7 @@ static VALUE ossl_pkcs7_get_certificates(VALUE self) { - return ossl_x509_sk2ary(pkcs7_get_certs_or_crls(self, 1)); + return ossl_x509_sk2ary(pkcs7_get_certs(self)); } static VALUE @@ -650,7 +670,7 @@ STACK_OF(X509_CRL) *crls; X509_CRL *crl; - crls = pkcs7_get_certs_or_crls(self, 0); + crls = pkcs7_get_crls(self); while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl); rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self); @@ -660,7 +680,7 @@ static VALUE ossl_pkcs7_get_crls(VALUE self) { - return ossl_x509crl_sk2ary(pkcs7_get_certs_or_crls(self, 0)); + return ossl_x509crl_sk2ary(pkcs7_get_crls(self)); } static VALUE Index: ruby_1_8/ChangeLog =================================================================== --- ruby_1_8/ChangeLog (revision 26837) +++ ruby_1_8/ChangeLog (revision 26838) @@ -1,3 +1,20 @@ +Sun Mar 7 06:41:59 2010 NAKAMURA, Hiroshi <nahi@r...> + + * backport the commit from trunk: + Sun Feb 28 11:49:35 2010 NARUSE, Yui <naruse@r...> + + * openssl/ossl.c (OSSL_IMPL_SK2ARY): for OpenSSL 1.0. + patched by Jeroen van Meeuwen at [ruby-core:25210] + fixed by Nobuyoshi Nakada [ruby-core:25238], + Hongli Lai [ruby-core:27417], + and Motohiro KOSAKI [ruby-core:28063] + + * ext/openssl/ossl_ssl.c (ossl_ssl_method_tab), + (ossl_ssl_cipher_to_ary): constified. + + * ext/openssl/ossl_pkcs7.c (pkcs7_get_certs, pkcs7_get_crls): + split pkcs7_get_certs_or_crls. + Sun Mar 7 06:40:10 2010 NAKAMURA, Hiroshi <nahi@r...> * test/openssl/test_ec.rb: added test_dsa_sign_asn1_FIPS186_3. dgst is -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/