-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Hi!
Thank you for this effort! I was trying the library, and after some modifications to the source code, particularly a few missing include clauses and a more intriguing error, that, may explain (perhaps) why I am not being able to sucessfully sign the .xml I was able to build the library.
I was "forced" to change the xmlsign.cpp source file, specifically bool QXmlSign::sign() because the compilation failed as xmlSecCryptoAppKeyLoad method was not declared. I used xmlSecCryptoAppKeyLoadEx instead, and to accomodate this change also added a new private member of type unsigned int to the Certificate class to match the argument list of the xmlSecCryptoAppKeyLoadEx symbol. After this change, I was able to build xmlsec-qt.
Now I was trying to sign a demo xml by including this library in a minimalist Qt project. I am using the following code
`QDomDocument targetDocument;
QFile file("/home/dev/mini_projects/xmlsign/data/demo.xml");
if (!file.open(QIODevice::ReadOnly))
return;
if (!targetDocument.setContent(&file)) {
file.close();
return;
}
file.close();
QXmlSecCertificate certificateData;
QXmlSign signer;
QXmlSec xmlsec;
QString keyInfoId;
certificateData.setFormat(QXmlSecCertificate::Pkcs12);
certificateData.setFilepath("/home/dev/mini_projects/xmlsign/data/u718ja1.p12");
certificateData.setPassword("blablabla");
certificateData.setType(0);
signer.withSignatureId("Signature-a53a6ab2")
.useNamespace("ds")
.useCertificate(certificateData)
.useDocument(targetDocument);
keyInfoId = signer.signatureContext().tagId("KeyInfo");
signer.useKeyInfo(QXmlSignKeyInfo()
.withId(keyInfoId)
.withKeyValue()
.withX509Data()
);
signer.useSignInfo(QXmlSignInfo()
.addReference(QXmlSignReference()
.withType(QUrl("http://www.w3.org/2000/09/xmldsig#Object"))
.useAlgorithm(QUrl("http://www.w3.org/2000/09/xmldsig#Object"))
.addTransform(QUrl("http://www.w3.org/2000/09/xmldsig#enveloped-signature"))
.addTransform(QUrl("http://www.w3.org/TR/1999/REC-xpath-19991116"))
)
.addReference(QXmlSignReference()
.withUri('#' + keyInfoId)
.useAlgorithm(QUrl("http://www.w3.org/2001/04/xmlenc#sha512"))
)
);
if (signer.sign())
{
std::cerr << "Successfully signed XML document" << std::endl;
std::cout << signer.toString().toStdString() << std::endl;
}
else
std::cerr << "Failed to sign XML document." << std::endl;`
Please note the line certificateData.setType(0) with the call of the setter of the "type" member which I added to the Certificate class in order to be able to call the xmlSecCryptoAppKeyLoadEx method.
When signign, the following error is shown:
Anybody can help me? I am in an effort to port some Python code used to sign xml files to C++ and found this library very useful!
