-
Notifications
You must be signed in to change notification settings - Fork 993
Fix static zero IV in InternalSecurityAccessor #7374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||||||||||
|
|
||||||||||||||
| package org.apache.kyuubi.service.authentication | ||||||||||||||
|
|
||||||||||||||
| import java.security.SecureRandom | ||||||||||||||
| import javax.crypto.Cipher | ||||||||||||||
| import javax.crypto.spec.{IvParameterSpec, SecretKeySpec} | ||||||||||||||
|
|
||||||||||||||
|
|
@@ -32,23 +33,17 @@ class InternalSecurityAccessor(conf: KyuubiConf, val isServer: Boolean) { | |||||||||||||
| val cryptoKeyAlgorithm = conf.get(ENGINE_SECURITY_CRYPTO_KEY_ALGORITHM) | ||||||||||||||
| val cryptoCipher = conf.get(ENGINE_SECURITY_CRYPTO_CIPHER_TRANSFORMATION) | ||||||||||||||
|
|
||||||||||||||
| private val random = new SecureRandom() | ||||||||||||||
| private val tokenMaxLifeTime: Long = conf.get(ENGINE_SECURITY_TOKEN_MAX_LIFETIME) | ||||||||||||||
| private val provider: EngineSecuritySecretProvider = EngineSecuritySecretProvider.create(conf) | ||||||||||||||
| private val (encryptor, decryptor) = | ||||||||||||||
| private val (secretKeySpec, encryptor, decryptor) = | ||||||||||||||
| initializeForAuth(cryptoCipher, normalizeSecret(provider.getSecret())) | ||||||||||||||
|
|
||||||||||||||
| private def initializeForAuth(cipher: String, secret: String): (Cipher, Cipher) = { | ||||||||||||||
| private def initializeForAuth(cipher: String, secret: String): (SecretKeySpec, Cipher, Cipher) = { | ||||||||||||||
| val secretKeySpec = new SecretKeySpec(secret.getBytes, cryptoKeyAlgorithm) | ||||||||||||||
| val nonce = new Array[Byte](cryptoIvLength) | ||||||||||||||
| val iv = new IvParameterSpec(nonce) | ||||||||||||||
|
|
||||||||||||||
| val _encryptor = Cipher.getInstance(cipher) | ||||||||||||||
| _encryptor.init(Cipher.ENCRYPT_MODE, secretKeySpec, iv) | ||||||||||||||
|
|
||||||||||||||
| val _decryptor = Cipher.getInstance(cipher) | ||||||||||||||
| _decryptor.init(Cipher.DECRYPT_MODE, secretKeySpec, iv) | ||||||||||||||
|
|
||||||||||||||
| (_encryptor, _decryptor) | ||||||||||||||
| (secretKeySpec, _encryptor, _decryptor) | ||||||||||||||
|
Comment on lines
+42
to
+47
|
||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| def issueToken(): String = { | ||||||||||||||
|
|
@@ -69,11 +64,17 @@ class InternalSecurityAccessor(conf: KyuubiConf, val isServer: Boolean) { | |||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| private[authentication] def encrypt(value: String): String = synchronized { | ||||||||||||||
| byteArrayToHexString(encryptor.doFinal(value.getBytes)) | ||||||||||||||
| val nonce = new Array[Byte](cryptoIvLength) | ||||||||||||||
| random.nextBytes(nonce) | ||||||||||||||
| encryptor.init(Cipher.ENCRYPT_MODE, secretKeySpec, new IvParameterSpec(nonce)) | ||||||||||||||
| byteArrayToHexString(nonce ++ encryptor.doFinal(value.getBytes)) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
67
to
72
|
||||||||||||||
|
|
||||||||||||||
| private[authentication] def decrypt(value: String): String = synchronized { | ||||||||||||||
| new String(decryptor.doFinal(hexStringToByteArray(value))) | ||||||||||||||
| val bytes = hexStringToByteArray(value) | ||||||||||||||
|
||||||||||||||
| val bytes = hexStringToByteArray(value) | |
| val bytes = hexStringToByteArray(value) | |
| if (bytes.length <= cryptoIvLength) { | |
| throw new IllegalArgumentException( | |
| "Malformed engine access token: ciphertext is shorter than the IV length") | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in abfe628
Copilot
AI
Apr 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decryption constructs a String with the platform-default charset. To avoid inconsistent behavior across JVM default encodings, decode using an explicit charset (commonly UTF-8 in this codebase; e.g., SignUtils.scala:52,68).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in abfe628
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move it to
object InternalSecurityAccessor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Moved it.