makdimka077 / xades4j

Automatically exported from code.google.com/p/xades4j
GNU Lesser General Public License v3.0
0 stars 0 forks source link

ds:X509SubjectName tag doesn't created #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi 
I signed xml documents with xades and i can validate xml successfully but i 
send it to my goverment system but system gave me this error ds:X509Data 
doesn't have  ds:X509SubjectName  tag.  after that i checked my document and it 
ealy doesn't have that tag. i searched internet i couldn't find any useful 
information, i also checked my token info and it has subejct vale. 

Could anyone help me Why doesn't xades create  ds:X509SubjectName  tag ? or i 
can insert it myself with code.  

here is my code 

public void Sign() throws TransformerFactoryConfigurationError, Exception {
        Document doc = SignatureServicesBase.getDocument(_inputStream);

        Pkcs11KeyingDataProvider s = new Pkcs11KeyingDataProvider(_cert);
        XadesBesSigningProfile pr = new XadesBesSigningProfile(s);
        pr.withAlgorithmsProvider(Sha1AlgProvider.class);
        pr.withBasicSignatureOptionsProvider(new MyBasicSignatureOptionsProvider(
                true, true, true));
        MySignaturePropertiesProvider propProv = new MySignaturePropertiesProvider();

        propProv.setSignerRole(_role);

        pr.withSignaturePropertiesProvider(propProv);

        XadesSigner signer = pr.newSigner();

        String refUri = "";
        DataObjectDesc dataObjRef = new DataObjectReference(refUri)
                .withTransform(new DataObjectTransform(
                        Transforms.TRANSFORM_ENVELOPED_SIGNATURE));
        Element elementToSign;

        if (_UBLFormat) {
            NodeList l = doc.getElementsByTagNameNS("*", "ExtensionContent");
            if (l.getLength() <= 0) {
                throw new Exception("Can not find ExtensionContent node!");
            }
            elementToSign = (Element) l.item(0);
        } else {
            elementToSign = doc.getDocumentElement();
        }
        signer.sign(new SignedDataObjects(dataObjRef), elementToSign);

        // new Enveloped(signer).sign(elemenToSign);
        SignatureServicesBase.outputDocument(doc, _outStream);

        if (!_isStream) {
            _inputStream.close();
            _outStream.close();
        }
    }

and example signed document is attached.

Original issue reported on code.google.com by keklikhasan on 10 Aug 2012 at 8:54

Attachments:

GoogleCodeExporter commented 9 years ago
xades4j doesn't include that tag and currently there's no option to control 
that. It may be included on the next version. If you really need it, you can 
change the code to include the tag. The X509Data element is created on the 
KeyInfoBuilder class.

Original comment by luis.fgoncalv on 11 Aug 2012 at 7:59

GoogleCodeExporter commented 9 years ago
Yes i noticed that i changed org.apache.xml.security.signature.XMLSignature   
class in xml-security jar.

orginal 
 public void addKeyInfo(X509Certificate cert) throws XMLSecurityException {

        X509Data x509data = new X509Data(this._doc);

        x509data.addCertificate(cert);
        this.getKeyInfo().add(x509data);
    }

i added x509data.addSubjectName(cert);   code in method and it solved my 
problem.

Original comment by keklikhasan on 11 Aug 2012 at 10:38

GoogleCodeExporter commented 9 years ago
I have run into similar issue, and since we are using maven, source code 
modifications of external libraries is not the best idea.
I have added method to my Code:

 public void addX509certInfo(XMLSignature sig, Document doc, X509Certificate certificate) throws XMLSecurityException {
    X509Data x509data = new X509Data(doc);
    x509data.addCertificate(certificate);
    x509data.addSubjectName(certificate);
    sig.getKeyInfo().add(x509data);
  }

Original comment by mort...@gmail.com on 8 Mar 2013 at 3:19