Im與Android應用上的團隊一起工作,並分配了設置用戶登錄和註冊頁面的任務。設置我的服務器類後,使用HttpsURLConnection
類,我得到SSLHandshakeException
錯誤。
HttpsURLConnection的代碼 HttpsURLConnection connection = (HttpsURLConnection) new URL(spec.toString()).openConnection();
經過一番研究,我意識到這是因爲Android不信任我們的服務器,因爲它是自簽名。我試圖從Android開發站點跟蹤這個documentation,但不知道如何獲取crt
文件。即時通訊使用AWS服務器,但我不是設置自簽名證書的人,但我確實擁有對服務器的完全訪問權限。
從Android的文件(我如何獲得負載der.crt文件?)使用來自AWS服務器的自簽名證書在Android上設置HTTPS連接
// Load CAs from an InputStream
// (could be from a resource or ByteArrayInputStream or ...)
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// From https://www.washington.edu/itconnect/security/ca/load-der.crt
InputStream caInput = new BufferedInputStream(new FileInputStream("load-der.crt"));
Certificate ca;
那個washington.edu網址不再可用。 –