Skip to content
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
14 changes: 7 additions & 7 deletions tools/shoestring/shoestring/internal/CertificateFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ def _prepare_ca_certificate(self, ca_cn):
'basicConstraints = critical,CA:TRUE',
'subjectKeyIdentifier = hash',
'authorityKeyIdentifier = keyid:always,issuer'
'',
'[x509_v3_node]',
'basicConstraints = CA:FALSE',
'subjectKeyIdentifier = hash',
'authorityKeyIdentifier = keyid,issuer'
]))

# create new certs directory
Expand Down Expand Up @@ -143,15 +148,9 @@ def generate_node_certificate(self, node_cn, days=375, start_date=None):
'[req]',
'prompt = no',
'distinguished_name = dn',
'x509_extensions = x509_v3',
'',
'[dn]',
f'CN = {node_cn}',
'',
'[x509_v3]',
'basicConstraints = CA:FALSE',
'subjectKeyIdentifier = hash',
'authorityKeyIdentifier = keyid,issuer'
]))

# prepare node certificate signing request
Expand All @@ -177,7 +176,8 @@ def generate_node_certificate(self, node_cn, days=375, start_date=None):
'-notext',
'-batch',
'-in', 'node.csr.pem',
'-out', 'node.crt.pem'
'-out', 'node.crt.pem',
'-extensions', 'x509_v3_node'
] + ([] if not start_date else ['-startdate', start_date.strftime('%y%m%d%H%M%SZ')])))

@staticmethod
Expand Down
9 changes: 9 additions & 0 deletions tools/shoestring/tests/internal/test_CertificateFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ def _assert_certificate_duration(self, x509_output, test_start_time, expected_da

self.assertEqual(expected_days, (cert_end_time - cert_start_time).days)

def _assert_certificate_is_x509v3(self, x509_output):
self.assertIn('X509v3 extensions', x509_output)

def _assert_can_generate_ca_certificate(self, additional_args, expected_duration_days):
# Arrange: certificate has second resolution, so clear microseconds for assert below to work
test_start_time = datetime.datetime.utcnow().replace(microsecond=0)
Expand Down Expand Up @@ -174,6 +177,9 @@ def _assert_can_generate_ca_certificate(self, additional_args, expected_duration
# - verify certificate is properly self signed
self._create_executor().dispatch(['verify', '-CAfile', ca_certificate_path, ca_certificate_path])

# - check certificate is x509v3
self._assert_certificate_is_x509v3(x509_output)

def test_can_generate_ca_certificate(self):
self._assert_can_generate_ca_certificate({}, 20 * 365)

Expand Down Expand Up @@ -235,6 +241,9 @@ def _assert_can_generate_node_certificate(self, should_generate_certificate_chai
if not future_start_delay_days:
self._create_executor().dispatch(['verify', '-CAfile', ca_certificate_path, node_certificate_path])

# - check certificate is x509v3
self._assert_certificate_is_x509v3(x509_output)

def test_can_generate_node_certificate(self):
self._assert_can_generate_node_certificate(False, {}, {})

Expand Down