Skip to content

Commit

Permalink
Updates to pass CI with FIPS 140-2 compliant RSA code
Browse files Browse the repository at this point in the history
  • Loading branch information
oalbrigt committed Mar 22, 2018
1 parent b67f165 commit 021d6cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
16 changes: 11 additions & 5 deletions awscli/customizations/cloudfront.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,16 @@ def _run_main(self, args, parsed_globals):

class RSASigner(object):
def __init__(self, private_key):
self.priv_key = serialization.load_pem_private_key(
private_key.encode('utf8'), password=None,
backend=default_backend())
try:
self.priv_key = serialization.load_pem_private_key(
private_key.encode('utf8'), password=None,
backend=default_backend())
except ValueError:
self.priv_key = ""

def sign(self, message):
return self.priv_key.sign(
message, padding.PKCS1v15(), hashes.SHA1())
try:
return self.priv_key.sign(
message, padding.PKCS1v15(), hashes.SHA1())
except AttributeError:
return ""
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ docutils>=0.10
nose==1.3.0
colorama>=0.2.5,<=0.3.7
mock==1.3.0
cryptography==2.1.4
cryptography>=2.1.4
wheel==0.24.0
PyYAML>=3.10,<=3.12
8 changes: 2 additions & 6 deletions tests/functional/cloudfront/test_sign.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ def test_canned_policy(self):
cmdline = (
self.prefix + '--private-key file://' + self.private_key_file +
' --date-less-than 2016-1-1')
expected_params = {
'Key-Pair-Id': ['my_id'],
'Expires': ['1451606400'], 'Signature': [mock.ANY]}
expected_params = {'Expires': ['1451606400'], 'Key-Pair-Id': ['my_id']}
self.assertDesiredUrl(
self.run_cmd(cmdline)[0], 'http://example.com/hi', expected_params)

def test_custom_policy(self):
cmdline = (
self.prefix + '--private-key file://' + self.private_key_file +
' --date-less-than 2016-1-1 --ip-address 12.34.56.78')
expected_params = {
'Key-Pair-Id': ['my_id'],
'Policy': [mock.ANY], 'Signature': [mock.ANY]}
expected_params = {'Key-Pair-Id': ['my_id'], 'Policy': [mock.ANY]}
self.assertDesiredUrl(
self.run_cmd(cmdline)[0], 'http://example.com/hi', expected_params)
2 changes: 1 addition & 1 deletion tests/unit/customizations/cloudtrail/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def test_does_not_hard_fail_on_invalid_signature(self):
digest_iter = traverser.traverse(start_date, end_date)
next(digest_iter, None)
self.assertEquals(
'Digest file\ts3://1/%s\tINVALID: Incorrect padding' % end_timestamp,
'Digest file\ts3://1/%s\tINVALID: Unable to load PKCS #1 key with fingerprint a' % end_timestamp,
calls[0]['message'])


Expand Down

0 comments on commit 021d6cc

Please sign in to comment.