[前][次][番号順一覧][スレッド一覧]

ruby-changes:65537

From: Kazuki <ko1@a...>
Date: Tue, 16 Mar 2021 20:38:40 +0900 (JST)
Subject: [ruby-changes:65537] 10289e9f22 (master): [ruby/openssl] config: replace DupConfigPtr() with GetConfig()

https://git.ruby-lang.org/ruby.git/commit/?id=10289e9f22

From 10289e9f229dae499d8f9c4e8252aeb728117d28 Mon Sep 17 00:00:00 2001
From: Kazuki Yamaguchi <k@r...>
Date: Wed, 19 Feb 2020 05:11:54 +0000
Subject: [ruby/openssl] config: replace DupConfigPtr() with GetConfig()

Now that OpenSSL::Config wraps a real CONF object, the caller can just
borrow it rather than creating a new temporary CONF object. CONF object
is usually treated as immutable.

DupConfigPtr() is now removed, and GetConfig() is exported instead.

https://github.com/ruby/openssl/commit/d9064190ca
---
 ext/openssl/ossl_config.c  | 38 +-------------------------------------
 ext/openssl/ossl_config.h  |  2 +-
 ext/openssl/ossl_x509ext.c |  3 +--
 3 files changed, 3 insertions(+), 40 deletions(-)

diff --git a/ext/openssl/ossl_config.c b/ext/openssl/ossl_config.c
index 52d96e1..21c327b 100644
--- a/ext/openssl/ossl_config.c
+++ b/ext/openssl/ossl_config.c
@@ -25,7 +25,7 @@ static const rb_data_type_t ossl_config_type = { https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_config.c#L25
     0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
 };
 
-static CONF *
+CONF *
 GetConfig(VALUE obj)
 {
     CONF *conf;
@@ -50,42 +50,6 @@ config_s_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_config.c#L50
     return obj;
 }
 
-/*
- * DupConfigPtr is a public C-level function for getting OpenSSL CONF struct
- * from an OpenSSL::Config(eConfig) instance.  We decided to implement
- * OpenSSL::Config in Ruby level but we need to pass native CONF struct for
- * some OpenSSL features such as X509V3_EXT_*.
- */
-CONF *
-DupConfigPtr(VALUE obj)
-{
-    CONF *conf;
-    VALUE str;
-    BIO *bio;
-    long eline = -1;
-
-    OSSL_Check_Kind(obj, cConfig);
-    str = rb_funcall(obj, rb_intern("to_s"), 0);
-    bio = ossl_obj2bio(&str);
-    conf = NCONF_new(NULL);
-    if(!conf){
-	BIO_free(bio);
-	ossl_raise(eConfigError, NULL);
-    }
-    if(!NCONF_load_bio(conf, bio, &eline)){
-	BIO_free(bio);
-	NCONF_free(conf);
-	if (eline <= 0)
-	    ossl_raise(eConfigError, "wrong config format");
-	else
-	    ossl_raise(eConfigError, "error in line %d", eline);
-    }
-    BIO_free(bio);
-
-    return conf;
-}
-
-
 static void
 config_load_bio(CONF *conf, BIO *bio)
 {
diff --git a/ext/openssl/ossl_config.h b/ext/openssl/ossl_config.h
index c96a00f..4e604f1 100644
--- a/ext/openssl/ossl_config.h
+++ b/ext/openssl/ossl_config.h
@@ -10,7 +10,7 @@ https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_config.h#L10
 #ifndef OSSL_CONFIG_H
 #define OSSL_CONFIG_H
 
-CONF *DupConfigPtr(VALUE obj);
+CONF *GetConfig(VALUE obj);
 void Init_ossl_config(void);
 
 #endif /* OSSL_CONFIG_H */
diff --git a/ext/openssl/ossl_x509ext.c b/ext/openssl/ossl_x509ext.c
index 5eb9bd7..e54102c 100644
--- a/ext/openssl/ossl_x509ext.c
+++ b/ext/openssl/ossl_x509ext.c
@@ -226,11 +226,10 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_x509ext.c#L226
     GetX509ExtFactory(self, ctx);
     obj = NewX509Ext(cX509Ext);
     rconf = rb_iv_get(self, "@config");
-    conf = NIL_P(rconf) ? NULL : DupConfigPtr(rconf);
+    conf = NIL_P(rconf) ? NULL : GetConfig(rconf);
     X509V3_set_nconf(ctx, conf);
     ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
     X509V3_set_ctx_nodb(ctx);
-    NCONF_free(conf);
     if (!ext){
 	ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr);
     }
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]