author | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2014-06-02 11:39:16 (UTC) |
---|---|---|
committer | Giulio Cesare Solaroli <giulio.cesare@clipperz.com> | 2014-06-02 16:35:38 (UTC) |
commit | 0422224521f62da210d1ae6ee15ecdf09f47f1f8 (patch) (unidiff) | |
tree | df7c0394fbcd1f8bc588ca8aab3ee83f5dc9f0cf /frontend/delta | |
parent | 7fdb41fa2b1f621636882ad9059c1f3ecfb74083 (diff) | |
download | clipperz-0422224521f62da210d1ae6ee15ecdf09f47f1f8.zip clipperz-0422224521f62da210d1ae6ee15ecdf09f47f1f8.tar.gz clipperz-0422224521f62da210d1ae6ee15ecdf09f47f1f8.tar.bz2 |
Fixed authentication procedure for offline copy
-rw-r--r-- | frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.LocalStorageDataStore.js | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.LocalStorageDataStore.js b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.LocalStorageDataStore.js index 3f16f70..d03f873 100644 --- a/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.LocalStorageDataStore.js +++ b/frontend/delta/js/Clipperz/PM/Proxy/Proxy.Offline.LocalStorageDataStore.js | |||
@@ -1,422 +1,437 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2013 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz, the online password manager. | 5 | This file is part of Clipperz, the online password manager. |
6 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
7 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
8 | 8 | ||
9 | * Clipperz is free software: you can redistribute it and/or modify it | 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 | 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 | 11 | by the Free Software Foundation, either version 3 of the License, or |
12 | (at your option) any later version. | 12 | (at your option) any later version. |
13 | 13 | ||
14 | * Clipperz is distributed in the hope that it will be useful, but | 14 | * Clipperz is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
18 | 18 | ||
19 | * 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 |
20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
21 | 21 | ||
22 | */ | 22 | */ |
23 | 23 | ||
24 | try { if (typeof(Clipperz.PM.Proxy.Offline.DataStore) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.PM.Proxy.Offline.DataStore) == 'undefined') { throw ""; }} catch (e) { |
25 | throw "Clipperz.PM.Proxy.Offline.LocalStorageDataStore depends on Clipperz.PM.Proxy.Offline.DataStore!"; | 25 | throw "Clipperz.PM.Proxy.Offline.LocalStorageDataStore depends on Clipperz.PM.Proxy.Offline.DataStore!"; |
26 | } | 26 | } |
27 | 27 | ||
28 | //============================================================================= | 28 | //============================================================================= |
29 | 29 | ||
30 | Clipperz.PM.Proxy.Offline.LocalStorageDataStore = function(args) { | 30 | Clipperz.PM.Proxy.Offline.LocalStorageDataStore = function(args) { |
31 | args = args || {}; | 31 | args = args || {}; |
32 | 32 | ||
33 | //this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); | 33 | //this._data = args.data || (typeof(_clipperz_dump_data_) != 'undefined' ? _clipperz_dump_data_ : null); |
34 | this._data = JSON.parse(localStorage.getItem('clipperz_dump_data')); | 34 | this._data = JSON.parse(localStorage.getItem('clipperz_dump_data')); |
35 | 35 | ||
36 | this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); | 36 | this._isReadOnly = (typeof(args.readOnly) == 'undefined' ? true : args.readOnly); |
37 | this._shouldPayTolls = args.shouldPayTolls || false; | 37 | this._shouldPayTolls = args.shouldPayTolls || false; |
38 | 38 | ||
39 | this._tolls = {}; | 39 | this._tolls = {}; |
40 | this._currentStaticConnection = null; | 40 | this._currentStaticConnection = null; |
41 | 41 | ||
42 | //Clipperz.PM.Proxy.Offline.LocalStorageDataStore.superclass.constructor.apply(this, arguments); | 42 | //Clipperz.PM.Proxy.Offline.LocalStorageDataStore.superclass.constructor.apply(this, arguments); |
43 | 43 | ||
44 | return this; | 44 | return this; |
45 | } | 45 | } |
46 | 46 | ||
47 | Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.LocalStorageDataStore, Clipperz.PM.Proxy.Offline.DataStore, { | 47 | Clipperz.Base.extend(Clipperz.PM.Proxy.Offline.LocalStorageDataStore, Clipperz.PM.Proxy.Offline.DataStore, { |
48 | 48 | ||
49 | //========================================================================= | 49 | //========================================================================= |
50 | 50 | ||
51 | '_knock': function(aConnection, someParameters) { | 51 | '_knock': function(aConnection, someParameters) { |
52 | var result; | 52 | var result; |
53 | 53 | ||
54 | result = { | 54 | result = { |
55 | toll: this.getTollForRequestType(someParameters['requestType']) | 55 | toll: this.getTollForRequestType(someParameters['requestType']) |
56 | } | 56 | } |
57 | 57 | ||
58 | return result; | 58 | return result; |
59 | }, | 59 | }, |
60 | 60 | ||
61 | //------------------------------------------------------------------------- | 61 | //------------------------------------------------------------------------- |
62 | 62 | ||
63 | '_registration': function(aConnection, someParameters) { | 63 | '_registration': function(aConnection, someParameters) { |
64 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 64 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
65 | }, | 65 | }, |
66 | 66 | ||
67 | //------------------------------------------------------------------------- | 67 | //------------------------------------------------------------------------- |
68 | 68 | ||
69 | '_handshake': function(aConnection, someParameters) { | 69 | '_handshake': function(aConnection, someParameters) { |
70 | var result; | 70 | var result; |
71 | varnextTollRequestType; | 71 | varnextTollRequestType; |
72 | 72 | ||
73 | result = {}; | 73 | result = {}; |
74 | if (someParameters.message == "connect") { | 74 | if (someParameters.message == "connect") { |
75 | var userData; | 75 | var userData; |
76 | var randomBytes; | 76 | var randomBytes; |
77 | var v; | 77 | var v; |
78 | 78 | ||
79 | userData = this.data()['users'][someParameters.parameters.C]; | 79 | userData = this.data()['users'][someParameters.parameters.C]; |
80 | 80 | ||
81 | if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) { | 81 | if ((typeof(userData) != 'undefined') && (userData['version'] == someParameters.version)) { |
82 | aConnection['userData'] = userData; | 82 | aConnection['userData'] = userData; |
83 | aConnection['C'] = someParameters.parameters.C; | 83 | aConnection['C'] = someParameters.parameters.C; |
84 | } else { | 84 | } else { |
85 | aConnection['userData'] = this.data()['users']['catchAllUser']; | 85 | aConnection['userData'] = this.data()['users']['catchAllUser']; |
86 | } | 86 | } |
87 | 87 | ||
88 | randomBytes = Clipperz.Crypto.Base.generateRandomSeed(); | 88 | randomBytes = Clipperz.Crypto.Base.generateRandomSeed(); |
89 | aConnection['b'] = new Clipperz.Crypto.BigInt(randomBytes, 16); | 89 | aConnection['b'] = new Clipperz.Crypto.BigInt(randomBytes, 16); |
90 | v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16); | 90 | v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16); |
91 | aConnection['B'] = v.add(Clipperz.Crypto.SRP.g().powerModule(aConnection['b'], Clipperz.Crypto.SRP.n())); | 91 | aConnection['B'] = (Clipperz.Crypto.SRP.k().multiply(v)).add(Clipperz.Crypto.SRP.g().powerModule(aConnection['b'], Clipperz.Crypto.SRP.n())); |
92 | 92 | ||
93 | aConnection['A'] = someParameters.parameters.A; | 93 | aConnection['A'] = someParameters.parameters.A; |
94 | 94 | ||
95 | result['s'] = aConnection['userData']['s']; | 95 | result['s'] = aConnection['userData']['s']; |
96 | result['B'] = aConnection['B'].asString(16); | 96 | result['B'] = aConnection['B'].asString(16); |
97 | 97 | ||
98 | nextTollRequestType = 'CONNECT'; | 98 | nextTollRequestType = 'CONNECT'; |
99 | } else if (someParameters.message == "credentialCheck") { | 99 | } else if (someParameters.message == "credentialCheck") { |
100 | var v, u, S, A, K, M1; | 100 | var v, u, s, S, A, K, M1; |
101 | var stringHash = function (aValue) { | ||
102 | return Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(aValue)).toHexString().substring(2); | ||
103 | }; | ||
101 | 104 | ||
102 | v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16); | 105 | v = new Clipperz.Crypto.BigInt(aConnection['userData']['v'], 16); |
103 | u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(aConnection['B'].asString(10))).toHexString(), 16); | ||
104 | A = new Clipperz.Crypto.BigInt(aConnection['A'], 16); | 106 | A = new Clipperz.Crypto.BigInt(aConnection['A'], 16); |
107 | u = new Clipperz.Crypto.BigInt(Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + aConnection['B'].asString(10))).toHexString(), 16); | ||
108 | s = new Clipperz.Crypto.BigInt(aConnection['userData']['s'], 16); | ||
105 | S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(aConnection['b'], Clipperz.Crypto.SRP.n()); | 109 | S = (A.multiply(v.powerModule(u, Clipperz.Crypto.SRP.n()))).powerModule(aConnection['b'], Clipperz.Crypto.SRP.n()); |
106 | 110 | ||
107 | K = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(S.asString(10))).toHexString().slice(2); | 111 | K = stringHash(S.asString(10)); |
108 | 112 | ||
109 | M1 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + aConnection['B'].asString(10) + K)).toHexString().slice(2); | 113 | M1 = stringHash( |
114 | "597626870978286801440197562148588907434001483655788865609375806439877501869636875571920406529" + | ||
115 | stringHash(aConnection['C']) + | ||
116 | s.asString(10) + | ||
117 | A.asString(10) + | ||
118 | aConnection['B'].asString(10) + | ||
119 | K | ||
120 | ); | ||
110 | if (someParameters.parameters.M1 == M1) { | 121 | if (someParameters.parameters.M1 == M1) { |
111 | var M2; | 122 | var M2; |
112 | 123 | ||
113 | M2 = Clipperz.PM.Crypto.encryptingFunctions.versions[someParameters.version].hash(new Clipperz.ByteArray(A.asString(10) + someParameters.parameters.M1 + K)).toHexString().slice(2); | 124 | M2 = stringHash( |
125 | A.asString(10) + | ||
126 | someParameters.parameters.M1 + | ||
127 | K | ||
128 | ); | ||
114 | result['M2'] = M2; | 129 | result['M2'] = M2; |
115 | } else { | 130 | } else { |
116 | throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); | 131 | throw new Error("Client checksum verification failed! Expected <" + M1 + ">, received <" + someParameters.parameters.M1 + ">.", "Error"); |
117 | } | 132 | } |
118 | 133 | ||
119 | nextTollRequestType = 'MESSAGE'; | 134 | nextTollRequestType = 'MESSAGE'; |
120 | } else if (someParameters.message == "oneTimePassword") { | 135 | } else if (someParameters.message == "oneTimePassword") { |
121 | var otpData; | 136 | var otpData; |
122 | 137 | ||
123 | otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; | 138 | otpData = this.data()['onetimePasswords'][someParameters.parameters.oneTimePasswordKey]; |
124 | 139 | ||
125 | try { | 140 | try { |
126 | if (typeof(otpData) != 'undefined') { | 141 | if (typeof(otpData) != 'undefined') { |
127 | if (otpData['status'] == 'ACTIVE') { | 142 | if (otpData['status'] == 'ACTIVE') { |
128 | if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { | 143 | if (otpData['key_checksum'] == someParameters.parameters.oneTimePasswordKeyChecksum) { |
129 | result = { | 144 | result = { |
130 | 'data': otpData['data'], | 145 | 'data': otpData['data'], |
131 | 'version':otpData['version'] | 146 | 'version':otpData['version'] |
132 | } | 147 | } |
133 | 148 | ||
134 | otpData['status'] = 'REQUESTED'; | 149 | otpData['status'] = 'REQUESTED'; |
135 | } else { | 150 | } else { |
136 | otpData['status'] = 'DISABLED'; | 151 | otpData['status'] = 'DISABLED'; |
137 | throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; | 152 | throw "The requested One Time Password has been disabled, due to a wrong keyChecksum"; |
138 | } | 153 | } |
139 | } else { | 154 | } else { |
140 | throw "The requested One Time Password was not active"; | 155 | throw "The requested One Time Password was not active"; |
141 | } | 156 | } |
142 | } else { | 157 | } else { |
143 | throw "The requested One Time Password has not been found" | 158 | throw "The requested One Time Password has not been found" |
144 | } | 159 | } |
145 | } catch (exception) { | 160 | } catch (exception) { |
146 | result = { | 161 | result = { |
147 | 'data': Clipperz.PM.Crypto.randomKey(), | 162 | 'data': Clipperz.PM.Crypto.randomKey(), |
148 | 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion | 163 | 'version':Clipperz.PM.Connection.communicationProtocol.currentVersion |
149 | } | 164 | } |
150 | } | 165 | } |
151 | nextTollRequestType = 'CONNECT'; | 166 | nextTollRequestType = 'CONNECT'; |
152 | } else { | 167 | } else { |
153 | Clipperz.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); | 168 | Clipperz.logError("Clipperz.PM.Proxy.Test.handshake - unhandled message: " + someParameters.message); |
154 | } | 169 | } |
155 | 170 | ||
156 | result = { | 171 | result = { |
157 | result: result, | 172 | result: result, |
158 | toll: this.getTollForRequestType(nextTollRequestType) | 173 | toll: this.getTollForRequestType(nextTollRequestType) |
159 | } | 174 | } |
160 | 175 | ||
161 | return result; | 176 | return result; |
162 | }, | 177 | }, |
163 | 178 | ||
164 | //------------------------------------------------------------------------- | 179 | //------------------------------------------------------------------------- |
165 | 180 | ||
166 | '_message': function(aConnection, someParameters) { | 181 | '_message': function(aConnection, someParameters) { |
167 | var result; | 182 | var result; |
168 | 183 | ||
169 | result = {}; | 184 | result = {}; |
170 | 185 | ||
171 | //===================================================================== | 186 | //===================================================================== |
172 | // | 187 | // |
173 | // R E A D - O N L Y M e t h o d s | 188 | // R E A D - O N L Y M e t h o d s |
174 | // | 189 | // |
175 | //===================================================================== | 190 | //===================================================================== |
176 | if (someParameters.message == 'getUserDetails') { | 191 | if (someParameters.message == 'getUserDetails') { |
177 | var recordsStats; | 192 | var recordsStats; |
178 | var recordReference; | 193 | var recordReference; |
179 | 194 | ||
180 | recordsStats = {}; | 195 | recordsStats = {}; |
181 | for (recordReference in aConnection['userData']['records']) { | 196 | for (recordReference in aConnection['userData']['records']) { |
182 | recordsStats[recordReference] = { | 197 | recordsStats[recordReference] = { |
183 | 'updateDate': aConnection['userData']['records'][recordReference]['updateDate'] | 198 | 'updateDate': aConnection['userData']['records'][recordReference]['updateDate'] |
184 | } | 199 | } |
185 | } | 200 | } |
186 | 201 | ||
187 | result['header'] = this.userDetails(aConnection); | 202 | result['header'] = this.userDetails(aConnection); |
188 | result['statistics'] = this.statistics(aConnection); | 203 | result['statistics'] = this.statistics(aConnection); |
189 | result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords']; | 204 | result['maxNumberOfRecords'] = aConnection['userData']['maxNumberOfRecords']; |
190 | result['version'] = aConnection['userData']['userDetailsVersion']; | 205 | result['version'] = aConnection['userData']['userDetailsVersion']; |
191 | result['recordsStats'] = recordsStats; | 206 | result['recordsStats'] = recordsStats; |
192 | 207 | ||
193 | if (this.isReadOnly() == false) { | 208 | if (this.isReadOnly() == false) { |
194 | varlock; | 209 | varlock; |
195 | 210 | ||
196 | if (typeof(aConnection['userData']['lock']) == 'undefined') { | 211 | if (typeof(aConnection['userData']['lock']) == 'undefined') { |
197 | aConnection['userData']['lock'] = "<<LOCK>>"; | 212 | aConnection['userData']['lock'] = "<<LOCK>>"; |
198 | } | 213 | } |
199 | 214 | ||
200 | result['lock'] = aConnection['userData']['lock']; | 215 | result['lock'] = aConnection['userData']['lock']; |
201 | } | 216 | } |
202 | 217 | ||
203 | //===================================================================== | 218 | //===================================================================== |
204 | } else if (someParameters.message == 'getRecordDetail') { | 219 | } else if (someParameters.message == 'getRecordDetail') { |
205 | /* | 220 | /* |
206 | varrecordData; | 221 | varrecordData; |
207 | var currentVersionData; | 222 | var currentVersionData; |
208 | 223 | ||
209 | recordData = this.userData()['records'][someParameters['parameters']['reference']]; | 224 | recordData = this.userData()['records'][someParameters['parameters']['reference']]; |
210 | result['reference'] = someParameters['parameters']['reference']; | 225 | result['reference'] = someParameters['parameters']['reference']; |
211 | result['data'] = recordData['data']; | 226 | result['data'] = recordData['data']; |
212 | result['version'] = recordData['version']; | 227 | result['version'] = recordData['version']; |
213 | result['creationData'] = recordData['creationDate']; | 228 | result['creationData'] = recordData['creationDate']; |
214 | result['updateDate'] = recordData['updateDate']; | 229 | result['updateDate'] = recordData['updateDate']; |
215 | result['accessDate'] = recordData['accessDate']; | 230 | result['accessDate'] = recordData['accessDate']; |
216 | 231 | ||
217 | currentVersionData = recordData['versions'][recordData['currentVersion']]; | 232 | currentVersionData = recordData['versions'][recordData['currentVersion']]; |
218 | 233 | ||
219 | result['currentVersion'] = {}; | 234 | result['currentVersion'] = {}; |
220 | result['currentVersion']['reference'] = recordData['currentVersion']; | 235 | result['currentVersion']['reference'] = recordData['currentVersion']; |
221 | result['currentVersion']['version'] = currentVersionData['version']; | 236 | result['currentVersion']['version'] = currentVersionData['version']; |
222 | result['currentVersion']['header'] = currentVersionData['header']; | 237 | result['currentVersion']['header'] = currentVersionData['header']; |
223 | result['currentVersion']['data'] = currentVersionData['data']; | 238 | result['currentVersion']['data'] = currentVersionData['data']; |
224 | result['currentVersion']['creationData'] = currentVersionData['creationDate']; | 239 | result['currentVersion']['creationData'] = currentVersionData['creationDate']; |
225 | result['currentVersion']['updateDate'] = currentVersionData['updateDate']; | 240 | result['currentVersion']['updateDate'] = currentVersionData['updateDate']; |
226 | result['currentVersion']['accessDate'] = currentVersionData['accessDate']; | 241 | result['currentVersion']['accessDate'] = currentVersionData['accessDate']; |
227 | if (typeof(currentVersionData['previousVersion']) != 'undefined') { | 242 | if (typeof(currentVersionData['previousVersion']) != 'undefined') { |
228 | result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey']; | 243 | result['currentVersion']['previousVersionKey'] = currentVersionData['previousVersionKey']; |
229 | result['currentVersion']['previousVersion'] = currentVersionData['previousVersion']; | 244 | result['currentVersion']['previousVersion'] = currentVersionData['previousVersion']; |
230 | } | 245 | } |
231 | */ | 246 | */ |
232 | MochiKit.Base.update(result, aConnection['userData']['records'][someParameters['parameters']['reference']]); | 247 | MochiKit.Base.update(result, aConnection['userData']['records'][someParameters['parameters']['reference']]); |
233 | result['reference'] = someParameters['parameters']['reference']; | 248 | result['reference'] = someParameters['parameters']['reference']; |
234 | 249 | ||
235 | //===================================================================== | 250 | //===================================================================== |
236 | // | 251 | // |
237 | // R E A D - W R I T E M e t h o d s | 252 | // R E A D - W R I T E M e t h o d s |
238 | // | 253 | // |
239 | //===================================================================== | 254 | //===================================================================== |
240 | } else if (someParameters.message == 'upgradeUserCredentials') { | 255 | } else if (someParameters.message == 'upgradeUserCredentials') { |
241 | if (this.isReadOnly() == false) { | 256 | if (this.isReadOnly() == false) { |
242 | var parameters; | 257 | var parameters; |
243 | var credentials; | 258 | var credentials; |
244 | 259 | ||
245 | parameters = someParameters['parameters']; | 260 | parameters = someParameters['parameters']; |
246 | credentials = parameters['credentials']; | 261 | credentials = parameters['credentials']; |
247 | 262 | ||
248 | if ((credentials['C'] == null) | 263 | if ((credentials['C'] == null) |
249 | ||(credentials['s'] == null) | 264 | ||(credentials['s'] == null) |
250 | ||(credentials['v'] == null) | 265 | ||(credentials['v'] == null) |
251 | ||(credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) | 266 | ||(credentials['version'] != Clipperz.PM.Connection.communicationProtocol.currentVersion) |
252 | ) { | 267 | ) { |
253 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; | 268 | result = Clipperz.PM.DataModel.User.exception.CredentialUpgradeFailed; |
254 | } else { | 269 | } else { |
255 | varoldCValue; | 270 | varoldCValue; |
256 | oldCValue = aConnection['C']; | 271 | oldCValue = aConnection['C']; |
257 | 272 | ||
258 | this.data()['users'][credentials['C']] = aConnection['userData']; | 273 | this.data()['users'][credentials['C']] = aConnection['userData']; |
259 | aConnection['C'] = credentials['C']; | 274 | aConnection['C'] = credentials['C']; |
260 | 275 | ||
261 | aConnection['userData']['s'] = credentials['s']; | 276 | aConnection['userData']['s'] = credentials['s']; |
262 | aConnection['userData']['v'] = credentials['v']; | 277 | aConnection['userData']['v'] = credentials['v']; |
263 | aConnection['userData']['version'] = credentials['version']; | 278 | aConnection['userData']['version'] = credentials['version']; |
264 | 279 | ||
265 | aConnection['userData']['userDetails'] = parameters['user']['header']; | 280 | aConnection['userData']['userDetails'] = parameters['user']['header']; |
266 | aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; | 281 | aConnection['userData']['userDetailsVersion'] = parameters['user']['version']; |
267 | aConnection['userData']['statistics'] = parameters['user']['statistics']; | 282 | aConnection['userData']['statistics'] = parameters['user']['statistics']; |
268 | 283 | ||
269 | aConnection['userData']['lock'] = parameters['user']['lock']; | 284 | aConnection['userData']['lock'] = parameters['user']['lock']; |
270 | 285 | ||
271 | delete this.data()['users'][oldCValue]; | 286 | delete this.data()['users'][oldCValue]; |
272 | 287 | ||
273 | result = {result:"done", parameters:parameters}; | 288 | result = {result:"done", parameters:parameters}; |
274 | } | 289 | } |
275 | } else { | 290 | } else { |
276 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 291 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
277 | } | 292 | } |
278 | 293 | ||
279 | //===================================================================== | 294 | //===================================================================== |
280 | 295 | ||
281 | } else if (someParameters.message == 'saveChanges') { | 296 | } else if (someParameters.message == 'saveChanges') { |
282 | if (this.isReadOnly() == false) { | 297 | if (this.isReadOnly() == false) { |
283 | var i, c; | 298 | var i, c; |
284 | 299 | ||
285 | if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { | 300 | if (aConnection['userData']['lock']!= someParameters['parameters']['user']['lock']) { |
286 | throw "the lock attribute is not processed correctly" | 301 | throw "the lock attribute is not processed correctly" |
287 | } | 302 | } |
288 | 303 | ||
289 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; | 304 | aConnection['userData']['userDetails'] = someParameters['parameters']['user']['header']; |
290 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; | 305 | aConnection['userData']['statistics'] = someParameters['parameters']['user']['statistics']; |
291 | aConnection['userData']['userDetailsVersion']= someParameters['parameters']['user']['version']; | 306 | aConnection['userData']['userDetailsVersion']= someParameters['parameters']['user']['version']; |
292 | 307 | ||
293 | c = someParameters['parameters']['records']['updated'].length; | 308 | c = someParameters['parameters']['records']['updated'].length; |
294 | for (i=0; i<c; i++) { | 309 | for (i=0; i<c; i++) { |
295 | var currentRecord; | 310 | var currentRecord; |
296 | var currentRecordData; | 311 | var currentRecordData; |
297 | 312 | ||
298 | currentRecordData = someParameters['parameters']['records']['updated'][i]; | 313 | currentRecordData = someParameters['parameters']['records']['updated'][i]; |
299 | currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; | 314 | currentRecord = aConnection['userData']['records'][currentRecordData['record']['reference']]; |
300 | 315 | ||
301 | if ( | 316 | if ( |
302 | (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') | 317 | (typeof(aConnection['userData']['records'][currentRecordData['record']['reference']]) == 'undefined') |
303 | && | 318 | && |
304 | (typeof(currentRecordData['currentRecordVersion']) == 'undefined') | 319 | (typeof(currentRecordData['currentRecordVersion']) == 'undefined') |
305 | ) { | 320 | ) { |
306 | throw "Record added without a recordVersion"; | 321 | throw "Record added without a recordVersion"; |
307 | } | 322 | } |
308 | 323 | ||
309 | if (currentRecord == null) { | 324 | if (currentRecord == null) { |
310 | currentRecord = {}; | 325 | currentRecord = {}; |
311 | currentRecord['versions'] = {}; | 326 | currentRecord['versions'] = {}; |
312 | currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 327 | currentRecord['creationDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
313 | currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 328 | currentRecord['accessDate'] = Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
314 | 329 | ||
315 | aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; | 330 | aConnection['userData']['records'][currentRecordData['record']['reference']] = currentRecord; |
316 | } | 331 | } |
317 | 332 | ||
318 | currentRecord['data'] = currentRecordData['record']['data']; | 333 | currentRecord['data'] = currentRecordData['record']['data']; |
319 | currentRecord['version']= currentRecordData['record']['version']; | 334 | currentRecord['version']= currentRecordData['record']['version']; |
320 | currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); | 335 | currentRecord['updateDate']= Clipperz.PM.Date.formatDateWithUTCFormat(new Date()); |
321 | 336 | ||
322 | if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { | 337 | if (typeof(currentRecordData['currentRecordVersion']) != 'undefined') { |
323 | currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; | 338 | currentRecord['currentVersion'] = currentRecordData['currentRecordVersion']['reference']; |
324 | currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { | 339 | currentRecord['versions'][currentRecordData['currentRecordVersion']['reference']] = { |
325 | 'data': currentRecordData['currentRecordVersion']['data'], | 340 | 'data': currentRecordData['currentRecordVersion']['data'], |
326 | 'version': currentRecordData['currentRecordVersion']['version'], | 341 | 'version': currentRecordData['currentRecordVersion']['version'], |
327 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], | 342 | 'previousVersion': currentRecordData['currentRecordVersion']['previousVersion'], |
328 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'], | 343 | 'previousVersionKey':currentRecordData['currentRecordVersion']['previousVersionKey'], |
329 | 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), | 344 | 'creationDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), |
330 | 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), | 345 | 'updateDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()), |
331 | 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) | 346 | 'accessDate':Clipperz.PM.Date.formatDateWithUTCFormat(new Date()) |
332 | } | 347 | } |
333 | } | 348 | } |
334 | } | 349 | } |
335 | 350 | ||
336 | c = someParameters['parameters']['records']['deleted'].length; | 351 | c = someParameters['parameters']['records']['deleted'].length; |
337 | for (i=0; i<c; i++) { | 352 | for (i=0; i<c; i++) { |
338 | var currentRecordReference; | 353 | var currentRecordReference; |
339 | 354 | ||
340 | currentRecordReference = someParameters['parameters']['records']['deleted'][i]; | 355 | currentRecordReference = someParameters['parameters']['records']['deleted'][i]; |
341 | delete aConnection['userData']['records'][currentRecordReference]; | 356 | delete aConnection['userData']['records'][currentRecordReference]; |
342 | } | 357 | } |
343 | 358 | ||
344 | aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey(); | 359 | aConnection['userData']['lock'] = Clipperz.PM.Crypto.randomKey(); |
345 | result['lock'] = aConnection['userData']['lock']; | 360 | result['lock'] = aConnection['userData']['lock']; |
346 | result['result'] = 'done'; | 361 | result['result'] = 'done'; |
347 | } else { | 362 | } else { |
348 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; | 363 | throw Clipperz.PM.Proxy.Offline.DataStore.exception.ReadOnly; |
349 | } | 364 | } |
350 | 365 | ||
351 | //===================================================================== | 366 | //===================================================================== |
352 | // | 367 | // |
353 | // U N H A N D L E D M e t h o d | 368 | // U N H A N D L E D M e t h o d |
354 | // | 369 | // |
355 | //===================================================================== | 370 | //===================================================================== |
356 | } else { | 371 | } else { |
357 | Clipperz.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); | 372 | Clipperz.logError("Clipperz.PM.Proxy.Test.message - unhandled message: " + someParameters.message); |
358 | } | 373 | } |
359 | 374 | ||
360 | result = { | 375 | result = { |
361 | result: result, | 376 | result: result, |
362 | toll: this.getTollForRequestType('MESSAGE') | 377 | toll: this.getTollForRequestType('MESSAGE') |
363 | } | 378 | } |
364 | 379 | ||
365 | // return MochiKit.Async.succeed(result); | 380 | // return MochiKit.Async.succeed(result); |
366 | return result; | 381 | return result; |
367 | }, | 382 | }, |
368 | 383 | ||
369 | //------------------------------------------------------------------------- | 384 | //------------------------------------------------------------------------- |
370 | 385 | ||
371 | '_logout': function(someParameters) { | 386 | '_logout': function(someParameters) { |
372 | // return MochiKit.Async.succeed({result: 'done'}); | 387 | // return MochiKit.Async.succeed({result: 'done'}); |
373 | return {result: 'done'}; | 388 | return {result: 'done'}; |
374 | }, | 389 | }, |
375 | 390 | ||
376 | //========================================================================= | 391 | //========================================================================= |
377 | //######################################################################### | 392 | //######################################################################### |
378 | /* | 393 | /* |
379 | 'userDetails': function(aConnection) { | 394 | 'userDetails': function(aConnection) { |
380 | var result; | 395 | var result; |
381 | 396 | ||
382 | if (this.isTestData(aConnection)) { | 397 | if (this.isTestData(aConnection)) { |
383 | var serializedHeader; | 398 | var serializedHeader; |
384 | var version; | 399 | var version; |
385 | 400 | ||
386 | //Clipperz.logDebug("### test data"); | 401 | //Clipperz.logDebug("### test data"); |
387 | version = aConnection['userData']['userDetailsVersion']; | 402 | version = aConnection['userData']['userDetailsVersion']; |
388 | serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']); | 403 | serializedHeader = Clipperz.Base.serializeJSON(aConnection['userData']['userDetails']); |
389 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader); | 404 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedHeader); |
390 | } else { | 405 | } else { |
391 | //Clipperz.logDebug("### NOT test data"); | 406 | //Clipperz.logDebug("### NOT test data"); |
392 | result = aConnection['userData']['userDetails']; | 407 | result = aConnection['userData']['userDetails']; |
393 | } | 408 | } |
394 | 409 | ||
395 | return result; | 410 | return result; |
396 | }, | 411 | }, |
397 | 412 | ||
398 | 'statistics': function(aConnection) { | 413 | 'statistics': function(aConnection) { |
399 | var result; | 414 | var result; |
400 | 415 | ||
401 | if (aConnection['userData']['statistics'] != null) { | 416 | if (aConnection['userData']['statistics'] != null) { |
402 | if (this.isTestData(aConnection)) { | 417 | if (this.isTestData(aConnection)) { |
403 | var serializedStatistics; | 418 | var serializedStatistics; |
404 | var version; | 419 | var version; |
405 | 420 | ||
406 | version = aConnection['userData']['userDetailsVersion']; | 421 | version = aConnection['userData']['userDetailsVersion']; |
407 | serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']); | 422 | serializedStatistics = Clipperz.Base.serializeJSON(aConnection['userData']['statistics']); |
408 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics); | 423 | result = Clipperz.PM.Crypto.encryptingFunctions.versions[version].encrypt(aConnection['userData']['__masterkey_test_value__'], serializedStatistics); |
409 | } else { | 424 | } else { |
410 | result = aConnection['userData']['statistics']; | 425 | result = aConnection['userData']['statistics']; |
411 | } | 426 | } |
412 | } else { | 427 | } else { |
413 | result = null; | 428 | result = null; |
414 | } | 429 | } |
415 | 430 | ||
416 | return result; | 431 | return result; |
417 | }, | 432 | }, |
418 | */ | 433 | */ |
419 | //========================================================================= | 434 | //========================================================================= |
420 | __syntaxFix__: "syntax fix" | 435 | __syntaxFix__: "syntax fix" |
421 | }); | 436 | }); |
422 | 437 | ||