mirror of https://github.com/lukechilds/node.git
Rhys Jones
15 years ago
committed by
Ryan Dahl
10 changed files with 743 additions and 12 deletions
@ -0,0 +1,20 @@ |
|||||
|
-----BEGIN CERTIFICATE----- |
||||
|
MIIDXDCCAsWgAwIBAgIJAKL0UG+mRkSPMA0GCSqGSIb3DQEBBQUAMH0xCzAJBgNV |
||||
|
BAYTAlVLMRQwEgYDVQQIEwtBY2tuYWNrIEx0ZDETMBEGA1UEBxMKUmh5cyBKb25l |
||||
|
czEQMA4GA1UEChMHbm9kZS5qczEdMBsGA1UECxMUVGVzdCBUTFMgQ2VydGlmaWNh |
||||
|
dGUxEjAQBgNVBAMTCWxvY2FsaG9zdDAeFw0wOTExMTEwOTUyMjJaFw0yOTExMDYw |
||||
|
OTUyMjJaMH0xCzAJBgNVBAYTAlVLMRQwEgYDVQQIEwtBY2tuYWNrIEx0ZDETMBEG |
||||
|
A1UEBxMKUmh5cyBKb25lczEQMA4GA1UEChMHbm9kZS5qczEdMBsGA1UECxMUVGVz |
||||
|
dCBUTFMgQ2VydGlmaWNhdGUxEjAQBgNVBAMTCWxvY2FsaG9zdDCBnzANBgkqhkiG |
||||
|
9w0BAQEFAAOBjQAwgYkCgYEA8d8Hc6atq78Jt1HLp9agA/wpQfsFvkYUdZ1YsdvO |
||||
|
kL2janjwHQgMMCy/Njal3FUEW0OLPebKZUJ8L44JBXSlVxU4zyiiSOWld8EkTetR |
||||
|
AVT3WKQq3ud+cnxv7g8rGRQp1UHZwmdbZ1wEfAYq8QjYx6m1ciMgRo7DaDQhD29k |
||||
|
d+UCAwEAAaOB4zCB4DAdBgNVHQ4EFgQUL9miTJn+HKNuTmx/oMWlZP9cd4QwgbAG |
||||
|
A1UdIwSBqDCBpYAUL9miTJn+HKNuTmx/oMWlZP9cd4ShgYGkfzB9MQswCQYDVQQG |
||||
|
EwJVSzEUMBIGA1UECBMLQWNrbmFjayBMdGQxEzARBgNVBAcTClJoeXMgSm9uZXMx |
||||
|
EDAOBgNVBAoTB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ud+cnxv7g8rGRQp1UHZwmdbZ1wEfAYq8QjYx6m1ciMgRo7DaDQhD29k |
||||
|
d+UCAwEAAaOB4zCB4DAdBgNVHQ4EFgQUL9miTJn+HKNuTmx/oMWlZP9cd4QwgbAG |
||||
|
A1UdIwSBqDCBpYAUL9miTJn+HKNuTmx/oMWlZP9cd4ShgYGkfzB9MQswCQYDVQQG |
||||
|
EwJVSzEUMBIGA1UECBMLQWNrbmFjayBMdGQxEzARBgNVBAcTClJoeXMgSm9uZXMx |
||||
|
EDAOBgNVBAoTB25vZGUuanMxHTAbBgNVBAsTFFRlc3QgVExTIENlcnRpZmljYXRl |
||||
|
MRIwEAYDVQQDEwlsb2NhbGhvc3SCCQCi9FBvpkZEjzAMBgNVHRMEBTADAQH/MA0G |
||||
|
CSqGSIb3DQEBBQUAA4GBADRXXA2xSUK5W1i3oLYWW6NEDVWkTQ9RveplyeS9MOkP |
||||
|
e7yPcpz0+O0ZDDrxR9chAiZ7fmdBBX1Tr+pIuCrG/Ud49SBqeS5aMJGVwiSd7o1n |
||||
|
dhU2Sz3Q60DwJEL1VenQHiVYlWWtqXBThe9ggqRPnCfsCRTP8qifKkjk45zWPcpN |
||||
|
-----END CERTIFICATE----- |
@ -0,0 +1,15 @@ |
|||||
|
-----BEGIN RSA PRIVATE KEY----- |
||||
|
MIICXQIBAAKBgQDx3wdzpq2rvwm3Ucun1qAD/ClB+wW+RhR1nVix286QvaNqePAd |
||||
|
CAwwLL82NqXcVQRbQ4s95splQnwvjgkFdKVXFTjPKKJI5aV3wSRN61EBVPdYpCre |
||||
|
535yfG/uDysZFCnVQdnCZ1tnXAR8BirxCNjHqbVyIyBGjsNoNCEPb2R35QIDAQAB |
||||
|
AoGBAJNem9C4ftrFNGtQ2DB0Udz7uDuucepkErUy4MbFsc947GfENjDKJXr42Kx0 |
||||
|
kYx09ImS1vUpeKpH3xiuhwqe7tm4FsCBg4TYqQle14oxxm7TNeBwwGC3OB7hiokb |
||||
|
aAjbPZ1hAuNs6ms3Ybvvj6Lmxzx42m8O5DXCG2/f+KMvaNUhAkEA/ekrOsWkNoW9 |
||||
|
2n3m+msdVuxeek4B87EoTOtzCXb1dybIZUVv4J48VAiM43hhZHWZck2boD/hhwjC |
||||
|
M5NWd4oY6QJBAPPcgBVNdNZSZ8hR4ogI4nzwWrQhl9MRbqqtfOn2TK/tjMv10ALg |
||||
|
lPmn3SaPSNRPKD2hoLbFuHFERlcS79pbCZ0CQQChX3PuIna/gDitiJ8oQLOg7xEM |
||||
|
wk9TRiDK4kl2lnhjhe6PDpaQN4E4F0cTuwqLAoLHtrNWIcOAQvzKMrYdu1MhAkBm |
||||
|
Et3qDMnjDAs05lGT72QeN90/mPAcASf5eTTYGahv21cb6IBxM+AnwAPpqAAsHhYR |
||||
|
9h13Y7uYbaOjvuF23LRhAkBoI9eaSMn+l81WXOVUHnzh3ZwB4GuTyxMXXNOhuiFd |
||||
|
0z4LKAMh99Z4xQmqSoEkXsfM4KPpfhYjF/bwIcP5gOei |
||||
|
-----END RSA PRIVATE KEY----- |
@ -0,0 +1,122 @@ |
|||||
|
process.mixin(require("./common")); |
||||
|
tcp = require("tcp"); |
||||
|
posix=require("posix"); |
||||
|
|
||||
|
var tests_run = 0; |
||||
|
|
||||
|
function tlsTest (port, host, caPem, keyPem, certPem) { |
||||
|
var N = 50; |
||||
|
var count = 0; |
||||
|
var sent_final_ping = false; |
||||
|
|
||||
|
var server = tcp.createServer(function (socket) { |
||||
|
assertTrue(socket.remoteAddress !== null); |
||||
|
assertTrue(socket.remoteAddress !== undefined); |
||||
|
if (host === "127.0.0.1") |
||||
|
assertEquals(socket.remoteAddress, "127.0.0.1"); |
||||
|
else if (host == null) |
||||
|
assertEquals(socket.remoteAddress, "127.0.0.1"); |
||||
|
|
||||
|
socket.setEncoding("utf8"); |
||||
|
socket.setNoDelay(); |
||||
|
socket.timeout = 0; |
||||
|
|
||||
|
socket.addListener("receive", function (data) { |
||||
|
var verified = socket.verifyPeer(); |
||||
|
var peerDN = socket.getPeerCertificate("DNstring"); |
||||
|
assertEquals(verified, 1); |
||||
|
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," |
||||
|
+ "OU=Test TLS Certificate,CN=localhost"); |
||||
|
puts("server got: " + JSON.stringify(data)); |
||||
|
assertEquals("open", socket.readyState); |
||||
|
assertTrue(count <= N); |
||||
|
if (/PING/.exec(data)) { |
||||
|
socket.send("PONG"); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
socket.addListener("eof", function () { |
||||
|
assertEquals("writeOnly", socket.readyState); |
||||
|
socket.close(); |
||||
|
}); |
||||
|
|
||||
|
socket.addListener("close", function (had_error) { |
||||
|
assertFalse(had_error); |
||||
|
assertEquals("closed", socket.readyState); |
||||
|
socket.server.close(); |
||||
|
}); |
||||
|
}); |
||||
|
|
||||
|
server.setSecure('X509_PEM', caPem, 0, keyPem, certPem); |
||||
|
server.listen(port, host); |
||||
|
|
||||
|
var client = tcp.createConnection(port, host); |
||||
|
|
||||
|
client.setEncoding("utf8"); |
||||
|
client.setSecure('X509_PEM', caPem, 0, keyPem, caPem); |
||||
|
|
||||
|
client.addListener("connect", function () { |
||||
|
assertEquals("open", client.readyState); |
||||
|
var verified = client.verifyPeer(); |
||||
|
var peerDN = client.getPeerCertificate("DNstring"); |
||||
|
assertEquals(verified, 1); |
||||
|
assertEquals(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js," |
||||
|
+ "OU=Test TLS Certificate,CN=localhost"); |
||||
|
client.send("PING"); |
||||
|
}); |
||||
|
|
||||
|
client.addListener("receive", function (data) { |
||||
|
assertEquals("PONG", data); |
||||
|
count += 1; |
||||
|
|
||||
|
puts("client got PONG"); |
||||
|
|
||||
|
if (sent_final_ping) { |
||||
|
assertEquals("readOnly", client.readyState); |
||||
|
return; |
||||
|
} else { |
||||
|
assertEquals("open", client.readyState); |
||||
|
} |
||||
|
|
||||
|
if (count < N) { |
||||
|
client.send("PING"); |
||||
|
} else { |
||||
|
sent_final_ping = true; |
||||
|
client.send("PING"); |
||||
|
client.close(); |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
client.addListener("close", function () { |
||||
|
assertEquals(N+1, count); |
||||
|
assertTrue(sent_final_ping); |
||||
|
tests_run += 1; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
var have_tls; |
||||
|
try { |
||||
|
var dummy_server = tcp.createServer(); |
||||
|
dummy_server.setSecure(); |
||||
|
have_tls=true; |
||||
|
} catch (e) { |
||||
|
have_tls=false; |
||||
|
} |
||||
|
|
||||
|
if (have_tls) { |
||||
|
var caPem = posix.cat(fixturesDir+"/test_ca.pem").wait(); |
||||
|
var certPem = posix.cat(fixturesDir+"/test_cert.pem").wait(); |
||||
|
var keyPem = posix.cat(fixturesDir+"/test_key.pem").wait(); |
||||
|
|
||||
|
/* All are run at once, so run on different ports */ |
||||
|
tlsTest(20443, "localhost", caPem, keyPem, certPem); |
||||
|
tlsTest(21443, null, caPem, keyPem, certPem); |
||||
|
|
||||
|
process.addListener("exit", function () { |
||||
|
assertEquals(2, tests_run); |
||||
|
}); |
||||
|
} else { |
||||
|
puts("Not compiled with TLS support."); |
||||
|
process.exit(1); |
||||
|
} |
Loading…
Reference in new issue