Package org.alfresco.encryption
Class DefaultEncryptionUtils
java.lang.Object
org.alfresco.encryption.DefaultEncryptionUtils
- All Implemented Interfaces:
EncryptionUtils
Various encryption utility methods.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
authenticate
(byte[] expectedMAC, MACUtils.MACInput macInput) 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.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.protected AlgorithmParameters
decodeAlgorithmParameters
(javax.servlet.http.HttpServletRequest req) Decode cipher algorithm parameters from the HTTP methodprotected AlgorithmParameters
decodeAlgorithmParameters
(org.apache.commons.httpclient.HttpMethod method) Decode cipher algorithm parameters from the HTTP methodbyte[]
decryptBody
(javax.servlet.http.HttpServletRequest req) Decrypt the body of the http requestbyte[]
decryptResponseBody
(org.apache.commons.httpclient.HttpMethod method) Decrypt the response body of the http methodprotected String
Get the local registered IP address for authentication purposesprotected byte[]
getMac
(javax.servlet.http.HttpServletRequest req) Get the MAC (Message Authentication Code) on the HTTP requestprotected byte[]
getResponseMac
(org.apache.commons.httpclient.HttpMethod res) Get the MAC (Message Authentication Code) on the HTTP responseprotected Long
getResponseTimestamp
(org.apache.commons.httpclient.HttpMethod method) Get the timestamp on the HTTP responseprotected Long
getTimestamp
(javax.servlet.http.HttpServletRequest method) Get the timestamp on the HTTP requestprotected void
setAlgorithmParameters
(javax.servlet.http.HttpServletResponse response, AlgorithmParameters params) Set the algorithm parameters header on the HTTP responsevoid
setEncryptor
(Encryptor encryptor) protected void
setMac
(javax.servlet.http.HttpServletResponse response, byte[] mac) Set the MAC on the HTTP responsevoid
setMacUtils
(MACUtils macUtils) void
setMessageTimeout
(long messageTimeout) void
setRemoteIP
(String remoteIP) void
setRequestAlgorithmParameters
(org.apache.commons.httpclient.HttpMethod method, AlgorithmParameters params) Set the algorithm parameters header on the method requestvoid
setRequestAuthentication
(org.apache.commons.httpclient.HttpMethod method, byte[] message) Encrypt the http method request bodyprotected void
setRequestMac
(org.apache.commons.httpclient.HttpMethod method, byte[] mac) protected void
setRequestTimestamp
(org.apache.commons.httpclient.HttpMethod method, long timestamp) Set the timestamp on the HTTP requestvoid
setResponseAuthentication
(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse, byte[] responseBody, AlgorithmParameters params) Sets authentication headers on the HTTP response.protected void
setTimestamp
(javax.servlet.http.HttpServletResponse res, long timestamp) Set the timestamp on the HTTP responseprotected boolean
validateTimestamp
(long timestamp)
-
Field Details
-
logger
protected static org.apache.commons.logging.Log logger -
HEADER_ALGORITHM_PARAMETERS
-
HEADER_MAC
-
HEADER_TIMESTAMP
-
encryptor
-
macUtils
-
messageTimeout
protected long messageTimeout -
remoteIP
-
localIP
-
-
Constructor Details
-
DefaultEncryptionUtils
public DefaultEncryptionUtils()
-
-
Method Details
-
getRemoteIP
-
setRemoteIP
-
getLocalIPAddress
Get the local registered IP address for authentication purposes- Returns:
- String
-
setMessageTimeout
public void setMessageTimeout(long messageTimeout) -
setEncryptor
-
setMacUtils
-
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
- HttpServletResponsemac
- byte[]
-
getMac
Get the MAC (Message Authentication Code) on the HTTP request- Parameters:
req
- HttpServletRequest- Returns:
- the MAC
- Throws:
IOException
-
getResponseMac
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
- HttpMethodtimestamp
- (ms, in UNIX time)
-
setTimestamp
protected void setTimestamp(javax.servlet.http.HttpServletResponse res, long timestamp) Set the timestamp on the HTTP response- Parameters:
res
- HttpServletResponsetimestamp
- (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
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 interfaceEncryptionUtils
- 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
- HttpServletResponseparams
- 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 interfaceEncryptionUtils
- Returns:
- decrypted response body
- Throws:
IOException
-
decryptBody
Decrypt the body of the http request- Specified by:
decryptBody
in interfaceEncryptionUtils
- 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 interfaceEncryptionUtils
- 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 interfaceEncryptionUtils
- 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 interfaceEncryptionUtils
- 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 interfaceEncryptionUtils
- Throws:
IOException
-
authenticate
-
validateTimestamp
protected boolean validateTimestamp(long timestamp)
-