I have various test suites that use self-signed certs to test HTTPS/TLS stuff. I'm trying to use the 'ca' option of the tls and https clients to make them trust my certs, rather than forgoing validation at all, since I would rather give my projects APIs for adding CAs than for disabling validation.
However when I pass my server certificate in the 'ca' option of an HTTPS request I get this error:
var https = require('https'),
fs = require('fs');
var server = https.createServer({
cert: fs.readFileSync('./server.crt'),
key: fs.readFileSync('./server.key')
});
server.on('request', function(request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello\n');
});
server.listen(8000);
// client.js
var https = require('https'),
fs = require('fs');
var request = https.request({
method: 'GET',
host: 'localhost',
port: 8000,
path: '/',
ca: [fs.readFileSync('./server.crt')]
});
request.on('error', function(error) {
console.log('ERROR', error);
});
request.on('response', function(response) {
console.log(response.statusCode);
});
--
James Coglan
http://jcoglan.com+44 (0) 7771512510