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,54 +1,52 @@ | |||
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 | ||
35 | MochiKit.Base.update(Clipperz.PM.Crypto, { | 33 | MochiKit.Base.update(Clipperz.PM.Crypto, { |
36 | 34 | ||
37 | '__repr__': function () { | 35 | '__repr__': function () { |
38 | return "[" + this.NAME + " " + this.VERSION + "]"; | 36 | return "[" + this.NAME + " " + this.VERSION + "]"; |
39 | }, | 37 | }, |
40 | 38 | ||
41 | //------------------------------------------------------------------------- | 39 | //------------------------------------------------------------------------- |
42 | 40 | ||
43 | 'toString': function () { | 41 | 'toString': function () { |
44 | return this.__repr__(); | 42 | return this.__repr__(); |
45 | }, | 43 | }, |
46 | 44 | ||
47 | //------------------------------------------------------------------------- | 45 | //------------------------------------------------------------------------- |
48 | /* | 46 | /* |
49 | 'communicationProtocol': { | 47 | 'communicationProtocol': { |
50 | 'currentVersion': '0.2', | 48 | 'currentVersion': '0.2', |
51 | 'versions': { | 49 | 'versions': { |
52 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, | 50 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, |
53 | '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection | 51 | '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection |
54 | }, | 52 | }, |
@@ -145,97 +143,97 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
145 | 143 | ||
146 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 144 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
147 | value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); | 145 | value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); |
148 | dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); | 146 | dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); |
149 | 147 | ||
150 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.2].deferredEncrypt") | 148 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.2].deferredEncrypt") |
151 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, dataToEncrypt, aNonce); | 149 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, dataToEncrypt, aNonce); |
152 | deferredResult.addCallback(function(aResult) { | 150 | deferredResult.addCallback(function(aResult) { |
153 | return aResult.toBase64String(); | 151 | return aResult.toBase64String(); |
154 | }) | 152 | }) |
155 | deferredResult.callback(); | 153 | deferredResult.callback(); |
156 | 154 | ||
157 | return deferredResult; | 155 | return deferredResult; |
158 | }, | 156 | }, |
159 | 157 | ||
160 | 'decrypt': function(aKey, aValue) { | 158 | 'decrypt': function(aKey, aValue) { |
161 | var result; | 159 | var result; |
162 | 160 | ||
163 | if (aValue != null) { | 161 | if (aValue != null) { |
164 | var key, value; | 162 | var key, value; |
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 | ||
190 | if (aValue != null) { | 188 | if (aValue != null) { |
191 | var deferredResult; | 189 | var deferredResult; |
192 | var key, value; | 190 | var key, value; |
193 | // var decryptedData; | 191 | // var decryptedData; |
194 | 192 | ||
195 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 193 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
196 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 194 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
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 | ||
222 | return result; | 220 | return result; |
223 | }, | 221 | }, |
224 | 222 | ||
225 | 'hash': Clipperz.Crypto.SHA.sha_d256, | 223 | 'hash': Clipperz.Crypto.SHA.sha_d256, |
226 | 224 | ||
227 | 'deriveKey': function(aStringValue) { | 225 | 'deriveKey': function(aStringValue) { |
228 | varbyteData; | 226 | varbyteData; |
229 | var result; | 227 | var result; |
230 | 228 | ||
231 | byteData = new Clipperz.ByteArray(aStringValue); | 229 | byteData = new Clipperz.ByteArray(aStringValue); |
232 | result = Clipperz.Crypto.SHA.sha_d256(byteData); | 230 | result = Clipperz.Crypto.SHA.sha_d256(byteData); |
233 | 231 | ||
234 | return result; | 232 | return result; |
235 | } | 233 | } |
236 | }, | 234 | }, |
237 | 235 | ||
238 | //##################################################################### | 236 | //##################################################################### |
239 | 237 | ||
240 | '0.3': { | 238 | '0.3': { |
241 | 'encrypt': function(aKey, aValue, aNonce) { | 239 | 'encrypt': function(aKey, aValue, aNonce) { |
@@ -262,182 +260,182 @@ MochiKit.Base.update(Clipperz.PM.Crypto, { | |||
262 | var encryptedData; | 260 | var encryptedData; |
263 | 261 | ||
264 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 262 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
265 | value = Clipperz.Base.serializeJSON(aValue); | 263 | value = Clipperz.Base.serializeJSON(aValue); |
266 | data = new Clipperz.ByteArray(value); | 264 | data = new Clipperz.ByteArray(value); |
267 | 265 | ||
268 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredEncrypt") | 266 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredEncrypt") |
269 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data, aNonce); | 267 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, data, aNonce); |
270 | deferredResult.addCallback(function(aResult) { | 268 | deferredResult.addCallback(function(aResult) { |
271 | return aResult.toBase64String(); | 269 | return aResult.toBase64String(); |
272 | }) | 270 | }) |
273 | deferredResult.callback(); | 271 | deferredResult.callback(); |
274 | 272 | ||
275 | return deferredResult; | 273 | return deferredResult; |
276 | }, | 274 | }, |
277 | 275 | ||
278 | 'decrypt': function(aKey, aValue) { | 276 | 'decrypt': function(aKey, aValue) { |
279 | var result; | 277 | var result; |
280 | 278 | ||
281 | if (aValue != null) { | 279 | if (aValue != null) { |
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 | ||
307 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredDecrypt", {trace: false}); | 305 | deferredResult = new Clipperz.Async.Deferred("Crypto[0.3].deferredDecrypt", {trace: false}); |
308 | // now = new Date; | 306 | // now = new Date; |
309 | 307 | ||
310 | if (aValue != null) { | 308 | if (aValue != null) { |
311 | var key, value; | 309 | var key, value; |
312 | // var decryptedData; | 310 | // var decryptedData; |
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 | ||
338 | 'hash': Clipperz.Crypto.SHA.sha_d256, | 336 | 'hash': Clipperz.Crypto.SHA.sha_d256, |
339 | 337 | ||
340 | 'deriveKey': function(aStringValue) { | 338 | 'deriveKey': function(aStringValue) { |
341 | varbyteData; | 339 | varbyteData; |
342 | var result; | 340 | var result; |
343 | 341 | ||
344 | byteData = new Clipperz.ByteArray(aStringValue); | 342 | byteData = new Clipperz.ByteArray(aStringValue); |
345 | result = Clipperz.Crypto.SHA.sha_d256(byteData); | 343 | result = Clipperz.Crypto.SHA.sha_d256(byteData); |
346 | 344 | ||
347 | return result; | 345 | return result; |
348 | } | 346 | } |
349 | 347 | ||
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)); |
395 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 393 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
396 | 394 | ||
397 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 395 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); |
398 | 396 | ||
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 |
424 | }, | 422 | }, |
425 | */ | 423 | */ |
426 | //##################################################################### | 424 | //##################################################################### |
427 | __syntaxFix__: "syntax fix" | 425 | __syntaxFix__: "syntax fix" |
428 | } | 426 | } |
429 | }, | 427 | }, |
430 | 428 | ||
431 | //------------------------------------------------------------------------- | 429 | //------------------------------------------------------------------------- |
432 | 430 | ||
433 | 'encrypt': function(aKey, aValue, aVersion) { | 431 | 'encrypt': function(aKey, aValue, aVersion) { |
434 | return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].encrypt(aKey, aValue); | 432 | return Clipperz.PM.Crypto.encryptingFunctions.versions[aVersion].encrypt(aKey, aValue); |
435 | }, | 433 | }, |
436 | 434 | ||
437 | 'deferredEncrypt': function(someParameters) { | 435 | 'deferredEncrypt': function(someParameters) { |
438 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredEncrypt(someParameters['key'], someParameters['value']); | 436 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters['version']].deferredEncrypt(someParameters['key'], someParameters['value']); |
439 | }, | 437 | }, |
440 | 438 | ||
441 | //......................................................................... | 439 | //......................................................................... |
442 | 440 | ||
443 | 'decrypt': function(aKey, aValue, aVersion) { | 441 | 'decrypt': function(aKey, aValue, aVersion) { |