custom Message soap certified
Bonjour, j'aimerai faire un appel à mon web service sécurisé par un certificat x509 en tapant directement le message soap (sans creer de stub/web reference)
le probleme est que je n'arrive pas à générer les "ciphervalues , digestvalue + tout les autre champs générés" (qui sont d'après ce que j'ai compris des données encryptées)
toutes les string défini en début de fichier sont les chaines qui diffèrent d'un appel à l'autre depuis mon client java qui lui utilise les stub.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
string encryptedkey = "l58NppgYk0A8CyS8";
string securityTokenReference = "str_HMvcr7HA4eifVVW9";
string dataReference = "#xPMvy2zL1Srcl6RH";
string cipherValue = "qL7k7N2HJ0k1qkKYXkAG+hFGVCNweEcxWDTf5UEVsfcem6MtNDD1p1VpyTdmhAXsrgjEb5PZsj99UL4jlzSmG4+zt2lKf6cjpppfjY9PKFu4IeWdRDLF9hSdJLMk8Ldju64nUGfIUEOe7Lu1YDUzuxxArvCIayQXUd4Dl0/ypSc=";
string binarySecurityToken = "bst_Z4MBLuPh33uIyX21";
string timestampID = "Timestamp_duPomD25z6Kd7z9G";
string digestValue = "nr2YiKQby1yDhHAPiySEaj0IwDg=";
string bodyID = "Body_moyUixfGUq1emxT2";
string digestValue2 = "4XgPFPQX98SkeE38rgMDKeo2bwc=";
string untRefURI = "unt_8qU01PMUcFw1zcOc";
string digestValue3 = "qaSCT5s50arpLfWpH7Y4bfnlLVE";
string digestValue4 = "wfh7CT47rMDSoUjmNmEPrnULLFY";
string signatureValue = "VI6HG25WIMtbluhrvgDrOSyl+No1C4YB8Ont5AUxvLK0YJLjDTr38YeaiUKZNcz1AKzqJoCzy5YjRS1+A3a/iXADsY3fzlYxNjo6SrOScWPxze1qnoxO7d/fkR6BUIFF92RnD4vPj+qfo+5NgNFbo39wzOoVpz9+mnaastfRUWo=";
string securityTokenReference2 = "str_r2FnZKdnpd2tSAaB";
string encryptedData = "xPMvy2zL1Srcl6RH";
string cipherValue2 = "MljU3mhLeXpc1qtjcY0Zyf1r1ZHukeHQYxKsJ34IEm6fqawYDfW85Bm4AT5NfnfHEVQr90F0WYdIs3dj24faPotK9Wxo0I03NEBo0P0t1CMo3eYtVPz4y8nZLt+yNpGg+q/47AfXZv4NAYLd9KxxzxSnRINcoounMYIfG3bsZ5vCKNrADy84Wg/JuSotQcDgliD9ZO63cJLOwZWB203umgrZGFfTUctq0jw3HKU0IwbECZRulvfdoPZRYIFepfXa63QOolGGAblRnO8TsDPP3Q+ETiQSGfeOa8zXFZ5b+/fegk53ocWfc6t7spYNYIskMK7b4Cu/zu87WG7MQIh4t9RlkrDtYtsJim6lO+4vCq1JAPU07T3APrnQjw930nmJMyAduHzPD1oZWfkZ77D6OEic+ql4cMj1gwOeoAXA+0OEa5wc/fhJSvwrOOHbFxZyMVFgif39t8zYCZn9ciVqY+So5XdjiqII/jcLSqopR25eslP78Uc+XCGzFdxQLdnAACl0ux+QnZ+0IRWYBO3EfzF+f5a+ZVMZpr/wY2UTV2h0u9kFe9qJKQlj4+yfR42DkcboLtN0eRxdvvJLj0x5mKCSKSuMsNEWCkGCIDnDOXL35dp9yZfc1z+qXcn1jnSH";
Uri uri = new Uri("http://FXP-350:7001/ServiceDomaineBeanSecureSSL/ServiceDomaineBeanSecureSSLService");
string data = "<?xml version='1.0' encoding='utf-8'?>" +
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
"<S:Body><ns2:createDeal xmlns:ns2=\"http://service.p.com/\">" +
"<arg0>pastek.NET "+DateTime.Today+" </arg0></ns2:createDeal></S:Body></S:Envelope>";
string xmldatacerti = "<?xml version='1.0' encoding='utf-8'?>"+
"<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
"<S:Header>"+
"<wsse:Security xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" S:mustUnderstand=\"1\">"+
"<ns1:EncryptedKey xmlns:ns1=\"http://www.w3.org/2001/04/xmlenc#\" Id=\""+encryptedkey+"\">"+
"<ns1:EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p\">"+
"<ns2:DigestMethod xmlns:ns2=\"http://www.w3.org/2000/09/xmldsig#\" Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\">"+
"</ns2:DigestMethod>"+
"</ns1:EncryptionMethod>"+
"<ns3:KeyInfo xmlns:ns3=\"http://www.w3.org/2000/09/xmldsig#\">"+
"<wsse:SecurityTokenReference xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" 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\" wsse11:TokenType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" wsu:Id=\""+securityTokenReference+"\">"+
"<wsse:KeyIdentifier EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" ValueType=\"http://docs.oasis-open.org/wss/oasis-wss-soap-message-security-1.1#ThumbprintSHA1\">27dJxxHaIiYpGEKBWCk0lGLN9l0="+
"</wsse:KeyIdentifier>"+
"</wsse:SecurityTokenReference>"+
"</ns3:KeyInfo>"+
"<ns1:CipherData>"+
"<ns1:CipherValue>"+cipherValue+
"</ns1:CipherValue>"+
"</ns1:CipherData>"+
"<ns1:ReferenceList>"+
"<ns1:DataReference URI=\""+dataReference+"\">"+
"</ns1:DataReference>"+
"</ns1:ReferenceList>"+
"</ns1:EncryptedKey>"+
"<wsse:BinarySecurityToken xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" EncodingType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" wsu:Id=\""+binarySecurityToken+"\">MIICLDCCAdYCEEXTJ0/xFNTqNV7cPxQE2mQwDQYJKoZIhvcNAQEEBQAweTELMAkGA1UEBhMCVVMxEDAOBgNVBAgTB015U3RhdGUxDzANBgNVBAcTBk15VG93bjEXMBUGA1UEChMOTXlPcmdhbml6YXRpb24xGTAXBgNVBAsTEEZPUiBURVNUSU5HIE9OTFkxEzARBgNVBAMTCkNlcnRHZW5DQUIwHhcNMTAwMzI5MTQ1NzU2WhcNMjUwMzMwMTQ1NzU2WjB2MQswCQYDVQQGEwJVUzEQMA4GA1UECBYHTXlTdGF0ZTEPMA0GA1UEBxYGTXlUb3duMRcwFQYDVQQKFg5NeU9yZ2FuaXphdGlvbjEZMBcGA1UECxYQRk9SIFRFU1RJTkcgT05MWTEQMA4GA1UEAxYHRlhQLTM1MDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAnoPFIoWc8TT8TZNuntcDlUqkuS7NZep1eznqcyzzYdAjMmuyCoRJPkXExcq7wlIfSfvqgRjEbTrwbKNRqIv8SRRYeGUCcLjk0lTzLNaUvGl0k6btMmqOWg/zOZ8q/fklTRtcNlsGk3wGYGG7KYdl57AI85e1I//NN3cl/oc4VVcCAwEAATANBgkqhkiG9w0BAQQFAANBAFvNoHgimHx6DfwxLXwcMEbRh8iHFDjUBnFxMLUb7sxoAwmgCDff2tayI3AqR3D4H5ucC49CmnmCHuZhkHRhBuI="+
"</wsse:BinarySecurityToken>"+
"<dsig:Signature xmlns:dsig=\"http://www.w3.org/2000/09/xmldsig#\">"+
"<dsig:SignedInfo>"+
"<dsig:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"<exc14n:InclusiveNamespaces xmlns:exc14n=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"</exc14n:InclusiveNamespaces>"+
"</dsig:CanonicalizationMethod>"+
"<dsig:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\">"+
"</dsig:SignatureMethod>"+
"<dsig:Reference URI=\"#"+timestampID+"\">"+
"<dsig:Transforms>"+
"<dsig:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"<exc14n:InclusiveNamespaces xmlns:exc14n=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"</exc14n:InclusiveNamespaces>"+
"</dsig:Transform>"+
"</dsig:Transforms>"+
"<dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\">"+
"</dsig:DigestMethod>"+
"<dsig:DigestValue>"+digestValue+
"</dsig:DigestValue>"+
"</dsig:Reference>"+
"<dsig:Reference URI=\"#"+bodyID+"\">"+
"<dsig:Transforms>"+
"<dsig:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"<exc14n:InclusiveNamespaces xmlns:exc14n=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"</exc14n:InclusiveNamespaces>"+
"</dsig:Transform>"+
"</dsig:Transforms>"+
"<dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\">"+
"</dsig:DigestMethod>"+
"<dsig:DigestValue>"+digestValue2+
"</dsig:DigestValue>"+
"</dsig:Reference>"+
"<dsig:Reference URI=\"#"+untRefURI+"\">"+
"<dsig:Transforms>"+
"<dsig:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"<exc14n:InclusiveNamespaces xmlns:exc14n=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"</exc14n:InclusiveNamespaces>"+
"</dsig:Transform>"+
"</dsig:Transforms>"+
"<dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\">"+
"</dsig:DigestMethod>"+
"<dsig:DigestValue>"+digestValue3+"="+
"</dsig:DigestValue>"+
"</dsig:Reference>"+
"<dsig:Reference URI=\"#" + binarySecurityToken + "\">" +
"<dsig:Transforms>"+
"<dsig:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"<exc14n:InclusiveNamespaces xmlns:exc14n=\"http://www.w3.org/2001/10/xml-exc-c14n#\">"+
"</exc14n:InclusiveNamespaces>"+
"</dsig:Transform>"+
"</dsig:Transforms>"+
"<dsig:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\">"+
"</dsig:DigestMethod>"+
"<dsig:DigestValue>" + digestValue4 + "=" +
"</dsig:DigestValue>"+
"</dsig:Reference>"+
"</dsig:SignedInfo>"+
"<dsig:SignatureValue>"+signatureValue+
"</dsig:SignatureValue>"+
"<dsig:KeyInfo>"+
"<wsse:SecurityTokenReference xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\" 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\" wsse11:TokenType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\" wsu:Id=\""+securityTokenReference2+"\">"+
"<wsse:Reference URI=\"#"+binarySecurityToken+"\" ValueType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3\">"+
"</wsse:Reference>"+
"</wsse:SecurityTokenReference>"+
"</dsig:KeyInfo>"+
"</dsig:Signature>"+
"<ns1:EncryptedData xmlns:ns1=\"http://www.w3.org/2001/04/xmlenc#\" Encoding=\"UTF-8\" Id=\""+encryptedData+"\" MimeType=\"text/xml\" Type=\"http://www.w3.org/2001/04/xmlenc#Element\">"+
"<ns1:EncryptionMethod Algorithm=\"http://www.w3.org/2001/04/xmlenc#aes256-cbc\">"+
"</ns1:EncryptionMethod>"+
"<ns1:CipherData>"+
"<ns1:CipherValue>"+cipherValue2+
"</ns1:CipherValue>"+
"</ns1:CipherData>"+
"</ns1:EncryptedData>"+
"<wsu:Timestamp xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"" + timestampID + "\">" +
"<wsu:Created>2010-03-31T07:15:02Z"+
"</wsu:Created>"+
"<wsu:Expires>2010-04-30T07:16:02Z"+
"</wsu:Expires>"+
"</wsu:Timestamp>"+
"</wsse:Security>"+
"</S:Header>"+
"<S:Body xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" wsu:Id=\"" + bodyID + "\">" +
"<ns2:createDeal xmlns:ns2=\"http://service.p.com/\">"+
"<arg0 xmlns=\"\">poiuytSSL2"+
"</arg0>"+
"</ns2:createDeal>"+
"</S:Body>"+
"</S:Envelope> ";
data = xmldatacerti;
if (uri.Scheme == Uri.UriSchemeHttp)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(uri);
request.Method = WebRequestMethods.Http.Post;
request.ContentLength = data.Length;
request.ContentType = "text/xml; charset=\"utf-8\"";
request.Headers.Add("Authorization", "Basic dXRpbGlzYXRldXIxOnV0aWxpc2F0ZXVyMQ==");
System.Security.Cryptography.X509Certificates.X509Certificate certif =new System.Security.Cryptography.X509Certificates.X509Certificate("c:/tmp/ClientCert.der");
request.ClientCertificates.Add(certif);
StreamWriter writer = new StreamWriter(request.GetRequestStream());
writer.Write(data);
writer.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string tmp = reader.ReadToEnd();
response.Close();
//Response.Write(tmp);
} |