2017-09-11 76 views
0

所以我一直試圖通宵讓它工作,但似乎沒有什麼訣竅...我一直得到信任錨沒有找到認證路徑。沒有找到與okhttp認證路徑的信任錨點

這裏是我是如何建立okhttpClient(我跟着https://medium.com/@sreekumar_av/certificate-public-key-pinning-in-android-using-retrofit-2-0-74140800025b

fun provideOkHttpClient(): OkHttpClient { 
    val httpClientBuilder = OkHttpClient() 
      .newBuilder() 

    val logging = HttpLoggingInterceptor() 
    logging.level = if (BuildConfig.DEBUG) 
     HttpLoggingInterceptor.Level.BODY 
    else 
     HttpLoggingInterceptor.Level.NONE 


    val certificatePinner = CertificatePinner.Builder() 
      .add(HOST, SHA) 
      .build() 

    val connectionSpec = ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS) 
    connectionSpec.tlsVersions(TlsVersion.TLS_1_2).build() 

    val tlsSocketFactory = TLSSocketFactory() 
    return httpClientBuilder 
      .certificatePinner(certificatePinner) 
      .addNetworkInterceptor(logging) 
      .sslSocketFactory(tlsSocketFactory, tlsSocketFactory.systemDefaultTrustManager()) 
      .connectionSpecs(Collections.singletonList(connectionSpec.build())) 
      .build() 
} 

我得到了這樣的SHA:OpenSSL的的s_client.First -connect主機:端口| openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | OpenSSL的ENC -base64

這裏是TLSFacotry:https://gist.github.com/pollux-/fbcc74984e110bb49497faa2d0ed5ee1#file-tlssocketfactory-java

我真的不明白爲什麼它不會在這一點上工作..

任何幫助將不勝感激!

+1

IIRC,完整的LogCat輸出將顯示OkHttp遇到的內容,因此您可以將它與'certificatePinner'中的內容進行比較。我不知道爲什麼你有'sslSocketFactory()'調用。 – CommonsWare

+0

我沒有真正的logcat更多的信息,但這裏是完整的日誌: https://gist.github.com/NeoDigi/60abbcdd1f650897f600afda9268837b –

+0

它不會在堆棧跟蹤,但在行前或之後。 – CommonsWare

回答

0

IIRC證書鎖定僅評估證書鏈接受。

這將有助於獲得完整的堆棧跟蹤以及您嘗試連接的主機,因爲它有可能使用您的客戶端不會接受的自簽名證書。

試着讓它在沒有先插入證書的情況下工作,然後將其添加進去。由於@CommonsWare提到證書鎖定失敗時,它會告訴您該怎麼做。

相關問題