author | Clipperz <info@clipperz.com> | 2013-01-08 15:21:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-08 15:21:04 (UTC) |
commit | 816fc35420a434b1d54ae5833d617608f7456048 (patch) (unidiff) | |
tree | 95b8caf354083593d7775e4dda6f4c556b44a2d9 /frontend/gamma/js/Clipperz/PM/PIN.js | |
parent | 267603e3aa3cf0029411e67ae14018b52344c296 (diff) | |
download | clipperz-816fc35420a434b1d54ae5833d617608f7456048.zip clipperz-816fc35420a434b1d54ae5833d617608f7456048.tar.gz clipperz-816fc35420a434b1d54ae5833d617608f7456048.tar.bz2 |
Updated version of /gamma
Tons of changes, included a new draft of the mobile version (still VERY rough)
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/PIN.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/PIN.js | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/PIN.js b/frontend/gamma/js/Clipperz/PM/PIN.js new file mode 100644 index 0000000..bc932b2 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/PIN.js | |||
@@ -0,0 +1,134 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz Community Edition. | ||
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | ||
8 | refer to http://www.clipperz.com. | ||
9 | |||
10 | * Clipperz Community Edition is free software: you can redistribute | ||
11 | it and/or modify it under the terms of the GNU Affero General Public | ||
12 | License as published by the Free Software Foundation, either version | ||
13 | 3 of the License, or (at your option) any later version. | ||
14 | |||
15 | * Clipperz Community Edition is distributed in the hope that it will | ||
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
18 | See the GNU Affero General Public License for more details. | ||
19 | |||
20 | * You should have received a copy of the GNU Affero General Public | ||
21 | License along with Clipperz Community Edition. If not, see | ||
22 | <http://www.gnu.org/licenses/>. | ||
23 | |||
24 | */ | ||
25 | |||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
27 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
28 | if (typeof(Clipperz.PM.PIN) == 'undefined') { Clipperz.PM.PIN = {}; } | ||
29 | |||
30 | MochiKit.Base.update(Clipperz.PM.PIN, { | ||
31 | |||
32 | //------------------------------------------------------------------------- | ||
33 | |||
34 | '__repr__': function () { | ||
35 | return "[" + this.NAME + " " + this.VERSION + "]"; | ||
36 | }, | ||
37 | |||
38 | //------------------------------------------------------------------------- | ||
39 | |||
40 | 'toString': function () { | ||
41 | return this.__repr__(); | ||
42 | }, | ||
43 | |||
44 | 'CREDENTIALS': 'CLIPPERZ.CREDENTIALS', | ||
45 | 'FAILURE_COUNT': 'CLIPPERZ.FAILED_LOGIN_COUNT', | ||
46 | 'ALLOWED_RETRY': 3, | ||
47 | |||
48 | //------------------------------------------------------------------------- | ||
49 | |||
50 | 'isSet': function () { | ||
51 | return (this.storedCredentials() != null); | ||
52 | }, | ||
53 | |||
54 | 'storedCredentials': function () { | ||
55 | return localStorage[this.CREDENTIALS]; | ||
56 | }, | ||
57 | |||
58 | //------------------------------------------------------------------------- | ||
59 | |||
60 | 'recordFailedAttempt': function () { | ||
61 | varfailureCount; | ||
62 | varresult; | ||
63 | |||
64 | failureCount = localStorage[this.FAILURE_COUNT]; | ||
65 | |||
66 | if (failureCount == null) { | ||
67 | failureCount = 0 | ||
68 | } | ||
69 | |||
70 | failureCount ++; | ||
71 | |||
72 | if (failureCount < this.ALLOWED_RETRY) { | ||
73 | localStorage[this.FAILURE_COUNT] = failureCount; | ||
74 | result = failureCount; | ||
75 | } else { | ||
76 | this.removeLocalCredentials(); | ||
77 | result = -1; | ||
78 | } | ||
79 | |||
80 | return result; | ||
81 | }, | ||
82 | |||
83 | 'resetFailedAttemptCount': function () { | ||
84 | localStorage.removeItem(this.FAILURE_COUNT); | ||
85 | }, | ||
86 | |||
87 | 'failureCount': function () { | ||
88 | return localStorage[this.FAILURE_COUNT]; | ||
89 | }, | ||
90 | |||
91 | //------------------------------------------------------------------------- | ||
92 | |||
93 | 'deriveKeyFromPin': function (aPIN) { | ||
94 | return Clipperz.Crypto.SHA.sha256(new Clipperz.ByteArray(aPIN)); | ||
95 | }, | ||
96 | |||
97 | 'credentialsWithPIN': function (aPIN) { | ||
98 | varbyteArrayValue; | ||
99 | var decryptedValue; | ||
100 | varresult; | ||
101 | |||
102 | byteArrayValue = (new Clipperz.ByteArray()).appendBase64String(localStorage[this.CREDENTIALS]); | ||
103 | decryptedValue = Clipperz.Crypto.AES.decrypt(this.deriveKeyFromPin(aPIN), byteArrayValue).asString(); | ||
104 | try { | ||
105 | result = Clipperz.Base.evalJSON(decryptedValue); | ||
106 | } catch (error) { | ||
107 | result = {'username':'fakeusername', 'passphrase':'fakepassphrase'}; | ||
108 | } | ||
109 | |||
110 | return result; | ||
111 | }, | ||
112 | |||
113 | 'setCredentialsWithPIN': function (aPIN, someCredentials) { | ||
114 | varencodedValue; | ||
115 | varbyteArrayValue; | ||
116 | var encryptedValue; | ||
117 | |||
118 | encodedValue = Clipperz.Base.serializeJSON(someCredentials); | ||
119 | byteArrayValue = new Clipperz.ByteArray(encodedValue); | ||
120 | encryptedValue = Clipperz.Crypto.AES.encrypt(this.deriveKeyFromPin(aPIN), byteArrayValue).toBase64String(); | ||
121 | |||
122 | localStorage[this.CREDENTIALS] = encryptedValue; | ||
123 | }, | ||
124 | |||
125 | 'removeLocalCredentials': function () { | ||
126 | localStorage.removeItem(this.CREDENTIALS); | ||
127 | localStorage.removeItem(this.FAILURE_COUNT); | ||
128 | }, | ||
129 | |||
130 | //------------------------------------------------------------------------- | ||
131 | __syntaxFix__: "syntax fix" | ||
132 | |||
133 | }); | ||
134 | |||