mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-03-03 02:42:00 -05:00
Code cleaning in PgpDecryptVerify
This commit is contained in:
parent
61ee811d60
commit
875adae40c
@ -440,12 +440,12 @@ public class PgpDecryptVerify {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
// TODO: progressDialogUpdater calculation is broken here! Try to rework it based on commented code!
|
// TODO: progress calculation is broken here! Try to rework it based on commented code!
|
||||||
// int progressDialogUpdater = 0;
|
// int progress = 0;
|
||||||
long startPos = data.getStreamPosition();
|
long startPos = data.getStreamPosition();
|
||||||
while ((n = dataIn.read(buffer)) > 0) {
|
while ((n = dataIn.read(buffer)) > 0) {
|
||||||
outStream.write(buffer, 0, n);
|
outStream.write(buffer, 0, n);
|
||||||
// progressDialogUpdater += n;
|
// progress += n;
|
||||||
if (signature != null) {
|
if (signature != null) {
|
||||||
try {
|
try {
|
||||||
signature.update(buffer, 0, n);
|
signature.update(buffer, 0, n);
|
||||||
@ -455,9 +455,9 @@ public class PgpDecryptVerify {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: dead code?!
|
// TODO: dead code?!
|
||||||
// unknown size, but try to at least have a moving, slowing down progressDialogUpdater bar
|
// unknown size, but try to at least have a moving, slowing down progress bar
|
||||||
// currentProgress = startProgress + (endProgress - startProgress) * progressDialogUpdater
|
// currentProgress = startProgress + (endProgress - startProgress) * progress
|
||||||
// / (progressDialogUpdater + 100000);
|
// / (progress + 100000);
|
||||||
if (data.getSize() - startPos == 0) {
|
if (data.getSize() - startPos == 0) {
|
||||||
currentProgress = endProgress;
|
currentProgress = endProgress;
|
||||||
} else {
|
} else {
|
||||||
@ -478,11 +478,11 @@ public class PgpDecryptVerify {
|
|||||||
signatureResult.setSignatureOnly(false);
|
signatureResult.setSignatureOnly(false);
|
||||||
|
|
||||||
//Now check binding signatures
|
//Now check binding signatures
|
||||||
boolean keyBinding_isok = verifyKeyBinding(context, messageSignature, signatureKey);
|
boolean validKeyBinding = verifyKeyBinding(context, messageSignature, signatureKey);
|
||||||
boolean sig_isok = signature.verify(messageSignature);
|
boolean validSignature = signature.verify(messageSignature);
|
||||||
|
|
||||||
// TODO: implement CERTIFIED!
|
// TODO: implement CERTIFIED!
|
||||||
if (keyBinding_isok & sig_isok) {
|
if (validKeyBinding & validSignature) {
|
||||||
signatureResult.setStatus(OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED);
|
signatureResult.setStatus(OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -618,12 +618,11 @@ public class PgpDecryptVerify {
|
|||||||
} while (lookAhead != -1);
|
} while (lookAhead != -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean sig_isok = signature.verify();
|
|
||||||
|
|
||||||
//Now check binding signatures
|
//Now check binding signatures
|
||||||
boolean keyBinding_isok = verifyKeyBinding(context, signature, signatureKey);
|
boolean validKeyBinding = verifyKeyBinding(context, signature, signatureKey);
|
||||||
|
boolean validSignature = signature.verify();
|
||||||
|
|
||||||
if (sig_isok & keyBinding_isok) {
|
if (validSignature & validKeyBinding) {
|
||||||
signatureResult.setStatus(OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED);
|
signatureResult.setStatus(OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -637,34 +636,34 @@ public class PgpDecryptVerify {
|
|||||||
|
|
||||||
private static boolean verifyKeyBinding(Context context, PGPSignature signature, PGPPublicKey signatureKey) {
|
private static boolean verifyKeyBinding(Context context, PGPSignature signature, PGPPublicKey signatureKey) {
|
||||||
long signatureKeyId = signature.getKeyID();
|
long signatureKeyId = signature.getKeyID();
|
||||||
boolean keyBinding_isok = false;
|
boolean validKeyBinding = false;
|
||||||
String userId = null;
|
|
||||||
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByKeyId(context,
|
PGPPublicKeyRing signKeyRing = ProviderHelper.getPGPPublicKeyRingByKeyId(context,
|
||||||
signatureKeyId);
|
signatureKeyId);
|
||||||
PGPPublicKey mKey = null;
|
PGPPublicKey mKey = null;
|
||||||
if (signKeyRing != null) {
|
if (signKeyRing != null) {
|
||||||
mKey = PgpKeyHelper.getMasterKey(signKeyRing);
|
mKey = PgpKeyHelper.getMasterKey(signKeyRing);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signature.getKeyID() != mKey.getKeyID()) {
|
if (signature.getKeyID() != mKey.getKeyID()) {
|
||||||
keyBinding_isok = verifyKeyBinding(mKey, signatureKey);
|
validKeyBinding = verifyKeyBinding(mKey, signatureKey);
|
||||||
} else { //if the key used to make the signature was the master key, no need to check binding sigs
|
} else { //if the key used to make the signature was the master key, no need to check binding sigs
|
||||||
keyBinding_isok = true;
|
validKeyBinding = true;
|
||||||
}
|
}
|
||||||
return keyBinding_isok;
|
return validKeyBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean verifyKeyBinding(PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {
|
private static boolean verifyKeyBinding(PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {
|
||||||
boolean subkeyBinding_isok = false;
|
boolean validSubkeyBinding = false;
|
||||||
boolean tmp_subkeyBinding_isok = false;
|
boolean validTempSubkeyBinding = false;
|
||||||
boolean primkeyBinding_isok = false;
|
boolean validPrimaryKeyBinding = false;
|
||||||
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider()
|
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
||||||
|
new JcaPGPContentVerifierBuilderProvider()
|
||||||
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
||||||
|
|
||||||
Iterator<PGPSignature> itr = signingPublicKey.getSignatures();
|
Iterator<PGPSignature> itr = signingPublicKey.getSignatures();
|
||||||
|
|
||||||
subkeyBinding_isok = false;
|
|
||||||
tmp_subkeyBinding_isok = false;
|
|
||||||
primkeyBinding_isok = false;
|
|
||||||
while (itr.hasNext()) { //what does gpg do if the subkey binding is wrong?
|
while (itr.hasNext()) { //what does gpg do if the subkey binding is wrong?
|
||||||
//gpg has an invalid subkey binding error on key import I think, but doesn't shout
|
//gpg has an invalid subkey binding error on key import I think, but doesn't shout
|
||||||
//about keys without subkey signing. Can't get it to import a slightly broken one
|
//about keys without subkey signing. Can't get it to import a slightly broken one
|
||||||
@ -674,32 +673,36 @@ public class PgpDecryptVerify {
|
|||||||
//check and if ok, check primary key binding.
|
//check and if ok, check primary key binding.
|
||||||
try {
|
try {
|
||||||
sig.init(contentVerifierBuilderProvider, masterPublicKey);
|
sig.init(contentVerifierBuilderProvider, masterPublicKey);
|
||||||
tmp_subkeyBinding_isok = sig.verifyCertification(masterPublicKey, signingPublicKey);
|
validTempSubkeyBinding = sig.verifyCertification(masterPublicKey, signingPublicKey);
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
continue;
|
continue;
|
||||||
} catch (SignatureException e) {
|
} catch (SignatureException e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp_subkeyBinding_isok)
|
if (validTempSubkeyBinding)
|
||||||
subkeyBinding_isok = true;
|
validSubkeyBinding = true;
|
||||||
if (tmp_subkeyBinding_isok) {
|
if (validTempSubkeyBinding) {
|
||||||
primkeyBinding_isok = verifyPrimaryBinding(sig.getUnhashedSubPackets(), masterPublicKey, signingPublicKey);
|
validPrimaryKeyBinding = verifyPrimaryKeyBinding(sig.getUnhashedSubPackets(),
|
||||||
if (primkeyBinding_isok)
|
masterPublicKey, signingPublicKey);
|
||||||
|
if (validPrimaryKeyBinding)
|
||||||
break;
|
break;
|
||||||
primkeyBinding_isok = verifyPrimaryBinding(sig.getHashedSubPackets(), masterPublicKey, signingPublicKey);
|
validPrimaryKeyBinding = verifyPrimaryKeyBinding(sig.getHashedSubPackets(),
|
||||||
if (primkeyBinding_isok)
|
masterPublicKey, signingPublicKey);
|
||||||
|
if (validPrimaryKeyBinding)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return (subkeyBinding_isok & primkeyBinding_isok);
|
return (validSubkeyBinding & validPrimaryKeyBinding);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean verifyPrimaryBinding(PGPSignatureSubpacketVector Pkts, PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {
|
private static boolean verifyPrimaryKeyBinding(PGPSignatureSubpacketVector Pkts,
|
||||||
boolean primkeyBinding_isok = false;
|
PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) {
|
||||||
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider()
|
boolean validPrimaryKeyBinding = false;
|
||||||
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
|
||||||
|
new JcaPGPContentVerifierBuilderProvider()
|
||||||
|
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
|
||||||
PGPSignatureList eSigList;
|
PGPSignatureList eSigList;
|
||||||
|
|
||||||
if (Pkts.hasSubpacket(SignatureSubpacketTags.EMBEDDED_SIGNATURE)) {
|
if (Pkts.hasSubpacket(SignatureSubpacketTags.EMBEDDED_SIGNATURE)) {
|
||||||
@ -715,8 +718,8 @@ public class PgpDecryptVerify {
|
|||||||
if (emSig.getSignatureType() == PGPSignature.PRIMARYKEY_BINDING) {
|
if (emSig.getSignatureType() == PGPSignature.PRIMARYKEY_BINDING) {
|
||||||
try {
|
try {
|
||||||
emSig.init(contentVerifierBuilderProvider, signingPublicKey);
|
emSig.init(contentVerifierBuilderProvider, signingPublicKey);
|
||||||
primkeyBinding_isok = emSig.verifyCertification(masterPublicKey, signingPublicKey);
|
validPrimaryKeyBinding = emSig.verifyCertification(masterPublicKey, signingPublicKey);
|
||||||
if (primkeyBinding_isok)
|
if (validPrimaryKeyBinding)
|
||||||
break;
|
break;
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
continue;
|
continue;
|
||||||
@ -726,7 +729,8 @@ public class PgpDecryptVerify {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return primkeyBinding_isok;
|
|
||||||
|
return validPrimaryKeyBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user