@@ -328,7 +328,110 @@ public PkiResponse issue(
328328 final String ttl ,
329329 final CredentialFormat format ) throws VaultException {
330330
331- return issue (roleName , commonName , altNames , ipSans , ttl , format , "" );
331+ return issue (roleName , commonName , altNames , ipSans , ttl , format , "" , PrivateKeyFormat .DER );
332+ }
333+
334+ /**
335+ * <p>Operation to generate a new set of credentials (private key and certificate) based on a
336+ * given role using the PKI backend. The issuing CA certificate is returned as well, so that
337+ * only the root CA need be in a client's trust store.</p>
338+ *
339+ * <p>A successful operation will return a 204 HTTP status. A <code>VaultException</code> will
340+ * be thrown if the role does not exist, or if any other problem occurs. Credential information
341+ * will be populated in the <code>credential</code> field of the <code>PkiResponse</code> return
342+ * value. Example usage:</p>
343+ *
344+ * <blockquote>
345+ * <pre>{@code
346+ * final VaultConfig config = new VaultConfig.address(...).token(...).build();
347+ * final Vault vault = Vault.create(config);
348+ *
349+ * final PkiResponse response = vault.pki().deleteRole("testRole");
350+ * assertEquals(204, response.getRestResponse().getStatus();
351+ * }</pre>
352+ * </blockquote>
353+ *
354+ * @param roleName The role on which the credentials will be based.
355+ * @param commonName The requested CN for the certificate. If the CN is allowed by role policy,
356+ * it will be issued.
357+ * @param altNames (optional) Requested Subject Alternative Names, in a comma-delimited list.
358+ * These can be host names or email addresses; they will be parsed into their respective fields.
359+ * If any requested names do not match role policy, the entire request will be denied.
360+ * @param ipSans (optional) Requested IP Subject Alternative Names, in a comma-delimited list.
361+ * Only valid if the role allows IP SANs (which is the default).
362+ * @param ttl (optional) Requested Time To Live. Cannot be greater than the role's max_ttl
363+ * value. If not provided, the role's ttl value will be used. Note that the role values default
364+ * to system values if not explicitly set.
365+ * @param format (optional) Format for returned data. Can be pem, der, or pem_bundle; defaults
366+ * to pem. If der, the output is base64 encoded. If pem_bundle, the certificate field will
367+ * contain the private key, certificate, and issuing CA, concatenated.
368+ * @param privateKeyFormat (optional) Specifies the format for marshaling the
369+ * private key. Defaults to `der` which will return either base64-encoded DER or
370+ * PEM-encoded DER, depending on the value of `format`. The other option is
371+ * `pkcs8` which will return the key marshalled as PEM-encoded PKCS8
372+ * @return A container for the information returned by Vault
373+ * @throws VaultException If any error occurs or unexpected response is received from Vault
374+ */
375+ public PkiResponse issue (
376+ final String roleName ,
377+ final String commonName ,
378+ final List <String > altNames ,
379+ final List <String > ipSans ,
380+ final String ttl ,
381+ final CredentialFormat format ,
382+ final PrivateKeyFormat privateKeyFormat ) throws VaultException {
383+
384+ return issue (roleName , commonName , altNames , ipSans , ttl , format , "" , privateKeyFormat );
385+ }
386+
387+ /**
388+ * <p>Operation to generate a new set of credentials (private key and certificate) based on a
389+ * given role using the PKI backend. The issuing CA certificate is returned as well, so that
390+ * only the root CA need be in a client's trust store.</p>
391+ *
392+ * <p>A successful operation will return a 204 HTTP status. A <code>VaultException</code> will
393+ * be thrown if the role does not exist, or if any other problem occurs. Credential information
394+ * will be populated in the <code>credential</code> field of the <code>PkiResponse</code> return
395+ * value. Example usage:</p>
396+ *
397+ * <blockquote>
398+ * <pre>{@code
399+ * final VaultConfig config = new VaultConfig.address(...).token(...).build();
400+ * final Vault vault = Vault.create(config);
401+ *
402+ * final PkiResponse response = vault.pki().deleteRole("testRole");
403+ * assertEquals(204, response.getRestResponse().getStatus();
404+ * }</pre>
405+ * </blockquote>
406+ *
407+ * @param roleName The role on which the credentials will be based.
408+ * @param commonName The requested CN for the certificate. If the CN is allowed by role policy,
409+ * it will be issued.
410+ * @param altNames (optional) Requested Subject Alternative Names, in a comma-delimited list.
411+ * These can be host names or email addresses; they will be parsed into their respective fields.
412+ * If any requested names do not match role policy, the entire request will be denied.
413+ * @param ipSans (optional) Requested IP Subject Alternative Names, in a comma-delimited list.
414+ * Only valid if the role allows IP SANs (which is the default).
415+ * @param ttl (optional) Requested Time To Live. Cannot be greater than the role's max_ttl
416+ * value. If not provided, the role's ttl value will be used. Note that the role values default
417+ * to system values if not explicitly set.
418+ * @param format (optional) Format for returned data. Can be pem, der, or pem_bundle; defaults
419+ * to pem. If der, the output is base64 encoded. If pem_bundle, the certificate field will
420+ * contain the private key, certificate, and issuing CA, concatenated.
421+ * @param csr (optional) PEM Encoded CSR
422+ * @return A container for the information returned by Vault
423+ * @throws VaultException If any error occurs or unexpected response is received from Vault
424+ */
425+ public PkiResponse issue (
426+ final String roleName ,
427+ final String commonName ,
428+ final List <String > altNames ,
429+ final List <String > ipSans ,
430+ final String ttl ,
431+ final CredentialFormat format ,
432+ final String csr ) throws VaultException {
433+
434+ return issue (roleName , commonName , altNames , ipSans , ttl , format , csr , PrivateKeyFormat .DER );
332435 }
333436
334437 /**
@@ -368,6 +471,10 @@ public PkiResponse issue(
368471 * to pem. If der, the output is base64 encoded. If pem_bundle, the certificate field will
369472 * contain the private key, certificate, and issuing CA, concatenated.
370473 * @param csr (optional) PEM Encoded CSR
474+ * @param privateKeyFormat (optional) Specifies the format for marshaling the
475+ * private key. Defaults to `der` which will return either base64-encoded DER or
476+ * PEM-encoded DER, depending on the value of `format`. The other option is
477+ * `pkcs8` which will return the key marshalled as PEM-encoded PKCS8
371478 * @return A container for the information returned by Vault
372479 * @throws VaultException If any error occurs or unexpected response is received from Vault
373480 */
@@ -378,7 +485,8 @@ public PkiResponse issue(
378485 final List <String > ipSans ,
379486 final String ttl ,
380487 final CredentialFormat format ,
381- final String csr
488+ final String csr ,
489+ final PrivateKeyFormat privateKeyFormat
382490 ) throws VaultException {
383491 return retry (attempt -> {
384492 // Construct a JSON body from inputs
@@ -418,6 +526,10 @@ public PkiResponse issue(
418526 jsonObject .add ("format" , format .toString ());
419527 }
420528
529+ if (privateKeyFormat != null ) {
530+ jsonObject .add ("private_key_format" , privateKeyFormat .toString ());
531+ }
532+
421533 if (csr != null ) {
422534 jsonObject .add ("csr" , csr );
423535 }
0 commit comments