共用方式為


<security><customBinding>

指定自訂綁定的安全選項。

<configuration>
  <system.serviceModel>
    <bindings>
      <customBinding>
        <binding>
          <security>

語法

<security allowSerializedSigningTokenOnReply="Boolean"
          authenticationMode="AuthenticationMode"
          defaultAlgorithmSuite="SecurityAlgorithmSuite"
          includeTimestamp="Boolean"
          requireDerivedKeys="Boolean"
          keyEntropyMode="ClientEntropy/ServerEntropy/CombinedEntropy"
          messageProtectionOrder="SignBeforeEncrypt/SignBeforeEncryptAndEncryptSignature/EncryptBeforeSign"
          messageSecurityVersion="WSSecurityJan2004/WSSecurityXXX2005"
          requireSecurityContextCancellation="Boolean"
          requireSignatureConfirmation="Boolean"
          securityHeaderLayout="Strict/Lax/LaxTimestampFirst/LaxTimestampLast">
   <issuedTokenParameters />
   <localClientSettings />
   <localServiceSettings />
   <secureConversationBootstrap />
</security>

屬性和項目

下列各節說明屬性、子元素和父元素

Attributes

Attribute Description
allowSerializedSigningTokenOnReply 選擇性。 一個布林值,指定是否可以在回覆時使用序列化的標記。 預設值是 false。 使用雙重綁定時,設定預設為 , true 任何設定都會被忽略。
authenticationMode 選擇性。 指定發起者與回應者之間所使用的認證模式。 所有數值請見下方。

預設值為 sspiNegotiated
defaultAlgorithmSuite 選擇性。 設定訊息加密與金鑰包裝演算法。 演算法與金鑰大小由 SecurityAlgorithmSuite 類別決定。 這些演算法對應於安全政策語言(WS-SecurityPolicy)規範中所規定的。

可能的數值如下所示。 預設值是 Basic256

此屬性用於使用不同平台,該平台採用與預設不同的演算法。 在修改此設定時,你應該了解相關演算法的優缺點。 此屬性的類型 SecurityAlgorithmSuite為 。
包括時間戳記 一個布林值,指定每則訊息是否包含時間戳記。 預設值為 true
keyEntropyMode 規定了用於保護訊息的金鑰的計算方式。 金鑰可以僅基於用戶端金鑰材料、僅基於服務金鑰材料,或兩者結合。 有效的數值為

- ClientEntropy:會話金鑰是基於用戶端提供的金鑰資料。
- ServerEntropy: 會話金鑰是基於伺服器提供的金鑰資料。
- CombinedEntropy: 會話金鑰基於客戶端與服務所提供的金鑰資料。

預設值為 CombinedEntropy

此屬性的類型 SecurityKeyEntropyMode為 。
訊息保護令 設定訊息層級安全演算法應用於訊息的順序。 有效的數值包括以下幾項:

- SignBeforeEncrypt:先簽名,再加密。
- SignBeforeEncryptAndEncryptSignature:先簽名,加密,再加密簽名。
- EncryptBeforeSign:先加密,再簽名。

預設值取決於所使用的 WS-Security 版本。 預設值是 SignBeforeEncryptAndEncryptSignature 使用 WS-Security 1.1 版本時。 預設值是 SignBeforeEncrypt 使用 WS-Security 1.0 版本時。

此屬性的類型 MessageProtectionOrder為 。
訊息安全版本 選擇性。 設定所使用的 WS-Security 版本。 有效的數值包括以下幾項:

- WSSecurity11WSTrust2005年2月WSSecureConversation2005年2月WSSecurityPolicy11
- WSSecurity10WSTrust2005年2月WSSecureConversation2005年2月WSSecurityPolicy11基本安全剖面10
- WSSecurity11WSTrust2005年2月WSSecureConversation2005年2月WSSecurityPolicy11基本安全剖面10

預設為 WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11,可在 XML 中簡單表示為 Default。 此屬性的類型 MessageSecurityVersion為 。
requireDerivedKeys 一個布林值,指定鍵是否能從原始證明鍵中推導出。 預設值為 true
要求安全上下文取消 選擇性。 一個布林值,指定安全上下文是否應在不再需要時取消並終止。 預設值為 true
要求簽名確認 選擇性。 一個布林值,指定是否啟用 WS-Security 簽名確認。 當設定為 true時,訊息簽名會由回應者確認。 當自訂綁定設定為互惠憑證或設定使用已發行的憑證(WSS 1.1 綁定)時,此屬性預設為 true。 否則,預設為 false

簽名確認用於確認服務在完全知情的情況下回應請求。
securityHeaderLayout 選擇性。 指定安全標頭中元素的順序。 有效的數值為

- Strict: 項目依據「使用前宣告」的一般原則加入安全標頭。
- Lax: 項目可依符合 WSS: SOAP 訊息安全性的任意順序加入安全標頭。
- LaxWithTimestampFirst: 項目可依符合 WSS: SOAP 訊息安全性的順序加入安全標頭,但安全標頭的第一個元素必須是 wsse:Timestamp 元素。
- LaxWithTimestampLast: 項目可依符合 WSS: SOAP 訊息安全性的順序加入安全標頭,但安全標頭的最後一個元素必須是 wsse:Timestamp 元素。

預設值為 Strict

此元素的類型 SecurityHeaderLayout為 。

認證模式屬性

價值觀 Description
繩子 AnonymousForCertificate

AnonymousForSslNegotiated

CertificateOverTransport

IssuedToken

IssuedTokenForCertificate

IssuedTokenForSslNegotiated

IssuedTokenOverTransport

Kerberos

KerberosOverTransport

MutualCertificate

MutualCertificateDuplex

MutualSslNegotiated

SecureConversation

SspiNegotiated

UserNameForCertificate

UserNameForSslNegotiated

UserNameOverTransport

SspiNegotiatedOverTransport

defaultAlgorithm 屬性

價值觀 Description
Basic128 使用 Aes128 加密,Sha1 用於訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
基礎192 使用 Aes192 加密,Sha1 用於訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
基礎256 使用 Aes256 加密,Sha1 用於訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
Basic256Rsa15 使用 Aes256 進行訊息加密,Sha1 用於訊息摘要,Rsa15 用於金鑰包裝。
Basic192Rsa15 使用 Aes192 進行訊息加密,Sha1 用於訊息摘要,Rsa15 用於金鑰包裝。
三重音響 使用 TripleDes 加密,Sha1 用於訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
Basic128Rsa15 使用 Aes128 進行訊息加密,Sha1 用於訊息摘要,Rsa15 用於金鑰包裝。
三重驅逐艦RSA15 使用 TripleDes 加密,Sha1 用於訊息摘要,Rsa15 用於金鑰包裝。
Basic128Sha256 使用 Aes128 進行訊息加密,Sha256 進行訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
Basic192Sha256 使用 Aes192 進行訊息加密,Sha256 進行訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
Basic256Sha256 使用 Aes256 進行訊息加密,Sha256 進行訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
三重DesSha256 使用 TripleDes 進行訊息加密,Sha256 進行訊息摘要,Rsa-oaep-mgf1p 用於金鑰包裝。
Basic128Sha256Rsa15 使用 Aes128 進行訊息加密,Sha256 用於訊息摘要,Rsa15 用於金鑰包裝。
Basic192Sha256Rsa15 使用 Aes192 進行訊息加密,Sha256 用於訊息摘要,Rsa15 用於金鑰包裝。
Basic256Sha256Rsa15 使用 Aes256 進行訊息加密,Sha256 進行訊息摘要,Rsa15 進行金鑰包裝。
三重DesSha256Rsa15 使用 TripleDes 進行訊息加密,Sha256 用於訊息摘要,Rsa15 用於金鑰包裝。

子專案

元素 Description
<issuedTokenParameters(發行代幣參數)> 指定目前發行的代幣。 此元素的類型 IssuedTokenParametersElement為 。
<localClientSettings> 指定本地用戶端為此綁定設定的安全設定。 此元素的類型 LocalClientSecuritySettingsElement為 。
<localServiceSettings> 指定本地服務對此綁定的安全設定。 此元素的類型 LocalServiceSecuritySettingsElement為 。
<secureConversationBootstrap> 指定用於啟動安全對話服務的預設值。

父項目

元素 Description
<裝訂> 定義自訂綁定的所有綁定功能。

備註

欲了解更多使用此元素的資訊,請參閱 SecurityBindingElement 認證模式如何:使用 SecurityBindingElement 建立自訂綁定

Example

以下範例示範如何使用自訂綁定來設定安全性。 它展示了如何使用自訂綁定來啟用訊息層級的安全,同時實現安全傳輸。 當需要安全傳輸來在用戶端與服務間傳送訊息,且訊息層級必須安全時,這非常有用。 此配置不被系統提供的綁定支援。

服務配置定義了一套自訂綁定,支援使用 TLS/SSL 協定保護的 TCP 通訊,以及 Windows 訊息安全。 自訂綁定使用服務憑證在傳輸層級驗證服務,並保護用戶端與服務間傳輸期間的訊息。 這是透過 <sslStreamSecurity> 綁定元素來實現的。 服務的憑證是透過服務行為來設定的。

此外,自訂綁定使用訊息安全,使用 Windows 憑證類型——這是預設的憑證類型。 這是透過 安全 綁定元素來實現的。 如果有 Kerberos 認證機制,客戶端與服務皆會以訊息層級安全進行認證。 若無法使用 Kerberos 認證機制,則使用 NTLM 認證。 NTLM 會將客戶端驗證給服務,但不會對客戶端進行認證服務。 安全綁定元素被設定為使用 SecureConversation AuthenticationType,這會導致在用戶端與服務上建立安全會話。 這是使服務的雙工合約得以運作所必需的。 欲了解更多執行此範例的資訊,請參閱 自訂綁定安全性

<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
               behaviorConfiguration="CalculatorServiceBehavior">
        <host>
          <baseAddresses>
            <!-- use following base address -->
            <add baseAddress="net.tcp://localhost:8000/ServiceModelSamples/Service"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                  binding="customBinding"
                  bindingConfiguration="Binding1"
                  contract="Microsoft.ServiceModel.Samples.ICalculatorDuplex" />
        <!-- the mex endpoint is exposed at net.tcp://localhost:8000/ServiceModelSamples/service/mex -->
        <endpoint address="mex"
                  binding="mexTcpBinding"
                  contract="IMetadataExchange" />
      </service>
    </services>
    <bindings>
      <!-- configure a custom binding -->
      <customBinding>
        <binding name="Binding1">
          <security authenticationMode="SecureConversation"
                    requireSecurityContextCancellation="true">
          </security>
          <textMessageEncoding messageVersion="Soap12WSAddressing10"
                               writeEncoding="utf-8" />
          <sslStreamSecurity requireClientCertificate="false" />
          <tcpTransport />
        </binding>
      </customBinding>
    </bindings>
    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata />
          <serviceDebug includeExceptionDetailInFaults="False" />
          <serviceCredentials>
            <serviceCertificate findValue="localhost"
                                storeLocation="LocalMachine"
                                storeName="My"
                                x509FindType="FindBySubjectName" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

另請參閱