Skip to content

Commit 19d2366

Browse files
committed
Fix for Bug#118389 (Bug#38044940), OCI ephemeral keys not working after change in OCI CLI.
Change-Id: Ic9110703d12b106816541130dd57f10b908fb48c
1 parent 1cf0719 commit 19d2366

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
Version 9.4.0
55

6+
- Fix for Bug#118389 (Bug#38044940), OCI ephemeral keys not working after change in OCI CLI.
7+
68
- Fix for Bug#22473405, GETOBJECT(STRING , CLASS<T>) METHOD RETURNS ERROR FOR POOLED CONNECTION.
79

810
- WL#17009, Upgrade 3rd party libraries and tools.

src/main/core-impl/java/com/mysql/cj/protocol/ExportControlled.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
package com.mysql.cj.protocol;
2222

23+
import java.io.BufferedReader;
2324
import java.io.IOException;
2425
import java.io.InputStream;
26+
import java.io.StringReader;
2527
import java.net.MalformedURLException;
2628
import java.net.Socket;
2729
import java.net.URL;
@@ -276,14 +278,39 @@ public static RSAPrivateKey decodeRSAPrivateKey(String key) throws RSAException
276278
throw ExceptionFactory.createException(RSAException.class, "Key parameter is null");
277279
}
278280

279-
String keyData = key.replace("-----BEGIN PRIVATE KEY-----", "").replaceAll("\\R", "").replace("-----END PRIVATE KEY-----", "");
280-
byte[] decodedKeyData = Base64.getDecoder().decode(keyData);
281+
StringBuilder keyData = new StringBuilder();
282+
283+
try {
284+
BufferedReader br = new BufferedReader(new StringReader(key));
285+
String line;
286+
boolean insideKey = false;
287+
while ((line = br.readLine()) != null) {
288+
line = line.trim();
289+
if (line.equals("-----BEGIN PRIVATE KEY-----")) {
290+
insideKey = true;
291+
continue;
292+
}
293+
if (line.equals("-----END PRIVATE KEY-----")) {
294+
break;
295+
}
296+
if (insideKey) {
297+
keyData.append(line);
298+
}
299+
}
300+
} catch (IOException e) {
301+
}
302+
303+
if (keyData.length() == 0) {
304+
throw new IllegalArgumentException("No valid unencrypted PKCS#8 key block found");
305+
}
306+
307+
byte[] decodedKeyData = Base64.getDecoder().decode(keyData.toString());
281308

282309
try {
283310
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
284311
return (RSAPrivateKey) keyFactory.generatePrivate(new PKCS8EncodedKeySpec(decodedKeyData));
285312
} catch (NoSuchAlgorithmException | InvalidKeySpecException e) {
286-
throw ExceptionFactory.createException(RSAException.class, "Unable to decode private key", e);
313+
throw ExceptionFactory.createException(RSAException.class, "Unable to decode PKCS#8 private key", e);
287314
}
288315
}
289316

0 commit comments

Comments
 (0)