browser.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /*
  2. HTTP Hawk Authentication Scheme
  3. Copyright (c) 2012-2013, Eran Hammer <eran@hueniverse.com>
  4. MIT Licensed
  5. */
  6. // Declare namespace
  7. var hawk = {};
  8. // Export if used as a module
  9. if (typeof module !== "undefined" && module.exports) {
  10. module.exports = hawk;
  11. }
  12. hawk.client = {
  13. // Generate an Authorization header for a given request
  14. /*
  15. uri: 'http://example.com/resource?a=b'
  16. method: HTTP verb (e.g. 'GET', 'POST')
  17. options: {
  18. // Required
  19. credentials: {
  20. id: 'dh37fgj492je',
  21. key: 'aoijedoaijsdlaksjdl',
  22. algorithm: 'sha256' // 'sha1', 'sha256'
  23. },
  24. // Optional
  25. ext: 'application-specific', // Application specific data sent via the ext attribute
  26. timestamp: Date.now() / 1000, // A pre-calculated timestamp in seconds
  27. nonce: '2334f34f', // A pre-generated nonce
  28. localtimeOffsetMsec: 400, // Time offset to sync with server time (ignored if timestamp provided)
  29. payload: '{"some":"payload"}', // UTF-8 encoded string for body hash generation (ignored if hash provided)
  30. contentType: 'application/json', // Payload content-type (ignored if hash provided)
  31. hash: 'U4MKKSmiVxk37JCCrAVIjV=', // Pre-calculated payload hash
  32. app: '24s23423f34dx', // Oz application id
  33. dlg: '234sz34tww3sd' // Oz delegated-by application id
  34. }
  35. */
  36. header: function (uri, method, options) {
  37. var result = {
  38. field: '',
  39. artifacts: {}
  40. };
  41. // Validate inputs
  42. if (!uri || (typeof uri !== 'string' && typeof uri !== 'object') ||
  43. !method || typeof method !== 'string' ||
  44. !options || typeof options !== 'object') {
  45. result.err = 'Invalid argument type';
  46. return result;
  47. }
  48. // Application time
  49. var timestamp = options.timestamp || Math.floor((hawk.utils.now() + (options.localtimeOffsetMsec || 0)) / 1000)
  50. // Validate credentials
  51. var credentials = options.credentials;
  52. if (!credentials ||
  53. !credentials.id ||
  54. !credentials.key ||
  55. !credentials.algorithm) {
  56. result.err = 'Invalid credential object';
  57. return result;
  58. }
  59. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  60. result.err = 'Unknown algorithm';
  61. return result;
  62. }
  63. // Parse URI
  64. if (typeof uri === 'string') {
  65. uri = hawk.utils.parseUri(uri);
  66. }
  67. // Calculate signature
  68. var artifacts = {
  69. ts: timestamp,
  70. nonce: options.nonce || hawk.utils.randomString(6),
  71. method: method,
  72. resource: uri.relative,
  73. host: uri.hostname,
  74. port: uri.port,
  75. hash: options.hash,
  76. ext: options.ext,
  77. app: options.app,
  78. dlg: options.dlg
  79. };
  80. result.artifacts = artifacts;
  81. // Calculate payload hash
  82. if (!artifacts.hash &&
  83. options.hasOwnProperty('payload')) {
  84. artifacts.hash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
  85. }
  86. var mac = hawk.crypto.calculateMac('header', credentials, artifacts);
  87. // Construct header
  88. var hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''; // Other falsey values allowed
  89. var header = 'Hawk id="' + credentials.id +
  90. '", ts="' + artifacts.ts +
  91. '", nonce="' + artifacts.nonce +
  92. (artifacts.hash ? '", hash="' + artifacts.hash : '') +
  93. (hasExt ? '", ext="' + hawk.utils.escapeHeaderAttribute(artifacts.ext) : '') +
  94. '", mac="' + mac + '"';
  95. if (artifacts.app) {
  96. header += ', app="' + artifacts.app +
  97. (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"';
  98. }
  99. result.field = header;
  100. return result;
  101. },
  102. // Validate server response
  103. /*
  104. request: object created via 'new XMLHttpRequest()' after response received
  105. artifacts: object recieved from header().artifacts
  106. options: {
  107. payload: optional payload received
  108. required: specifies if a Server-Authorization header is required. Defaults to 'false'
  109. }
  110. */
  111. authenticate: function (request, credentials, artifacts, options) {
  112. options = options || {};
  113. if (request.getResponseHeader('www-authenticate')) {
  114. // Parse HTTP WWW-Authenticate header
  115. var attributes = hawk.utils.parseAuthorizationHeader(request.getResponseHeader('www-authenticate'), ['ts', 'tsm', 'error']);
  116. if (!attributes) {
  117. return false;
  118. }
  119. if (attributes.ts) {
  120. var tsm = hawk.crypto.calculateTsMac(attributes.ts, credentials);
  121. if (tsm !== attributes.tsm) {
  122. return false;
  123. }
  124. hawk.utils.setNtpOffset(attributes.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
  125. }
  126. }
  127. // Parse HTTP Server-Authorization header
  128. if (!request.getResponseHeader('server-authorization') &&
  129. !options.required) {
  130. return true;
  131. }
  132. var attributes = hawk.utils.parseAuthorizationHeader(request.getResponseHeader('server-authorization'), ['mac', 'ext', 'hash']);
  133. if (!attributes) {
  134. return false;
  135. }
  136. var modArtifacts = {
  137. ts: artifacts.ts,
  138. nonce: artifacts.nonce,
  139. method: artifacts.method,
  140. resource: artifacts.resource,
  141. host: artifacts.host,
  142. port: artifacts.port,
  143. hash: attributes.hash,
  144. ext: attributes.ext,
  145. app: artifacts.app,
  146. dlg: artifacts.dlg
  147. };
  148. var mac = hawk.crypto.calculateMac('response', credentials, modArtifacts);
  149. if (mac !== attributes.mac) {
  150. return false;
  151. }
  152. if (!options.hasOwnProperty('payload')) {
  153. return true;
  154. }
  155. if (!attributes.hash) {
  156. return false;
  157. }
  158. var calculatedHash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, request.getResponseHeader('content-type'));
  159. return (calculatedHash === attributes.hash);
  160. },
  161. message: function (host, port, message, options) {
  162. // Validate inputs
  163. if (!host || typeof host !== 'string' ||
  164. !port || typeof port !== 'number' ||
  165. message === null || message === undefined || typeof message !== 'string' ||
  166. !options || typeof options !== 'object') {
  167. return null;
  168. }
  169. // Application time
  170. var timestamp = options.timestamp || Math.floor((hawk.utils.now() + (options.localtimeOffsetMsec || 0)) / 1000)
  171. // Validate credentials
  172. var credentials = options.credentials;
  173. if (!credentials ||
  174. !credentials.id ||
  175. !credentials.key ||
  176. !credentials.algorithm) {
  177. // Invalid credential object
  178. return null;
  179. }
  180. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  181. return null;
  182. }
  183. // Calculate signature
  184. var artifacts = {
  185. ts: timestamp,
  186. nonce: options.nonce || hawk.utils.randomString(6),
  187. host: host,
  188. port: port,
  189. hash: hawk.crypto.calculatePayloadHash(message, credentials.algorithm)
  190. };
  191. // Construct authorization
  192. var result = {
  193. id: credentials.id,
  194. ts: artifacts.ts,
  195. nonce: artifacts.nonce,
  196. hash: artifacts.hash,
  197. mac: hawk.crypto.calculateMac('message', credentials, artifacts)
  198. };
  199. return result;
  200. },
  201. authenticateTimestamp: function (message, credentials, updateClock) { // updateClock defaults to true
  202. var tsm = hawk.crypto.calculateTsMac(message.ts, credentials);
  203. if (tsm !== message.tsm) {
  204. return false;
  205. }
  206. if (updateClock !== false) {
  207. hawk.utils.setNtpOffset(message.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
  208. }
  209. return true;
  210. }
  211. };
  212. hawk.crypto = {
  213. headerVersion: '1',
  214. algorithms: ['sha1', 'sha256'],
  215. calculateMac: function (type, credentials, options) {
  216. var normalized = hawk.crypto.generateNormalizedString(type, options);
  217. var hmac = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()](normalized, credentials.key);
  218. return hmac.toString(CryptoJS.enc.Base64);
  219. },
  220. generateNormalizedString: function (type, options) {
  221. var normalized = 'hawk.' + hawk.crypto.headerVersion + '.' + type + '\n' +
  222. options.ts + '\n' +
  223. options.nonce + '\n' +
  224. (options.method || '').toUpperCase() + '\n' +
  225. (options.resource || '') + '\n' +
  226. options.host.toLowerCase() + '\n' +
  227. options.port + '\n' +
  228. (options.hash || '') + '\n';
  229. if (options.ext) {
  230. normalized += options.ext.replace('\\', '\\\\').replace('\n', '\\n');
  231. }
  232. normalized += '\n';
  233. if (options.app) {
  234. normalized += options.app + '\n' +
  235. (options.dlg || '') + '\n';
  236. }
  237. return normalized;
  238. },
  239. calculatePayloadHash: function (payload, algorithm, contentType) {
  240. var hash = CryptoJS.algo[algorithm.toUpperCase()].create();
  241. hash.update('hawk.' + hawk.crypto.headerVersion + '.payload\n');
  242. hash.update(hawk.utils.parseContentType(contentType) + '\n');
  243. hash.update(payload || '');
  244. hash.update('\n');
  245. return hash.finalize().toString(CryptoJS.enc.Base64);
  246. },
  247. calculateTsMac: function (ts, credentials) {
  248. var hash = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()]('hawk.' + hawk.crypto.headerVersion + '.ts\n' + ts + '\n', credentials.key);
  249. return hash.toString(CryptoJS.enc.Base64);
  250. }
  251. };
  252. hawk.utils = {
  253. storage: { // localStorage compatible interface
  254. _cache: {},
  255. setItem: function (key, value) {
  256. hawk.utils.storage._cache[key] = value;
  257. },
  258. getItem: function (key) {
  259. return hawk.utils.storage._cache[key];
  260. }
  261. },
  262. setStorage: function (storage) {
  263. var ntpOffset = hawk.utils.getNtpOffset() || 0;
  264. hawk.utils.storage = storage;
  265. hawk.utils.setNtpOffset(ntpOffset);
  266. },
  267. setNtpOffset: function (offset) {
  268. try {
  269. hawk.utils.storage.setItem('hawk_ntp_offset', offset);
  270. }
  271. catch (err) {
  272. console.error('[hawk] could not write to storage.');
  273. console.error(err);
  274. }
  275. },
  276. getNtpOffset: function () {
  277. return parseInt(hawk.utils.storage.getItem('hawk_ntp_offset') || '0', 10);
  278. },
  279. now: function () {
  280. return Date.now() + hawk.utils.getNtpOffset();
  281. },
  282. escapeHeaderAttribute: function (attribute) {
  283. return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
  284. },
  285. parseContentType: function (header) {
  286. if (!header) {
  287. return '';
  288. }
  289. return header.split(';')[0].trim().toLowerCase();
  290. },
  291. parseAuthorizationHeader: function (header, keys) {
  292. if (!header) {
  293. return null;
  294. }
  295. var headerParts = header.match(/^(\w+)(?:\s+(.*))?$/); // Header: scheme[ something]
  296. if (!headerParts) {
  297. return null;
  298. }
  299. var scheme = headerParts[1];
  300. if (scheme.toLowerCase() !== 'hawk') {
  301. return null;
  302. }
  303. var attributesString = headerParts[2];
  304. if (!attributesString) {
  305. return null;
  306. }
  307. var attributes = {};
  308. var verify = attributesString.replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, function ($0, $1, $2) {
  309. // Check valid attribute names
  310. if (keys.indexOf($1) === -1) {
  311. return;
  312. }
  313. // Allowed attribute value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9
  314. if ($2.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~]+$/) === null) {
  315. return;
  316. }
  317. // Check for duplicates
  318. if (attributes.hasOwnProperty($1)) {
  319. return;
  320. }
  321. attributes[$1] = $2;
  322. return '';
  323. });
  324. if (verify !== '') {
  325. return null;
  326. }
  327. return attributes;
  328. },
  329. randomString: function (size) {
  330. var randomSource = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  331. var len = randomSource.length;
  332. var result = [];
  333. for (var i = 0; i < size; ++i) {
  334. result[i] = randomSource[Math.floor(Math.random() * len)];
  335. }
  336. return result.join('');
  337. },
  338. parseUri: function (input) {
  339. // Based on: parseURI 1.2.2
  340. // http://blog.stevenlevithan.com/archives/parseuri
  341. // (c) Steven Levithan <stevenlevithan.com>
  342. // MIT License
  343. var keys = ['source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'hostname', 'port', 'resource', 'relative', 'pathname', 'directory', 'file', 'query', 'fragment'];
  344. var uriRegex = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?(((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?)(?:#(.*))?)/;
  345. var uriByNumber = uriRegex.exec(input);
  346. var uri = {};
  347. var i = 15;
  348. while (i--) {
  349. uri[keys[i]] = uriByNumber[i] || '';
  350. }
  351. if (uri.port === null ||
  352. uri.port === '') {
  353. uri.port = (uri.protocol.toLowerCase() === 'http' ? '80' : (uri.protocol.toLowerCase() === 'https' ? '443' : ''));
  354. }
  355. return uri;
  356. }
  357. };
  358. // Based on: Crypto-JS v3.1.2
  359. // Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
  360. // http://code.google.com/p/crypto-js/
  361. // http://code.google.com/p/crypto-js/wiki/License
  362. var CryptoJS=CryptoJS||function(h,r){var k={},l=k.lib={},n=function(){},f=l.Base={extend:function(a){n.prototype=this;var b=new n;a&&b.mixIn(a);b.hasOwnProperty("init")||(b.init=function(){b.$super.init.apply(this,arguments)});b.init.prototype=b;b.$super=this;return b},create:function(){var a=this.extend();a.init.apply(a,arguments);return a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}},j=l.WordArray=f.extend({init:function(a,b){a=this.words=a||[];this.sigBytes=b!=r?b:4*a.length},toString:function(a){return(a||s).stringify(this)},concat:function(a){var b=this.words,d=a.words,c=this.sigBytes;a=a.sigBytes;this.clamp();if(c%4)for(var e=0;e<a;e++)b[c+e>>>2]|=(d[e>>>2]>>>24-8*(e%4)&255)<<24-8*((c+e)%4);else if(65535<d.length)for(e=0;e<a;e+=4)b[c+e>>>2]=d[e>>>2];else b.push.apply(b,d);this.sigBytes+=a;return this},clamp:function(){var a=this.words,b=this.sigBytes;a[b>>>2]&=4294967295<<32-8*(b%4);a.length=h.ceil(b/4)},clone:function(){var a=f.clone.call(this);a.words=this.words.slice(0);return a},random:function(a){for(var b=[],d=0;d<a;d+=4)b.push(4294967296*h.random()|0);return new j.init(b,a)}}),m=k.enc={},s=m.Hex={stringify:function(a){var b=a.words;a=a.sigBytes;for(var d=[],c=0;c<a;c++){var e=b[c>>>2]>>>24-8*(c%4)&255;d.push((e>>>4).toString(16));d.push((e&15).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c<b;c+=2)d[c>>>3]|=parseInt(a.substr(c,2),16)<<24-4*(c%8);return new j.init(d,b/2)}},p=m.Latin1={stringify:function(a){var b=a.words;a=a.sigBytes;for(var d=[],c=0;c<a;c++)d.push(String.fromCharCode(b[c>>>2]>>>24-8*(c%4)&255));return d.join("")},parse:function(a){for(var b=a.length,d=[],c=0;c<b;c++)d[c>>>2]|=(a.charCodeAt(c)&255)<<24-8*(c%4);return new j.init(d,b)}},t=m.Utf8={stringify:function(a){try{return decodeURIComponent(escape(p.stringify(a)))}catch(b){throw Error("Malformed UTF-8 data");}},parse:function(a){return p.parse(unescape(encodeURIComponent(a)))}},q=l.BufferedBlockAlgorithm=f.extend({reset:function(){this._data=new j.init;this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=t.parse(a));this._data.concat(a);this._nDataBytes+=a.sigBytes},_process:function(a){var b=this._data,d=b.words,c=b.sigBytes,e=this.blockSize,f=c/(4*e),f=a?h.ceil(f):h.max((f|0)-this._minBufferSize,0);a=f*e;c=h.min(4*a,c);if(a){for(var g=0;g<a;g+=e)this._doProcessBlock(d,g);g=d.splice(0,a);b.sigBytes-=c}return new j.init(g,c)},clone:function(){var a=f.clone.call(this);a._data=this._data.clone();return a},_minBufferSize:0});l.Hasher=q.extend({cfg:f.extend(),init:function(a){this.cfg=this.cfg.extend(a);this.reset()},reset:function(){q.reset.call(this);this._doReset()},update:function(a){this._append(a);this._process();return this},finalize:function(a){a&&this._append(a);return this._doFinalize()},blockSize:16,_createHelper:function(a){return function(b,d){return(new a.init(d)).finalize(b)}},_createHmacHelper:function(a){return function(b,d){return(new u.HMAC.init(a,d)).finalize(b)}}});var u=k.algo={};return k}(Math);
  363. (function () { var k = CryptoJS, b = k.lib, m = b.WordArray, l = b.Hasher, d = [], b = k.algo.SHA1 = l.extend({ _doReset: function () { this._hash = new m.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]) }, _doProcessBlock: function (n, p) { for (var a = this._hash.words, e = a[0], f = a[1], h = a[2], j = a[3], b = a[4], c = 0; 80 > c; c++) { if (16 > c) d[c] = n[p + c] | 0; else { var g = d[c - 3] ^ d[c - 8] ^ d[c - 14] ^ d[c - 16]; d[c] = g << 1 | g >>> 31 } g = (e << 5 | e >>> 27) + b + d[c]; g = 20 > c ? g + ((f & h | ~f & j) + 1518500249) : 40 > c ? g + ((f ^ h ^ j) + 1859775393) : 60 > c ? g + ((f & h | f & j | h & j) - 1894007588) : g + ((f ^ h ^ j) - 899497514); b = j; j = h; h = f << 30 | f >>> 2; f = e; e = g } a[0] = a[0] + e | 0; a[1] = a[1] + f | 0; a[2] = a[2] + h | 0; a[3] = a[3] + j | 0; a[4] = a[4] + b | 0 }, _doFinalize: function () { var b = this._data, d = b.words, a = 8 * this._nDataBytes, e = 8 * b.sigBytes; d[e >>> 5] |= 128 << 24 - e % 32; d[(e + 64 >>> 9 << 4) + 14] = Math.floor(a / 4294967296); d[(e + 64 >>> 9 << 4) + 15] = a; b.sigBytes = 4 * d.length; this._process(); return this._hash }, clone: function () { var b = l.clone.call(this); b._hash = this._hash.clone(); return b } }); k.SHA1 = l._createHelper(b); k.HmacSHA1 = l._createHmacHelper(b) })();
  364. (function (k) { for (var g = CryptoJS, h = g.lib, v = h.WordArray, j = h.Hasher, h = g.algo, s = [], t = [], u = function (q) { return 4294967296 * (q - (q | 0)) | 0 }, l = 2, b = 0; 64 > b;) { var d; a: { d = l; for (var w = k.sqrt(d), r = 2; r <= w; r++) if (!(d % r)) { d = !1; break a } d = !0 } d && (8 > b && (s[b] = u(k.pow(l, 0.5))), t[b] = u(k.pow(l, 1 / 3)), b++); l++ } var n = [], h = h.SHA256 = j.extend({ _doReset: function () { this._hash = new v.init(s.slice(0)) }, _doProcessBlock: function (q, h) { for (var a = this._hash.words, c = a[0], d = a[1], b = a[2], k = a[3], f = a[4], g = a[5], j = a[6], l = a[7], e = 0; 64 > e; e++) { if (16 > e) n[e] = q[h + e] | 0; else { var m = n[e - 15], p = n[e - 2]; n[e] = ((m << 25 | m >>> 7) ^ (m << 14 | m >>> 18) ^ m >>> 3) + n[e - 7] + ((p << 15 | p >>> 17) ^ (p << 13 | p >>> 19) ^ p >>> 10) + n[e - 16] } m = l + ((f << 26 | f >>> 6) ^ (f << 21 | f >>> 11) ^ (f << 7 | f >>> 25)) + (f & g ^ ~f & j) + t[e] + n[e]; p = ((c << 30 | c >>> 2) ^ (c << 19 | c >>> 13) ^ (c << 10 | c >>> 22)) + (c & d ^ c & b ^ d & b); l = j; j = g; g = f; f = k + m | 0; k = b; b = d; d = c; c = m + p | 0 } a[0] = a[0] + c | 0; a[1] = a[1] + d | 0; a[2] = a[2] + b | 0; a[3] = a[3] + k | 0; a[4] = a[4] + f | 0; a[5] = a[5] + g | 0; a[6] = a[6] + j | 0; a[7] = a[7] + l | 0 }, _doFinalize: function () { var d = this._data, b = d.words, a = 8 * this._nDataBytes, c = 8 * d.sigBytes; b[c >>> 5] |= 128 << 24 - c % 32; b[(c + 64 >>> 9 << 4) + 14] = k.floor(a / 4294967296); b[(c + 64 >>> 9 << 4) + 15] = a; d.sigBytes = 4 * b.length; this._process(); return this._hash }, clone: function () { var b = j.clone.call(this); b._hash = this._hash.clone(); return b } }); g.SHA256 = j._createHelper(h); g.HmacSHA256 = j._createHmacHelper(h) })(Math);
  365. (function(){var c=CryptoJS,k=c.enc.Utf8;c.algo.HMAC=c.lib.Base.extend({init:function(a,b){a=this._hasher=new a.init;"string"==typeof b&&(b=k.parse(b));var c=a.blockSize,e=4*c;b.sigBytes>e&&(b=a.finalize(b));b.clamp();for(var f=this._oKey=b.clone(),g=this._iKey=b.clone(),h=f.words,j=g.words,d=0;d<c;d++)h[d]^=1549556828,j[d]^=909522486;f.sigBytes=g.sigBytes=e;this.reset()},reset:function(){var a=this._hasher;a.reset();a.update(this._iKey)},update:function(a){this._hasher.update(a);return this},finalize:function(a){var b=this._hasher;a=b.finalize(a);b.reset();return b.finalize(this._oKey.clone().concat(a))}})})();
  366. (function(){var h=CryptoJS,j=h.lib.WordArray;h.enc.Base64={stringify:function(b){var e=b.words,f=b.sigBytes,c=this._map;b.clamp();b=[];for(var a=0;a<f;a+=3)for(var d=(e[a>>>2]>>>24-8*(a%4)&255)<<16|(e[a+1>>>2]>>>24-8*((a+1)%4)&255)<<8|e[a+2>>>2]>>>24-8*((a+2)%4)&255,g=0;4>g&&a+0.75*g<f;g++)b.push(c.charAt(d>>>6*(3-g)&63));if(e=c.charAt(64))for(;b.length%4;)b.push(e);return b.join("")},parse:function(b){var e=b.length,f=this._map,c=f.charAt(64);c&&(c=b.indexOf(c),-1!=c&&(e=c));for(var c=[],a=0,d=0;d<e;d++)if(d%4){var g=f.indexOf(b.charAt(d-1))<<2*(d%4),h=f.indexOf(b.charAt(d))>>>6-2*(d%4);c[a>>>2]|=(g|h)<<24-8*(a%4);a++}return j.create(c,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}})();