Class DKIMSignature
java.lang.Object
org.jboss.resteasy.security.doseta.DKIMSignature
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
protected boolean
static final String
static String
This is settablestatic String
This is settablestatic final String
static final String
static final String
static final String
protected String
static final String
static final String
protected PrivateKey
static final String
static final String
static final String
protected byte[]
static final String
static final String
static final String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a reference to a header within the signature calculation.protected void
getId()
Private key to use to sign the message.getQuery()
byte[]
boolean
Whether or not to add a body hash to signature.boolean
Return false if true current time.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.void
setAlgorithm
(String value) Default value is SHA256withRSA, see Javadoc on java.security.Signature for other supported values.void
setAttribute
(String name, String value) void
setBase64Signature
(String signature) void
setBodyHashRequired
(boolean bodyHashRequired) void
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.void
setExpiration
(Date expire) void
void
setPrivateKey
(PrivateKey privateKey) void
void
setSelector
(String selector) void
setSignature
(byte[] signature) void
void
setTimestamp
(String value) void
sign
(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
-
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
-
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
-