Loading core/java/android/net/http/X509TrustManagerExtensions.java +25 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ public class X509TrustManagerExtensions { private final X509TrustManager mTrustManager; private final Method mCheckServerTrusted; private final Method mIsUserAddedCertificate; private final Method mIsSameTrustConfiguration; /** * Constructs a new X509TrustManagerExtensions wrapper. Loading @@ -57,6 +58,7 @@ public class X509TrustManagerExtensions { mTrustManager = null; mCheckServerTrusted = null; mIsUserAddedCertificate = null; mIsSameTrustConfiguration = null; return; } // Use duck typing if possible. Loading @@ -80,6 +82,15 @@ public class X509TrustManagerExtensions { throw new IllegalArgumentException( "Required method isUserAddedCertificate(X509Certificate) missing"); } // Get the option isSameTrustConfiguration method. Method isSameTrustConfiguration = null; try { isSameTrustConfiguration = tm.getClass().getMethod("isSameTrustConfiguration", String.class, String.class); } catch (ReflectiveOperationException ignored) { } mIsSameTrustConfiguration = isSameTrustConfiguration; } /** Loading Loading @@ -150,6 +161,19 @@ public class X509TrustManagerExtensions { */ @SystemApi public boolean isSameTrustConfiguration(String hostname1, String hostname2) { if (mIsSameTrustConfiguration == null) { return true; } try { return (Boolean) mIsSameTrustConfiguration.invoke(mTrustManager, hostname1, hostname2); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to call isSameTrustConfiguration", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException("isSameTrustConfiguration failed", e.getCause()); } } } } core/java/android/security/net/config/RootTrustManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -148,4 +148,15 @@ public class RootTrustManager extends X509ExtendedTrustManager { NetworkSecurityConfig config = mConfig.getConfigForHostname(""); return config.getTrustManager().getAcceptedIssuers(); } /** * Returns {@code true} if this trust manager uses the same trust configuration for the provided * hostnames. * * <p>This is required by android.net.http.X509TrustManagerExtensions. */ public boolean isSameTrustConfiguration(String hostname1, String hostname2) { return mConfig.getConfigForHostname(hostname1) .equals(mConfig.getConfigForHostname(hostname2)); } } Loading
core/java/android/net/http/X509TrustManagerExtensions.java +25 −1 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ public class X509TrustManagerExtensions { private final X509TrustManager mTrustManager; private final Method mCheckServerTrusted; private final Method mIsUserAddedCertificate; private final Method mIsSameTrustConfiguration; /** * Constructs a new X509TrustManagerExtensions wrapper. Loading @@ -57,6 +58,7 @@ public class X509TrustManagerExtensions { mTrustManager = null; mCheckServerTrusted = null; mIsUserAddedCertificate = null; mIsSameTrustConfiguration = null; return; } // Use duck typing if possible. Loading @@ -80,6 +82,15 @@ public class X509TrustManagerExtensions { throw new IllegalArgumentException( "Required method isUserAddedCertificate(X509Certificate) missing"); } // Get the option isSameTrustConfiguration method. Method isSameTrustConfiguration = null; try { isSameTrustConfiguration = tm.getClass().getMethod("isSameTrustConfiguration", String.class, String.class); } catch (ReflectiveOperationException ignored) { } mIsSameTrustConfiguration = isSameTrustConfiguration; } /** Loading Loading @@ -150,6 +161,19 @@ public class X509TrustManagerExtensions { */ @SystemApi public boolean isSameTrustConfiguration(String hostname1, String hostname2) { if (mIsSameTrustConfiguration == null) { return true; } try { return (Boolean) mIsSameTrustConfiguration.invoke(mTrustManager, hostname1, hostname2); } catch (IllegalAccessException e) { throw new RuntimeException("Failed to call isSameTrustConfiguration", e); } catch (InvocationTargetException e) { if (e.getCause() instanceof RuntimeException) { throw (RuntimeException) e.getCause(); } else { throw new RuntimeException("isSameTrustConfiguration failed", e.getCause()); } } } }
core/java/android/security/net/config/RootTrustManager.java +11 −0 Original line number Diff line number Diff line Loading @@ -148,4 +148,15 @@ public class RootTrustManager extends X509ExtendedTrustManager { NetworkSecurityConfig config = mConfig.getConfigForHostname(""); return config.getTrustManager().getAcceptedIssuers(); } /** * Returns {@code true} if this trust manager uses the same trust configuration for the provided * hostnames. * * <p>This is required by android.net.http.X509TrustManagerExtensions. */ public boolean isSameTrustConfiguration(String hostname1, String hostname2) { return mConfig.getConfigForHostname(hostname1) .equals(mConfig.getConfigForHostname(hostname2)); } }