You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by mu...@apache.org on 2007/07/25 19:22:54 UTC
svn commit: r559527 -
/xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java
Author: mullan
Date: Wed Jul 25 10:22:52 2007
New Revision: 559527
URL: http://svn.apache.org/viewvc?view=rev&rev=559527
Log:
Add support for parsing X509Certificate and X509CRLs to X509DataWorker.
Modified:
xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java
Modified: 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=diff&rev=559527&r1=559526&r2=559527
==============================================================================
--- xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java (original)
+++ xml/security/branches/stax_jsr105/src/com/r_bg/stax/XMLSignatureWorker.java Wed Jul 25 10:22:52 2007
@@ -1,5 +1,6 @@
package com.r_bg.stax;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.InputStream;
@@ -7,6 +8,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
+import java.security.cert.CertificateFactory;
import java.security.spec.AlgorithmParameterSpec;
import java.util.ArrayList;
import java.util.Arrays;
@@ -158,7 +160,7 @@
}
public List getTransforms() {
- return transforms;
+ return Collections.unmodifiableList(transforms);
}
public DigestMethod getDigestMethod() {
return new DigestMethod() {
@@ -176,11 +178,11 @@
public String getId() {
return id;
}
- public byte[] getDigestValue() {
- return (byte[]) digestValue.clone();
+ public byte[] getDigestValue() {
+ return digestValue == null ? null : (byte[]) digestValue.clone();
}
public byte[] getCalculatedDigestValue() {
- return calculateDigestValue;
+ return calculateDigestValue == null ? null : (byte[]) calculateDigestValue.clone();
}
public boolean validate(XMLValidateContext validateContext) throws XMLSignatureException {
return correct;
@@ -200,11 +202,10 @@
return type;
}
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;
@@ -279,7 +280,7 @@
}
public List getReferences() {
- return references;
+ return Collections.unmodifiableList(references);
}
public String getId() {
@@ -292,7 +293,6 @@
}
public boolean isFeatureSupported(String feature) {
- // TODO Auto-generated method stub
return false;
}
@@ -375,6 +375,7 @@
class X509DataWorker implements StaxWorker, X509Data {
private List content = new ArrayList();
+ private CertificateFactory cf;
public StaxWorker read(XMLStreamReader reader) {
switch (reader.getEventType()) {
@@ -406,21 +407,38 @@
return false;
}
});
+ } else if (name.equals("X509Certificate")) {
+ try {
+ byte[] cert = Base64.decode(reader.getElementText());
+ if (cf == null) {
+ cf = CertificateFactory.getInstance("X.509");
+ }
+ content.add(cf.generateCertificate(new ByteArrayInputStream(cert)));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else if (name.equals("X509CRL")) {
+ try {
+ byte[] crl = Base64.decode(reader.getElementText());
+ if (cf == null) {
+ cf = CertificateFactory.getInstance("X.509");
+ }
+ content.add(cf.generateCRL(new ByteArrayInputStream(crl)));
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
break;
}
return null;
}
-
public StaxWatcher remove() {
return null;
}
-
public List getContent() {
- return content;
+ return Collections.unmodifiableList(content);
}
-
public boolean isFeatureSupported(String feature) {
return false;
}
@@ -489,23 +507,18 @@
}
return null;
}
-
public StaxWatcher remove() {
return null;
}
-
public List getContent() {
- return content;
+ return Collections.unmodifiableList(content);
}
-
public String getId() {
return id;
}
-
public void marshal(XMLStructure parent, XMLCryptoContext context) throws MarshalException {
throw new UnsupportedOperationException();
}
-
public boolean isFeatureSupported(String feature) {
return false;
}