Salut,

j'essai d'établir une connexion avec un serveur HTTPS pour y créer des répertoires.

La fonction :

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
    public static String creer_rep(String hote, String login, String password, String chemin, String nom_repertoire) {
        try {
        //Configuration de l'hôte
        HostConfiguration hostConfig = new HostConfiguration();
        Protocol easyhttps = new Protocol("https",(ProtocolSocketFactory) new EasySSLProtocolSocketFactory(),443);
        Protocol.registerProtocol("https", easyhttps);
        hostConfig.setHost(hote, 443, easyhttps);
        //On défini un HttpConnectionManager, qui permet de gérer les connexions, et éventuellement le multithreading 
        HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        int maxHostConnections = 20;
        params.setMaxConnectionsPerHost(hostConfig, maxHostConnections);
        connectionManager.setParams(params);
        //On créé l'objet HttpClient et on lui passe les données d'authentification 
        HttpClient client = new HttpClient(connectionManager);
        client.setHostConfiguration(hostConfig);
        Credentials creds2 = new UsernamePasswordCredentials(login,password);
        client.getState().setCredentials(AuthScope.ANY, creds2);
 
        //Création du répertoire via la méthode MKCOL
        EntityEnclosingMethod mkcol = new EntityEnclosingMethod(chemin + nom_repertoire){
            public String getName() { return "MKCOL"; }
        };
        client.executeMethod(mkcol);
        System.out.println("Répertoire " + chemin + nom_repertoire + " créé avec succès.");
        mkcol.releaseConnection();
 
        return "OK";
        }
        catch(IOException ioe) {
            ioe.printStackTrace();
            return ioe.toString();
        }
    }
J'essai d'accepter tous les certificats "self-signed" grâce à la classe EasySSLProtocolSocketFactory fournit par Apache.

J'obtiens :

javax.net.ssl.SSLHandshakeException: java.security.cert.CertificateException: Could not find trusted certificate
Si je tente d'intégrer le chargement du certificat dans la classe EasySSLProtocolSocketFactory :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
     private static SSLContext createEasySSLContext() {
          try {
            Provider provider = Security.getProvider("SUN");
            KeyStore keyStore = KeyStore.getInstance("jks",provider);
            FileInputStream walletFile = new FileInputStream("/ORA/db001/syscontrol/etc/WALLETS/rdbms/cwallet.sso");
            keyStore.load(walletFile,"".toCharArray());
            walletFile.close();
            SSLContext context = SSLContext.getInstance("SSL");
            context.init(null, new TrustManager[] { new EasyX509TrustManager(keyStore) }, null);
            return context;
          } catch (Exception e) {
               throw new HttpClientError(e.toString());
          }
     }
J'obtiens :

org.apache.commons.httpclient.HttpClientError: java.io.IOException: Invalid keystore format
Le code run dans la base de données (Oracle 10G R2, JVM intégrée v1.4).

Si quelqu'un à une idée, mois je ne sais plus quoi faire.

Merci !