Merge lp:~nik90/cliffhanger/fix-authentication-error into lp:~flashback-dev/cliffhanger/trunk

Proposed by Nekhelesh Ramananthan
Status: Merged
Merged at revision: 49
Proposed branch: lp:~nik90/cliffhanger/fix-authentication-error
Merge into: lp:~flashback-dev/cliffhanger/trunk
Diff against target: 405 lines (+214/-146)
4 files modified
Flashback.json (+1/-1)
backend/sha1.js (+201/-144)
manifest.json (+1/-1)
ui/TraktLogin.qml (+11/-0)
To merge this branch: bzr merge lp:~nik90/cliffhanger/fix-authentication-error
Reviewer Review Type Date Requested Status
Flashback Dev Pending
Review via email: mp+213267@code.launchpad.net

Commit message

1298989

Description of the change

Fixed the authentication error and provided a way to show/hide the password in clear text.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Flashback.json'
2--- Flashback.json 2013-12-12 12:30:07 +0000
3+++ Flashback.json 2014-03-28 13:53:23 +0000
4@@ -3,4 +3,4 @@
5 "networking"
6 ],
7 "policy_version": 1
8-}
9+}
10\ No newline at end of file
11
12=== modified file 'backend/sha1.js'
13--- backend/sha1.js 2013-11-21 22:11:26 +0000
14+++ backend/sha1.js 2014-03-28 13:53:23 +0000
15@@ -1,145 +1,202 @@
16-function sha1 (str) {
17- // http://kevin.vanzonneveld.net
18- // + original by: Webtoolkit.info (http://www.webtoolkit.info/)
19- // + namespaced by: Michael White (http://getsprink.com)
20- // + input by: Brett Zamir (http://brett-zamir.me)
21- // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
22- // - depends on: utf8_encode
23- // * example 1: sha1('Kevin van Zonneveld');
24- // * returns 1: '54916d2e62f65b3afa6e192e6a601cdbe5cb5897'
25- var rotate_left = function (n, s) {
26- var t4 = (n << s) | (n >>> (32 - s));
27- return t4;
28- };
29-
30-/*var lsb_hex = function (val) { // Not in use; needed?
31- var str="";
32- var i;
33- var vh;
34- var vl;
35-
36- for ( i=0; i<=6; i+=2 ) {
37- vh = (val>>>(i*4+4))&0x0f;
38- vl = (val>>>(i*4))&0x0f;
39- str += vh.toString(16) + vl.toString(16);
40- }
41- return str;
42- };*/
43-
44- var cvt_hex = function (val) {
45- var str = "";
46- var i;
47- var v;
48-
49- for (i = 7; i >= 0; i--) {
50- v = (val >>> (i * 4)) & 0x0f;
51- str += v.toString(16);
52- }
53- return str;
54- };
55-
56- var blockstart;
57- var i, j;
58- var W = new Array(80);
59- var H0 = 0x67452301;
60- var H1 = 0xEFCDAB89;
61- var H2 = 0x98BADCFE;
62- var H3 = 0x10325476;
63- var H4 = 0xC3D2E1F0;
64- var A, B, C, D, E;
65- var temp;
66-
67- str = encodeURIComponent(str);
68- var str_len = str.length;
69-
70- var word_array = [];
71- for (i = 0; i < str_len - 3; i += 4) {
72- j = str.charCodeAt(i) << 24 | str.charCodeAt(i + 1) << 16 | str.charCodeAt(i + 2) << 8 | str.charCodeAt(i + 3);
73- word_array.push(j);
74- }
75-
76- switch (str_len % 4) {
77- case 0:
78- i = 0x080000000;
79- break;
80- case 1:
81- i = str.charCodeAt(str_len - 1) << 24 | 0x0800000;
82- break;
83- case 2:
84- i = str.charCodeAt(str_len - 2) << 24 | str.charCodeAt(str_len - 1) << 16 | 0x08000;
85- break;
86- case 3:
87- i = str.charCodeAt(str_len - 3) << 24 | str.charCodeAt(str_len - 2) << 16 | str.charCodeAt(str_len - 1) << 8 | 0x80;
88- break;
89- }
90-
91- word_array.push(i);
92-
93- while ((word_array.length % 16) != 14) {
94- word_array.push(0);
95- }
96-
97- word_array.push(str_len >>> 29);
98- word_array.push((str_len << 3) & 0x0ffffffff);
99-
100- for (blockstart = 0; blockstart < word_array.length; blockstart += 16) {
101- for (i = 0; i < 16; i++) {
102- W[i] = word_array[blockstart + i];
103- }
104- for (i = 16; i <= 79; i++) {
105- W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
106- }
107-
108-
109- A = H0;
110- B = H1;
111- C = H2;
112- D = H3;
113- E = H4;
114-
115- for (i = 0; i <= 19; i++) {
116- temp = (rotate_left(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
117- E = D;
118- D = C;
119- C = rotate_left(B, 30);
120- B = A;
121- A = temp;
122- }
123-
124- for (i = 20; i <= 39; i++) {
125- temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
126- E = D;
127- D = C;
128- C = rotate_left(B, 30);
129- B = A;
130- A = temp;
131- }
132-
133- for (i = 40; i <= 59; i++) {
134- temp = (rotate_left(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
135- E = D;
136- D = C;
137- C = rotate_left(B, 30);
138- B = A;
139- A = temp;
140- }
141-
142- for (i = 60; i <= 79; i++) {
143- temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
144- E = D;
145- D = C;
146- C = rotate_left(B, 30);
147- B = A;
148- A = temp;
149- }
150-
151- H0 = (H0 + A) & 0x0ffffffff;
152- H1 = (H1 + B) & 0x0ffffffff;
153- H2 = (H2 + C) & 0x0ffffffff;
154- H3 = (H3 + D) & 0x0ffffffff;
155- H4 = (H4 + E) & 0x0ffffffff;
156- }
157-
158- temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
159- return temp.toLowerCase();
160+/*
161+ * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
162+ * in FIPS PUB 180-1
163+ * Version 2.1a Copyright Paul Johnston 2000 - 2002.
164+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
165+ * Distributed under the BSD License
166+ * See http://pajhome.org.uk/crypt/md5 for details.
167+ */
168+
169+/*
170+ * Configurable variables. You may need to tweak these to be compatible with
171+ * the server-side, but the defaults work in most cases.
172+ */
173+var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
174+var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
175+var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
176+
177+/*
178+ * These are the functions you'll usually want to call
179+ * They take string arguments and return either hex or base-64 encoded strings
180+ */
181+function sha1(s){return binb2hex(core_sha1(str2binb(s),s.length * chrsz));}
182+function b64_sha1(s){return binb2b64(core_sha1(str2binb(s),s.length * chrsz));}
183+function str_sha1(s){return binb2str(core_sha1(str2binb(s),s.length * chrsz));}
184+function hex_hmac_sha1(key, data){ return binb2hex(core_hmac_sha1(key, data));}
185+function b64_hmac_sha1(key, data){ return binb2b64(core_hmac_sha1(key, data));}
186+function str_hmac_sha1(key, data){ return binb2str(core_hmac_sha1(key, data));}
187+
188+/*
189+ * Perform a simple self-test to see if the VM is working
190+ */
191+function sha1_vm_test()
192+{
193+ return sha1("abc") == "a9993e364706816aba3e25717850c26c9cd0d89d";
194+}
195+
196+/*
197+ * Calculate the SHA-1 of an array of big-endian words, and a bit length
198+ */
199+function core_sha1(x, len)
200+{
201+ /* append padding */
202+ x[len >> 5] |= 0x80 << (24 - len % 32);
203+ x[((len + 64 >> 9) << 4) + 15] = len;
204+
205+ var w = Array(80);
206+ var a = 1732584193;
207+ var b = -271733879;
208+ var c = -1732584194;
209+ var d = 271733878;
210+ var e = -1009589776;
211+
212+ for(var i = 0; i < x.length; i += 16)
213+ {
214+ var olda = a;
215+ var oldb = b;
216+ var oldc = c;
217+ var oldd = d;
218+ var olde = e;
219+
220+ for(var j = 0; j < 80; j++)
221+ {
222+ if(j < 16) w[j] = x[i + j];
223+ else w[j] = rol(w[j-3] ^ w[j-8] ^ w[j-14] ^ w[j-16], 1);
224+ var t = safe_add(safe_add(rol(a, 5), sha1_ft(j, b, c, d)),
225+ safe_add(safe_add(e, w[j]), sha1_kt(j)));
226+ e = d;
227+ d = c;
228+ c = rol(b, 30);
229+ b = a;
230+ a = t;
231+ }
232+
233+ a = safe_add(a, olda);
234+ b = safe_add(b, oldb);
235+ c = safe_add(c, oldc);
236+ d = safe_add(d, oldd);
237+ e = safe_add(e, olde);
238+ }
239+ return Array(a, b, c, d, e);
240+
241+}
242+
243+/*
244+ * Perform the appropriate triplet combination function for the current
245+ * iteration
246+ */
247+function sha1_ft(t, b, c, d)
248+{
249+ if(t < 20) return (b & c) | ((~b) & d);
250+ if(t < 40) return b ^ c ^ d;
251+ if(t < 60) return (b & c) | (b & d) | (c & d);
252+ return b ^ c ^ d;
253+}
254+
255+/*
256+ * Determine the appropriate additive constant for the current iteration
257+ */
258+function sha1_kt(t)
259+{
260+ return (t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
261+ (t < 60) ? -1894007588 : -899497514;
262+}
263+
264+/*
265+ * Calculate the HMAC-SHA1 of a key and some data
266+ */
267+function core_hmac_sha1(key, data)
268+{
269+ var bkey = str2binb(key);
270+ if(bkey.length > 16) bkey = core_sha1(bkey, key.length * chrsz);
271+
272+ var ipad = Array(16), opad = Array(16);
273+ for(var i = 0; i < 16; i++)
274+ {
275+ ipad[i] = bkey[i] ^ 0x36363636;
276+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
277+ }
278+
279+ var hash = core_sha1(ipad.concat(str2binb(data)), 512 + data.length * chrsz);
280+ return core_sha1(opad.concat(hash), 512 + 160);
281+}
282+
283+/*
284+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
285+ * to work around bugs in some JS interpreters.
286+ */
287+function safe_add(x, y)
288+{
289+ var lsw = (x & 0xFFFF) + (y & 0xFFFF);
290+ var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
291+ return (msw << 16) | (lsw & 0xFFFF);
292+}
293+
294+/*
295+ * Bitwise rotate a 32-bit number to the left.
296+ */
297+function rol(num, cnt)
298+{
299+ return (num << cnt) | (num >>> (32 - cnt));
300+}
301+
302+/*
303+ * Convert an 8-bit or 16-bit string to an array of big-endian words
304+ * In 8-bit function, characters >255 have their hi-byte silently ignored.
305+ */
306+function str2binb(str)
307+{
308+ var bin = Array();
309+ var mask = (1 << chrsz) - 1;
310+ for(var i = 0; i < str.length * chrsz; i += chrsz)
311+ bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (32 - chrsz - i%32);
312+ return bin;
313+}
314+
315+/*
316+ * Convert an array of big-endian words to a string
317+ */
318+function binb2str(bin)
319+{
320+ var str = "";
321+ var mask = (1 << chrsz) - 1;
322+ for(var i = 0; i < bin.length * 32; i += chrsz)
323+ str += String.fromCharCode((bin[i>>5] >>> (32 - chrsz - i%32)) & mask);
324+ return str;
325+}
326+
327+/*
328+ * Convert an array of big-endian words to a hex string.
329+ */
330+function binb2hex(binarray)
331+{
332+ var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
333+ var str = "";
334+ for(var i = 0; i < binarray.length * 4; i++)
335+ {
336+ str += hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8+4)) & 0xF) +
337+ hex_tab.charAt((binarray[i>>2] >> ((3 - i%4)*8 )) & 0xF);
338+ }
339+ return str;
340+}
341+
342+/*
343+ * Convert an array of big-endian words to a base-64 string
344+ */
345+function binb2b64(binarray)
346+{
347+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
348+ var str = "";
349+ for(var i = 0; i < binarray.length * 4; i += 3)
350+ {
351+ var triplet = (((binarray[i >> 2] >> 8 * (3 - i %4)) & 0xFF) << 16)
352+ | (((binarray[i+1 >> 2] >> 8 * (3 - (i+1)%4)) & 0xFF) << 8 )
353+ | ((binarray[i+2 >> 2] >> 8 * (3 - (i+2)%4)) & 0xFF);
354+ for(var j = 0; j < 4; j++)
355+ {
356+ if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
357+ else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
358+ }
359+ }
360+ return str;
361 }
362
363=== added file 'graphics/unwatched_gray.png'
364Binary files graphics/unwatched_gray.png 1970-01-01 00:00:00 +0000 and graphics/unwatched_gray.png 2014-03-28 13:53:23 +0000 differ
365=== added file 'graphics/watched_gray.png'
366Binary files graphics/watched_gray.png 1970-01-01 00:00:00 +0000 and graphics/watched_gray.png 2014-03-28 13:53:23 +0000 differ
367=== modified file 'manifest.json'
368--- manifest.json 2014-03-14 09:51:08 +0000
369+++ manifest.json 2014-03-28 13:53:23 +0000
370@@ -12,4 +12,4 @@
371 "name": "com.ubuntu.developer.nik90.flashback",
372 "title": "Flashback",
373 "version": "0.3.2"
374-}
375+}
376\ No newline at end of file
377
378=== modified file 'ui/TraktLogin.qml'
379--- ui/TraktLogin.qml 2014-03-08 14:09:52 +0000
380+++ ui/TraktLogin.qml 2014-03-28 13:53:23 +0000
381@@ -154,6 +154,7 @@
382
383 TextField {
384 id: password
385+ hasClearButton: false
386 placeholderText: i18n.tr("Password")
387 echoMode: TextInput.Password
388 onTextChanged: !isLogin ? password_timer.restart() : undefined
389@@ -162,6 +163,16 @@
390 fillMode: Image.PreserveAspectFit
391 source: Qt.resolvedUrl("../graphics/password.png")
392 }
393+ secondaryItem: Image {
394+ visible: password.text !== ""
395+ height: parent.height/1.5;
396+ fillMode: Image.PreserveAspectFit
397+ source: password.echoMode === TextInput.Password ? Qt.resolvedUrl("../graphics/watched_gray.png") : Qt.resolvedUrl("../graphics/unwatched_gray.png")
398+ MouseArea {
399+ anchors.fill: parent
400+ onClicked: password.echoMode = password.echoMode === TextInput.Password ? TextInput.Normal : TextInput.Password
401+ }
402+ }
403 }
404
405 TextField {

Subscribers

People subscribed via source and target branches