From 67e54de3bb032d7839449f6f1834d0b819b9d7b7 Mon Sep 17 00:00:00 2001
From: Ben Adida <ben@adida.net>
Date: Fri, 20 Jul 2012 17:12:43 -0700
Subject: [PATCH] upgrade data formats

---
 lib/keysigner/ca.js                    |  2 +-
 lib/secrets.js                         |  4 +++-
 package.json                           |  2 +-
 scripts/serve_example_primary.js       |  4 +++-
 tests/add-email-with-assertion-test.js |  2 +-
 tests/auth-with-assertion-test.js      |  2 +-
 tests/conformance-test.js              |  2 +-
 tests/lib/primary.js                   |  2 +-
 tests/stalled-mysql-test.js            |  2 +-
 tests/verifier-test.js                 | 10 +++++-----
 10 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/lib/keysigner/ca.js b/lib/keysigner/ca.js
index c32076a1e..e8ecf9208 100644
--- a/lib/keysigner/ca.js
+++ b/lib/keysigner/ca.js
@@ -29,7 +29,7 @@ function certify(hostname, email, publicKey, expiration, cb) {
   if (expiration == null)
     return cb("expiration cannot be null");
 
-  cert.sign(publicKey, {email: email},
+  cert.sign({publicKey: publicKey, principal: {email: email}},
             {issuer: hostname, issuedAt: new Date(), expiresAt: expiration},
             null,
             secret_key, cb);
diff --git a/lib/secrets.js b/lib/secrets.js
index eb674481e..da6528c76 100644
--- a/lib/secrets.js
+++ b/lib/secrets.js
@@ -115,5 +115,7 @@ exports.publicKeyCreationDate = function(name, dir) {
 };
 
 exports.loadPublicKey = function(name, dir) {
-  return jwcrypto.loadPublicKey(JSON.stringify(readAndParseCert(name, dir)['public-key']));
+  var parsedCert = readAndParseCert(name, dir);
+  var pkString = parsedCert['public-key'] || parsedCert.publicKey;
+  return jwcrypto.loadPublicKey(JSON.stringify(pkString));
 };
diff --git a/package.json b/package.json
index 1e45de688..c2ad1d3da 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,7 @@
         "express": "2.5.0",
         "gobbledygook": "0.0.3", 
         "mustache": "0.3.1-dev",
-        "jwcrypto": "0.3.2",
+        "jwcrypto": "https://github.com/mozilla/jwcrypto/tarball/2012-07-new-data-formats",
         "mysql": "0.9.5",
         "node-statsd": "https://github.com/downloads/lloyd/node-statsd/0509f85.tgz",
         "nodemailer": "0.1.24",
diff --git a/scripts/serve_example_primary.js b/scripts/serve_example_primary.js
index 974c4e88b..e5400ce1a 100755
--- a/scripts/serve_example_primary.js
+++ b/scripts/serve_example_primary.js
@@ -90,7 +90,9 @@ exampleServer.post("/api/cert_key", function (req, res) {
   var expiration = new Date();
   var pubkey = jwcrypto.loadPublicKeyFromObject(req.body.pubkey);
   expiration.setTime(new Date().valueOf() + req.body.duration * 1000);
-  jwcrypto.cert.sign(pubkey, {email: user + "@" + domain}, {issuer: domain, expiresAt: expiration, issuedAt: new Date()}, {}, _privKey, function(err, cert) {
+  jwcrypto.cert.sign({publicKey: pubkey, principal: {email: user + "@" + domain}},
+                     {issuer: domain, expiresAt: expiration, issuedAt: new Date()},
+                     {}, _privKey, function(err, cert) {
     res.json({ cert: cert });
   });
 });
diff --git a/tests/add-email-with-assertion-test.js b/tests/add-email-with-assertion-test.js
index e6e0688ea..181cf2622 100755
--- a/tests/add-email-with-assertion-test.js
+++ b/tests/add-email-with-assertion-test.js
@@ -68,7 +68,7 @@ suite.addBatch({
 
       var expiration = new Date();
       expiration.setTime(new Date().valueOf() + 60 * 60 * 1000);
-      jwcrypto.cert.sign(g_keypair.publicKey, {email: TEST_EMAIL}, {issuer: TEST_DOMAIN, expiresAt: expiration, issuedAt: new Date()}, null, g_privKey, this.callback);
+      jwcrypto.cert.sign({publicKey: g_keypair.publicKey, principal: {email: TEST_EMAIL}}, {issuer: TEST_DOMAIN, expiresAt: expiration, issuedAt: new Date()}, null, g_privKey, this.callback);
     },
     "works swimmingly": function(err, cert) {
       assert.isString(cert);
diff --git a/tests/auth-with-assertion-test.js b/tests/auth-with-assertion-test.js
index d82156e74..385b96f81 100755
--- a/tests/auth-with-assertion-test.js
+++ b/tests/auth-with-assertion-test.js
@@ -88,7 +88,7 @@ suite.addBatch({
           
           // sign this innerkeypair with the key from g_cert (g_keypair)
           jwcrypto.cert.sign(
-            innerKeypair.publicKey, {email: OTHER_EMAIL},
+            {publicKey: innerKeypair.publicKey, principal: {email: OTHER_EMAIL}},
             {issuedAt: new Date(), expiresAt: expirationDate},
             {}, primaryUser._keyPair.secretKey,
             function(err, innerCert) {
diff --git a/tests/conformance-test.js b/tests/conformance-test.js
index 205cb6289..5082ce4b2 100755
--- a/tests/conformance-test.js
+++ b/tests/conformance-test.js
@@ -193,7 +193,7 @@ suite.addBatch({
 suite.addBatch({
   "sign a cert": {
     topic: function() {
-      jwcrypto.cert.sign(userKeypair.publicKey, {email: EMAIL},
+      jwcrypto.cert.sign({publicKey: userKeypair.publicKey, principal: {email: EMAIL}},
                          {issuedAt: now, issuer: ISSUER, expiresAt: in_a_minute},
                          {},
                          domainKeypair.secretKey, this.callback);
diff --git a/tests/lib/primary.js b/tests/lib/primary.js
index 40d3a5200..a00e3232f 100644
--- a/tests/lib/primary.js
+++ b/tests/lib/primary.js
@@ -30,7 +30,7 @@ User.prototype.setup = function(cb) {
     var expiration = new Date();
     expiration.setTime(new Date().valueOf() + 60 * 60 * 1000);
 
-    jwcrypto.cert.sign(self._keyPair.publicKey, {email: self.options.email},
+    jwcrypto.cert.sign({publicKey: self._keyPair.publicKey, principal: {email: self.options.email}},
                        {expiresAt: expiration, issuer: self.options.domain, issuedAt: new Date()},
                        {}, self.options.privKey || g_privKey, function(err, signedCert) {
                          if (err) return cb(err);
diff --git a/tests/stalled-mysql-test.js b/tests/stalled-mysql-test.js
index 889dad843..46b529baa 100755
--- a/tests/stalled-mysql-test.js
+++ b/tests/stalled-mysql-test.js
@@ -328,7 +328,7 @@ suite.addBatch({
 
       var expiration = new Date();
       expiration.setTime(new Date().valueOf() + 60 * 60 * 1000);
-      jwcrypto.cert.sign(g_keypair.publicKey, {email: TEST_EMAIL},
+      jwcrypto.cert.sign({publicKey: g_keypair.publicKey, principal: {email: TEST_EMAIL}},
                         {expiresAt: expiration, issuedAt: new Date(), issuer: TEST_DOMAIN},
                          null, g_privKey, this.callback);
     },
diff --git a/tests/verifier-test.js b/tests/verifier-test.js
index f6225c048..cc93e9577 100755
--- a/tests/verifier-test.js
+++ b/tests/verifier-test.js
@@ -536,7 +536,7 @@ suite.addBatch({
   "certify the user key": {
     topic: function() {
       var expiration = new Date(new Date().getTime() + (1000 * 60 * 60 * 6));
-      jwcrypto.cert.sign(newClientKeypair.publicKey, {email: TEST_EMAIL},
+      jwcrypto.cert.sign({publicKey: newClientKeypair.publicKey, principal: {email: TEST_EMAIL}},
                          {issuedAt: new Date(), issuer: "127.0.0.1",
                           expiresAt: expiration},
                          {}, fakeDomainKeypair.secretKey, this.callback);
@@ -786,7 +786,7 @@ suite.addBatch({
   "certify the user key for other issuer": {
     topic: function() {
       var expiration = new Date(new Date().getTime() + (1000 * 60 * 60 * 6));
-      jwcrypto.cert.sign(newClientKeypair.publicKey, {email: TEST_EMAIL},
+      jwcrypto.cert.sign({publicKey: newClientKeypair.publicKey, principal: {email: TEST_EMAIL}},
                          {issuedAt: new Date(), issuer: "no.such.domain",
                           expiresAt: expiration},
                          {}, fakeDomainKeypair.secretKey, this.callback);
@@ -856,7 +856,7 @@ suite.addBatch({
           path.join(__dirname, '..', 'example', 'primary', 'sample.privatekey')));
 
       var expiration = new Date(new Date().getTime() + (1000 * 60 * 60 * 6));
-      jwcrypto.cert.sign(newClientKeypair.publicKey, {email: TEST_EMAIL},
+      jwcrypto.cert.sign({publicKey: newClientKeypair.publicKey, principal: {email: TEST_EMAIL}},
                          {issuedAt: new Date(), issuer: "example.domain",
                           expiresAt: expiration},
                          {}, secretKey, this.callback);
@@ -914,7 +914,7 @@ suite.addBatch({
           path.join(__dirname, '..', 'example', 'primary', 'sample.privatekey')));
 
       var expiration = new Date(new Date().getTime() + (1000 * 60 * 60 * 6));
-      jwcrypto.cert.sign(newClientKeypair.publicKey, {email: "foo@example.domain"},
+      jwcrypto.cert.sign({publicKey: newClientKeypair.publicKey, principal: {email: "foo@example.domain"}},
                          {issuedAt: new Date(), issuer: "example.domain",
                           expiresAt: expiration},
                          {}, secretKey, this.callback);
@@ -983,7 +983,7 @@ suite.addBatch({
 
           // sign this innerkeypair with the key from g_cert (g_keypair)
           jwcrypto.cert.sign(
-            innerKeypair.publicKey, {email: OTHER_EMAIL},
+            {publicKey: innerKeypair.publicKey, principal: {email: OTHER_EMAIL}},
             {issuedAt: new Date(), expiresAt: expirationDate},
             {}, g_keypair.secretKey,
             function(err, innerCert) {
-- 
GitLab