2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2013-10-18 23:14:21 +02:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
2015-03-04 02:11:21 +01:00
|
|
|
if (!common.hasCrypto) {
|
|
|
|
console.log('1..0 # Skipped: missing crypto');
|
2015-07-07 17:25:55 +02:00
|
|
|
return;
|
2013-10-18 23:14:21 +02:00
|
|
|
}
|
2015-03-04 02:11:21 +01:00
|
|
|
var crypto = require('crypto');
|
|
|
|
var tls = require('tls');
|
2013-10-18 23:14:21 +02:00
|
|
|
|
|
|
|
crypto.DEFAULT_ENCODING = 'buffer';
|
|
|
|
|
|
|
|
var fs = require('fs');
|
|
|
|
|
|
|
|
var certPem = fs.readFileSync(common.fixturesDir + '/test_cert.pem', 'ascii');
|
|
|
|
|
|
|
|
var options = {
|
|
|
|
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
|
|
|
|
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
|
|
|
|
};
|
|
|
|
|
|
|
|
var canSend = true;
|
|
|
|
|
|
|
|
var server = tls.Server(options, function(socket) {
|
2013-10-25 20:26:05 +02:00
|
|
|
setImmediate(function() {
|
2015-05-19 13:00:06 +02:00
|
|
|
console.log('sending');
|
|
|
|
verify();
|
|
|
|
setImmediate(function() {
|
|
|
|
socket.destroy();
|
|
|
|
});
|
2013-10-18 23:14:21 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
var client;
|
|
|
|
|
|
|
|
function verify() {
|
|
|
|
console.log('verify');
|
|
|
|
var verified = crypto.createVerify('RSA-SHA1')
|
|
|
|
.update('Test')
|
|
|
|
.verify(certPem, 'asdfasdfas', 'base64');
|
|
|
|
}
|
|
|
|
|
|
|
|
server.listen(common.PORT, function() {
|
|
|
|
client = tls.connect({
|
|
|
|
port: common.PORT,
|
|
|
|
rejectUnauthorized: false
|
|
|
|
}, function() {
|
|
|
|
verify();
|
|
|
|
}).on('data', function(data) {
|
|
|
|
console.log(data);
|
|
|
|
}).on('error', function(err) {
|
|
|
|
throw err;
|
|
|
|
}).on('close', function() {
|
|
|
|
server.close();
|
|
|
|
}).resume();
|
|
|
|
});
|
|
|
|
|
|
|
|
server.unref();
|