@@ -18,9 +18,11 @@ local util = require "resty.openssl.util"
18
18
local txtnid2nid = require (" resty.openssl.objects" ).txtnid2nid
19
19
local ctypes = require " resty.openssl.auxiliary.ctypes"
20
20
local format_error = require (" resty.openssl.err" ).format_error
21
- local OPENSSL_10 = require (" resty.openssl.version" ).OPENSSL_10
22
- local OPENSSL_11_OR_LATER = require (" resty.openssl.version" ).OPENSSL_11_OR_LATER
23
- local OPENSSL_30 = require (" resty.openssl.version" ).OPENSSL_30
21
+ local version = require (" resty.openssl.version" )
22
+ local OPENSSL_10 = version .OPENSSL_10
23
+ local OPENSSL_11_OR_LATER = version .OPENSSL_11_OR_LATER
24
+ local OPENSSL_30 = version .OPENSSL_30
25
+ local BORINGSSL_110 = version .BORINGSSL_110 -- used in boringssl-fips-20190808
24
26
25
27
-- accessors provides an openssl version neutral interface to lua layer
26
28
-- it doesn't handle any error, expect that to be implemented in
@@ -37,13 +39,26 @@ accessors.get_issuer_name = C.X509_get_issuer_name -- returns internal ptr, we d
37
39
accessors .set_issuer_name = C .X509_set_issuer_name
38
40
accessors .get_signature_nid = C .X509_get_signature_nid
39
41
40
- if OPENSSL_11_OR_LATER then
41
- -- generally, use get1 if we return a lua table wrapped ctx which doesn't support dup.
42
- -- in that case, a new struct is returned from C api, and we will handle gc.
43
- -- openssl will increment the reference count for returned ptr, and won't free it when
44
- -- parent struct is freed.
45
- -- otherwise, use get0, which returns an internal pointer, we don't need to free it up.
46
- -- it will be gone together with the parent struct.
42
+ -- generally, use get1 if we return a lua table wrapped ctx which doesn't support dup.
43
+ -- in that case, a new struct is returned from C api, and we will handle gc.
44
+ -- openssl will increment the reference count for returned ptr, and won't free it when
45
+ -- parent struct is freed.
46
+ -- otherwise, use get0, which returns an internal pointer, we don't need to free it up.
47
+ -- it will be gone together with the parent struct.
48
+
49
+ if BORINGSSL_110 then
50
+ accessors .get_not_before = C .X509_get0_notBefore -- returns internal ptr, we convert to number
51
+ accessors .set_not_before = C .X509_set_notBefore
52
+ accessors .get_not_after = C .X509_get0_notAfter -- returns internal ptr, we convert to number
53
+ accessors .set_not_after = C .X509_set_notAfter
54
+ accessors .get_version = function (x509 )
55
+ if x509 == nil or x509 .cert_info == nil or x509 .cert_info .validity == nil then
56
+ return nil
57
+ end
58
+ return C .ASN1_INTEGER_get (x509 .cert_info .version )
59
+ end
60
+ accessors .get_serial_number = C .X509_get_serialNumber -- returns internal ptr, we convert to bn
61
+ elseif OPENSSL_11_OR_LATER then
47
62
accessors .get_not_before = C .X509_get0_notBefore -- returns internal ptr, we convert to number
48
63
accessors .set_not_before = C .X509_set1_notBefore
49
64
accessors .get_not_after = C .X509_get0_notAfter -- returns internal ptr, we convert to number
0 commit comments