Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Belgium eHealth Platform - AddressBook - Search for ProfessionalsSee more Belgian eHealth Platform ExamplesDemonstrates how to search for professionals using the AddressBook API. For more information, see https://www.ehealth.fgov.be/ehealthplatform/nl/data/file/view/6c419e5685327eed7200d1c543c38a55d5387d30?name=AddressBook%20Consultation%20WS%20v.1%20-%20Cookbook%20v.1.11%20dd%2031082023.pdf
#include <C_CkCertW.h> #include <C_CkXmlW.h> #include <C_CkBinDataW.h> #include <C_CkDateTimeW.h> #include <C_CkXmlDSigGenW.h> #include <C_CkStringBuilderW.h> #include <C_CkHttpW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { BOOL success; HCkCertW cert; HCkXmlW xmlToSign; HCkBinDataW bdCert; HCkDateTimeW dt; HCkXmlDSigGenW gen; HCkXmlW xmlCustomKeyInfo; HCkStringBuilderW sbXml; HCkHttpW http; HCkHttpResponseW resp; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. success = TRUE; // Provide a certificate + private key. // Note: If your certificate + private key is located on a hardware token or smartcard, you can call a different function to load from smartcard.. cert = CkCertW_Create(); success = CkCertW_LoadPfxFile(cert,L"SSIN=12345678.acc.p12",L"p12_password"); if (success != TRUE) { wprintf(L"%s\n",CkCertW_lastErrorText(cert)); CkCertW_Dispose(cert); return; } // Create the XML to be signed... xmlToSign = CkXmlW_Create(); CkXmlW_putTag(xmlToSign,L"soapenv:Envelope"); CkXmlW_AddAttribute(xmlToSign,L"xmlns:soapenv",L"http://schemas.xmlsoap.org/soap/envelope/"); CkXmlW_AddAttribute(xmlToSign,L"xmlns:urn",L"urn:be:fgov:ehealth:platformintegrationconsumertest:v1"); CkXmlW_AddAttribute(xmlToSign,L"xmlns:urn1",L"urn:be:fgov:ehealth:platformintegrationconsumertest:types:v1"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Header|wsse:Security",TRUE,L"xmlns:wsse",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Header|wsse:Security",TRUE,L"xmlns:wsu",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Header|wsse:Security|wsse:BinarySecurityToken",TRUE,L"EncodingType",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Header|wsse:Security|wsse:BinarySecurityToken",TRUE,L"ValueType",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Header|wsse:Security|wsse:BinarySecurityToken",TRUE,L"wsu:Id",L"X509-FC77E2C72083DA8E0F16711753508182856"); // --------------------------------------------------------------------------------------------------------------- // A note about the Id's, such as X509-FC77E2C72083DA8E0F16711753508182856, TS-FC77E2C72083DA8E0F16711753508042855, etc. // These Id's simply need to be unique within the XML document. You don't need to generate new Id's every time. // You can use the same Id's in each XML document that is submitted. The purpose of each Id is to // match the XMLDsig Reference to the element in XML being referenced. // In other words, you could use the Id's "mickey_mouse", "donald_duck", and "goofy", and it would work perfectly OK, // as long as no other XML elements also use the Id's "mickey_mouse", "donald_duck", or "goofy" // --------------------------------------------------------------------------------------------------------------- bdCert = CkBinDataW_Create(); CkCertW_ExportCertDerBd(cert,bdCert); CkXmlW_UpdateChildContent(xmlToSign,L"soapenv:Header|wsse:Security|wsse:BinarySecurityToken",CkBinDataW_getEncoded(bdCert,L"base64")); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Header|wsse:Security|wsu:Timestamp",TRUE,L"wsu:Id",L"TS-FC77E2C72083DA8E0F16711753508042855"); dt = CkDateTimeW_Create(); CkDateTimeW_SetFromCurrentSystemTime(dt); CkXmlW_UpdateChildContent(xmlToSign,L"soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Created",CkDateTimeW_getAsTimestamp(dt,FALSE)); CkDateTimeW_AddSeconds(dt,3600); CkXmlW_UpdateChildContent(xmlToSign,L"soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Expires",CkDateTimeW_getAsTimestamp(dt,FALSE)); CkDateTimeW_AddSeconds(dt,-3600); // The body part of the SOAP request to search for professionals looks like this: // <soapenv:Body> // <urn:SearchProfessionalsRequest Id="id-FC77E2C72083DA8E0F16711753508182859" IssueInstant="2016-03-23T18:49:26.968+01:00" Offset="0" MaxElements="100"> // <urn:SSIN>74062423769</urn:SSIN> // </urn:SearchProfessionalsRequest> // </soapenv:Body> CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Body|urn:SearchProfessionalsRequest",TRUE,L"Id",L"id-FC77E2C72083DA8E0F16711753508182859"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Body|urn:SearchProfessionalsRequest",TRUE,L"IssueInstant",CkDateTimeW_getAsTimestamp(dt,TRUE)); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Body|urn:SearchProfessionalsRequest",TRUE,L"Offset",L"0"); CkXmlW_UpdateAttrAt(xmlToSign,L"soapenv:Body|urn:SearchProfessionalsRequest",TRUE,L"MaxElements",L"100"); CkXmlW_UpdateChildContent(xmlToSign,L"soapenv:Body|urn:SearchProfessionalsRequest|urn:SSIN",L"12345678910"); gen = CkXmlDSigGenW_Create(); CkXmlDSigGenW_putSigLocation(gen,L"soapenv:Envelope|soapenv:Header|wsse:Security|wsse:BinarySecurityToken"); CkXmlDSigGenW_putSigLocationMod(gen,1); CkXmlDSigGenW_putSigId(gen,L"SIG-FC77E2C72083DA8E0F16711753508252860"); CkXmlDSigGenW_putSigNamespacePrefix(gen,L"ds"); CkXmlDSigGenW_putSigNamespaceUri(gen,L"http://www.w3.org/2000/09/xmldsig#"); CkXmlDSigGenW_putSignedInfoPrefixList(gen,L"soapenv urn urn1"); CkXmlDSigGenW_putIncNamespacePrefix(gen,L"ec"); CkXmlDSigGenW_putIncNamespaceUri(gen,L"http://www.w3.org/2001/10/xml-exc-c14n#"); CkXmlDSigGenW_putSignedInfoCanonAlg(gen,L"EXCL_C14N"); CkXmlDSigGenW_putSignedInfoDigestMethod(gen,L"sha256"); // Set the KeyInfoId before adding references.. CkXmlDSigGenW_putKeyInfoId(gen,L"KI-FC77E2C72083DA8E0F16711753508182857"); // -------- Reference 1 -------- CkXmlDSigGenW_AddSameDocRef(gen,L"TS-FC77E2C72083DA8E0F16711753508042855",L"sha256",L"EXCL_C14N",L"wsse soapenv urn urn1",L""); // -------- Reference 2 -------- CkXmlDSigGenW_AddSameDocRef(gen,L"id-FC77E2C72083DA8E0F16711753508182859",L"sha256",L"EXCL_C14N",L"urn urn1",L""); // -------- Reference 3 -------- CkXmlDSigGenW_AddSameDocRef(gen,L"X509-FC77E2C72083DA8E0F16711753508182856",L"sha256",L"EXCL_C14N",L"_EMPTY_",L""); CkXmlDSigGenW_SetX509Cert(gen,cert,TRUE); CkXmlDSigGenW_putKeyInfoType(gen,L"Custom"); // Create the custom KeyInfo XML.. xmlCustomKeyInfo = CkXmlW_Create(); CkXmlW_putTag(xmlCustomKeyInfo,L"wsse:SecurityTokenReference"); CkXmlW_AddAttribute(xmlCustomKeyInfo,L"wsu:Id",L"STR-FC77E2C72083DA8E0F16711753508182858"); CkXmlW_UpdateAttrAt(xmlCustomKeyInfo,L"wsse:Reference",TRUE,L"URI",L"#X509-FC77E2C72083DA8E0F16711753508182856"); CkXmlW_UpdateAttrAt(xmlCustomKeyInfo,L"wsse:Reference",TRUE,L"ValueType",L"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"); CkXmlW_putEmitXmlDecl(xmlCustomKeyInfo,FALSE); CkXmlDSigGenW_putCustomKeyInfoXml(gen,CkXmlW_getXml(xmlCustomKeyInfo)); // Load XML to be signed... sbXml = CkStringBuilderW_Create(); CkXmlW_GetXmlSb(xmlToSign,sbXml); CkXmlDSigGenW_putBehaviors(gen,L"IndentedSignature"); // Sign the XML... success = CkXmlDSigGenW_CreateXmlDSigSb(gen,sbXml); if (success != TRUE) { wprintf(L"%s\n",CkXmlDSigGenW_lastErrorText(gen)); CkCertW_Dispose(cert); CkXmlW_Dispose(xmlToSign); CkBinDataW_Dispose(bdCert); CkDateTimeW_Dispose(dt); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(xmlCustomKeyInfo); CkStringBuilderW_Dispose(sbXml); return; } // ----------------------------------------------- // Send the signed XML... http = CkHttpW_Create(); success = CkHttpW_SetSslClientCert(http,cert); if (success != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkCertW_Dispose(cert); CkXmlW_Dispose(xmlToSign); CkBinDataW_Dispose(bdCert); CkDateTimeW_Dispose(dt); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(xmlCustomKeyInfo); CkStringBuilderW_Dispose(sbXml); CkHttpW_Dispose(http); return; } CkHttpW_SetRequestHeader(http,L"Content-Type",L"text/xml"); CkHttpW_SetRequestHeader(http,L"SOAPAction",L"urn:be:fgov:ehealth:addressbook:protocol:v1:searchProfessionals"); resp = CkHttpW_PostXml(http,L"https://services.ehealth.fgov.be/AddressBook/v1",CkStringBuilderW_getAsString(sbXml),L"utf-8"); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkCertW_Dispose(cert); CkXmlW_Dispose(xmlToSign); CkBinDataW_Dispose(bdCert); CkDateTimeW_Dispose(dt); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(xmlCustomKeyInfo); CkStringBuilderW_Dispose(sbXml); CkHttpW_Dispose(http); return; } wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); wprintf(L"response status code = %d\n",CkHttpResponseW_getStatusCode(resp)); CkHttpResponseW_Dispose(resp); CkCertW_Dispose(cert); CkXmlW_Dispose(xmlToSign); CkBinDataW_Dispose(bdCert); CkDateTimeW_Dispose(dt); CkXmlDSigGenW_Dispose(gen); CkXmlW_Dispose(xmlCustomKeyInfo); CkStringBuilderW_Dispose(sbXml); CkHttpW_Dispose(http); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.