SslStreamSecurityBindingElement クラス

定義

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
継承
SslStreamSecurityBindingElement
継承
SslStreamSecurityBindingElement
実装

注釈

TCP などのストリーム指向プロトコルおよび名前付きパイプを使用するトランスポートは、ストリーム ベースのトランスポート アップグレードをサポートします。 具体的には、Windows Communication Foundation (WCF) はセキュリティ アップグレードを提供します。 このトランスポート セキュリティの構成は、このクラスおよび SslStreamSecurityBindingElement によってカプセル化され、構成してカスタム バインディングに追加できます。 さらに、サードパーティは独自のカスタム StreamSecurityBindingElement を作成できます。 これらのバインド要素は、クライアントとサーバーのストリーム アップグレード プロバイダーを作成するために呼び出される StreamUpgradeBindingElement クラスを拡張します。

カスタム バインドには、特定の順序で配置されたバインド要素のコレクションが含まれます。バインド スタックの一番上を表す要素が最初に追加され、バインド スタックの 1 つ下の要素が 2 番目に追加される、という順序で配置されます。

このクラスをバインドに追加するには

  1. BindingElementCollection を作成します。

  2. オプションの TransactionFlowBindingElementReliableSessionBindingElement など、バインド スタックでこのバインド要素の上になるカスタム バインド要素を作成します。

  3. BindingElementCollection メソッドを使用して、作成した要素を前に述べた順序で InsertItem に追加します。

  4. SslStreamSecurityBindingElement インスタンスを作成して、コレクションに追加します。

  5. TcpTransportBindingElement など、追加のカスタム バインド要素があればコレクションに追加します。

WSDL のインポート後にクライアント エンドポイントで正しい UPN/SPN を手動で指定するか、クライアントの SslStreamSecurityBindingElementでカスタムIdentityVerifierを指定する必要がある 3 つのシナリオがあります。

  1. サービス ID が WSDL で公開されない場合。 SspiNegotiatedOverTransport と HTTPS が使用されます (たとえば、SecurityMode = WSHttpBinding が設定された TransportWithMessageCredential)。 サービスがコンピューター ID を使用して実行されていない場合は、WSDL をインポートした後でクライアント エンドポイントで正しい UPN/SPN を手動で指定する必要があります。

  2. DNS サービス ID は WSDL で発行されます。 SspiNegotiatedOverTransportSslStreamSecurityBindingElement は、 NetTcpBinding UPN/SPN の代わりに (SecurityMode = TransportWithMessageCredentialなど) 使用されます。 サービスがコンピューター ID を使用して実行されていないか、DNS ID がコンピューターの ID ではない場合は、WSDL をインポートした後でクライアント エンドポイントで正しい UPN/SPN を手動で指定する必要があります。

  3. DNS ID が WSDL で公開される場合。 SslStreamSecurityBindingElement がクライアントでオーバーライドされる場合は、クライアントの IdentityVerifier でカスタムの SslStreamSecurityBindingElement を指定する必要があります。

次のコードは、クライアント エンドポイントで正しい UPN/SPN を手動で指定する方法と、クライアントの IdentityVerifier でカスタムの 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();  
        }  
    }  

コンストラクター

SslStreamSecurityBindingElement()

SslStreamSecurityBindingElement クラスの新しいインスタンスを初期化します。

SslStreamSecurityBindingElement(SslStreamSecurityBindingElement)

別の SslStreamSecurityBindingElement の値を使用して、SslStreamSecurityBindingElement クラスの新しいインスタンスを初期化します。

プロパティ

IdentityVerifier

このバインドの ID 検証機能を取得または設定します。

RequireClientCertificate

クライアント証明書がこのバインディングに必要かどうかを指定する値を取得または設定します。

SslProtocols

TcpClientCredentialType.Certificate のクライアント資格情報の種類を使用するときの、ネゴシエートする SSL/TLS プロトコルの一覧を指定します。 値には、次の列挙体メンバーの 1 つ以上の組み合わせを指定できます: Ssl3、Tls、Tls11、Tls12。

メソッド

BuildChannelFactory<TChannel>(BindingContext)

指定した種類のチャネル ファクトリを作成します。

BuildChannelListener<TChannel>(BindingContext)

指定した種類のチャネル リスナーを作成します。

BuildChannelListener<TChannel>(BindingContext)

指定した種類のチャネルを受け入れるよう、バインディング コンテキストからチャネル リスナーを初期化します。

(継承元 BindingElement)
BuildClientStreamUpgradeProvider(BindingContext)

提供するチャネル コンテキストに基づいて、StreamUpgradeProvider のクライアント上にインスタンスを作成します。

BuildServerStreamUpgradeProvider(BindingContext)

提供するチャネル コンテキストに基づいて、StreamUpgradeProvider のサーバー上にインスタンスを作成します。

BuildServerStreamUpgradeProvider(BindingContext)

提供するチャネル コンテキストに基づいて、StreamUpgradeProvider のサーバー上にインスタンスを作成します。

(継承元 StreamUpgradeBindingElement)
CanBuildChannelFactory<TChannel>(BindingContext)

指定した種類のチャネル ファクトリを作成できるかどうかを示す値を取得します。

CanBuildChannelListener<TChannel>(BindingContext)

指定した種類のチャネル リスナーを作成できるかどうかを示す値を取得します。

CanBuildChannelListener<TChannel>(BindingContext)

指定した種類のチャネルに対するリスナーをバインド要素が作成できるかどうかを示す値を返します。

(継承元 BindingElement)
Clone()

現在のインスタンスのコピーである新しいインスタンスを作成します。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetProperty<T>(BindingContext)

BindingContext から指定したオブジェクトを取得します。

GetTransportTokenAssertion()

セキュリティ バインドで使用されるトランスポート トークンを表す XmlElement を取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ShouldSerializeIdentityVerifier()

ID 検証機能をシリアル化する必要があるかどうかを示す値を取得します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

IPolicyExportExtension.ExportPolicy(MetadataExporter, PolicyConversionContext)

バインディングに関するカスタム ポリシー アサーションをエクスポートします。

適用対象