0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/disabled/tls_client.js

43 lines
1.2 KiB
JavaScript
Raw Normal View History

2010-12-05 00:20:34 +01:00
var common = require('../common');
var assert = require('assert');;
var util=require('util');
2010-04-03 02:10:32 +02:00
var net=require('net');
var fs=require('fs');
2010-04-15 21:03:55 +02:00
var crypto=require('crypto');
2010-04-03 02:10:32 +02:00
//var client = net.createConnection(4443, "localhost");
var client = net.createConnection(443, "www.microsoft.com");
//var client = net.createConnection(443, "www.google.com");
var caPem = fs.readFileSync(common.fixturesDir+"/msca.pem");
2010-04-03 02:10:32 +02:00
//var caPem = fs.readFileSync("ca.pem");
try{
var credentials = crypto.createCredentials({ca:caPem});
} catch (e) {
console.log("Not compiled with OPENSSL support.");
process.exit();
}
2010-04-03 02:10:32 +02:00
client.setEncoding("UTF8");
client.addListener("connect", function () {
console.log("client connected.");
2010-04-03 02:10:32 +02:00
client.setSecure(credentials);
});
client.addListener("secure", function () {
console.log("client secure : "+JSON.stringify(client.getCipher()));
console.log(JSON.stringify(client.getPeerCertificate()));
console.log("verifyPeer : "+client.verifyPeer());
2010-04-03 02:10:32 +02:00
client.write("GET / HTTP/1.0\r\n\r\n");
});
client.addListener("data", function (chunk) {
common.error(chunk);
2010-04-03 02:10:32 +02:00
});
client.addListener("end", function () {
console.log("client disconnected.");
2010-04-03 02:10:32 +02:00
});