Commit a62b69fb authored by Oleg Korshul's avatar Oleg Korshul

.

parent 5eb36efb
...@@ -8,6 +8,22 @@ ...@@ -8,6 +8,22 @@
#define OOXML_HASH_ALG_SHA1 0 #define OOXML_HASH_ALG_SHA1 0
#define OOXML_HASH_ALG_INVALID 1 #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 class Q_DECL_EXPORT ICertificate
{ {
public: public:
...@@ -26,6 +42,9 @@ public: ...@@ -26,6 +42,9 @@ public:
virtual std::string GetCertificateBase64() = 0; virtual std::string GetCertificateBase64() = 0;
virtual std::string GetCertificateHash() = 0; virtual std::string GetCertificateHash() = 0;
virtual std::string GetDate() = 0;
virtual std::string GetId() = 0;
public: public:
virtual std::string Sign(const std::string& sXml) = 0; virtual std::string Sign(const std::string& sXml) = 0;
virtual std::string GetHash(unsigned char* pData, unsigned int nSize, int nAlg) = 0; virtual std::string GetHash(unsigned char* pData, unsigned int nSize, int nAlg) = 0;
...@@ -39,6 +58,18 @@ public: ...@@ -39,6 +58,18 @@ public:
virtual bool ShowSelectDialog() = 0; virtual bool ShowSelectDialog() = 0;
virtual int ShowCertificate() = 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: public:
static int GetOOXMLHashAlg(const std::string& sAlg); static int GetOOXMLHashAlg(const std::string& sAlg);
static ICertificate* CreateInstance(); static ICertificate* CreateInstance();
......
...@@ -543,5 +543,7 @@ int COOXMLVerifier::GetSignatureCount() ...@@ -543,5 +543,7 @@ int COOXMLVerifier::GetSignatureCount()
COOXMLSignature* COOXMLVerifier::GetSignature(const int& index) COOXMLSignature* COOXMLVerifier::GetSignature(const int& index)
{ {
if (index >= (int)m_internal->m_arSignatures.size())
return NULL;
return m_internal->m_arSignatures[index]; return m_internal->m_arSignatures[index];
} }
...@@ -26,3 +26,67 @@ ICertificate* ICertificate::CreateInstance() ...@@ -26,3 +26,67 @@ ICertificate* ICertificate::CreateInstance()
{ {
return new CCertificate(); 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 ...@@ -16,6 +16,7 @@ class CCertificate_mscrypto : public ICertificate
public: public:
HCERTSTORE m_store; HCERTSTORE m_store;
PCCERT_CONTEXT m_context; PCCERT_CONTEXT m_context;
bool m_release;
protected: protected:
BYTE* m_rawData; BYTE* m_rawData;
...@@ -29,6 +30,8 @@ public: ...@@ -29,6 +30,8 @@ public:
m_rawData = NULL; m_rawData = NULL;
m_rawDataLen = 0; m_rawDataLen = 0;
m_release = false;
} }
CCertificate_mscrypto(PCCERT_CONTEXT ctx) : ICertificate() CCertificate_mscrypto(PCCERT_CONTEXT ctx) : ICertificate()
{ {
...@@ -37,11 +40,13 @@ public: ...@@ -37,11 +40,13 @@ public:
m_rawData = NULL; m_rawData = NULL;
m_rawDataLen = 0; m_rawDataLen = 0;
m_release = false;
} }
virtual ~CCertificate_mscrypto() virtual ~CCertificate_mscrypto()
{ {
if (m_store != NULL || m_rawData != NULL) if (m_store != NULL || m_rawData != NULL || m_release)
{ {
if (NULL != m_context) if (NULL != m_context)
CertFreeCertificateContext(m_context); CertFreeCertificateContext(m_context);
...@@ -99,6 +104,33 @@ public: ...@@ -99,6 +104,33 @@ public:
return GetHash(m_context->pbCertEncoded, (unsigned int)m_context->cbCertEncoded, OOXML_HASH_ALG_SHA1); 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: public:
virtual std::string Sign(const std::string& sXml) virtual std::string Sign(const std::string& sXml)
{ {
......
...@@ -45,6 +45,16 @@ public: ...@@ -45,6 +45,16 @@ public:
return ""; return "";
} }
virtual std::string GetDate()
{
return "";
}
virtual std::string GetId()
{
return "";
}
public: public:
virtual std::string Sign(const std::string& sXml) 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