Skip to content
Merged
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
22 changes: 14 additions & 8 deletions AWS/AWS.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,9 @@ def create_thing_with_self_signed_certificates(
policy_name: str = "",
thing_type: str = "",
auto_delete: bool = True,
certificate_pem: str = "",
) -> ThingData:
"""Create thing with newly generated self-signed certificate (private and public key)
"""Create thing with optionally generated self-signed certificate (private and public key)

Random values are used for the name and policy name if they are not provided.

Expand All @@ -757,6 +758,7 @@ def create_thing_with_self_signed_certificates(
thing_type (str, optional): Thing type. Defaults to None
auto_delete (bool, optional): Automatically delete thing on suite teardown.
Defaults to True
certificate_pem (str, optional): Use give public certificate instead of generating one
"""
if not name:
name = self.get_random_name()
Expand All @@ -765,12 +767,16 @@ def create_thing_with_self_signed_certificates(
policy_name = self.get_random_name()
self.create_policy(name=policy_name, auto_delete=auto_delete)

cert_key_path = self.create_cert_private_key(auto_delete=auto_delete)
public_key = self.create_self_signed_certificate(
cert_key_path, common_name=name
)
private_key_pem = None
if not certificate_pem:
cert_key_path = self.create_cert_private_key(auto_delete=auto_delete)
certificate_pem = self.create_self_signed_certificate(
cert_key_path, common_name=name
)
private_key_pem = Path(cert_key_path).read_text(encoding="utf-8")

cert_response = self.register_certificate(
public_key, policy_name=policy_name, auto_delete=auto_delete
certificate_pem, policy_name=policy_name, auto_delete=auto_delete
)
self.create_thing(
name,
Expand All @@ -782,8 +788,8 @@ def create_thing_with_self_signed_certificates(
return ThingData(
name=name,
policy_name=policy_name,
private_key=Path(cert_key_path).read_text(encoding="utf-8"),
public_key=public_key,
private_key=private_key_pem,
public_key=certificate_pem,
url=self.get_iot_url(),
)

Expand Down