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