Package org.jboss.resteasy.security.doseta

## 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 String` | `ALGORITHM` |
    `protected Map<String,​String>` | `attributes` |
    `static String` | `BODY_HASH` |
    `protected boolean` | `bodyHashRequired` |
    `static String` | `CANONICALIZATION` |
    `static String` | `DEFAULT_ALGORITHM` | This is settable
    `static String` | `DEFAULT_SIGNER` | This is settable
    `static String` | `DKIM_SIGNATURE` |
    `static String` | `DOMAIN` |
    `static String` | `EXPIRATION` |
    `protected List<String>` | `headers` |
    `static String` | `HEADERS` |
    `protected String` | `headerValue` |
    `static String` | `IDENTITY` |
    `static String` | `LENGTH` |
    `protected PrivateKey` | `privateKey` |
    `static String` | `QUERY` |
    `static String` | `SELECTOR` |
    `static String` | `SHA256WITH_RSA` |
    `protected byte[]` | `signature` |
    `static String` | `SIGNATURE` |
    `static String` | `TIMESTAMP` |
    `static String` | `VERSION` |

  - ### 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
    --- | --- | ---
    `void` | `addHeader​(String headerName)` | Add a reference to a header within the signature calculation.
    `protected void` | `extractAttributes()` |
    `String` | `getAlgorithm()` |
    `Map<String,​String>` | `getAttributes()` |
    `String` | `getBased64Signature()` |
    `String` | `getDomain()` |
    `List<String>` | `getHeaderList()` |
    `String` | `getId()` |
    `PrivateKey` | `getPrivateKey()` | Private key to use to sign the message.
    `String` | `getQuery()` |
    `String` | `getSelector()` |
    `byte[]` | `getSignature()` |
    `boolean` | `isBodyHashRequired()` | Whether or not to add a body hash to signature.
    `boolean` | `isExpired()` | 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` | `setDomain​(String domain)` |
    `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` | `setId​(String id)` |
    `void` | `setPrivateKey​(PrivateKey privateKey)` |
    `void` | `setQuery​(String query)` |
    `void` | `setSelector​(String selector)` |
    `void` | `setSignature​(byte[] signature)` |
    `void` | `setTimestamp()` |
    `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>>.
    `String` | `toString()` | 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)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### 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

    - #### attributes

          protected Map<String,​String> attributes

    - #### headers

          protected List<String> headers

    - #### signature

          protected byte[] signature

    - #### headerValue

          protected String headerValue

    - #### bodyHashRequired

          protected boolean bodyHashRequired

  - ### Constructor Detail

    - #### DKIMSignature

          public DKIMSignature()

    - #### DKIMSignature

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

    - #### DKIMSignature

          public DKIMSignature​(String headerValue)

  - ### Method Detail

    - #### 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 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 required
        `headers` - headers map
        `body` - body
        `key` - public key
      Returns:
        map of verified headers and their values
      Throws:
        `SignatureException` - signature exception