Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of SOAP request authenticated with WS-UsernameToken

Tags:

I'm trying to authenticate a SOAP request using WS-UsernameToken spec, but the target device is always denying access. My non-working request looks like this. (The password I'm trying to hash is system.)

<?xml version="1.0" encoding="UTF-8"?> <Envelope xmlns="http://www.w3.org/2003/05/soap-envelope">  <Header>   <Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">     <UsernameToken>       <Username>root</Username>       <Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">EVpXS/7yc/vDo+ZyIg+cc0fWdMA=</Password>       <Nonce>tKUH8ab3Rokm4t6IAlgcdg9yaEw=</Nonce>       <Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2010-08-10T10:52:42Z</Created>     </UsernameToken>   </Security>  </Header>   <Body>     <SomeRequest xmlns="http://example.ns.com/foo/bar" />   </Body> </Envelope> 

What I'm looking for is a similar request example, but with authentication token that actually works. For example if you have gSOAP application that uses these token, and can generate a request and post the result here, I'd be very grateful.

like image 262
che Avatar asked Aug 10 '10 11:08

che


People also ask

What is WS-Security explain in detail with an example?

WS-Security mechanisms can be used to accommodate a wide variety of security models and encryption technologies. WS-Security is a message-level standard that is based on securing SOAP messages through XML digital signature, confidentiality through XML encryption, and credential propagation through security tokens.

What is Username Token in SOAP?

A WS-Security UsernameToken enables an end-user identity to be passed over multiple hops before reaching the destination web service. The user identity is inserted into the message and is available for processing at each hop on its path.

What is Wsse authentication?

The basic premise of WSSE is that a request header is checked for encrypted credentials, verified using a timestamp and nonce, and authenticated for the requested user using a password digest. It is implemented by the OroWsseAuthenticationBundle that covers most cases from the WSSE specification (PDF).

How do I give my SOAP request a username and password?

You need to send the username and password in Basic format: String userAndPassword = String. format("%s:%s",username, password); String basicAuth = new sun.


1 Answers

The core thing is to define prefixes for namespaces and use them to fortify each and every tag - you are mixing 3 namespaces and that just doesn't fly by trying to hack defaults. It's also good to use exactly the prefixes used in the standard doc - just in case that the other side get a little sloppy.

Last but not least, it's much better to use default types for fields whenever you can - so for password you have to list the type, for the Nonce it's already Base64.

Make sure that you check that the generated token is correct before you send it via XML and don't forget that the content of wsse:Password is Base64( SHA-1 (nonce + created + password) ) and date-time in wsu:Created can easily mess you up. So once you fix prefixes and namespaces and verify that yout SHA-1 work fine without XML (just imagine you are validating the request and do the server side of SHA-1 calculation) you can also do a truial wihtout Created and even without Nonce. Oh and Nonce can have different encodings so if you really want to force another encoding you'll have to look further into wsu namespace.

<S11:Envelope xmlns:S11="..." xmlns:wsse="..." xmlns:wsu= "...">   <S11:Header>   ...     <wsse:Security>       <wsse:UsernameToken>         <wsse:Username>NNK</wsse:Username>         <wsse:Password Type="...#PasswordDigest">weYI3nXd8LjMNVksCKFV8t3rgHh3Rw==</wsse:Password>         <wsse:Nonce>WScqanjCEAC4mQoBE07sAQ==</wsse:Nonce>         <wsu:Created>2003-07-16T01:24:32</wsu:Created>       </wsse:UsernameToken>     </wsse:Security>   ...   </S11:Header> ... </S11:Envelope> 
like image 182
ZXX Avatar answered Oct 13 '22 01:10

ZXX