From 2706f369c754a20dbe71b3b7cdb7885d8905123a Mon Sep 17 00:00:00 2001
From: Lloyd Hilaiel <lloyd@hilaiel.com>
Date: Fri, 4 Nov 2011 02:43:10 -0600
Subject: [PATCH] re-enable the keysigner!  issue #460

---
 lib/browserid/http_forward.js | 12 ++++++++----
 lib/browserid/wsapi.js        | 21 ---------------------
 2 files changed, 8 insertions(+), 25 deletions(-)

diff --git a/lib/browserid/http_forward.js b/lib/browserid/http_forward.js
index 61f431f5d..3eec38ed9 100644
--- a/lib/browserid/http_forward.js
+++ b/lib/browserid/http_forward.js
@@ -16,10 +16,14 @@ module.exports = function(dest, req, res, cb) {
     path: u.pathname,
     method: req.method
   }, function(pres) {
-    res.writeHead(
-      pres.statusCode,
-      pres.headers
-    );
+    var hdrs = {};
+    [ 'access-control-allow-origin', 'content-type', 'content-length' ].forEach(function(key) {
+      if (pres.headers.hasOwnProperty(key)) {
+        hdrs[key] = pres.headers[key];
+      }
+    });
+    res.writeHead(pres.statusCode, hdrs);
+
     pres.on('data', function (chunk) {
       res.write(chunk);
     }).on('end', function() {
diff --git a/lib/browserid/wsapi.js b/lib/browserid/wsapi.js
index e6be9ea80..0e94ed046 100644
--- a/lib/browserid/wsapi.js
+++ b/lib/browserid/wsapi.js
@@ -420,26 +420,6 @@ function setup(app) {
   });
 
   app.post('/wsapi/cert_key', checkAuthed, validate(["email", "pubkey"]), function(req, res) {
-    db.emailsBelongToSameAccount(req.session.authenticatedUser, req.body.email, function(sameAccount) {
-      // not same account? big fat error
-      if (!sameAccount) return httputils.badRequest(res, "that email does not belong to you");
-
-      // parse the pubkey
-      var pk = ca.parsePublicKey(req.body.pubkey);
-
-      // same account, we certify the key
-      // we certify it for a day for now
-      var expiration = new Date();
-      expiration.setTime(new Date().valueOf() + config.get('certificate_validity_ms'));
-      var cert = ca.certify(req.body.email, pk, expiration);
-
-      res.writeHead(200, {'Content-Type': 'text/plain'});
-      res.write(cert);
-      res.end();
-    });
-
-/* code to bounce the cert off of a proper keysigner (issue #460)
-
     db.emailsBelongToSameAccount(req.session.authenticatedUser, req.body.email, function(sameAccount) {
       // not same account? big fat error
       if (!sameAccount) return httputils.badRequest(res, "that email does not belong to you");
@@ -453,7 +433,6 @@ function setup(app) {
         }
       });
     });
-*/
   });
 
   app.post('/wsapi/logout', function(req, resp) {
-- 
GitLab