Bonjour,
Je me permets de poster car cela fais des heures que je tourne en rond sur ce problème, et un regard neuf sur mon problème ne ferait pas de tord. Et que je suis bientôt prêt à abandonner PHP pour passer à Java : p.
Je suis étudiant en sciences informatique et pour le moment en stage chez Vodafone Allemagne, dans un département IT B2B
La problématique :
Un serveur SOAP est en place et opérationnel, il possède toute une série de services auxquelles je tente d'accéder par l'intermédiaire d'un serveur PHP. Je travaille en local avec un serveur WAMP où j'ai bien activé mes extensions Soap, cURL et openSSL.
La connexion au serveur se fait en https://, cela requiert donc l'acceptation de son certificat (périmé en plus :/).
De plus, un certificat côté client est également demandé, avec un passphrase pour ce dernier.
Ce qui fait que je dois jouer avec deux certificats : Un coté serveur et un coté client.
J'ai trouvé une solution à ma problématique ici , que j'ai largement plagié.
Voici le code PHP (purgé des données et variables sensibles, désolé : ))
Qui me retourne un beau
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 <?php $wsdl = "fichier.wsdl"; $location = "https://...:20575"; $certsClient = "C:\wamp\www\vodafone\keys.pem"; $passPhraseClient = "..."; $certsServeur = "C:\wamp\www\vodafone\CERT.pem"; $context = stream_context_create(array("ssl" => array("verify_peer" => true,"cafile" => $certsServeur))); $client = new SoapClient($wsdl,array("trace" => 1,"soap_version" => SOAP_1_1,"location" => $location,"local_cert" => $certsClient,'passphrase' => $passPhraseClient,"stream_context" => $context)); $client->leNomDuneFonction(array("..." =>"...","..." => "...")); ?>
Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in C:\wamp\www\vodafone\soapclient.php
Alors qu'une version similaire en Java fonctionne, elle :
Et les envois avec SoapUI fonctionnent également.
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 public class ACRConverter { public final static String DEFAULT_SERVER = "https://...:20575"; public final static String SOAP_ACTION = "..."; public final static String CLIENT_CERTIFICATE = "C:\\wamp\\www\\vodafone\\Test_Partner_PreProd_Certificate.pfx"; public final static String CLIENT_CERTIFICATE_PASSWORD = "..."; public final static String ACR_INPUT_FILE = "C:\\wamp\\www\\vodafone\\ACRs.txt"; public final static String MSISDN_OUTPUT_FILE = "C:\\wamp\\www\\vodafone\\MSISNDs.txt"; private static SSLSocketFactory getFactory(File pKeyFile, String pKeyPassword) throws Exception { KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("SunX509"); KeyStore keyStore = KeyStore.getInstance("PKCS12"); InputStream keyInput = new FileInputStream(pKeyFile); keyStore.load(keyInput, pKeyPassword.toCharArray()); keyInput.close(); keyManagerFactory.init(keyStore, pKeyPassword.toCharArray()); SSLContext context = SSLContext.getInstance("TLS"); context.init(keyManagerFactory.getKeyManagers(), null, new SecureRandom()); return context.getSocketFactory(); } public static void main(String[] args) { String server = DEFAULT_SERVER; try { // open parameter file FileInputStream fstream = new FileInputStream(ACR_INPUT_FILE); DataInputStream input_file_in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(input_file_in)); // Open output file for responses BufferedWriter output_file_out = new BufferedWriter(new FileWriter(MSISDN_OUTPUT_FILE)); // Prepare connection to service URL url = new URL(server); // Read File Line By Line String s; while ((s = br.readLine()) != null) { System.out.println(s); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); connection.setSSLSocketFactory(getFactory(new File(CLIENT_CERTIFICATE), CLIENT_CERTIFICATE_PASSWORD)); connection.setDoOutput(true); connection.setDoInput(true); connection.setRequestMethod("POST"); connection.setRequestProperty("SOAPAction", SOAP_ACTION); OutputStream out = connection.getOutputStream(); Writer wout = new OutputStreamWriter(out); // Send request wout.write("<soapenv:Envelope xmlns:v=\"http://...\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\">"); wout.write("<soapenv:Header/>"); wout.write("<soapenv:Body>"); wout.write("<v:..."); wout.write("<v:...><![CDATA[" + ... + "]]></v:...>"); wout.write("</v:...>"); wout.write("</soapenv:Body>"); wout.write("</soapenv:Envelope>"); wout.flush(); wout.close(); // Get response InputStream in = connection.getInputStream(); int c; while ((c = in.read()) != -1) { output_file_out.write(c); } in.close(); // Wait a second to reduce load Thread.sleep(1000); } // Close the file with ACR list input_file_in.close(); // Close the file with the MSISDNs output_file_out.close(); } catch (Exception e) { System.err.println(e); } } }
Qu'ai-je fait de mal : (
EDIT : Testé également sur un dédié perso et sur un hébergement mutualisé OVH, rien n'y fait, toujours la même erreur.
Partager