diff --git a/win-linux/defaults.pri b/win-linux/defaults.pri index 0af1399e9..ab263154d 100644 --- a/win-linux/defaults.pri +++ b/win-linux/defaults.pri @@ -126,6 +126,9 @@ app_linux { $$PWD/src/linux/csinglewindow.cpp \ $$PWD/src/linux/singleapplication.cpp + HEADERS += $$PWD/src/linux/cdialogopenssl.h + SOURCES += $$PWD/src/linux/cdialogopenssl.cpp + DEFINES += LINUX _LINUX CONFIG += link_pkgconfig PKGCONFIG += glib-2.0 gdk-2.0 gtkglext-1.0 atk cairo gtk+-unix-print-2.0 diff --git a/win-linux/src/cascapplicationmanagerwrapper.cpp b/win-linux/src/cascapplicationmanagerwrapper.cpp index 757a96c32..c53032cc8 100644 --- a/win-linux/src/cascapplicationmanagerwrapper.cpp +++ b/win-linux/src/cascapplicationmanagerwrapper.cpp @@ -18,6 +18,9 @@ #ifdef _WIN32 #include "csplash.h" #else +# ifdef DOCUMENTSCORE_OPENSSL_SUPPORT +# include "linux/cdialogopenssl.h" +# endif #endif @@ -315,6 +318,13 @@ void CAscApplicationManagerWrapper::startApp() } } #endif + +#ifdef DOCUMENTSCORE_OPENSSL_SUPPORT + APP_CAST(_app); + + CCertificateSelectDialogOpenSsl * _openSslDialog = new CCertificateSelectDialogOpenSsl(_window); + _app.OpenSsl_SetDialog(_openSslDialog); +#endif } void CAscApplicationManagerWrapper::initializeApp() diff --git a/win-linux/src/linux/cdialogopenssl.cpp b/win-linux/src/linux/cdialogopenssl.cpp new file mode 100644 index 000000000..c4e17a3ca --- /dev/null +++ b/win-linux/src/linux/cdialogopenssl.cpp @@ -0,0 +1,316 @@ +#include "cdialogopenssl.h" +#include "cmessage.h" + +#include +#include +#include +#include + +#include +#include + +class CSslDialog_Private +{ +public: + CSslDialog_Private(QWidget * parent = nullptr) + : _txtCertPath(new QLineEdit(parent)) + , _txtCertPass(new QLineEdit(parent)) + , _txtKeyPath(new QLineEdit(parent)) + , _txtKeyPass(new QLineEdit(parent)) + , _btnCertFile(new QPushButton("...", parent)) + , _btnKeyFile(new QPushButton("...", parent)) + , _labelCertPass(new QLabel(parent)) + , _labelKeyPass(new QLabel(parent)) + { + _txtCertPass->setEchoMode(QLineEdit::Password); + _txtKeyPass->setEchoMode(QLineEdit::Password); + } + + void setKeyDisabled(bool v = true) { + _txtKeyPath->setDisabled(v); + _btnKeyFile->setDisabled(v); + _txtKeyPass->setDisabled(v); + _labelKeyPass->setDisabled(v); + } + + void clearKey(bool disable = false) { + _txtKeyPath->clear(); + _txtKeyPass->clear(); + + if ( disable ) { + setKeyDisabled(true); + } + } + + void setPassDisabled(QString type = QString(), bool value = true) { + if ( type == "cert" || type.isEmpty() ) { + _txtCertPass->setDisabled(value); + _labelCertPass->setDisabled( value); + } + if ( type == "key" || type.isEmpty() ) { + _txtKeyPass->setDisabled(value); + _labelKeyPass->setDisabled( value); + } + } + + void clearCertPass(bool disable = false) { + _txtCertPass->clear(); + if ( disable ) + _txtCertPass->setDisabled(true); + } + + QString certificatePath() { + return _txtCertPath->text().trimmed(); + } + + QString certificatePassword() { + return _txtCertPass->text().trimmed(); + } + + QString keyPath() { + if ( _txtKeyPath->isEnabled() ) + return _txtKeyPath->text().trimmed(); + else return ""; + } + + QString keyPassword() { + if ( _txtKeyPass->isEnabled() ) + return _txtKeyPass->text().trimmed(); + else return ""; + } +public: + QLineEdit * _txtCertPath, + * _txtCertPass, + * _txtKeyPath, + * _txtKeyPass; + QPushButton * _btnCertFile, + * _btnKeyFile; + QLabel * _labelCertPass, + * _labelKeyPass; +}; + +CDialogOpenSsl::CDialogOpenSsl(QWidget *parent, CCertificateSelectDialogOpenSsl*) + : QDialog(parent) + , m_private(new CSslDialog_Private) +{ + setMinimumWidth(300); + setWindowTitle(tr("Select certificate")); + + QGridLayout * _main_layout = new QGridLayout(this); + + m_private->_txtCertPath->setPlaceholderText(tr("select certificate file...")); + m_private->_labelCertPass->setText(tr("Certifacate password:")); + m_private->_txtKeyPath->setPlaceholderText(tr("select key file...")); + m_private->_labelKeyPass->setText(tr("Key password:")); + + connect(m_private->_btnCertFile, &QPushButton::clicked, this, &CDialogOpenSsl::onBtnCertificateClick); + connect(m_private->_btnKeyFile, &QPushButton::clicked, this, &CDialogOpenSsl::onBtnKeyClick); + + QHBoxLayout * _pass_layout = new QHBoxLayout; + _pass_layout->addWidget(m_private->_labelCertPass); + _pass_layout->addWidget(m_private->_txtCertPass, 1); + + QHBoxLayout * _keypass_layout = new QHBoxLayout; + _keypass_layout->addWidget(m_private->_labelKeyPass); + _keypass_layout->addWidget(m_private->_txtKeyPass, 1); + + _main_layout->setColumnStretch(0, 1); + _main_layout->setRowStretch(3, 2); + _main_layout->setColumnMinimumWidth(1, 20); + + _main_layout->addWidget(m_private->_txtCertPath, 0, 0); + _main_layout->addWidget(m_private->_btnCertFile, 0, 1); + _main_layout->addLayout(_pass_layout, 1, 0); + _main_layout->addWidget(m_private->_txtKeyPath, 2, 0); + _main_layout->addWidget(m_private->_btnKeyFile, 2, 1); + _main_layout->addLayout(_keypass_layout, 3, 0); + _main_layout->addWidget(new QWidget, 4, 0); + _main_layout->setRowStretch(4, 1); + + m_private->setKeyDisabled(true); + m_private->setPassDisabled(); + + QHBoxLayout * _ok_layout = new QHBoxLayout; + _main_layout->addLayout(_ok_layout, 5,0,1,2); + + QPushButton * _btn_ok = new QPushButton("OK"); + _btn_ok->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); + _ok_layout->addWidget(_btn_ok); + +// _btn_ok->setMinimumWidth(30); + _btn_ok->setFixedSize(10,28); + m_private->_btnCertFile->setFixedSize(20,28); + m_private->_btnKeyFile->setFixedSize(20,28); + + m_bIsOK = false; + connect(_btn_ok, &QPushButton::clicked, [=]{ + if ( (m_bIsOK = checkCertificate()) ) { + close(); + } + }); + + QRect rect = this->geometry(); + + int nX = rect.x(); + int nY = rect.y(); + int nW = 500; + int nH = 170; + + if (parent) + { + QRect rectParent = parent->geometry(); + nX = rectParent.center().x() - (nW >> 1); + nY = rectParent.center().y() - (nH >> 1); + } + + this->setGeometry(nX, nY, nW, nH); +} + +CDialogOpenSsl::~CDialogOpenSsl() +{ +} + +void CDialogOpenSsl::resizeEvent(QResizeEvent* e) +{ +} + +void CDialogOpenSsl::onBtnCertificateClick() +{ + QString sDirectory = "~/"; + + QString _file_name = QFileDialog::getOpenFileName(NULL, QString(), sDirectory +#ifdef FILEDIALOG_DONT_USE_NATIVEDIALOGS + , QString(), Q_NULLPTR, QFileDialog::DontUseNativeDialog +#endif + ); + + if ( !_file_name.isEmpty() ) { + m_private->clearKey(true); + m_private->setPassDisabled(); + + m_private->_txtCertPath->setText(_file_name); + checkCertificate(); + } +} + +void CDialogOpenSsl::onBtnKeyClick() +{ + QString sDirectory = "~/"; + + QString _file_name = QFileDialog::getOpenFileName(NULL, QString(), sDirectory +#ifdef FILEDIALOG_DONT_USE_NATIVEDIALOGS + , QString(), Q_NULLPTR, QFileDialog::DontUseNativeDialog +#endif + ); + + if ( !_file_name.isEmpty() ) { + m_private->setPassDisabled("key"); + m_private->_txtKeyPath->setText(_file_name); + + checkCertificate(); + } +} + +bool CDialogOpenSsl::checkCertificate() +{ + if ( m_private->certificatePath().isEmpty() ) { + CMessage::info(this, tr("Enter certificate path")); + return false; + } + + int _result = CAscApplicationManager::OpenSsl_LoadCert( + m_private->_txtCertPath->text().toStdWString(), m_private->_txtCertPass->text().toStdString() ); + + switch ( _result ) { + case OPEN_SSL_WARNING_ERR: + CMessage::error(this, tr("Certificate is not supported")); + break; + case OPEN_SSL_WARNING_PASS: + m_private->setPassDisabled("cert", false); + m_private->_txtCertPass->setFocus(); + if ( m_private->_txtCertPass->text().isEmpty() ) + CMessage::info(this, tr("Enter certificate password")); + else CMessage::info(this, tr("Wrong certificate password.
Please enter again")); + break; + case OPEN_SSL_WARNING_OK: + case OPEN_SSL_WARNING_ALL_OK: + default: break; + } + + if ( _result == OPEN_SSL_WARNING_OK ) { + if ( m_private->_txtKeyPath->text().isEmpty() ) { + CMessage::info(this, tr("Enter valid private key")); + m_private->_txtKeyPath->setDisabled(false); + m_private->_btnKeyFile->setDisabled(false); + m_private->_txtKeyPath->setFocus(); + } else { + _result = CAscApplicationManager::OpenSsl_LoadKey( + m_private->_txtKeyPass->text().toStdWString(), m_private->_txtKeyPass->text().toStdString() ); + + _result = OPEN_SSL_WARNING_PASS; + switch ( _result ) { + case OPEN_SSL_WARNING_ERR: + CMessage::info(this, tr("Key is not supported")); + break; + case OPEN_SSL_WARNING_PASS: + m_private->setPassDisabled("key", false); + m_private->_txtKeyPass->setFocus(); + CMessage::info(this, tr("Enter key password")); + break; + case OPEN_SSL_WARNING_OK: +// "Strange... it's an unreal situation"; + _result = OPEN_SSL_WARNING_ALL_OK; + break; + case OPEN_SSL_WARNING_ALL_OK: + default: + break; + } + } + } + + return _result == OPEN_SSL_WARNING_ALL_OK; +} + +/////////////// +std::wstring CCertificateSelectDialogOpenSsl::GetCertificatePath() +{ + return m_sCertPath; +} + +std::wstring CCertificateSelectDialogOpenSsl::GetCertificatePassword() +{ + return m_sCertPassword; +} + +std::wstring CCertificateSelectDialogOpenSsl::GetKeyPath() +{ + return m_sKeyPath; +} + +std::wstring CCertificateSelectDialogOpenSsl::GetKeyPassword() +{ + return m_sKeyPassword; +} + +bool CCertificateSelectDialogOpenSsl::ShowSelectDialog() +{ + CDialogOpenSsl oDialog(m_pParent, this); + //oDialog.setAttribute(Qt::WA_DeleteOnClose); + oDialog.setWindowModality(Qt::WindowModal); + oDialog.exec(); + + bool bResult = oDialog.m_bIsOK; + + m_sCertPath = oDialog.m_private->certificatePath().toStdWString(); + m_sCertPassword = oDialog.m_private->keyPath().toStdWString(); + + m_sKeyPath = oDialog.m_private->keyPath().toStdWString(); + m_sKeyPassword = oDialog.m_private->keyPassword().toStdWString(); + + return bResult; +} + +int CCertificateSelectDialogOpenSsl::ShowCertificate(ICertificate* pCert) +{ + return 1; +} diff --git a/win-linux/src/linux/cdialogopenssl.h b/win-linux/src/linux/cdialogopenssl.h new file mode 100644 index 000000000..2196aba91 --- /dev/null +++ b/win-linux/src/linux/cdialogopenssl.h @@ -0,0 +1,67 @@ +#ifndef DIALOG_OPEN_SSL_H +#define DIALOG_OPEN_SSL_H + +#include +#include +#include +#include +#include +#include + +#include "../../../desktop-sdk/ChromiumBasedEditors/lib/include/applicationmanager.h" + +class CCertificateSelectDialogOpenSsl : public ICertificateSelectDialogOpenSsl +{ +public: + QWidget* m_pParent; + CAscApplicationManager* m_pManager = nullptr; + + std::wstring m_sCertPath; + std::wstring m_sCertPassword; + std::wstring m_sKeyPath; + std::wstring m_sKeyPassword; + +public: + CCertificateSelectDialogOpenSsl(QWidget * parent = nullptr) : m_pParent(parent) {} + virtual ~CCertificateSelectDialogOpenSsl(){} + +public: + virtual std::wstring GetCertificatePath(); + virtual std::wstring GetCertificatePassword(); + + virtual std::wstring GetKeyPath(); + virtual std::wstring GetKeyPassword(); + + virtual bool ShowSelectDialog(); + virtual int ShowCertificate(ICertificate* pCert); +}; + +class CSslDialog_Private; +class CDialogOpenSsl : public QDialog +{ + Q_OBJECT + +public: + explicit CDialogOpenSsl(QWidget *parent, CCertificateSelectDialogOpenSsl* openssl); + ~CDialogOpenSsl(); + + virtual void resizeEvent(QResizeEvent*); + void CalculatePlaces(); + + friend class CCertificateSelectDialogOpenSsl; + +public: + bool m_bIsOK; + +private: + bool checkCertificate(); + +protected: + CSslDialog_Private * m_private; + +private slots: + void onBtnCertificateClick(); + void onBtnKeyClick(); +}; + +#endif // DIALOG_OPEN_SSL_H