次の方法で共有


メッセージ セキュリティと相互の証明書

次のシナリオでは、メッセージ セキュリティ モードを使用して保護されている Windows Communication Foundation (WCF) サービスおよびクライアントを示します。クライアントとサービスは、証明書を使用して認証されます。

このシナリオは、X.509 証明書トークン プロファイルと共に WS-Security を使用するため、相互運用性があります。

ms733102.note(ja-jp,VS.90).gifメモ :
このシナリオでは、サービス証明書のネゴシエーションは実行されません。通信を開始する前に、サービス証明書をクライアントに提供しておく必要があります。サーバー証明書は、アプリケーションと共に配布したり、帯域外通信で提供できます。

相互の証明書を利用したメッセージ セキュリティ

特性 説明

セキュリティ モード

メッセージ

相互運用性

○ WS-Security および X.509 証明書トークン プロファイルと互換性があるクライアントとサービスで相互運用性があります。

認証

サーバーとクライアントの相互認証

整合性

機密性

トランスポート

HTTP

バインディング

WSHttpBinding

サービス

次のコードと構成は、別々に実行することを想定しています。次のいずれかを行います。

  • 構成を使用せずに、コードを使用してスタンドアロン サービスを作成する。
  • 提供された構成を使用してサービスを作成するが、エンドポイントを定義しない。

コード

次のコードでは、メッセージ セキュリティを使用するサービス エンドポイントを作成します。サービスには、自身を認証するための証明書が必要です。

構成

コードの代わりに次の構成を使用して、同じサービスを作成できます。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="serviceCredentialBehavior">
          <serviceCredentials>
            <serviceCertificate findValue="Contoso.com" 
                                storeLocation="LocalMachine"
                                storeName="My" 
                                x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service behaviorConfiguration="serviceCredentialBehavior" 
               name="ServiceModel.Calculator">
        <endpoint address="https://localhost/Calculator" 
                  binding="wsHttpBinding"
                  bindingConfiguration="InteropCertificateBinding"
                  name="WSHttpBinding_ICalculator"
                  contract="ServiceModel.ICalculator" />
      </service>
    </services>
    <bindings>
      <wsHttpBinding>
        <binding name="InteropCertificateBinding">
          <security mode="Message">
            <message clientCredentialType="Certificate"
                     negotiateServiceCredential="false"
                     establishSecurityContext="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client />
  </system.serviceModel>
</configuration>

クライアント

次のコードと構成は、別々に実行します。以下のいずれかの操作を行います。

  • コード (およびクライアント コード) を使用してスタンドアロン クライアントを作成する。
  • エンドポイント アドレスを定義しないクライアントを作成する。代わりに、引数として構成名を受け取るクライアント コンストラクタを使用する。次に例を示します。

コード

クライアントを作成する場合のコード例を次に示します。セキュリティ モードは Message に設定され、クライアント資格情報の種類は Certificate に設定されています。

構成

次のコードは、クライアントを構成します。クライアント証明書は、<clientCertificate> of <clientCredentials> Elementを使用して指定する必要があります。また、サービス証明書は、<defaultCertificate> Elementを使用して指定します。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="ClientCredentialsBehavior">
          <clientCredentials>
            <clientCertificate findValue="Cohowinery.com" 
                 storeLocation="CurrentUser"
                 storeName="My"
                 x509FindType="FindBySubjectName" />
            <serviceCertificate>
              <defaultCertificate findValue="Contoso.com" 
                                  storeLocation="CurrentUser"
                                  storeName="TrustedPeople"
                                  x509FindType="FindBySubjectName" />
            </serviceCertificate>
          </clientCredentials>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="WSHttpBinding_ICalculator" >
          <security mode="Message">
            <message clientCredentialType="Certificate" 
                     negotiateServiceCredential="false"
                     establishSecurityContext="false" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://machineName/Calculator" 
                behaviorConfiguration="ClientCredentialsBehavior"
                binding="wsHttpBinding" 
                bindingConfiguration="WSHttpBinding_ICalculator"
                contract="ICalculator"
                name="WSHttpBinding_ICalculator">
        <identity>
          <certificate encodedValue="Encoded_Value_Not_Shown" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>
</configuration>

関連項目

概念

セキュリティの概要