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()
})
signatureIsVerified(req) {
try {
const parsed = httpSignature.parseRequest(req)
if (!httpSignature.verifySignature(parsed, publicKey)) {
console.error('Forbidden - failed verifySignature')
return false
}
} catch (error) {
console.error(error)
return false
}
return true
}
}
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
}
}
}