Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Crypto.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Crypto.js | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Crypto.js b/frontend/gamma/js/Clipperz/PM/Crypto.js index 31fe349..cd10e33 100644 --- a/frontend/gamma/js/Clipperz/PM/Crypto.js +++ b/frontend/gamma/js/Clipperz/PM/Crypto.js | |||
@@ -1,34 +1,32 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | 25 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } |
28 | if (typeof(Clipperz.PM.Crypto) == 'undefined') { Clipperz.PM.Crypto = {}; } | 26 | if (typeof(Clipperz.PM.Crypto) == 'undefined') { Clipperz.PM.Crypto = {}; } |
29 | 27 | ||
30 | Clipperz.PM.Crypto.VERSION = "0.2"; | 28 | Clipperz.PM.Crypto.VERSION = "0.2"; |
31 | Clipperz.PM.Crypto.NAME = "Clipperz.PM.Crypto"; | 29 | Clipperz.PM.Crypto.NAME = "Clipperz.PM.Crypto"; |
32 | 30 | ||
33 | Clipperz.PM.Crypto.encryptingFunctions = {}; | 31 | Clipperz.PM.Crypto.encryptingFunctions = {}; |
34 | 32 | ||
@@ -165,25 +163,25 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
165 | var decryptedData; | 163 | var decryptedData; |
166 | var decryptedValue; | 164 | var decryptedValue; |
167 | 165 | ||
168 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 166 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
169 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 167 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
170 | 168 | ||
171 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 169 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); |
172 | decryptedValue = decryptedData.split((256/8)); | 170 | decryptedValue = decryptedData.split((256/8)); |
173 | 171 | ||
174 | try { | 172 | try { |
175 | result = Clipperz.Base.evalJSON(decryptedValue.asString()); | 173 | result = Clipperz.Base.evalJSON(decryptedValue.asString()); |
176 | } catch (exception) { | 174 | } catch (exception) { |
177 | MochiKit.Logging.logError("Error while decrypting data [1]"); | 175 | Clipperz.logError("Error while decrypting data [1]"); |
178 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 176 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
179 | } | 177 | } |
180 | } else { | 178 | } else { |
181 | result = null; | 179 | result = null; |
182 | } | 180 | } |
183 | 181 | ||
184 | return result; | 182 | return result; |
185 | }, | 183 | }, |
186 | 184 | ||
187 | 'deferredDecrypt': function(aKey, aValue) { | 185 | 'deferredDecrypt': function(aKey, aValue) { |
188 | var result; | 186 | var result; |
189 | 187 | ||
@@ -197,25 +195,25 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
197 | 195 | ||
198 | deferredResult = new Clipperz.Async.Deferred("Crypto.[0.2].deferredDecrypt"); | 196 | deferredResult = new Clipperz.Async.Deferred("Crypto.[0.2].deferredDecrypt"); |
199 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); | 197 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); |
200 | deferredResult.addCallback(function(aResult) { | 198 | deferredResult.addCallback(function(aResult) { |
201 | var result; | 199 | var result; |
202 | var decryptedData; | 200 | var decryptedData; |
203 | 201 | ||
204 | decryptedData = aResult.split((256/8)); | 202 | decryptedData = aResult.split((256/8)); |
205 | 203 | ||
206 | try { | 204 | try { |
207 | result = Clipperz.Base.evalJSON(decryptedData.asString()); | 205 | result = Clipperz.Base.evalJSON(decryptedData.asString()); |
208 | } catch (exception) { | 206 | } catch (exception) { |
209 | MochiKit.Logging.logError("Error while decrypting data [2]"); | 207 | Clipperz.logError("Error while decrypting data [2]"); |
210 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 208 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
211 | } | 209 | } |
212 | 210 | ||
213 | return result; | 211 | return result; |
214 | }) | 212 | }) |
215 | deferredResult.callback(); | 213 | deferredResult.callback(); |
216 | 214 | ||
217 | result = deferredResult; | 215 | result = deferredResult; |
218 | } else { | 216 | } else { |
219 | result = MochiKit.Async.succeed(null); | 217 | result = MochiKit.Async.succeed(null); |
220 | } | 218 | } |
221 | 219 | ||
@@ -282,25 +280,25 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
282 | var key, value; | 280 | var key, value; |
283 | var decryptedData; | 281 | var decryptedData; |
284 | 282 | ||
285 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 283 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
286 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 284 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
287 | 285 | ||
288 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 286 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); |
289 | 287 | ||
290 | value = decryptedData.asString(); | 288 | value = decryptedData.asString(); |
291 | try { | 289 | try { |
292 | result = Clipperz.Base.evalJSON(value); | 290 | result = Clipperz.Base.evalJSON(value); |
293 | } catch (exception) { | 291 | } catch (exception) { |
294 | MochiKit.Logging.logError("Error while decrypting data [3]"); | 292 | Clipperz.logError("Error while decrypting data [3]"); |
295 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 293 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
296 | } | 294 | } |
297 | } else { | 295 | } else { |
298 | result = null; | 296 | result = null; |
299 | } | 297 | } |
300 | 298 | ||
301 | return result; | 299 | return result; |
302 | }, | 300 | }, |
303 | 301 | ||
304 | 'deferredDecrypt': function(aKey, aValue) { | 302 | 'deferredDecrypt': function(aKey, aValue) { |
305 | var deferredResult; | 303 | var deferredResult; |
306 | 304 | ||
@@ -313,25 +311,25 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
313 | 311 | ||
314 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 312 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
315 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 313 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
316 | 314 | ||
317 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); | 315 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); |
318 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | 316 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); |
319 | deferredResult.addCallback(function(aResult) { | 317 | deferredResult.addCallback(function(aResult) { |
320 | return aResult.asString(); | 318 | return aResult.asString(); |
321 | }); | 319 | }); |
322 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); | 320 | deferredResult.addCallback(MochiKit.Async.wait, 0.1); |
323 | deferredResult.addCallback(Clipperz.Base.evalJSON); | 321 | deferredResult.addCallback(Clipperz.Base.evalJSON); |
324 | deferredResult.addErrback(function(anError) { | 322 | deferredResult.addErrback(function(anError) { |
325 | MochiKit.Logging.logError("Error while decrypting data [4]"); | 323 | Clipperz.logError("Error while decrypting data [4]"); |
326 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 324 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
327 | }) | 325 | }) |
328 | } else { | 326 | } else { |
329 | deferredResult.addCallback(function() { | 327 | deferredResult.addCallback(function() { |
330 | return null; | 328 | return null; |
331 | }); | 329 | }); |
332 | } | 330 | } |
333 | deferredResult.callback(); | 331 | deferredResult.callback(); |
334 | 332 | ||
335 | return deferredResult; | 333 | return deferredResult; |
336 | }, | 334 | }, |
337 | 335 | ||
@@ -350,45 +348,45 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
350 | }, | 348 | }, |
351 | 349 | ||
352 | //##################################################################### | 350 | //##################################################################### |
353 | /* | 351 | /* |
354 | '0.4': { | 352 | '0.4': { |
355 | 'encrypt': function(aKey, aValue, aNonce) { | 353 | 'encrypt': function(aKey, aValue, aNonce) { |
356 | var result; | 354 | var result; |
357 | varkey, value; | 355 | varkey, value; |
358 | var data; | 356 | var data; |
359 | var dataToEncrypt; | 357 | var dataToEncrypt; |
360 | var encryptedData; | 358 | var encryptedData; |
361 | 359 | ||
362 | //MochiKit.Logging.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | 360 | //Clipperz.logDebug(">>> [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); |
363 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 361 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
364 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); | 362 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 1"); |
365 | value = Clipperz.Base.serializeJSON(aValue); | 363 | value = Clipperz.Base.serializeJSON(aValue); |
366 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); | 364 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 2"); |
367 | / * | 365 | / * |
368 | //MochiKit.Logging.logDebug("--> encrypt.fullSize: " + value.length); | 366 | //Clipperz.logDebug("--> encrypt.fullSize: " + value.length); |
369 | value = value.replace(/":{"label":"/g, '":{l:"'); | 367 | value = value.replace(/":{"label":"/g, '":{l:"'); |
370 | value = value.replace(/":{"key":"/g, '":{k:"'); | 368 | value = value.replace(/":{"key":"/g, '":{k:"'); |
371 | value = value.replace(/":{"notes":"/g, '":{n:"'); | 369 | value = value.replace(/":{"notes":"/g, '":{n:"'); |
372 | value = value.replace(/":{"record":"/g, '":{r:"'); | 370 | value = value.replace(/":{"record":"/g, '":{r:"'); |
373 | value = value.replace(/", "label":"/g, '",l:"'); | 371 | value = value.replace(/", "label":"/g, '",l:"'); |
374 | value = value.replace(/", "favicon":"/g,'",f:"'); | 372 | value = value.replace(/", "favicon":"/g,'",f:"'); |
375 | //MochiKit.Logging.logDebug("<-- encrypt.compressed: " + value.length); | 373 | //Clipperz.logDebug("<-- encrypt.compressed: " + value.length); |
376 | * / | 374 | * / |
377 | data = new Clipperz.ByteArray(value); | 375 | data = new Clipperz.ByteArray(value); |
378 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); | 376 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 3"); |
379 | encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); | 377 | encryptedData = Clipperz.Crypto.AES.encrypt(key, data, aNonce); |
380 | //MochiKit.Logging.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); | 378 | //Clipperz.logDebug("--- [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt - 4"); |
381 | result = encryptedData.toBase64String(); | 379 | result = encryptedData.toBase64String(); |
382 | //MochiKit.Logging.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); | 380 | //Clipperz.logDebug("<<< [" + (new Date()).valueOf() + "] Clipperz.PM.Crypto.versions[0.3].encrypt"); |
383 | 381 | ||
384 | return result; | 382 | return result; |
385 | }, | 383 | }, |
386 | 384 | ||
387 | 'decrypt': function(aKey, aValue) { | 385 | 'decrypt': function(aKey, aValue) { |
388 | var result; | 386 | var result; |
389 | 387 | ||
390 | if (aValue != null) { | 388 | if (aValue != null) { |
391 | var key, value; | 389 | var key, value; |
392 | var decryptedData; | 390 | var decryptedData; |
393 | 391 | ||
394 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 392 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
@@ -399,25 +397,25 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
399 | value = decryptedData.asString(); | 397 | value = decryptedData.asString(); |
400 | / * | 398 | / * |
401 | value = value.replace(/":{l:"/g,'":{"label":"'); | 399 | value = value.replace(/":{l:"/g,'":{"label":"'); |
402 | value = value.replace(/":{k:"/g,'":{"key":"'); | 400 | value = value.replace(/":{k:"/g,'":{"key":"'); |
403 | value = value.replace(/":{n:"/g,'":{"notes":"'); | 401 | value = value.replace(/":{n:"/g,'":{"notes":"'); |
404 | value = value.replace(/":{r:"/g,'":{"record":"'); | 402 | value = value.replace(/":{r:"/g,'":{"record":"'); |
405 | value = value.replace(/",l:"/g, '", "label":"'); | 403 | value = value.replace(/",l:"/g, '", "label":"'); |
406 | value = value.replace(/",f:"/g, '", "favicon":"'); | 404 | value = value.replace(/",f:"/g, '", "favicon":"'); |
407 | * / | 405 | * / |
408 | try { | 406 | try { |
409 | result = Clipperz.Base.evalJSON(value); | 407 | result = Clipperz.Base.evalJSON(value); |
410 | } catch (exception) { | 408 | } catch (exception) { |
411 | MochiKit.Logging.logError("Error while decrypting data"); | 409 | Clipperz.logError("Error while decrypting data"); |
412 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 410 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
413 | } | 411 | } |
414 | 412 | ||
415 | 413 | ||
416 | } else { | 414 | } else { |
417 | result = null; | 415 | result = null; |
418 | } | 416 | } |
419 | 417 | ||
420 | return result; | 418 | return result; |
421 | }, | 419 | }, |
422 | 420 | ||
423 | 'hash': Clipperz.Crypto.SHA.sha_d256 | 421 | 'hash': Clipperz.Crypto.SHA.sha_d256 |