From f26ee40b41e67ba9562468743bc14ebf468b6470 Mon Sep 17 00:00:00 2001 From: Matthijs van Henten Date: Wed, 19 Oct 2016 18:03:37 +0200 Subject: [PATCH] Revert "Rotate sso" --- node_modules/c9/crypt.js | 29 ++++++-------------- node_modules/c9/crypt_test.js | 50 ++++++++--------------------------- 2 files changed, 19 insertions(+), 60 deletions(-) diff --git a/node_modules/c9/crypt.js b/node_modules/c9/crypt.js index 638b974e..9630bb53 100644 --- a/node_modules/c9/crypt.js +++ b/node_modules/c9/crypt.js @@ -1,35 +1,22 @@ var crypto = require("crypto"); exports.crypt = function(sessionId, secret) { - secret = [].concat(secret); - secret = secret[1] || secret[0]; - var cipher = crypto.createCipher("aes256", secret); - return ( - cipher.update(sessionId, "ascii", "base64") + + cipher.update(sessionId, "ascii", "base64") + cipher.final("base64") ).replace(/\=+$/, ""); }; exports.decrypt = function(encrypted, secret) { - var secrets = [].concat(secret); + var cipher = crypto.createDecipher("aes256", secret); + + var data = [ + cipher.update(encrypted, "base64", "ascii"), + cipher.final("ascii") + ]; - var data; - - for (var i = 0; i < secrets.length; i++) { - secret = secrets[i]; - var cipher = crypto.createDecipher("aes256", secret); - - try { - data = [ - cipher.update(encrypted, "base64", "ascii"), - cipher.final("ascii") - ]; - } - catch (err) { /** ignore failed decrypt **/ } - if (data) return data.join("").replace(/\=+$/, ""); - } + return data.join("").replace(/\=+$/, ""); }; exports.uid = function(length) { diff --git a/node_modules/c9/crypt_test.js b/node_modules/c9/crypt_test.js index 9c11861e..542f21e9 100644 --- a/node_modules/c9/crypt_test.js +++ b/node_modules/c9/crypt_test.js @@ -1,53 +1,25 @@ "use strict"; -"use server"; -require("c9/inline-mocha")(module); +"use server"; var assert = require("assert"); var crypt = require("./crypt"); -describe("c9/crypt", function() { - it("encrpyt and decrypt should return input", function() { +module.exports = { + + name: "cookie crypt", + + "test encrpyt and decrypt should return input" : function() { var sessionId = "vOcRVvhaBBauiYexVvWyJpPb.AqmabaXkhpmlR8AUkORJHu%2FB7WA57EsDqzled0VoKAg"; var secret = "geheim"; - + assert.equal(crypt.crypt(sessionId, secret), "C+kRJ4UWhmjgqo7DVv31cJLfZ9LIPLZB7OuMdN8i07ZdZHKlusCClMKaqBEwHDiKH3uFKf8IUZOxoVHU6+eNrkLArr32HrBDLr8qfnKfAgY"); - + assert.equal( crypt.decrypt(crypt.crypt(sessionId, secret), secret), sessionId ); - }); + } +}; - - it("Should accept an array for decrypt", function() { - var message = Math.random().toString(36); - var secret = "swordfish"; - - var crypted = crypt.crypt(message, secret); - var plaintext = crypt.decrypt(crypted, [Math.random().toString(36), Math.random().toString(36), secret]); - - assert.equal(plaintext, message, "Got message back"); - }); - - it("Should accept an array for crypt", function() { - var message = Math.random().toString(36); - var secret = ["letmein", "swordfish"]; - - var crypted = crypt.crypt(message, secret); - var plaintext = crypt.decrypt(crypted, secret); - - assert.equal(plaintext, message, "Got message back"); - }); - - it("Should prefer the #1st secret", function() { - var message = Math.random().toString(36); - var secret = ["letmein", "swordfish", "princess"]; - - var crypted = crypt.crypt(message, secret); - - assert.ok(!crypt.decrypt(crypted, secret[0]), "String was not encrypted with the #1st secret"); - assert.ok(!crypt.decrypt(crypted, secret[2]), "String was not encrypted with the #3rd secret"); - assert.equal(crypt.decrypt(crypted, secret[1]), message, "Got message back"); - }); -}); +!module.parent && require("asyncjs").test.testcase(module.exports).exec();