7.3. TLS/SSL(Hot Rod)および REST 暗号化
Hot Rod および REST プロトコルはいずれも、SSL/TLS を使用した暗号化と任意の TLS/SNI サポート(Server Name Indication)をサポートします。これを設定するには、サーバー証明書を保存する JDK の一部である keytool アプリケーションを使用してキーストアを作成する必要があります。次に、<server-identities> 要素をセキュリティーレルムに追加します。
SSL のセキュリティーレルム設定
<security-realm name="ApplicationRealm">
<server-identities>
<ssl>
<keystore path="keystore_server.jks" relative-to="jboss.server.config.dir" keystore-password="secret" />
</ssl>
</server-identities>
</security-realm>
SNI サポートを使用する場合は、複数のセキュリティーレルムが設定される可能性があります。
サーバーの起動時に開発証明書を生成することもできます。これを行うには、以下のように keystore 要素に generate-self-signed-certificate-host を指定します。
キーストアの自動生成
<security-realm name="ApplicationRealm">
<server-identities>
<ssl>
<keystore path="keystore_server.jks" relative-to="jboss.server.config.dir" keystore-password="secret" generate-self-signed-certificate-host="localhost"/>
</ssl>
</server-identities>
</security-realm>
自動生成されたキーストアを使用する場合は、覚えておく必要のある基本的な原則が 3 つあります。
- 実稼働環境では使用しないでください。
- これらは、必要に応じて生成されます(例: クライアントからの最初の接続の取得時など)。
- これらの証明書も証明書が含まれているので、Hot Rod クライアントで直接使用することもできます。
次に、endpoint サブシステムの <hotrod-connector> または <rest-connector> 要素を変更して暗号化を必要とします。オプションで SNI 設定を追加します。
hot Rod コネクター SSL 設定
<hotrod-connector socket-binding="hotrod" cache-container="local">
<encryption security-realm="ApplicationRealm" require-ssl-client-auth="false">
<sni host-name="domain1" security-realm="Domain1ApplicationRealm" />
<sni host-name="domain2" security-realm="Domain2ApplicationRealm" />
</encryption>
</hotrod-connector>
<rest-connector socket-binding="rest" cache-container="local">
<encryption security-realm="ApplicationRealm" require-ssl-client-auth="false">
<sni host-name="domain1" security-realm="Domain1ApplicationRealm" />
<sni host-name="domain2" security-realm="Domain2ApplicationRealm" />
</encryption>
</rest-connector>
clients In order to connect to the server using the Hot Rod protocol(Hot Rod プロトコルを使用してサーバーに接続するには、JRE が信頼する認証局(CA)によって鍵が署名されていない限り、接続する公開鍵が含まれるトラストストアが必要です。
ConfigurationBuilder clientBuilder = new ConfigurationBuilder();
clientBuilder
.addServer()
.host("127.0.0.1")
.port(11222)
.security()
.ssl()
.enabled(true)
.sniHostName("domain1")
.trustStoreFileName("truststore_client.jks")
.trustStorePassword("secret".toCharArray());
remoteCacheManager = new RemoteCacheManager(clientBuilder.build());
さらに、クライアント証明書認証を有効にすることもできます(オプションで EXTERNAL SASL メッチを使用してクライアントの認証および承認も許可します)。これを有効にするには、サーバー上のセキュリティーレルムがトラストストアを追加して受信クライアント証明書を信頼できるようにする必要があります。
<security-realm name="ApplicationRealm">
<authentication>
<truststore path="truststore_server.jks" relative-to="jboss.server.config.dir" keystore-password="secret"/>
</authentication>
<server-identities>
<ssl>
<keystore path="keystore_server.jks" relative-to="jboss.server.config.dir" keystore-password="secret" />
</ssl>
</server-identities>
</security-realm>
次に、コネクターにクライアント証明書を必要とするよう指示します。
<hotrod-connector socket-binding="hotrod" cache-container="local">
<encryption security-realm="ApplicationRealm" require-ssl-client-auth="true" />
</hotrod-connector>
クライアントでは、この時点では、サーバー証明書を信頼する trustStore に証明書が含まれる keyStore を指定する必要があります。
その方法を学ぶためのセクションです。