Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) Signed SOAP for www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/ using BinarySecurityTokenCreates a signed SOAP request for www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/ using a BinarySecurityToken.
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoXmlToSign Handle hoDtNow Handle hoGen Variant vCert Handle hoCert Handle hoXmlCustomKeyInfo Variant vSbXml Handle hoSbXml Variant vBdCert Handle hoBdCert Variant vSbCert64 Handle hoSbCert64 Integer iNReplaced Handle hoVerifier Integer iNumSigs Integer iVerifyIdx Boolean iVerified String sTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Create the following pre-signed SOAP XML: // Note: We'll be constructing a placeholder for the wseBinarySecurityToken in the soapenv:Header. // Chilkat will automatically replace the "BinarySecurityToken_Base64Binary_Content" with actual data when signing the XML. // However: Your application should insert the actual desired timestamp values for wsu:Created and wsuExpires // Typically this is the current system date/time and a few minutes from the current system date/time. // The example below shows a 5 minute window. We'll write code below to insert the current date/time and the current date/time + 5 minutes.. // <?xml version="1.0" encoding="utf-8"?> // <soapenv:Envelope // xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" // xmlns:scat="www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/" // xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" // xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" // xmlns:ds="http://www.w3.org/2000/09/xmldsig#" // xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#"> // <soapenv:Header xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> // <wsse:Security soapenv:mustUnderstand="1"> // <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" // wsu:Id="X509Token">BinarySecurityToken_Base64Binary_Content</wsse:BinarySecurityToken> // <wsu:Timestamp wsu:Id="_1"> // <wsu:Created>2020-03-20T18:08:19Z</wsu:Created> // <wsu:Expires>2020-03-20T18:13:19Z</wsu:Expires> // </wsu:Timestamp> // </wsse:Security> // <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/> // </soapenv:Header> // <soapenv:Body> // <scat:getRuoliStruttureOperatore> // <scat:codFiscaleOperatore>CLDxxxxxxxxxxxxL</scat:codFiscaleOperatore> // </scat:getRuoliStruttureOperatore> // </soapenv:Body> // </soapenv:Envelope> Move True To iSuccess // 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:scat" "www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/" To iSuccess Get ComAddAttribute Of hoXmlToSign "xmlns:wsse" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" To iSuccess Get ComAddAttribute Of hoXmlToSign "xmlns:wsu" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" To iSuccess Get ComAddAttribute Of hoXmlToSign "xmlns:ds" "http://www.w3.org/2000/09/xmldsig#" To iSuccess Get ComAddAttribute Of hoXmlToSign "xmlns:exc14n" "http://www.w3.org/2001/10/xml-exc-c14n#" To iSuccess Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header" 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" True "soapenv:mustUnderstand" "1" 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 "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 "wsu:Id" "X509Token" To iSuccess Send ComUpdateChildContent To hoXmlToSign "soapenv:Header|wsse:Security|wsse:BinarySecurityToken" "BinarySecurityToken_Base64Binary_Content" Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security|wsu:Timestamp" True "wsu:Id" "_1" To iSuccess // Insert a 5-minute timestampe window. Get Create (RefClass(cComCkDateTime)) To hoDtNow If (Not(IsComObjectCreated(hoDtNow))) Begin Send CreateComObject of hoDtNow End Get ComSetFromCurrentSystemTime Of hoDtNow To iSuccess Get ComGetAsTimestamp Of hoDtNow False To sTemp1 Send ComUpdateChildContent To hoXmlToSign "soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Created" sTemp1 // Add 5 minutes to the time. Get ComAddSeconds Of hoDtNow 300 To iSuccess Get ComGetAsTimestamp Of hoDtNow False To sTemp1 Send ComUpdateChildContent To hoXmlToSign "soapenv:Header|wsse:Security|wsu:Timestamp|wsu:Expires" sTemp1 Get ComUpdateAttrAt Of hoXmlToSign "soapenv:Header|wsse:Security[1]" True "xmlns:wsse" "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" To iSuccess Send ComUpdateChildContent To hoXmlToSign "soapenv:Body|scat:getRuoliStruttureOperatore|scat:codFiscaleOperatore" "CLDxxxxxxxxxxxxL" Showln "XML to sign:" Get ComGetXml Of hoXmlToSign To sTemp1 Showln 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" Set ComSigLocationMod Of hoGen To 0 Set ComSigNamespacePrefix Of hoGen To "ds" Set ComSigNamespaceUri Of hoGen To "http://www.w3.org/2000/09/xmldsig#" Set ComSignedInfoCanonAlg Of hoGen To "EXCL_C14N" Set ComSignedInfoDigestMethod Of hoGen To "sha1" // Set the KeyInfoId before adding references.. Set ComKeyInfoId Of hoGen To "X509KeyId" // -------- Reference 1 -------- Get ComAddSameDocRef Of hoGen "_1" "sha1" "EXCL_C14N" "" "" To iSuccess // Provide a certificate + private key. (PFX password is test123) Get Create (RefClass(cComChilkatCert)) To hoCert If (Not(IsComObjectCreated(hoCert))) Begin Send CreateComObject of hoCert End Get ComLoadPfxFile Of hoCert "qa_data/pfx/cert_test123.pfx" "test123" To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoCert To sTemp1 Showln sTemp1 Procedure_Return End 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" "X509TokenReference" To iSuccess Get ComUpdateAttrAt Of hoXmlCustomKeyInfo "wsse:Reference" True "URI" "#X509Token" 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 // Update BinarySecurityToken_Base64Binary_Content with the actual X509 of the signing cert. 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 Create (RefClass(cComChilkatStringBuilder)) To hoSbCert64 If (Not(IsComObjectCreated(hoSbCert64))) Begin Send CreateComObject of hoSbCert64 End Get pvComObject of hoSbCert64 to vSbCert64 Get ComGetEncodedSb Of hoBdCert "base64" vSbCert64 To iSuccess Get ComGetAsString Of hoSbCert64 To sTemp1 Get ComReplace Of hoSbXml "BinarySecurityToken_Base64Binary_Content" sTemp1 To iNReplaced 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 // ----------------------------------------------- // Save the signed XML to a file. Get ComWriteFile Of hoSbXml "qa_output/signedXml.xml" "utf-8" False To iSuccess Get ComGetAsString Of hoSbXml To sTemp1 Showln sTemp1 // Produces the following signed XML: // Note: The following has been edited for readability. Therefore, what you see here will not actually validate because it's been modified. // <?xml version="1.0" encoding="utf-8"?> // <soapenv:Envelope // xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" // xmlns:scat="www.sist.puglia.it/Schemas/PDD_SIST/SCATEL/" // xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" // xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" // xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:exc14n="http://www.w3.org/2001/10/xml-exc-c14n#"> // <soapenv:Header xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> // <wsse:Security soapenv:mustUnderstand="1"> // <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" wsu:Id="X509Token">MIIFNTCCBB2gAwIBAgIQHozVnBl1lTsusAh26u6WZTANBgkqhkiG9w0BAQsFADCB // lzELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G // A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxPTA7BgNV // BAMTNENPTU9ETyBSU0EgQ2xpZW50IEF1dGhlbnRpY2F0aW9uIGFuZCBTZWN1cmUg // RW1haWwgQ0EwHhcNMTcxMjE0MDAwMDAwWhcNMTgxMjE0MjM1OTU5WjAmMSQwIgYJ // KoZIhvcNAQkBFhVhc2Rhc2Rhc2Rhc2RkQGJ5b20uZGUwggEiMA0GCSqGSIb3DQEB // AQUAA4IBDwAwggEKAoIBAQC96oQe50EDoiuJVITeKJzy6GzVq74cEa14eFypjMNb // YVyedfCI6cn9pVClLqL7dlwxFGCRA62bbNE9woKLBT3SO1IvgoFDVIrbJm+84GEo // qQ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jUKEuK6Kv6wZ3/XugsBoNrMYWlYX8g2jWVDBCJ+Z0eT // QkaYkeSxzBSMQP3DxJS/bWh5LfwSyWYk4a3SVRJV4QVyBDXKt2uwjj1wWfxfGtiw // 6uAd2F3YIymZKsRVdrU6+h0gXMnmtpX8T+SDV6M72PP2/ZzF6gVVItyyrIScK1J8 // mcEaR5GGkLBk1s9qQM9esp3FRlACVeb1Qlytr4vgc5FlCqn0rMtjlF4= // </wsse:BinarySecurityToken> // <wsu:Timestamp wsu:Id="_1"> // <wsu:Created>2020-03-26T17:19:50Z</wsu:Created> // <wsu:Expires>2020-03-26T17:24:50Z</wsu:Expires> // </wsu:Timestamp> // </wsse:Security> // <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> // <ds:SignedInfo> // <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> // <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> // <ds:Reference URI="#_1"> // <ds:Transforms> // <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/> // </ds:Transforms> // <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> // <ds:DigestValue>cwrTw7wFZqNc50NxE//UT11qZCY=</ds:DigestValue> // </ds:Reference> // </ds:SignedInfo> // <ds:SignatureValue>s2UmYNVDz9dm3eU ... 619qSZqw==</ds:SignatureValue> // <ds:KeyInfo Id="X509KeyId"><wsse:SecurityTokenReference wsu:Id="X509TokenReference"> // <wsse:Reference URI="#X509Token" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> // </wsse:SecurityTokenReference> // </ds:KeyInfo> // </ds:Signature></wsse:Security> // </soapenv:Header> // <soapenv:Body> // <scat:getRuoliStruttureOperatore> // <scat:codFiscaleOperatore>CLDxxxxxxxxxxxxL</scat:codFiscaleOperatore> // </scat:getRuoliStruttureOperatore> // </soapenv:Body> // </soapenv:Envelope> // ---------------------------------------- // Verify the signatures we just produced... Get Create (RefClass(cComChilkatXmlDSig)) To hoVerifier If (Not(IsComObjectCreated(hoVerifier))) Begin Send CreateComObject of hoVerifier End Get pvComObject of hoSbXml to vSbXml Get ComLoadSignatureSb Of hoVerifier vSbXml To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoVerifier To sTemp1 Showln sTemp1 Procedure_Return End Get ComNumSignatures Of hoVerifier To iNumSigs Move 0 To iVerifyIdx While (iVerifyIdx < iNumSigs) Set ComSelector Of hoVerifier To iVerifyIdx Get ComVerifySignature Of hoVerifier True To iVerified If (iVerified <> True) Begin Get ComLastErrorText Of hoVerifier To sTemp1 Showln sTemp1 Procedure_Return End Move (iVerifyIdx + 1) To iVerifyIdx Loop Showln "All signatures were successfully verified." End_Procedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.