aajisaka commented on code in PR #7374:
URL: https://github.com/apache/kyuubi/pull/7374#discussion_r3043385697
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala:
##########
@@ -69,11 +63,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)
+ InternalSecurityAccessor.random.nextBytes(nonce)
+ encryptor.init(Cipher.ENCRYPT_MODE, secretKeySpec, new
IvParameterSpec(nonce))
+ byteArrayToHexString(nonce ++ encryptor.doFinal(value.getBytes))
}
Review Comment:
Fixed in
https://github.com/apache/kyuubi/pull/7374/commits/abfe628643535cf0ff011b104389de43aa9c89b1
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala:
##########
@@ -69,11 +63,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)
+ InternalSecurityAccessor.random.nextBytes(nonce)
+ encryptor.init(Cipher.ENCRYPT_MODE, secretKeySpec, new
IvParameterSpec(nonce))
+ byteArrayToHexString(nonce ++ encryptor.doFinal(value.getBytes))
}
private[authentication] def decrypt(value: String): String = synchronized {
- new String(decryptor.doFinal(hexStringToByteArray(value)))
+ val bytes = hexStringToByteArray(value)
+ val nonce = bytes.take(cryptoIvLength)
+ decryptor.init(Cipher.DECRYPT_MODE, secretKeySpec, new
IvParameterSpec(nonce))
+ new String(decryptor.doFinal(bytes.drop(cryptoIvLength)))
}
Review Comment:
Fixed in
https://github.com/apache/kyuubi/pull/7374/commits/abfe628643535cf0ff011b104389de43aa9c89b1
##########
kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/InternalSecurityAccessor.scala:
##########
@@ -34,21 +35,14 @@ class InternalSecurityAccessor(conf: KyuubiConf, val
isServer: Boolean) {
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)
Review Comment:
Fixed in
https://github.com/apache/kyuubi/pull/7374/commits/abfe628643535cf0ff011b104389de43aa9c89b1
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]