Class Pbkdf2PasswordHashProvider
java.lang.Object
com.svenruppert.jsentinel.credential.password.pbkdf2.Pbkdf2PasswordHashProvider
- All Implemented Interfaces:
PasswordHashProvider
JDK/JCA-only PBKDF2 password hash provider.
This is the secure core default and must remain JDK-only so that
security-core introduces no runtime dependencies. Modern
memory-hard algorithms (Argon2id, scrypt) live in the optional
security-crypto-bc module that ships in Phase 1b.
Implementation notes:
- The provider never modifies the global JCA provider order.
A specific JCA provider can be pinned through the
jcaProviderNameconstructor argument; the lookup is performed viaSecretKeyFactory.getInstance(String, String)on every call. - Salt is drawn fresh from a caller-supplied
SecureRandomfor everyhash(...)so that two identical passwords never yield identical envelopes (CWE-759 / CWE-760). - The constant-time comparison uses
MessageDigest.isEqual(byte[], byte[]). - Temporary
byte[]arrays holding salt and derived key material are zeroed before the method returns. ThePBEKeySpec.clearPassword()hook is invoked even on failure paths. - The provider returns
ProviderVerificationResult.ProviderErroron JCA-level failures (missing algorithm or provider, invalid key spec) so the surrounding pipeline can keep public messaging generic (CWE-209).
-
Constructor Summary
ConstructorsConstructorDescriptionPbkdf2PasswordHashProvider(PasswordHashCodec codec, SecureRandom random, Optional<String> jcaProviderName) Test/SPI constructor that lets callers inject a deterministicSecureRandom(for known-answer assertions) or pin the JCA provider (for FIPS-mode deployments).Pbkdf2PasswordHashProvider(String jcaProviderName) -
Method Summary
Modifier and TypeMethodDescriptionCanonical algorithm identifier this provider handles by default.hash(char[] password, PasswordHashPolicy policy, Optional<PepperReference> pepper) Derives a fresh hash for the supplied password under the active policy.Logical provider identifier, stable across releases.verify(char[] password, PasswordHashEnvelope envelope, Optional<PepperReference> pepper) Verifies the supplied password against the parsed envelope.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface PasswordHashProvider
resourceEstimate, supportsModifier and TypeMethodDescriptiondefault ResourceEstimateresourceEstimate(Map<String, String> parameters) Optional resource estimate for the supplied parameter map.default booleanReturns whether this provider can serve the given combination.
-
Constructor Details
-
Pbkdf2PasswordHashProvider
public Pbkdf2PasswordHashProvider() -
Pbkdf2PasswordHashProvider
-
Pbkdf2PasswordHashProvider
public Pbkdf2PasswordHashProvider(PasswordHashCodec codec, SecureRandom random, Optional<String> jcaProviderName) Test/SPI constructor that lets callers inject a deterministicSecureRandom(for known-answer assertions) or pin the JCA provider (for FIPS-mode deployments).
-
-
Method Details
-
providerId
Description copied from interface:PasswordHashProviderLogical provider identifier, stable across releases. Stored in the envelope so that verification can resolve the same implementation regardless of the active policy.- Specified by:
providerIdin interfacePasswordHashProvider
-
algorithm
Description copied from interface:PasswordHashProviderCanonical algorithm identifier this provider handles by default.- Specified by:
algorithmin interfacePasswordHashProvider
-
hash
public PasswordHashResult hash(char[] password, PasswordHashPolicy policy, Optional<PepperReference> pepper) Description copied from interface:PasswordHashProviderDerives a fresh hash for the supplied password under the active policy.- Specified by:
hashin interfacePasswordHashProvider- Parameters:
password- caller-owned character array; the provider must not zero or modify itpolicy- active policy from which to read parameterspepper- resolved active pepper key, orOptional.empty()when peppering is off; the provider applies the pepper asHMAC-SHA-256(pepper.key, KDF(password,salt))and writes thepepper.keyIdinto the envelope
-
verify
public ProviderVerificationResult verify(char[] password, PasswordHashEnvelope envelope, Optional<PepperReference> pepper) Description copied from interface:PasswordHashProviderVerifies the supplied password against the parsed envelope.Implementations must use a constant-time comparison and must never throw on a genuine mismatch. Provider-level failures (missing JCA service, unsupported parameter combination) collapse onto
ProviderVerificationResult.ProviderErrorso the pipeline can keep public messaging generic.- Specified by:
verifyin interfacePasswordHashProvider- Parameters:
pepper- resolved pepper key matchingenvelope.pepperKeyId(), orOptional.empty()when the envelope has no pepper field
-