Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exception handling in TlsUtil#decodePem #6034

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}