Class UsernameTokenUtil

java.lang.Object
org.apache.wss4j.common.util.UsernameTokenUtil

public final class UsernameTokenUtil extends Object
  • Field Details

    • DEFAULT_ITERATION

      public static final int DEFAULT_ITERATION
      See Also:
    • MAX_ITERATION

      public static final int MAX_ITERATION
      The maximum number of hash rounds that an inbound UsernameToken may request through its wsse11:Iteration element. The Iteration value is attacker-controlled message content and the key derivation below performs one SHA-1 round per iteration, so leaving it unbounded lets a small request buy an arbitrary amount of CPU time on the receiver.
      See Also:
  • Method Details

    • generateDerivedKey

      public static byte[] generateDerivedKey(byte[] password, byte[] salt, int iteration) throws WSSecurityException
      This static method generates a derived key as defined in WSS Username Token Profile.
      Parameters:
      password - The password to include in the key generation
      salt - The Salt value
      iteration - The Iteration value. If zero (0) is given the method uses the default value
      Returns:
      Returns the derived key a byte array
      Throws:
      WSSecurityException
    • generateDerivedKey

      public static byte[] generateDerivedKey(String password, byte[] salt, int iteration) throws WSSecurityException
      This static method generates a derived key as defined in WSS Username Token Profile.
      Parameters:
      password - The password to include in the key generation
      salt - The Salt value
      iteration - The Iteration value. If zero (0) is given the method uses the default value
      Returns:
      Returns the derived key a byte array
      Throws:
      WSSecurityException
    • generateSalt

      public static byte[] generateSalt(boolean useForMac)
      This static method generates a 128 bit salt value as defined in WSS Username Token Profile.
      Parameters:
      useForMac - If true define the Salt for use in a MAC
      Returns:
      Returns the 128 bit salt value as byte array
    • generateNonce

      public static byte[] generateNonce(int length) throws WSSecurityException
      Generate a nonce of the given length using a secure random algorithm. The SecureRandom instance that backs this method is cached for efficiency.
      Returns:
      a nonce of the given length
      Throws:
      WSSecurityException
    • doPasswordDigest

      public static String doPasswordDigest(byte[] nonce, String created, String password) throws WSSecurityException
      Throws:
      WSSecurityException
    • doPasswordDigest

      public static String doPasswordDigest(byte[] nonce, String created, byte[] password) throws WSSecurityException
      Throws:
      WSSecurityException
    • doRawPasswordDigest

      public static byte[] doRawPasswordDigest(byte[] nonce, String created, byte[] password) throws WSSecurityException
      Throws:
      WSSecurityException
    • getRawPassword

      public static String getRawPassword(CallbackHandler callbackHandler, String username, String password, String passwordType) throws WSSecurityException
      Get the raw (plain text) password used to compute secret key.
      Throws:
      WSSecurityException
    • getCanonicalNonce

      public static String getCanonicalNonce(String nonce) throws WSSecurityException
      Get the canonical form of the given Nonce, for use as a replay cache key. The Nonce is base64, and every other part of the stack decodes it before use, so two Nonces that decode to the same bytes are the same Nonce however they happen to be written. The decoder ignores whitespace and any other character outside the base64 alphabet, and does not reject non-zero unused trailing bits, so one Nonce has many valid encodings. Keying the replay cache on the raw element text would let a replayed message escape detection simply by rewriting its Nonce into an equivalent encoding.
      Parameters:
      nonce - the Nonce exactly as it appeared in the message
      Returns:
      the same Nonce re-encoded in canonical base64
      Throws:
      WSSecurityException - if the Nonce is not valid base64