Class DKIMSignature
java.lang.Object
org.jboss.resteasy.security.doseta.DKIMSignature
One single signature within a DKIM-Signature header
- Version:
- $Revision: 1 $
- Author:
- Bill Burke
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringprotected booleanstatic final Stringstatic StringThis is settablestatic StringThis is settablestatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected Stringstatic final Stringstatic final Stringprotected PrivateKeystatic final Stringstatic final Stringstatic final Stringprotected byte[]static final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd a reference to a header within the signature calculation.protected voidgetId()Private key to use to sign the message.getQuery()byte[]booleanWhether or not to add a body hash to signature.booleanReturn 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) voidvoidsetExpiration(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) voidvoidsetPrivateKey(PrivateKey privateKey) voidvoidsetSelector(String selector) voidsetSignature(byte[] signature) voidvoidsetTimestamp(String value) voidsign(Map headers, byte[] body, PrivateKey defaultKey) Headers can be a Map<String, Object> or a Map<String, List<Object>>.toString()Generates the Content-Signature value.Headers can be a Map<String, Object> or a Map<String, List<Object>>.
-
Field Details
-
DKIM_SIGNATURE
- See Also:
-
TIMESTAMP
- See Also:
-
DOMAIN
- See Also:
-
EXPIRATION
- See Also:
-
ALGORITHM
- See Also:
-
SIGNATURE
- See Also:
-
HEADERS
- See Also:
-
IDENTITY
- See Also:
-
VERSION
- See Also:
-
BODY_HASH
- See Also:
-
CANONICALIZATION
- See Also:
-
QUERY
- See Also:
-
SELECTOR
- See Also:
-
LENGTH
- See Also:
-
DEFAULT_SIGNER
This is settable -
SHA256WITH_RSA
- See Also:
-
DEFAULT_ALGORITHM
This is settable -
privateKey
-
attributes
-
headers
-
signature
protected byte[] signature -
headerValue
-
bodyHashRequired
protected boolean bodyHashRequired
-
-
Constructor Details
-
DKIMSignature
public DKIMSignature() -
DKIMSignature
-
DKIMSignature
-
-
Method Details
-
extractAttributes
protected void extractAttributes() -
getHeaderList
-
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
Add a reference to a header within the signature calculation.- Parameters:
headerName- header name
-
setAttribute
- Parameters:
name- attribute namevalue- if null, remove attribute
-
setAlgorithm
Default value is SHA256withRSA, see Javadoc on java.security.Signature for other supported values.- Parameters:
value- if null, remove attribute
-
setTimestamp
-
setTimestamp
public void setTimestamp() -
setSelector
-
getSelector
-
getQuery
-
setQuery
-
setDomain
-
getDomain
-
setId
- Parameters:
id- id
-
setExpiration
-
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
-
getAlgorithm
-
getAttributes
-
getBased64Signature
-
setBase64Signature
-
getSignature
public byte[] getSignature() -
setSignature
public void setSignature(byte[] signature) -
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
-
sign
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 jakarta.ws.rs.core.MultivaluedMap<String,String> verify(Map headers, byte[] body, PublicKey key) throws SignatureException - Throws:
SignatureException
-
verify
public jakarta.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
-