const crypto = require('crypto') | |
const superagent = require('superagent') | |
const aws = require('aws-sdk') | |
const sns = new aws.SNS({ | |
apiVersion: '2010-03-31', | |
region: 'ap-northeast-1' | |
}); | |
exports.handler = async (event) => { | |
const message = JSON.parse(event.body) | |
const pemFile = await superagent.get(message.SigningCertURL) | |
const pemContent = pemFile.body.toString('utf-8') | |
const verify = crypto.createVerify('sha1WithRSAEncryption') | |
const arr = ['Message', 'MessageId', 'Subject', 'Timestamp', 'TopicArn', 'Type'] | |
arr.forEach(key => { | |
if (key in message) { | |
verify.write(`${key}\n${message[key]}\n`) | |
} | |
}) | |
verify.end() | |
const result = verify.verify(pemContent, message.Signature, 'base64') | |
console.log(result) // trueなら署名検証OK | |
const response = { | |
statusCode: 200, | |
body: JSON.stringify('Hello from Lambda!'), | |
}; | |
return response; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment