Ignore invalid files in '.gnupg/private-keys-v1.d'

Bug: 545673
Change-Id: I4a2ee1e76f320209b3f8090264d771f1a9da566f
Signed-off-by: Gunnar Wagenknecht <gunnar@wagenknecht.org>
This commit is contained in:
Gunnar Wagenknecht 2019-04-02 13:47:07 -07:00
parent 27f1fb668f
commit 440296873b
1 changed files with 10 additions and 2 deletions

View File

@ -85,6 +85,8 @@
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 <code>~/.gnupg/private-keys-v1.d</code> or
@ -92,6 +94,9 @@
*/
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 @@ public BouncyCastleGpgKeyLocator(String signingKey,
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;
}
}