Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Crypto.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Crypto.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Crypto.js b/frontend/beta/js/Clipperz/PM/Crypto.js index 6e9608c..ad16ff0 100644 --- a/frontend/beta/js/Clipperz/PM/Crypto.js +++ b/frontend/beta/js/Clipperz/PM/Crypto.js | |||
@@ -1,214 +1,212 @@ | |||
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 | MochiKit.Base.update(Clipperz.PM.Crypto, { | 31 | MochiKit.Base.update(Clipperz.PM.Crypto, { |
34 | 32 | ||
35 | '__repr__': function () { | 33 | '__repr__': function () { |
36 | return "[" + this.NAME + " " + this.VERSION + "]"; | 34 | return "[" + this.NAME + " " + this.VERSION + "]"; |
37 | }, | 35 | }, |
38 | 36 | ||
39 | //------------------------------------------------------------------------- | 37 | //------------------------------------------------------------------------- |
40 | 38 | ||
41 | 'toString': function () { | 39 | 'toString': function () { |
42 | return this.__repr__(); | 40 | return this.__repr__(); |
43 | }, | 41 | }, |
44 | 42 | ||
45 | //------------------------------------------------------------------------- | 43 | //------------------------------------------------------------------------- |
46 | 44 | ||
47 | 'communicationProtocol': { | 45 | 'communicationProtocol': { |
48 | 'currentVersion': '0.2', | 46 | 'currentVersion': '0.2', |
49 | 'versions': { | 47 | 'versions': { |
50 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, | 48 | '0.1': Clipperz.PM.Connection.SRP['1.0'],//Clipperz.Crypto.SRP.versions['1.0'].Connection, |
51 | '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection, | 49 | '0.2': Clipperz.PM.Connection.SRP['1.1']//Clipperz.Crypto.SRP.versions['1.1'].Connection, |
52 | }, | 50 | }, |
53 | 'fallbackVersions': { | 51 | 'fallbackVersions': { |
54 | 'current':'0.1', | 52 | 'current':'0.1', |
55 | '0.2': '0.1', | 53 | '0.2': '0.1', |
56 | '0.1': null | 54 | '0.1': null |
57 | } | 55 | } |
58 | }, | 56 | }, |
59 | 57 | ||
60 | //------------------------------------------------------------------------- | 58 | //------------------------------------------------------------------------- |
61 | 59 | ||
62 | 'encryptingFunctions': { | 60 | 'encryptingFunctions': { |
63 | 'currentVersion': '0.3', | 61 | 'currentVersion': '0.3', |
64 | 'versions': { | 62 | 'versions': { |
65 | 63 | ||
66 | //##################################################################### | 64 | //##################################################################### |
67 | 65 | ||
68 | '0.1': { | 66 | '0.1': { |
69 | 'encrypt': function(aKey, aValue) { | 67 | 'encrypt': function(aKey, aValue) { |
70 | return Clipperz.Crypto.Base.encryptUsingSecretKey(aKey, Clipperz.Base.serializeJSON(aValue)); | 68 | return Clipperz.Crypto.Base.encryptUsingSecretKey(aKey, Clipperz.Base.serializeJSON(aValue)); |
71 | }, | 69 | }, |
72 | 70 | ||
73 | 'deferredEncrypt': function(aKey, aValue) { | 71 | 'deferredEncrypt': function(aKey, aValue) { |
74 | var deferredResult; | 72 | var deferredResult; |
75 | 73 | ||
76 | deferredResult = new MochiKit.Async.Deferred(); | 74 | deferredResult = new MochiKit.Async.Deferred(); |
77 | deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].encrypt, aKey, aValue); | 75 | deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].encrypt, aKey, aValue); |
78 | deferredResult.callback(); | 76 | deferredResult.callback(); |
79 | 77 | ||
80 | return deferredResult; | 78 | return deferredResult; |
81 | }, | 79 | }, |
82 | 80 | ||
83 | 'decrypt': function(aKey, aValue) { | 81 | 'decrypt': function(aKey, aValue) { |
84 | var result; | 82 | var result; |
85 | 83 | ||
86 | if (aValue != null) { | 84 | if (aValue != null) { |
87 | result = Clipperz.Base.evalJSON(Clipperz.Crypto.Base.decryptUsingSecretKey(aKey, aValue)); | 85 | result = Clipperz.Base.evalJSON(Clipperz.Crypto.Base.decryptUsingSecretKey(aKey, aValue)); |
88 | } else { | 86 | } else { |
89 | result = null; | 87 | result = null; |
90 | } | 88 | } |
91 | 89 | ||
92 | return result; | 90 | return result; |
93 | }, | 91 | }, |
94 | 92 | ||
95 | 'deferredDecrypt': function(aKey, aValue) { | 93 | 'deferredDecrypt': function(aKey, aValue) { |
96 | var deferredResult; | 94 | var deferredResult; |
97 | 95 | ||
98 | deferredResult = new MochiKit.Async.Deferred(); | 96 | deferredResult = new MochiKit.Async.Deferred(); |
99 | deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].decrypt, aKey, aValue); | 97 | deferredResult.addCallback(Clipperz.PM.Crypto.encryptingFunctions.versions['0.1'].decrypt, aKey, aValue); |
100 | deferredResult.callback(); | 98 | deferredResult.callback(); |
101 | 99 | ||
102 | return deferredResult; | 100 | return deferredResult; |
103 | }, | 101 | }, |
104 | 102 | ||
105 | 'hash': function(aValue) { | 103 | 'hash': function(aValue) { |
106 | var result; | 104 | var result; |
107 | var strngResult; | 105 | var strngResult; |
108 | 106 | ||
109 | stringResult = Clipperz.Crypto.Base.computeHashValue(aValue.asString()); //!!!!!!! | 107 | stringResult = Clipperz.Crypto.Base.computeHashValue(aValue.asString()); //!!!!!!! |
110 | result = new Clipperz.ByteArray("0x" + stringResult); | 108 | result = new Clipperz.ByteArray("0x" + stringResult); |
111 | 109 | ||
112 | return result; | 110 | return result; |
113 | } | 111 | } |
114 | }, | 112 | }, |
115 | 113 | ||
116 | //##################################################################### | 114 | //##################################################################### |
117 | 115 | ||
118 | '0.2': { | 116 | '0.2': { |
119 | 'encrypt': function(aKey, aValue, aNonce) { | 117 | 'encrypt': function(aKey, aValue, aNonce) { |
120 | var result; | 118 | var result; |
121 | varkey, value; | 119 | varkey, value; |
122 | var dataToEncrypt; | 120 | var dataToEncrypt; |
123 | var encryptedData; | 121 | var encryptedData; |
124 | 122 | ||
125 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 123 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
126 | value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); | 124 | value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); |
127 | dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); | 125 | dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); |
128 | encryptedData = Clipperz.Crypto.AES.encrypt(key, dataToEncrypt, aNonce); | 126 | encryptedData = Clipperz.Crypto.AES.encrypt(key, dataToEncrypt, aNonce); |
129 | result = encryptedData.toBase64String(); | 127 | result = encryptedData.toBase64String(); |
130 | 128 | ||
131 | return result; | 129 | return result; |
132 | }, | 130 | }, |
133 | 131 | ||
134 | 'deferredEncrypt': function(aKey, aValue, aNonce) { | 132 | 'deferredEncrypt': function(aKey, aValue, aNonce) { |
135 | var deferredResult; | 133 | var deferredResult; |
136 | varkey, value; | 134 | varkey, value; |
137 | var dataToEncrypt; | 135 | var dataToEncrypt; |
138 | var encryptedData; | 136 | var encryptedData; |
139 | 137 | ||
140 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 138 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
141 | value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); | 139 | value = new Clipperz.ByteArray(Clipperz.Base.serializeJSON(aValue)); |
142 | dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); | 140 | dataToEncrypt = Clipperz.Crypto.SHA.sha_d256(value).appendBlock(value); |
143 | 141 | ||
144 | deferredResult = new MochiKit.Async.Deferred() | 142 | deferredResult = new MochiKit.Async.Deferred() |
145 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, dataToEncrypt, aNonce); | 143 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredEncrypt, key, dataToEncrypt, aNonce); |
146 | deferredResult.addCallback(function(aResult) { | 144 | deferredResult.addCallback(function(aResult) { |
147 | return aResult.toBase64String(); | 145 | return aResult.toBase64String(); |
148 | }) | 146 | }) |
149 | deferredResult.callback(); | 147 | deferredResult.callback(); |
150 | 148 | ||
151 | return deferredResult; | 149 | return deferredResult; |
152 | }, | 150 | }, |
153 | 151 | ||
154 | 'decrypt': function(aKey, aValue) { | 152 | 'decrypt': function(aKey, aValue) { |
155 | var result; | 153 | var result; |
156 | 154 | ||
157 | if (aValue != null) { | 155 | if (aValue != null) { |
158 | var key, value; | 156 | var key, value; |
159 | var decryptedData; | 157 | var decryptedData; |
160 | var decryptedData; | 158 | var decryptedData; |
161 | 159 | ||
162 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 160 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
163 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 161 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
164 | 162 | ||
165 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); | 163 | decryptedData = Clipperz.Crypto.AES.decrypt(key, value); |
166 | decryptedData = decryptedData.split((256/8)); | 164 | decryptedData = decryptedData.split((256/8)); |
167 | 165 | ||
168 | try { | 166 | try { |
169 | result = Clipperz.Base.evalJSON(decryptedData.asString()); | 167 | result = Clipperz.Base.evalJSON(decryptedData.asString()); |
170 | } catch (exception) { | 168 | } catch (exception) { |
171 | MochiKit.Logging.logError("Error while decrypting data"); | 169 | MochiKit.Logging.logError("Error while decrypting data"); |
172 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 170 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
173 | } | 171 | } |
174 | } else { | 172 | } else { |
175 | result = null; | 173 | result = null; |
176 | } | 174 | } |
177 | 175 | ||
178 | return result; | 176 | return result; |
179 | }, | 177 | }, |
180 | 178 | ||
181 | 'deferredDecrypt': function(aKey, aValue) { | 179 | 'deferredDecrypt': function(aKey, aValue) { |
182 | var result; | 180 | var result; |
183 | 181 | ||
184 | if (aValue != null) { | 182 | if (aValue != null) { |
185 | var deferredResult; | 183 | var deferredResult; |
186 | var key, value; | 184 | var key, value; |
187 | var decryptedData; | 185 | var decryptedData; |
188 | 186 | ||
189 | result = new MochiKit.Async.Deferred(); | 187 | result = new MochiKit.Async.Deferred(); |
190 | 188 | ||
191 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); | 189 | key = Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aKey)); |
192 | value = new Clipperz.ByteArray().appendBase64String(aValue); | 190 | value = new Clipperz.ByteArray().appendBase64String(aValue); |
193 | 191 | ||
194 | 192 | ||
195 | deferredResult = new MochiKit.Async.Deferred() | 193 | deferredResult = new MochiKit.Async.Deferred() |
196 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); | 194 | deferredResult.addCallback(Clipperz.Crypto.AES.deferredDecrypt, key, value); |
197 | deferredResult.addCallback(function(aResult) { | 195 | deferredResult.addCallback(function(aResult) { |
198 | var result; | 196 | var result; |
199 | var decryptedData; | 197 | var decryptedData; |
200 | 198 | ||
201 | decryptedData = aResult.split((256/8)); | 199 | decryptedData = aResult.split((256/8)); |
202 | 200 | ||
203 | try { | 201 | try { |
204 | result = Clipperz.Base.evalJSON(decryptedData.asString()); | 202 | result = Clipperz.Base.evalJSON(decryptedData.asString()); |
205 | } catch (exception) { | 203 | } catch (exception) { |
206 | MochiKit.Logging.logError("Error while decrypting data"); | 204 | MochiKit.Logging.logError("Error while decrypting data"); |
207 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; | 205 | throw Clipperz.Crypto.Base.exception.CorruptedMessage; |
208 | } | 206 | } |
209 | 207 | ||
210 | return result; | 208 | return result; |
211 | }) | 209 | }) |
212 | deferredResult.callback(); | 210 | deferredResult.callback(); |
213 | 211 | ||
214 | result = deferredResult; | 212 | result = deferredResult; |