summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js
Unidiff
Diffstat (limited to 'frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js b/frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js
index 88f383a..3f611b4 100644
--- a/frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js
+++ b/frontend/beta/js/Clipperz/PM/DataModel/OneTimePassword.js
@@ -1,214 +1,212 @@
1/* 1/*
2 2
3Copyright 2008-2011 Clipperz Srl 3Copyright 2008-2013 Clipperz Srl
4 4
5This file is part of Clipperz Community Edition. 5This file is part of Clipperz, the online password manager.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please 6For further information about its features and functionalities please
8refer to http://www.clipperz.com. 7refer 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
26if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } 24if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
27if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } 25if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
28if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; } 26if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }
29 27
30 28
31//############################################################################# 29//#############################################################################
32 30
33Clipperz.PM.DataModel.OneTimePassword = function(args) { 31Clipperz.PM.DataModel.OneTimePassword = function(args) {
34 args = args || {}; 32 args = args || {};
35 33
36//console.log("new OneTimePassword", args); 34//console.log("new OneTimePassword", args);
37//MochiKit.Logging.logDebug("---"); 35//MochiKit.Logging.logDebug("---");
38 this._user = args['user']; 36 this._user = args['user'];
39 this._password = args['password']; 37 this._password = args['password'];
40 this._passwordValue = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(args['password']); 38 this._passwordValue = Clipperz.PM.DataModel.OneTimePassword.normalizedOneTimePassword(args['password']);
41 this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey(); 39 this._reference = args['reference'] || Clipperz.PM.Crypto.randomKey();
42 this._creationDate = args['created'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['created']) : new Date(); 40 this._creationDate = args['created'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['created']) : new Date();
43 this._usageDate = args['used'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['used']) : null; 41 this._usageDate = args['used'] ? Clipperz.PM.Date.parseDateWithUTCFormat(args['used']) : null;
44 42
45 this._status = args['status'] || 'ACTIVE'; 43 this._status = args['status'] || 'ACTIVE';
46 this._connectionInfo = null; 44 this._connectionInfo = null;
47 45
48 this._key = null; 46 this._key = null;
49 this._keyChecksum = null; 47 this._keyChecksum = null;
50 48
51 return this; 49 return this;
52} 50}
53 51
54Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, { 52Clipperz.PM.DataModel.OneTimePassword.prototype = MochiKit.Base.update(null, {
55 53
56 'toString': function() { 54 'toString': function() {
57 return "Clipperz.PM.DataModel.OneTimePassword"; 55 return "Clipperz.PM.DataModel.OneTimePassword";
58 }, 56 },
59 57
60 //------------------------------------------------------------------------- 58 //-------------------------------------------------------------------------
61 59
62 'user': function() { 60 'user': function() {
63 return this._user; 61 return this._user;
64 }, 62 },
65 63
66 //------------------------------------------------------------------------- 64 //-------------------------------------------------------------------------
67 65
68 'password': function() { 66 'password': function() {
69 return this._password; 67 return this._password;
70 }, 68 },
71 69
72 //------------------------------------------------------------------------- 70 //-------------------------------------------------------------------------
73 71
74 'passwordValue': function() { 72 'passwordValue': function() {
75 return this._passwordValue; 73 return this._passwordValue;
76 }, 74 },
77 75
78 //------------------------------------------------------------------------- 76 //-------------------------------------------------------------------------
79 77
80 'creationDate': function() { 78 'creationDate': function() {
81 return this._creationDate; 79 return this._creationDate;
82 }, 80 },
83 81
84 //------------------------------------------------------------------------- 82 //-------------------------------------------------------------------------
85 83
86 'reference': function() { 84 'reference': function() {
87 return this._reference; 85 return this._reference;
88 }, 86 },
89 87
90 //------------------------------------------------------------------------- 88 //-------------------------------------------------------------------------
91 89
92 'key': function() { 90 'key': function() {
93 if (this._key == null) { 91 if (this._key == null) {
94 this._key = Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(this.user().username(), this.passwordValue()); 92 this._key = Clipperz.PM.DataModel.OneTimePassword.computeKeyWithUsernameAndPassword(this.user().username(), this.passwordValue());
95 } 93 }
96 94
97 return this._key; 95 return this._key;
98 }, 96 },
99 97
100 //------------------------------------------------------------------------- 98 //-------------------------------------------------------------------------
101 99
102 'keyChecksum': function() { 100 'keyChecksum': function() {
103 if (this._keyChecksum == null) { 101 if (this._keyChecksum == null) {
104 this._keyChecksum = Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(this.user().username(), this.passwordValue()); 102 this._keyChecksum = Clipperz.PM.DataModel.OneTimePassword.computeKeyChecksumWithUsernameAndPassword(this.user().username(), this.passwordValue());
105 } 103 }
106 104
107 return this._keyChecksum; 105 return this._keyChecksum;
108 }, 106 },
109 107
110 //------------------------------------------------------------------------- 108 //-------------------------------------------------------------------------
111 109
112 'status': function() { 110 'status': function() {
113 return this._status; 111 return this._status;
114 }, 112 },
115 113
116 'setStatus': function(aValue) { 114 'setStatus': function(aValue) {
117 this._status = aValue; 115 this._status = aValue;
118 }, 116 },
119 117
120 //------------------------------------------------------------------------- 118 //-------------------------------------------------------------------------
121 119
122 'serializedData': function() { 120 'serializedData': function() {
123 var result; 121 var result;
124 122
125 result = { 123 result = {
126 'password': this.password(), 124 'password': this.password(),
127 'created': this.creationDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.creationDate()) : null, 125 'created': this.creationDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.creationDate()) : null,
128 'used': this.usageDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.usageDate()) : null, 126 'used': this.usageDate() ? Clipperz.PM.Date.formatDateWithUTCFormat(this.usageDate()) : null,
129 'status': this.status() 127 'status': this.status()
130 }; 128 };
131 129
132 return result; 130 return result;
133 }, 131 },
134 132
135 //------------------------------------------------------------------------- 133 //-------------------------------------------------------------------------
136 134
137 'packedPassphrase': function() { 135 'packedPassphrase': function() {
138 var result; 136 var result;
139 var packedPassphrase; 137 var packedPassphrase;
140 var encodedPassphrase; 138 var encodedPassphrase;
141 varprefixPadding; 139 varprefixPadding;
142 var suffixPadding; 140 var suffixPadding;
143 var getRandomBytes; 141 var getRandomBytes;
144 142
145 getRandomBytes = MochiKit.Base.method(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'getRandomBytes'); 143 getRandomBytes = MochiKit.Base.method(Clipperz.Crypto.PRNG.defaultRandomGenerator(), 'getRandomBytes');
146 144
147 encodedPassphrase = new Clipperz.ByteArray(this.user().passphrase()).toBase64String(); 145 encodedPassphrase = new Clipperz.ByteArray(this.user().passphrase()).toBase64String();
148//MochiKit.Logging.logDebug("--- encodedPassphrase.length: " + encodedPassphrase.length); 146//MochiKit.Logging.logDebug("--- encodedPassphrase.length: " + encodedPassphrase.length);
149 prefixPadding = getRandomBytes(getRandomBytes(1).byteAtIndex(0)).toBase64String(); 147 prefixPadding = getRandomBytes(getRandomBytes(1).byteAtIndex(0)).toBase64String();
150//MochiKit.Logging.logDebug("--- prefixPadding.length: " + prefixPadding.length); 148//MochiKit.Logging.logDebug("--- prefixPadding.length: " + prefixPadding.length);
151 suffixPadding = getRandomBytes((500 - prefixPadding.length - encodedPassphrase.length) * 6 / 8).toBase64String(); 149 suffixPadding = getRandomBytes((500 - prefixPadding.length - encodedPassphrase.length) * 6 / 8).toBase64String();
152//MochiKit.Logging.logDebug("--- suffixPadding.length: " + suffixPadding.length); 150//MochiKit.Logging.logDebug("--- suffixPadding.length: " + suffixPadding.length);
153//MochiKit.Logging.logDebug("--- total.length: " + (prefixPadding.length + encodedPassphrase.length + suffixPadding.length)); 151//MochiKit.Logging.logDebug("--- total.length: " + (prefixPadding.length + encodedPassphrase.length + suffixPadding.length));
154 152
155 packedPassphrase = { 153 packedPassphrase = {
156 'prefix': prefixPadding, 154 'prefix': prefixPadding,
157 'passphrase': encodedPassphrase, 155 'passphrase': encodedPassphrase,
158 'suffix': suffixPadding 156 'suffix': suffixPadding
159 }; 157 };
160 158
161 // result = Clipperz.Base.serializeJSON(packedPassphrase); 159 // result = Clipperz.Base.serializeJSON(packedPassphrase);
162 result = packedPassphrase; 160 result = packedPassphrase;
163//MochiKit.Logging.logDebug("===== OTP packedPassprase: [" + result.length + "]" + result); 161//MochiKit.Logging.logDebug("===== OTP packedPassprase: [" + result.length + "]" + result);
164//MochiKit.Logging.logDebug("<<< OneTimePassword.packedPassphrase"); 162//MochiKit.Logging.logDebug("<<< OneTimePassword.packedPassphrase");
165 163
166 return result; 164 return result;
167 }, 165 },
168 166
169 //------------------------------------------------------------------------- 167 //-------------------------------------------------------------------------
170 168
171 'encryptedPackedPassphrase': function() { 169 'encryptedPackedPassphrase': function() {
172 return Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion(this.passwordValue(), this.packedPassphrase()) 170 return Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion(this.passwordValue(), this.packedPassphrase())
173 }, 171 },
174 172
175 //------------------------------------------------------------------------- 173 //-------------------------------------------------------------------------
176 174
177 'encryptedData': function() { 175 'encryptedData': function() {
178 var deferredResult; 176 var deferredResult;
179 varresult; 177 varresult;
180 178
181//MochiKit.Logging.logDebug(">>> OneTimePassword.encryptedData"); 179//MochiKit.Logging.logDebug(">>> OneTimePassword.encryptedData");
182//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - id: " + this.reference()); 180//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - id: " + this.reference());
183 result = { 181 result = {
184 'reference': this.reference(), 182 'reference': this.reference(),
185 'key': this.key(), 183 'key': this.key(),
186 'keyChecksum': this.keyChecksum(), 184 'keyChecksum': this.keyChecksum(),
187 'data': "", 185 'data': "",
188 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion 186 'version': Clipperz.PM.Crypto.encryptingFunctions.currentVersion
189 } 187 }
190//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 2: " + Clipperz.Base.serializeJSON(result)); 188//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 2: " + Clipperz.Base.serializeJSON(result));
191 deferredResult = new MochiKit.Async.Deferred(); 189 deferredResult = new MochiKit.Async.Deferred();
192//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 3"); 190//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 3");
193//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 1: " + res); return res;}); 191//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 1: " + res); return res;});
194 //# deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.passwordValue(), this.packedPassphrase()); 192 //# deferredResult.addCallback(Clipperz.PM.Crypto.deferredEncryptWithCurrentVersion, this.passwordValue(), this.packedPassphrase());
195 deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedPackedPassphrase')); 193 deferredResult.addCallback(MochiKit.Base.method(this, 'encryptedPackedPassphrase'));
196//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 4"); 194//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 4");
197//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 2: [" + res.length + "]" + res); return res;}); 195//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 2: [" + res.length + "]" + res); return res;});
198 deferredResult.addCallback(function(aResult, res) { 196 deferredResult.addCallback(function(aResult, res) {
199 aResult['data'] = res; 197 aResult['data'] = res;
200 return aResult; 198 return aResult;
201 }, result); 199 }, result);
202//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 5"); 200//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 5");
203//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 3: " + Clipperz.Base.serializeJSON(res)); return res;}); 201//deferredResult.addBoth(function(res) {MochiKit.Logging.logDebug("OneTimePassword.encryptedData - 3: " + Clipperz.Base.serializeJSON(res)); return res;});
204 deferredResult.callback(); 202 deferredResult.callback();
205//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 6"); 203//MochiKit.Logging.logDebug("--- OneTimePassword.encryptedData - 6");
206 204
207 return deferredResult; 205 return deferredResult;
208 }, 206 },
209 207
210 //------------------------------------------------------------------------- 208 //-------------------------------------------------------------------------
211 209
212 'saveChanges': function() { 210 'saveChanges': function() {
213 var deferredResult; 211 var deferredResult;
214 varresult; 212 varresult;