Skip to content

Commit d1c9078

Browse files
mcrrhenium
authored andcommitted
x509ext: let X509::ExtensionFactory#create_ext take a dotted OID string
instead of looking of NIDs and then using X509V3_EXT_nconf_nid, instead just pass strings to X509V3_EXT_nconf, which has all the logic for processing dealing with generic extensions also process the oid through ln2nid() to retain compatibility. [rhe: tweaked commit message and added a test case]
1 parent 94fb342 commit d1c9078

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

ext/openssl/ossl_x509ext.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,16 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
209209
int nid;
210210
VALUE rconf;
211211
CONF *conf;
212+
const char *oid_cstr = NULL;
212213

213214
rb_scan_args(argc, argv, "21", &oid, &value, &critical);
214-
StringValueCStr(oid);
215215
StringValue(value);
216216
if(NIL_P(critical)) critical = Qfalse;
217217

218-
nid = OBJ_ln2nid(RSTRING_PTR(oid));
219-
if(!nid) nid = OBJ_sn2nid(RSTRING_PTR(oid));
220-
if(!nid) ossl_raise(eX509ExtError, "unknown OID `%"PRIsVALUE"'", oid);
218+
oid_cstr = StringValueCStr(oid);
219+
nid = OBJ_ln2nid(oid_cstr);
220+
if (nid != NID_undef)
221+
oid_cstr = OBJ_nid2sn(nid);
221222

222223
valstr = rb_str_new2(RTEST(critical) ? "critical," : "");
223224
rb_str_append(valstr, value);
@@ -228,7 +229,8 @@ ossl_x509extfactory_create_ext(int argc, VALUE *argv, VALUE self)
228229
rconf = rb_iv_get(self, "@config");
229230
conf = NIL_P(rconf) ? NULL : GetConfig(rconf);
230231
X509V3_set_nconf(ctx, conf);
231-
ext = X509V3_EXT_nconf_nid(conf, ctx, nid, RSTRING_PTR(valstr));
232+
233+
ext = X509V3_EXT_nconf(conf, ctx, oid_cstr, RSTRING_PTR(valstr));
232234
X509V3_set_ctx_nodb(ctx);
233235
if (!ext){
234236
ossl_raise(eX509ExtError, "%"PRIsVALUE" = %"PRIsVALUE, oid, valstr);

test/openssl/test_x509ext.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ def test_factory_create_extension_sn_ln
7878
assert_equal(@basic_constraints.to_der, bc_ln.to_der)
7979
end
8080

81+
def test_factory_create_extension_oid
82+
ef = OpenSSL::X509::ExtensionFactory.new
83+
ef.config = OpenSSL::Config.parse(<<~_end_of_cnf_)
84+
[basic_constraints]
85+
cA = BOOLEAN:TRUE
86+
pathLenConstraint = INTEGER:2
87+
_end_of_cnf_
88+
bc_oid = ef.create_extension("2.5.29.19", "ASN1:SEQUENCE:basic_constraints", true)
89+
assert_equal(@basic_constraints.to_der, bc_oid.to_der)
90+
end
91+
8192
def test_dup
8293
ext = OpenSSL::X509::Extension.new(@basic_constraints.to_der)
8394
assert_equal(@basic_constraints.to_der, ext.to_der)

0 commit comments

Comments
 (0)