Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
fc041a8
tls: Applied PR #6701 to master, and updated outdated code snippets, …
taylorzane Aug 22, 2017
9e188bc
tls: Updated TLS-PSK Circuit test to pass all assertions.
taylorzane Aug 22, 2017
51db277
tls: Updated TLS documentation to detail that pskIdentity must be enc…
taylorzane Aug 22, 2017
09b9a8e
tls: Updated TLS-PSK tests to use `method() {}` syntax instead of `me…
taylorzane Aug 22, 2017
e954c49
tls: Updated SetPskIdentity to not throw when provided with too many …
taylorzane Aug 22, 2017
caadeaf
tls: Updated createSecureContext TLS-PSK logic to use `internal/error…
taylorzane Aug 22, 2017
45c120b
tls: Updated formatting to conform with eslint rules.
taylorzane Aug 22, 2017
eef89b8
tls: Added #14978 PR to the `changes:` section. Improved wording of p…
taylorzane Aug 22, 2017
6f095f8
tls: Updated tests to use the `common.skip` method when crypto is not…
taylorzane Aug 22, 2017
ba22b97
tls: Updated `onpskexchange` callback to use `ArrayBuffer.isView`. Cl…
taylorzane Aug 22, 2017
ba0727e
tls: Added `HandleScope` to PSK callbacks. Updated calls to `onpskexc…
taylorzane Aug 22, 2017
361b5ed
tls: Updated a few `assert` calls to use the proper `CHECK` call.
taylorzane Aug 22, 2017
49a285f
tls: Updated PSK callbacks to use `MaybeLocal` overload of `NewFromUt…
taylorzane Aug 22, 2017
16921ab
tls: Updated docs and tests to reflect changes to the TLS-PSK API.
taylorzane Aug 23, 2017
959887e
tls: Updated TLS-PSK API to only accept strings for `psk` and `identi…
taylorzane Aug 23, 2017
65cb351
tls: Updated TLS-PSK tests to not use `common.PORT` when possible. Ad…
taylorzane Aug 25, 2017
7b43283
tls: Updated TLS to check that TLS-PSK callback is a function. Update…
taylorzane Aug 25, 2017
bbbb658
tls: Updated `PSKClientCallback` to use a better method for casting a…
taylorzane Aug 25, 2017
5136c93
tls: Fixed linter error in _tls_common.js.
taylorzane Aug 25, 2017
6ed9f92
tls: Updated `PSKServerCallback` to use a better method for casting a…
taylorzane Aug 25, 2017
97a71bd
tls: Renamed `pskIdentity` to `pskIdentityHint`. Updated errors to us…
taylorzane Apr 13, 2018
b810f97
tls: Updated PSK callbacks to use the new syntax for getting the SSL …
taylorzane Apr 13, 2018
92fc64e
tls: Updated PSK tests to use new error messages, improved test asser…
taylorzane Apr 13, 2018
4880511
tls: Resolved lint errors.
taylorzane Apr 13, 2018
40fae68
tls: Updated PSK code to latest best practices.
taylorzane Apr 25, 2018
001b3bd
tls: Removed an unused env string.
taylorzane Apr 25, 2018
34e54c9
tls: Updated PSK functions to use automatic memory management.
taylorzane May 24, 2018
31fff46
tls: Add PSK support
taylorzane Aug 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tls: Resolved lint errors.
  • Loading branch information
taylorzane committed Oct 1, 2018
commit 4880511a815964e2525dac0949cae1837aba4e7b
20 changes: 4 additions & 16 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,8 @@ changes:
`ciphers` option. Additionally, it may be necessary to disable
`rejectUnauthorized` if a client attempts to specify a certificate for the
session.
* *Note*: `psk` must be a hexadecimal string, `identity` must use UTF-8 encoding.
* *Note*: `psk` must be a hexadecimal string,
`identity` must use UTF-8 encoding.
* `NPNProtocols` {string[]|Buffer[]|Uint8Array[]|Buffer|Uint8Array}
An array of strings, `Buffer`s or `Uint8Array`s, or a single `Buffer` or
`Uint8Array` containing supported NPN protocols. `Buffer`s should have the
Expand Down Expand Up @@ -1211,7 +1212,8 @@ changes:
a 16-byte HMAC key, and a 16-byte AES key. This can be used to accept TLS
session tickets on multiple instances of the TLS server.
* ...: Any [`tls.createSecureContext()`][] options can be provided. For
servers, the identity options (`pfx`, `key`/`cert` or `pskCallback`) are usually required.
servers, the identity options (`pfx`, `key`/`cert` or `pskCallback`)
are usually required.
* `secureConnectionListener` {Function}

Creates a new [`tls.Server`][]. The `secureConnectionListener`, if provided, is
Expand Down Expand Up @@ -1369,20 +1371,6 @@ changes:
certificate from a connecting client. Only applies when `isServer` is `true`.
* `rejectUnauthorized` {boolean} If not `false` a server automatically reject
clients with invalid certificates. Only applies when `isServer` is `true`.
* `pskCallback(hint)` {Function} When negotiating TLS-PSK, this optional
function is called with the identity hint provided by the server. If the
client should continue to negotiate PSK ciphers, the return value of this
function must be an object in the form `{psk: <string>, identity:
<string>}`.
* *Note*: PSK ciphers are disabled by default, and using
TLS-PSK thus requires explicitly specifying a cipher suite with the
`ciphers` option. Additionally, it may be necessary to disable
`rejectUnauthorized` if a client attempts to specify a certificate for the
session.
* *Note*: `psk` must be a hexadecimal string.
* `pskIdentityHint`: {string} The identity hint to send to clients when
negotiating TLS-PSK.
* *Note*: Must use UTF-8 encoding.
* `options`
* `secureContext`: A TLS context object from [`tls.createSecureContext()`][]
* `isServer`: If `true` the TLS socket will be instantiated in server-mode.
Expand Down
12 changes: 5 additions & 7 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const { parseCertString } = require('internal/tls');
const { isArrayBufferView } = require('internal/util/types');
const tls = require('tls');
const {
ERR_ASSERTION,
ERR_CRYPTO_CUSTOM_ENGINE_NOT_SUPPORTED,
ERR_INVALID_ARG_TYPE
} = require('internal/errors').codes;
const Buffer = require('buffer').Buffer;

const { SSL_OP_CIPHER_SERVER_PREFERENCE } = process.binding('constants').crypto;

Expand Down Expand Up @@ -165,7 +165,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (options.pskCallback && c.context.enablePskCallback) {
if (typeof options.pskCallback !== 'function') {
throw new ERR_INVALID_ARG_TYPE('pskCallback',
'function', options.pskCallback);
'function', options.pskCallback);
}

c.context.onpskexchange = (identity, maxPskLen, maxIdentLen) => {
Expand All @@ -181,8 +181,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
throw new ERR_INVALID_ARG_TYPE('psk', ['string']);
}
if (ret.psk.length / 2 > maxPskLen) {
throw new errors.RangeError(
'ERR_ASSERTION',
throw new ERR_ASSERTION(
`Pre-shared key exceeds ${maxPskLen} bytes`
);
}
Expand All @@ -191,11 +190,10 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (maxIdentLen) {
if (typeof ret.identity !== 'string') {
throw new ERR_INVALID_ARG_TYPE('identity',
'string');
'string');
}
if (ret.identity.length > maxIdentLen) {
throw new errors.RangeError(
'ERR_ASSERTION',
throw new ERR_ASSERTION(
`PSK identity exceeds ${maxIdentLen} bytes`
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/node_crypto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ using v8::DontDelete;
using v8::EscapableHandleScope;
using v8::Exception;
using v8::External;
using v8::False;
using v8::Function;
using v8::FunctionCallbackInfo;
using v8::FunctionTemplate;
Expand Down Expand Up @@ -1397,7 +1396,7 @@ void SecureContext::SetPskIdentity(const FunctionCallbackInfo<Value>& args) {
return wrap->env()->ThrowTypeError("Argument must be a string");
}

String::Utf8Value identity(args[0]);
String::Utf8Value identity(args.GetIsolate(), args[0]);
if (!SSL_CTX_use_psk_identity_hint(wrap->ctx_, *identity)) {
return wrap->env()->ThrowError("Failed to set PSK identity hint");
}
Expand Down Expand Up @@ -1559,7 +1558,7 @@ unsigned int SecureContext::PskClientCallback(SSL *ssl,

Local<String> identity_str = identity_val.As<String>();
size_t identity_len = identity_str->Length();
String::Utf8Value identity_buf(identity_str);
String::Utf8Value identity_buf(isolate, identity_str);

CHECK_LE(identity_len, max_identity_len);
memcpy(identity, *identity_buf, identity_len);
Expand Down
8 changes: 6 additions & 2 deletions test/parallel/test-tls-psk-circuit.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ function startTest(port) {
doTestCase(0);
}

const DISCONNECT_MESSAGE =
'Client network socket disconnected before ' +
'secure TLS connection was established';

process.on('exit', () => {
assert.deepStrictEqual(clientResults, [
'connect',
'connect',
'Client network socket disconnected before secure TLS connection was established',
'Client network socket disconnected before secure TLS connection was established',
DISCONNECT_MESSAGE,
DISCONNECT_MESSAGE,
'connect'
]);
assert.deepStrictEqual(connectingIds, [
Expand Down
4 changes: 2 additions & 2 deletions test/parallel/test-tls-psk-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const IDENTITY = 'Client_identity'; // Hardcoded by openssl

const server = spawn(common.opensslCli, [
's_server',
'-accept', 54323 /*common.PORT*/,
'-accept', 54323 /* common.PORT */,
'-cipher', CIPHERS,
'-psk', KEY,
'-psk_hint', IDENTITY,
Expand Down Expand Up @@ -68,7 +68,7 @@ server.on('exit', (code) => {


function startClient() {
const s = tls.connect(54323 /*common.PORT*/, {
const s = tls.connect(54323 /* common.PORT */, {
ciphers: CIPHERS,
rejectUnauthorized: false,
pskCallback(hint) {
Expand Down
1 change: 0 additions & 1 deletion test/parallel/test-tls-psk-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,3 @@ server.listen(0, () => {
server.close();
}));
});