Class DKIMSignature
- java.lang.Object
-
- org.jboss.resteasy.security.doseta.DKIMSignature
-
public class DKIMSignature extends Object
One single signature within a DKIM-Signature header- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
-
Field Summary
Fields Modifier and Type Field Description static StringALGORITHMprotected Map<String,String>attributesstatic StringBODY_HASHprotected booleanbodyHashRequiredstatic StringCANONICALIZATIONstatic StringDEFAULT_ALGORITHMThis is settablestatic StringDEFAULT_SIGNERThis is settablestatic StringDKIM_SIGNATUREstatic StringDOMAINstatic StringEXPIRATIONprotected List<String>headersstatic StringHEADERSprotected StringheaderValuestatic StringIDENTITYstatic StringLENGTHprotected PrivateKeyprivateKeystatic StringQUERYstatic StringSELECTORstatic StringSHA256WITH_RSAprotected byte[]signaturestatic StringSIGNATUREstatic StringTIMESTAMPstatic StringVERSION
-
Constructor Summary
Constructors Constructor Description DKIMSignature()DKIMSignature(String headerValue)DKIMSignature(Map<String,String> attrs)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddHeader(String headerName)Add a reference to a header within the signature calculation.protected voidextractAttributes()StringgetAlgorithm()Map<String,String>getAttributes()StringgetBased64Signature()StringgetDomain()List<String>getHeaderList()StringgetId()PrivateKeygetPrivateKey()Private key to use to sign the message.StringgetQuery()StringgetSelector()byte[]getSignature()booleanisBodyHashRequired()Whether or not to add a body hash to signature.booleanisExpired()Return false if true current time.booleanisStale(int seconds, int minutes, int hours, int days, int months, int years)Returns false if timestamp does not exist or if the current time is greater than timestamp + variables.voidsetAlgorithm(String value)Default value is SHA256withRSA, see Javadoc on java.security.Signature for other supported values.voidsetAttribute(String name, String value)voidsetBase64Signature(String signature)voidsetBodyHashRequired(boolean bodyHashRequired)voidsetDomain(String domain)voidsetExpiration(int seconds, int minutes, int hours, int days, int months, int years)Calculates an expiration date based on the current time plus the additional time units specified in the method parameters.voidsetExpiration(Date expire)voidsetId(String id)voidsetPrivateKey(PrivateKey privateKey)voidsetQuery(String query)voidsetSelector(String selector)voidsetSignature(byte[] signature)voidsetTimestamp()voidsetTimestamp(String value)voidsign(Map headers, byte[] body, PrivateKey defaultKey)Headers can be a Map<String, Object> or a Map<String, List<Object>>.StringtoString()Generates the Content-Signature value.javax.ws.rs.core.MultivaluedMap<String,String>verify(boolean bodyHashRequired, Map headers, byte[] body, PublicKey key)Headers can be a Map<String, Object> or a Map<String, List<Object>>.javax.ws.rs.core.MultivaluedMap<String,String>verify(Map headers, byte[] body, PublicKey key)
-
-
-
Field Detail
-
DKIM_SIGNATURE
public static final String DKIM_SIGNATURE
- See Also:
- Constant Field Values
-
TIMESTAMP
public static final String TIMESTAMP
- See Also:
- Constant Field Values
-
DOMAIN
public static final String DOMAIN
- See Also:
- Constant Field Values
-
EXPIRATION
public static final String EXPIRATION
- See Also:
- Constant Field Values
-
ALGORITHM
public static final String ALGORITHM
- See Also:
- Constant Field Values
-
SIGNATURE
public static final String SIGNATURE
- See Also:
- Constant Field Values
-
HEADERS
public static final String HEADERS
- See Also:
- Constant Field Values
-
IDENTITY
public static final String IDENTITY
- See Also:
- Constant Field Values
-
VERSION
public static final String VERSION
- See Also:
- Constant Field Values
-
BODY_HASH
public static final String BODY_HASH
- See Also:
- Constant Field Values
-
CANONICALIZATION
public static final String CANONICALIZATION
- See Also:
- Constant Field Values
-
QUERY
public static final String QUERY
- See Also:
- Constant Field Values
-
SELECTOR
public static final String SELECTOR
- See Also:
- Constant Field Values
-
LENGTH
public static final String LENGTH
- See Also:
- Constant Field Values
-
DEFAULT_SIGNER
public static String DEFAULT_SIGNER
This is settable
-
SHA256WITH_RSA
public static final String SHA256WITH_RSA
- See Also:
- Constant Field Values
-
DEFAULT_ALGORITHM
public static String DEFAULT_ALGORITHM
This is settable
-
privateKey
protected PrivateKey privateKey
-
signature
protected byte[] signature
-
headerValue
protected String headerValue
-
bodyHashRequired
protected boolean bodyHashRequired
-
-
Method Detail
-
extractAttributes
protected void extractAttributes()
-
toString
public String toString()
Generates the Content-Signature value.
-
isBodyHashRequired
public boolean isBodyHashRequired()
Whether or not to add a body hash to signature.- Returns:
- body hash required
-
setBodyHashRequired
public void setBodyHashRequired(boolean bodyHashRequired)
-
addHeader
public void addHeader(String headerName)
Add a reference to a header within the signature calculation.- Parameters:
headerName- header name
-
setAttribute
public void setAttribute(String name, String value)
- Parameters:
name- attribute namevalue- if null, remove attribute
-
setAlgorithm
public void setAlgorithm(String value)
Default value is SHA256withRSA, see Javadoc on java.security.Signature for other supported values.- Parameters:
value- if null, remove attribute
-
setTimestamp
public void setTimestamp(String value)
-
setTimestamp
public void setTimestamp()
-
setSelector
public void setSelector(String selector)
-
getSelector
public String getSelector()
-
getQuery
public String getQuery()
-
setQuery
public void setQuery(String query)
-
setDomain
public void setDomain(String domain)
-
getDomain
public String getDomain()
-
setId
public void setId(String id)
- Parameters:
id- id
-
setExpiration
public void setExpiration(Date expire)
-
setExpiration
public void setExpiration(int seconds, int minutes, int hours, int days, int months, int years)Calculates an expiration date based on the current time plus the additional time units specified in the method parameters.- Parameters:
seconds- number of secondsminutes- number of minuteshours- number of hoursdays- number of daysmonths- number of monthsyears- number of years
-
isExpired
public boolean isExpired()
Return false if true current time. If expiration isn't set, then just return false. Returns false otherwise.- Returns:
- true if expired, false otherwise or when expiration attribute is not set
-
isStale
public boolean isStale(int seconds, int minutes, int hours, int days, int months, int years)Returns false if timestamp does not exist or if the current time is greater than timestamp + variables.- Parameters:
seconds- number of secondsminutes- number of minuteshours- number of hoursdays- number of daysmonths- number of monthsyears- number of years- Returns:
- true if stale or timestamp attribute is not set
-
getId
public String getId()
-
getAlgorithm
public String getAlgorithm()
-
getBased64Signature
public String getBased64Signature()
-
setBase64Signature
public void setBase64Signature(String signature)
-
getSignature
public byte[] getSignature()
-
setSignature
public void setSignature(byte[] signature)
-
getPrivateKey
public PrivateKey getPrivateKey()
Private key to use to sign the message. Can be null. If so, system will try to figure out the signer based on a default value, or the current user principal.- Returns:
PrivateKey
-
setPrivateKey
public void setPrivateKey(PrivateKey privateKey)
-
sign
public void sign(Map headers, byte[] body, PrivateKey defaultKey) throws SignatureException
Headers can be a Map<String, Object> or a Map<String, List<Object>>. This gives some compatibility with JAX-RS's MultivaluedMap. If a map of lists, every value of each header duplicate will be added.- Parameters:
headers- headers mapbody- if null, bh field will not be set or provideddefaultKey- will be used if privateKey is null- Throws:
SignatureException- if security exception occurred
-
verify
public javax.ws.rs.core.MultivaluedMap<String,String> verify(Map headers, byte[] body, PublicKey key) throws SignatureException
- Throws:
SignatureException
-
verify
public javax.ws.rs.core.MultivaluedMap<String,String> verify(boolean bodyHashRequired, Map headers, byte[] body, PublicKey key) throws SignatureException
Headers can be a Map<String, Object> or a Map<String, List<Object>>. This gives some compatibility with JAX-RS's MultivaluedMap. If a map of lists, every value of each header duplicate will be added.- Parameters:
bodyHashRequired- body hash requiredheaders- headers mapbody- bodykey- public key- Returns:
- map of verified headers and their values
- Throws:
SignatureException- signature exception
-
-