summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/PIN.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/PIN.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/PIN.js22
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/PIN.js b/frontend/gamma/js/Clipperz/PM/PIN.js
index bc932b2..a32889a 100644
--- a/frontend/gamma/js/Clipperz/PM/PIN.js
+++ b/frontend/gamma/js/Clipperz/PM/PIN.js
@@ -1,118 +1,116 @@
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.PIN) == 'undefined') { Clipperz.PM.PIN = {}; } 26if (typeof(Clipperz.PM.PIN) == 'undefined') { Clipperz.PM.PIN = {}; }
29 27
30MochiKit.Base.update(Clipperz.PM.PIN, { 28MochiKit.Base.update(Clipperz.PM.PIN, {
31 29
32 //------------------------------------------------------------------------- 30 //-------------------------------------------------------------------------
33 31
34 '__repr__': function () { 32 '__repr__': function () {
35 return "[" + this.NAME + " " + this.VERSION + "]"; 33 return "[" + this.NAME + " " + this.VERSION + "]";
36 }, 34 },
37 35
38 //------------------------------------------------------------------------- 36 //-------------------------------------------------------------------------
39 37
40 'toString': function () { 38 'toString': function () {
41 return this.__repr__(); 39 return this.__repr__();
42 }, 40 },
43 41
44 'CREDENTIALS': 'CLIPPERZ.CREDENTIALS', 42 'CREDENTIALS': 'CLIPPERZ.CREDENTIALS',
45 'FAILURE_COUNT': 'CLIPPERZ.FAILED_LOGIN_COUNT', 43 'FAILURE_COUNT': 'CLIPPERZ.FAILED_LOGIN_COUNT',
46 'ALLOWED_RETRY': 3, 44 'ALLOWED_RETRY': 3,
47 45
48 //------------------------------------------------------------------------- 46 //-------------------------------------------------------------------------
49 47
50 'isSet': function () { 48 'isSet': function () {
51 return (this.storedCredentials() != null); 49 return (this.storedCredentials() != null);
52 }, 50 },
53 51
54 'storedCredentials': function () { 52 'storedCredentials': function () {
55 return localStorage[this.CREDENTIALS]; 53 return localStorage[this.CREDENTIALS];
56 }, 54 },
57 55
58 //------------------------------------------------------------------------- 56 //-------------------------------------------------------------------------
59 57
60 'recordFailedAttempt': function () { 58 'recordFailedAttempt': function () {
61 varfailureCount; 59 varfailureCount;
62 varresult; 60 varresult;
63 61
64 failureCount = localStorage[this.FAILURE_COUNT]; 62 failureCount = localStorage[this.FAILURE_COUNT];
65 63
66 if (failureCount == null) { 64 if (failureCount == null) {
67 failureCount = 0 65 failureCount = 0
68 } 66 }
69 67
70 failureCount ++; 68 failureCount ++;
71 69
72 if (failureCount < this.ALLOWED_RETRY) { 70 if (failureCount < this.ALLOWED_RETRY) {
73 localStorage[this.FAILURE_COUNT] = failureCount; 71 localStorage[this.FAILURE_COUNT] = failureCount;
74 result = failureCount; 72 result = failureCount;
75 } else { 73 } else {
76 this.removeLocalCredentials(); 74 this.removeLocalCredentials();
77 result = -1; 75 result = -1;
78 } 76 }
79 77
80 return result; 78 return result;
81 }, 79 },
82 80
83 'resetFailedAttemptCount': function () { 81 'resetFailedAttemptCount': function () {
84 localStorage.removeItem(this.FAILURE_COUNT); 82 localStorage.removeItem(this.FAILURE_COUNT);
85 }, 83 },
86 84
87 'failureCount': function () { 85 'failureCount': function () {
88 return localStorage[this.FAILURE_COUNT]; 86 return localStorage[this.FAILURE_COUNT];
89 }, 87 },
90 88
91 //------------------------------------------------------------------------- 89 //-------------------------------------------------------------------------
92 90
93 'deriveKeyFromPin': function (aPIN) { 91 'deriveKeyFromPin': function (aPIN) {
94 return Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(aPIN)); 92 return Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(aPIN));
95 }, 93 },
96 94
97 'credentialsWithPIN': function (aPIN) { 95 'credentialsWithPIN': function (aPIN) {
98 varbyteArrayValue; 96 varbyteArrayValue;
99 var decryptedValue; 97 var decryptedValue;
100 varresult; 98 varresult;
101 99
102 byteArrayValue = (new Clipperz.ByteArray()).appendBase64String(localStorage[this.CREDENTIALS]); 100 byteArrayValue = (new Clipperz.ByteArray()).appendBase64String(localStorage[this.CREDENTIALS]);
103 decryptedValue = Clipperz.Crypto.AES.decrypt(this.deriveKeyFromPin(aPIN), byteArrayValue).asString(); 101 decryptedValue = Clipperz.Crypto.AES.decrypt(this.deriveKeyFromPin(aPIN), byteArrayValue).asString();
104 try { 102 try {
105 result = Clipperz.Base.evalJSON(decryptedValue); 103 result = Clipperz.Base.evalJSON(decryptedValue);
106 } catch (error) { 104 } catch (error) {
107 result = {'username':'fakeusername', 'passphrase':'fakepassphrase'}; 105 result = {'username':'fakeusername', 'passphrase':'fakepassphrase'};
108 } 106 }
109 107
110 return result; 108 return result;
111 }, 109 },
112 110
113 'setCredentialsWithPIN': function (aPIN, someCredentials) { 111 'setCredentialsWithPIN': function (aPIN, someCredentials) {
114 varencodedValue; 112 varencodedValue;
115 varbyteArrayValue; 113 varbyteArrayValue;
116 var encryptedValue; 114 var encryptedValue;
117 115
118 encodedValue = Clipperz.Base.serializeJSON(someCredentials); 116 encodedValue = Clipperz.Base.serializeJSON(someCredentials);