Class PGPVerifyService

  • All Implemented Interfaces:
    AdaptrisComponent, ComponentLifecycle, ComponentLifecycleExtension, MessageEventGenerator, Service, StateManagedComponent

    @ComponentProfile(summary="Verify sign data using a PGP/GPG public key",
                      tag="pgp,gpg,sign,signature,verify,public key",
                      since="3.9.2")
    public class PGPVerifyService
    extends ServiceImp
    This service provides a way to verify GPG/PGP signed messages. It requires the public key of whom signed the message, the signed message, and (if the signature is detached) the signature. It will will also optionally return the original/unsigned message (especially useful if the signature was not detached).
    
        <pgp-verify>
            <unique-id>jovial-elion</unique-id>
            <public-key class="constant-data-input-parameter">
                <value>-----BEGIN PGP PUBLIC KEY BLOCK-----
    
        mQENBF2ckxABCAC5Kfu39ky3OIXkxwWOJx70G2dLRYvDMHXf3ZraUPNRMIhh3ZGx
        -----END PGP PUBLIC KEY BLOCK-----</value>
            </public-key>
            <signed-message class="stream-payload-input-parameter"/>         <!-- signed message (without signature, as it's detached) -->
            <signature class="metadata-stream-input-parameter">              <!-- detached signature comes into message metadata -->
                <metadata-key>signature</metadata-key>
            </signature>
            <original-message class="string-payload-data-output-parameter"/> <!-- optional original message, without signature -->
        </pgp-verify>
     

    In the adapter configuration file this class is aliased as pgp-verify which is the preferred alternative to the fully qualified classname when building your configuration.

    • Constructor Detail

      • PGPVerifyService

        public PGPVerifyService()
    • Method Detail

      • setPublicKey

        public void setPublicKey​(DataInputParameter publicKey)
        Set the private key for decryption.
        Parameters:
        publicKey - The private key.
      • getPublicKey

        public DataInputParameter getPublicKey()
        Get the private key for decryption.
        Returns:
        The private key.
      • setSignedMessage

        public void setSignedMessage​(DataInputParameter signedMessage)
        Set the signed message to verify.
        Parameters:
        signedMessage - The signed message.
      • getSignedMessage

        public DataInputParameter getSignedMessage()
        Get the signed message to verify.
        Returns:
        The signed message.
      • setSignature

        public void setSignature​(DataInputParameter signature)
        Set the signature to verify.
        Parameters:
        signature - The signature.
      • getSignature

        public DataInputParameter getSignature()
        Get the signature to verify.
        Returns:
        The signature.
      • setOriginalMessage

        public void setOriginalMessage​(DataOutputParameter message)
        Set the unsigned message.
        Parameters:
        message - The message.
      • getOriginalMessage

        public DataOutputParameter getOriginalMessage()
        Get the unsigned message.
        Returns:
        The message.
      • prepare

        public void prepare()
        .
      • extractStream

        protected java.io.InputStream extractStream​(AdaptrisMessage message,
                                                    DataInputParameter parameter,
                                                    java.lang.String warning)
                                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • extractString

        protected java.lang.String extractString​(AdaptrisMessage message,
                                                 DataInputParameter parameter,
                                                 java.lang.String warning)
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • insertStream

        protected void insertStream​(AdaptrisMessage message,
                                    DataOutputParameter parameter,
                                    java.io.ByteArrayOutputStream value)
                             throws java.lang.Exception
        Throws:
        java.lang.Exception
      • getDecoderStream

        protected static java.io.InputStream getDecoderStream​(java.io.InputStream in)
                                                       throws java.io.IOException
        Obtains a stream that can be used to read PGP data from the provided stream.

        If the initial bytes of the underlying stream are binary PGP encodings, then the stream will be returned directly, otherwise an ArmoredInputStream is used to wrap the provided stream and remove ASCII-Armored encoding.

        Parameters:
        in - the stream to be checked and possibly wrapped.
        Returns:
        a stream that will return PGP binary encoded data.
        Throws:
        java.io.IOException - if an error occurs reading the stream, or initialising the ArmoredInputStream.
      • processLine

        protected static void processLine​(java.io.OutputStream aOut,
                                          org.bouncycastle.openpgp.PGPSignatureGenerator sGen,
                                          byte[] line)
                                   throws java.security.SignatureException,
                                          java.io.IOException
        Throws:
        java.security.SignatureException
        java.io.IOException
      • processLine

        protected static void processLine​(org.bouncycastle.openpgp.PGPSignature sig,
                                          byte[] line)
                                   throws java.security.SignatureException,
                                          java.io.IOException
        Throws:
        java.security.SignatureException
        java.io.IOException
      • getLengthWithoutWhiteSpace

        protected static int getLengthWithoutWhiteSpace​(byte[] line)
      • getLengthWithoutSeparatorOrTrailingWhitespace

        protected static int getLengthWithoutSeparatorOrTrailingWhitespace​(byte[] line)
      • getLineSeparator

        protected static byte[] getLineSeparator()
      • readInputLine

        protected static int readInputLine​(java.io.ByteArrayOutputStream bOut,
                                           java.io.InputStream fIn)
                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • readInputLine

        protected static int readInputLine​(java.io.ByteArrayOutputStream bOut,
                                           int lookAhead,
                                           java.io.InputStream fIn)
                                    throws java.io.IOException
        Throws:
        java.io.IOException