Skip to content

Commit 9a5ae18

Browse files
committed
up
1 parent c3d138b commit 9a5ae18

File tree

6 files changed

+1084
-31
lines changed

6 files changed

+1084
-31
lines changed

Diff for: docs/lua/openssl.md

+25-8
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ dnf -y install lua5.1-resty-openssl
3232

3333
To use this Lua library with NGINX, ensure that [nginx-module-lua](../modules/lua.md) is installed.
3434

35-
This document describes lua-resty-openssl [v1.5.2](https://github.com/fffonion/lua-resty-openssl/releases/tag/1.5.2){target=_blank}
36-
released on Feb 05 2025.
35+
This document describes lua-resty-openssl [v1.6.1](https://github.com/fffonion/lua-resty-openssl/releases/tag/1.6.1){target=_blank}
36+
released on Apr 16 2025.
3737

3838
<hr />
3939

@@ -523,12 +523,13 @@ pkey.new(pem_or_der_text, {
523523

524524
When loading JWK, there are couple of caveats:
525525
- Make sure the encoded JSON text is passed in, it must have been base64 decoded.
526-
- Constraint `type` on JWK key is not supported, the parameters
527-
in provided JSON will decide if a private or public key is loaded.
526+
- When using OpenSSL 1.1.1 or lua-resty-openssl earlier than 1.6.0, constraint `type`
527+
on JWK key is only supported on OpenSSL 3.x and lua-resty-openssl 1.6.0.
528+
Otherwise the parameters in provided JSON will decide if a private or public key is loaded,
529+
specifying `type` will result in an error; also public key part for `OKP` keys (the `x` parameter)
530+
is not honored and derived from private key part (the `d` parameter) if it's specified.
528531
- Only key type of `RSA`, `P-256`, `P-384` and `P-512` `EC`,
529532
`Ed25519`, `X25519`, `Ed448` and `X448` `OKP` keys are supported.
530-
- Public key part for `OKP` keys (the `x` parameter) is always not honored and derived
531-
from private key part (the `d` parameter) if it's specified.
532533
- Signatures and verification must use `ecdsa_use_raw` option to work with JWS standards
533534
for EC keys. See [pkey:sign](#pkeysign) and [pkey.verify](#pkeyverify) for detail.
534535
- When running outside of OpenResty, needs to install a JSON library (`cjson` or `dkjson`)
@@ -742,7 +743,7 @@ private | private key | [bn](#restyopensslbn)
742743
public | public key | [bn](#restyopensslbn)
743744
p | prime modulus | [bn](#restyopensslbn)
744745
q | reference position | [bn](#restyopensslbn)
745-
p | base generator | [bn](#restyopensslbn)
746+
g | base generator | [bn](#restyopensslbn)
746747

747748

748749
Parameters for Curve25519 and Curve448 keys:
@@ -761,17 +762,33 @@ it's a public key.
761762

762763
### pkey:get_key_type
763764

764-
**syntax**: *obj, err = pk:get_key_type()*
765+
**syntax**: *obj, err = pk:get_key_type(nid_only?)*
765766

766767
Returns a ASN1_OBJECT of key type of the private key as a table.
767768

769+
Starting from lua-resty-openssl 1.6.0, an optional argument `nid_only` can be set to `true`
770+
to only return the numeric NID of the key.
771+
768772
```lua
769773
local pkey, err = require("resty.openssl.pkey").new({type="X448"})
770774

771775
ngx.say(require("cjson").encode(pkey:get_key_type()))
772776
-- outputs '{"ln":"X448","nid":1035,"sn":"X448","id":"1.3.101.111"}'
777+
ngx.say(pkey:get_key_type(true))
778+
-- outputs 1035
773779
```
774780

781+
### pkey:get_size
782+
783+
**syntax**: *size, err = pk:get_size()*
784+
785+
Returns the maximum suitable size for the output buffers for almost all
786+
operations that can be done with pkey.
787+
788+
For RSA key, this is the size of the modulus.
789+
For EC, Ed25519 and Ed448 keys, this is the size of the private key.
790+
For DH key, this is the size of the prime modulus.
791+
775792
### pkey:get_default_digest_type
776793

777794
**syntax**: *obj, err = pk:get_default_digest_type()*

Diff for: docs/lua/session.md

+21-13
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ dnf -y install lua5.1-resty-session
3232

3333
To use this Lua library with NGINX, ensure that [nginx-module-lua](../modules/lua.md) is installed.
3434

35-
This document describes lua-resty-session [v4.0.5](https://github.com/bungle/lua-resty-session/releases/tag/v4.0.5){target=_blank}
36-
released on Aug 16 2023.
35+
This document describes lua-resty-session [v4.1.1](https://github.com/bungle/lua-resty-session/releases/tag/v4.1.1){target=_blank}
36+
released on Apr 16 2025.
3737

3838
<hr />
3939

@@ -42,9 +42,10 @@ released on Aug 16 2023.
4242
## TL;DR;
4343

4444
- Sessions are immutable (each save generates a new session), and lockless.
45-
- Session data is AES-256-GCM encrypted with a key derived using HKDF-SHA256.
45+
- Session data is AES-256-GCM encrypted with a key derived using HKDF-SHA256
46+
(on FIPS-mode it uses PBKDF2 with SHA-256 instead.
4647
- Session has a fixed size header that is protected with HMAC-SHA256 MAC with
47-
a key derived using HKDF-SHA256.
48+
a key derived using HKDF-SHA256 (on FIPS-mode it uses PBKDF2 with SHA-256 instead).
4849
- Session data can be stored in a stateless cookie or in various backend storages.
4950
- A single session cookie can maintain multiple sessions across different audiences.
5051

@@ -251,6 +252,7 @@ Here are the possible session configuration options:
251252
| `cookie_prefix` | `nil` | Cookie prefix, use `nil`, `"__Host-"` or `"__Secure-"`. |
252253
| `cookie_name` | `"session"` | Session cookie name, e.g. `"session"`. |
253254
| `cookie_path` | `"/"` | Cookie path, e.g. `"/"`. |
255+
| `cookie_domain` | `nil` | Cookie domain, e.g. `"example.com"` |
254256
| `cookie_http_only` | `true` | Mark cookie HTTP only, use `true` or `false`. |
255257
| `cookie_secure` | `nil` | Mark cookie secure, use `nil`, `true` or `false`. |
256258
| `cookie_priority` | `nil` | Cookie priority, use `nil`, `"Low"`, `"Medium"`, or `"High"`. |
@@ -274,6 +276,7 @@ Here are the possible session configuration options:
274276
| `store_metadata` | `false` | Whether to also store metadata of sessions, such as collecting data of sessions for a specific audience belonging to a specific subject. |
275277
| `touch_threshold` | `60` | Touch threshold controls how frequently or infrequently the `session:refresh` touches the cookie, e.g. `60` (a minute) (in seconds) |
276278
| `compression_threshold` | `1024` | Compression threshold controls when the data is deflated, e.g. `1024` (a kilobyte) (in bytes), `0` disables compression. |
279+
| `bind` | `nil` | Bind the session to data acquired from the HTTP request or connection, use `ip`, `scheme`, `user-agent`. E.g. `{ "scheme", "user-agent" }` will calculate MAC utilizing also HTTP request `Scheme` and `User-Agent` header. |
277280
| `request_headers` | `nil` | Set of headers to send to upstream, use `id`, `audience`, `subject`, `timeout`, `idling-timeout`, `rolling-timeout`, `absolute-timeout`. E.g. `{ "id", "timeout" }` will set `Session-Id` and `Session-Timeout` request headers when `set_headers` is called. |
278281
| `response_headers` | `nil` | Set of headers to send to downstream, use `id`, `audience`, `subject`, `timeout`, `idling-timeout`, `rolling-timeout`, `absolute-timeout`. E.g. `{ "id", "timeout" }` will set `Session-Id` and `Session-Timeout` response headers when `set_headers` is called. |
279282
| `storage` | `nil` | Storage is responsible of storing session data, use `nil` or `"cookie"` (data is stored in cookie), `"dshm"`, `"file"`, `"memcached"`, `"mysql"`, `"postgres"`, `"redis"`, or `"shm"`, or give a name of custom module (`"custom-storage"`), or a `table` that implements session storage interface. |
@@ -1051,12 +1054,13 @@ end
10511054

10521055
### session:clear_request_cookie
10531056

1054-
**syntax:** *session:clear_request_cookie()*
1057+
**syntax:** *ok, err = session:clear_request_cookie()*
10551058

10561059
Modifies the request headers by removing the session related
10571060
cookies. This is useful when you use the session library on
10581061
a proxy server and don't want the session cookies to be forwarded
1059-
to the upstream service.
1062+
to the upstream service. In error case it returns `nil` and an
1063+
error message, otherwise `true` (which can be ignored).
10601064

10611065
```lua
10621066
local session, err, exists = require "resty.session".open()
@@ -1068,9 +1072,11 @@ end
10681072

10691073
### session:set_headers
10701074

1071-
**syntax:** *session:set_headers(arg1, arg2, ...)*
1075+
**syntax:** *ok, err = session:set_headers(arg1, arg2, ...)*
10721076

10731077
Sets request and response headers based on configuration.
1078+
In error case it returns `nil` and an error message,
1079+
otherwise `true` (that can be ignored).
10741080

10751081
```lua
10761082
local session, err, exists = require "resty.session".open({
@@ -1090,9 +1096,10 @@ See [configuration](#configuration) for possible header names.
10901096

10911097
### session:set_request_headers
10921098

1093-
**syntax:** *session:set_request_headers(arg1, arg2, ...)*
1099+
**syntax:** *ok, err = session:set_request_headers(arg1, arg2, ...)*
10941100

1095-
Set request headers.
1101+
Set request headers. In error case it returns `nil` and an error message,
1102+
otherwise `true` (that can be ignored).
10961103

10971104
```lua
10981105
local session, err, exists = require "resty.session".open()
@@ -1108,9 +1115,10 @@ See [configuration](#configuration) for possible header names.
11081115

11091116
### session:set_response_headers
11101117

1111-
**syntax:** *session:set_response_headers(arg1, arg2, ...)*
1118+
**syntax:** *ok, err = session:set_response_headers(arg1, arg2, ...)*
11121119

1113-
Set request headers.
1120+
Set request headers. In error case it returns `nil` and an error message,
1121+
otherwise `true` (that can be ignored).
11141122

11151123
```lua
11161124
local session, err, exists = require "resty.session".open()
@@ -1164,7 +1172,7 @@ end
11641172

11651173
### session.info:save
11661174

1167-
**syntax:** *value = session.info:save()*
1175+
**syntax:** *ok, err = session.info:save()*
11681176

11691177
Save information. Only updates backend storage. Does not send a new cookie (except with cookie storage).
11701178

@@ -1203,7 +1211,7 @@ Header fields explained:
12031211
- SID: `32` bytes of crypto random data (Session ID).
12041212
- Created at: binary packed secs from epoch in a little endian form, truncated to 5 bytes.
12051213
- Rolling Offset: binary packed secs from creation time in a little endian form (integer).
1206-
- Size: binary packed data size (short) in a two byte little endian form.
1214+
- Size: binary packed data size in a three byte little endian form.
12071215
- Tag: `16` bytes of authentication tag from AES-256-GCM encryption of the data.
12081216
- Idling Offset: binary packed secs from creation time + rolling offset in a little endian form, truncated to 3 bytes.
12091217
- Mac: `16` bytes message authentication code of the header.

0 commit comments

Comments
 (0)