@@ -1557,6 +1557,12 @@ finds from beginning. Index is 1-based.
1557
1557
1558
1558
``` lua
1559
1559
local ext , pos , err = x509 :get_extension (" keyUsage" )
1560
+ ngx .say (ext :text ())
1561
+ -- outputs "Digital Signature, Key Encipherment"
1562
+
1563
+ local ext , pos , err = x509 :get_extension (" subjectKeyIdentifier" )
1564
+ ngx .say (ext :text ())
1565
+ -- outputs "3D:42:13:57:8F:79:BE:30:7D:86:A9:AC:67:50:E5:56:3E:0E:AF:4F"
1560
1566
```
1561
1567
1562
1568
[ Back to TOC] ( #table-of-contents )
@@ -1569,9 +1575,9 @@ Adds an X.509 `extension` to certificate, the first argument must be a
1569
1575
[ resty.openssl.x509.extension] ( #restyopensslx509extension ) instance.
1570
1576
1571
1577
``` lua
1572
- local extension , err = require (" resty.openssl.extension" ).new ({
1573
- " keyUsage" , " critical,keyCertSign,cRLSign" ,
1574
- } )
1578
+ local extension , err = require (" resty.openssl.x509. extension" ).new (
1579
+ " keyUsage" , " critical,keyCertSign,cRLSign"
1580
+ )
1575
1581
local x509 , err = require (" resty.openssl.x509" ).new ()
1576
1582
local ok , err = x509 :add_extension (extension )
1577
1583
```
@@ -2261,26 +2267,67 @@ Module to interact with X.509 extensions.
2261
2267
Creates a new ` extension ` instance. ` name ` and ` value ` are strings in OpenSSL
2262
2268
[ arbitrary extension format] ( https://www.openssl.org/docs/manmaster/man5/x509v3_config.html ) .
2263
2269
2264
- ` data ` can be a table or nil. Where data is a table, the following key will be looked up:
2270
+ ` data ` can be a table, string or nil. Where ` data ` is a table, the following key will be looked up:
2265
2271
2266
2272
``` lua
2267
2273
data = {
2268
- issuer = resty .openssl .x509 instance ,
2269
- subject = resty .openssl .x509 instance ,
2270
- request = resty .openssl .x509 .csr instance ,
2271
- crl = resty .openssl .x509 .crl instance ,
2274
+ issuer = resty .openssl .x509 instance ,
2275
+ subject = resty .openssl .x509 instance ,
2276
+ request = resty .openssl .x509 .csr instance ,
2277
+ crl = resty .openssl .x509 .crl instance ,
2272
2278
}
2273
2279
```
2274
2280
2275
- Example:
2281
+ When ` data ` is a string, it's the full nconf string. Using section lookup from ` value ` to
2282
+ ` data ` is also supported.
2283
+
2284
+ <details >
2285
+ <summary >Example usages:</summary >
2286
+
2276
2287
``` lua
2277
- local x509 , err = require (" resty.openssl.x509" ).new ()
2278
2288
local extension = require (" resty.openssl.x509.extension" )
2289
+ -- extendedKeyUsage=serverAuth,clientAuth
2279
2290
local ext , err = extension .new (" extendedKeyUsage" , " serverAuth,clientAuth" )
2291
+ -- crlDistributionPoints=URI:http://myhost.com/myca.crl
2292
+ ext , err = extension .new (" crlDistributionPoints" , " URI:http://myhost.com/myca.crl" )
2293
+ -- with section lookup
2294
+ ext , err = extension .new (
2295
+ " crlDistributionPoints" , " crldp1_section" ,
2296
+ [[
2297
+ [crldp1_section]
2298
+ fullname=URI:http://myhost.com/myca.crl
2299
+ CRLissuer=dirName:issuer_sect
2300
+ reasons=keyCompromise, CACompromise
2301
+
2302
+ [issuer_sect]
2303
+ C=UK
2304
+ O=Organisation
2305
+ CN=Some Name
2306
+ ]]
2307
+ )
2308
+ -- combine section lookup with other value
2309
+ ext , err = extension .new (
2310
+ " certificatePolicies" , " ia5org,1.2.3.4,1.5.6.7.8,@polsect" ,
2311
+ [[
2312
+ [polsect]
2313
+ policyIdentifier = 1.3.5.8
2314
+ CPS.1="http://my.host.name/"
2315
+ CPS.2="http://my.your.name/"
2316
+ userNotice.1=@notice
2317
+
2318
+ [notice]
2319
+ explicitText="Explicit Text Here"
2320
+ organization="Organisation Name"
2321
+ noticeNumbers=1,2,3,4
2322
+ ]]
2323
+ ))
2324
+ -- subjectKeyIdentifier=hash
2325
+ local x509 , err = require (" resty.openssl.x509" ).new ()
2280
2326
ext , err = extension .new (" subjectKeyIdentifier" , " hash" , {
2281
- subject = crt
2327
+ subject = x509
2282
2328
})
2283
2329
```
2330
+ </details >
2284
2331
2285
2332
See [ examples/tls-alpn-01.lua] ( https://github.com/fffonion/lua-resty-openssl/blob/master/examples/tls-alpn-01.lua )
2286
2333
for an example to create extension with an unknown nid.
@@ -2295,17 +2342,33 @@ Creates a new `extension` instance from `X509_EXTENSION*` pointer.
2295
2342
2296
2343
[ Back to TOC] ( #table-of-contents )
2297
2344
2345
+ ### extension.from_der
2346
+
2347
+ ** syntax** : * ext, ok = extension.from_der(der, nid_or_txt, crit?)*
2348
+
2349
+ Creates a new ` extension ` instance. ` der ` is the ASN.1 encoded string to be
2350
+ set for the extension.
2351
+
2352
+ ` nid_or_txt ` is a number or text representation of [ NID] and
2353
+ ` crit ` is the critical flag of the extension.
2354
+
2355
+ See [ examples/tls-alpn-01.lua] ( https://github.com/fffonion/lua-resty-openssl/blob/master/examples/tls-alpn-01.lua )
2356
+ for an example to create extension with an unknown nid.
2357
+
2358
+ [ Back to TOC] ( #table-of-contents )
2359
+
2298
2360
### extension.from_data
2299
2361
2300
- ** syntax** : * ext, ok = extension.from_data(table, nid , crit?)*
2362
+ ** syntax** : * ext, ok = extension.from_data(table, nid_or_txt , crit?)*
2301
2363
2302
2364
Creates a new ` extension ` instance. ` table ` can be instance of:
2303
2365
2304
2366
- [ x509.altname] ( #restyopensslx509altname )
2305
2367
- [ x509.extension.info_access] ( #restyopensslx509extensioninfo_access )
2306
2368
- [ x509.extension.dist_points] ( #restyopensslx509extensiondist_points )
2307
2369
2308
- ` nid ` is a number of [ NID] and ` crit ` is the critical flag of the extension.
2370
+ ` nid_or_txt ` is a number or text representation of [ NID] and
2371
+ ` crit ` is the critical flag of the extension.
2309
2372
2310
2373
[ Back to TOC] ( #table-of-contents )
2311
2374
0 commit comments