Skip to content

Commit 0a12d2a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "certs: add subject key identifier extension"
2 parents 3d7c57c + 89f185b commit 0a12d2a

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

magnum/common/x509/operations.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def sign(csr, issuer_name, ca_key, ca_key_password=None,
223223
builder = builder.add_extension(extention.value,
224224
critical=extention.critical)
225225

226+
subject_key_identifier = x509.SubjectKeyIdentifier.from_public_key(
227+
csr.public_key())
228+
builder = builder.add_extension(
229+
subject_key_identifier, critical=False
230+
)
231+
226232
certificate = builder.sign(
227233
private_key=ca_key, algorithm=hashes.SHA256(),
228234
).public_bytes(serialization.Encoding.PEM).strip()

magnum/tests/unit/common/x509/test_sign.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,26 @@ def test_sign_empty_chars(self, mock_load_pem):
233233
self.assertEqual(certificate,
234234
certificate.strip())
235235

236+
# If a subject key identifier is given in the CSR, ensure it is added
237+
@mock.patch('cryptography.x509.load_pem_x509_csr')
238+
def test_sign_subject_key_identifier(self, mock_load_pem):
239+
ca_key = self._generate_private_key()
240+
private_key = self._generate_private_key()
241+
csr_obj = self._build_csr(private_key)
242+
csr = csr_obj.public_bytes(serialization.Encoding.PEM)
243+
csr = csr.decode('utf-8')
244+
245+
mock_load_pem.return_value = csr_obj
246+
certificate = operations.sign(csr, self.issuer_name,
247+
ca_key, skip_validation=True)
248+
249+
# Ensure the Subject Key Identifier extension is present
250+
cert = c_x509.load_pem_x509_certificate(certificate)
251+
ext_ski = [ext for ext in cert.extensions
252+
if cert.extensions[0].oid ==
253+
c_x509.oid.ExtensionOID.SUBJECT_KEY_IDENTIFIER]
254+
self.assertEqual(len(ext_ski), 1)
255+
236256
def test_sign_with_invalid_csr(self):
237257
ca_key = self._generate_private_key()
238258
csr = 'test'
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
features:
3+
- |
4+
Add subject key identifier extension to x509 operations
5+
signing function. Allows for magnum Kubernetes clusters
6+
to generate certificates with authority key
7+
identifier extension.

0 commit comments

Comments
 (0)