SslStreamSecurityBindingElement Klasa

Definicja

Reprezentuje niestandardowy element powiązania, który obsługuje zabezpieczenia kanału przy użyciu strumienia SSL.

public ref class SslStreamSecurityBindingElement : System::ServiceModel::Channels::BindingElement
public ref class SslStreamSecurityBindingElement : System::ServiceModel::Channels::StreamUpgradeBindingElement
public ref class SslStreamSecurityBindingElement : System::ServiceModel::Channels::StreamUpgradeBindingElement, System::ServiceModel::Channels::ITransportTokenAssertionProvider, System::ServiceModel::Description::IPolicyExportExtension
public class SslStreamSecurityBindingElement : System.ServiceModel.Channels.BindingElement
public class SslStreamSecurityBindingElement : System.ServiceModel.Channels.StreamUpgradeBindingElement
public class SslStreamSecurityBindingElement : System.ServiceModel.Channels.StreamUpgradeBindingElement, System.ServiceModel.Channels.ITransportTokenAssertionProvider, System.ServiceModel.Description.IPolicyExportExtension
type SslStreamSecurityBindingElement = class
    inherit BindingElement
type SslStreamSecurityBindingElement = class
    inherit StreamUpgradeBindingElement
type SslStreamSecurityBindingElement = class
    inherit StreamUpgradeBindingElement
    interface ITransportTokenAssertionProvider
    interface IPolicyExportExtension
Public Class SslStreamSecurityBindingElement
Inherits BindingElement
Public Class SslStreamSecurityBindingElement
Inherits StreamUpgradeBindingElement
Public Class SslStreamSecurityBindingElement
Inherits StreamUpgradeBindingElement
Implements IPolicyExportExtension, ITransportTokenAssertionProvider
Dziedziczenie
SslStreamSecurityBindingElement
Dziedziczenie
SslStreamSecurityBindingElement
Implementuje

Uwagi

Transporty korzystające z protokołu zorientowanego na strumień, takiego jak TCP i nazwane potoki, obsługują uaktualnienia transportu opartego na strumieniu. W szczególności program Windows Communication Foundation (WCF) zapewnia uaktualnienia zabezpieczeń. Konfiguracja tego zabezpieczeń transportu jest hermetyzowana przez tę klasę, a także przez SslStreamSecurityBindingElementprogram , który można skonfigurować i dodać do powiązania niestandardowego. Ponadto inna firma może napisać własne niestandardowe StreamSecurityBindingElementpolecenie . Te elementy powiązania rozszerzają klasę wywoływaną StreamUpgradeBindingElement w celu utworzenia dostawców uaktualniania strumienia klienta i serwera.

Powiązanie niestandardowe zawiera kolekcję elementów powiązań rozmieszczonych w określonej kolejności: element reprezentujący górną część stosu powiązań jest dodawany najpierw, następny element w stosie powiązań jest dodawany drugi i tak dalej.

Aby dodać tę klasę do powiązania

  1. Utwórz element BindingElementCollection.

  2. Utwórz niestandardowe elementy powiązania powyżej tego elementu powiązania w stosie powiązań, takie jak opcjonalne TransactionFlowBindingElement i ReliableSessionBindingElement.

  3. Dodaj utworzone elementy w kolejności opisanej wcześniej do BindingElementCollection metody using .InsertItem

  4. Utwórz wystąpienie obiektu SslStreamSecurityBindingElement i dodaj je do kolekcji.

  5. Dodaj do kolekcji dodatkowe niestandardowe elementy powiązania, takie jak TcpTransportBindingElement.

Istnieją trzy scenariusze, w których należy ręcznie określić poprawną nazwę UPN/nazwę SPN w punkcie końcowym klienta po zaimportowaniu WSDL lub określić niestandardowy IdentityVerifier parametr na kliencie SslStreamSecurityBindingElement.

  1. Żadna tożsamość usługi nie jest publikowana w języku WSDL. SspiNegotiatedOverTransport i HTTPS są używane (na przykład WSHttpBinding z wartością SecurityMode = TransportWithMessageCredential). Jeśli usługa nie jest uruchomiona z tożsamością komputera, należy ręcznie określić poprawną nazwę UPN/spN w punkcie końcowym klienta po zaimportowaniu WSDL.

  2. Tożsamość usługi DNS jest publikowana w języku WSDL. SspiNegotiatedOverTransport i SslStreamSecurityBindingElement są używane (na przykład NetTcpBinding z wartością SecurityMode = TransportWithMessageCredential) zamiast nazwy UPN/SPN. Jeśli usługa nie jest uruchomiona z tożsamością komputera lub tożsamość DNS nie jest tożsamością maszyny, należy ręcznie określić poprawną nazwę UPN/SPN w punkcie końcowym klienta po zaimportowaniu WSDL.

  3. Tożsamość DNS jest publikowana w języku WSDL. Jeśli SslStreamSecurityBindingElement element jest zastępowany na kliencie, musisz określić niestandardowy element IdentityVerifier na komputerze klienckim SslStreamSecurityBindingElement.

Poniższy kod pokazuje, jak ręcznie określić poprawną nazwę UPN/nazwę SPN w punkcie końcowym klienta, a także sposób określania niestandardowego IdentityVerifier na kliencie SslStreamSecurityBindingElement.

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Net;  
using System.IdentityModel.Claims;  
using System.IdentityModel.Policy;  
using System.Security.Cryptography.X509Certificates;  
using System.ServiceModel;  
using System.ServiceModel.Channels;  
using System.ServiceModel.Description;  
using System.ServiceModel.Security;  
using System.Xml;  

namespace ServiceNamespace  
{  
    [ServiceContract]  
    interface IService  
    {  
        [OperationContract]  
        void DoSomething();  
    }  

    class DnsIdentityVerifier : IdentityVerifier  
    {  
        DnsEndpointIdentity _expectedIdentity;  

        public DnsIdentityVerifier(EndpointAddress serviceEndpoint)  
        {  
            _expectedIdentity = new DnsEndpointIdentity(serviceEndpoint.Uri.DnsSafeHost);  
        }  

        public override bool CheckAccess(EndpointIdentity identity, AuthorizationContext authContext)  
        {  
            Claim dnsClaim = authContext.Claims().Single(claim => claim.ClaimType == ClaimTypes.Dns);  
            return String.Equals(_expectedIdentity.IdentityClaim.Resource, dnsClaim.Resource);  
        }  

        public override bool TryGetIdentity(EndpointAddress reference, out EndpointIdentity identity)  
        {  
            identity = _expectedIdentity;  
            return true;  
        }  
    }  

    static class LinqExtensionForClaims  
    {  
        public static IEnumerable<Claim> Claims(this AuthorizationContext authContext)  
        {  
            if (null != authContext.ClaimSets)  
            {  
                foreach (ClaimSet claimSet in authContext.ClaimSets)  
                {  
                    if (null != claimSet)  
                    {  
                        foreach (Claim claim in claimSet)  
                        {  
                            yield return claim;  
                        }  
                    }  
                }  
            }  
        }  
    }  

    class Service : IService  
    {  
        public void DoSomething()  
        {  
            Console.WriteLine("Service called.");  
        }  
    }  

    class Program  
    {  
        static void Main(string[] args)  
        {  
            string hostname = Dns.GetHostEntry(String.Empty).HostName;  
            NetTcpBinding serviceBinding = new NetTcpBinding(SecurityMode.TransportWithMessageCredential);  

            ServiceHost serviceHost = new ServiceHost(typeof(Service), new Uri(String.Format("net.tcp://{0}:8080/Service", hostname)));  
            serviceHost.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindByThumbprint, "8a 42 1b eb cf 8a 14 b1 de 83 d9 a5 70 88 0a 62 f9 bf 69 06");  
            ServiceEndpoint serviceEndpoint = serviceHost.AddServiceEndpoint(typeof(IService), serviceBinding, "Endpoint");  
            serviceHost.Open();  

            CustomBinding clientBinding = new CustomBinding(serviceBinding.CreateBindingElements());  
            SslStreamSecurityBindingElement sslStream = clientBinding.Elements.Find<SslStreamSecurityBindingElement>();  
            sslStream.IdentityVerifier = new DnsIdentityVerifier(serviceEndpoint.Address);  

            ChannelFactory<IService> channelFactory = new ChannelFactory<IService>(clientBinding, new EndpointAddress(serviceEndpoint.Address.Uri, UpnEndpointIdentity.CreateUpnIdentity("username@domain")));  
            channelFactory.Credentials.Windows.AllowNtlm = false;  
            IService channel = channelFactory.CreateChannel();  
            channel.DoSomething();  
        }  
    }  

Konstruktory

SslStreamSecurityBindingElement()

Inicjuje nowe wystąpienie klasy SslStreamSecurityBindingElement.

SslStreamSecurityBindingElement(SslStreamSecurityBindingElement)

Inicjuje SslStreamSecurityBindingElement nowe wystąpienie klasy przy użyciu wartości z innej SslStreamSecurityBindingElementklasy .

Właściwości

IdentityVerifier

Pobiera lub ustawia weryfikator tożsamości dla tego powiązania.

RequireClientCertificate

Pobiera lub ustawia wartość określającą, czy certyfikat klienta jest wymagany dla tego powiązania.

SslProtocols

Określa listę protokołów SSL/TLS do negocjowania podczas korzystania z typu poświadczeń klienta TcpClientCredentialType.Certificate. Wartość może być kombinacją jednego z następujących elementów członkowskich wyliczenia: Ssl3, Tls, Tls11, Tls12.

Metody

BuildChannelFactory<TChannel>(BindingContext)

Tworzy fabrykę kanałów określonego typu.

BuildChannelListener<TChannel>(BindingContext)

Tworzy odbiornik kanału określonego typu.

BuildChannelListener<TChannel>(BindingContext)

Inicjuje odbiornik kanału, aby akceptował kanały określonego typu z kontekstu powiązania.

(Odziedziczone po BindingElement)
BuildClientStreamUpgradeProvider(BindingContext)

Tworzy wystąpienie na kliencie na podstawie podanego StreamUpgradeProvider kontekstu kanału.

BuildServerStreamUpgradeProvider(BindingContext)

Tworzy wystąpienie na serwerze na podstawie podanego StreamUpgradeProvider kontekstu kanału.

BuildServerStreamUpgradeProvider(BindingContext)

Tworzy wystąpienie na serwerze na podstawie podanego StreamUpgradeProvider kontekstu kanału.

(Odziedziczone po StreamUpgradeBindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

Pobiera wartość wskazującą, czy można skompilować fabrykę kanałów określonego typu.

CanBuildChannelListener<TChannel>(BindingContext)

Pobiera wartość wskazującą, czy można skompilować odbiornik kanału określonego typu.

CanBuildChannelListener<TChannel>(BindingContext)

Zwraca wartość wskazującą, czy element powiązania może skompilować odbiornik dla określonego typu kanału.

(Odziedziczone po BindingElement)
Clone()

Tworzy nowe wystąpienie, które jest kopią bieżącego wystąpienia.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetProperty<T>(BindingContext)

Pobiera określony obiekt z obiektu BindingContext.

GetTransportTokenAssertion()

XmlElement Pobiera element reprezentujący token transportu używany w powiązaniu zabezpieczeń.

GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ShouldSerializeIdentityVerifier()

Pobiera wartość wskazującą, czy weryfikator identyfikacji powinien być serializowany.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

Eksportuje niestandardowe potwierdzenie zasad dotyczące powiązań.

Dotyczy