Open GoogleCodeExporter opened 9 years ago
Sorry, I wrote the code for version 4.0.4. For your new version 4.1.0 is:
private void incorporateSigningCertificate() {
final Element signingCertificateDom = DSSXMLUtils.addElement(documentDom, signedSignaturePropertiesDom, XAdESNamespaces.XAdES, "xades:SigningCertificate");
final List<X509Certificate> certificates = new ArrayList<X509Certificate>();
final X509Certificate signingCertificate = params.getSigningCertificate();
certificates.add(signingCertificate);
if (params.getCertificateChain()!=null && (!params.getCertificateChain().isEmpty())) {
for (int i=0; i<params.getCertificateChain().size(); i++) {
if (params.getCertificateChain().get(i)!=null && (!params.getCertificateChain().get(i).getSerialNumber().equals(certificates.get(0).getSerialNumber()))) {
certificates.add(params.getCertificateChain().get(i));
}
}
}
incorporateCertificateRef(signingCertificateDom, certificates);
}
///////////////////////////////////////////////
protected void incorporateCertificateRef(final Element signingCertificateDom,
final List<X509Certificate> certificates) {
for (final X509Certificate certificate : certificates) {
final Element certDom = DSSXMLUtils.addElement(documentDom, signingCertificateDom, XAdESNamespaces.XAdES, "xades:Cert");
final Element certDigestDom = DSSXMLUtils.addElement(documentDom, certDom, XAdESNamespaces.XAdES, "xades:CertDigest");
final DigestAlgorithm signingCertificateDigestMethod = params.bLevel().getSigningCertificateDigestMethod();
incorporateDigestMethod(certDigestDom, signingCertificateDigestMethod);
final InMemoryDocument inMemoryCertificate = new InMemoryDocument(DSSUtils.getEncoded(certificate));
incorporateDigestValue(certDigestDom, signingCertificateDigestMethod, inMemoryCertificate);
final Element issuerSerialDom = DSSXMLUtils.addElement(documentDom, certDom, XAdESNamespaces.XAdES, "xades:IssuerSerial");
final Element x509IssuerNameDom = DSSXMLUtils.addElement(documentDom, issuerSerialDom, XMLSignature.XMLNS, "ds:X509IssuerName");
final String issuerX500PrincipalName = DSSUtils.getIssuerX500PrincipalName(certificate);
DSSXMLUtils.setTextNode(documentDom, x509IssuerNameDom, issuerX500PrincipalName);
final Element x509SerialNumberDom = DSSXMLUtils.addElement(documentDom, issuerSerialDom, XMLSignature.XMLNS, "ds:X509SerialNumber");
final BigInteger serialNumber = certificate.getSerialNumber();
final String serialNumberString = new String(serialNumber.toString());
DSSXMLUtils.setTextNode(documentDom, x509SerialNumberDom, serialNumberString);
}
}
Original comment by eb.j...@gmail.com
on 18 Aug 2014 at 10:36
Please follow:
https://joinup.ec.europa.eu/asset/sd-dss/issue/impossible-add-certificate-chain-
xades-signingcertificate-element-and-bug-signing
Original comment by bielecki...@gmail.com
on 17 Sep 2014 at 10:39
Original issue reported on code.google.com by
eb.j...@gmail.com
on 13 Aug 2014 at 4:20