Skip to content
Permalink
Browse files

feat(x509.extension) allow to create an extension by NID

  • Loading branch information
fffonion committed Feb 6, 2020
1 parent bcc38e9 commit 6d66a2d9fa7cc36cc2e6c85a78ad2236e525f3b0
Showing with 12 additions and 6 deletions.
  1. +1 −1 README.md
  2. +1 −0 lib/resty/openssl/include/objects.lua
  3. +1 −0 lib/resty/openssl/objects.lua
  4. +9 −5 lib/resty/openssl/x509/extension.lua
@@ -913,7 +913,7 @@ ngx.say(not_before)
err = x509:set_basic_constraints_critical(true)
```

If type is a table, setter requires a table with case-insentive keys to set;
If type is a table, setter requires a table with case-insensitive keys to set;
getter returns the value of the given case-insensitive key or a table of all keys if no key provided.

```lua
@@ -13,4 +13,5 @@ ffi.cdef [[
const char *OBJ_nid2sn(int n);
int OBJ_obj2nid(const ASN1_OBJECT *o);
const ASN1_OBJECT *OBJ_nid2obj(int n);
int OBJ_create(const char *oid, const char *sn, const char *ln);
]]
@@ -57,4 +57,5 @@ return {
nid2table = nid2table,
txt2nid = txt2nid,
txtnid2nid = txtnid2nid,
create = C.OBJ_create,
}
@@ -21,12 +21,16 @@ local extension_types = {
crl = "resty.openssl.x509.crl",
-- db, -- NYI
}
function _M.new(name, value, data)
function _M.new(txtnid, value, data)
local nid, err = objects_lib.txtnid2nid(txtnid)
if err then
return nil, err
end
if type(value) ~= 'string' then
return nil, "expect string at #2"
end
-- get a ptr and also zerofill the struct
local x509_ctx_ptr = ffi_new('X509V3_CTX[1]')
if type(name) ~= 'string' or type(value) ~= 'string' then
return nil, "expect both strings at #1 and #2"
end

if type(data) == 'table' then
local args = {}
@@ -44,7 +48,7 @@ function _M.new(name, value, data)
return nil, "expect nil or a table at #3"
end

local ctx = C.X509V3_EXT_nconf(nil, x509_ctx_ptr[0], name, value)
local ctx = C.X509V3_EXT_nconf_nid(nil, x509_ctx_ptr[0], nid, value)
if ctx == nil then
return nil, format_error("x509.extension.new")
end

0 comments on commit 6d66a2d

Please sign in to comment.
You can’t perform that action at this time.