Accès à un WS sécurisé - version http non supportée + "No Security Header in message"
Bonjour à tous,
Je bloque sur ce problème depuis 2 jours, et malheureusement je n'arrive pas à isoler l'origine de celui-ci.
Je dois développer créer et déployer des web services sécurisés en JEE via Netbeans 6.0, Metro WSIT, et le serveur d'applications apache tomcat 5.5. :lol:
Ceux-ci doivent être accessibles et facilement utilisables depuis un projet Visual Studio 2005.
Je pense avoir correctement réussi la config de mon serveur d'appli, (ajout des bonnes librairies, création keystore, certificat via l'outil java "keytool", etc...)
Quand je déploie un web service classique, aucun problème, VS le reconnait et l'exploite facilement.
Si j'ajoute de la sécuration https (SSL), encore une fois, cela réussit.
THE problem:
Si je modifie mon Service pour que celui-ci demande une authentification basique (nom d'utilisateur et mot de passe définis dans un fichier de config d'Apache Tomcat), je parviens à ajouter la Web Référence à mon projet VS, mais voici ce que j'obtiens à l'exécution:
Citation:
L'exception System.Net.WebException n'a pas été gérée
Message="La demande a échoué avec l'état HTTP 505 : Version HTTP Non Supportée."
Source="System.Web.Services"
StackTrace:
à System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
à WindowsApplication1.WebReference.ServicesService.operation(Int32 p1, Int32 p2, Int32 p3) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Web References\WebReference\Reference.cs:ligne 79
à WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Form1.cs:ligne 41
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ButtonBase.WndProc(Message& m)
à System.Windows.Forms.Button.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(Form mainForm)
à WindowsApplication1.Program.Main() dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Program.cs:ligne 17
à System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
Je fournis également le code qui fait appel à ce Web Service:
Code:
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
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WindowsApplication1.WebReference;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Security.Cryptography.X509Certificates;
using System.Net;
using System.Net.Security;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// On indique la validation automatique des
// demandes d'acceptation des certificats
System.Net.ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificateCallback;
// Instanciation de la classe proxy permettant
// l'appel distant au Webservice
ServicesService vWSClient = new ServicesService();
// vWSClient.Timeout = -1;
// Définir les données d'identification
vWSClient.Credentials = new NetworkCredential("wsuid", "wspwd");
// Appel au Web Service
wsLocation[] vList = vWSClient.operation(1, 2, 3);
int vNbEl = vList == null ? 0 : vList.Length;
MessageBox.Show("taille de la liste : " + vNbEl);
}
public static bool TrustAllCertificateCallback(object sender,
X509Certificate cert, X509Chain chain, SslPolicyErrors errors)
{
return true;
}
}
} |
Si vous avez une idée, je suis preneur. Je suis complètement paralysé. :?
Dans cette situation, le problème ne vient peut etre pas de Visual Studio, là est toute la difficulté, si vous pouviez tout de même me communiquer votre avis ;)
Merci beaucoup.
Solution trouvée, mais nouvelle quête... :)
J'ai résolu le problème de l'erreur 505. C'était apparemment du à tomcat. Problème de reconnaissance entre http 1.0 et 1.1.
Pour que http 1.1 soit correctement supporté il m'a fallu ajouter ce code:
Code:
1 2 3 4 5 6 7 8 9 10
|
[...]
System.Net.ServicePointManager.ServerCertificateValidationCallback = TrustAllCertificateCallback;
ServicePointManager.Expect100continue = false;
// Instanciation de la classe proxy permettant
// l'appel distant au Webservice
ServicesService vWSClient = new ServicesService();
[...] |
Pour le nouveau problème, cette fois-ci les modifications sont peut-être à mener du coté serveur, je vous l'expose tout de même.
Le web service est accessible et fonctionnel lorsque je ne passe pas par l'assistant netbeans pour configurer la sécurisation (c'est à dire en bidouillant juste mon web.xml).
Si j'essaie de suivre la démarche officielle de l'assistant (choix du mode de sécurisation, choix de l'algorithme de cryptage, etc...) l'on m'adresse un warning:
Citation:
"Avertissement de l'outil personnalisé: Au moins une importation ServiceDescriptionFormatExtension facultative a été ignorée"
A l'exécution, j'obtiens une exception
Citation:
System.Web.Services.Protocols.SoapException, "Security Requirements not met - No Security header in message".
Citation:
L'exception System.Web.Services.Protocols.SoapException n'a pas été gérée
Message="Security Requirements not met - No Security header in message"
Source="System.Web.Services"
Actor=""
Lang=""
Node=""
Role=""
StackTrace:
à System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
à System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
à WindowsApplication1.WebReference.ServicesService.operation(Int32 p1, Int32 p2, Int32 p3) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Web References\WebReference\Reference.cs:ligne 80
à WindowsApplication1.Form1.button1_Click(Object sender, EventArgs e) dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Form1.cs:ligne 41
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ButtonBase.WndProc(Message& m)
à System.Windows.Forms.Button.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(Form mainForm)
à WindowsApplication1.Program.Main() dans E:\Mes documents\Visual Studio Projects\WindowsApplication1\WindowsApplication1\Program.cs:ligne 17
à System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
à System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
à Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
à System.Threading.ThreadHelper.ThreadStart_Context(Object state)
à System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
à System.Threading.ThreadHelper.ThreadStart()
Coté développement du web service sous netbeans, lorsque je suis la démarche rigoureuse de sécurisation, le fichier wsit-webservices.Services.xml change considérablement:
wsit-webservices.Services.xml en contournant l'assistant visuel de netbeans (pas de détail pour l'encryptage des données, etc.):
Code:
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
|
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ServicesService" targetNamespace="http://webservices/" xmlns:tns="http://webservices/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy"
>
<message name="operation"/>
<message name="operationResponse"/>
<portType name="Services">
<operation name="operation">
<input message="tns:operation"/>
<output message="tns:operationResponse"/>
</operation>
</portType>
<binding name="ServicesPortBinding" type="tns:Services">
<operation name="operation">
<input></input>
<output></output>
</operation>
</binding>
<service name="ServicesService">
<port name="ServicesPort" binding="tns:ServicesPortBinding"/>
</service>
</definitions> |
wsit-webservices.Services.xml en passant par l'assistant design Services de Netbeans:
- Message authentication over SSL
- Authentication token: Username
- WSS Version: 1.0
- Algorithm Suite: Basic 128 bits
- Security Header layout: Lax
- Establish secure session: non cochée
- Encrypt signature: non cochée
Code:
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
|
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="ServicesService" targetNamespace="http://webservices/" xmlns:tns="http://webservices/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsaws="http://www.w3.org/2005/08/addressing" xmlns:sc="http://schemas.sun.com/2006/03/wss/server" xmlns:wspp="http://java.sun.com/xml/ns/wsit/policy" xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy"
>
<message name="operation"/>
<message name="operationResponse"/>
<portType name="Services">
<operation name="operation">
<input message="tns:operation"/>
<output message="tns:operationResponse"/>
</operation>
</portType>
<binding name="ServicesPortBinding" type="tns:Services">
<wsp:PolicyReference URI="#ServicesPortBindingPolicy"/>
<operation name="operation">
<input></input>
<output></output>
</operation>
</binding>
<service name="ServicesService">
<port name="ServicesPort" binding="tns:ServicesPortBinding"/>
</service>
<wsp:Policy wsu:Id="ServicesPortBindingPolicy">
<wsp:ExactlyOne>
<wsp:All>
<wsaws:UsingAddressing xmlns:wsaws="http://www.w3.org/2006/05/addressing/wsdl"/>
<sp:TransportBinding>
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false"/>
</wsp:Policy>
</sp:TransportToken>
<sp:Layout>
<wsp:Policy>
<sp:Lax/>
</wsp:Policy>
</sp:Layout>
<sp:IncludeTimestamp/>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic128/>
</wsp:Policy>
</sp:AlgorithmSuite>
</wsp:Policy>
</sp:TransportBinding>
<sp:Wss10>
<wsp:Policy>
<sp:MustSupportRefKeyIdentifier/>
</wsp:Policy>
</sp:Wss10>
<sp:SignedSupportingTokens>
<wsp:Policy>
<sp:UsernameToken sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient">
<wsp:Policy>
<sp:WssUsernameToken10/>
</wsp:Policy>
</sp:UsernameToken>
</wsp:Policy>
</sp:SignedSupportingTokens>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
</definitions> |
Voila, c'est à peu près tout, je suis entrain de vérifier ma configuration coté serveur d'applications, support web services, etc... Je vous tiens au courant.
Merci