summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/Crypto/AES_2.js829
-rw-r--r--frontend/beta/js/Clipperz/PM/Crypto.js91
-rw-r--r--frontend/beta/properties/beta.properties.json1
-rw-r--r--frontend/gamma/js/Clipperz/Crypto/AES_2.js843
-rw-r--r--frontend/gamma/js/Clipperz/PM/Crypto.js106
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/User.js4
-rw-r--r--frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js4
-rw-r--r--frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js5
-rw-r--r--frontend/gamma/properties/gamma.properties.json1
-rw-r--r--frontend/gamma/properties/mobile.properties.json25
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html57
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js85
-rw-r--r--frontend/gamma/tests/tests/Clipperz/Crypto/index.html1
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html60
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js50
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html1
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html1
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html1
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js8
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html1
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js2
-rw-r--r--frontend/gamma/tests/tests/Clipperz/PM/index.html1
22 files changed, 2098 insertions, 79 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/AES_2.js b/frontend/beta/js/Clipperz/Crypto/AES_2.js
new file mode 100644
index 0000000..9735d17
--- a/dev/null
+++ b/frontend/beta/js/Clipperz/Crypto/AES_2.js
@@ -0,0 +1,829 @@
+/*
+
+Copyright 2008-2013 Clipperz Srl
+
+This file is part of Clipperz, the online password manager.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com.
+
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
+
+*/
+
+try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
+ throw "Clipperz.Crypto.AES_2 depends on Clipperz.ByteArray!";
+}
+
+// Dependency commented to avoid a circular reference
+//try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) {
+// throw "Clipperz.Crypto.AES_2 depends on Clipperz.Crypto.PRNG!";
+//}
+
+if (typeof(Clipperz.Crypto.AES_2) == 'undefined') { Clipperz.Crypto.AES_2 = {}; }
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.DeferredExecutionContext = function(args) {
+ args = args || {};
+
+ this._key = args.key;
+ this._message = args.message;
+ this._result = args.message.clone();
+ this._nonce = args.nonce;
+ this._messageLength = this._message.length();
+
+ this._messageArray = this._message.arrayValues();
+ this._resultArray = this._result.arrayValues();
+ this._nonceArray = this._nonce.arrayValues();
+
+ this._executionStep = 0;
+
+ return this;
+}
+
+Clipperz.Crypto.AES_2.DeferredExecutionContext.prototype = MochiKit.Base.update(null, {
+
+ 'key': function() {
+ return this._key;
+ },
+
+ 'message': function() {
+ return this._message;
+ },
+
+ 'messageLength': function() {
+ return this._messageLength;
+ },
+
+ 'result': function() {
+ return new Clipperz.ByteArray(this.resultArray());
+ },
+
+ 'nonce': function() {
+ return this._nonce;
+ },
+
+ 'messageArray': function() {
+ return this._messageArray;
+ },
+
+ 'resultArray': function() {
+ return this._resultArray;
+ },
+
+ 'nonceArray': function() {
+ return this._nonceArray;
+ },
+
+ 'elaborationChunkSize': function() {
+ return Clipperz.Crypto.AES_2.DeferredExecution.chunkSize;
+ },
+
+ 'executionStep': function() {
+ return this._executionStep;
+ },
+
+ 'setExecutionStep': function(aValue) {
+ this._executionStep = aValue;
+ },
+
+ 'pause': function(aValue) {
+ return MochiKit.Async.wait(Clipperz.Crypto.AES_2.DeferredExecution.pauseTime, aValue);
+ },
+
+ //-----------------------------------------------------------------------------
+ __syntaxFix__: "syntax fix"
+
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.Key = function(args) {
+ args = args || {};
+
+ this._key = args.key;
+ this._keySize = args.keySize || this.key().length();
+
+ if (this.keySize() == 128/8) {
+ this._b = 176;
+ this._numberOfRounds = 10;
+ } else if (this.keySize() == 256/8) {
+ this._b = 240;
+ this._numberOfRounds = 14;
+ } else {
+ MochiKit.Logging.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits");
+ throw Clipperz.Crypto.AES_2.exception.UnsupportedKeySize;
+ }
+
+ this._stretchedKey = null;
+
+ return this;
+}
+
+Clipperz.Crypto.AES_2.Key.prototype = MochiKit.Base.update(null, {
+
+ 'asString': function() {
+ return "Clipperz.Crypto.AES_2.Key (" + this.key().toHexString() + ")";
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'key': function() {
+ return this._key;
+ },
+
+ 'keySize': function() {
+ return this._keySize;
+ },
+
+ 'b': function() {
+ return this._b;
+ },
+
+ 'numberOfRounds': function() {
+ return this._numberOfRounds;
+ },
+ //=========================================================================
+
+ 'keyScheduleCore': function(aWord, aRoundConstantsIndex) {
+ var result;
+ var sbox;
+
+ sbox = Clipperz.Crypto.AES_2.sbox();
+
+ result = [ sbox[aWord[1]] ^ Clipperz.Crypto.AES_2.roundConstants()[aRoundConstantsIndex],
+ sbox[aWord[2]],
+ sbox[aWord[3]],
+ sbox[aWord[0]] ];
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) {
+ var result;
+ var i,c;
+
+ result = [];
+ c = 4;
+ for (i=0; i<c; i++) {
+ result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i);
+ }
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'sboxShakeup': function(aWord) {
+ var result;
+ var sbox;
+ var i,c;
+
+ result = [];
+ sbox = Clipperz.Crypto.AES_2.sbox();
+ c =4;
+ for (i=0; i<c; i++) {
+ result[i] = sbox[aWord[i]];
+ }
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'stretchKey': function(aKey) {
+ var currentWord;
+ var keyLength;
+ var previousStretchIndex;
+ var i,c;
+
+ keyLength = aKey.length();
+ previousStretchIndex = keyLength - this.keySize();
+
+ currentWord = [ aKey.byteAtIndex(keyLength - 4),
+ aKey.byteAtIndex(keyLength - 3),
+ aKey.byteAtIndex(keyLength - 2),
+ aKey.byteAtIndex(keyLength - 1) ];
+ currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize());
+
+ if (this.keySize() == 256/8) {
+ c = 8;
+ } else if (this.keySize() == 128/8){
+ c = 4;
+ }
+
+ for (i=0; i<c; i++) {
+ if (i == 4) {
+ // fifth streatch word
+ currentWord = this.sboxShakeup(currentWord);
+ }
+
+ currentWord = this.xorWithPreviousStretchValues(aKey, currentWord, previousStretchIndex + (i*4));
+ aKey.appendBytes(currentWord);
+ }
+
+ return aKey;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'stretchedKey': function() {
+ if (this._stretchedKey == null) {
+ var stretchedKey;
+
+ stretchedKey = this.key().clone();
+
+ while (stretchedKey.length() < this.keySize()) {
+ stretchedKey.appendByte(0);
+ }
+
+ while (stretchedKey.length() < this.b()) {
+ stretchedKey = this.stretchKey(stretchedKey);
+ }
+
+ this._stretchedKey = stretchedKey.split(0, this.b());
+ }
+
+ return this._stretchedKey;
+ },
+
+ //=========================================================================
+ __syntaxFix__: "syntax fix"
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.State = function(args) {
+ args = args || {};
+
+ this._data = args.block.slice(0);
+ this._key = args.key;
+
+ return this;
+}
+
+Clipperz.Crypto.AES_2.State.prototype = MochiKit.Base.update(null, {
+
+ 'key': function() {
+ return this._key;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'data': function() {
+ return this._data;
+ },
+
+ 'setData': function(aValue) {
+ this._data = aValue;
+ },
+
+ //=========================================================================
+
+ 'addRoundKey': function(aRoundNumber) {
+ // each byte of the state is combined with the round key; each round key is derived from the cipher key using a key schedule.
+ var data;
+ var stretchedKey;
+ var firstStretchedKeyIndex;
+ var i,c;
+
+ data = this.data();
+ stretchedKey = this.key().stretchedKey();
+ firstStretchedKeyIndex = aRoundNumber * (128/8);
+ c = 128/8;
+ for (i=0; i<c; i++) {
+ data[i] = data[i] ^ stretchedKey.byteAtIndex(firstStretchedKeyIndex + i);
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'subBytes': function() {
+ // a non-linear substitution step where each byte is replaced with another according to a lookup table.
+ var i,c;
+ var data;
+ var sbox;
+
+ data = this.data();
+ sbox = Clipperz.Crypto.AES_2.sbox();
+
+ c = 16;
+ for (i=0; i<c; i++) {
+ data[i] = sbox[data[i]];
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'shiftRows': function() {
+ // a transposition step where each row of the state is shifted cyclically a certain number of steps.
+ var newValue;
+ var data;
+ var shiftMapping;
+ var i,c;
+
+ newValue = new Array(16);
+ data = this.data();
+ shiftMapping = Clipperz.Crypto.AES_2.shiftRowMapping();
+// [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11];
+ c = 16;
+ for (i=0; i<c; i++) {
+ newValue[i] = data[shiftMapping[i]];
+ }
+ for (i=0; i<c; i++) {
+ data[i] = newValue[i];
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+/*
+ 'mixColumnsWithValues': function(someValues) {
+ var result;
+ var a;
+ var i,c;
+
+ c = 4;
+ result = [];
+ a = [];
+ for (i=0; i<c; i++) {
+ a[i] = [];
+ a[i][1] = someValues[i]
+ if ((a[i][1] & 0x80) == 0x80) {
+ a[i][2] = (a[i][1] << 1) ^ 0x11b;
+ } else {
+ a[i][2] = a[i][1] << 1;
+ }
+
+ a[i][3] = a[i][2] ^ a[i][1];
+ }
+
+ for (i=0; i<c; i++) {
+ var x;
+
+ x = Clipperz.Crypto.AES_2.mixColumnsMatrix()[i];
+ result[i] = a[0][x[0]] ^ a[1][x[1]] ^ a[2][x[2]] ^ a[3][x[3]];
+ }
+
+ return result;
+ },
+
+ 'mixColumns': function() {
+ // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation.
+ var data;
+ var i, c;
+
+ data = this.data();
+ c = 4;
+ for(i=0; i<c; i++) {
+ var blockIndex;
+ var mixedValues;
+
+ blockIndex = i * 4;
+ mixedValues = this.mixColumnsWithValues([ data[blockIndex + 0],
+ data[blockIndex + 1],
+ data[blockIndex + 2],
+ data[blockIndex + 3]]);
+ data[blockIndex + 0] = mixedValues[0];
+ data[blockIndex + 1] = mixedValues[1];
+ data[blockIndex + 2] = mixedValues[2];
+ data[blockIndex + 3] = mixedValues[3];
+ }
+ },
+*/
+
+ 'mixColumns': function() {
+ // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation.
+ var data;
+ var i, c;
+ var a_1;
+ var a_2;
+
+ a_1 = new Array(4);
+ a_2 = new Array(4);
+
+ data = this.data();
+ c = 4;
+ for(i=0; i<c; i++) {
+ var blockIndex;
+ var ii, cc;
+
+ blockIndex = i * 4;
+
+ cc = 4;
+ for (ii=0; ii<cc; ii++) {
+ var value;
+
+ value = data[blockIndex + ii];
+ a_1[ii] = value;
+ a_2[ii] = (value & 0x80) ? ((value << 1) ^ 0x011b) : (value << 1);
+ }
+
+ data[blockIndex + 0] = a_2[0] ^ a_1[1] ^ a_2[1] ^ a_1[2] ^ a_1[3];
+ data[blockIndex + 1] = a_1[0] ^ a_2[1] ^ a_1[2] ^ a_2[2] ^ a_1[3];
+ data[blockIndex + 2] = a_1[0] ^ a_1[1] ^ a_2[2] ^ a_1[3] ^ a_2[3];
+ data[blockIndex + 3] = a_1[0] ^ a_2[0] ^ a_1[1] ^ a_1[2] ^ a_2[3];
+ }
+ },
+
+ //=========================================================================
+
+ 'spinRound': function(aRoundNumber) {
+ this.addRoundKey(aRoundNumber);
+ this.subBytes();
+ this.shiftRows();
+ this.mixColumns();
+ },
+
+ 'spinLastRound': function() {
+ this.addRoundKey(this.key().numberOfRounds() - 1);
+ this.subBytes();
+ this.shiftRows();
+ this.addRoundKey(this.key().numberOfRounds());
+ },
+
+ //=========================================================================
+
+ 'encrypt': function() {
+ var i,c;
+
+ c = this.key().numberOfRounds() - 1;
+ for (i=0; i<c; i++) {
+ this.spinRound(i);
+ }
+
+ this.spinLastRound();
+ },
+
+ //=========================================================================
+ __syntaxFix__: "syntax fix"
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.VERSION = "0.1";
+Clipperz.Crypto.AES_2.NAME = "Clipperz.Crypto.AES_2";
+
+MochiKit.Base.update(Clipperz.Crypto.AES_2, {
+
+// http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html
+// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
+// http://en.wikipedia.org/wiki/Rijndael_key_schedule
+// http://en.wikipedia.org/wiki/Rijndael_S-box
+
+ '__repr__': function () {
+ return "[" + this.NAME + " " + this.VERSION + "]";
+ },
+
+ 'toString': function () {
+ return this.__repr__();
+ },
+
+ //=============================================================================
+
+ '_sbox': null,
+ 'sbox': function() {
+ if (Clipperz.Crypto.AES_2._sbox == null) {
+ Clipperz.Crypto.AES_2._sbox = [
+0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+ ];
+ }
+
+ return Clipperz.Crypto.AES_2._sbox;
+ },
+
+ //-----------------------------------------------------------------------------
+ //
+ // 0 4 8 12 0 4 8 12
+ // 1 5 9 13 => 5 9 13 1
+ // 2 6 10 14 10 14 2 6
+ // 3 7 11 15 15 3 7 11
+ //
+ '_shiftRowMapping': null,
+ 'shiftRowMapping': function() {
+ if (Clipperz.Crypto.AES_2._shiftRowMapping == null) {
+ Clipperz.Crypto.AES_2._shiftRowMapping = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11];
+ }
+
+ return Clipperz.Crypto.AES_2._shiftRowMapping;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ '_mixColumnsMatrix': null,
+ 'mixColumnsMatrix': function() {
+ if (Clipperz.Crypto.AES_2._mixColumnsMatrix == null) {
+ Clipperz.Crypto.AES_2._mixColumnsMatrix = [ [2, 3, 1 ,1],
+ [1, 2, 3, 1],
+ [1, 1, 2, 3],
+ [3, 1, 1, 2] ];
+ }
+
+ return Clipperz.Crypto.AES_2._mixColumnsMatrix;
+ },
+
+ '_roundConstants': null,
+ 'roundConstants': function() {
+ if (Clipperz.Crypto.AES_2._roundConstants == null) {
+ Clipperz.Crypto.AES_2._roundConstants = [ , 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154];
+// Clipperz.Crypto.AES_2._roundConstants = [ , 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a];
+ }
+
+ return Clipperz.Crypto.AES_2._roundConstants;
+ },
+
+ //=============================================================================
+
+ 'incrementNonce': function(nonce) {
+ var i;
+ var done;
+
+ done = false;
+ i = nonce.length - 1;
+
+ while ((i>=0) && (done == false)) {
+ var currentByteValue;
+
+ currentByteValue = nonce[i];
+
+ if (currentByteValue == 0xff) {
+ nonce[i] = 0;
+ if (i>= 0) {
+ i --;
+ } else {
+ done = true;
+ }
+ } else {
+ nonce[i] = currentByteValue + 1;
+ done = true;
+ }
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'encryptBlock': function(aKey, aBlock) {
+ var result;
+ var state;
+
+ state = new Clipperz.Crypto.AES_2.State({block:aBlock, key:aKey});
+//is(state.data(), 'before');
+ state.encrypt();
+ result = state.data();
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'encryptBlocks': function(aKey, aMessage, aNonce) {
+ var result;
+ var nonce;
+ var self;
+ var messageIndex;
+ var messageLength;
+ var blockSize;
+
+ self = Clipperz.Crypto.AES_2;
+ blockSize = 128/8;
+ messageLength = aMessage.length;
+ nonce = aNonce;
+
+ result = aMessage;
+ messageIndex = 0;
+ while (messageIndex < messageLength) {
+ var encryptedBlock;
+ var i,c;
+
+ encryptedBlock = self.encryptBlock(aKey, nonce);
+
+ if ((messageLength - messageIndex) > blockSize) {
+ c = blockSize;
+ } else {
+ c = messageLength - messageIndex;
+ }
+
+ for (i=0; i<c; i++) {
+ result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i];
+ }
+
+ messageIndex += blockSize;
+ self.incrementNonce(nonce);
+ }
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'encrypt': function(aKey, someData, aNonce) {
+ var result;
+ var nonce;
+ var encryptedData;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+ nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8);
+
+ encryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, someData.arrayValues(), nonce.arrayValues());
+
+ result = nonce.appendBytes(encryptedData);
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'decrypt': function(aKey, someData) {
+ var result;
+ var nonce;
+ var encryptedData;
+ var decryptedData;
+ var dataIterator;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+
+ encryptedData = someData.arrayValues();
+ nonce = encryptedData.slice(0, (128/8));
+ encryptedData = encryptedData.slice(128/8);
+ decryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, encryptedData, nonce);
+
+ result = new Clipperz.ByteArray(decryptedData);
+
+ return result;
+ },
+
+ //=============================================================================
+
+ 'deferredEncryptExecutionChunk': function(anExecutionContext) {
+ var result;
+ var nonce;
+ var self;
+ var messageIndex;
+ var messageLength;
+ var blockSize;
+ var executionLimit;
+
+ self = Clipperz.Crypto.AES_2;
+ blockSize = 128/8;
+ messageLength = anExecutionContext.messageArray().length;
+ nonce = anExecutionContext.nonceArray();
+ result = anExecutionContext.resultArray();
+
+ messageIndex = anExecutionContext.executionStep();
+ executionLimit = messageIndex + anExecutionContext.elaborationChunkSize();
+ executionLimit = Math.min(executionLimit, messageLength);
+
+ while (messageIndex < executionLimit) {
+ var encryptedBlock;
+ var i,c;
+
+ encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce);
+
+ if ((executionLimit - messageIndex) > blockSize) {
+ c = blockSize;
+ } else {
+ c = executionLimit - messageIndex;
+ }
+
+ for (i=0; i<c; i++) {
+ result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i];
+ }
+
+ messageIndex += blockSize;
+ self.incrementNonce(nonce);
+ }
+ anExecutionContext.setExecutionStep(messageIndex);
+
+ return anExecutionContext;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'deferredEncryptBlocks': function(anExecutionContext) {
+ var deferredResult;
+ var messageSize;
+ var i,c;
+ var now;
+
+ messageSize = anExecutionContext.messageLength();
+
+ deferredResult = new MochiKit.Async.Deferred();
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - START: " + res); return res;});
+// deferredResult.addCallback(MochiKit.Base.method(anExecutionContext, 'pause'));
+
+ c = Math.ceil(messageSize / anExecutionContext.elaborationChunkSize());
+ for (i=0; i<c; i++) {
+//deferredResult.addBoth(function(res) {now = new Date(); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") - " + res); return res;});
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptExecutionChunk);
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "]Clipperz.Crypto.AES_2.deferredEncryptBlocks"); return res;});
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") -- " + res); return res;});
+ deferredResult.addCallback(MochiKit.Base.method(anExecutionContext, 'pause'));
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") --- " + res); return res;});
+ }
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - END: " + res); return res;});
+
+ deferredResult.callback(anExecutionContext);
+
+ return deferredResult;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'deferredEncrypt': function(aKey, someData, aNonce) {
+ var deferredResult;
+ var executionContext;
+ var result;
+ var nonce;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+ nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8);
+
+ executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:someData, nonce:nonce});
+
+ deferredResult = new MochiKit.Async.Deferred();
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 1: " + res); return res;});
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks);
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 2: " + res); return res;});
+ deferredResult.addCallback(function(anExecutionContext) {
+ var result;
+
+ result = anExecutionContext.nonce().clone();
+ result.appendBytes(anExecutionContext.resultArray());
+
+ return result;
+ });
+//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 3: " + res); return res;});
+ deferredResult.callback(executionContext)
+
+ return deferredResult;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'deferredDecrypt': function(aKey, someData) {
+ var deferredResult
+ var nonce;
+ var message;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+ nonce = someData.split(0, (128/8));
+ message = someData.split(128/8);
+ executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:message, nonce:nonce});
+
+ deferredResult = new MochiKit.Async.Deferred();
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks);
+ deferredResult.addCallback(function(anExecutionContext) {
+ return anExecutionContext.result();
+ });
+ deferredResult.callback(executionContext);
+
+ return deferredResult;
+ },
+
+ //-----------------------------------------------------------------------------
+ __syntaxFix__: "syntax fix"
+
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.DeferredExecution = {
+ 'chunkSize': 4096, // 1024 4096 8192 16384 32768;
+ 'pauseTime': 0.2
+}
+
+Clipperz.Crypto.AES_2.exception = {
+ 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES_2.exception.UnsupportedKeySize")
+};
diff --git a/frontend/beta/js/Clipperz/PM/Crypto.js b/frontend/beta/js/Clipperz/PM/Crypto.js
index ad16ff0..e1e87ec 100644
--- a/frontend/beta/js/Clipperz/PM/Crypto.js
+++ b/frontend/beta/js/Clipperz/PM/Crypto.js
@@ -60,3 +60,3 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
'encryptingFunctions': {
- 'currentVersion': '0.3',
+ 'currentVersion': '0.4',
'versions': {
@@ -297,3 +297,3 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
deferredResult = new MochiKit.Async.Deferred();
- now = new Date;
+// now = new Date;
@@ -342,3 +342,3 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
//#####################################################################
-/*
+
'0.4': {
@@ -351,23 +351,7 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
-//MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt");
key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
-//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1");
value = Clipperz.Base.serializeJSON(aValue);
-//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2");
-/ *
-//MochiKit.Logging.logDebug("--> encrypt.fullSize: " + value.length);
- value = value.replace(/":{"label":"/g, '":{l:"');
- value = value.replace(/":{"key":"/g, '":{k:"');
- value = value.replace(/":{"notes":"/g, '":{n:"');
- value = value.replace(/":{"record":"/g, '":{r:"');
- value = value.replace(/", "label":"/g, '",l:"');
- value = value.replace(/", "favicon":"/g, '",f:"');
-//MochiKit.Logging.logDebug("<-- encrypt.compressed: " + value.length);
-* /
data = new Clipperz.ByteArray(value);
-//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3");
- encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce);
-//MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4");
+ encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce);
result = encryptedData.toBase64String();
-//MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt");
@@ -375,2 +359,23 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
},
+
+ 'deferredEncrypt': function(aKey, aValue, aNonce) {
+ var deferredResult;
+ var key, value;
+ var data;
+ var dataToEncrypt;
+ var encryptedData;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = Clipperz.Base.serializeJSON(aValue);
+ data = new Clipperz.ByteArray(value);
+
+ deferredResult = new MochiKit.Async.Deferred()
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.toBase64String();
+ })
+ deferredResult.callback();
+
+ return deferredResult;
+ },
@@ -387,13 +392,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
- decryptedData = Clipperz.Crypto.AES.decrypt(key, value);
+ decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value);
value = decryptedData.asString();
-/ *
- value = value.replace(/":{l:"/g, '":{"label":"');
- value = value.replace(/":{k:"/g, '":{"key":"');
- value = value.replace(/":{n:"/g, '":{"notes":"');
- value = value.replace(/":{r:"/g, '":{"record":"');
- value = value.replace(/",l:"/g, '", "label":"');
- value = value.replace(/",f:"/g, '", "favicon":"');
-* /
try {
@@ -404,4 +401,2 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
}
-
-
} else {
@@ -413,5 +408,37 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
+ 'deferredDecrypt': function(aKey, aValue) {
+ var deferredResult;
+
+ deferredResult = new MochiKit.Async.Deferred();
+ if (aValue != null) {
+ var key, value;
+ var decryptedData;
+ var decryptedValue;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = new Clipperz.ByteArray().appendBase64String(aValue);
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value);
+ deferredResult.addCallback(MochiKit.Async.wait, 0.1);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.asString();
+ });
+ deferredResult.addCallback(MochiKit.Async.wait, 0.1);
+ deferredResult.addCallback(Clipperz.Base.evalJSON);
+ deferredResult.addErrback(function(anError) {
+ MochiKit.Logging.logError("Error while decrypting data");
+ throw Clipperz.Crypto.Base.exception.CorruptedMessage;
+ })
+ } else {
+ deferredResult.addCallback(function() {
+ return null;
+ });
+ }
+ deferredResult.callback();
+
+ return deferredResult;
+ },
+
'hash': Clipperz.Crypto.SHA.sha_d256
},
-*/
+
//#####################################################################
diff --git a/frontend/beta/properties/beta.properties.json b/frontend/beta/properties/beta.properties.json
index bfa152d..7d34677 100644
--- a/frontend/beta/properties/beta.properties.json
+++ b/frontend/beta/properties/beta.properties.json
@@ -79,2 +79,3 @@
"Clipperz/Crypto/AES.js",
+ "Clipperz/Crypto/AES_2.js",
"Clipperz/Crypto/PRNG.js",
diff --git a/frontend/gamma/js/Clipperz/Crypto/AES_2.js b/frontend/gamma/js/Clipperz/Crypto/AES_2.js
new file mode 100644
index 0000000..1627f39
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/Crypto/AES_2.js
@@ -0,0 +1,843 @@
+/*
+
+Copyright 2008-2013 Clipperz Srl
+
+This file is part of Clipperz, the online password manager.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com.
+
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
+
+*/
+
+try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) {
+ throw "Clipperz.Crypto.AES_2 depends on Clipperz.ByteArray!";
+}
+
+// Dependency commented to avoid a circular reference
+//try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) {
+// throw "Clipperz.Crypto.AES_2 depends on Clipperz.Crypto.PRNG!";
+//}
+
+if (typeof(Clipperz.Crypto.AES_2) == 'undefined') { Clipperz.Crypto.AES_2 = {}; }
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.DeferredExecutionContext = function(args) {
+ args = args || {};
+
+ this._key = args.key;
+ this._message = args.message;
+ this._result = args.message.clone();
+ this._nonce = args.nonce;
+ this._messageLength = this._message.length();
+
+ this._messageArray = this._message.arrayValues();
+ this._resultArray = this._result.arrayValues();
+ this._nonceArray = this._nonce.arrayValues();
+
+ this._executionStep = 0;
+
+// this._elaborationChunkSize = 1024; // 4096; // 16384; // 4096;
+ this._elaborationChunks = 10;
+ this._pauseTime = 0.02; // 0.02 // 0.2;
+
+ return this;
+}
+
+Clipperz.Crypto.AES_2.DeferredExecutionContext.prototype = MochiKit.Base.update(null, {
+
+ 'key': function() {
+ return this._key;
+ },
+
+ 'message': function() {
+ return this._message;
+ },
+
+ 'messageLength': function() {
+ return this._messageLength;
+ },
+
+ 'result': function() {
+ return new Clipperz.ByteArray(this.resultArray());
+ },
+
+ 'nonce': function() {
+ return this._nonce;
+ },
+
+ 'messageArray': function() {
+ return this._messageArray;
+ },
+
+ 'resultArray': function() {
+ return this._resultArray;
+ },
+
+ 'nonceArray': function() {
+ return this._nonceArray;
+ },
+
+ 'elaborationChunkSize': function() {
+// return Clipperz.Crypto.AES_2.DeferredExecution.chunkSize;
+// return this._elaborationChunkSize;
+ return (this._elaborationChunks * 1024);
+ },
+
+ 'executionStep': function() {
+ return this._executionStep;
+ },
+
+ 'setExecutionStep': function(aValue) {
+ this._executionStep = aValue;
+ },
+
+ 'tuneExecutionParameters': function (anElapsedTime) {
+//var originalChunks = this._elaborationChunks;
+ if (anElapsedTime > 0) {
+ this._elaborationChunks = Math.round(this._elaborationChunks * ((anElapsedTime + 1000)/(anElapsedTime * 2)));
+ }
+//Clipperz.log("tuneExecutionParameters - elapsedTime: " + anElapsedTime + /*originalChunks,*/ " chunks # " + this._elaborationChunks + " [" + this._executionStep + " / " + this._messageLength + "]");
+ },
+
+ 'pause': function(aValue) {
+// return MochiKit.Async.wait(Clipperz.Crypto.AES_2.DeferredExecution.pauseTime, aValue);
+ return MochiKit.Async.wait(this._pauseTime, aValue);
+ },
+
+ 'isDone': function () {
+ return (this._executionStep >= this._messageLength);
+ },
+
+ //-----------------------------------------------------------------------------
+ __syntaxFix__: "syntax fix"
+
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.Key = function(args) {
+ args = args || {};
+
+ this._key = args.key;
+ this._keySize = args.keySize || this.key().length();
+
+ if (this.keySize() == 128/8) {
+ this._b = 176;
+ this._numberOfRounds = 10;
+ } else if (this.keySize() == 256/8) {
+ this._b = 240;
+ this._numberOfRounds = 14;
+ } else {
+ Clipperz.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits");
+ throw Clipperz.Crypto.AES_2.exception.UnsupportedKeySize;
+ }
+
+ this._stretchedKey = null;
+
+ return this;
+}
+
+Clipperz.Crypto.AES_2.Key.prototype = MochiKit.Base.update(null, {
+
+ 'asString': function() {
+ return "Clipperz.Crypto.AES_2.Key (" + this.key().toHexString() + ")";
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'key': function() {
+ return this._key;
+ },
+
+ 'keySize': function() {
+ return this._keySize;
+ },
+
+ 'b': function() {
+ return this._b;
+ },
+
+ 'numberOfRounds': function() {
+ return this._numberOfRounds;
+ },
+ //=========================================================================
+
+ 'keyScheduleCore': function(aWord, aRoundConstantsIndex) {
+ var result;
+ var sbox;
+
+ sbox = Clipperz.Crypto.AES_2.sbox();
+
+ result = [ sbox[aWord[1]] ^ Clipperz.Crypto.AES_2.roundConstants()[aRoundConstantsIndex],
+ sbox[aWord[2]],
+ sbox[aWord[3]],
+ sbox[aWord[0]] ];
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) {
+ var result;
+ var i,c;
+
+ result = [];
+ c = 4;
+ for (i=0; i<c; i++) {
+ result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i);
+ }
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'sboxShakeup': function(aWord) {
+ var result;
+ var sbox;
+ var i,c;
+
+ result = [];
+ sbox = Clipperz.Crypto.AES_2.sbox();
+ c =4;
+ for (i=0; i<c; i++) {
+ result[i] = sbox[aWord[i]];
+ }
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'stretchKey': function(aKey) {
+ var currentWord;
+ var keyLength;
+ var previousStretchIndex;
+ var i,c;
+
+ keyLength = aKey.length();
+ previousStretchIndex = keyLength - this.keySize();
+
+ currentWord = [ aKey.byteAtIndex(keyLength - 4),
+ aKey.byteAtIndex(keyLength - 3),
+ aKey.byteAtIndex(keyLength - 2),
+ aKey.byteAtIndex(keyLength - 1) ];
+ currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize());
+
+ if (this.keySize() == 256/8) {
+ c = 8;
+ } else if (this.keySize() == 128/8){
+ c = 4;
+ }
+
+ for (i=0; i<c; i++) {
+ if (i == 4) {
+ // fifth streatch word
+ currentWord = this.sboxShakeup(currentWord);
+ }
+
+ currentWord = this.xorWithPreviousStretchValues(aKey, currentWord, previousStretchIndex + (i*4));
+ aKey.appendBytes(currentWord);
+ }
+
+ return aKey;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'stretchedKey': function() {
+ if (this._stretchedKey == null) {
+ var stretchedKey;
+
+ stretchedKey = this.key().clone();
+
+ while (stretchedKey.length() < this.keySize()) {
+ stretchedKey.appendByte(0);
+ }
+
+ while (stretchedKey.length() < this.b()) {
+ stretchedKey = this.stretchKey(stretchedKey);
+ }
+
+ this._stretchedKey = stretchedKey.split(0, this.b());
+ }
+
+ return this._stretchedKey;
+ },
+
+ //=========================================================================
+ __syntaxFix__: "syntax fix"
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.State = function(args) {
+ args = args || {};
+
+ this._data = args.block.slice(0);
+ this._key = args.key;
+
+ return this;
+}
+
+Clipperz.Crypto.AES_2.State.prototype = MochiKit.Base.update(null, {
+
+ 'key': function() {
+ return this._key;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'data': function() {
+ return this._data;
+ },
+
+ 'setData': function(aValue) {
+ this._data = aValue;
+ },
+
+ //=========================================================================
+
+ 'addRoundKey': function(aRoundNumber) {
+ // each byte of the state is combined with the round key; each round key is derived from the cipher key using a key schedule.
+ var data;
+ var stretchedKey;
+ var firstStretchedKeyIndex;
+ var i,c;
+
+ data = this.data();
+ stretchedKey = this.key().stretchedKey();
+ firstStretchedKeyIndex = aRoundNumber * (128/8);
+ c = 128/8;
+ for (i=0; i<c; i++) {
+ data[i] = data[i] ^ stretchedKey.byteAtIndex(firstStretchedKeyIndex + i);
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'subBytes': function() {
+ // a non-linear substitution step where each byte is replaced with another according to a lookup table.
+ var i,c;
+ var data;
+ var sbox;
+
+ data = this.data();
+ sbox = Clipperz.Crypto.AES_2.sbox();
+
+ c = 16;
+ for (i=0; i<c; i++) {
+ data[i] = sbox[data[i]];
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'shiftRows': function() {
+ // a transposition step where each row of the state is shifted cyclically a certain number of steps.
+ var newValue;
+ var data;
+ var shiftMapping;
+ var i,c;
+
+ newValue = new Array(16);
+ data = this.data();
+ shiftMapping = Clipperz.Crypto.AES_2.shiftRowMapping();
+// [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11];
+ c = 16;
+ for (i=0; i<c; i++) {
+ newValue[i] = data[shiftMapping[i]];
+ }
+ for (i=0; i<c; i++) {
+ data[i] = newValue[i];
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+/*
+ 'mixColumnsWithValues': function(someValues) {
+ var result;
+ var a;
+ var i,c;
+
+ c = 4;
+ result = [];
+ a = [];
+ for (i=0; i<c; i++) {
+ a[i] = [];
+ a[i][1] = someValues[i]
+ if ((a[i][1] & 0x80) == 0x80) {
+ a[i][2] = (a[i][1] << 1) ^ 0x11b;
+ } else {
+ a[i][2] = a[i][1] << 1;
+ }
+
+ a[i][3] = a[i][2] ^ a[i][1];
+ }
+
+ for (i=0; i<c; i++) {
+ var x;
+
+ x = Clipperz.Crypto.AES_2.mixColumnsMatrix()[i];
+ result[i] = a[0][x[0]] ^ a[1][x[1]] ^ a[2][x[2]] ^ a[3][x[3]];
+ }
+
+ return result;
+ },
+
+ 'mixColumns': function() {
+ // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation.
+ var data;
+ var i, c;
+
+ data = this.data();
+ c = 4;
+ for(i=0; i<c; i++) {
+ var blockIndex;
+ var mixedValues;
+
+ blockIndex = i * 4;
+ mixedValues = this.mixColumnsWithValues([ data[blockIndex + 0],
+ data[blockIndex + 1],
+ data[blockIndex + 2],
+ data[blockIndex + 3]]);
+ data[blockIndex + 0] = mixedValues[0];
+ data[blockIndex + 1] = mixedValues[1];
+ data[blockIndex + 2] = mixedValues[2];
+ data[blockIndex + 3] = mixedValues[3];
+ }
+ },
+*/
+
+ 'mixColumns': function() {
+ // a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation.
+ var data;
+ var i, c;
+ var a_1;
+ var a_2;
+
+ a_1 = new Array(4);
+ a_2 = new Array(4);
+
+ data = this.data();
+ c = 4;
+ for(i=0; i<c; i++) {
+ var blockIndex;
+ var ii, cc;
+
+ blockIndex = i * 4;
+
+ cc = 4;
+ for (ii=0; ii<cc; ii++) {
+ var value;
+
+ value = data[blockIndex + ii];
+ a_1[ii] = value;
+ a_2[ii] = (value & 0x80) ? ((value << 1) ^ 0x011b) : (value << 1);
+ }
+
+ data[blockIndex + 0] = a_2[0] ^ a_1[1] ^ a_2[1] ^ a_1[2] ^ a_1[3];
+ data[blockIndex + 1] = a_1[0] ^ a_2[1] ^ a_1[2] ^ a_2[2] ^ a_1[3];
+ data[blockIndex + 2] = a_1[0] ^ a_1[1] ^ a_2[2] ^ a_1[3] ^ a_2[3];
+ data[blockIndex + 3] = a_1[0] ^ a_2[0] ^ a_1[1] ^ a_1[2] ^ a_2[3];
+ }
+ },
+
+ //=========================================================================
+
+ 'spinRound': function(aRoundNumber) {
+ this.addRoundKey(aRoundNumber);
+ this.subBytes();
+ this.shiftRows();
+ this.mixColumns();
+ },
+
+ 'spinLastRound': function() {
+ this.addRoundKey(this.key().numberOfRounds() - 1);
+ this.subBytes();
+ this.shiftRows();
+ this.addRoundKey(this.key().numberOfRounds());
+ },
+
+ //=========================================================================
+
+ 'encrypt': function() {
+ var i,c;
+
+ c = this.key().numberOfRounds() - 1;
+ for (i=0; i<c; i++) {
+ this.spinRound(i);
+ }
+
+ this.spinLastRound();
+ },
+
+ //=========================================================================
+ __syntaxFix__: "syntax fix"
+});
+
+//#############################################################################
+
+Clipperz.Crypto.AES_2.VERSION = "0.1";
+Clipperz.Crypto.AES_2.NAME = "Clipperz.Crypto.AES_2";
+
+MochiKit.Base.update(Clipperz.Crypto.AES_2, {
+
+// http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html
+// http://en.wikipedia.org/wiki/Advanced_Encryption_Standard
+// http://en.wikipedia.org/wiki/Rijndael_key_schedule
+// http://en.wikipedia.org/wiki/Rijndael_S-box
+
+ '__repr__': function () {
+ return "[" + this.NAME + " " + this.VERSION + "]";
+ },
+
+ 'toString': function () {
+ return this.__repr__();
+ },
+
+ //=============================================================================
+
+ '_sbox': null,
+ 'sbox': function() {
+ if (Clipperz.Crypto.AES_2._sbox == null) {
+ Clipperz.Crypto.AES_2._sbox = [
+0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
+0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
+0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
+0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75,
+0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84,
+0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
+0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8,
+0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2,
+0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
+0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb,
+0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79,
+0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
+0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a,
+0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e,
+0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
+0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16
+ ];
+ }
+
+ return Clipperz.Crypto.AES_2._sbox;
+ },
+
+ //-----------------------------------------------------------------------------
+ //
+ // 0 4 8 12 0 4 8 12
+ // 1 5 9 13 => 5 9 13 1
+ // 2 6 10 14 10 14 2 6
+ // 3 7 11 15 15 3 7 11
+ //
+ '_shiftRowMapping': null,
+ 'shiftRowMapping': function() {
+ if (Clipperz.Crypto.AES_2._shiftRowMapping == null) {
+ Clipperz.Crypto.AES_2._shiftRowMapping = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11];
+ }
+
+ return Clipperz.Crypto.AES_2._shiftRowMapping;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ '_mixColumnsMatrix': null,
+ 'mixColumnsMatrix': function() {
+ if (Clipperz.Crypto.AES_2._mixColumnsMatrix == null) {
+ Clipperz.Crypto.AES_2._mixColumnsMatrix = [ [2, 3, 1 ,1],
+ [1, 2, 3, 1],
+ [1, 1, 2, 3],
+ [3, 1, 1, 2] ];
+ }
+
+ return Clipperz.Crypto.AES_2._mixColumnsMatrix;
+ },
+
+ '_roundConstants': null,
+ 'roundConstants': function() {
+ if (Clipperz.Crypto.AES_2._roundConstants == null) {
+ Clipperz.Crypto.AES_2._roundConstants = [ , 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154];
+// Clipperz.Crypto.AES_2._roundConstants = [ , 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a];
+ }
+
+ return Clipperz.Crypto.AES_2._roundConstants;
+ },
+
+ //=============================================================================
+
+ 'incrementNonce': function(nonce) {
+ var i;
+ var done;
+
+ done = false;
+ i = nonce.length - 1;
+
+ while ((i>=0) && (done == false)) {
+ var currentByteValue;
+
+ currentByteValue = nonce[i];
+
+ if (currentByteValue == 0xff) {
+ nonce[i] = 0;
+ if (i>= 0) {
+ i --;
+ } else {
+ done = true;
+ }
+ } else {
+ nonce[i] = currentByteValue + 1;
+ done = true;
+ }
+ }
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'encryptBlock': function(aKey, aBlock) {
+ var result;
+ var state;
+
+ state = new Clipperz.Crypto.AES_2.State({block:aBlock, key:aKey});
+//is(state.data(), 'before');
+ state.encrypt();
+ result = state.data();
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'encryptBlocks': function(aKey, aMessage, aNonce) {
+ var result;
+ var nonce;
+ var self;
+ var messageIndex;
+ var messageLength;
+ var blockSize;
+
+ self = Clipperz.Crypto.AES_2;
+ blockSize = 128/8;
+ messageLength = aMessage.length;
+ nonce = aNonce;
+
+ result = aMessage;
+ messageIndex = 0;
+ while (messageIndex < messageLength) {
+ var encryptedBlock;
+ var i,c;
+
+ encryptedBlock = self.encryptBlock(aKey, nonce);
+
+ if ((messageLength - messageIndex) > blockSize) {
+ c = blockSize;
+ } else {
+ c = messageLength - messageIndex;
+ }
+
+ for (i=0; i<c; i++) {
+ result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i];
+ }
+
+ messageIndex += blockSize;
+// nonce = self.incrementNonce(nonce);
+ self.incrementNonce(nonce)
+ }
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'encrypt': function(aKey, someData, aNonce) {
+ var result;
+ var nonce;
+ var encryptedData;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+ nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8);
+
+ encryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, someData.arrayValues(), nonce.arrayValues());
+
+ result = nonce.appendBytes(encryptedData);
+
+ return result;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'decrypt': function(aKey, someData) {
+ var result;
+ var nonce;
+ var encryptedData;
+ var decryptedData;
+ var dataIterator;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+
+ encryptedData = someData.arrayValues();
+ nonce = encryptedData.slice(0, (128/8));
+ encryptedData = encryptedData.slice(128/8);
+ decryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, encryptedData, nonce);
+
+ result = new Clipperz.ByteArray(decryptedData);
+
+ return result;
+ },
+
+ //=============================================================================
+
+ 'deferredEncryptExecutionChunk': function(anExecutionContext) {
+ var result;
+ var nonce;
+ var self;
+ var messageIndex;
+ var messageLength;
+ var blockSize;
+ var executionLimit;
+ var startTime, endTime;
+
+ self = Clipperz.Crypto.AES_2;
+ startTime = new Date();
+ blockSize = 128/8;
+ messageLength = anExecutionContext.messageArray().length;
+ nonce = anExecutionContext.nonceArray();
+ result = anExecutionContext.resultArray();
+
+ messageIndex = anExecutionContext.executionStep();
+ executionLimit = messageIndex + anExecutionContext.elaborationChunkSize();
+ executionLimit = Math.min(executionLimit, messageLength);
+
+ while (messageIndex < executionLimit) {
+ var encryptedBlock;
+ var i,c;
+
+//console.log("+++ nonce: [" + nonce + "]")
+ encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce);
+
+ if ((executionLimit - messageIndex) > blockSize) {
+ c = blockSize;
+ } else {
+ c = executionLimit - messageIndex;
+ }
+
+ for (i=0; i<c; i++) {
+ result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i];
+ }
+
+ messageIndex += blockSize;
+// nonce = self.incrementNonce(nonce);
+ self.incrementNonce(nonce);
+ }
+ anExecutionContext.setExecutionStep(messageIndex);
+ endTime = new Date();
+ anExecutionContext.tuneExecutionParameters(endTime - startTime);
+
+ return anExecutionContext;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'deferredEncryptBlocks': function(anExecutionContext) {
+ var deferredResult;
+
+//console.log("executionContext", anExecutionContext)
+//console.log(" --- nonce: " + anExecutionContext.nonceArray())
+ if (! anExecutionContext.isDone()) {
+ deferredResult = Clipperz.Async.callbacks("Clipperz.Crypto.AES_2.deferredEncryptBloks", [
+ Clipperz.Crypto.AES_2.deferredEncryptExecutionChunk,
+ MochiKit.Base.method(anExecutionContext, 'pause'),
+ Clipperz.Crypto.AES_2.deferredEncryptBlocks
+ ], {trace:false}, anExecutionContext);
+ } else {
+ deferredResult = MochiKit.Async.succeed(anExecutionContext);
+ }
+
+ return deferredResult;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'deferredEncrypt': function(aKey, someData, aNonce) {
+ var deferredResult;
+ var executionContext;
+ var result;
+ var nonce;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+ nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8);
+
+ executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:someData, nonce:nonce});
+
+ deferredResult = new Clipperz.Async.Deferred("AES.deferredEncrypt");
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks);
+ deferredResult.addCallback(function(anExecutionContext) {
+ var result;
+
+ result = anExecutionContext.nonce().clone();
+ result.appendBytes(anExecutionContext.resultArray());
+
+ return result;
+ });
+ deferredResult.callback(executionContext)
+
+ return deferredResult;
+ },
+
+ //-----------------------------------------------------------------------------
+
+ 'deferredDecrypt': function(aKey, someData) {
+ var deferredResult
+ var nonce;
+ var message;
+ var key;
+
+ key = new Clipperz.Crypto.AES_2.Key({key:aKey});
+ nonce = someData.split(0, (128/8));
+//console.log("nonce: [" + nonce.arrayValues() + "]")
+ message = someData.split(128/8);
+//console.log("message: [" + message.arrayValues() + "]")
+ executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:message, nonce:nonce});
+
+ deferredResult = new Clipperz.Async.Deferred("AES.deferredDecrypt");
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks);
+ deferredResult.addCallback(function(anExecutionContext) {
+ return anExecutionContext.result();
+ });
+ deferredResult.callback(executionContext);
+
+ return deferredResult;
+ },
+
+ //-----------------------------------------------------------------------------
+ __syntaxFix__: "syntax fix"
+
+});
+
+//#############################################################################
+
+//Clipperz.Crypto.AES_2.DeferredExecution = {
+// 'chunkSize': 16384, // 4096, // 1024 4096 8192 16384 32768;
+// 'pauseTime': 0.02 // 0.2
+//}
+
+Clipperz.Crypto.AES_2.exception = {
+ 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES_2.exception.UnsupportedKeySize")
+};
diff --git a/frontend/gamma/js/Clipperz/PM/Crypto.js b/frontend/gamma/js/Clipperz/PM/Crypto.js
index cd10e33..7edf17f 100644
--- a/frontend/gamma/js/Clipperz/PM/Crypto.js
+++ b/frontend/gamma/js/Clipperz/PM/Crypto.js
@@ -62,3 +62,3 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
'encryptingFunctions': {
- 'currentVersion': '0.3',
+ 'currentVersion': '0.4',
'versions': {
@@ -322,2 +322,3 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
deferredResult.addErrback(function(anError) {
+console.log("PIPPO_1", anError)
Clipperz.logError("Error while decrypting data [4]");
@@ -346,3 +347,2 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
}
-
},
@@ -350,3 +350,3 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
//#####################################################################
-/*
+
'0.4': {
@@ -359,23 +359,7 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
-//Clipperz.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt");
key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
-//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1");
value = Clipperz.Base.serializeJSON(aValue);
-//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2");
-/ *
-//Clipperz.logDebug("--> encrypt.fullSize: " + value.length);
- value = value.replace(/":{"label":"/g, '":{l:"');
- value = value.replace(/":{"key":"/g, '":{k:"');
- value = value.replace(/":{"notes":"/g, '":{n:"');
- value = value.replace(/":{"record":"/g, '":{r:"');
- value = value.replace(/", "label":"/g, '",l:"');
- value = value.replace(/", "favicon":"/g, '",f:"');
-//Clipperz.logDebug("<-- encrypt.compressed: " + value.length);
-* /
data = new Clipperz.ByteArray(value);
-//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3");
- encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce);
-//Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4");
+ encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce);
result = encryptedData.toBase64String();
-//Clipperz.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt");
@@ -383,2 +367,23 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
},
+
+ 'deferredEncrypt': function(aKey, aValue, aNonce) {
+ var deferredResult;
+ var key, value;
+ var data;
+ var dataToEncrypt;
+ var encryptedData;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = Clipperz.Base.serializeJSON(aValue);
+ data = new Clipperz.ByteArray(value);
+
+ deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredEncrypt")
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.toBase64String();
+ })
+ deferredResult.callback();
+
+ return deferredResult;
+ },
@@ -394,13 +399,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
- decryptedData = Clipperz.Crypto.AES.decrypt(key, value);
+ decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value);
value = decryptedData.asString();
-/ *
- value = value.replace(/":{l:"/g, '":{"label":"');
- value = value.replace(/":{k:"/g, '":{"key":"');
- value = value.replace(/":{n:"/g, '":{"notes":"');
- value = value.replace(/":{r:"/g, '":{"record":"');
- value = value.replace(/",l:"/g, '", "label":"');
- value = value.replace(/",f:"/g, '", "favicon":"');
-* /
try {
@@ -408,7 +405,6 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
} catch (exception) {
- Clipperz.logError("Error while decrypting data");
+ console.log("PIPPO_2", anError)
+ Clipperz.logError("Error while decrypting data [4]");
throw Clipperz.Crypto.Base.exception.CorruptedMessage;
}
-
-
} else {
@@ -420,5 +416,47 @@ MochiKit.Base.update(Clipperz.PM.Crypto, {
- 'hash': Clipperz.Crypto.SHA.sha_d256
+ 'deferredDecrypt': function(aKey, aValue) {
+ var deferredResult;
+
+ deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredDecrypt", {trace: false});
+
+ if (aValue != null) {
+ var key, value;
+
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey));
+ value = new Clipperz.ByteArray().appendBase64String(aValue);
+
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value);
+ deferredResult.addCallback(MochiKit.Async.wait, 0.1);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.asString();
+ });
+ deferredResult.addCallback(MochiKit.Async.wait, 0.1);
+ deferredResult.addCallback(Clipperz.Base.evalJSON);
+ deferredResult.addErrback(function(anError) {
+ Clipperz.logError("Error while decrypting data [4]");
+ throw Clipperz.Crypto.Base.exception.CorruptedMessage;
+ })
+ } else {
+ deferredResult.addCallback(function() {
+ return null;
+ });
+ }
+ deferredResult.callback();
+
+ return deferredResult;
+ },
+
+ 'hash': Clipperz.Crypto.SHA.sha_d256,
+
+ 'deriveKey': function(aStringValue) {
+ var byteData;
+ var result;
+
+ byteData = new Clipperz.ByteArray(aStringValue);
+ result = Clipperz.Crypto.SHA.sha_d256(byteData);
+
+ return result;
+ }
},
-*/
+
//#####################################################################
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/User.js b/frontend/gamma/js/Clipperz/PM/DataModel/User.js
index fd18faf..b94fe4c 100644
--- a/frontend/gamma/js/Clipperz/PM/DataModel/User.js
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/User.js
@@ -728,4 +728,4 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, {
header['directLogins'] = someHeaderPackedData['recordIndex']['directLogins'];
- header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; // this._serverData['header']['preferences']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['preferences']; // ???????????
- header['oneTimePasswords'] = {'data': someHeaderPackedData['oneTimePasswords']['data']}; // this._serverData['header']['oneTimePasswords']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['oneTimePasswords']; // ???????????
+ header['preferences'] = {'data': someHeaderPackedData['preferences']['data']};
+ header['oneTimePasswords'] = {'data': someHeaderPackedData['oneTimePasswords']['data']};
header['version'] = '0.1';
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
index 326022c..b806cb7 100644
--- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
+++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Offline.DataStore.js
@@ -283,3 +283,3 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
'version': someParameters['credentials']['version'],
- 'lock': Clipperz.Crypto.Base.generateRandomSeed(),
+// 'lock': Clipperz.Crypto.Base.generateRandomSeed(),
'userDetails': someParameters['user']['header'],
@@ -571,3 +571,3 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, {
aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics'];
- aConnection['userData']['userDetailsVersions'] = someParameters['parameters']['user']['version'];
+ aConnection['userData']['userDetailsVersion'] = someParameters['parameters']['user']['version'];
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js
index d459726..1a860c5 100644
--- a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js
+++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js
@@ -145,2 +145,7 @@ Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.ser
};
+//if (aFunctionName == 'knock') {
+// console.log(">>> send message - " + aFunctionName, someParameters);
+//} else {
+// console.log(">>> SEND MESSAGE - " + aFunctionName + " [" + someParameters['parameters']['message'] + "]", someParameters['parameters']['parameters']);
+//}
this.checkRequest(aFunctionName, someParameters);
diff --git a/frontend/gamma/properties/gamma.properties.json b/frontend/gamma/properties/gamma.properties.json
index d00e03a..1bc9e27 100644
--- a/frontend/gamma/properties/gamma.properties.json
+++ b/frontend/gamma/properties/gamma.properties.json
@@ -46,2 +46,3 @@
"Clipperz/Crypto/AES.js",
+ "Clipperz/Crypto/AES_2.js",
"Clipperz/Crypto/PRNG.js",
diff --git a/frontend/gamma/properties/mobile.properties.json b/frontend/gamma/properties/mobile.properties.json
index 0127ce6..2b3b49d 100644
--- a/frontend/gamma/properties/mobile.properties.json
+++ b/frontend/gamma/properties/mobile.properties.json
@@ -11,3 +11,3 @@
"MochiKit/Iter.js",
- "MochiKit/Logging.js",
+ "-- MochiKit/Logging.js",
"MochiKit/DateTime.js",
@@ -17,3 +17,3 @@
"MochiKit/Style.js",
- "MochiKit/LoggingPane.js",
+ "-- MochiKit/LoggingPane.js",
"-- MochiKit/Color.js",
@@ -24,3 +24,3 @@
- "JSON/json2.js",
+ "-- JSON/json2.js",
@@ -45,2 +45,3 @@
"Clipperz/Crypto/AES.js",
+ "Clipperz/Crypto/AES_2.js",
"Clipperz/Crypto/PRNG.js",
@@ -97,2 +98,6 @@
+ "JQuery/1.9.1/jquery.js",
+ "Clipperz/PM/UI/Mobile/CustomizeJQueryMobile.js",
+ "JQuery/Mobile/1.3.0-rc.1/jquery.mobile.js",
+
"-- Zepto/zepto.js",
@@ -128,7 +133,7 @@
- "Clipperz/PM/UI/Common/Components/BaseComponent.js",
+ "-- Clipperz/PM/UI/Common/Components/BaseComponent.js",
"-- Clipperz/PM/UI/Common/Components/Button.js",
- "Clipperz/PM/UI/Common/Components/ComponentSlot.js",
+ "-- Clipperz/PM/UI/Common/Components/ComponentSlot.js",
"-- Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js",
- "Clipperz/PM/UI/Common/Components/ProgressBar.js",
+ "-- Clipperz/PM/UI/Common/Components/ProgressBar.js",
"-- Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js",
@@ -139,8 +144,11 @@
- "Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js",
- "Clipperz/PM/UI/Common/Controllers/ProgressBarController.js",
+ "-- Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js",
+ "-- Clipperz/PM/UI/Common/Controllers/ProgressBarController.js",
"-- Clipperz/PM/UI/Common/Controllers/TabPanelController.js",
+ "Clipperz/PM/UI/Mobile/Components/BaseComponent.js",
+ "Clipperz/PM/UI/Mobile/Components/Overlay.js",
"Clipperz/PM/UI/Mobile/Components/LoginForm.js",
"Clipperz/PM/UI/Mobile/Components/CardList.js",
+ "Clipperz/PM/UI/Mobile/Components/Preferences.js",
"-- Clipperz/PM/UI/Mobile/Components/CardDetail.js",
@@ -153,2 +161,3 @@
"css": [
+ "jquery.mobile-1.3.0-rc.1.css",
"mobile.css"
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html
new file mode 100644
index 0000000..8f922fb
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.html
@@ -0,0 +1,57 @@
+<!--
+
+Copyright 2008-2013 Clipperz Srl
+
+This file is part of Clipperz, the online password manager.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com.
+
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.Crypto.AES_2 - tests</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES_2.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript" src="AES_2.test.js"></script>
+</pre>
+</body>
+</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js
new file mode 100644
index 0000000..f753747
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/AES_2.test.js
@@ -0,0 +1,85 @@
+/*
+
+Copyright 2008-2013 Clipperz Srl
+
+This file is part of Clipperz, the online password manager.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com.
+
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
+
+*/
+
+function testEncryptedData (tool, keyValue, encryptedText, expectedCleanText, someTestArgs) {
+ key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(keyValue));
+ value = new Clipperz.ByteArray().appendBase64String(encryptedText);
+
+ deferredResult = new Clipperz.Async.Deferred("pythonCompatibility_test", someTestArgs);
+ deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value);
+ deferredResult.addCallback(function(aResult) {
+ return aResult.asString();
+ });
+ deferredResult.addTest(expectedCleanText, tool);
+ deferredResult.callback();
+
+ return deferredResult;
+}
+
+//=============================================================================
+
+var tests = {
+
+ 'incrementNonce_test': function (someTestArgs) {
+ var nonce;
+
+ nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
+ Clipperz.Crypto.AES_2.incrementNonce(nonce)
+ SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "increment 0 based nonce");
+
+ nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
+ Clipperz.Crypto.AES_2.incrementNonce(nonce)
+ SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], "increment '1' nonce");
+
+ nonce = [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,89]
+ Clipperz.Crypto.AES_2.incrementNonce(nonce)
+ SimpleTest.eq(nonce, [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,90], "increment '1' nonce");
+ return
+ },
+
+ 'pythonCompatibility_test': function (someTestArgs) {
+ var keyValue = "clipperz"
+ var cleanText = "Lorem īpsum dōlōr siÞ ǽmēt, stet voluptatum ei eum, quō pērfecto lobortis eā, vel ċu deserūisse comprehēƿsam. Eu sed cībō veniam effīciendi, Þe legere ðominġ est, ðuō ċu saperet inermis pērfeċto. Vim ei essent consetētūr, quo etīam saepē æpeirian in, et atqūi velīÞ sǣepe his? Æn porrō putanÞ sinġulis mei, ēx sonet noster mea, tē alterum praesent percipitur qūo. ViÞaē neċessitatibus ne vim, per ex communē sentēntiǣe! Qui stet ǽdhūċ uÞ."
+
+// def testEncrypt (keyValue, cleanText):
+// key = keyDerivation(keyValue)
+// iv = random.getrandbits(128)
+// ctr = Crypto.Util.Counter.new(128, initial_value=iv)
+// cipher = AES.new(key, Crypto.Cipher.AES.MODE_CTR, counter=ctr)
+// encryptedValue = cipher.encrypt(cleanText.encode('utf-8'))
+// data = base64.b64encode(base64.b16decode(hex(iv).upper()[2:-1]) + encryptedValue)
+//
+// return data
+
+ var pythonEncryptedData = "9AFIXRO2nY0mkLJI6Xd4bd+Ov1g+kYUh73nICEVUM8OGt5FnfV/w2BfmTvdMGZjs+rF8w0ksrS9Ny8j2+2zPUUrKnVRXO6eGVPSN5VfuYFSHucV98msINH0FpOZHftuKCuJkB/orjQhoIbj9SXT0yUwB3b4R2bk48Br7R8G2bhxqrHRmnYQn22AQVA83UstNvCOdXT7ArfwJZbVSSMkdmvcziZ8ObMvaH+FXD/K8i7dzS1yP03MMBtIkYN8PnyUMS2uAHKiR11jGuha9QfXjLJlWUQWZgNB9NKyOKf7tN+OgtAoWmHmKlpTshfwbfFD8wBPR0kkhR0cC+7queIjpCDnBJ+Nod78zWgPDR8g64sph7OB686HkP03cO66aH/LNuAt03gxaVyE8ufvoStRjlIthOuys5xYWP+hTFYDC7OhCOLKvhZoY4Tr/FP+TjporX3ivCJUEEvwvXeftAxFVRl4JDin0ys0iPTQ7QlbtVa+iep2n9FUG1NOn5boD9y+iw64UJAcex4MqEIdpCHne9LjpiqshcwLmfEeLlFab28LHnvYPGkXDrSRjCujx8ZmmTw96sAIDqER8p1AqaSojwvONYBGrq+f5/f4xjzZJAknMmxYEN14Phbxc8WEhpe5omWdB80C1Kv6CLsoQnGAIshURSZryToXL"
+ return testEncryptedData("python", keyValue, pythonEncryptedData, cleanText, someTestArgs)
+ },
+
+ //-------------------------------------------------------------------------
+ 'syntaxFix': MochiKit.Base.noop
+}
+
+//=============================================================================
+
+Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
+SimpleTest.runDeferredTests("Clipperz.Crypto.AES_2", tests, {trace:false});
diff --git a/frontend/gamma/tests/tests/Clipperz/Crypto/index.html b/frontend/gamma/tests/tests/Clipperz/Crypto/index.html
index 5ee8b8c..0679739 100644
--- a/frontend/gamma/tests/tests/Clipperz/Crypto/index.html
+++ b/frontend/gamma/tests/tests/Clipperz/Crypto/index.html
@@ -34,2 +34,3 @@ TestRunner.runTests(
'AES.html',
+// 'AES_2.html',
'AES.performance.html',
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html
new file mode 100644
index 0000000..1ed863a
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.html
@@ -0,0 +1,60 @@
+<!--
+
+Copyright 2008-2013 Clipperz Srl
+
+This file is part of Clipperz, the online password manager.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com.
+
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
+
+-->
+
+<html>
+<head>
+ <title>Clipperz.PM.Crypto [0.4] - tests</title>
+
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+
+ <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script>
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css">
+
+ <script type='text/javascript' src='../../../../js/JSON/json2.js'></script>
+
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES_2.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Proxy.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Connection.js'></script>
+ <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script>
+
+ <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script>
+
+</head>
+<body>
+<pre id="test">
+<script type="text/javascript" src="Crypto_v0_4.test.js"></script>
+</pre>
+</body>
+</html>
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js
new file mode 100644
index 0000000..ecfbec3
--- a/dev/null
+++ b/frontend/gamma/tests/tests/Clipperz/PM/Crypto_v0_4.test.js
@@ -0,0 +1,50 @@
+/*
+
+Copyright 2008-2013 Clipperz Srl
+
+This file is part of Clipperz, the online password manager.
+For further information about its features and functionalities please
+refer to http://www.clipperz.com.
+
+* Clipperz is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+* Clipperz is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ See the GNU Affero General Public License for more details.
+
+* You should have received a copy of the GNU Affero General Public
+ License along with Clipperz. If not, see http://www.gnu.org/licenses/.
+
+*/
+
+var tests = {
+
+ 'decryptDataEncryptedUsingPythonLibrary_test': function (someTestArgs) {
+ var deferredResult;
+
+ passphrase = 'trustno1';
+ encryptedData = 'OucTxzBWmqm8jS7EUyIlWUWDPSFKvulL5iM4WwLPbNVIH7jtaK9pmzpm9w5ioVy2/tyebVwWr36t7QXSBOPwUPo2SlGmARCozA==';
+
+ deferredResult = new Clipperz.Async.Deferred("decryptDataEncryptedUsingPythonLibrary_test", someTestArgs);
+ deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, {key:passphrase, value:encryptedData, version:'0.4'});
+ deferredResult.addCallback(MochiKit.Base.itemgetter('message'));
+ deferredResult.addTest("The quick brown fox jumps over the lazy dog", "expected value");
+
+ deferredResult.callback();
+
+ return deferredResult;
+
+ },
+
+ //-------------------------------------------------------------------------
+ 'syntaxFix': MochiKit.Base.noop
+}
+
+//=============================================================================
+
+Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose();
+SimpleTest.runDeferredTests("Clipperz.PM.Crypto [0.4]", tests, {trace:false});
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html
index 73b8225..74d1a07 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html
+++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/DirectLogin.html
@@ -45,2 +45,3 @@ refer to http://www.clipperz.com.
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script>
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script>
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html
index a711ba9..c264ff7 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html
+++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/EncryptedRemoteObject.html
@@ -44,2 +44,3 @@ refer to http://www.clipperz.com.
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script>
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script>
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html
index 0332008..4d6bc5d 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html
+++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.html
@@ -45,2 +45,3 @@ refer to http://www.clipperz.com.
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script>
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script>
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js
index 3478743..af1ffe8 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js
+++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/Record.test.js
@@ -179,2 +179,9 @@ var tests = {
deferredResult.addMethod(user, 'login');
+
+ deferredResult.addMethod(user, 'getRecord', recordID);
+ deferredResult.addMethodcaller('directLogins');
+ deferredResult.addCallback(MochiKit.Base.keys);
+ deferredResult.addCallback(MochiKit.Base.itemgetter('length'));
+ deferredResult.addTest(4, "The record initially has 4 direct logins");
+
deferredResult.addMethod(user, 'getRecord', recordID);
@@ -189,2 +196,3 @@ var tests = {
deferredResult.addMethod(user, 'saveChanges');
+
deferredResult.addMethod(user, 'hasPendingChanges');
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html
index 793f763..3a0eda8 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html
+++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.html
@@ -45,2 +45,3 @@ refer to http://www.clipperz.com.
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script>
+ <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script>
<script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script>
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js
index 45f3297..545580f 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js
+++ b/frontend/gamma/tests/tests/Clipperz/PM/DataModel/User.test.js
@@ -1924,3 +1924,3 @@ var tests = {
user2 = new Clipperz.PM.DataModel.User({username:username, getPassphraseFunction:function () { return passphrase;}});
-
+console.log("PROXY", proxy);
deferredResult = new Clipperz.Async.Deferred("registerNewUserAndAddARecord_test", someTestArgs);
diff --git a/frontend/gamma/tests/tests/Clipperz/PM/index.html b/frontend/gamma/tests/tests/Clipperz/PM/index.html
index eeda692..6eb6622 100644
--- a/frontend/gamma/tests/tests/Clipperz/PM/index.html
+++ b/frontend/gamma/tests/tests/Clipperz/PM/index.html
@@ -39,2 +39,3 @@ TestRunner.runTests(
'Crypto.html',
+ 'Crypto_v0_4.html',
// 'Crypto_other_implementation_comparison.html',