Skip to content

Commit d906419

Browse files
committed
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.
1 parent c891e0e commit d906419

File tree

3 files changed

+3
-40
lines changed

3 files changed

+3
-40
lines changed

ext/openssl/ossl_config.c

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static const rb_data_type_t ossl_config_type = {
2525
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
2626
};
2727

28-
static CONF *
28+
CONF *
2929
GetConfig(VALUE obj)
3030
{
3131
CONF *conf;
@@ -50,42 +50,6 @@ config_s_alloc(VALUE klass)
5050
return obj;
5151
}
5252

53-
/*
54-
* DupConfigPtr is a public C-level function for getting OpenSSL CONF struct
55-
* from an OpenSSL::Config(eConfig) instance. We decided to implement
56-
* OpenSSL::Config in Ruby level but we need to pass native CONF struct for
57-
* some OpenSSL features such as X509V3_EXT_*.
58-
*/
59-
CONF *
60-
DupConfigPtr(VALUE obj)
61-
{
62-
CONF *conf;
63-
VALUE str;
64-
BIO *bio;
65-
long eline = -1;
66-
67-
OSSL_Check_Kind(obj, cConfig);
68-
str = rb_funcall(obj, rb_intern("to_s"), 0);
69-
bio = ossl_obj2bio(&str);
70-
conf = NCONF_new(NULL);
71-
if(!conf){
72-
BIO_free(bio);
73-
ossl_raise(eConfigError, NULL);
74-
}
75-
if(!NCONF_load_bio(conf, bio, &eline)){
76-
BIO_free(bio);
77-
NCONF_free(conf);
78-
if (eline <= 0)
79-
ossl_raise(eConfigError, "wrong config format");
80-
else
81-
ossl_raise(eConfigError, "error in line %d", eline);
82-
}
83-
BIO_free(bio);
84-
85-
return conf;
86-
}
87-
88-
8953
static void
9054
config_load_bio(CONF *conf, BIO *bio)
9155
{

ext/openssl/ossl_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef OSSL_CONFIG_H
1111
#define OSSL_CONFIG_H
1212

13-
CONF *DupConfigPtr(VALUE obj);
13+
CONF *GetConfig(VALUE obj);
1414
void Init_ossl_config(void);
1515

1616
#endif /* OSSL_CONFIG_H */

ext/openssl/ossl_x509ext.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,10 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
226226
GetX509ExtFactory(self, ctx);
227227
obj = NewX509Ext(cX509Ext);
228228
rconf = rb_iv_get(self, "@config");
229-
conf = NIL_P(rconf) ? NULL : DupConfigPtr(rconf);
229+
conf = NIL_P(rconf) ? NULL : GetConfig(rconf);
230230
X509V3_set_nconf(ctx, conf);
231231
ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
232232
X509V3_set_ctx_nodb(ctx);
233-
NCONF_free(conf);
234233
if (!ext){
235234
ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr);
236235
}

0 commit comments

Comments
 (0)