在 Android 中使用 SSL

Using SSL in Android

我是 SSL 新手。我正在使用 https://developer.android.com/training/articles/security-ssl.html#HttpsExample 处给出的代码并使用它我能够与我的 URL 建立连接(由 urlConnection.getResponseCode() 验证,其中 urlConnection 的类型为 HttpsURL联系)。现在我的疑问是如何使用它来确保我正在与正确的服务器通信?如果没有它,我认为仍然会有 MITM 攻击。在上面提到的 link 中有一些关于这个的讨论,但我不知道如何使用 java 代码来检查这个。 感谢您的宝贵时间和帮助。

要验证正确的服务器,您必须固定证书。请看一下https://developer.android.com/training/articles/security-ssl.html#Pinning whereby a tutorial is given here http://www.thoughtcrime.org/blog/authenticity-is-broken-in-ssl-but-your-app-ha/