New scheme for openssl certificate selection

This commit is contained in:
Oleg Korshul
2018-04-22 15:34:36 +03:00
committed by Alexey Golubev
parent f0ffb7f14c
commit aad12cf471
5 changed files with 50 additions and 95 deletions

View File

@ -15,31 +15,11 @@
#define OPEN_SSL_WARNING_PASS 4
#define OPEN_SSL_WARNING_NOVERIFY 8
class ICertificate;
class Q_DECL_EXPORT ICertificateSelectDialogOpenSsl
namespace NSOpenSSL
{
public:
ICertificateSelectDialogOpenSsl()
{
}
virtual ~ICertificateSelectDialogOpenSsl()
{
}
public:
virtual std::wstring GetCertificatePath() = 0;
virtual std::wstring GetCertificatePassword() = 0;
virtual std::wstring GetKeyPath() = 0;
virtual std::wstring GetKeyPassword() = 0;
virtual bool ShowSelectDialog() = 0;
virtual int ShowCertificate(ICertificate* pCert) = 0;
static int LoadKey(std::wstring file, std::string password);
static int LoadCert(std::wstring file, std::string password);
static void SetOpenSslDialogApplication(ICertificateSelectDialogOpenSsl* pDialog);
};
Q_DECL_EXPORT int LoadKey(std::wstring file, std::string password);
Q_DECL_EXPORT int LoadCert(std::wstring file, std::string password);
}
class Q_DECL_EXPORT CCertificateInfo
{
@ -126,16 +106,16 @@ public:
virtual bool LoadFromBase64Data(const std::string& data) = 0;
public:
virtual bool ShowSelectDialog() = 0;
virtual int ShowSelectDialog() = 0;
virtual int ShowCertificate() = 0;
virtual void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog) {}
static CCertificateInfo GetDefault();
static ICertificate* GetById(const std::string& id);
virtual CCertificateInfo GetInfo();
virtual bool FromFiles(const std::wstring& keyPath, const std::string& keyPassword, const std::wstring& certPath, const std::string& certPassword);
public:
static int GetOOXMLHashAlg(const std::string& sAlg);
static ICertificate* CreateInstance();

View File

@ -2,14 +2,17 @@
#include "./XmlSigner_mscrypto.h"
#define CCertificate CCertificate_mscrypto
int ICertificateSelectDialogOpenSsl::LoadKey(std::wstring file, std::string password)
namespace NSOpenSSL
{
return 0;
}
int LoadKey(std::wstring file, std::string password)
{
return 0;
}
int ICertificateSelectDialogOpenSsl::LoadCert(std::wstring file, std::string password)
{
return 0;
int LoadCert(std::wstring file, std::string password)
{
return 0;
}
}
#endif
@ -26,16 +29,6 @@ int ICertificateSelectDialogOpenSsl::LoadCert(std::wstring file, std::string pas
#define CCertificate CCertificate_openssl
#endif
namespace
{
ICertificateSelectDialogOpenSsl* g_application_openssl_gialog = NULL;
}
void ICertificateSelectDialogOpenSsl::SetOpenSslDialogApplication(ICertificateSelectDialogOpenSsl* pDialog)
{
g_application_openssl_gialog = pDialog;
}
int ICertificate::GetOOXMLHashAlg(const std::string& sAlg)
{
if ("http://www.w3.org/2000/09/xmldsig#rsa-sha1" == sAlg ||
@ -48,7 +41,6 @@ int ICertificate::GetOOXMLHashAlg(const std::string& sAlg)
ICertificate* ICertificate::CreateInstance()
{
ICertificate* pCert = new CCertificate();
pCert->SetOpenSslDialog(g_application_openssl_gialog);
return pCert;
}
@ -62,6 +54,11 @@ CCertificateInfo ICertificate::GetInfo()
return info;
}
bool ICertificate::FromFiles(const std::wstring& keyPath, const std::string& keyPassword, const std::wstring& certPath, const std::string& certPassword)
{
return false;
}
CCertificateInfo ICertificate::GetDefault()
{
CCertificateInfo info;

View File

@ -375,20 +375,20 @@ public:
}
public:
virtual bool ShowSelectDialog()
virtual int ShowSelectDialog()
{
m_store = CertOpenSystemStoreA(NULL, "MY");
if (!m_store)
return false;
return 0;
m_context = CryptUIDlgSelectCertificateFromStore(m_store, NULL, NULL, NULL, CRYPTUI_SELECT_LOCATION_COLUMN, 0, NULL);
if (!m_context)
{
CertCloseStore(m_store, 0);
m_store = NULL;
return false;
return 0;
}
return true;
return 1;
}
private:

View File

@ -44,9 +44,6 @@ void X509_FREE(X509*& cert)
class CCertificate_openssl_private
{
protected:
ICertificateSelectDialogOpenSsl* m_pDialog;
X509* m_cert;
EVP_PKEY* m_key;
@ -59,8 +56,6 @@ public:
public:
CCertificate_openssl_private()
{
m_pDialog = NULL;
m_cert = NULL;
m_key = NULL;
@ -117,18 +112,25 @@ public:
return L"";
X509_NAME* name = X509_get_issuer_name(m_cert);
char buffer[1024];
memset(buffer, 0, 1025);
char buffer[10000];
memset(buffer, 0, 10000);
X509_NAME_oneline(name, buffer, 1024);
X509_NAME_oneline(name, buffer, 10000);
std::string sName(buffer);
std::wstring sNameW = UTF8_TO_U(sName);
std::wstring::size_type pos = sNameW.find(L"CN=");
if (std::wstring::npos != pos)
{
sNameW = sNameW.substr(pos + 3);
pos = sNameW.find(L"/");
if (std::wstring::npos != pos)
{
sNameW = sNameW.substr(0, pos);
}
}
return sNameW;
}
@ -347,22 +349,9 @@ public:
}
public:
bool ShowSelectDialog()
int ShowSelectDialog()
{
if (!m_pDialog)
return false;
bool bResult = m_pDialog->ShowSelectDialog();
std::wstring sKeyPath = m_pDialog->GetKeyPath();
std::wstring sKeyPasswordW = m_pDialog->GetKeyPassword();
std::string sKeyPassword = U_TO_UTF8(sKeyPasswordW);
std::wstring sCertPath = m_pDialog->GetCertificatePath();
std::wstring sCertPasswordW = m_pDialog->GetCertificatePassword();
std::string sCertPassword = U_TO_UTF8(sCertPasswordW);
return FromFiles(sKeyPath, sKeyPassword, sCertPath, sCertPassword);
return -1;
}
bool FromFiles(const std::wstring& sKeyPath, const std::string& sKeyPassword, const std::wstring& certPath, const std::string& certPassword)
@ -429,14 +418,7 @@ public:
int ShowCertificate()
{
if (m_pDialog)
return m_pDialog->ShowCertificate(m_pBase);
return 1;
}
void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog)
{
m_pDialog = pDialog;
return -1;
}
int VerifySelf()
@ -787,7 +769,7 @@ bool CCertificate_openssl::LoadFromBase64Data(const std::string& data)
return m_internal->LoadFromBase64Data(data);
}
bool CCertificate_openssl::ShowSelectDialog()
int CCertificate_openssl::ShowSelectDialog()
{
return m_internal->ShowSelectDialog();
}
@ -807,17 +789,15 @@ bool CCertificate_openssl::FromId(const std::string& id)
return m_internal->FromKey(id);
}
void CCertificate_openssl::SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog)
namespace NSOpenSSL
{
return m_internal->SetOpenSslDialog(pDialog);
}
int LoadKey(std::wstring file, std::string password)
{
return CCertificate_openssl_private::LoadKey(file, password, NULL);
}
int ICertificateSelectDialogOpenSsl::LoadKey(std::wstring file, std::string password)
{
return CCertificate_openssl_private::LoadKey(file, password, NULL);
}
int ICertificateSelectDialogOpenSsl::LoadCert(std::wstring file, std::string password)
{
return CCertificate_openssl_private::LoadCert(file, password, NULL);
int LoadCert(std::wstring file, std::string password)
{
return CCertificate_openssl_private::LoadCert(file, password, NULL);
}
}

View File

@ -42,13 +42,11 @@ public:
virtual bool LoadFromBase64Data(const std::string& data);
public:
virtual bool ShowSelectDialog();
virtual int ShowSelectDialog();
virtual int ShowCertificate();
bool FromFiles(const std::wstring& keyPath, const std::string& keyPassword, const std::wstring& certPath, const std::string& certPassword);
virtual bool FromFiles(const std::wstring& keyPath, const std::string& keyPassword, const std::wstring& certPath, const std::string& certPassword);
bool FromId(const std::string& id);
virtual void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog);
};
#endif // _XMLSIGNER_OPENSSL_H_