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 Link icon

  • Constructor Details Link icon

    • DKIMSignature Link icon

      public DKIMSignature()
    • DKIMSignature Link icon

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

      public DKIMSignature(String headerValue)
  • Method Details Link icon

    • extractAttributes Link icon

      protected void extractAttributes()
    • getHeaderList Link icon

      public List<String> getHeaderList()
    • toString Link icon

      public String toString()
      Generates the Content-Signature value.
      Overrides:
      toString in class Object
      Returns:
      header value
    • isBodyHashRequired Link icon

      public boolean isBodyHashRequired()
      Whether or not to add a body hash to signature.
      Returns:
      body hash required
    • setBodyHashRequired Link icon

      public void setBodyHashRequired(boolean bodyHashRequired)
    • addHeader Link icon

      public void addHeader(String headerName)
      Add a reference to a header within the signature calculation.
      Parameters:
      headerName - header name
    • setAttribute Link icon

      public void setAttribute(String name, String value)
      Parameters:
      name - attribute name
      value - if null, remove attribute
    • setAlgorithm Link icon

      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 Link icon

      public void setTimestamp(String value)
    • setTimestamp Link icon

      public void setTimestamp()
    • setSelector Link icon

      public void setSelector(String selector)
    • getSelector Link icon

      public String getSelector()
    • getQuery Link icon

      public String getQuery()
    • setQuery Link icon

      public void setQuery(String query)
    • setDomain Link icon

      public void setDomain(String domain)
    • getDomain Link icon

      public String getDomain()
    • setId Link icon

      public void setId(String id)
      Parameters:
      id - id
    • setExpiration Link icon

      public void setExpiration(Date expire)
    • setExpiration Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      public String getId()
    • getAlgorithm Link icon

      public String getAlgorithm()
    • getAttributes Link icon

      public Map<String,String> getAttributes()
    • getBased64Signature Link icon

      public String getBased64Signature()
    • setBase64Signature Link icon

      public void setBase64Signature(String signature)
    • getSignature Link icon

      public byte[] getSignature()
    • setSignature Link icon

      public void setSignature(byte[] signature)
    • getPrivateKey Link icon

      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 Link icon

      public void setPrivateKey(PrivateKey privateKey)
    • sign Link icon

      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 Link icon

      public jakarta.ws.rs.core.MultivaluedMap<String,String> verify(Map headers, byte[] body, PublicKey key) throws SignatureException
      Throws:
      SignatureException
    • verify Link icon

      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