summaryrefslogtreecommitdiff
path: root/ext/openssl/ossl_x509ext.c
diff options
context:
space:
mode:
authorgotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-22 22:29:13 +0000
committergotoyuzo <gotoyuzo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-22 22:29:13 +0000
commitb54ab5610b81bdaacead8148e6a4e5b41ed50ea4 (patch)
tree13507cc5684defb597bc427d54ace08d83e359d0 /ext/openssl/ossl_x509ext.c
parentd927ff121020d3e122f558072d00a078e01157c0 (diff)
* ext/openssl/extconf.rb: check for X509V3_EXT_nconf_nid.
* ext/openssl/ossl_x509ext.c (MakeX509ExtFactory): should use OPENSSL_malloc to allocate X509V3_CTX. * ext/openssl/ossl_x509ext.c (ossl_x509extfactory_create_ext): use X509V3_EXT_nconf_nid to avoid SEGV (and to build extensions which values are placed in separate section). * test/openssl/test_x509ext.rb: new file. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/openssl/ossl_x509ext.c')
-rw-r--r--ext/openssl/ossl_x509ext.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index 8ba555d3e0..31ffec48fa 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -26,9 +26,12 @@
OSSL_Check_Kind(obj, cX509Ext); \
GetX509Ext(obj, ext); \
} while (0)
-
-#define MakeX509ExtFactory(klass, obj, ctx) \
- obj = Data_Make_Struct(klass, X509V3_CTX, 0, ossl_x509extfactory_free, ctx)
+#define MakeX509ExtFactory(klass, obj, ctx) do { \
+ if (!(ctx = OPENSSL_malloc(sizeof(X509V3_CTX)))) \
+ ossl_raise(rb_eRuntimeError, "CTX wasn't allocated!"); \
+ X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, 0); \
+ obj = Data_Wrap_Struct(klass, 0, ossl_x509extfactory_free, ctx); \
+} while (0)
#define GetX509ExtFactory(obj, ctx) do { \
Data_Get_Struct(obj, X509V3_CTX, ctx); \
if (!ctx) { \
@@ -214,6 +217,12 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
X509_EXTENSION *ext;
VALUE oid, value, critical, valstr, obj;
int nid;
+#ifdef HAVE_X509V3_EXT_NCONF_NID
+ VALUE rconf;
+ CONF *conf;
+#else
+ static LHASH *empty_lhash;
+#endif
rb_scan_args(argc, argv, "21", &oid, &value, &critical);
StringValue(oid);
@@ -226,7 +235,14 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
rb_str_append(valstr, value);
GetX509ExtFactory(self, ctx);
- ext = X509V3_EXT_conf_nid(NULL, ctx, nid, RSTRING(valstr)->ptr);
+#ifdef HAVE_X509V3_EXT_NCONF_NID
+ rconf = rb_iv_get(self, "@config");
+ conf = NIL_P(rconf) ? NULL : GetConfigPtr(rconf);
+ ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING(valstr)->ptr);
+#else
+ if (!empty_lhash) empty_lhash = lh_new(NULL, NULL);
+ ext = X509V3_EXT_conf_nid(empty_lhash, ctx, nid, RSTRING(valstr)->ptr);
+#endif
if (!ext){
ossl_raise(eX509ExtError, "%s = %s",
RSTRING(oid)->ptr, RSTRING(value)->ptr);