Diffstat (limited to 'frontend/beta/js/Clipperz/PM') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Crypto.js | 91 |
1 files changed, 59 insertions, 32 deletions
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 | |||
@@ -57,9 +57,9 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
57 | 57 | ||
58 | //------------------------------------------------------------------------- | 58 | //------------------------------------------------------------------------- |
59 | 59 | ||
60 | 'encryptingFunctions': { | 60 | 'encryptingFunctions': { |
61 | 'currentVersion': '0.3', | 61 | 'currentVersion': '0.4', |
62 | 'versions': { | 62 | 'versions': { |
63 | 63 | ||
64 | //##################################################################### | 64 | //##################################################################### |
65 | 65 | ||
@@ -294,9 +294,9 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
294 | var deferredResult; | 294 | var deferredResult; |
295 | // var now; | 295 | // var now; |
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;}); |
301 | if (aValue != null) { | 301 | if (aValue != null) { |
302 | var key, value; | 302 | var key, value; |
@@ -339,41 +339,46 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
339 | 'hash': Clipperz.Crypto.SHA.sha_d256 | 339 | 'hash': Clipperz.Crypto.SHA.sha_d256 |
340 | }, | 340 | }, |
341 | 341 | ||
342 | //##################################################################### | 342 | //##################################################################### |
343 | /* | 343 | |
344 | '0.4': { | 344 | '0.4': { |
345 | 'encrypt': function(aKey, aValue, aNonce) { | 345 | 'encrypt': function(aKey, aValue, aNonce) { |
346 | var result; | 346 | var result; |
347 | varkey, value; | 347 | varkey, value; |
348 | var data; | 348 | var data; |
349 | var dataToEncrypt; | 349 | var dataToEncrypt; |
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) { |
378 | var result; | 383 | var result; |
379 | 384 | ||
@@ -384,37 +389,59 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
384 | 389 | ||
385 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 390 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
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); |
401 | } catch (exception) { | 398 | } catch (exception) { |
402 | MochiKit.Logging.logError("Error while decrypting data"); | 399 | MochiKit.Logging.logError("Error while decrypting data"); |
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; |
409 | } | 404 | } |
410 | 405 | ||
411 | return result; | 406 | return result; |
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" |
419 | } | 446 | } |
420 | }, | 447 | }, |