summaryrefslogtreecommitdiff
path: root/node_modules/request/lib/hawk.js
diff options
context:
space:
mode:
authorLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 23:08:57 +0300
committerLinuxWizard42 <computerwizard@linuxmail.org>2022-10-12 23:08:57 +0300
commit726b81b19251674e149ccfbb1abacbd837fc6db0 (patch)
treefbdbb227dc01357eb76e8222d76185bc124c5ca6 /node_modules/request/lib/hawk.js
parent34f0890e175698940d49238097579f44e4d78c89 (diff)
downloadFlashRunner-726b81b19251674e149ccfbb1abacbd837fc6db0.tar.gz
FlashRunner-726b81b19251674e149ccfbb1abacbd837fc6db0.tar.zst
Removed files that should not have been included in git
Diffstat (limited to 'node_modules/request/lib/hawk.js')
-rw-r--r--node_modules/request/lib/hawk.js89
1 files changed, 0 insertions, 89 deletions
diff --git a/node_modules/request/lib/hawk.js b/node_modules/request/lib/hawk.js
deleted file mode 100644
index de48a98..0000000
--- a/node_modules/request/lib/hawk.js
+++ /dev/null
@@ -1,89 +0,0 @@
-'use strict'
-
-var crypto = require('crypto')
-
-function randomString (size) {
- var bits = (size + 1) * 6
- var buffer = crypto.randomBytes(Math.ceil(bits / 8))
- var string = buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '')
- return string.slice(0, size)
-}
-
-function calculatePayloadHash (payload, algorithm, contentType) {
- var hash = crypto.createHash(algorithm)
- hash.update('hawk.1.payload\n')
- hash.update((contentType ? contentType.split(';')[0].trim().toLowerCase() : '') + '\n')
- hash.update(payload || '')
- hash.update('\n')
- return hash.digest('base64')
-}
-
-exports.calculateMac = function (credentials, opts) {
- var normalized = 'hawk.1.header\n' +
- opts.ts + '\n' +
- opts.nonce + '\n' +
- (opts.method || '').toUpperCase() + '\n' +
- opts.resource + '\n' +
- opts.host.toLowerCase() + '\n' +
- opts.port + '\n' +
- (opts.hash || '') + '\n'
-
- if (opts.ext) {
- normalized = normalized + opts.ext.replace('\\', '\\\\').replace('\n', '\\n')
- }
-
- normalized = normalized + '\n'
-
- if (opts.app) {
- normalized = normalized + opts.app + '\n' + (opts.dlg || '') + '\n'
- }
-
- var hmac = crypto.createHmac(credentials.algorithm, credentials.key).update(normalized)
- var digest = hmac.digest('base64')
- return digest
-}
-
-exports.header = function (uri, method, opts) {
- var timestamp = opts.timestamp || Math.floor((Date.now() + (opts.localtimeOffsetMsec || 0)) / 1000)
- var credentials = opts.credentials
- if (!credentials || !credentials.id || !credentials.key || !credentials.algorithm) {
- return ''
- }
-
- if (['sha1', 'sha256'].indexOf(credentials.algorithm) === -1) {
- return ''
- }
-
- var artifacts = {
- ts: timestamp,
- nonce: opts.nonce || randomString(6),
- method: method,
- resource: uri.pathname + (uri.search || ''),
- host: uri.hostname,
- port: uri.port || (uri.protocol === 'http:' ? 80 : 443),
- hash: opts.hash,
- ext: opts.ext,
- app: opts.app,
- dlg: opts.dlg
- }
-
- if (!artifacts.hash && (opts.payload || opts.payload === '')) {
- artifacts.hash = calculatePayloadHash(opts.payload, credentials.algorithm, opts.contentType)
- }
-
- var mac = exports.calculateMac(credentials, artifacts)
-
- var hasExt = artifacts.ext !== null && artifacts.ext !== undefined && artifacts.ext !== ''
- var header = 'Hawk id="' + credentials.id +
- '", ts="' + artifacts.ts +
- '", nonce="' + artifacts.nonce +
- (artifacts.hash ? '", hash="' + artifacts.hash : '') +
- (hasExt ? '", ext="' + artifacts.ext.replace(/\\/g, '\\\\').replace(/"/g, '\\"') : '') +
- '", mac="' + mac + '"'
-
- if (artifacts.app) {
- header = header + ', app="' + artifacts.app + (artifacts.dlg ? '", dlg="' + artifacts.dlg : '') + '"'
- }
-
- return header
-}