所以我一直試圖通宵讓它工作,但似乎沒有什麼訣竅...我一直得到信任錨沒有找到認證路徑。沒有找到與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
我真的不明白爲什麼它不會在這一點上工作..
任何幫助將不勝感激!
IIRC,完整的LogCat輸出將顯示OkHttp遇到的內容,因此您可以將它與'certificatePinner'中的內容進行比較。我不知道爲什麼你有'sslSocketFactory()'調用。 – CommonsWare
我沒有真正的logcat更多的信息,但這裏是完整的日誌: https://gist.github.com/NeoDigi/60abbcdd1f650897f600afda9268837b –
它不會在堆棧跟蹤,但在行前或之後。 – CommonsWare