ASF Bugzilla – Attachment 19265 Details for
Bug 39029
Stax verifier JSR105 implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
A new patch with signature verification
stax_patch_1.patch (text/plain), 62.89 KB, created by
Raul Benito
on 2006-12-15 08:20:07 UTC
(
hide
)
Description:
A new patch with signature verification
Filename:
MIME Type:
Creator:
Raul Benito
Created:
2006-12-15 08:20:07 UTC
Size:
62.89 KB
patch
obsolete
>Index: src/org/apache/xml/security/algorithms/Algorithm.java >=================================================================== >--- src/org/apache/xml/security/algorithms/Algorithm.java (revision 478935) >+++ src/org/apache/xml/security/algorithms/Algorithm.java (working copy) >@@ -30,7 +30,9 @@ > * > */ > public abstract class Algorithm extends SignatureElementProxy { >- >+ public Algorithm() { >+ >+ }; > /** > * > * @param doc >Index: src/org/apache/xml/security/algorithms/SignatureAlgorithm.java >=================================================================== >--- src/org/apache/xml/security/algorithms/SignatureAlgorithm.java (revision 478935) >+++ src/org/apache/xml/security/algorithms/SignatureAlgorithm.java (working copy) >@@ -77,6 +77,16 @@ > * @param algorithmURI > * @throws XMLSecurityException > */ >+ public SignatureAlgorithm(String algorithmURI) { >+ this.algorithmURI = algorithmURI; >+ } >+ /** >+ * Constructor SignatureAlgorithm >+ * >+ * @param doc >+ * @param algorithmURI >+ * @throws XMLSecurityException >+ */ > public SignatureAlgorithm(Document doc, String algorithmURI) > throws XMLSecurityException { > super(doc, algorithmURI); >Index: src/org/apache/xml/security/signature/Reference.java >=================================================================== >--- src/org/apache/xml/security/signature/Reference.java (revision 478935) >+++ src/org/apache/xml/security/signature/Reference.java (working copy) >@@ -684,7 +684,7 @@ > MessageDigestAlgorithm mda = this.getMessageDigestAlgorithm(); > > mda.reset(); >- DigesterOutputStream diOs=new DigesterOutputStream(mda); >+ DigesterOutputStream diOs=new DigesterOutputStream(mda.getAlgorithm()); > OutputStream os=new UnsyncBufferedOutputStream(diOs); > XMLSignatureInput output=this.dereferenceURIandPerformTransforms(os); > output.updateOutputStream(os); >Index: src/org/apache/xml/security/utils/DigesterOutputStream.java >=================================================================== >--- src/org/apache/xml/security/utils/DigesterOutputStream.java (revision 377148) >+++ src/org/apache/xml/security/utils/DigesterOutputStream.java (working copy) >@@ -17,6 +17,7 @@ > package org.apache.xml.security.utils; > > import java.io.ByteArrayOutputStream; >+import java.security.MessageDigest; > > import org.apache.xml.security.algorithms.MessageDigestAlgorithm; > >@@ -26,11 +27,11 @@ > */ > public class DigesterOutputStream extends ByteArrayOutputStream { > final static byte none[]="error".getBytes(); >- final MessageDigestAlgorithm mda; >+ final MessageDigest mda; > /** > * @param mda > */ >- public DigesterOutputStream(MessageDigestAlgorithm mda) { >+ public DigesterOutputStream(MessageDigest mda) { > this.mda=mda; > } > >Index: src/com/r_bg/stax/c14n/AttributeComparator.java >=================================================================== >--- src/com/r_bg/stax/c14n/AttributeComparator.java >+++ src/com/r_bg/stax/c14n/AttributeComparator.java >@@ -0,0 +1,27 @@ >+package com.r_bg.stax.c14n; >+ >+import java.util.Comparator; >+ >+import javax.xml.stream.XMLStreamReader; >+ >+class AttributeCompartor implements Comparator { >+ XMLStreamReader in; >+ public AttributeCompartor(XMLStreamReader in) { >+ this.in=in; >+ } >+ public int compare(Object arg0, Object arg1) { >+ int first=((Integer)arg0).intValue(); >+ int second=((Integer)arg1).intValue(); >+ String uri1=in.getAttributeNamespace(first); >+ String uri2=in.getAttributeNamespace(second); >+ if (uri1==null) { >+ return (uri2!=null )? 1 : >+ in.getAttributeLocalName(first).compareTo(in.getAttributeLocalName(second)); >+ } >+ if (uri2==null) { >+ return -1; >+ } >+ int result=uri1.compareTo(uri2); >+ return (result!=0) ? result :in.getAttributeLocalName(first).compareTo(in.getAttributeLocalName(second)); >+ } >+} >Index: src/com/r_bg/stax/c14n/AttributeHandleExclusive.java >=================================================================== >--- src/com/r_bg/stax/c14n/AttributeHandleExclusive.java >+++ src/com/r_bg/stax/c14n/AttributeHandleExclusive.java >@@ -0,0 +1,67 @@ >+package com.r_bg.stax.c14n; >+ >+import java.io.IOException; >+import java.io.OutputStream; >+import java.util.HashSet; >+import java.util.Iterator; >+import java.util.Set; >+import java.util.SortedSet; >+import java.util.TreeSet; >+ >+import javax.xml.namespace.NamespaceContext; >+import javax.xml.stream.XMLStreamReader; >+ >+public class AttributeHandleExclusive implements C14nAttributeHandler { >+ static final byte[] EQ={'=','"'}; >+ static final byte[] XMLNS={' ','x','m','l','n','s'}; >+ public void handleAttributes(XMLStreamReader in,StaxC14nHelper nsD,OutputStream os) throws IOException{ >+ SortedSet args=new TreeSet(new AttributeCompartor(in)); >+ SortedSet nss=new TreeSet(); >+ Set prefixes=new HashSet(); >+ int length; >+ length=in.getAttributeCount(); >+ for (int i=0;i<length;i++) { >+ args.add(new Integer(i)); >+ String prefix=in.getAttributePrefix(i); >+ if (prefix!=null) >+ prefixes.add(prefix); >+ } >+ prefixes.add(in.getPrefix()==null? "" : in.getPrefix()); >+ Iterator it=prefixes.iterator(); >+ NamespaceContext nc=in.getNamespaceContext(); >+ while (it.hasNext()) { >+ String prefix=(String)it.next(); >+ if (!nsD.hasBeenRender(prefix,nc.getNamespaceURI(prefix))) >+ nss.add(prefix); >+ } >+ it=nss.iterator(); >+ while (it.hasNext()) { >+ String realPrefix=(String) it.next(); >+ String prefix=realPrefix; >+ os.write(XMLNS); >+ if (prefix!="") { >+ os.write(':'); >+ os.write(prefix.getBytes()); >+ } >+ os.write(EQ); >+ os.write(nc.getNamespaceURI(realPrefix).getBytes()); >+ os.write('\"');; >+ } >+ >+ it=args.iterator(); >+ for (int i=0;i<length;i++) { >+ int arg=((Integer)it.next()).intValue(); >+ os.write(' '); >+ C14n.writeAttribute(in,arg,os); >+ os.write(EQ); >+ os.write(in.getAttributeValue(arg).getBytes()); >+ os.write('\"'); >+ } >+ >+ return; >+ } >+ >+ } >+ >+ >+ >Index: src/com/r_bg/stax/c14n/C14n.java >=================================================================== >--- src/com/r_bg/stax/c14n/C14n.java >+++ src/com/r_bg/stax/c14n/C14n.java >@@ -0,0 +1,147 @@ >+package com.r_bg.stax.c14n; >+ >+import java.io.ByteArrayOutputStream; >+import java.io.IOException; >+import java.io.OutputStream; >+ >+import javax.xml.namespace.QName; >+import javax.xml.stream.EventFilter; >+import javax.xml.stream.StreamFilter; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.stream.XMLStreamReader; >+import javax.xml.stream.events.XMLEvent; >+ >+ >+public class C14n implements EventFilter,StreamFilter { >+ //String result=""; >+ static final byte[] END_EL={'<','/'}; >+ static void writePiData(XMLStreamReader in,OutputStream os) throws IOException { >+ os.write(in.getPITarget().getBytes()); >+ String data=in.getPIData(); >+ if (data!=null && data.length()!=0) { >+ os.write(' '); >+ os.write(data.getBytes()); >+ } >+ } >+ static void obtainName(QName name,OutputStream os) throws IOException { >+ String prefix=name.getPrefix(); >+ if (prefix!=null && prefix.length()!=0) { >+ os.write(prefix.getBytes()); >+ os.write(':'); >+ } >+ os.write(name.getLocalPart().getBytes()); >+ } >+ static void writeAttribute(XMLStreamReader in, int i, OutputStream os) throws IOException { >+ String result=in.getAttributePrefix(i); >+ if (result!=null) { >+ os.write(result.getBytes()); >+ os.write(':'); >+ } >+ os.write(in.getAttributeLocalName(i).getBytes()); >+ } >+ public static String cannoicalizeWithoutComments(XMLStreamReader in, C14nAttributeHandler handler) throws XMLStreamException, IOException { >+ ByteArrayOutputStream os=new ByteArrayOutputStream(); >+ int type; >+ int beforeDocumentElement=1; >+ StaxC14nHelper nsD=new StaxC14nHelper(); >+ int number=0; >+ while ((type=in.getEventType())!=XMLStreamReader.END_DOCUMENT) { >+ switch (type) { >+ case XMLStreamReader.PROCESSING_INSTRUCTION: >+ if (beforeDocumentElement==-1) >+ os.write('\n'); >+ os.write("<?".getBytes()); >+ writePiData(in,os); >+ os.write("?>".getBytes()); >+ if (beforeDocumentElement==1) >+ os.write('\n'); >+ break; >+ case XMLStreamReader.START_ELEMENT: >+ number++; >+ nsD.push(); >+ beforeDocumentElement=0; >+ os.write('<'); >+ obtainName(in.getName(),os); >+ handler.handleAttributes(in,nsD,os); >+ os.write('>'); >+ break; >+ case XMLStreamReader.END_ELEMENT: >+ if (--number==0) { >+ beforeDocumentElement=-1; >+ } >+ os.write(END_EL); >+ obtainName(in.getName(),os); >+ os.write('>'); >+ nsD.pop(); >+ break; >+ >+ case XMLStreamReader.CHARACTERS: >+ case XMLStreamReader.CDATA: >+ os.write(in.getText().getBytes()); >+ break; >+ } >+ in.next(); >+ } >+ return new String(os.toByteArray()); >+ } >+ >+ int beforeDocumentElement=-1; >+ int number=0; >+ C14nAttributeHandler handler; >+ StaxC14nHelper nsD=new StaxC14nHelper(); >+ OutputStream os; >+ public C14n(C14nAttributeHandler handler, OutputStream os) { >+ this.handler=handler; >+ this.os=os; >+ } >+ public boolean accept(XMLEvent arg0) { >+ return false; >+ } >+ public boolean accept(XMLStreamReader in) { >+ try { >+ int type=in.getEventType(); >+ switch (type) { >+ case XMLStreamReader.PROCESSING_INSTRUCTION: >+ if (beforeDocumentElement==-1) >+ os.write('\n'); >+ os.write("<?".getBytes()); >+ writePiData(in,os); >+ os.write("?>".getBytes()); >+ if (beforeDocumentElement==1) >+ os.write('\n'); >+ break; >+ case XMLStreamReader.START_ELEMENT: >+ number++; >+ nsD.push(); >+ beforeDocumentElement=0; >+ os.write('<'); >+ obtainName(in.getName(),os); >+ handler.handleAttributes(in,nsD,os); >+ os.write('>'); >+ break; >+ case XMLStreamReader.END_ELEMENT: >+ if (--number==0) { >+ beforeDocumentElement=-1; >+ } >+ os.write(END_EL); >+ obtainName(in.getName(),os); >+ os.write('>'); >+ nsD.pop(); >+ break; >+ >+ case XMLStreamReader.CHARACTERS: >+ case XMLStreamReader.CDATA: >+ os.write(in.getText().getBytes()); >+ break; >+ >+ } >+ } catch (IOException ex) { >+ ex.printStackTrace(); >+ } >+ return true; >+ } >+} >+ >+ >+ >+ >Index: src/com/r_bg/stax/c14n/C14nAttributeHandler.java >=================================================================== >--- src/com/r_bg/stax/c14n/C14nAttributeHandler.java >+++ src/com/r_bg/stax/c14n/C14nAttributeHandler.java >@@ -0,0 +1,10 @@ >+package com.r_bg.stax.c14n; >+ >+import java.io.IOException; >+import java.io.OutputStream; >+ >+import javax.xml.stream.XMLStreamReader; >+ >+public interface C14nAttributeHandler { >+ public void handleAttributes(XMLStreamReader in,StaxC14nHelper nsD, OutputStream os) throws IOException; >+} >Index: src/com/r_bg/stax/c14n/C14nInclusive.java >=================================================================== >--- src/com/r_bg/stax/c14n/C14nInclusive.java >+++ src/com/r_bg/stax/c14n/C14nInclusive.java >@@ -0,0 +1,56 @@ >+package com.r_bg.stax.c14n; >+ >+import java.io.IOException; >+import java.io.OutputStream; >+import java.util.Iterator; >+import java.util.SortedSet; >+import java.util.TreeSet; >+ >+import javax.xml.stream.XMLStreamReader; >+/** >+ * TODO: Copy the already defined namespaces sadly stax doesnot give any way to obtain this >+ * so we are going to have stack for inclusive. >+ * @author raul >+ * >+ */ >+public class C14nInclusive implements C14nAttributeHandler { >+ public void handleAttributes(XMLStreamReader in,StaxC14nHelper nsD,OutputStream os) throws IOException { >+ SortedSet args=new TreeSet(new AttributeCompartor(in)); >+ SortedSet nss=new TreeSet(new NsCompartor(in)); >+ int length=in.getNamespaceCount(); >+ for (int i=0;i<length;i++) { >+ if (!nsD.hasBeenRender(in.getNamespacePrefix(i),in.getNamespaceURI(i))) >+ nss.add(new Integer(i)); >+ } >+ Iterator it=nss.iterator(); >+ while (it.hasNext()) { >+ int arg=((Integer)it.next()).intValue(); >+ String prefix=in.getNamespacePrefix(arg); >+ if (prefix!="") { >+ prefix=" xmlns:"+prefix; >+ } else { >+ prefix=" xmlns"; >+ } >+ os.write(prefix.getBytes()); >+ os.write("=\"".getBytes()); >+ os.write(in.getNamespaceURI(arg).getBytes()); >+ os.write('\"'); >+ } >+ length=in.getAttributeCount(); >+ for (int i=0;i<length;i++) { >+ args.add(new Integer(i)); >+ } >+ it=args.iterator(); >+ for (int i=0;i<length;i++) { >+ int arg=((Integer)it.next()).intValue(); >+ os.write(' '); >+ C14n.writeAttribute(in,arg,os); >+ os.write("=\"".getBytes()); >+ os.write(in.getAttributeValue(arg).getBytes()); >+ os.write('\"'); >+ } >+ >+ return; >+ } >+ >+} >Index: src/com/r_bg/stax/c14n/C14Unknown.java >=================================================================== >--- src/com/r_bg/stax/c14n/C14Unknown.java >+++ src/com/r_bg/stax/c14n/C14Unknown.java >@@ -0,0 +1,20 @@ >+package com.r_bg.stax.c14n; >+ >+import javax.xml.stream.EventFilter; >+import javax.xml.stream.StreamFilter; >+import javax.xml.stream.XMLStreamReader; >+import javax.xml.stream.events.XMLEvent; >+ >+public class C14Unknown implements EventFilter,StreamFilter { >+ >+ public boolean accept(XMLEvent arg0) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+ public boolean accept(XMLStreamReader arg0) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+} >Index: src/com/r_bg/stax/c14n/NsComparator.java >=================================================================== >--- src/com/r_bg/stax/c14n/NsComparator.java >+++ src/com/r_bg/stax/c14n/NsComparator.java >@@ -0,0 +1,19 @@ >+package com.r_bg.stax.c14n; >+ >+import java.util.Comparator; >+ >+import javax.xml.stream.XMLStreamReader; >+ >+class NsCompartor implements Comparator { >+ XMLStreamReader in; >+ public NsCompartor(XMLStreamReader in) { >+ this.in=in; >+ } >+ public int compare(Object arg0, Object arg1) { >+ int first=((Integer)arg0).intValue(); >+ int second=((Integer)arg1).intValue(); >+ String uri1=in.getNamespacePrefix(first); >+ String uri2=in.getNamespacePrefix(second); >+ return uri1.compareTo(uri2); >+ } >+} >\ No newline at end of file >Index: src/com/r_bg/stax/c14n/StaxC14nHelper.java >=================================================================== >--- src/com/r_bg/stax/c14n/StaxC14nHelper.java >+++ src/com/r_bg/stax/c14n/StaxC14nHelper.java >@@ -0,0 +1,55 @@ >+package com.r_bg.stax.c14n; >+/* >+ * Copyright 1999-2004 The Apache Software Foundation. >+ * >+ * Licensed under the Apache License, Version 2.0 (the "License"); >+ * you may not use this file except in compliance with the License. >+ * You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ * >+ */ >+ >+ >+import java.util.ArrayList; >+import java.util.HashMap; >+import java.util.List; >+ >+ >+ >+ >+/** >+ * A stack based Symble Table. >+ *<br>For speed reasons all the symbols are introduced in the same map, >+ * and at the same time in a list so it can be removed when the frame is pop back. >+ * @author Raul Benito >+ **/ >+public class StaxC14nHelper { >+ List levels=new ArrayList(); >+ //boolean needToClone=false; >+ HashMap currentRender=new HashMap(); >+ public StaxC14nHelper() { >+ currentRender.put("",""); >+ } >+ public void push() { >+ levels.add(currentRender.clone()); >+ } >+ public void pop() { >+ currentRender=(HashMap) levels.remove(levels.size()-1); >+ } >+ public boolean hasBeenRender(String prefix, String uri) { >+ String previousRendered=(String) currentRender.get(prefix); >+ if ((previousRendered!=null) && (previousRendered.equals(uri))) { >+ return true; >+ } >+ currentRender.put(prefix,uri); >+ return false; >+ } >+ >+} >\ No newline at end of file >Index: src/com/r_bg/stax/C14nWorker.java >=================================================================== >--- src/com/r_bg/stax/C14nWorker.java >+++ src/com/r_bg/stax/C14nWorker.java >@@ -0,0 +1,26 @@ >+package com.r_bg.stax; >+ >+import java.io.OutputStream; >+ >+import javax.xml.stream.XMLStreamReader; >+ >+import com.r_bg.stax.c14n.C14n; >+ >+public class C14nWorker implements StaxWorker { >+ DigestResultListener re; >+ C14n c14n; >+ public C14nWorker(DigestResultListener re,OutputStream os) { >+ c14n=new C14n(new com.r_bg.stax.c14n.AttributeHandleExclusive(),os); >+ this.re=re; >+ } >+ >+ public StaxWorker read(XMLStreamReader reader) { >+ c14n.accept(reader); >+ return null; >+ } >+ >+ public StaxWatcher remove() { >+ re.setResult(null); >+ return null; >+ } >+} >Index: src/com/r_bg/stax/DigestResultListener.java >=================================================================== >--- src/com/r_bg/stax/DigestResultListener.java >+++ src/com/r_bg/stax/DigestResultListener.java >@@ -0,0 +1,7 @@ >+package com.r_bg.stax; >+ >+interface DigestResultListener { >+ >+ public abstract void setResult(byte[] result); >+ >+} >\ No newline at end of file >Index: src/com/r_bg/stax/StaxProvider.java >=================================================================== >--- src/com/r_bg/stax/StaxProvider.java >+++ src/com/r_bg/stax/StaxProvider.java >@@ -0,0 +1,68 @@ >+/* >+ * Copyright 2005 The Apache Software Foundation. >+ * >+ * Licensed under the Apache License, Version 2.0 (the "License"); >+ * you may not use this file except in compliance with the License. >+ * You may obtain a copy of the License at >+ * >+ * http://www.apache.org/licenses/LICENSE-2.0 >+ * >+ * Unless required by applicable law or agreed to in writing, software >+ * distributed under the License is distributed on an "AS IS" BASIS, >+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ * See the License for the specific language governing permissions and >+ * limitations under the License. >+ * >+ */ >+/* >+ * =========================================================================== >+ * >+ * (C) Copyright IBM Corp. 2003 All Rights Reserved. >+ * >+ * =========================================================================== >+ */ >+/* >+ * Portions copyright 2005 Sun Microsystems, Inc. All rights reserved. >+ */ >+/* >+ * $Id: XMLDSigRI.java 375655 2006-02-07 18:35:54Z mullan $ >+ */ >+package com.r_bg.stax; >+ >+import java.security.AccessController; >+import java.security.Provider; >+import java.util.HashMap; >+import java.util.Map; >+ >+/** >+ * The XMLDSig RI Provider. >+ * >+ * @author Joyce Leung >+ */ >+ >+/** >+ * Defines the XMLDSigRI provider. >+ */ >+ >+public final class StaxProvider extends Provider { >+ >+ static final long serialVersionUID = -5049765099299494554L; >+ >+ private static final String INFO = "XMLDSig " + >+ "(Stax XMLSignatureFactory; Stax KeyInfoFactory)"; >+ >+ public StaxProvider() { >+ /* We are the XMLDSig provider */ >+ super("XMLDSig", 1.0, INFO); >+ >+ final Map map = new HashMap(); >+ map.put("XMLSignatureFactory.Stax", >+ "com.r_bg.stax.StaxXMLSignatureFactory"); >+ AccessController.doPrivileged(new java.security.PrivilegedAction() { >+ public Object run() { >+ putAll(map); >+ return null; >+ } >+ }); >+ } >+} >Index: src/com/r_bg/stax/StaxSignatureVerificator.java >=================================================================== >--- src/com/r_bg/stax/StaxSignatureVerificator.java >+++ src/com/r_bg/stax/StaxSignatureVerificator.java >@@ -0,0 +1,92 @@ >+package com.r_bg.stax; >+ >+import java.io.OutputStream; >+import java.util.ArrayList; >+import java.util.List; >+ >+import javax.xml.stream.StreamFilter; >+import javax.xml.stream.XMLStreamReader; >+ >+ >+class IdWatcher implements StaxWatcher { >+ String uri; >+ DigestResultListener re; >+ OutputStream os; >+ public IdWatcher(String uri, DigestResultListener reader,OutputStream os) { >+ this.uri=uri; >+ this.re=reader; >+ this.os=os; >+ } >+ public StaxWorker watch(XMLStreamReader reader, StaxSignatureVerificator sig) { >+ if (uri.equals(reader.getAttributeValue(null, "Id"))) { >+ return new C14nWorker(re,os); >+ } >+ return null; >+ } >+ >+} >+ >+public class StaxSignatureVerificator implements StreamFilter{ >+ List<XMLSignatureWorker> signatures=new ArrayList<XMLSignatureWorker>(); >+ List<StaxWorker> filters=new ArrayList<StaxWorker>(); >+ List<Integer> filterStart=new ArrayList<Integer>(); >+ List<StaxWatcher> watchers=new ArrayList<StaxWatcher>(); >+ int level=0; >+ public StaxSignatureVerificator() { >+ watchers.add(new SignatureWatcher()); >+ } >+ public void addSignature(XMLSignatureWorker s) { >+ signatures.add(s); >+ >+ } >+ public void insertWatch(IdWatcher watcher) { >+ watchers.add(watcher); >+ >+ } >+ public boolean accept(XMLStreamReader cur) { >+ int eventType = cur.getEventType(); >+ if (eventType==XMLStreamReader.START_ELEMENT) { >+ //Start element notify all watcher >+ level++; >+ for (StaxWatcher watcher : watchers) { >+ StaxWorker sf=watcher.watch(cur, this); >+ if (sf!=null) { >+ //Add a new worker >+ filters.add(sf); >+ filterStart.add(level); >+ } >+ } >+ } >+ List<StaxWorker> added=filters; >+ //A worker can add new workers. Iterate while there is more workers to add. >+ while (added.size()!=0) { >+ List<StaxWorker> toAdd=new ArrayList<StaxWorker>(); >+ List<Integer> toAddStart=new ArrayList<Integer>(); >+ for (StaxWorker filter: added) { >+ StaxWorker sf=filter.read(cur); >+ if (sf!=null) { >+ toAdd.add(sf); >+ toAddStart.add(level); >+ } >+ } >+ added=toAdd; >+ filters.addAll(toAdd); >+ filterStart.addAll(toAddStart); >+ } >+ if (eventType==XMLStreamReader.END_ELEMENT) { >+ //an end element remove any worker attached to this element >+ do { >+ int i=filterStart.lastIndexOf(level); >+ if (i!=-1) { >+ StaxWatcher watch=filters.remove(i).remove(); >+ if (watch!=null) { >+ watchers.add(watch); >+ } >+ filterStart.remove(i); >+ } >+ } while (filterStart.contains(level)); >+ level--; >+ } >+ return true; >+ } >+} >Index: src/com/r_bg/stax/StaxValidateContext.java >=================================================================== >--- src/com/r_bg/stax/StaxValidateContext.java >+++ src/com/r_bg/stax/StaxValidateContext.java >@@ -0,0 +1,108 @@ >+package com.r_bg.stax; >+ >+import java.security.Key; >+ >+import javax.xml.crypto.KeySelector; >+import javax.xml.crypto.URIDereferencer; >+import javax.xml.crypto.dsig.XMLSignature; >+import javax.xml.crypto.dsig.XMLValidateContext; >+import javax.xml.stream.StreamFilter; >+import javax.xml.stream.XMLStreamReader; >+ >+public class StaxValidateContext implements XMLValidateContext { >+ XMLStreamReader reader; >+ int signatureNumber=0; >+ private StaxSignatureVerificator sig; >+ Key key; >+ public static StaxValidateContext createEnvolopedValidator(Key key, XMLStreamReader reader) { >+ return new StaxValidateContext(key,reader); >+ } >+ public void setSignatureNumber(int number) { >+ signatureNumber=number; >+ } >+ >+ protected StaxValidateContext(Key key,XMLStreamReader reader) { >+ this.key=key; >+ this.reader=reader; >+ } >+ >+ public String getBaseURI() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public void setBaseURI(String baseURI) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public KeySelector getKeySelector() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public void setKeySelector(KeySelector ks) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public URIDereferencer getURIDereferencer() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public void setURIDereferencer(URIDereferencer dereferencer) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public String getNamespacePrefix(String namespaceURI, String defaultPrefix) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public String putNamespacePrefix(String namespaceURI, String prefix) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public String getDefaultNamespacePrefix() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public void setDefaultNamespacePrefix(String defaultPrefix) { >+ // TODO Auto-generated method stub >+ >+ } >+ >+ public Object setProperty(String name, Object value) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public Object getProperty(String name) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public Object get(Object key) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public Object put(Object key, Object value) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public StreamFilter getStreamReader() { >+ sig = new StaxSignatureVerificator(); >+ return sig; >+ } >+ >+ protected XMLSignature getSignature() { >+ return sig.signatures.get(signatureNumber); >+ } >+ >+} >Index: src/com/r_bg/stax/StaxWatcher.java >=================================================================== >--- src/com/r_bg/stax/StaxWatcher.java >+++ src/com/r_bg/stax/StaxWatcher.java >@@ -0,0 +1,13 @@ >+package com.r_bg.stax; >+ >+import javax.xml.stream.XMLStreamReader; >+ >+public interface StaxWatcher { >+ /** >+ * Insert a C14n if needed >+ * @param reader >+ * @return a StreamFilter to be notified for the life of the element and all >+ * subelements. >+ */ >+ public StaxWorker watch(XMLStreamReader reader, StaxSignatureVerificator sig); >+} >Index: src/com/r_bg/stax/StaxWorker.java >=================================================================== >--- src/com/r_bg/stax/StaxWorker.java >+++ src/com/r_bg/stax/StaxWorker.java >@@ -0,0 +1,8 @@ >+package com.r_bg.stax; >+ >+import javax.xml.stream.XMLStreamReader; >+ >+public interface StaxWorker { >+ public StaxWorker read(XMLStreamReader reader); >+ public StaxWatcher remove(); >+} >Index: src/com/r_bg/stax/StaxXMLSignatureFactory.java >=================================================================== >--- src/com/r_bg/stax/StaxXMLSignatureFactory.java >+++ src/com/r_bg/stax/StaxXMLSignatureFactory.java >@@ -0,0 +1,179 @@ >+package com.r_bg.stax; >+ >+import java.security.AccessController; >+import java.security.InvalidAlgorithmParameterException; >+import java.security.NoSuchAlgorithmException; >+import java.security.PrivilegedAction; >+import java.security.Provider; >+import java.security.Security; >+import java.util.List; >+ >+import javax.xml.crypto.Data; >+import javax.xml.crypto.MarshalException; >+import javax.xml.crypto.URIDereferencer; >+import javax.xml.crypto.XMLStructure; >+import javax.xml.crypto.dsig.CanonicalizationMethod; >+import javax.xml.crypto.dsig.DigestMethod; >+import javax.xml.crypto.dsig.Manifest; >+import javax.xml.crypto.dsig.Reference; >+import javax.xml.crypto.dsig.SignatureMethod; >+import javax.xml.crypto.dsig.SignatureProperties; >+import javax.xml.crypto.dsig.SignatureProperty; >+import javax.xml.crypto.dsig.SignedInfo; >+import javax.xml.crypto.dsig.Transform; >+import javax.xml.crypto.dsig.XMLObject; >+import javax.xml.crypto.dsig.XMLSignature; >+import javax.xml.crypto.dsig.XMLSignatureFactory; >+import javax.xml.crypto.dsig.XMLValidateContext; >+import javax.xml.crypto.dsig.keyinfo.KeyInfo; >+import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec; >+import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec; >+import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec; >+import javax.xml.crypto.dsig.spec.TransformParameterSpec; >+ >+import org.jcp.xml.dsig.internal.dom.XMLDSigRI; >+ >+public class StaxXMLSignatureFactory extends XMLSignatureFactory { >+ static { >+ >+ Security.addProvider(new StaxProvider()); >+ >+ }@Override >+ public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki, List objects, String id, String signatureValueId) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Reference newReference(String uri, DigestMethod dm) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Reference newReference(String uri, DigestMethod dm, List transforms, String type, String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Reference newReference(String uri, DigestMethod dm, List transforms, String type, String id, byte[] digestValue) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Reference newReference(String uri, DigestMethod dm, List appliedTransforms, Data result, List transforms, String type, String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public SignedInfo newSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, List references) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public SignedInfo newSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, List references, String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public XMLObject newXMLObject(List content, String id, String mimeType, String encoding) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Manifest newManifest(List references) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Manifest newManifest(List references, String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public SignatureProperty newSignatureProperty(List content, String target, String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public SignatureProperties newSignatureProperties(List properties, String id) { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public DigestMethod newDigestMethod(String algorithm, DigestMethodParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public SignatureMethod newSignatureMethod(String algorithm, SignatureMethodParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Transform newTransform(String algorithm, TransformParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public Transform newTransform(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public CanonicalizationMethod newCanonicalizationMethod(String algorithm, C14NMethodParameterSpec params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public CanonicalizationMethod newCanonicalizationMethod(String algorithm, XMLStructure params) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public XMLSignature unmarshalXMLSignature(XMLValidateContext context) throws MarshalException { >+ // TODO Auto-generated method stub >+ return ((StaxValidateContext)context).getSignature(); >+ } >+ >+ @Override >+ public XMLSignature unmarshalXMLSignature(XMLStructure xmlStructure) throws MarshalException { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ @Override >+ public boolean isFeatureSupported(String feature) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+ @Override >+ public URIDereferencer getURIDereferencer() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+} >Index: src/com/r_bg/stax/XMLSignatureWorker.java >=================================================================== >--- src/com/r_bg/stax/XMLSignatureWorker.java >+++ src/com/r_bg/stax/XMLSignatureWorker.java >@@ -0,0 +1,320 @@ >+package com.r_bg.stax; >+ >+import java.io.ByteArrayOutputStream; >+import java.io.InputStream; >+import java.security.MessageDigest; >+import java.security.NoSuchAlgorithmException; >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+import javax.xml.crypto.Data; >+import javax.xml.crypto.KeySelectorResult; >+import javax.xml.crypto.MarshalException; >+import javax.xml.crypto.dsig.CanonicalizationMethod; >+import javax.xml.crypto.dsig.DigestMethod; >+import javax.xml.crypto.dsig.Reference; >+import javax.xml.crypto.dsig.SignatureMethod; >+import javax.xml.crypto.dsig.SignedInfo; >+import javax.xml.crypto.dsig.XMLSignContext; >+import javax.xml.crypto.dsig.XMLSignature; >+import javax.xml.crypto.dsig.XMLSignatureException; >+import javax.xml.crypto.dsig.XMLValidateContext; >+import javax.xml.crypto.dsig.keyinfo.KeyInfo; >+import javax.xml.stream.XMLStreamReader; >+ >+import org.apache.xml.security.algorithms.JCEMapper; >+import org.apache.xml.security.algorithms.MessageDigestAlgorithm; >+import org.apache.xml.security.algorithms.SignatureAlgorithm; >+import org.apache.xml.security.exceptions.Base64DecodingException; >+import org.apache.xml.security.utils.Base64; >+import org.apache.xml.security.utils.DigesterOutputStream; >+ >+class Constants { >+ public static final String DS_URI="http://www.w3.org/2000/09/xmldsig#"; >+} >+ >+ >+ >+ >+class ReferenceWorker implements StaxWorker, Reference, DigestResultListener { >+ boolean readDigestValue=false; >+ String uri; >+ String c14nType; >+ String digestMethod; >+ byte[] digestValue; >+ byte[] calculateDigestValue; >+ boolean correct=false; >+ DigesterOutputStream os; >+ public StaxWorker read(XMLStreamReader reader) { >+ switch (reader.getEventType()) { >+ >+ case XMLStreamReader.START_ELEMENT: >+ if(Constants.DS_URI.equals(reader.getNamespaceURI())) { >+ String name=reader.getLocalName(); >+ if (name.equals("Reference") ) { >+ uri=reader.getAttributeValue(null,"URI"); >+ } >+ if (name.equals("DigestMethod")) { >+ digestMethod=reader.getAttributeValue(null,"Algorithm"); >+ try { >+ MessageDigest ms = MessageDigest.getInstance( >+ JCEMapper.translateURItoJCEID(digestMethod)); >+ os=new DigesterOutputStream(ms); >+ } catch (NoSuchAlgorithmException e) { >+ //TODO: Better error handling. >+ e.printStackTrace(); >+ } >+ } >+ if (name.equals("DigestValue")) { >+ readDigestValue=true; >+ } >+ } >+ break; >+ case XMLStreamReader.END_ELEMENT: >+ if (Constants.DS_URI.equals(reader.getNamespaceURI())) { >+ if (reader.getLocalName().equals("DigestValue")) { >+ readDigestValue=false; >+ } >+ } >+ break; >+ case XMLStreamReader.CHARACTERS: >+ if (readDigestValue) { >+ try { >+ digestValue=Base64.decode(reader.getText()); >+ } catch (Base64DecodingException e) { >+ e.printStackTrace(); >+ } >+ } >+ break; >+ } >+ return null; >+ } >+ public StaxWatcher remove() { >+ return new IdWatcher(uri.substring(1),this,os); >+ } >+ /* (non-Javadoc) >+ * @see com.r_bg.stax.DigestResultListener#setResult(byte[]) >+ */ >+ public void setResult(byte[] result) { >+ calculateDigestValue=os.getDigestValue(); >+ correct=Arrays.equals(calculateDigestValue, digestValue); >+ >+ } >+ public List getTransforms() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public DigestMethod getDigestMethod() { >+ return null; >+ } >+ public String getId() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public byte[] getDigestValue() { >+ return digestValue; >+ } >+ public byte[] getCalculatedDigestValue() { >+ return calculateDigestValue; >+ } >+ public boolean validate(XMLValidateContext validateContext) throws XMLSignatureException { >+ return correct; >+ } >+ public Data getDereferencedData() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public InputStream getDigestInputStream() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public String getURI() { >+ return uri; >+ } >+ public String getType() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public boolean isFeatureSupported(String feature) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+} >+class SignedInfoWorker implements StaxWorker, SignedInfo, DigestResultListener { >+ ByteArrayOutputStream bos=new ByteArrayOutputStream(); >+ boolean initial=true; >+ C14nWorker c14n=new C14nWorker(this,bos); >+ List<ReferenceWorker> references=new ArrayList<ReferenceWorker>(); >+ String signatureMethod; >+ String c14nMethod; >+ public StaxWorker read(XMLStreamReader reader) { >+ if (reader.getEventType()==XMLStreamReader.START_ELEMENT && Constants.DS_URI.equals(reader.getNamespaceURI())) { >+ String name=reader.getLocalName(); >+ if (name.equals("Reference") ) { >+ ReferenceWorker r=new ReferenceWorker(); >+ references.add(r); >+ return r; >+ } >+ if (name.equals("SignatureMethod")) { >+ signatureMethod=reader.getAttributeValue(null,"Algorithm"); >+ } >+ if (name.equals("CanonicalizationMethod")) { >+ //TODO: Change c14n. >+ c14nMethod=reader.getAttributeValue(null,"Algorithm"); >+ } >+ } >+ if (initial) { >+ initial=false; >+ return c14n; >+ } >+ >+ return null; >+ } >+ >+ public StaxWatcher remove() { >+ return null; >+ } >+ >+ public CanonicalizationMethod getCanonicalizationMethod() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public SignatureMethod getSignatureMethod() { >+ return null; >+ } >+ >+ public List getReferences() { >+ return references; >+ } >+ >+ public String getId() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public InputStream getCanonicalizedData() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ >+ public boolean isFeatureSupported(String feature) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+ public void setResult(byte[] result) { >+ >+ } >+ >+} >+class SignatureWatcher implements StaxWatcher { >+ public StaxWorker watch(XMLStreamReader reader, StaxSignatureVerificator sig) { >+ String name=reader.getLocalName(); >+ String uri=reader.getNamespaceURI(); >+ if (name.equals("Signature") && >+ uri.equals(Constants.DS_URI)) { >+ XMLSignatureWorker s=new XMLSignatureWorker(); >+ sig.addSignature(s); >+ return s; >+ } >+ >+ return null; >+ } >+} >+ >+public class XMLSignatureWorker implements StaxWorker,XMLSignature { >+ SignedInfoWorker si; >+ private boolean readSignatureValue=false; >+ private byte[] signatureValue; >+ public StaxWorker read(XMLStreamReader reader) { >+ switch (reader.getEventType()) { >+ case XMLStreamReader.START_ELEMENT: >+ if (Constants.DS_URI.equals(reader.getNamespaceURI())) { >+ String name=reader.getLocalName(); >+ if (name.equals("SignedInfo") ) { >+ si=new SignedInfoWorker(); >+ return si; >+ } >+ if (name.equals("SignatureValue")) { >+ readSignatureValue=true; >+ } >+ } >+ break; >+ case XMLStreamReader.END_ELEMENT: >+ if (Constants.DS_URI.equals(reader.getNamespaceURI())) { >+ if (reader.getLocalName().equals("SignatureValue")) { >+ readSignatureValue=false; >+ } >+ } >+ break; >+ case XMLStreamReader.CHARACTERS: >+ if (readSignatureValue) { >+ try { >+ signatureValue=Base64.decode(reader.getText()); >+ } catch (Base64DecodingException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ } >+ break; >+ } >+ return null; >+ } >+ >+ public StaxWatcher remove() { >+ return null; >+ } >+ public boolean validate(XMLValidateContext validateContext) throws XMLSignatureException { >+ StaxValidateContext ctx=(StaxValidateContext) validateContext; >+ try { >+ for (Reference ref: si.references) { >+ if (!ref.validate(ctx)) >+ return false; >+ } >+ SignatureAlgorithm sa=new SignatureAlgorithm(si.signatureMethod); >+ sa.initVerify(ctx.key); >+ sa.update(si.bos.toByteArray()); >+ return sa.verify(signatureValue); >+ } catch (org.apache.xml.security.signature.XMLSignatureException e) { >+ // TODO Auto-generated catch block >+ e.printStackTrace(); >+ } >+ >+ return false; >+ } >+ public KeyInfo getKeyInfo() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public SignedInfo getSignedInfo() { >+ return si; >+ } >+ public List getObjects() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public String getId() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public SignatureValue getSignatureValue() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public void sign(XMLSignContext signContext) throws MarshalException, XMLSignatureException { >+ // TODO Auto-generated method stub >+ >+ } >+ public KeySelectorResult getKeySelectorResult() { >+ // TODO Auto-generated method stub >+ return null; >+ } >+ public boolean isFeatureSupported(String feature) { >+ // TODO Auto-generated method stub >+ return false; >+ } >+ >+} >Index: src_unitTests/com/r_bg/stax/c14n/C14nExcl.java >=================================================================== >--- src_unitTests/com/r_bg/stax/c14n/C14nExcl.java >+++ src_unitTests/com/r_bg/stax/c14n/C14nExcl.java >@@ -0,0 +1,29 @@ >+package com.r_bg.stax.c14n; >+ >+import java.io.ByteArrayInputStream; >+ >+import javax.xml.stream.XMLInputFactory; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.stream.XMLStreamReader; >+ >+import junit.framework.TestCase; >+ >+public class C14nExcl extends TestCase { >+ public void testStandard() throws Exception { >+ String in="<doc xmlns:a=\"http://a\">\n" + >+ " <a:a xmlns=\"http://a\">\n" + >+ " <b/>\n" + >+ " </a:a>\n" + >+ "</doc>"; >+ String out="<doc>\n" + >+ " <a:a xmlns:a=\"http://a\">\n" + >+ " <b xmlns=\"http://a\"></b>\n" + >+ " </a:a>\n" + >+ "</doc>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ assertEquals("mismath",out, >+ C14n.cannoicalizeWithoutComments(reader,new AttributeHandleExclusive())); >+ } >+} >Index: src_unitTests/com/r_bg/stax/c14n/C14nIncl.java >=================================================================== >--- src_unitTests/com/r_bg/stax/c14n/C14nIncl.java >+++ src_unitTests/com/r_bg/stax/c14n/C14nIncl.java >@@ -0,0 +1,171 @@ >+package com.r_bg.stax.c14n; >+ >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+ >+import javax.xml.stream.XMLInputFactory; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.stream.XMLStreamReader; >+ >+import junit.framework.TestCase; >+ >+public class C14nIncl extends TestCase { >+ >+ public static void main(String[] args) { >+ } >+ public static void testRfc3_1() throws Exception { >+ String in="<?xml version=\"1.0\"?>\n" + >+ "\n" + >+ "<?xml-stylesheet href=\"doc.xsl\"\n" + >+ " type=\"text/xsl\" ?>\n" + >+ "\n" + >+ "<!DOCTYPE doc SYSTEM \"doc.dtd\">\n" + >+ "\n" + >+ "<doc>Hello, world!<!-- Comment 1 --></doc>\n" + >+ "\n" + >+ "<?pi-without-data ?>\n" + >+ "\n" + >+ "<!-- Comment 2 -->\n" + >+ "\n" + >+ "<!-- Comment 3 -->"; >+ String outWithoutComments="<?xml-stylesheet href=\"doc.xsl\"\n" + >+ " type=\"text/xsl\" ?>\n" + >+ "<doc>Hello, world!</doc>\n" + >+ "<?pi-without-data?>"; >+ String outWithComments="<?xml-stylesheet href=\"doc.xsl\"\n" + >+ " type=\"text/xsl\" ?>\n" + >+ "<doc>Hello, world!<!-- Comment 1 --></doc>\n" + >+ "<?pi-without-data?>\n" + >+ "<!-- Comment 2 -->\n" + >+ "<!-- Comment 3 -->"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ assertEquals("Output not like stated in 3.1 rfc",outWithoutComments, >+ C14n.cannoicalizeWithoutComments(reader,new C14nInclusive())); >+ >+ } >+ public static void testRfc3_2() throws Exception { >+ String in="<doc>\n" + >+ " <clean> </clean>\n" + >+ " <dirty> A B </dirty>\n" + >+ " <mixed>\n" + >+ " A\n" + >+ " <clean> </clean>\n" + >+ " B\n" + >+ " <dirty> A B </dirty>\n" + >+ " C\n" + >+ " </mixed>\n" + >+ "</doc>"; >+ String outWithoutComments="<doc>\n" + >+ " <clean> </clean>\n" + >+ " <dirty> A B </dirty>\n" + >+ " <mixed>\n" + >+ " A\n" + >+ " <clean> </clean>\n" + >+ " B\n" + >+ " <dirty> A B </dirty>\n" + >+ " C\n" + >+ " </mixed>\n" + >+ "</doc>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ assertEquals("Output not like stated in 3.1 rfc",outWithoutComments, >+ C14n.cannoicalizeWithoutComments(reader,new C14nInclusive())); >+ >+ } >+ public static void testOrderInAttributes() throws Exception { >+ String in="<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" + >+ "<doc xmlns:b=\"http://www.ietf.org\">" + >+ " <doc2 xmlns:a=\"http://www.w3.org\">" + >+ " <doc3 xmlns=\"http://example.org\">\n" + >+ " <e3 name = \"elem3\" id=\"elem3\" />\n" + >+ " <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\" attr=\"I\'m\"\n" + >+ " />\n" + >+ "</doc3></doc2></doc>"; >+ String outWithoutComments="<doc xmlns:b=\"http://www.ietf.org\"> <doc2 xmlns:a=\"http://www.w3.org\"> <doc3 xmlns=\"http://example.org\">\n" + >+ " <e3 id=\"elem3\" name=\"elem3\"></e3>\n" + >+ " <e5 attr=\"I\'m\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" + >+ "</doc3></doc2></doc>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ assertEquals("Output not like stated in 3.1 rfc",outWithoutComments, >+ C14n.cannoicalizeWithoutComments(reader,new C14nInclusive())); >+ >+ } >+ public static void testOrderBetwenAttributesAndNss() throws Exception { >+ String in="<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" + >+ "<doc>\n"+ >+ " <e3 name = \"elem3\" xmlns=\"http://a.com/\" id=\"elem3\" />\n" + >+ "</doc>"; >+ String outWithoutComments="<doc>\n"+ >+ " <e3 xmlns=\"http://a.com/\" id=\"elem3\" name=\"elem3\"></e3>\n" + >+ "</doc>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ >+ assertEquals("Output not like stated in 3.1 rfc",outWithoutComments, >+ C14n.cannoicalizeWithoutComments(reader,new C14nInclusive())); >+ >+ } >+ public static void testRfc3_3() throws Exception { >+ String in="<!DOCTYPE doc [<!ATTLIST e9 attr CDATA \"default\">]>\n" + >+ "<doc>\n" + >+ " <e1 />\n" + >+ " <e2 ></e2>\n" + >+ " <e3 name = \"elem3\" id=\"elem3\" />\n" + >+ " <e4 name=\"elem4\" id=\"elem4\" ></e4>\n" + >+ " <e5 a:attr=\"out\" b:attr=\"sorted\" attr2=\"all\" attr=\"I\'m\"\n" + >+ " xmlns:b=\"http://www.ietf.org\"\n" + >+ " xmlns:a=\"http://www.w3.org\"\n" + >+ " xmlns=\"http://example.org\"/>\n" + >+ " <e6 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" + >+ " <e7 xmlns=\"http://www.ietf.org\">\n" + >+ " <e8 xmlns=\"\" xmlns:a=\"http://www.w3.org\">\n" + >+ " <e9 xmlns=\"\" xmlns:a=\"http://www.ietf.org\"/>\n" + >+ " </e8>\n" + >+ " </e7>\n" + >+ " </e6>\n" + >+ "</doc>"; >+ String outWithoutComments="<doc>\n" + >+ " <e1></e1>\n" + >+ " <e2></e2>\n" + >+ " <e3 id=\"elem3\" name=\"elem3\"></e3>\n" + >+ " <e4 id=\"elem4\" name=\"elem4\"></e4>\n" + >+ " <e5 xmlns=\"http://example.org\" xmlns:a=\"http://www.w3.org\" xmlns:b=\"http://www.ietf.org\" attr=\"I\'m\" attr2=\"all\" b:attr=\"sorted\" a:attr=\"out\"></e5>\n" + >+ " <e6 xmlns:a=\"http://www.w3.org\">\n" + >+ " <e7 xmlns=\"http://www.ietf.org\">\n" + >+ " <e8 xmlns=\"\">\n" + >+ " <e9 xmlns:a=\"http://www.ietf.org\" attr=\"default\"></e9>\n" + >+ " </e8>\n" + >+ " </e7>\n" + >+ " </e6>\n" + >+ "</doc>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ //im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ assertEquals("Output not like stated in 3.1 rfc",outWithoutComments, >+ C14n.cannoicalizeWithoutComments(reader,new C14nInclusive())); >+ ByteArrayOutputStream os=new ByteArrayOutputStream(); >+ C14n c=new C14n(new C14nInclusive(),os); >+ reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ reader=im.createFilteredReader(reader,c); >+ while ((reader.getEventType())!=XMLStreamReader.END_DOCUMENT) { >+ reader.next(); >+ } >+ assertEquals("Output not like stated in 3.1 rfc",outWithoutComments, >+ new String(os.toByteArray())); >+ >+ >+ >+ } >+ >+ >+ protected void setUp() throws Exception { >+ super.setUp(); >+ } >+ >+} >Index: src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java >=================================================================== >--- src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java >+++ src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java >@@ -0,0 +1,32 @@ >+package com.r_bg.stax.c14n; >+ >+import junit.framework.TestCase; >+ >+import java.io.ByteArrayInputStream; >+ >+import javax.xml.stream.XMLInputFactory; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.stream.XMLStreamReader; >+ >+ >+ >+public class C14nUnknown extends TestCase { >+ public void testStandard() throws Exception { >+ String in="<doc xmlns:a=\"http://a\">\n" + >+ " <a:a xmlns=\"http://a\">\n" + >+ " <b/>\n" + >+ " </a:a>\n" + >+ "</doc>"; >+ String out="<doc>\n" + >+ " <a:a xmlns:a=\"http://a\">\n" + >+ " <b xmlns=\"http://a\"></b>\n" + >+ " </a:a>\n" + >+ "</doc>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ assertEquals("mismath",out, >+ C14n.cannoicalizeWithoutComments(reader,new AttributeHandleExclusive())); >+ } >+} >+ >Index: src_unitTests/com/r_bg/stax/XMLSignatureTest.java >=================================================================== >--- src_unitTests/com/r_bg/stax/XMLSignatureTest.java >+++ src_unitTests/com/r_bg/stax/XMLSignatureTest.java >@@ -0,0 +1,255 @@ >+package com.r_bg.stax; >+ >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.FileInputStream; >+import java.io.FileOutputStream; >+import java.io.IOException; >+import java.math.BigInteger; >+import java.security.Key; >+import java.security.KeyFactory; >+import java.security.KeyStore; >+import java.security.NoSuchAlgorithmException; >+import java.security.PrivateKey; >+import java.security.PublicKey; >+import java.security.spec.RSAPublicKeySpec; >+ >+import javax.xml.crypto.XMLStructure; >+import javax.xml.crypto.dsig.Reference; >+import javax.xml.crypto.dsig.XMLSignature; >+import javax.xml.crypto.dsig.XMLSignatureFactory; >+import javax.xml.crypto.dsig.XMLValidateContext; >+import javax.xml.parsers.DocumentBuilderFactory; >+import javax.xml.parsers.ParserConfigurationException; >+import javax.xml.stream.XMLInputFactory; >+import javax.xml.stream.XMLStreamException; >+import javax.xml.stream.XMLStreamReader; >+ >+import org.apache.xml.security.Init; >+import org.apache.xml.security.c14n.Canonicalizer; >+import org.apache.xml.security.signature.ObjectContainer; >+import org.apache.xml.security.transforms.Transforms; >+import org.apache.xml.security.utils.Base64; >+import org.apache.xml.security.utils.XMLUtils; >+import org.w3c.dom.Document; >+import org.w3c.dom.Element; >+import org.xml.sax.SAXException; >+ >+import sun.security.rsa.RSAKeyFactory; >+import sun.security.rsa.RSAPrivateKeyImpl; >+ >+import junit.framework.TestCase; >+ >+public class XMLSignatureTest extends TestCase { >+ static Key getKey() throws Exception { >+ byte[] modulus=Base64.decode("skqbW7oBwM1lCWNwC1obkgj4VV58G1AX7ERMWEIrQQlZ8uFdQ3FNkgMdtmx/XUjNF+zXTDmxe+K/\n" + >+ "lne+0KDwLWskqhS6gnkQmxZoR4FUovqRngoqU6bnnn0pM9gF/AI/vcdu7aowbF9S7TVlSw7IpxIQ\n" + >+ "VjevEfohDpn/+oxljm0=\n"); >+ byte[] exponent=Base64.decode("AQAB"); >+ RSAPublicKeySpec spec=new RSAPublicKeySpec(new BigInteger(1,modulus),new BigInteger(1,exponent)); >+ return KeyFactory.getInstance("rsa").generatePublic(spec); >+ } >+ static PrivateKey obtainPrivateKey() throws Exception { >+ KeyStore ks = KeyStore.getInstance("JKS"); >+ FileInputStream fis = new FileInputStream("keystore.jks"); >+ >+ ks.load(fis, "secret".toCharArray()); >+ return (PrivateKey) ks.getKey("tfc", >+ "secret".toCharArray()); >+ } >+ static PublicKey obtainPublicKey() throws Exception { >+ KeyStore ks = KeyStore.getInstance("JKS"); >+ FileInputStream fis = new FileInputStream("keystore.jks"); >+ >+ ks.load(fis, "secret".toCharArray()); >+ return ks.getCertificate("tfc").getPublicKey(); >+ >+ } >+ static String generateSignature(int size,String name) throws Exception{ >+ DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance(); >+ fact.setNamespaceAware(true); >+ Document doc=fact.newDocumentBuilder().newDocument(); >+ org.apache.xml.security.signature.XMLSignature sig=new org.apache.xml.security.signature.XMLSignature(doc,"", >+ org.apache.xml.security.signature.XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, >+ Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS); >+ Transforms trs=new Transforms(doc); >+ trs.addTransform(Transforms.TRANSFORM_C14N_EXCL_OMIT_COMMENTS); >+ sig.addDocument("#1",trs); >+ doc.appendChild(sig.getElement()); >+ ObjectContainer ob=new ObjectContainer(doc); >+ ob.setId("1"); >+ sig.appendObject(ob); >+ sig.addKeyInfo(obtainPublicKey()); >+ for (int i=0;i<size;i++) { >+ Element el=doc.createElement("Prueba"); >+ Element el2=doc.createElement("SubPrueba"); >+ el2.appendChild(doc.createTextNode("Prueba de firmas gordas")); >+ el.appendChild(el2); >+ Element el3=doc.createElement("SubPrueba"); >+ el3.appendChild(doc.createElement("SubSubPrueba")); >+ el3.appendChild(doc.createTextNode("Otro textillo por aqui")); >+ el2.appendChild(el3); >+ el.appendChild(doc.createTextNode("\n")); >+ ob.appendChild(el); >+ } >+ >+ sig.sign(obtainPrivateKey()); >+ FileOutputStream bos=new FileOutputStream(name); >+ XMLUtils.outputDOM(doc, bos); >+ //System.out.println(bos.toByteArray().length); >+ return ""; >+ } >+ static Key checkSignature(String sig) throws Exception { >+ DocumentBuilderFactory fact=DocumentBuilderFactory.newInstance(); >+ fact.setNamespaceAware(true); >+ Document doc=fact.newDocumentBuilder().parse(new ByteArrayInputStream(sig.getBytes())); >+ org.apache.xml.security.signature.XMLSignature signature = new org.apache.xml.security.signature.XMLSignature((Element)doc.getDocumentElement().getFirstChild(),""); >+ System.out.println("Her:"+signature.checkSignatureValue(signature.getKeyInfo().getPublicKey())); >+ System.out.println("Her2:"+(getKey().equals(signature.getKeyInfo().getPublicKey()))) ; >+ return signature.getKeyInfo().getPublicKey(); >+ } >+ public void testEnvelopedSignature() throws Exception { >+ String in="<RootObject><ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\n" + >+ "<ds:SignedInfo>\n" + >+ "<ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\n" + >+ "<ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\n" + >+ "<ds:Reference URI=\"#1\">\n" + >+ "<ds:Transforms>\n" + >+ "<ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:Transform>\n" + >+ "</ds:Transforms>\n" + >+ "<ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></ds:DigestMethod>\n" + >+ "<ds:DigestValue>oMQoFufPA7Un6cfz0GaEOJpE4Z8=</ds:DigestValue>\n" + >+ "</ds:Reference>\n" + >+ "</ds:SignedInfo>\n" + >+ "<ds:SignatureValue>\n" + >+ "AhyiFQ6hucykYJOJDBV3wbPBe2TAURXXfCUD7BmSAecT+izT9fHFsxRVez3s+6hYSgtaVhmeVgbd\n" + >+ "ZEOMPFihBGldi1NV73Z/tpXxqNvY+/NwQmmasQp9gzFHxYF2cqi8m7sAHM03BIC1YoBctxVw/jxV\n" + >+ "ClhLJuTSHoKwlzKH24g=\n" + >+ "</ds:SignatureValue>\n" + >+ "<ds:KeyInfo>\n" + >+ "<ds:KeyValue>\n" + >+ "<ds:RSAKeyValue>\n" + >+ "<ds:Modulus>\n" + >+ "skqbW7oBwM1lCWNwC1obkgj4VV58G1AX7ERMWEIrQQlZ8uFdQ3FNkgMdtmx/XUjNF+zXTDmxe+K/\n" + >+ "lne+0KDwLWskqhS6gnkQmxZoR4FUovqRngoqU6bnnn0pM9gF/AI/vcdu7aowbF9S7TVlSw7IpxIQ\n" + >+ "VjevEfohDpn/+oxljm0=\n" + >+ "</ds:Modulus>\n" + >+ "<ds:Exponent>AQAB</ds:Exponent>\n" + >+ "</ds:RSAKeyValue>\n" + >+ "</ds:KeyValue>\n" + >+ "</ds:KeyInfo>\n" + >+ "<ds:Object Id=\"1\"><UnderObject>A text in a box<OtherObject><OtherObject2></OtherObject2><OtherObject6></OtherObject6><OtherObject></OtherObject></OtherObject></UnderObject></ds:Object>\n" + >+ "</ds:Signature></RootObject>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ StaxValidateContext stx = StaxValidateContext.createEnvolopedValidator(getKey(),reader); >+ reader=im.createFilteredReader(reader, stx.getStreamReader()); >+ while ((reader.getEventType())!=XMLStreamReader.END_DOCUMENT) { >+ reader.next(); >+ } >+ XMLSignatureFactory fac=XMLSignatureFactory.getInstance("Stax"); >+ stx.setSignatureNumber(0); >+ XMLSignature sig=fac.unmarshalXMLSignature(stx); >+ if (!((Reference)sig.getSignedInfo().getReferences().get(0)).validate(stx)) { >+ //Firma invalida. >+ } >+ generateSignature(262144/34,"Enveloped1MB.xml"); >+ assertTrue("Signature References must be right", >+ ((Reference)sig.getSignedInfo().getReferences().get(0)).validate(stx)); >+ assertTrue("Signature must be right", >+ sig.validate(stx)); >+ } >+ public void testTamperedEnvelopedSignature() throws Exception { >+ String in="<RootObject><ds:Signature xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\n" + >+ "<ds:SignedInfo>\n" + >+ "<ds:CanonicalizationMethod Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"/>\n" + >+ "<ds:SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/>\n" + >+ "<ds:Reference URI=\"#1\">\n" + >+ "<ds:Transforms>\n" + >+ "<ds:Transform Algorithm=\"http://www.w3.org/2001/10/xml-exc-c14n#\"></ds:Transform>\n" + >+ "</ds:Transforms>\n" + >+ "<ds:DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"></ds:DigestMethod>\n" + >+ "<ds:DigestValue>oMQoFufPA7Un6cfz0GaEOJpE4Z8=</ds:DigestValue>\n" + >+ "</ds:Reference>\n" + >+ "</ds:SignedInfo>\n" + >+ "<ds:SignatureValue>\n" + >+ "AhyiFQ6hucykYJOJDBV3wbPBe2TAURXXfCUD7BmSAecT+izT9fHFsxRVez3s+6hYSgtaVhmeVgbd\n" + >+ "ZEOMPFihBGldi1NV73Z/tpXxqNvY+/NwQmmasQp9gzFHxYF2cqi8m7sAHM03BIC1YoBctxVw/jxV\n" + >+ "ClhLJuTSHoKwlzKH24g=\n" + >+ "</ds:SignatureValue>\n" + >+ "<ds:KeyInfo>\n" + >+ "<ds:KeyValue>\n" + >+ "<ds:RSAKeyValue>\n" + >+ "<ds:Modulus>\n" + >+ "skqbW7oBwM1lCWNwC1obkgj4VV58G1AX7ERMWEIrQQlZ8uFdQ3FNkgMdtmx/XUjNF+zXTDmxe+K/\n" + >+ "lne+0KDwLWskqhS6gnkQmxZoR4FUovqRngoqU6bnnn0pM9gF/AI/vcdu7aowbF9S7TVlSw7IpxIQ\n" + >+ "VjevEfohDpn/+oxljm0=\n" + >+ "</ds:Modulus>\n" + >+ "<ds:Exponent>AQAB</ds:Exponent>\n" + >+ "</ds:RSAKeyValue>\n" + >+ "</ds:KeyValue>\n" + >+ "</ds:KeyInfo>\n" + >+ "<ds:Object Id=\"1\"><UnderObject>a text in a box<OtherObject><OtherObject2></OtherObject2><OtherObject6></OtherObject6><OtherObject></OtherObject></OtherObject></UnderObject></ds:Object>\n" + >+ "</ds:Signature></RootObject>"; >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new ByteArrayInputStream(in.getBytes())); >+ StaxValidateContext stx = StaxValidateContext.createEnvolopedValidator(getKey(),reader); >+ reader=im.createFilteredReader(reader, stx.getStreamReader()); >+ while ((reader.getEventType())!=XMLStreamReader.END_DOCUMENT) { >+ reader.next(); >+ } >+ XMLSignatureFactory fac=XMLSignatureFactory.getInstance("Stax" ); >+ stx.setSignatureNumber(0); >+ XMLSignature sig=fac.unmarshalXMLSignature(stx); >+ assertFalse("Signature must be wrong", >+ ((Reference)sig.getSignedInfo().getReferences().get(0)).validate(stx)); >+ assertFalse("Signature must be false", >+ sig.validate(stx)); >+ } >+ final static String ALUMNO_NS="http://fi.upm.es/alumnos/1/0"; >+ public void atestParsing() throws Exception { >+ XMLInputFactory im=XMLInputFactory.newInstance(); >+ im.setProperty("javax.xml.stream.supportDTD", new Boolean(false)); >+ XMLStreamReader reader=im.createXMLStreamReader(new FileInputStream("alumnoEnveloped.xml")); >+ StaxValidateContext stx = StaxValidateContext.createEnvolopedValidator(getKey(),reader); >+ reader=im.createFilteredReader(reader, stx.getStreamReader()); >+ String nombre=null; >+ String apellidos=null; >+ do { >+ if (reader.getEventType()==XMLStreamReader.START_ELEMENT) { >+ if (!ALUMNO_NS.equals(reader.getNamespaceURI())) >+ continue; >+ if ("Nombre".equals(reader.getLocalName())) { >+ reader.next(); >+ nombre=reader.getText(); >+ continue; >+ } >+ if ("Apellidos".equals(reader.getLocalName())) { >+ reader.next(); >+ apellidos=reader.getText(); >+ continue; >+ } >+ } >+ reader.next(); >+ } while ((reader.getEventType())!=XMLStreamReader.END_DOCUMENT); >+ System.out.println("Nombre: "+nombre+" Apellidos:"+apellidos); >+ XMLSignatureFactory fac=XMLSignatureFactory.getInstance("Stax"); >+ stx.setSignatureNumber(0); >+ XMLSignature sig=fac.unmarshalXMLSignature(stx); >+ if (!sig.validate(stx)) { >+ //Firma invalida. >+ System.out.println("Firma Invalida"); >+ } >+ } >+ >+ >+ static { >+ Init.init(); >+ >+ StaxXMLSignatureFactory.getInstance("Stax", new StaxProvider()); >+ >+ }; >+ >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 39029
:
17918
|
18360
| 19265