Class SignatureSubpacketsUtil


  • public class SignatureSubpacketsUtil
    extends java.lang.Object
    Utility class to access signature subpackets from signatures. Since rfc4880 is not always clear about where a signature subpacket can be located (hashed/unhashed area), this class makes some educated guesses as to where the subpacket may be found when necessary.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.bouncycastle.openpgp.PGPSignatureList getEmbeddedSignature​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the embedded signature subpacket from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.Exportable getExportableCertification​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the signatures exportable certification subpacket from the hashed area.
      static org.bouncycastle.bcpg.sig.Features getFeatures​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the features subpacket from the signatures hashed area.
      static java.util.List<org.bouncycastle.bcpg.sig.NotationData> getHashedNotationData​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the notation data subpackets from the signatures hashed area.
      static java.util.List<org.bouncycastle.bcpg.sig.IntendedRecipientFingerprint> getIntendedRecipientFingerprints​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the intended recipients fingerprint subpackets from the hashed area of this signature.
      static org.bouncycastle.bcpg.sig.IssuerFingerprint getIssuerFingerprint​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the issuer-fingerprint subpacket of the signature.
      static OpenPgpV4Fingerprint getIssuerFingerprintAsOpenPgpV4Fingerprint​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the IssuerFingerprint subpacket of the signature into a OpenPgpV4Fingerprint.
      static org.bouncycastle.bcpg.sig.IssuerKeyID getIssuerKeyId​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the issuer key-id subpacket of the signature.
      static org.bouncycastle.bcpg.sig.KeyExpirationTime getKeyExpirationTime​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the key expiration time subpacket of this signature.
      static java.util.Date getKeyExpirationTimeAsDate​(org.bouncycastle.openpgp.PGPSignature signature, org.bouncycastle.openpgp.PGPPublicKey signingKey)
      Return the signatures key-expiration time as a date.
      static org.bouncycastle.bcpg.sig.KeyFlags getKeyFlags​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the key flags subpacket from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.PreferredAlgorithms getPreferredCompressionAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the compression algorithm preferences from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.PreferredAlgorithms getPreferredHashAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the hash algorithm preferences from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.PreferredAlgorithms getPreferredSymmetricAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the symmetric algorithm preferences from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.PrimaryUserID getPrimaryUserId​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the primary user-id subpacket from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.Revocable getRevocable​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the revocable subpacket of this signature.
      static org.bouncycastle.bcpg.sig.RevocationKey getRevocationKey​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the revocation key subpacket from the signatures hashed area.
      static org.bouncycastle.bcpg.sig.RevocationReason getRevocationReason​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the revocation reason subpacket of the signature.
      static org.bouncycastle.bcpg.sig.SignatureCreationTime getSignatureCreationTime​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the signature creation time subpacket.
      static org.bouncycastle.bcpg.sig.SignatureExpirationTime getSignatureExpirationTime​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the signature expiration time subpacket of the signature.
      static java.util.Date getSignatureExpirationTimeAsDate​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the signatures expiration time as a date.
      static <P extends org.bouncycastle.bcpg.SignatureSubpacket>
      P
      getSignatureSubpacket​(org.bouncycastle.openpgp.PGPSignatureSubpacketVector vector, SignatureSubpacket type)
      Return the last occurence of a subpacket type in the given signature subpacket vector.
      static org.bouncycastle.bcpg.sig.SignatureTarget getSignatureTarget​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the signature target subpacket from the signature.
      static org.bouncycastle.bcpg.sig.SignerUserID getSignerUserID​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the signers user-id from the hashed area of the signature.
      static org.bouncycastle.bcpg.sig.TrustSignature getTrustSignature​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the trust signature packet from the signatures hashed area.
      static java.util.List<org.bouncycastle.bcpg.sig.NotationData> getUnhashedNotationData​(org.bouncycastle.openpgp.PGPSignature signature)
      Return the notation data subpackets from the signatures unhashed area.
      static java.util.List<KeyFlag> parseKeyFlags​(org.bouncycastle.openpgp.PGPSignature signature)
      Return a list of key flags carried by the signature.
      static java.util.Set<CompressionAlgorithm> parsePreferredCompressionAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)  
      static java.util.Set<HashAlgorithm> parsePreferredHashAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)  
      static java.util.Set<SymmetricKeyAlgorithm> parsePreferredSymmetricKeyAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SignatureSubpacketsUtil

        public SignatureSubpacketsUtil()
    • Method Detail

      • getIssuerFingerprint

        public static org.bouncycastle.bcpg.sig.IssuerFingerprint getIssuerFingerprint​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the issuer-fingerprint subpacket of the signature. Since this packet is self-authenticating, we expect it to be in the unhashed area, however as it cannot hurt we search for it in the hashed area first.
        Parameters:
        signature - signature
        Returns:
        issuer fingerprint or null
      • getIssuerFingerprintAsOpenPgpV4Fingerprint

        public static OpenPgpV4Fingerprint getIssuerFingerprintAsOpenPgpV4Fingerprint​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the IssuerFingerprint subpacket of the signature into a OpenPgpV4Fingerprint. If no issuer fingerprint is present in the signature, return null.
        Parameters:
        signature - signature
        Returns:
        v4 fingerprint of the issuer, or null
      • getIssuerKeyId

        public static org.bouncycastle.bcpg.sig.IssuerKeyID getIssuerKeyId​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the issuer key-id subpacket of the signature. Since this packet is self-authenticating, we expect it to be in the unhashed area, however as it cannot hurt we search for it in the hashed area first.
        Parameters:
        signature - signature
        Returns:
        issuer key-id or null
      • getRevocationReason

        public static org.bouncycastle.bcpg.sig.RevocationReason getRevocationReason​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the revocation reason subpacket of the signature. Since this packet is rather important for revocations, we only search for it in the hashed area of the signature.
        Parameters:
        signature - signature
        Returns:
        revocation reason
      • getSignatureCreationTime

        public static org.bouncycastle.bcpg.sig.SignatureCreationTime getSignatureCreationTime​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the signature creation time subpacket. Since this packet is rather important, we only search for it in the hashed area of the signature.
        Parameters:
        signature - signature
        Returns:
        signature creation time subpacket
      • getSignatureExpirationTime

        public static org.bouncycastle.bcpg.sig.SignatureExpirationTime getSignatureExpirationTime​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the signature expiration time subpacket of the signature. Since this packet is rather important, we only search for it in the hashed area of the signature.
        Parameters:
        signature - signature
        Returns:
        signature expiration time
      • getSignatureExpirationTimeAsDate

        public static java.util.Date getSignatureExpirationTimeAsDate​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the signatures expiration time as a date. The expiration date is computed by adding the expiration time to the signature creation date. If the signature has no expiration time subpacket, or the expiration time is set to '0', this message returns null.
        Parameters:
        signature - signature
        Returns:
        expiration time as date
      • getKeyExpirationTime

        public static org.bouncycastle.bcpg.sig.KeyExpirationTime getKeyExpirationTime​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the key expiration time subpacket of this signature. We only look for it in the hashed area of the signature.
        Parameters:
        signature - signature
        Returns:
        key expiration time
      • getKeyExpirationTimeAsDate

        public static java.util.Date getKeyExpirationTimeAsDate​(org.bouncycastle.openpgp.PGPSignature signature,
                                                                org.bouncycastle.openpgp.PGPPublicKey signingKey)
        Return the signatures key-expiration time as a date. The expiration date is computed by adding the signatures' key-expiration time to the signing keys creation date. If the signature does not have a key-expiration time subpacket, or its value is '0', this method returns null.
        Parameters:
        signature - self-signature carrying the key-expiration time subpacket
        signingKey - signature creation key
        Returns:
        key expiration time as date
      • getRevocable

        public static org.bouncycastle.bcpg.sig.Revocable getRevocable​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the revocable subpacket of this signature. We only look for it in the hashed area of the signature.
        Parameters:
        signature - signature
        Returns:
        revocable subpacket
      • getPreferredSymmetricAlgorithms

        public static org.bouncycastle.bcpg.sig.PreferredAlgorithms getPreferredSymmetricAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the symmetric algorithm preferences from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        symm. algo. prefs
      • parsePreferredSymmetricKeyAlgorithms

        public static java.util.Set<SymmetricKeyAlgorithm> parsePreferredSymmetricKeyAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
      • getPreferredHashAlgorithms

        public static org.bouncycastle.bcpg.sig.PreferredAlgorithms getPreferredHashAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the hash algorithm preferences from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        hash algo prefs
      • parsePreferredHashAlgorithms

        public static java.util.Set<HashAlgorithm> parsePreferredHashAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
      • getPreferredCompressionAlgorithms

        public static org.bouncycastle.bcpg.sig.PreferredAlgorithms getPreferredCompressionAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the compression algorithm preferences from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        compression algo prefs
      • parsePreferredCompressionAlgorithms

        public static java.util.Set<CompressionAlgorithm> parsePreferredCompressionAlgorithms​(org.bouncycastle.openpgp.PGPSignature signature)
      • getPrimaryUserId

        public static org.bouncycastle.bcpg.sig.PrimaryUserID getPrimaryUserId​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the primary user-id subpacket from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        primary user id
      • getKeyFlags

        public static org.bouncycastle.bcpg.sig.KeyFlags getKeyFlags​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the key flags subpacket from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        key flags
      • parseKeyFlags

        public static java.util.List<KeyFlag> parseKeyFlags​(@Nullable
                                                            org.bouncycastle.openpgp.PGPSignature signature)
        Return a list of key flags carried by the signature. If the signature is null, or has no KeyFlags subpacket, return null.
        Parameters:
        signature - signature
        Returns:
        list of key flags
      • getFeatures

        public static org.bouncycastle.bcpg.sig.Features getFeatures​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the features subpacket from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        features subpacket
      • getSignatureTarget

        public static org.bouncycastle.bcpg.sig.SignatureTarget getSignatureTarget​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the signature target subpacket from the signature. We search for this subpacket in the hashed and unhashed area (in this order).
        Parameters:
        signature - signature
        Returns:
        signature target
      • getHashedNotationData

        public static java.util.List<org.bouncycastle.bcpg.sig.NotationData> getHashedNotationData​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the notation data subpackets from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        hashed notations
      • getUnhashedNotationData

        public static java.util.List<org.bouncycastle.bcpg.sig.NotationData> getUnhashedNotationData​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the notation data subpackets from the signatures unhashed area.
        Parameters:
        signature - signture
        Returns:
        unhashed notations
      • getRevocationKey

        public static org.bouncycastle.bcpg.sig.RevocationKey getRevocationKey​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the revocation key subpacket from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        revocation key
      • getSignerUserID

        public static org.bouncycastle.bcpg.sig.SignerUserID getSignerUserID​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the signers user-id from the hashed area of the signature. TODO: Can this subpacket also be found in the unhashed area?
        Parameters:
        signature - signature
        Returns:
        signers user-id
      • getIntendedRecipientFingerprints

        public static java.util.List<org.bouncycastle.bcpg.sig.IntendedRecipientFingerprint> getIntendedRecipientFingerprints​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the intended recipients fingerprint subpackets from the hashed area of this signature.
        Parameters:
        signature - signature
        Returns:
        intended recipient fingerprint subpackets
      • getEmbeddedSignature

        public static org.bouncycastle.openpgp.PGPSignatureList getEmbeddedSignature​(org.bouncycastle.openpgp.PGPSignature signature)
                                                                              throws org.bouncycastle.openpgp.PGPException
        Return the embedded signature subpacket from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        embedded signature
        Throws:
        org.bouncycastle.openpgp.PGPException
      • getExportableCertification

        public static org.bouncycastle.bcpg.sig.Exportable getExportableCertification​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the signatures exportable certification subpacket from the hashed area. TODO: Can this packet also be placed in the unhashed area?
        Parameters:
        signature - signature
        Returns:
        exportable certification subpacket
      • getTrustSignature

        public static org.bouncycastle.bcpg.sig.TrustSignature getTrustSignature​(org.bouncycastle.openpgp.PGPSignature signature)
        Return the trust signature packet from the signatures hashed area.
        Parameters:
        signature - signature
        Returns:
        trust signature subpacket
      • getSignatureSubpacket

        public static <P extends org.bouncycastle.bcpg.SignatureSubpacket> P getSignatureSubpacket​(org.bouncycastle.openpgp.PGPSignatureSubpacketVector vector,
                                                                                                   SignatureSubpacket type)
        Return the last occurence of a subpacket type in the given signature subpacket vector.
        Type Parameters:
        P - generic return type of the subpacket
        Parameters:
        vector - subpacket vector (hashed/unhashed)
        type - subpacket type
        Returns:
        last occurrence of the subpacket in the vector