11package com .datatheorem .android .trustkit .pinning ;
22
33import android .net .http .X509TrustManagerExtensions ;
4+ import android .os .Build ;
45
56import androidx .annotation .NonNull ;
67import androidx .annotation .RequiresApi ;
1920 * <p>This trust manager delegates to the appropriate {@link PinningTrustManager} decided by the
2021 * hostname set by the {@link OkHttp3PinningInterceptor}.</p>
2122 */
22- @ RequiresApi (api = 17 )
2323class OkHttpRootTrustManager implements X509TrustManager {
2424 private final ThreadLocal <String > mServerHostname = new ThreadLocal <>();
2525
@@ -33,14 +33,17 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws
3333 String host = mServerHostname .get ();
3434 DomainPinningPolicy serverConfig =
3535 TrustKit .getInstance ().getConfiguration ().getPolicyForHostname (host );
36- //This check is needed for compatibility with the Platform default's implementation of
36+ X509TrustManager trustManager = TrustKit .getInstance ().getTrustManager (host );
37+
38+ //The first check is needed for compatibility with the Platform default's implementation of
3739 //the Trust Manager. For APIs 24 and greater, the Platform's default TrustManager states
3840 //that it requires usage of the hostname-aware version of checkServerTrusted for app's that
39- //implement Android's network_security_config file.
40- if (serverConfig == null ) {
41- new X509TrustManagerExtensions (TrustKit .getInstance ().getTrustManager (host )).checkServerTrusted (chain , authType , host );
41+ //implement Android's network_security_config file. The 2nd check is to allow usage of the
42+ //X509TrustManagerExtensions class. Any API below will default to the baseline trust manager.
43+ if (serverConfig == null && Build .VERSION .SDK_INT >= Build .VERSION_CODES .JELLY_BEAN_MR1 ) {
44+ new X509TrustManagerExtensions (trustManager ).checkServerTrusted (chain , authType , host );
4245 } else {
43- TrustKit . getInstance (). getTrustManager ( host ) .checkServerTrusted (chain , authType );
46+ trustManager .checkServerTrusted (chain , authType );
4447 }
4548 }
4649
0 commit comments