Package com.adaptris.security.pgp
Class PGPSignService
- java.lang.Object
-
- com.adaptris.core.ServiceImp
-
- com.adaptris.security.pgp.PGPSignService
-
- All Implemented Interfaces:
AdaptrisComponent
,ComponentLifecycle
,ComponentLifecycleExtension
,MessageEventGenerator
,Service
,StateManagedComponent
@ComponentProfile(summary="Sign data using a PGP/GPG private key", tag="pgp,gpg,sign,signature,private key", since="3.9.2") public class PGPSignService extends ServiceImp
This service provides a way to sign messages via GPG/PGP. It requires a private key, the passphrase to unlock the key, and a message to sign. Optionally it will ASCII armor encode the signature (default) and create a detached signature (default).<pgp-sign> <unique-id>nostalgic-golick</unique-id> <private-key class="constant-data-input-parameter"> <value>-----BEGIN PGP PRIVATE KEY BLOCK----- lQPGBF2ckxABCAC5Kfu39ky3OIXkxwWOJx70G2dLRYvDMHXf3ZraUPNRMIhh3ZGx -----END PGP PRIVATE KEY BLOCK-----</value> </private-key> <passphrase class="constant-data-input-parameter"> <value>my5ecr3tP455w0rd</value> </passphrase> <clearText class="stream-payload-input-parameter"/> <!-- clear text comes from message payload --> <armor-encoding>true</armor-encoding> <detached-signature>true</detached-signature> <signature class="metadata-stream-output-parameter"> <!-- detached signature goes into message metadata --> <metadata-key>signature</metadata-key> </signature> </pgp-sign>
In the adapter configuration file this class is aliased as pgp-sign which is the preferred alternative to the fully qualified classname when building your configuration.
-
-
Constructor Summary
Constructors Constructor Description PGPSignService()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeService()
.void
doService(AdaptrisMessage message)
.protected java.io.InputStream
extractStream(AdaptrisMessage message, DataInputParameter parameter, java.lang.String warning)
protected java.lang.String
extractString(AdaptrisMessage message, DataInputParameter parameter, java.lang.String warning)
java.lang.Boolean
getArmorEncoding()
Get whether the signature output should be ASCII armor encoded.DataInputParameter
getClearText()
Get the data to sign.protected static java.io.InputStream
getDecoderStream(java.io.InputStream in)
Obtains a stream that can be used to read PGP data from the provided stream.java.lang.Boolean
getDetachedSignature()
Get whether the signature should be detached from the message.protected static int
getLengthWithoutSeparatorOrTrailingWhitespace(byte[] line)
protected static int
getLengthWithoutWhiteSpace(byte[] line)
protected static byte[]
getLineSeparator()
DataInputParameter
getPassphrase()
Get the passphrase to unlock the private key.DataInputParameter
getPrivateKey()
Get the private key for decryption.DataOutputParameter
getSignature()
Get the signature.protected void
initService()
.protected void
insertStream(AdaptrisMessage message, DataOutputParameter parameter, java.io.ByteArrayOutputStream value)
void
prepare()
.protected static void
processLine(java.io.OutputStream aOut, org.bouncycastle.openpgp.PGPSignatureGenerator sGen, byte[] line)
protected static void
processLine(org.bouncycastle.openpgp.PGPSignature sig, byte[] line)
protected static int
readInputLine(java.io.ByteArrayOutputStream bOut, int lookAhead, java.io.InputStream fIn)
protected static int
readInputLine(java.io.ByteArrayOutputStream bOut, java.io.InputStream fIn)
void
setArmorEncoding(java.lang.Boolean armorEncoding)
Set whether the signature output should be ASCII armor encoded.void
setClearText(DataInputParameter clearText)
Set the data to sign.void
setDetachedSignature(java.lang.Boolean detachedSignature)
Set whether the signature should be detached from the message.void
setPassphrase(DataInputParameter passphrase)
Set the passphrase to unlock the private key.void
setPrivateKey(DataInputParameter privateKey)
Set the private key for decryption.void
setSignature(DataOutputParameter signature)
Set the signature.-
Methods inherited from class com.adaptris.core.ServiceImp
changeState, close, continueOnFailure, createName, createQualifier, getContinueOnFail, getIsTrackingEndpoint, getUniqueId, init, isBranching, isTrackingEndpoint, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, setContinueOnFail, setIsTrackingEndpoint, setUniqueId, start, stop
-
-
-
-
Method Detail
-
doService
public void doService(AdaptrisMessage message) throws ServiceException
.- Throws:
ServiceException
-
setPrivateKey
public void setPrivateKey(DataInputParameter privateKey)
Set the private key for decryption.- Parameters:
privateKey
- The private key.
-
getPrivateKey
public DataInputParameter getPrivateKey()
Get the private key for decryption.- Returns:
- The private key.
-
setPassphrase
public void setPassphrase(DataInputParameter passphrase)
Set the passphrase to unlock the private key.- Parameters:
passphrase
- The passphrase.
-
getPassphrase
public DataInputParameter getPassphrase()
Get the passphrase to unlock the private key.- Returns:
- The passphrase.
-
setClearText
public void setClearText(DataInputParameter clearText)
Set the data to sign.- Parameters:
clearText
- The data to sign.
-
getClearText
public DataInputParameter getClearText()
Get the data to sign.- Returns:
- The data to sign.
-
setArmorEncoding
public void setArmorEncoding(java.lang.Boolean armorEncoding)
Set whether the signature output should be ASCII armor encoded.- Parameters:
armorEncoding
- Whether the signature should be armor encoded.
-
getArmorEncoding
public java.lang.Boolean getArmorEncoding()
Get whether the signature output should be ASCII armor encoded.- Returns:
- Whether the signature should be armor encoded.
-
setDetachedSignature
public void setDetachedSignature(java.lang.Boolean detachedSignature)
Set whether the signature should be detached from the message.- Parameters:
detachedSignature
- Whether the signature should be detached.
-
getDetachedSignature
public java.lang.Boolean getDetachedSignature()
Get whether the signature should be detached from the message.- Returns:
- Whether the signature should be detached.
-
setSignature
public void setSignature(DataOutputParameter signature)
Set the signature.- Parameters:
signature
- The signature.
-
getSignature
public DataOutputParameter getSignature()
Get the signature.- Returns:
- The signature.
-
initService
protected void initService()
.- Specified by:
initService
in classServiceImp
-
closeService
protected void closeService()
.- Specified by:
closeService
in classServiceImp
-
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 theArmoredInputStream
.
-
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
-
-