Skip to content

Commit 61ec2af

Browse files
mildsunrisemarco-ippolito
authored andcommitted
doc: move all TLS-PSK documentation to its section
PR-URL: #35717 Reviewed-By: Rich Trott <[email protected]>
1 parent 2b07d01 commit 61ec2af

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

doc/api/tls.md

+29-38
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ specifying a cipher suite with the `ciphers` option. The list of available
173173
ciphers can be retrieved via `openssl ciphers -v 'PSK'`. All TLS 1.3
174174
ciphers are eligible for PSK and can be retrieved via
175175
`openssl ciphers -v -s -tls1_3 -psk`.
176+
On the client connection, a custom `checkServerIdentity` should be passed
177+
because the default one will fail in the absence of a certificate.
176178

177179
According to the [RFC 4279][], PSK identities up to 128 bytes in length and
178180
PSKs up to 64 bytes in length must be supported. As of OpenSSL 1.1.0
@@ -181,6 +183,30 @@ maximum identity size is 128 bytes, and maximum PSK length is 256 bytes.
181183
The current implementation doesn't support asynchronous PSK callbacks due to the
182184
limitations of the underlying OpenSSL API.
183185

186+
To use TLS-PSK, client and server must specify the `pskCallback` option,
187+
a function that returns the PSK to use (which must be compatible with
188+
the selected cipher's digest).
189+
190+
It will be called first on the client:
191+
192+
* hint: {string} optional message sent from the server to help the client
193+
decide which identity to use during negotiation.
194+
Always `null` if TLS 1.3 is used.
195+
* Returns: {Object} in the form
196+
`{ psk: <Buffer|TypedArray|DataView>, identity: <string> }` or `null`.
197+
198+
Then on the server:
199+
200+
* socket: {tls.TLSSocket} the server socket instance, equivalent to `this`.
201+
* identity: {string} identity parameter sent from the client.
202+
* Returns: {Buffer|TypedArray|DataView} the PSK (or `null`).
203+
204+
A return value of `null` stops the negotiation process and sends an
205+
`unknown_psk_identity` alert message to the other party.
206+
If the server wishes to hide the fact that the PSK identity was not known,
207+
the callback must provide some random data as `psk` to make the connection
208+
fail with `decrypt_error` before negotiation is finished.
209+
184210
### Client-initiated renegotiation attack mitigation
185211

186212
<!-- type=misc -->
@@ -1646,25 +1672,7 @@ changes:
16461672
verified against the list of supplied CAs. An `'error'` event is emitted if
16471673
verification fails; `err.code` contains the OpenSSL error code. **Default:**
16481674
`true`.
1649-
* `pskCallback` {Function}
1650-
1651-
* hint: {string} optional message sent from the server to help client
1652-
decide which identity to use during negotiation.
1653-
Always `null` if TLS 1.3 is used.
1654-
* Returns: {Object} An object in the form
1655-
`{ psk: <Buffer|TypedArray|DataView>, identity: <string> }`
1656-
or `null` to stop the negotiation process. `psk` must be
1657-
compatible with the selected cipher's digest.
1658-
`identity` must use UTF-8 encoding.
1659-
1660-
When negotiating TLS-PSK (pre-shared keys), this function is called
1661-
with optional identity `hint` provided by the server or `null`
1662-
in case of TLS 1.3 where `hint` was removed.
1663-
It will be necessary to provide a custom `tls.checkServerIdentity()`
1664-
for the connection as the default one will try to check host name/IP
1665-
of the server against the certificate but that's not applicable for PSK
1666-
because there won't be a certificate present.
1667-
More information can be found in the [RFC 4279][].
1675+
* `pskCallback` {Function} For TLS-PSK negotiation, see [Pre-shared keys][].
16681676
* `ALPNProtocols`: {string\[]|Buffer\[]|TypedArray\[]|DataView\[]|Buffer|
16691677
TypedArray|DataView}
16701678
An array of strings, `Buffer`s, `TypedArray`s, or `DataView`s, or a
@@ -2119,25 +2127,7 @@ changes:
21192127
default callback with high-level API will be used (see below).
21202128
* `ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudorandom
21212129
data. See [Session Resumption][] for more information.
2122-
* `pskCallback` {Function}
2123-
2124-
* socket: {tls.TLSSocket} the server [`tls.TLSSocket`][] instance for
2125-
this connection.
2126-
* identity: {string} identity parameter sent from the client.
2127-
* Returns: {Buffer|TypedArray|DataView} pre-shared key that must either be
2128-
a buffer or `null` to stop the negotiation process. Returned PSK must be
2129-
compatible with the selected cipher's digest.
2130-
2131-
When negotiating TLS-PSK (pre-shared keys), this function is called
2132-
with the identity provided by the client.
2133-
If the return value is `null` the negotiation process will stop and an
2134-
"unknown\_psk\_identity" alert message will be sent to the other party.
2135-
If the server wishes to hide the fact that the PSK identity was not known,
2136-
the callback must provide some random data as `psk` to make the connection
2137-
fail with "decrypt\_error" before negotiation is finished.
2138-
PSK ciphers are disabled by default, and using TLS-PSK thus
2139-
requires explicitly specifying a cipher suite with the `ciphers` option.
2140-
More information can be found in the [RFC 4279][].
2130+
* `pskCallback` {Function} For TLS-PSK negotiation, see [Pre-shared keys][].
21412131
* `pskIdentityHint` {string} optional hint to send to a client to help
21422132
with selecting the identity during TLS-PSK negotiation. Will be ignored
21432133
in TLS 1.3. Upon failing to set pskIdentityHint `'tlsClientError'` will be
@@ -2286,6 +2276,7 @@ added: v19.8.0
22862276
[Mozilla's publicly trusted list of CAs]: https://hg.mozilla.org/mozilla-central/raw-file/tip/security/nss/lib/ckfw/builtins/certdata.txt
22872277
[OCSP request]: https://en.wikipedia.org/wiki/OCSP_stapling
22882278
[OpenSSL Options]: crypto.md#openssl-options
2279+
[Pre-shared keys]: #pre-shared-keys
22892280
[RFC 2246]: https://www.ietf.org/rfc/rfc2246.txt
22902281
[RFC 4086]: https://tools.ietf.org/html/rfc4086
22912282
[RFC 4279]: https://tools.ietf.org/html/rfc4279

0 commit comments

Comments
 (0)