You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by ra...@apache.org on 2007/07/15 18:32:48 UTC

svn commit: r556426 - in /xml/security/branches/stax_jsr105: src/com/ src/com/r_bg/ src/com/r_bg/stax/ src/com/r_bg/stax/c14n/ src/org/apache/xml/security/algorithms/ src/org/apache/xml/security/signature/ src/org/apache/xml/security/utils/ src_unitTes...

Author: raul
Date: Sun Jul 15 09:32:46 2007
New Revision: 556426

URL: http://svn.apache.org/viewvc?view=rev&rev=556426
Log:
First Import

Added:
    xml/security/branches/stax_jsr105/src/com/
    xml/security/branches/stax_jsr105/src/com/r_bg/
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/C14nWorker.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/DigestResultListener.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxProvider.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxSignatureVerificator.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxValidateContext.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWatcher.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWorker.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxXMLSignatureFactory.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeComparator.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeHandleExclusive.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14Unknown.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14n.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nAttributeHandler.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nInclusive.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/NsComparator.java   (with props)
    xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/StaxC14nHelper.java   (with props)
    xml/security/branches/stax_jsr105/src_unitTests/com/
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/XMLSignatureTest.java   (with props)
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nExcl.java   (with props)
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nIncl.java   (with props)
    xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java   (with props)
Modified:
    xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/Algorithm.java
    xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java
    xml/security/branches/stax_jsr105/src/org/apache/xml/security/signature/Reference.java
    xml/security/branches/stax_jsr105/src/org/apache/xml/security/utils/DigesterOutputStream.java

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/C14nWorker.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/C14nWorker.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/C14nWorker.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/C14nWorker.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/C14nWorker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/DigestResultListener.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/DigestResultListener.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/DigestResultListener.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/DigestResultListener.java Sun Jul 15 09:32:46 2007
@@ -0,0 +1,7 @@
+package com.r_bg.stax;
+
+interface DigestResultListener {
+
+	public abstract void setResult(byte[] result);
+
+}
\ No newline at end of file

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/DigestResultListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxProvider.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxProvider.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxProvider.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxProvider.java Sun Jul 15 09:32:46 2007
@@ -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;
+	    }
+	});
+    }
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxProvider.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxSignatureVerificator.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxSignatureVerificator.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxSignatureVerificator.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxSignatureVerificator.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxSignatureVerificator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxValidateContext.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxValidateContext.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxValidateContext.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxValidateContext.java Sun Jul 15 09:32:46 2007
@@ -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);
+	}
+
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxValidateContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWatcher.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWatcher.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWatcher.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWatcher.java Sun Jul 15 09:32:46 2007
@@ -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);
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWatcher.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWorker.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWorker.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWorker.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWorker.java Sun Jul 15 09:32:46 2007
@@ -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();
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxWorker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxXMLSignatureFactory.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxXMLSignatureFactory.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxXMLSignatureFactory.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxXMLSignatureFactory.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}
+
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/StaxXMLSignatureFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}
+	
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeComparator.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeComparator.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeComparator.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeComparator.java Sun Jul 15 09:32:46 2007
@@ -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));				
+	}	
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeComparator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeHandleExclusive.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeHandleExclusive.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeHandleExclusive.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeHandleExclusive.java Sun Jul 15 09:32:46 2007
@@ -0,0 +1,72 @@
+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();
+			String nsDef=nc.getNamespaceURI(prefix);
+			if (nsDef==null)
+				nsDef="";
+			if (!nsD.hasBeenRender(prefix,nsDef))
+				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);
+			String nsDef=nc.getNamespaceURI(realPrefix);
+			if (nsDef==null) nsDef="";
+			os.write(nsDef.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;
+	}	
+
+	}
+
+
+

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/AttributeHandleExclusive.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14Unknown.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14Unknown.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14Unknown.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14Unknown.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}
+
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14Unknown.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14n.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14n.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14n.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14n.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}
+}
+	
+
+
+

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14n.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nAttributeHandler.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nAttributeHandler.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nAttributeHandler.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nAttributeHandler.java Sun Jul 15 09:32:46 2007
@@ -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;
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nAttributeHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nInclusive.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nInclusive.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nInclusive.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nInclusive.java Sun Jul 15 09:32:46 2007
@@ -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;
+	}	
+
+}

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/C14nInclusive.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/NsComparator.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/NsComparator.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/NsComparator.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/NsComparator.java Sun Jul 15 09:32:46 2007
@@ -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

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/NsComparator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/StaxC14nHelper.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/StaxC14nHelper.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/StaxC14nHelper.java (added)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/StaxC14nHelper.java Sun Jul 15 09:32:46 2007
@@ -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

Propchange: xml/security/branches/stax_jsr105/src/com/r_bg/stax/c14n/StaxC14nHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/Algorithm.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/Algorithm.java?view=diff&rev=556426&r1=556425&r2=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/Algorithm.java (original)
+++ xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/Algorithm.java Sun Jul 15 09:32:46 2007
@@ -30,7 +30,9 @@
  *
  */
 public abstract class Algorithm extends SignatureElementProxy {
-
+	public Algorithm() {
+		
+	};
    /**
     *
     * @param doc

Modified: xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java?view=diff&rev=556426&r1=556425&r2=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java (original)
+++ xml/security/branches/stax_jsr105/src/org/apache/xml/security/algorithms/SignatureAlgorithm.java Sun Jul 15 09:32:46 2007
@@ -78,6 +78,9 @@
 
    private String algorithmURI;
 
+   public SignatureAlgorithm(String algorithmURI) {	   
+	   this.algorithmURI = algorithmURI;
+   }
    /**
     * Constructor SignatureAlgorithm
     *

Modified: xml/security/branches/stax_jsr105/src/org/apache/xml/security/signature/Reference.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/org/apache/xml/security/signature/Reference.java?view=diff&rev=556426&r1=556425&r2=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/org/apache/xml/security/signature/Reference.java (original)
+++ xml/security/branches/stax_jsr105/src/org/apache/xml/security/signature/Reference.java Sun Jul 15 09:32:46 2007
@@ -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);

Modified: xml/security/branches/stax_jsr105/src/org/apache/xml/security/utils/DigesterOutputStream.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src/org/apache/xml/security/utils/DigesterOutputStream.java?view=diff&rev=556426&r1=556425&r2=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src/org/apache/xml/security/utils/DigesterOutputStream.java (original)
+++ xml/security/branches/stax_jsr105/src/org/apache/xml/security/utils/DigesterOutputStream.java Sun Jul 15 09:32:46 2007
@@ -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;		
 	}
 

Added: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/XMLSignatureTest.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/XMLSignatureTest.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/XMLSignatureTest.java (added)
+++ xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/XMLSignatureTest.java Sun Jul 15 09:32:46 2007
@@ -0,0 +1,256 @@
+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());
+
+	};
+
+}
\ No newline at end of file

Propchange: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/XMLSignatureTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nExcl.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nExcl.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nExcl.java (added)
+++ xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nExcl.java Sun Jul 15 09:32:46 2007
@@ -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()));
+	}
+}

Propchange: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nExcl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nIncl.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nIncl.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nIncl.java (added)
+++ xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nIncl.java Sun Jul 15 09:32:46 2007
@@ -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();
+	}
+
+}

Propchange: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nIncl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java
URL: http://svn.apache.org/viewvc/xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java?view=auto&rev=556426
==============================================================================
--- xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java (added)
+++ xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java Sun Jul 15 09:32:46 2007
@@ -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()));
+		}
+}
+

Propchange: xml/security/branches/stax_jsr105/src_unitTests/com/r_bg/stax/c14n/C14nUnknown.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain