From 440296873b8200fbba5f3d2a5d3f71708d75f2fc Mon Sep 17 00:00:00 2001 From: Gunnar Wagenknecht Date: Tue, 2 Apr 2019 13:47:07 -0700 Subject: Ignore invalid files in '.gnupg/private-keys-v1.d' Bug: 545673 Change-Id: I4a2ee1e76f320209b3f8090264d771f1a9da566f Signed-off-by: Gunnar Wagenknecht --- .../eclipse/jgit/lib/internal/BouncyCastleGpgKeyLocator.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/BouncyCastleGpgKeyLocator.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/BouncyCastleGpgKeyLocator.java index 091667db01..c942cf403d 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/BouncyCastleGpgKeyLocator.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/internal/BouncyCastleGpgKeyLocator.java @@ -85,6 +85,8 @@ import org.eclipse.jgit.errors.UnsupportedCredentialItem; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.util.FS; import org.eclipse.jgit.util.SystemReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Locates GPG keys from either ~/.gnupg/private-keys-v1.d or @@ -92,6 +94,9 @@ import org.eclipse.jgit.util.SystemReader; */ class BouncyCastleGpgKeyLocator { + private static final Logger log = LoggerFactory + .getLogger(BouncyCastleGpgKeyLocator.class); + private static final Path GPG_DIRECTORY = findGpgDirectory(); private static final Path USER_KEYBOX_PATH = GPG_DIRECTORY @@ -157,11 +162,14 @@ class BouncyCastleGpgKeyLocator { private PGPSecretKey attemptParseSecretKey(Path keyFile, PGPDigestCalculatorProvider calculatorProvider, PBEProtectionRemoverFactory passphraseProvider, - PGPPublicKey publicKey) throws IOException { + PGPPublicKey publicKey) { try (InputStream in = newInputStream(keyFile)) { return new SExprParser(calculatorProvider).parseSecretKey( new BufferedInputStream(in), passphraseProvider, publicKey); - } catch (PGPException | ClassCastException e) { + } catch (IOException | PGPException | ClassCastException e) { + if (log.isDebugEnabled()) + log.debug("Ignoring unreadable file '{}': {}", keyFile, //$NON-NLS-1$ + e.getMessage(), e); return null; } } -- cgit v1.2.3