1
1
local ffi = require " ffi"
2
2
local C = ffi .C
3
- local ffi_new = ffi .new
4
3
local ffi_str = ffi .string
5
4
6
- local provider_macro = require " resty.openssl.include.provider"
5
+ require " resty.openssl.include.provider"
6
+ local param_macro = require " resty.openssl.include.param"
7
7
local OPENSSL_30 = require (" resty.openssl.version" ).OPENSSL_30
8
8
local format_error = require (" resty.openssl.err" ).format_error
9
9
14
14
local _M = {}
15
15
local mt = {__index = _M }
16
16
17
- local ossl_lib_ctx_st = ffi .typeof (' OSSL_LIB_CTX *' )
17
+ local ossl_provider_ctx_ct = ffi .typeof (' OSSL_PROVIDER *' )
18
18
19
19
function _M .load (name , try )
20
20
local ctx
@@ -37,18 +37,15 @@ function _M.load(name, try)
37
37
end
38
38
39
39
function _M .set_default_search_path (path )
40
- if C .OSSL_PROVIDER_set_default_search_path (nil , path ) ~= 1 then
41
- return false , format_error (" provider.set_default_search_path" )
42
- end
43
- return true
40
+ C .OSSL_PROVIDER_set_default_search_path (nil , path )
44
41
end
45
42
46
43
function _M .is_available (name )
47
44
return C .OSSL_PROVIDER_available (nil , name ) == 1
48
45
end
49
46
50
47
function _M .istype (l )
51
- return l and l .ctx and ffi .istype (ossl_lib_ctx_st , l .ctx )
48
+ return l and l .ctx and ffi .istype (ossl_provider_ctx_ct , l .ctx )
52
49
end
53
50
54
51
function _M :unload ()
67
64
68
65
local params_well_known = {
69
66
-- Well known parameter names that core passes to providers
70
- [" openssl-version" ] = provider_macro .OSSL_PARAM_UTF8_PTR ,
71
- [" provider-name" ] = provider_macro .OSSL_PARAM_UTF8_PTR ,
72
- [" module-filename" ] = provider_macro .OSSL_PARAM_UTF8_PTR ,
67
+ [" openssl-version" ] = param_macro .OSSL_PARAM_UTF8_PTR ,
68
+ [" provider-name" ] = param_macro .OSSL_PARAM_UTF8_PTR ,
69
+ [" module-filename" ] = param_macro .OSSL_PARAM_UTF8_PTR ,
73
70
74
71
-- Well known parameter names that Providers can define
75
- [" name" ] = provider_macro .OSSL_PARAM_UTF8_PTR ,
76
- [" version" ] = provider_macro .OSSL_PARAM_UTF8_PTR ,
77
- [" buildinfo" ] = provider_macro .OSSL_PARAM_UTF8_PTR ,
78
- [" status" ] = provider_macro .OSSL_PARAM_INTEGER ,
79
- [" security-checks" ] = provider_macro .OSSL_PARAM_INTEGER ,
72
+ [" name" ] = param_macro .OSSL_PARAM_UTF8_PTR ,
73
+ [" version" ] = param_macro .OSSL_PARAM_UTF8_PTR ,
74
+ [" buildinfo" ] = param_macro .OSSL_PARAM_UTF8_PTR ,
75
+ [" status" ] = param_macro .OSSL_PARAM_INTEGER ,
76
+ [" security-checks" ] = param_macro .OSSL_PARAM_INTEGER ,
80
77
}
81
78
82
79
local function load_gettable_names (ctx )
@@ -116,46 +113,22 @@ function _M:get_params(...)
116
113
self .param_types = param_types
117
114
end
118
115
119
- local req = ffi_new (" OSSL_PARAM[?]" , key_length + 1 )
120
-
121
116
local buffers = {}
122
- for i , key in ipairs (keys ) do
123
- local typ = self .param_types [key ]
124
- if not typ then
125
- return nil , " provider:get_params: unknown key \" " .. key .. " \" "
126
- end
127
- local param
128
- if typ == provider_macro .OSSL_PARAM_UTF8_PTR then
129
- local buf = ffi_new (" char*[1]" )
130
- buffers [i ] = buf
131
- param = C .OSSL_PARAM_construct_utf8_ptr (key , buf , 0 )
132
- elseif typ == provider_macro .OSSL_PARAM_INTEGER then
133
- local buf = ffi_new (" int[1]" )
134
- buffers [i ] = buf
135
- param = C .OSSL_PARAM_construct_int (key , buf )
136
- else
137
- return nil , " provider:get_params: not yet supported type \" " .. typ .. " \" for \" " .. key .. " \" "
138
- end
139
- req [i - 1 ] = param
117
+ for _ , key in ipairs (keys ) do
118
+ buffers [key ] = ngx .null
119
+ end
120
+ local req , err = param_macro .construct (buffers , key_length , self .param_types )
121
+ if not req then
122
+ return nil , " provider:get_params: failed to construct params: " .. err
140
123
end
141
-
142
- req [key_length ] = C .OSSL_PARAM_construct_end ()
143
124
144
125
if C .OSSL_PROVIDER_get_params (self .ctx , req ) ~= 1 then
145
126
return nil , format_error (" provider:get_params" )
146
127
end
147
128
148
- for i = 0 , key_length do
149
- local buf = buffers [i ]
150
- local key = keys [i ]
151
- local typ = self .param_types [key ]
152
- if typ == provider_macro .OSSL_PARAM_UTF8_PTR then
153
- buffers [key ] = ffi_str (buf [0 ])
154
- elseif typ == provider_macro .OSSL_PARAM_INTEGER then
155
- buffers [key ] = tonumber (buf [0 ])
156
- end
157
- buffers [i ] = nil
158
- -- crypto_macro.OPENSSL_free(req[i-1].data)
129
+ buffers , err = param_macro .parse (buffers , key_length , self .param_types )
130
+ if err then
131
+ return nil , " provider:get_params: failed to parse params: " .. err
159
132
end
160
133
161
134
if key_length == 1 then
0 commit comments