Share via


SslStreamSecurityBindingElement Třída

Definice

Představuje vlastní prvek vazby, který podporuje zabezpečení kanálu pomocí streamu 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
Dědičnost
SslStreamSecurityBindingElement
Dědičnost
SslStreamSecurityBindingElement
Implementuje

Poznámky

Přenosy, které používají protokol orientovaný na stream, jako je TCP a pojmenované kanály, podporují upgrady přenosu založené na datových proudech. Konkrétně windows Communication Foundation (WCF) poskytuje upgrady zabezpečení. Konfigurace tohoto zabezpečení přenosu je zapouzdřena touto třídou a také nástrojem SslStreamSecurityBindingElement, který lze nakonfigurovat a přidat do vlastní vazby. Kromě toho může třetí strana napsat vlastní StreamSecurityBindingElement. Tyto prvky vazby StreamUpgradeBindingElement rozšiřují třídu, která je volána k sestavení zprostředkovatelů upgradu z klientských a serverových datových proudů.

Vlastní vazba obsahuje kolekci prvků vazby uspořádaných v určitém pořadí: element, který představuje horní část zásobníku vazeb, je přidán jako první, další prvek dolů v zásobníku vazeb je přidán druhý atd.

Přidání této třídy do vazby

  1. Vytvořte BindingElementCollection.

  2. Vytvořte vlastní prvky vazby, které jsou nad tímto elementem vazby v zásobníku vazby, například volitelné TransactionFlowBindingElement a ReliableSessionBindingElement.

  3. Pomocí metody přidejte vytvořené prvky v pořadí popsaném BindingElementCollectionInsertItem výše.

  4. Vytvořte instanci SslStreamSecurityBindingElement a přidejte ji do kolekce.

  5. Přidejte do kolekce další vlastní prvky vazby, například TcpTransportBindingElement.

Existují tři scénáře, ve kterých musíte buď ručně zadat správný hlavní název uživatele nebo hlavní název služby (UPN)/SPN v koncovém bodu klienta po importu WSDL, nebo zadat vlastní IdentityVerifier název na straně klienta SslStreamSecurityBindingElement.

  1. Ve WSDL není publikována žádná identita služby. SspiNegotiatedOverTransport a HTTPS (například WSHttpBinding s SecurityMode = TransportWithMessageCredential). Pokud služba není spuštěná s identitou počítače, musíte po importu WSDL ručně zadat správný hlavní název uživatele (UPN/SPN) v koncovém bodu klienta.

  2. Identita služby DNS je publikovaná ve WSDL. SspiNegotiatedOverTransport a SslStreamSecurityBindingElement se používají (například NetTcpBinding s SecurityMode = TransportWithMessageCredential) místo hlavního názvu uživatele (UPN/SPN). Pokud služba není spuštěná s identitou počítače nebo identita DNS není identitou počítače, musíte po importu WSDL v koncovém bodu klienta ručně zadat správný hlavní název uživatele (UPN/SPN).

  3. Identita DNS se publikuje ve WSDL. Pokud SslStreamSecurityBindingElement je v klientovi přepsán, je nutné zadat vlastní IdentityVerifier v klientovi SslStreamSecurityBindingElement.

Následující kód ukazuje, jak ručně zadat správný hlavní název uživatele (UPN) nebo hlavní název služby (SPN) v koncovém bodu klienta a také jak zadat vlastní IdentityVerifier název v klientovi 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()

Inicializuje novou instanci SslStreamSecurityBindingElement třídy.

SslStreamSecurityBindingElement(SslStreamSecurityBindingElement)

Inicializuje novou instanci SslStreamSecurityBindingElement třídy pomocí hodnot z jiné .SslStreamSecurityBindingElement

Vlastnosti

IdentityVerifier

Získá nebo nastaví ověřovatel identity pro tuto vazbu.

RequireClientCertificate

Získá nebo nastaví hodnotu, která určuje, zda klientský certifikát je požadován pro tuto vazbu.

SslProtocols

Určuje seznam protokolů SSL/TLS, které se mají vyjednat při použití typu přihlašovacích údajů klienta TcpClientCredentialType.Certificate. Hodnota může být kombinací jednoho z několika následujících členů výčtu: Ssl3, Tls, Tls11, Tls12.

Metody

BuildChannelFactory<TChannel>(BindingContext)

Vytvoří objekt pro vytváření kanálů zadaného typu.

BuildChannelListener<TChannel>(BindingContext)

Vytvoří naslouchací proces kanálu zadaného typu.

BuildChannelListener<TChannel>(BindingContext)

Inicializuje naslouchací proces kanálu pro příjem kanálů zadaného typu z kontextu vazby.

(Zděděno od BindingElement)
BuildClientStreamUpgradeProvider(BindingContext)

Vytvoří instanci v klientovi na StreamUpgradeProvider základě zadaného kontextu kanálu.

BuildServerStreamUpgradeProvider(BindingContext)

Vytvoří instanci na serveru na základě zadaného StreamUpgradeProvider kontextu kanálu.

BuildServerStreamUpgradeProvider(BindingContext)

Vytvoří instanci na serveru na základě zadaného StreamUpgradeProvider kontextu kanálu.

(Zděděno od StreamUpgradeBindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

Získá hodnotu, která označuje, zda kanál factory zadaného typu lze sestavit.

CanBuildChannelListener<TChannel>(BindingContext)

Získá hodnotu, která označuje, zda kanál naslouchací proces zadaného typu lze sestavit.

CanBuildChannelListener<TChannel>(BindingContext)

Vrátí hodnotu, která označuje, zda element vazby může vytvořit naslouchací proces pro konkrétní typ kanálu.

(Zděděno od BindingElement)
Clone()

Vytvoří novou instanci, která je kopií aktuální instance.

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetProperty<T>(BindingContext)

Získá zadaný objekt z objektu BindingContext.

GetTransportTokenAssertion()

XmlElement Získá, který představuje token přenosu použitý ve vazbě zabezpečení.

GetType()

Získá aktuální Type instanci.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ShouldSerializeIdentityVerifier()

Získá hodnotu, která označuje, zda by měl být serializován identifikační ověřovatel.

ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

Exportuje vlastní kontrolní výraz zásad o vazbách.

Platí pro