diff options
author | Moritz Horstmann <MHorstmann@privacy-central.de> | 2019-02-14 15:52:27 +0100 |
---|---|---|
committer | David Pursehouse <dpursehouse@collab.net> | 2019-02-18 10:10:48 +0900 |
commit | c2499c80ee59857b52af28a41abc447377fd205e (patch) | |
tree | 63e89e15fd01eb02f90dda398811a4c1a647f87d | |
parent | 12c859f61f454c1b8d91ebbb746d318212d80695 (diff) |
Fix GPG public key export
The armored output stream needs to be closed to finish the armoring process.
Failure to do so leads to incomplete GPG public keys transferred to the UI/REST API.
Bug: Issue 10488
Change-Id: Id9569d969d362ea93a8b8259fd05abe141a05dfd
-rw-r--r-- | gerrit-gpg/src/main/java/com/google/gerrit/gpg/server/GpgKeys.java | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/gerrit-gpg/src/main/java/com/google/gerrit/gpg/server/GpgKeys.java b/gerrit-gpg/src/main/java/com/google/gerrit/gpg/server/GpgKeys.java index ecff7e6a3c..6dd3c7ec3a 100644 --- a/gerrit-gpg/src/main/java/com/google/gerrit/gpg/server/GpgKeys.java +++ b/gerrit-gpg/src/main/java/com/google/gerrit/gpg/server/GpgKeys.java @@ -222,13 +222,14 @@ public class GpgKeys implements ChildCollection<AccountResource, GpgKey> { Iterator<String> userIds = key.getUserIDs(); info.userIds = ImmutableList.copyOf(userIds); - try (ByteArrayOutputStream out = new ByteArrayOutputStream(4096); - ArmoredOutputStream aout = new ArmoredOutputStream(out)) { - // This is not exactly the key stored in the store, but is equivalent. In - // particular, it will have a Bouncy Castle version string. The armored - // stream reader in PublicKeyStore doesn't give us an easy way to extract - // the original ASCII armor. - key.encode(aout); + try (ByteArrayOutputStream out = new ByteArrayOutputStream(4096)) { + try (ArmoredOutputStream aout = new ArmoredOutputStream(out)) { + // This is not exactly the key stored in the store, but is equivalent. In + // particular, it will have a Bouncy Castle version string. The armored + // stream reader in PublicKeyStore doesn't give us an easy way to extract + // the original ASCII armor. + key.encode(aout); + } info.key = new String(out.toByteArray(), UTF_8); } } |