Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var server = http.createServer(function (req, res) {
var parsed = httpSignature.parseRequest(req)
var publicKeyPEM = publicKeyPEMs[parsed.keyId]
var verified = httpSignature.verifySignature(parsed, publicKeyPEM)
res.writeHead(verified ? 200 : 400)
res.end()
})
function parseSignature(request, options) {
var opts = options || {};
opts.algorithms = OPTIONS.algorithms;
try {
return httpSignature.parseRequest(request, options);
} catch (e) {
throw new InvalidHeaderError(
'Authorization header invalid: ' + e.message
);
}
}
function parseSignature(request) {
try {
return (httpSignature.parseRequest(request, OPTIONS));
} catch (e) {
throw new InvalidHeaderError('Authorization header invalid: ' +
e.message);
}
}
function parseSignature(request, options) {
options = options || {};
options.algorithms = OPTIONS.algorithms;
try {
return (httpSignature.parseRequest(request, options));
} catch (e) {
throw new InvalidHeaderError('Authorization header invalid: ' +
e.message);
}
}
function parseSignature(request, options) {
options = options || {};
options.algorithms = OPTIONS.algorithms;
try {
return (httpSignature.parseRequest(request, options));
} catch (e) {
throw new InvalidHeaderError('Authorization header invalid: ' +
e.message);
}
}
async isAuthorized(req) {
try {
const keyResolver = this._keyResolver
const parsed = httpSignature.parseRequest(req, undefined)
const publicKey = await keyResolver.getKey(parsed.keyId)
if (httpSignature.verifySignature(parsed, publicKey)) {
return true
}
this._logger.error('Forbidden - failed verifySignature')
return false
} catch (error) {
this._logger.exception(error)
return false
}
}
}