<?xml  version="1.0" ?><html>
<head>
<title></title>
</head>
<body>
<div align="left"><font face="Arial"><span style="font-size:10pt">Hi</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I successfully signed xml according to rules http://www.w3.org/TR/xmldsig-core/.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I did it using xmlsec. Signature is correct because I checked it using external tool.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">But I've got an unsolved problem at verifing my signature myself.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I used code published in verify3.c file doing little changes matching to my task</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">and context (CryptoApi, X509, C++Builder6)</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">I read xml file to char* buffer and call my VerifyCert function. It successfully read</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">all certs from &quot;CA&quot; CryptoApi store and put them to xmlsec keys manager using</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">xmlSecMSCryptoAppKeysMngrCertLoadMemory (see LoadCerts() function).</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">But VerifyCert fails during call of xmlSecDSigCtxVerify(). This function returns</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">a few error context via error callback function. They look like:</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">1.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> file:&#160;&#160;&#160;&#160;&#160;&#160;&#160; ..\src\keys.c</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> func:&#160;&#160;&#160;&#160;&#160;&#160;&#160; xmlSecKeysMngrGetKey</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorObject:&#160;&#160; </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorSubject:&#160;&#160;&#160; xmlSecKeysMngrFindKey</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> reason:&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> msg:&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">2.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> file:&#160;&#160;&#160;&#160;&#160;&#160;&#160; ..\src\xmldsig.c</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> func:&#160;&#160;&#160;&#160;&#160;&#160;&#160; xmlSecDSigCtxProcessKeyInfoNode</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorObject:&#160;&#160;&#160; </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorSubject:&#160;&#160;&#160; </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> reason:&#160;&#160;&#160;&#160;&#160;&#160;&#160; 45</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> msg:&#160;&#160;&#160; </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">3.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> file:&#160;&#160;&#160;&#160;&#160;&#160;&#160; ..\src\xmldsig.c</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> func:&#160;&#160;&#160;&#160;&#160;&#160;&#160; xmlSecDSigCtxProcessSignatureNode</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorObject:&#160;&#160; </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorSubject:&#160;&#160;&#160; xmlSecDSigCtxProcessKeyInfoNode</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> reason:&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> msg:</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">4.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> file:&#160;&#160;&#160;&#160;&#160;&#160;&#160; ..\src\xmldsig.c</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> func:&#160;&#160;&#160;&#160;&#160;&#160;&#160; xmlSecDSigCtxVerify</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorObject:&#160;&#160;&#160; </span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> errorSubject:&#160;&#160;&#160; xmlSecDSigCtxSigantureProcessNode</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> reason:&#160;&#160;&#160;&#160;&#160;&#160;&#160; 1</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt"> msg:&#160;&#160;&#160;&#160;&#160; </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">What should I change to make this code to work?</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Where did I mistakes?</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Should I load all certs from CA store, or only proper one?</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Thanx in advance</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Peter</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">My code looks like:</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">//------------------------------------------------------------</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">// loads certs from MsStore</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">//</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">xmlSecKeysMngrPtr LoadCerts(AnsiString StoreName) {</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecKeysMngrPtr mngr = NULL;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // przygotowanie menagera xmlsec</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; mngr = xmlSecKeysMngrCreate();</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(mngr == NULL) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return (NULL);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecCryptoAppDefaultKeysMngrInit(mngr) &lt; 0) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; xmlSecKeysMngrDestroy(mngr);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return (NULL);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; //xmlSecKeyDataFormat secKeyDataFormat = X509_ASN_ENCODING;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // pobranie listy certyfikatow&#160; - retrieving cert list</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; wchar_t wcharStoreName[256];</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; StoreName.WideChar(wcharStoreName, 256);</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; HCERTSTORE hStoreHandle;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; PCCERT_CONTEXT pSignerCert = NULL;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; CRYPT_SIGN_MESSAGE_PARA&#160; SigParams;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; DWORD cbSignedMessageBlob;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; BYTE&#160; *pbSignedMessageBlob;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; DWORD cbDecodedMessageBlob;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; BYTE&#160; *pbDecodedMessageBlob;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; CRYPT_VERIFY_MESSAGE_PARA VerifyParams;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; //--------------------------------------------------------------------</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // opening CryptoApi cert store</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(!( hStoreHandle = CertOpenStore(</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; CERT_STORE_PROV_SYSTEM,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; 0,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; NULL,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; CERT_SYSTEM_STORE_CURRENT_USER,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; wcharStoreName))){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return NULL;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; PCCERT_CONTEXT&#160; pCertContext = NULL;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; int loadResult = 0;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // enumerating certs from CryptoApi store and loading to xmlsec keys menager</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; while(loadResult == 0){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; pCertContext = CertEnumCertificatesInStore(hStoreHandle, pCertContext);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; if(!pCertContext)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; break;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; //char pszNameString[256];</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; //CertGetNameString(pCertContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; //&#160;&#160; pszNameString, 128);</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; //if(strcmp(pszNameString, &quot;Izba Celna w Krakowie&quot;) == 0)</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; loadResult = xmlSecMSCryptoAppKeysMngrCertLoadMemory(mngr,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
pCertContext-&gt;pbCertEncoded,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
pCertContext-&gt;cbCertEncoded,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
xmlSecKeyDataFormatDer,</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 
xmlSecKeyDataTypeTrusted);</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(loadResult &lt; 0){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; // cleaning</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; xmlSecKeysMngrDestroy(mngr);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return NULL;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; return mngr;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">}</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">// --------------------------------------------------------------</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">/* verifing certs</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">/*</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">some explanation: storeName = &quot;CA&quot;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">inBuffer - contains previously loaded xml data</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">inSize&#160;&#160; - size of inBuffer</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">txt - holds error messages</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">*/</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">bool VerifyCert(char *inBuffer, int inSize, char *storeName, int storeNameSize, AnsiString&amp; 
txt){</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; txt = &quot;&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; bool result = true;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecKeysMngrPtr mngr = NULL;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(!InitParser(storeName)){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; txt = &quot;Nie można zainicjalizować parsera&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // setting up error callback</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecErrorsDefaultCallbackEnableOutput (1);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecErrorsSetCallback(myXmlSecErrorsCallback);</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // loading certs from CryptoApi</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; mngr = LoadCerts(storeName);</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(!mngr){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; txt = &quot;TXMLDocumentSign::VerifyCert() - błąd ładowania certyfikatów&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; StopParser();</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlDocPtr doc = NULL;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecDSigCtxPtr dsigCtx = NULL;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlNodePtr node = NULL;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; int res = -1;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // loading data from buffer and parsing</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; doc = xmlParseMemory(inBuffer, inSize);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlNodePtr rootNode = xmlDocGetRootElement(doc);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if ((doc == NULL) || (rootNode == NULL)){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; result = false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; txt = &quot;TXMLDocumentSign::VerifyCert() - brak elemementu głównego w dokumencie 
XML.&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; goto done;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // test code</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; xmlChar *mem&#160; = NULL;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; int size = 0;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; xmlDocDumpMemory(doc, &amp;mem, &amp;size);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; std::auto_ptr&lt;TFileStream&gt; fs (new TFileStream(&quot;dump.xml&quot;, fmCreate));</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; fs-&gt;Write(mem, size);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; fs.release();</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // find start node</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; node = xmlSecFindNode(rootNode, BAD_CAST &quot;Signature&quot;, BAD_CAST 
&quot;http://www.w3.org/2000/09/xmldsig#&quot;/*xmlSecDSigNs*/ );</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(node == NULL) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; result = false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; txt = &quot;TXMLDocumentSign::VerifyCert() - nie można odnaleŁć elementu \&quot;Signature\&quot;.&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; goto done;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // create signature context</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; dsigCtx = xmlSecDSigCtxCreate(mngr);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(dsigCtx == NULL) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; result = false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; txt = &quot;TXMLDocumentSign::VerifyCert() - błąd pozyskiwania kontekstu.&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; goto done;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Verify signature</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecDSigCtxVerify(dsigCtx, node) &lt; 0) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; txt = &quot;TXMLDocumentSign::VerifyCert() - nieudana weryfikacja podpisu.&quot;;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; result = false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; goto done;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(!dsigCtx-&gt;status == xmlSecDSigStatusSucceeded){</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; result = false;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">done:</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // cleanup</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(dsigCtx != NULL) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; xmlSecDSigCtxDestroy(dsigCtx);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(doc != NULL) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; xmlFreeDoc(doc);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; StopParser();</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; return result;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">}</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">// --------------- initialization of xmlsec</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">int InitParser(char *storeName){</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlInitParser();</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; LIBXML_TEST_VERSION xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | 
XML_COMPLETE_ATTRS;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSubstituteEntitiesDefault(1);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">#ifndef XMLSEC_NO_XSLT</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlIndentTreeOutput = 1;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">#endif // XMLSEC_NO_XSLT</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Init xmlsec library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecInit() &lt; 0) {</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return(0);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Check loaded library version</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecCheckVersion() != 1) {</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return(0);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Load default crypto engine if we are supporting dynamic</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // * loading for xmlsec-crypto libraries. Use the crypto library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // * name (&quot;openssl&quot;, &quot;nss&quot;, etc.) to load corresponding</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // * xmlsec-crypto library.</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; //</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">#ifdef XMLSEC_CRYPTO_DYNAMIC_LOADING</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecCryptoDLLoadLibrary(BAD_CAST XMLSEC_CRYPTO) &lt; 0) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return(0);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">#endif // XMLSEC_CRYPTO_DYNAMIC_LOADING</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Init crypto library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecCryptoAppInit(storeName) &lt; 0) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return(0);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Init xmlsec-crypto library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; if(xmlSecCryptoInit() &lt; 0) {</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160;&#160;&#160;&#160; return(0);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; }</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; return 1;</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">}</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">// shutting down xmlsec</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">int StopParser(){</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Shutdown xmlsec-crypto library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecCryptoShutdown();</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Shutdown crypto library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecCryptoAppShutdown();</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Shutdown xmlsec library</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlSecShutdown();</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; // Shutdown libxslt/libxml</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">//#ifndef XMLSEC_NO_XSLT</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">//&#160;&#160; xsltCleanupGlobals();</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">//#endif // XMLSEC_NO_XSLT</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; xmlCleanupParser();</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial"><span style="font-size:10pt">&#160;&#160; return(0);</span></font></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">}</span></font></div>
<div align="left"><br/>
</div>
<div align="left"></div>
</body>
</html>