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é SslStreamSecurityBindingElement, které lze nakonfigurovat a přidat do vlastní vazby. Kromě toho může třetí strana napsat vlastní .StreamSecurityBindingElement Tyto prvky vazby rozšiřují třídu, která je volána k sestavení zprostředkovatelů upgradu datového StreamUpgradeBindingElement proudu klienta a serveru.

Vlastní vazba obsahuje kolekci prvků vazby uspořádaných v určitém pořadí: element, který představuje začátek 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ření souboru BindingElementCollection.

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

  3. Přidejte vytvořené prvky v pořadí popsaném výše do BindingElementCollection metody.InsertItem

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

  5. Přidejte do kolekce všechny 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) na koncovém bodu klienta po importu WSDL, nebo zadat vlastní název IdentityVerifier klienta SslStreamSecurityBindingElement.

  1. Ve WSDL se nepublikuje žádná identita služby. SspiNegotiatedOverTransport a HTTPS se používají (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 a hlavní název služby (UPN)/SPN.

  2. Identita služby DNS se publikuje ve WSDL. SspiNegotiatedOverTransport a SslStreamSecurityBindingElement používají se (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 ručně zadat správný hlavní název uživatele nebo hlavní název služby (UPN)/SPN.

  3. Identita DNS se publikuje ve WSDL. Pokud SslStreamSecurityBindingElement je přepsán v klientovi, 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 a hlavní název služby (UPN)/SPN v koncovém bodu klienta a jak zadat vlastní název IdentityVerifier klienta 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

Name Description
SslStreamSecurityBindingElement()

Inicializuje novou instanci SslStreamSecurityBindingElement třídy.

SslStreamSecurityBindingElement(SslStreamSecurityBindingElement)

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

Vlastnosti

Name Description
IdentityVerifier

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

RequireClientCertificate

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

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 více z následujících členů výčtu: Ssl3, Tls, Tls11, Tls12.

Metody

Name Description
BuildChannelFactory<TChannel>(BindingContext)

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

BuildChannelListener<TChannel>(BindingContext)

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

BuildClientStreamUpgradeProvider(BindingContext)

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

BuildServerStreamUpgradeProvider(BindingContext)

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

CanBuildChannelFactory<TChannel>(BindingContext)

Získá hodnotu, která určuje, zda lze sestavit objekt pro vytváření kanálů zadaného typu.

CanBuildChannelListener<TChannel>(BindingContext)

Získá hodnotu, která určuje, zda je možné sestavit naslouchací proces kanálu zadaného typu.

Clone()

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

Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

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

Slouží jako výchozí funkce hash.

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

Získá zadaný objekt z objektu BindingContext.

GetTransportTokenAssertion()

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

GetType()

Získá Type aktuální instance.

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

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

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

Získá hodnotu, která určuje, zda identifikovat ověřitel má být serializován.

ToString()

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

(Zděděno od Object)

Explicitní implementace rozhraní

Name Description
IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

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

Platí pro