Skip to content

Commit 0da456c

Browse files
authoredApr 1, 2022
Merge pull request #200 from alexa/doiron-sha256-2
update signature algorithm validation from sha-1 to sha-256
2 parents bb76642 + 99c9d44 commit 0da456c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed
 

‎ask-sdk-webservice-support/ask_sdk_webservice_support/verifier.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
SubjectAlternativeName)
3434
from cryptography.hazmat.backends import default_backend
3535
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
36-
from cryptography.hazmat.primitives.hashes import SHA1
36+
from cryptography.hazmat.primitives.hashes import SHA256
3737
from cryptography.exceptions import InvalidSignature
3838
from contextlib import closing
3939
from asn1crypto import pem
@@ -121,7 +121,7 @@ def __init__(
121121
self,
122122
signature_cert_chain_url_key=SIGNATURE_CERT_CHAIN_URL_HEADER,
123123
signature_key=SIGNATURE_HEADER,
124-
padding=PKCS1v15(), hash_algorithm=SHA1()):
124+
padding=PKCS1v15(), hash_algorithm=SHA256()):
125125
# type: (str, str, AsymmetricPadding, HashAlgorithm) -> None
126126
"""Verifier that performs request signature verification.
127127
@@ -140,7 +140,7 @@ def __init__(
140140
can also provide the Padding and the Hash Algorithm functions
141141
that is used to verify the input body. These are defaulted as
142142
:py:class:`cryptography.hazmat.primitives.asymmetric.padding.PKCS1v15`
143-
and :py:class:`cryptography.hazmat.primitives.hashes.SHA1`
143+
and :py:class:`cryptography.hazmat.primitives.hashes.SHA256`
144144
instances respectively.
145145
146146
A certificate cache is initialized, to store certificate chains
@@ -160,7 +160,7 @@ def __init__(
160160
cryptography.hazmat.primitives.asymmetric.padding.AsymmetricPadding
161161
:param hash_algorithm: Hash algorithm instance to be used
162162
to verify the hash value of the request body with the
163-
decrypted signature. Defaulted to `SHA1`
163+
decrypted signature. Defaulted to `SHA256`
164164
:type hash_algorithm:
165165
cryptography.hazmat.primitives.hashes.HashAlgorithm
166166
"""

‎ask-sdk-webservice-support/ask_sdk_webservice_support/verifier_constants.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#: Header key to be used, to retrieve request header that contains the
2626
#: request signature.
2727
#: For more info, check `link <https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html#check-request-signature>`__.
28-
SIGNATURE_HEADER = "Signature"
28+
SIGNATURE_HEADER = "Signature-256"
2929

3030
#: Case insensitive protocol to be checked on signature certificate url.
3131
#: For more info, check `link <https://developer.amazon.com/docs/custom-skills/host-a-custom-skill-as-a-web-service.html#check-request-signature>`__.

‎ask-sdk-webservice-support/tests/unit/test_verifier.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from cryptography.hazmat.backends import default_backend
3737
from cryptography.hazmat.primitives.asymmetric import rsa
3838
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
39-
from cryptography.hazmat.primitives.hashes import SHA1
39+
from cryptography.hazmat.primitives.hashes import SHA256
4040
from cryptography.x509 import Certificate, load_pem_x509_certificate
4141
from cryptography.x509.oid import NameOID
4242
from dateutil.tz import tzlocal, tzutc
@@ -102,7 +102,7 @@ def create_self_signed_certificate(self):
102102
[x509.DNSName(u"{}".format(CERT_CHAIN_DOMAIN))]),
103103
critical=False).sign(
104104
private_key=self.private_key,
105-
algorithm=SHA1(),
105+
algorithm=SHA256(),
106106
backend=default_backend()
107107
) # type: Certificate
108108

@@ -124,7 +124,7 @@ def load_valid_certificate(self):
124124

125125
def sign_data(
126126
self, data, private_key=None,
127-
padding=PKCS1v15(), hash_algorithm=SHA1()):
127+
padding=PKCS1v15(), hash_algorithm=SHA256()):
128128
if private_key is None:
129129
private_key = self.private_key
130130

0 commit comments

Comments
 (0)
Please sign in to comment.