質問編集履歴
2
内容の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -63,4 +63,11 @@
|
|
63
63
|
```
|
64
64
|
E/Exception: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
|
65
65
|
```
|
66
|
-
コードの意味もほとんどよく分かっていないまま書いているのでもう少し調べていきたいと思います。
|
66
|
+
コードの意味もほとんどよく分かっていないまま書いているのでもう少し調べていきたいと思います。
|
67
|
+
|
68
|
+
### 4月8日現在の状況
|
69
|
+
|
70
|
+
現在、問題の原因としてSSL証明書自体に問題があるというような話が出ています。
|
71
|
+
[https://kaede.jp/2018/06/10191854.html](https://kaede.jp/2018/06/10191854.html)
|
72
|
+
上記の記事に書いてある「subjectAltName」が入っていない?のが原因なのではないかという話です。
|
73
|
+
再度SSL証明書を作成して、成功したらまた自己解決として書きます。
|
1
内容の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,4 +24,43 @@
|
|
24
24
|
の、**val caInput: InputStream = BufferedInputStream(FileInputStream("load-der.crt"))**の箇所に、代わりに端末内のファイルにアクセスするような文言を書くのだろうと推測していますが、パスも分からないので途方に暮れています。
|
25
25
|
|
26
26
|
どなたかアドバイスしてくださると助かります。
|
27
|
-
宜しくお願い致します。
|
27
|
+
宜しくお願い致します。
|
28
|
+
|
29
|
+
### 現時点まででやってみたこと
|
30
|
+
一先ずアセットに証明書ファイル**ca.der**を置いて、以下のようにコードを書いてみました。
|
31
|
+
|
32
|
+
```Kotlin
|
33
|
+
val cf: CertificateFactory = CertificateFactory.getInstance("X.509")
|
34
|
+
val file = context.assets.open("cacert.der")
|
35
|
+
val ca = cf.generateCertificate(file) as X509Certificate
|
36
|
+
|
37
|
+
val keyStoreType = KeyStore.getDefaultType()
|
38
|
+
val keyStore = KeyStore.getInstance(keyStoreType).apply {
|
39
|
+
load(null, null)
|
40
|
+
setCertificateEntry("ca", ca)
|
41
|
+
}
|
42
|
+
|
43
|
+
val tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm()
|
44
|
+
val tmf = TrustManagerFactory.getInstance(tmfAlgorithm).apply {
|
45
|
+
init(keyStore)
|
46
|
+
}
|
47
|
+
|
48
|
+
val context = SSLContext.getInstance("TLS").apply {
|
49
|
+
init(null, tmf.trustManagers, null)
|
50
|
+
}
|
51
|
+
|
52
|
+
try {
|
53
|
+
val con = URL("https://xxxxxxxxxxxxxxxxxxx").openConnection() as HttpsURLConnection
|
54
|
+
con.sslSocketFactory = context.socketFactory
|
55
|
+
con.requestMethod = "GET"
|
56
|
+
.
|
57
|
+
.
|
58
|
+
.
|
59
|
+
```
|
60
|
+
|
61
|
+
しかし以前としてエラーは出てしまいます。
|
62
|
+
|
63
|
+
```
|
64
|
+
E/Exception: javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
|
65
|
+
```
|
66
|
+
コードの意味もほとんどよく分かっていないまま書いているのでもう少し調べていきたいと思います。
|