Diffstat (limited to 'frontend/beta/js/Clipperz/Crypto/SRP.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Crypto/SRP.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Crypto/SRP.js b/frontend/beta/js/Clipperz/Crypto/SRP.js index 3b25275..8cc80ba 100644 --- a/frontend/beta/js/Clipperz/Crypto/SRP.js +++ b/frontend/beta/js/Clipperz/Crypto/SRP.js | |||
@@ -1,214 +1,212 @@ | |||
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 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { | 24 | try { if (typeof(Clipperz.ByteArray) == 'undefined') { throw ""; }} catch (e) { |
27 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; | 25 | throw "Clipperz.Crypto.PRNG depends on Clipperz.ByteArray!"; |
28 | } | 26 | } |
29 | 27 | ||
30 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { | 28 | try { if (typeof(Clipperz.Crypto.BigInt) == 'undefined') { throw ""; }} catch (e) { |
31 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.BigInt!"; | 29 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.BigInt!"; |
32 | } | 30 | } |
33 | 31 | ||
34 | try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { | 32 | try { if (typeof(Clipperz.Crypto.PRNG) == 'undefined') { throw ""; }} catch (e) { |
35 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.PRNG!"; | 33 | throw "Clipperz.Crypto.SRP depends on Clipperz.Crypto.PRNG!"; |
36 | } | 34 | } |
37 | 35 | ||
38 | if (typeof(Clipperz.Crypto.SRP) == 'undefined') { Clipperz.Crypto.SRP = {}; } | 36 | if (typeof(Clipperz.Crypto.SRP) == 'undefined') { Clipperz.Crypto.SRP = {}; } |
39 | 37 | ||
40 | Clipperz.Crypto.SRP.VERSION = "0.1"; | 38 | Clipperz.Crypto.SRP.VERSION = "0.1"; |
41 | Clipperz.Crypto.SRP.NAME = "Clipperz.Crypto.SRP"; | 39 | Clipperz.Crypto.SRP.NAME = "Clipperz.Crypto.SRP"; |
42 | 40 | ||
43 | //############################################################################# | 41 | //############################################################################# |
44 | 42 | ||
45 | MochiKit.Base.update(Clipperz.Crypto.SRP, { | 43 | MochiKit.Base.update(Clipperz.Crypto.SRP, { |
46 | 44 | ||
47 | '_n': null, | 45 | '_n': null, |
48 | '_g': null, | 46 | '_g': null, |
49 | //------------------------------------------------------------------------- | 47 | //------------------------------------------------------------------------- |
50 | 48 | ||
51 | 'n': function() { | 49 | 'n': function() { |
52 | if (Clipperz.Crypto.SRP._n == null) { | 50 | if (Clipperz.Crypto.SRP._n == null) { |
53 | Clipperz.Crypto.SRP._n = new Clipperz.Crypto.BigInt("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); | 51 | Clipperz.Crypto.SRP._n = new Clipperz.Crypto.BigInt("115b8b692e0e045692cf280b436735c77a5a9e8a9e7ed56c965f87db5b2a2ece3", 16); |
54 | } | 52 | } |
55 | 53 | ||
56 | return Clipperz.Crypto.SRP._n; | 54 | return Clipperz.Crypto.SRP._n; |
57 | }, | 55 | }, |
58 | 56 | ||
59 | //------------------------------------------------------------------------- | 57 | //------------------------------------------------------------------------- |
60 | 58 | ||
61 | 'g': function() { | 59 | 'g': function() { |
62 | if (Clipperz.Crypto.SRP._g == null) { | 60 | if (Clipperz.Crypto.SRP._g == null) { |
63 | Clipperz.Crypto.SRP._g = new Clipperz.Crypto.BigInt(2); //eventually 5 (as suggested on the Diffi-Helmann documentation) | 61 | Clipperz.Crypto.SRP._g = new Clipperz.Crypto.BigInt(2); //eventually 5 (as suggested on the Diffi-Helmann documentation) |
64 | } | 62 | } |
65 | 63 | ||
66 | return Clipperz.Crypto.SRP._g; | 64 | return Clipperz.Crypto.SRP._g; |
67 | }, | 65 | }, |
68 | 66 | ||
69 | //----------------------------------------------------------------------------- | 67 | //----------------------------------------------------------------------------- |
70 | 68 | ||
71 | 'exception': { | 69 | 'exception': { |
72 | 'InvalidValue': new MochiKit.Base.NamedError("Clipperz.Crypto.SRP.exception.InvalidValue") | 70 | 'InvalidValue': new MochiKit.Base.NamedError("Clipperz.Crypto.SRP.exception.InvalidValue") |
73 | }, | 71 | }, |
74 | 72 | ||
75 | //------------------------------------------------------------------------- | 73 | //------------------------------------------------------------------------- |
76 | __syntaxFix__: "syntax fix" | 74 | __syntaxFix__: "syntax fix" |
77 | 75 | ||
78 | }); | 76 | }); |
79 | 77 | ||
80 | //############################################################################# | 78 | //############################################################################# |
81 | // | 79 | // |
82 | // S R P C o n n e c t i o n version 1.0 | 80 | // S R P C o n n e c t i o n version 1.0 |
83 | // | 81 | // |
84 | //============================================================================= | 82 | //============================================================================= |
85 | Clipperz.Crypto.SRP.Connection = function (args) { | 83 | Clipperz.Crypto.SRP.Connection = function (args) { |
86 | args = args || {}; | 84 | args = args || {}; |
87 | 85 | ||
88 | this._C = args.C; | 86 | this._C = args.C; |
89 | this._P = args.P; | 87 | this._P = args.P; |
90 | this.hash = args.hash; | 88 | this.hash = args.hash; |
91 | 89 | ||
92 | this._a = null; | 90 | this._a = null; |
93 | this._A = null; | 91 | this._A = null; |
94 | 92 | ||
95 | this._s = null; | 93 | this._s = null; |
96 | this._B = null; | 94 | this._B = null; |
97 | 95 | ||
98 | this._x = null; | 96 | this._x = null; |
99 | 97 | ||
100 | this._u = null; | 98 | this._u = null; |
101 | this._K = null; | 99 | this._K = null; |
102 | this._M1 = null; | 100 | this._M1 = null; |
103 | this._M2 = null; | 101 | this._M2 = null; |
104 | 102 | ||
105 | this._sessionKey = null; | 103 | this._sessionKey = null; |
106 | 104 | ||
107 | return this; | 105 | return this; |
108 | } | 106 | } |
109 | 107 | ||
110 | Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, { | 108 | Clipperz.Crypto.SRP.Connection.prototype = MochiKit.Base.update(null, { |
111 | 109 | ||
112 | 'toString': function () { | 110 | 'toString': function () { |
113 | return "Clipperz.Crypto.SRP.Connection (username: " + this.username() + "). Status: " + this.statusDescription(); | 111 | return "Clipperz.Crypto.SRP.Connection (username: " + this.username() + "). Status: " + this.statusDescription(); |
114 | }, | 112 | }, |
115 | 113 | ||
116 | //------------------------------------------------------------------------- | 114 | //------------------------------------------------------------------------- |
117 | 115 | ||
118 | 'C': function () { | 116 | 'C': function () { |
119 | return this._C; | 117 | return this._C; |
120 | }, | 118 | }, |
121 | 119 | ||
122 | //------------------------------------------------------------------------- | 120 | //------------------------------------------------------------------------- |
123 | 121 | ||
124 | 'P': function () { | 122 | 'P': function () { |
125 | return this._P; | 123 | return this._P; |
126 | }, | 124 | }, |
127 | 125 | ||
128 | //------------------------------------------------------------------------- | 126 | //------------------------------------------------------------------------- |
129 | 127 | ||
130 | 'a': function () { | 128 | 'a': function () { |
131 | if (this._a == null) { | 129 | if (this._a == null) { |
132 | this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16); | 130 | this._a = new Clipperz.Crypto.BigInt(Clipperz.Crypto.PRNG.defaultRandomGenerator().getRandomBytes(32).toHexString().substring(2), 16); |
133 | // this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10); | 131 | // this._a = new Clipperz.Crypto.BigInt("37532428169486597638072888476611365392249575518156687476805936694442691012367", 10); |
134 | //MochiKit.Logging.logDebug("SRP a: " + this._a); | 132 | //MochiKit.Logging.logDebug("SRP a: " + this._a); |
135 | } | 133 | } |
136 | 134 | ||
137 | return this._a; | 135 | return this._a; |
138 | }, | 136 | }, |
139 | 137 | ||
140 | //------------------------------------------------------------------------- | 138 | //------------------------------------------------------------------------- |
141 | 139 | ||
142 | 'A': function () { | 140 | 'A': function () { |
143 | if (this._A == null) { | 141 | if (this._A == null) { |
144 | //Warning: this value should be strictly greater than zero: how should we perform this check? | 142 | //Warning: this value should be strictly greater than zero: how should we perform this check? |
145 | this._A = Clipperz.Crypto.SRP.g().powerModule(this.a(), Clipperz.Crypto.SRP.n()); | 143 | this._A = Clipperz.Crypto.SRP.g().powerModule(this.a(), Clipperz.Crypto.SRP.n()); |
146 | 144 | ||
147 | if (this._A.equals(0)) { | 145 | if (this._A.equals(0)) { |
148 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'A' to 0."); | 146 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'A' to 0."); |
149 | throw Clipperz.Crypto.SRP.exception.InvalidValue; | 147 | throw Clipperz.Crypto.SRP.exception.InvalidValue; |
150 | } | 148 | } |
151 | //MochiKit.Logging.logDebug("SRP A: " + this._A); | 149 | //MochiKit.Logging.logDebug("SRP A: " + this._A); |
152 | } | 150 | } |
153 | 151 | ||
154 | return this._A; | 152 | return this._A; |
155 | }, | 153 | }, |
156 | 154 | ||
157 | //------------------------------------------------------------------------- | 155 | //------------------------------------------------------------------------- |
158 | 156 | ||
159 | 's': function () { | 157 | 's': function () { |
160 | return this._s; | 158 | return this._s; |
161 | //MochiKit.Logging.logDebug("SRP s: " + this._S); | 159 | //MochiKit.Logging.logDebug("SRP s: " + this._S); |
162 | }, | 160 | }, |
163 | 161 | ||
164 | 'set_s': function(aValue) { | 162 | 'set_s': function(aValue) { |
165 | this._s = aValue; | 163 | this._s = aValue; |
166 | }, | 164 | }, |
167 | 165 | ||
168 | //------------------------------------------------------------------------- | 166 | //------------------------------------------------------------------------- |
169 | 167 | ||
170 | 'B': function () { | 168 | 'B': function () { |
171 | return this._B; | 169 | return this._B; |
172 | }, | 170 | }, |
173 | 171 | ||
174 | 'set_B': function(aValue) { | 172 | 'set_B': function(aValue) { |
175 | //Warning: this value should be strictly greater than zero: how should we perform this check? | 173 | //Warning: this value should be strictly greater than zero: how should we perform this check? |
176 | if (! aValue.equals(0)) { | 174 | if (! aValue.equals(0)) { |
177 | this._B = aValue; | 175 | this._B = aValue; |
178 | //MochiKit.Logging.logDebug("SRP B: " + this._B); | 176 | //MochiKit.Logging.logDebug("SRP B: " + this._B); |
179 | } else { | 177 | } else { |
180 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'B' to 0."); | 178 | MochiKit.Logging.logError("Clipperz.Crypto.SRP.Connection: trying to set 'B' to 0."); |
181 | throw Clipperz.Crypto.SRP.exception.InvalidValue; | 179 | throw Clipperz.Crypto.SRP.exception.InvalidValue; |
182 | } | 180 | } |
183 | }, | 181 | }, |
184 | 182 | ||
185 | //------------------------------------------------------------------------- | 183 | //------------------------------------------------------------------------- |
186 | 184 | ||
187 | 'x': function () { | 185 | 'x': function () { |
188 | if (this._x == null) { | 186 | if (this._x == null) { |
189 | this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16); | 187 | this._x = new Clipperz.Crypto.BigInt(this.stringHash(this.s().asString(16, 64) + this.P()), 16); |
190 | //MochiKit.Logging.logDebug("SRP x: " + this._x); | 188 | //MochiKit.Logging.logDebug("SRP x: " + this._x); |
191 | } | 189 | } |
192 | 190 | ||
193 | return this._x; | 191 | return this._x; |
194 | }, | 192 | }, |
195 | 193 | ||
196 | //------------------------------------------------------------------------- | 194 | //------------------------------------------------------------------------- |
197 | 195 | ||
198 | 'u': function () { | 196 | 'u': function () { |
199 | if (this._u == null) { | 197 | if (this._u == null) { |
200 | this._u = new Clipperz.Crypto.BigInt(this.stringHash(this.B().asString()), 16); | 198 | this._u = new Clipperz.Crypto.BigInt(this.stringHash(this.B().asString()), 16); |
201 | //MochiKit.Logging.logDebug("SRP u: " + this._u); | 199 | //MochiKit.Logging.logDebug("SRP u: " + this._u); |
202 | } | 200 | } |
203 | 201 | ||
204 | return this._u; | 202 | return this._u; |
205 | }, | 203 | }, |
206 | 204 | ||
207 | //------------------------------------------------------------------------- | 205 | //------------------------------------------------------------------------- |
208 | 206 | ||
209 | 'S': function () { | 207 | 'S': function () { |
210 | if (this._S == null) { | 208 | if (this._S == null) { |
211 | var bigint; | 209 | var bigint; |
212 | varsrp; | 210 | varsrp; |
213 | 211 | ||
214 | bigint = Clipperz.Crypto.BigInt; | 212 | bigint = Clipperz.Crypto.BigInt; |