Titanium JIRA Archive
Appcelerator Community (AC)

[AC-1901] Javascript Whirlpool implementation causes null-pointer exception

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionCannot Reproduce
Resolution Date2014-01-12T06:23:44.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelscore, defect, ios
ReporterKenan Sulayman
AssigneeRitu Agrawal
Created2013-12-10T03:07:07.000+0000
Updated2016-03-08T07:40:49.000+0000

Description

We're requiring client-side hashing for logging into some of our company-internal infrastructure. That is, I took the same code we use on our web-login to Titanium. When pasting the attached code to /any/ place in the code, Titanium will crash with a null-pointer exception. It looks like Titanium has troubles with reading strings using the \u<0000> notation inside JavascriptCore. If you like pictures, checkout the attached screenshot. I can't really do anything without this. Is there a way to hook openSSL's crypto-functions or at least somehow get a working Whirlpool implementation? If not, let's see how this evolves.

Attachments

FileDateSize
Bildschirmfoto 2013-12-10 um 04.03.17.png2013-12-10T03:07:07.000+0000462025
Text 2013.12.10 04-01-34.txt2013-12-10T03:13:07.000+00006441

Comments

  1. Ritu Agrawal 2013-12-23

    [~kenansulayman] Would it be possible for you to provide a simple Titanium test case that can help us reproduce this issue?
  2. Ritu Agrawal 2014-01-12

    I had to add missing semi colons to the provided test case but it works fine after that. Here is the code and output. Let us know if it does not resolve your issue and we would be happy to reopen the ticket.
       var wp = (function () {
               var p, c = [],
                       u = [],
                       b, e, v, s, z, w, A;
               for (b = 8; 0 < b--;) c[b] = [];
               for (e = 0; 256 > e; e++)
                       for (b = "\u1823\uc6e8\u87b8\u014f\u36a6\ud2f5\u796f\u9152\u60bc\u9b8e\ua30c\u7b35\u1de0\ud7c2\u2e4b\ufe57\u1577\u37e5\u9ff0\u4ada\u58c9\u290a\ub1a0\u6b85\ubd5d\u10f4\ucb3e\u0567\ue427\u418b\ua77d\u95d8\ufbee\u7c66\udd17\u479e\uca2d\ubf07\uad5a\u8333\u6302\uaa71\uc819\u49d9\uf2e3\u5b88\u9a26\u32b0\ue90f\ud580\ubecd\u3448\uff7a\u905f\u2068\u1aae\ub454\u9322\u64f1\u7312\u4008\uc3ec\udba1\u8d3d\u9700\ucf2b\u7682\ud61b\ub5af\u6a50\u45f3\u30ef\u3f55\ua2ea\u65ba\u2fc0\ude1c\ufd4d\u9275\u068a\ub2e6\u0e1f\u62d4\ua896\uf9c5\u2559\u8472\u394c\u5e78\u388c\ud1a5\ue261\ub321\u9c1e\u43c7\ufc04\u5199\u6d0d\ufadf\u7e24\u3bab\uce11\u8f4e\ub7eb\u3c81\u94f7\ub913\u2cd3\ue76e\uc403\u5644\u7fa9\u2abb\uc153\udc0b\u9d6c\u3174\uf646\uac89\u14e1\u163a\u6909\u70b6\ud0ed\ucc42\u98a4\u285c\uf886".charCodeAt(e /
                               2), b = 0 == (e & 1) ? b >>> 8 : b & 255, v = b << 1, 256 <= v && (v ^= 285), s = v << 1, 256 <= s && (s ^= 285), z = s ^ b, w = s << 1, 256 <= w && (w ^= 285), A = w ^ b, c[0][e] = [0, 0], c[0][e][0] = b << 24 | b << 16 | s << 8 | b, c[0][e][1] = w << 24 | z << 16 | v << 8 | A, b = 1; 8 > b; b++) c[b][e] = [0, 0], c[b][e][0] = c[b - 1][e][0] >>> 8 | c[b - 1][e][1] << 24, c[b][e][1] = c[b - 1][e][1] >>> 8 | c[b - 1][e][0] << 24;
               u[0] = [0, 0];
               for (e = 1; 10 >= e; e++) b = 8 * (e - 1), u[e] = [0, 0], u[e][0] = c[0][b][0] & 4278190080 ^ c[1][b + 1][0] & 16711680 ^ c[2][b + 2][0] & 65280 ^ c[3][b + 3][0] & 255, u[e][1] = c[4][b + 4][1] & 4278190080 ^ c[5][b + 5][1] & 16711680 ^ c[6][b + 6][1] &
                       65280 ^ c[7][b + 7][1] & 255;
               var x = [],
                       g = [],
                       m = 0,
                       l = 0,
                       q = [],
                       n = [],
                       h = [],
                       t = [],
                       r = [],
                       y = function() {
                               var a, f, b, k, d;
                               for (f = a = 0; 8 > a; a++, f += 8) t[a] = [0, 0], t[a][0] = (g[f] & 255) << 24 ^ (g[f + 1] & 255) << 16 ^ (g[f + 2] & 255) << 8 ^ g[f + 3] & 255, t[a][1] = (g[f + 4] & 255) << 24 ^ (g[f + 5] & 255) << 16 ^ (g[f + 6] & 255) << 8 ^ g[f + 7] & 255;
                               for (a = 0; 8 > a; a++) r[a] = [0, 0], n[a] = [0, 0], r[a][0] = t[a][0] ^ (n[a][0] = q[a][0]), r[a][1] = t[a][1] ^ (n[a][1] = q[a][1]);
                               for (b = 1; 10 >= b; b++) {
                                       for (a = 0; 8 > a; a++)
                                               for (h[a] = [0, 0], d = 0, k = 56, f = 0; 8 > d; d++, k -= 8, f = 32 > k ? 1 : 0) h[a][0] ^= c[d][n[a - d & 7][f] >>> k % 32 & 255][0],
                                       h[a][1] ^= c[d][n[a - d & 7][f] >>> k % 32 & 255][1];
                                       for (a = 0; 8 > a; a++) n[a][0] = h[a][0], n[a][1] = h[a][1];
                                       n[0][0] ^= u[b][0];
                                       n[0][1] ^= u[b][1];
                                       for (a = 0; 8 > a; a++)
                                               for (h[a][0] = n[a][0], h[a][1] = n[a][1], d = 0, k = 56, f = 0; 8 > d; d++, k -= 8, f = 32 > k ? 1 : 0) h[a][0] ^= c[d][r[a - d & 7][f] >>> k % 32 & 255][0], h[a][1] ^= c[d][r[a - d & 7][f] >>> k % 32 & 255][1];
                                       for (a = 0; 8 > a; a++) r[a][0] = h[a][0], r[a][1] = h[a][1];
                               }
                               for (a = 0; 8 > a; a++) q[a][0] = q[a][0] ^ r[a][0] ^ t[a][0], q[a][1] = q[a][1] ^ r[a][1] ^ t[a][1];
                       };
               p = function(a) {
                       return p.init().add(a).finalize();
               };
               p.init =
                       function() {
                               for (var a = 32; 0 < a--;) x[a] = 0;
                               m = l = 0;
                               g = [0];
                               for (a = 8; 0 < a--;) q[a] = [0, 0];
                               return p;
               };
               p.add = function(a, f) {
                       if (!a) return p;
                       if (!f) {
                               var b, k, d, c = a.toString();
                               b = [];
                               for (k = 0; k < c.length; k++) d = c.charCodeAt(k), 256 <= d && b.push(d >>> 8 & 255), b.push(d & 255);
                               a = b;
                               f = 8 * a.length;
                       }
                       b = 0;
                       k = 8 - (f & 7) & 7;
                       d = m & 7;
                       var e, h = f,
                               c = 31;
                       for (e = 0; 0 <= c; c--) e += (x[c] & 255) + h % 256, x[c] = e & 255, e >>>= 8, h = Math.floor(h / 256);
                       for (; 8 < f;) {
                               c = a[b] << k & 255 | (a[b + 1] & 255) >>> 8 - k;
                               if (0 > c || 256 <= c) return 0;
                               g[l++] |= c >>> d;
                               m += 8 - d;
                               512 == m && (y(),
                                       m = l = 0, g = []);
                               g[l] = c << 8 - d & 255;
                               m += d;
                               f -= 8;
                               b++;
                       }
                       0 < f ? (c = a[b] << k & 255, g[l] |= c >>> d) : c = 0;
                       8 > d + f || (l++, m += 8 - d, f -= 8 - d, 512 == m && (y(), m = l = 0, g = []), g[l] = c << 8 - d & 255);
                       m += f;
                       return p;
               };
               p.finalize = function() {
                       var a, b, c, e = "",
                               d = [],
                               h = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];
                       g[l] |= 128 >>> (m & 7);
                       l++;
                       if (32 < l) {
                               for (; 64 > l;) g[l++] = 0;
                               y();
                               l = 0;
                               g = [];
                       }
                       for (; 32 > l;) g[l++] = 0;
                       g.push.apply(g,x);
                       y();
                       for (b = a = 0; 8 > a; a++, b += 8) c = q[a][0], d[b] = c >>> 24 & 255, d[b + 1] = c >>> 16 & 255, d[b + 2] = c >>> 8 & 255, d[b + 3] = c & 255, c = q[a][1], d[b + 4] = c >>> 24 & 255, d[b + 5] = c >>> 16 & 255, d[b + 6] = c >>> 8 & 255, d[b +
                               7] = c & 255;
                       for (a = 0; a < d.length; a++) e += h[d[a] >>> 4], e += h[d[a] & 15];
                       return e;
               };
       
               return p;
       })();
       
       Ti.API.info("test: " + wp("test"));
       
    [INFO] : test: b913d5bbb8e461c2c5961cbe0edcdadfd29f068225ceb37da6defcf89849368f8c6c2eb6a4c4ac75775d032a0ecfdfe8550573062b653fe92fc7b8fb3b7be8d6

JSON Source