Push Notifications server-side SDK for Java に TLS 1.2 対応を加える(IBM JDK 使用時)
2018年3月から IBM Cloud は TLS 1.2 への対応が必須になりました(TLS 1.0, 1.1 は現在使えなくなっています).詳細は以下のページをご覧ください.
今回 TLS 1.2 関連で Push Notifications SDK のバグを踏んだのでそれの詳細と、暫定的な対応策をご紹介したいと思います.
今回バグを踏んだのはこちらの SDK .
この SDK を IBM JDK、TLS 1.2 の組み合わせで使うとバグが発現します.
問題はこの SDK が内部で使っている org.apache.httpcomponents/httpclient に起因します.
httpcomponents/httpclient を IBM JDK で使うと常に TLS 1.0 が使われてしまうらしい.
As long as HttpClient can be configured to use IBM specific TLS protocol implementations I personally consider this issue ‘not a problem’. I do not think HttpClient should use different SSL context initialization depending on JSSE provider.
対応はしないとのことなので自力で直すしかありません.
幸いにも対応策は書いてあるのでそれ通りに実装します.
SSLContext sslContext = null;
try {
sslContext = SSLContexts.custom()
.useProtocol("SSL_TLSv2")
.build();
} catch (KeyManagementException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLContext(sslContext)
.build();
SSLContexts.default(); ではなく custom で “SSL_TLSv2” を指定してあげればいいだけです.
以下の環境で動作を確認しました.
- IBM JDK 1.8
- WAS 17.0.0.2 Liberty
TLS 1.2 対応を加え、 dependencies ありで maven ビルドできるようにしたものを置いておきます.よろしければご活用ください.
以上です.