Notes
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
Cet article décrit l’utilisation de certificats X.509 pour l’authentification du serveur et du client lors de l’utilisation de la sécurité de transport. Pour plus d’informations sur les certificats X.509, consultez certificats de clé publique X.509. Les certificats doivent être émis par une autorité de certification, qui est souvent un émetteur tiers de certificats. Sur un domaine Windows Server, les services de certificats Active Directory peuvent être utilisés pour émettre des certificats à des ordinateurs clients sur le domaine. Dans ce scénario, le service est hébergé sous Internet Information Services (IIS) qui est configuré avec SSL (Secure Sockets Layer). Le service est configuré avec un certificat SSL (X.509) pour permettre aux clients de vérifier l’identité du serveur. Le client est également configuré avec un certificat X.509 qui permet au service de vérifier l’identité du client. Le certificat du serveur doit être approuvé par le client et le certificat du client doit être approuvé par le serveur. La mécanique réelle de la façon dont le service et le client vérifie l’identité des uns des autres dépasse la portée de cet article. Pour plus d’informations, consultez Signature numérique sur Wikipédia.
Ce scénario implémente un modèle de message de demande/réponse, comme illustré par le diagramme suivant.
Pour plus d’informations sur l’utilisation d’un certificat avec un service, consultez Utilisation de certificats et guide pratique pour configurer un port avec un certificat SSL. Le tableau suivant décrit les différentes caractéristiques du scénario.
Caractéristique | Descriptif |
---|---|
Mode de sécurité | Transport |
Interopérabilité | Avec les clients et services Web existants. |
Authentification (serveur) Authentification (client) |
Oui (à l’aide d’un certificat SSL) Oui (à l’aide d’un certificat X.509) |
Intégrité des données | Oui |
Confidentialité des données | Oui |
Transport | HTTPS |
Reliure | WSHttpBinding |
Configurer le service
Étant donné que le service dans ce scénario est hébergé sous IIS, il est configuré avec un fichier web.config. La web.config suivante montre comment configurer le WSHttpBinding pour utiliser la sécurité du transport et les informations d'identification du client X.509.
<configuration>
<system.serviceModel>
<protocolMapping>
<add scheme="https" binding="wsHttpBinding" />
</protocolMapping>
<bindings>
<wsHttpBinding>
<!-- configure wsHttp binding with Transport security mode and clientCredentialType as Certificate -->
<binding>
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
<behaviors>
<serviceBehaviors>
<behavior>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Configurer le client
Le client peut être configuré dans du code ou dans un fichier app.config. L’exemple suivant montre comment configurer le client dans le code.
// Create the binding.
var myBinding = new WSHttpBinding();
myBinding.Security.Mode = SecurityMode.Transport;
myBinding.Security.Transport.ClientCredentialType =
HttpClientCredentialType.Certificate;
// Create the endpoint address. Note that the machine name
// must match the subject or DNS field of the X.509 certificate
// used to authenticate the service.
var ea = new
EndpointAddress("https://localhost/CalculatorService/service.svc");
// Create the client. The code for the calculator
// client is not shown here. See the sample applications
// for examples of the calculator code.
var cc =
new CalculatorClient(myBinding, ea);
// The client must specify a certificate trusted by the server.
cc.ClientCredentials.ClientCertificate.SetCertificate(
StoreLocation.CurrentUser,
StoreName.My,
X509FindType.FindBySubjectName,
"contoso.com");
// Begin using the client.
Console.WriteLine(cc.Add(100, 1111));
//...
cc.Close();
Vous pouvez également configurer le client dans un fichier App.config, comme illustré dans l’exemple suivant :
<configuration>
<system.serviceModel>
<client>
<!-- this endpoint has an https: address -->
<endpoint address=" https://localhost/CalculatorService/service.svc "
behaviorConfiguration="endpointCredentialBehavior"
binding="wsHttpBinding"
bindingConfiguration="Binding1"
contract="Microsoft.Samples.TransportSecurity.ICalculator"/>
</client>
<behaviors>
<endpointBehaviors>
<behavior name="endpointCredentialBehavior">
<clientCredentials>
<clientCertificate findValue="contoso.com"
storeLocation="CurrentUser"
storeName="My"
x509FindType="FindBySubjectName" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<!-- configure wsHttpbinding with Transport security mode
and clientCredentialType as Certificate -->
<binding name="Binding1">
<security mode="Transport">
<transport clientCredentialType="Certificate"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>