Skip to content

Instantly share code, notes, and snippets.

@elyscape
Last active June 21, 2016 16:24
Show Gist options
  • Save elyscape/645ca1853d8b4c77789e56b748c9f773 to your computer and use it in GitHub Desktop.
Save elyscape/645ca1853d8b4c77789e56b748c9f773 to your computer and use it in GitHub Desktop.
This script converts an AWS secret access key into an SMTP password for SES.
#!/usr/bin/env ruby
require 'openssl'
require 'base64'
require 'io/console'
VERSION = "\x02".force_encoding('BINARY').freeze
MESSAGE = 'SendRawEmail'.freeze
digest = OpenSSL::Digest.new('sha256')
print 'Please enter your secret access key: '
key = nil
STDIN.noecho do
key = gets.chomp
end
puts
signature = OpenSSL::HMAC.digest(digest, key, MESSAGE)
signature_with_version = VERSION + signature
smtp_password = Base64.encode64(signature_with_version).chomp
puts smtp_password
@elyscape
Copy link
Author

This is based on the algorithm documented here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment