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 Details

  • Constructor Details

    • DKIMSignature

      public DKIMSignature()
    • DKIMSignature

      public DKIMSignature(Map<String,String> attrs)
    • DKIMSignature

      public DKIMSignature(String headerValue)
  • Method Details

    • extractAttributes

      protected void extractAttributes()
    • getHeaderList

      public List<String> getHeaderList()
    • toString

      public String toString()
      Generates the Content-Signature value.
      Overrides:
      toString in class Object
      Returns:
      header 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 name
      value - 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 seconds
      minutes - number of minutes
      hours - number of hours
      days - number of days
      months - number of months
      years - 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 seconds
      minutes - number of minutes
      hours - number of hours
      days - number of days
      months - number of months
      years - number of years
      Returns:
      true if stale or timestamp attribute is not set
    • getId

      public String getId()
    • getAlgorithm

      public String getAlgorithm()
    • getAttributes

      public Map<String,String> getAttributes()
    • 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 map
      body - if null, bh field will not be set or provided
      defaultKey - 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 required
      headers - headers map
      body - body
      key - public key
      Returns:
      map of verified headers and their values
      Throws:
      SignatureException - signature exception