Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The XADES-BES sign example does not work with IE11 #101

Open
gcie opened this issue Apr 28, 2020 · 12 comments
Open

The XADES-BES sign example does not work with IE11 #101

gcie opened this issue Apr 28, 2020 · 12 comments

Comments

@gcie
Copy link

gcie commented Apr 28, 2020

Hello,
The XADES-BES signature example from readme fails in IE11 with "WrongDocumentError". I have created a fiddle with it:
https://jsfiddle.net/tao24/4a3bog9d/4/

Also I have tracked the error up to "toString()" method in "SignedXml" definition in xmldsigjs:

    public toString() {
        // Check for EnvelopedTransform
        const signature = this.XmlSignature;
        const enveloped = signature.SignedInfo.References && signature.SignedInfo.References.Some((r) =>
            r.Transforms && r.Transforms.Some((t) => t instanceof Transforms.XmlDsigEnvelopedSignatureTransform),
        );

        if (enveloped) {
            const doc = this.document!.documentElement.cloneNode(true);
            const node = this.XmlSignature.GetXml();
            if (!node) {
                throw new XmlCore.XmlError(XmlCore.XE.XML_EXCEPTION, "Cannot get Xml element from Signature");
            }
            const sig = node.cloneNode(true);
            doc.appendChild(sig); // this line causes problems in IE
            return new XMLSerializer().serializeToString(doc);
        }
        return this.XmlSignature.toString();
    }

However I don't know whether the issue is within xadesjs or xmldsigjs.

@rmhrisk
Copy link
Contributor

rmhrisk commented Apr 28, 2020

I do not have an IE11 machine handy but I did not see the use of a polyfill for webcrypto: https://github.com/PeculiarVentures/webcrypto-liner

@gcie
Copy link
Author

gcie commented Apr 28, 2020

I have copied this example from readme.md from your repository: https://github.com/PeculiarVentures/xadesjs#in-the-browser
And I also swapped arrow functions to regular ones (because IE does not support arrow functions), but I doubt that's the case.

The polyfill for webcrypto is included. If something is missing, please fix the example in readme.md.

@microshine
Copy link
Contributor

Looks like it's IE11 limitation. It throws an exception on appending a signature element to the XML document.

// SignedXml.toString
doc.appendChild(sig);

As I can see from this StackOverflow answer, a signature element must be created from XML document object.

I'll pay attention to the problem

@microshine
Copy link
Contributor

I updated your code a bit

    })
-    .then(function() {
-      return signedXml.toString();
+    .then(function(signature) {
+      return new XMLSerializer().serializeToString(signature.GetXml());
    });
}

image

@gcie
Copy link
Author

gcie commented Apr 29, 2020

Ok, so we can access the signature. But can we get the whole document with enveloped signature as it was in other browsers?

@microshine
Copy link
Contributor

microshine commented Apr 29, 2020

I found a solution

var xmlDoc = new DOMParser().parseFromString(xmlString, "application/xml");
var xmlSig = new DOMParser().parseFromString(signedDocument, "application/xml");

xmlDoc.documentElement.appendChild(xmlSig.documentElement);

console.log(new XMLSerializer().serializeToString(xmlDoc));

image

@rmhrisk
Copy link
Contributor

rmhrisk commented Apr 29, 2020

Is solution to change lib or app code?

@microshine
Copy link
Contributor

It fixes IE11 limitation only but lib works fine for other browsers

@rmhrisk
Copy link
Contributor

rmhrisk commented Apr 29, 2020

So change is in app code or in our library?

@microshine
Copy link
Contributor

app code

@rmhrisk
Copy link
Contributor

rmhrisk commented Apr 29, 2020

Should we update our sample so future people don't encounter this?

@gcie
Copy link
Author

gcie commented Apr 30, 2020

If I were to decide, then definitely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants