Class PurposeKeyDerivation

java.lang.Object
com.irurueta.authserver.authorization.infrastructure.keys.PurposeKeyDerivation

@Component public class PurposeKeyDerivation extends Object
Derives, from the key-encryption secret (KeyEncryptionProperties), a distinct salt and key for each purpose other than the encryption of signing keys, so no two uses share a key: a key exposed or misused for one purpose says nothing about the others. The salt of a purpose is the HMAC-SHA256 of the purpose label keyed with the configured salt; its key is derived from the passphrase and that salt with PBKDF2-HMAC-SHA256. The signing-key cipher (AesGcmKeyCipher) keeps using the configured salt itself, so the keys already stored still decrypt.
  • Field Details

    • SALT_ALGORITHM

      private static final String SALT_ALGORITHM
      Algorithm that derives the salt of a purpose.
      See Also:
    • KEY_ALGORITHM

      private static final String KEY_ALGORITHM
      Algorithm that derives the key of a purpose.
      See Also:
    • ITERATIONS

      private static final int ITERATIONS
      PBKDF2 iterations; a key is derived once per purpose, when its bean is created.
      See Also:
    • KEY_BITS

      private static final int KEY_BITS
      Size of a derived key in bits (AES-256 / HMAC-SHA256).
      See Also:
    • properties

      private final KeyEncryptionProperties properties
      The passphrase and the salt of the key-encryption secret.
  • Constructor Details

    • PurposeKeyDerivation

      public PurposeKeyDerivation()
  • Method Details

    • saltFor

      public String saltFor(String purpose)
      Derives the salt of a purpose.
      Parameters:
      purpose - label of the purpose, for example totp-secret.
      Returns:
      the salt, hex encoded, as Encryptors.stronger expects it.
    • keyFor

      public byte[] keyFor(String purpose)
      Derives the key of a purpose.
      Parameters:
      purpose - label of the purpose, for example trusted-device-cookie.
      Returns:
      the 256-bit key.