質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Q&A

解決済

1回答

4525閲覧

AndroidでHttps通信エラー

yamayamak

総合スコア131

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

0グッド

0クリップ

投稿2018/01/22 13:24

AndroidでHttps通信を以下のサイトを参考に作っています。

https://akira-watson.com/android/httpurlconnection-post.html

サーバはAWSでロードバランサーでHTTPSを終端しEC2サーバにはHTTP通信です。
(WebサーバはHTTPで通信しています)

以下のエラーが原因だと思うのですが
NativeCrypto_SSL_do_handshake ret=-1 errno=11 sslError=2 timeout_millis=10000
最後あたりに、Successfullになっているので、問題ではないのでしょうか?
どういう意味なのかよくわからないので、ご教授ください。

Java

104:54.076 I/System.out: open:https://hogehoge.com/api/remocons/destroy 204:54.077 I/System.out: [CDS][DNS] getAllByNameImpl netId = 0 304:54.077 D/libc-netbsd: [getaddrinfo]: hostname=hogehoge.com; servname=(null); cache_mode=(null), netid=0; mark=0 404:54.077 D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0 504:54.078 D/libc-netbsd: [getaddrinfo]: hostname=hogehoge.com; servname=(null); cache_mode=(null), netid=0; mark=0 604:54.078 D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=1024; ai_family=0 704:54.176 D/libc-netbsd: getaddrinfo: hogehoge.com get result from proxy >> 804:54.176 I/System.out: propertyValue:true 904:54.177 I/System.out: [CDS]rx timeout:10000 1004:54.177 I/System.out: [socket][0] connection hogehoge.com/54.92.100.254:443;LocalPort=49613(20000) 1104:54.177 I/System.out: [CDS]connect[hogehoge.com/54.92.100.254:443] tm:20 1204:54.178 D/Posix: [Posix_connect Debug]Process com.androidhttps :443 1304:54.207 I/System.out: [socket][/192.168.1.6:49613] connected 1404:54.210 D/libc-netbsd: [getaddrinfo]: hostname=hogehoge.com; servname=(null); cache_mode=(null), netid=0; mark=0 1504:54.210 D/libc-netbsd: [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0 1604:54.211 D/NativeCrypto: ssl=2862 NativeCrypto_SSL_do_handshake fd=0xa0cd4040 shc=0xa0cd4044 timeout_millis=10000 client_mode=1 npn=0x0 1704:54.211 D/NativeCrypto: doing handshake ++ 1804:54.211 D/NativeCrypto: ssl=2862 info_callback where=0x10 ret=1 1904:54.211 D/NativeCrypto: ssl=2862 handshake start in UNKWN before/connect initialization 2004:54.211 D/NativeCrypto: ssl=2862 info_callback calling handshakeCompleted 2104:54.211 D/NativeCrypto: ssl=2862 info_callback completed 2204:54.211 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 2304:54.211 D/NativeCrypto: ssl=2862 SSL_connect:UNKWN before/connect initialization 2404:54.211 D/NativeCrypto: ssl=2862 info_callback ignored 2504:54.211 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 2604:54.211 D/NativeCrypto: ssl=2862 SSL_connect:23WCHA SSLv2/v3 write client hello A 2704:54.211 D/NativeCrypto: ssl=2862 info_callback ignored 2804:54.211 D/NativeCrypto: ssl=2862 info_callback where=0x1002 ret=-1 2904:54.211 D/NativeCrypto: ssl=2862 SSL_connect:error exit in 23RSHA SSLv2/v3 read server hello A 3004:54.211 D/NativeCrypto: ssl=2862 info_callback ignored 3104:54.211 D/NativeCrypto: doing handshake -- ret=-1 3204:54.211 D/NativeCrypto: ssl=2862 NativeCrypto_SSL_do_handshake ret=-1 errno=11 sslError=2 timeout_millis=10000 3304:54.240 D/NativeCrypto: doing handshake ++ 3404:54.240 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 3504:54.240 D/NativeCrypto: ssl=2862 SSL_connect:3RSH_A SSLv3 read server hello A 3604:54.240 D/NativeCrypto: ssl=2862 info_callback ignored 3704:54.242 E/NativeCrypto: ssl=2862 cert_verify_callback x509_store_ctx=0xa0cd3e00 arg=0x0 3804:54.242 E/NativeCrypto: ssl=2862 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA 3904:54.285 D/NativeCrypto: ssl=2862 cert_verify_callback => 1 4004:54.285 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 4104:54.285 D/NativeCrypto: ssl=2862 SSL_connect:3RSC_A SSLv3 read server certificate A 4204:54.285 D/NativeCrypto: ssl=2862 info_callback ignored 4304:54.286 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 4404:54.286 D/NativeCrypto: ssl=2862 SSL_connect:3RSKEA SSLv3 read server key exchange A 4504:54.286 D/NativeCrypto: ssl=2862 info_callback ignored 4604:54.286 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 4704:54.286 D/NativeCrypto: ssl=2862 SSL_connect:3RSD_A SSLv3 read server done A 4804:54.286 D/NativeCrypto: ssl=2862 info_callback ignored 4904:54.294 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 5004:54.294 D/NativeCrypto: ssl=2862 SSL_connect:3WCKEA SSLv3 write client key exchange A 5104:54.294 D/NativeCrypto: ssl=2862 info_callback ignored 5204:54.294 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 5304:54.294 D/NativeCrypto: ssl=2862 SSL_connect:3WCCSA SSLv3 write change cipher spec A 5404:54.294 D/NativeCrypto: ssl=2862 info_callback ignored 5504:54.294 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 5604:54.294 D/NativeCrypto: ssl=2862 SSL_connect:3WFINA SSLv3 write finished A 5704:54.294 D/NativeCrypto: ssl=2862 info_callback ignored 5804:54.294 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 5904:54.294 D/NativeCrypto: ssl=2862 SSL_connect:3FLUSH SSLv3 flush data 6004:54.294 D/NativeCrypto: ssl=2862 info_callback ignored 6104:54.294 D/NativeCrypto: ssl=2862 info_callback where=0x1002 ret=-1 6204:54.294 D/NativeCrypto: ssl=2862 SSL_connect:error exit in UNKWN SSLv3 read server session ticket A 6304:54.294 D/NativeCrypto: ssl=2862 info_callback ignored 6404:54.294 D/NativeCrypto: ssl=2862 info_callback where=0x1002 ret=-1 6504:54.294 D/NativeCrypto: ssl=2862 SSL_connect:error exit in UNKWN SSLv3 read server session ticket A 6604:54.294 D/NativeCrypto: ssl=2862 info_callback ignored 6704:54.295 D/NativeCrypto: doing handshake -- ret=-1 6804:54.295 D/NativeCrypto: ssl=2862 NativeCrypto_SSL_do_handshake ret=-1 errno=11 sslError=2 timeout_millis=10000 6904:54.329 D/NativeCrypto: doing handshake ++ 7004:54.329 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 7104:54.329 D/NativeCrypto: ssl=2862 SSL_connect:UNKWN SSLv3 read server session ticket A 7204:54.329 D/NativeCrypto: ssl=2862 info_callback ignored 7304:54.329 D/NativeCrypto: ssl=2862 info_callback where=0x1001 ret=1 7404:54.329 D/NativeCrypto: ssl=2862 SSL_connect:3RFINA SSLv3 read finished A 7504:54.329 D/NativeCrypto: ssl=2862 info_callback ignored 7604:54.329 D/NativeCrypto: ssl=2862 info_callback where=0x20 ret=1 7704:54.329 D/NativeCrypto: ssl=2862 handshake done in SSLOK SSL negotiation finished successfully 7804:54.329 D/NativeCrypto: ssl=2862 info_callback calling handshakeCompleted 7904:54.329 D/NativeCrypto: ssl=2862 info_callback completed 8004:54.329 D/NativeCrypto: ssl=2862 info_callback where=0x1002 ret=1 8104:54.329 D/NativeCrypto: ssl=2862 SSL_connect:ok exit in SSLOK SSL negotiation finished successfully 8204:54.329 D/NativeCrypto: ssl=2862 info_callback ignored 8304:54.329 D/NativeCrypto: doing handshake -- ret=1 8404:54.329 D/NativeCrypto: ssl=2862 NativeCrypto_SSL_get_certificate => NULL 8504:54.329 I/System.out: gba_cipher_suite:TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 8604:54.330 D/debug: flush 8704:54.330 I/System.out: [OkHttp] sendRequest>> 8804:54.330 I/System.out: [OkHttp] sendRequest<< 8904:54.330 D/NativeCrypto: ssl=2862 sslWrite buf=0xb44c3000 len=298 write_timeout_millis=0 9004:54.331 D/NativeCrypto: ssl=2862 sslRead buf=0xb44c3000 len=2048,timeo=10000 9104:54.362 D/NativeCrypto: ssl=2862 NativeCrypto_SSL_interrupt 9204:54.362 D/NativeCrypto: sslNotify, appData=0xb46dda80 ret=1 9304:54.362 D/NativeCrypto: sslNotify, appData=0xb46dda80 ret=1 9404:54.362 D/NativeCrypto: ssl=2862 info_callback where=0x4008 ret=256 9504:54.362 D/NativeCrypto: ssl=2862 SSL3 alert write:W:CN warning close notify 9604:54.362 D/NativeCrypto: ssl=2862 info_callback ignored 9704:54.362 I/System.out: [CDS]close[49613]

プログラムは以下のような感じです。
端末のルート証明書のようなものが何かしないといけないのでしょうか?

java

1public class UploadTask extends AsyncTask<String, Void, String> { 2 3 private Listener listener; 4 5 // 非同期処理 6 @Override 7 protected String doInBackground(String... params) { 8 String urlSt = "https://t.hogehoge.biz/api/test"; 9 HttpURLConnection con = null; 10 String result = null; 11 String word = "a="+params[0]; 12 try { 13 // URL設定 14 URL url = new URL(urlSt); 15 16 // HttpURLConnection 17 con = (HttpURLConnection) url.openConnection(); 18 19 // request POST 20 con.setRequestMethod("POST"); 21 con.setRequestProperty("application/json", "Accept"); 22 con.setRequestProperty("Bearer aaa", "Authorization"); 23 24 // no Redirects 25 con.setInstanceFollowRedirects(false); 26 27 // データを書き込む 28 con.setDoOutput(true); 29 30 // 時間制限 31 con.setReadTimeout(10000); 32 con.setConnectTimeout(20000); 33 34 // 接続 35 con.connect(); 36 37 // POSTデータ送信処理 38 OutputStream out = null; 39 try { 40 out = con.getOutputStream(); 41 out.write( word.getBytes("UTF-8") ); 42 out.flush(); 43 Log.d("debug","flush"); 44 } catch (IOException e) { 45 // POST送信エラー 46 e.printStackTrace(); 47 result="POST送信エラー"; 48 } finally { 49 if (out != null) { 50 out.close(); 51 } 52 } 53 54 final int status = con.getResponseCode(); 55 if (status == HttpURLConnection.HTTP_OK) { 56 // レスポンスを受け取る処理等 57 result="HTTP_OK"; 58 } 59 else{ 60 result="status="+String.valueOf(status); 61 } 62 63 } catch (IOException e) { 64 e.printStackTrace(); 65 } finally { 66 if (con != null) { 67 con.disconnect(); 68 } 69 } 70 return result; 71 } 72省略 73}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

HTTPSは接続できていました。Headerの作り方に誤りがありました。
以下のようにして、動きそうです。

java

1 con.setRequestProperty ("Authorization", "Bearer aaa"); 2 con.setRequestProperty("Accept", "application/json");

ありがとうございました。

投稿2018/01/22 14:28

yamayamak

総合スコア131

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問