Remove version 3 checks, no longer supported in import

This commit is contained in:
Dominik Schürmann 2014-09-02 16:42:07 +02:00
parent fe2c17cdeb
commit b08aa132e0
3 changed files with 24 additions and 27 deletions

View File

@ -27,7 +27,6 @@ import android.text.style.ForegroundColorSpan;
import org.spongycastle.asn1.ASN1ObjectIdentifier;
import org.spongycastle.asn1.nist.NISTNamedCurves;
import org.spongycastle.asn1.teletrust.TeleTrusTNamedCurves;
import org.spongycastle.bcpg.ECPublicBCPGKey;
import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
@ -156,9 +155,11 @@ public class PgpKeyHelper {
return algorithmStr;
}
// Return name of a curve. These are names, no need for translation
/**
* Return name of a curve. These are names, no need for translation
*/
public static String getCurveInfo(Context context, Curve curve) {
switch(curve) {
switch (curve) {
case NIST_P256:
return "NIST P-256";
case NIST_P384:
@ -211,9 +212,7 @@ public class PgpKeyHelper {
* @return
*/
public static String convertFingerprintToHex(byte[] fingerprint) {
String hexString = Hex.toHexString(fingerprint).toLowerCase(Locale.ENGLISH);
return hexString;
return Hex.toHexString(fingerprint).toLowerCase(Locale.ENGLISH);
}
/**
@ -327,10 +326,9 @@ public class PgpKeyHelper {
md.update(bytes);
byte[] digest = md.digest();
int[] result = {((int) digest[0] + 256) % 256,
return new int[]{((int) digest[0] + 256) % 256,
((int) digest[1] + 256) % 256,
((int) digest[2] + 256) % 256};
return result;
}
}

View File

@ -124,9 +124,9 @@ public class PgpKeyOperation {
*
* http://kbsriram.com/2013/01/generating-rsa-keys-with-bouncycastle.html
*/
private static final int SECRET_KEY_ENCRYPTOR_S2K_COUNT = 0x60;
private static final int SECRET_KEY_ENCRYPTOR_HASH_ALGO = HashAlgorithmTags.SHA512;
private static final int SECRET_KEY_ENCRYPTOR_SYMMETRIC_ALGO = SymmetricKeyAlgorithmTags.AES_256;
private static final int SECRET_KEY_ENCRYPTOR_S2K_COUNT = 0x60;
public PgpKeyOperation(Progressable progress) {
super();
@ -415,8 +415,7 @@ public class PgpKeyOperation {
PGPSecretKey masterSecretKey = sKR.getSecretKey();
// Make sure the fingerprint matches
if (saveParcel.mFingerprint == null
|| !Arrays.equals(saveParcel.mFingerprint,
if (saveParcel.mFingerprint == null || !Arrays.equals(saveParcel.mFingerprint,
masterSecretKey.getPublicKey().getFingerprint())) {
log.add(LogLevel.ERROR, LogType.MSG_MF_ERROR_FINGERPRINT, indent);
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);

View File

@ -207,12 +207,15 @@ public class UncachedPublicKey {
return getAlgorithm() == PGPPublicKey.ECDH || getAlgorithm() == PGPPublicKey.ECDSA;
}
/**
* Get all key usage flags
*
* TODO make this safe
*/
@SuppressWarnings("unchecked")
// TODO make this safe
public int getKeyUsage() {
if(mCacheUsage == null) {
mCacheUsage = 0;
if (mPublicKey.getVersion() >= 4) {
for (PGPSignature sig : new IterableIterator<PGPSignature>(mPublicKey.getSignatures())) {
if (mPublicKey.isMasterKey() && sig.getKeyID() != mPublicKey.getKeyID()) {
continue;
@ -224,16 +227,15 @@ public class UncachedPublicKey {
}
}
}
}
return mCacheUsage;
}
public boolean canAuthenticate() {
return mPublicKey.getVersion() <= 3 || (getKeyUsage() & KeyFlags.AUTHENTICATION) != 0;
return (getKeyUsage() & KeyFlags.AUTHENTICATION) != 0;
}
public boolean canCertify() {
return mPublicKey.getVersion() <= 3 || (getKeyUsage() & KeyFlags.CERTIFY_OTHER) != 0;
return (getKeyUsage() & KeyFlags.CERTIFY_OTHER) != 0;
}
public boolean canEncrypt() {
@ -250,9 +252,7 @@ public class UncachedPublicKey {
return true;
}
return mPublicKey.getVersion() <= 3 ||
(getKeyUsage() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0;
return (getKeyUsage() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0;
}
public boolean canSign() {
@ -261,7 +261,7 @@ public class UncachedPublicKey {
return true;
}
return mPublicKey.getVersion() <= 3 || (getKeyUsage() & KeyFlags.SIGN_DATA) != 0;
return (getKeyUsage() & KeyFlags.SIGN_DATA) != 0;
}
public byte[] getFingerprint() {