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
(DataFlex) Belgium eHealth Platform - checkAccessControlSee more Belgian eHealth Platform ExamplesDemonstrates the checkAccessControl operation of PlatformIntegrationConsumerTest, which requires an X.509 certificate and signature. This tests the validity of your certificate and signature. For more information, see https://www.ehealth.fgov.be/ehealthplatform/nl/beveiliging-van-webservices#1
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Variant vCert Handle hoCert Handle hoXmlToSign Variant vBdCert Handle hoBdCert Handle hoDt Handle hoGen Handle hoXmlCustomKeyInfo Variant vSbXml Handle hoSbXml Handle hoHttp Variant vResp Handle hoResp String sTemp1 Integer iTemp1 Boolean bTemp1 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Move True To iSuccess // 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.. Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComLoadPfxFile Of hoCert "SSIN=12345678.acc.p12" "p12_password" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End // Create the XML to be signed... Get Create (RefClass(cComChilkatXml)) To hoXmlToSign If (Not(IsComObjectCreated(hoXmlToSign))) Begin Send CreateComObject of hoXmlToSign End Set ComTag Of hoXmlToSign To "soapenv:Envelope" Get ComAddAttribute Of hoXmlToSign "xmlns:soapenv" "http://schemas.xmlsoap.org/soap/envelope/" To iSuccess Get ComAddAttribute Of hoXmlToSign "xmlns:urn" "urn:be:fgov:ehealth:platformintegrationconsumertest:v1" To iSuccess Get ComAddAttribute Of hoXmlToSign "xmlns:urn1" "urn:be:fgov:ehealth:platformintegrationconsumertest:types:v1" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security" True "xmlns:wsse" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security" True "xmlns:wsu" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security|wsse:BinarySecurityToken" True "EncodingType" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security|wsse:BinarySecurityToken" True "ValueType" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security|wsse:BinarySecurityToken" True "wsu:Id" "X509-FC77E2C72083DA8E0F16711753508182856" To iSuccess // --------------------------------------------------------------------------------------------------------------- // 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" // --------------------------------------------------------------------------------------------------------------- Get Create (RefClass(cComChilkatBinData)) To hoBdCert If (Not(IsComObjectCreated(hoBdCert))) Begin Send CreateComObject of hoBdCert End Get pvComObject of hoBdCert to vBdCert Get ComExportCertDerBd Of hoCert vBdCert To iSuccess Get ComGetEncoded Of hoBdCert "base64" To sTemp1 Send ComUpdateChildContent To hoXmlToSign "soapenv:Header|wsse:Security|wsse:BinarySecurityToken" sTemp1 Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security|wsu:Timestamp" True "wsu:Id" "TS-FC77E2C72083DA8E0F16711753508042855" To iSuccess Get Create (RefClass(cComCkDateTime)) To hoDt If (Not(IsComObjectCreated(hoDt))) Begin Send CreateComObject of hoDt End Get ComSetFromCurrentSystemTime Of hoDt To iSuccess Get ComGetAsTimestamp Of hoDt False To sTemp1 Send ComUpdateChildContent To hoXmlToSign "soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Created" sTemp1 Get ComAddSeconds Of hoDt 3600 To iSuccess Get ComGetAsTimestamp Of hoDt False To sTemp1 Send ComUpdateChildContent To hoXmlToSign "soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Expires" sTemp1 Get ComAddSeconds Of hoDt -3600 To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Body" True "wsu:Id" "id-FC77E2C72083DA8E0F16711753508182859" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Body" True "xmlns:wsu" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" To iSuccess Send ComUpdateChildContent To hoXmlToSign "soapenv:Body|urn:CheckAccessControlRequest|urn1:Message" "Hello World" // Create a timestamp with the current date/time in the following format: 2014-12-30T15:29:03.157+01:00 Get ComGetAsTimestamp Of hoDt True To sTemp1 Send ComUpdateChildContent To hoXmlToSign "soapenv:Body|urn:CheckAccessControlRequest|urn1:Timestamp" sTemp1 Get Create (RefClass(cComChilkatXmlDSigGen)) To hoGen If (Not(IsComObjectCreated(hoGen))) Begin Send CreateComObject of hoGen End Set ComSigLocation Of hoGen To "soapenv:Envelope|soapenv:Header|wsse:Security|wsse:BinarySecurityToken" Set ComSigLocationMod Of hoGen To 1 Set ComSigId Of hoGen To "SIG-FC77E2C72083DA8E0F16711753508252860" Set ComSigNamespacePrefix Of hoGen To "ds" Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#" Set ComSignedInfoPrefixList Of hoGen To "soapenv urn urn1" Set ComIncNamespacePrefix Of hoGen To "ec" Set ComIncNamespaceUri Of hoGen To "http://www.w3.org/2001/10/xml-exc-c14n#" Set ComSignedInfoCanonAlg Of hoGen To "EXCL_C14N" Set ComSignedInfoDigestMethod Of hoGen To "sha256" // Set the KeyInfoId before adding references.. Set ComKeyInfoId Of hoGen To "KI-FC77E2C72083DA8E0F16711753508182857" // -------- Reference 1 -------- Get ComAddSameDocRef Of hoGen "TS-FC77E2C72083DA8E0F16711753508042855" "sha256" "EXCL_C14N" "wsse soapenv urn urn1" "" To iSuccess // -------- Reference 2 -------- Get ComAddSameDocRef Of hoGen "id-FC77E2C72083DA8E0F16711753508182859" "sha256" "EXCL_C14N" "urn urn1" "" To iSuccess // -------- Reference 3 -------- Get ComAddSameDocRef Of hoGen "X509-FC77E2C72083DA8E0F16711753508182856" "sha256" "EXCL_C14N" "_EMPTY_" "" To iSuccess Get pvComObject of hoCert to vCert Get ComSetX509Cert Of hoGen vCert True To iSuccess Set ComKeyInfoType Of hoGen To "Custom" // Create the custom KeyInfo XML.. Get Create (RefClass(cComChilkatXml)) To hoXmlCustomKeyInfo If (Not(IsComObjectCreated(hoXmlCustomKeyInfo))) Begin Send CreateComObject of hoXmlCustomKeyInfo End Set ComTag Of hoXmlCustomKeyInfo To "wsse:SecurityTokenReference" Get ComAddAttribute Of hoXmlCustomKeyInfo "wsu:Id" "STR-FC77E2C72083DA8E0F16711753508182858" To iSuccess Get ComUpdateAttrAt Of hoXmlCustomKeyInfo "wsse:Reference" True "URI" "#X509-FC77E2C72083DA8E0F16711753508182856" To iSuccess Get ComUpdateAttrAt Of hoXmlCustomKeyInfo "wsse:Reference" True "ValueType" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" To iSuccess Set ComEmitXmlDecl Of hoXmlCustomKeyInfo To False Get ComGetXml Of hoXmlCustomKeyInfo To sTemp1 Set ComCustomKeyInfoXml Of hoGen To sTemp1 // Load XML to be signed... Get Create (RefClass(cComChilkatStringBuilder)) To hoSbXml If (Not(IsComObjectCreated(hoSbXml))) Begin Send CreateComObject of hoSbXml End Get pvComObject of hoSbXml to vSbXml Get ComGetXmlSb Of hoXmlToSign vSbXml To iSuccess Set ComBehaviors Of hoGen To "IndentedSignature" // Sign the XML... Get pvComObject of hoSbXml to vSbXml Get ComCreateXmlDSigSb Of hoGen vSbXml To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoGen To sTemp1 Showln sTemp1 Procedure_Return End // ----------------------------------------------- // Send the signed XML... Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Get pvComObject of hoCert to vCert Get ComSetSslClientCert Of hoHttp vCert To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Send ComSetRequestHeader To hoHttp "Content-Type" "text/xml" // Change to services.ehealth.fgov.be for the production environment. Get ComGetAsString Of hoSbXml To sTemp1 Get ComPostXml Of hoHttp "https://services-acpt.ehealth.fgov.be/PlatformIntegrationConsumerTest/v1" sTemp1 "utf-8" To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComBodyStr Of hoResp To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iTemp1 Showln "response status code = " iTemp1 Send Destroy of hoResp // A successful response is a 200 status code, with this sample response: // <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> // <soapenv:Header xmlns:v1="urn:be:fgov:ehealth:platformintegrationconsumertest:v1" xmlns:v11="urn:be:fgov:ehealth:platformintegrationconsumertest:types:v1"/> // <soapenv:Body xmlns:ic="urn:be:fgov:ehealth:platformintegrationconsumertest:v1" xmlns:type="urn:be:fgov:ehealth:platformintegrationconsumertest:types:v1"> // <ic:CheckAccessControlResponse> // <type:Message>Hello World</type:Message> // <type:Timestamp>2023-09-28T22:17:26.643+02:00</type:Timestamp> // <type:AuthenticatedConsumer>CN="SSIN=aaaaaa", OU=eHealth-platform Belgium, OU=bbbb, OU="SSIN=aaaaaaa", O=Federal Government, C=BE</type:AuthenticatedConsumer> // </ic:CheckAccessControlResponse> // </soapenv:Body> // </soapenv:Envelope> End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.