66 lines
1.5 KiB
Plaintext
66 lines
1.5 KiB
Plaintext
include::../summary.adoc[]
|
|
|
|
== Why is this an issue?
|
|
|
|
include::../rationale.adoc[]
|
|
|
|
include::../impact.adoc[]
|
|
|
|
== How to fix it in Java Cryptography Extension
|
|
|
|
=== Code examples
|
|
|
|
==== Noncompliant code example
|
|
|
|
The derived key is vulnerable because the cost factor (rounds) is too low for the chosen algorithm.
|
|
|
|
[source,kotlin,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
private fun deriveKey(password: String, salt: ByteArray): SecretKey? {
|
|
val keySpec = PBEKeySpec(password.toCharArray(), salt, 120000, 256) // Noncompliant
|
|
val secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA512")
|
|
return secretKeyFactory.generateSecret(keySpec)
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,kotlin,diff-id=1,diff-type=compliant]
|
|
----
|
|
private fun deriveKey(password: String, salt: ByteArray): SecretKey? {
|
|
val keySpec = PBEKeySpec(password.toCharArray(), salt, 210000, 256)
|
|
val secretKeyFactory = SecretKeyFactory.getInstance("PBKDF2withHmacSHA512")
|
|
return secretKeyFactory.generateSecret(keySpec)
|
|
}
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../common/fix/pbkdf2-parameters.adoc[]
|
|
|
|
=== Going the extra mile
|
|
|
|
include::../common/extra-mile/peppering.adoc[]
|
|
|
|
|
|
== Resources
|
|
|
|
=== Documentation
|
|
|
|
* OWASP CheatSheet - https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html[Password Storage Cheat Sheet]
|
|
|
|
include::../common/resources/standards-mobile.adoc[]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
include::highlighting.adoc[]
|
|
|
|
endif::env-github,rspecator-view[]
|
|
|