mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-07 01:35:00 -05:00
fix Android Studio analysis issues
This commit is contained in:
parent
75640934a0
commit
5bd0a2ebc8
@ -23,6 +23,7 @@ import java.security.InvalidAlgorithmParameterException;
|
|||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.NoSuchProviderException;
|
import java.security.NoSuchProviderException;
|
||||||
|
import java.security.PublicKey;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.SignatureException;
|
import java.security.SignatureException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -56,6 +57,7 @@ import org.spongycastle.openpgp.operator.PGPContentSignerBuilder;
|
|||||||
import org.spongycastle.openpgp.operator.PGPDigestCalculator;
|
import org.spongycastle.openpgp.operator.PGPDigestCalculator;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
|
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
import org.spongycastle.openpgp.operator.jcajce.JcaPGPDigestCalculatorProviderBuilder;
|
||||||
|
import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyConverter;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
import org.spongycastle.openpgp.operator.jcajce.JcaPGPKeyPair;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
|
||||||
@ -71,8 +73,8 @@ import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public class PgpKeyOperation {
|
public class PgpKeyOperation {
|
||||||
private Context mContext;
|
private final Context mContext;
|
||||||
private ProgressDialogUpdater mProgress;
|
private final ProgressDialogUpdater mProgress;
|
||||||
|
|
||||||
private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] {
|
private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[] {
|
||||||
SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192,
|
SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192,
|
||||||
@ -90,34 +92,18 @@ public class PgpKeyOperation {
|
|||||||
this.mProgress = progress;
|
this.mProgress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProgress(int message, int current, int total) {
|
void updateProgress(int message, int current, int total) {
|
||||||
if (mProgress != null) {
|
if (mProgress != null) {
|
||||||
mProgress.setProgress(message, current, total);
|
mProgress.setProgress(message, current, total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateProgress(int current, int total) {
|
void updateProgress(int current, int total) {
|
||||||
if (mProgress != null) {
|
if (mProgress != null) {
|
||||||
mProgress.setProgress(current, total);
|
mProgress.setProgress(current, total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates new secret key.
|
|
||||||
*
|
|
||||||
* @param algorithmChoice
|
|
||||||
* @param keySize
|
|
||||||
* @param passPhrase
|
|
||||||
* @param isMasterKey
|
|
||||||
* @return
|
|
||||||
* @throws NoSuchAlgorithmException
|
|
||||||
* @throws PGPException
|
|
||||||
* @throws NoSuchProviderException
|
|
||||||
* @throws PgpGeneralException
|
|
||||||
* @throws InvalidAlgorithmParameterException
|
|
||||||
*/
|
|
||||||
|
|
||||||
// TODO: key flags?
|
|
||||||
public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
|
public PGPSecretKey createKey(int algorithmChoice, int keySize, String passPhrase,
|
||||||
boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
boolean isMasterKey) throws NoSuchAlgorithmException, PGPException, NoSuchProviderException,
|
||||||
PgpGeneralException, InvalidAlgorithmParameterException {
|
PgpGeneralException, InvalidAlgorithmParameterException {
|
||||||
@ -130,8 +116,8 @@ public class PgpKeyOperation {
|
|||||||
passPhrase = "";
|
passPhrase = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
int algorithm = 0;
|
int algorithm;
|
||||||
KeyPairGenerator keyGen = null;
|
KeyPairGenerator keyGen;
|
||||||
|
|
||||||
switch (algorithmChoice) {
|
switch (algorithmChoice) {
|
||||||
case Id.choice.algorithm.dsa: {
|
case Id.choice.algorithm.dsa: {
|
||||||
@ -183,15 +169,13 @@ public class PgpKeyOperation {
|
|||||||
PGPEncryptedData.CAST5, sha1Calc)
|
PGPEncryptedData.CAST5, sha1Calc)
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME).build(passPhrase.toCharArray());
|
||||||
|
|
||||||
PGPSecretKey secKey = new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(),
|
return new PGPSecretKey(keyPair.getPrivateKey(), keyPair.getPublicKey(),
|
||||||
sha1Calc, isMasterKey, keyEncryptor);
|
sha1Calc, isMasterKey, keyEncryptor);
|
||||||
|
|
||||||
return secKey;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
|
public void changeSecretKeyPassphrase(PGPSecretKeyRing keyRing, String oldPassPhrase,
|
||||||
String newPassPhrase) throws IOException, PGPException, PGPException,
|
String newPassPhrase) throws IOException, PGPException {
|
||||||
NoSuchProviderException {
|
|
||||||
|
|
||||||
updateProgress(R.string.progress_building_key, 0, 100);
|
updateProgress(R.string.progress_building_key, 0, 100);
|
||||||
if (oldPassPhrase == null) {
|
if (oldPassPhrase == null) {
|
||||||
@ -219,9 +203,8 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
public void buildSecretKey(ArrayList<String> userIds, ArrayList<PGPSecretKey> keys,
|
public void buildSecretKey(ArrayList<String> userIds, ArrayList<PGPSecretKey> keys,
|
||||||
ArrayList<Integer> keysUsages, ArrayList<GregorianCalendar> keysExpiryDates,
|
ArrayList<Integer> keysUsages, ArrayList<GregorianCalendar> keysExpiryDates,
|
||||||
long masterKeyId, String oldPassPhrase,
|
String oldPassPhrase, String newPassPhrase) throws PgpGeneralException,
|
||||||
String newPassPhrase) throws PgpGeneralException, NoSuchProviderException,
|
PGPException, SignatureException, IOException {
|
||||||
PGPException, NoSuchAlgorithmException, SignatureException, IOException {
|
|
||||||
|
|
||||||
Log.d(Constants.TAG, "userIds: " + userIds.toString());
|
Log.d(Constants.TAG, "userIds: " + userIds.toString());
|
||||||
|
|
||||||
@ -237,17 +220,16 @@ public class PgpKeyOperation {
|
|||||||
updateProgress(R.string.progress_preparing_master_key, 10, 100);
|
updateProgress(R.string.progress_preparing_master_key, 10, 100);
|
||||||
|
|
||||||
int usageId = keysUsages.get(0);
|
int usageId = keysUsages.get(0);
|
||||||
boolean canSign = (usageId & KeyFlags.SIGN_DATA) > 0;
|
boolean canSign;
|
||||||
boolean canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0;
|
|
||||||
|
|
||||||
String mainUserId = userIds.get(0);
|
String mainUserId = userIds.get(0);
|
||||||
|
|
||||||
PGPSecretKey masterKey = keys.get(0);
|
PGPSecretKey masterKey = keys.get(0);
|
||||||
|
|
||||||
// this removes all userIds and certifications previously attached to the masterPublicKey
|
// this removes all userIds and certifications previously attached to the masterPublicKey
|
||||||
PGPPublicKey tmpKey = masterKey.getPublicKey();
|
PGPPublicKey tmpKey = masterKey.getPublicKey();
|
||||||
PGPPublicKey masterPublicKey = new PGPPublicKey(tmpKey.getAlgorithm(),
|
PublicKey tmpPuK = new JcaPGPKeyConverter().setProvider(new BouncyCastleProvider()).getPublicKey(tmpKey);
|
||||||
tmpKey.getKey(new BouncyCastleProvider()), tmpKey.getCreationTime());
|
PGPPublicKey masterPublicKey = new JcaPGPKeyConverter().getPGPPublicKey(tmpKey.getAlgorithm(),
|
||||||
|
tmpPuK, tmpKey.getCreationTime());
|
||||||
|
|
||||||
// already done by code above:
|
// already done by code above:
|
||||||
// PGPPublicKey masterPublicKey = masterKey.getPublicKey();
|
// PGPPublicKey masterPublicKey = masterKey.getPublicKey();
|
||||||
@ -347,7 +329,6 @@ public class PgpKeyOperation {
|
|||||||
|
|
||||||
usageId = keysUsages.get(i);
|
usageId = keysUsages.get(i);
|
||||||
canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this
|
canSign = (usageId & KeyFlags.SIGN_DATA) > 0; //todo - separate function for this
|
||||||
canEncrypt = (usageId & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) > 0;
|
|
||||||
if (canSign) {
|
if (canSign) {
|
||||||
Date todayDate = new Date(); //both sig times the same
|
Date todayDate = new Date(); //both sig times the same
|
||||||
// cross-certify signing keys
|
// cross-certify signing keys
|
||||||
@ -396,8 +377,7 @@ public class PgpKeyOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public PGPPublicKeyRing signKey(long masterKeyId, long pubKeyId, String passphrase)
|
public PGPPublicKeyRing signKey(long masterKeyId, long pubKeyId, String passphrase)
|
||||||
throws PgpGeneralException, NoSuchAlgorithmException, NoSuchProviderException,
|
throws PgpGeneralException, PGPException, SignatureException {
|
||||||
PGPException, SignatureException {
|
|
||||||
if (passphrase == null) {
|
if (passphrase == null) {
|
||||||
throw new PgpGeneralException("Unable to obtain passphrase");
|
throw new PgpGeneralException("Unable to obtain passphrase");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user