Add some verification code to tls.connect()
authorRyan Dahl <ry@tinyclouds.org>
Thu, 9 Dec 2010 10:35:16 +0000 (02:35 -0800)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 9 Dec 2010 10:46:57 +0000 (02:46 -0800)
lib/tls.js
test/disabled/tls-client.js

index 45c0cde..b0af617 100644 (file)
@@ -608,14 +608,16 @@ exports.connect = function(port /* host, options, cb */) {
   socket.connect(port, host);
 
   pair.on('secure', function() {
-    console.log('client cleartext.getPeerCertificate(): %j',
-                cleartext.getPeerCertificate());
-    console.log('client cleartext.getCipher(): %j',
-                cleartext.getCipher());
+    var verifyError = pair._ssl.verifyError();
 
-    if (cb) {
-      cb(cleartext);
+    if (verifyError) {
+      cleartext.authorized = false;
+      cleartext.authorizationError = verifyError;
+    } else {
+      cleartext.authorized = true;
     }
+
+    if (cb) cb();
   });
 
   return cleartext;
index a323c25..8383582 100644 (file)
@@ -10,8 +10,12 @@ var options = {
 };
 
 
-var s = tls.connect(443, "google.com", options, function() {
-  console.error("CONNECTED");
+var s = tls.connect(443, "joyent.com", options, function() {
+  if (!s.authorized) {
+    console.error("CONNECTED: " +  s.authorizationError);
+    s.destroy();
+    return;
+  }
   s.pipe(process.stdout);
   process.openStdin().pipe(s);
 });