Skip to content

Commit

Permalink
Cache the Google Cloud private key when the alias contains the versio…
Browse files Browse the repository at this point in the history
…n or the algorithm
  • Loading branch information
ebourg committed Apr 30, 2024
1 parent 9e6df4d commit 7b5b22f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public SigningServicePrivateKey getPrivateKey(String alias, char[] password) thr

SigningServicePrivateKey key = new SigningServicePrivateKey(alias, algorithm, this);
keys.put(alias, key);
keys.put(alias.substring(0, alias.indexOf("/cryptoKeyVersions")), key); // cache without the version
keys.put(alias + ":" + algorithm, key); // cache with the algorithm appended
return key;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ public void testGetPrivateKey(String alias, boolean certificate) throws Exceptio
assertNotNull("null key", key);
assertEquals("id", "projects/fifth-glider-316809/locations/global/keyRings/jsignkeyring/cryptoKeys/jsign-rsa-2048/cryptoKeyVersions/2", key.getId());
assertEquals("algorithm", "RSA", key.getAlgorithm());

// check if the key is cached
SigningServicePrivateKey key2 = service.getPrivateKey(alias, null);
assertSame("private key not cached", key, key2);
}

@Test
Expand Down

0 comments on commit 7b5b22f

Please sign in to comment.