From c2499c80ee59857b52af28a41abc447377fd205e Mon Sep 17 00:00:00 2001 From: Moritz Horstmann Date: Thu, 14 Feb 2019 15:52:27 +0100 Subject: [PATCH] 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 --- .../com/google/gerrit/gpg/server/GpgKeys.java | 15 ++++++++------- 1 file 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 { Iterator 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); } }