Package tigase.form

Class SignatureCalculator

java.lang.Object
tigase.form.SignatureCalculator

public class SignatureCalculator extends Object
  • Field Details

  • Constructor Details

    • SignatureCalculator

      public SignatureCalculator()
    • SignatureCalculator

      public SignatureCalculator(String oauthConsumerKey, String oauthConsumerSecret)
    • SignatureCalculator

      public SignatureCalculator(String oauthToken, String oauthTokenSecret, String oauthConsumerKey, String oauthConsumerSecret)
  • Method Details

    • escape

      protected static String escape(String s)
    • hmac

      protected static byte[] hmac(SecretKey key, byte[] data) throws NoSuchAlgorithmException, InvalidKeyException
      Throws:
      NoSuchAlgorithmException
      InvalidKeyException
    • addEmptyFields

      public void addEmptyFields(Form form)
    • calculateSignature

      public String calculateSignature(JID to, Form form) throws InvalidKeyException, NoSuchAlgorithmException
      Calculate signature of given form. Form will not be changed.
      Parameters:
      to - the full destination address, including resource, if any.
      form - form to sign.
      Returns:
      Signature of form.
      Throws:
      InvalidKeyException
      NoSuchAlgorithmException
    • getOauthConsumerKey

      public String getOauthConsumerKey()
      Returns:
      the oauthConsumerKey
    • setOauthConsumerKey

      public void setOauthConsumerKey(String oauthConsumerKey)
      Parameters:
      oauthConsumerKey - the oauthConsumerKey to set
    • getOauthConsumerSecret

      public String getOauthConsumerSecret()
      Returns:
      the oauthConsumerSecret
    • setOauthConsumerSecret

      public void setOauthConsumerSecret(String oauthConsumerSecret)
      Parameters:
      oauthConsumerSecret - the oauthConsumerSecret to set
    • getOauthToken

      public String getOauthToken()
      Returns:
      the oauthToken
    • setOauthToken

      public void setOauthToken(String oauthToken)
      Parameters:
      oauthToken - the oauthToken to set
    • getOauthTokenSecret

      public String getOauthTokenSecret()
      Returns:
      the oauthTokenSecret
    • setOauthTokenSecret

      public void setOauthTokenSecret(String oauthTokenSecret)
      Parameters:
      oauthTokenSecret - the oauthTokenSecret to set
    • isMethodSupported

      public boolean isMethodSupported(String fOauthSignatureMethod)
    • sign

      public void sign(JID to, Form form) throws InvalidKeyException, NoSuchAlgorithmException
      Sign given form with current time. Signature will be added to form.
      Parameters:
      to - the full destination address, including resource, if any.
      form - form to sign.
      Throws:
      InvalidKeyException
      NoSuchAlgorithmException
    • sign

      public void sign(JID to, String nonce, long timestamp, Form form) throws InvalidKeyException, NoSuchAlgorithmException
      Sign given Form. Signature will be added to form.
      Parameters:
      to - the full destination address, including resource, if any.
      nonce - A nonce value that the client has to set. Can be a random alphanumerical string.
      timestamp - Number of seconds since 1st of January 1970, 00:00:00 GMT. The client has to set this at the time of signature.
      form - form to sign.
      Throws:
      InvalidKeyException
      NoSuchAlgorithmException
    • h

      protected byte[] h(byte[] data) throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException
    • key

      protected SecretKey key(byte[] key)
    • randomString

      protected String randomString()