-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Openssl clientcertengine support2 #14903
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
'targets': [ | ||
{ | ||
'target_name': 'testengine', | ||
'type': 'none', | ||
'conditions': [ | ||
['OS=="mac" and ' | ||
'node_use_openssl=="true" and ' | ||
'node_shared=="false" and ' | ||
'node_shared_openssl=="false"', { | ||
'type': 'shared_library', | ||
'sources': [ 'testengine.cc' ], | ||
'product_extension': 'engine', | ||
'include_dirs': ['../../../deps/openssl/openssl/include'], | ||
'link_settings': { | ||
'libraries': [ | ||
'../../../../out/<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)' | ||
] | ||
}, | ||
}] | ||
] | ||
} | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const fixture = require('../../common/fixtures'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const engine = path.join(__dirname, | ||
`/build/${common.buildType}/testengine.engine`); | ||
|
||
if (!fs.existsSync(engine)) | ||
common.skip('no client cert engine'); | ||
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. Should this check be here? Shouldn't that be an outright error? 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. On CI, the necessary |
||
|
||
const assert = require('assert'); | ||
const https = require('https'); | ||
|
||
const agentKey = fs.readFileSync(fixture.path('/keys/agent1-key.pem')); | ||
const agentCert = fs.readFileSync(fixture.path('/keys/agent1-cert.pem')); | ||
const agentCa = fs.readFileSync(fixture.path('/keys/ca1-cert.pem')); | ||
|
||
const port = common.PORT; | ||
|
||
const serverOptions = { | ||
key: agentKey, | ||
cert: agentCert, | ||
ca: agentCa, | ||
requestCert: true, | ||
rejectUnauthorized: true | ||
}; | ||
|
||
const server = https.createServer(serverOptions, (req, res) => { | ||
res.writeHead(200); | ||
res.end('hello world'); | ||
}).listen(port, common.localhostIPv4, () => { | ||
const clientOptions = { | ||
method: 'GET', | ||
host: common.localhostIPv4, | ||
port: port, | ||
path: '/test', | ||
clientCertEngine: engine, // engine will provide key+cert | ||
rejectUnauthorized: false, // prevent failing on self-signed certificates | ||
headers: {} | ||
}; | ||
|
||
const req = https.request(clientOptions, common.mustCall(function(response) { | ||
let body = ''; | ||
response.setEncoding('utf8'); | ||
response.on('data', function(chunk) { | ||
body += chunk; | ||
}); | ||
|
||
response.on('end', common.mustCall(function() { | ||
assert.strictEqual(body, 'hello world'); | ||
server.close(); | ||
})); | ||
})); | ||
|
||
req.end(); | ||
}); |
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.
The natural way to get test coverage for this line would be to compile OpenSSL with
OPENSSL_NO_ENGINE
set. I don't think we're going to do that in CI (unless FIPS requires it maybe or something like that?). So once this lands, I'll have to open an issue to get that line covered somehow. At first I thought some straightforward monkey-patching would get to it, but it doesn't.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.
Scratch that. I was able to do it with monkey-patching after all.