Compare commits

...

3 Commits

Author SHA1 Message Date
c389801937 . 2017-06-15 14:26:43 +03:00
24214cb561 . 2017-06-15 12:58:07 +03:00
b19191b286 openssl signing bugs 2017-06-15 11:13:18 +03:00
2 changed files with 33 additions and 2 deletions

View File

@ -1,5 +1,8 @@
#include "./../include/OOXMLSigner.h"
#include "./../src/XmlTransform.h"
#include <cstdio>
#include <ctime>
#include <time.h>
class COOXMLSigner_private
{
@ -28,6 +31,20 @@ public:
m_date = L"2017-04-21T08:30:21Z";
std::time_t rawtime;
std::tm* timeinfo;
char buffer1[100];
char buffer2[100];
std::time(&rawtime);
timeinfo = std::gmtime(&rawtime);
std::strftime(buffer1, 100, "%Y-%m-%d", timeinfo);
std::strftime(buffer2, 100, "%H:%M:%S", timeinfo);
std::string date = (std::string(buffer1) + "T" + std::string(buffer2) + "Z");
m_date = NSFile::CUtf8Converter::GetUnicodeFromCharPtr(date);
m_signed_info.WriteString("<CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315\"/>");
m_signed_info.WriteString("<SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>");
}

View File

@ -75,6 +75,17 @@ public:
EVP_PKEY_FREE(m_key);
}
protected:
static void string_replace(std::string& text, const std::string& replaceFrom, const std::string& replaceTo)
{
size_t posn = 0;
while (std::string::npos != (posn = text.find(replaceFrom, posn)))
{
text.replace(posn, replaceFrom.length(), replaceTo);
posn += replaceTo.length();
}
}
public:
std::string GetNumber()
{
@ -143,6 +154,7 @@ public:
std::string::size_type nStart = nPos1 + sFindFirst.length();
sReturn = sReturn.substr(nStart, nPos2 - nStart);
}
string_replace(sReturn, "\n", "");
BIO_free(bio);
return sReturn;
@ -278,12 +290,12 @@ public:
int nDigestLen = 0;
NSFile::CBase64Converter::Decode(sXmlSignature.c_str(), (int)sXmlSignature.length(), pDigestValue, nDigestLen);
int n2 = EVP_VerifyUpdate(pCtx, pDigestValue, (size_t)nDigestLen);
int n2 = EVP_VerifyUpdate(pCtx, (BYTE*)sXml.c_str(), (size_t)sXml.length());
n2 = n2;
EVP_PKEY* pubkey = X509_get_pubkey(m_cert);
int n3 = EVP_VerifyFinal(pCtx, (BYTE*)sXml.c_str(), (unsigned int)sXml.length(), pubkey);
int n3 = EVP_VerifyFinal(pCtx, pDigestValue, (unsigned int)nDigestLen, pubkey);
n3 = n3;
EVP_MD_CTX_destroy(pCtx);
@ -383,6 +395,8 @@ public:
if (!id.empty())
arr.push_back(id);
else if (3 == arr.size())
arr.push_back("");
if (4 != arr.size())
return false;