|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Member
Iscritto dal: Feb 2006
Messaggi: 88
|
[JAVA] Client HTTPS
Salve ho un problema,
devo implementare un client https che effettua una richiesta al server (Apache Tomcat in localhost) sulla porta 8443. Lato server, ho configurato il file di configurazione server.xml . Ho inserito il seguente connettore: <Connector port="8443" maxHttpHeaderSize="8192" maxThreads="150" minSpareThreads="25" maxSpareThreads="75" enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS" truststoreFile="D:\trust\cacerts" mode="gsi"/> Quando eseguo il client (ho postato il codice sotto) mi da questo errore: ********************************************************* 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 at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1591) at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:187) at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Handshaker.java:181) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:975) at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:123) at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Handshaker.java:516) at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Handshaker.java:454) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:884) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1123) at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1107) at https.SSLSocketClient.main(SSLSocketClient.java:43) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:285) at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:191) at sun.security.validator.Validator.validate(Validator.java:218) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:126) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:209) at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:249) at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:954) ... 8 more Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:174) at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:238) at sun.security.validator.PKIXValidator.doB ********************************************************* Mentre se eseguo questo client sul server www.sun.com e sulla porta 443, funziona tutto correttamente. Il server restituisce al client il codice html della pagina index. Da cosa dipende??????Cosa mi manca da settare????? Ho sbagliato qualcosa??????? ![]() ![]() ![]() ![]() //////////////////////////// Client HTTPS /////////////////////// import java.net.*; import java.io.*; import javax.net.ssl.*; public class SSLSocketClient { public static void main(String[] args) throws Exception { try { SSLSocketFactory factory = (SSLSocketFactory)SSLSocketFactory.getDefault(); SSLSocket socket = (SSLSocket)factory.createSocket("localhost", 8443); socket.startHandshake(); PrintWriter out = new PrintWriter(new BufferedWriter( new OutputStreamWriter(socket.getOutputStream()))); out.println("GET / HTTP/1.1"); out.println(); out.flush(); if (out.checkError()) System.out.println("SSLSocketClient: java.io.PrintWriter error"); /* read response */ BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); out.close(); socket.close(); } catch (Exception e) { e.printStackTrace(); } } } |
![]() |
![]() |
![]() |
#2 |
Member
Iscritto dal: Feb 2006
Messaggi: 88
|
nessuno mi può aiutare???????
Come mai sul server: www.sun.com funziona e sul mio localhost(Apache Tomcat) no???????? Qualcuno ha qualche idea????? ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
![]() |
#3 |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 3306
|
sembra proprio che ti manchi un certificato valido lato server
|
![]() |
![]() |
![]() |
#4 |
Member
Iscritto dal: Feb 2006
Messaggi: 88
|
ma il truststoreFile non è sufficiente?????
cosa devo modificare????? mi puoi postare qualche esempio???? grazie. |
![]() |
![]() |
![]() |
#5 | |
Senior Member
Iscritto dal: Oct 2005
Messaggi: 3306
|
Quote:
L'eccezione che ti viene fuori dice proprio che manca il certificato. Senza quello non puoi cominciare una comunicazione sicura. Credo inoltre che ti manchi il parametro truststorePass, ma non sono esperto di Tomcat perciò non so dirti di più. Comunque per la configurazione SSL di Tomcat guarda qui: http://tomcat.apache.org/tomcat-4.0-doc/ssl-howto.html |
|
![]() |
![]() |
![]() |
#6 |
Member
Iscritto dal: Feb 2006
Messaggi: 88
|
Il problema è che se dal browser web digito:
https:\\localhost:8443 mi esce la pagina iniziale di Tomcat, mentre se eseguo il mio client mi spara quell'errore. Per quanto riguarda il certificato lato server l'ho creatoma non l'ho inserito nel file di congigurazione perchè sta nella home e quindi lo prende di default. keystoreFile : Add this attribute if the keystore file you created is not in the default place that Tomcat expects (a file named .keystore in the user home directory under which Tomcat is running). Per quanto riguarda la password siccome è quella di default ("changeit") non c'è bisogno di inserirla. Qualche idea?????? Qualcuno mi può aiutare??? |
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 06:33.