wrapped-key-ring: no more pgp imports in PassphraseDialogFragment

This commit is contained in:
Vincent Breitmoser
2014-05-04 03:38:58 +02:00
parent f524fa692c
commit b5647b2062
6 changed files with 62 additions and 88 deletions

View File

@@ -41,17 +41,18 @@ public class CachedSecretKey extends CachedPublicKey {
return (CachedSecretKeyRing) mRing;
}
public void unlock(String passphrase) throws PgpGeneralException {
public boolean unlock(String passphrase) throws PgpGeneralException {
try {
PBESecretKeyDecryptor keyDecryptor = new JcePBESecretKeyDecryptorBuilder().setProvider(
Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passphrase.toCharArray());
mPrivateKey = mSecretKey.extractPrivateKey(keyDecryptor);
} catch (PGPException e) {
throw new PgpGeneralException("error extracting key!", e);
return false;
}
if(mPrivateKey == null) {
throw new PgpGeneralException("error extracting key (bad passphrase?)");
throw new PgpGeneralException("error extracting key");
}
return true;
}
public PGPSignatureGenerator getSignatureGenerator(int hashAlgo, boolean cleartext)

View File

@@ -344,9 +344,11 @@ public class PgpDecryptVerify {
currentProgress += 5;
updateProgress(R.string.progress_extracting_key, currentProgress, 100);
try {
secretEncryptionKey.unlock(mPassphrase);
} catch (PgpGeneralException e) {
throw new WrongPassphraseException();
if (!secretEncryptionKey.unlock(mPassphrase)) {
throw new WrongPassphraseException();
}
} catch(PgpGeneralException e) {
throw new KeyExtractionException();
}
currentProgress += 5;
updateProgress(R.string.progress_preparing_streams, currentProgress, 100);

View File

@@ -338,8 +338,8 @@ public class PgpKeyOperation {
}
public UncachedKeyRing buildSecretKey(CachedSecretKeyRing wmKR,
CachedPublicKeyRing wpKR,
SaveKeyringParcel saveParcel)
CachedPublicKeyRing wpKR,
SaveKeyringParcel saveParcel)
throws PgpGeneralMsgIdException, PGPException, SignatureException, IOException {
PGPSecretKeyRing mKR = wmKR.getRing();