Bonjours, ayant essayé de trouver une solution sans grande réussite. Je me tourne vers vos âmes charitables
Je créer une application qui doit ce connecter avec l'aide de certificats dans les deux sens, le problème est que je reçois des erreurs une fois que je lance l'application.
Si quelqu'un d'autre est intéresser par le problème, il est le bienvenue


Voici la classe qui initialise le context de ma connexion:

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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
import java.io.FileInputStream;
	import java.io.IOException;
	import java.io.InputStream;
	import java.security.KeyManagementException;
	import java.security.KeyStore;
	import java.security.KeyStoreException;
	import java.security.NoSuchAlgorithmException;
import java.security.Security;
	import java.security.UnrecoverableKeyException;
	import java.security.cert.CertificateException;
 
	import javax.net.ssl.KeyManagerFactory;
	import javax.net.ssl.SSLContext;
	import javax.net.ssl.SSLServerSocket;
	import javax.net.ssl.SSLServerSocketFactory;
	import javax.net.ssl.SSLSocket;
	import javax.net.ssl.TrustManager;
	import javax.net.ssl.TrustManagerFactory;
import java.util.Properties;
 
 
 
public class ConfigConnexion {
 
 
 
 
 
		///** Algorihtme de certification. */
		//public static final String ALGORITHM = "sunx509";
 
		/** Type du conteneur keystore. */
		public static final String KEYSTORE_TYPE = "JKS";
 
		/** Protocole SSL à utiliser. */
		public final static String PROTOCOL = "SSLv3";
 
		/**
                 * 
                 * @throws KeyStoreException
                 * @throws IOException
                 * @throws FileNotFoundException
                 */
 
		// Récupérer les infos.
		final int port;
		final String keystorePath;
		final String keystorePass;
		final String truststorePath;
		final String truststorePass;
 
		boolean over = true;
 
		// Les objets que l'on va utiliser.
		Properties data = null;
		SSLSocket ssls = null;
		SSLServerSocket sslss = null;
		SSLServerSocketFactory sslssf = null;
		KeyManagerFactory kmf = null;
		TrustManagerFactory tmf = null;
		KeyStore ks = null;
		KeyStore ts = null;
		SSLContext sslc = null;
		TrustManager[] trustManagers = null;
		Thread t2 = null;
 
 
 
 
 
 
 
 
		public ConfigConnexion(Properties properties) {
 
			this.data = properties;
 
			System.out.println(properties.getProperty("Port", "defaultPort")); 
			this.port = Integer.parseInt(properties.getProperty("Port"));
 
			System.out.println(properties.getProperty("KeystorePath", "defaultPort")); 
			this.keystorePath = (properties.getProperty("KeystorePath"));
 
			System.out.println(properties.getProperty("KeystorePass", "defaultPort")); 
			this.keystorePass = (properties.getProperty("KeystorePass"));
 
			System.out.println(properties.getProperty("TruststorePath", "defaultPort")); 
			this.truststorePath = (properties.getProperty("TruststorePath"));
 
			System.out.println(properties.getProperty("TruststorePass", "defaultPort")); 
			this.truststorePass = (properties.getProperty("TruststorePass"));
		}
 
 
		public void initConfigConnexion() throws IOException {
 
			initKeyStore();
			initKeyManagerFactory();
			initTrustManagerFactory();
			initSSLContext();
			initServerSocketFactory();
 
 
 
		}
 
 
		public SSLSocket getSsls() {
			return ssls;
		}
 
 
		public void setSsls(SSLSocket ssls) {
			this.ssls = ssls;
		}
 
 
		public SSLServerSocket getSslss() {
			return sslss;
		}
 
 
		public void setSslss(SSLServerSocket sslss) {
			this.sslss = sslss;
		}
 
 
		// Récupérer la keystore et charger le fichier.
		public void initKeyStore() throws IOException {
			System.out.print("Récupération du keystore... ");
			try {
 
				ks = KeyStore.getInstance(KEYSTORE_TYPE);
				ks.load(new FileInputStream(keystorePath),
						keystorePass.toCharArray());
			} catch (NoSuchAlgorithmException | KeyStoreException
					| CertificateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.print("OK\n");
		}
 
 
		// Récupérer une instance d'un KeyManagerFactory et l'initialiser.
		public void initKeyManagerFactory() {
 
			System.out.print("Récupération et configuration du KeyManager...");
			try {
 
				this.kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
				this.kmf.init(ks, keystorePass.toCharArray());
 
			} catch (UnrecoverableKeyException | KeyStoreException
					| NoSuchAlgorithmException e2) {
				// TODO Auto-generated catch block
				e2.printStackTrace();
			}
			System.out.print(" OK\n");
 
		}
 
		// Récupérer une instance d'un TrustManagerFactory et l'initialiser.
		public void initTrustManagerFactory() throws IOException {
 
			System.out.print("Récupération et configuration du Trust... ");
 
 
			try {
			ts = KeyStore.getInstance("JKS");
 
 
			// this.getResources().openRawResource(R.raw.mykeystore);
			InputStream inputStream = new java.io.FileInputStream(
					truststorePath);
 
				ts.load(inputStream, truststorePass.toCharArray());
 
 
			tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
			//TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(ALGORITHM);
			//TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("PKIX");
 
				tmf.init(ts);
 
			} catch (KeyStoreException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (NoSuchAlgorithmException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (CertificateException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
 
 
			System.out.print("OK\n");
 
		}
 
		// Récupérer une instace d'un SSLContext et l'initialiser.
		public void initSSLContext() {
 
			System.out.print("Récupération et configuration de SSL ... ");
			try {
 
				sslc = SSLContext.getInstance(PROTOCOL);
				sslc.init(kmf.getKeyManagers(), trustManagers, null);
 
			} catch (KeyManagementException | NoSuchAlgorithmException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.print("OK\n");
 
		}
 
		// Récupérer une instance d'une fabrique à socket SSL,
		// puis intancier une socket.
		public void initServerSocketFactory() {
 
			System.out.print("Récupération et configuration de SSL fac ... ");
 
			sslssf = sslc.getServerSocketFactory();
 
			try {
				sslss = (SSLServerSocket) sslssf.createServerSocket(port);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.out.println("Le port est déjà utiliser!");
			}
 
			sslss.setUseClientMode(false);
			sslss.setNeedClientAuth(true);
			sslss.setWantClientAuth(true);
			Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
 
			System.out.print("OK\n");
		}
 
 
 
 
	}
et celle qui reçoit les 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
import java.io.*;
import java.util.Properties;
import java.util.Timer;
 
import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
 
public class Accepter_connexion_Socket implements Runnable {
 
	private String Mod_Auth;
	private Properties properties;
	private SSLServerSocket sslss = null;
	private SSLSocket ssls = null;
	private SSLSession session = null;
	public Thread t1;
	//private GUI app;
	boolean ecoute = true;
 
 
	public Accepter_connexion_Socket(Properties properties, ConfigConnexion cc) {
 
		this.properties = properties;
		this.Mod_Auth = (String) properties.get("Mod_Auth");
		this.ssls = cc.getSsls();
		this.sslss = cc.getSslss();
	}
 
	public void run() {
 
		try {
 
			while (ecoute) {
 
				try {
					initConnexion();
					Thread.sleep(4000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
 
				System.out.println("Un Client veut se connecter\n");
 
				if(this.Mod_Auth.equalsIgnoreCase("Authentification_Login")){
					Authentification_Par_Mdp amp = new Authentification_Par_Mdp(ssls, sslss, properties);
					t1 = new Thread(amp);
					t1.start();
				}
 
				if(this.Mod_Auth.equalsIgnoreCase("Authentification_Certificat")){
					t1 = new Thread(new Authentification_Par_Certificat(ssls, sslss,properties));
					t1.start();
 
				}
				ecoute = false;
 
			}
		} catch (IOException e) {
 
			System.err.println("Vous n'avez pas bien configuré le mode d'Authentification de vôtre fichier config.txt");
		}
 
	}
 
	// Attendre la connexion d'un client.
			public void initConnexion() throws IOException, InterruptedException {
				System.out.print("Attendre une connexion ... ");
				this.ssls = (SSLSocket) this.sslss.accept();
 
				session = ssls.getSession();
 
				//Timer sessionTimer = new Timer();
                //sessionTimer.schedule(new ExpireSession(sessionTimer, session,
                       // this.app, ssls.getInetAddress()), 5*60*1000);
				System.out.print("client présent \n");
 
			}
 
}
Une fois lancé, je reçois les erreurs suivantes:
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
Erreur d'envoi javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.checkEOF(SSLSocketImpl.java:1476)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:92)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:154)
at java.io.BufferedReader.readLine(BufferedReader.java:317)
at java.io.BufferedReader.readLine(BufferedReader.java:382)
at Authentification_Par_Certificat.run(Authentification_Par_Certificat.java:44)
at java.lang.Thread.run(Thread.java:724)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:946)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1339)
at sun.security.ssl.SSLSocketImpl.getSession(SSLSocketImpl.java:2171)
at Accepter_connexion_Socket.initConnexion(Accepter_connexion_Socket.java:71)
at Accepter_connexion_Socket.run(Accepter_connexion_Socket.java:36)
... 1 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
at sun.security.ssl.InputRecord.read(InputRecord.java:482)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:927)
... 6 more