Created
November 8, 2010 12:53
-
-
Save codeboost/667668 to your computer and use it in GitHub Desktop.
test-ssl-client.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const | |
| util = require('util'), | |
| net = require('net'); | |
| var sendBug = process.argv[2] == '-bug'; | |
| var socket = net.createConnection(8001).on('connect', function(){ | |
| util.log('Connected to server'); | |
| if (!sendBug){ | |
| util.log('Setting secure'); | |
| socket.setSecure(); | |
| setInterval(function(){ | |
| var str = 'THE MESSAGE'; | |
| util.log('Sending "' + str + '"'); | |
| socket.write(str); | |
| }, 1000); | |
| } | |
| else { | |
| util.log('NOT setting secure'); | |
| util.log('Sending random data'); | |
| socket.write('\n\n\n\n\nsad\n\n\n'); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const | |
| util = require('util'), | |
| net = require('net'), | |
| crypto = require('crypto'), | |
| fs = require('fs'); | |
| var privateKey = fs.readFileSync('../cert/privatekey.pem').toString(); | |
| var certificate = fs.readFileSync('../cert/certificate.pem').toString(); | |
| var credentials = crypto.createCredentials({key: privateKey, cert: certificate}); | |
| util.log('SSL certificate and key loaded'); | |
| net.createServer(function(socket){ | |
| socket.setSecure(credentials); | |
| util.log('New connection from ' + socket.remoteAddress); | |
| socket.on('data', function(data){ | |
| util.puts('onData: "' + data.toString() + '"; ' + util.inspect(data)); | |
| }) | |
| .on('error', function(err){ | |
| util.log(socket.remoteAddress + ' error.'); | |
| }) | |
| .on('close', function(){ | |
| util.log(socket.remoteAddress + ' disconnected.'); | |
| }); | |
| }).listen(8001); | |
| util.log('SSLSocket server listening on 8001'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment