Fix encrypt only

This commit is contained in:
Dominik Schürmann 2014-08-16 03:59:58 +02:00
parent b1dc663930
commit 8d60d9f103
4 changed files with 34 additions and 37 deletions

View File

@ -68,7 +68,7 @@ public class PgpSignEncrypt {
private long mSignatureMasterKeyId; private long mSignatureMasterKeyId;
private int mSignatureHashAlgorithm; private int mSignatureHashAlgorithm;
private String mSignaturePassphrase; private String mSignaturePassphrase;
private boolean mEncryptToSigner; private long mAdditionalEncryptId;
private boolean mCleartextInput; private boolean mCleartextInput;
private String mOriginalFilename; private String mOriginalFilename;
@ -98,7 +98,7 @@ public class PgpSignEncrypt {
this.mSignatureMasterKeyId = builder.mSignatureMasterKeyId; this.mSignatureMasterKeyId = builder.mSignatureMasterKeyId;
this.mSignatureHashAlgorithm = builder.mSignatureHashAlgorithm; this.mSignatureHashAlgorithm = builder.mSignatureHashAlgorithm;
this.mSignaturePassphrase = builder.mSignaturePassphrase; this.mSignaturePassphrase = builder.mSignaturePassphrase;
this.mEncryptToSigner = builder.mEncryptToSigner; this.mAdditionalEncryptId = builder.mAdditionalEncryptId;
this.mCleartextInput = builder.mCleartextInput; this.mCleartextInput = builder.mCleartextInput;
this.mOriginalFilename = builder.mOriginalFilename; this.mOriginalFilename = builder.mOriginalFilename;
} }
@ -120,7 +120,7 @@ public class PgpSignEncrypt {
private long mSignatureMasterKeyId = Constants.key.none; private long mSignatureMasterKeyId = Constants.key.none;
private int mSignatureHashAlgorithm = 0; private int mSignatureHashAlgorithm = 0;
private String mSignaturePassphrase = null; private String mSignaturePassphrase = null;
private boolean mEncryptToSigner = false; private long mAdditionalEncryptId = Constants.key.none;
private boolean mCleartextInput = false; private boolean mCleartextInput = false;
private String mOriginalFilename = ""; private String mOriginalFilename = "";
@ -166,7 +166,7 @@ public class PgpSignEncrypt {
} }
public Builder setSignatureMasterKeyId(long signatureMasterKeyId) { public Builder setSignatureMasterKeyId(long signatureMasterKeyId) {
this.mSignatureMasterKeyId = signatureMasterKeyId; mSignatureMasterKeyId = signatureMasterKeyId;
return this; return this;
} }
@ -183,11 +183,11 @@ public class PgpSignEncrypt {
/** /**
* Also encrypt with the signing keyring * Also encrypt with the signing keyring
* *
* @param encryptToSigner * @param additionalEncryptId
* @return * @return
*/ */
public Builder setEncryptToSigner(boolean encryptToSigner) { public Builder setAdditionalEncryptId(long additionalEncryptId) {
mEncryptToSigner = encryptToSigner; mAdditionalEncryptId = additionalEncryptId;
return this; return this;
} }
@ -256,10 +256,10 @@ public class PgpSignEncrypt {
+ "\nenableCompression:" + enableCompression + "\nenableCompression:" + enableCompression
+ "\nenableAsciiArmorOutput:" + mEnableAsciiArmorOutput); + "\nenableAsciiArmorOutput:" + mEnableAsciiArmorOutput);
// add signature key id to encryption ids (self-encrypt) // add additional key id to encryption ids (mostly to do self-encryption)
if (enableEncryption && enableSignature && mEncryptToSigner) { if (enableEncryption && mAdditionalEncryptId != Constants.key.none) {
mEncryptionMasterKeyIds = Arrays.copyOf(mEncryptionMasterKeyIds, mEncryptionMasterKeyIds.length + 1); mEncryptionMasterKeyIds = Arrays.copyOf(mEncryptionMasterKeyIds, mEncryptionMasterKeyIds.length + 1);
mEncryptionMasterKeyIds[mEncryptionMasterKeyIds.length - 1] = mSignatureMasterKeyId; mEncryptionMasterKeyIds[mEncryptionMasterKeyIds.length - 1] = mAdditionalEncryptId;
} }
ArmoredOutputStream armorOut = null; ArmoredOutputStream armorOut = null;

View File

@ -29,7 +29,6 @@ import org.openintents.openpgp.OpenPgpMetadata;
import org.openintents.openpgp.OpenPgpError; import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.OpenPgpSignatureResult; import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.spongycastle.util.Arrays;
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;
@ -261,10 +260,6 @@ public class OpenPgpService extends RemoteService {
return result; return result;
} }
// add own key for encryption
keyIds = Arrays.copyOf(keyIds, keyIds.length + 1);
keyIds[keyIds.length - 1] = accSettings.getKeyId();
// build InputData and write into OutputStream // build InputData and write into OutputStream
// Get Input- and OutputStream from ParcelFileDescriptor // Get Input- and OutputStream from ParcelFileDescriptor
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input); InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
@ -281,7 +276,8 @@ public class OpenPgpService extends RemoteService {
.setCompressionId(accSettings.getCompression()) .setCompressionId(accSettings.getCompression())
.setSymmetricEncryptionAlgorithm(accSettings.getEncryptionAlgorithm()) .setSymmetricEncryptionAlgorithm(accSettings.getEncryptionAlgorithm())
.setEncryptionMasterKeyIds(keyIds) .setEncryptionMasterKeyIds(keyIds)
.setOriginalFilename(originalFilename); .setOriginalFilename(originalFilename)
.setAdditionalEncryptId(accSettings.getKeyId()); // add acc key for encryption
if (sign) { if (sign) {
String passphrase; String passphrase;
@ -300,9 +296,6 @@ public class OpenPgpService extends RemoteService {
builder.setSignatureHashAlgorithm(accSettings.getHashAlgorithm()) builder.setSignatureHashAlgorithm(accSettings.getHashAlgorithm())
.setSignatureMasterKeyId(accSettings.getKeyId()) .setSignatureMasterKeyId(accSettings.getKeyId())
.setSignaturePassphrase(passphrase); .setSignaturePassphrase(passphrase);
} else {
// encrypt only
builder.setSignatureMasterKeyId(Constants.key.none);
} }
try { try {

View File

@ -247,26 +247,30 @@ public class KeychainIntentService extends IntentService
String originalFilename = getOriginalFilename(data); String originalFilename = getOriginalFilename(data);
/* Operation */ /* Operation */
PgpSignEncrypt.Builder builder = PgpSignEncrypt.Builder builder = new PgpSignEncrypt.Builder(
new PgpSignEncrypt.Builder(
new ProviderHelper(this), new ProviderHelper(this),
inputData, outStream); inputData, outStream
builder.setProgressable(this); );
builder.setProgressable(this)
builder.setEnableAsciiArmorOutput(useAsciiArmor) .setEnableAsciiArmorOutput(useAsciiArmor)
.setVersionHeader(PgpHelper.getVersionForHeader(this)) .setVersionHeader(PgpHelper.getVersionForHeader(this))
.setCompressionId(compressionId) .setCompressionId(compressionId)
.setSymmetricEncryptionAlgorithm( .setSymmetricEncryptionAlgorithm(
Preferences.getPreferences(this).getDefaultEncryptionAlgorithm()) Preferences.getPreferences(this).getDefaultEncryptionAlgorithm())
.setEncryptionMasterKeyIds(encryptionKeyIds) .setEncryptionMasterKeyIds(encryptionKeyIds)
.setSymmetricPassphrase(symmetricPassphrase) .setSymmetricPassphrase(symmetricPassphrase)
.setSignatureMasterKeyId(signatureKeyId) .setOriginalFilename(originalFilename);
.setEncryptToSigner(true)
.setSignatureHashAlgorithm( try {
Preferences.getPreferences(this).getDefaultHashAlgorithm()) builder.setSignatureMasterKeyId(signatureKeyId)
.setSignaturePassphrase( .setSignaturePassphrase(
PassphraseCacheService.getCachedPassphrase(this, signatureKeyId)) PassphraseCacheService.getCachedPassphrase(this, signatureKeyId))
.setOriginalFilename(originalFilename); .setSignatureHashAlgorithm(
Preferences.getPreferences(this).getDefaultHashAlgorithm())
.setAdditionalEncryptId(signatureKeyId);
} catch (PassphraseCacheService.KeyNotFoundException e) {
// encrypt-only
}
// this assumes that the bytes are cleartext (valid for current implementation!) // this assumes that the bytes are cleartext (valid for current implementation!)
if (source == IO_BYTES) { if (source == IO_BYTES) {
@ -406,7 +410,7 @@ public class KeychainIntentService extends IntentService
} }
// If the edit operation didn't succeed, exit here // If the edit operation didn't succeed, exit here
if ( ! modifyResult.success()) { if (!modifyResult.success()) {
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, modifyResult); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, modifyResult);
return; return;
} }
@ -418,7 +422,7 @@ public class KeychainIntentService extends IntentService
.saveSecretKeyRing(ring, new ProgressScaler(this, 60, 95, 100)); .saveSecretKeyRing(ring, new ProgressScaler(this, 60, 95, 100));
// If the edit operation didn't succeed, exit here // If the edit operation didn't succeed, exit here
if ( ! saveResult.success()) { if (!saveResult.success()) {
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult); sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, saveResult);
return; return;
} }

View File

@ -77,7 +77,7 @@ public class PassphraseCacheService extends Service {
private static final int NOTIFICATION_ID = 1; private static final int NOTIFICATION_ID = 1;
private static final int MSG_PASSPHRASE_CACHE_GET_OKAY = 1; private static final int MSG_PASSPHRASE_CACHE_GET_OKAY = 1;
private static final int MSG_PASSPHRASE_CACHE_GET_KEY_NO_FOUND = 2; private static final int MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND = 2;
private BroadcastReceiver mIntentReceiver; private BroadcastReceiver mIntentReceiver;
@ -169,7 +169,7 @@ public class PassphraseCacheService extends Service {
switch (returnMessage.what) { switch (returnMessage.what) {
case MSG_PASSPHRASE_CACHE_GET_OKAY: case MSG_PASSPHRASE_CACHE_GET_OKAY:
return returnMessage.getData().getString(EXTRA_PASSPHRASE); return returnMessage.getData().getString(EXTRA_PASSPHRASE);
case MSG_PASSPHRASE_CACHE_GET_KEY_NO_FOUND: case MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND:
throw new KeyNotFoundException(); throw new KeyNotFoundException();
default: default:
throw new KeyNotFoundException("should not happen!"); throw new KeyNotFoundException("should not happen!");
@ -313,7 +313,7 @@ public class PassphraseCacheService extends Service {
msg.setData(bundle); msg.setData(bundle);
} catch (ProviderHelper.NotFoundException e) { } catch (ProviderHelper.NotFoundException e) {
Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!"); Log.e(Constants.TAG, "PassphraseCacheService: Passphrase for unknown key was requested!");
msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NO_FOUND; msg.what = MSG_PASSPHRASE_CACHE_GET_KEY_NOT_FOUND;
} }
try { try {