aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-05-14 15:37:55 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-05-27 13:56:30 +0200
commita53da491c09fc7db814d4c2358ffe5dc9fe888bc (patch)
treef2bcc862c883de89016f8eec437f9aa8e5d1f706 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
parent6415290b2d059752ebcfd74fa2c514aa5e5ef875 (diff)
downloadopen-keychain-a53da491c09fc7db814d4c2358ffe5dc9fe888bc.tar.gz
open-keychain-a53da491c09fc7db814d4c2358ffe5dc9fe888bc.tar.bz2
open-keychain-a53da491c09fc7db814d4c2358ffe5dc9fe888bc.zip
new savekeyring operation (mostly stub)
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java77
1 files changed, 53 insertions, 24 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
index cdadbca7f..9f26439d2 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedSignature.java
@@ -5,6 +5,7 @@ import org.spongycastle.bcpg.SignatureSubpacketTags;
import org.spongycastle.bcpg.sig.RevocationReason;
import org.spongycastle.openpgp.PGPException;
import org.spongycastle.openpgp.PGPObjectFactory;
+import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.PGPSignature;
import org.spongycastle.openpgp.PGPSignatureList;
import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
@@ -14,6 +15,7 @@ import org.sufficientlysecure.keychain.util.Log;
import java.io.IOException;
import java.security.SignatureException;
+import java.util.Date;
public class WrappedSignature {
@@ -33,16 +35,57 @@ public class WrappedSignature {
return mSig.getKeyID();
}
+ public int getSignatureType() {
+ return mSig.getSignatureType();
+ }
+
public int getKeyAlgorithm() {
return mSig.getKeyAlgorithm();
}
+ public Date getCreationTime() {
+ return mSig.getCreationTime();
+ }
+
+ public byte[] getEncoded() throws IOException {
+ return mSig.getEncoded();
+ }
+
+ public boolean isRevocation() {
+ return mSig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.REVOCATION_REASON);
+ }
+
+ public boolean isPrimaryUserId() {
+ return mSig.getHashedSubPackets().isPrimaryUserID();
+ }
+
+ public String getRevocationReason() throws PgpGeneralException {
+ if(!isRevocation()) {
+ throw new PgpGeneralException("Not a revocation signature.");
+ }
+ SignatureSubpacket p = mSig.getHashedSubPackets().getSubpacket(
+ SignatureSubpacketTags.REVOCATION_REASON);
+ // For some reason, this is missing in SignatureSubpacketInputStream:146
+ if (!(p instanceof RevocationReason)) {
+ p = new RevocationReason(false, p.getData());
+ }
+ return ((RevocationReason) p).getRevocationDescription();
+ }
+
public void init(WrappedPublicKey key) throws PgpGeneralException {
+ init(key.getPublicKey());
+ }
+
+ public void init(UncachedPublicKey key) throws PgpGeneralException {
+ init(key.getPublicKey());
+ }
+
+ protected void init(PGPPublicKey key) throws PgpGeneralException {
try {
JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
new JcaPGPContentVerifierBuilderProvider()
.setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
- mSig.init(contentVerifierBuilderProvider, key.getPublicKey());
+ mSig.init(contentVerifierBuilderProvider, key);
} catch(PGPException e) {
throw new PgpGeneralException(e);
}
@@ -74,30 +117,9 @@ public class WrappedSignature {
}
}
- public boolean isRevocation() {
- return mSig.getHashedSubPackets().hasSubpacket(SignatureSubpacketTags.REVOCATION_REASON);
- }
-
- public String getRevocationReason() throws PgpGeneralException {
- if(!isRevocation()) {
- throw new PgpGeneralException("Not a revocation signature.");
- }
- SignatureSubpacket p = mSig.getHashedSubPackets().getSubpacket(
- SignatureSubpacketTags.REVOCATION_REASON);
- // For some reason, this is missing in SignatureSubpacketInputStream:146
- if (!(p instanceof RevocationReason)) {
- p = new RevocationReason(false, p.getData());
- }
- return ((RevocationReason) p).getRevocationDescription();
- }
-
- /** 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(WrappedPublicKey key, String uid) throws PgpGeneralException {
+ protected boolean verifySignature(PGPPublicKey key, String uid) throws PgpGeneralException {
try {
- return mSig.verifyCertification(uid, key.getPublicKey());
+ return mSig.verifyCertification(uid, key);
} catch (SignatureException e) {
throw new PgpGeneralException("Error!", e);
} catch (PGPException e) {
@@ -105,6 +127,13 @@ public class WrappedSignature {
}
}
+ public boolean verifySignature(UncachedPublicKey key, String uid) throws PgpGeneralException {
+ return verifySignature(key.getPublicKey(), uid);
+ }
+ public boolean verifySignature(WrappedPublicKey key, String uid) throws PgpGeneralException {
+ return verifySignature(key.getPublicKey(), uid);
+ }
+
public static WrappedSignature fromBytes(byte[] data) {
PGPObjectFactory factory = new PGPObjectFactory(data);
PGPSignatureList signatures = null;