Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c5b4f6b

Browse filesBrowse files
committed
tls: introduce secureContext for tls.connect
Add `secureContext` option to `tls.connect`. It is useful for caching client certificates, key, and CA certificates. PR-URL: #4246 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 425a354 commit c5b4f6b
Copy full SHA for c5b4f6b

File tree

Expand file treeCollapse file tree

3 files changed

+43
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+43
-1
lines changed
Open diff view settings
Collapse file

‎doc/api/tls.markdown‎

Copy file name to clipboardExpand all lines: doc/api/tls.markdown
+4Lines changed: 4 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ Creates a new client connection to the given `port` and `host` (old API) or
597597
SSL version 3. The possible values depend on your installation of
598598
OpenSSL and are defined in the constant [SSL_METHODS][].
599599

600+
- `secureContext`: An optional TLS context object from
601+
`tls.createSecureContext( ... )`. Could it be used for caching client
602+
certificates, key, and CA certificates.
603+
600604
- `session`: A `Buffer` instance, containing TLS session.
601605

602606
- `minDHSize`: Minimum size of DH parameter in bits to accept a TLS
Collapse file

‎lib/_tls_wrap.js‎

Copy file name to clipboardExpand all lines: lib/_tls_wrap.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ exports.connect = function(/* [port, host], options, cb */) {
984984
'localhost',
985985
NPN = {},
986986
ALPN = {},
987-
context = tls.createSecureContext(options);
987+
context = options.secureContext || tls.createSecureContext(options);
988988
tls.convertNPNProtocols(options.NPNProtocols, NPN);
989989
tls.convertALPNProtocols(options.ALPNProtocols, ALPN);
990990

Collapse file
+38Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
5+
if (!common.hasCrypto) {
6+
console.log('1..0 # Skipped: missing crypto');
7+
return;
8+
}
9+
const tls = require('tls');
10+
11+
const fs = require('fs');
12+
const path = require('path');
13+
14+
const keysDir = path.join(common.fixturesDir, 'keys');
15+
16+
const ca = fs.readFileSync(path.join(keysDir, 'ca1-cert.pem'));
17+
const cert = fs.readFileSync(path.join(keysDir, 'agent1-cert.pem'));
18+
const key = fs.readFileSync(path.join(keysDir, 'agent1-key.pem'));
19+
20+
const server = tls.createServer({
21+
cert: cert,
22+
key: key
23+
}, function(c) {
24+
c.end();
25+
}).listen(common.PORT, function() {
26+
const secureContext = tls.createSecureContext({
27+
ca: ca
28+
});
29+
30+
const socket = tls.connect({
31+
secureContext: secureContext,
32+
servername: 'agent1',
33+
port: common.PORT
34+
}, common.mustCall(function() {
35+
server.close();
36+
socket.end();
37+
}));
38+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.