You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by mm...@apache.org on 2020/04/08 16:07:15 UTC

[pulsar] branch master updated: More accurately load the private key from PEM file (#6690) (#6691)

This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 5663acb  More accurately load the private key from PEM file (#6690) (#6691)
5663acb is described below

commit 5663acb68e905ab0634a80748a44c7c9b9c0a8a9
Author: schahal <sa...@gmail.com>
AuthorDate: Wed Apr 8 09:07:02 2020 -0700

    More accurately load the private key from PEM file (#6690) (#6691)
    
    Co-authored-by: Satbir Chahal <sa...@petuum.com>
---
 .../org/apache/pulsar/common/util/SecurityUtility.java    | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/util/SecurityUtility.java b/pulsar-common/src/main/java/org/apache/pulsar/common/util/SecurityUtility.java
index d3a2615..181ddec 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/util/SecurityUtility.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/util/SecurityUtility.java
@@ -257,16 +257,17 @@ public class SecurityUtility {
 
         try (BufferedReader reader = new BufferedReader(new FileReader(keyFilePath))) {
             StringBuilder sb = new StringBuilder();
-            String previousLine = "";
             String currentLine = null;
 
-            // Skip the first line (-----BEGIN RSA PRIVATE KEY-----)
-            reader.readLine();
-            while ((currentLine = reader.readLine()) != null) {
-                sb.append(previousLine);
-                previousLine = currentLine;
+            // Jump to the first line after -----BEGIN [RSA] PRIVATE KEY-----
+            while (!reader.readLine().startsWith("-----BEGIN")) {
+                reader.readLine();
+            }
+
+            // Stop (and skip) at the last line that has, say, -----END [RSA] PRIVATE KEY-----
+            while ((currentLine = reader.readLine()) != null && !currentLine.startsWith("-----END")) {
+                sb.append(currentLine);
             }
-            // Skip the last line (-----END RSA PRIVATE KEY-----)
 
             KeyFactory kf = KeyFactory.getInstance("RSA");
             KeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(sb.toString()));