Merge branch 'result-parcels'

This commit is contained in:
Vincent Breitmoser 2014-09-13 21:32:17 +02:00
commit f8677a5f16
10 changed files with 383 additions and 215 deletions

View File

@ -19,7 +19,7 @@ package org.sufficientlysecure.keychain.support;
import android.content.Context; import android.content.Context;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
@ -56,7 +56,7 @@ public class PgpVerifyTestingHelper {
OutputStream outStream = new ByteArrayOutputStream(); OutputStream outStream = new ByteArrayOutputStream();
PgpDecryptVerify verify = new PgpDecryptVerify.Builder(providerHelper, passphraseCache, data, outStream).build(); PgpDecryptVerify verify = new PgpDecryptVerify.Builder(providerHelper, passphraseCache, data, outStream).build();
PgpDecryptVerifyResult result = verify.execute(); DecryptVerifyResult result = verify.execute();
return result.getSignatureResult().getStatus(); return result.getSignatureResult().getStatus();
} }

View File

@ -48,6 +48,10 @@ import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogLevel;
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.LogType;
import org.sufficientlysecure.keychain.service.results.OperationResultParcel.OperationLog;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;
@ -60,6 +64,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.URLConnection; import java.net.URLConnection;
import java.security.SignatureException; import java.security.SignatureException;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
@ -177,73 +182,52 @@ public class PgpDecryptVerify {
throws NoSecretKeyException; throws NoSecretKeyException;
} }
public static class InvalidDataException extends Exception {
public InvalidDataException() {
}
}
public static class KeyExtractionException extends Exception {
public KeyExtractionException() {
}
}
public static class WrongPassphraseException extends Exception {
public WrongPassphraseException() {
}
}
public static class NoSecretKeyException extends Exception { public static class NoSecretKeyException extends Exception {
public NoSecretKeyException() { public NoSecretKeyException() {
} }
} }
public static class IntegrityCheckFailedException extends Exception {
public IntegrityCheckFailedException() {
}
}
public static class NeedNfcDataException extends Exception {
public byte[] mEncryptedSessionKey;
public String mPassphrase;
public NeedNfcDataException(byte[] encryptedSessionKey, String passphrase) {
mEncryptedSessionKey = encryptedSessionKey;
mPassphrase = passphrase;
}
}
/** /**
* Decrypts and/or verifies data based on parameters of class * Decrypts and/or verifies data based on parameters of class
*/ */
public PgpDecryptVerifyResult execute() public DecryptVerifyResult execute() {
throws IOException, PGPException, SignatureException, try {
WrongPassphraseException, NoSecretKeyException, KeyExtractionException, // automatically works with ascii armor input and binary
InvalidDataException, IntegrityCheckFailedException, NeedNfcDataException { InputStream in = PGPUtil.getDecoderStream(mData.getInputStream());
// automatically works with ascii armor input and binary
InputStream in = PGPUtil.getDecoderStream(mData.getInputStream());
if (in instanceof ArmoredInputStream) {
ArmoredInputStream aIn = (ArmoredInputStream) in;
// it is ascii armored
Log.d(Constants.TAG, "ASCII Armor Header Line: " + aIn.getArmorHeaderLine());
if (aIn.isClearText()) { if (in instanceof ArmoredInputStream) {
// a cleartext signature, verify it with the other method ArmoredInputStream aIn = (ArmoredInputStream) in;
return verifyCleartextSignature(aIn); // it is ascii armored
Log.d(Constants.TAG, "ASCII Armor Header Line: " + aIn.getArmorHeaderLine());
if (aIn.isClearText()) {
// a cleartext signature, verify it with the other method
return verifyCleartextSignature(aIn);
}
// else: ascii armored encryption! go on...
} }
// else: ascii armored encryption! go on...
}
return decryptVerify(in); return decryptVerify(in, 0);
} catch (PGPException e) {
OperationLog log = new OperationLog();
log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_PGP_EXCEPTION, 1);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} catch (IOException e) {
OperationLog log = new OperationLog();
log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_IO, 1);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
}
} }
/** /**
* Decrypt and/or verifies binary or ascii armored pgp * Decrypt and/or verifies binary or ascii armored pgp
*/ */
private PgpDecryptVerifyResult decryptVerify(InputStream in) private DecryptVerifyResult decryptVerify(InputStream in, int indent) throws IOException, PGPException {
throws IOException, PGPException, SignatureException,
WrongPassphraseException, KeyExtractionException, NoSecretKeyException, OperationLog log = new OperationLog();
InvalidDataException, IntegrityCheckFailedException, NeedNfcDataException {
PgpDecryptVerifyResult result = new PgpDecryptVerifyResult(); log.add(LogLevel.START, LogType.MSG_DC, indent);
indent += 1;
PGPObjectFactory pgpF = new PGPObjectFactory(in, new JcaKeyFingerprintCalculator()); PGPObjectFactory pgpF = new PGPObjectFactory(in, new JcaKeyFingerprintCalculator());
PGPEncryptedDataList enc; PGPEncryptedDataList enc;
@ -259,7 +243,8 @@ public class PgpDecryptVerify {
} }
if (enc == null) { if (enc == null) {
throw new InvalidDataException(); log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_INVALID_SIGLIST, indent);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
InputStream clear; InputStream clear;
@ -271,35 +256,44 @@ public class PgpDecryptVerify {
Iterator<?> it = enc.getEncryptedDataObjects(); Iterator<?> it = enc.getEncryptedDataObjects();
boolean asymmetricPacketFound = false; boolean asymmetricPacketFound = false;
boolean symmetricPacketFound = false; boolean symmetricPacketFound = false;
boolean anyPacketFound = false;
// go through all objects and find one we can decrypt // go through all objects and find one we can decrypt
while (it.hasNext()) { while (it.hasNext()) {
Object obj = it.next(); Object obj = it.next();
if (obj instanceof PGPPublicKeyEncryptedData) { if (obj instanceof PGPPublicKeyEncryptedData) {
anyPacketFound = true;
currentProgress += 2; currentProgress += 2;
updateProgress(R.string.progress_finding_key, currentProgress, 100); updateProgress(R.string.progress_finding_key, currentProgress, 100);
PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj; PGPPublicKeyEncryptedData encData = (PGPPublicKeyEncryptedData) obj;
long subKeyId = encData.getKeyID(); long subKeyId = encData.getKeyID();
log.add(LogLevel.DEBUG, LogType.MSG_DC_ASYM, indent,
PgpKeyHelper.convertKeyIdToHex(subKeyId));
CanonicalizedSecretKeyRing secretKeyRing; CanonicalizedSecretKeyRing secretKeyRing;
try { try {
// get actual keyring object based on master key id // get actual keyring object based on master key id
secretKeyRing = mProviderHelper.getCanonicalizedSecretKeyRing( secretKeyRing = mProviderHelper.getCanonicalizedSecretKeyRing(
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(encData.getKeyID()) KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId)
); );
} catch (ProviderHelper.NotFoundException e) { } catch (ProviderHelper.NotFoundException e) {
// continue with the next packet in the while loop // continue with the next packet in the while loop
log.add(LogLevel.DEBUG, LogType.MSG_DC_ASKIP_NO_KEY, indent +1);
continue; continue;
} }
if (secretKeyRing == null) { if (secretKeyRing == null) {
// continue with the next packet in the while loop // continue with the next packet in the while loop
log.add(LogLevel.DEBUG, LogType.MSG_DC_ASKIP_NO_KEY, indent +1);
continue; continue;
} }
// get subkey which has been used for this encryption packet // get subkey which has been used for this encryption packet
secretEncryptionKey = secretKeyRing.getSecretKey(subKeyId); secretEncryptionKey = secretKeyRing.getSecretKey(subKeyId);
if (secretEncryptionKey == null) { if (secretEncryptionKey == null) {
// continue with the next packet in the while loop // should actually never happen, so no need to be more specific.
log.add(LogLevel.DEBUG, LogType.MSG_DC_ASKIP_NO_KEY, indent +1);
continue; continue;
} }
@ -313,6 +307,7 @@ public class PgpDecryptVerify {
if (!mAllowedKeyIds.contains(masterKeyId)) { if (!mAllowedKeyIds.contains(masterKeyId)) {
// this key is in our db, but NOT allowed! // this key is in our db, but NOT allowed!
// continue with the next packet in the while loop // continue with the next packet in the while loop
log.add(LogLevel.DEBUG, LogType.MSG_DC_ASKIP_NOT_ALLOWED, indent +1);
continue; continue;
} }
} }
@ -324,22 +319,38 @@ public class PgpDecryptVerify {
// if no passphrase was explicitly set try to get it from the cache service // if no passphrase was explicitly set try to get it from the cache service
if (mPassphrase == null) { if (mPassphrase == null) {
// returns "" if key has no passphrase try {
mPassphrase = mPassphraseCache.getCachedPassphrase(subKeyId); // returns "" if key has no passphrase
mPassphrase = mPassphraseCache.getCachedPassphrase(subKeyId);
log.add(LogLevel.DEBUG, LogType.MSG_DC_PASS_CACHED, indent +1);
} catch (NoSecretKeyException e) {
log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_NO_KEY, indent +1);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
}
// if passphrase was not cached, return here // if passphrase was not cached, return here indicating that a passphrase is missing!
// indicating that a passphrase is missing!
if (mPassphrase == null) { if (mPassphrase == null) {
log.add(LogLevel.INFO, LogType.MSG_DC_PENDING_PASSPHRASE, indent +1);
DecryptVerifyResult result =
new DecryptVerifyResult(DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE, log);
result.setKeyIdPassphraseNeeded(subKeyId); result.setKeyIdPassphraseNeeded(subKeyId);
result.setStatus(PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED);
return result; return result;
} }
} }
// break out of while, only decrypt the first packet where we have a key // break out of while, only decrypt the first packet where we have a key
// TODO???: There could be more pgp objects, which are not decrypted!
break; break;
} else if (mAllowSymmetricDecryption && obj instanceof PGPPBEEncryptedData) {
} else if (obj instanceof PGPPBEEncryptedData) {
anyPacketFound = true;
log.add(LogLevel.DEBUG, LogType.MSG_DC_SYM, indent);
if (! mAllowSymmetricDecryption) {
log.add(LogLevel.WARN, LogType.MSG_DC_SYM_SKIP, indent +1);
continue;
}
/* /*
* When mAllowSymmetricDecryption == true and we find a data packet here, * When mAllowSymmetricDecryption == true and we find a data packet here,
* we do not search for other available asymmetric packets! * we do not search for other available asymmetric packets!
@ -351,16 +362,30 @@ public class PgpDecryptVerify {
// if no passphrase is given, return here // if no passphrase is given, return here
// indicating that a passphrase is missing! // indicating that a passphrase is missing!
if (mPassphrase == null) { if (mPassphrase == null) {
result.setStatus(PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED); log.add(LogLevel.INFO, LogType.MSG_DC_PENDING_PASSPHRASE, indent +1);
return result; return new DecryptVerifyResult(DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE, log);
} }
// break out of while, only decrypt the first packet // break out of while, only decrypt the first packet
// TODO???: There could be more pgp objects, which are not decrypted!
break; break;
} }
} }
// More data, just acknowledge and ignore.
while (it.hasNext()) {
Object obj = it.next();
if (obj instanceof PGPPublicKeyEncryptedData) {
log.add(LogLevel.WARN, LogType.MSG_DC_TRAIL_ASYM, 0);
} else if (obj instanceof PGPPBEEncryptedData) {
log.add(LogLevel.WARN, LogType.MSG_DC_TRAIL_SYM, 0);
} else {
log.add(LogLevel.WARN, LogType.MSG_DC_TRAIL_UNKNOWN, 0);
}
}
log.add(LogLevel.DEBUG, LogType.MSG_DC_PREP_STREAMS, indent);
// we made sure above one of these two would be true
if (symmetricPacketFound) { if (symmetricPacketFound) {
currentProgress += 2; currentProgress += 2;
updateProgress(R.string.progress_preparing_streams, currentProgress, 100); updateProgress(R.string.progress_preparing_streams, currentProgress, 100);
@ -372,17 +397,21 @@ public class PgpDecryptVerify {
mPassphrase.toCharArray()); mPassphrase.toCharArray());
clear = encryptedDataSymmetric.getDataStream(decryptorFactory); clear = encryptedDataSymmetric.getDataStream(decryptorFactory);
encryptedData = encryptedDataSymmetric; encryptedData = encryptedDataSymmetric;
} else if (asymmetricPacketFound) { } else if (asymmetricPacketFound) {
currentProgress += 2; currentProgress += 2;
updateProgress(R.string.progress_extracting_key, currentProgress, 100); updateProgress(R.string.progress_extracting_key, currentProgress, 100);
try { try {
log.add(LogLevel.INFO, LogType.MSG_DC_UNLOCKING, indent +1);
if (!secretEncryptionKey.unlock(mPassphrase)) { if (!secretEncryptionKey.unlock(mPassphrase)) {
throw new WrongPassphraseException(); log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_BAD_PASSPHRASE, indent +1);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
} catch (PgpGeneralException e) { } catch (PgpGeneralException e) {
throw new KeyExtractionException(); log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_EXTRACT_KEY, indent +1);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
currentProgress += 2; currentProgress += 2;
@ -393,12 +422,20 @@ public class PgpDecryptVerify {
= secretEncryptionKey.getDecryptorFactory(mDecryptedSessionKey); = secretEncryptionKey.getDecryptorFactory(mDecryptedSessionKey);
clear = encryptedDataAsymmetric.getDataStream(decryptorFactory); clear = encryptedDataAsymmetric.getDataStream(decryptorFactory);
} catch (NfcSyncPublicKeyDataDecryptorFactoryBuilder.NfcInteractionNeeded e) { } catch (NfcSyncPublicKeyDataDecryptorFactoryBuilder.NfcInteractionNeeded e) {
throw new NeedNfcDataException(e.encryptedSessionKey, mPassphrase); log.add(LogLevel.INFO, LogType.MSG_DC_PENDING_NFC, indent +1);
DecryptVerifyResult result =
new DecryptVerifyResult(DecryptVerifyResult.RESULT_PENDING_NFC, log);
result.setNfcEncryptedSessionKey(e.encryptedSessionKey);
// TODO save passphrase here?
return result;
} }
encryptedData = encryptedDataAsymmetric; encryptedData = encryptedDataAsymmetric;
} else { } else {
// If we didn't find any useful data, error out
// no packet has been found where we have the corresponding secret key in our db // no packet has been found where we have the corresponding secret key in our db
throw new NoSecretKeyException(); log.add(LogLevel.ERROR,
anyPacketFound ? LogType.MSG_DC_ERROR_NO_KEY : LogType.MSG_DC_ERROR_NO_DATA, indent +1);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
PGPObjectFactory plainFact = new PGPObjectFactory(clear, new JcaKeyFingerprintCalculator()); PGPObjectFactory plainFact = new PGPObjectFactory(clear, new JcaKeyFingerprintCalculator());
@ -408,7 +445,11 @@ public class PgpDecryptVerify {
CanonicalizedPublicKeyRing signingRing = null; CanonicalizedPublicKeyRing signingRing = null;
CanonicalizedPublicKey signingKey = null; CanonicalizedPublicKey signingKey = null;
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR, indent);
indent += 1;
if (dataChunk instanceof PGPCompressedData) { if (dataChunk instanceof PGPCompressedData) {
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_DECOMPRESS, indent +1);
currentProgress += 2; currentProgress += 2;
updateProgress(R.string.progress_decompressing_data, currentProgress, 100); updateProgress(R.string.progress_decompressing_data, currentProgress, 100);
@ -421,6 +462,7 @@ public class PgpDecryptVerify {
PGPOnePassSignature signature = null; PGPOnePassSignature signature = null;
if (dataChunk instanceof PGPOnePassSignatureList) { if (dataChunk instanceof PGPOnePassSignatureList) {
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_SIGNATURE, indent +1);
currentProgress += 2; currentProgress += 2;
updateProgress(R.string.progress_processing_signature, currentProgress, 100); updateProgress(R.string.progress_processing_signature, currentProgress, 100);
@ -468,7 +510,11 @@ public class PgpDecryptVerify {
dataChunk = plainFact.nextObject(); dataChunk = plainFact.nextObject();
} }
OpenPgpMetadata metadata;
if (dataChunk instanceof PGPLiteralData) { if (dataChunk instanceof PGPLiteralData) {
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_DATA, indent +1);
indent += 2;
currentProgress += 4; currentProgress += 4;
updateProgress(R.string.progress_decrypting, currentProgress, 100); updateProgress(R.string.progress_decrypting, currentProgress, 100);
@ -503,17 +549,30 @@ public class PgpDecryptVerify {
} }
} }
OpenPgpMetadata metadata = new OpenPgpMetadata( metadata = new OpenPgpMetadata(
originalFilename, originalFilename,
mimeType, mimeType,
literalData.getModificationTime().getTime(), literalData.getModificationTime().getTime(),
originalSize); originalSize);
result.setDecryptMetadata(metadata);
Log.d(Constants.TAG, "metadata: " + metadata); if ( ! originalFilename.equals("")) {
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_META_FILE, indent + 1, originalFilename);
}
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_META_MIME, indent +1,
mimeType);
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_META_TIME, indent +1,
new Date(literalData.getModificationTime().getTime()).toString());
if (originalSize != 0) {
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_META_SIZE, indent + 1,
Long.toString(originalSize));
}
// return here if we want to decrypt the metadata only // return here if we want to decrypt the metadata only
if (mDecryptMetadataOnly) { if (mDecryptMetadataOnly) {
log.add(LogLevel.OK, LogType.MSG_DC_OK_META_ONLY, indent);
DecryptVerifyResult result =
new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log);
result.setDecryptMetadata(metadata);
return result; return result;
} }
@ -557,6 +616,7 @@ public class PgpDecryptVerify {
if (signature != null) { if (signature != null) {
updateProgress(R.string.progress_verifying_signature, 90, 100); updateProgress(R.string.progress_verifying_signature, 90, 100);
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_SIGNATURE_CHECK, indent);
PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject(); PGPSignatureList signatureList = (PGPSignatureList) plainFact.nextObject();
PGPSignature messageSignature = signatureList.get(signatureIndex); PGPSignature messageSignature = signatureList.get(signatureIndex);
@ -567,20 +627,28 @@ public class PgpDecryptVerify {
// Verify signature and check binding signatures // Verify signature and check binding signatures
boolean validSignature = signature.verify(messageSignature); boolean validSignature = signature.verify(messageSignature);
if (validSignature) {
log.add(LogLevel.DEBUG, LogType.MSG_DC_CLEAR_SIGNATURE_OK, indent +1);
} else {
log.add(LogLevel.WARN, LogType.MSG_DC_CLEAR_SIGNATURE_BAD, indent +1);
}
signatureResultBuilder.setValidSignature(validSignature); signatureResultBuilder.setValidSignature(validSignature);
} }
indent -= 1;
} else {
// If there is no literalData, we don't have any metadata
metadata = null;
} }
if (encryptedData.isIntegrityProtected()) { if (encryptedData.isIntegrityProtected()) {
updateProgress(R.string.progress_verifying_integrity, 95, 100); updateProgress(R.string.progress_verifying_integrity, 95, 100);
if (encryptedData.verify()) { if (encryptedData.verify()) {
// passed log.add(LogLevel.INFO, LogType.MSG_DC_INTEGRITY_CHECK_OK, indent);
Log.d(Constants.TAG, "Integrity verification: success!");
} else { } else {
// failed log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_INTEGRITY_CHECK, indent);
Log.d(Constants.TAG, "Integrity verification: failed!"); return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
throw new IntegrityCheckFailedException();
} }
} else { } else {
// no integrity check // no integrity check
@ -590,14 +658,22 @@ public class PgpDecryptVerify {
// Handle missing integrity protection like failed integrity protection! // Handle missing integrity protection like failed integrity protection!
// The MDC packet can be stripped by an attacker! // The MDC packet can be stripped by an attacker!
if (!signatureResultBuilder.isValidSignature()) { if (!signatureResultBuilder.isValidSignature()) {
throw new IntegrityCheckFailedException(); log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_INTEGRITY_CHECK, indent);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
} }
updateProgress(R.string.progress_done, 100, 100); updateProgress(R.string.progress_done, 100, 100);
log.add(LogLevel.OK, LogType.MSG_DC_OK, indent);
// Return a positive result, with metadata and verification info
DecryptVerifyResult result =
new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log);
result.setDecryptMetadata(metadata);
result.setSignatureResult(signatureResultBuilder.build()); result.setSignatureResult(signatureResultBuilder.build());
return result; return result;
} }
/** /**
@ -607,9 +683,11 @@ public class PgpDecryptVerify {
* The method is heavily based on * The method is heavily based on
* pg/src/main/java/org/spongycastle/openpgp/examples/ClearSignedFileProcessor.java * pg/src/main/java/org/spongycastle/openpgp/examples/ClearSignedFileProcessor.java
*/ */
private PgpDecryptVerifyResult verifyCleartextSignature(ArmoredInputStream aIn) private DecryptVerifyResult verifyCleartextSignature(ArmoredInputStream aIn)
throws IOException, PGPException, SignatureException, InvalidDataException { throws IOException, PGPException {
PgpDecryptVerifyResult result = new PgpDecryptVerifyResult();
OperationLog log = new OperationLog();
OpenPgpSignatureResultBuilder signatureResultBuilder = new OpenPgpSignatureResultBuilder(); OpenPgpSignatureResultBuilder signatureResultBuilder = new OpenPgpSignatureResultBuilder();
// cleartext signatures are never encrypted ;) // cleartext signatures are never encrypted ;)
signatureResultBuilder.setSignatureOnly(true); signatureResultBuilder.setSignatureOnly(true);
@ -643,7 +721,8 @@ public class PgpDecryptVerify {
PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject(); PGPSignatureList sigList = (PGPSignatureList) pgpFact.nextObject();
if (sigList == null) { if (sigList == null) {
throw new InvalidDataException(); log.add(LogLevel.ERROR, LogType.MSG_DC_ERROR_INVALID_SIGLIST, 0);
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
CanonicalizedPublicKeyRing signingRing = null; CanonicalizedPublicKeyRing signingRing = null;
@ -686,7 +765,7 @@ public class PgpDecryptVerify {
} }
} }
if (signature != null) { if (signature != null) try {
updateProgress(R.string.progress_verifying_signature, 90, 100); updateProgress(R.string.progress_verifying_signature, 90, 100);
InputStream sigIn = new BufferedInputStream(new ByteArrayInputStream(clearText)); InputStream sigIn = new BufferedInputStream(new ByteArrayInputStream(clearText));
@ -708,13 +787,16 @@ public class PgpDecryptVerify {
// Verify signature and check binding signatures // Verify signature and check binding signatures
boolean validSignature = signature.verify(); boolean validSignature = signature.verify();
signatureResultBuilder.setValidSignature(validSignature); signatureResultBuilder.setValidSignature(validSignature);
} catch (SignatureException e) {
return new DecryptVerifyResult(DecryptVerifyResult.RESULT_ERROR, log);
} }
result.setSignatureResult(signatureResultBuilder.build());
updateProgress(R.string.progress_done, 100, 100); updateProgress(R.string.progress_done, 100, 100);
DecryptVerifyResult result = new DecryptVerifyResult(DecryptVerifyResult.RESULT_OK, log);
result.setSignatureResult(signatureResultBuilder.build());
return result; return result;
} }

View File

@ -34,7 +34,7 @@ import org.sufficientlysecure.keychain.nfc.NfcActivity;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@ -462,32 +462,23 @@ public class OpenPgpService extends RemoteService {
.setDecryptMetadataOnly(decryptMetadataOnly) .setDecryptMetadataOnly(decryptMetadataOnly)
.setNfcState(nfcDecryptedSessionKey); .setNfcState(nfcDecryptedSessionKey);
PgpDecryptVerifyResult decryptVerifyResult; // TODO: currently does not support binary signed-only content
try { DecryptVerifyResult decryptVerifyResult = builder.build().execute();
// TODO: currently does not support binary signed-only content
decryptVerifyResult = builder.build().execute();
// throw exceptions upwards to client with meaningful messages if (decryptVerifyResult.isPending()) {
} catch (PgpDecryptVerify.InvalidDataException e) { switch (decryptVerifyResult.getResult()) {
throw new Exception(getString(R.string.error_invalid_data)); case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
} catch (PgpDecryptVerify.KeyExtractionException e) { return getPassphraseIntent(data, decryptVerifyResult.getKeyIdPassphraseNeeded());
throw new Exception(getString(R.string.error_could_not_extract_private_key)); case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
} catch (PgpDecryptVerify.WrongPassphraseException e) { throw new PgpGeneralException(
throw new Exception(getString(R.string.error_wrong_passphrase)); "Decryption of symmetric content not supported by API!");
} catch (PgpDecryptVerify.NoSecretKeyException e) { case DecryptVerifyResult.RESULT_PENDING_NFC:
throw new Exception(getString(R.string.error_no_secret_key_found)); // TODO get passphrase here? currently not in DecryptVerifyResult
} catch (PgpDecryptVerify.IntegrityCheckFailedException e) { return getNfcDecryptIntent(
throw new Exception(getString(R.string.error_integrity_check_failed)); data, null, decryptVerifyResult.getNfcEncryptedSessionKey());
} catch (PgpDecryptVerify.NeedNfcDataException e) { }
// return PendingIntent to execute NFC activity throw new PgpGeneralException(
return getNfcDecryptIntent(data, e.mPassphrase, e.mEncryptedSessionKey); "Encountered unhandled type of pending action not supported by API!");
}
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
// get PendingIntent for passphrase input, add it to given params and return to client
return getPassphraseIntent(data, decryptVerifyResult.getKeyIdPassphraseNeeded());
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) {
throw new PgpGeneralException("Decryption of symmetric content not supported by API!");
} }
OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult();

View File

@ -41,7 +41,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.pgp.PgpImportExport; import org.sufficientlysecure.keychain.pgp.PgpImportExport;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
@ -343,12 +343,12 @@ public class KeychainIntentService extends IntentService implements Progressable
new ProviderHelper(this), new ProviderHelper(this),
new PgpDecryptVerify.PassphraseCache() { new PgpDecryptVerify.PassphraseCache() {
@Override @Override
public String getCachedPassphrase(long masterKeyId) throws PgpDecryptVerify.NoSecretKeyException { public String getCachedPassphrase(long masterKeyId) {
try { try {
return PassphraseCacheService.getCachedPassphrase( return PassphraseCacheService.getCachedPassphrase(
KeychainIntentService.this, masterKeyId); KeychainIntentService.this, masterKeyId);
} catch (PassphraseCacheService.KeyNotFoundException e) { } catch (PassphraseCacheService.KeyNotFoundException e) {
throw new PgpDecryptVerify.NoSecretKeyException(); return null;
} }
} }
}, },
@ -358,7 +358,7 @@ public class KeychainIntentService extends IntentService implements Progressable
.setAllowSymmetricDecryption(true) .setAllowSymmetricDecryption(true)
.setPassphrase(passphrase); .setPassphrase(passphrase);
PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute(); DecryptVerifyResult decryptVerifyResult = builder.build().execute();
outStream.close(); outStream.close();
@ -407,7 +407,7 @@ public class KeychainIntentService extends IntentService implements Progressable
.setPassphrase(passphrase) .setPassphrase(passphrase)
.setDecryptMetadataOnly(true); .setDecryptMetadataOnly(true);
PgpDecryptVerifyResult decryptVerifyResult = builder.build().execute(); DecryptVerifyResult decryptVerifyResult = builder.build().execute();
resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT, decryptVerifyResult); resultData.putParcelable(RESULT_DECRYPT_VERIFY_RESULT, decryptVerifyResult);
@ -785,16 +785,6 @@ public class KeychainIntentService extends IntentService implements Progressable
message = getString(R.string.error_no_signature_passphrase); message = getString(R.string.error_no_signature_passphrase);
} else if (e instanceof PgpSignEncrypt.NoSigningKeyException) { } else if (e instanceof PgpSignEncrypt.NoSigningKeyException) {
message = getString(R.string.error_no_signature_key); message = getString(R.string.error_no_signature_key);
} else if (e instanceof PgpDecryptVerify.InvalidDataException) {
message = getString(R.string.error_invalid_data);
} else if (e instanceof PgpDecryptVerify.KeyExtractionException) {
message = getString(R.string.error_could_not_extract_private_key);
} else if (e instanceof PgpDecryptVerify.WrongPassphraseException) {
message = getString(R.string.error_wrong_passphrase);
} else if (e instanceof PgpDecryptVerify.NoSecretKeyException) {
message = getString(R.string.error_no_secret_key_found);
} else if (e instanceof PgpDecryptVerify.IntegrityCheckFailedException) {
message = getString(R.string.error_integrity_check_failed);
} else { } else {
message = e.getMessage(); message = e.getMessage();
} }

View File

@ -15,33 +15,29 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.sufficientlysecure.keychain.pgp; package org.sufficientlysecure.keychain.service.results;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable;
import org.openintents.openpgp.OpenPgpMetadata; import org.openintents.openpgp.OpenPgpMetadata;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
public class PgpDecryptVerifyResult implements Parcelable { public class DecryptVerifyResult extends OperationResultParcel {
public static final int SUCCESS = 1;
public static final int KEY_PASSHRASE_NEEDED = 2; // the fourth bit indicates a "data pending" result!
public static final int SYMMETRIC_PASSHRASE_NEEDED = 3; public static final int RESULT_PENDING = 8;
// fifth to sixth bit in addition indicate specific type of pending
public static final int RESULT_PENDING_ASYM_PASSPHRASE = RESULT_PENDING +16;
public static final int RESULT_PENDING_SYM_PASSPHRASE = RESULT_PENDING +32;
public static final int RESULT_PENDING_NFC = RESULT_PENDING +48;
int mStatus;
long mKeyIdPassphraseNeeded; long mKeyIdPassphraseNeeded;
byte[] mNfcSessionKey;
OpenPgpSignatureResult mSignatureResult; OpenPgpSignatureResult mSignatureResult;
OpenPgpMetadata mDecryptMetadata; OpenPgpMetadata mDecryptMetadata;
public int getStatus() {
return mStatus;
}
public void setStatus(int status) {
mStatus = status;
}
public long getKeyIdPassphraseNeeded() { public long getKeyIdPassphraseNeeded() {
return mKeyIdPassphraseNeeded; return mKeyIdPassphraseNeeded;
} }
@ -50,6 +46,14 @@ public class PgpDecryptVerifyResult implements Parcelable {
mKeyIdPassphraseNeeded = keyIdPassphraseNeeded; mKeyIdPassphraseNeeded = keyIdPassphraseNeeded;
} }
public void setNfcEncryptedSessionKey(byte[] sessionKey) {
mNfcSessionKey = sessionKey;
}
public byte[] getNfcEncryptedSessionKey() {
return mNfcSessionKey;
}
public OpenPgpSignatureResult getSignatureResult() { public OpenPgpSignatureResult getSignatureResult() {
return mSignatureResult; return mSignatureResult;
} }
@ -66,41 +70,47 @@ public class PgpDecryptVerifyResult implements Parcelable {
mDecryptMetadata = decryptMetadata; mDecryptMetadata = decryptMetadata;
} }
public PgpDecryptVerifyResult() { public boolean isPending() {
return (mResult & RESULT_PENDING) != 0;
} }
public PgpDecryptVerifyResult(PgpDecryptVerifyResult b) { public DecryptVerifyResult(int result, OperationLog log) {
this.mStatus = b.mStatus; super(result, log);
this.mKeyIdPassphraseNeeded = b.mKeyIdPassphraseNeeded;
this.mSignatureResult = b.mSignatureResult;
this.mDecryptMetadata = b.mDecryptMetadata;
} }
public DecryptVerifyResult(Parcel source) {
super(source);
mKeyIdPassphraseNeeded = source.readLong();
mSignatureResult = source.readParcelable(OpenPgpSignatureResult.class.getClassLoader());
mDecryptMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader());
mNfcSessionKey = source.readInt() != 0 ? source.createByteArray() : null;
}
public int describeContents() { public int describeContents() {
return 0; return 0;
} }
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mStatus); super.writeToParcel(dest, flags);
dest.writeLong(mKeyIdPassphraseNeeded); dest.writeLong(mKeyIdPassphraseNeeded);
dest.writeParcelable(mSignatureResult, 0); dest.writeParcelable(mSignatureResult, 0);
dest.writeParcelable(mDecryptMetadata, 0); dest.writeParcelable(mDecryptMetadata, 0);
if (mNfcSessionKey != null) {
dest.writeInt(1);
dest.writeByteArray(mNfcSessionKey);
} else {
dest.writeInt(0);
}
} }
public static final Creator<PgpDecryptVerifyResult> CREATOR = new Creator<PgpDecryptVerifyResult>() { public static final Creator<DecryptVerifyResult> CREATOR = new Creator<DecryptVerifyResult>() {
public PgpDecryptVerifyResult createFromParcel(final Parcel source) { public DecryptVerifyResult createFromParcel(final Parcel source) {
PgpDecryptVerifyResult vr = new PgpDecryptVerifyResult(); return new DecryptVerifyResult(source);
vr.mStatus = source.readInt();
vr.mKeyIdPassphraseNeeded = source.readLong();
vr.mSignatureResult = source.readParcelable(OpenPgpSignatureResult.class.getClassLoader());
vr.mDecryptMetadata = source.readParcelable(OpenPgpMetadata.class.getClassLoader());
return vr;
} }
public PgpDecryptVerifyResult[] newArray(final int size) { public DecryptVerifyResult[] newArray(final int size) {
return new PgpDecryptVerifyResult[size]; return new DecryptVerifyResult[size];
} }
}; };
} }

View File

@ -435,6 +435,44 @@ public class OperationResultParcel implements Parcelable {
MSG_EK_ERROR_DUMMY (R.string.msg_ek_error_dummy), MSG_EK_ERROR_DUMMY (R.string.msg_ek_error_dummy),
MSG_EK_ERROR_NOT_FOUND (R.string.msg_ek_error_not_found), MSG_EK_ERROR_NOT_FOUND (R.string.msg_ek_error_not_found),
// decryptverify
MSG_DC_ASKIP_NO_KEY (R.string.msg_dc_askip_no_key),
MSG_DC_ASKIP_NOT_ALLOWED (R.string.msg_dc_askip_not_allowed),
MSG_DC_ASYM (R.string.msg_dc_asym),
MSG_DC_CLEAR_DATA (R.string.msg_dc_clear_data),
MSG_DC_CLEAR_DECOMPRESS (R.string.msg_dc_clear_decompress),
MSG_DC_CLEAR_META_FILE (R.string.msg_dc_clear_meta_file),
MSG_DC_CLEAR_META_MIME (R.string.msg_dc_clear_meta_mime),
MSG_DC_CLEAR_META_SIZE (R.string.msg_dc_clear_meta_size),
MSG_DC_CLEAR_META_TIME (R.string.msg_dc_clear_meta_time),
MSG_DC_CLEAR (R.string.msg_dc_clear),
MSG_DC_CLEAR_SIGNATURE_BAD (R.string.msg_dc_clear_signature_bad),
MSG_DC_CLEAR_SIGNATURE_CHECK (R.string.msg_dc_clear_signature_check),
MSG_DC_CLEAR_SIGNATURE_OK (R.string.msg_dc_clear_signature_ok),
MSG_DC_CLEAR_SIGNATURE (R.string.msg_dc_clear_signature),
MSG_DC_ERROR_BAD_PASSPHRASE (R.string.msg_dc_error_bad_passphrase),
MSG_DC_ERROR_EXTRACT_KEY (R.string.msg_dc_error_extract_key),
MSG_DC_ERROR_INTEGRITY_CHECK (R.string.msg_dc_error_integrity_check),
MSG_DC_ERROR_INVALID_SIGLIST(R.string.msg_dc_error_invalid_siglist),
MSG_DC_ERROR_IO (R.string.msg_dc_error_io),
MSG_DC_ERROR_NO_DATA (R.string.msg_dc_error_no_data),
MSG_DC_ERROR_NO_KEY (R.string.msg_dc_error_no_key),
MSG_DC_ERROR_PGP_EXCEPTION (R.string.msg_dc_error_pgp_exception),
MSG_DC_INTEGRITY_CHECK_OK (R.string.msg_dc_integrity_check_ok),
MSG_DC_OK_META_ONLY (R.string.msg_dc_ok_meta_only),
MSG_DC_OK (R.string.msg_dc_ok),
MSG_DC_PASS_CACHED (R.string.msg_dc_pass_cached),
MSG_DC_PENDING_NFC (R.string.msg_dc_pending_nfc),
MSG_DC_PENDING_PASSPHRASE (R.string.msg_dc_pending_passphrase),
MSG_DC_PREP_STREAMS (R.string.msg_dc_prep_streams),
MSG_DC (R.string.msg_dc),
MSG_DC_SYM (R.string.msg_dc_sym),
MSG_DC_SYM_SKIP (R.string.msg_dc_sym_skip),
MSG_DC_TRAIL_ASYM (R.string.msg_dc_trail_asym),
MSG_DC_TRAIL_SYM (R.string.msg_dc_trail_sym),
MSG_DC_TRAIL_UNKNOWN (R.string.msg_dc_trail_unknown),
MSG_DC_UNLOCKING (R.string.msg_dc_unlocking),
; ;
private final int mMsgId; private final int mMsgId;

View File

@ -36,7 +36,7 @@ import android.widget.TextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.FileHelper; import org.sufficientlysecure.keychain.helper.FileHelper;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
@ -178,19 +178,20 @@ public class DecryptFileFragment extends DecryptFragment {
// get returned data bundle // get returned data bundle
Bundle returnData = message.getData(); Bundle returnData = message.getData();
PgpDecryptVerifyResult decryptVerifyResult = DecryptVerifyResult result =
returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT); returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT);
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { switch (result.getResult()) {
showPassphraseDialogForFilename(decryptVerifyResult.getKeyIdPassphraseNeeded()); case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == showPassphraseDialog(result.getKeyIdPassphraseNeeded());
decryptVerifyResult.getStatus()) { return;
showPassphraseDialogForFilename(Constants.key.symmetric); case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
} else { showPassphraseDialog(Constants.key.symmetric);
return;
// go on...
askForOutputFilename(decryptVerifyResult.getDecryptMetadata().getFilename());
} }
// go on...
askForOutputFilename(result.getDecryptMetadata().getFilename());
} }
} }
}; };
@ -257,35 +258,43 @@ public class DecryptFileFragment extends DecryptFragment {
// get returned data bundle // get returned data bundle
Bundle returnData = message.getData(); Bundle returnData = message.getData();
PgpDecryptVerifyResult decryptVerifyResult = DecryptVerifyResult result =
returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT); returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT);
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { if (result.isPending()) {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded()); switch (result.getResult()) {
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
decryptVerifyResult.getStatus()) { showPassphraseDialog(result.getKeyIdPassphraseNeeded());
showPassphraseDialog(Constants.key.symmetric); return;
} else { case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
// display signature result in activity showPassphraseDialog(Constants.key.symmetric);
onResult(decryptVerifyResult); return;
if (mDeleteAfter.isChecked()) {
// Create and show dialog to delete original file
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mInputUri);
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
setInputUri(null);
} }
// error, we can't work with this!
/* result.createNotify(getActivity());
// A future open after decryption feature return;
if () {
Intent viewFile = new Intent(Intent.ACTION_VIEW);
viewFile.setData(mOutputUri);
startActivity(viewFile);
}
*/
} }
// display signature result in activity
onResult(result);
if (mDeleteAfter.isChecked()) {
// Create and show dialog to delete original file
DeleteFileDialogFragment deleteFileDialog = DeleteFileDialogFragment.newInstance(mInputUri);
deleteFileDialog.show(getActivity().getSupportFragmentManager(), "deleteDialog");
setInputUri(null);
}
/*
// A future open after decryption feature
if () {
Intent viewFile = new Intent(Intent.ACTION_VIEW);
viewFile.setData(mOutputUri);
startActivity(viewFile);
}
*/
} }
} }
}; };

View File

@ -34,7 +34,7 @@ import android.widget.TextView;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment; import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
@ -100,7 +100,7 @@ public abstract class DecryptFragment extends Fragment {
} }
} }
protected void onResult(PgpDecryptVerifyResult decryptVerifyResult) { protected void onResult(DecryptVerifyResult decryptVerifyResult) {
OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult(); OpenPgpSignatureResult signatureResult = decryptVerifyResult.getSignatureResult();
mSignatureKeyId = 0; mSignatureKeyId = 0;

View File

@ -31,7 +31,7 @@ import android.widget.EditText;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.ClipboardReflection; import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.service.results.DecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler; import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
@ -143,24 +143,34 @@ public class DecryptMessageFragment extends DecryptFragment {
// get returned data bundle // get returned data bundle
Bundle returnData = message.getData(); Bundle returnData = message.getData();
PgpDecryptVerifyResult decryptVerifyResult = DecryptVerifyResult result =
returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT); returnData.getParcelable(KeychainIntentService.RESULT_DECRYPT_VERIFY_RESULT);
if (PgpDecryptVerifyResult.KEY_PASSHRASE_NEEDED == decryptVerifyResult.getStatus()) { if (result.isPending()) {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded()); switch (result.getResult()) {
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == case DecryptVerifyResult.RESULT_PENDING_ASYM_PASSPHRASE:
decryptVerifyResult.getStatus()) { showPassphraseDialog(result.getKeyIdPassphraseNeeded());
showPassphraseDialog(Constants.key.symmetric); return;
} else { case DecryptVerifyResult.RESULT_PENDING_SYM_PASSPHRASE:
byte[] decryptedMessage = returnData showPassphraseDialog(Constants.key.symmetric);
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); return;
mMessage.setText(new String(decryptedMessage)); }
mMessage.setHorizontallyScrolling(false); // error, we can't work with this!
result.createNotify(getActivity()).show();
// display signature result in activity return;
onResult(decryptVerifyResult);
} }
byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);
mMessage.setText(new String(decryptedMessage));
mMessage.setHorizontallyScrolling(false);
result.createNotify(getActivity()).show();
// display signature result in activity
onResult(result);
} }
} }
}; };

View File

@ -764,6 +764,44 @@
<string name="msg_ek_error_dummy">"Cannot edit keyring with stripped master key!"</string> <string name="msg_ek_error_dummy">"Cannot edit keyring with stripped master key!"</string>
<string name="msg_ek_error_not_found">"Key not found!"</string> <string name="msg_ek_error_not_found">"Key not found!"</string>
<!-- Messages for DecryptVerify operation -->
<string name="msg_dc_askip_no_key">"Data not encrypted with known key, skipping…"</string>
<string name="msg_dc_askip_not_allowed">"Data not encrypted with allowed key, skipping…"</string>
<string name="msg_dc_asym">"Found block of asymmetrically encrypted data for key %s"</string>
<string name="msg_dc_clear_data">"Processing literal data"</string>
<string name="msg_dc_clear_decompress">"Unpacking compressed data"</string>
<string name="msg_dc_clear_meta_file">"Filename: %s"</string>
<string name="msg_dc_clear_meta_mime">"MIME type: %s"</string>
<string name="msg_dc_clear_meta_size">"Filesize: %s"</string>
<string name="msg_dc_clear_meta_time">"Modification time: %s"</string>
<string name="msg_dc_clear_signature_bad">"Signature check NOT OK!"</string>
<string name="msg_dc_clear_signature_check">"Verifying signature data"</string>
<string name="msg_dc_clear_signature_ok">"Signature check OK"</string>
<string name="msg_dc_clear_signature">"Saving signature data for later"</string>
<string name="msg_dc_clear">"Processing cleartext data"</string>
<string name="msg_dc_error_bad_passphrase">"Error unlocking key, bad passphrase!"</string>
<string name="msg_dc_error_extract_key">"Unknown error unlocking key!"</string>
<string name="msg_dc_error_integrity_check">"Integrity check error!"</string>
<string name="msg_dc_error_invalid_siglist">"No valid signature data found!"</string>
<string name="msg_dc_error_io">"Encountered IO Exception during operation!"</string>
<string name="msg_dc_error_no_data">"No encrypted data found in stream!"</string>
<string name="msg_dc_error_no_key">"No encrypted data with known secret key found in stream!"</string>
<string name="msg_dc_error_pgp_exception">"Encountered PGP Exception during operation!"</string>
<string name="msg_dc_integrity_check_ok">"Integrity check ok!"</string>
<string name="msg_dc_ok_meta_only">"Only metadata was requested, skipping decryption"</string>
<string name="msg_dc_ok">"OK"</string>
<string name="msg_dc_pass_cached">"Using passphrase from cache"</string>
<string name="msg_dc_pending_nfc">"NFC token required, requesting user input…"</string>
<string name="msg_dc_pending_passphrase">"Passphrase required, requesting user input…"</string>
<string name="msg_dc_prep_streams">"Preparing streams for decryption"</string>
<string name="msg_dc">"Starting decrypt operation…"</string>
<string name="msg_dc_sym_skip">"Symmetric data not allowed, skipping…"</string>
<string name="msg_dc_sym">"Found block of symmetrically encrypted data"</string>
<string name="msg_dc_trail_asym">"Encountered trailing, asymmetrically encrypted data"</string>
<string name="msg_dc_trail_sym">"Encountered trailing, symmetrically encrypted data"</string>
<string name="msg_dc_trail_unknown">"Encountered trailing data of unknown type"</string>
<string name="msg_dc_unlocking">"Unlocking secret key"</string>
<!-- PassphraseCache --> <!-- PassphraseCache -->
<string name="passp_cache_notif_click_to_clear">"Click to clear cached passphrases"</string> <string name="passp_cache_notif_click_to_clear">"Click to clear cached passphrases"</string>
<string name="passp_cache_notif_n_keys">"OpenKeychain has cached %d passphrases"</string> <string name="passp_cache_notif_n_keys">"OpenKeychain has cached %d passphrases"</string>