Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 没有客户端证书的WCF消息/方法安全性_.net_Wcf_Web Services_Authentication_Basic Authentication - Fatal编程技术网

.net 没有客户端证书的WCF消息/方法安全性

.net 没有客户端证书的WCF消息/方法安全性,.net,wcf,web-services,authentication,basic-authentication,.net,Wcf,Web Services,Authentication,Basic Authentication,我有一个WCF服务,托管在IIS中。关于服务,我在服务中有大约20种方法。我想用用户名/密码保护其中一些方法。我无法控制调用服务的客户端,因此无法在客户端上安装证书。我们的服务作为一个平台,保存所有用户配置文件信息,包括登录信息 我想我希望客户端对WCF服务上的authenticate(username,password)方法进行一次身份验证,获取一个授权令牌,并将该令牌传递给后续调用。(有点像Asp.net成员资格提供程序使用表单身份验证会话)。如果可能的话,我不希望客户端必须为每个方法调用传

我有一个WCF服务,托管在IIS中。关于服务,我在服务中有大约20种方法。我想用用户名/密码保护其中一些方法。我无法控制调用服务的客户端,因此无法在客户端上安装证书。我们的服务作为一个平台,保存所有用户配置文件信息,包括登录信息


我想我希望客户端对WCF服务上的authenticate(username,password)方法进行一次身份验证,获取一个授权令牌,并将该令牌传递给后续调用。(有点像Asp.net成员资格提供程序使用表单身份验证会话)。如果可能的话,我不希望客户端必须为每个方法调用传递用户名/密码。这是正确的模式吗?有没有更好的方法使用标准WCF功能来实现此功能?是否有人有任何示例配置/代码来显示正确的方法来实现此功能?

仅供参考:如果您想使用内置的WCF自定义用户/通行证子系统,WCF 4.0引入了一个。这允许您在没有证书等的情况下使用WCF安全子系统。。。在WCF不认为它是安全的情况下,这是有用的(例如当SSL是在设备级别而不是WebServer级别上完成的,或者当使用IP过滤时)。

WCF不提供每个操作验证。如果您想要安全和不安全的操作,最简单的方法是将它们分成两个服务契约,并使用不同的安全设置公开每个服务契约

您的授权令牌思想已经在WCF中实现,但在您的场景中,您必须使用wsHttpBinding、用户名客户端凭据、SecurityContext和服务证书

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="securedService">
          <serviceCredentials>
            <serviceCertificate x509FindType="FindBySubjectName" findValue="ServerCert" 
                                storeLocation="LocalMachine" storeName="My"/>
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="Secured">
          <security mode="Message">
            <message clientCredentialType="UserName" establishSecurityContext="true" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="MessageSecurity.Service" behaviorConfiguration="securedService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Secured"
                  contract="MessageSecurity.IService">
        </endpoint>
      </service>
    </services>
  </system.serviceModel>

SecurityContext是基于WS-SecureConversation的可互操作功能。它只需要在服务代理实例的第一次调用中传递用户名和密码(在WCF中,这是完全透明的-客户端代理实例维护安全上下文)。以下调用仅使用在第一次调用期间发出的安全令牌。默认情况下,wsHttpBinding中会打开SecurityContext

此配置还将对消息进行加密和签名-这是一种全功能WS-Security。任何其他方法都取决于您。你必须完全靠自己来实施

你提到你不能控制客户。这并不意味着你不能使用证书。如果您使用证书,客户有责任获得证书,如果他们想呼叫您的服务。它与控制客户对证书的信任无关——对于公共web服务,它意味着从受信任的证书颁发机构购买证书

此外,无需安装即可获得服务证书。第一种可能性是使用证书作为端点标识。在这种情况下,编码证书是WSDL的一部分:

<wsdl:service name="Service">
  <wsdl:port name="WSHttpBinding_IService" binding="tns:WSHttpBinding_IService">
    <soap12:address location="http://localhost:1432/Service.svc" /> 
    <wsa10:EndpointReference>
      <wsa10:Address>http://localhost:1432/Service.svc</wsa10:Address> 
      <Identity xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <X509Data>
            <X509Certificate>MIICmzCCAYegAwI....<X509Certificate> 
          </X509Data>
        </KeyInfo>
      </Identity>
    </wsa10:EndpointReference>
  </wsdl:port>
</wsdl:service>

http://localhost:1432/Service.svc 
米茨卡耶加维。。。。
如果指定配置了服务证书的wsHttpBinding端点,并且未设置其标识,则会自动执行此操作。这种方法的缺点是证书过期。如果更改过期证书,则必须更新所有客户端

第二种可能性是启用服务凭据协商:

<bindings>
  <wsHttpBinding>
    <binding name="Secured">
      <security mode="Message">
        <message clientCredentialType="UserName" negotiateServiceCredential="true"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>


默认情况下,协商处于启用状态。它使用TLSNego协议在安全通信开始之前交换服务凭据(证书)。这种方法的缺点是并非所有平台都支持TLSNego

我可以用
netTCPBinding
来执行此操作吗?