-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
https: throw error if required params missing #3064
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -869,9 +869,25 @@ Server.prototype.setOptions = function(options) { | |
} | ||
|
||
if (options.pfx) this.pfx = options.pfx; | ||
if (options.key) this.key = options.key; | ||
var defaultCiphers = options.ciphers === tls.DEFAULT_CIPHERS; | ||
if (!options.key) { | ||
if ((options.ciphers === undefined || defaultCiphers) && !options.pfx) { | ||
throw new Error('key is a required parameter for Server.createServer'); | ||
} | ||
} else { | ||
this.key = options.key; | ||
} | ||
|
||
if (options.passphrase) this.passphrase = options.passphrase; | ||
if (options.cert) this.cert = options.cert; | ||
|
||
if (!options.cert) { | ||
if ((options.ciphers === undefined || defaultCiphers) && !options.pfx) { | ||
throw new Error('cert is a required parameter for Server.createServer'); | ||
} | ||
} else { | ||
this.cert = options.cert; | ||
} | ||
|
||
if (options.ca) this.ca = options.ca; | ||
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. What happens if I want to set the certificate authority for reading only but not the cert/private key. 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. @cbshakumar you mean if cert authority is provided then skip this whole cert/key error handling right? 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. @kulkarniankita It has been a while since I've looked at this. Should it be possible to set the certificate authority and not set a cert? |
||
if (options.secureProtocol) this.secureProtocol = options.secureProtocol; | ||
if (options.crl) this.crl = options.crl; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const https = require('https'); | ||
const fs = require('fs'); | ||
|
||
const options1 = { | ||
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem', 'ascii'), | ||
crt: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem', 'ascii') | ||
}; | ||
|
||
const options2 = { | ||
ky: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem', 'ascii'), | ||
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem', 'ascii') | ||
}; | ||
|
||
assert.throws(() => https.createServer(options1, assert.fail), | ||
'cert is a required parameter for Server.createServer'); | ||
|
||
assert.throws(() => https.createServer(options2, assert.fail), | ||
'key is a required parameter for Server.createServer'); |
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.
assert(options.cert, 'cert is required parameter for ...')
, maybe?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.
@indutny Right now I test this way:
assert.throws(() => https.createServer(options1, assert.fail),'cert is a required parameter for server.createServer');
Is one better than the other? If so I am curious to understand why?