1

私は私の問題を提示するつもりです:

私の Web アプリケーションは、通信を設定するためにクライアント証明書が必要なサーバーに https でフォームを送信します。フォームを送信すると、httpsサーバーが証明書を要求し、証明書を選択するとサーバーが応答します。しかし今、httpsサーバーからの応答を管理したいので、HttpClientを使用してサーブレットからhttpsサーバーに投稿したいのですが、ここで問題があります...

HttpClient で投稿を送信する私のコードは次のとおりです。

DefaultHttpClient client = new DefaultHttpClient();

// in the truststore i have the https server certificates for establish connection
// from my client to https server       
FileInputStream instream = new FileInputStream(new File(TRUESTORE_PATH));       
KeyStore truststore  = KeyStore.getInstance(KeyStore.getDefaultType());
truststore.load(instream, KEY_TRUESTORE_PASS.toCharArray());

// in the keystore i have the client certificate but without private key because,
// in theory, i shouldn't know it   
FileInputStream otherinstream = new FileInputStream(new File(KEYSTORE_PATH));
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
keystore.load(otherinstream,KEY_STORE_PASS.toCharArray());

SSLSocketFactory socketFactory = new SocketFactory(keystore,KEY_STORE_PASS,truststore);
Scheme sch = new Scheme("https", 443, socketFactory);
client.getConnectionManager().getSchemeRegistry().register(sch);

HttpGet httpget = new HttpGet("https://remote_server_with_client_authentication");
HttpResponse response = client.execute(httpget);

たとえば、単体テストでこのコードを実行すると、https サーバーからの応答がありますが、許可されていないことがわかります。キーストアにはクライアント証明書がありますが、秘密鍵がないため、https サーバーで認証できないと思われます。認証されていません。

次に、ユーザーが選択したクライアント証明書を使用して https サーバーとの通信を確立する方法はありますか?

ありがとう!

4

0 に答える 0