José Cabrera
José Cabrera

Reputation: 153

Resulting certificate on Signature has "&#13" how to remove them?

I'm using xades4j to sing an xml, everything works fine. But on the resulting XML the X509Certificate looks something like this:

<ds:X509Certificate>  MIIDUjCCAjqgAwIBAgIIYFxFM0GPYwowDQYJKoZIhvcNAQELBQAwKTEMMAoGA1UEAwwDRkVMMQww&#13;
    CgYDVQQKDANTQVQxCzAJBgNVBAYTAkdUMB4XDTE4MTIxMDE1MTQyOFoXDTIwMTIwOTE1MTQyOFow&#13;
    KDERMA8GA1UEAwwIODI1NzYyNTQxEzARBgNVBAoMCnNhdC5nb2IuZ3QwggEiMA0GCSqGSIb3DQEB&#13;
    AQUAA4IBDwAwggEKAoIBAQC6QTYY7yGtmikBaV6pNVee6WzNBToIr3jlFikbvZI4JD+4p0LJqten&#13;
</ds:X509Certificate>

How can I remove the "& #13;" from it?

The method that executes the signature is this one:

@Override
    public DOMSource generarFirmaDigitalParaXML(Document xml, KeyingDataProvider keyingDataProvider, String nombreArchivoXmlOriginal) {
    final Element rootElement = xml.getDocumentElement();
    Element elementoAFirmar = null;
    NodeList nodeList = xml.getElementsByTagName("dte:DatosEmision");

    DOMSource source = null;
    int lenght = nodeList.getLength();
    for (int i = 0; i < lenght; i++) {
        Node nNode = nodeList.item(i);
        elementoAFirmar = (Element) nNode;
    }

    XadesBesSigningProfile profile = new XadesBesSigningProfile(keyingDataProvider);
    try {
        XadesSigner signer = profile.newSigner();
        String atributoUtilizado = seleccionarAttributoComoId(elementoAFirmar, "ID");

        if (atributoUtilizado != null) {
            DataObjectDesc obj = new DataObjectReference("#" + elementoAFirmar.getAttribute(atributoUtilizado))
                    .withTransform(new EnvelopedSignatureTransform());
            SignedDataObjects dataObjs = new SignedDataObjects().withSignedDataObject(obj);
            signer.sign(dataObjs, rootElement);
            xml.setXmlStandalone(true);
            source = new DOMSource(xml);
        } else {
            throw new Exception("Atributo no encontrado en el XML");
        }
    } catch (Exception e) {
        bitacora.log(Level.SEVERE, LOGGER, bitacora.obtenerStackTrace(e), true);
    }
    return source;
}

Upvotes: 1

Views: 2524

Answers (1)

Kosmoski
Kosmoski

Reputation: 61

It took me a few hours to resolve it, but I've finally found the solution here: https://bugs.openjdk.java.net/browse/JDK-8264194

static {
    System.setProperty("com.sun.org.apache.xml.internal.security.ignoreLineBreaks", "true");
}

Upvotes: 4

Related Questions