Commit a62b69fb authored by Oleg Korshul's avatar Oleg Korshul

.

parent 5eb36efb
......@@ -8,6 +8,22 @@
#define OOXML_HASH_ALG_SHA1 0
#define OOXML_HASH_ALG_INVALID 1
class Q_DECL_EXPORT CCertificateInfo
{
public:
std::wstring m_name;
std::string m_date;
std::string m_id;
public:
CCertificateInfo()
{
}
~CCertificateInfo()
{
}
};
class Q_DECL_EXPORT ICertificate
{
public:
......@@ -26,6 +42,9 @@ public:
virtual std::string GetCertificateBase64() = 0;
virtual std::string GetCertificateHash() = 0;
virtual std::string GetDate() = 0;
virtual std::string GetId() = 0;
public:
virtual std::string Sign(const std::string& sXml) = 0;
virtual std::string GetHash(unsigned char* pData, unsigned int nSize, int nAlg) = 0;
......@@ -39,6 +58,18 @@ public:
virtual bool ShowSelectDialog() = 0;
virtual int ShowCertificate() = 0;
static CCertificateInfo GetDefault();
static ICertificate* GetById(const std::string& id);
virtual CCertificateInfo GetInfo()
{
CCertificateInfo info;
info.m_name = GetSignerName();
info.m_date = GetDate();
info.m_id = GetId();
return info;
}
public:
static int GetOOXMLHashAlg(const std::string& sAlg);
static ICertificate* CreateInstance();
......
......@@ -543,5 +543,7 @@ int COOXMLVerifier::GetSignatureCount()
COOXMLSignature* COOXMLVerifier::GetSignature(const int& index)
{
if (index >= (int)m_internal->m_arSignatures.size())
return NULL;
return m_internal->m_arSignatures[index];
}
......@@ -26,3 +26,67 @@ ICertificate* ICertificate::CreateInstance()
{
return new CCertificate();
}
CCertificateInfo ICertificate::GetDefault()
{
CCertificateInfo info;
// detect user name
std::wstring sUserName;
#ifdef WIN32
DWORD dwUserNameLen = 1024;
wchar_t* _name = new wchar_t[dwUserNameLen + 1];
GetUserNameW(_name, &dwUserNameLen);
sUserName = std::wstring(_name);
delete []_name;
#endif
////////////////////
#ifdef WIN32
HANDLE hStoreHandle = CertOpenSystemStoreA(NULL, "MY");
if (!hStoreHandle)
return info;
PCCERT_CONTEXT pCertContext = NULL;
while (pCertContext = CertEnumCertificatesInStore(hStoreHandle, pCertContext))
{
CCertificate_mscrypto _cert(pCertContext);
if (sUserName == _cert.GetSignerName())
{
info = _cert.GetInfo();
}
}
CertCloseStore(hStoreHandle, 0);
#endif
return info;
}
ICertificate* ICertificate::GetById(const std::string& id)
{
#ifdef WIN32
HANDLE hStoreHandle = CertOpenSystemStoreA(NULL, "MY");
if (!hStoreHandle)
return NULL;
PCCERT_CONTEXT pCertContext = NULL;
while (pCertContext = CertEnumCertificatesInStore(hStoreHandle, pCertContext))
{
CCertificate_mscrypto* _cert = new CCertificate_mscrypto(pCertContext);
if (id == _cert->GetId())
{
_cert->m_release = true;
return _cert;
}
RELEASEOBJECT(_cert);
}
CertCloseStore(hStoreHandle, 0);
#endif
return NULL;
}
......@@ -16,6 +16,7 @@ class CCertificate_mscrypto : public ICertificate
public:
HCERTSTORE m_store;
PCCERT_CONTEXT m_context;
bool m_release;
protected:
BYTE* m_rawData;
......@@ -29,6 +30,8 @@ public:
m_rawData = NULL;
m_rawDataLen = 0;
m_release = false;
}
CCertificate_mscrypto(PCCERT_CONTEXT ctx) : ICertificate()
{
......@@ -37,11 +40,13 @@ public:
m_rawData = NULL;
m_rawDataLen = 0;
m_release = false;
}
virtual ~CCertificate_mscrypto()
{
if (m_store != NULL || m_rawData != NULL)
if (m_store != NULL || m_rawData != NULL || m_release)
{
if (NULL != m_context)
CertFreeCertificateContext(m_context);
......@@ -99,6 +104,33 @@ public:
return GetHash(m_context->pbCertEncoded, (unsigned int)m_context->cbCertEncoded, OOXML_HASH_ALG_SHA1);
}
virtual std::string GetDate()
{
SYSTEMTIME t1;
FileTimeToSystemTime(&m_context->pCertInfo->NotBefore, &t1);
SYSTEMTIME t2;
FileTimeToSystemTime(&m_context->pCertInfo->NotAfter, &t2);
std::string sRet = std::to_string(t1.wDay) +
"/" +
std::to_string(t1.wMonth) +
"/" +
std::to_string(t1.wYear) +
" - " +
std::to_string(t1.wDay) +
"/" +
std::to_string(t2.wMonth) +
"/" +
std::to_string(t2.wYear);
return sRet;
}
virtual std::string GetId()
{
// TODO: + public key?
return GetNumber();
}
public:
virtual std::string Sign(const std::string& sXml)
{
......
......@@ -45,6 +45,16 @@ public:
return "";
}
virtual std::string GetDate()
{
return "";
}
virtual std::string GetId()
{
return "";
}
public:
virtual std::string Sign(const std::string& sXml)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment