Implemented SOAP message generation.
This commit is contained in:
@@ -17,6 +17,7 @@ int main(int argc, char *argv[])
|
||||
request.setCelkTrzba(100);
|
||||
|
||||
EetSender sender;
|
||||
sender.setupSigner("/home/pepa/Dokumenty/dev/eet/01000003.p12", "eet");
|
||||
sender.sendRequest(&request);
|
||||
|
||||
return a.exec();
|
||||
|
||||
+37
-2
@@ -1,16 +1,51 @@
|
||||
#include "eetsender.h"
|
||||
#include "eetsigner.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
EetSender::EetSender(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
m_signer = nullptr;
|
||||
}
|
||||
|
||||
void EetSender::sendRequest(EetRequest *request)
|
||||
{
|
||||
if (m_signer == nullptr)
|
||||
{
|
||||
emit certError();
|
||||
return;
|
||||
}
|
||||
|
||||
request->setUuidZpravy(QUuid::createUuid());
|
||||
|
||||
EetTemplate tempBody(BODY_TEMPLATE);
|
||||
tempBody.setSigner(m_signer);
|
||||
QString strBody = tempBody.fillTemplate(request);
|
||||
|
||||
qDebug() << strBody;
|
||||
QByteArray digest = m_signer->sha256HashData(strBody.toUtf8());
|
||||
QMap<QString, QString> val;
|
||||
val["digest"] = QString(digest.toBase64());
|
||||
EetTemplate tempSignature(SIGNATURE_TEMPLATE);
|
||||
QString strSignature = tempSignature.fillTemplate(val);
|
||||
|
||||
QByteArray sign = m_signer->signData(strSignature.toUtf8());
|
||||
val["signature"] = QString(sign.toBase64());
|
||||
val["soap:Body"] = strBody;
|
||||
val["certb64"] = m_signer->getCertificate();
|
||||
EetTemplate tempRequest(REQUEST_TEMPLATE);
|
||||
|
||||
QString strRequest = tempRequest.fillTemplate(val);
|
||||
|
||||
qDebug() << strRequest;
|
||||
}
|
||||
|
||||
void EetSender::setupSigner(const QString &certPath, const QString &passwd)
|
||||
{
|
||||
if (m_signer != nullptr)
|
||||
{
|
||||
delete m_signer;
|
||||
}
|
||||
|
||||
m_signer = new EetSigner(this);
|
||||
m_signer->setup(certPath, QCA::SecureArray(passwd.toUtf8()));
|
||||
}
|
||||
|
||||
@@ -14,8 +14,15 @@ public:
|
||||
explicit EetSender(QObject *parent = 0);
|
||||
|
||||
void sendRequest(EetRequest *request);
|
||||
void setupSigner(const QString &certPath, const QString &passwd);
|
||||
|
||||
private:
|
||||
EetSigner *m_signer;
|
||||
|
||||
signals:
|
||||
void certError();
|
||||
void sendError();
|
||||
void responseRecieved();
|
||||
|
||||
public slots:
|
||||
};
|
||||
|
||||
+37
-6
@@ -5,7 +5,6 @@
|
||||
|
||||
EetSigner::EetSigner(QObject *parent) : QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QByteArray EetSigner::signData(const QByteArray &data)
|
||||
@@ -15,15 +14,12 @@ QByteArray EetSigner::signData(const QByteArray &data)
|
||||
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())
|
||||
if (m_result != QCA::ConvertGood || m_bundle.isNull())
|
||||
{
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
QCA::PrivateKey privKey = bundle.privateKey();
|
||||
QCA::PrivateKey privKey = m_bundle.privateKey();
|
||||
|
||||
return privKey.signMessage(QCA::MemoryRegion(data), QCA::EMSA3_SHA256);
|
||||
}
|
||||
@@ -37,3 +33,38 @@ QByteArray EetSigner::sha1HashData(const QByteArray &data)
|
||||
|
||||
return QCA::Hash("sha1").hash(QCA::MemoryRegion(data)).toByteArray();
|
||||
}
|
||||
|
||||
QByteArray EetSigner::sha256HashData(const QByteArray &data)
|
||||
{
|
||||
if (!QCA::isSupported("sha256"))
|
||||
{
|
||||
return QByteArray();
|
||||
}
|
||||
|
||||
return QCA::Hash("sha256").hash(QCA::MemoryRegion(data)).toByteArray();
|
||||
}
|
||||
|
||||
QString EetSigner::getCertificate()
|
||||
{
|
||||
if (!QCA::isSupported("cert"))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (m_result != QCA::ConvertGood || m_bundle.isNull())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
if (!m_bundle.certificateChain().isEmpty())
|
||||
{
|
||||
return m_bundle.certificateChain().primary().toPEM();
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
void EetSigner::setup(const QString &certPath, const QCA::SecureArray &certPasswd)
|
||||
{
|
||||
m_bundle = QCA::KeyBundle::fromFile(certPath, certPasswd, &m_result);
|
||||
}
|
||||
|
||||
@@ -10,11 +10,17 @@ class EetSigner : public QObject
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit EetSigner(QObject *parent = 0);
|
||||
|
||||
QByteArray signData(const QByteArray &data);
|
||||
QByteArray sha1HashData(const QByteArray &data);
|
||||
QByteArray sha256HashData(const QByteArray &data);
|
||||
QString getCertificate();
|
||||
void setup(const QString &certPath, const QCA::SecureArray &certPasswd);
|
||||
|
||||
private:
|
||||
QCA::Initializer m_qcaInit;
|
||||
QCA::KeyBundle m_bundle;
|
||||
QCA::ConvertResult m_result;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ QString EetTemplate::fillTemplate(EetRequest *request)
|
||||
|
||||
QString pkp = getPkpString(request);
|
||||
|
||||
QByteArray signedPkp = m_signer.signData(pkp.toUtf8());
|
||||
QByteArray sha1Bkp = m_signer.sha1HashData(signedPkp);
|
||||
QByteArray signedPkp = m_signer->signData(pkp.toUtf8());
|
||||
QByteArray sha1Bkp = m_signer->sha1HashData(signedPkp);
|
||||
|
||||
QString base64Sign(signedPkp.toBase64());
|
||||
QString base16bkp(sha1Bkp.toHex());
|
||||
|
||||
@@ -21,6 +21,7 @@ public:
|
||||
|
||||
QString fillTemplate(EetRequest *request);
|
||||
QString fillTemplate(QMap<QString, QString> map);
|
||||
void setSigner(EetSigner *signer) { m_signer = signer; }
|
||||
|
||||
signals:
|
||||
|
||||
@@ -30,7 +31,7 @@ private:
|
||||
QString m_template;
|
||||
QString fillTemplateInternal(EetRequest *request, QMap<QString, QString> *map);
|
||||
QString getPkpString(EetRequest *request);
|
||||
EetSigner m_signer;
|
||||
EetSigner *m_signer;
|
||||
};
|
||||
|
||||
#endif // EETTEMPLATE_H
|
||||
|
||||
Reference in New Issue
Block a user