santuario-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sean Mullan <sean.mul...@oracle.com>
Subject Re: Problem with an XSLT transformation
Date Fri, 25 May 2012 14:26:28 GMT
I don't have time to debug your code, but the exception indicates that the XSLT
Transform cannot find the stylesheet element.

My guess is that the XSLT stylesheet is located in an external document than the
document that will contain the XML Signature. This is a problem. You will need
to import that element into the Document that will contain the signature so the
Transform can find it - try the DOM Document.importNode method.

--Sean

On 5/25/12 2:14 AM, Ernad Besirevic wrote:
> 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