browser.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. 'use strict';
  2. /*
  3. HTTP Hawk Authentication Scheme
  4. Copyright (c) 2012-2016, Eran Hammer <eran@hammer.io>
  5. BSD Licensed
  6. */
  7. // Declare namespace
  8. const hawk = {
  9. internals: {}
  10. };
  11. hawk.client = {
  12. // Generate an Authorization header for a given request
  13. /*
  14. uri: 'http://example.com/resource?a=b' or object generated by hawk.utils.parseUri()
  15. method: HTTP verb (e.g. 'GET', 'POST')
  16. options: {
  17. // Required
  18. credentials: {
  19. id: 'dh37fgj492je',
  20. key: 'aoijedoaijsdlaksjdl',
  21. algorithm: 'sha256' // 'sha1', 'sha256'
  22. },
  23. // Optional
  24. ext: 'application-specific', // Application specific data sent via the ext attribute
  25. timestamp: Date.now() / 1000, // A pre-calculated timestamp in seconds
  26. nonce: '2334f34f', // A pre-generated nonce
  27. localtimeOffsetMsec: 400, // Time offset to sync with server time (ignored if timestamp provided)
  28. payload: '{"some":"payload"}', // UTF-8 encoded string for body hash generation (ignored if hash provided)
  29. contentType: 'application/json', // Payload content-type (ignored if hash provided)
  30. hash: 'U4MKKSmiVxk37JCCrAVIjV=', // Pre-calculated payload hash
  31. app: '24s23423f34dx', // Oz application id
  32. dlg: '234sz34tww3sd' // Oz delegated-by application id
  33. }
  34. */
  35. header: function (uri, method, options) {
  36. const result = {
  37. field: '',
  38. artifacts: {}
  39. };
  40. // Validate inputs
  41. if (!uri || (typeof uri !== 'string' && typeof uri !== 'object') ||
  42. !method || typeof method !== 'string' ||
  43. !options || typeof options !== 'object') {
  44. result.err = 'Invalid argument type';
  45. return result;
  46. }
  47. // Application time
  48. const timestamp = options.timestamp || hawk.utils.nowSec(options.localtimeOffsetMsec);
  49. // Validate credentials
  50. const credentials = options.credentials;
  51. if (!credentials ||
  52. !credentials.id ||
  53. !credentials.key ||
  54. !credentials.algorithm) {
  55. result.err = 'Invalid credentials object';
  56. return result;
  57. }
  58. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  59. result.err = 'Unknown algorithm';
  60. return result;
  61. }
  62. // Parse URI
  63. if (typeof uri === 'string') {
  64. uri = hawk.utils.parseUri(uri);
  65. }
  66. // Calculate signature
  67. const artifacts = {
  68. ts: timestamp,
  69. nonce: options.nonce || hawk.utils.randomString(6),
  70. method,
  71. resource: uri.resource,
  72. host: uri.host,
  73. port: uri.port,
  74. hash: options.hash,
  75. ext: options.ext,
  76. app: options.app,
  77. dlg: options.dlg
  78. };
  79. result.artifacts = artifacts;
  80. // Calculate payload hash
  81. if (!artifacts.hash &&
  82. (options.payload || options.payload === '')) {
  83. artifacts.hash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
  84. }
  85. const mac = hawk.crypto.calculateMac('header', credentials, artifacts);
  86. // Construct header
  87. const hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''; // Other falsey values allowed
  88. let header = 'Hawk id="' + credentials.id +
  89. '", ts="' + artifacts.ts +
  90. '", nonce="' + artifacts.nonce +
  91. (artifacts.hash ? '", hash="' + artifacts.hash : '') +
  92. (hasExt ? '", ext="' + hawk.utils.escapeHeaderAttribute(artifacts.ext) : '') +
  93. '", mac="' + mac + '"';
  94. if (artifacts.app) {
  95. header += ', app="' + artifacts.app +
  96. (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"';
  97. }
  98. result.field = header;
  99. return result;
  100. },
  101. // Generate a bewit value for a given URI
  102. /*
  103. uri: 'http://example.com/resource?a=b'
  104. options: {
  105. // Required
  106. credentials: {
  107. id: 'dh37fgj492je',
  108. key: 'aoijedoaijsdlaksjdl',
  109. algorithm: 'sha256' // 'sha1', 'sha256'
  110. },
  111. ttlSec: 60 * 60, // TTL in seconds
  112. // Optional
  113. ext: 'application-specific', // Application specific data sent via the ext attribute
  114. localtimeOffsetMsec: 400 // Time offset to sync with server time
  115. };
  116. */
  117. bewit: function (uri, options) {
  118. // Validate inputs
  119. if (!uri ||
  120. (typeof uri !== 'string') ||
  121. !options ||
  122. typeof options !== 'object' ||
  123. !options.ttlSec) {
  124. return '';
  125. }
  126. options.ext = (options.ext === null || options.ext === undefined ? '' : options.ext); // Zero is valid value
  127. // Application time
  128. const now = hawk.utils.nowSec(options.localtimeOffsetMsec);
  129. // Validate credentials
  130. const credentials = options.credentials;
  131. if (!credentials ||
  132. !credentials.id ||
  133. !credentials.key ||
  134. !credentials.algorithm) {
  135. return '';
  136. }
  137. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  138. return '';
  139. }
  140. // Parse URI
  141. uri = hawk.utils.parseUri(uri);
  142. // Calculate signature
  143. const exp = now + options.ttlSec;
  144. const mac = hawk.crypto.calculateMac('bewit', credentials, {
  145. ts: exp,
  146. nonce: '',
  147. method: 'GET',
  148. resource: uri.resource, // Maintain trailing '?' and query params
  149. host: uri.host,
  150. port: uri.port,
  151. ext: options.ext
  152. });
  153. // Construct bewit: id\exp\mac\ext
  154. const bewit = credentials.id + '\\' + exp + '\\' + mac + '\\' + options.ext;
  155. return hawk.utils.base64urlEncode(bewit);
  156. },
  157. // Validate server response
  158. /*
  159. request: object created via 'new XMLHttpRequest()' after response received or fetch API 'Response'
  160. artifacts: object received from header().artifacts
  161. options: {
  162. payload: optional payload received
  163. required: specifies if a Server-Authorization header is required. Defaults to 'false'
  164. }
  165. */
  166. authenticate: function (request, credentials, artifacts, options) {
  167. options = options || {};
  168. const getHeader = function (name) {
  169. // Fetch API or plain headers
  170. if (request.headers) {
  171. return (typeof request.headers.get === 'function' ? request.headers.get(name) : request.headers[name]);
  172. }
  173. // XMLHttpRequest
  174. return (request.getResponseHeader ? request.getResponseHeader(name) : request.getHeader(name));
  175. };
  176. const wwwAuthenticate = getHeader('www-authenticate');
  177. if (wwwAuthenticate) {
  178. // Parse HTTP WWW-Authenticate header
  179. const wwwAttributes = hawk.utils.parseAuthorizationHeader(wwwAuthenticate, ['ts', 'tsm', 'error']);
  180. if (!wwwAttributes) {
  181. return false;
  182. }
  183. if (wwwAttributes.ts) {
  184. const tsm = hawk.crypto.calculateTsMac(wwwAttributes.ts, credentials);
  185. if (tsm !== wwwAttributes.tsm) {
  186. return false;
  187. }
  188. hawk.utils.setNtpSecOffset(wwwAttributes.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
  189. }
  190. }
  191. // Parse HTTP Server-Authorization header
  192. const serverAuthorization = getHeader('server-authorization');
  193. if (!serverAuthorization &&
  194. !options.required) {
  195. return true;
  196. }
  197. const attributes = hawk.utils.parseAuthorizationHeader(serverAuthorization, ['mac', 'ext', 'hash']);
  198. if (!attributes) {
  199. return false;
  200. }
  201. const modArtifacts = {
  202. ts: artifacts.ts,
  203. nonce: artifacts.nonce,
  204. method: artifacts.method,
  205. resource: artifacts.resource,
  206. host: artifacts.host,
  207. port: artifacts.port,
  208. hash: attributes.hash,
  209. ext: attributes.ext,
  210. app: artifacts.app,
  211. dlg: artifacts.dlg
  212. };
  213. const mac = hawk.crypto.calculateMac('response', credentials, modArtifacts);
  214. if (mac !== attributes.mac) {
  215. return false;
  216. }
  217. if (!options.payload &&
  218. options.payload !== '') {
  219. return true;
  220. }
  221. if (!attributes.hash) {
  222. return false;
  223. }
  224. const calculatedHash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, getHeader('content-type'));
  225. return (calculatedHash === attributes.hash);
  226. },
  227. message: function (host, port, message, options) {
  228. // Validate inputs
  229. if (!host || typeof host !== 'string' ||
  230. !port || typeof port !== 'number' ||
  231. message === null || message === undefined || typeof message !== 'string' ||
  232. !options || typeof options !== 'object') {
  233. return null;
  234. }
  235. // Application time
  236. const timestamp = options.timestamp || hawk.utils.nowSec(options.localtimeOffsetMsec);
  237. // Validate credentials
  238. const credentials = options.credentials;
  239. if (!credentials ||
  240. !credentials.id ||
  241. !credentials.key ||
  242. !credentials.algorithm) {
  243. // Invalid credential object
  244. return null;
  245. }
  246. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  247. return null;
  248. }
  249. // Calculate signature
  250. const artifacts = {
  251. ts: timestamp,
  252. nonce: options.nonce || hawk.utils.randomString(6),
  253. host,
  254. port,
  255. hash: hawk.crypto.calculatePayloadHash(message, credentials.algorithm)
  256. };
  257. // Construct authorization
  258. const result = {
  259. id: credentials.id,
  260. ts: artifacts.ts,
  261. nonce: artifacts.nonce,
  262. hash: artifacts.hash,
  263. mac: hawk.crypto.calculateMac('message', credentials, artifacts)
  264. };
  265. return result;
  266. },
  267. authenticateTimestamp: function (message, credentials, updateClock) { // updateClock defaults to true
  268. const tsm = hawk.crypto.calculateTsMac(message.ts, credentials);
  269. if (tsm !== message.tsm) {
  270. return false;
  271. }
  272. if (updateClock !== false) {
  273. hawk.utils.setNtpSecOffset(message.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
  274. }
  275. return true;
  276. }
  277. };
  278. hawk.crypto = {
  279. headerVersion: '1',
  280. algorithms: ['sha1', 'sha256'],
  281. calculateMac: function (type, credentials, options) {
  282. const normalized = hawk.crypto.generateNormalizedString(type, options);
  283. const hmac = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()](normalized, credentials.key);
  284. return hmac.toString(CryptoJS.enc.Base64);
  285. },
  286. generateNormalizedString: function (type, options) {
  287. let normalized = 'hawk.' + hawk.crypto.headerVersion + '.' + type + '\n' +
  288. options.ts + '\n' +
  289. options.nonce + '\n' +
  290. (options.method || '').toUpperCase() + '\n' +
  291. (options.resource || '') + '\n' +
  292. options.host.toLowerCase() + '\n' +
  293. options.port + '\n' +
  294. (options.hash || '') + '\n';
  295. if (options.ext) {
  296. normalized += options.ext.replace('\\', '\\\\').replace('\n', '\\n');
  297. }
  298. normalized += '\n';
  299. if (options.app) {
  300. normalized += options.app + '\n' +
  301. (options.dlg || '') + '\n';
  302. }
  303. return normalized;
  304. },
  305. calculatePayloadHash: function (payload, algorithm, contentType) {
  306. const hash = CryptoJS.algo[algorithm.toUpperCase()].create();
  307. hash.update('hawk.' + hawk.crypto.headerVersion + '.payload\n');
  308. hash.update(hawk.utils.parseContentType(contentType) + '\n');
  309. hash.update(payload);
  310. hash.update('\n');
  311. return hash.finalize().toString(CryptoJS.enc.Base64);
  312. },
  313. calculateTsMac: function (ts, credentials) {
  314. const hash = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()]('hawk.' + hawk.crypto.headerVersion + '.ts\n' + ts + '\n', credentials.key);
  315. return hash.toString(CryptoJS.enc.Base64);
  316. }
  317. };
  318. // localStorage compatible interface
  319. hawk.internals.LocalStorage = function () {
  320. this._cache = {};
  321. this.length = 0;
  322. this.getItem = function (key) {
  323. return this._cache.hasOwnProperty(key) ? String(this._cache[key]) : null;
  324. };
  325. this.setItem = function (key, value) {
  326. this._cache[key] = String(value);
  327. this.length = Object.keys(this._cache).length;
  328. };
  329. this.removeItem = function (key) {
  330. delete this._cache[key];
  331. this.length = Object.keys(this._cache).length;
  332. };
  333. this.clear = function () {
  334. this._cache = {};
  335. this.length = 0;
  336. };
  337. this.key = function (i) {
  338. return Object.keys(this._cache)[i || 0];
  339. };
  340. };
  341. hawk.utils = {
  342. storage: new hawk.internals.LocalStorage(),
  343. setStorage: function (storage) {
  344. const ntpOffset = hawk.utils.storage.getItem('hawk_ntp_offset');
  345. hawk.utils.storage = storage;
  346. if (ntpOffset) {
  347. hawk.utils.setNtpSecOffset(ntpOffset);
  348. }
  349. },
  350. setNtpSecOffset: function (offset) {
  351. try {
  352. hawk.utils.storage.setItem('hawk_ntp_offset', offset);
  353. }
  354. catch (err) {
  355. console.error('[hawk] could not write to storage.');
  356. console.error(err);
  357. }
  358. },
  359. getNtpSecOffset: function () {
  360. const offset = hawk.utils.storage.getItem('hawk_ntp_offset');
  361. if (!offset) {
  362. return 0;
  363. }
  364. return parseInt(offset, 10);
  365. },
  366. now: function (localtimeOffsetMsec) {
  367. return Date.now() + (localtimeOffsetMsec || 0) + (hawk.utils.getNtpSecOffset() * 1000);
  368. },
  369. nowSec: function (localtimeOffsetMsec) {
  370. return Math.floor(hawk.utils.now(localtimeOffsetMsec) / 1000);
  371. },
  372. escapeHeaderAttribute: function (attribute) {
  373. return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
  374. },
  375. parseContentType: function (header) {
  376. if (!header) {
  377. return '';
  378. }
  379. return header.split(';')[0].replace(/^\s+|\s+$/g, '').toLowerCase();
  380. },
  381. parseAuthorizationHeader: function (header, keys) {
  382. if (!header) {
  383. return null;
  384. }
  385. const headerParts = header.match(/^(\w+)(?:\s+(.*))?$/); // Header: scheme[ something]
  386. if (!headerParts) {
  387. return null;
  388. }
  389. const scheme = headerParts[1];
  390. if (scheme.toLowerCase() !== 'hawk') {
  391. return null;
  392. }
  393. const attributesString = headerParts[2];
  394. if (!attributesString) {
  395. return null;
  396. }
  397. const attributes = {};
  398. const verify = attributesString.replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, ($0, $1, $2) => {
  399. // Check valid attribute names
  400. if (keys.indexOf($1) === -1) {
  401. return;
  402. }
  403. // Allowed attribute value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9
  404. if ($2.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~]+$/) === null) {
  405. return;
  406. }
  407. // Check for duplicates
  408. if (attributes.hasOwnProperty($1)) {
  409. return;
  410. }
  411. attributes[$1] = $2;
  412. return '';
  413. });
  414. if (verify !== '') {
  415. return null;
  416. }
  417. return attributes;
  418. },
  419. randomString: function (size) {
  420. const randomSource = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  421. const len = randomSource.length;
  422. const result = [];
  423. for (let i = 0; i < size; ++i) {
  424. result[i] = randomSource[Math.floor(Math.random() * len)];
  425. }
  426. return result.join('');
  427. },
  428. // 1 2 3 4
  429. uriRegex: /^([^:]+)\:\/\/(?:[^@/]*@)?([^\/:]+)(?:\:(\d+))?([^#]*)(?:#.*)?$/, // scheme://credentials@host:port/resource#fragment
  430. parseUri: function (input) {
  431. const parts = input.match(hawk.utils.uriRegex);
  432. if (!parts) {
  433. return { host: '', port: '', resource: '' };
  434. }
  435. const scheme = parts[1].toLowerCase();
  436. const uri = {
  437. host: parts[2],
  438. port: parts[3] || (scheme === 'http' ? '80' : (scheme === 'https' ? '443' : '')),
  439. resource: parts[4]
  440. };
  441. return uri;
  442. },
  443. base64urlEncode: function (value) {
  444. const wordArray = CryptoJS.enc.Utf8.parse(value);
  445. const encoded = CryptoJS.enc.Base64.stringify(wordArray);
  446. return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
  447. }
  448. };
  449. // $lab:coverage:off$
  450. /* eslint-disable */
  451. // Based on: Crypto-JS v3.1.2
  452. // Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
  453. // http://code.google.com/p/crypto-js/
  454. // http://code.google.com/p/crypto-js/wiki/License
  455. 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 (let 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 (let 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 (let 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 (let 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);
  456. (() => { 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) })();
  457. (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);
  458. (() => { 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)) } }) })();
  459. (() => { 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+/=" } })();
  460. hawk.crypto.utils = CryptoJS;
  461. // Export if used as a module
  462. if (typeof module !== 'undefined' && module.exports) {
  463. module.exports = hawk;
  464. }
  465. /* eslint-enable */
  466. // $lab:coverage:on$