This commit is contained in:
Ashley Hughes 2014-01-14 22:12:57 +00:00
parent cd4a3dd237
commit c95a52c070

View File

@ -897,9 +897,7 @@ public class PgpOperation {
boolean sig_isok = signature.verify(); boolean sig_isok = signature.verify();
//Now check binding signatures //Now check binding signatures
boolean subkeyBinding_isok = false; boolean keyBinding_isok = false;
boolean tmp_subkeyBinding_isok = false;
boolean primkeyBinding_isok = false;
signatureKeyId = signature.getKeyID(); signatureKeyId = signature.getKeyID();
String userId = null; String userId = null;
@ -910,7 +908,25 @@ public class PgpOperation {
mKey = PgpKeyHelper.getMasterKey(signKeyRing); mKey = PgpKeyHelper.getMasterKey(signKeyRing);
} }
if (signature.getKeyID() != mKey.getKeyID()) { if (signature.getKeyID() != mKey.getKeyID()) {
Iterator<PGPSignature> itr = signatureKey.getSignatures(); keyBinding_isok = verifyKeyBinding(mKey, signatureKey);
} else { //if the key used to make the signature was the master key, no need to check binding sigs
keyBinding_isok = true;
}
returnData.putBoolean(KeychainIntentService.RESULT_SIGNATURE_SUCCESS, sig_isok & keyBinding_isok);
updateProgress(R.string.progress_done, 100, 100);
return returnData;
}
private boolean verifyKeyBinding(PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey)
{
boolean subkeyBinding_isok = false;
boolean tmp_subkeyBinding_isok = false;
boolean primkeyBinding_isok = false;
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider = new JcaPGPContentVerifierBuilderProvider()
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
Iterator<PGPSignature> itr = signingPublicKey.getSignatures();
subkeyBinding_isok = false; subkeyBinding_isok = false;
tmp_subkeyBinding_isok = false; tmp_subkeyBinding_isok = false;
@ -920,30 +936,30 @@ public class PgpOperation {
//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
//either, so we will err on bad subkey binding here. //either, so we will err on bad subkey binding here.
PGPSignature sig = itr.next(); PGPSignature sig = itr.next();
if (sig.getKeyID() == mKey.getKeyID() && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING) { if (sig.getKeyID() == masterPublicKey.getKeyID() && sig.getSignatureType() == PGPSignature.SUBKEY_BINDING) {
//check and if ok, check primary key binding. //check and if ok, check primary key binding.
sig.init(contentVerifierBuilderProvider, mKey); try {
tmp_subkeyBinding_isok = sig.verifyCertification(mKey, signatureKey); sig.init(contentVerifierBuilderProvider, masterPublicKey);
tmp_subkeyBinding_isok = sig.verifyCertification(masterPublicKey, signingPublicKey);
} catch (PGPException e) {
continue;
} catch (SignatureException e) {
continue;
}
if (tmp_subkeyBinding_isok) if (tmp_subkeyBinding_isok)
subkeyBinding_isok = true; subkeyBinding_isok = true;
if (tmp_subkeyBinding_isok) { if (tmp_subkeyBinding_isok) {
primkeyBinding_isok = verifyPrimaryBinding(sig.getUnhashedSubPackets(), mKey, signatureKey); primkeyBinding_isok = verifyPrimaryBinding(sig.getUnhashedSubPackets(), masterPublicKey, signingPublicKey);
if (primkeyBinding_isok) if (primkeyBinding_isok)
break; break;
primkeyBinding_isok = verifyPrimaryBinding(sig.getHashedSubPackets(), mKey, signatureKey); primkeyBinding_isok = verifyPrimaryBinding(sig.getHashedSubPackets(), masterPublicKey, signingPublicKey);
if (primkeyBinding_isok) if (primkeyBinding_isok)
break; break;
} }
} }
} }
} else { //if the key used to make the signature was the master key, no need to check binding sigs return (subkeyBinding_isok & primkeyBinding_isok);
subkeyBinding_isok = true;
primkeyBinding_isok = true;
}
returnData.putBoolean(KeychainIntentService.RESULT_SIGNATURE_SUCCESS, sig_isok & subkeyBinding_isok & primkeyBinding_isok);
updateProgress(R.string.progress_done, 100, 100);
return returnData;
} }
private boolean verifyPrimaryBinding(PGPSignatureSubpacketVector Pkts, PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey) private boolean verifyPrimaryBinding(PGPSignatureSubpacketVector Pkts, PGPPublicKey masterPublicKey, PGPPublicKey signingPublicKey)