bunkerweb/lib/resty/openssl/objects.lua
Théophile Diot 411cd2df5a Squashed 'src/deps/src/lua-resty-openssl/' changes from e56da6c5f..529f0c5ad
529f0c5ad release: 1.5.0
1f7d7b326 tests(*) unload provider to make valgrind happy
766955521 fix(param) fix issue when gettable schema may be overwritten by settable schema
8c366c22c fix(param) save converted value to prevent potential use-after-free
a0711de99 fix(x509.csr) fix potential use-after-free in set_extension and add_extension
407d31ec3 fix(x509.*) fix potential use-after-free when get or set subject_alt_name, info_access and dist_points
e0872dcfa chore(x509.*) use const type name
b16f759c2 fix(x509.store) fix potential use-after-free in store:verify and store:check_revocation
48ab40148 tests(ci) catch more GC corner cases
e924ee045 fix(pkey) fix potential use-after-free in pkey.paramgen (#176)
224fae68c fix(bn) fix potential use-after-free in bn.new (#177)
a88f1ba30 fix(x509.store) fix the string is not NUL terminated in set_purpose (#174)
d94064cc7 fix(objects): fix a buffer overflow issue in find_sigid_algs. (#175)
7d6d8b5d2 fix(asn1) correct time_t to be 64 bits type (#171)
30bc5b7f4 doc(examples) update comment for raw-sign-and-recover

git-subtree-dir: src/deps/src/lua-resty-openssl
git-subtree-split: 529f0c5ad1a3275a2313b68003650e7c5693dc3d
2024-07-24 12:22:21 +01:00

74 lines
1.7 KiB
Lua

local ffi = require "ffi"
local C = ffi.C
local ffi_str = ffi.string
local ffi_sizeof = ffi.sizeof
require "resty.openssl.include.objects"
require "resty.openssl.include.err"
local buf = ffi.new('char[?]', 100)
local function obj2table(obj)
local nid = C.OBJ_obj2nid(obj)
local len = C.OBJ_obj2txt(buf, ffi_sizeof(buf), obj, 1)
local oid = ffi_str(buf, len)
return {
id = oid,
nid = nid,
sn = ffi_str(C.OBJ_nid2sn(nid)),
ln = ffi_str(C.OBJ_nid2ln(nid)),
}
end
local function nid2table(nid)
return obj2table(C.OBJ_nid2obj(nid))
end
local function txt2nid(txt)
if type(txt) ~= "string" then
return nil, "objects.txt2nid: expect a string at #1"
end
local nid = C.OBJ_txt2nid(txt)
if nid == 0 then
-- clean up error occurs during OBJ_txt2nid
C.ERR_clear_error()
return nil, "objects.txt2nid: invalid NID text " .. txt
end
return nid
end
local function txtnid2nid(txt_nid)
local nid
if type(txt_nid) == "string" then
nid = C.OBJ_txt2nid(txt_nid)
if nid == 0 then
-- clean up error occurs during OBJ_txt2nid
C.ERR_clear_error()
return nil, "objects.txtnid2nid: invalid NID text " .. txt_nid
end
elseif type(txt_nid) == "number" then
nid = txt_nid
else
return nil, "objects.txtnid2nid: expect string or number at #1"
end
return nid
end
local function find_sigid_algs(nid)
local out = ffi.new("int[1]")
if C.OBJ_find_sigid_algs(nid, out, nil) == 0 then
return 0, "objects.find_sigid_algs: invalid sigid " .. nid
end
return tonumber(out[0])
end
return {
obj2table = obj2table,
nid2table = nid2table,
txt2nid = txt2nid,
txtnid2nid = txtnid2nid,
find_sigid_algs = find_sigid_algs,
create = C.OBJ_create,
}