Zdenek Jonak 8 years ago
commit 8499a4b8e7

@ -0,0 +1,39 @@
#include "eetsigner.h"
#include <QDebug>
#include <QStringList>
EetSigner::EetSigner(QObject *parent) : QObject(parent)
{
}
QByteArray EetSigner::signData(const QByteArray &data)
{
if (!QCA::isSupported("sha256"))
{
return QByteArray();
}
QCA::ConvertResult result;
QCA::KeyBundle bundle = QCA::KeyBundle::fromFile("/home/pepa/Dokumenty/dev/eet/01000003.p12", QCA::SecureArray("eet"), &result);
if (result != QCA::ConvertGood || bundle.isNull())
{
return QByteArray();
}
QCA::PrivateKey privKey = bundle.privateKey();
return privKey.signMessage(QCA::MemoryRegion(data), QCA::EMSA3_SHA256);
}
QByteArray EetSigner::sha1HashData(const QByteArray &data)
{
if (!QCA::isSupported("sha1"))
{
return QByteArray();
}
return QCA::Hash("sha1").hash(QCA::MemoryRegion(data)).toByteArray();
}

@ -0,0 +1,24 @@
#ifndef EETSIGNER_H
#define EETSIGNER_H
#include <QObject>
#include <QByteArray>
#include <Qca-qt5/QtCrypto/QtCrypto>
class EetSigner : public QObject
{
Q_OBJECT
public:
explicit EetSigner(QObject *parent = 0);
QByteArray signData(const QByteArray &data);
QByteArray sha1HashData(const QByteArray &data);
private:
QCA::Initializer m_qcaInit;
signals:
public slots:
};
#endif // EETSIGNER_H

@ -18,7 +18,32 @@ EetTemplate::EetTemplate(const QString &tmp, QObject *parent) : QObject(parent)
QString EetTemplate::fillTemplate(EetRequest *request)
{
return fillTemplateInternal(request, nullptr);
m_template = fillTemplateInternal(request, nullptr);
QString pkp = getPkpString(request);
QByteArray signedPkp = m_signer.signData(pkp.toUtf8());
QByteArray sha1Bkp = m_signer.sha1HashData(signedPkp);
QString base64Sign(signedPkp.toBase64());
QString base16bkp(sha1Bkp.toHex());
QString splitedBkp;
for (int i = 0; i < base16bkp.length(); i++)
{
if (i > 0 && i % 8 == 0)
{
splitedBkp += "-";
}
splitedBkp += base16bkp[i];
}
QMap<QString, QString> varMap;
varMap["pkp"] = base64Sign;
varMap["bkp"] = splitedBkp.toUpper();
return fillTemplate(varMap);
}
QString EetTemplate::fillTemplate(QMap<QString, QString> map)
@ -69,7 +94,17 @@ QString EetTemplate::fillTemplateInternal(EetRequest *request, QMap<QString, QSt
if (value != NULL_VAL)
{
QString attrib = QString("%1=\"%2\"").arg(var, value);
QString attrib;
if (request != NULL)
{
attrib = QString("%1=\"%2\"").arg(var, value);
}
else
{
attrib = value;
}
ret += attrib;
}
@ -78,3 +113,14 @@ QString EetTemplate::fillTemplateInternal(EetRequest *request, QMap<QString, QSt
return ret;
}
QString EetTemplate::getPkpString(EetRequest *request)
{
QString ret = QString("%1|%2|%3|%4|%5|%6").arg(request->property("dic_popl").toString(),
request->property("id_provoz").toString(),
request->property("id_pokl").toString(),
request->property("porad_cis").toString(),
request->property("dat_trzby").toString(),
request->property("celk_trzba").toString());
return ret;
}

@ -6,6 +6,7 @@
#include <QMap>
#include "eetrequest.h"
#include "eetsigner.h"
#define BODY_TEMPLATE ":/res/template_body.txt"
#define REQUEST_TEMPLATE ":/res/template_request.txt"
@ -28,6 +29,8 @@ public slots:
private:
QString m_template;
QString fillTemplateInternal(EetRequest *request, QMap<QString, QString> *map);
QString getPkpString(EetRequest *request);
EetSigner m_signer;
};
#endif // EETTEMPLATE_H

@ -18,18 +18,22 @@ DEFINES += EETCPP_LIBRARY
SOURCES += eetcpp.cpp \
eetrequest.cpp \
eettemplate.cpp \
eetsender.cpp
eetsender.cpp \
eetsigner.cpp
HEADERS += eetcpp.h\
eetcpp_global.h \
eetrequest.h \
eettemplate.h \
eetsender.h
eetsender.h \
eetsigner.h
unix {
target.path = /usr/lib
INSTALLS += target
}
LIBS += -lqca-qt5
RESOURCES += \
resource.qrc

Loading…
Cancel
Save