spring-vault icon indicating copy to clipboard operation
spring-vault copied to clipboard

Private Key is null in CertificateBundle

Open JackSilk opened this issue 1 year ago • 1 comments

Hello,

I'm trying to update from Spring Vault 3.0.2 to 3.1.0 (through spring-cloud-starter-vault-config) and I'm having an issue where, having created an instance of the CertificateBundle, I get null when I try to get the private key back.

Here's a simple test case to illustrate.

@Test
  void shouldNotThrowNullPointerExceptionWhenGettingPrivateKey() {
    var serialNumber = "aserialnumber";
    var certificate = "certificate";
    var caCertificate = "caCertificate";
    var privateKey = "aprivatekey";
    
 var certificateBundle =
        CertificateBundle.of(serialNumber, certificate, caCertificate, privateKey);
    Assertions.assertThat(certificateBundle.getPrivateKey()).isNotNull();
  }

I had a look at the code and it seems to me that the order of arguments is transposed on this line https://github.com/spring-projects/spring-vault/blob/74ff3b648dae1f6eedc403b782db003dec575aaf/spring-vault-core/src/main/java/org/springframework/vault/support/CertificateBundle.java#L98

That is, it's passing null as the privateKey argument and passing the intended private key to the privateKeyType argument.

Does that look/sound like it makes sense? Thanks for your assistance.

JackSilk avatar Feb 26 '24 13:02 JackSilk

This is a regression from an earlier change. As a workaround, please use a different factory method until this is fixed.

mp911de avatar Feb 27 '24 14:02 mp911de

That's fixed now.

mp911de avatar Jun 06 '24 12:06 mp911de