santuario-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ernad Besirevic <ern...@gmail.com>
Subject Re: Problem with an XSLT transformation
Date Fri, 25 May 2012 06:14:34 GMT
Ernad Besirevic <ernadb <at> gmail.com> writes:

> 
> I get following 
> exception:
> 
> javax.xml.crypto.dsig.XMLSignatureException: 
> javax.xml.crypto.dsig.TransformException: 
> com.sun.org.apache.xml.internal.security.transforms.TransformationException:
> Cannot find xslt:stylesheet in Transform
> Original Exception was 
> com.sun.org.apache.xml.internal.security.transforms.
TransformationException:
> Cannot find xslt:stylesheet in Transform
> at org.jcp.xml.dsig.internal.dom.DOMReference.transform(Unknown Source)
> at org.jcp.xml.dsig.internal.dom.DOMReference.digest(Unknown Source)
> at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.
digestReference(Unknown Source)
> at org.jcp.xml.dsig.internal.dom.DOMXMLSignature.sign(Unknown Source)
> 

Here is the code (Sun's XML Signature API):

<code>

Document signingDocument = signRequest.getDocument();
		
// add references
List<Reference> references = 
                 new ArrayList<Reference>();
List<Transform> transforms = 
                 new ArrayList<Transform>();
			
XSLTTransformParameterSpec spec = 
new XSLTTransformParameterSpec(
    getStylesheetXmlStructure() );
		
transforms.add( fac.newTransform( Transform.XSLT, spec ) );
		
Reference ref = fac.newReference( "", 
fac.newDigestMethod( DigestMethod.SHA1,
null), transforms, null, null );
references.add( ref );
		
SignedInfo si = fac.newSignedInfo(
fac.newCanonicalizationMethod(
   CanonicalizationMethod.INCLUSIVE_WITH_COMMENTS,
(C14NMethodParameterSpec) null),
fac.newSignatureMethod( SignatureMethod.RSA_SHA1, 
                       null ),references );

X509Certificate cert = (X509Certificate)
signRequest.getCertificate();
KeyInfoFactory kif = fac.getKeyInfoFactory();
List<Object> x509Content = new ArrayList<Object>();
		
x509Content.add( cert.getSubjectX500Principal().getName() );
x509Content.add( cert );
		
X509Data xd = kif.newX509Data( x509Content );
KeyInfo ki = kif.newKeyInfo( Collections.singletonList( xd ) );
DOMSignContext dsc = new DOMSignContext(
     signRequest.getPrivateKey(),
     signingDocument.getDocumentElement() );
XMLSignature signature = fac.newXMLSignature( si, ki );

signature.sign( dsc );

</code>

With Santuario I am not sure how to add XSLT document. 
Here is my Santuario code:

<code>
Init.init();
ElementProxy.setDefaultPrefix( Constants.SignatureSpecNS, "ds" );

Document signedDocument = signRequest.getDocument();
Element rootElement = signedDocument.getDocumentElement();
XMLSignature signature = new XMLSignature( signedDocument, null,
XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1 );
		
rootElement.appendChild( signature.getElement() );		
		
Transforms transforms = new Transforms( signedDocument );

transforms.addTransform( Transforms.TRANSFORM_ENVELOPED_SIGNATURE );
transforms.addTransform( Transforms.TRANSFORM_C14N_WITH_COMMENTS );
        
// only for testing purpose I added the second Transforms object
Transforms transforms2 = new Transforms( signedDocument );
        
transforms2.addTransform( Transforms.TRANSFORM_XSLT );

// ???? How to add XSLT file to the transformation?
        
signature.addDocument( "", transforms, Constants.ALGO_ID_DIGEST_SHA1 );
signature.addDocument( "", transforms2 );
        
X509Certificate certificate = signRequest.getCertificate();
        
signature.addKeyInfo( certificate );
signature.addKeyInfo( certificate.getPublicKey() );
        
signature.sign( signRequest.getPrivateKey() );
		
return signedDocument;
</code>

Thanks in advance
errno



Mime
View raw message