author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js b/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js index 834e21b..fbca1ff 100644 --- a/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js +++ b/frontend/gamma/js/Clipperz/PM/DataModel/OneTimePassword.js | |||
@@ -1,70 +1,68 @@ | |||
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.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } | 26 | if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } |
29 | 27 | ||
30 | 28 | ||
31 | //############################################################################# | 29 | //############################################################################# |
32 | 30 | ||
33 | Clipperz.PM.DataModel.OneTimePassword = function(args) { | 31 | Clipperz.PM.DataModel.OneTimePassword = function(args) { |
34 | args = args || {}; | 32 | args = args || {}; |
35 | 33 | ||
36 | //this._user = args['user']; | 34 | //this._user = args['user']; |
37 | this._reference = args['reference']|| Clipperz.PM.Crypto.randomKey(); | 35 | this._reference = args['reference']|| Clipperz.PM.Crypto.randomKey(); |
38 | this._password = args['password']; | 36 | this._password = args['password']; |
39 | this._passwordValue = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(args['password']); | 37 | this._passwordValue = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(args['password']); |
40 | this._creationDate = args['created'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['created']) : new Date(); | 38 | this._creationDate = args['created'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['created']) : new Date(); |
41 | this._usageDate = args['used'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['used']) : null; | 39 | this._usageDate = args['used'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['used']) : null; |
42 | 40 | ||
43 | this._status = args['status'] || 'ACTIVE'; //'REQUESTED', 'USED', 'DISABLED' | 41 | this._status = args['status'] || 'ACTIVE'; //'REQUESTED', 'USED', 'DISABLED' |
44 | this._connectionInfo= null; | 42 | this._connectionInfo= null; |
45 | 43 | ||
46 | this._key = null; | 44 | this._key = null; |
47 | this._keyChecksum= null; | 45 | this._keyChecksum= null; |
48 | 46 | ||
49 | return this; | 47 | return this; |
50 | } | 48 | } |
51 | 49 | ||
52 | Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, { | 50 | Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, { |
53 | 51 | ||
54 | 'toString': function() { | 52 | 'toString': function() { |
55 | return "Clipperz.PM.DataModel.OneTimePassword"; | 53 | return "Clipperz.PM.DataModel.OneTimePassword"; |
56 | }, | 54 | }, |
57 | /* | 55 | /* |
58 | //------------------------------------------------------------------------- | 56 | //------------------------------------------------------------------------- |
59 | 57 | ||
60 | 'user': function() { | 58 | 'user': function() { |
61 | return this._user; | 59 | return this._user; |
62 | }, | 60 | }, |
63 | 61 | ||
64 | //------------------------------------------------------------------------- | 62 | //------------------------------------------------------------------------- |
65 | 63 | ||
66 | 'password': function() { | 64 | 'password': function() { |
67 | return this._password; | 65 | return this._password; |
68 | }, | 66 | }, |
69 | 67 | ||
70 | //------------------------------------------------------------------------- | 68 | //------------------------------------------------------------------------- |
@@ -98,257 +96,255 @@ Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, { | |||
98 | //------------------------------------------------------------------------- | 96 | //------------------------------------------------------------------------- |
99 | 97 | ||
100 | 'keyChecksum': function() { | 98 | 'keyChecksum': function() { |
101 | if (this._keyChecksum == null) { | 99 | if (this._keyChecksum == null) { |
102 | this._keyChecksum = Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(this.user().username(), this.passwordValue()); | 100 | this._keyChecksum = Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(this.user().username(), this.passwordValue()); |
103 | } | 101 | } |
104 | 102 | ||
105 | return this._keyChecksum; | 103 | return this._keyChecksum; |
106 | }, | 104 | }, |
107 | */ | 105 | */ |
108 | //------------------------------------------------------------------------- | 106 | //------------------------------------------------------------------------- |
109 | 107 | ||
110 | 'status': function() { | 108 | 'status': function() { |
111 | return this._status; | 109 | return this._status; |
112 | }, | 110 | }, |
113 | 111 | ||
114 | 'setStatus': function(aValue) { | 112 | 'setStatus': function(aValue) { |
115 | this._status = aValue; | 113 | this._status = aValue; |
116 | }, | 114 | }, |
117 | 115 | ||
118 | //------------------------------------------------------------------------- | 116 | //------------------------------------------------------------------------- |
119 | /* | 117 | /* |
120 | 'serializedData': function() { | 118 | 'serializedData': function() { |
121 | var result; | 119 | var result; |
122 | 120 | ||
123 | result = { | 121 | result = { |
124 | 'password': this.password(), | 122 | 'password': this.password(), |
125 | 'created': this.creationDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.creationDate()) : null, | 123 | 'created': this.creationDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.creationDate()) : null, |
126 | 'used': this.usageDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.usageDate()) : null, | 124 | 'used': this.usageDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.usageDate()) : null, |
127 | 'status': this.status() | 125 | 'status': this.status() |
128 | }; | 126 | }; |
129 | 127 | ||
130 | return result; | 128 | return result; |
131 | }, | 129 | }, |
132 | 130 | ||
133 | //------------------------------------------------------------------------- | 131 | //------------------------------------------------------------------------- |
134 | 132 | ||
135 | 'packedPassphrase': function() { | 133 | 'packedPassphrase': function() { |
136 | var result; | 134 | var result; |
137 | var packedPassphrase; | 135 | var packedPassphrase; |
138 | var encodedPassphrase; | 136 | var encodedPassphrase; |
139 | varprefixPadding; | 137 | varprefixPadding; |
140 | var suffixPadding; | 138 | var suffixPadding; |
141 | var getRandomBytes; | 139 | var getRandomBytes; |
142 | 140 | ||
143 | getRandomBytes = MochiKit.Base.method(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'getRandomBytes'); | 141 | getRandomBytes = MochiKit.Base.method(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'getRandomBytes'); |
144 | 142 | ||
145 | encodedPassphrase = new Clipperz.ByteArray(this.user().passphrase()).toBase64String(); | 143 | encodedPassphrase = new Clipperz.ByteArray(this.user().passphrase()).toBase64String(); |
146 | //MochiKit.Logging.logDebug("--- encodedPassphrase.length: " + encodedPassphrase.length); | 144 | //Clipperz.logDebug("--- encodedPassphrase.length: " + encodedPassphrase.length); |
147 | prefixPadding = getRandomBytes(getRandomBytes(1).byteAtIndex(0)).toBase64String(); | 145 | prefixPadding = getRandomBytes(getRandomBytes(1).byteAtIndex(0)).toBase64String(); |
148 | //MochiKit.Logging.logDebug("--- prefixPadding.length: " + prefixPadding.length); | 146 | //Clipperz.logDebug("--- prefixPadding.length: " + prefixPadding.length); |
149 | suffixPadding = getRandomBytes((500 - prefixPadding.length - encodedPassphrase.length) * 6 / 8).toBase64String(); | 147 | suffixPadding = getRandomBytes((500 - prefixPadding.length - encodedPassphrase.length) * 6 / 8).toBase64String(); |
150 | //MochiKit.Logging.logDebug("--- suffixPadding.length: " + suffixPadding.length); | 148 | //Clipperz.logDebug("--- suffixPadding.length: " + suffixPadding.length); |
151 | //MochiKit.Logging.logDebug("--- total.length: " + (prefixPadding.length + encodedPassphrase.length + suffixPadding.length)); | 149 | //Clipperz.logDebug("--- total.length: " + (prefixPadding.length + encodedPassphrase.length + suffixPadding.length)); |
152 | 150 | ||
153 | packedPassphrase = { | 151 | packedPassphrase = { |
154 | 'prefix': prefixPadding, | 152 | 'prefix': prefixPadding, |
155 | 'passphrase': encodedPassphrase, | 153 | 'passphrase': encodedPassphrase, |
156 | 'suffix': suffixPadding | 154 | 'suffix': suffixPadding |
157 | }; | 155 | }; |
158 | 156 | ||
159 | // result = Clipperz.Base.serializeJSON(packedPassphrase); | 157 | // result = Clipperz.Base.serializeJSON(packedPassphrase); |
160 | result = packedPassphrase; | 158 | result = packedPassphrase; |
161 | //MochiKit.Logging.logDebug("===== OTP packedPassprase: [" + result.length + "]" + result); | 159 | //Clipperz.logDebug("===== OTP packedPassprase: [" + result.length + "]" + result); |
162 | //MochiKit.Logging.logDebug("<<< OneTimePassword.packedPassphrase"); | 160 | //Clipperz.logDebug("<<< OneTimePassword.packedPassphrase"); |
163 | 161 | ||
164 | return result; | 162 | return result; |
165 | }, | 163 | }, |
166 | 164 | ||
167 | //------------------------------------------------------------------------- | 165 | //------------------------------------------------------------------------- |
168 | 166 | ||
169 | 'encryptedPackedPassphrase': function() { | 167 | 'encryptedPackedPassphrase': function() { |
170 | return Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion(this.passwordValue(), this.packedPassphrase()) | 168 | return Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion(this.passwordValue(), this.packedPassphrase()) |
171 | }, | 169 | }, |
172 | 170 | ||
173 | //------------------------------------------------------------------------- | 171 | //------------------------------------------------------------------------- |
174 | 172 | ||
175 | 'encryptedData': function() { | 173 | 'encryptedData': function() { |
176 | var deferredResult; | 174 | var deferredResult; |
177 | varresult; | 175 | varresult; |
178 | 176 | ||
179 | //MochiKit.Logging.logDebug(">>> OneTimePassword.encryptedData"); | 177 | //Clipperz.logDebug(">>> OneTimePassword.encryptedData"); |
180 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - id: " + this.reference()); | 178 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - id: " + this.reference()); |
181 | result = { | 179 | result = { |
182 | 'reference': this.reference(), | 180 | 'reference': this.reference(), |
183 | 'key': this.key(), | 181 | 'key': this.key(), |
184 | 'keyChecksum': this.keyChecksum(), | 182 | 'keyChecksum': this.keyChecksum(), |
185 | 'data': "", | 183 | 'data': "", |
186 | 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion | 184 | 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion |
187 | } | 185 | } |
188 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 2: " + Clipperz.Base.serializeJSON(result)); | 186 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 2: " + Clipperz.Base.serializeJSON(result)); |
189 | deferredResult = new MochiKit.Async.Deferred(); | 187 | deferredResult = new MochiKit.Async.Deferred(); |
190 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 3"); | 188 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 3"); |
191 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 1: " + res); return res;}); | 189 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.encryptedData - 1: " + res); return res;}); |
192 | //# deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.passwordValue(), this.packedPassphrase()); | 190 | //# deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.passwordValue(), this.packedPassphrase()); |
193 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedPackedPassphrase')); | 191 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedPackedPassphrase')); |
194 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 4"); | 192 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 4"); |
195 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 2: [" + res.length + "]" + res); return res;}); | 193 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.encryptedData - 2: [" + res.length + "]" + res); return res;}); |
196 | deferredResult.addCallback(function(aResult, res) { | 194 | deferredResult.addCallback(function(aResult, res) { |
197 | aResult['data'] = res; | 195 | aResult['data'] = res; |
198 | return aResult; | 196 | return aResult; |
199 | }, result); | 197 | }, result); |
200 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 5"); | 198 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 5"); |
201 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); | 199 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.encryptedData - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); |
202 | deferredResult.callback(); | 200 | deferredResult.callback(); |
203 | //MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 6"); | 201 | //Clipperz.logDebug("--- OneTimePassword.encryptedData - 6"); |
204 | 202 | ||
205 | return deferredResult; | 203 | return deferredResult; |
206 | }, | 204 | }, |
207 | 205 | ||
208 | //------------------------------------------------------------------------- | 206 | //------------------------------------------------------------------------- |
209 | 207 | ||
210 | 'saveChanges': function() { | 208 | 'saveChanges': function() { |
211 | var deferredResult; | 209 | var deferredResult; |
212 | varresult; | 210 | varresult; |
213 | 211 | ||
214 | //MochiKit.Logging.logDebug(">>> OneTimePassword.saveChanges"); | 212 | //Clipperz.logDebug(">>> OneTimePassword.saveChanges"); |
215 | result = {}; | 213 | result = {}; |
216 | deferredResult = new MochiKit.Async.Deferred(); | 214 | deferredResult = new MochiKit.Async.Deferred(); |
217 | 215 | ||
218 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptUserData'); | 216 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptUserData'); |
219 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); | 217 | deferredResult.addCallback(MochiKit.Base.method(this.user(), 'encryptedData')); |
220 | deferredResult.addCallback(function(aResult, res) { | 218 | deferredResult.addCallback(function(aResult, res) { |
221 | aResult['user'] = res; | 219 | aResult['user'] = res; |
222 | return aResult; | 220 | return aResult; |
223 | }, result); | 221 | }, result); |
224 | 222 | ||
225 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptOTPData'); | 223 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_encryptOTPData'); |
226 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); | 224 | deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedData')); |
227 | deferredResult.addCallback(function(aResult, res) { | 225 | deferredResult.addCallback(function(aResult, res) { |
228 | aResult['oneTimePassword'] = res; | 226 | aResult['oneTimePassword'] = res; |
229 | return aResult; | 227 | return aResult; |
230 | }, result); | 228 | }, result); |
231 | 229 | ||
232 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_sendingData'); | 230 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_sendingData'); |
233 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.saveChanges - 1: " + Clipperz.Base.serializeJSON(res)); return res;}); | 231 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.saveChanges - 1: " + Clipperz.Base.serializeJSON(res)); return res;}); |
234 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewOneTimePassword'); | 232 | deferredResult.addCallback(MochiKit.Base.method(this.user().connection(), 'message'), 'addNewOneTimePassword'); |
235 | 233 | ||
236 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_updatingInterface'); | 234 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'updatedProgressState', 'saveOTP_updatingInterface'); |
237 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); | 235 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); |
238 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'OTPUpdated'); | 236 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'notify', 'OTPUpdated'); |
239 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'oneTimePassword_saveChanges_done', null); | 237 | deferredResult.addCallback(Clipperz.NotificationCenter.deferredNotification, this, 'oneTimePassword_saveChanges_done', null); |
240 | //deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); | 238 | //deferredResult.addBoth(function(res) {Clipperz.logDebug("OneTimePassword.saveChanges - 2: " + res); return res;}); |
241 | deferredResult.callback(); | 239 | deferredResult.callback(); |
242 | //MochiKit.Logging.logDebug("<<< OneTimePassword.saveChanges"); | 240 | //Clipperz.logDebug("<<< OneTimePassword.saveChanges"); |
243 | 241 | ||
244 | return deferredResult; | 242 | return deferredResult; |
245 | }, | 243 | }, |
246 | 244 | ||
247 | //------------------------------------------------------------------------- | 245 | //------------------------------------------------------------------------- |
248 | 246 | ||
249 | 'usageDate': function() { | 247 | 'usageDate': function() { |
250 | return this._usageDate; | 248 | return this._usageDate; |
251 | }, | 249 | }, |
252 | 250 | ||
253 | 'setUsageDate': function(aValue) { | 251 | 'setUsageDate': function(aValue) { |
254 | this._usageDate = aValue; | 252 | this._usageDate = aValue; |
255 | }, | 253 | }, |
256 | 254 | ||
257 | //------------------------------------------------------------------------- | 255 | //------------------------------------------------------------------------- |
258 | 256 | ||
259 | 'connectionInfo': function() { | 257 | 'connectionInfo': function() { |
260 | return this._connectionInfo; | 258 | return this._connectionInfo; |
261 | }, | 259 | }, |
262 | 260 | ||
263 | 'setConnectionInfo': function(aValue) { | 261 | 'setConnectionInfo': function(aValue) { |
264 | this._connectionInfo = aValue; | 262 | this._connectionInfo = aValue; |
265 | }, | 263 | }, |
266 | 264 | ||
267 | //------------------------------------------------------------------------- | 265 | //------------------------------------------------------------------------- |
268 | 266 | ||
269 | 'isExpired': function() { | 267 | 'isExpired': function() { |
270 | return (this.usageDate() != null); | 268 | return (this.usageDate() != null); |
271 | }, | 269 | }, |
272 | 270 | ||
273 | //------------------------------------------------------------------------- | 271 | //------------------------------------------------------------------------- |
274 | 272 | ||
275 | 'updateStatusWithValues': function(someValues) { | 273 | 'updateStatusWithValues': function(someValues) { |
276 | var result; | 274 | var result; |
277 | 275 | ||
278 | result = false; | 276 | result = false; |
279 | 277 | ||
280 | if (someValues['status'] != this.status()) { | 278 | if (someValues['status'] != this.status()) { |
281 | result = true; | 279 | result = true; |
282 | } | 280 | } |
283 | 281 | ||
284 | this.setStatus(someValues['status']); | 282 | this.setStatus(someValues['status']); |
285 | this.setUsageDate(Clipperz.PM.Date.parseDateWithUTCFormat(someValues['requestDate'])); | 283 | this.setUsageDate(Clipperz.PM.Date.parseDateWithUTCFormat(someValues['requestDate'])); |
286 | this.setConnectionInfo(someValues['connection']); | 284 | this.setConnectionInfo(someValues['connection']); |
287 | 285 | ||
288 | return result; | 286 | return result; |
289 | }, | 287 | }, |
290 | */ | 288 | */ |
291 | //------------------------------------------------------------------------- | 289 | //------------------------------------------------------------------------- |
292 | __syntaxFix__: "syntax fix" | 290 | __syntaxFix__: "syntax fix" |
293 | }); | 291 | }); |
294 | 292 | ||
295 | //############################################################################# | 293 | //############################################################################# |
296 | 294 | ||
297 | Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword = function(anUsername, aPassword) { | 295 | Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword = function(anUsername, aPassword) { |
298 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aPassword)).toHexString().substring(2); | 296 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(aPassword)).toHexString().substring(2); |
299 | } | 297 | } |
300 | 298 | ||
301 | Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword = function(anUsername, aPassword) { | 299 | Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword = function(anUsername, aPassword) { |
302 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(anUsername + aPassword)).toHexString().substring(2); | 300 | return Clipperz.Crypto.SHA.sha_d256(new Clipperz.ByteArray(anUsername + aPassword)).toHexString().substring(2); |
303 | } | 301 | } |
304 | 302 | ||
305 | //============================================================================= | 303 | //============================================================================= |
306 | 304 | ||
307 | Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue = function(aPassword) { | 305 | Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue = function(aPassword) { |
308 | var result; | 306 | var result; |
309 | 307 | ||
310 | //"yaxx k7ww - f8y6 tqz5 - 58b6 th44 - 9cwv q0fg" | 308 | //"yaxx k7ww - f8y6 tqz5 - 58b6 th44 - 9cwv q0fg" |
311 | //console.log("Clipperz.PM.DataModel.OneTimePassword.isValidOneTimePasswordValue", aPassword); | ||
312 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { | 309 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { |
313 | try { | 310 | try { |
314 | var passwordByteArray; | 311 | var passwordByteArray; |
315 | 312 | ||
316 | passwordByteArray = new Clipperz.ByteArray(); | 313 | passwordByteArray = new Clipperz.ByteArray(); |
317 | passwordByteArray.appendBase32String(aPassword); | 314 | passwordByteArray.appendBase32String(aPassword); |
318 | 315 | ||
319 | result = true; | 316 | result = true; |
320 | } catch(exception) { | 317 | } catch(exception) { |
321 | result = false; | 318 | result = false; |
322 | } | 319 | } |
323 | } else { | 320 | } else { |
324 | result = false; | 321 | result = false; |
325 | } | 322 | } |
326 | 323 | ||
327 | return result; | 324 | return result; |
328 | } | 325 | } |
329 | 326 | ||
330 | //============================================================================= | 327 | //============================================================================= |
331 | 328 | ||
332 | Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword = function(aPassword) { | 329 | Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword = function(aPassword) { |
333 | varresult; | 330 | varresult; |
334 | 331 | ||
335 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { | 332 | if (aPassword.replace(/[\s\-]/g, '').length == 32) { |
336 | try { | 333 | try { |
337 | var passwordByteArray; | 334 | var passwordByteArray; |
338 | 335 | ||
339 | passwordByteArray = new Clipperz.ByteArray(); | 336 | passwordByteArray = new Clipperz.ByteArray(); |
340 | passwordByteArray.appendBase32String(aPassword); | 337 | passwordByteArray.appendBase32String(aPassword); |
341 | 338 | ||
342 | result = passwordByteArray.toBase64String(); | 339 | result = passwordByteArray.toBase64String(); |
343 | } catch(exception) { | 340 | } catch(exception) { |
344 | result = aPassword; | 341 | result = aPassword; |
345 | } | 342 | } |
346 | } else { | 343 | } else { |
347 | result = aPassword; | 344 | result = aPassword; |
348 | } | 345 | } |
349 | 346 | ||
350 | //console.log("Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword", aPassword, result); | ||
351 | return result; | 347 | return result; |
352 | } | 348 | } |
353 | 349 | ||
354 | //############################################################################# | 350 | //############################################################################# |