Class DefaultEncryptionUtils

java.lang.Object
org.alfresco.encryption.DefaultEncryptionUtils
All Implemented Interfaces:
EncryptionUtils

public class DefaultEncryptionUtils extends Object implements EncryptionUtils
Various encryption utility methods.
Since:
4.0
  • Field Details

    • logger

      protected static org.apache.commons.logging.Log logger
    • HEADER_ALGORITHM_PARAMETERS

      protected static String HEADER_ALGORITHM_PARAMETERS
    • HEADER_MAC

      protected static String HEADER_MAC
    • HEADER_TIMESTAMP

      protected static String HEADER_TIMESTAMP
    • encryptor

      protected Encryptor encryptor
    • macUtils

      protected MACUtils macUtils
    • messageTimeout

      protected long messageTimeout
    • remoteIP

      protected String remoteIP
    • localIP

      protected String localIP
  • Constructor Details

    • DefaultEncryptionUtils

      public DefaultEncryptionUtils()
  • Method Details

    • getRemoteIP

      public String getRemoteIP()
    • setRemoteIP

      public void setRemoteIP(String remoteIP)
    • getLocalIPAddress

      protected String getLocalIPAddress()
      Get the local registered IP address for authentication purposes
      Returns:
      String
    • setMessageTimeout

      public void setMessageTimeout(long messageTimeout)
    • setEncryptor

      public void setEncryptor(Encryptor encryptor)
    • setMacUtils

      public void setMacUtils(MACUtils macUtils)
    • setRequestMac

      protected void setRequestMac(org.apache.commons.httpclient.HttpMethod method, byte[] mac)
    • setMac

      protected void setMac(javax.servlet.http.HttpServletResponse response, byte[] mac)
      Set the MAC on the HTTP response
      Parameters:
      response - HttpServletResponse
      mac - byte[]
    • getMac

      protected byte[] getMac(javax.servlet.http.HttpServletRequest req) throws IOException
      Get the MAC (Message Authentication Code) on the HTTP request
      Parameters:
      req - HttpServletRequest
      Returns:
      the MAC
      Throws:
      IOException
    • getResponseMac

      protected byte[] getResponseMac(org.apache.commons.httpclient.HttpMethod res) throws IOException
      Get the MAC (Message Authentication Code) on the HTTP response
      Parameters:
      res - HttpMethod
      Returns:
      the MAC
      Throws:
      IOException
    • setRequestTimestamp

      protected void setRequestTimestamp(org.apache.commons.httpclient.HttpMethod method, long timestamp)
      Set the timestamp on the HTTP request
      Parameters:
      method - HttpMethod
      timestamp - (ms, in UNIX time)
    • setTimestamp

      protected void setTimestamp(javax.servlet.http.HttpServletResponse res, long timestamp)
      Set the timestamp on the HTTP response
      Parameters:
      res - HttpServletResponse
      timestamp - (ms, in UNIX time)
    • getResponseTimestamp

      protected Long getResponseTimestamp(org.apache.commons.httpclient.HttpMethod method) throws IOException
      Get the timestamp on the HTTP response
      Parameters:
      method - HttpMethod
      Returns:
      timestamp (ms, in UNIX time)
      Throws:
      IOException
    • getTimestamp

      protected Long getTimestamp(javax.servlet.http.HttpServletRequest method) throws IOException
      Get the timestamp on the HTTP request
      Parameters:
      method - HttpServletRequest
      Returns:
      timestamp (ms, in UNIX time)
      Throws:
      IOException
    • setRequestAlgorithmParameters

      public void setRequestAlgorithmParameters(org.apache.commons.httpclient.HttpMethod method, AlgorithmParameters params) throws IOException
      Set the algorithm parameters header on the method request
      Specified by:
      setRequestAlgorithmParameters in interface EncryptionUtils
      Throws:
      IOException
    • setAlgorithmParameters

      protected void setAlgorithmParameters(javax.servlet.http.HttpServletResponse response, AlgorithmParameters params) throws IOException
      Set the algorithm parameters header on the HTTP response
      Parameters:
      response - HttpServletResponse
      params - AlgorithmParameters
      Throws:
      IOException
    • decodeAlgorithmParameters

      protected AlgorithmParameters decodeAlgorithmParameters(org.apache.commons.httpclient.HttpMethod method) throws IOException
      Decode cipher algorithm parameters from the HTTP method
      Parameters:
      method - HttpMethod
      Returns:
      decoded algorithm parameters
      Throws:
      IOException
    • decodeAlgorithmParameters

      protected AlgorithmParameters decodeAlgorithmParameters(javax.servlet.http.HttpServletRequest req) throws IOException
      Decode cipher algorithm parameters from the HTTP method
      Parameters:
      req -
      Returns:
      decoded algorithm parameters
      Throws:
      IOException
    • decryptResponseBody

      public byte[] decryptResponseBody(org.apache.commons.httpclient.HttpMethod method) throws IOException
      Decrypt the response body of the http method
      Specified by:
      decryptResponseBody in interface EncryptionUtils
      Returns:
      decrypted response body
      Throws:
      IOException
    • decryptBody

      public byte[] decryptBody(javax.servlet.http.HttpServletRequest req) throws IOException
      Decrypt the body of the http request
      Specified by:
      decryptBody in interface EncryptionUtils
      Returns:
      decrypted response body
      Throws:
      IOException
    • authenticateResponse

      public boolean authenticateResponse(org.apache.commons.httpclient.HttpMethod method, String remoteIP, byte[] decryptedBody)
      Authenticate the http method response: validate the MAC, check that the remote IP is as expected and that the timestamp is recent.
      Specified by:
      authenticateResponse in interface EncryptionUtils
      Returns:
      true if the method reponse is authentic, false otherwise
    • authenticate

      public boolean authenticate(javax.servlet.http.HttpServletRequest req, byte[] decryptedBody)
      Authenticate the http request: validate the MAC, check that the remote IP is as expected and that the timestamp is recent.
      Specified by:
      authenticate in interface EncryptionUtils
      Returns:
      true if the method request is authentic, false otherwise
    • setRequestAuthentication

      public void setRequestAuthentication(org.apache.commons.httpclient.HttpMethod method, byte[] message) throws IOException
      Encrypt the http method request body
      Specified by:
      setRequestAuthentication in interface EncryptionUtils
      Throws:
      IOException
    • setResponseAuthentication

      public void setResponseAuthentication(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse, byte[] responseBody, AlgorithmParameters params) throws IOException
      Sets authentication headers on the HTTP response.
      Specified by:
      setResponseAuthentication in interface EncryptionUtils
      Throws:
      IOException
    • authenticate

      protected boolean authenticate(byte[] expectedMAC, MACUtils.MACInput macInput)
    • validateTimestamp

      protected boolean validateTimestamp(long timestamp)