@@ -134,18 +134,20 @@ private Path createDefaultConfig() throws IOException {
134
134
/**
135
135
* Add basic constraints and subject alt names section to the provided openssl configuration file
136
136
*
137
- * @param sbj subject information
138
- *
137
+ * @param sbj subject information
138
+ * @param needsAki if true adds AKI (authorityKeyIdentifier)
139
139
* @return openssl configuration file with subject alt names added
140
- *
141
- * @throws IOException Throws IOException when IO operations fail
140
+ * @throws IOException
142
141
*/
143
- private Path buildConfigFile (Subject sbj , boolean isCa ) throws IOException {
142
+ private Path buildConfigFile (Subject sbj , boolean isCa , boolean needsAki ) throws IOException {
144
143
Path sna = createDefaultConfig ();
145
144
try (BufferedWriter out = new BufferedWriter (new OutputStreamWriter (new FileOutputStream (sna .toFile (), true ), StandardCharsets .UTF_8 ))) {
146
145
if (isCa ) {
147
146
out .append ("basicConstraints = critical,CA:true,pathlen:0\n " );
148
147
}
148
+ if (needsAki ) {
149
+ out .append ("authorityKeyIdentifier = keyid,issuer\n " );
150
+ }
149
151
if (sbj != null ) {
150
152
if (sbj .hasSubjectAltNames ()) {
151
153
out .append ("subjectAltName = @alt_names\n " +
@@ -282,7 +284,7 @@ private void generateCaCert(File issuerCaKeyFile, File issuerCaCertFile,
282
284
}
283
285
284
286
csrFile = Files .createTempFile (null , null );
285
- sna = buildConfigFile (subject , true );
287
+ sna = buildConfigFile (subject , true , false );
286
288
new OpensslArgs ("openssl" , "req" )
287
289
.opt ("-new" )
288
290
.optArg ("-config" , sna , true )
@@ -468,7 +470,7 @@ public void generateCsr(File keyFile, File csrFile, Subject subject) throws IOEx
468
470
try {
469
471
if (subject .hasSubjectAltNames ()) {
470
472
// subject alt names need to be in an openssl configuration file
471
- sna = buildConfigFile (subject , false );
473
+ sna = buildConfigFile (subject , false , false );
472
474
cmd .optArg ("-config" , sna , true ).optArg ("-extensions" , "v3_req" );
473
475
}
474
476
@@ -532,7 +534,7 @@ public void generateCert(File csrFile, File caKey, File caCert, File crtFile, Su
532
534
if (sbj .hasSubjectAltNames ()) {
533
535
cmd .optArg ("-extensions" , "v3_req" );
534
536
// subject alt names need to be in an openssl configuration file
535
- sna = buildConfigFile (sbj , false );
537
+ sna = buildConfigFile (sbj , false , true );
536
538
cmd .optArg ("-extfile" , sna , true );
537
539
}
538
540
@@ -578,7 +580,7 @@ public void generateCert(File csrFile, byte[] caKey, byte[] caCert, File crtFile
578
580
* Helper for building arg lists and environments.
579
581
* The environment is used so that the config file can be parameterised for things like basic constraints.
580
582
* 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 )}).
582
584
*/
583
585
private static class OpensslArgs {
584
586
ProcessBuilder pb = new ProcessBuilder ();
0 commit comments