Bonjour,
j'ai un client et un serveur echo sécurisés avec SSL. En lancant le serveur tout va bien, puis je lance le client, tout va bien. Puis j'envoi un message et j'obtiens l'erreur suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
*** ServerHelloDone
main, WRITE: TLSv1 Handshake, length = 1915
main, READ: TLSv1 Alert, length = 2
main, RECV TLSv1 ALERT:  fatal, certificate_unknown
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown
javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown
        at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:174)
        at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Alerts.java:136)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1657)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:932)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1096)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:744)
        at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)
        at java.io.InputStream.read(InputStream.java:85)
        at sslecho.SSLEchoServer1.serve(SSLEchoServer1.java:88)
        at sslecho.SSLEchoServer1.main(SSLEchoServer1.java:108)
Et voici le code de mon serveur :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
 
import javax.net.ServerSocketFactory;
import javax.net.ssl.SSLServerSocketFactory;
 
public class Main {
 
	public static void main(String[] args) {
 
		try {
			int port = 443;
			ServerSocketFactory ssocketFactory = SSLServerSocketFactory
					.getDefault();
			ServerSocket ssocket = ssocketFactory.createServerSocket(port);
 
			// Attente d'un client
			Socket socket = ssocket.accept();
 
			// Récupération des flux d'entrée de sortie
			InputStream in = socket.getInputStream();
			OutputStream out = socket.getOutputStream();
 
			// Lecture d'un entier et retourne l'entier + 1
			int read = 0;
			while ((read = in.read()) != -1) {
				out.write(read + 1);
			}
 
			// Ferme la connexion
			in.close();
			out.close();
		} catch (IOException e) {
			System.out.println("error : " + e);
		}
	}
}
Et mon client :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
 
import javax.net.SocketFactory;
import javax.net.ssl.SSLSocketFactory;
 
/**
 * Une classe implémentant un client sécurisé SSL pour le service Echo (RFC 862)
 * @author P. Guichet
 */
public class SSLEchoClient1 {
    // Le port par défaut du service Echo
    private static final int ECHO_PORT = 7878;
 
    // Le socket permettant la connection au serveur
    Socket socket;
 
    /**
     * Création d'un nouveau client
     * @param hostname Le nom de l'hote auquel se connecter
     * @param port le port du service
     */
    public SSLEchoClient1(String hostname, int port) {
        //////////////////////////////////////////////////////////////////
        // Initialisation des propriétés nécessiares à l'établissement de la connection
        // Ces proriétés peuvent aussi être initialisées comme paramètres passés à la
        // machine virtuelle : eg. -Djavax.net.ssl.trustStore=tls/client.ks
 
        // Le magasin des certificats de confiance
        // Remarque : si le trustStore n'est pas spécifiée ce sera
        // JAVA_HOME$/jre/lib/security/cacerts
        System.setProperty("javax.net.ssl.trustStore","rootca.ks");
        // Le type de ce magasin
        System.setProperty("javax.net.ssl.trustStoreType", "JCEKS");
        // Pour le débogage
        System.setProperty("javax.net.debug", "ssl");
 
        // Obtention d'une fabrique de Socket SSL, c'est la fabrique par défaut
        SocketFactory factory = SSLSocketFactory.getDefault();
        try {
            // Création d'un socket permettant la communication vers l'hote et le port choisi
            socket = factory.createSocket(hostname, port);
            System.out.println("Client : connection établie!..");
            // Affichage des propriétés de la communication
            //Utils.printSocketProps(socket, " ---> ");
        } catch (UnknownHostException uhe) {
            uhe.printStackTrace();
            System.exit(-1);
        } catch (IOException ioe) {
            ioe.printStackTrace();
            System.exit(-1);
        }
    }
 
    /**
     * Création d'un nouveau client connecté au port Echo de l'hote distant
     * @param hostname l'hote auquel se connecter
     */
    public SSLEchoClient1(String hostname) {
        this(hostname, ECHO_PORT);
    }
 
 
    /**
     * Etablissement connection au serveur cible
     * @throws IOException si la demande de connection
     * ou la transmission des données échoue
     */
    public void request() throws IOException {
        // Récupération des flots entrant et sortant associés au socket
        InputStream is = socket.getInputStream();
        OutputStream os = socket.getOutputStream();
 
        // Connection d'un lecteur à l'entrée standard
        BufferedReader brin = new BufferedReader(new InputStreamReader(System.in));
        // Boucle d'émission réception
        byte[] buffer = new byte[1024];
        for(;;) {
            System.out.println("Entrer le message ou \"!x\" pour quitter");
            System.out.flush();
            // Lire le message à envoyer
            String message = brin.readLine();
            // Tester si fin de session
            if(message.equals("!x"))
                break;
            // Envoi message
            os.write(message.getBytes());
            // Lecture écho
            int nr = is.read(buffer);
            // Affichage écho
            System.out.println(">>> " + new String(buffer,0,nr));
        }
        // Fermeture socket
        socket.close();
        System.out.println("Connection fermée!..");
    }
 
 
    /**
     * @param args les arguments passés en ligne de commande
     */
    public static void main(String[] args) throws IOException {
        try {
            if(args.length == 0){
                new SSLEchoClient1("127.0.0.1", 7878).request();
            } else if(args.length == 1) {
                new SSLEchoClient1(args[0]).request();
            } else
                new SSLEchoClient1(args[0], Integer.parseInt(args[1]));
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}
Si quelqu'un sait ce que ça signifie...
Merci !