Commit 01ba3b41 authored by Oleg Korshul's avatar Oleg Korshul

openssl signing bugs

parent ddb67584
...@@ -121,14 +121,7 @@ public: ...@@ -121,14 +121,7 @@ public:
static CCertificateInfo GetDefault(); static CCertificateInfo GetDefault();
static ICertificate* GetById(const std::string& id); static ICertificate* GetById(const std::string& id);
virtual CCertificateInfo GetInfo() virtual CCertificateInfo GetInfo();
{
CCertificateInfo info;
info.SetName(GetSignerName());
info.SetDate(GetDate());
info.SetId(GetId());
return info;
}
public: public:
static int GetOOXMLHashAlg(const std::string& sAlg); static int GetOOXMLHashAlg(const std::string& sAlg);
......
...@@ -50,6 +50,15 @@ ICertificate* ICertificate::CreateInstance() ...@@ -50,6 +50,15 @@ ICertificate* ICertificate::CreateInstance()
return pCert; return pCert;
} }
CCertificateInfo ICertificate::GetInfo()
{
CCertificateInfo info;
info.SetName(GetSignerName());
info.SetDate(GetDate());
info.SetId(GetId());
return info;
}
CCertificateInfo ICertificate::GetDefault() CCertificateInfo ICertificate::GetDefault()
{ {
CCertificateInfo info; CCertificateInfo info;
......
...@@ -25,6 +25,22 @@ void BIO_FREE(BIO*& bio) ...@@ -25,6 +25,22 @@ void BIO_FREE(BIO*& bio)
bio = NULL; bio = NULL;
} }
} }
void EVP_PKEY_FREE(EVP_PKEY*& key)
{
if (key)
{
EVP_PKEY_free(key);
key = NULL;
}
}
void X509_FREE(X509*& cert)
{
if (cert)
{
X509_free(cert);
cert = NULL;
}
}
class CCertificate_openssl_private class CCertificate_openssl_private
{ {
...@@ -50,9 +66,9 @@ public: ...@@ -50,9 +66,9 @@ public:
virtual ~CCertificate_openssl_private() virtual ~CCertificate_openssl_private()
{ {
if (NULL != m_cert) if (NULL != m_cert)
X509_free(m_cert); X509_FREE(m_cert);
if (NULL != m_key) if (NULL != m_key)
EVP_PKEY_free(m_key); EVP_PKEY_FREE(m_key);
} }
public: public:
...@@ -76,7 +92,6 @@ public: ...@@ -76,7 +92,6 @@ public:
std::string sReturn(tmp); std::string sReturn(tmp);
BN_free(bn); BN_free(bn);
ASN1_INTEGER_free(asn1_serial);
return sReturn; return sReturn;
} }
...@@ -87,12 +102,13 @@ public: ...@@ -87,12 +102,13 @@ public:
return L""; return L"";
X509_NAME* name = X509_get_issuer_name(m_cert); X509_NAME* name = X509_get_issuer_name(m_cert);
char* utf_8_name = X509_NAME_oneline(name, NULL, 0); char buffer[1024];
memset(buffer, 0, 1025);
std::string sName(utf_8_name); X509_NAME_oneline(name, buffer, 1024);
std::wstring sNameW = UTF8_TO_U(sName);
OPENSSL_free(utf_8_name); std::string sName(buffer);
std::wstring sNameW = UTF8_TO_U(sName);
return sNameW; return sNameW;
} }
...@@ -137,11 +153,9 @@ public: ...@@ -137,11 +153,9 @@ public:
ASN1_TIME* _time1 = X509_get_notBefore(m_cert); ASN1_TIME* _time1 = X509_get_notBefore(m_cert);
struct tm t1 = this->ASN1_GetTimeT(_time1); struct tm t1 = this->ASN1_GetTimeT(_time1);
ASN1_TIME_free(_time1);
ASN1_TIME* _time2 = X509_get_notAfter(m_cert); ASN1_TIME* _time2 = X509_get_notAfter(m_cert);
struct tm t2 = this->ASN1_GetTimeT(_time2); struct tm t2 = this->ASN1_GetTimeT(_time2);
ASN1_TIME_free(_time2);
std::string sRet = std::to_string(t1.tm_mday) + std::string sRet = std::to_string(t1.tm_mday) +
"/" + "/" +
...@@ -154,6 +168,7 @@ public: ...@@ -154,6 +168,7 @@ public:
std::to_string(t2.tm_mon + 1) + std::to_string(t2.tm_mon + 1) +
"/" + "/" +
std::to_string(t2.tm_year + 1900); std::to_string(t2.tm_year + 1900);
return sRet; return sRet;
} }
...@@ -246,7 +261,7 @@ public: ...@@ -246,7 +261,7 @@ public:
n3 = n3; n3 = n3;
EVP_MD_CTX_destroy(pCtx); EVP_MD_CTX_destroy(pCtx);
EVP_PKEY_free(pubkey); EVP_PKEY_FREE(pubkey);
RELEASEARRAYOBJECTS(pDigestValue); RELEASEARRAYOBJECTS(pDigestValue);
...@@ -268,7 +283,7 @@ public: ...@@ -268,7 +283,7 @@ public:
} }
else else
{ {
X509_free(pCert); X509_FREE(pCert);
m_cert = NULL; m_cert = NULL;
} }
...@@ -450,7 +465,7 @@ public: ...@@ -450,7 +465,7 @@ public:
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa)) if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
{ {
sk_X509_pop_free(pCa, X509_free); sk_X509_pop_free(pCa, X509_free);
X509_free(pCert); X509_FREE(pCert);
PKCS12_free(p12); PKCS12_free(p12);
nErr = OPEN_SSL_WARNING_ALL_OK; nErr = OPEN_SSL_WARNING_ALL_OK;
goto end; goto end;
...@@ -467,7 +482,7 @@ public: ...@@ -467,7 +482,7 @@ public:
end: end:
if (NULL == ppKey) if (NULL == ppKey)
EVP_PKEY_free(pKey); EVP_PKEY_FREE(pKey);
else else
*ppKey = pKey; *ppKey = pKey;
...@@ -535,7 +550,7 @@ end: ...@@ -535,7 +550,7 @@ end:
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa)) if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
{ {
sk_X509_pop_free(pCa, X509_free); sk_X509_pop_free(pCa, X509_free);
EVP_PKEY_free(pKey); EVP_PKEY_FREE(pKey);
PKCS12_free(p12); PKCS12_free(p12);
BIO_FREE(bio); BIO_FREE(bio);
nErr = OPEN_SSL_WARNING_ALL_OK; nErr = OPEN_SSL_WARNING_ALL_OK;
...@@ -553,7 +568,7 @@ end: ...@@ -553,7 +568,7 @@ end:
end: end:
if (NULL == ppCert) if (NULL == ppCert)
X509_free(pCert); X509_FREE(pCert);
else else
*ppCert = pCert; *ppCert = pCert;
......
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