証明書付きのSSL接続を使用してサーバーに接続できるコードを作成しようとしています。 私は証明書、その.crt
ファイルを持っています。 私は、コードを組み立てましたが、機能しません:証明書を使用したSSL接続
public class SSLClient {
public static void main(String[] args) throws Exception{
String strServerName = "Some Server"; // SSL Server Name
int intSSLport = 443; // Port where the SSL Server is listening
PrintWriter out = null;
BufferedReader in = null;
{
// Registering the JSSE provider
Security.addProvider(new Provider());
}
try {
// Creating Client Sockets
SSLSocketFactory sslfac = (SSLSocketFactory)SSLSocketFactory.getDefault();
SSLSocket socket = (SSLSocket)sslfac.createSocket(strServerName,intSSLport);
System.setProperty("javax.net.ssl.keyStore", "D:/projects/TemporaryTesting/certificate.crt");
// Initializing the streams for Communication with the Server
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput = "Hello Testing ";
out.println(userInput);
System.out.println("echo: " + in.readLine());
// Closing the Streams and the Socket
out.close();
in.close();
stdIn.close();
socket.close();
}
catch(Exception exp)
{
System.out.println(" Exception occurred .... " +exp);
exp.printStackTrace();
}
}}
これは私が取得していますエラーです:私は間違っ
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested targetjavax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
何をしているのですか? 私はそれを使用する前に証明書をJavaで登録する必要がありますか? どうすれば修正できますか? これは私のSSL接続との最初の遭遇であり、どんな助けにも感謝します。
私は日食に証明書をインポートすると、また最後に、このパラメータを追加することのlib /セキュリティの下にJDKフォルダにcacerts
ファイルにcmdを手動 http://magicmonster.com/kb/prg/java/ssl/pkix_path_building_failed.html
をインポートし、日食でkeytoolをインストールするようないくつかのことをやって覚えて
あなたのトラスト内にサーバの証明書( 'strServerName')を追加するのを忘れたと思います。 –
[これをチェック](http:// stackoverf low.com/questions/6908948/java-sun-security-provider-certpath-suncertpathbuilderexception-unable-to-find) –
@ oliv37トラストアとは何ですか?証明書をどのように追加するのですか? –