Skip to content

Commit

Permalink
Remove exception handling in TlsUtil#decodePem (#6034)
Browse files Browse the repository at this point in the history
  • Loading branch information
jack-berg authored Nov 30, 2023
1 parent 14eaa4c commit 40325e5
Showing 1 changed file with 1 addition and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509KeyManager;
import javax.net.ssl.X509TrustManager;
import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;

/**
* Utilities for working with TLS.
Expand Down Expand Up @@ -142,9 +141,6 @@ public static X509TrustManager trustManager(byte[] trustedCertificatesPem) throw
}
}

// We catch linkage error to provide a better exception message on Android.
// https://github.com/open-telemetry/opentelemetry-java/issues/4533
@IgnoreJRERequirement
// Visible for testing
static byte[] decodePem(byte[] pem) {
String pemStr = new String(pem, StandardCharsets.UTF_8).trim();
Expand All @@ -157,12 +153,6 @@ static byte[] decodePem(byte[] pem) {
pemStr.substring(PEM_KEY_HEADER.length(), pemStr.length() - PEM_KEY_FOOTER.length());
String content = contentWithNewLines.replaceAll("\\s", "");

try {
return Base64.getDecoder().decode(content);
} catch (LinkageError unused) {
throw new IllegalArgumentException(
"PEM private keys are currently not supported on Android. "
+ "You may try a key encoded as DER.");
}
return Base64.getDecoder().decode(content);
}
}

0 comments on commit 40325e5

Please sign in to comment.