Commit 525b8285 authored by Alexey.Musinov's avatar Alexey.Musinov

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

* 'develop' of https://github.com/ONLYOFFICE/core:
  TextParagraphPr swap marR/marL
  .
  .
  .
  Use `uname -m` for determine linux x64\x686
  Add travis example config
  .
parents f64ee80a f6402813
language: cpp
\ No newline at end of file
language: cpp
compiler: gcc
dist: trusty
addons:
apt:
packages:
- p7zip-full
script:
- exit 0
# Build fails anyway. See explanation in
# https://github.com/ONLYOFFICE/core/pull/29#issuecomment-306773327
- cd Common/3dParty && ./make.sh
- cd ../../
- make
\ No newline at end of file
......@@ -189,8 +189,8 @@ namespace PPTX
WritingElement_ReadAttributes_Read_else_if( oReader, _T("lvl"), lvl)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("algn"), algn)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("fontAlgn"),fontAlgn)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marL"), marR)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marR"), marL)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marL"), marL)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("marR"), marR)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("indent"), indent)
WritingElement_ReadAttributes_Read_else_if( oReader, _T("defTabSz"),defTabSz)
WritingElement_ReadAttributes_End ( oReader )
......@@ -541,4 +541,4 @@ namespace PPTX
} // namespace Logic
} // namespace PPTX
#endif // PPTX_LOGIC_TEXTPARAGRAPHPR_INCLUDE_H_
\ No newline at end of file
#endif // PPTX_LOGIC_TEXTPARAGRAPHPR_INCLUDE_H_
......@@ -452,6 +452,14 @@ namespace NSStringExt
return arrElements;
}
static inline void ToLower(std::string& wsString)
{
std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towlower);
}
static inline void ToUpper(std::string& wsString)
{
std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towupper);
}
static inline void ToLower(std::wstring& wsString)
{
std::transform(wsString.begin(), wsString.end(), wsString.begin(), ::towlower);
......
#-------------------------------------------------
#
# Project created by QtCreator 2017-06-05T12:59:43
#
#-------------------------------------------------
QT += core gui
QT += widgets
TARGET = OpenSSL_gui_test
TEMPLATE = app
DEFINES -= \
UNICODE \
_UNICODE
CORE_ROOT_DIR = $$PWD/../../../..
PWD_ROOT_DIR = $$PWD
include($$CORE_ROOT_DIR/Common/base.pri)
core_linux {
QMAKE_LFLAGS += -Wl,--rpath=./
QMAKE_LFLAGS += -static-libstdc++ -static-libgcc
}
DEFINES += XMLSEC_OPENSSL_110
#DEFINES += "OPENSSL_API_COMPAT=\"0x10100000\""
INCLUDEPATH += $$PWD/../../openssl/include
LIBS += -L$$PWD/../../openssl -lssl
LIBS += -L$$PWD/../../openssl -lcrypto
LIBS += -ldl
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
HEADERS += opensslwrapper.h
SOURCES += opensslwrapper.cpp
#include "mainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
#include "mainwindow.h"
#include <QGridLayout>
#include <QFileDialog>
#include <QtNetwork/QSslSocket>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
QRect rect = this->geometry();
this->setGeometry(rect.x(), rect.y(), 600, 170);
QGridLayout *mainGridLayout = new QGridLayout();
mainGridLayout->setSpacing( 0 );
mainGridLayout->setMargin( 0 );
setLayout( mainGridLayout );
QWidget *centralWidget = new QWidget( this );
centralWidget->setObjectName( "centralWidget" );
centralWidget->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
this->setCentralWidget(centralWidget);
m_pKeyFile = new QPlainTextEdit(centralWidget);
m_pKeyPassword = new QPlainTextEdit(centralWidget);
m_pCertFile = new QPlainTextEdit(centralWidget);
m_pCertPassword = new QPlainTextEdit(centralWidget);
m_pKeyDialog = new QPushButton(centralWidget);
m_pCertDialog = new QPushButton(centralWidget);
m_pOK = new QPushButton(centralWidget);
m_pKeyDialog->setText("...");
m_pCertDialog->setText("...");
m_pOK->setText("OK");
m_pKeyFile->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pKeyPassword->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pCertFile->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
m_pCertPassword->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QObject::connect( m_pKeyDialog, SIGNAL( clicked() ), this, SLOT( pushButtonKeyClicked()) );
QObject::connect( m_pCertDialog, SIGNAL( clicked() ), this, SLOT( pushButtonCertClicked()) );
QObject::connect( m_pOK, SIGNAL( clicked() ), this, SLOT( pushButtonOKClicked()) );
CalculatePlaces();
}
MainWindow::~MainWindow()
{
}
void MainWindow::resizeEvent(QResizeEvent* e)
{
CalculatePlaces();
}
void MainWindow::CalculatePlaces()
{
int nWidth = this->width();
int nHeight = this->height();
int nWidthBetween = 30;
int nWidthButton = 40;
int nWidthPassword = 40;
int nHeightLine = 30;
int nWidthPath = nWidth - 40 - 2 * nWidthBetween - nWidthButton - nWidthPassword;
if (nWidthPath < 20)
nWidthPath = 20;
int nTop1 = 20;
m_pKeyFile->setGeometry(20, nTop1, nWidthPath, nHeightLine);
m_pKeyPassword->setGeometry(20 + nWidthPath + nWidthBetween, nTop1, nWidthPassword, nHeightLine);
m_pKeyDialog->setGeometry(nWidth - 20 - nWidthButton, nTop1, nWidthButton, nHeightLine);
nTop1 = 20 + nHeightLine + 20;
m_pCertFile->setGeometry(20, nTop1, nWidthPath, nHeightLine);
m_pCertPassword->setGeometry(20 + nWidthPath + nWidthBetween, nTop1, nWidthPassword, nHeightLine);
m_pCertDialog->setGeometry(nWidth - 20 - nWidthButton, nTop1, nWidthButton, nHeightLine);
m_pOK->setGeometry((nWidth - 40) >> 1, nTop1 + nHeightLine + 20, 40, nHeightLine);
}
void MainWindow::pushButtonKeyClicked()
{
std::wstring sFile = QFileDialog::getOpenFileName(NULL, QString(), QString()).toStdWString();
if (sFile.empty())
return;
m_pKeyFile->setPlainText(QString::fromStdWString(sFile));
}
void MainWindow::pushButtonCertClicked()
{
std::wstring sFile = QFileDialog::getOpenFileName(NULL, QString(), QString()).toStdWString();
if (sFile.empty())
return;
m_pCertFile->setPlainText(QString::fromStdWString(sFile));
}
void MainWindow::pushButtonOKClicked()
{
COpenssl_library library;
int nKeyValue = library.LoadKey(m_pKeyFile->toPlainText().toStdWString(), m_pKeyPassword->toPlainText().toStdString());
int nCertValue = library.LoadCert(m_pCertFile->toPlainText().toStdWString(), m_pCertPassword->toPlainText().toStdString());
int y = 0;
y++;
}
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QTextEdit>
#include <QPushButton>
#include <QResizeEvent>
#include <QPlainTextEdit>
#include "opensslwrapper.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
virtual void resizeEvent(QResizeEvent*);
void CalculatePlaces();
public:
QPlainTextEdit* m_pKeyFile;
QPlainTextEdit* m_pKeyPassword;
QPushButton* m_pKeyDialog;
QPlainTextEdit* m_pCertFile;
QPlainTextEdit* m_pCertPassword;
QPushButton* m_pCertDialog;
QPushButton* m_pOK;
public slots:
void pushButtonKeyClicked();
void pushButtonCertClicked();
void pushButtonOKClicked();
};
#endif // MAINWINDOW_H
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/x509.h>
#include <openssl/pkcs12.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include <openssl/crypto.h>
#include <openssl/engine.h>
#include <openssl/evp.h>
#include <openssl/conf.h>
#include "../../../common/File.h"
#include "../../../common/String.h"
#include "opensslwrapper.h"
class COpenssl_library_private
{
private:
static bool m_bInit;
public:
EVP_PKEY* m_key;
public:
COpenssl_library_private()
{
if (!m_bInit)
{
SSL_library_init();
OpenSSL_add_all_algorithms();
ERR_load_BIO_strings();
ERR_load_crypto_strings();
m_bInit = true;
}
}
~COpenssl_library_private()
{
ENGINE_cleanup();
CONF_modules_unload(1);
ERR_free_strings();
EVP_cleanup();
CRYPTO_cleanup_all_ex_data();
}
};
bool COpenssl_library_private::m_bInit = false;
std::string GetOpenSslErrors()
{
BIO* bio = BIO_new(BIO_s_mem());
ERR_print_errors(bio);
char *buf = NULL;
size_t len = BIO_get_mem_data(bio, &buf);
std::string sRet((char*)buf, len);
NSStringExt::ToLower(sRet);
BIO_free (bio);
return sRet;
}
bool IsOpenSslPasswordError(const std::string& str)
{
if (std::string::npos != str.find("mac verify error"))
return true;
if (std::string::npos != str.find("mac verify failure"))
return true;
if (std::string::npos != str.find("password"))
return true;
return false;
}
COpenssl_library::COpenssl_library()
{
m_internal = new COpenssl_library_private();
}
COpenssl_library::~COpenssl_library()
{
RELEASEOBJECT(m_internal);
}
int COpenssl_library::LoadKey(std::wstring file, std::string password)
{
BYTE* pData = NULL;
DWORD dwDataLen;
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwDataLen))
return OPEN_SSL_WARNING_ERR;
EVP_PKEY* pKey = NULL;
char* pPassword = (password.empty()) ? NULL : (char*)password.c_str();
BIO* bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
if (PEM_read_bio_PrivateKey(bio, &pKey, NULL, (void*)pPassword))
{
EVP_PKEY_free(pKey);
BIO_free(bio);
return OPEN_SSL_WARNING_OK;
}
std::string sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
EVP_PKEY_free(pKey);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
BIO_free(bio);
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
if (d2i_PrivateKey_bio(bio, &pKey))
{
EVP_PKEY_free(pKey);
BIO_free(bio);
return OPEN_SSL_WARNING_OK;
}
sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
EVP_PKEY_free(pKey);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
BIO_free(bio);
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
if (d2i_PKCS8PrivateKey_bio(bio, &pKey, NULL, (void*)pPassword))
{
EVP_PKEY_free(pKey);
BIO_free(bio);
return OPEN_SSL_WARNING_OK;
}
sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
EVP_PKEY_free(pKey);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
BIO_free(bio);
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
PKCS12* p12 = d2i_PKCS12_bio(bio, NULL);
if (p12)
{
X509* pCert = NULL;
STACK_OF(X509)* pCa = NULL;
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
{
sk_X509_pop_free(pCa, X509_free);
X509_free(pCert);
EVP_PKEY_free(pKey);
PKCS12_free(p12);
BIO_free(bio);
return OPEN_SSL_WARNING_ALL_OK;
}
sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
PKCS12_free(p12);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
PKCS12_free(p12);
}
BIO_free(bio);
return OPEN_SSL_WARNING_ERR;
}
int COpenssl_library::LoadCert(std::wstring file, std::string password)
{
BYTE* pData = NULL;
DWORD dwDataLen;
if (!NSFile::CFileBinary::ReadAllBytes(file, &pData, dwDataLen))
return OPEN_SSL_WARNING_ERR;
X509* pCert = NULL;
char* pPassword = (password.empty()) ? NULL : (char*)password.c_str();
BIO* bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
if (PEM_read_bio_X509(bio, &pCert, NULL, (void*)pPassword))
{
X509_free(pCert);
BIO_free(bio);
return OPEN_SSL_WARNING_OK;
}
std::string sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
X509_free(pCert);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
BIO_free(bio);
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
if (d2i_X509_bio(bio, &pCert))
{
X509_free(pCert);
BIO_free(bio);
return OPEN_SSL_WARNING_OK;
}
sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
X509_free(pCert);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
BIO_free(bio);
bio = BIO_new_mem_buf((void*)pData, (int)dwDataLen);
PKCS12* p12 = d2i_PKCS12_bio(bio, NULL);
if (p12)
{
EVP_PKEY* pKey = NULL;
STACK_OF(X509)* pCa = NULL;
if (PKCS12_parse(p12, pPassword, &pKey, &pCert, &pCa))
{
sk_X509_pop_free(pCa, X509_free);
X509_free(pCert);
EVP_PKEY_free(pKey);
PKCS12_free(p12);
BIO_free(bio);
return OPEN_SSL_WARNING_ALL_OK;
}
sError = GetOpenSslErrors();
if (IsOpenSslPasswordError(sError))
{
PKCS12_free(p12);
BIO_free(bio);
return OPEN_SSL_WARNING_PASS;
}
PKCS12_free(p12);
}
BIO_free(bio);
return OPEN_SSL_WARNING_ERR;
}
#ifndef OPENSSL_WRAPPER
#define OPENSSL_WRAPPER
#define OPEN_SSL_WARNING_OK 0
#define OPEN_SSL_WARNING_ERR 1
#define OPEN_SSL_WARNING_ALL_OK 2
#define OPEN_SSL_WARNING_PASS 4
class COpenssl_library_private;
class COpenssl_library
{
private:
COpenssl_library_private* m_internal;
public:
COpenssl_library();
~COpenssl_library();
int LoadKey(std::wstring file, std::string password);
int LoadCert(std::wstring file, std::string password);
};
#endif // OPENSSL_WRAPPER
......@@ -5,6 +5,7 @@
#include <openssl/pkcs12.h>
#include <openssl/sha.h>
#include <openssl/ssl.h>
#include "../../../common/File.h"
......@@ -43,7 +44,7 @@ static time_t ASN1_GetTimeT(ASN1_TIME* time)
return mktime(&t);
}
#if 1
#if 0
int main()
{
std::wstring sFolderW = NSFile::GetProcessDirectory();
......@@ -140,7 +141,7 @@ int main()
}
#endif
#if 0
#if 1
int main(int argc, char **argv)
{
std::wstring sFolderW = NSFile::GetProcessDirectory();
......@@ -157,6 +158,7 @@ int main(int argc, char **argv)
STACK_OF(X509) *ca = NULL;
PKCS12 *p12;
SSL_library_init();
OpenSSL_add_all_algorithms();
ERR_load_crypto_strings();
......
......@@ -18,7 +18,7 @@ DEFINES += XMLSEC_OPENSSL_110
INCLUDEPATH += $$PWD/../../openssl/include
LIBS += -L$$PWD/../../openssl -lcrypto -lssl
LIBS += -L$$PWD/../../openssl -lssl -lcrypto
LIBS += -ldl
SOURCES += main.cpp
......@@ -21,11 +21,11 @@ else
LIB_PREFIX := lib
MAKE := make -j $(shell grep -c ^processor /proc/cpuinfo)
endif
UNAME_P := $(shell uname -p)
ifeq ($(UNAME_P),x86_64)
UNAME_M := $(shell uname -m)
ifeq ($(UNAME_M),x86_64)
ARCHITECTURE := 64
endif
ifneq ($(filter %86,$(UNAME_P)),)
ifneq ($(filter %86,$(UNAME_M)),)
ARCHITECTURE := 32
endif
endif
......
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