Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to sig v4 #82

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/aws/ses/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ module SES
DEFAULT_HOST = 'email.us-east-1.amazonaws.com'

DEFAULT_MESSAGE_ID_DOMAIN = 'email.amazonses.com'


DEFAULT_SIGNATURE_VERSION = 4

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dev from AWS SES here. Thanks for this initiative. Sigv4 is not just going to be the default, it's going to be the only signing method supported in the near future, so I don't think backward compatibility applies here, only Sigv4 can remain


USER_AGENT = 'github-aws-ses-ruby-gem'

# Encodes the given string with the secret_access_key by taking the
Expand Down Expand Up @@ -107,10 +109,11 @@ def initialize( options = {} )
:path => "/",
:user_agent => USER_AGENT,
:proxy_server => nil,
:region => DEFAULT_REGION
:region => DEFAULT_REGION,
:signature_version => DEFAULT_SIGNATURE_VERSION,
}.merge(options)

@signature_version = options[:signature_version] || 2
@signature_version = options[:signature_version]
@server = options[:server]
@message_id_domain = options[:message_id_domain]
@proxy_server = options[:proxy_server]
Expand Down Expand Up @@ -194,7 +197,7 @@ def request(action, params = {})
end

# Set the Authorization header using AWS signed header authentication
def get_aws_auth_param(timestamp, secret_access_key, action = '', signature_version = 2)
def get_aws_auth_param(timestamp, secret_access_key, action = '', signature_version = self.DEFAULT_SIGNATURE_VERSION)
raise(ArgumentError, "signature_version must be `2` or `4`") unless signature_version == 2 || signature_version == 4
encoded_canonical = SES.encode(secret_access_key, timestamp, false)

Expand Down
13 changes: 4 additions & 9 deletions test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_ses_authorization_header_v2
secret_access_key: aws_secret_access_key
)

assert_equal 'AWS3-HTTPS AWSAccessKeyId=fake_aws_key_id, Algorithm=HmacSHA256, Signature=eHh/cPIJJUc1+RMCueAi50EPlYxkZNXMrxtGxjkBD1w=', base.get_aws_auth_param(timestamp.httpdate, aws_secret_access_key)
assert_equal 'AWS3-HTTPS AWSAccessKeyId=fake_aws_key_id, Algorithm=HmacSHA256, Signature=eHh/cPIJJUc1+RMCueAi50EPlYxkZNXMrxtGxjkBD1w=', base.get_aws_auth_param(timestamp.httpdate, aws_secret_access_key, 'DescribeRegions', 2)
end

def test_ses_authorization_header_v4
Expand All @@ -58,13 +58,11 @@ def test_ses_authorization_header_v4
::Timecop.freeze(time)

base = ::AWS::SES::Base.new(
server: 'ec2.amazonaws.com',
signature_version: 4,
access_key_id: aws_access_key_id,
secret_access_key: aws_secret_access_key
)

assert_equal 'AWS4-HMAC-SHA256 Credential=fake_aws_key_id/20200702/us-east-1/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=c0465b36efd110b14a1c6dcca3e105085ed2bfb2a3fd3b3586cc459326ab43aa', base.get_aws_auth_param(time.httpdate, aws_secret_access_key, 'DescribeRegions', 4)
assert_equal 'AWS4-HMAC-SHA256 Credential=fake_aws_key_id/20200702/us-east-1/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=b872601457070ab98e7038bdcd4dc1f5eab586ececf9908525474408b0740515', base.get_aws_auth_param(time.httpdate, aws_secret_access_key, 'DescribeRegions', 4)
Timecop.return
end

Expand All @@ -75,13 +73,12 @@ def test_ses_authorization_header_v4_changed_host
::Timecop.freeze(time)

base = ::AWS::SES::Base.new(
server: 'email.us-east-1.amazonaws.com',
signature_version: 4,
server: 'ec2.amazonaws.com',
access_key_id: aws_access_key_id,
secret_access_key: aws_secret_access_key
)

assert_equal 'AWS4-HMAC-SHA256 Credential=fake_aws_key_id/20200702/us-east-1/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=b872601457070ab98e7038bdcd4dc1f5eab586ececf9908525474408b0740515', base.get_aws_auth_param(time.httpdate, aws_secret_access_key, 'DescribeRegions', 4)
assert_equal 'AWS4-HMAC-SHA256 Credential=fake_aws_key_id/20200702/us-east-1/ec2/aws4_request, SignedHeaders=host;x-amz-date, Signature=c0465b36efd110b14a1c6dcca3e105085ed2bfb2a3fd3b3586cc459326ab43aa', base.get_aws_auth_param(time.httpdate, aws_secret_access_key, 'DescribeRegions', 4)
Timecop.return
end

Expand All @@ -92,8 +89,6 @@ def test_ses_authorization_header_v4_changed_region
::Timecop.freeze(time)

base = ::AWS::SES::Base.new(
server: 'email.us-east-1.amazonaws.com',
signature_version: 4,
access_key_id: aws_access_key_id,
secret_access_key: aws_secret_access_key,
region: 'eu-west-1'
Expand Down