browser.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  9. var hawk = {
  10. internals: {}
  11. };
  12. hawk.client = {
  13. // Generate an Authorization header for a given request
  14. /*
  15. uri: 'http://example.com/resource?a=b' or object generated by hawk.utils.parseUri()
  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 header(uri, method, options) {
  37. var result = {
  38. field: '',
  39. artifacts: {}
  40. };
  41. // Validate inputs
  42. if (!uri || typeof uri !== 'string' && (typeof uri === 'undefined' ? 'undefined' : _typeof(uri)) !== 'object' || !method || typeof method !== 'string' || !options || (typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') {
  43. result.err = 'Invalid argument type';
  44. return result;
  45. }
  46. // Application time
  47. var timestamp = options.timestamp || hawk.utils.nowSec(options.localtimeOffsetMsec);
  48. // Validate credentials
  49. var credentials = options.credentials;
  50. if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) {
  51. result.err = 'Invalid credentials object';
  52. return result;
  53. }
  54. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  55. result.err = 'Unknown algorithm';
  56. return result;
  57. }
  58. // Parse URI
  59. if (typeof uri === 'string') {
  60. uri = hawk.utils.parseUri(uri);
  61. }
  62. // Calculate signature
  63. var artifacts = {
  64. ts: timestamp,
  65. nonce: options.nonce || hawk.utils.randomString(6),
  66. method: method,
  67. resource: uri.resource,
  68. host: uri.host,
  69. port: uri.port,
  70. hash: options.hash,
  71. ext: options.ext,
  72. app: options.app,
  73. dlg: options.dlg
  74. };
  75. result.artifacts = artifacts;
  76. // Calculate payload hash
  77. if (!artifacts.hash && (options.payload || options.payload === '')) {
  78. artifacts.hash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, options.contentType);
  79. }
  80. var mac = hawk.crypto.calculateMac('header', credentials, artifacts);
  81. // Construct header
  82. var hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''; // Other falsey values allowed
  83. var header = 'Hawk id="' + credentials.id + '", ts="' + artifacts.ts + '", nonce="' + artifacts.nonce + (artifacts.hash ? '", hash="' + artifacts.hash : '') + (hasExt ? '", ext="' + hawk.utils.escapeHeaderAttribute(artifacts.ext) : '') + '", mac="' + mac + '"';
  84. if (artifacts.app) {
  85. header += ', app="' + artifacts.app + (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"';
  86. }
  87. result.field = header;
  88. return result;
  89. },
  90. // Generate a bewit value for a given URI
  91. /*
  92. uri: 'http://example.com/resource?a=b'
  93. options: {
  94. // Required
  95. credentials: {
  96. id: 'dh37fgj492je',
  97. key: 'aoijedoaijsdlaksjdl',
  98. algorithm: 'sha256' // 'sha1', 'sha256'
  99. },
  100. ttlSec: 60 * 60, // TTL in seconds
  101. // Optional
  102. ext: 'application-specific', // Application specific data sent via the ext attribute
  103. localtimeOffsetMsec: 400 // Time offset to sync with server time
  104. };
  105. */
  106. bewit: function bewit(uri, options) {
  107. // Validate inputs
  108. if (!uri || typeof uri !== 'string' || !options || (typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object' || !options.ttlSec) {
  109. return '';
  110. }
  111. options.ext = options.ext === null || options.ext === undefined ? '' : options.ext; // Zero is valid value
  112. // Application time
  113. var now = hawk.utils.nowSec(options.localtimeOffsetMsec);
  114. // Validate credentials
  115. var credentials = options.credentials;
  116. if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) {
  117. return '';
  118. }
  119. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  120. return '';
  121. }
  122. // Parse URI
  123. uri = hawk.utils.parseUri(uri);
  124. // Calculate signature
  125. var exp = now + options.ttlSec;
  126. var mac = hawk.crypto.calculateMac('bewit', credentials, {
  127. ts: exp,
  128. nonce: '',
  129. method: 'GET',
  130. resource: uri.resource, // Maintain trailing '?' and query params
  131. host: uri.host,
  132. port: uri.port,
  133. ext: options.ext
  134. });
  135. // Construct bewit: id\exp\mac\ext
  136. var bewit = credentials.id + '\\' + exp + '\\' + mac + '\\' + options.ext;
  137. return hawk.utils.base64urlEncode(bewit);
  138. },
  139. // Validate server response
  140. /*
  141. request: object created via 'new XMLHttpRequest()' after response received or fetch API 'Response'
  142. artifacts: object received from header().artifacts
  143. options: {
  144. payload: optional payload received
  145. required: specifies if a Server-Authorization header is required. Defaults to 'false'
  146. }
  147. */
  148. authenticate: function authenticate(request, credentials, artifacts, options) {
  149. options = options || {};
  150. var getHeader = function getHeader(name) {
  151. // Fetch API or plain headers
  152. if (request.headers) {
  153. return typeof request.headers.get === 'function' ? request.headers.get(name) : request.headers[name];
  154. }
  155. // XMLHttpRequest
  156. return request.getResponseHeader ? request.getResponseHeader(name) : request.getHeader(name);
  157. };
  158. var wwwAuthenticate = getHeader('www-authenticate');
  159. if (wwwAuthenticate) {
  160. // Parse HTTP WWW-Authenticate header
  161. var wwwAttributes = hawk.utils.parseAuthorizationHeader(wwwAuthenticate, ['ts', 'tsm', 'error']);
  162. if (!wwwAttributes) {
  163. return false;
  164. }
  165. if (wwwAttributes.ts) {
  166. var tsm = hawk.crypto.calculateTsMac(wwwAttributes.ts, credentials);
  167. if (tsm !== wwwAttributes.tsm) {
  168. return false;
  169. }
  170. hawk.utils.setNtpSecOffset(wwwAttributes.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
  171. }
  172. }
  173. // Parse HTTP Server-Authorization header
  174. var serverAuthorization = getHeader('server-authorization');
  175. if (!serverAuthorization && !options.required) {
  176. return true;
  177. }
  178. var attributes = hawk.utils.parseAuthorizationHeader(serverAuthorization, ['mac', 'ext', 'hash']);
  179. if (!attributes) {
  180. return false;
  181. }
  182. var modArtifacts = {
  183. ts: artifacts.ts,
  184. nonce: artifacts.nonce,
  185. method: artifacts.method,
  186. resource: artifacts.resource,
  187. host: artifacts.host,
  188. port: artifacts.port,
  189. hash: attributes.hash,
  190. ext: attributes.ext,
  191. app: artifacts.app,
  192. dlg: artifacts.dlg
  193. };
  194. var mac = hawk.crypto.calculateMac('response', credentials, modArtifacts);
  195. if (mac !== attributes.mac) {
  196. return false;
  197. }
  198. if (!options.payload && options.payload !== '') {
  199. return true;
  200. }
  201. if (!attributes.hash) {
  202. return false;
  203. }
  204. var calculatedHash = hawk.crypto.calculatePayloadHash(options.payload, credentials.algorithm, getHeader('content-type'));
  205. return calculatedHash === attributes.hash;
  206. },
  207. message: function message(host, port, _message, options) {
  208. // Validate inputs
  209. if (!host || typeof host !== 'string' || !port || typeof port !== 'number' || _message === null || _message === undefined || typeof _message !== 'string' || !options || (typeof options === 'undefined' ? 'undefined' : _typeof(options)) !== 'object') {
  210. return null;
  211. }
  212. // Application time
  213. var timestamp = options.timestamp || hawk.utils.nowSec(options.localtimeOffsetMsec);
  214. // Validate credentials
  215. var credentials = options.credentials;
  216. if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) {
  217. // Invalid credential object
  218. return null;
  219. }
  220. if (hawk.crypto.algorithms.indexOf(credentials.algorithm) === -1) {
  221. return null;
  222. }
  223. // Calculate signature
  224. var artifacts = {
  225. ts: timestamp,
  226. nonce: options.nonce || hawk.utils.randomString(6),
  227. host: host,
  228. port: port,
  229. hash: hawk.crypto.calculatePayloadHash(_message, credentials.algorithm)
  230. };
  231. // Construct authorization
  232. var result = {
  233. id: credentials.id,
  234. ts: artifacts.ts,
  235. nonce: artifacts.nonce,
  236. hash: artifacts.hash,
  237. mac: hawk.crypto.calculateMac('message', credentials, artifacts)
  238. };
  239. return result;
  240. },
  241. authenticateTimestamp: function authenticateTimestamp(message, credentials, updateClock) {
  242. // updateClock defaults to true
  243. var tsm = hawk.crypto.calculateTsMac(message.ts, credentials);
  244. if (tsm !== message.tsm) {
  245. return false;
  246. }
  247. if (updateClock !== false) {
  248. hawk.utils.setNtpSecOffset(message.ts - Math.floor(Date.now() / 1000)); // Keep offset at 1 second precision
  249. }
  250. return true;
  251. }
  252. };
  253. hawk.crypto = {
  254. headerVersion: '1',
  255. algorithms: ['sha1', 'sha256'],
  256. calculateMac: function calculateMac(type, credentials, options) {
  257. var normalized = hawk.crypto.generateNormalizedString(type, options);
  258. var hmac = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()](normalized, credentials.key);
  259. return hmac.toString(CryptoJS.enc.Base64);
  260. },
  261. generateNormalizedString: function generateNormalizedString(type, options) {
  262. var normalized = 'hawk.' + hawk.crypto.headerVersion + '.' + type + '\n' + options.ts + '\n' + options.nonce + '\n' + (options.method || '').toUpperCase() + '\n' + (options.resource || '') + '\n' + options.host.toLowerCase() + '\n' + options.port + '\n' + (options.hash || '') + '\n';
  263. if (options.ext) {
  264. normalized += options.ext.replace('\\', '\\\\').replace('\n', '\\n');
  265. }
  266. normalized += '\n';
  267. if (options.app) {
  268. normalized += options.app + '\n' + (options.dlg || '') + '\n';
  269. }
  270. return normalized;
  271. },
  272. calculatePayloadHash: function calculatePayloadHash(payload, algorithm, contentType) {
  273. var hash = CryptoJS.algo[algorithm.toUpperCase()].create();
  274. hash.update('hawk.' + hawk.crypto.headerVersion + '.payload\n');
  275. hash.update(hawk.utils.parseContentType(contentType) + '\n');
  276. hash.update(payload);
  277. hash.update('\n');
  278. return hash.finalize().toString(CryptoJS.enc.Base64);
  279. },
  280. calculateTsMac: function calculateTsMac(ts, credentials) {
  281. var hash = CryptoJS['Hmac' + credentials.algorithm.toUpperCase()]('hawk.' + hawk.crypto.headerVersion + '.ts\n' + ts + '\n', credentials.key);
  282. return hash.toString(CryptoJS.enc.Base64);
  283. }
  284. };
  285. // localStorage compatible interface
  286. hawk.internals.LocalStorage = function () {
  287. this._cache = {};
  288. this.length = 0;
  289. this.getItem = function (key) {
  290. return this._cache.hasOwnProperty(key) ? String(this._cache[key]) : null;
  291. };
  292. this.setItem = function (key, value) {
  293. this._cache[key] = String(value);
  294. this.length = Object.keys(this._cache).length;
  295. };
  296. this.removeItem = function (key) {
  297. delete this._cache[key];
  298. this.length = Object.keys(this._cache).length;
  299. };
  300. this.clear = function () {
  301. this._cache = {};
  302. this.length = 0;
  303. };
  304. this.key = function (i) {
  305. return Object.keys(this._cache)[i || 0];
  306. };
  307. };
  308. hawk.utils = {
  309. storage: new hawk.internals.LocalStorage(),
  310. setStorage: function setStorage(storage) {
  311. var ntpOffset = hawk.utils.storage.getItem('hawk_ntp_offset');
  312. hawk.utils.storage = storage;
  313. if (ntpOffset) {
  314. hawk.utils.setNtpSecOffset(ntpOffset);
  315. }
  316. },
  317. setNtpSecOffset: function setNtpSecOffset(offset) {
  318. try {
  319. hawk.utils.storage.setItem('hawk_ntp_offset', offset);
  320. } catch (err) {
  321. console.error('[hawk] could not write to storage.');
  322. console.error(err);
  323. }
  324. },
  325. getNtpSecOffset: function getNtpSecOffset() {
  326. var offset = hawk.utils.storage.getItem('hawk_ntp_offset');
  327. if (!offset) {
  328. return 0;
  329. }
  330. return parseInt(offset, 10);
  331. },
  332. now: function now(localtimeOffsetMsec) {
  333. return Date.now() + (localtimeOffsetMsec || 0) + hawk.utils.getNtpSecOffset() * 1000;
  334. },
  335. nowSec: function nowSec(localtimeOffsetMsec) {
  336. return Math.floor(hawk.utils.now(localtimeOffsetMsec) / 1000);
  337. },
  338. escapeHeaderAttribute: function escapeHeaderAttribute(attribute) {
  339. return attribute.replace(/\\/g, '\\\\').replace(/\"/g, '\\"');
  340. },
  341. parseContentType: function parseContentType(header) {
  342. if (!header) {
  343. return '';
  344. }
  345. return header.split(';')[0].replace(/^\s+|\s+$/g, '').toLowerCase();
  346. },
  347. parseAuthorizationHeader: function parseAuthorizationHeader(header, keys) {
  348. if (!header) {
  349. return null;
  350. }
  351. var headerParts = header.match(/^(\w+)(?:\s+(.*))?$/); // Header: scheme[ something]
  352. if (!headerParts) {
  353. return null;
  354. }
  355. var scheme = headerParts[1];
  356. if (scheme.toLowerCase() !== 'hawk') {
  357. return null;
  358. }
  359. var attributesString = headerParts[2];
  360. if (!attributesString) {
  361. return null;
  362. }
  363. var attributes = {};
  364. var verify = attributesString.replace(/(\w+)="([^"\\]*)"\s*(?:,\s*|$)/g, function ($0, $1, $2) {
  365. // Check valid attribute names
  366. if (keys.indexOf($1) === -1) {
  367. return;
  368. }
  369. // Allowed attribute value characters: !#$%&'()*+,-./:;<=>?@[]^_`{|}~ and space, a-z, A-Z, 0-9
  370. if ($2.match(/^[ \w\!#\$%&'\(\)\*\+,\-\.\/\:;<\=>\?@\[\]\^`\{\|\}~]+$/) === null) {
  371. return;
  372. }
  373. // Check for duplicates
  374. if (attributes.hasOwnProperty($1)) {
  375. return;
  376. }
  377. attributes[$1] = $2;
  378. return '';
  379. });
  380. if (verify !== '') {
  381. return null;
  382. }
  383. return attributes;
  384. },
  385. randomString: function randomString(size) {
  386. var randomSource = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  387. var len = randomSource.length;
  388. var result = [];
  389. for (var i = 0; i < size; ++i) {
  390. result[i] = randomSource[Math.floor(Math.random() * len)];
  391. }
  392. return result.join('');
  393. },
  394. // 1 2 3 4
  395. uriRegex: /^([^:]+)\:\/\/(?:[^@/]*@)?([^\/:]+)(?:\:(\d+))?([^#]*)(?:#.*)?$/, // scheme://credentials@host:port/resource#fragment
  396. parseUri: function parseUri(input) {
  397. var parts = input.match(hawk.utils.uriRegex);
  398. if (!parts) {
  399. return { host: '', port: '', resource: '' };
  400. }
  401. var scheme = parts[1].toLowerCase();
  402. var uri = {
  403. host: parts[2],
  404. port: parts[3] || (scheme === 'http' ? '80' : scheme === 'https' ? '443' : ''),
  405. resource: parts[4]
  406. };
  407. return uri;
  408. },
  409. base64urlEncode: function base64urlEncode(value) {
  410. var wordArray = CryptoJS.enc.Utf8.parse(value);
  411. var encoded = CryptoJS.enc.Base64.stringify(wordArray);
  412. return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/\=/g, '');
  413. }
  414. };
  415. // $lab:coverage:off$
  416. /* eslint-disable */
  417. // Based on: Crypto-JS v3.1.2
  418. // Copyright (c) 2009-2013, Jeff Mott. All rights reserved.
  419. // http://code.google.com/p/crypto-js/
  420. // http://code.google.com/p/crypto-js/wiki/License
  421. var CryptoJS = CryptoJS || function (h, r) {
  422. var k = {},
  423. l = k.lib = {},
  424. n = function n() {},
  425. f = l.Base = { extend: function extend(a) {
  426. n.prototype = this;var b = new n();a && b.mixIn(a);b.hasOwnProperty("init") || (b.init = function () {
  427. b.$super.init.apply(this, arguments);
  428. });b.init.prototype = b;b.$super = this;return b;
  429. }, create: function create() {
  430. var a = this.extend();a.init.apply(a, arguments);return a;
  431. }, init: function init() {}, mixIn: function mixIn(a) {
  432. for (var _b in a) {
  433. a.hasOwnProperty(_b) && (this[_b] = a[_b]);
  434. }a.hasOwnProperty("toString") && (this.toString = a.toString);
  435. }, clone: function clone() {
  436. return this.init.prototype.extend(this);
  437. } },
  438. j = l.WordArray = f.extend({ init: function init(a, b) {
  439. a = this.words = a || [];this.sigBytes = b != r ? b : 4 * a.length;
  440. }, toString: function toString(a) {
  441. return (a || s).stringify(this);
  442. }, concat: function concat(a) {
  443. var b = this.words,
  444. d = a.words,
  445. c = this.sigBytes;a = a.sigBytes;this.clamp();if (c % 4) for (var e = 0; e < a; e++) {
  446. b[c + e >>> 2] |= (d[e >>> 2] >>> 24 - 8 * (e % 4) & 255) << 24 - 8 * ((c + e) % 4);
  447. } else if (65535 < d.length) for (var _e = 0; _e < a; _e += 4) {
  448. b[c + _e >>> 2] = d[_e >>> 2];
  449. } else b.push.apply(b, d);this.sigBytes += a;return this;
  450. }, clamp: function clamp() {
  451. var a = this.words,
  452. b = this.sigBytes;a[b >>> 2] &= 4294967295 << 32 - 8 * (b % 4);a.length = h.ceil(b / 4);
  453. }, clone: function clone() {
  454. var a = f.clone.call(this);a.words = this.words.slice(0);return a;
  455. }, random: function random(a) {
  456. for (var _b2 = [], d = 0; d < a; d += 4) {
  457. _b2.push(4294967296 * h.random() | 0);
  458. }return new j.init(b, a);
  459. } }),
  460. m = k.enc = {},
  461. s = m.Hex = { stringify: function stringify(a) {
  462. var b = a.words;a = a.sigBytes;for (var d = [], c = 0; c < a; c++) {
  463. var e = b[c >>> 2] >>> 24 - 8 * (c % 4) & 255;d.push((e >>> 4).toString(16));d.push((e & 15).toString(16));
  464. }return d.join("");
  465. }, parse: function parse(a) {
  466. for (var b = a.length, d = [], c = 0; c < b; c += 2) {
  467. d[c >>> 3] |= parseInt(a.substr(c, 2), 16) << 24 - 4 * (c % 8);
  468. }return new j.init(d, b / 2);
  469. } },
  470. p = m.Latin1 = { stringify: function stringify(a) {
  471. var b = a.words;a = a.sigBytes;for (var d = [], c = 0; c < a; c++) {
  472. d.push(String.fromCharCode(b[c >>> 2] >>> 24 - 8 * (c % 4) & 255));
  473. }return d.join("");
  474. }, parse: function parse(a) {
  475. for (var b = a.length, d = [], c = 0; c < b; c++) {
  476. d[c >>> 2] |= (a.charCodeAt(c) & 255) << 24 - 8 * (c % 4);
  477. }return new j.init(d, b);
  478. } },
  479. t = m.Utf8 = { stringify: function stringify(a) {
  480. try {
  481. return decodeURIComponent(escape(p.stringify(a)));
  482. } catch (b) {
  483. throw Error("Malformed UTF-8 data");
  484. }
  485. }, parse: function parse(a) {
  486. return p.parse(unescape(encodeURIComponent(a)));
  487. } },
  488. q = l.BufferedBlockAlgorithm = f.extend({ reset: function reset() {
  489. this._data = new j.init();this._nDataBytes = 0;
  490. }, _append: function _append(a) {
  491. "string" == typeof a && (a = t.parse(a));this._data.concat(a);this._nDataBytes += a.sigBytes;
  492. }, _process: function _process(a) {
  493. var b = this._data,
  494. d = b.words,
  495. c = b.sigBytes,
  496. e = this.blockSize,
  497. f = c / (4 * e),
  498. f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0);a = f * e;c = h.min(4 * a, c);if (a) {
  499. for (var g = 0; g < a; g += e) {
  500. this._doProcessBlock(d, g);
  501. }g = d.splice(0, a);b.sigBytes -= c;
  502. }return new j.init(g, c);
  503. }, clone: function clone() {
  504. var a = f.clone.call(this);a._data = this._data.clone();return a;
  505. }, _minBufferSize: 0 });l.Hasher = q.extend({ cfg: f.extend(), init: function init(a) {
  506. this.cfg = this.cfg.extend(a);this.reset();
  507. }, reset: function reset() {
  508. q.reset.call(this);this._doReset();
  509. }, update: function update(a) {
  510. this._append(a);this._process();return this;
  511. }, finalize: function finalize(a) {
  512. a && this._append(a);return this._doFinalize();
  513. }, blockSize: 16, _createHelper: function _createHelper(a) {
  514. return function (b, d) {
  515. return new a.init(d).finalize(b);
  516. };
  517. }, _createHmacHelper: function _createHmacHelper(a) {
  518. return function (b, d) {
  519. return new u.HMAC.init(a, d).finalize(b);
  520. };
  521. } });var u = k.algo = {};return k;
  522. }(Math);
  523. (function () {
  524. var k = CryptoJS,
  525. b = k.lib,
  526. m = b.WordArray,
  527. l = b.Hasher,
  528. d = [],
  529. b = k.algo.SHA1 = l.extend({ _doReset: function _doReset() {
  530. this._hash = new m.init([1732584193, 4023233417, 2562383102, 271733878, 3285377520]);
  531. }, _doProcessBlock: function _doProcessBlock(n, p) {
  532. 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++) {
  533. if (16 > c) d[c] = n[p + c] | 0;else {
  534. var g = d[c - 3] ^ d[c - 8] ^ d[c - 14] ^ d[c - 16];d[c] = g << 1 | g >>> 31;
  535. }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;
  536. }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;
  537. }, _doFinalize: function _doFinalize() {
  538. var b = this._data,
  539. d = b.words,
  540. a = 8 * this._nDataBytes,
  541. 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;
  542. }, clone: function clone() {
  543. var b = l.clone.call(this);b._hash = this._hash.clone();return b;
  544. } });k.SHA1 = l._createHelper(b);k.HmacSHA1 = l._createHmacHelper(b);
  545. })();
  546. (function (k) {
  547. for (var g = CryptoJS, h = g.lib, v = h.WordArray, j = h.Hasher, h = g.algo, s = [], t = [], u = function u(q) {
  548. return 4294967296 * (q - (q | 0)) | 0;
  549. }, l = 2, b = 0; 64 > b;) {
  550. var d;a: {
  551. d = l;for (var w = k.sqrt(d), r = 2; r <= w; r++) {
  552. if (!(d % r)) {
  553. d = !1;break a;
  554. }
  555. }d = !0;
  556. }d && (8 > b && (s[b] = u(k.pow(l, 0.5))), t[b] = u(k.pow(l, 1 / 3)), b++);l++;
  557. }var n = [],
  558. h = h.SHA256 = j.extend({ _doReset: function _doReset() {
  559. this._hash = new v.init(s.slice(0));
  560. }, _doProcessBlock: function _doProcessBlock(q, h) {
  561. 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++) {
  562. if (16 > e) n[e] = q[h + e] | 0;else {
  563. var m = n[e - 15],
  564. 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];
  565. }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;
  566. }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;
  567. }, _doFinalize: function _doFinalize() {
  568. var d = this._data,
  569. b = d.words,
  570. a = 8 * this._nDataBytes,
  571. 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;
  572. }, clone: function clone() {
  573. var b = j.clone.call(this);b._hash = this._hash.clone();return b;
  574. } });g.SHA256 = j._createHelper(h);g.HmacSHA256 = j._createHmacHelper(h);
  575. })(Math);
  576. (function () {
  577. var c = CryptoJS,
  578. k = c.enc.Utf8;c.algo.HMAC = c.lib.Base.extend({ init: function init(a, b) {
  579. a = this._hasher = new a.init();"string" == typeof b && (b = k.parse(b));var c = a.blockSize,
  580. 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++) {
  581. h[d] ^= 1549556828, j[d] ^= 909522486;
  582. }f.sigBytes = g.sigBytes = e;this.reset();
  583. }, reset: function reset() {
  584. var a = this._hasher;a.reset();a.update(this._iKey);
  585. }, update: function update(a) {
  586. this._hasher.update(a);return this;
  587. }, finalize: function finalize(a) {
  588. var b = this._hasher;a = b.finalize(a);b.reset();return b.finalize(this._oKey.clone().concat(a));
  589. } });
  590. })();
  591. (function () {
  592. var h = CryptoJS,
  593. j = h.lib.WordArray;h.enc.Base64 = { stringify: function stringify(b) {
  594. var e = b.words,
  595. f = b.sigBytes,
  596. c = this._map;b.clamp();b = [];for (var a = 0; a < f; a += 3) {
  597. 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++) {
  598. b.push(c.charAt(d >>> 6 * (3 - g) & 63));
  599. }
  600. }if (e = c.charAt(64)) for (; b.length % 4;) {
  601. b.push(e);
  602. }return b.join("");
  603. }, parse: function parse(b) {
  604. var e = b.length,
  605. f = this._map,
  606. c = f.charAt(64);c && (c = b.indexOf(c), -1 != c && (e = c));for (var c = [], a = 0, d = 0; d < e; d++) {
  607. if (d % 4) {
  608. var g = f.indexOf(b.charAt(d - 1)) << 2 * (d % 4),
  609. h = f.indexOf(b.charAt(d)) >>> 6 - 2 * (d % 4);c[a >>> 2] |= (g | h) << 24 - 8 * (a % 4);a++;
  610. }
  611. }return j.create(c, a);
  612. }, _map: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" };
  613. })();
  614. hawk.crypto.utils = CryptoJS;
  615. // Export if used as a module
  616. if (typeof module !== 'undefined' && module.exports) {
  617. module.exports = hawk;
  618. }
  619. /* eslint-enable */
  620. // $lab:coverage:on$