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
This commit is contained in:
Moritz Horstmann 2019-02-14 15:52:27 +01:00 committed by David Pursehouse
parent 12c859f61f
commit c2499c80ee
1 changed files with 8 additions and 7 deletions

View File

@ -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);
}
}