-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce ability to request CA chain (#196)
* feat: add support for returning the ca chain to tls_cert lambda Adds one new parameter to the `tls_cert` lambda request : * `ca_chain_only`: returns CA chain without generating a certificate * feat: introduce request and response classes * feat: update documentation in README for tls_cert lambda to include inputs and outputs.
- Loading branch information
Showing
9 changed files
with
363 additions
and
52 deletions.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
modules/terraform-aws-ca-lambda/lambda_code/tls_cert/requirements.txt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cryptography == 43.0.0 | ||
dataclasses-json == 0.6.7 | ||
validators == 0.33.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .tls_cert import create_csr_info, create_csr_subject | ||
from .tls_cert import create_csr_info, create_csr_subject, CaChainResponse, CertificateResponse, Request | ||
|
||
|
||
def test_create_csr_info(): | ||
|
@@ -52,3 +52,87 @@ def test_create_csr_subject(): | |
"ST=England,OU=Animation,O=Acme Inc,L=London,[email protected],C=GB,CN=blah.example.com" | ||
) | ||
assert subject.x509_name().rfc4514_string() == expected | ||
|
||
|
||
def test_request_deserialise_basic(): | ||
event = {"common_name": "test.example.com"} | ||
|
||
request = Request.from_dict(event) | ||
|
||
assert request.common_name == "test.example.com" | ||
assert request.lifetime == 30 | ||
|
||
|
||
def test_request_deserialise_full(): | ||
event = { | ||
"common_name": "test.example.com", | ||
"locality": "London", | ||
"organization": "Example", | ||
"organizational_unit": "IT", | ||
"country": "GB", | ||
"email_address": "[email protected]", | ||
"state": "London", | ||
"lifetime": 365, | ||
"purposes": ["server_auth"], | ||
"sans": ["test2.example.com"], | ||
"ca_chain_only": True, | ||
"force_issue": True, | ||
"csr_file": "csr.pem", | ||
"cert_bundle": True, | ||
"base64_csr_data": "base64data", | ||
} | ||
|
||
request = Request(**event) | ||
|
||
assert request.common_name == "test.example.com" | ||
assert request.lifetime == 365 | ||
assert request.purposes == ["server_auth"] | ||
assert request.csr_file == "csr.pem" | ||
|
||
|
||
def test_response_serialise_as_dict(): | ||
response = CertificateResponse( | ||
certificate_info={ | ||
"CommonName": "test.example.com", | ||
"SerialNumber": "123456", | ||
"Issued": "2021-01-01 00:00:00", | ||
"Expires": "2022-01-01 00:00:00", | ||
}, | ||
base64_certificate="base64data", | ||
subject="test.example.com", | ||
base64_issuing_ca_certificate="base64data", | ||
base64_root_ca_certificate="base64data", | ||
base64_ca_chain="base64data", | ||
) | ||
|
||
serialised = response.to_dict() | ||
|
||
assert serialised == { | ||
"CertificateInfo": { | ||
"CommonName": "test.example.com", | ||
"SerialNumber": "123456", | ||
"Issued": "2021-01-01 00:00:00", | ||
"Expires": "2022-01-01 00:00:00", | ||
}, | ||
"Base64Certificate": "base64data", | ||
"Subject": "test.example.com", | ||
"Base64IssuingCaCertificate": "base64data", | ||
"Base64RootCaCertificate": "base64data", | ||
"Base64CaChain": "base64data", | ||
} | ||
|
||
|
||
def test_ca_chain_response_serialise_as_dict(): | ||
response = CaChainResponse( | ||
base64_issuing_ca_certificate="base64data", | ||
base64_root_ca_certificate="base64data", | ||
base64_ca_chain="base64data", | ||
) | ||
|
||
serialised = response.to_dict() | ||
|
||
assert serialised == { | ||
"Base64IssuingCaCertificate": "base64data", | ||
"Base64RootCaCertificate": "base64data", | ||
"Base64CaChain": "base64data", | ||
} |
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
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
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
Oops, something went wrong.