Removing remaining uses of Id, closing one of the oldest bugs #9

This commit is contained in:
Dominik Schürmann 2014-04-14 13:48:20 +02:00
parent 59220fbe04
commit b04e6816f4
26 changed files with 126 additions and 183 deletions

View File

@ -19,6 +19,7 @@ package org.sufficientlysecure.keychain;
import android.os.Environment; import android.os.Environment;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
import org.spongycastle.jce.provider.BouncyCastleProvider; import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.sufficientlysecure.keychain.remote.ui.AppsListActivity; import org.sufficientlysecure.keychain.remote.ui.AppsListActivity;
import org.sufficientlysecure.keychain.ui.DecryptActivity; import org.sufficientlysecure.keychain.ui.DecryptActivity;
@ -80,4 +81,24 @@ public final class Constants {
REGISTERED_APPS_LIST REGISTERED_APPS_LIST
}; };
} }
public static final class choice {
public static final class algorithm {
public static final int dsa = 0x21070001;
public static final int elgamal = 0x21070002;
public static final int rsa = 0x21070003;
}
public static final class compression {
public static final int none = 0x21070001;
public static final int zlib = CompressionAlgorithmTags.ZLIB;
public static final int bzip2 = CompressionAlgorithmTags.BZIP2;
public static final int zip = CompressionAlgorithmTags.ZIP;
}
}
public static final class key {
public static final int none = 0;
public static final int symmetric = -1;
}
} }

View File

@ -1,65 +0,0 @@
/*
* Copyright (C) 2010-2014 Thialfihar <thi@thialfihar.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
/**
* TODO:
* <p/>
* - refactor ids, some are not needed and can be done with xml
*/
public final class Id {
public static final class type {
public static final int public_key = 0x21070001;
public static final int secret_key = 0x21070002;
public static final int user_id = 0x21070003;
public static final int key = 0x21070004;
}
public static final class choice {
public static final class algorithm {
public static final int dsa = 0x21070001;
public static final int elgamal = 0x21070002;
public static final int rsa = 0x21070003;
}
public static final class compression {
public static final int none = 0x21070001;
public static final int zlib = CompressionAlgorithmTags.ZLIB;
public static final int bzip2 = CompressionAlgorithmTags.BZIP2;
public static final int zip = CompressionAlgorithmTags.ZIP;
}
}
public static final class return_value {
public static final int ok = 0;
public static final int error = -1;
public static final int no_master_key = -2;
public static final int updated = 1;
public static final int bad = -3;
}
public static final class key {
public static final int none = 0;
public static final int symmetric = -1;
}
}

View File

@ -28,7 +28,6 @@ import android.os.Messenger;
import android.support.v7.app.ActionBarActivity; import android.support.v7.app.ActionBarActivity;
import android.widget.Toast; import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround; import org.sufficientlysecure.keychain.compatibility.DialogFragmentWorkaround;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;

View File

@ -23,7 +23,6 @@ import android.content.SharedPreferences;
import org.spongycastle.bcpg.HashAlgorithmTags; import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.openpgp.PGPEncryptedData; import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import java.util.Vector; import java.util.Vector;
@ -99,7 +98,7 @@ public class Preferences {
public int getDefaultMessageCompression() { public int getDefaultMessageCompression() {
return mSharedPreferences.getInt(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION, return mSharedPreferences.getInt(Constants.Pref.DEFAULT_MESSAGE_COMPRESSION,
Id.choice.compression.zlib); Constants.choice.compression.zlib);
} }
public void setDefaultMessageCompression(int value) { public void setDefaultMessageCompression(int value) {
@ -110,7 +109,7 @@ public class Preferences {
public int getDefaultFileCompression() { public int getDefaultFileCompression() {
return mSharedPreferences.getInt(Constants.Pref.DEFAULT_FILE_COMPRESSION, return mSharedPreferences.getInt(Constants.Pref.DEFAULT_FILE_COMPRESSION,
Id.choice.compression.none); Constants.choice.compression.none);
} }
public void setDefaultFileCompression(int value) { public void setDefaultFileCompression(int value) {

View File

@ -22,14 +22,7 @@ import android.content.Context;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import org.spongycastle.openpgp.PGPEncryptedDataList;
import org.spongycastle.openpgp.PGPObjectFactory;
import org.spongycastle.openpgp.PGPPublicKeyRing;
import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPUtil;
import org.sufficientlysecure.keychain.BuildConfig;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater; import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;

View File

@ -31,7 +31,6 @@ import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
@ -59,6 +58,11 @@ public class PgpImportExport {
private ProviderHelper mProviderHelper; private ProviderHelper mProviderHelper;
public static final int RETURN_OK = 0;
public static final int RETURN_ERROR = -1;
public static final int RETURN_BAD = -2;
public static final int RETURN_UPDATED = 1;
public PgpImportExport(Context context, ProgressDialogUpdater progress) { public PgpImportExport(Context context, ProgressDialogUpdater progress) {
super(); super();
this.mContext = context; this.mContext = context;
@ -112,8 +116,12 @@ public class PgpImportExport {
return false; return false;
} finally { } finally {
try { try {
if (aos != null) { aos.close(); } if (aos != null) {
if (bos != null) { bos.close(); } aos.close();
}
if (bos != null) {
bos.close();
}
} catch (IOException e) { } catch (IOException e) {
} }
} }
@ -142,17 +150,17 @@ public class PgpImportExport {
int status = storeKeyRingInCache(keyring); int status = storeKeyRingInCache(keyring);
if (status == Id.return_value.error) { if (status == RETURN_ERROR) {
throw new PgpGeneralException( throw new PgpGeneralException(
mContext.getString(R.string.error_saving_keys)); mContext.getString(R.string.error_saving_keys));
} }
// update the counts to display to the user at the end // update the counts to display to the user at the end
if (status == Id.return_value.updated) { if (status == RETURN_UPDATED) {
++oldKeys; ++oldKeys;
} else if (status == Id.return_value.ok) { } else if (status == RETURN_OK) {
++newKeys; ++newKeys;
} else if (status == Id.return_value.bad) { } else if (status == RETURN_BAD) {
++badKeys; ++badKeys;
} }
} else { } else {
@ -248,12 +256,9 @@ public class PgpImportExport {
return returnData; return returnData;
} }
/**
* TODO: implement Id.return_value.updated as status when key already existed
*/
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public int storeKeyRingInCache(PGPKeyRing keyring) { public int storeKeyRingInCache(PGPKeyRing keyring) {
int status = Integer.MIN_VALUE; // out of bounds value (Id.return_value.*) int status = RETURN_ERROR;
try { try {
if (keyring instanceof PGPSecretKeyRing) { if (keyring instanceof PGPSecretKeyRing) {
PGPSecretKeyRing secretKeyRing = (PGPSecretKeyRing) keyring; PGPSecretKeyRing secretKeyRing = (PGPSecretKeyRing) keyring;
@ -265,7 +270,7 @@ public class PgpImportExport {
if (testSecretKey.isPrivateKeyEmpty()) { if (testSecretKey.isPrivateKeyEmpty()) {
// this is bad, something is very wrong... // this is bad, something is very wrong...
save = false; save = false;
status = Id.return_value.bad; status = RETURN_BAD;
} }
} }
} }
@ -286,17 +291,15 @@ public class PgpImportExport {
mProviderHelper.saveKeyRing(newPubRing); mProviderHelper.saveKeyRing(newPubRing);
} }
mProviderHelper.saveKeyRing(secretKeyRing); mProviderHelper.saveKeyRing(secretKeyRing);
// TODO: remove status returns, use exceptions! status = RETURN_OK;
status = Id.return_value.ok;
} }
} else if (keyring instanceof PGPPublicKeyRing) { } else if (keyring instanceof PGPPublicKeyRing) {
PGPPublicKeyRing publicKeyRing = (PGPPublicKeyRing) keyring; PGPPublicKeyRing publicKeyRing = (PGPPublicKeyRing) keyring;
mProviderHelper.saveKeyRing(publicKeyRing); mProviderHelper.saveKeyRing(publicKeyRing);
// TODO: remove status returns, use exceptions! status = RETURN_OK;
status = Id.return_value.ok;
} }
} catch (IOException e) { } catch (IOException e) {
status = Id.return_value.error; status = RETURN_ERROR;
} }
return status; return status;

View File

@ -48,7 +48,6 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
@ -144,14 +143,14 @@ public class PgpKeyOperation {
KeyPairGenerator keyGen; KeyPairGenerator keyGen;
switch (algorithmChoice) { switch (algorithmChoice) {
case Id.choice.algorithm.dsa: { case Constants.choice.algorithm.dsa: {
keyGen = KeyPairGenerator.getInstance("DSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME); keyGen = KeyPairGenerator.getInstance("DSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
keyGen.initialize(keySize, new SecureRandom()); keyGen.initialize(keySize, new SecureRandom());
algorithm = PGPPublicKey.DSA; algorithm = PGPPublicKey.DSA;
break; break;
} }
case Id.choice.algorithm.elgamal: { case Constants.choice.algorithm.elgamal: {
if (isMasterKey) { if (isMasterKey) {
throw new PgpGeneralMsgIdException(R.string.error_master_key_must_not_be_el_gamal); throw new PgpGeneralMsgIdException(R.string.error_master_key_must_not_be_el_gamal);
} }
@ -166,7 +165,7 @@ public class PgpKeyOperation {
break; break;
} }
case Id.choice.algorithm.rsa: { case Constants.choice.algorithm.rsa: {
keyGen = KeyPairGenerator.getInstance("RSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME); keyGen = KeyPairGenerator.getInstance("RSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
keyGen.initialize(keySize, new SecureRandom()); keyGen.initialize(keySize, new SecureRandom());

View File

@ -41,7 +41,6 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator; import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
@ -123,11 +122,11 @@ public class PgpSignEncrypt {
// optional // optional
private ProgressDialogUpdater mProgress = null; private ProgressDialogUpdater mProgress = null;
private boolean mEnableAsciiArmorOutput = false; private boolean mEnableAsciiArmorOutput = false;
private int mCompressionId = Id.choice.compression.none; private int mCompressionId = Constants.choice.compression.none;
private long[] mEncryptionMasterKeyIds = null; private long[] mEncryptionMasterKeyIds = null;
private String mSymmetricPassphrase = null; private String mSymmetricPassphrase = null;
private int mSymmetricEncryptionAlgorithm = 0; private int mSymmetricEncryptionAlgorithm = 0;
private long mSignatureMasterKeyId = Id.key.none; private long mSignatureMasterKeyId = Constants.key.none;
private int mSignatureHashAlgorithm = 0; private int mSignatureHashAlgorithm = 0;
private boolean mSignatureForceV3 = false; private boolean mSignatureForceV3 = false;
private String mSignaturePassphrase = null; private String mSignaturePassphrase = null;
@ -252,10 +251,10 @@ public class PgpSignEncrypt {
throws IOException, PGPException, NoSuchProviderException, throws IOException, PGPException, NoSuchProviderException,
NoSuchAlgorithmException, SignatureException, KeyExtractionException, NoSigningKeyException, NoPassphraseException { NoSuchAlgorithmException, SignatureException, KeyExtractionException, NoSigningKeyException, NoPassphraseException {
boolean enableSignature = mSignatureMasterKeyId != Id.key.none; boolean enableSignature = mSignatureMasterKeyId != Constants.key.none;
boolean enableEncryption = ((mEncryptionMasterKeyIds != null && mEncryptionMasterKeyIds.length > 0) boolean enableEncryption = ((mEncryptionMasterKeyIds != null && mEncryptionMasterKeyIds.length > 0)
|| mSymmetricPassphrase != null); || mSymmetricPassphrase != null);
boolean enableCompression = (mCompressionId != Id.choice.compression.none); boolean enableCompression = (mCompressionId != Constants.choice.compression.none);
Log.d(Constants.TAG, "enableSignature:" + enableSignature Log.d(Constants.TAG, "enableSignature:" + enableSignature
+ "\nenableEncryption:" + enableEncryption + "\nenableEncryption:" + enableEncryption

View File

@ -19,11 +19,11 @@ package org.sufficientlysecure.keychain.remote;
import org.spongycastle.bcpg.HashAlgorithmTags; import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.openpgp.PGPEncryptedData; import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.Constants;
public class AccountSettings { public class AccountSettings {
private String mAccountName; private String mAccountName;
private long mKeyId = Id.key.none; private long mKeyId = Constants.key.none;
private int mEncryptionAlgorithm; private int mEncryptionAlgorithm;
private int mHashAlgorithm; private int mHashAlgorithm;
private int mCompression; private int mCompression;
@ -39,7 +39,7 @@ public class AccountSettings {
// defaults: // defaults:
this.mEncryptionAlgorithm = PGPEncryptedData.AES_256; this.mEncryptionAlgorithm = PGPEncryptedData.AES_256;
this.mHashAlgorithm = HashAlgorithmTags.SHA512; this.mHashAlgorithm = HashAlgorithmTags.SHA512;
this.mCompression = Id.choice.compression.zlib; this.mCompression = Constants.choice.compression.zlib;
} }
public String getAccountName() { public String getAccountName() {

View File

@ -30,7 +30,6 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.spongycastle.util.Arrays; import org.spongycastle.util.Arrays;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult;
import org.sufficientlysecure.keychain.pgp.PgpHelper; import org.sufficientlysecure.keychain.pgp.PgpHelper;
@ -269,7 +268,7 @@ public class OpenPgpService extends RemoteService {
.signaturePassphrase(passphrase); .signaturePassphrase(passphrase);
} else { } else {
// encrypt only // encrypt only
builder.signatureMasterKeyId(Id.key.none); builder.signatureMasterKeyId(Constants.key.none);
} }
// execute PGP operation! // execute PGP operation!
builder.build().execute(); builder.build().execute();

View File

@ -27,7 +27,6 @@ import android.view.View;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.sufficientlysecure.htmltextview.HtmlTextView; import org.sufficientlysecure.htmltextview.HtmlTextView;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
@ -142,7 +141,7 @@ public class RemoteServiceActivity extends ActionBarActivity {
// Save // Save
// user needs to select a key! // user needs to select a key!
if (mAccSettingsFragment.getAccSettings().getKeyId() == Id.key.none) { if (mAccSettingsFragment.getAccSettings().getKeyId() == Constants.key.none) {
mAccSettingsFragment.setErrorOnSelectKeyFragment( mAccSettingsFragment.setErrorOnSelectKeyFragment(
getString(R.string.api_register_error_select_key)); getString(R.string.api_register_error_select_key));
} else { } else {

View File

@ -36,7 +36,6 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.PGPUtil; import org.spongycastle.openpgp.PGPUtil;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
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.helper.OtherHelper; import org.sufficientlysecure.keychain.helper.OtherHelper;
@ -588,21 +587,21 @@ public class KeychainIntentService extends IntentService
keysTotal); keysTotal);
PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 100, 100)); PgpKeyOperation keyOperations = new PgpKeyOperation(new ProgressScaler(this, 0, 100, 100));
PGPSecretKey masterKey = keyOperations.createKey(Id.choice.algorithm.rsa, PGPSecretKey masterKey = keyOperations.createKey(Constants.choice.algorithm.rsa,
4096, passphrase, true); 4096, passphrase, true);
newKeys.add(masterKey); newKeys.add(masterKey);
keyUsageList.add(KeyFlags.CERTIFY_OTHER); keyUsageList.add(KeyFlags.CERTIFY_OTHER);
keysCreated++; keysCreated++;
setProgress(keysCreated, keysTotal); setProgress(keysCreated, keysTotal);
PGPSecretKey subKey = keyOperations.createKey(Id.choice.algorithm.rsa, PGPSecretKey subKey = keyOperations.createKey(Constants.choice.algorithm.rsa,
4096, passphrase, false); 4096, passphrase, false);
newKeys.add(subKey); newKeys.add(subKey);
keyUsageList.add(KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE); keyUsageList.add(KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE);
keysCreated++; keysCreated++;
setProgress(keysCreated, keysTotal); setProgress(keysCreated, keysTotal);
subKey = keyOperations.createKey(Id.choice.algorithm.rsa, subKey = keyOperations.createKey(Constants.choice.algorithm.rsa,
4096, passphrase, false); 4096, passphrase, false);
newKeys.add(subKey); newKeys.add(subKey);
keyUsageList.add(KeyFlags.SIGN_DATA); keyUsageList.add(KeyFlags.SIGN_DATA);
@ -846,7 +845,7 @@ public class KeychainIntentService extends IntentService
// store the signed key in our local cache // store the signed key in our local cache
PgpImportExport pgpImportExport = new PgpImportExport(this, null); PgpImportExport pgpImportExport = new PgpImportExport(this, null);
int retval = pgpImportExport.storeKeyRingInCache(publicRing); int retval = pgpImportExport.storeKeyRingInCache(publicRing);
if (retval != Id.return_value.ok && retval != Id.return_value.updated) { if (retval != PgpImportExport.RETURN_OK && retval != PgpImportExport.RETURN_UPDATED) {
throw new PgpGeneralException("Failed to store signed key in local cache"); throw new PgpGeneralException("Failed to store signed key in local cache");
} }

View File

@ -42,9 +42,7 @@ import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
@ -170,7 +168,7 @@ public class PassphraseCacheService extends Service {
// try to get master key id which is used as an identifier for cached passphrases // try to get master key id which is used as an identifier for cached passphrases
long masterKeyId = keyId; long masterKeyId = keyId;
if (masterKeyId != Id.key.symmetric) { if (masterKeyId != Constants.key.symmetric) {
try { try {
masterKeyId = new ProviderHelper(this).getMasterKeyId( masterKeyId = new ProviderHelper(this).getMasterKeyId(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId))); KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(Long.toString(keyId)));

View File

@ -33,9 +33,7 @@ import android.widget.EditText;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
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.pgp.PgpDecryptVerifyResult;
@ -202,7 +200,7 @@ public class DecryptFileFragment extends DecryptFragment {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded()); showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded());
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == } else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
decryptVerifyResult.getStatus()) { decryptVerifyResult.getStatus()) {
showPassphraseDialog(Id.key.symmetric); showPassphraseDialog(Constants.key.symmetric);
} else { } else {
// display signature result in activity // display signature result in activity
onResult(decryptVerifyResult); onResult(decryptVerifyResult);

View File

@ -31,9 +31,7 @@ import android.widget.EditText;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.openintents.openpgp.OpenPgpSignatureResult;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
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.pgp.PgpDecryptVerifyResult;
@ -156,7 +154,7 @@ public class DecryptMessageFragment extends DecryptFragment {
showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded()); showPassphraseDialog(decryptVerifyResult.getKeyIdPassphraseNeeded());
} else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED == } else if (PgpDecryptVerifyResult.SYMMETRIC_PASSHRASE_NEEDED ==
decryptVerifyResult.getStatus()) { decryptVerifyResult.getStatus()) {
showPassphraseDialog(Id.key.symmetric); showPassphraseDialog(Constants.key.symmetric);
} else { } else {
byte[] decryptedMessage = returnData byte[] decryptedMessage = returnData
.getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES); .getByteArray(KeychainIntentService.RESULT_DECRYPTED_BYTES);

View File

@ -44,11 +44,9 @@ import android.widget.Toast;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.ExportHelper;
@ -73,7 +71,6 @@ import org.sufficientlysecure.keychain.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.Vector; import java.util.Vector;
@ -391,13 +388,13 @@ public class EditKeyActivity extends ActionBarActivity implements EditorListener
mChangePassphrase.setText(getString(R.string.btn_change_passphrase)); mChangePassphrase.setText(getString(R.string.btn_change_passphrase));
} }
mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false); mUserIdsView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
mUserIdsView.setType(Id.type.user_id); mUserIdsView.setType(SectionView.TYPE_USER_ID);
mUserIdsView.setCanBeEdited(mMasterCanSign); mUserIdsView.setCanBeEdited(mMasterCanSign);
mUserIdsView.setUserIds(mUserIds); mUserIdsView.setUserIds(mUserIds);
mUserIdsView.setEditorListener(this); mUserIdsView.setEditorListener(this);
container.addView(mUserIdsView); container.addView(mUserIdsView);
mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false); mKeysView = (SectionView) inflater.inflate(R.layout.edit_key_section, container, false);
mKeysView.setType(Id.type.key); mKeysView.setType(SectionView.TYPE_KEY);
mKeysView.setCanBeEdited(mMasterCanSign); mKeysView.setCanBeEdited(mMasterCanSign);
mKeysView.setKeys(mKeys, mKeysUsages, newKeys); mKeysView.setKeys(mKeys, mKeysUsages, newKeys);
mKeysView.setEditorListener(this); mKeysView.setEditorListener(this);

View File

@ -26,7 +26,6 @@ import android.support.v4.view.ViewPager;
import android.widget.Toast; import android.widget.Toast;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ActionBarHelper; import org.sufficientlysecure.keychain.helper.ActionBarHelper;
import org.sufficientlysecure.keychain.helper.FileHelper; import org.sufficientlysecure.keychain.helper.FileHelper;
@ -74,7 +73,7 @@ public class EncryptActivity extends DrawerActivity implements
// model useb by message and file fragment // model useb by message and file fragment
private long mEncryptionKeyIds[] = null; private long mEncryptionKeyIds[] = null;
private long mSigningKeyId = Id.key.none; private long mSigningKeyId = Constants.key.none;
private String mPassphrase; private String mPassphrase;
private String mPassphraseAgain; private String mPassphraseAgain;

View File

@ -33,7 +33,6 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.PGPSecretKeyRing; import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
@ -60,7 +59,7 @@ public class EncryptAsymmetricFragment extends Fragment {
private TextView mMainUserIdRest; private TextView mMainUserIdRest;
// model // model
private long mSecretKeyId = Id.key.none; private long mSecretKeyId = Constants.key.none;
private long mEncryptionKeyIds[] = null; private long mEncryptionKeyIds[] = null;
// Container Activity must implement this interface // Container Activity must implement this interface
@ -116,7 +115,7 @@ public class EncryptAsymmetricFragment extends Fragment {
if (checkBox.isChecked()) { if (checkBox.isChecked()) {
selectSecretKey(); selectSecretKey();
} else { } else {
setSignatureKeyId(Id.key.none); setSignatureKeyId(Constants.key.none);
} }
} }
}); });
@ -196,7 +195,7 @@ public class EncryptAsymmetricFragment extends Fragment {
mEncryptionKeyIds.length)); mEncryptionKeyIds.length));
} }
if (mSecretKeyId == Id.key.none) { if (mSecretKeyId == Constants.key.none) {
mSign.setChecked(false); mSign.setChecked(false);
mMainUserId.setText(""); mMainUserId.setText("");
mMainUserIdRest.setText(""); mMainUserIdRest.setText("");
@ -263,7 +262,7 @@ public class EncryptAsymmetricFragment extends Fragment {
Uri uriMasterKey = data.getData(); Uri uriMasterKey = data.getData();
setSignatureKeyId(Long.valueOf(uriMasterKey.getLastPathSegment())); setSignatureKeyId(Long.valueOf(uriMasterKey.getLastPathSegment()));
} else { } else {
setSignatureKeyId(Id.key.none); setSignatureKeyId(Constants.key.none);
} }
break; break;
} }

View File

@ -38,7 +38,6 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import com.devspark.appmsg.AppMsg; import com.devspark.appmsg.AppMsg;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
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.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
@ -112,13 +111,13 @@ public class EncryptFileFragment extends Fragment {
mFileCompression = (Spinner) view.findViewById(R.id.fileCompression); mFileCompression = (Spinner) view.findViewById(R.id.fileCompression);
Choice[] choices = new Choice[]{ Choice[] choices = new Choice[]{
new Choice(Id.choice.compression.none, getString(R.string.choice_none) + " (" new Choice(Constants.choice.compression.none, getString(R.string.choice_none) + " ("
+ getString(R.string.compression_fast) + ")"), + getString(R.string.compression_fast) + ")"),
new Choice(Id.choice.compression.zip, "ZIP (" new Choice(Constants.choice.compression.zip, "ZIP ("
+ getString(R.string.compression_fast) + ")"), + getString(R.string.compression_fast) + ")"),
new Choice(Id.choice.compression.zlib, "ZLIB (" new Choice(Constants.choice.compression.zlib, "ZLIB ("
+ getString(R.string.compression_fast) + ")"), + getString(R.string.compression_fast) + ")"),
new Choice(Id.choice.compression.bzip2, "BZIP2 (" new Choice(Constants.choice.compression.bzip2, "BZIP2 ("
+ getString(R.string.compression_very_slow) + ")"), + getString(R.string.compression_very_slow) + ")"),
}; };
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getActivity(), ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(getActivity(),

View File

@ -28,7 +28,6 @@ import android.view.ViewGroup;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.FileHelper; import org.sufficientlysecure.keychain.helper.FileHelper;

View File

@ -55,7 +55,6 @@ import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import com.beardedhen.androidbootstrap.BootstrapButton; import com.beardedhen.androidbootstrap.BootstrapButton;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.ExportHelper; import org.sufficientlysecure.keychain.helper.ExportHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
@ -238,7 +237,7 @@ public class KeyListFragment extends Fragment
setListShown(false); setListShown(false);
// Create an empty adapter we will use to display the loaded data. // Create an empty adapter we will use to display the loaded data.
mAdapter = new KeyListAdapter(getActivity(), null, Id.type.public_key); mAdapter = new KeyListAdapter(getActivity(), null, 0);
mStickyList.setAdapter(mAdapter); mStickyList.setAdapter(mAdapter);
// Prepare the loader. Either re-connect with an existing one, // Prepare the loader. Either re-connect with an existing one,

View File

@ -31,7 +31,6 @@ import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.openpgp.PGPEncryptedData; import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.helper.Preferences;
import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference;
@ -89,8 +88,12 @@ public class PreferencesActivity extends PreferenceActivity {
initializeEncryptionAlgorithm( initializeEncryptionAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM)); (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM));
int[] valueIds = new int[]{Id.choice.compression.none, Id.choice.compression.zip, int[] valueIds = new int[]{
Id.choice.compression.zlib, Id.choice.compression.bzip2,}; Constants.choice.compression.none,
Constants.choice.compression.zip,
Constants.choice.compression.zlib,
Constants.choice.compression.bzip2,
};
String[] entries = new String[]{ String[] entries = new String[]{
getString(R.string.choice_none) + " (" + getString(R.string.compression_fast) + ")", getString(R.string.choice_none) + " (" + getString(R.string.compression_fast) + ")",
"ZIP (" + getString(R.string.compression_fast) + ")", "ZIP (" + getString(R.string.compression_fast) + ")",
@ -226,13 +229,20 @@ public class PreferencesActivity extends PreferenceActivity {
initializeEncryptionAlgorithm( initializeEncryptionAlgorithm(
(IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM)); (IntegerListPreference) findPreference(Constants.Pref.DEFAULT_ENCRYPTION_ALGORITHM));
int[] valueIds = new int[]{Id.choice.compression.none, Id.choice.compression.zip, int[] valueIds = new int[]{
Id.choice.compression.zlib, Id.choice.compression.bzip2,}; Constants.choice.compression.none,
Constants.choice.compression.zip,
Constants.choice.compression.zlib,
Constants.choice.compression.bzip2,
};
String[] entries = new String[]{ String[] entries = new String[]{
getString(R.string.choice_none) + " (" + getString(R.string.compression_fast) + ")", getString(R.string.choice_none) + " (" + getString(R.string.compression_fast) + ")",
"ZIP (" + getString(R.string.compression_fast) + ")", "ZIP (" + getString(R.string.compression_fast) + ")",
"ZLIB (" + getString(R.string.compression_fast) + ")", "ZLIB (" + getString(R.string.compression_fast) + ")",
"BZIP2 (" + getString(R.string.compression_very_slow) + ")",}; "BZIP2 (" + getString(R.string.compression_very_slow) + ")",
};
String[] values = new String[valueIds.length]; String[] values = new String[valueIds.length];
for (int i = 0; i < values.length; ++i) { for (int i = 0; i < values.length; ++i) {
values[i] = "" + valueIds[i]; values[i] = "" + valueIds[i];

View File

@ -34,7 +34,8 @@ import android.widget.ArrayAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.util.Choice; import org.sufficientlysecure.keychain.util.Choice;
@ -91,14 +92,14 @@ public class CreateKeyDialogFragment extends DialogFragment {
mAlgorithmSpinner = (Spinner) view.findViewById(R.id.create_key_algorithm); mAlgorithmSpinner = (Spinner) view.findViewById(R.id.create_key_algorithm);
ArrayList<Choice> choices = new ArrayList<Choice>(); ArrayList<Choice> choices = new ArrayList<Choice>();
choices.add(new Choice(Id.choice.algorithm.dsa, getResources().getString( choices.add(new Choice(Constants.choice.algorithm.dsa, getResources().getString(
R.string.dsa))); R.string.dsa)));
if (!wouldBeMasterKey) { if (!wouldBeMasterKey) {
choices.add(new Choice(Id.choice.algorithm.elgamal, getResources().getString( choices.add(new Choice(Constants.choice.algorithm.elgamal, getResources().getString(
R.string.elgamal))); R.string.elgamal)));
} }
choices.add(new Choice(Id.choice.algorithm.rsa, getResources().getString( choices.add(new Choice(Constants.choice.algorithm.rsa, getResources().getString(
R.string.rsa))); R.string.rsa)));
ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(context, ArrayAdapter<Choice> adapter = new ArrayAdapter<Choice>(context,
@ -107,7 +108,7 @@ public class CreateKeyDialogFragment extends DialogFragment {
mAlgorithmSpinner.setAdapter(adapter); mAlgorithmSpinner.setAdapter(adapter);
// make RSA the default // make RSA the default
for (int i = 0; i < choices.size(); ++i) { for (int i = 0; i < choices.size(); ++i) {
if (choices.get(i).getId() == Id.choice.algorithm.rsa) { if (choices.get(i).getId() == Constants.choice.algorithm.rsa) {
mAlgorithmSpinner.setSelection(i); mAlgorithmSpinner.setSelection(i);
break; break;
} }
@ -224,12 +225,12 @@ public class CreateKeyDialogFragment extends DialogFragment {
final int[] elGamalSupportedLengths = {1536, 2048, 3072, 4096, 8192}; final int[] elGamalSupportedLengths = {1536, 2048, 3072, 4096, 8192};
int properKeyLength = -1; int properKeyLength = -1;
switch (algorithmId) { switch (algorithmId) {
case Id.choice.algorithm.rsa: case Constants.choice.algorithm.rsa:
if (currentKeyLength > 1024 && currentKeyLength <= 8192) { if (currentKeyLength > 1024 && currentKeyLength <= 8192) {
properKeyLength = currentKeyLength + ((8 - (currentKeyLength % 8)) % 8); properKeyLength = currentKeyLength + ((8 - (currentKeyLength % 8)) % 8);
} }
break; break;
case Id.choice.algorithm.elgamal: case Constants.choice.algorithm.elgamal:
int[] elGammalKeyDiff = new int[elGamalSupportedLengths.length]; int[] elGammalKeyDiff = new int[elGamalSupportedLengths.length];
for (int i = 0; i < elGamalSupportedLengths.length; i++) { for (int i = 0; i < elGamalSupportedLengths.length; i++) {
elGammalKeyDiff[i] = Math.abs(elGamalSupportedLengths[i] - currentKeyLength); elGammalKeyDiff[i] = Math.abs(elGamalSupportedLengths[i] - currentKeyLength);
@ -244,7 +245,7 @@ public class CreateKeyDialogFragment extends DialogFragment {
} }
properKeyLength = elGamalSupportedLengths[minimalIndex]; properKeyLength = elGamalSupportedLengths[minimalIndex];
break; break;
case Id.choice.algorithm.dsa: case Constants.choice.algorithm.dsa:
if (currentKeyLength >= 512 && currentKeyLength <= 1024) { if (currentKeyLength >= 512 && currentKeyLength <= 1024) {
properKeyLength = currentKeyLength + ((64 - (currentKeyLength % 64)) % 64); properKeyLength = currentKeyLength + ((64 - (currentKeyLength % 64)) % 64);
} }
@ -283,15 +284,15 @@ public class CreateKeyDialogFragment extends DialogFragment {
final Object selectedItem = mKeySizeSpinner.getSelectedItem(); final Object selectedItem = mKeySizeSpinner.getSelectedItem();
keySizeAdapter.clear(); keySizeAdapter.clear();
switch (algorithmId) { switch (algorithmId) {
case Id.choice.algorithm.rsa: case Constants.choice.algorithm.rsa:
replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values); replaceArrayAdapterContent(keySizeAdapter, R.array.rsa_key_size_spinner_values);
mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa)); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_rsa));
break; break;
case Id.choice.algorithm.elgamal: case Constants.choice.algorithm.elgamal:
replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values); replaceArrayAdapterContent(keySizeAdapter, R.array.elgamal_key_size_spinner_values);
mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length mCustomKeyInfoTextView.setText(""); // ElGamal does not support custom key length
break; break;
case Id.choice.algorithm.dsa: case Constants.choice.algorithm.dsa:
replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values); replaceArrayAdapterContent(keySizeAdapter, R.array.dsa_key_size_spinner_values);
mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa)); mCustomKeyInfoTextView.setText(getResources().getString(R.string.key_size_custom_info_dsa));
break; break;

View File

@ -46,7 +46,6 @@ import org.spongycastle.openpgp.PGPSecretKey;
import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor; import org.spongycastle.openpgp.operator.PBESecretKeyDecryptor;
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
@ -99,7 +98,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
public static PassphraseDialogFragment newInstance(Context context, Messenger messenger, public static PassphraseDialogFragment newInstance(Context context, Messenger messenger,
long secretKeyId) throws PgpGeneralException { long secretKeyId) throws PgpGeneralException {
// check if secret key has a passphrase // check if secret key has a passphrase
if (!(secretKeyId == Id.key.symmetric || secretKeyId == Id.key.none)) { if (!(secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none)) {
if (!PassphraseCacheService.hasPassphrase(context, secretKeyId)) { if (!PassphraseCacheService.hasPassphrase(context, secretKeyId)) {
throw new PgpGeneralException("No passphrase! No passphrase dialog needed!"); throw new PgpGeneralException("No passphrase! No passphrase dialog needed!");
} }
@ -135,7 +134,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
final PGPSecretKey secretKey; final PGPSecretKey secretKey;
if (secretKeyId == Id.key.symmetric || secretKeyId == Id.key.none) { if (secretKeyId == Constants.key.symmetric || secretKeyId == Constants.key.none) {
secretKey = null; secretKey = null;
alert.setMessage(R.string.passphrase_for_symmetric_encryption); alert.setMessage(R.string.passphrase_for_symmetric_encryption);
} else { } else {
@ -225,7 +224,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
} }
keyId = secretKey.getKeyID(); keyId = secretKey.getKeyID();
} else { } else {
keyId = Id.key.symmetric; keyId = Constants.key.symmetric;
} }
// cache the new passphrase // cache the new passphrase

View File

@ -38,7 +38,6 @@ import com.beardedhen.androidbootstrap.BootstrapButton;
import org.spongycastle.openpgp.PGPKeyFlags; import org.spongycastle.openpgp.PGPKeyFlags;
import org.spongycastle.openpgp.PGPSecretKey; import org.spongycastle.openpgp.PGPSecretKey;
import org.sufficientlysecure.keychain.Id;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper; import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
@ -72,6 +71,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
private ProgressDialogFragment mGeneratingDialog; private ProgressDialogFragment mGeneratingDialog;
public static final int TYPE_USER_ID = 1;
public static final int TYPE_KEY = 2;
public void setEditorListener(EditorListener listener) { public void setEditorListener(EditorListener listener) {
mEditorListener = listener; mEditorListener = listener;
} }
@ -93,12 +95,12 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public void setType(int type) { public void setType(int type) {
mType = type; mType = type;
switch (type) { switch (type) {
case Id.type.user_id: { case TYPE_USER_ID: {
mTitle.setText(R.string.section_user_ids); mTitle.setText(R.string.section_user_ids);
break; break;
} }
case Id.type.key: { case TYPE_KEY: {
mTitle.setText(R.string.section_keys); mTitle.setText(R.string.section_keys);
break; break;
} }
@ -142,9 +144,9 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public void onDeleted(Editor editor, boolean wasNewItem) { public void onDeleted(Editor editor, boolean wasNewItem) {
mOldItemDeleted |= !wasNewItem; mOldItemDeleted |= !wasNewItem;
if (mOldItemDeleted) { if (mOldItemDeleted) {
if (mType == Id.type.user_id) { if (mType == TYPE_USER_ID) {
mDeletedIDs.add(((UserIdEditor) editor).getOriginalID()); mDeletedIDs.add(((UserIdEditor) editor).getOriginalID());
} else if (mType == Id.type.key) { } else if (mType == TYPE_KEY) {
mDeletedKeys.add(((KeyEditor) editor).getValue()); mDeletedKeys.add(((KeyEditor) editor).getValue());
} }
} }
@ -172,7 +174,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
for (int i = 0; i < mEditors.getChildCount(); ++i) { for (int i = 0; i < mEditors.getChildCount(); ++i) {
Editor editor = (Editor) mEditors.getChildAt(i); Editor editor = (Editor) mEditors.getChildAt(i);
ret |= editor.needsSaving(); ret |= editor.needsSaving();
if (mType == Id.type.user_id) { if (mType == TYPE_USER_ID) {
ret |= ((UserIdEditor) editor).primarySwapped(); ret |= ((UserIdEditor) editor).primarySwapped();
} }
} }
@ -183,7 +185,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
boolean ret = false; boolean ret = false;
for (int i = 0; i < mEditors.getChildCount(); ++i) { for (int i = 0; i < mEditors.getChildCount(); ++i) {
Editor editor = (Editor) mEditors.getChildAt(i); Editor editor = (Editor) mEditors.getChildAt(i);
if (mType == Id.type.user_id) { if (mType == TYPE_USER_ID) {
ret |= ((UserIdEditor) editor).primarySwapped(); ret |= ((UserIdEditor) editor).primarySwapped();
} }
} }
@ -196,7 +198,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
// revoked ones make this harder than the simple case we are continuing to assume here // revoked ones make this harder than the simple case we are continuing to assume here
for (int i = 0; i < mEditors.getChildCount(); ++i) { for (int i = 0; i < mEditors.getChildCount(); ++i) {
Editor editor = (Editor) mEditors.getChildAt(i); Editor editor = (Editor) mEditors.getChildAt(i);
if (mType == Id.type.user_id) { if (mType == TYPE_USER_ID) {
if (((UserIdEditor) editor).getIsOriginallyMainUserID()) { if (((UserIdEditor) editor).getIsOriginallyMainUserID()) {
return ((UserIdEditor) editor).getOriginalID(); return ((UserIdEditor) editor).getOriginalID();
} }
@ -207,7 +209,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public ArrayList<String> getOriginalIDs() { public ArrayList<String> getOriginalIDs() {
ArrayList<String> orig = new ArrayList<String>(); ArrayList<String> orig = new ArrayList<String>();
if (mType == Id.type.user_id) { if (mType == TYPE_USER_ID) {
for (int i = 0; i < mEditors.getChildCount(); ++i) { for (int i = 0; i < mEditors.getChildCount(); ++i) {
UserIdEditor editor = (UserIdEditor) mEditors.getChildAt(i); UserIdEditor editor = (UserIdEditor) mEditors.getChildAt(i);
if (editor.isMainUserId()) { if (editor.isMainUserId()) {
@ -254,7 +256,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public List<Boolean> getNewKeysArray() { public List<Boolean> getNewKeysArray() {
ArrayList<Boolean> mList = new ArrayList<Boolean>(); ArrayList<Boolean> mList = new ArrayList<Boolean>();
if (mType == Id.type.key) { if (mType == TYPE_KEY) {
for (int i = 0; i < mEditors.getChildCount(); ++i) { for (int i = 0; i < mEditors.getChildCount(); ++i) {
KeyEditor editor = (KeyEditor) mEditors.getChildAt(i); KeyEditor editor = (KeyEditor) mEditors.getChildAt(i);
mList.add(editor.getIsNewKey()); mList.add(editor.getIsNewKey());
@ -269,7 +271,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public void onClick(View v) { public void onClick(View v) {
if (mCanBeEdited) { if (mCanBeEdited) {
switch (mType) { switch (mType) {
case Id.type.user_id: { case TYPE_USER_ID: {
UserIdEditor view = (UserIdEditor) mInflater.inflate( UserIdEditor view = (UserIdEditor) mInflater.inflate(
R.layout.edit_key_user_id_item, mEditors, false); R.layout.edit_key_user_id_item, mEditors, false);
view.setEditorListener(this); view.setEditorListener(this);
@ -281,7 +283,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
break; break;
} }
case Id.type.key: { case TYPE_KEY: {
CreateKeyDialogFragment mCreateKeyDialogFragment = CreateKeyDialogFragment mCreateKeyDialogFragment =
CreateKeyDialogFragment.newInstance(mEditors.getChildCount()); CreateKeyDialogFragment.newInstance(mEditors.getChildCount());
mCreateKeyDialogFragment mCreateKeyDialogFragment
@ -307,7 +309,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
} }
public void setUserIds(Vector<String> list) { public void setUserIds(Vector<String> list) {
if (mType != Id.type.user_id) { if (mType != TYPE_USER_ID) {
return; return;
} }
@ -325,7 +327,7 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
} }
public void setKeys(Vector<PGPSecretKey> list, Vector<Integer> usages, boolean newKeys) { public void setKeys(Vector<PGPSecretKey> list, Vector<Integer> usages, boolean newKeys) {
if (mType != Id.type.key) { if (mType != TYPE_KEY) {
return; return;
} }

View File

@ -21,7 +21,7 @@ import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
import org.spongycastle.bcpg.HashAlgorithmTags; import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.openpgp.PGPEncryptedData; import org.spongycastle.openpgp.PGPEncryptedData;
import org.sufficientlysecure.keychain.Id; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import java.util.HashMap; import java.util.HashMap;
@ -56,13 +56,13 @@ public class AlgorithmNames {
mHashNames.put(HashAlgorithmTags.SHA384, "SHA-384"); mHashNames.put(HashAlgorithmTags.SHA384, "SHA-384");
mHashNames.put(HashAlgorithmTags.SHA512, "SHA-512"); mHashNames.put(HashAlgorithmTags.SHA512, "SHA-512");
mCompressionNames.put(Id.choice.compression.none, mActivity.getString(R.string.choice_none) mCompressionNames.put(Constants.choice.compression.none, mActivity.getString(R.string.choice_none)
+ " (" + mActivity.getString(R.string.compression_fast) + ")"); + " (" + mActivity.getString(R.string.compression_fast) + ")");
mCompressionNames.put(Id.choice.compression.zip, mCompressionNames.put(Constants.choice.compression.zip,
"ZIP (" + mActivity.getString(R.string.compression_fast) + ")"); "ZIP (" + mActivity.getString(R.string.compression_fast) + ")");
mCompressionNames.put(Id.choice.compression.zlib, mCompressionNames.put(Constants.choice.compression.zlib,
"ZLIB (" + mActivity.getString(R.string.compression_fast) + ")"); "ZLIB (" + mActivity.getString(R.string.compression_fast) + ")");
mCompressionNames.put(Id.choice.compression.bzip2, mCompressionNames.put(Constants.choice.compression.bzip2,
"BZIP2 (" + mActivity.getString(R.string.compression_very_slow) + ")"); "BZIP2 (" + mActivity.getString(R.string.compression_very_slow) + ")");
} }