Commit 6fc6f9ea authored by ElenaSubbotina's avatar ElenaSubbotina

Merge branch 'develop' of https://github.com/ONLYOFFICE/core into develop

parents 270c1fa2 f76a03fa
...@@ -16,11 +16,13 @@ int ICertificateSelectDialogOpenSsl::LoadCert(std::wstring file, std::string pas ...@@ -16,11 +16,13 @@ int ICertificateSelectDialogOpenSsl::LoadCert(std::wstring file, std::string pas
#if defined(_LINUX) && !defined(_MAC) #if defined(_LINUX) && !defined(_MAC)
#include "./XmlSigner_openssl.h" #include "./XmlSigner_openssl.h"
#define XML_CERTIFICATE_USE_OPENSSL
#define CCertificate CCertificate_openssl #define CCertificate CCertificate_openssl
#endif #endif
#ifdef _MAC #ifdef _MAC
#include "./XmlSigner_openssl.h" #include "./XmlSigner_openssl.h"
#define XML_CERTIFICATE_USE_OPENSSL
#define CCertificate CCertificate_openssl #define CCertificate CCertificate_openssl
#endif #endif
...@@ -118,5 +120,14 @@ ICertificate* ICertificate::GetById(const std::string& id) ...@@ -118,5 +120,14 @@ ICertificate* ICertificate::GetById(const std::string& id)
CertCloseStore(hStoreHandle, 0); CertCloseStore(hStoreHandle, 0);
#endif #endif
#ifdef XML_CERTIFICATE_USE_OPENSSL
CCertificate_openssl* pCertificate = (CCertificate_openssl*)CreateInstance();
if (pCertificate->FromId(id))
return pCertificate;
delete pCertificate;
#endif
return NULL; return NULL;
} }
...@@ -50,6 +50,9 @@ protected: ...@@ -50,6 +50,9 @@ protected:
X509* m_cert; X509* m_cert;
EVP_PKEY* m_key; EVP_PKEY* m_key;
std::string m_separator;
std::string m_id;
public: public:
ICertificate* m_pBase; ICertificate* m_pBase;
...@@ -62,6 +65,7 @@ public: ...@@ -62,6 +65,7 @@ public:
m_key = NULL; m_key = NULL;
m_pBase = NULL; m_pBase = NULL;
m_separator = ";;;;;;;ONLYOFFICE;;;;;;;";
} }
virtual ~CCertificate_openssl_private() virtual ~CCertificate_openssl_private()
{ {
...@@ -175,6 +179,8 @@ public: ...@@ -175,6 +179,8 @@ public:
std::string GetId() std::string GetId()
{ {
// TODO: + public key? // TODO: + public key?
if (!m_id.empty())
return m_id;
return GetNumber(); return GetNumber();
} }
...@@ -309,6 +315,14 @@ public: ...@@ -309,6 +315,14 @@ public:
std::wstring sCertPasswordW = m_pDialog->GetCertificatePassword(); std::wstring sCertPasswordW = m_pDialog->GetCertificatePassword();
std::string sCertPassword = U_TO_UTF8(sCertPasswordW); std::string sCertPassword = U_TO_UTF8(sCertPasswordW);
return FromFiles(sKeyPath, sKeyPassword, sCertPath, sCertPassword);
}
bool FromFiles(const std::wstring& sKeyPath, const std::string& sKeyPassword, const std::wstring& certPath, const std::string& certPassword)
{
std::wstring sCertPath = certPath;
std::string sCertPassword = certPassword;
if (sCertPath.empty()) if (sCertPath.empty())
{ {
sCertPath = sKeyPath; sCertPath = sKeyPath;
...@@ -325,8 +339,45 @@ public: ...@@ -325,8 +339,45 @@ public:
if (nErr != OPEN_SSL_WARNING_OK && nErr != OPEN_SSL_WARNING_ALL_OK) if (nErr != OPEN_SSL_WARNING_OK && nErr != OPEN_SSL_WARNING_ALL_OK)
return false; return false;
m_id = U_TO_UTF8(sKeyPath);
m_id += m_separator;
m_id += sKeyPassword;
m_id += m_separator;
m_id += U_TO_UTF8(sCertPath);
m_id += m_separator;
m_id += sCertPassword;
return true; return true;
} }
bool FromKey(const std::string& sId)
{
std::string id = sId;
std::vector<std::string> arr;
size_t pos = 0;
while ((pos = id.find(m_separator)) != std::string::npos)
{
arr.push_back(id.substr(0, pos));
id.erase(0, pos + m_separator.length());
}
if (!id.empty())
arr.push_back(id);
if (4 != arr.size())
return false;
std::string sKeyPathA = arr[0];
std::string sKeyPasswordA = arr[1];
std::string sCertPathA = arr[2];
std::string sCertPasswordA = arr[3];
std::wstring sKeyPath = UTF8_TO_U(sKeyPathA);
std::wstring sCertPath = UTF8_TO_U(sCertPathA);
return FromFiles(sKeyPath, sKeyPasswordA, sCertPath, sCertPasswordA);
}
int ShowCertificate() int ShowCertificate()
{ {
if (m_pDialog) if (m_pDialog)
...@@ -671,6 +722,16 @@ int CCertificate_openssl::ShowCertificate() ...@@ -671,6 +722,16 @@ int CCertificate_openssl::ShowCertificate()
return m_internal->ShowCertificate(); return m_internal->ShowCertificate();
} }
bool CCertificate_openssl::FromFiles(const std::wstring& keyPath, const std::string& keyPassword, const std::wstring& certPath, const std::string& certPassword)
{
return m_internal->FromFiles(keyPath, keyPassword, certPath, certPassword);
}
bool CCertificate_openssl::FromId(const std::string& id)
{
return m_internal->FromKey(id);
}
void CCertificate_openssl::SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog) void CCertificate_openssl::SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog)
{ {
return m_internal->SetOpenSslDialog(pDialog); return m_internal->SetOpenSslDialog(pDialog);
......
...@@ -43,6 +43,9 @@ public: ...@@ -43,6 +43,9 @@ public:
virtual bool ShowSelectDialog(); virtual bool ShowSelectDialog();
virtual int ShowCertificate(); virtual int ShowCertificate();
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); virtual void SetOpenSslDialog(ICertificateSelectDialogOpenSsl* pDialog);
}; };
......
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