标签: ws-security

JAX-WS使用WS-Security和WS-Addressing来使用Web服务

我正在尝试使用JAX-WS(Metro)开发独立的Java Web服务客户端,该客户端使用带有用户名令牌身份验证的WS-Security(密码摘要,随机数和时间戳)和时间戳验证以及SSL上的WS-Addressing.

我必须使用的WSDL没有定义任何安全策略信息.当WSDL不包含此信息时,我无法确切地知道如何添加此标头信息(正确的方法).我发现使用Metro的大多数示例都围绕着使用Netbeans从WSDL自动生成这个,这对我没有任何帮助.我没有太多的清晰度或方向,已经研究过WSIT,XWSS等.JBoss WS Metro看起来很有希望也没有太多运气.

任何人都有这方面的经验或有关如何完成此任务的建议?即使把我指向正确的方向也会有所帮助.除了必须基于Java之外,我不限于特定技术.

java ws-security web-services java-metro-framework jax-ws

10
推荐指数
1
解决办法
4万
查看次数

WSContext.getUserPrincipal()为密码摘要认证返回null

在我的WebService中,我需要记录调用者的id,但是即使使用带有密码身份验证的WS-Security对用户进行了身份验证,wsContext.getUserPrincipal()也会返回null.根据JavaDocs for JAX-WS 2.1,WSContext.getUserPrincipal()只应在用户未经过身份验证时返回null.

我是否必须在安全处理程序中执行某些操作才能将用户主体设置为WSContext?文档似乎表明它是自动完成的.

我在Tomcat上使用了带有jax-ws 2.1.3堆栈的metro 1.1堆栈(我认为是1.1.5).

java ws-security web-services java-metro-framework jax-ws

10
推荐指数
1
解决办法
1524
查看次数

在C#中以编程方式创建WCF客户端的标头(wsse)部分

如何以编程方式在app #config中创建app.config服务设置的以下部分:

    <client>
  <endpoint address="https://someServiceUrl"
      binding="basicHttpBinding" bindingConfiguration="Contact"
      contract="ServiceReference.PostingWebService" name="PostingWebServicePort">
    <headers>
      <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken>
          <wsse:Username>someusername</wsse:Username>
          <wsse:Password Type='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText'>somepassword</wsse:Password>
        </wsse:UsernameToken>
      </wsse:Security>
    </headers>
  </endpoint>
</client>
Run Code Online (Sandbox Code Playgroud)

我已设法从c#生成绑定部分(上面未包含)和端点部分.我无法创建标题部分.

出现的错误是:(这是因为当我从c#生成所有内容时,我没有标题部分)

这项服务需要<wsse:Security>,但缺少.

header部分很重要,好像我从配置中排除它并使用config运行代码它也会产生上述错误.

我不想使用web.config/app.config.我必须从C#运行所有东西.(上面的app.config工作正常,但我想通过c#做同样的事情)

注意:下面的更新是基于以下提供的解决方案请通过以下解决方案的评论,以获得更好的理解

更新1 :(首先以编程方式使用BasicHttpBinding)

BasicHttpBinding binding = new BasicHttpBinding();
        binding.Name = "Contact";
        binding.CloseTimeout = TimeSpan.FromMinutes(1);
        binding.OpenTimeout = TimeSpan.FromMinutes(1);
        binding.ReceiveTimeout = TimeSpan.FromMinutes(10);
        binding.SendTimeout = TimeSpan.FromMinutes(1);
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
        binding.MaxBufferSize = 524288;
        binding.MaxBufferPoolSize = 524288;
        binding.MaxReceivedMessageSize = 524288;
        binding.MessageEncoding = WSMessageEncoding.Text;
        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.TransferMode = TransferMode.Buffered;
        binding.UseDefaultWebProxy = …
Run Code Online (Sandbox Code Playgroud)

c# wcf ws-security wcf-security

10
推荐指数
2
解决办法
2万
查看次数

WCF客户端使用WS-Security Web服务

我设法使用WS-Security 1.1协议使用基于Java的Web服务(第三方).Web服务只需要通过x509证书进行签名,而不是加密.但是我收到了这个错误:

主签名后不能发生签名确认元素.

捕获的服务器响应包如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true">
            <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="Signature-501">
                <ds:SignedInfo>
                    <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                    <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
                    <ds:Reference URI="#id-502">
                        <ds:Transforms>
                            <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                        </ds:Transforms>
                        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                        <ds:DigestValue>...</ds:DigestValue>
                    </ds:Reference>
                    <ds:Reference URI="#SigConf-500">
                        <ds:Transforms>
                            <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
                        </ds:Transforms>
                        <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/>
                        <ds:DigestValue>...</ds:DigestValue>
                    </ds:Reference>
                </ds:SignedInfo>
                <ds:SignatureValue>
                ...
                </ds:SignatureValue>
                <ds:KeyInfo Id="KeyId-...">
                    <wsse:SecurityTokenReference xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="STRId-...">
                        <ds:X509Data>
                            <ds:X509IssuerSerial>
                                <ds:X509IssuerName>CN=COMODO RSA Organization Validation Secure Server CA,O=COMODO CA Limited,L=Salford,ST=Greater Manchester,C=GB</ds:X509IssuerName>

                                <ds:X509SerialNumber>...</ds:X509SerialNumber>
                            </ds:X509IssuerSerial>
                        </ds:X509Data>
                    </wsse:SecurityTokenReference>
                </ds:KeyInfo>
            </ds:Signature>
            <wsse11:SignatureConfirmation xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" Value="..." wsu:Id="SigConf-500"/>
        </wsse:Security>
    </soapenv:Header>
    <soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="id-502"> …
Run Code Online (Sandbox Code Playgroud)

.net c# wcf ws-security x509

10
推荐指数
1
解决办法
352
查看次数

如何在php5中实现ws-security 1.1

我试图在PHP5中使用Soap调用Web服务,为此,我需要使用WS-Security 1.1.

(在java和.NET中,这都是自动生成的.)

是否有可用于在PHP中轻松生成安全标头的框架?或者我必须自己添加整个标头?

WS-Security 1.1的规格:http://oasis-open.org/committees/download.php/16790/wss-1.1-spec-os-SOAPMessageSecurity.pdf

php ws-security soap web-services zend-framework

9
推荐指数
1
解决办法
1万
查看次数

使用WS-Security的WCF服务仅需要签名时间戳

我需要向第三方提供服务,该服务将发送带有签名时间戳的soap消息.

如何配置我的服务以支持此功能?

更新 我已经设法接近我们所追求的Soap消息的格式,但WCF坚持同时签署用户名和时间戳令牌,有没有办法修改绑定只签署时间戳?


进一步更新 以下是我们的要求:

  • 时间戳元素必须签名.
  • 用于签名的证书上的CN名称必须与UsernameToken元素中的用户名给出匹配.
  • 用于签名的证书必须在BinarySecurityToken元素中发送.
  • KeyInfo元素必须只包含一个SecurityTokenReference元素,该元素必须用于引用BinarySecurityToken.
  • 必须指定规范化算法.
  • 必须指定SignatureMethod,并且必须是SHA-1或SHA-2算法.
  • 应该使用分离的签名.

有什么建议?

当前配置

客户端绑定

<bindings>
  <wsHttpBinding>
    <binding name="WSBC">
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Certificate" proxyCredentialType="None"></transport>
        <message clientCredentialType="UserName" negotiateServiceCredential="false" establishSecurityContext="false" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
Run Code Online (Sandbox Code Playgroud)

客户端端点

<client>
  <endpoint address="https://localhost/WcfTestService/Service2.svc"
  behaviorConfiguration="CCB" binding="wsHttpBinding"
  bindingConfiguration="WSBC"
  contract="ServiceReference2.IService2"
  name="wsHttpBinding_IService2" />
</client>
Run Code Online (Sandbox Code Playgroud)

客户行为

<behaviors>
  <endpointBehaviors>
    <behavior name="MBB">
      <clientCredentials>
        <clientCertificate  findValue="03 58 d3 bf 4b e7 67 2e 57 05 47 dc e6 3b 52 7f f8 66 d5 2a"
                            storeLocation="LocalMachine"
                            storeName="My"
                            x509FindType="FindByThumbprint" />
        <serviceCertificate>
          <defaultCertificate findValue="03 58 …
Run Code Online (Sandbox Code Playgroud)

wcf ws-security

9
推荐指数
2
解决办法
4855
查看次数

WCF是否支持SOAP 1.1的WS-Security?

我需要调用一些需要WS-Security的第三Web服务.我使用以下配置创建了一个WCF端点:

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="TestBinding">
        <security mode="TransportWithMessageCredential">
          <message clientCredentialType="Certificate" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="TestBehavior">
        <callbackDebug includeExceptionDetailInFaults="true" />
        <clientCredentials>
          <clientCertificate findValue="Acme" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
          <serviceCertificate>
            <authentication certificateValidationMode="PeerOrChainTrust" />
          </serviceCertificate>
        </clientCredentials>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <client>
    <endpoint address="https://acme.com/webservices" binding="wsHttpBinding" bindingConfiguration="TestBinding" behaviorConfiguration="TestBehavior" contract="AcmeContract" name="AcmeEndpoint"></endpoint>
  </client>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)

问题是第三方服务器抛出以下异常:

收到协议'_http://schemas.xmlsoap.org/wsdl/soap12/',必需的协议'_http://schemas.xmlsoap.org/wsdl/soap/'.

据我所知,使用wsHttpBinding将导致WCF发送SOAP 1.2请求,而使用basicHttpBinding将导致SOAP 1.1请求.由于WS-Security部分是必需的,据我所知,我必须使用wsHttpBinding.我的问题是如何强制SOAP 1.1请求?我有什么选择?

.net c# wcf ws-security soap

9
推荐指数
2
解决办法
2万
查看次数

Apache CXF - 不从WSS4JOutInterceptor发送凭据?

我正在尝试使用apache cxf 2.4.0使用WS-Security UsernameToken规范1.0连接到Web服务.

我已经从CXF文档中复制了下面的代码,但是我得到了:org.apache.cxf.ws.policy.PolicyException:没有可用的用户名

    MyService_Service ss = new MyService_Service(wsdlURL, SERVICE_NAME);
    MyService port = ss.getBasicHttpBindingMyService ();  


    Client client = ClientProxy.getClient(port);
    Endpoint cxfEndpoint = client.getEndpoint();

    Map<String,Object> outProps = new HashMap<String,Object>();
    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.USER, "USERNAME");
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
    outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, 
    ClientPasswordHandler.class.getName());

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    cxfEndpoint.getOutInterceptors().add(wssOut);
Run Code Online (Sandbox Code Playgroud)

我还从文档中实现了一个ClientPasswordHandler类,但似乎从未发送用户名(根据错误).这是密码处理程序:

public class ClientPasswordHandler implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
    WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
    pc.setPassword("Password");     
    }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法看看是否正在应用WSS4Jinterceptor,并且发送了UsernameToken?

java ws-security web-services cxf

9
推荐指数
1
解决办法
2万
查看次数

WCF客户端 - 为WS-Security时间戳签名指定签名算法

我有一个WCF客户端正在向非WCF服务发送消息,并且该服务在处理用于签署WS-Security Timestamp元素的HMAC-SHA1签名方法时遇到问题.理想情况下,我们想使用RSA-SHA1签名方法,但我无法让WCF使用该签名方法.

我正在使用的绑定是一个自定义绑定,它允许我通过HTTPS发送SAML 2.0令牌:

<customBinding>
    <!-- This binding is a WS2007FederationHttpBinding without Secure Sessions that uses Text message encoding. -->
    <binding
        name="WS2007FederationHttpBinding_NoSecureSession_Text"
        closeTimeout="00:01:00"
        openTimeout="00:01:00"
        receiveTimeout="00:10:00"
        sendTimeout="00:01:00">
        <security
            authenticationMode="IssuedTokenOverTransport"
            requireSignatureConfirmation="true"
            securityHeaderLayout="Lax"
            messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
            keyEntropyMode="CombinedEntropy"
            includeTimestamp="true">
            <issuedTokenParameters
                tokenType="urn:oasis:names:tc:SAML:2.0:assertion">
                <!-- This describes the STS. That is, the URL, the binding to use, and its Identity -->
                <issuer
                    address="http://hostname//STS.svc"
                    binding="ws2007HttpBinding"
                    bindingConfiguration="StsUserNameBindingConfiguration">
                    <identity>
                        <!-- This is the certificate used for signing on the STS. -->
                        <!-- Replace "sts-signing-certificate-thumbprint" with the actual thumbprint of the STS's signing …
Run Code Online (Sandbox Code Playgroud)

c# wcf ws-security wcf-client xml-signature

9
推荐指数
1
解决办法
5494
查看次数

使用spring安全性保护REST端点

我正在尝试为REST端点提供安全性.我正在按照本页的说明操作.在我的情况下,我没有视图,因此我没有创建控制器来指定视图,也没有在我的AppConfig.java中添加viewResolver

实现后,它在调用安全的REST端点时正确显示访问被拒绝错误.但即使我在请求标头中指定了用户名/密码,我也会收到拒绝访问错误.我正在测试基本身份验证中的邮递员设置用户名/密码.我有什么想法?

ws-security authorization restful-authentication spring-security rest-security

9
推荐指数
1
解决办法
1807
查看次数