Created
December 7, 2021 09:54
-
-
Save peinwag/25e1d50708081d7b877add20985096f9 to your computer and use it in GitHub Desktop.
derive access key to smtp secret v4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'openssl' | |
require 'base64' | |
def aws_iam_smtp_password_generator(key, region) | |
# The values of the following variables should always stay the same. | |
date = "11111111" | |
service = "ses" | |
terminal = "aws4_request" | |
message = "SendRawEmail" | |
version_in_bytes = "\x04" | |
k_date = OpenSSL::HMAC.digest('sha256', "AWS4" + key, date) | |
k_region = OpenSSL::HMAC.digest('sha256', k_date, region) | |
k_service = OpenSSL::HMAC.digest('sha256', k_region, service) | |
k_terminal = OpenSSL::HMAC.digest('sha256', k_service, terminal) | |
k_message = OpenSSL::HMAC.digest('sha256', k_terminal, message) | |
signature_and_version = version_in_bytes + k_message | |
smtp_password = Base64.encode64(signature_and_version) | |
smtp_password.to_s.strip | |
end | |
print aws_iam_smtp_password_generator('<YOUR_IAM_SECRET_HERE>', "<YOUR_AWS_REGION_HERE>") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment