Skip to content

Commit 0d0d0c5

Browse files
committed
Add AKI on certificate generation for brokers
Signed-off-by: Oleksiy Afanasenko <oleksiy.afanasenko@exness.com>
1 parent 33c45f8 commit 0d0d0c5

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

certificate-manager/src/main/java/io/strimzi/certs/OpenSslCertManager.java

+11-9
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,20 @@ private Path createDefaultConfig() throws IOException {
134134
/**
135135
* Add basic constraints and subject alt names section to the provided openssl configuration file
136136
*
137-
* @param sbj subject information
138-
*
137+
* @param sbj subject information
138+
* @param needsAki if true adds AKI (authorityKeyIdentifier)
139139
* @return openssl configuration file with subject alt names added
140-
*
141-
* @throws IOException Throws IOException when IO operations fail
140+
* @throws IOException
142141
*/
143-
private Path buildConfigFile(Subject sbj, boolean isCa) throws IOException {
142+
private Path buildConfigFile(Subject sbj, boolean isCa, boolean needsAki) throws IOException {
144143
Path sna = createDefaultConfig();
145144
try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sna.toFile(), true), StandardCharsets.UTF_8))) {
146145
if (isCa) {
147146
out.append("basicConstraints = critical,CA:true,pathlen:0\n");
148147
}
148+
if (needsAki) {
149+
out.append("authorityKeyIdentifier = keyid,issuer\n");
150+
}
149151
if (sbj != null) {
150152
if (sbj.hasSubjectAltNames()) {
151153
out.append("subjectAltName = @alt_names\n" +
@@ -282,7 +284,7 @@ private void generateCaCert(File issuerCaKeyFile, File issuerCaCertFile,
282284
}
283285

284286
csrFile = Files.createTempFile(null, null);
285-
sna = buildConfigFile(subject, true);
287+
sna = buildConfigFile(subject, true, false);
286288
new OpensslArgs("openssl", "req")
287289
.opt("-new")
288290
.optArg("-config", sna, true)
@@ -468,7 +470,7 @@ public void generateCsr(File keyFile, File csrFile, Subject subject) throws IOEx
468470
try {
469471
if (subject.hasSubjectAltNames()) {
470472
// subject alt names need to be in an openssl configuration file
471-
sna = buildConfigFile(subject, false);
473+
sna = buildConfigFile(subject, false, false);
472474
cmd.optArg("-config", sna, true).optArg("-extensions", "v3_req");
473475
}
474476

@@ -532,7 +534,7 @@ public void generateCert(File csrFile, File caKey, File caCert, File crtFile, Su
532534
if (sbj.hasSubjectAltNames()) {
533535
cmd.optArg("-extensions", "v3_req");
534536
// subject alt names need to be in an openssl configuration file
535-
sna = buildConfigFile(sbj, false);
537+
sna = buildConfigFile(sbj, false, true);
536538
cmd.optArg("-extfile", sna, true);
537539
}
538540

@@ -578,7 +580,7 @@ public void generateCert(File csrFile, byte[] caKey, byte[] caCert, File crtFile
578580
* Helper for building arg lists and environments.
579581
* The environment is used so that the config file can be parameterised for things like basic constraints.
580582
* But it's still necessary to use dynamically generated configs for specifying SANs
581-
* (see {@link OpenSslCertManager#buildConfigFile(Subject, boolean)}).
583+
* (see {@link OpenSslCertManager#buildConfigFile(Subject, boolean, boolean)}).
582584
*/
583585
private static class OpensslArgs {
584586
ProcessBuilder pb = new ProcessBuilder();

certificate-manager/src/test/java/io/strimzi/certs/OpenSslCertManagerIT.java

+3
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ public void testGenerateClientCertWithSubjectAndAltNames() throws Exception {
323323
ssl.generateSelfSignedCert(caKey, caCert, caSbj, 365);
324324
doGenerateSignedCert(caKey, caCert, caSbj, key, csr, cert, store, "123456", subject);
325325

326+
X509Certificate certificate = loadCertificate(cert);
327+
assertThat(certificate.getExtensionValue("2.5.29.35"), is(notNullValue()));
328+
326329
caKey.delete();
327330
caCert.delete();
328331
key.delete();

0 commit comments

Comments
 (0)