Giter VIP home page Giter VIP logo

qxmlsec's People

Contributors

plaristote avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

qxmlsec's Issues

Unable to sign xml file

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:

2024-03-06_17-18

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.