[KYUUBI #6408] Change to Base64 RFC4648 for handle guid and credential

# 🔍 Description

`Base64.getMimeEncoder`(RFC2045) might generate newline when encoded chars exceed 76, so I changed it to `Base64.getEncoder`(RFC4648).
## Types of changes 🔖

- [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 <chengpan@apache.org>
This commit is contained in:
wforget 2024-05-22 17:54:58 +08:00 committed by Cheng Pan
parent 5b592d07ca
commit cb91dfaa4f
No known key found for this signature in database
GPG Key ID: 8001952629BCC75D
5 changed files with 9 additions and 9 deletions

View File

@ -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 = {

View File

@ -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()

View File

@ -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

View File

@ -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 =

View File

@ -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)