Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
You are viewing an older version of this section. Click here to navigate to the latest version.

PGP Security

This extension adds PGP security on endpoint communication. With PGP you can achieve end-to-end security communication with signed and encrypted messages between parties.


Policy Files

If you are running JDK 1.4+ that comes with the Sun JCE by default, you must install the Unlimited Strength Jurisdiction Policy files, which can be downloaded from the following URL (note that they are listed entirely at the bottom of the page, in the Other Downloads section):

These files must be installed in $JAVA_HOME$/jre/lib/security

According to Sun, the default distribution of the JCE allows "strong, but limited strength cryptography." This means that you cannot use RSA keys bigger than 2048 bits and no symmetric ciphers that use more than 128 bits. ElGamal is not allowed at all, thus DH/DSS cannot be used for encryption.

Encrypting and Decrypting

To encrypt and decrypt messages you need to configure the following elements:

  • A security manager: responsible of holding a security provider, which contains the key rings, and the encryption strategy to be used. This allows for the encryption of all messages using the same key or to facilitate the use of different key rings.

  • A key manager: which is responsible for reading the key rings.

  • A credential accessor: which determines the key ring and key manager to be used to encrypt/decrypt the message being processed.

A full example is shown below:

<spring:beans> <spring:bean id="pgpKeyManager" class="org.mule.module.pgp.PGPKeyRingImpl" init-method="initialise">                            <spring:property name="publicKeyRingFileName" value="pubring.gpg"/>     <spring:property name="secretKeyRingFileName" value="secring.gpg"/>     <spring:property name="secretAliasId" value="${public.KeyId.LongValue}"/>               <spring:property name="secretPassphrase" value="${secret.Passphrase}"/> </spring:bean>      <spring:bean id="credentialAccessor" class="com.somecompany.apps.AppCredentialAccessor">            <spring:property name="credentials" value="John Smith (TestingKey) &lt;;"/>        </spring:bean>  </spring:beans><pgp:security-manager>   <pgp:security-provider name="pgpSecurityProvider" keyManager-ref="pgpKeyManager"/>      <pgp:keybased-encryption-strategy        name="keyBasedEncryptionStrategy"       keyManager-ref="pgpKeyManager"      credentialsAccessor-ref="credentialAccessor"/></pgp:security-manager>

The pgpKeyManager (in the spring:beans tag) is the one responsible for reading the rings. You have to set all the parameters: public and secret rings, the alias id (the long value in the ring) and the secret passphrase. In the same section, you can see the credentials accessor which needs to implement the CredentialsAccessor interface basically returning the key id based on the message (MuleEvent). Finally the pgp:security-manager glues both beans.

You are ready to encrypt and decrypt messages in your flows. The following two flows show how to use the encrypt-transformer and decrypt-transformer to encrypt and decrypt files.

<flow name="processEncryptFiles">  <file:inbound-endpoint connector-ref="inputEncrypt"      path="file:///temp/fileInput" moveToDirectory="file:///temp/fileInputBackup"        moveToPattern="#[header:originalFilename].backup" transformer-refs="file2Bytes" />   <encrypt-transformer name="pgpEncrypt"       strategy-ref="keyBasedEncryptionStrategy" /> <file:outbound-endpoint connector-ref="output"       path="file:///temp/fileOutput" outputPattern="#[function:datestamp]-#[header:originalFilename]" /></flow><flow name="processDecryptFiles">   <file:inbound-endpoint connector-ref="inputDecrypt"      path="file:///temp/fileOutput" moveToDirectory="file:///temp/fileOutputEncrypted"       moveToPattern="#[header:originalFilename].backup" transformer-refs="file2Bytes" />   <decrypt-transformer name="pgpDecrypt"       strategy-ref="keyBasedEncryptionStrategy" /> <file:outbound-endpoint connector-ref="output"       path="file:///temp/fileOutputDecrypted" outputPattern="#[function:datestamp]-#[header:originalFilename]" /></flow>

In the following section we explain how to configure each element.

Configuring the Security Manager

To configure the Security Manager you need to reference your key manager and your encryption strategy. The Key manager is simple a reference to your key manager ring.

Configuring the Key Manager

To configure your key manager you have to create a spring bean as shown before. You will need to set the public and secret ring files, the alias id and the secret passphrase. As Mule uses the bouncy castle library to encrypt/decrypt messages we recommend to obtain the alias id (as a long value) using this library. If Mule does not find your id in the ring it will throw an exception and it will list all the available ids in your ring.

Configuring a Credential Accessor

To configure your credential accessor you need to define a class which determines your key id. For instance the following class (used in the example) returns always the same fixed string thus all the messages will be encrypted/decrypted using the same key id. If you need to use different key ids then return different strings according to the MuleEvent received as a parameter.

public class FakeCredentialAccessor implements CredentialsAccessor{    private String credentials = "John Smith (TestingKey) <>";        public FakeCredentialAccessor()    {    }        public FakeCredentialAccessor(String string)    {        this.credentials = string;    }    public String getCredentials()    {        return credentials;    }    public void setCredentials(String credentials)    {        this.credentials = credentials;    }    public Object getCredentials(MuleEvent event)    {        return this.credentials;    }    public void setCredentials(MuleEvent event, Object credentials)    {        // dummy    }}