-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
tls: multiple PFX support in createSecureContext #14793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
21e2413
a389780
f8fdff4
f2607b3
17a9522
be2756d
501fe05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Add support for multiple PFX files in tls.createSecureContext. Also added support for object-style PFX pass. Fixes: #14756
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -161,19 +161,34 @@ exports.createSecureContext = function createSecureContext(options, context) { | |
| } | ||
|
|
||
| if (options.pfx) { | ||
| var pfx = options.pfx; | ||
|
|
||
| if (!crypto) | ||
| crypto = require('crypto'); | ||
|
|
||
| pfx = crypto._toBuf(pfx); | ||
| if (passphrase) | ||
| passphrase = crypto._toBuf(passphrase); | ||
|
|
||
| if (passphrase) { | ||
| c.context.loadPKCS12(pfx, passphrase); | ||
| const Buffer = require('buffer').Buffer; | ||
|
|
||
| if (Array.isArray(options.pfx)) { | ||
| for (i = 0; i < options.pfx.length; i++) { | ||
| const pfx = options.pfx[i]; | ||
| let buf; | ||
| if (pfx.buffer instanceof Buffer) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, should this be limited to just
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #14978 (comment) :D
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK |
||
| buf = crypto._toBuf(pfx.buffer); | ||
| } else { | ||
| buf = crypto._toBuf(pfx); | ||
| } | ||
| const passphrase = pfx.passphrase || options.passphrase; | ||
| if (passphrase) { | ||
| c.context.loadPKCS12(buf, crypto._toBuf(passphrase)); | ||
| } else { | ||
| c.context.loadPKCS12(buf); | ||
| } | ||
| } | ||
| } else { | ||
| c.context.loadPKCS12(pfx); | ||
| const buf = crypto._toBuf(options.pfx); | ||
| const passphrase = options.passphrase; | ||
| if (passphrase) { | ||
| c.context.loadPKCS12(buf, crypto._toBuf(passphrase)); | ||
| } else { | ||
| c.context.loadPKCS12(buf); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| 'use strict'; | ||
| const common = require('../common'); | ||
| if (!common.hasCrypto) | ||
| common.skip('missing crypto'); | ||
|
|
||
| const assert = require('assert'); | ||
| const tls = require('tls'); | ||
| const fs = require('fs'); | ||
|
|
||
| const options = { | ||
| pfx: [ | ||
| { | ||
| buffer: fs.readFileSync(`${common.fixturesDir}/keys/agent1-pfx.pem`), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the new const fixtures = require('../common/fixtures');
/*... */
{
buffer: fixtures.readKey('agent1-pfx.pem')
} |
||
| passphrase: 'sample' | ||
| }, | ||
| fs.readFileSync(`${common.fixturesDir}/keys/ec-pfx.pem`) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should add a third case for when an object is supplied with an encrypted key and the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK (partially). Maybe add separate case out of "multi-pfx" test? |
||
| ] | ||
| }; | ||
|
|
||
| const ciphers = []; | ||
|
|
||
| const server = tls.createServer(options, function(conn) { | ||
| conn.end('ok'); | ||
| }).listen(0, function() { | ||
| const ecdsa = tls.connect(this.address().port, { | ||
| ciphers: 'ECDHE-ECDSA-AES256-GCM-SHA384', | ||
| rejectUnauthorized: false | ||
| }, function() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jasnell in listen (L24) also? Or not necessary? |
||
| ciphers.push(ecdsa.getCipher()); | ||
| const rsa = tls.connect(server.address().port, { | ||
| ciphers: 'ECDHE-RSA-AES256-GCM-SHA384', | ||
| rejectUnauthorized: false | ||
| }, function() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ciphers.push(rsa.getCipher()); | ||
| ecdsa.end(); | ||
| rsa.end(); | ||
| server.close(); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| process.on('exit', function() { | ||
| assert.deepStrictEqual(ciphers, [{ | ||
| name: 'ECDHE-ECDSA-AES256-GCM-SHA384', | ||
| version: 'TLSv1/SSLv3' | ||
| }, { | ||
| name: 'ECDHE-RSA-AES256-GCM-SHA384', | ||
| version: 'TLSv1/SSLv3' | ||
| }]); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come
stringis not supported anymore?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PKCS12 is very rarely stored in PEM format, by default it's DER-encoded. But I forget about binary strings in JS. Will revert it, ACK.