author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-19 15:09:28 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2013-04-19 15:09:28 (UTC) |
commit | 074e70457c90344b3c1cb236105638d692a0066b (patch) (unidiff) | |
tree | c5ffabd3eaf74cbeb69974beacdb5a5f8c235adc | |
parent | 48c9280c9a255f2a85ad5729830df884e64a9c5d (diff) | |
download | clipperz-074e70457c90344b3c1cb236105638d692a0066b.zip clipperz-074e70457c90344b3c1cb236105638d692a0066b.tar.gz clipperz-074e70457c90344b3c1cb236105638d692a0066b.tar.bz2 |
Fixed an issue on the AES-CTR block mode
The previous version of the CTR encoding was incrementing the counter in a weird way, mixing up data from the previous block.
The current fix can correctly decrypt data encoded with AES-CTR using other libraries/languages (currently tested only with Python).
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 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
25 | throw "Clipperz.Crypto.AES_2 depends on Clipperz.ByteArray!"; | ||
26 | } | ||
27 | |||
28 | //Dependency commented to avoid a circular reference | ||
29 | //try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.AES_2 depends on Clipperz.Crypto.PRNG!"; | ||
31 | //} | ||
32 | |||
33 | if (typeof(Clipperz.Crypto.AES_2) == 'undefined') { Clipperz.Crypto.AES_2 = {}; } | ||
34 | |||
35 | //############################################################################# | ||
36 | |||
37 | Clipperz.Crypto.AES_2.DeferredExecutionContext = function(args) { | ||
38 | args = args || {}; | ||
39 | |||
40 | this._key = args.key; | ||
41 | this._message = args.message; | ||
42 | this._result = args.message.clone(); | ||
43 | this._nonce = args.nonce; | ||
44 | this._messageLength = this._message.length(); | ||
45 | |||
46 | this._messageArray = this._message.arrayValues(); | ||
47 | this._resultArray = this._result.arrayValues(); | ||
48 | this._nonceArray = this._nonce.arrayValues(); | ||
49 | |||
50 | this._executionStep = 0; | ||
51 | |||
52 | return this; | ||
53 | } | ||
54 | |||
55 | Clipperz.Crypto.AES_2.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { | ||
56 | |||
57 | 'key': function() { | ||
58 | return this._key; | ||
59 | }, | ||
60 | |||
61 | 'message': function() { | ||
62 | return this._message; | ||
63 | }, | ||
64 | |||
65 | 'messageLength': function() { | ||
66 | return this._messageLength; | ||
67 | }, | ||
68 | |||
69 | 'result': function() { | ||
70 | return new Clipperz.ByteArray(this.resultArray()); | ||
71 | }, | ||
72 | |||
73 | 'nonce': function() { | ||
74 | return this._nonce; | ||
75 | }, | ||
76 | |||
77 | 'messageArray': function() { | ||
78 | return this._messageArray; | ||
79 | }, | ||
80 | |||
81 | 'resultArray': function() { | ||
82 | return this._resultArray; | ||
83 | }, | ||
84 | |||
85 | 'nonceArray': function() { | ||
86 | return this._nonceArray; | ||
87 | }, | ||
88 | |||
89 | 'elaborationChunkSize': function() { | ||
90 | return Clipperz.Crypto.AES_2.DeferredExecution.chunkSize; | ||
91 | }, | ||
92 | |||
93 | 'executionStep': function() { | ||
94 | return this._executionStep; | ||
95 | }, | ||
96 | |||
97 | 'setExecutionStep': function(aValue) { | ||
98 | this._executionStep = aValue; | ||
99 | }, | ||
100 | |||
101 | 'pause': function(aValue) { | ||
102 | return MochiKit.Async.wait(Clipperz.Crypto.AES_2.DeferredExecution.pauseTime, aValue); | ||
103 | }, | ||
104 | |||
105 | //----------------------------------------------------------------------------- | ||
106 | __syntaxFix__: "syntax fix" | ||
107 | |||
108 | }); | ||
109 | |||
110 | //############################################################################# | ||
111 | |||
112 | Clipperz.Crypto.AES_2.Key = function(args) { | ||
113 | args = args || {}; | ||
114 | |||
115 | this._key = args.key; | ||
116 | this._keySize = args.keySize || this.key().length(); | ||
117 | |||
118 | if (this.keySize() == 128/8) { | ||
119 | this._b = 176; | ||
120 | this._numberOfRounds = 10; | ||
121 | } else if (this.keySize() == 256/8) { | ||
122 | this._b = 240; | ||
123 | this._numberOfRounds = 14; | ||
124 | } else { | ||
125 | MochiKit.Logging.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); | ||
126 | throw Clipperz.Crypto.AES_2.exception.UnsupportedKeySize; | ||
127 | } | ||
128 | |||
129 | this._stretchedKey = null; | ||
130 | |||
131 | return this; | ||
132 | } | ||
133 | |||
134 | Clipperz.Crypto.AES_2.Key.prototype = MochiKit.Base.update(null, { | ||
135 | |||
136 | 'asString': function() { | ||
137 | return "Clipperz.Crypto.AES_2.Key (" + this.key().toHexString() + ")"; | ||
138 | }, | ||
139 | |||
140 | //----------------------------------------------------------------------------- | ||
141 | |||
142 | 'key': function() { | ||
143 | return this._key; | ||
144 | }, | ||
145 | |||
146 | 'keySize': function() { | ||
147 | return this._keySize; | ||
148 | }, | ||
149 | |||
150 | 'b': function() { | ||
151 | return this._b; | ||
152 | }, | ||
153 | |||
154 | 'numberOfRounds': function() { | ||
155 | return this._numberOfRounds; | ||
156 | }, | ||
157 | //========================================================================= | ||
158 | |||
159 | 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { | ||
160 | varresult; | ||
161 | var sbox; | ||
162 | |||
163 | sbox = Clipperz.Crypto.AES_2.sbox(); | ||
164 | |||
165 | result = [sbox[aWord[1]] ^ Clipperz.Crypto.AES_2.roundConstants()[aRoundConstantsIndex], | ||
166 | sbox[aWord[2]], | ||
167 | sbox[aWord[3]], | ||
168 | sbox[aWord[0]]]; | ||
169 | |||
170 | return result; | ||
171 | }, | ||
172 | |||
173 | //----------------------------------------------------------------------------- | ||
174 | |||
175 | 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { | ||
176 | varresult; | ||
177 | var i,c; | ||
178 | |||
179 | result = []; | ||
180 | c = 4; | ||
181 | for (i=0; i<c; i++) { | ||
182 | result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); | ||
183 | } | ||
184 | |||
185 | return result; | ||
186 | }, | ||
187 | |||
188 | //----------------------------------------------------------------------------- | ||
189 | |||
190 | 'sboxShakeup': function(aWord) { | ||
191 | var result; | ||
192 | var sbox; | ||
193 | var i,c; | ||
194 | |||
195 | result = []; | ||
196 | sbox = Clipperz.Crypto.AES_2.sbox(); | ||
197 | c =4; | ||
198 | for (i=0; i<c; i++) { | ||
199 | result[i] = sbox[aWord[i]]; | ||
200 | } | ||
201 | |||
202 | return result; | ||
203 | }, | ||
204 | |||
205 | //----------------------------------------------------------------------------- | ||
206 | |||
207 | 'stretchKey': function(aKey) { | ||
208 | varcurrentWord; | ||
209 | varkeyLength; | ||
210 | varpreviousStretchIndex; | ||
211 | var i,c; | ||
212 | |||
213 | keyLength = aKey.length(); | ||
214 | previousStretchIndex = keyLength - this.keySize(); | ||
215 | |||
216 | currentWord = [aKey.byteAtIndex(keyLength - 4), | ||
217 | aKey.byteAtIndex(keyLength - 3), | ||
218 | aKey.byteAtIndex(keyLength - 2), | ||
219 | aKey.byteAtIndex(keyLength - 1)]; | ||
220 | currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize()); | ||
221 | |||
222 | if (this.keySize() == 256/8) { | ||
223 | c = 8; | ||
224 | } else if (this.keySize() == 128/8){ | ||
225 | c = 4; | ||
226 | } | ||
227 | |||
228 | for (i=0; i<c; i++) { | ||
229 | if (i == 4) { | ||
230 | //fifth streatch word | ||
231 | currentWord = this.sboxShakeup(currentWord); | ||
232 | } | ||
233 | |||
234 | currentWord = this.xorWithPreviousStretchValues(aKey, currentWord, previousStretchIndex + (i*4)); | ||
235 | aKey.appendBytes(currentWord); | ||
236 | } | ||
237 | |||
238 | return aKey; | ||
239 | }, | ||
240 | |||
241 | //----------------------------------------------------------------------------- | ||
242 | |||
243 | 'stretchedKey': function() { | ||
244 | if (this._stretchedKey == null) { | ||
245 | var stretchedKey; | ||
246 | |||
247 | stretchedKey = this.key().clone(); | ||
248 | |||
249 | while (stretchedKey.length() < this.keySize()) { | ||
250 | stretchedKey.appendByte(0); | ||
251 | } | ||
252 | |||
253 | while (stretchedKey.length() < this.b()) { | ||
254 | stretchedKey = this.stretchKey(stretchedKey); | ||
255 | } | ||
256 | |||
257 | this._stretchedKey = stretchedKey.split(0, this.b()); | ||
258 | } | ||
259 | |||
260 | return this._stretchedKey; | ||
261 | }, | ||
262 | |||
263 | //========================================================================= | ||
264 | __syntaxFix__: "syntax fix" | ||
265 | }); | ||
266 | |||
267 | //############################################################################# | ||
268 | |||
269 | Clipperz.Crypto.AES_2.State = function(args) { | ||
270 | args = args || {}; | ||
271 | |||
272 | this._data = args.block.slice(0); | ||
273 | this._key = args.key; | ||
274 | |||
275 | return this; | ||
276 | } | ||
277 | |||
278 | Clipperz.Crypto.AES_2.State.prototype = MochiKit.Base.update(null, { | ||
279 | |||
280 | 'key': function() { | ||
281 | return this._key; | ||
282 | }, | ||
283 | |||
284 | //----------------------------------------------------------------------------- | ||
285 | |||
286 | 'data': function() { | ||
287 | return this._data; | ||
288 | }, | ||
289 | |||
290 | 'setData': function(aValue) { | ||
291 | this._data = aValue; | ||
292 | }, | ||
293 | |||
294 | //========================================================================= | ||
295 | |||
296 | 'addRoundKey': function(aRoundNumber) { | ||
297 | //each byte of the state is combined with the round key; each round key is derived from the cipher key using a key schedule. | ||
298 | vardata; | ||
299 | varstretchedKey; | ||
300 | varfirstStretchedKeyIndex; | ||
301 | var i,c; | ||
302 | |||
303 | data = this.data(); | ||
304 | stretchedKey = this.key().stretchedKey(); | ||
305 | firstStretchedKeyIndex = aRoundNumber * (128/8); | ||
306 | c = 128/8; | ||
307 | for (i=0; i<c; i++) { | ||
308 | data[i] = data[i] ^ stretchedKey.byteAtIndex(firstStretchedKeyIndex + i); | ||
309 | } | ||
310 | }, | ||
311 | |||
312 | //----------------------------------------------------------------------------- | ||
313 | |||
314 | 'subBytes': function() { | ||
315 | // a non-linear substitution step where each byte is replaced with another according to a lookup table. | ||
316 | var i,c; | ||
317 | vardata; | ||
318 | var sbox; | ||
319 | |||
320 | data = this.data(); | ||
321 | sbox = Clipperz.Crypto.AES_2.sbox(); | ||
322 | |||
323 | c = 16; | ||
324 | for (i=0; i<c; i++) { | ||
325 | data[i] = sbox[data[i]]; | ||
326 | } | ||
327 | }, | ||
328 | |||
329 | //----------------------------------------------------------------------------- | ||
330 | |||
331 | 'shiftRows': function() { | ||
332 | //a transposition step where each row of the state is shifted cyclically a certain number of steps. | ||
333 | varnewValue; | ||
334 | vardata; | ||
335 | varshiftMapping; | ||
336 | vari,c; | ||
337 | |||
338 | newValue = new Array(16); | ||
339 | data = this.data(); | ||
340 | shiftMapping = Clipperz.Crypto.AES_2.shiftRowMapping(); | ||
341 | // [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; | ||
342 | c = 16; | ||
343 | for (i=0; i<c; i++) { | ||
344 | newValue[i] = data[shiftMapping[i]]; | ||
345 | } | ||
346 | for (i=0; i<c; i++) { | ||
347 | data[i] = newValue[i]; | ||
348 | } | ||
349 | }, | ||
350 | |||
351 | //----------------------------------------------------------------------------- | ||
352 | /* | ||
353 | 'mixColumnsWithValues': function(someValues) { | ||
354 | varresult; | ||
355 | vara; | ||
356 | var i,c; | ||
357 | |||
358 | c = 4; | ||
359 | result = []; | ||
360 | a = []; | ||
361 | for (i=0; i<c; i++) { | ||
362 | a[i] = []; | ||
363 | a[i][1] = someValues[i] | ||
364 | if ((a[i][1] & 0x80) == 0x80) { | ||
365 | a[i][2] = (a[i][1] << 1) ^ 0x11b; | ||
366 | } else { | ||
367 | a[i][2] = a[i][1] << 1; | ||
368 | } | ||
369 | |||
370 | a[i][3] = a[i][2] ^ a[i][1]; | ||
371 | } | ||
372 | |||
373 | for (i=0; i<c; i++) { | ||
374 | varx; | ||
375 | |||
376 | x = Clipperz.Crypto.AES_2.mixColumnsMatrix()[i]; | ||
377 | result[i] = a[0][x[0]] ^ a[1][x[1]] ^ a[2][x[2]] ^ a[3][x[3]]; | ||
378 | } | ||
379 | |||
380 | return result; | ||
381 | }, | ||
382 | |||
383 | 'mixColumns': function() { | ||
384 | //a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. | ||
385 | var data; | ||
386 | var i, c; | ||
387 | |||
388 | data = this.data(); | ||
389 | c = 4; | ||
390 | for(i=0; i<c; i++) { | ||
391 | varblockIndex; | ||
392 | var mixedValues; | ||
393 | |||
394 | blockIndex = i * 4; | ||
395 | mixedValues = this.mixColumnsWithValues([data[blockIndex + 0], | ||
396 | data[blockIndex + 1], | ||
397 | data[blockIndex + 2], | ||
398 | data[blockIndex + 3]]); | ||
399 | data[blockIndex + 0] = mixedValues[0]; | ||
400 | data[blockIndex + 1] = mixedValues[1]; | ||
401 | data[blockIndex + 2] = mixedValues[2]; | ||
402 | data[blockIndex + 3] = mixedValues[3]; | ||
403 | } | ||
404 | }, | ||
405 | */ | ||
406 | |||
407 | 'mixColumns': function() { | ||
408 | //a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. | ||
409 | var data; | ||
410 | var i, c; | ||
411 | var a_1; | ||
412 | var a_2; | ||
413 | |||
414 | a_1 = new Array(4); | ||
415 | a_2 = new Array(4); | ||
416 | |||
417 | data = this.data(); | ||
418 | c = 4; | ||
419 | for(i=0; i<c; i++) { | ||
420 | varblockIndex; | ||
421 | var ii, cc; | ||
422 | |||
423 | blockIndex = i * 4; | ||
424 | |||
425 | cc = 4; | ||
426 | for (ii=0; ii<cc; ii++) { | ||
427 | var value; | ||
428 | |||
429 | value = data[blockIndex + ii]; | ||
430 | a_1[ii] = value; | ||
431 | a_2[ii] = (value & 0x80) ? ((value << 1) ^ 0x011b) : (value << 1); | ||
432 | } | ||
433 | |||
434 | data[blockIndex + 0] = a_2[0] ^ a_1[1] ^ a_2[1] ^ a_1[2] ^ a_1[3]; | ||
435 | data[blockIndex + 1] = a_1[0] ^ a_2[1] ^ a_1[2] ^ a_2[2] ^ a_1[3]; | ||
436 | data[blockIndex + 2] = a_1[0] ^ a_1[1] ^ a_2[2] ^ a_1[3] ^ a_2[3]; | ||
437 | data[blockIndex + 3] = a_1[0] ^ a_2[0] ^ a_1[1] ^ a_1[2] ^ a_2[3]; | ||
438 | } | ||
439 | }, | ||
440 | |||
441 | //========================================================================= | ||
442 | |||
443 | 'spinRound': function(aRoundNumber) { | ||
444 | this.addRoundKey(aRoundNumber); | ||
445 | this.subBytes(); | ||
446 | this.shiftRows(); | ||
447 | this.mixColumns(); | ||
448 | }, | ||
449 | |||
450 | 'spinLastRound': function() { | ||
451 | this.addRoundKey(this.key().numberOfRounds() - 1); | ||
452 | this.subBytes(); | ||
453 | this.shiftRows(); | ||
454 | this.addRoundKey(this.key().numberOfRounds()); | ||
455 | }, | ||
456 | |||
457 | //========================================================================= | ||
458 | |||
459 | 'encrypt': function() { | ||
460 | vari,c; | ||
461 | |||
462 | c = this.key().numberOfRounds() - 1; | ||
463 | for (i=0; i<c; i++) { | ||
464 | this.spinRound(i); | ||
465 | } | ||
466 | |||
467 | this.spinLastRound(); | ||
468 | }, | ||
469 | |||
470 | //========================================================================= | ||
471 | __syntaxFix__: "syntax fix" | ||
472 | }); | ||
473 | |||
474 | //############################################################################# | ||
475 | |||
476 | Clipperz.Crypto.AES_2.VERSION = "0.1"; | ||
477 | Clipperz.Crypto.AES_2.NAME = "Clipperz.Crypto.AES_2"; | ||
478 | |||
479 | MochiKit.Base.update(Clipperz.Crypto.AES_2, { | ||
480 | |||
481 | //http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html | ||
482 | //http://en.wikipedia.org/wiki/Advanced_Encryption_Standard | ||
483 | //http://en.wikipedia.org/wiki/Rijndael_key_schedule | ||
484 | //http://en.wikipedia.org/wiki/Rijndael_S-box | ||
485 | |||
486 | '__repr__': function () { | ||
487 | return "[" + this.NAME + " " + this.VERSION + "]"; | ||
488 | }, | ||
489 | |||
490 | 'toString': function () { | ||
491 | return this.__repr__(); | ||
492 | }, | ||
493 | |||
494 | //============================================================================= | ||
495 | |||
496 | '_sbox': null, | ||
497 | 'sbox': function() { | ||
498 | if (Clipperz.Crypto.AES_2._sbox == null) { | ||
499 | Clipperz.Crypto.AES_2._sbox = [ | ||
500 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, | ||
501 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, | ||
502 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, | ||
503 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, | ||
504 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, | ||
505 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, | ||
506 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, | ||
507 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, | ||
508 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, | ||
509 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, | ||
510 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, | ||
511 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, | ||
512 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, | ||
513 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, | ||
514 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, | ||
515 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 | ||
516 | ]; | ||
517 | } | ||
518 | |||
519 | return Clipperz.Crypto.AES_2._sbox; | ||
520 | }, | ||
521 | |||
522 | //----------------------------------------------------------------------------- | ||
523 | // | ||
524 | // 0 4 8 12 0 4 812 | ||
525 | // 1 5 9 13 => 5 9 131 | ||
526 | // 2 6 10 14 10 14 26 | ||
527 | // 3 7 11 15 15 3 711 | ||
528 | // | ||
529 | '_shiftRowMapping': null, | ||
530 | 'shiftRowMapping': function() { | ||
531 | if (Clipperz.Crypto.AES_2._shiftRowMapping == null) { | ||
532 | Clipperz.Crypto.AES_2._shiftRowMapping = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; | ||
533 | } | ||
534 | |||
535 | return Clipperz.Crypto.AES_2._shiftRowMapping; | ||
536 | }, | ||
537 | |||
538 | //----------------------------------------------------------------------------- | ||
539 | |||
540 | '_mixColumnsMatrix': null, | ||
541 | 'mixColumnsMatrix': function() { | ||
542 | if (Clipperz.Crypto.AES_2._mixColumnsMatrix == null) { | ||
543 | Clipperz.Crypto.AES_2._mixColumnsMatrix = [[2, 3, 1 ,1], | ||
544 | [1, 2, 3, 1], | ||
545 | [1, 1, 2, 3], | ||
546 | [3, 1, 1, 2] ]; | ||
547 | } | ||
548 | |||
549 | return Clipperz.Crypto.AES_2._mixColumnsMatrix; | ||
550 | }, | ||
551 | |||
552 | '_roundConstants': null, | ||
553 | 'roundConstants': function() { | ||
554 | if (Clipperz.Crypto.AES_2._roundConstants == null) { | ||
555 | Clipperz.Crypto.AES_2._roundConstants = [ , 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154]; | ||
556 | // Clipperz.Crypto.AES_2._roundConstants = [ , 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a]; | ||
557 | } | ||
558 | |||
559 | return Clipperz.Crypto.AES_2._roundConstants; | ||
560 | }, | ||
561 | |||
562 | //============================================================================= | ||
563 | |||
564 | 'incrementNonce': function(nonce) { | ||
565 | var i; | ||
566 | var done; | ||
567 | |||
568 | done = false; | ||
569 | i = nonce.length - 1; | ||
570 | |||
571 | while ((i>=0) && (done == false)) { | ||
572 | var currentByteValue; | ||
573 | |||
574 | currentByteValue = nonce[i]; | ||
575 | |||
576 | if (currentByteValue == 0xff) { | ||
577 | nonce[i] = 0; | ||
578 | if (i>= 0) { | ||
579 | i --; | ||
580 | } else { | ||
581 | done = true; | ||
582 | } | ||
583 | } else { | ||
584 | nonce[i] = currentByteValue + 1; | ||
585 | done = true; | ||
586 | } | ||
587 | } | ||
588 | }, | ||
589 | |||
590 | //----------------------------------------------------------------------------- | ||
591 | |||
592 | 'encryptBlock': function(aKey, aBlock) { | ||
593 | varresult; | ||
594 | varstate; | ||
595 | |||
596 | state = new Clipperz.Crypto.AES_2.State({block:aBlock, key:aKey}); | ||
597 | //is(state.data(), 'before'); | ||
598 | state.encrypt(); | ||
599 | result = state.data(); | ||
600 | |||
601 | return result; | ||
602 | }, | ||
603 | |||
604 | //----------------------------------------------------------------------------- | ||
605 | |||
606 | 'encryptBlocks': function(aKey, aMessage, aNonce) { | ||
607 | varresult; | ||
608 | var nonce; | ||
609 | var self; | ||
610 | varmessageIndex; | ||
611 | varmessageLength; | ||
612 | var blockSize; | ||
613 | |||
614 | self = Clipperz.Crypto.AES_2; | ||
615 | blockSize = 128/8; | ||
616 | messageLength = aMessage.length; | ||
617 | nonce = aNonce; | ||
618 | |||
619 | result = aMessage; | ||
620 | messageIndex = 0; | ||
621 | while (messageIndex < messageLength) { | ||
622 | var encryptedBlock; | ||
623 | var i,c; | ||
624 | |||
625 | encryptedBlock = self.encryptBlock(aKey, nonce); | ||
626 | |||
627 | if ((messageLength - messageIndex) > blockSize) { | ||
628 | c = blockSize; | ||
629 | } else { | ||
630 | c = messageLength - messageIndex; | ||
631 | } | ||
632 | |||
633 | for (i=0; i<c; i++) { | ||
634 | result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; | ||
635 | } | ||
636 | |||
637 | messageIndex += blockSize; | ||
638 | self.incrementNonce(nonce); | ||
639 | } | ||
640 | |||
641 | return result; | ||
642 | }, | ||
643 | |||
644 | //----------------------------------------------------------------------------- | ||
645 | |||
646 | 'encrypt': function(aKey, someData, aNonce) { | ||
647 | var result; | ||
648 | var nonce; | ||
649 | varencryptedData; | ||
650 | var key; | ||
651 | |||
652 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
653 | nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); | ||
654 | |||
655 | encryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, someData.arrayValues(), nonce.arrayValues()); | ||
656 | |||
657 | result = nonce.appendBytes(encryptedData); | ||
658 | |||
659 | return result; | ||
660 | }, | ||
661 | |||
662 | //----------------------------------------------------------------------------- | ||
663 | |||
664 | 'decrypt': function(aKey, someData) { | ||
665 | var result; | ||
666 | var nonce; | ||
667 | var encryptedData; | ||
668 | var decryptedData; | ||
669 | vardataIterator; | ||
670 | var key; | ||
671 | |||
672 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
673 | |||
674 | encryptedData = someData.arrayValues(); | ||
675 | nonce = encryptedData.slice(0, (128/8)); | ||
676 | encryptedData = encryptedData.slice(128/8); | ||
677 | decryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, encryptedData, nonce); | ||
678 | |||
679 | result = new Clipperz.ByteArray(decryptedData); | ||
680 | |||
681 | return result; | ||
682 | }, | ||
683 | |||
684 | //============================================================================= | ||
685 | |||
686 | 'deferredEncryptExecutionChunk': function(anExecutionContext) { | ||
687 | varresult; | ||
688 | var nonce; | ||
689 | var self; | ||
690 | varmessageIndex; | ||
691 | varmessageLength; | ||
692 | var blockSize; | ||
693 | var executionLimit; | ||
694 | |||
695 | self = Clipperz.Crypto.AES_2; | ||
696 | blockSize = 128/8; | ||
697 | messageLength = anExecutionContext.messageArray().length; | ||
698 | nonce = anExecutionContext.nonceArray(); | ||
699 | result = anExecutionContext.resultArray(); | ||
700 | |||
701 | messageIndex = anExecutionContext.executionStep(); | ||
702 | executionLimit = messageIndex + anExecutionContext.elaborationChunkSize(); | ||
703 | executionLimit = Math.min(executionLimit, messageLength); | ||
704 | |||
705 | while (messageIndex < executionLimit) { | ||
706 | var encryptedBlock; | ||
707 | var i,c; | ||
708 | |||
709 | encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce); | ||
710 | |||
711 | if ((executionLimit - messageIndex) > blockSize) { | ||
712 | c = blockSize; | ||
713 | } else { | ||
714 | c = executionLimit - messageIndex; | ||
715 | } | ||
716 | |||
717 | for (i=0; i<c; i++) { | ||
718 | result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; | ||
719 | } | ||
720 | |||
721 | messageIndex += blockSize; | ||
722 | self.incrementNonce(nonce); | ||
723 | } | ||
724 | anExecutionContext.setExecutionStep(messageIndex); | ||
725 | |||
726 | return anExecutionContext; | ||
727 | }, | ||
728 | |||
729 | //----------------------------------------------------------------------------- | ||
730 | |||
731 | 'deferredEncryptBlocks': function(anExecutionContext) { | ||
732 | vardeferredResult; | ||
733 | varmessageSize; | ||
734 | var i,c; | ||
735 | var now; | ||
736 | |||
737 | messageSize = anExecutionContext.messageLength(); | ||
738 | |||
739 | deferredResult = new MochiKit.Async.Deferred(); | ||
740 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - START: " + res); return res;}); | ||
741 | // deferredResult.addCallback(MochiKit.Base.method(anExecutionContext, 'pause')); | ||
742 | |||
743 | c = Math.ceil(messageSize / anExecutionContext.elaborationChunkSize()); | ||
744 | for (i=0; i<c; i++) { | ||
745 | //deferredResult.addBoth(function(res) {now = new Date(); return res;}); | ||
746 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") - " + res); return res;}); | ||
747 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptExecutionChunk); | ||
748 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "]Clipperz.Crypto.AES_2.deferredEncryptBlocks"); return res;}); | ||
749 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") -- " + res); return res;}); | ||
750 | deferredResult.addCallback(MochiKit.Base.method(anExecutionContext, 'pause')); | ||
751 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - : (" + i + ") --- " + res); return res;}); | ||
752 | } | ||
753 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncryptBlocks - END: " + res); return res;}); | ||
754 | |||
755 | deferredResult.callback(anExecutionContext); | ||
756 | |||
757 | return deferredResult; | ||
758 | }, | ||
759 | |||
760 | //----------------------------------------------------------------------------- | ||
761 | |||
762 | 'deferredEncrypt': function(aKey, someData, aNonce) { | ||
763 | var deferredResult; | ||
764 | varexecutionContext; | ||
765 | var result; | ||
766 | var nonce; | ||
767 | var key; | ||
768 | |||
769 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
770 | nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); | ||
771 | |||
772 | executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:someData, nonce:nonce}); | ||
773 | |||
774 | deferredResult = new MochiKit.Async.Deferred(); | ||
775 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 1: " + res); return res;}); | ||
776 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); | ||
777 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 2: " + res); return res;}); | ||
778 | deferredResult.addCallback(function(anExecutionContext) { | ||
779 | var result; | ||
780 | |||
781 | result = anExecutionContext.nonce().clone(); | ||
782 | result.appendBytes(anExecutionContext.resultArray()); | ||
783 | |||
784 | return result; | ||
785 | }); | ||
786 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("Clipperz.Crypto.AES_2.deferredEncrypt - 3: " + res); return res;}); | ||
787 | deferredResult.callback(executionContext) | ||
788 | |||
789 | return deferredResult; | ||
790 | }, | ||
791 | |||
792 | //----------------------------------------------------------------------------- | ||
793 | |||
794 | 'deferredDecrypt': function(aKey, someData) { | ||
795 | var deferredResult | ||
796 | var nonce; | ||
797 | var message; | ||
798 | var key; | ||
799 | |||
800 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
801 | nonce = someData.split(0, (128/8)); | ||
802 | message = someData.split(128/8); | ||
803 | executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:message, nonce:nonce}); | ||
804 | |||
805 | deferredResult = new MochiKit.Async.Deferred(); | ||
806 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); | ||
807 | deferredResult.addCallback(function(anExecutionContext) { | ||
808 | return anExecutionContext.result(); | ||
809 | }); | ||
810 | deferredResult.callback(executionContext); | ||
811 | |||
812 | return deferredResult; | ||
813 | }, | ||
814 | |||
815 | //----------------------------------------------------------------------------- | ||
816 | __syntaxFix__: "syntax fix" | ||
817 | |||
818 | }); | ||
819 | |||
820 | //############################################################################# | ||
821 | |||
822 | Clipperz.Crypto.AES_2.DeferredExecution = { | ||
823 | 'chunkSize': 4096, // 1024 4096 8192 1638432768; | ||
824 | 'pauseTime': 0.2 | ||
825 | } | ||
826 | |||
827 | Clipperz.Crypto.AES_2.exception = { | ||
828 | 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES_2.exception.UnsupportedKeySize") | ||
829 | }; | ||
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 | |||
@@ -59,5 +59,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
59 | 59 | ||
60 | 'encryptingFunctions': { | 60 | 'encryptingFunctions': { |
61 | 'currentVersion': '0.3', | 61 | 'currentVersion': '0.4', |
62 | 'versions': { | 62 | 'versions': { |
63 | 63 | ||
@@ -296,5 +296,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
296 | 296 | ||
297 | deferredResult = new MochiKit.Async.Deferred(); | 297 | deferredResult = new MochiKit.Async.Deferred(); |
298 | now = new Date; | 298 | // now = new Date; |
299 | 299 | ||
300 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 1: " + res); return res;}); | 300 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("[" + (new Date() - now) + "] Clipperz.PM.Crypto.deferredDecrypt - 1: " + res); return res;}); |
@@ -341,5 +341,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
341 | 341 | ||
342 | //##################################################################### | 342 | //##################################################################### |
343 | /* | 343 | |
344 | '0.4': { | 344 | '0.4': { |
345 | 'encrypt': function(aKey, aValue, aNonce) { | 345 | 'encrypt': function(aKey, aValue, aNonce) { |
@@ -350,28 +350,33 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
350 | var encryptedData; | 350 | var encryptedData; |
351 | 351 | ||
352 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | ||
353 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 352 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
354 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); | ||
355 | value = Clipperz.Base.serializeJSON(aValue); | 353 | value = Clipperz.Base.serializeJSON(aValue); |
356 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); | ||
357 | / * | ||
358 | //MochiKit.Logging.logDebug("--> encrypt.fullSize: " + value.length); | ||
359 | value = value.replace(/":{"label":"/g, '":{l:"'); | ||
360 | value = value.replace(/":{"key":"/g, '":{k:"'); | ||
361 | value = value.replace(/":{"notes":"/g, '":{n:"'); | ||
362 | value = value.replace(/":{"record":"/g, '":{r:"'); | ||
363 | value = value.replace(/", "label":"/g, '",l:"'); | ||
364 | value = value.replace(/", "favicon":"/g,'",f:"'); | ||
365 | //MochiKit.Logging.logDebug("<-- encrypt.compressed: " + value.length); | ||
366 | * / | ||
367 | data = new Clipperz.ByteArray(value); | 354 | data = new Clipperz.ByteArray(value); |
368 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); | 355 | encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce); |
369 | encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); | ||
370 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); | ||
371 | result = encryptedData.toBase64String(); | 356 | result = encryptedData.toBase64String(); |
372 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | ||
373 | 357 | ||
374 | return result; | 358 | return result; |
375 | }, | 359 | }, |
360 | |||
361 | 'deferredEncrypt': function(aKey, aValue, aNonce) { | ||
362 | var deferredResult; | ||
363 | varkey, value; | ||
364 | var data; | ||
365 | var dataToEncrypt; | ||
366 | var encryptedData; | ||
367 | |||
368 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | ||
369 | value = Clipperz.Base.serializeJSON(aValue); | ||
370 | data = new Clipperz.ByteArray(value); | ||
371 | |||
372 | deferredResult = new MochiKit.Async.Deferred() | ||
373 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce); | ||
374 | deferredResult.addCallback(function(aResult) { | ||
375 | return aResult.toBase64String(); | ||
376 | }) | ||
377 | deferredResult.callback(); | ||
378 | |||
379 | return deferredResult; | ||
380 | }, | ||
376 | 381 | ||
377 | 'decrypt': function(aKey, aValue) { | 382 | 'decrypt': function(aKey, aValue) { |
@@ -386,15 +391,7 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
386 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 391 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
387 | 392 | ||
388 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 393 | decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value); |
389 | 394 | ||
390 | value = decryptedData.asString(); | 395 | value = decryptedData.asString(); |
391 | / * | ||
392 | value = value.replace(/":{l:"/g,'":{"label":"'); | ||
393 | value = value.replace(/":{k:"/g,'":{"key":"'); | ||
394 | value = value.replace(/":{n:"/g,'":{"notes":"'); | ||
395 | value = value.replace(/":{r:"/g,'":{"record":"'); | ||
396 | value = value.replace(/",l:"/g, '", "label":"'); | ||
397 | value = value.replace(/",f:"/g, '", "favicon":"'); | ||
398 | * / | ||
399 | try { | 396 | try { |
400 | result = Clipperz.Base.evalJSON(value); | 397 | result = Clipperz.Base.evalJSON(value); |
@@ -403,6 +400,4 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
403 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 400 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
404 | } | 401 | } |
405 | |||
406 | |||
407 | } else { | 402 | } else { |
408 | result = null; | 403 | result = null; |
@@ -412,7 +407,39 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
412 | }, | 407 | }, |
413 | 408 | ||
409 | 'deferredDecrypt': function(aKey, aValue) { | ||
410 | var deferredResult; | ||
411 | |||
412 | deferredResult = new MochiKit.Async.Deferred(); | ||
413 | if (aValue != null) { | ||
414 | var key, value; | ||
415 | var decryptedData; | ||
416 | var decryptedValue; | ||
417 | |||
418 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | ||
419 | value = new Clipperz.ByteArray().appendBase64String(aValue); | ||
420 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); | ||
421 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | ||
422 | deferredResult.addCallback(function(aResult) { | ||
423 | return aResult.asString(); | ||
424 | }); | ||
425 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | ||
426 | deferredResult.addCallback(Clipperz.Base.evalJSON); | ||
427 | deferredResult.addErrback(function(anError) { | ||
428 | MochiKit.Logging.logError("Error while decrypting data"); | ||
429 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | ||
430 | }) | ||
431 | } else { | ||
432 | deferredResult.addCallback(function() { | ||
433 | return null; | ||
434 | }); | ||
435 | } | ||
436 | deferredResult.callback(); | ||
437 | |||
438 | return deferredResult; | ||
439 | }, | ||
440 | |||
414 | 'hash': Clipperz.Crypto.SHA.sha_d256 | 441 | 'hash': Clipperz.Crypto.SHA.sha_d256 |
415 | }, | 442 | }, |
416 | */ | 443 | |
417 | //##################################################################### | 444 | //##################################################################### |
418 | __syntaxFix__: "syntax fix" | 445 | __syntaxFix__: "syntax fix" |
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 | |||
@@ -78,4 +78,5 @@ | |||
78 | "Clipperz/Crypto/SHA.js", | 78 | "Clipperz/Crypto/SHA.js", |
79 | "Clipperz/Crypto/AES.js", | 79 | "Clipperz/Crypto/AES.js", |
80 | "Clipperz/Crypto/AES_2.js", | ||
80 | "Clipperz/Crypto/PRNG.js", | 81 | "Clipperz/Crypto/PRNG.js", |
81 | "Clipperz/Crypto/BigInt.js", | 82 | "Clipperz/Crypto/BigInt.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 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | ||
25 | throw "Clipperz.Crypto.AES_2 depends on Clipperz.ByteArray!"; | ||
26 | } | ||
27 | |||
28 | //Dependency commented to avoid a circular reference | ||
29 | //try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | ||
30 | //throw "Clipperz.Crypto.AES_2 depends on Clipperz.Crypto.PRNG!"; | ||
31 | //} | ||
32 | |||
33 | if (typeof(Clipperz.Crypto.AES_2) == 'undefined') { Clipperz.Crypto.AES_2 = {}; } | ||
34 | |||
35 | //############################################################################# | ||
36 | |||
37 | Clipperz.Crypto.AES_2.DeferredExecutionContext = function(args) { | ||
38 | args = args || {}; | ||
39 | |||
40 | this._key = args.key; | ||
41 | this._message = args.message; | ||
42 | this._result = args.message.clone(); | ||
43 | this._nonce = args.nonce; | ||
44 | this._messageLength = this._message.length(); | ||
45 | |||
46 | this._messageArray = this._message.arrayValues(); | ||
47 | this._resultArray = this._result.arrayValues(); | ||
48 | this._nonceArray = this._nonce.arrayValues(); | ||
49 | |||
50 | this._executionStep = 0; | ||
51 | |||
52 | // this._elaborationChunkSize = 1024; // 4096; // 16384; //4096; | ||
53 | this._elaborationChunks = 10; | ||
54 | this._pauseTime = 0.02; // 0.02 //0.2; | ||
55 | |||
56 | return this; | ||
57 | } | ||
58 | |||
59 | Clipperz.Crypto.AES_2.DeferredExecutionContext.prototype = MochiKit.Base.update(null, { | ||
60 | |||
61 | 'key': function() { | ||
62 | return this._key; | ||
63 | }, | ||
64 | |||
65 | 'message': function() { | ||
66 | return this._message; | ||
67 | }, | ||
68 | |||
69 | 'messageLength': function() { | ||
70 | return this._messageLength; | ||
71 | }, | ||
72 | |||
73 | 'result': function() { | ||
74 | return new Clipperz.ByteArray(this.resultArray()); | ||
75 | }, | ||
76 | |||
77 | 'nonce': function() { | ||
78 | return this._nonce; | ||
79 | }, | ||
80 | |||
81 | 'messageArray': function() { | ||
82 | return this._messageArray; | ||
83 | }, | ||
84 | |||
85 | 'resultArray': function() { | ||
86 | return this._resultArray; | ||
87 | }, | ||
88 | |||
89 | 'nonceArray': function() { | ||
90 | return this._nonceArray; | ||
91 | }, | ||
92 | |||
93 | 'elaborationChunkSize': function() { | ||
94 | // return Clipperz.Crypto.AES_2.DeferredExecution.chunkSize; | ||
95 | // return this._elaborationChunkSize; | ||
96 | return (this._elaborationChunks * 1024); | ||
97 | }, | ||
98 | |||
99 | 'executionStep': function() { | ||
100 | return this._executionStep; | ||
101 | }, | ||
102 | |||
103 | 'setExecutionStep': function(aValue) { | ||
104 | this._executionStep = aValue; | ||
105 | }, | ||
106 | |||
107 | 'tuneExecutionParameters': function (anElapsedTime) { | ||
108 | //var originalChunks = this._elaborationChunks; | ||
109 | if (anElapsedTime > 0) { | ||
110 | this._elaborationChunks = Math.round(this._elaborationChunks * ((anElapsedTime + 1000)/(anElapsedTime * 2))); | ||
111 | } | ||
112 | //Clipperz.log("tuneExecutionParameters - elapsedTime: " + anElapsedTime + /*originalChunks,*/ " chunks # " + this._elaborationChunks + " [" + this._executionStep + " / " + this._messageLength + "]"); | ||
113 | }, | ||
114 | |||
115 | 'pause': function(aValue) { | ||
116 | // return MochiKit.Async.wait(Clipperz.Crypto.AES_2.DeferredExecution.pauseTime, aValue); | ||
117 | return MochiKit.Async.wait(this._pauseTime, aValue); | ||
118 | }, | ||
119 | |||
120 | 'isDone': function () { | ||
121 | return (this._executionStep >= this._messageLength); | ||
122 | }, | ||
123 | |||
124 | //----------------------------------------------------------------------------- | ||
125 | __syntaxFix__: "syntax fix" | ||
126 | |||
127 | }); | ||
128 | |||
129 | //############################################################################# | ||
130 | |||
131 | Clipperz.Crypto.AES_2.Key = function(args) { | ||
132 | args = args || {}; | ||
133 | |||
134 | this._key = args.key; | ||
135 | this._keySize = args.keySize || this.key().length(); | ||
136 | |||
137 | if (this.keySize() == 128/8) { | ||
138 | this._b = 176; | ||
139 | this._numberOfRounds = 10; | ||
140 | } else if (this.keySize() == 256/8) { | ||
141 | this._b = 240; | ||
142 | this._numberOfRounds = 14; | ||
143 | } else { | ||
144 | Clipperz.logError("AES unsupported key size: " + (this.keySize() * 8) + " bits"); | ||
145 | throw Clipperz.Crypto.AES_2.exception.UnsupportedKeySize; | ||
146 | } | ||
147 | |||
148 | this._stretchedKey = null; | ||
149 | |||
150 | return this; | ||
151 | } | ||
152 | |||
153 | Clipperz.Crypto.AES_2.Key.prototype = MochiKit.Base.update(null, { | ||
154 | |||
155 | 'asString': function() { | ||
156 | return "Clipperz.Crypto.AES_2.Key (" + this.key().toHexString() + ")"; | ||
157 | }, | ||
158 | |||
159 | //----------------------------------------------------------------------------- | ||
160 | |||
161 | 'key': function() { | ||
162 | return this._key; | ||
163 | }, | ||
164 | |||
165 | 'keySize': function() { | ||
166 | return this._keySize; | ||
167 | }, | ||
168 | |||
169 | 'b': function() { | ||
170 | return this._b; | ||
171 | }, | ||
172 | |||
173 | 'numberOfRounds': function() { | ||
174 | return this._numberOfRounds; | ||
175 | }, | ||
176 | //========================================================================= | ||
177 | |||
178 | 'keyScheduleCore': function(aWord, aRoundConstantsIndex) { | ||
179 | varresult; | ||
180 | var sbox; | ||
181 | |||
182 | sbox = Clipperz.Crypto.AES_2.sbox(); | ||
183 | |||
184 | result = [sbox[aWord[1]] ^ Clipperz.Crypto.AES_2.roundConstants()[aRoundConstantsIndex], | ||
185 | sbox[aWord[2]], | ||
186 | sbox[aWord[3]], | ||
187 | sbox[aWord[0]]]; | ||
188 | |||
189 | return result; | ||
190 | }, | ||
191 | |||
192 | //----------------------------------------------------------------------------- | ||
193 | |||
194 | 'xorWithPreviousStretchValues': function(aKey, aWord, aPreviousWordIndex) { | ||
195 | varresult; | ||
196 | var i,c; | ||
197 | |||
198 | result = []; | ||
199 | c = 4; | ||
200 | for (i=0; i<c; i++) { | ||
201 | result[i] = aWord[i] ^ aKey.byteAtIndex(aPreviousWordIndex + i); | ||
202 | } | ||
203 | |||
204 | return result; | ||
205 | }, | ||
206 | |||
207 | //----------------------------------------------------------------------------- | ||
208 | |||
209 | 'sboxShakeup': function(aWord) { | ||
210 | var result; | ||
211 | var sbox; | ||
212 | var i,c; | ||
213 | |||
214 | result = []; | ||
215 | sbox = Clipperz.Crypto.AES_2.sbox(); | ||
216 | c =4; | ||
217 | for (i=0; i<c; i++) { | ||
218 | result[i] = sbox[aWord[i]]; | ||
219 | } | ||
220 | |||
221 | return result; | ||
222 | }, | ||
223 | |||
224 | //----------------------------------------------------------------------------- | ||
225 | |||
226 | 'stretchKey': function(aKey) { | ||
227 | varcurrentWord; | ||
228 | varkeyLength; | ||
229 | varpreviousStretchIndex; | ||
230 | var i,c; | ||
231 | |||
232 | keyLength = aKey.length(); | ||
233 | previousStretchIndex = keyLength - this.keySize(); | ||
234 | |||
235 | currentWord = [aKey.byteAtIndex(keyLength - 4), | ||
236 | aKey.byteAtIndex(keyLength - 3), | ||
237 | aKey.byteAtIndex(keyLength - 2), | ||
238 | aKey.byteAtIndex(keyLength - 1)]; | ||
239 | currentWord = this.keyScheduleCore(currentWord, keyLength / this.keySize()); | ||
240 | |||
241 | if (this.keySize() == 256/8) { | ||
242 | c = 8; | ||
243 | } else if (this.keySize() == 128/8){ | ||
244 | c = 4; | ||
245 | } | ||
246 | |||
247 | for (i=0; i<c; i++) { | ||
248 | if (i == 4) { | ||
249 | //fifth streatch word | ||
250 | currentWord = this.sboxShakeup(currentWord); | ||
251 | } | ||
252 | |||
253 | currentWord = this.xorWithPreviousStretchValues(aKey, currentWord, previousStretchIndex + (i*4)); | ||
254 | aKey.appendBytes(currentWord); | ||
255 | } | ||
256 | |||
257 | return aKey; | ||
258 | }, | ||
259 | |||
260 | //----------------------------------------------------------------------------- | ||
261 | |||
262 | 'stretchedKey': function() { | ||
263 | if (this._stretchedKey == null) { | ||
264 | var stretchedKey; | ||
265 | |||
266 | stretchedKey = this.key().clone(); | ||
267 | |||
268 | while (stretchedKey.length() < this.keySize()) { | ||
269 | stretchedKey.appendByte(0); | ||
270 | } | ||
271 | |||
272 | while (stretchedKey.length() < this.b()) { | ||
273 | stretchedKey = this.stretchKey(stretchedKey); | ||
274 | } | ||
275 | |||
276 | this._stretchedKey = stretchedKey.split(0, this.b()); | ||
277 | } | ||
278 | |||
279 | return this._stretchedKey; | ||
280 | }, | ||
281 | |||
282 | //========================================================================= | ||
283 | __syntaxFix__: "syntax fix" | ||
284 | }); | ||
285 | |||
286 | //############################################################################# | ||
287 | |||
288 | Clipperz.Crypto.AES_2.State = function(args) { | ||
289 | args = args || {}; | ||
290 | |||
291 | this._data = args.block.slice(0); | ||
292 | this._key = args.key; | ||
293 | |||
294 | return this; | ||
295 | } | ||
296 | |||
297 | Clipperz.Crypto.AES_2.State.prototype = MochiKit.Base.update(null, { | ||
298 | |||
299 | 'key': function() { | ||
300 | return this._key; | ||
301 | }, | ||
302 | |||
303 | //----------------------------------------------------------------------------- | ||
304 | |||
305 | 'data': function() { | ||
306 | return this._data; | ||
307 | }, | ||
308 | |||
309 | 'setData': function(aValue) { | ||
310 | this._data = aValue; | ||
311 | }, | ||
312 | |||
313 | //========================================================================= | ||
314 | |||
315 | 'addRoundKey': function(aRoundNumber) { | ||
316 | //each byte of the state is combined with the round key; each round key is derived from the cipher key using a key schedule. | ||
317 | vardata; | ||
318 | varstretchedKey; | ||
319 | varfirstStretchedKeyIndex; | ||
320 | var i,c; | ||
321 | |||
322 | data = this.data(); | ||
323 | stretchedKey = this.key().stretchedKey(); | ||
324 | firstStretchedKeyIndex = aRoundNumber * (128/8); | ||
325 | c = 128/8; | ||
326 | for (i=0; i<c; i++) { | ||
327 | data[i] = data[i] ^ stretchedKey.byteAtIndex(firstStretchedKeyIndex + i); | ||
328 | } | ||
329 | }, | ||
330 | |||
331 | //----------------------------------------------------------------------------- | ||
332 | |||
333 | 'subBytes': function() { | ||
334 | // a non-linear substitution step where each byte is replaced with another according to a lookup table. | ||
335 | var i,c; | ||
336 | vardata; | ||
337 | var sbox; | ||
338 | |||
339 | data = this.data(); | ||
340 | sbox = Clipperz.Crypto.AES_2.sbox(); | ||
341 | |||
342 | c = 16; | ||
343 | for (i=0; i<c; i++) { | ||
344 | data[i] = sbox[data[i]]; | ||
345 | } | ||
346 | }, | ||
347 | |||
348 | //----------------------------------------------------------------------------- | ||
349 | |||
350 | 'shiftRows': function() { | ||
351 | //a transposition step where each row of the state is shifted cyclically a certain number of steps. | ||
352 | varnewValue; | ||
353 | vardata; | ||
354 | varshiftMapping; | ||
355 | vari,c; | ||
356 | |||
357 | newValue = new Array(16); | ||
358 | data = this.data(); | ||
359 | shiftMapping = Clipperz.Crypto.AES_2.shiftRowMapping(); | ||
360 | // [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; | ||
361 | c = 16; | ||
362 | for (i=0; i<c; i++) { | ||
363 | newValue[i] = data[shiftMapping[i]]; | ||
364 | } | ||
365 | for (i=0; i<c; i++) { | ||
366 | data[i] = newValue[i]; | ||
367 | } | ||
368 | }, | ||
369 | |||
370 | //----------------------------------------------------------------------------- | ||
371 | /* | ||
372 | 'mixColumnsWithValues': function(someValues) { | ||
373 | varresult; | ||
374 | vara; | ||
375 | var i,c; | ||
376 | |||
377 | c = 4; | ||
378 | result = []; | ||
379 | a = []; | ||
380 | for (i=0; i<c; i++) { | ||
381 | a[i] = []; | ||
382 | a[i][1] = someValues[i] | ||
383 | if ((a[i][1] & 0x80) == 0x80) { | ||
384 | a[i][2] = (a[i][1] << 1) ^ 0x11b; | ||
385 | } else { | ||
386 | a[i][2] = a[i][1] << 1; | ||
387 | } | ||
388 | |||
389 | a[i][3] = a[i][2] ^ a[i][1]; | ||
390 | } | ||
391 | |||
392 | for (i=0; i<c; i++) { | ||
393 | varx; | ||
394 | |||
395 | x = Clipperz.Crypto.AES_2.mixColumnsMatrix()[i]; | ||
396 | result[i] = a[0][x[0]] ^ a[1][x[1]] ^ a[2][x[2]] ^ a[3][x[3]]; | ||
397 | } | ||
398 | |||
399 | return result; | ||
400 | }, | ||
401 | |||
402 | 'mixColumns': function() { | ||
403 | //a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. | ||
404 | var data; | ||
405 | var i, c; | ||
406 | |||
407 | data = this.data(); | ||
408 | c = 4; | ||
409 | for(i=0; i<c; i++) { | ||
410 | varblockIndex; | ||
411 | var mixedValues; | ||
412 | |||
413 | blockIndex = i * 4; | ||
414 | mixedValues = this.mixColumnsWithValues([data[blockIndex + 0], | ||
415 | data[blockIndex + 1], | ||
416 | data[blockIndex + 2], | ||
417 | data[blockIndex + 3]]); | ||
418 | data[blockIndex + 0] = mixedValues[0]; | ||
419 | data[blockIndex + 1] = mixedValues[1]; | ||
420 | data[blockIndex + 2] = mixedValues[2]; | ||
421 | data[blockIndex + 3] = mixedValues[3]; | ||
422 | } | ||
423 | }, | ||
424 | */ | ||
425 | |||
426 | 'mixColumns': function() { | ||
427 | //a mixing operation which operates on the columns of the state, combining the four bytes in each column using a linear transformation. | ||
428 | var data; | ||
429 | var i, c; | ||
430 | var a_1; | ||
431 | var a_2; | ||
432 | |||
433 | a_1 = new Array(4); | ||
434 | a_2 = new Array(4); | ||
435 | |||
436 | data = this.data(); | ||
437 | c = 4; | ||
438 | for(i=0; i<c; i++) { | ||
439 | varblockIndex; | ||
440 | var ii, cc; | ||
441 | |||
442 | blockIndex = i * 4; | ||
443 | |||
444 | cc = 4; | ||
445 | for (ii=0; ii<cc; ii++) { | ||
446 | var value; | ||
447 | |||
448 | value = data[blockIndex + ii]; | ||
449 | a_1[ii] = value; | ||
450 | a_2[ii] = (value & 0x80) ? ((value << 1) ^ 0x011b) : (value << 1); | ||
451 | } | ||
452 | |||
453 | data[blockIndex + 0] = a_2[0] ^ a_1[1] ^ a_2[1] ^ a_1[2] ^ a_1[3]; | ||
454 | data[blockIndex + 1] = a_1[0] ^ a_2[1] ^ a_1[2] ^ a_2[2] ^ a_1[3]; | ||
455 | data[blockIndex + 2] = a_1[0] ^ a_1[1] ^ a_2[2] ^ a_1[3] ^ a_2[3]; | ||
456 | data[blockIndex + 3] = a_1[0] ^ a_2[0] ^ a_1[1] ^ a_1[2] ^ a_2[3]; | ||
457 | } | ||
458 | }, | ||
459 | |||
460 | //========================================================================= | ||
461 | |||
462 | 'spinRound': function(aRoundNumber) { | ||
463 | this.addRoundKey(aRoundNumber); | ||
464 | this.subBytes(); | ||
465 | this.shiftRows(); | ||
466 | this.mixColumns(); | ||
467 | }, | ||
468 | |||
469 | 'spinLastRound': function() { | ||
470 | this.addRoundKey(this.key().numberOfRounds() - 1); | ||
471 | this.subBytes(); | ||
472 | this.shiftRows(); | ||
473 | this.addRoundKey(this.key().numberOfRounds()); | ||
474 | }, | ||
475 | |||
476 | //========================================================================= | ||
477 | |||
478 | 'encrypt': function() { | ||
479 | vari,c; | ||
480 | |||
481 | c = this.key().numberOfRounds() - 1; | ||
482 | for (i=0; i<c; i++) { | ||
483 | this.spinRound(i); | ||
484 | } | ||
485 | |||
486 | this.spinLastRound(); | ||
487 | }, | ||
488 | |||
489 | //========================================================================= | ||
490 | __syntaxFix__: "syntax fix" | ||
491 | }); | ||
492 | |||
493 | //############################################################################# | ||
494 | |||
495 | Clipperz.Crypto.AES_2.VERSION = "0.1"; | ||
496 | Clipperz.Crypto.AES_2.NAME = "Clipperz.Crypto.AES_2"; | ||
497 | |||
498 | MochiKit.Base.update(Clipperz.Crypto.AES_2, { | ||
499 | |||
500 | //http://www.cs.eku.edu/faculty/styer/460/Encrypt/JS-AES.html | ||
501 | //http://en.wikipedia.org/wiki/Advanced_Encryption_Standard | ||
502 | //http://en.wikipedia.org/wiki/Rijndael_key_schedule | ||
503 | //http://en.wikipedia.org/wiki/Rijndael_S-box | ||
504 | |||
505 | '__repr__': function () { | ||
506 | return "[" + this.NAME + " " + this.VERSION + "]"; | ||
507 | }, | ||
508 | |||
509 | 'toString': function () { | ||
510 | return this.__repr__(); | ||
511 | }, | ||
512 | |||
513 | //============================================================================= | ||
514 | |||
515 | '_sbox': null, | ||
516 | 'sbox': function() { | ||
517 | if (Clipperz.Crypto.AES_2._sbox == null) { | ||
518 | Clipperz.Crypto.AES_2._sbox = [ | ||
519 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, | ||
520 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, | ||
521 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, | ||
522 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, | ||
523 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, | ||
524 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, | ||
525 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, | ||
526 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, | ||
527 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, | ||
528 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, | ||
529 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, | ||
530 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, | ||
531 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, | ||
532 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, | ||
533 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, | ||
534 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 | ||
535 | ]; | ||
536 | } | ||
537 | |||
538 | return Clipperz.Crypto.AES_2._sbox; | ||
539 | }, | ||
540 | |||
541 | //----------------------------------------------------------------------------- | ||
542 | // | ||
543 | // 0 4 8 12 0 4 812 | ||
544 | // 1 5 9 13 => 5 9 131 | ||
545 | // 2 6 10 14 10 14 26 | ||
546 | // 3 7 11 15 15 3 711 | ||
547 | // | ||
548 | '_shiftRowMapping': null, | ||
549 | 'shiftRowMapping': function() { | ||
550 | if (Clipperz.Crypto.AES_2._shiftRowMapping == null) { | ||
551 | Clipperz.Crypto.AES_2._shiftRowMapping = [0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11]; | ||
552 | } | ||
553 | |||
554 | return Clipperz.Crypto.AES_2._shiftRowMapping; | ||
555 | }, | ||
556 | |||
557 | //----------------------------------------------------------------------------- | ||
558 | |||
559 | '_mixColumnsMatrix': null, | ||
560 | 'mixColumnsMatrix': function() { | ||
561 | if (Clipperz.Crypto.AES_2._mixColumnsMatrix == null) { | ||
562 | Clipperz.Crypto.AES_2._mixColumnsMatrix = [[2, 3, 1 ,1], | ||
563 | [1, 2, 3, 1], | ||
564 | [1, 1, 2, 3], | ||
565 | [3, 1, 1, 2] ]; | ||
566 | } | ||
567 | |||
568 | return Clipperz.Crypto.AES_2._mixColumnsMatrix; | ||
569 | }, | ||
570 | |||
571 | '_roundConstants': null, | ||
572 | 'roundConstants': function() { | ||
573 | if (Clipperz.Crypto.AES_2._roundConstants == null) { | ||
574 | Clipperz.Crypto.AES_2._roundConstants = [ , 1, 2, 4, 8, 16, 32, 64, 128, 27, 54, 108, 216, 171, 77, 154]; | ||
575 | // Clipperz.Crypto.AES_2._roundConstants = [ , 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a]; | ||
576 | } | ||
577 | |||
578 | return Clipperz.Crypto.AES_2._roundConstants; | ||
579 | }, | ||
580 | |||
581 | //============================================================================= | ||
582 | |||
583 | 'incrementNonce': function(nonce) { | ||
584 | var i; | ||
585 | var done; | ||
586 | |||
587 | done = false; | ||
588 | i = nonce.length - 1; | ||
589 | |||
590 | while ((i>=0) && (done == false)) { | ||
591 | var currentByteValue; | ||
592 | |||
593 | currentByteValue = nonce[i]; | ||
594 | |||
595 | if (currentByteValue == 0xff) { | ||
596 | nonce[i] = 0; | ||
597 | if (i>= 0) { | ||
598 | i --; | ||
599 | } else { | ||
600 | done = true; | ||
601 | } | ||
602 | } else { | ||
603 | nonce[i] = currentByteValue + 1; | ||
604 | done = true; | ||
605 | } | ||
606 | } | ||
607 | }, | ||
608 | |||
609 | //----------------------------------------------------------------------------- | ||
610 | |||
611 | 'encryptBlock': function(aKey, aBlock) { | ||
612 | varresult; | ||
613 | varstate; | ||
614 | |||
615 | state = new Clipperz.Crypto.AES_2.State({block:aBlock, key:aKey}); | ||
616 | //is(state.data(), 'before'); | ||
617 | state.encrypt(); | ||
618 | result = state.data(); | ||
619 | |||
620 | return result; | ||
621 | }, | ||
622 | |||
623 | //----------------------------------------------------------------------------- | ||
624 | |||
625 | 'encryptBlocks': function(aKey, aMessage, aNonce) { | ||
626 | varresult; | ||
627 | var nonce; | ||
628 | var self; | ||
629 | varmessageIndex; | ||
630 | varmessageLength; | ||
631 | var blockSize; | ||
632 | |||
633 | self = Clipperz.Crypto.AES_2; | ||
634 | blockSize = 128/8; | ||
635 | messageLength = aMessage.length; | ||
636 | nonce = aNonce; | ||
637 | |||
638 | result = aMessage; | ||
639 | messageIndex = 0; | ||
640 | while (messageIndex < messageLength) { | ||
641 | var encryptedBlock; | ||
642 | var i,c; | ||
643 | |||
644 | encryptedBlock = self.encryptBlock(aKey, nonce); | ||
645 | |||
646 | if ((messageLength - messageIndex) > blockSize) { | ||
647 | c = blockSize; | ||
648 | } else { | ||
649 | c = messageLength - messageIndex; | ||
650 | } | ||
651 | |||
652 | for (i=0; i<c; i++) { | ||
653 | result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; | ||
654 | } | ||
655 | |||
656 | messageIndex += blockSize; | ||
657 | // nonce = self.incrementNonce(nonce); | ||
658 | self.incrementNonce(nonce) | ||
659 | } | ||
660 | |||
661 | return result; | ||
662 | }, | ||
663 | |||
664 | //----------------------------------------------------------------------------- | ||
665 | |||
666 | 'encrypt': function(aKey, someData, aNonce) { | ||
667 | var result; | ||
668 | var nonce; | ||
669 | varencryptedData; | ||
670 | var key; | ||
671 | |||
672 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
673 | nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); | ||
674 | |||
675 | encryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, someData.arrayValues(), nonce.arrayValues()); | ||
676 | |||
677 | result = nonce.appendBytes(encryptedData); | ||
678 | |||
679 | return result; | ||
680 | }, | ||
681 | |||
682 | //----------------------------------------------------------------------------- | ||
683 | |||
684 | 'decrypt': function(aKey, someData) { | ||
685 | var result; | ||
686 | var nonce; | ||
687 | var encryptedData; | ||
688 | var decryptedData; | ||
689 | vardataIterator; | ||
690 | var key; | ||
691 | |||
692 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
693 | |||
694 | encryptedData = someData.arrayValues(); | ||
695 | nonce = encryptedData.slice(0, (128/8)); | ||
696 | encryptedData = encryptedData.slice(128/8); | ||
697 | decryptedData = Clipperz.Crypto.AES_2.encryptBlocks(key, encryptedData, nonce); | ||
698 | |||
699 | result = new Clipperz.ByteArray(decryptedData); | ||
700 | |||
701 | return result; | ||
702 | }, | ||
703 | |||
704 | //============================================================================= | ||
705 | |||
706 | 'deferredEncryptExecutionChunk': function(anExecutionContext) { | ||
707 | varresult; | ||
708 | var nonce; | ||
709 | var self; | ||
710 | varmessageIndex; | ||
711 | varmessageLength; | ||
712 | var blockSize; | ||
713 | var executionLimit; | ||
714 | var startTime, endTime; | ||
715 | |||
716 | self = Clipperz.Crypto.AES_2; | ||
717 | startTime = new Date(); | ||
718 | blockSize = 128/8; | ||
719 | messageLength = anExecutionContext.messageArray().length; | ||
720 | nonce = anExecutionContext.nonceArray(); | ||
721 | result = anExecutionContext.resultArray(); | ||
722 | |||
723 | messageIndex = anExecutionContext.executionStep(); | ||
724 | executionLimit = messageIndex + anExecutionContext.elaborationChunkSize(); | ||
725 | executionLimit = Math.min(executionLimit, messageLength); | ||
726 | |||
727 | while (messageIndex < executionLimit) { | ||
728 | var encryptedBlock; | ||
729 | var i,c; | ||
730 | |||
731 | //console.log("+++ nonce: [" + nonce + "]") | ||
732 | encryptedBlock = self.encryptBlock(anExecutionContext.key(), nonce); | ||
733 | |||
734 | if ((executionLimit - messageIndex) > blockSize) { | ||
735 | c = blockSize; | ||
736 | } else { | ||
737 | c = executionLimit - messageIndex; | ||
738 | } | ||
739 | |||
740 | for (i=0; i<c; i++) { | ||
741 | result[messageIndex + i] = result[messageIndex + i] ^ encryptedBlock[i]; | ||
742 | } | ||
743 | |||
744 | messageIndex += blockSize; | ||
745 | // nonce = self.incrementNonce(nonce); | ||
746 | self.incrementNonce(nonce); | ||
747 | } | ||
748 | anExecutionContext.setExecutionStep(messageIndex); | ||
749 | endTime = new Date(); | ||
750 | anExecutionContext.tuneExecutionParameters(endTime - startTime); | ||
751 | |||
752 | return anExecutionContext; | ||
753 | }, | ||
754 | |||
755 | //----------------------------------------------------------------------------- | ||
756 | |||
757 | 'deferredEncryptBlocks': function(anExecutionContext) { | ||
758 | vardeferredResult; | ||
759 | |||
760 | //console.log("executionContext", anExecutionContext) | ||
761 | //console.log(" --- nonce: " + anExecutionContext.nonceArray()) | ||
762 | if (! anExecutionContext.isDone()) { | ||
763 | deferredResult = Clipperz.Async.callbacks("Clipperz.Crypto.AES_2.deferredEncryptBloks", [ | ||
764 | Clipperz.Crypto.AES_2.deferredEncryptExecutionChunk, | ||
765 | MochiKit.Base.method(anExecutionContext, 'pause'), | ||
766 | Clipperz.Crypto.AES_2.deferredEncryptBlocks | ||
767 | ], {trace:false}, anExecutionContext); | ||
768 | } else { | ||
769 | deferredResult = MochiKit.Async.succeed(anExecutionContext); | ||
770 | } | ||
771 | |||
772 | return deferredResult; | ||
773 | }, | ||
774 | |||
775 | //----------------------------------------------------------------------------- | ||
776 | |||
777 | 'deferredEncrypt': function(aKey, someData, aNonce) { | ||
778 | var deferredResult; | ||
779 | varexecutionContext; | ||
780 | var result; | ||
781 | var nonce; | ||
782 | var key; | ||
783 | |||
784 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
785 | nonce = aNonce ? aNonce.clone() : Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(128/8); | ||
786 | |||
787 | executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:someData, nonce:nonce}); | ||
788 | |||
789 | deferredResult = new Clipperz.Async.Deferred("AES.deferredEncrypt"); | ||
790 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); | ||
791 | deferredResult.addCallback(function(anExecutionContext) { | ||
792 | var result; | ||
793 | |||
794 | result = anExecutionContext.nonce().clone(); | ||
795 | result.appendBytes(anExecutionContext.resultArray()); | ||
796 | |||
797 | return result; | ||
798 | }); | ||
799 | deferredResult.callback(executionContext) | ||
800 | |||
801 | return deferredResult; | ||
802 | }, | ||
803 | |||
804 | //----------------------------------------------------------------------------- | ||
805 | |||
806 | 'deferredDecrypt': function(aKey, someData) { | ||
807 | var deferredResult | ||
808 | var nonce; | ||
809 | var message; | ||
810 | var key; | ||
811 | |||
812 | key = new Clipperz.Crypto.AES_2.Key({key:aKey}); | ||
813 | nonce = someData.split(0, (128/8)); | ||
814 | //console.log("nonce: [" + nonce.arrayValues() + "]") | ||
815 | message = someData.split(128/8); | ||
816 | //console.log("message: [" + message.arrayValues() + "]") | ||
817 | executionContext = new Clipperz.Crypto.AES_2.DeferredExecutionContext({key:key, message:message, nonce:nonce}); | ||
818 | |||
819 | deferredResult = new Clipperz.Async.Deferred("AES.deferredDecrypt"); | ||
820 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncryptBlocks); | ||
821 | deferredResult.addCallback(function(anExecutionContext) { | ||
822 | return anExecutionContext.result(); | ||
823 | }); | ||
824 | deferredResult.callback(executionContext); | ||
825 | |||
826 | return deferredResult; | ||
827 | }, | ||
828 | |||
829 | //----------------------------------------------------------------------------- | ||
830 | __syntaxFix__: "syntax fix" | ||
831 | |||
832 | }); | ||
833 | |||
834 | //############################################################################# | ||
835 | |||
836 | //Clipperz.Crypto.AES_2.DeferredExecution = { | ||
837 | // 'chunkSize': 16384, // 4096, // 1024 4096 8192 1638432768; | ||
838 | // 'pauseTime': 0.02 //0.2 | ||
839 | //} | ||
840 | |||
841 | Clipperz.Crypto.AES_2.exception = { | ||
842 | 'UnsupportedKeySize': new MochiKit.Base.NamedError("Clipperz.Crypto.AES_2.exception.UnsupportedKeySize") | ||
843 | }; | ||
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 | |||
@@ -61,5 +61,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
61 | 61 | ||
62 | 'encryptingFunctions': { | 62 | 'encryptingFunctions': { |
63 | 'currentVersion': '0.3', | 63 | 'currentVersion': '0.4', |
64 | 'versions': { | 64 | 'versions': { |
65 | 65 | ||
@@ -321,4 +321,5 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
321 | deferredResult.addCallback(Clipperz.Base.evalJSON); | 321 | deferredResult.addCallback(Clipperz.Base.evalJSON); |
322 | deferredResult.addErrback(function(anError) { | 322 | deferredResult.addErrback(function(anError) { |
323 | console.log("PIPPO_1", anError) | ||
323 | Clipperz.logError("Error while decrypting data [4]"); | 324 | Clipperz.logError("Error while decrypting data [4]"); |
324 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 325 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
@@ -345,9 +346,8 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
345 | return result; | 346 | return result; |
346 | } | 347 | } |
347 | |||
348 | }, | 348 | }, |
349 | 349 | ||
350 | //##################################################################### | 350 | //##################################################################### |
351 | /* | 351 | |
352 | '0.4': { | 352 | '0.4': { |
353 | 'encrypt': function(aKey, aValue, aNonce) { | 353 | 'encrypt': function(aKey, aValue, aNonce) { |
@@ -358,28 +358,33 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
358 | var encryptedData; | 358 | var encryptedData; |
359 | 359 | ||
360 | //Clipperz.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | ||
361 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 360 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
362 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); | ||
363 | value = Clipperz.Base.serializeJSON(aValue); | 361 | value = Clipperz.Base.serializeJSON(aValue); |
364 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); | ||
365 | / * | ||
366 | //Clipperz.logDebug("--> encrypt.fullSize: " + value.length); | ||
367 | value = value.replace(/":{"label":"/g, '":{l:"'); | ||
368 | value = value.replace(/":{"key":"/g, '":{k:"'); | ||
369 | value = value.replace(/":{"notes":"/g, '":{n:"'); | ||
370 | value = value.replace(/":{"record":"/g, '":{r:"'); | ||
371 | value = value.replace(/", "label":"/g, '",l:"'); | ||
372 | value = value.replace(/", "favicon":"/g,'",f:"'); | ||
373 | //Clipperz.logDebug("<-- encrypt.compressed: " + value.length); | ||
374 | * / | ||
375 | data = new Clipperz.ByteArray(value); | 362 | data = new Clipperz.ByteArray(value); |
376 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); | 363 | encryptedData = Clipperz.Crypto.AES_2.encrypt(key, data, aNonce); |
377 | encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); | ||
378 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); | ||
379 | result = encryptedData.toBase64String(); | 364 | result = encryptedData.toBase64String(); |
380 | //Clipperz.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | ||
381 | 365 | ||
382 | return result; | 366 | return result; |
383 | }, | 367 | }, |
368 | |||
369 | 'deferredEncrypt': function(aKey, aValue, aNonce) { | ||
370 | var deferredResult; | ||
371 | varkey, value; | ||
372 | var data; | ||
373 | var dataToEncrypt; | ||
374 | var encryptedData; | ||
375 | |||
376 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | ||
377 | value = Clipperz.Base.serializeJSON(aValue); | ||
378 | data = new Clipperz.ByteArray(value); | ||
379 | |||
380 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredEncrypt") | ||
381 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredEncrypt, key, data, aNonce); | ||
382 | deferredResult.addCallback(function(aResult) { | ||
383 | return aResult.toBase64String(); | ||
384 | }) | ||
385 | deferredResult.callback(); | ||
386 | |||
387 | return deferredResult; | ||
388 | }, | ||
384 | 389 | ||
385 | 'decrypt': function(aKey, aValue) { | 390 | 'decrypt': function(aKey, aValue) { |
@@ -393,23 +398,14 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
393 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 398 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
394 | 399 | ||
395 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 400 | decryptedData = Clipperz.Crypto.AES_2.decrypt(key, value); |
396 | 401 | ||
397 | value = decryptedData.asString(); | 402 | value = decryptedData.asString(); |
398 | / * | ||
399 | value = value.replace(/":{l:"/g,'":{"label":"'); | ||
400 | value = value.replace(/":{k:"/g,'":{"key":"'); | ||
401 | value = value.replace(/":{n:"/g,'":{"notes":"'); | ||
402 | value = value.replace(/":{r:"/g,'":{"record":"'); | ||
403 | value = value.replace(/",l:"/g, '", "label":"'); | ||
404 | value = value.replace(/",f:"/g, '", "favicon":"'); | ||
405 | * / | ||
406 | try { | 403 | try { |
407 | result = Clipperz.Base.evalJSON(value); | 404 | result = Clipperz.Base.evalJSON(value); |
408 | } catch (exception) { | 405 | } catch (exception) { |
409 | Clipperz.logError("Error while decrypting data"); | 406 | console.log("PIPPO_2", anError) |
407 | Clipperz.logError("Error while decrypting data [4]"); | ||
410 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 408 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
411 | } | 409 | } |
412 | |||
413 | |||
414 | } else { | 410 | } else { |
415 | result = null; | 411 | result = null; |
@@ -419,7 +415,49 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
419 | }, | 415 | }, |
420 | 416 | ||
421 | 'hash': Clipperz.Crypto.SHA.sha_d256 | 417 | 'deferredDecrypt': function(aKey, aValue) { |
418 | var deferredResult; | ||
419 | |||
420 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.4].deferredDecrypt", {trace: false}); | ||
421 | |||
422 | if (aValue != null) { | ||
423 | var key, value; | ||
424 | |||
425 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | ||
426 | value = new Clipperz.ByteArray().appendBase64String(aValue); | ||
427 | |||
428 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); | ||
429 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | ||
430 | deferredResult.addCallback(function(aResult) { | ||
431 | return aResult.asString(); | ||
432 | }); | ||
433 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | ||
434 | deferredResult.addCallback(Clipperz.Base.evalJSON); | ||
435 | deferredResult.addErrback(function(anError) { | ||
436 | Clipperz.logError("Error while decrypting data [4]"); | ||
437 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | ||
438 | }) | ||
439 | } else { | ||
440 | deferredResult.addCallback(function() { | ||
441 | return null; | ||
442 | }); | ||
443 | } | ||
444 | deferredResult.callback(); | ||
445 | |||
446 | return deferredResult; | ||
447 | }, | ||
448 | |||
449 | 'hash': Clipperz.Crypto.SHA.sha_d256, | ||
450 | |||
451 | 'deriveKey': function(aStringValue) { | ||
452 | varbyteData; | ||
453 | var result; | ||
454 | |||
455 | byteData = new Clipperz.ByteArray(aStringValue); | ||
456 | result = Clipperz.Crypto.SHA.sha_d256(byteData); | ||
457 | |||
458 | return result; | ||
459 | } | ||
422 | }, | 460 | }, |
423 | */ | 461 | |
424 | //##################################################################### | 462 | //##################################################################### |
425 | __syntaxFix__: "syntax fix" | 463 | __syntaxFix__: "syntax fix" |
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 | |||
@@ -727,6 +727,6 @@ Clipperz.Base.extend(Clipperz.PM.DataModel.User, Object, { | |||
727 | header['records'] = someHeaderPackedData['recordIndex']['records']; | 727 | header['records'] = someHeaderPackedData['recordIndex']['records']; |
728 | header['directLogins'] = someHeaderPackedData['recordIndex']['directLogins']; | 728 | header['directLogins'] = someHeaderPackedData['recordIndex']['directLogins']; |
729 | header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; // this._serverData['header']['preferences']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['preferences']; //??????????? | 729 | header['preferences'] = {'data': someHeaderPackedData['preferences']['data']}; |
730 | header['oneTimePasswords'] = {'data': someHeaderPackedData['oneTimePasswords']['data']}; // this._serverData['header']['oneTimePasswords']; // Clipperz.Base.evalJSON(this._serverData['header']['data'])['oneTimePasswords']; //??????????? | 730 | header['oneTimePasswords']= {'data': someHeaderPackedData['oneTimePasswords']['data']}; |
731 | header['version'] = '0.1'; | 731 | header['version'] = '0.1'; |
732 | 732 | ||
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 | |||
@@ -282,5 +282,5 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | |||
282 | 'v': someParameters['credentials']['v'], | 282 | 'v': someParameters['credentials']['v'], |
283 | 'version':someParameters['credentials']['version'], | 283 | 'version':someParameters['credentials']['version'], |
284 | 'lock': Clipperz.Crypto.Base.generateRandomSeed(), | 284 | // 'lock': Clipperz.Crypto.Base.generateRandomSeed(), |
285 | 'userDetails': someParameters['user']['header'], | 285 | 'userDetails': someParameters['user']['header'], |
286 | 'statistics': someParameters['user']['statistics'], | 286 | 'statistics': someParameters['user']['statistics'], |
@@ -570,5 +570,5 @@ Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.DataStore, Object, { | |||
570 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; | 570 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; |
571 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; | 571 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; |
572 | aConnection['userData']['userDetailsVersions']= someParameters['parameters']['user']['version']; | 572 | aConnection['userData']['userDetailsVersion']= someParameters['parameters']['user']['version']; |
573 | 573 | ||
574 | c = someParameters['parameters']['records']['updated'].length; | 574 | c = someParameters['parameters']['records']['updated'].length; |
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 | |||
@@ -144,4 +144,9 @@ Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.ser | |||
144 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); | 144 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); |
145 | }; | 145 | }; |
146 | //if (aFunctionName == 'knock') { | ||
147 | //console.log(">>> send message - " + aFunctionName, someParameters); | ||
148 | //} else { | ||
149 | //console.log(">>> SEND MESSAGE - " + aFunctionName + " [" + someParameters['parameters']['message'] + "]", someParameters['parameters']['parameters']); | ||
150 | //} | ||
146 | this.checkRequest(aFunctionName, someParameters); | 151 | this.checkRequest(aFunctionName, someParameters); |
147 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); | 152 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, 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 | |||
@@ -45,4 +45,5 @@ | |||
45 | "Clipperz/Crypto/SHA.js", | 45 | "Clipperz/Crypto/SHA.js", |
46 | "Clipperz/Crypto/AES.js", | 46 | "Clipperz/Crypto/AES.js", |
47 | "Clipperz/Crypto/AES_2.js", | ||
47 | "Clipperz/Crypto/PRNG.js", | 48 | "Clipperz/Crypto/PRNG.js", |
48 | "Clipperz/Crypto/BigInt.js", | 49 | "Clipperz/Crypto/BigInt.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 | |||
@@ -10,5 +10,5 @@ | |||
10 | "MochiKit/Base.js", | 10 | "MochiKit/Base.js", |
11 | "MochiKit/Iter.js", | 11 | "MochiKit/Iter.js", |
12 | "MochiKit/Logging.js", | 12 | "-- MochiKit/Logging.js", |
13 | "MochiKit/DateTime.js", | 13 | "MochiKit/DateTime.js", |
14 | "MochiKit/Format.js", | 14 | "MochiKit/Format.js", |
@@ -16,5 +16,5 @@ | |||
16 | "MochiKit/DOM.js", | 16 | "MochiKit/DOM.js", |
17 | "MochiKit/Style.js", | 17 | "MochiKit/Style.js", |
18 | "MochiKit/LoggingPane.js", | 18 | "-- MochiKit/LoggingPane.js", |
19 | "-- MochiKit/Color.js", | 19 | "-- MochiKit/Color.js", |
20 | "MochiKit/Signal.js", | 20 | "MochiKit/Signal.js", |
@@ -23,5 +23,5 @@ | |||
23 | "-- MochiKit/Visual.js", | 23 | "-- MochiKit/Visual.js", |
24 | 24 | ||
25 | "JSON/json2.js", | 25 | "-- JSON/json2.js", |
26 | 26 | ||
27 | "Clipperz/YUI/Utils.js", | 27 | "Clipperz/YUI/Utils.js", |
@@ -44,4 +44,5 @@ | |||
44 | "Clipperz/Crypto/SHA.js", | 44 | "Clipperz/Crypto/SHA.js", |
45 | "Clipperz/Crypto/AES.js", | 45 | "Clipperz/Crypto/AES.js", |
46 | "Clipperz/Crypto/AES_2.js", | ||
46 | "Clipperz/Crypto/PRNG.js", | 47 | "Clipperz/Crypto/PRNG.js", |
47 | "Clipperz/Crypto/BigInt.js", | 48 | "Clipperz/Crypto/BigInt.js", |
@@ -96,4 +97,8 @@ | |||
96 | "Clipperz/PM/DataModel/OneTimePassword.js", | 97 | "Clipperz/PM/DataModel/OneTimePassword.js", |
97 | 98 | ||
99 | "JQuery/1.9.1/jquery.js", | ||
100 | "Clipperz/PM/UI/Mobile/CustomizeJQueryMobile.js", | ||
101 | "JQuery/Mobile/1.3.0-rc.1/jquery.mobile.js", | ||
102 | |||
98 | "-- Zepto/zepto.js", | 103 | "-- Zepto/zepto.js", |
99 | "-- Zepto/ajax.js", | 104 | "-- Zepto/ajax.js", |
@@ -127,9 +132,9 @@ | |||
127 | "-- Bootstrap/bootstrap-typeahead.js", | 132 | "-- Bootstrap/bootstrap-typeahead.js", |
128 | 133 | ||
129 | "Clipperz/PM/UI/Common/Components/BaseComponent.js", | 134 | "-- Clipperz/PM/UI/Common/Components/BaseComponent.js", |
130 | "-- Clipperz/PM/UI/Common/Components/Button.js", | 135 | "-- Clipperz/PM/UI/Common/Components/Button.js", |
131 | "Clipperz/PM/UI/Common/Components/ComponentSlot.js", | 136 | "-- Clipperz/PM/UI/Common/Components/ComponentSlot.js", |
132 | "-- Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js", | 137 | "-- Clipperz/PM/UI/Common/Components/PasswordEntropyDisplay.js", |
133 | "Clipperz/PM/UI/Common/Components/ProgressBar.js", | 138 | "-- Clipperz/PM/UI/Common/Components/ProgressBar.js", |
134 | "-- Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js", | 139 | "-- Clipperz/PM/UI/Common/Components/SimpleMessagePanel.js", |
135 | "-- Clipperz/PM/UI/Common/Components/MessagePanelWithProgressBar.js", | 140 | "-- Clipperz/PM/UI/Common/Components/MessagePanelWithProgressBar.js", |
@@ -138,10 +143,13 @@ | |||
138 | "-- Clipperz/PM/UI/Common/Components/TranslatorWidget.js", | 143 | "-- Clipperz/PM/UI/Common/Components/TranslatorWidget.js", |
139 | 144 | ||
140 | "Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js", | 145 | "-- Clipperz/PM/UI/Common/Controllers/DirectLoginRunner.js", |
141 | "Clipperz/PM/UI/Common/Controllers/ProgressBarController.js", | 146 | "-- Clipperz/PM/UI/Common/Controllers/ProgressBarController.js", |
142 | "-- Clipperz/PM/UI/Common/Controllers/TabPanelController.js", | 147 | "-- Clipperz/PM/UI/Common/Controllers/TabPanelController.js", |
143 | 148 | ||
149 | "Clipperz/PM/UI/Mobile/Components/BaseComponent.js", | ||
150 | "Clipperz/PM/UI/Mobile/Components/Overlay.js", | ||
144 | "Clipperz/PM/UI/Mobile/Components/LoginForm.js", | 151 | "Clipperz/PM/UI/Mobile/Components/LoginForm.js", |
145 | "Clipperz/PM/UI/Mobile/Components/CardList.js", | 152 | "Clipperz/PM/UI/Mobile/Components/CardList.js", |
153 | "Clipperz/PM/UI/Mobile/Components/Preferences.js", | ||
146 | "-- Clipperz/PM/UI/Mobile/Components/CardDetail.js", | 154 | "-- Clipperz/PM/UI/Mobile/Components/CardDetail.js", |
147 | 155 | ||
@@ -152,4 +160,5 @@ | |||
152 | 160 | ||
153 | "css": [ | 161 | "css": [ |
162 | "jquery.mobile-1.3.0-rc.1.css", | ||
154 | "mobile.css" | 163 | "mobile.css" |
155 | ] | 164 | ] |
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 @@ | |||
1 | <!-- | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | --> | ||
23 | |||
24 | <html> | ||
25 | <head> | ||
26 | <title>Clipperz.Crypto.AES_2 - tests</title> | ||
27 | |||
28 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
29 | |||
30 | <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> | ||
31 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> | ||
32 | <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> | ||
33 | |||
34 | <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> | ||
35 | |||
36 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> | ||
37 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> | ||
38 | <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> | ||
39 | <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> | ||
40 | <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script> | ||
41 | <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script> | ||
42 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script> | ||
43 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script> | ||
44 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> | ||
45 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES_2.js'></script> | ||
46 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> | ||
47 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script> | ||
48 | |||
49 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script> | ||
50 | |||
51 | </head> | ||
52 | <body> | ||
53 | <pre id="test"> | ||
54 | <script type="text/javascript" src="AES_2.test.js"></script> | ||
55 | </pre> | ||
56 | </body> | ||
57 | </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 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | function testEncryptedData (tool, keyValue, encryptedText, expectedCleanText, someTestArgs) { | ||
25 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(keyValue)); | ||
26 | value = new Clipperz.ByteArray().appendBase64String(encryptedText); | ||
27 | |||
28 | deferredResult = new Clipperz.Async.Deferred("pythonCompatibility_test", someTestArgs); | ||
29 | deferredResult.addCallback(Clipperz.Crypto.AES_2.deferredDecrypt, key, value); | ||
30 | deferredResult.addCallback(function(aResult) { | ||
31 | return aResult.asString(); | ||
32 | }); | ||
33 | deferredResult.addTest(expectedCleanText, tool); | ||
34 | deferredResult.callback(); | ||
35 | |||
36 | return deferredResult; | ||
37 | } | ||
38 | |||
39 | //============================================================================= | ||
40 | |||
41 | var tests = { | ||
42 | |||
43 | 'incrementNonce_test': function (someTestArgs) { | ||
44 | var nonce; | ||
45 | |||
46 | nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] | ||
47 | Clipperz.Crypto.AES_2.incrementNonce(nonce) | ||
48 | SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1], "increment 0 based nonce"); | ||
49 | |||
50 | nonce = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | ||
51 | Clipperz.Crypto.AES_2.incrementNonce(nonce) | ||
52 | SimpleTest.eq(nonce, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2], "increment '1' nonce"); | ||
53 | |||
54 | nonce = [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,89] | ||
55 | Clipperz.Crypto.AES_2.incrementNonce(nonce) | ||
56 | SimpleTest.eq(nonce, [58,231,19,199,48,86,154,169,188,141,46,196,83,34,37,90], "increment '1' nonce"); | ||
57 | return | ||
58 | }, | ||
59 | |||
60 | 'pythonCompatibility_test': function (someTestArgs) { | ||
61 | var keyValue = "clipperz" | ||
62 | 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Þ." | ||
63 | |||
64 | // def testEncrypt (keyValue, cleanText): | ||
65 | // key = keyDerivation(keyValue) | ||
66 | // iv = random.getrandbits(128) | ||
67 | // ctr = Crypto.Util.Counter.new(128, initial_value=iv) | ||
68 | // cipher = AES.new(key, Crypto.Cipher.AES.MODE_CTR, counter=ctr) | ||
69 | // encryptedValue = cipher.encrypt(cleanText.encode('utf-8')) | ||
70 | // data = base64.b64encode(base64.b16decode(hex(iv).upper()[2:-1]) + encryptedValue) | ||
71 | // | ||
72 | // return data | ||
73 | |||
74 | var pythonEncryptedData = "9AFIXRO2nY0mkLJI6Xd4bd+Ov1g+kYUh73nICEVUM8OGt5FnfV/w2BfmTvdMGZjs+rF8w0ksrS9Ny8j2+2zPUUrKnVRXO6eGVPSN5VfuYFSHucV98msINH0FpOZHftuKCuJkB/orjQhoIbj9SXT0yUwB3b4R2bk48Br7R8G2bhxqrHRmnYQn22AQVA83UstNvCOdXT7ArfwJZbVSSMkdmvcziZ8ObMvaH+FXD/K8i7dzS1yP03MMBtIkYN8PnyUMS2uAHKiR11jGuha9QfXjLJlWUQWZgNB9NKyOKf7tN+OgtAoWmHmKlpTshfwbfFD8wBPR0kkhR0cC+7queIjpCDnBJ+Nod78zWgPDR8g64sph7OB686HkP03cO66aH/LNuAt03gxaVyE8ufvoStRjlIthOuys5xYWP+hTFYDC7OhCOLKvhZoY4Tr/FP+TjporX3ivCJUEEvwvXeftAxFVRl4JDin0ys0iPTQ7QlbtVa+iep2n9FUG1NOn5boD9y+iw64UJAcex4MqEIdpCHne9LjpiqshcwLmfEeLlFab28LHnvYPGkXDrSRjCujx8ZmmTw96sAIDqER8p1AqaSojwvONYBGrq+f5/f4xjzZJAknMmxYEN14Phbxc8WEhpe5omWdB80C1Kv6CLsoQnGAIshURSZryToXL" | ||
75 | return testEncryptedData("python", keyValue, pythonEncryptedData, cleanText, someTestArgs) | ||
76 | }, | ||
77 | |||
78 | //------------------------------------------------------------------------- | ||
79 | 'syntaxFix': MochiKit.Base.noop | ||
80 | } | ||
81 | |||
82 | //============================================================================= | ||
83 | |||
84 | Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); | ||
85 | 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 | |||
@@ -33,4 +33,5 @@ refer to http://www.clipperz.com. | |||
33 | TestRunner.runTests( | 33 | TestRunner.runTests( |
34 | 'AES.html', | 34 | 'AES.html', |
35 | //'AES_2.html', | ||
35 | 'AES.performance.html', | 36 | 'AES.performance.html', |
36 | 'Base.html', | 37 | 'Base.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 @@ | |||
1 | <!-- | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | --> | ||
23 | |||
24 | <html> | ||
25 | <head> | ||
26 | <title>Clipperz.PM.Crypto [0.4] - tests</title> | ||
27 | |||
28 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> | ||
29 | |||
30 | <script type="text/javascript" src="../../../../js/MochiKit/MochiKit.js"></script> | ||
31 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.js"></script> | ||
32 | <link rel="stylesheet" type="text/css" href="../../../SimpleTest/test.css"> | ||
33 | |||
34 | <script type='text/javascript' src='../../../../js/JSON/json2.js'></script> | ||
35 | |||
36 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/Utils.js'></script> | ||
37 | <script type='text/javascript' src='../../../../js/Clipperz/YUI/DomHelper.js'></script> | ||
38 | <script type='text/javascript' src='../../../../js/Clipperz/Base.js'></script> | ||
39 | <script type='text/javascript' src='../../../../js/Clipperz/ByteArray.js'></script> | ||
40 | <script type='text/javascript' src='../../../../js/Clipperz/Async.js'></script> | ||
41 | <script type='text/javascript' src='../../../../js/Clipperz/Logging.js'></script> | ||
42 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/Base.js'></script> | ||
43 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/BigInt.js'></script> | ||
44 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES.js'></script> | ||
45 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/AES_2.js'></script> | ||
46 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/SHA.js'></script> | ||
47 | <script type='text/javascript' src='../../../../js/Clipperz/Crypto/PRNG.js'></script> | ||
48 | <script type='text/javascript' src='../../../../js/Clipperz/PM/Proxy.js'></script> | ||
49 | <script type='text/javascript' src='../../../../js/Clipperz/PM/Connection.js'></script> | ||
50 | <script type='text/javascript' src='../../../../js/Clipperz/PM/Crypto.js'></script> | ||
51 | |||
52 | <script type="text/javascript" src="../../../SimpleTest/SimpleTest.Async.js"></script> | ||
53 | |||
54 | </head> | ||
55 | <body> | ||
56 | <pre id="test"> | ||
57 | <script type="text/javascript" src="Crypto_v0_4.test.js"></script> | ||
58 | </pre> | ||
59 | </body> | ||
60 | </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 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2013 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz, the online password manager. | ||
6 | For further information about its features and functionalities please | ||
7 | refer to http://www.clipperz.com. | ||
8 | |||
9 | * Clipperz is free software: you can redistribute it and/or modify it | ||
10 | under the terms of the GNU Affero General Public License as published | ||
11 | by the Free Software Foundation, either version 3 of the License, or | ||
12 | (at your option) any later version. | ||
13 | |||
14 | * Clipperz is distributed in the hope that it will be useful, but | ||
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
17 | See the GNU Affero General Public License for more details. | ||
18 | |||
19 | * You should have received a copy of the GNU Affero General Public | ||
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | ||
21 | |||
22 | */ | ||
23 | |||
24 | var tests = { | ||
25 | |||
26 | 'decryptDataEncryptedUsingPythonLibrary_test': function (someTestArgs) { | ||
27 | var deferredResult; | ||
28 | |||
29 | passphrase = 'trustno1'; | ||
30 | encryptedData = 'OucTxzBWmqm8jS7EUyIlWUWDPSFKvulL5iM4WwLPbNVIH7jtaK9pmzpm9w5ioVy2/tyebVwWr36t7QXSBOPwUPo2SlGmARCozA=='; | ||
31 | |||
32 | deferredResult = new Clipperz.Async.Deferred("decryptDataEncryptedUsingPythonLibrary_test", someTestArgs); | ||
33 | deferredResult.addCallback(Clipperz.PM.Crypto.deferredDecrypt, {key:passphrase, value:encryptedData, version:'0.4'}); | ||
34 | deferredResult.addCallback(MochiKit.Base.itemgetter('message')); | ||
35 | deferredResult.addTest("The quick brown fox jumps over the lazy dog", "expected value"); | ||
36 | |||
37 | deferredResult.callback(); | ||
38 | |||
39 | return deferredResult; | ||
40 | |||
41 | }, | ||
42 | |||
43 | //------------------------------------------------------------------------- | ||
44 | 'syntaxFix': MochiKit.Base.noop | ||
45 | } | ||
46 | |||
47 | //============================================================================= | ||
48 | |||
49 | Clipperz.Crypto.PRNG.defaultRandomGenerator().fastEntropyAccumulationForTestingPurpose(); | ||
50 | 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 | |||
@@ -44,4 +44,5 @@ refer to http://www.clipperz.com. | |||
44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> | 44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> |
45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> | 45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> |
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> | ||
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> | 47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> |
47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> | 48 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.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 | |||
@@ -43,4 +43,5 @@ refer to http://www.clipperz.com. | |||
43 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> | 43 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> |
44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> | 44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> |
45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> | ||
45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> | 46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> |
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> | 47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.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 | |||
@@ -44,4 +44,5 @@ refer to http://www.clipperz.com. | |||
44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> | 44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> |
45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> | 45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> |
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> | ||
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> | 47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> |
47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> | 48 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.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 | |||
@@ -178,4 +178,11 @@ var tests = { | |||
178 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); | 178 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_data']); |
179 | deferredResult.addMethod(user, 'login'); | 179 | deferredResult.addMethod(user, 'login'); |
180 | |||
181 | deferredResult.addMethod(user, 'getRecord', recordID); | ||
182 | deferredResult.addMethodcaller('directLogins'); | ||
183 | deferredResult.addCallback(MochiKit.Base.keys); | ||
184 | deferredResult.addCallback(MochiKit.Base.itemgetter('length')); | ||
185 | deferredResult.addTest(4, "The record initially has 4 direct logins"); | ||
186 | |||
180 | deferredResult.addMethod(user, 'getRecord', recordID); | 187 | deferredResult.addMethod(user, 'getRecord', recordID); |
181 | deferredResult.addMethodcaller('directLogins'); | 188 | deferredResult.addMethodcaller('directLogins'); |
@@ -188,4 +195,5 @@ var tests = { | |||
188 | 195 | ||
189 | deferredResult.addMethod(user, 'saveChanges'); | 196 | deferredResult.addMethod(user, 'saveChanges'); |
197 | |||
190 | deferredResult.addMethod(user, 'hasPendingChanges'); | 198 | deferredResult.addMethod(user, 'hasPendingChanges'); |
191 | deferredResult.addTest(false, "after saving there should be not any pending changes"); | 199 | deferredResult.addTest(false, "after saving there should be not any pending changes"); |
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 | |||
@@ -44,4 +44,5 @@ refer to http://www.clipperz.com. | |||
44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> | 44 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/BigInt.js'></script> |
45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> | 45 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES.js'></script> |
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/AES_2.js'></script> | ||
46 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> | 47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/SHA.js'></script> |
47 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.js'></script> | 48 | <script type='text/javascript' src='../../../../../js/Clipperz/Crypto/PRNG.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 | |||
@@ -1923,5 +1923,5 @@ var tests = { | |||
1923 | proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); | 1923 | proxy = new Clipperz.PM.Proxy.Test({shouldPayTolls:true, isDefault:true, readOnly:false}); |
1924 | user2 = new Clipperz.PM.DataModel.User({username:username, getPassphraseFunction:function () { return passphrase;}}); | 1924 | user2 = new Clipperz.PM.DataModel.User({username:username, getPassphraseFunction:function () { return passphrase;}}); |
1925 | 1925 | console.log("PROXY", proxy); | |
1926 | deferredResult = new Clipperz.Async.Deferred("registerNewUserAndAddARecord_test", someTestArgs); | 1926 | deferredResult = new Clipperz.Async.Deferred("registerNewUserAndAddARecord_test", someTestArgs); |
1927 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); | 1927 | deferredResult.addMethod(proxy.dataStore(), 'setupWithEncryptedData', testData['joe_clipperz_offline_copy_with_preferences_and_OTPs_data']); |
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 | |||
@@ -38,4 +38,5 @@ TestRunner.runTests( | |||
38 | 'Connection.html', | 38 | 'Connection.html', |
39 | 'Crypto.html', | 39 | 'Crypto.html', |
40 | 'Crypto_v0_4.html', | ||
40 | //'Crypto_other_implementation_comparison.html', | 41 | //'Crypto_other_implementation_comparison.html', |
41 | 'Crypto_performanceEvaluation.html', | 42 | 'Crypto_performanceEvaluation.html', |