From cb91dfaa4f8f1024beea2f90823b18073ead8c0d Mon Sep 17 00:00:00 2001 From: wforget <643348094@qq.com> Date: Wed, 22 May 2024 17:54:58 +0800 Subject: [PATCH] [KYUUBI #6408] Change to Base64 RFC4648 for handle guid and credential MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # :mag: Description `Base64.getMimeEncoder`(RFC2045) might generate newline when encoded chars exceed 76, so I changed it to `Base64.getEncoder`(RFC4648). ## Types of changes :bookmark: - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan ๐Ÿงช Use the changed BeeLine to connect to Kyuubi Server 1.9.0, everything goes well. ``` $ bin/beeline -u 'jdbc:kyuubi://0.0.0.0:10009/' ... Connected to: Spark SQL (version 3.4.1) Driver: Kyuubi Project Hive JDBC Client (version 1.10.0-SNAPSHOT) Beeline version 1.10.0-SNAPSHOT by Apache Kyuubi 0: jdbc:kyuubi://0.0.0.0:10009/> ``` --- # Checklist ๐Ÿ“ - [X] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6408 from wForget/base64. Closes #6408 a19f6f64f [wforget] change to Base64.getEncoder/getDecoder 7052a9346 [wforget] change to Base64.getEncoder/getDecoder 1b94ad991 [wforget] Change to Base64 urlEncoder/urlDecoder for handle guid and credential Authored-by: wforget <643348094@qq.com> Signed-off-by: Cheng Pan --- .../service/authentication/HadoopThriftAuthBridgeServer.scala | 2 +- .../main/scala/org/apache/kyuubi/util/KyuubiHadoopUtils.scala | 4 ++-- .../scala/org/apache/kyuubi/operation/TClientTestUtils.scala | 4 ++-- .../java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java | 4 ++-- .../apache/kyuubi/server/KyuubiTBinaryFrontendService.scala | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/HadoopThriftAuthBridgeServer.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/HadoopThriftAuthBridgeServer.scala index 845767c88..565ef0a84 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/HadoopThriftAuthBridgeServer.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/HadoopThriftAuthBridgeServer.scala @@ -196,7 +196,7 @@ object HadoopThriftAuthBridgeServer { def getPasswd(identifier: KyuubiDelegationTokenIdentifier): Array[Char] = { val passwd = secretMgr.retrievePassword(identifier) - Base64.getMimeEncoder.encodeToString(passwd).toCharArray + Base64.getEncoder.encodeToString(passwd).toCharArray } override def handle(callbacks: Array[Callback]): Unit = { diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiHadoopUtils.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiHadoopUtils.scala index ad083f173..a3047d0f4 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiHadoopUtils.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/util/KyuubiHadoopUtils.scala @@ -60,11 +60,11 @@ object KyuubiHadoopUtils extends Logging { val byteStream = new ByteArrayOutputStream creds.writeTokenStorageToStream(new DataOutputStream(byteStream)) - Base64.getMimeEncoder.encodeToString(byteStream.toByteArray) + Base64.getEncoder.encodeToString(byteStream.toByteArray) } def decodeCredentials(newValue: String): Credentials = { - val decoded = Base64.getMimeDecoder.decode(newValue) + val decoded = Base64.getDecoder.decode(newValue) val byteStream = new ByteArrayInputStream(decoded) val creds = new Credentials() diff --git a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/TClientTestUtils.scala b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/TClientTestUtils.scala index 7d2d69464..e5822277e 100644 --- a/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/TClientTestUtils.scala +++ b/kyuubi-common/src/test/scala/org/apache/kyuubi/operation/TClientTestUtils.scala @@ -127,8 +127,8 @@ object TClientTestUtils extends Logging { val launchOpHandleOpt = if (guid != null && secret != null) { val launchHandleId = new THandleIdentifier( - ByteBuffer.wrap(Base64.getMimeDecoder.decode(guid)), - ByteBuffer.wrap(Base64.getMimeDecoder.decode(secret))) + ByteBuffer.wrap(Base64.getDecoder.decode(guid)), + ByteBuffer.wrap(Base64.getDecoder.decode(secret))) Some(new TOperationHandle(launchHandleId, TOperationType.UNKNOWN, false)) } else None diff --git a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java index 87872581c..8b6c8f50d 100644 --- a/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java +++ b/kyuubi-hive-jdbc/src/main/java/org/apache/kyuubi/jdbc/hive/KyuubiConnection.java @@ -797,8 +797,8 @@ public class KyuubiConnection implements SQLConnection, KyuubiLoggable { if (launchEngineOpHandleGuid != null && launchEngineOpHandleSecret != null) { try { - byte[] guidBytes = Base64.getMimeDecoder().decode(launchEngineOpHandleGuid); - byte[] secretBytes = Base64.getMimeDecoder().decode(launchEngineOpHandleSecret); + byte[] guidBytes = Base64.getDecoder().decode(launchEngineOpHandleGuid); + byte[] secretBytes = Base64.getDecoder().decode(launchEngineOpHandleSecret); THandleIdentifier handleIdentifier = new THandleIdentifier(ByteBuffer.wrap(guidBytes), ByteBuffer.wrap(secretBytes)); launchEngineOpHandle = diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTBinaryFrontendService.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTBinaryFrontendService.scala index f95ea5947..278aa67fe 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTBinaryFrontendService.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/server/KyuubiTBinaryFrontendService.scala @@ -90,10 +90,10 @@ final class KyuubiTBinaryFrontendService( val opHandleIdentifier = Handle.toTHandleIdentifier(launchEngineOp.getHandle.identifier) respConfiguration.put( KYUUBI_SESSION_ENGINE_LAUNCH_HANDLE_GUID, - Base64.getMimeEncoder.encodeToString(opHandleIdentifier.getGuid)) + Base64.getEncoder.encodeToString(opHandleIdentifier.getGuid)) respConfiguration.put( KYUUBI_SESSION_ENGINE_LAUNCH_HANDLE_SECRET, - Base64.getMimeEncoder.encodeToString(opHandleIdentifier.getSecret)) + Base64.getEncoder.encodeToString(opHandleIdentifier.getSecret)) respConfiguration.put(KYUUBI_SESSION_ENGINE_LAUNCH_SUPPORT_RESULT, true.toString)