spring-projects / spring-vault

Provides familiar Spring abstractions for HashiCorp Vault
https://spring.io/projects/spring-vault
Apache License 2.0
283 stars 186 forks source link

Private Key is `null` in `CertificateBundle` using `of(String serialNumber, String certificate, String issuingCaCertificate, String privateKey)` #857

Closed JackSilk closed 4 months ago

JackSilk commented 7 months ago

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.

mp911de commented 7 months ago

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

mp911de commented 4 months ago

That's fixed now.