xml-signaturexades4j

Remove Signing Certificate From Qualifying Properties Xades4j


I'm using Xades4j to Sign XMl Documents, How can I remove this node from the Qualifying Properties

<xades:SigningCertificate>
    <xades:Cert>
        <xades:CertDigest>
            <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
            <ds:DigestValue>****************=</ds:DigestValue>
        </xades:CertDigest>
        <xades:IssuerSerial>
            <ds:X509IssuerName>******************</ds:X509IssuerName>
            <ds:X509SerialNumber>****************</ds:X509SerialNumber>
        </xades:IssuerSerial>
    </xades:Cert>
</xades:SigningCertificate>

Solution

  • TL;DR: it's currently not possible. xades4j always adds the SigningCertificate property.


    xades4j implements ETSI TS 101 903 V1.4.2. In section 4.4.1 XAdES-BES that specs states:

    For this form it is mandatory to protect the signing certificate with the signature, in one of the two following ways:

    • either incorporating the SigningCertificate signed property; or
    • not incorporating the SigningCertificate but incorporating the signing certificate within the ds:KeyInfo element and signing at least the signing certificate.

    For xades4j I chose the first option. However, the spec also says:

    The ds:KeyInfo element. ... If SigningCertificate element is not present in the signature, then the following restrictions apply:

    • the ds:KeyInfo element MUST include a ds:X509Data containing the signing certificate;
    • the ds:SignedInfo element MUST contain a ds:Reference element referencing ds:KeyInfo. That ds:Reference element SHALL be built in such a way that at least the signing certificate is actually signed.

    It is possible to configure xades4j to achieve this last option, but it doesn't remove the SigningCertificate property.

    Regarding KeyInfo content, it's not clear what "a ds:X509Data containing the signing certificate" means. In my interpretation, it needs to be a X509Certificate element with the certificate itself. In the example you provided on the project's Github issue (https://github.com/luisgoncalves/xades4j/issues/288), there's only a X509IssuerSerial, so I'd say that signature is not conformant to the spec, because it doesn't include neither of the two options to protect the signing certificate (quoted above).

    This is a bit arguable, because one can say that including X509IssuerSerial also prevents the simple substitution of the signer's certificate (the goal mentioned in the spec).

    However, the XAdES Baseline Profile recommends both the presence of the SigningCertificate property and a X509Certificate in KeyInfo, so xades4j is doing the best thing. I believe being more strict is better in this case.

    I could consider adding a configuration to not add SigningCertificate, but I'd say it would only be allowed if KeyInfo is signed and contains either X509IssuerSerial or X509Certificate (as configured in BasicSignatureOptions. This is already a bit too flexible for my liking, but the default can still be the current behavior..

    Do you have more thoughts given my explanation above? Please share in the comments.