-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[APPSEC-26] Add Kotlin specification (#1045)
- Loading branch information
1 parent
4fb47c2
commit 6fd8b5b
Showing
2 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== Highlighting | ||
|
||
* Primary location | ||
** javax.crypto.Cipher.init call | ||
* Secondary locations | ||
** javax.crypto.spec.GCMParameterSpec constructor | ||
** nonce variable declaration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,48 @@ | ||
FIXME: add a description | ||
|
||
// If you want to factorize the description uncomment the following line and create the file. | ||
//include::../description.adoc[] | ||
include::../description.adoc[] | ||
|
||
== Noncompliant Code Example | ||
|
||
[source,kotlin] | ||
---- | ||
FIXME | ||
fun encrypt(key: ByteArray, ptxt: ByteArray) { | ||
val nonce: ByteArray = "7cVgr5cbdCZV".toByteArray() // The initialization vector is a static value | ||
val gcmSpec = GCMParameterSpec(128, nonce) // The initialization vector is configured here | ||
val skeySpec = SecretKeySpec(key, "AES") | ||
val cipher: Cipher = Cipher.getInstance("AES/GCM/NoPadding") | ||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, gcmSpec) // Noncompliant | ||
} | ||
---- | ||
|
||
== Compliant Solution | ||
|
||
[source,kotlin] | ||
---- | ||
FIXME | ||
fun encrypt(key: ByteArray, ptxt: ByteArray) { | ||
val random: SecureRandom = SecureRandom() | ||
val nonce: ByteArray = ByteArray(12) | ||
random.nextBytes(nonce) // Random 96 bit IV | ||
val gcmSpec = GCMParameterSpec(128, nonce) | ||
val skeySpec = SecretKeySpec(key, "AES") | ||
val cipher: Cipher = Cipher.getInstance("AES/GCM/NoPadding") | ||
cipher.init(Cipher.ENCRYPT_MODE, skeySpec, gcmSpec) | ||
} | ||
---- | ||
|
||
== See | ||
include::../see.adoc[] | ||
|
||
|
||
ifdef::env-github,rspecator-view[] | ||
|
||
''' | ||
== Implementation Specification | ||
(visible only on this page) | ||
|
||
include::../message.adoc[] | ||
|
||
include::./highlighting.adoc[] | ||
|
||
FIXME: A list of links | ||
endif::env-github,rspecator-view[] |