mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-14 04:45:04 -05:00
wrapped-key-ring: view certify
This commit is contained in:
parent
b5647b2062
commit
d68fce6875
@ -11,6 +11,7 @@ import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodG
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.util.IterableIterator;
|
import org.sufficientlysecure.keychain.util.IterableIterator;
|
||||||
|
|
||||||
|
import java.security.SignatureException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -157,6 +158,18 @@ public class CachedPublicKey {
|
|||||||
sig.init(contentVerifierBuilderProvider, mKey);
|
sig.init(contentVerifierBuilderProvider, mKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Verify a signature for this pubkey, after it has been initialized by the signer using
|
||||||
|
* initSignature(). This method should probably move into a wrapped PGPSignature class
|
||||||
|
* at some point.
|
||||||
|
*/
|
||||||
|
public boolean verifySignature(PGPSignature sig, String uid) throws PGPException {
|
||||||
|
try {
|
||||||
|
return sig.verifyCertification(uid, mKey);
|
||||||
|
} catch (SignatureException e) {
|
||||||
|
throw new PGPException("Error!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] getFingerprint() {
|
public byte[] getFingerprint() {
|
||||||
return mKey.getFingerprint();
|
return mKey.getFingerprint();
|
||||||
}
|
}
|
||||||
|
@ -37,20 +37,17 @@ import org.spongycastle.bcpg.SignatureSubpacket;
|
|||||||
import org.spongycastle.bcpg.SignatureSubpacketTags;
|
import org.spongycastle.bcpg.SignatureSubpacketTags;
|
||||||
import org.spongycastle.bcpg.sig.RevocationReason;
|
import org.spongycastle.bcpg.sig.RevocationReason;
|
||||||
import org.spongycastle.openpgp.PGPException;
|
import org.spongycastle.openpgp.PGPException;
|
||||||
import org.spongycastle.openpgp.PGPKeyRing;
|
|
||||||
import org.spongycastle.openpgp.PGPSignature;
|
import org.spongycastle.openpgp.PGPSignature;
|
||||||
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.CachedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.Certs;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.security.SignatureException;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class ViewCertActivity extends ActionBarActivity
|
public class ViewCertActivity extends ActionBarActivity
|
||||||
@ -147,26 +144,17 @@ public class ViewCertActivity extends ActionBarActivity
|
|||||||
PGPSignature sig = PgpConversionHelper.BytesToPGPSignature(data.getBlob(INDEX_DATA));
|
PGPSignature sig = PgpConversionHelper.BytesToPGPSignature(data.getBlob(INDEX_DATA));
|
||||||
try {
|
try {
|
||||||
ProviderHelper providerHelper = new ProviderHelper(this);
|
ProviderHelper providerHelper = new ProviderHelper(this);
|
||||||
PGPKeyRing signeeRing = providerHelper.getPGPKeyRing(
|
CachedPublicKeyRing signeeRing = providerHelper.getCachedPublicKeyRing(data.getLong(INDEX_MASTER_KEY_ID));
|
||||||
KeychainContract.KeyRingData.buildPublicKeyRingUri(
|
CachedPublicKeyRing signerRing = providerHelper.getCachedPublicKeyRing(sig.getKeyID());
|
||||||
Long.toString(data.getLong(INDEX_MASTER_KEY_ID))));
|
|
||||||
PGPKeyRing signerRing = providerHelper.getPGPKeyRing(
|
|
||||||
KeychainContract.KeyRingData.buildPublicKeyRingUri(
|
|
||||||
Long.toString(sig.getKeyID())));
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
sig.init(new JcaPGPContentVerifierBuilderProvider().setProvider(
|
signerRing.getSubkey().initSignature(sig);
|
||||||
Constants.BOUNCY_CASTLE_PROVIDER_NAME), signerRing.getPublicKey());
|
if (signeeRing.getSubkey().verifySignature(sig, signeeUid)) {
|
||||||
if (sig.verifyCertification(signeeUid, signeeRing.getPublicKey())) {
|
|
||||||
mStatus.setText(R.string.cert_verify_ok);
|
mStatus.setText(R.string.cert_verify_ok);
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.bbutton_success));
|
mStatus.setTextColor(getResources().getColor(R.color.bbutton_success));
|
||||||
} else {
|
} else {
|
||||||
mStatus.setText(R.string.cert_verify_failed);
|
mStatus.setText(R.string.cert_verify_failed);
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
||||||
}
|
}
|
||||||
} catch (SignatureException e) {
|
|
||||||
mStatus.setText(R.string.cert_verify_error);
|
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
|
||||||
} catch (PGPException e) {
|
} catch (PGPException e) {
|
||||||
mStatus.setText(R.string.cert_verify_error);
|
mStatus.setText(R.string.cert_verify_error);
|
||||||
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
mStatus.setTextColor(getResources().getColor(R.color.alert));
|
||||||
|
Loading…
Reference in New Issue
Block a user