指定自定义绑定的安全选项。
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding>
<security>
Syntax
<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>
特性和元素
以下部分介绍属性、子元素和父元素
特性
| Attribute | Description |
|---|---|
| allowSerializedSigningTokenOnReply | 可选。 一个布尔值,指定是否可以在回复上使用序列化令牌。 默认值为 false。 使用双重绑定时,将忽略默认设置 true 和所做的任何设置。 |
| authenticationMode | 可选。 指定在发起方和响应方之间使用的身份验证模式。 有关所有值,请参阅下文。 默认值为 sspiNegotiated。 |
| defaultAlgorithmSuite | 可选。 设置消息加密和密钥包装算法。 算法和键大小由 SecurityAlgorithmSuite 类确定。 这些算法映射到安全策略语言(WS-SecurityPolicy)规范中指定的算法。 可能的值如下所示。 默认值为 Basic256。使用选择不同于默认值的一组算法的不同平台时,将使用此属性。 在对此设置进行修改时,应注意相关算法的优缺点。 此属性的类型 SecurityAlgorithmSuite为 . |
| includeTimestamp | 一个布尔值,该值指定是否在每个消息中包含时间戳。 默认值为 true。 |
| keyEntropyMode | 指定用于保护消息的密钥的计算方式。 密钥只能基于客户端密钥材料、仅服务密钥材料或两者的组合。 有效值为 - ClientEntropy:会话密钥基于客户端提供的密钥数据。- ServerEntropy:会话密钥基于服务器提供的密钥数据。- CombinedEntropy:会话密钥基于客户端和服务提供的密钥数据。默认值为 CombinedEntropy。此属性的类型 SecurityKeyEntropyMode为 . |
| messageProtectionOrder | 设置消息级别安全算法应用于消息的顺序。 有效值包括: - SignBeforeEncrypt:先签名,然后加密。- SignBeforeEncryptAndEncryptSignature:先签名,加密,然后加密签名。- EncryptBeforeSign:首先加密,然后签名。默认值取决于所使用的 WS-Security 版本。 默认值为 SignBeforeEncryptAndEncryptSignature 使用 WS-Security 1.1 时。 默认值为 SignBeforeEncrypt 使用 WS-Security 1.0。此属性的类型 MessageProtectionOrder为 . |
| messageSecurityVersion | 可选。 设置所使用的 WS-Security 版本。 有效值包括: - WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11 - WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 - WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10 默认值为 WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11,并且可以简单地用 XML Default表示。 此属性的类型 MessageSecurityVersion为 . |
| requireDerivedKeys | 一个布尔值,该值指定是否可以从原始校对键派生密钥。 默认值为 true。 |
| requireSecurityContextCancellation | 可选。 一个布尔值,该值指定在不再需要安全上下文时是否应取消和终止。 默认值为 true。 |
| requireSignatureConfirmation | 可选。 一个布尔值,该值指定是否启用 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为 . |
authenticationMode 属性
| 价值 | Description |
|---|---|
| String | AnonymousForCertificateAnonymousForSslNegotiatedCertificateOverTransportIssuedTokenIssuedTokenForCertificateIssuedTokenForSslNegotiatedIssuedTokenOverTransportKerberosKerberosOverTransportMutualCertificateMutualCertificateDuplexMutualSslNegotiatedSecureConversationSspiNegotiatedUserNameForCertificateUserNameForSslNegotiatedUserNameOverTransportSspiNegotiatedOverTransport |
defaultAlgorithm 属性
| 价值 | Description |
|---|---|
| Basic128 | 使用 Aes128 加密、Sha1 进行消息摘要,使用 Rsa-oaep-mgf1p 进行密钥包装。 |
| Basic192 | 使用 Aes192 加密、Sha1 进行消息摘要、Rsa-oaep-mgf1p 进行密钥包装。 |
| Basic256 | 使用 Aes256 加密、Sha1 进行消息摘要、Rsa-oaep-mgf1p 进行密钥包装。 |
| Basic256Rsa15 | 将 Aes256 用于消息加密,Sha1 用于消息摘要,Rsa15 用于密钥包装。 |
| Basic192Rsa15 | 将 Aes192 用于消息加密,Sha1 用于消息摘要,Rsa15 用于密钥包装。 |
| TripleDes | 使用 TripleDes 加密、Sha1 进行消息摘要、Rsa-oaep-mgf1p 进行密钥包装。 |
| Basic128Rsa15 | 将 Aes128 用于消息加密,Sha1 用于消息摘要,Rsa15 用于密钥包装。 |
| TripleDesRsa15 | 使用 TripleDes 加密,对消息摘要使用 Sha1,将 Rsa15 用于密钥包装。 |
| Basic128Sha256 | 将 Aes128 用于消息加密,Sha256 用于消息摘要,将 Rsa-oaep-mgf1p 用于密钥包装。 |
| Basic192Sha256 | 将 Aes192 用于消息加密,Sha256 用于消息摘要,将 Rsa-oaep-mgf1p 用于密钥包装。 |
| Basic256Sha256 | 将 Aes256 用于消息加密,Sha256 用于消息摘要,将 Rsa-oaep-mgf1p 用于密钥包装。 |
| TripleDesSha256 | 将 TripleDes 用于消息加密,Sha256 用于消息摘要,将 Rsa-oaep-mgf1p 用于密钥包装。 |
| Basic128Sha256Rsa15 | 将 Aes128 用于消息加密,Sha256 用于消息摘要,将 Rsa15 用于密钥包装。 |
| Basic192Sha256Rsa15 | 将 Aes192 用于消息加密,Sha256 用于消息摘要,将 Rsa15 用于密钥包装。 |
| Basic256Sha256Rsa15 | 将 Aes256 用于消息加密,Sha256 用于消息摘要,Rsa15 用于密钥包装。 |
| TripleDesSha256Rsa15 | 将 TripleDes 用于消息加密,Sha256 用于消息摘要,将 Rsa15 用于密钥包装。 |
子元素
| 元素 | Description |
|---|---|
| <issuedTokenParameters> | 指定当前颁发的令牌。 此元素的类型 IssuedTokenParametersElement为 . |
| <localClientSettings> | 指定此绑定的本地客户端的安全设置。 此元素的类型 LocalClientSecuritySettingsElement为 . |
| <localServiceSettings> | 指定此绑定的本地服务的安全设置。 此元素的类型 LocalServiceSecuritySettingsElement为 . |
| <secureConversationBootstrap> | 指定用于启动安全聊天服务的默认值。 |
父元素
| 元素 | Description |
|---|---|
| <捆绑> | 定义自定义绑定的所有绑定功能。 |
注解
有关使用此元素的详细信息,请参阅 SecurityBindingElement 身份验证模式 以及如何 :使用 SecurityBindingElement 创建自定义绑定。
Example
以下示例演示如何使用自定义绑定配置安全性。 它演示如何使用自定义绑定来启用消息级安全性以及安全传输。 当需要安全传输才能在客户端和服务之间传输消息,同时消息必须在消息级别上安全时,这非常有用。 系统提供的绑定不支持此配置。
服务配置定义一个自定义绑定,该绑定支持使用 TLS/SSL 协议和 Windows 消息安全性保护的 TCP 通信。 自定义绑定使用服务证书对传输级别的服务进行身份验证,并在客户端和服务之间的传输过程中保护消息。 这是由 <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>