c# - username token in soap ws security http -
this first part soap header trying generate
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mhs="http://org/emedny/mhs/" xmlns:urn="urn:hl7-org:v3"> <soapenv:header> <wsse:security soap:mustunderstand="1" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:binarysecuritytoken valuetype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#x509v3" encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#base64binary" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:id="securitytoken-e00c8062-83d2-4f04-88fc-996218e7bb3d">miicedcc....(emedny signed user mls cert).......</wsse:binarysecuritytoken> <wsse:binarysecuritytoken valuetype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#x509v3" encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#base64binary" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:id="securitytoken-c0cc2cd4-cb77-4fa5-abfa-bd485afd1685">miidfj.....( emedny mls web-service end-point public cert)........</wsse:binarysecuritytoken> <wsse:usernametoken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:id="securitytoken-970e9a80-00cc-4c86-8ec4-3ba16e029a5b"> <wsse:username>....your_username.....</wsse:username> <wsse:password type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#passwordtext">.....your_plaintext_password....</wsse:password> <wsse:nonce>knyu6msxcktg4ddyvwveiw==</wsse:nonce> <wsu:created>2010-09-15t18:00:30z</wsu:created> </wsse:usernametoken> <xenc:encryptedkey xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"> <xenc:encryptionmethod algorithm="http://www.w3.org/2001/04/xmlenc#rsa-1_5"/> <keyinfo xmlns="http://www.w3.org/2000/09/xmldsig#"> <wsse:securitytokenreference> <wsse:reference uri="#securitytoken-c0cc2cd4-cb77-4fa5-abfa-bd485afd1685" valuetype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#x509v3"/> </wsse:securitytokenreference>
although have wsdl, code in c# create custom binding. not sure how use wsdl create soap header.what know how use invoke operation.i used svcutil generate proxy. let me know if wants see wsdl also, believe webconfig doesn't need binding configurations. because setting binding, endpoints in code
protected void button2_click(object sender, eventargs e) { var b = new custombinding(); var sec = (asymmetricsecuritybindingelement)securitybindingelement.createmutualcertificatebindingelement(messagesecurityversion.wssecurity10wstrust13wssecureconversation13wssecuritypolicy12basicsecurityprofile10); usernamesecuritytokenparameters tokenparameters = new usernamesecuritytokenparameters(); tokenparameters.inclusionmode = securitytokeninclusionmode.alwaystorecipient; tokenparameters.requirederivedkeys = false; sec.endpointsupportingtokenparameters.signedencrypted.add( tokenparameters); //b.elements.add(security); // sec.endpointsupportingtokenparameters.signed.add(new usernamesecuritytokenparameters()); sec.messagesecurityversion = messagesecurityversion. wssecurity10wstrust13wssecureconversation13wssecuritypolicy12basicsecurityprofile10; sec.includetimestamp = true; sec.messageprotectionorder = system.servicemodel.security.messageprotectionorder.encryptbeforesign; b.elements.add(sec); b.elements.add(new textmessageencodingbindingelement(messageversion.soap11, encoding.utf8)); b.elements.add(new httptransportbindingelement()); //addressheader addressheader1 = addressheader.createaddressheader("wsse", "http://12.23.28.113:9047/mhservice", 1); addressheader[] addressheaders = null; endpointaddress endptaddress = new endpointaddress(new uri("http://12.23.28.113:9047/mhservice"), endpointidentity.creatednsidentity("dpmedshistory"), addressheaders); mhsclient serviceproxy = new mhsclient(b, endptaddress); serviceproxy.clientcredentials.username.username = "sss"; serviceproxy.clientcredentials.username.password = "fff"; serviceproxy.clientcredentials.clientcertificate.setcertificate(storelocation.currentuser, storename.my, x509findtype.findbysubjectname, "sss"); serviceproxy.clientcredentials.servicecertificate.setdefaultcertificate(storelocation.currentuser, storename.my, x509findtype.findbysubjectname, "dsfdsa"); byte[] array = encoding.ascii.getbytes("hi"); transaction t = new transaction(); t.transdata = array; serviceproxy.geteligibility(t); }
this generated request per fiddler
<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <s:header><vsdebuggercausalitydata xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">vsdebuggercausalitydata> <o:security s:mustunderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <u:timestamp u:id="uuid-c243958e-b070-4ac7-b497-9f668427eeb9-2"><u:created>2013-05-08t17:03:14.129z</u:created><u:expires>2013-05-08t17:08:14.129z</u:expires> </u:timestamp> <o:binarysecuritytoken u:id="uuid-2e5edef4-96b6-4747-83ad-f8b5a34d1ada-6" valuetype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#x509v3" encodingtype="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#base64binary">l81/yyta2h</e:ciphervalue></e:cipherdata></e:encrypteddata></s:body></s:envelope>
questions: why not generating usernametoken 2) how wsse headers. external service url uses http
ok got nonce work using these links
wcf: adding nonce usernametoken
http://blogs.msdn.com/b/aszego/archive/2010/06/24/usernametoken-profile-vs-wcf.aspx http://www.west-wind.com/weblog/posts/2012/nov/24/wcf-wssecurity-and-wse-nonce-authentication
thanks yaron naveh
Comments
Post a Comment