Skip to content

Commit

Permalink
fixup! pass socket to server's pskCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
lundibundi committed Dec 20, 2019
1 parent 366a320 commit 596296f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -1648,6 +1648,8 @@ changes:
* `ticketKeys`: {Buffer} 48-bytes of cryptographically strong pseudo-random
data. See [Session Resumption][] for more information.
* `pskCallback` {Function}
* socket: {tls.TLSSocket} the server [`tls.TLSSocket`][] instance for
this connection.
* identity: {string} identity parameter sent from the client.
* Returns: {Buffer|TypedArray|DataView} pre-shared key that must either be
a buffer or `null` to stop the negotiation process. Returned PSK must be
Expand Down
2 changes: 1 addition & 1 deletion lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function onnewsession(sessionId, session) {

function onPskServerCallback(identity, maxPskLen) {
const owner = this[owner_symbol];
const ret = owner[kPskCallback](identity);
const ret = owner[kPskCallback](owner, identity);
if (ret == null)
return undefined;

Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tls-psk-circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ const TEST_DATA = 'x';

const serverOptions = {
ciphers: CIPHERS,
pskCallback(id) {
pskCallback(socket, id) {
assert.ok(socket instanceof tls.TLSSocket);
assert.ok(typeof id === 'string');
return USERS[id];
},
};
Expand Down
4 changes: 3 additions & 1 deletion test/parallel/test-tls-psk-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const IDENTITY = 'TestUser';
const server = tls.createServer({
ciphers: CIPHERS,
pskIdentityHint: IDENTITY,
pskCallback(identity) {
pskCallback(socket, identity) {
assert.ok(socket instanceof tls.TLSSocket);
assert.ok(typeof identity === 'string');
if (identity === IDENTITY)
return Buffer.from(KEY, 'hex');
}
Expand Down

0 comments on commit 596296f

Please sign in to comment.