This commit is contained in:
Lana Steuck 2013-07-05 14:37:41 -07:00
commit 18748d45b6
231 changed files with 27141 additions and 23914 deletions

View File

@ -2,82 +2,78 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.algorithms;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* The Algorithm class which stores the Algorithm URI as a string.
*
*/
public abstract class Algorithm extends SignatureElementProxy {
/**
*
* @param doc
* @param algorithmURI is the URI of the algorithm as String
*/
public Algorithm(Document doc, String algorithmURI) {
/**
*
* @param doc
* @param algorithmURI is the URI of the algorithm as String
*/
public Algorithm(Document doc, String algorithmURI) {
super(doc);
super(doc);
this.setAlgorithmURI(algorithmURI);
}
this.setAlgorithmURI(algorithmURI);
}
/**
* Constructor Algorithm
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public Algorithm(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor Algorithm
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public Algorithm(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Method getAlgorithmURI
*
* @return The URI of the algorithm
*/
public String getAlgorithmURI() {
return this.constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
/**
* Method getAlgorithmURI
*
* @return The URI of the alogrithm
*/
public String getAlgorithmURI() {
return this._constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
/**
* Sets the algorithm's URI as used in the signature.
*
* @param algorithmURI is the URI of the algorithm as String
*/
protected void setAlgorithmURI(String algorithmURI) {
if ( (algorithmURI != null)) {
this._constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM,
algorithmURI);
}
}
/**
* Sets the algorithm's URI as used in the signature.
*
* @param algorithmURI is the URI of the algorithm as String
*/
protected void setAlgorithmURI(String algorithmURI) {
if (algorithmURI != null) {
this.constructionElement.setAttributeNS(
null, Constants._ATT_ALGORITHM, algorithmURI
);
}
}
}

View File

@ -114,6 +114,18 @@ public class JCEMapper {
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1,
new Algorithm("", "SHA1withECDSA", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256,
new Algorithm("", "SHA256withECDSA", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384,
new Algorithm("", "SHA384withECDSA", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512,
new Algorithm("", "SHA512withECDSA", "Signature")
);
algorithmsMap.put(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5,
new Algorithm("", "HmacMD5", "Mac")
@ -154,6 +166,18 @@ public class JCEMapper {
XMLCipher.AES_256,
new Algorithm("AES", "AES/CBC/ISO10126Padding", "BlockEncryption", 256)
);
algorithmsMap.put(
XMLCipher.AES_128_GCM,
new Algorithm("AES", "AES/GCM/NoPadding", "BlockEncryption", 128)
);
algorithmsMap.put(
XMLCipher.AES_192_GCM,
new Algorithm("AES", "AES/GCM/NoPadding", "BlockEncryption", 192)
);
algorithmsMap.put(
XMLCipher.AES_256_GCM,
new Algorithm("AES", "AES/GCM/NoPadding", "BlockEncryption", 256)
);
algorithmsMap.put(
XMLCipher.RSA_v1dot5,
new Algorithm("RSA", "RSA/ECB/PKCS1Padding", "KeyTransport")
@ -162,6 +186,10 @@ public class JCEMapper {
XMLCipher.RSA_OAEP,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
);
algorithmsMap.put(
XMLCipher.RSA_OAEP_11,
new Algorithm("RSA", "RSA/ECB/OAEPPadding", "KeyTransport")
);
algorithmsMap.put(
XMLCipher.DIFFIE_HELLMAN,
new Algorithm("", "", "KeyAgreement")

View File

@ -2,265 +2,254 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.algorithms;
import java.security.MessageDigest;
import java.security.NoSuchProviderException;
import java.util.HashMap;
import java.util.Map;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants;
import org.w3c.dom.Document;
/**
* Digest Message wrapper & selector class.
*
* <pre>
* MessageDigestAlgorithm.getInstance()
* </pre>
*
*/
public class MessageDigestAlgorithm extends Algorithm {
/** Message Digest - NOT RECOMMENDED MD5*/
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 = Constants.MoreAlgorithmsSpecNS + "md5";
/** Digest - Required SHA1*/
public static final String ALGO_ID_DIGEST_SHA1 = Constants.SignatureSpecNS + "sha1";
/** Message Digest - RECOMMENDED SHA256*/
public static final String ALGO_ID_DIGEST_SHA256 = EncryptionConstants.EncryptionSpecNS + "sha256";
/** Message Digest - OPTIONAL SHA384*/
public static final String ALGO_ID_DIGEST_SHA384 = Constants.MoreAlgorithmsSpecNS + "sha384";
/** Message Digest - OPTIONAL SHA512*/
public static final String ALGO_ID_DIGEST_SHA512 = EncryptionConstants.EncryptionSpecNS + "sha512";
/** Message Digest - OPTIONAL RIPEMD-160*/
public static final String ALGO_ID_DIGEST_RIPEMD160 = EncryptionConstants.EncryptionSpecNS + "ripemd160";
public static final String ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5 =
Constants.MoreAlgorithmsSpecNS + "md5";
/** Digest - Required SHA1*/
public static final String ALGO_ID_DIGEST_SHA1 = Constants.SignatureSpecNS + "sha1";
/** Message Digest - RECOMMENDED SHA256*/
public static final String ALGO_ID_DIGEST_SHA256 =
EncryptionConstants.EncryptionSpecNS + "sha256";
/** Message Digest - OPTIONAL SHA384*/
public static final String ALGO_ID_DIGEST_SHA384 =
Constants.MoreAlgorithmsSpecNS + "sha384";
/** Message Digest - OPTIONAL SHA512*/
public static final String ALGO_ID_DIGEST_SHA512 =
EncryptionConstants.EncryptionSpecNS + "sha512";
/** Message Digest - OPTIONAL RIPEMD-160*/
public static final String ALGO_ID_DIGEST_RIPEMD160 =
EncryptionConstants.EncryptionSpecNS + "ripemd160";
/** Field algorithm stores the actual {@link java.security.MessageDigest} */
java.security.MessageDigest algorithm = null;
/** Field algorithm stores the actual {@link java.security.MessageDigest} */
private final MessageDigest algorithm;
/**
* Constructor for the brave who pass their own message digest algorithms and the corresponding URI.
* @param doc
* @param messageDigest
* @param algorithmURI
*/
private MessageDigestAlgorithm(Document doc, MessageDigest messageDigest,
String algorithmURI) {
/**
* Constructor for the brave who pass their own message digest algorithms and the
* corresponding URI.
* @param doc
* @param algorithmURI
*/
private MessageDigestAlgorithm(Document doc, String algorithmURI)
throws XMLSignatureException {
super(doc, algorithmURI);
super(doc, algorithmURI);
algorithm = getDigestInstance(algorithmURI);
}
this.algorithm = messageDigest;
}
/**
* Factory method for constructing a message digest algorithm by name.
*
* @param doc
* @param algorithmURI
* @return The MessageDigestAlgorithm element to attach in document and to digest
* @throws XMLSignatureException
*/
public static MessageDigestAlgorithm getInstance(
Document doc, String algorithmURI
) throws XMLSignatureException {
return new MessageDigestAlgorithm(doc, algorithmURI);
}
static ThreadLocal<Map<String, MessageDigest>> instances=new
ThreadLocal<Map<String, MessageDigest>>() {
protected Map<String, MessageDigest> initialValue() {
return new HashMap<String, MessageDigest>();
};
};
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
/**
* Factory method for constructing a message digest algorithm by name.
*
* @param doc
* @param algorithmURI
* @return The MessageDigestAlgorithm element to attach in document and to digest
* @throws XMLSignatureException
*/
public static MessageDigestAlgorithm getInstance(
Document doc, String algorithmURI) throws XMLSignatureException {
MessageDigest md = getDigestInstance(algorithmURI);
return new MessageDigestAlgorithm(doc, md, algorithmURI);
}
private static MessageDigest getDigestInstance(String algorithmURI) throws XMLSignatureException {
MessageDigest result= instances.get().get(algorithmURI);
if (result!=null)
return result;
String algorithmID = JCEMapper.translateURItoJCEID(algorithmURI);
if (algorithmID == null) {
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
}
MessageDigest md;
String provider=JCEMapper.getProviderId();
try {
if (provider==null) {
md = MessageDigest.getInstance(algorithmID);
} else {
md = MessageDigest.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
if (algorithmID == null) {
Object[] exArgs = { algorithmURI };
throw new XMLSignatureException("algorithms.NoSuchMap", exArgs);
}
instances.get().put(algorithmURI, md);
MessageDigest md;
String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
md = MessageDigest.getInstance(algorithmID);
} else {
md = MessageDigest.getInstance(algorithmID, provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
}
return md;
}
/**
* Returns the actual {@link java.security.MessageDigest} algorithm object
*
* @return the actual {@link java.security.MessageDigest} algorithm object
*/
public java.security.MessageDigest getAlgorithm() {
return this.algorithm;
}
/**
* Proxy method for {@link java.security.MessageDigest#isEqual}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param digesta
* @param digestb
* @return the result of the {@link java.security.MessageDigest#isEqual} method
*/
public static boolean isEqual(byte[] digesta, byte[] digestb) {
return java.security.MessageDigest.isEqual(digesta, digestb);
}
/**
* Proxy method for {@link java.security.MessageDigest#digest()}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#digest()} method
*/
public byte[] digest() {
return this.algorithm.digest();
}
/**
* Proxy method for {@link java.security.MessageDigest#digest(byte[])}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
* @return the result of the {@link java.security.MessageDigest#digest(byte[])} method
*/
public byte[] digest(byte input[]) {
return this.algorithm.digest(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#digest(byte[], int, int)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param buf
* @param offset
* @param len
* @return the result of the {@link java.security.MessageDigest#digest(byte[], int, int)} method
* @throws java.security.DigestException
*/
public int digest(byte buf[], int offset, int len)
throws java.security.DigestException {
return this.algorithm.digest(buf, offset, len);
}
/**
* Proxy method for {@link java.security.MessageDigest#getAlgorithm}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getAlgorithm} method
*/
public String getJCEAlgorithmString() {
return this.algorithm.getAlgorithm();
}
/**
* Proxy method for {@link java.security.MessageDigest#getProvider}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getProvider} method
*/
public java.security.Provider getJCEProvider() {
return this.algorithm.getProvider();
}
/**
* Proxy method for {@link java.security.MessageDigest#getDigestLength}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getDigestLength} method
*/
public int getDigestLength() {
return this.algorithm.getDigestLength();
}
/**
* Proxy method for {@link java.security.MessageDigest#reset}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
*/
public void reset() {
this.algorithm.reset();
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte[])}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
*/
public void update(byte[] input) {
this.algorithm.update(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
*/
public void update(byte input) {
this.algorithm.update(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte[], int, int)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param buf
* @param offset
* @param len
*/
public void update(byte buf[], int offset, int len) {
this.algorithm.update(buf, offset, len);
}
/** @inheritDoc */
public String getBaseNamespace() {
return Constants.SignatureSpecNS;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DIGESTMETHOD;
}
}
/**
* Returns the actual {@link java.security.MessageDigest} algorithm object
*
* @return the actual {@link java.security.MessageDigest} algorithm object
*/
public java.security.MessageDigest getAlgorithm() {
return algorithm;
}
/**
* Proxy method for {@link java.security.MessageDigest#isEqual}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param digesta
* @param digestb
* @return the result of the {@link java.security.MessageDigest#isEqual} method
*/
public static boolean isEqual(byte[] digesta, byte[] digestb) {
return java.security.MessageDigest.isEqual(digesta, digestb);
}
/**
* Proxy method for {@link java.security.MessageDigest#digest()}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#digest()} method
*/
public byte[] digest() {
return algorithm.digest();
}
/**
* Proxy method for {@link java.security.MessageDigest#digest(byte[])}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
* @return the result of the {@link java.security.MessageDigest#digest(byte[])} method
*/
public byte[] digest(byte input[]) {
return algorithm.digest(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#digest(byte[], int, int)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param buf
* @param offset
* @param len
* @return the result of the {@link java.security.MessageDigest#digest(byte[], int, int)} method
* @throws java.security.DigestException
*/
public int digest(byte buf[], int offset, int len) throws java.security.DigestException {
return algorithm.digest(buf, offset, len);
}
/**
* Proxy method for {@link java.security.MessageDigest#getAlgorithm}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getAlgorithm} method
*/
public String getJCEAlgorithmString() {
return algorithm.getAlgorithm();
}
/**
* Proxy method for {@link java.security.MessageDigest#getProvider}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getProvider} method
*/
public java.security.Provider getJCEProvider() {
return algorithm.getProvider();
}
/**
* Proxy method for {@link java.security.MessageDigest#getDigestLength}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @return the result of the {@link java.security.MessageDigest#getDigestLength} method
*/
public int getDigestLength() {
return algorithm.getDigestLength();
}
/**
* Proxy method for {@link java.security.MessageDigest#reset}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
*/
public void reset() {
algorithm.reset();
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte[])}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
*/
public void update(byte[] input) {
algorithm.update(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param input
*/
public void update(byte input) {
algorithm.update(input);
}
/**
* Proxy method for {@link java.security.MessageDigest#update(byte[], int, int)}
* which is executed on the internal {@link java.security.MessageDigest} object.
*
* @param buf
* @param offset
* @param len
*/
public void update(byte buf[], int offset, int len) {
algorithm.update(buf, offset, len);
}
/** @inheritDoc */
public String getBaseNamespace() {
return Constants.SignatureSpecNS;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DIGESTMETHOD;
}
}

View File

@ -74,7 +74,7 @@ public class SignatureAlgorithm extends Algorithm {
this.algorithmURI = algorithmURI;
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
}
/**
@ -92,10 +92,10 @@ public class SignatureAlgorithm extends Algorithm {
this.algorithmURI = algorithmURI;
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
signatureAlgorithm.engineSetHMACOutputLength(hmacOutputLength);
((IntegrityHmac)signatureAlgorithm).engineAddContextToElement(_constructionElement);
((IntegrityHmac)signatureAlgorithm).engineAddContextToElement(constructionElement);
}
/**
@ -136,7 +136,7 @@ public class SignatureAlgorithm extends Algorithm {
}
signatureAlgorithm = getSignatureAlgorithmSpi(algorithmURI);
signatureAlgorithm.engineGetContextFromElement(this._constructionElement);
signatureAlgorithm.engineGetContextFromElement(this.constructionElement);
}
/**
@ -310,7 +310,7 @@ public class SignatureAlgorithm extends Algorithm {
* @return the URI representation of Transformation algorithm
*/
public final String getURI() {
return _constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
return constructionElement.getAttributeNS(null, Constants._ATT_ALGORITHM);
}
/**
@ -380,9 +380,7 @@ public class SignatureAlgorithm extends Algorithm {
* This method registers the default algorithms.
*/
public static void registerDefaultAlgorithms() {
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_DSA, SignatureDSA.class
);
algorithmHash.put(SignatureDSA.URI, SignatureDSA.class);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1, SignatureBaseRSA.SignatureRSASHA1.class
);
@ -409,6 +407,15 @@ public class SignatureAlgorithm extends Algorithm {
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1, SignatureECDSA.SignatureECDSASHA1.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256, SignatureECDSA.SignatureECDSASHA256.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384, SignatureECDSA.SignatureECDSASHA384.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512, SignatureECDSA.SignatureECDSASHA512.class
);
algorithmHash.put(
XMLSignature.ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5, IntegrityHmac.IntegrityHmacMD5.class
);

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.algorithms;
@ -27,157 +29,149 @@ import java.security.spec.AlgorithmParameterSpec;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureAlgorithmSpi {
/**
* Returns the URI representation of <code>Transformation algorithm</code>
*
* @return the URI representation of <code>Transformation algorithm</code>
*/
protected abstract String engineGetURI();
/**
* Returns the URI representation of <code>Transformation algorithm</code>
*
* @return the URI representation of <code>Transformation algorithm</code>
*/
protected abstract String engineGetURI();
/**
* Proxy method for {@link java.security.Signature#getAlgorithm}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#getAlgorithm} method
*/
protected abstract String engineGetJCEAlgorithmString();
/**
* Proxy method for {@link java.security.Signature#getAlgorithm}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#getAlgorithm} method
*/
protected abstract String engineGetJCEAlgorithmString();
/**
* Method engineGetJCEProviderName
*
* @return the JCE ProviderName
*/
protected abstract String engineGetJCEProviderName();
/**
* Method engineGetJCEProviderName
*
* @return the JCE ProviderName
*/
protected abstract String engineGetJCEProviderName();
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param input
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte[] input)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param input
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte[] input) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param input
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte input)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param input
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte input) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[], int, int)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param buf
* @param offset
* @param len
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#update(byte[], int, int)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param buf
* @param offset
* @param len
* @throws XMLSignatureException
*/
protected abstract void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signingKey
* @throws XMLSignatureException if this method is called on a MAC
*/
protected abstract void engineInitSign(Key signingKey)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signingKey
* @throws XMLSignatureException if this method is called on a MAC
*/
protected abstract void engineInitSign(Key signingKey) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey, java.security.SecureRandom)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signingKey
* @param secureRandom
* @throws XMLSignatureException if this method is called on a MAC
*/
protected abstract void engineInitSign(
Key signingKey, SecureRandom secureRandom) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#initSign(java.security.PrivateKey,
* java.security.SecureRandom)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signingKey
* @param secureRandom
* @throws XMLSignatureException if this method is called on a MAC
*/
protected abstract void engineInitSign(Key signingKey, SecureRandom secureRandom)
throws XMLSignatureException;
/**
* Proxy method for {@link javax.crypto.Mac}
* which is executed on the internal {@link javax.crypto.Mac#init(Key)} object.
*
* @param signingKey
* @param algorithmParameterSpec
* @throws XMLSignatureException if this method is called on a Signature
*/
protected abstract void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException;
/**
* Proxy method for {@link javax.crypto.Mac}
* which is executed on the internal {@link javax.crypto.Mac#init(Key)} object.
*
* @param signingKey
* @param algorithmParameterSpec
* @throws XMLSignatureException if this method is called on a Signature
*/
protected abstract void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#sign()}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#sign()} method
* @throws XMLSignatureException
*/
protected abstract byte[] engineSign() throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#sign()}
* which is executed on the internal {@link java.security.Signature} object.
*
* @return the result of the {@link java.security.Signature#sign()} method
* @throws XMLSignatureException
*/
protected abstract byte[] engineSign() throws XMLSignatureException;
/**
* Method engineInitVerify
*
* @param verificationKey
* @throws XMLSignatureException
*/
protected abstract void engineInitVerify(Key verificationKey)
throws XMLSignatureException;
/**
* Method engineInitVerify
*
* @param verificationKey
* @throws XMLSignatureException
*/
protected abstract void engineInitVerify(Key verificationKey) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#verify(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signature
* @return true if the signature is correct
* @throws XMLSignatureException
*/
protected abstract boolean engineVerify(byte[] signature)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#verify(byte[])}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param signature
* @return true if the signature is correct
* @throws XMLSignatureException
*/
protected abstract boolean engineVerify(byte[] signature) throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#setParameter(java.security.spec.AlgorithmParameterSpec)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param params
* @throws XMLSignatureException
*/
protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException;
/**
* Proxy method for {@link java.security.Signature#setParameter(
* java.security.spec.AlgorithmParameterSpec)}
* which is executed on the internal {@link java.security.Signature} object.
*
* @param params
* @throws XMLSignatureException
*/
protected abstract void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException;
/**
* Method engineGetContextFromElement
*
* @param element
*/
protected void engineGetContextFromElement(Element element) {
}
/**
* Method engineGetContextFromElement
*
* @param element
*/
protected void engineGetContextFromElement(Element element) {
}
/**
* Method engineSetHMACOutputLength
*
* @param HMACOutputLength
* @throws XMLSignatureException
*/
protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException;
/**
* Method engineSetHMACOutputLength
*
* @param HMACOutputLength
* @throws XMLSignatureException
*/
protected abstract void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException;
public void reset() {
}
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2007 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.algorithms.implementations;
@ -36,22 +38,17 @@ import com.sun.org.apache.xml.internal.security.algorithms.SignatureAlgorithmSpi
import com.sun.org.apache.xml.internal.security.signature.XMLSignature;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
/**
*
* @author $Author: mullan $
*/
public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger
(SignatureBaseRSA.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureBaseRSA.class.getName());
/** @inheritDoc */
public abstract String engineGetURI();
/** Field algorithm */
private java.security.Signature _signatureAlgorithm = null;
private java.security.Signature signatureAlgorithm = null;
/**
* Constructor SignatureRSA
@ -59,17 +56,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException
*/
public SignatureBaseRSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Created SignatureRSA using " + algorithmID);
String provider=JCEMapper.getProviderId();
}
String provider = JCEMapper.getProviderId();
try {
if (provider==null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
if (provider == null) {
this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
this.signatureAlgorithm = Signature.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
@ -85,20 +82,17 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
try {
this._signatureAlgorithm.setParameter(params);
this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
try {
return this._signatureAlgorithm.verify(signature);
return this.signatureAlgorithm.verify(signature);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -106,32 +100,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey);
this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
Signature sig = this.signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
@ -140,7 +131,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException {
try {
return this._signatureAlgorithm.sign();
return this.signatureAlgorithm.sign();
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -149,19 +140,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign
((PrivateKey) privateKey, secureRandom);
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -169,18 +157,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey);
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -189,7 +175,7 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -198,17 +184,16 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException {
protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(buf, offset, len);
this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -216,34 +201,29 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/** @inheritDoc */
protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm();
return this.signatureAlgorithm.getAlgorithm();
}
/** @inheritDoc */
protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName();
return this.signatureAlgorithm.getProvider().getName();
}
/** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException
("algorithms.HMACOutputLengthOnlyForHMAC");
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/** @inheritDoc */
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.CannotUseAlgorithmParameterSpecOnRSA");
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnRSA");
}
/**
* Class SignatureRSASHA1
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA1 extends SignatureBaseRSA {
@ -264,9 +244,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSASHA256
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA256 extends SignatureBaseRSA {
@ -287,9 +264,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSASHA384
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA384 extends SignatureBaseRSA {
@ -310,9 +284,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSASHA512
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSASHA512 extends SignatureBaseRSA {
@ -333,9 +304,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSARIPEMD160
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSARIPEMD160 extends SignatureBaseRSA {
@ -356,9 +324,6 @@ public abstract class SignatureBaseRSA extends SignatureAlgorithmSpi {
/**
* Class SignatureRSAMD5
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public static class SignatureRSAMD5 extends SignatureBaseRSA {

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.algorithms.implementations;
@ -37,21 +39,17 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Base64;
import com.sun.org.apache.xml.internal.security.utils.Constants;
/**
*
* @author $Author: mullan $
*/
public class SignatureDSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureDSA.class.getName());
/** Field _URI */
public static final String _URI = Constants.SignatureSpecNS + "dsa-sha1";
/** Field URI */
public static final String URI = Constants.SignatureSpecNS + "dsa-sha1";
/** Field algorithm */
private java.security.Signature _signatureAlgorithm = null;
private java.security.Signature signatureAlgorithm = null;
/**
* Method engineGetURI
@ -59,7 +57,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected String engineGetURI() {
return SignatureDSA._URI;
return SignatureDSA.URI;
}
/**
@ -68,17 +66,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException
*/
public SignatureDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA._URI);
if (log.isLoggable(java.util.logging.Level.FINE))
String algorithmID = JCEMapper.translateURItoJCEID(SignatureDSA.URI);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Created SignatureDSA using " + algorithmID);
}
String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm =
this.signatureAlgorithm =
Signature.getInstance(algorithmID, provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
@ -95,9 +93,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
try {
this._signatureAlgorithm.setParameter(params);
this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -107,15 +104,15 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
throws XMLSignatureException {
try {
if (log.isLoggable(java.util.logging.Level.FINE))
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Called DSA.verify() on " + Base64.encode(signature));
}
byte[] jcebytes = SignatureDSA.convertXMLDSIGtoASN1(signature);
return this._signatureAlgorithm.verify(jcebytes);
return this.signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
@ -127,32 +124,29 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey);
this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
Signature sig = this.signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
@ -162,9 +156,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected byte[] engineSign() throws XMLSignatureException {
try {
byte jcebytes[] = this._signatureAlgorithm.sign();
byte jcebytes[] = this.signatureAlgorithm.sign();
return SignatureDSA.convertASN1toXMLDSIG(jcebytes);
} catch (IOException ex) {
@ -178,20 +171,17 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey,
secureRandom);
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -201,18 +191,16 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException
("algorithms.WrongKeyForThisOperation", exArgs);
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey);
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -223,7 +211,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -234,7 +222,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
*/
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(input);
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -243,10 +231,9 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
/**
* @inheritDoc
*/
protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException {
protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
this._signatureAlgorithm.update(buf, offset, len);
this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
@ -258,7 +245,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm();
return this.signatureAlgorithm.getAlgorithm();
}
/**
@ -267,7 +254,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @inheritDoc
*/
protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName();
return this.signatureAlgorithm.getProvider().getName();
}
/**
@ -282,8 +269,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
throws IOException {
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
byte rLength = asn1Bytes[3];
int i;
@ -294,19 +280,18 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
int j;
for (j = sLength;
(j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
(j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
|| (asn1Bytes[2] != 2) || (i > 20)
|| (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
|| (asn1Bytes[2] != 2) || (i > 20)
|| (asn1Bytes[4 + rLength] != 2) || (j > 20)) {
throw new IOException("Invalid ASN.1 format of DSA signature");
}
byte xmldsigBytes[] = new byte[40];
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i,
i);
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 20 - i, i);
System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
40 - j, j);
40 - j, j);
return xmldsigBytes;
}
@ -323,8 +308,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
*/
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
throws IOException {
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
if (xmldsigBytes.length != 40) {
throw new IOException("Invalid XMLDSIG format of DSA signature");
@ -337,7 +321,7 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
int j = i;
if (xmldsigBytes[20 - i] < 0) {
j += 1;
j += 1;
}
int k;
@ -373,10 +357,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @param HMACOutputLength
* @throws XMLSignatureException
*/
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.HMACOutputLengthOnlyForHMAC");
protected void engineSetHMACOutputLength(int HMACOutputLength) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/**
@ -387,9 +369,8 @@ public class SignatureDSA extends SignatureAlgorithmSpi {
* @throws XMLSignatureException
*/
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.CannotUseAlgorithmParameterSpecOnDSA");
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnDSA");
}
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.algorithms.implementations;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
@ -40,345 +40,417 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignature;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Base64;
/**
*
* @author $Author: mullan $
* @author $Author: raul $
* @author Alex Dupre
*/
public abstract class SignatureECDSA extends SignatureAlgorithmSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SignatureECDSA.class.getName());
/** @inheritDoc */
public abstract String engineGetURI();
public abstract String engineGetURI();
/** Field algorithm */
private java.security.Signature _signatureAlgorithm = null;
/** Field algorithm */
private java.security.Signature signatureAlgorithm = null;
/**
* Converts an ASN.1 ECDSA value to a XML Signature ECDSA Value.
*
* The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
* pairs; the XML Signature requires the core BigInteger values.
*
* @param asn1Bytes
* @return the decode bytes
*
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
private static byte[] convertASN1toXMLDSIG(byte asn1Bytes[])
throws IOException {
/**
* Converts an ASN.1 ECDSA value to a XML Signature ECDSA Value.
*
* The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
* pairs; the XML Signature requires the core BigInteger values.
*
* @param asn1Bytes
* @return the decode bytes
*
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
public static byte[] convertASN1toXMLDSIG(byte asn1Bytes[]) throws IOException {
byte rLength = asn1Bytes[3];
int i;
for (i = rLength; (i > 0) && (asn1Bytes[(4 + rLength) - i] == 0); i--);
byte sLength = asn1Bytes[5 + rLength];
int j;
for (j = sLength;
(j > 0) && (asn1Bytes[(6 + rLength + sLength) - j] == 0); j--);
if ((asn1Bytes[0] != 48) || (asn1Bytes[1] != asn1Bytes.length - 2)
|| (asn1Bytes[2] != 2) || (i > 24)
|| (asn1Bytes[4 + rLength] != 2) || (j > 24)) {
throw new IOException("Invalid ASN.1 format of ECDSA signature");
}
byte xmldsigBytes[] = new byte[48];
System.arraycopy(asn1Bytes, (4 + rLength) - i, xmldsigBytes, 24 - i,
i);
System.arraycopy(asn1Bytes, (6 + rLength + sLength) - j, xmldsigBytes,
48 - j, j);
return xmldsigBytes;
}
/**
* Converts a XML Signature ECDSA Value to an ASN.1 DSA value.
*
* The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
* pairs; the XML Signature requires the core BigInteger values.
*
* @param xmldsigBytes
* @return the encoded ASN.1 bytes
*
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
private static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[])
throws IOException {
if (xmldsigBytes.length != 48) {
throw new IOException("Invalid XMLDSIG format of ECDSA signature");
}
int i;
for (i = 24; (i > 0) && (xmldsigBytes[24 - i] == 0); i--);
int j = i;
if (xmldsigBytes[24 - i] < 0) {
j += 1;
}
int k;
for (k = 24; (k > 0) && (xmldsigBytes[48 - k] == 0); k--);
int l = k;
if (xmldsigBytes[48 - k] < 0) {
l += 1;
}
byte asn1Bytes[] = new byte[6 + j + l];
asn1Bytes[0] = 48;
asn1Bytes[1] = (byte) (4 + j + l);
asn1Bytes[2] = 2;
asn1Bytes[3] = (byte) j;
System.arraycopy(xmldsigBytes, 24 - i, asn1Bytes, (4 + j) - i, i);
asn1Bytes[4 + j] = 2;
asn1Bytes[5 + j] = (byte) l;
System.arraycopy(xmldsigBytes, 48 - k, asn1Bytes, (6 + j + l) - k, k);
return asn1Bytes;
}
/**
* Constructor SignatureRSA
*
* @throws XMLSignatureException
*/
public SignatureECDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Created SignatureECDSA using " + algorithmID);
String provider=JCEMapper.getProviderId();
try {
if (provider==null) {
this._signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this._signatureAlgorithm = Signature.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID,
ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
if (asn1Bytes.length < 8 || asn1Bytes[0] != 48) {
throw new IOException("Invalid ASN.1 format of ECDSA signature");
}
int offset;
if (asn1Bytes[1] > 0) {
offset = 2;
} else if (asn1Bytes[1] == (byte) 0x81) {
offset = 3;
} else {
throw new IOException("Invalid ASN.1 format of ECDSA signature");
}
}
/** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
byte rLength = asn1Bytes[offset + 1];
int i;
try {
this._signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
}
for (i = rLength; (i > 0) && (asn1Bytes[(offset + 2 + rLength) - i] == 0); i--);
/** @inheritDoc */
protected boolean engineVerify(byte[] signature)
throws XMLSignatureException {
byte sLength = asn1Bytes[offset + 2 + rLength + 1];
int j;
try {
byte[] jcebytes = SignatureECDSA.convertXMLDSIGtoASN1(signature);
for (j = sLength;
(j > 0) && (asn1Bytes[(offset + 2 + rLength + 2 + sLength) - j] == 0); j--);
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Called ECDSA.verify() on " + Base64.encode(signature));
int rawLen = Math.max(i, j);
return this._signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
}
}
if ((asn1Bytes[offset - 1] & 0xff) != asn1Bytes.length - offset
|| (asn1Bytes[offset - 1] & 0xff) != 2 + rLength + 2 + sLength
|| asn1Bytes[offset] != 2
|| asn1Bytes[offset + 2 + rLength] != 2) {
throw new IOException("Invalid ASN.1 format of ECDSA signature");
}
byte xmldsigBytes[] = new byte[2*rawLen];
/** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
System.arraycopy(asn1Bytes, (offset + 2 + rLength) - i, xmldsigBytes, rawLen - i, i);
System.arraycopy(asn1Bytes, (offset + 2 + rLength + 2 + sLength) - j, xmldsigBytes,
2*rawLen - j, j);
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
return xmldsigBytes;
}
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
exArgs);
}
/**
* Converts a XML Signature ECDSA Value to an ASN.1 DSA value.
*
* The JAVA JCE ECDSA Signature algorithm creates ASN.1 encoded (r,s) value
* pairs; the XML Signature requires the core BigInteger values.
*
* @param xmldsigBytes
* @return the encoded ASN.1 bytes
*
* @throws IOException
* @see <A HREF="http://www.w3.org/TR/xmldsig-core/#dsa-sha1">6.4.1 DSA</A>
* @see <A HREF="ftp://ftp.rfc-editor.org/in-notes/rfc4050.txt">3.3. ECDSA Signatures</A>
*/
public static byte[] convertXMLDSIGtoASN1(byte xmldsigBytes[]) throws IOException {
try {
this._signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
int rawLen = xmldsigBytes.length/2;
int i;
for (i = rawLen; (i > 0) && (xmldsigBytes[rawLen - i] == 0); i--);
int j = i;
if (xmldsigBytes[rawLen - i] < 0) {
j += 1;
}
int k;
for (k = rawLen; (k > 0) && (xmldsigBytes[2*rawLen - k] == 0); k--);
int l = k;
if (xmldsigBytes[2*rawLen - k] < 0) {
l += 1;
}
int len = 2 + j + 2 + l;
if (len > 255) {
throw new IOException("Invalid XMLDSIG format of ECDSA signature");
}
int offset;
byte asn1Bytes[];
if (len < 128) {
asn1Bytes = new byte[2 + 2 + j + 2 + l];
offset = 1;
} else {
asn1Bytes = new byte[3 + 2 + j + 2 + l];
asn1Bytes[1] = (byte) 0x81;
offset = 2;
}
asn1Bytes[0] = 48;
asn1Bytes[offset++] = (byte) len;
asn1Bytes[offset++] = 2;
asn1Bytes[offset++] = (byte) j;
System.arraycopy(xmldsigBytes, rawLen - i, asn1Bytes, (offset + j) - i, i);
offset += j;
asn1Bytes[offset++] = 2;
asn1Bytes[offset++] = (byte) l;
System.arraycopy(xmldsigBytes, 2*rawLen - k, asn1Bytes, (offset + l) - k, k);
return asn1Bytes;
}
/**
* Constructor SignatureRSA
*
* @throws XMLSignatureException
*/
public SignatureECDSA() throws XMLSignatureException {
String algorithmID = JCEMapper.translateURItoJCEID(this.engineGetURI());
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Created SignatureECDSA using " + algorithmID);
}
String provider = JCEMapper.getProviderId();
try {
if (provider == null) {
this.signatureAlgorithm = Signature.getInstance(algorithmID);
} else {
this.signatureAlgorithm = Signature.getInstance(algorithmID,provider);
}
} catch (java.security.NoSuchAlgorithmException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
} catch (NoSuchProviderException ex) {
Object[] exArgs = { algorithmID, ex.getLocalizedMessage() };
throw new XMLSignatureException("algorithms.NoSuchAlgorithm", exArgs);
}
}
/** @inheritDoc */
protected void engineSetParameter(AlgorithmParameterSpec params)
throws XMLSignatureException {
try {
this.signatureAlgorithm.setParameter(params);
} catch (InvalidAlgorithmParameterException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected boolean engineVerify(byte[] signature) throws XMLSignatureException {
try {
byte[] jcebytes = SignatureECDSA.convertXMLDSIGtoASN1(signature);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Called ECDSA.verify() on " + Base64.encode(signature));
}
return this.signatureAlgorithm.verify(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineInitVerify(Key publicKey) throws XMLSignatureException {
if (!(publicKey instanceof PublicKey)) {
String supplied = publicKey.getClass().getName();
String needed = PublicKey.class.getName();
Object exArgs[] = { supplied, needed };
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
try {
this.signatureAlgorithm.initVerify((PublicKey) publicKey);
} catch (InvalidKeyException ex) {
// reinstantiate Signature object to work around bug in JDK
// see: http://bugs.sun.com/view_bug.do?bug_id=4953555
Signature sig = this._signatureAlgorithm;
Signature sig = this.signatureAlgorithm;
try {
this._signatureAlgorithm = Signature.getInstance
(_signatureAlgorithm.getAlgorithm());
this.signatureAlgorithm = Signature.getInstance(signatureAlgorithm.getAlgorithm());
} catch (Exception e) {
// this shouldn't occur, but if it does, restore previous
// Signature
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Exception when reinstantiating Signature:" + e);
}
this._signatureAlgorithm = sig;
this.signatureAlgorithm = sig;
}
throw new XMLSignatureException("empty", ex);
}
}
}
}
/** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException {
/** @inheritDoc */
protected byte[] engineSign() throws XMLSignatureException {
try {
byte jcebytes[] = this.signatureAlgorithm.sign();
try {
byte jcebytes[] = this._signatureAlgorithm.sign();
return SignatureECDSA.convertASN1toXMLDSIG(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
}
}
return SignatureECDSA.convertASN1toXMLDSIG(jcebytes);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
} catch (IOException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
/** @inheritDoc */
protected void engineInitSign(Key privateKey, SecureRandom secureRandom)
throws XMLSignatureException {
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
try {
this.signatureAlgorithm.initSign((PrivateKey) privateKey, secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
}
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
exArgs);
}
/** @inheritDoc */
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey,
secureRandom);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
}
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation", exArgs);
}
/** @inheritDoc */
protected void engineInitSign(Key privateKey) throws XMLSignatureException {
try {
this.signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
}
if (!(privateKey instanceof PrivateKey)) {
String supplied = privateKey.getClass().getName();
String needed = PrivateKey.class.getName();
Object exArgs[] = { supplied, needed };
/** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException {
try {
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
throw new XMLSignatureException("algorithms.WrongKeyForThisOperation",
exArgs);
}
/** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException {
try {
this.signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
try {
this._signatureAlgorithm.initSign((PrivateKey) privateKey);
} catch (InvalidKeyException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len) throws XMLSignatureException {
try {
this.signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineUpdate(byte[] input) throws XMLSignatureException {
/** @inheritDoc */
protected String engineGetJCEAlgorithmString() {
return this.signatureAlgorithm.getAlgorithm();
}
try {
this._signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected String engineGetJCEProviderName() {
return this.signatureAlgorithm.getProvider().getName();
}
/** @inheritDoc */
protected void engineUpdate(byte input) throws XMLSignatureException {
/** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
try {
this._signatureAlgorithm.update(input);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec
) throws XMLSignatureException {
throw new XMLSignatureException("algorithms.CannotUseAlgorithmParameterSpecOnRSA");
}
/** @inheritDoc */
protected void engineUpdate(byte buf[], int offset, int len)
throws XMLSignatureException {
/**
* Class SignatureRSASHA1
*
* @author $Author: marcx $
*/
public static class SignatureECDSASHA1 extends SignatureECDSA {
/**
* Constructor SignatureRSASHA1
*
* @throws XMLSignatureException
*/
public SignatureECDSASHA1() throws XMLSignatureException {
super();
}
try {
this._signatureAlgorithm.update(buf, offset, len);
} catch (SignatureException ex) {
throw new XMLSignatureException("empty", ex);
}
}
/** @inheritDoc */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1;
}
}
/** @inheritDoc */
protected String engineGetJCEAlgorithmString() {
return this._signatureAlgorithm.getAlgorithm();
}
/**
* Class SignatureRSASHA256
*
* @author Alex Dupre
*/
public static class SignatureECDSASHA256 extends SignatureECDSA {
/** @inheritDoc */
protected String engineGetJCEProviderName() {
return this._signatureAlgorithm.getProvider().getName();
}
/**
* Constructor SignatureRSASHA256
*
* @throws XMLSignatureException
*/
public SignatureECDSASHA256() throws XMLSignatureException {
super();
}
/** @inheritDoc */
protected void engineSetHMACOutputLength(int HMACOutputLength)
throws XMLSignatureException {
throw new XMLSignatureException("algorithms.HMACOutputLengthOnlyForHMAC");
}
/** @inheritDoc */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA256;
}
}
/** @inheritDoc */
protected void engineInitSign(
Key signingKey, AlgorithmParameterSpec algorithmParameterSpec)
throws XMLSignatureException {
throw new XMLSignatureException(
"algorithms.CannotUseAlgorithmParameterSpecOnRSA");
}
/**
* Class SignatureRSASHA384
*
* @author Alex Dupre
*/
public static class SignatureECDSASHA384 extends SignatureECDSA {
/**
* Class SignatureRSASHA1
*
* @author $Author: mullan $
* @version $Revision: 1.2 $
*/
public static class SignatureECDSASHA1 extends SignatureECDSA {
/**
* Constructor SignatureRSASHA384
*
* @throws XMLSignatureException
*/
public SignatureECDSASHA384() throws XMLSignatureException {
super();
}
/**
* Constructor SignatureRSASHA1
*
* @throws XMLSignatureException
*/
public SignatureECDSASHA1() throws XMLSignatureException {
super();
}
/** @inheritDoc */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA384;
}
}
/** @inheritDoc */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA1;
}
}
/**
* Class SignatureRSASHA512
*
* @author Alex Dupre
*/
public static class SignatureECDSASHA512 extends SignatureECDSA {
/**
* Constructor SignatureRSASHA512
*
* @throws XMLSignatureException
*/
public SignatureECDSASHA512() throws XMLSignatureException {
super();
}
/** @inheritDoc */
public String engineGetURI() {
return XMLSignature.ALGO_ID_SIGNATURE_ECDSA_SHA512;
}
}
}

View File

@ -2,29 +2,28 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
* Class CanonicalizationException
*
@ -32,57 +31,58 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
*/
public class CanonicalizationException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor CanonicalizationException
*
*/
public CanonicalizationException() {
super();
}
/**
* Constructor CanonicalizationException
*
*/
public CanonicalizationException() {
super();
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
*/
public CanonicalizationException(String _msgID) {
super(_msgID);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
*/
public CanonicalizationException(String msgID) {
super(msgID);
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
* @param exArgs
*/
public CanonicalizationException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
* @param exArgs
*/
public CanonicalizationException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
* @param _originalException
*/
public CanonicalizationException(String _msgID, Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
* @param originalException
*/
public CanonicalizationException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor CanonicalizationException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public CanonicalizationException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
/**
* Constructor CanonicalizationException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public CanonicalizationException(
String msgID, Object exArgs[], Exception originalException
) {
super(msgID, exArgs, originalException);
}
}

View File

@ -39,6 +39,7 @@ import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicaliz
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315ExclWithComments;
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315OmitComments;
import com.sun.org.apache.xml.internal.security.c14n.implementations.Canonicalizer20010315WithComments;
import com.sun.org.apache.xml.internal.security.c14n.implementations.CanonicalizerPhysical;
import com.sun.org.apache.xml.internal.security.exceptions.AlgorithmAlreadyRegisteredException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
@ -91,6 +92,11 @@ public class Canonicalizer {
*/
public static final String ALGO_ID_C14N11_WITH_COMMENTS =
ALGO_ID_C14N11_OMIT_COMMENTS + "#WithComments";
/**
* Non-standard algorithm to serialize the physical representation for XML Encryption
*/
public static final String ALGO_ID_C14N_PHYSICAL =
"http://santuario.apache.org/c14n/physical";
private static Map<String, Class<? extends CanonicalizerSpi>> canonicalizerHash =
new ConcurrentHashMap<String, Class<? extends CanonicalizerSpi>>();
@ -202,6 +208,10 @@ public class Canonicalizer {
Canonicalizer.ALGO_ID_C14N11_WITH_COMMENTS,
Canonicalizer11_WithComments.class
);
canonicalizerHash.put(
Canonicalizer.ALGO_ID_C14N_PHYSICAL,
CanonicalizerPhysical.class
);
}
/**

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n;
import java.io.ByteArrayInputStream;
import java.io.OutputStream;
import java.util.Set;
@ -29,7 +29,6 @@ import java.util.Set;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document;
@ -37,166 +36,134 @@ import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
/**
* Base class which all Caninicalization algorithms extend.
* Base class which all Canonicalization algorithms extend.
*
* $todo$ cange JavaDoc
* @author Christian Geuer-Pollmann
*/
public abstract class CanonicalizerSpi {
/**
* Method canonicalize
*
*
* @param inputBytes
* @return the c14n bytes.
*
*
* @throws CanonicalizationException
* @throws java.io.IOException
* @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.SAXException
*
*/
public byte[] engineCanonicalize(byte[] inputBytes)
throws javax.xml.parsers.ParserConfigurationException,
java.io.IOException, org.xml.sax.SAXException,
CanonicalizationException {
/** Reset the writer after a c14n */
protected boolean reset = false;
java.io.ByteArrayInputStream bais = new ByteArrayInputStream(inputBytes);
InputSource in = new InputSource(bais);
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
/**
* Method canonicalize
*
* @param inputBytes
* @return the c14n bytes.
*
* @throws CanonicalizationException
* @throws java.io.IOException
* @throws javax.xml.parsers.ParserConfigurationException
* @throws org.xml.sax.SAXException
*/
public byte[] engineCanonicalize(byte[] inputBytes)
throws javax.xml.parsers.ParserConfigurationException, java.io.IOException,
org.xml.sax.SAXException, CanonicalizationException {
// needs to validate for ID attribute nomalization
dfactory.setNamespaceAware(true);
java.io.InputStream bais = new ByteArrayInputStream(inputBytes);
InputSource in = new InputSource(bais);
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
DocumentBuilder db = dfactory.newDocumentBuilder();
// needs to validate for ID attribute normalization
dfactory.setNamespaceAware(true);
/*
* for some of the test vectors from the specification,
* there has to be a validatin parser for ID attributes, default
* attribute values, NMTOKENS, etc.
* Unfortunaltely, the test vectors do use different DTDs or
* even no DTD. So Xerces 1.3.1 fires many warnings about using
* ErrorHandlers.
*
* Text from the spec:
*
* The input octet stream MUST contain a well-formed XML document,
* but the input need not be validated. However, the attribute
* value normalization and entity reference resolution MUST be
* performed in accordance with the behaviors of a validating
* XML processor. As well, nodes for default attributes (declared
* in the ATTLIST with an AttValue but not specified) are created
* in each element. Thus, the declarations in the document type
* declaration are used to help create the canonical form, even
* though the document type declaration is not retained in the
* canonical form.
*
*/
DocumentBuilder db = dfactory.newDocumentBuilder();
// ErrorHandler eh = new C14NErrorHandler();
// db.setErrorHandler(eh);
Document document = db.parse(in);
byte result[] = this.engineCanonicalizeSubTree(document);
return result;
}
Document document = db.parse(in);
return this.engineCanonicalizeSubTree(document);
}
/**
* Method engineCanonicalizeXPathNodeSet
*
* @param xpathNodeSet
* @return the c14n bytes
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet)
throws CanonicalizationException {
/**
* Method engineCanonicalizeXPathNodeSet
*
* @param xpathNodeSet
* @return the c14n bytes
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet)
throws CanonicalizationException {
return this.engineCanonicalizeXPathNodeSet(
XMLUtils.convertNodelistToSet(xpathNodeSet)
);
}
return this
.engineCanonicalizeXPathNodeSet(XMLUtils
.convertNodelistToSet(xpathNodeSet));
}
/**
* Method engineCanonicalizeXPathNodeSet
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException {
return this.engineCanonicalizeXPathNodeSet(
XMLUtils.convertNodelistToSet(xpathNodeSet), inclusiveNamespaces
);
}
/**
* Method engineCanonicalizeXPathNodeSet
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeXPathNodeSet(NodeList xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException {
/**
* Returns the URI of this engine.
* @return the URI
*/
public abstract String engineGetURI();
return this
.engineCanonicalizeXPathNodeSet(XMLUtils
.convertNodelistToSet(xpathNodeSet), inclusiveNamespaces);
}
/**
* Returns true if comments are included
* @return true if comments are included
*/
public abstract boolean engineGetIncludeComments();
//J-
/** Returns the URI of this engine.
* @return the URI
*/
public abstract String engineGetURI();
/**
* C14n a nodeset
*
* @param xpathNodeSet
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
throws CanonicalizationException;
/** Returns the URI if include comments
* @return true if include.
*/
public abstract boolean engineGetIncludeComments();
/**
* C14n a nodeset
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeXPathNodeSet(
Set<Node> xpathNodeSet, String inclusiveNamespaces
) throws CanonicalizationException;
/**
* C14n a nodeset
*
* @param xpathNodeSet
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet)
throws CanonicalizationException;
/**
* C14n a node tree.
*
* @param rootNode
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeSubTree(Node rootNode)
throws CanonicalizationException;
/**
* C14n a nodeset
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException;
/**
* C14n a node tree.
*
* @param rootNode
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
throws CanonicalizationException;
/**
* C14n a node tree.
*
* @param rootNode
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeSubTree(Node rootNode)
throws CanonicalizationException;
/**
* Sets the writer where the canonicalization ends. ByteArrayOutputStream if
* none is set.
* @param os
*/
public abstract void setWriter(OutputStream os);
/**
* C14n a node tree.
*
* @param rootNode
* @param inclusiveNamespaces
* @return the c14n bytes
* @throws CanonicalizationException
*/
public abstract byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
throws CanonicalizationException;
/**
* Sets the writter where the cannocalization ends. ByteArrayOutputStream if
* none is setted.
* @param os
*/
public abstract void setWriter(OutputStream os);
/** Reset the writter after a c14n */
protected boolean reset=false;
//J+
}

View File

@ -2,87 +2,82 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
*
* @author Christian Geuer-Pollmann
*/
public class InvalidCanonicalizerException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor InvalidCanonicalizerException
*
*/
public InvalidCanonicalizerException() {
super();
}
/**
* Constructor InvalidCanonicalizerException
*
*/
public InvalidCanonicalizerException() {
super();
}
/**
* Constructor InvalidCanonicalizerException
*
* @param _msgID
*/
public InvalidCanonicalizerException(String _msgID) {
super(_msgID);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param msgID
*/
public InvalidCanonicalizerException(String msgID) {
super(msgID);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param _msgID
* @param exArgs
*/
public InvalidCanonicalizerException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param msgID
* @param exArgs
*/
public InvalidCanonicalizerException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param _msgID
* @param _originalException
*/
public InvalidCanonicalizerException(String _msgID,
Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param msgID
* @param originalException
*/
public InvalidCanonicalizerException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public InvalidCanonicalizerException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
/**
* Constructor InvalidCanonicalizerException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public InvalidCanonicalizerException(
String msgID, Object exArgs[], Exception originalException
) {
super(msgID, exArgs, originalException);
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.helper;
@ -43,10 +45,10 @@ import java.util.Comparator;
*/
public class AttrCompare implements Comparator<Attr>, Serializable {
private final static long serialVersionUID = -7113259629930576230L;
private final static int ATTR0_BEFORE_ATTR1 = -1;
private final static int ATTR1_BEFORE_ATTR0 = 1;
private final static String XMLNS=Constants.NamespaceSpecNS;
private static final long serialVersionUID = -7113259629930576230L;
private static final int ATTR0_BEFORE_ATTR1 = -1;
private static final int ATTR1_BEFORE_ATTR0 = 1;
private static final String XMLNS = Constants.NamespaceSpecNS;
/**
* Compares two attributes based on the C14n specification.
@ -69,12 +71,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
*
*/
public int compare(Attr attr0, Attr attr1) {
String namespaceURI0 = attr0.getNamespaceURI();
String namespaceURI1 = attr1.getNamespaceURI();
boolean isNamespaceAttr0 = XMLNS==namespaceURI0;
boolean isNamespaceAttr1 = XMLNS==namespaceURI1;
boolean isNamespaceAttr0 = XMLNS.equals(namespaceURI0);
boolean isNamespaceAttr1 = XMLNS.equals(namespaceURI1);
if (isNamespaceAttr0) {
if (isNamespaceAttr1) {
@ -82,11 +83,11 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
String localname0 = attr0.getLocalName();
String localname1 = attr1.getLocalName();
if (localname0.equals("xmlns")) {
if ("xmlns".equals(localname0)) {
localname0 = "";
}
if (localname1.equals("xmlns")) {
if ("xmlns".equals(localname1)) {
localname1 = "";
}
@ -94,9 +95,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
}
// attr0 is a namespace, attr1 is not
return ATTR0_BEFORE_ATTR1;
}
if (isNamespaceAttr1) {
} else if (isNamespaceAttr1) {
// attr1 is a namespace, attr0 is not
return ATTR1_BEFORE_ATTR0;
}
@ -109,9 +108,7 @@ public class AttrCompare implements Comparator<Attr>, Serializable {
return name0.compareTo(name1);
}
return ATTR0_BEFORE_ATTR1;
}
if (namespaceURI1 == null) {
} else if (namespaceURI1 == null) {
return ATTR1_BEFORE_ATTR0;
}

View File

@ -2,33 +2,32 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.helper;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
/**
* Temporary swapped static functions from the normalizer Section
*
@ -36,129 +35,121 @@ import org.w3c.dom.NamedNodeMap;
*/
public class C14nHelper {
/**
* Constructor C14nHelper
*
*/
private C14nHelper() {
/**
* Constructor C14nHelper
*
*/
private C14nHelper() {
// don't allow instantiation
}
// don't allow instantiation
}
/**
* Method namespaceIsRelative
*
* @param namespace
* @return true if the given namespace is relative.
*/
public static boolean namespaceIsRelative(Attr namespace) {
return !namespaceIsAbsolute(namespace);
}
/**
* Method namespaceIsRelative
*
* @param namespace
* @return true if the given namespace is relative.
*/
public static boolean namespaceIsRelative(Attr namespace) {
return !namespaceIsAbsolute(namespace);
}
/**
* Method namespaceIsRelative
*
* @param namespaceValue
* @return true if the given namespace is relative.
*/
public static boolean namespaceIsRelative(String namespaceValue) {
return !namespaceIsAbsolute(namespaceValue);
}
/**
* Method namespaceIsRelative
*
* @param namespaceValue
* @return true if the given namespace is relative.
*/
public static boolean namespaceIsRelative(String namespaceValue) {
return !namespaceIsAbsolute(namespaceValue);
}
/**
* Method namespaceIsAbsolute
*
* @param namespace
* @return true if the given namespace is absolute.
*/
public static boolean namespaceIsAbsolute(Attr namespace) {
return namespaceIsAbsolute(namespace.getValue());
}
/**
* Method namespaceIsAbsolute
*
* @param namespace
* @return true if the given namespace is absolute.
*/
public static boolean namespaceIsAbsolute(Attr namespace) {
return namespaceIsAbsolute(namespace.getValue());
}
/**
* Method namespaceIsAbsolute
*
* @param namespaceValue
* @return true if the given namespace is absolute.
*/
public static boolean namespaceIsAbsolute(String namespaceValue) {
// assume empty namespaces are absolute
if (namespaceValue.length() == 0) {
return true;
}
return namespaceValue.indexOf(':') > 0;
}
/**
* Method namespaceIsAbsolute
*
* @param namespaceValue
* @return true if the given namespace is absolute.
*/
public static boolean namespaceIsAbsolute(String namespaceValue) {
/**
* This method throws an exception if the Attribute value contains
* a relative URI.
*
* @param attr
* @throws CanonicalizationException
*/
public static void assertNotRelativeNS(Attr attr) throws CanonicalizationException {
if (attr == null) {
return;
}
// assume empty namespaces are absolute
if (namespaceValue.length() == 0) {
return true;
}
return namespaceValue.indexOf(':')>0;
}
String nodeAttrName = attr.getNodeName();
boolean definesDefaultNS = nodeAttrName.equals("xmlns");
boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");
/**
* This method throws an exception if the Attribute value contains
* a relative URI.
*
* @param attr
* @throws CanonicalizationException
*/
public static void assertNotRelativeNS(Attr attr)
throws CanonicalizationException {
if (attr == null) {
return;
}
String nodeAttrName = attr.getNodeName();
boolean definesDefaultNS = nodeAttrName.equals("xmlns");
boolean definesNonDefaultNS = nodeAttrName.startsWith("xmlns:");
if (definesDefaultNS || definesNonDefaultNS) {
if (namespaceIsRelative(attr)) {
if ((definesDefaultNS || definesNonDefaultNS) && namespaceIsRelative(attr)) {
String parentName = attr.getOwnerElement().getTagName();
String attrValue = attr.getValue();
Object exArgs[] = { parentName, nodeAttrName, attrValue };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
/**
* This method throws a CanonicalizationException if the supplied Document
* is not able to be traversed using a TreeWalker.
*
* @param document
* @throws CanonicalizationException
*/
public static void checkTraversability(Document document)
throws CanonicalizationException {
/**
* This method throws a CanonicalizationException if the supplied Document
* is not able to be traversed using a TreeWalker.
*
* @param document
* @throws CanonicalizationException
*/
public static void checkTraversability(Document document)
throws CanonicalizationException {
if (!document.isSupported("Traversal", "2.0")) {
Object exArgs[] = {document.getImplementation().getClass().getName() };
if (!document.isSupported("Traversal", "2.0")) {
Object exArgs[] = {
document.getImplementation().getClass().getName() };
throw new CanonicalizationException(
"c14n.Canonicalizer.TraversalNotSupported", exArgs
);
}
}
throw new CanonicalizationException(
"c14n.Canonicalizer.TraversalNotSupported", exArgs);
}
}
/**
* This method throws a CanonicalizationException if the supplied Element
* contains any relative namespaces.
*
* @param ctxNode
* @throws CanonicalizationException
* @see C14nHelper#assertNotRelativeNS(Attr)
*/
public static void checkForRelativeNamespace(Element ctxNode)
throws CanonicalizationException {
if (ctxNode != null) {
NamedNodeMap attributes = ctxNode.getAttributes();
/**
* This method throws a CanonicalizationException if the supplied Element
* contains any relative namespaces.
*
* @param ctxNode
* @throws CanonicalizationException
* @see C14nHelper#assertNotRelativeNS(Attr)
*/
public static void checkForRelativeNamespace(Element ctxNode)
throws CanonicalizationException {
if (ctxNode != null) {
NamedNodeMap attributes = ctxNode.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
C14nHelper.assertNotRelativeNS((Attr) attributes.item(i));
}
} else {
throw new CanonicalizationException(
"Called checkForRelativeNamespace() on null");
}
}
for (int i = 0; i < attributes.getLength(); i++) {
C14nHelper.assertNotRelativeNS((Attr) attributes.item(i));
}
} else {
throw new CanonicalizationException("Called checkForRelativeNamespace() on null");
}
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2008 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
@ -25,7 +27,6 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -34,7 +35,6 @@ import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -42,8 +42,6 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import java.util.logging.Logger;
import java.util.logging.Logger;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
import com.sun.org.apache.xml.internal.security.c14n.helper.C14nHelper;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
@ -57,40 +55,46 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
*
* @author Sean Mullan
* @author Raul Benito
* @version $Revision: 1.2 $
*/
public abstract class Canonicalizer11 extends CanonicalizerBase {
boolean firstCall = true;
final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
static final String XMLNS_URI = Constants.NamespaceSpecNS;
static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
static Logger log = Logger.getLogger(Canonicalizer11.class.getName());
private static final String XMLNS_URI = Constants.NamespaceSpecNS;
private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(Canonicalizer11.class.getName());
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
static class XmlAttrStack {
int currentLevel = 0;
int lastlevel = 0;
XmlsStackElement cur;
private boolean firstCall = true;
private static class XmlAttrStack {
static class XmlsStackElement {
int level;
boolean rendered = false;
List<Attr> nodes = new ArrayList<Attr>();
};
int currentLevel = 0;
int lastlevel = 0;
XmlsStackElement cur;
List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
void push(int level) {
currentLevel = level;
if (currentLevel == -1)
if (currentLevel == -1) {
return;
}
cur = null;
while (lastlevel >= currentLevel) {
levels.remove(levels.size() - 1);
if (levels.size() == 0) {
int newSize = levels.size();
if (newSize == 0) {
lastlevel = 0;
return;
}
lastlevel=(levels.get(levels.size()-1)).level;
lastlevel = (levels.get(newSize - 1)).level;
}
}
void addXmlnsAttr(Attr n) {
if (cur == null) {
cur = new XmlsStackElement();
@ -100,22 +104,24 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
}
cur.nodes.add(n);
}
void getXmlnsAttr(Collection<Attr> col) {
int size = levels.size() - 1;
if (cur == null) {
cur = new XmlsStackElement();
cur.level = currentLevel;
lastlevel = currentLevel;
levels.add(cur);
}
int size = levels.size() - 2;
boolean parentRendered = false;
XmlsStackElement e = null;
if (size == -1) {
parentRendered = true;
} else {
e = levels.get(size);
if (e.rendered && e.level+1 == currentLevel)
if (e.rendered && e.level + 1 == currentLevel) {
parentRendered = true;
}
}
if (parentRendered) {
col.addAll(cur.nodes);
@ -126,7 +132,7 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
Map<String, Attr> loa = new HashMap<String, Attr>();
List<Attr> baseAttrs = new ArrayList<Attr>();
boolean successiveOmitted = true;
for (;size>=0;size--) {
for (; size >= 0; size--) {
e = levels.get(size);
if (e.rendered) {
successiveOmitted = false;
@ -134,16 +140,15 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
Iterator<Attr> it = e.nodes.iterator();
while (it.hasNext() && successiveOmitted) {
Attr n = it.next();
if (n.getLocalName().equals("base")) {
if (!e.rendered) {
baseAttrs.add(n);
}
} else if (!loa.containsKey(n.getName()))
if (n.getLocalName().equals("base") && !e.rendered) {
baseAttrs.add(n);
} else if (!loa.containsKey(n.getName())) {
loa.put(n.getName(), n);
}
}
}
if (!baseAttrs.isEmpty()) {
Iterator<Attr> it = cur.nodes.iterator();
Iterator<Attr> it = col.iterator();
String base = null;
Attr baseAttr = null;
while (it.hasNext()) {
@ -164,7 +169,9 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
try {
base = joinURI(n.getValue(), base);
} catch (URISyntaxException ue) {
ue.printStackTrace();
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, ue.getMessage(), ue);
}
}
}
}
@ -178,7 +185,8 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
col.addAll(loa.values());
}
};
XmlAttrStack xmlattrStack = new XmlAttrStack();
private XmlAttrStack xmlattrStack = new XmlAttrStack();
/**
* Constructor Canonicalizer11
@ -189,194 +197,6 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
super(includeComments);
}
/**
* Returns the Attr[]s to be outputted for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well --
* subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param E
* @param ns
* @return the Attr[]s to be outputted
* @throws CanonicalizationException
*/
Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!E.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be outputted
final SortedSet<Attr> result = this.result;
result.clear();
NamedNodeMap attrs = E.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
String NUri = N.getNamespaceURI();
if (XMLNS_URI != NUri) {
// It's not a namespace attr node. Add to the result and
// continue.
result.add(N);
continue;
}
String NName = N.getLocalName();
String NValue = N.getValue();
if (XML.equals(NName)
&& XML_LANG_URI.equals(NValue)) {
// The default mapping for xml must not be output.
continue;
}
Node n = ns.addMappingAndRender(NName, NValue, N);
if (n != null) {
// Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(N)) {
Object exArgs[] = {E.getTagName(), NName, N.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
if (firstCall) {
// It is the first node of the subtree
// Obtain all the namespaces defined in the parents, and added
// to the output.
ns.getUnrenderedNodes(result);
// output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(getSortedSetAsCollection(result));
firstCall = false;
}
return result.iterator();
}
/**
* Returns the Attr[]s to be outputted for the given element.
* <br>
* IMPORTANT: This method expects to work on a modified DOM tree, i.e. a
* DOM which has been prepared using
* {@link com.sun.org.apache.xml.internal.security.utils.XMLUtils#circumventBug2650(
* org.w3c.dom.Document)}.
*
* @param E
* @param ns
* @return the Attr[]s to be outputted
* @throws CanonicalizationException
*/
Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be output
xmlattrStack.push(ns.getLevel());
boolean isRealVisible = isVisibleDO(E, ns.getLevel()) == 1;
NamedNodeMap attrs = null;
int attrsLength = 0;
if (E.hasAttributes()) {
attrs = E.getAttributes();
attrsLength = attrs.getLength();
}
SortedSet<Attr> result = this.result;
result.clear();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr)attrs.item(i);
String NUri = N.getNamespaceURI();
if (XMLNS_URI != NUri) {
// A non namespace definition node.
if (XML_LANG_URI == NUri) {
if (N.getLocalName().equals("id")) {
if (isRealVisible) {
// treat xml:id like any other attribute
// (emit it, but don't inherit it)
result.add(N);
}
} else {
xmlattrStack.addXmlnsAttr(N);
}
} else if (isRealVisible) {
// The node is visible add the attribute to the list of
// output attributes.
result.add(N);
}
// keep working
continue;
}
String NName = N.getLocalName();
String NValue = N.getValue();
if ("xml".equals(NName)
&& XML_LANG_URI.equals(NValue)) {
/* except omit namespace node with local name xml, which defines
* the xml prefix, if its string value is
* http://www.w3.org/XML/1998/namespace.
*/
continue;
}
// add the prefix binding to the ns symb table.
// ns.addInclusiveMapping(NName,NValue,N,isRealVisible);
if (isVisible(N)) {
if (!isRealVisible && ns.removeMappingIfRender(NName)) {
continue;
}
// The xpath select this node output it if needed.
// Node n = ns.addMappingAndRenderXNodeSet
// (NName, NValue, N, isRealVisible);
Node n = ns.addMappingAndRender(NName, NValue, N);
if (n != null) {
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(N)) {
Object exArgs[] =
{ E.getTagName(), NName, N.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
} else {
if (isRealVisible && NName != XMLNS) {
ns.removeMapping(NName);
} else {
ns.addMapping(NName, NValue, N);
}
}
}
if (isRealVisible) {
// The element is visible, handle the xmlns definition
Attr xmlns = E.getAttributeNodeNS(XMLNS_URI, XMLNS);
Node n = null;
if (xmlns == null) {
// No xmlns def just get the already defined.
n = ns.getMapping(XMLNS);
} else if (!isVisible(xmlns)) {
// There is a defn but the xmlns is not selected by the xpath.
// then xmlns=""
n = ns.addMappingAndRender(XMLNS, "", nullNode);
}
// output the xmlns def if needed.
if (n != null) {
result.add((Attr)n);
}
// Float all xml:* attributes of the unselected parent elements to
// this one. addXmlAttributes(E,result);
xmlattrStack.getXmlnsAttr(result);
ns.getUnrenderedNodes(result);
}
return result.iterator();
}
/**
* Always throws a CanonicalizationException because this is inclusive c14n.
*
@ -385,10 +205,10 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
* @return none it always fails
* @throws CanonicalizationException always
*/
public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet,
String inclusiveNamespaces) throws CanonicalizationException {
throw new CanonicalizationException(
"c14n.Canonicalizer.UnsupportedOperation");
public byte[] engineCanonicalizeXPathNodeSet(
Set<Node> xpathNodeSet, String inclusiveNamespaces
) throws CanonicalizationException {
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
/**
@ -399,17 +219,189 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
* @return none it always fails
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode,
String inclusiveNamespaces) throws CanonicalizationException {
throw new CanonicalizationException(
"c14n.Canonicalizer.UnsupportedOperation");
public byte[] engineCanonicalizeSubTree(
Node rootNode, String inclusiveNamespaces
) throws CanonicalizationException {
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
void circumventBugIfNeeded(XMLSignatureInput input)
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well --
* subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
// It's not a namespace attr node. Add to the result and continue.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
// The default mapping for xml must not be output.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
// Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
}
if (firstCall) {
// It is the first node of the subtree
// Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result);
// output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall = false;
}
return result.iterator();
}
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* IMPORTANT: This method expects to work on a modified DOM tree, i.e. a
* DOM which has been prepared using
* {@link com.sun.org.apache.xml.internal.security.utils.XMLUtils#circumventBug2650(
* org.w3c.dom.Document)}.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be output
xmlattrStack.push(ns.getLevel());
boolean isRealVisible = isVisibleDO(element, ns.getLevel()) == 1;
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
//A non namespace definition node.
if (XML_LANG_URI.equals(NUri)) {
if (NName.equals("id")) {
if (isRealVisible) {
// treat xml:id like any other attribute
// (emit it, but don't inherit it)
result.add(attribute);
}
} else {
xmlattrStack.addXmlnsAttr(attribute);
}
} else if (isRealVisible) {
//The node is visible add the attribute to the list of output attributes.
result.add(attribute);
}
} else if (!XML.equals(NName) || !XML_LANG_URI.equals(NValue)) {
/* except omit namespace node with local name xml, which defines
* the xml prefix, if its string value is
* http://www.w3.org/XML/1998/namespace.
*/
// add the prefix binding to the ns symb table.
if (isVisible(attribute)) {
if (isRealVisible || !ns.removeMappingIfRender(NName)) {
// The xpath select this node output it if needed.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
} else {
if (isRealVisible && !XMLNS.equals(NName)) {
ns.removeMapping(NName);
} else {
ns.addMapping(NName, NValue, attribute);
}
}
}
}
}
if (isRealVisible) {
//The element is visible, handle the xmlns definition
Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
Node n = null;
if (xmlns == null) {
//No xmlns def just get the already defined.
n = ns.getMapping(XMLNS);
} else if (!isVisible(xmlns)) {
//There is a definition but the xmlns is not selected by the xpath.
//then xmlns=""
n = ns.addMappingAndRender(XMLNS, "", nullNode);
}
//output the xmlns def if needed.
if (n != null) {
result.add((Attr)n);
}
//Float all xml:* attributes of the unselected parent elements to this one.
xmlattrStack.getXmlnsAttr(result);
ns.getUnrenderedNodes(result);
}
return result.iterator();
}
protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException,
IOException, SAXException {
if (!input.isNeedsToBeExpanded())
if (!input.isNeedsToBeExpanded()) {
return;
}
Document doc = null;
if (input.getSubNode() != null) {
doc = XMLUtils.getOwnerDocument(input.getSubNode());
@ -419,40 +411,47 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
XMLUtils.circumventBug2650(doc);
}
void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes()) {
protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
return;
}
xmlattrStack.push(-1);
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
if (Constants.NamespaceSpecNS != N.getNamespaceURI()) {
// Not a namespace definition, ignore.
if (XML_LANG_URI == N.getNamespaceURI()) {
xmlattrStack.addXmlnsAttr(N);
}
continue;
}
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NValue = attribute.getNodeValue();
String NName = N.getLocalName();
String NValue = N.getNodeValue();
if (XML.equals(NName)
&& Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
continue;
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
ns.addMapping(NName, NValue, attribute);
}
} else if (!"id".equals(NName) && XML_LANG_URI.equals(attribute.getNamespaceURI())) {
xmlattrStack.addXmlnsAttr(attribute);
}
ns.addMapping(NName,NValue,N);
}
if (e.getNamespaceURI() != null) {
String NName = e.getPrefix();
String NValue = e.getNamespaceURI();
String Name;
if (NName == null || NName.equals("")) {
NName = "xmlns";
Name = "xmlns";
} else {
Name = "xmlns:" + NName;
}
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
n.setValue(NValue);
ns.addMapping(NName, NValue, n);
}
}
private static String joinURI(String baseURI, String relativeURI)
throws URISyntaxException {
private static String joinURI(String baseURI, String relativeURI) throws URISyntaxException {
String bscheme = null;
String bauthority = null;
String bpath = "";
String bquery = null;
String bfragment = null; // Is this correct?
// pre-parse the baseURI
if (baseURI != null) {
@ -464,7 +463,6 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
bauthority = base.getAuthority();
bpath = base.getPath();
bquery = base.getQuery();
bfragment = base.getFragment();
}
URI r = new URI(relativeURI);
@ -472,9 +470,8 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
String rauthority = r.getAuthority();
String rpath = r.getPath();
String rquery = r.getQuery();
String rfragment = null;
String tscheme, tauthority, tpath, tquery, tfragment;
String tscheme, tauthority, tpath, tquery;
if (rscheme != null && rscheme.equals(bscheme)) {
rscheme = null;
}
@ -518,13 +515,13 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
}
tscheme = bscheme;
}
tfragment = rfragment;
return new URI(tscheme, tauthority, tpath, tquery, tfragment).toString();
return new URI(tscheme, tauthority, tpath, tquery, null).toString();
}
private static String removeDotSegments(String path) {
log.log(java.util.logging.Level.FINE, "STEP OUTPUT BUFFER\t\tINPUT BUFFER");
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "STEP OUTPUT BUFFER\t\tINPUT BUFFER");
}
// 1. The input buffer is initialized with the now-appended path
// components then replace occurrences of "//" in the input buffer
@ -535,7 +532,7 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
}
// Initialize the output buffer with the empty string.
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
// If the input buffer starts with a root slash "/" then move this
// character to the output buffer.
@ -563,9 +560,9 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
output.append("../");
}
printStep("2A", output.toString(), input);
// 2B. if the input buffer begins with a prefix of "/./" or "/.",
// where "." is a complete path segment, then replace that prefix
// with "/" in the input buffer; otherwise,
// 2B. if the input buffer begins with a prefix of "/./" or "/.",
// where "." is a complete path segment, then replace that prefix
// with "/" in the input buffer; otherwise,
} else if (input.startsWith("/./")) {
input = input.substring(2);
printStep("2B", output.toString(), input);
@ -573,16 +570,16 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
// FIXME: what is complete path segment?
input = input.replaceFirst("/.", "/");
printStep("2B", output.toString(), input);
// 2C. if the input buffer begins with a prefix of "/../" or "/..",
// where ".." is a complete path segment, then replace that prefix
// with "/" in the input buffer and if also the output buffer is
// empty, last segment in the output buffer equals "../" or "..",
// where ".." is a complete path segment, then append ".." or "/.."
// for the latter case respectively to the output buffer else
// remove the last segment and its preceding "/" (if any) from the
// output buffer and if hereby the first character in the output
// buffer was removed and it was not the root slash then delete a
// leading slash from the input buffer; otherwise,
// 2C. if the input buffer begins with a prefix of "/../" or "/..",
// where ".." is a complete path segment, then replace that prefix
// with "/" in the input buffer and if also the output buffer is
// empty, last segment in the output buffer equals "../" or "..",
// where ".." is a complete path segment, then append ".." or "/.."
// for the latter case respectively to the output buffer else
// remove the last segment and its preceding "/" (if any) from the
// output buffer and if hereby the first character in the output
// buffer was removed and it was not the root slash then delete a
// leading slash from the input buffer; otherwise,
} else if (input.startsWith("/../")) {
input = input.substring(3);
if (output.length() == 0) {
@ -594,7 +591,7 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
} else {
int index = output.lastIndexOf("/");
if (index == -1) {
output = new StringBuffer();
output = new StringBuilder();
if (input.charAt(0) == '/') {
input = input.substring(1);
}
@ -615,7 +612,7 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
} else {
int index = output.lastIndexOf("/");
if (index == -1) {
output = new StringBuffer();
output = new StringBuilder();
if (input.charAt(0) == '/') {
input = input.substring(1);
}
@ -624,23 +621,24 @@ public abstract class Canonicalizer11 extends CanonicalizerBase {
}
}
printStep("2C", output.toString(), input);
// 2D. if the input buffer consists only of ".", then remove
// that from the input buffer else if the input buffer consists
// only of ".." and if the output buffer does not contain only
// the root slash "/", then move the ".." to the output buffer
// else delte it.; otherwise,
// 2D. if the input buffer consists only of ".", then remove
// that from the input buffer else if the input buffer consists
// only of ".." and if the output buffer does not contain only
// the root slash "/", then move the ".." to the output buffer
// else delte it.; otherwise,
} else if (input.equals(".")) {
input = "";
printStep("2D", output.toString(), input);
} else if (input.equals("..")) {
if (!output.toString().equals("/"))
if (!output.toString().equals("/")) {
output.append("..");
}
input = "";
printStep("2D", output.toString(), input);
// 2E. move the first path segment (if any) in the input buffer
// to the end of the output buffer, including the initial "/"
// character (if any) and any subsequent characters up to, but not
// including, the next "/" character or the end of the input buffer.
// 2E. move the first path segment (if any) in the input buffer
// to the end of the output buffer, including the initial "/"
// character (if any) and any subsequent characters up to, but not
// including, the next "/" character or the end of the input buffer.
} else {
int end = -1;
int begin = input.indexOf('/');

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2008 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2008 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
@ -47,344 +47,348 @@ import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
* Implements <A HREF="http://www.w3.org/TR/2001/REC-xml-c14n-20010315">Canonical
* XML Version 1.0</A>, a W3C Recommendation from 15 March 2001.
*
* @author Christian Geuer-Pollmann <geuerp@apache.org>
* @version $Revision: 1.5 $
*/
public abstract class Canonicalizer20010315 extends CanonicalizerBase {
boolean firstCall=true;
final SortedSet<Attr> result= new TreeSet<Attr>(COMPARE);
static final String XMLNS_URI=Constants.NamespaceSpecNS;
static final String XML_LANG_URI=Constants.XML_LANG_SPACE_SpecNS;
static class XmlAttrStack {
int currentLevel=0;
int lastlevel=0;
XmlsStackElement cur;
private static final String XMLNS_URI = Constants.NamespaceSpecNS;
private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
private boolean firstCall = true;
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
private static class XmlAttrStack {
static class XmlsStackElement {
int level;
boolean rendered=false;
List<Attr> nodes=new ArrayList<Attr>();
int level;
boolean rendered = false;
List<Attr> nodes = new ArrayList<Attr>();
};
List<XmlsStackElement> levels=new ArrayList<XmlsStackElement>();
int currentLevel = 0;
int lastlevel = 0;
XmlsStackElement cur;
List<XmlsStackElement> levels = new ArrayList<XmlsStackElement>();
void push(int level) {
currentLevel=level;
if (currentLevel==-1)
return;
cur=null;
while (lastlevel>=currentLevel) {
levels.remove(levels.size()-1);
if (levels.size()==0) {
lastlevel=0;
return;
}
lastlevel=(levels.get(levels.size()-1)).level;
currentLevel = level;
if (currentLevel == -1) {
return;
}
cur = null;
while (lastlevel >= currentLevel) {
levels.remove(levels.size() - 1);
int newSize = levels.size();
if (newSize == 0) {
lastlevel = 0;
return;
}
lastlevel = (levels.get(newSize - 1)).level;
}
}
void addXmlnsAttr(Attr n) {
if (cur==null) {
cur=new XmlsStackElement();
cur.level=currentLevel;
levels.add(cur);
lastlevel=currentLevel;
}
cur.nodes.add(n);
if (cur == null) {
cur = new XmlsStackElement();
cur.level = currentLevel;
levels.add(cur);
lastlevel = currentLevel;
}
cur.nodes.add(n);
}
void getXmlnsAttr(Collection<Attr> col) {
int size=levels.size()-1;
if (cur==null) {
cur=new XmlsStackElement();
cur.level=currentLevel;
lastlevel=currentLevel;
levels.add(cur);
int size = levels.size() - 1;
if (cur == null) {
cur = new XmlsStackElement();
cur.level = currentLevel;
lastlevel = currentLevel;
levels.add(cur);
}
boolean parentRendered = false;
XmlsStackElement e = null;
if (size == -1) {
parentRendered = true;
} else {
e = levels.get(size);
if (e.rendered && e.level + 1 == currentLevel) {
parentRendered = true;
}
boolean parentRendered=false;
XmlsStackElement e=null;
if (size==-1) {
parentRendered=true;
} else {
e=levels.get(size);
if (e.rendered && e.level+1==currentLevel)
parentRendered=true;
}
if (parentRendered) {
col.addAll(cur.nodes);
cur.rendered = true;
return;
}
Map<String, Attr> loa = new HashMap<String, Attr>();
for (; size >= 0; size--) {
e = levels.get(size);
Iterator<Attr> it = e.nodes.iterator();
while (it.hasNext()) {
Attr n = it.next();
if (!loa.containsKey(n.getName())) {
loa.put(n.getName(), n);
}
}
if (parentRendered) {
col.addAll(cur.nodes);
cur.rendered=true;
return;
}
}
Map<String,Attr> loa = new HashMap<String,Attr>();
for (;size>=0;size--) {
e=levels.get(size);
Iterator<Attr> it=e.nodes.iterator();
while (it.hasNext()) {
Attr n=it.next();
if (!loa.containsKey(n.getName()))
loa.put(n.getName(),n);
}
//if (e.rendered)
//break;
};
//cur.nodes.clear();
//cur.nodes.addAll(loa.values());
cur.rendered=true;
col.addAll(loa.values());
cur.rendered = true;
col.addAll(loa.values());
}
}
XmlAttrStack xmlattrStack=new XmlAttrStack();
private XmlAttrStack xmlattrStack = new XmlAttrStack();
/**
* Constructor Canonicalizer20010315
*
* @param includeComments
*/
public Canonicalizer20010315(boolean includeComments) {
super(includeComments);
}
/**
* Returns the Attr[]s to be outputted for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param E
* @param ns
* @return the Attr[]s to be outputted
* @throws CanonicalizationException
*/
Iterator<Attr> handleAttributesSubtree(Element E, NameSpaceSymbTable ns )
throws CanonicalizationException {
if (!E.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be outputted
final SortedSet<Attr> result = this.result;
result.clear();
NamedNodeMap attrs = E.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
String NUri =N.getNamespaceURI();
if (XMLNS_URI!=NUri) {
//It's not a namespace attr node. Add to the result and continue.
result.add(N);
continue;
}
String NName=N.getLocalName();
String NValue=N.getValue();
if (XML.equals(NName)
&& XML_LANG_URI.equals(NValue)) {
//The default mapping for xml must not be output.
continue;
}
Node n=ns.addMappingAndRender(NName,NValue,N);
if (n!=null) {
//Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(N)) {
Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
if (firstCall) {
//It is the first node of the subtree
//Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(getSortedSetAsCollection(result));
//output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall=false;
}
return result.iterator();
}
/**
* Returns the Attr[]s to be outputted for the given element.
* <br>
* IMPORTANT: This method expects to work on a modified DOM tree, i.e. a DOM which has
* been prepared using {@link com.sun.org.apache.xml.internal.security.utils.XMLUtils#circumventBug2650(
* org.w3c.dom.Document)}.
*
* @param E
* @param ns
* @return the Attr[]s to be outputted
* @throws CanonicalizationException
*/
Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns ) throws CanonicalizationException {
// result will contain the attrs which have to be outputted
xmlattrStack.push(ns.getLevel());
boolean isRealVisible=isVisibleDO(E,ns.getLevel())==1;
NamedNodeMap attrs = null;
int attrsLength = 0;
if (E.hasAttributes()) {
attrs=E.getAttributes();
attrsLength= attrs.getLength();
* Constructor Canonicalizer20010315
*
* @param includeComments
*/
public Canonicalizer20010315(boolean includeComments) {
super(includeComments);
}
/**
* Always throws a CanonicalizationException because this is inclusive c14n.
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return none it always fails
* @throws CanonicalizationException always
*/
public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException {
SortedSet<Attr> result = this.result;
result.clear();
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
String NUri =N.getNamespaceURI();
/**
* Always throws a CanonicalizationException because this is inclusive c14n.
*
* @param rootNode
* @param inclusiveNamespaces
* @return none it always fails
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
throws CanonicalizationException {
if (XMLNS_URI!=NUri) {
//A non namespace definition node.
if (XML_LANG_URI==NUri) {
xmlattrStack.addXmlnsAttr(N);
} else if (isRealVisible){
//The node is visible add the attribute to the list of output attributes.
result.add(N);
}
//keep working
continue;
}
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
String NName=N.getLocalName();
String NValue=N.getValue();
if ("xml".equals(NName)
&& XML_LANG_URI.equals(NValue)) {
/* except omit namespace node with local name xml, which defines
* the xml prefix, if its string value is http://www.w3.org/XML/1998/namespace.
*/
continue;
}
//add the prefix binding to the ns symb table.
//ns.addInclusiveMapping(NName,NValue,N,isRealVisible);
if (isVisible(N)) {
if (!isRealVisible && ns.removeMappingIfRender(NName)) {
continue;
}
//The xpath select this node output it if needed.
//Node n=ns.addMappingAndRenderXNodeSet(NName,NValue,N,isRealVisible);
Node n=ns.addMappingAndRender(NName,NValue,N);
if (n!=null) {
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(N)) {
Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
} else {
if (isRealVisible && NName!=XMLNS) {
ns.removeMapping(NName);
} else {
ns.addMapping(NName,NValue,N);
}
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes() && !firstCall) {
return null;
}
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
//It's not a namespace attr node. Add to the result and continue.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NValue))) {
//The default mapping for xml must not be output.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
//Render the ns definition
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
}
if (firstCall) {
//It is the first node of the subtree
//Obtain all the namespaces defined in the parents, and added to the output.
ns.getUnrenderedNodes(result);
//output the attributes in the xml namespace.
xmlattrStack.getXmlnsAttr(result);
firstCall = false;
}
return result.iterator();
}
if (isRealVisible) {
//The element is visible, handle the xmlns definition
Attr xmlns = E.getAttributeNodeNS(XMLNS_URI, XMLNS);
Node n=null;
if (xmlns == null) {
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* IMPORTANT: This method expects to work on a modified DOM tree, i.e. a DOM which has
* been prepared using {@link com.sun.org.apache.xml.internal.security.utils.XMLUtils#circumventBug2650(
* org.w3c.dom.Document)}.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be output
xmlattrStack.push(ns.getLevel());
boolean isRealVisible = isVisibleDO(element, ns.getLevel()) == 1;
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NUri = attribute.getNamespaceURI();
String NName = attribute.getLocalName();
String NValue = attribute.getValue();
if (!XMLNS_URI.equals(NUri)) {
//A non namespace definition node.
if (XML_LANG_URI.equals(NUri)) {
xmlattrStack.addXmlnsAttr(attribute);
} else if (isRealVisible) {
//The node is visible add the attribute to the list of output attributes.
result.add(attribute);
}
} else if (!XML.equals(NName) || !XML_LANG_URI.equals(NValue)) {
/* except omit namespace node with local name xml, which defines
* the xml prefix, if its string value is http://www.w3.org/XML/1998/namespace.
*/
//add the prefix binding to the ns symb table.
if (isVisible(attribute)) {
if (isRealVisible || !ns.removeMappingIfRender(NName)) {
//The xpath select this node output it if needed.
Node n = ns.addMappingAndRender(NName, NValue, attribute);
if (n != null) {
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
} else {
if (isRealVisible && !XMLNS.equals(NName)) {
ns.removeMapping(NName);
} else {
ns.addMapping(NName, NValue, attribute);
}
}
}
}
}
if (isRealVisible) {
//The element is visible, handle the xmlns definition
Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
Node n = null;
if (xmlns == null) {
//No xmlns def just get the already defined.
n=ns.getMapping(XMLNS);
} else if ( !isVisible(xmlns)) {
n = ns.getMapping(XMLNS);
} else if (!isVisible(xmlns)) {
//There is a definition but the xmlns is not selected by the xpath.
//then xmlns=""
n=ns.addMappingAndRender(XMLNS,"",nullNode);
n = ns.addMappingAndRender(XMLNS, "", nullNode);
}
//output the xmlns def if needed.
if (n != null) {
result.add((Attr)n);
}
//Float all xml:* attributes of the unselected parent elements to this one.
xmlattrStack.getXmlnsAttr(result);
ns.getUnrenderedNodes(result);
}
//output the xmlns def if needed.
if (n!=null) {
result.add((Attr)n);
}
//Float all xml:* attributes of the unselected parent elements to this one.
//addXmlAttributes(E,result);
xmlattrStack.getXmlnsAttr(result);
ns.getUnrenderedNodes(getSortedSetAsCollection(result));
return result.iterator();
}
return result.iterator();
}
/**
* Always throws a CanonicalizationException because this is inclusive c14n.
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return none it always fails
* @throws CanonicalizationException always
*/
public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException {
protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
if (!input.isNeedsToBeExpanded()) {
return;
}
Document doc = null;
if (input.getSubNode() != null) {
doc = XMLUtils.getOwnerDocument(input.getSubNode());
} else {
doc = XMLUtils.getOwnerDocument(input.getNodeSet());
}
XMLUtils.circumventBug2650(doc);
}
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException(
"c14n.Canonicalizer.UnsupportedOperation");
}
@Override
protected void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes() && e.getNamespaceURI() == null) {
return;
}
xmlattrStack.push(-1);
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NValue = attribute.getNodeValue();
/**
* Always throws a CanonicalizationException because this is inclusive c14n.
*
* @param rootNode
* @param inclusiveNamespaces
* @return none it always fails
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
throws CanonicalizationException {
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException(
"c14n.Canonicalizer.UnsupportedOperation");
}
void circumventBugIfNeeded(XMLSignatureInput input) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
if (!input.isNeedsToBeExpanded())
return;
Document doc = null;
if (input.getSubNode() != null) {
doc=XMLUtils.getOwnerDocument(input.getSubNode());
} else {
doc=XMLUtils.getOwnerDocument(input.getNodeSet());
}
XMLUtils.circumventBug2650(doc);
}
void handleParent(Element e, NameSpaceSymbTable ns) {
if (!e.hasAttributes()) {
return;
}
xmlattrStack.push(-1);
NamedNodeMap attrs = e.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
if (Constants.NamespaceSpecNS!=N.getNamespaceURI()) {
//Not a namespace definition, ignore.
if (XML_LANG_URI==N.getNamespaceURI()) {
xmlattrStack.addXmlnsAttr(N);
}
continue;
}
String NName=N.getLocalName();
String NValue=N.getNodeValue();
if (XML.equals(NName)
&& Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
continue;
}
ns.addMapping(NName,NValue,N);
}
}
if (Constants.NamespaceSpecNS.equals(attribute.getNamespaceURI())) {
if (!XML.equals(NName) || !Constants.XML_LANG_SPACE_SpecNS.equals(NValue)) {
ns.addMapping(NName, NValue, attribute);
}
} else if (XML_LANG_URI.equals(attribute.getNamespaceURI())) {
xmlattrStack.addXmlnsAttr(attribute);
}
}
if (e.getNamespaceURI() != null) {
String NName = e.getPrefix();
String NValue = e.getNamespaceURI();
String Name;
if (NName == null || NName.equals("")) {
NName = "xmlns";
Name = "xmlns";
} else {
Name = "xmlns:" + NName;
}
Attr n = e.getOwnerDocument().createAttributeNS("http://www.w3.org/2000/xmlns/", Name);
n.setValue(NValue);
ns.addMapping(NName, NValue, n);
}
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* 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
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
@ -25,7 +27,6 @@ import java.util.Iterator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
@ -40,6 +41,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
* Implements &quot; <A
* HREF="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/">Exclusive XML
@ -52,301 +54,279 @@ import org.xml.sax.SAXException;
* <i>THIS </i> implementation is a complete rewrite of the algorithm.
*
* @author Christian Geuer-Pollmann <geuerp@apache.org>
* @version $Revision: 1.5 $
* @version $Revision: 1147448 $
* @see <a href="http://www.w3.org/TR/2002/REC-xml-exc-c14n-20020718/ Exclusive#">
* XML Canonicalization, Version 1.0</a>
*/
public abstract class Canonicalizer20010315Excl extends CanonicalizerBase {
private static final String XML_LANG_URI = Constants.XML_LANG_SPACE_SpecNS;
private static final String XMLNS_URI = Constants.NamespaceSpecNS;
/**
* This Set contains the names (Strings like "xmlns" or "xmlns:foo") of
* the inclusive namespaces.
*/
TreeSet<String> _inclusiveNSSet = new TreeSet<String>();
static final String XMLNS_URI=Constants.NamespaceSpecNS;
final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
/**
* Constructor Canonicalizer20010315Excl
*
* @param includeComments
*/
public Canonicalizer20010315Excl(boolean includeComments) {
super(includeComments);
}
private SortedSet<String> inclusiveNSSet;
/**
* Method engineCanonicalizeSubTree
* @inheritDoc
* @param rootNode
*
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode)
throws CanonicalizationException {
return this.engineCanonicalizeSubTree(rootNode, "",null);
}
/**
* Method engineCanonicalizeSubTree
* @inheritDoc
* @param rootNode
* @param inclusiveNamespaces
*
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode,
String inclusiveNamespaces) throws CanonicalizationException {
return this.engineCanonicalizeSubTree(rootNode, inclusiveNamespaces,null);
}
/**
* Method engineCanonicalizeSubTree
* @param rootNode
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
/**
* Constructor Canonicalizer20010315Excl
*
* @param includeComments
*/
public Canonicalizer20010315Excl(boolean includeComments) {
super(includeComments);
}
/**
* Method engineCanonicalizeSubTree
* @inheritDoc
* @param rootNode
*
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode)
throws CanonicalizationException {
return engineCanonicalizeSubTree(rootNode, "", null);
}
/**
* Method engineCanonicalizeSubTree
* @inheritDoc
* @param rootNode
* @param inclusiveNamespaces
*
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(
Node rootNode, String inclusiveNamespaces
) throws CanonicalizationException {
return engineCanonicalizeSubTree(rootNode, inclusiveNamespaces, null);
}
/**
* Method engineCanonicalizeSubTree
* @param rootNode
* @param inclusiveNamespaces
* @param excl A element to exclude from the c14n process.
* @return the rootNode c14n.
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode,
String inclusiveNamespaces,Node excl) throws CanonicalizationException {
this._inclusiveNSSet = getInclusiveNameSpace(inclusiveNamespaces);
return super.engineCanonicalizeSubTree(rootNode,excl);
}
/**
*
* @param rootNode
* @param inclusiveNamespaces
* @return the rootNode c14n.
* @throws CanonicalizationException
*/
@SuppressWarnings("unchecked")
public byte[] engineCanonicalize(XMLSignatureInput rootNode,
String inclusiveNamespaces) throws CanonicalizationException {
this._inclusiveNSSet = getInclusiveNameSpace(inclusiveNamespaces);
return super.engineCanonicalize(rootNode);
}
/**
* Method handleAttributesSubtree
* @inheritDoc
* @param E
* @throws CanonicalizationException
*/
Iterator<Attr> handleAttributesSubtree(Element E,NameSpaceSymbTable ns)
throws CanonicalizationException {
// System.out.println("During the traversal, I encountered " +
// XMLUtils.getXPath(E));
// result will contain the attrs which have to be outputted
SortedSet<Attr> result = this.result;
result.clear();
NamedNodeMap attrs=null;
int attrsLength = 0;
if (E.hasAttributes()) {
attrs = E.getAttributes();
attrsLength = attrs.getLength();
}
//The prefix visibly utilized(in the attribute or in the name) in the element
SortedSet<String> visiblyUtilized = getNSSetClone();
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
if (XMLNS_URI!=N.getNamespaceURI()) {
//Not a namespace definition.
//The Element is output element, add his prefix(if used) to visibyUtilized
String prefix = N.getPrefix();
if ( (prefix != null) && (!prefix.equals(XML) && !prefix.equals(XMLNS)) ) {
visiblyUtilized.add(prefix);
}
//Add to the result.
result.add(N);
continue;
}
String NName=N.getLocalName();
String NNodeValue=N.getNodeValue();
if (ns.addMapping(NName, NNodeValue,N)) {
//New definition check if it is relative.
if (C14nHelper.namespaceIsRelative(NNodeValue)) {
Object exArgs[] = {E.getTagName(), NName,
N.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
String prefix;
if (E.getNamespaceURI() != null) {
prefix = E.getPrefix();
if ((prefix == null) || (prefix.length() == 0)) {
prefix=XMLNS;
}
} else {
prefix=XMLNS;
}
visiblyUtilized.add(prefix);
//This can be optimezed by I don't have time
Iterator<String> it=visiblyUtilized.iterator();
while (it.hasNext()) {
String s=it.next();
Attr key=ns.getMapping(s);
if (key==null) {
continue;
}
result.add(key);
}
return result.iterator();
}
/**
* Method engineCanonicalizeXPathNodeSet
* @inheritDoc
* @param xpathNodeSet
* @param inclusiveNamespaces
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet,
String inclusiveNamespaces) throws CanonicalizationException {
this._inclusiveNSSet = getInclusiveNameSpace(inclusiveNamespaces);
return super.engineCanonicalizeXPathNodeSet(xpathNodeSet);
}
@SuppressWarnings("unchecked")
private TreeSet<String> getInclusiveNameSpace(String inclusiveNameSpaces) {
return (TreeSet<String>)InclusiveNamespaces.prefixStr2Set(inclusiveNameSpaces);
* @return the rootNode c14n.
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(
Node rootNode, String inclusiveNamespaces, Node excl
) throws CanonicalizationException{
inclusiveNSSet = InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
return super.engineCanonicalizeSubTree(rootNode, excl);
}
@SuppressWarnings("unchecked")
private SortedSet<String> getNSSetClone() {
return (SortedSet<String>) this._inclusiveNSSet.clone();
/**
*
* @param rootNode
* @param inclusiveNamespaces
* @return the rootNode c14n.
* @throws CanonicalizationException
*/
public byte[] engineCanonicalize(
XMLSignatureInput rootNode, String inclusiveNamespaces
) throws CanonicalizationException {
inclusiveNSSet = InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
return super.engineCanonicalize(rootNode);
}
/**
/**
* Method engineCanonicalizeXPathNodeSet
* @inheritDoc
* @param E
* @throws CanonicalizationException
*/
final Iterator<Attr> handleAttributes(Element E, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be outputted
SortedSet<Attr> result = this.result;
result.clear();
NamedNodeMap attrs = null;
int attrsLength = 0;
if (E.hasAttributes()) {
attrs = E.getAttributes();
attrsLength = attrs.getLength();
* @param xpathNodeSet
* @param inclusiveNamespaces
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeXPathNodeSet(
Set<Node> xpathNodeSet, String inclusiveNamespaces
) throws CanonicalizationException {
inclusiveNSSet = InclusiveNamespaces.prefixStr2Set(inclusiveNamespaces);
return super.engineCanonicalizeXPathNodeSet(xpathNodeSet);
}
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
// The prefix visibly utilized (in the attribute or in the name) in
// the element
SortedSet<String> visiblyUtilized = new TreeSet<String>();
if (inclusiveNSSet != null && !inclusiveNSSet.isEmpty()) {
visiblyUtilized.addAll(inclusiveNSSet);
}
//The prefix visibly utilized(in the attribute or in the name) in the element
Set<String> visiblyUtilized =null;
//It's the output selected.
boolean isOutputElement=isVisibleDO(E,ns.getLevel())==1;
if (isOutputElement) {
visiblyUtilized = getNSSetClone();
}
for (int i = 0; i < attrsLength; i++) {
Attr N = (Attr) attrs.item(i);
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NNodeValue = attribute.getNodeValue();
if (XMLNS_URI!=N.getNamespaceURI()) {
if ( !isVisible(N) ) {
//The node is not in the nodeset(if there is a nodeset)
continue;
}
//Not a namespace definition.
if (isOutputElement) {
//The Element is output element, add his prefix(if used) to visibyUtilized
String prefix = N.getPrefix();
if ((prefix != null) && (!prefix.equals(XML) && !prefix.equals(XMLNS)) ){
visiblyUtilized.add(prefix);
}
//Add to the result.
result.add(N);
}
continue;
}
String NName=N.getLocalName();
if (isOutputElement && !isVisible(N) && NName!=XMLNS) {
ns.removeMappingIfNotRender(NName);
continue;
}
String NNodeValue=N.getNodeValue();
if (!isOutputElement && isVisible(N) && _inclusiveNSSet.contains(NName) && !ns.removeMappingIfRender(NName)) {
Node n=ns.addMappingAndRender(NName,NNodeValue,N);
if (n!=null) {
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(N)) {
Object exArgs[] = { E.getTagName(), NName, N.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
}
}
}
if (ns.addMapping(NName, NNodeValue,N)) {
//New definiton check if it is relative
if (C14nHelper.namespaceIsRelative(NNodeValue)) {
Object exArgs[] = {E.getTagName(), NName,
N.getNodeValue()};
if (!XMLNS_URI.equals(attribute.getNamespaceURI())) {
// Not a namespace definition.
// The Element is output element, add the prefix (if used) to
// visiblyUtilized
String prefix = attribute.getPrefix();
if (prefix != null && !(prefix.equals(XML) || prefix.equals(XMLNS))) {
visiblyUtilized.add(prefix);
}
// Add to the result.
result.add(attribute);
} else if (!(XML.equals(NName) && XML_LANG_URI.equals(NNodeValue))
&& ns.addMapping(NName, NNodeValue, attribute)
&& C14nHelper.namespaceIsRelative(NNodeValue)) {
// The default mapping for xml must not be output.
// New definition check if it is relative.
Object exArgs[] = {element.getTagName(), NName, attribute.getNodeValue()};
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs);
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
if (isOutputElement) {
//The element is visible, handle the xmlns definition
Attr xmlns = E.getAttributeNodeNS(XMLNS_URI, XMLNS);
if ((xmlns!=null) && (!isVisible(xmlns))) {
//There is a definition but the xmlns is not selected by the xpath.
//then xmlns=""
ns.addMapping(XMLNS,"",nullNode);
}
if (E.getNamespaceURI() != null) {
String prefix = E.getPrefix();
if ((prefix == null) || (prefix.length() == 0)) {
visiblyUtilized.add(XMLNS);
} else {
visiblyUtilized.add( prefix);
}
} else {
visiblyUtilized.add(XMLNS);
}
//This can be optimezed by I don't have time
//visiblyUtilized.addAll(this._inclusiveNSSet);
Iterator<String> it=visiblyUtilized.iterator();
while (it.hasNext()) {
String s=it.next();
Attr key=ns.getMapping(s);
if (key==null) {
continue;
}
result.add(key);
}
}
return result.iterator();
}
void circumventBugIfNeeded(XMLSignatureInput input) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
if (!input.isNeedsToBeExpanded() || _inclusiveNSSet.isEmpty())
return;
Document doc = null;
if (input.getSubNode() != null) {
doc=XMLUtils.getOwnerDocument(input.getSubNode());
} else {
doc=XMLUtils.getOwnerDocument(input.getNodeSet());
}
String prefix = null;
if (element.getNamespaceURI() != null
&& !(element.getPrefix() == null || element.getPrefix().length() == 0)) {
prefix = element.getPrefix();
} else {
prefix = XMLNS;
}
visiblyUtilized.add(prefix);
XMLUtils.circumventBug2650(doc);
}
for (String s : visiblyUtilized) {
Attr key = ns.getMapping(s);
if (key != null) {
result.add(key);
}
}
return result.iterator();
}
/**
* @inheritDoc
* @param element
* @throws CanonicalizationException
*/
@Override
protected final Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
// result will contain the attrs which have to be output
final SortedSet<Attr> result = this.result;
result.clear();
// The prefix visibly utilized (in the attribute or in the name) in
// the element
Set<String> visiblyUtilized = null;
// It's the output selected.
boolean isOutputElement = isVisibleDO(element, ns.getLevel()) == 1;
if (isOutputElement) {
visiblyUtilized = new TreeSet<String>();
if (inclusiveNSSet != null && !inclusiveNSSet.isEmpty()) {
visiblyUtilized.addAll(inclusiveNSSet);
}
}
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
String NName = attribute.getLocalName();
String NNodeValue = attribute.getNodeValue();
if (!XMLNS_URI.equals(attribute.getNamespaceURI())) {
if (isVisible(attribute) && isOutputElement) {
// The Element is output element, add the prefix (if used)
// to visibyUtilized
String prefix = attribute.getPrefix();
if (prefix != null && !(prefix.equals(XML) || prefix.equals(XMLNS))) {
visiblyUtilized.add(prefix);
}
// Add to the result.
result.add(attribute);
}
} else if (isOutputElement && !isVisible(attribute) && !XMLNS.equals(NName)) {
ns.removeMappingIfNotRender(NName);
} else {
if (!isOutputElement && isVisible(attribute)
&& inclusiveNSSet.contains(NName)
&& !ns.removeMappingIfRender(NName)) {
Node n = ns.addMappingAndRender(NName, NNodeValue, attribute);
if (n != null) {
result.add((Attr)n);
if (C14nHelper.namespaceIsRelative(attribute)) {
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
if (ns.addMapping(NName, NNodeValue, attribute)
&& C14nHelper.namespaceIsRelative(NNodeValue)) {
// New definition check if it is relative
Object exArgs[] = { element.getTagName(), NName, attribute.getNodeValue() };
throw new CanonicalizationException(
"c14n.Canonicalizer.RelativeNamespace", exArgs
);
}
}
}
}
if (isOutputElement) {
// The element is visible, handle the xmlns definition
Attr xmlns = element.getAttributeNodeNS(XMLNS_URI, XMLNS);
if (xmlns != null && !isVisible(xmlns)) {
// There is a definition but the xmlns is not selected by the
// xpath. then xmlns=""
ns.addMapping(XMLNS, "", nullNode);
}
String prefix = null;
if (element.getNamespaceURI() != null
&& !(element.getPrefix() == null || element.getPrefix().length() == 0)) {
prefix = element.getPrefix();
} else {
prefix = XMLNS;
}
visiblyUtilized.add(prefix);
for (String s : visiblyUtilized) {
Attr key = ns.getMapping(s);
if (key != null) {
result.add(key);
}
}
}
return result.iterator();
}
protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException,
IOException, SAXException {
if (!input.isNeedsToBeExpanded() || inclusiveNSSet.isEmpty() || inclusiveNSSet.isEmpty()) {
return;
}
Document doc = null;
if (input.getSubNode() != null) {
doc = XMLUtils.getOwnerDocument(input.getSubNode());
} else {
doc = XMLUtils.getOwnerDocument(input.getNodeSet());
}
XMLUtils.circumventBug2650(doc);
}
}

View File

@ -2,48 +2,44 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/**
*
*
*/
public class Canonicalizer20010315ExclOmitComments
extends Canonicalizer20010315Excl {
public class Canonicalizer20010315ExclOmitComments extends Canonicalizer20010315Excl {
/**
*
*/
public Canonicalizer20010315ExclOmitComments() {
super(false);
}
/**
*
*/
public Canonicalizer20010315ExclOmitComments() {
super(false);
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_EXCL_OMIT_COMMENTS;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return false;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return false;
}
}

View File

@ -2,52 +2,48 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/**
* Class Canonicalizer20010315ExclWithComments
*
* @version $Revision: 1.5 $
*/
public class Canonicalizer20010315ExclWithComments
extends Canonicalizer20010315Excl {
public class Canonicalizer20010315ExclWithComments extends Canonicalizer20010315Excl {
/**
* Constructor Canonicalizer20010315ExclWithComments
*
*/
public Canonicalizer20010315ExclWithComments() {
super(true);
}
/**
* Constructor Canonicalizer20010315ExclWithComments
*
*/
public Canonicalizer20010315ExclWithComments() {
super(true);
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_EXCL_WITH_COMMENTS;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return true;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return true;
}
}

View File

@ -2,50 +2,48 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/**
*
* @author Christian Geuer-Pollmann
*/
public class Canonicalizer20010315OmitComments extends Canonicalizer20010315 {
/**
* Constructor Canonicalizer20010315WithXPathOmitComments
*
*/
public Canonicalizer20010315OmitComments() {
super(false);
}
/**
* Constructor Canonicalizer20010315WithXPathOmitComments
*
*/
public Canonicalizer20010315OmitComments() {
super(false);
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_OMIT_COMMENTS;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return false;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return false;
}
}

View File

@ -2,47 +2,47 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
/**
*
* @author Christian Geuer-Pollmann
*/
public class Canonicalizer20010315WithComments extends Canonicalizer20010315 {
/**
* Constructor Canonicalizer20010315WithXPathWithComments
*
*/
public Canonicalizer20010315WithComments() {
super(true);
}
/**
* Constructor Canonicalizer20010315WithXPathWithComments
*/
public Canonicalizer20010315WithComments() {
super(true);
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_WITH_COMMENTS;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return true;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return true;
}
}

View File

@ -0,0 +1,184 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.xml.parsers.ParserConfigurationException;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
import org.w3c.dom.Attr;
import org.w3c.dom.Comment;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.ProcessingInstruction;
import org.xml.sax.SAXException;
/**
* Serializes the physical representation of the subtree. All the attributes
* present in the subtree are emitted. The attributes are sorted within an element,
* with the namespace declarations appearing before the regular attributes.
* This algorithm is not a true canonicalization since equivalent subtrees
* may produce different output. It is therefore unsuitable for digital signatures.
* This same property makes it ideal for XML Encryption Syntax and Processing,
* because the decrypted XML content will share the same physical representation
* as the original XML content that was encrypted.
*/
public class CanonicalizerPhysical extends CanonicalizerBase {
private final SortedSet<Attr> result = new TreeSet<Attr>(COMPARE);
/**
* Constructor Canonicalizer20010315
*/
public CanonicalizerPhysical() {
super(true);
}
/**
* Always throws a CanonicalizationException.
*
* @param xpathNodeSet
* @param inclusiveNamespaces
* @return none it always fails
* @throws CanonicalizationException always
*/
public byte[] engineCanonicalizeXPathNodeSet(Set<Node> xpathNodeSet, String inclusiveNamespaces)
throws CanonicalizationException {
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
/**
* Always throws a CanonicalizationException.
*
* @param rootNode
* @param inclusiveNamespaces
* @return none it always fails
* @throws CanonicalizationException
*/
public byte[] engineCanonicalizeSubTree(Node rootNode, String inclusiveNamespaces)
throws CanonicalizationException {
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
/**
* Returns the Attr[]s to be output for the given element.
* <br>
* The code of this method is a copy of {@link #handleAttributes(Element,
* NameSpaceSymbTable)},
* whereas it takes into account that subtree-c14n is -- well -- subtree-based.
* So if the element in question isRoot of c14n, it's parent is not in the
* node set, as well as all other ancestors.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributesSubtree(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
if (!element.hasAttributes()) {
return null;
}
// result will contain all the attrs declared directly on that element
final SortedSet<Attr> result = this.result;
result.clear();
if (element.hasAttributes()) {
NamedNodeMap attrs = element.getAttributes();
int attrsLength = attrs.getLength();
for (int i = 0; i < attrsLength; i++) {
Attr attribute = (Attr) attrs.item(i);
result.add(attribute);
}
}
return result.iterator();
}
/**
* Returns the Attr[]s to be output for the given element.
*
* @param element
* @param ns
* @return the Attr[]s to be output
* @throws CanonicalizationException
*/
@Override
protected Iterator<Attr> handleAttributes(Element element, NameSpaceSymbTable ns)
throws CanonicalizationException {
/** $todo$ well, should we throw UnsupportedOperationException ? */
throw new CanonicalizationException("c14n.Canonicalizer.UnsupportedOperation");
}
protected void circumventBugIfNeeded(XMLSignatureInput input)
throws CanonicalizationException, ParserConfigurationException, IOException, SAXException {
// nothing to do
}
@Override
protected void handleParent(Element e, NameSpaceSymbTable ns) {
// nothing to do
}
/** @inheritDoc */
public final String engineGetURI() {
return Canonicalizer.ALGO_ID_C14N_PHYSICAL;
}
/** @inheritDoc */
public final boolean engineGetIncludeComments() {
return true;
}
@Override
protected void outputPItoWriter(ProcessingInstruction currentPI,
OutputStream writer, int position) throws IOException {
// Processing Instructions before or after the document element are not treated specially
super.outputPItoWriter(currentPI, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
}
@Override
protected void outputCommentToWriter(Comment currentComment,
OutputStream writer, int position) throws IOException {
// Comments before or after the document element are not treated specially
super.outputCommentToWriter(currentComment, writer, NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT);
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
@ -29,191 +31,185 @@ import java.util.List;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
/**
* A stack based Symble Table.
* A stack based Symbol 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 NameSpaceSymbTable {
/**The map betwen prefix-> entry table. */
SymbMap symb;
/**The level of nameSpaces (for Inclusive visibility).*/
int nameSpaces=0;
/**The stacks for removing the definitions when doing pop.*/
List<SymbMap> level;
boolean cloned=true;
static final String XMLNS="xmlns";
final static SymbMap initialMap=new SymbMap();
static {
NameSpaceSymbEntry ne=new NameSpaceSymbEntry("",null,true,XMLNS);
ne.lastrendered="";
initialMap.put(XMLNS,ne);
}
private static final String XMLNS = "xmlns";
private static final SymbMap initialMap = new SymbMap();
static {
NameSpaceSymbEntry ne = new NameSpaceSymbEntry("", null, true, XMLNS);
ne.lastrendered = "";
initialMap.put(XMLNS, ne);
}
/**The map betwen prefix-> entry table. */
private SymbMap symb;
/**The stacks for removing the definitions when doing pop.*/
private List<SymbMap> level;
private boolean cloned = true;
/**
* Default constractor
**/
public NameSpaceSymbTable() {
level = new ArrayList<SymbMap>(10);
level = new ArrayList<SymbMap>();
//Insert the default binding for xmlns.
symb=(SymbMap) initialMap.clone();
symb = (SymbMap) initialMap.clone();
}
/**
* Get all the unrendered nodes in the name space.
* For Inclusive rendering
* Get all the unrendered nodes in the name space.
* For Inclusive rendering
* @param result the list where to fill the unrendered xmlns definitions.
**/
public void getUnrenderedNodes(Collection<Attr> result) {
//List result=new ArrayList();
Iterator<NameSpaceSymbEntry> it=symb.entrySet().iterator();
while (it.hasNext()) {
NameSpaceSymbEntry n= it.next();
//put them rendered?
if ((!n.rendered) && (n.n!=null)) {
n=(NameSpaceSymbEntry) n.clone();
**/
public void getUnrenderedNodes(Collection<Attr> result) {
Iterator<NameSpaceSymbEntry> it = symb.entrySet().iterator();
while (it.hasNext()) {
NameSpaceSymbEntry n = it.next();
//put them rendered?
if ((!n.rendered) && (n.n != null)) {
n = (NameSpaceSymbEntry) n.clone();
needsClone();
symb.put(n.prefix,n);
n.lastrendered=n.uri;
n.rendered=true;
symb.put(n.prefix, n);
n.lastrendered = n.uri;
n.rendered = true;
result.add(n.n);
}
}
result.add(n.n);
}
}
}
/**
/**
* Push a frame for visible namespace.
* For Inclusive rendering.
**/
public void outputNodePush() {
nameSpaces++;
push();
}
public void outputNodePush() {
push();
}
/**
/**
* Pop a frame for visible namespace.
**/
public void outputNodePop() {
nameSpaces--;
pop();
}
public void outputNodePop() {
pop();
}
/**
/**
* Push a frame for a node.
* Inclusive or Exclusive.
**/
public void push() {
//Put the number of namespace definitions in the stack.
public void push() {
//Put the number of namespace definitions in the stack.
level.add(null);
cloned=false;
}
cloned = false;
}
/**
/**
* Pop a frame.
* Inclusive or Exclusive.
**/
public void pop() {
int size=level.size()-1;
Object ob= level.remove(size);
if (ob!=null) {
symb=(SymbMap)ob;
if (size==0) {
cloned=false;
} else
cloned=(level.get(size-1)!=symb);
public void pop() {
int size = level.size() - 1;
Object ob = level.remove(size);
if (ob != null) {
symb = (SymbMap)ob;
if (size == 0) {
cloned = false;
} else {
cloned = (level.get(size - 1) != symb);
}
} else {
cloned=false;
cloned = false;
}
}
}
final void needsClone() {
if (!cloned) {
level.set(level.size()-1,symb);
symb=(SymbMap) symb.clone();
cloned=true;
final void needsClone() {
if (!cloned) {
level.set(level.size() - 1, symb);
symb = (SymbMap) symb.clone();
cloned = true;
}
}
/**
* Gets the attribute node that defines the binding for the prefix.
/**
* Gets the attribute node that defines the binding for the prefix.
* @param prefix the prefix to obtain the attribute.
* @return null if there is no need to render the prefix. Otherwise the node of
* definition.
**/
public Attr getMapping(String prefix) {
NameSpaceSymbEntry entry=symb.get(prefix);
if (entry==null) {
//There is no definition for the prefix(a bug?).
return null;
}
if (entry.rendered) {
//No need to render an entry already rendered.
return null;
}
// Mark this entry as render.
entry=(NameSpaceSymbEntry) entry.clone();
needsClone();
symb.put(prefix,entry);
entry.rendered=true;
entry.level=nameSpaces;
entry.lastrendered=entry.uri;
// Return the node for outputing.
return entry.n;
public Attr getMapping(String prefix) {
NameSpaceSymbEntry entry = symb.get(prefix);
if (entry == null) {
//There is no definition for the prefix(a bug?).
return null;
}
if (entry.rendered) {
//No need to render an entry already rendered.
return null;
}
// Mark this entry as render.
entry = (NameSpaceSymbEntry) entry.clone();
needsClone();
symb.put(prefix, entry);
entry.rendered = true;
entry.lastrendered = entry.uri;
// Return the node for outputing.
return entry.n;
}
/**
/**
* Gets a definition without mark it as render.
* For render in exclusive c14n the namespaces in the include prefixes.
* @param prefix The prefix whose definition is neaded.
* @return the attr to render, null if there is no need to render
**/
public Attr getMappingWithoutRendered(String prefix) {
NameSpaceSymbEntry entry= symb.get(prefix);
if (entry==null) {
return null;
}
if (entry.rendered) {
return null;
}
return entry.n;
public Attr getMappingWithoutRendered(String prefix) {
NameSpaceSymbEntry entry = symb.get(prefix);
if (entry == null) {
return null;
}
if (entry.rendered) {
return null;
}
return entry.n;
}
/**
/**
* Adds the mapping for a prefix.
* @param prefix the prefix of definition
* @param uri the Uri of the definition
* @param n the attribute that have the definition
* @return true if there is already defined.
**/
public boolean addMapping(String prefix, String uri,Attr n) {
NameSpaceSymbEntry ob = symb.get(prefix);
if ((ob!=null) && uri.equals(ob.uri)) {
//If we have it previously defined. Don't keep working.
return false;
}
//Creates and entry in the table for this new definition.
NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,false,prefix);
needsClone();
symb.put(prefix, ne);
if (ob != null) {
//We have a previous definition store it for the pop.
//Check if a previous definition(not the inmidiatly one) has been rendered.
ne.lastrendered=ob.lastrendered;
if ((ob.lastrendered!=null)&& (ob.lastrendered.equals(uri))) {
//Yes it is. Mark as rendered.
ne.rendered=true;
}
}
return true;
public boolean addMapping(String prefix, String uri, Attr n) {
NameSpaceSymbEntry ob = symb.get(prefix);
if ((ob != null) && uri.equals(ob.uri)) {
//If we have it previously defined. Don't keep working.
return false;
}
//Creates and entry in the table for this new definition.
NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri, n, false, prefix);
needsClone();
symb.put(prefix, ne);
if (ob != null) {
//We have a previous definition store it for the pop.
//Check if a previous definition(not the inmidiatly one) has been rendered.
ne.lastrendered = ob.lastrendered;
if ((ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
//Yes it is. Mark as rendered.
ne.rendered = true;
}
}
return true;
}
/**
* Adds a definition and mark it as render.
@ -223,79 +219,91 @@ public class NameSpaceSymbTable {
* @param n the attribute that have the definition
* @return the attr to render, null if there is no need to render
**/
public Node addMappingAndRender(String prefix, String uri,Attr n) {
public Node addMappingAndRender(String prefix, String uri, Attr n) {
NameSpaceSymbEntry ob = symb.get(prefix);
if ((ob!=null) && uri.equals(ob.uri)) {
if ((ob != null) && uri.equals(ob.uri)) {
if (!ob.rendered) {
ob=(NameSpaceSymbEntry) ob.clone();
ob = (NameSpaceSymbEntry) ob.clone();
needsClone();
symb.put(prefix,ob);
ob.lastrendered=uri;
ob.rendered=true;
symb.put(prefix, ob);
ob.lastrendered = uri;
ob.rendered = true;
return ob.n;
}
return null;
}
NameSpaceSymbEntry ne=new NameSpaceSymbEntry(uri,n,true,prefix);
ne.lastrendered=uri;
NameSpaceSymbEntry ne = new NameSpaceSymbEntry(uri,n,true,prefix);
ne.lastrendered = uri;
needsClone();
symb.put(prefix, ne);
if (ob != null) {
if ((ob.lastrendered!=null)&& (ob.lastrendered.equals(uri))) {
ne.rendered=true;
return null;
}
if ((ob != null) && (ob.lastrendered != null) && (ob.lastrendered.equals(uri))) {
ne.rendered = true;
return null;
}
return ne.n;
}
public int getLevel() {
// TODO Auto-generated method stub
return level.size();
}
public int getLevel() {
return level.size();
}
public void removeMapping(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
public void removeMapping(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
if (ob!=null) {
if (ob != null) {
needsClone();
symb.put(prefix,null);
}
symb.put(prefix, null);
}
}
public void removeMappingIfNotRender(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
public void removeMappingIfNotRender(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
if (ob!=null && !ob.rendered) {
if (ob != null && !ob.rendered) {
needsClone();
symb.put(prefix,null);
}
symb.put(prefix, null);
}
}
public boolean removeMappingIfRender(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
public boolean removeMappingIfRender(String prefix) {
NameSpaceSymbEntry ob = symb.get(prefix);
if (ob!=null && ob.rendered) {
if (ob != null && ob.rendered) {
needsClone();
symb.put(prefix,null);
symb.put(prefix, null);
}
return false;
}
}
}
/**
* The internal structure of NameSpaceSymbTable.
**/
class NameSpaceSymbEntry implements Cloneable {
NameSpaceSymbEntry(String name,Attr n,boolean rendered,String prefix) {
this.uri=name;
this.rendered=rendered;
this.n=n;
this.prefix=prefix;
String prefix;
/**The URI that the prefix defines */
String uri;
/**The last output in the URI for this prefix (This for speed reason).*/
String lastrendered = null;
/**This prefix-URI has been already render or not.*/
boolean rendered = false;
/**The attribute to include.*/
Attr n;
NameSpaceSymbEntry(String name, Attr n, boolean rendered, String prefix) {
this.uri = name;
this.rendered = rendered;
this.n = n;
this.prefix = prefix;
}
/** @inheritDoc */
public Object clone() {
try {
@ -304,46 +312,35 @@ class NameSpaceSymbEntry implements Cloneable {
return null;
}
}
/** The level where the definition was rendered(Only for inclusive) */
int level=0;
String prefix;
/**The URI that the prefix defines */
String uri;
/**The last output in the URI for this prefix (This for speed reason).*/
String lastrendered=null;
/**This prefix-URI has been already render or not.*/
boolean rendered=false;
/**The attribute to include.*/
Attr n;
};
class SymbMap implements Cloneable {
int free=23;
int free = 23;
NameSpaceSymbEntry[] entries;
String[] keys;
SymbMap() {
entries=new NameSpaceSymbEntry[free];
keys=new String[free];
}
SymbMap() {
entries = new NameSpaceSymbEntry[free];
keys = new String[free];
}
void put(String key, NameSpaceSymbEntry value) {
int index = index(key);
Object oldKey = keys[index];
keys[index] = key;
entries[index] = value;
if (oldKey==null || !oldKey.equals(key)) {
if (--free == 0) {
free=entries.length;
int newCapacity = free<<2;
rehash(newCapacity);
}
if ((oldKey == null || !oldKey.equals(key)) && (--free == 0)) {
free = entries.length;
int newCapacity = free << 2;
rehash(newCapacity);
}
}
List<NameSpaceSymbEntry> entrySet() {
List<NameSpaceSymbEntry> a=new ArrayList<NameSpaceSymbEntry>();
for (int i=0;i<entries.length;i++) {
if ((entries[i]!=null) && !("".equals(entries[i].uri))) {
a.add(entries[i]);
List<NameSpaceSymbEntry> a = new ArrayList<NameSpaceSymbEntry>();
for (int i = 0;i < entries.length;i++) {
if ((entries[i] != null) && !("".equals(entries[i].uri))) {
a.add(entries[i]);
}
}
return a;
@ -353,16 +350,16 @@ class SymbMap implements Cloneable {
Object[] set = keys;
int length = set.length;
//abs of index
int index = (obj.hashCode() & 0x7fffffff) % length;
int index = (obj.hashCode() & 0x7fffffff) % length;
Object cur = set[index];
if (cur == null || (cur.equals( obj))) {
return index;
if (cur == null || (cur.equals(obj))) {
return index;
}
length=length-1;
length--;
do {
index=index==length? 0:++index;
cur = set[index];
index = index == length ? 0 : ++index;
cur = set[index];
} while (cur != null && (!cur.equals(obj)));
return index;
}
@ -381,7 +378,7 @@ class SymbMap implements Cloneable {
entries = new NameSpaceSymbEntry[newCapacity];
for (int i = oldCapacity; i-- > 0;) {
if(oldKeys[i] != null) {
if (oldKeys[i] != null) {
String o = oldKeys[i];
int index = index(o);
keys[index] = o;
@ -391,20 +388,19 @@ class SymbMap implements Cloneable {
}
NameSpaceSymbEntry get(String key) {
return entries[index(key)];
return entries[index(key)];
}
protected Object clone() {
try {
SymbMap copy=(SymbMap) super.clone();
copy.entries=new NameSpaceSymbEntry[entries.length];
System.arraycopy(entries,0,copy.entries,0,entries.length);
copy.keys=new String[keys.length];
System.arraycopy(keys,0,copy.keys,0,keys.length);
SymbMap copy = (SymbMap) super.clone();
copy.entries = new NameSpaceSymbEntry[entries.length];
System.arraycopy(entries, 0, copy.entries, 0, entries.length);
copy.keys = new String[keys.length];
System.arraycopy(keys, 0, copy.keys, 0, keys.length);
return copy;
return copy;
} catch (CloneNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;

View File

@ -1,3 +1,25 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.c14n.implementations;
import java.io.IOException;
@ -6,150 +28,153 @@ import java.util.Map;
public class UtfHelpper {
final static void writeByte(final String str,final OutputStream out,Map<String,byte[]> cache) throws IOException {
byte []result= cache.get(str);
if (result==null) {
result=getStringInUtf8(str);
cache.put(str,result);
}
static final void writeByte(
final String str,
final OutputStream out,
Map<String, byte[]> cache
) throws IOException {
byte[] result = cache.get(str);
if (result == null) {
result = getStringInUtf8(str);
cache.put(str, result);
}
out.write(result);
out.write(result);
}
}
final static void writeCharToUtf8(final char c,final OutputStream out) throws IOException{
if (c < 0x80) {
out.write(c);
return;
static final void writeCharToUtf8(final char c, final OutputStream out) throws IOException {
if (c < 0x80) {
out.write(c);
return;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF)) {
//No Surrogates in sun java
out.write(0x3f);
return;
}
int bias;
int write;
char ch;
if (c > 0x07FF) {
ch = (char)(c>>>12);
write = 0xE0;
if (ch > 0) {
write |= (ch & 0x0F);
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF) ){
out.write(write);
write = 0x80;
bias = 0x3F;
} else {
write = 0xC0;
bias = 0x1F;
}
ch = (char)(c>>>6);
if (ch > 0) {
write |= (ch & bias);
}
out.write(write);
out.write(0x80 | ((c) & 0x3F));
}
static final void writeStringToUtf8(
final String str,
final OutputStream out
) throws IOException{
final int length = str.length();
int i = 0;
char c;
while (i < length) {
c = str.charAt(i++);
if (c < 0x80) {
out.write(c);
continue;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF)) {
//No Surrogates in sun java
out.write(0x3f);
return;
}
continue;
}
char ch;
int bias;
int write;
char ch;
if (c > 0x07FF) {
ch=(char)(c>>>12);
write=0xE0;
if (ch>0) {
write |= ( ch & 0x0F);
ch = (char)(c>>>12);
write = 0xE0;
if (ch > 0) {
write |= (ch & 0x0F);
}
out.write(write);
write=0x80;
bias=0x3F;
write = 0x80;
bias = 0x3F;
} else {
write=0xC0;
bias=0x1F;
write = 0xC0;
bias = 0x1F;
}
ch=(char)(c>>>6);
if (ch>0) {
write|= (ch & bias);
ch = (char)(c>>>6);
if (ch > 0) {
write |= (ch & bias);
}
out.write(write);
out.write(0x80 | ((c) & 0x3F));
}
}
final static void writeStringToUtf8(final String str,final OutputStream out) throws IOException{
final int length=str.length();
int i=0;
char c;
while (i<length) {
c=str.charAt(i++);
if (c < 0x80) {
out.write(c);
continue;
}
public static final byte[] getStringInUtf8(final String str) {
final int length = str.length();
boolean expanded = false;
byte[] result = new byte[length];
int i = 0;
int out = 0;
char c;
while (i < length) {
c = str.charAt(i++);
if (c < 0x80) {
result[out++] = (byte)c;
continue;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF)) {
//No Surrogates in sun java
result[out++] = 0x3f;
continue;
}
if (!expanded) {
byte newResult[] = new byte[3*length];
System.arraycopy(result, 0, newResult, 0, out);
result = newResult;
expanded = true;
}
char ch;
int bias;
byte write;
if (c > 0x07FF) {
ch = (char)(c>>>12);
write = (byte)0xE0;
if (ch > 0) {
write |= (ch & 0x0F);
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF) ){
//No Surrogates in sun java
out.write(0x3f);
continue;
}
char ch;
int bias;
int write;
if (c > 0x07FF) {
ch=(char)(c>>>12);
write=0xE0;
if (ch>0) {
write |= ( ch & 0x0F);
}
out.write(write);
write=0x80;
bias=0x3F;
} else {
write=0xC0;
bias=0x1F;
}
ch=(char)(c>>>6);
if (ch>0) {
write|= (ch & bias);
}
out.write(write);
out.write(0x80 | ((c) & 0x3F));
}
}
public final static byte[] getStringInUtf8(final String str) {
final int length=str.length();
boolean expanded=false;
byte []result=new byte[length];
int i=0;
int out=0;
char c;
while (i<length) {
c=str.charAt(i++);
if ( c < 0x80 ) {
result[out++]=(byte)c;
continue;
}
if ((c >= 0xD800 && c <= 0xDBFF) || (c >= 0xDC00 && c <= 0xDFFF) ){
//No Surrogates in sun java
result[out++]=0x3f;
continue;
}
if (!expanded) {
byte newResult[]=new byte[3*length];
System.arraycopy(result, 0, newResult, 0, out);
result=newResult;
expanded=true;
}
char ch;
int bias;
byte write;
if (c > 0x07FF) {
ch=(char)(c>>>12);
write=(byte)0xE0;
if (ch>0) {
write |= ( ch & 0x0F);
}
result[out++]=write;
write=(byte)0x80;
bias=0x3F;
} else {
write=(byte)0xC0;
bias=0x1F;
}
ch=(char)(c>>>6);
if (ch>0) {
write|= (ch & bias);
}
result[out++]=write;
result[out++]=(byte)(0x80 | ((c) & 0x3F));/**/
}
if (expanded) {
byte newResult[]=new byte[out];
System.arraycopy(result, 0, newResult, 0, out);
result=newResult;
}
return result;
}
result[out++] = write;
write = (byte)0x80;
bias = 0x3F;
} else {
write = (byte)0xC0;
bias = 0x1F;
}
ch = (char)(c>>>6);
if (ch > 0) {
write |= (ch & bias);
}
result[out++] = write;
result[out++] = (byte)(0x80 | ((c) & 0x3F));
}
if (expanded) {
byte newResult[] = new byte[out];
System.arraycopy(result, 0, newResult, 0, out);
result = newResult;
}
return result;
}
}

View File

@ -0,0 +1,249 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Converts <code>String</code>s into <code>Node</code>s and visa versa.
*
* An abstract class for common Serializer functionality
*/
public abstract class AbstractSerializer implements Serializer {
protected Canonicalizer canon;
public void setCanonicalizer(Canonicalizer canon) {
this.canon = canon;
}
/**
* Returns a <code>String</code> representation of the specified
* <code>Element</code>.
* <p/>
* Refer also to comments about setup of format.
*
* @param element the <code>Element</code> to serialize.
* @return the <code>String</code> representation of the serilaized
* <code>Element</code>.
* @throws Exception
*/
public String serialize(Element element) throws Exception {
return canonSerialize(element);
}
/**
* Returns a <code>byte[]</code> representation of the specified
* <code>Element</code>.
*
* @param element the <code>Element</code> to serialize.
* @return the <code>byte[]</code> representation of the serilaized
* <code>Element</code>.
* @throws Exception
*/
public byte[] serializeToByteArray(Element element) throws Exception {
return canonSerializeToByteArray(element);
}
/**
* Returns a <code>String</code> representation of the specified
* <code>NodeList</code>.
* <p/>
* This is a special case because the NodeList may represent a
* <code>DocumentFragment</code>. A document fragment may be a
* non-valid XML document (refer to appropriate description of
* W3C) because it my start with a non-element node, e.g. a text
* node.
* <p/>
* The methods first converts the node list into a document fragment.
* Special care is taken to not destroy the current document, thus
* the method clones the nodes (deep cloning) before it appends
* them to the document fragment.
* <p/>
* Refer also to comments about setup of format.
*
* @param content the <code>NodeList</code> to serialize.
* @return the <code>String</code> representation of the serialized
* <code>NodeList</code>.
* @throws Exception
*/
public String serialize(NodeList content) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
canon.setWriter(baos);
canon.notReset();
for (int i = 0; i < content.getLength(); i++) {
canon.canonicalizeSubtree(content.item(i));
}
String ret = baos.toString("UTF-8");
baos.reset();
return ret;
}
/**
* Returns a <code>byte[]</code> representation of the specified
* <code>NodeList</code>.
*
* @param content the <code>NodeList</code> to serialize.
* @return the <code>byte[]</code> representation of the serialized
* <code>NodeList</code>.
* @throws Exception
*/
public byte[] serializeToByteArray(NodeList content) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
canon.setWriter(baos);
canon.notReset();
for (int i = 0; i < content.getLength(); i++) {
canon.canonicalizeSubtree(content.item(i));
}
return baos.toByteArray();
}
/**
* Use the Canonicalizer to serialize the node
* @param node
* @return the canonicalization of the node
* @throws Exception
*/
public String canonSerialize(Node node) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
canon.setWriter(baos);
canon.notReset();
canon.canonicalizeSubtree(node);
String ret = baos.toString("UTF-8");
baos.reset();
return ret;
}
/**
* Use the Canonicalizer to serialize the node
* @param node
* @return the (byte[]) canonicalization of the node
* @throws Exception
*/
public byte[] canonSerializeToByteArray(Node node) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
canon.setWriter(baos);
canon.notReset();
canon.canonicalizeSubtree(node);
return baos.toByteArray();
}
/**
* @param source
* @param ctx
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
public abstract Node deserialize(String source, Node ctx) throws XMLEncryptionException;
/**
* @param source
* @param ctx
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
public abstract Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException;
protected static byte[] createContext(byte[] source, Node ctx) throws XMLEncryptionException {
// Create the context to parse the document against
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(byteArrayOutputStream, "UTF-8");
outputStreamWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");
// Run through each node up to the document node and find any xmlns: nodes
Map<String, String> storedNamespaces = new HashMap<String, String>();
Node wk = ctx;
while (wk != null) {
NamedNodeMap atts = wk.getAttributes();
if (atts != null) {
for (int i = 0; i < atts.getLength(); ++i) {
Node att = atts.item(i);
String nodeName = att.getNodeName();
if ((nodeName.equals("xmlns") || nodeName.startsWith("xmlns:"))
&& !storedNamespaces.containsKey(att.getNodeName())) {
outputStreamWriter.write(" ");
outputStreamWriter.write(nodeName);
outputStreamWriter.write("=\"");
outputStreamWriter.write(att.getNodeValue());
outputStreamWriter.write("\"");
storedNamespaces.put(nodeName, att.getNodeValue());
}
}
}
wk = wk.getParentNode();
}
outputStreamWriter.write(">");
outputStreamWriter.flush();
byteArrayOutputStream.write(source);
outputStreamWriter.write("</dummy>");
outputStreamWriter.close();
return byteArrayOutputStream.toByteArray();
} catch (UnsupportedEncodingException e) {
throw new XMLEncryptionException("empty", e);
} catch (IOException e) {
throw new XMLEncryptionException("empty", e);
}
}
protected static String createContext(String source, Node ctx) {
// Create the context to parse the document against
StringBuilder sb = new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><dummy");
// Run through each node up to the document node and find any xmlns: nodes
Map<String, String> storedNamespaces = new HashMap<String, String>();
Node wk = ctx;
while (wk != null) {
NamedNodeMap atts = wk.getAttributes();
if (atts != null) {
for (int i = 0; i < atts.getLength(); ++i) {
Node att = atts.item(i);
String nodeName = att.getNodeName();
if ((nodeName.equals("xmlns") || nodeName.startsWith("xmlns:"))
&& !storedNamespaces.containsKey(att.getNodeName())) {
sb.append(" " + nodeName + "=\"" + att.getNodeValue() + "\"");
storedNamespaces.put(nodeName, att.getNodeValue());
}
}
}
wk = wk.getParentNode();
}
sb.append(">" + source + "</dummy>");
return sb.toString();
}
}

View File

@ -2,30 +2,30 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.util.Iterator;
import com.sun.org.apache.xml.internal.security.keys.KeyInfo;
import org.w3c.dom.Element;
/**
* A Key Agreement algorithm provides for the derivation of a shared secret key
* based on a shared secret computed from certain types of compatible public
@ -79,9 +79,10 @@ import org.w3c.dom.Element;
* @author Axl Mattheus
*/
public interface AgreementMethod {
/**
* Returns an <code>byte</code> array.
* @return
* Returns a <code>byte</code> array.
* @return a <code>byte</code> array.
*/
byte[] getKANonce();
@ -92,8 +93,8 @@ public interface AgreementMethod {
void setKANonce(byte[] kanonce);
/**
* Returns aditional information regarding the <code>AgreementMethod</code>.
* @return
* Returns additional information regarding the <code>AgreementMethod</code>.
* @return additional information regarding the <code>AgreementMethod</code>.
*/
Iterator<Element> getAgreementMethodInformation();
@ -134,7 +135,7 @@ public interface AgreementMethod {
void setOriginatorKeyInfo(KeyInfo keyInfo);
/**
* Retruns information relating to the recipient's shared secret.
* Returns information relating to the recipient's shared secret.
*
* @return information relating to the recipient's shared secret.
*/

View File

@ -2,25 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
/**
* <code>CipherData</code> provides encrypted data. It must either contain the
* encrypted octet sequence as base64 encoded text of the
@ -42,10 +43,12 @@ package com.sun.org.apache.xml.internal.security.encryption;
* @author Axl Mattheus
*/
public interface CipherData {
/** VALUE_TYPE ASN */
public static final int VALUE_TYPE = 0x00000001;
int VALUE_TYPE = 0x00000001;
/** REFERENCE_TYPE ASN */
public static final int REFERENCE_TYPE = 0x00000002;
int REFERENCE_TYPE = 0x00000002;
/**
* Returns the type of encrypted data contained in the
@ -76,18 +79,17 @@ public interface CipherData {
* Returns a reference to an external location containing the encrypted
* octet sequence (<code>byte</code> array).
*
* @return the reference to an external location containing the enctrypted
* octet sequence.
* @return the reference to an external location containing the encrypted
* octet sequence.
*/
CipherReference getCipherReference();
/**
* Sets the <code>CipherData</code>'s reference.
*
* @param reference an external location containing the enctrypted octet
* sequence.
* @param reference an external location containing the encrypted octet sequence.
* @throws XMLEncryptionException
*/
void setCipherReference(CipherReference reference) throws
XMLEncryptionException;
void setCipherReference(CipherReference reference) throws XMLEncryptionException;
}

View File

@ -2,34 +2,34 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import org.w3c.dom.Attr;
/**
* <code>CipherReference</code> identifies a source which, when processed,
* yields the encrypted octet sequence.
* <p>
* The actual value is obtained as follows. The <code>CipherReference URI</code>
* contains an identifier that is dereferenced. Should the
* <code>CipherReference</code> element contain an OPTIONAL sequence of
* Transforms, the data resulting from dereferencing the <code>URI</code> is
* transformed as specified so as to yield the intended cipher value. For
* example, if the value is base64 encoded within an XML document; the
@ -62,20 +62,21 @@ public interface CipherReference {
/**
* Returns an <code>URI</code> that contains an identifier that should be
* dereferenced.
* @return
* @return an <code>URI</code> that contains an identifier that should be
* dereferenced.
*/
String getURI();
/**
* Gets the URI as an Attribute node. Used to meld the CipherREference
* with the XMLSignature ResourceResolvers
* @return
*/
public Attr getURIAsAttr();
/**
* Gets the URI as an Attribute node. Used to meld the CipherReference
* with the XMLSignature ResourceResolvers
* @return the URI as an Attribute node
*/
Attr getURIAsAttr();
/**
* Returns the <code>Transforms</code> that specifies how to transform the
* <code>URI</code> to yield the appropiate cipher value.
* <code>URI</code> to yield the appropriate cipher value.
*
* @return the transform that specifies how to transform the reference to
* yield the intended cipher value.
@ -84,10 +85,11 @@ public interface CipherReference {
/**
* Sets the <code>Transforms</code> that specifies how to transform the
* <code>URI</code> to yield the appropiate cipher value.
* <code>URI</code> to yield the appropriate cipher value.
*
* @param transforms the set of <code>Transforms</code> that specifies how
* to transform the reference to yield the intended cipher value.
*/
void setTransforms(Transforms transforms);
}

View File

@ -2,25 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
/**
* <code>CipherValue</code> is the wrapper for cipher text.
*
@ -28,20 +29,18 @@ package com.sun.org.apache.xml.internal.security.encryption;
*/
public interface CipherValue {
/**
* Resturns the Base 64 encoded, encrypted octets that is the
* <code>CihperValue</code>.
* Returns the Base 64 encoded, encrypted octets that is the
* <code>CipherValue</code>.
*
* @return cipher value.
*/
String getValue();
// byte[] getValue();
String getValue();
/**
* Sets the Base 64 encoded, encrypted octets that is the
* <code>CihperValue</code>.
* <code>CipherValue</code>.
*
* @param value the cipher value.
*/
void setValue(String value);
// void setValue(byte[] value);
void setValue(String value);
}

View File

@ -0,0 +1,114 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
* Converts <code>String</code>s into <code>Node</code>s and visa versa.
*/
public class DocumentSerializer extends AbstractSerializer {
protected DocumentBuilderFactory dbf;
/**
* @param source
* @param ctx
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
public Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException {
byte[] fragment = createContext(source, ctx);
return deserialize(ctx, new InputSource(new ByteArrayInputStream(fragment)));
}
/**
* @param source
* @param ctx
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
public Node deserialize(String source, Node ctx) throws XMLEncryptionException {
String fragment = createContext(source, ctx);
return deserialize(ctx, new InputSource(new StringReader(fragment)));
}
/**
* @param ctx
* @param inputSource
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
private Node deserialize(Node ctx, InputSource inputSource) throws XMLEncryptionException {
try {
if (dbf == null) {
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
dbf.setValidating(false);
}
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.parse(inputSource);
Document contextDocument = null;
if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
contextDocument = (Document)ctx;
} else {
contextDocument = ctx.getOwnerDocument();
}
Element fragElt =
(Element) contextDocument.importNode(d.getDocumentElement(), true);
DocumentFragment result = contextDocument.createDocumentFragment();
Node child = fragElt.getFirstChild();
while (child != null) {
fragElt.removeChild(child);
result.appendChild(child);
child = fragElt.getFirstChild();
}
return result;
} catch (SAXException se) {
throw new XMLEncryptionException("empty", se);
} catch (ParserConfigurationException pce) {
throw new XMLEncryptionException("empty", pce);
} catch (IOException ioe) {
throw new XMLEncryptionException("empty", ioe);
}
}
}

View File

@ -2,25 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
/**
* The <code>EncryptedData</code> element is the core element in the syntax. Not
* only does its <code>CipherData</code> child contain the encrypted data, but
@ -42,3 +43,4 @@ package com.sun.org.apache.xml.internal.security.encryption;
*/
public interface EncryptedData extends EncryptedType {
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
/**
* The <code>EncryptedKey</code> element is used to transport encryption keys
* from the originator to a known recipient(s). It may be used as a stand-alone
@ -51,9 +51,9 @@ package com.sun.org.apache.xml.internal.security.encryption;
* @author Axl Mattheus
*/
public interface EncryptedKey extends EncryptedType {
/**
* Returns a hint as to which recipient this encrypted key value is intended
* for.
* Returns a hint as to which recipient this encrypted key value is intended for.
*
* @return the recipient of the <code>EncryptedKey</code>.
*/
@ -110,3 +110,4 @@ public interface EncryptedKey extends EncryptedType {
*/
void setCarriedName(String name);
}

View File

@ -2,28 +2,28 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import com.sun.org.apache.xml.internal.security.keys.KeyInfo;
/**
* EncryptedType is the abstract type from which <code>EncryptedData</code> and
* <code>EncryptedKey</code> are derived. While these two latter element types
@ -50,6 +50,7 @@ import com.sun.org.apache.xml.internal.security.keys.KeyInfo;
* @author Axl Mattheus
*/
public interface EncryptedType {
/**
* Returns a <code>String</code> providing for the standard method of
* assigning an id to the element within the document context.
@ -61,7 +62,7 @@ public interface EncryptedType {
/**
* Sets the id.
*
* @param id.
* @param id
*/
void setId(String id);
@ -117,7 +118,7 @@ public interface EncryptedType {
void setMimeType(String type);
/**
* Retusn an <code>URI</code> representing the encoding of the
* Return an <code>URI</code> representing the encoding of the
* <code>EncryptedType</code>.
*
* @return the encoding of this <code>EncryptedType</code>.
@ -128,7 +129,7 @@ public interface EncryptedType {
* Sets the <code>URI</code> representing the encoding of the
* <code>EncryptedType</code>.
*
* @param encoding.
* @param encoding
*/
void setEncoding(String encoding);
@ -189,7 +190,8 @@ public interface EncryptedType {
* Sets the <code>EncryptionProperties</code> that supplies additional
* information about the generation of the <code>EncryptedType</code>.
*
* @param properties.
* @param properties
*/
void setEncryptionProperties(EncryptionProperties properties);
}

View File

@ -2,29 +2,29 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.util.Iterator;
import org.w3c.dom.Element;
/**
* <code>EncryptionMethod</code> describes the encryption algorithm applied to
* the cipher data. If the element is absent, the encryption algorithm must be
@ -82,6 +82,30 @@ public interface EncryptionMethod {
*/
void setOAEPparams(byte[] parameters);
/**
* Set the Digest Algorithm to use
* @param digestAlgorithm the Digest Algorithm to use
*/
void setDigestAlgorithm(String digestAlgorithm);
/**
* Get the Digest Algorithm to use
* @return the Digest Algorithm to use
*/
String getDigestAlgorithm();
/**
* Set the MGF Algorithm to use
* @param mgfAlgorithm the MGF Algorithm to use
*/
void setMGFAlgorithm(String mgfAlgorithm);
/**
* Get the MGF Algorithm to use
* @return the MGF Algorithm to use
*/
String getMGFAlgorithm();
/**
* Returns an iterator over all the additional elements contained in the
* <code>EncryptionMethod</code>.
@ -106,3 +130,4 @@ public interface EncryptionMethod {
*/
void removeEncryptionMethodInformation(Element information);
}

View File

@ -2,28 +2,28 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.util.Iterator;
/**
* <code>EncryptionProperties</code> can hold additional information concerning
* the generation of the <code>EncryptedData</code> or
@ -46,6 +46,7 @@ import java.util.Iterator;
* @author Axl Mattheus
*/
public interface EncryptionProperties {
/**
* Returns the <code>EncryptionProperties</code>' id.
*
@ -72,14 +73,15 @@ public interface EncryptionProperties {
/**
* Adds an <code>EncryptionProperty</code>.
*
* @param property.
* @param property
*/
void addEncryptionProperty(EncryptionProperty property);
/**
* Removes the specified <code>EncryptionProperty</code>.
*
* @param property.
* @param property
*/
void removeEncryptionProperty(EncryptionProperty property);
}

View File

@ -2,25 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.util.Iterator;
import org.w3c.dom.Element;
@ -50,6 +51,7 @@ import org.w3c.dom.Element;
* @author Axl Mattheus
*/
public interface EncryptionProperty {
/**
* Returns the <code>EncryptedType</code> being described.
*
@ -61,7 +63,7 @@ public interface EncryptionProperty {
/**
* Sets the target.
*
* @param target.
* @param target
*/
void setTarget(String target);
@ -75,7 +77,7 @@ public interface EncryptionProperty {
/**
* Sets the id.
*
* @param id.
* @param id
*/
void setId(String id);
@ -98,7 +100,7 @@ public interface EncryptionProperty {
/**
* Returns the properties of the <CODE>EncryptionProperty</CODE>.
*
* @return an <code>Iterator</code> over all the addiitonal encryption
* @return an <code>Iterator</code> over all the additional encryption
* information contained in this class.
*/
Iterator<Element> getEncryptionInformation();

View File

@ -2,29 +2,29 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.util.Iterator;
import org.w3c.dom.Element;
/**
* A wrapper for a pointer from a key value of an <code>EncryptedKey</code> to
* items encrypted by that key value (<code>EncryptedData</code> or
@ -44,6 +44,13 @@ import org.w3c.dom.Element;
* @see ReferenceList
*/
public interface Reference {
/**
* Returns the <code>Element</code> tag name for this <code>Reference</code>.
*
* @return the tag name of this <code>Reference</code>.
*/
String getType();
/**
* Returns a <code>URI</code> that points to an <code>Element</code> that
* were encrypted using the key defined in the enclosing
@ -79,14 +86,14 @@ public interface Reference {
/**
* Adds retrieval information.
*
* @param info.
* @param info
*/
void addElementRetrievalInformation(Element info);
/**
* Removes the specified retrieval information.
*
* @param info.
* @param info
*/
void removeElementRetrievalInformation(Element info);
}

View File

@ -2,28 +2,28 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.util.Iterator;
/**
* <code>ReferenceList</code> is an element that contains pointers from a key
* value of an <code>EncryptedKey</code> to items encrypted by that key value
@ -45,10 +45,12 @@ import java.util.Iterator;
* @see Reference
*/
public interface ReferenceList {
/** DATA TAG */
public static final int DATA_REFERENCE = 0x00000001;
/** DATA TAG */
int DATA_REFERENCE = 0x00000001;
/** KEY TAG */
public static final int KEY_REFERENCE = 0x00000002;
int KEY_REFERENCE = 0x00000002;
/**
* Adds a reference to this reference list.
@ -57,21 +59,21 @@ public interface ReferenceList {
* @throws IllegalAccessException if the <code>Reference</code> is not an
* instance of <code>DataReference</code> or <code>KeyReference</code>.
*/
public void add(Reference reference);
void add(Reference reference);
/**
* Removes a reference from the <code>ReferenceList</code>.
*
* @param reference the reference to remove.
*/
public void remove(Reference reference);
void remove(Reference reference);
/**
* Returns the size of the <code>ReferenceList</code>.
*
* @return the size of the <code>ReferenceList</code>.
*/
public int size();
int size();
/**
* Indicates if the <code>ReferenceList</code> is empty.
@ -79,29 +81,29 @@ public interface ReferenceList {
* @return <code><b>true</b></code> if the <code>ReferenceList</code> is
* empty, else <code><b>false</b></code>.
*/
public boolean isEmpty();
boolean isEmpty();
/**
* Returns an <code>Iterator</code> over all the <code>Reference</code>s
* contatined in this <code>ReferenceList</code>.
* contained in this <code>ReferenceList</code>.
*
* @return Iterator.
*/
public Iterator<Reference> getReferences();
Iterator<Reference> getReferences();
/**
* <code>DataReference</code> factory method. Returns a
* <code>DataReference</code>.
* @param uri
* @return
* @return a <code>DataReference</code>.
*/
public Reference newDataReference(String uri);
Reference newDataReference(String uri);
/**
* <code>KeyReference</code> factory method. Returns a
* <code>KeyReference</code>.
* @param uri
* @return
* @return a <code>KeyReference</code>.
*/
public Reference newKeyReference(String uri);
Reference newKeyReference(String uri);
}

View File

@ -0,0 +1,77 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import com.sun.org.apache.xml.internal.security.c14n.Canonicalizer;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
* Converts <code>String</code>s into <code>Node</code>s and visa versa.
*/
public interface Serializer {
/**
* Set the Canonicalizer object to use.
*/
void setCanonicalizer(Canonicalizer canon);
/**
* Returns a <code>byte[]</code> representation of the specified
* <code>Element</code>.
*
* @param element the <code>Element</code> to serialize.
* @return the <code>byte[]</code> representation of the serilaized
* <code>Element</code>.
* @throws Exception
*/
byte[] serializeToByteArray(Element element) throws Exception;
/**
* Returns a <code>byte[]</code> representation of the specified
* <code>NodeList</code>.
*
* @param content the <code>NodeList</code> to serialize.
* @return the <code>byte[]</code> representation of the serialized
* <code>NodeList</code>.
* @throws Exception
*/
byte[] serializeToByteArray(NodeList content) throws Exception;
/**
* Use the Canonicalizer to serialize the node
* @param node
* @return the (byte[]) canonicalization of the node
* @throws Exception
*/
byte[] canonSerializeToByteArray(Node node) throws Exception;
/**
* @param source
* @param ctx
* @return the Node resulting from the parse of the source
* @throws XMLEncryptionException
*/
Node deserialize(byte[] source, Node ctx) throws XMLEncryptionException;
}

View File

@ -2,27 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
/**
* A container for <code>ds:Transform</code>s.
* <p>
@ -40,36 +39,12 @@ package com.sun.org.apache.xml.internal.security.encryption;
*/
public interface Transforms {
/**
* Returns an <code>Iterator</code> over all the transforms contained in
* this transform list.
*
* @return all transforms.
* Temporary method to turn the XMLEncryption Transforms class
* into a DS class. The main logic is currently implemented in the
* DS class, so we need to get to get the base class.
* <p>
* <b>Note</b> This will be removed in future versions
*/
/* Iterator getTransforms(); */
/**
* Adds a <code>ds:Transform</code> to the list of transforms.
*
* @param transform.
*/
/* void addTransform(Transform transform); */
/**
* Removes the specified transform.
*
* @param transform.
*/
/* void removeTransform(Transform transform); */
/**
* Temporary method to turn the XMLEncryption Transforms class
* into a DS class. The main logic is currently implemented in the
* DS class, so we need to get to get the base class.
* <p>
* <b>Note</b> This will be removed in future versions
* @return
*/
com.sun.org.apache.xml.internal.security.transforms.Transforms getDSTransforms();
com.sun.org.apache.xml.internal.security.transforms.Transforms getDSTransforms();
}

View File

@ -2,23 +2,24 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
import java.io.IOException;
@ -32,7 +33,6 @@ import com.sun.org.apache.xml.internal.security.transforms.TransformationExcepti
import org.w3c.dom.Attr;
import com.sun.org.apache.xml.internal.security.utils.Base64;
/**
* <code>XMLCipherInput</code> is used to wrap input passed into the
* XMLCipher encryption operations.
@ -50,77 +50,79 @@ import com.sun.org.apache.xml.internal.security.utils.Base64;
public class XMLCipherInput {
private static java.util.logging.Logger logger =
java.util.logging.Logger.getLogger(XMLCipher.class.getName());
java.util.logging.Logger.getLogger(XMLCipherInput.class.getName());
/** The data we are working with */
private CipherData _cipherData;
/** The data we are working with */
private CipherData cipherData;
/** MODES */
private int _mode;
/** MODES */
private int mode;
/**
* Constructor for processing encrypted octets
*
* @param data The <code>CipherData</code> object to read the bytes from
* @throws XMLEncryptionException {@link XMLEncryptionException}
*/
public XMLCipherInput(CipherData data) throws XMLEncryptionException {
_cipherData = data;
_mode = XMLCipher.DECRYPT_MODE;
if (_cipherData == null) {
throw new XMLEncryptionException("CipherData is null");
}
private boolean secureValidation;
/**
* Constructor for processing encrypted octets
*
* @param data The <code>CipherData</code> object to read the bytes from
* @throws XMLEncryptionException {@link XMLEncryptionException}
*/
public XMLCipherInput(CipherData data) throws XMLEncryptionException {
cipherData = data;
mode = XMLCipher.DECRYPT_MODE;
if (cipherData == null) {
throw new XMLEncryptionException("CipherData is null");
}
}
/**
* Constructor for processing encrypted octets
*
* @param input The <code>EncryptedType</code> object to read
* the bytes from.
* @throws XMLEncryptionException {@link XMLEncryptionException}
*/
public XMLCipherInput(EncryptedType input) throws XMLEncryptionException {
_cipherData = ((input == null) ? null : input.getCipherData());
_mode = XMLCipher.DECRYPT_MODE;
if (_cipherData == null) {
throw new XMLEncryptionException("CipherData is null");
}
/**
* Constructor for processing encrypted octets
*
* @param input The <code>EncryptedType</code> object to read
* the bytes from.
* @throws XMLEncryptionException {@link XMLEncryptionException}
*/
public XMLCipherInput(EncryptedType input) throws XMLEncryptionException {
cipherData = ((input == null) ? null : input.getCipherData());
mode = XMLCipher.DECRYPT_MODE;
if (cipherData == null) {
throw new XMLEncryptionException("CipherData is null");
}
}
/**
* Dereferences the input and returns it as a single byte array.
*
* @throws XMLEncryptionException
/**
* Set whether secure validation is enabled or not. The default is false.
*/
public void setSecureValidation(boolean secureValidation) {
this.secureValidation = secureValidation;
}
/**
* Dereferences the input and returns it as a single byte array.
*
* @throws XMLEncryptionException
* @return The decripted bytes.
*/
public byte[] getBytes() throws XMLEncryptionException {
if (_mode == XMLCipher.DECRYPT_MODE) {
return getDecryptBytes();
}
return null;
*/
public byte[] getBytes() throws XMLEncryptionException {
if (mode == XMLCipher.DECRYPT_MODE) {
return getDecryptBytes();
}
return null;
}
/**
* Internal method to get bytes in decryption mode
* @return the decripted bytes
* @return the decrypted bytes
* @throws XMLEncryptionException
*/
private byte[] getDecryptBytes() throws XMLEncryptionException {
String base64EncodedEncryptedOctets = null;
if (_cipherData.getDataType() == CipherData.REFERENCE_TYPE) {
if (cipherData.getDataType() == CipherData.REFERENCE_TYPE) {
// Fun time!
logger.log(java.util.logging.Level.FINE, "Found a reference type CipherData");
CipherReference cr = _cipherData.getCipherReference();
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Found a reference type CipherData");
}
CipherReference cr = cipherData.getCipherReference();
// Need to wrap the uri in an Attribute node so that we can
// Pass to the resource resolvers
@ -130,25 +132,32 @@ public class XMLCipherInput {
try {
ResourceResolver resolver =
ResourceResolver.getInstance(uriAttr, null);
input = resolver.resolve(uriAttr, null);
ResourceResolver.getInstance(uriAttr, null, secureValidation);
input = resolver.resolve(uriAttr, null, secureValidation);
} catch (ResourceResolverException ex) {
throw new XMLEncryptionException("empty", ex);
}
if (input != null) {
logger.log(java.util.logging.Level.FINE, "Managed to resolve URI \"" + cr.getURI() + "\"");
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Managed to resolve URI \"" + cr.getURI() + "\"");
}
} else {
logger.log(java.util.logging.Level.FINE, "Failed to resolve URI \"" + cr.getURI() + "\"");
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Failed to resolve URI \"" + cr.getURI() + "\"");
}
}
// Lets see if there are any transforms
Transforms transforms = cr.getTransforms();
if (transforms != null) {
logger.log(java.util.logging.Level.FINE, "Have transforms in cipher reference");
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Have transforms in cipher reference");
}
try {
com.sun.org.apache.xml.internal.security.transforms.Transforms dsTransforms =
transforms.getDSTransforms();
dsTransforms.setSecureValidation(secureValidation);
input = dsTransforms.performTransforms(input);
} catch (TransformationException ex) {
throw new XMLEncryptionException("empty", ex);
@ -163,23 +172,21 @@ public class XMLCipherInput {
throw new XMLEncryptionException("empty", ex);
}
// retrieve the cipher text
} else if (_cipherData.getDataType() == CipherData.VALUE_TYPE) {
base64EncodedEncryptedOctets =
_cipherData.getCipherValue().getValue();
// retrieve the cipher text
} else if (cipherData.getDataType() == CipherData.VALUE_TYPE) {
base64EncodedEncryptedOctets = cipherData.getCipherValue().getValue();
} else {
throw new XMLEncryptionException("CipherData.getDataType() returned unexpected value");
}
logger.log(java.util.logging.Level.FINE, "Encrypted octets:\n" + base64EncodedEncryptedOctets);
if (logger.isLoggable(java.util.logging.Level.FINE)) {
logger.log(java.util.logging.Level.FINE, "Encrypted octets:\n" + base64EncodedEncryptedOctets);
}
byte[] encryptedBytes = null;
try {
encryptedBytes = Base64.decode(base64EncodedEncryptedOctets);
return Base64.decode(base64EncodedEncryptedOctets);
} catch (Base64DecodingException bde) {
throw new XMLEncryptionException("empty", bde);
}
return (encryptedBytes);
}
}

View File

@ -2,104 +2,85 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
/**
* Constants
*/
public interface XMLCipherParameters {
/** */
public static final String AES_128 =
String AES_128 =
"http://www.w3.org/2001/04/xmlenc#aes128-cbc";
/** */
public static final String AES_256 =
String AES_256 =
"http://www.w3.org/2001/04/xmlenc#aes256-cbc";
/** */
public static final String AES_192 =
String AES_192 =
"http://www.w3.org/2001/04/xmlenc#aes192-cbc";
/** */
public static final String RSA_1_5 =
String RSA_1_5 =
"http://www.w3.org/2001/04/xmlenc#rsa-1_5";
/** */
public static final String RSA_OAEP =
String RSA_OAEP =
"http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p";
/** */
public static final String DIFFIE_HELLMAN =
String DIFFIE_HELLMAN =
"http://www.w3.org/2001/04/xmlenc#dh";
/** */
public static final String TRIPLEDES_KEYWRAP =
String TRIPLEDES_KEYWRAP =
"http://www.w3.org/2001/04/xmlenc#kw-tripledes";
/** */
public static final String AES_128_KEYWRAP =
String AES_128_KEYWRAP =
"http://www.w3.org/2001/04/xmlenc#kw-aes128";
/** */
public static final String AES_256_KEYWRAP =
String AES_256_KEYWRAP =
"http://www.w3.org/2001/04/xmlenc#kw-aes256";
/** */
public static final String AES_192_KEYWRAP =
String AES_192_KEYWRAP =
"http://www.w3.org/2001/04/xmlenc#kw-aes192";
/** */
public static final String SHA1 =
String SHA1 =
"http://www.w3.org/2000/09/xmldsig#sha1";
/** */
public static final String SHA256 =
String SHA256 =
"http://www.w3.org/2001/04/xmlenc#sha256";
/** */
public static final String SHA512 =
String SHA512 =
"http://www.w3.org/2001/04/xmlenc#sha512";
/** */
public static final String RIPEMD_160 =
String RIPEMD_160 =
"http://www.w3.org/2001/04/xmlenc#ripemd160";
/** */
public static final String XML_DSIG =
String XML_DSIG =
"http://www.w3.org/2000/09/xmldsig#";
/** */
public static final String N14C_XML =
String N14C_XML =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
/** */
public static final String N14C_XML_CMMNTS =
String N14C_XML_CMMNTS =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
/** */
public static final String EXCL_XML_N14C =
String EXCL_XML_N14C =
"http://www.w3.org/2001/10/xml-exc-c14n#";
/** */
public static final String EXCL_XML_N14C_CMMNTS =
String EXCL_XML_N14C_CMMNTS =
"http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2003-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.encryption;
@ -26,49 +28,53 @@ import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
*
*/
public class XMLEncryptionException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
/**
*
*
*/
public XMLEncryptionException() {
super();
}
/**
*
* @param _msgID
*/
public XMLEncryptionException(String _msgID) {
super(_msgID);
}
/**
*
* @param _msgID
* @param exArgs
*/
public XMLEncryptionException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
*
* @param _msgID
* @param _originalException
*/
public XMLEncryptionException(String _msgID,
Exception _originalException) {
super(_msgID, _originalException);
}
/**
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public XMLEncryptionException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
*/
private static final long serialVersionUID = 1L;
/**
*
*
*/
public XMLEncryptionException() {
super();
}
/**
*
* @param msgID
*/
public XMLEncryptionException(String msgID) {
super(msgID);
}
/**
*
* @param msgID
* @param exArgs
*/
public XMLEncryptionException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
*
* @param msgID
* @param originalException
*/
public XMLEncryptionException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
*
* @param msgID
* @param exArgs
* @param originalException
*/
public XMLEncryptionException(String msgID, Object exArgs[], Exception originalException) {
super(msgID, exArgs, originalException);
}
}

View File

@ -2,88 +2,80 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.exceptions;
/**
*
*
*
*
* @author Christian Geuer-Pollmann
*
*/
public class AlgorithmAlreadyRegisteredException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor AlgorithmAlreadyRegisteredException
*
*/
public AlgorithmAlreadyRegisteredException() {
super();
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
*/
public AlgorithmAlreadyRegisteredException() {
super();
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param msgID
*/
public AlgorithmAlreadyRegisteredException(String msgID) {
super(msgID);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param _msgID
*/
public AlgorithmAlreadyRegisteredException(String _msgID) {
super(_msgID);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param msgID
* @param exArgs
*/
public AlgorithmAlreadyRegisteredException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param _msgID
* @param exArgs
*/
public AlgorithmAlreadyRegisteredException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param msgID
* @param originalException
*/
public AlgorithmAlreadyRegisteredException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param _msgID
* @param _originalException
*/
public AlgorithmAlreadyRegisteredException(String _msgID,
Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public AlgorithmAlreadyRegisteredException(
String msgID, Object exArgs[], Exception originalException
) {
super(msgID, exArgs, originalException);
}
/**
* Constructor AlgorithmAlreadyRegisteredException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public AlgorithmAlreadyRegisteredException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.exceptions;
/**
* This Exception is thrown if decoding of Base64 data fails.
*
@ -29,58 +29,54 @@ package com.sun.org.apache.xml.internal.security.exceptions;
*/
public class Base64DecodingException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 1L;
/**
* Constructor Base64DecodingException
*
*/
public Base64DecodingException() {
super();
}
/**
* Constructor Base64DecodingException
*
*/
public Base64DecodingException() {
super();
}
/**
* Constructor Base64DecodingException
*
* @param _msgID
*/
public Base64DecodingException(String _msgID) {
super(_msgID);
}
/**
* Constructor Base64DecodingException
*
* @param msgID
*/
public Base64DecodingException(String msgID) {
super(msgID);
}
/**
* Constructor Base64DecodingException
*
* @param _msgID
* @param exArgs
*/
public Base64DecodingException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor Base64DecodingException
*
* @param msgID
* @param exArgs
*/
public Base64DecodingException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor Base64DecodingException
*
* @param _msgID
* @param _originalException
*/
public Base64DecodingException(String _msgID,
Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor Base64DecodingException
*
* @param msgID
* @param originalException
*/
public Base64DecodingException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor Base64DecodingException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public Base64DecodingException(String msgID, Object exArgs[], Exception originalException) {
super(msgID, exArgs, originalException);
}
/**
* Constructor Base64DecodingException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public Base64DecodingException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.exceptions;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.MessageFormat;
@ -29,7 +29,6 @@ import java.text.MessageFormat;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.I18n;
/**
* The mother of all Exceptions in this bundle. It allows exceptions to have
* their messages translated to the different locales.
@ -64,186 +63,154 @@ import com.sun.org.apache.xml.internal.security.utils.I18n;
*/
public class XMLSecurityException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
/** Field msgID */
protected String msgID;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor XMLSecurityException
*
*/
public XMLSecurityException() {
super("Missing message string");
/** Field originalException */
protected Exception originalException = null;
this.msgID = null;
}
/** Field msgID */
protected String msgID;
/**
* Constructor XMLSecurityException
*
* @param msgID
*/
public XMLSecurityException(String msgID) {
super(I18n.getExceptionMessage(msgID));
/**
* Constructor XMLSecurityException
*
*/
public XMLSecurityException() {
this.msgID = msgID;
}
super("Missing message string");
/**
* Constructor XMLSecurityException
*
* @param msgID
* @param exArgs
*/
public XMLSecurityException(String msgID, Object exArgs[]) {
this.msgID = null;
this.originalException = null;
}
super(MessageFormat.format(I18n.getExceptionMessage(msgID), exArgs));
/**
* Constructor XMLSecurityException
*
* @param _msgID
*/
public XMLSecurityException(String _msgID) {
this.msgID = msgID;
}
super(I18n.getExceptionMessage(_msgID));
/**
* Constructor XMLSecurityException
*
* @param originalException
*/
public XMLSecurityException(Exception originalException) {
this.msgID = _msgID;
this.originalException = null;
}
super("Missing message ID to locate message string in resource bundle \""
+ Constants.exceptionMessagesResourceBundleBase
+ "\". Original Exception was a "
+ originalException.getClass().getName() + " and message "
+ originalException.getMessage(), originalException);
}
/**
* Constructor XMLSecurityException
*
* @param _msgID
* @param exArgs
*/
public XMLSecurityException(String _msgID, Object exArgs[]) {
/**
* Constructor XMLSecurityException
*
* @param msgID
* @param originalException
*/
public XMLSecurityException(String msgID, Exception originalException) {
super(I18n.getExceptionMessage(msgID, originalException), originalException);
super(MessageFormat.format(I18n.getExceptionMessage(_msgID), exArgs));
this.msgID = msgID;
}
this.msgID = _msgID;
this.originalException = null;
}
/**
* Constructor XMLSecurityException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public XMLSecurityException(String msgID, Object exArgs[], Exception originalException) {
super(MessageFormat.format(I18n.getExceptionMessage(msgID), exArgs), originalException);
/**
* Constructor XMLSecurityException
*
* @param _originalException
*/
public XMLSecurityException(Exception _originalException) {
this.msgID = msgID;
}
super("Missing message ID to locate message string in resource bundle \""
+ Constants.exceptionMessagesResourceBundleBase
+ "\". Original Exception was a "
+ _originalException.getClass().getName() + " and message "
+ _originalException.getMessage());
/**
* Method getMsgID
*
* @return the messageId
*/
public String getMsgID() {
if (msgID == null) {
return "Missing message ID";
}
return msgID;
}
this.originalException = _originalException;
}
/** @inheritDoc */
public String toString() {
String s = this.getClass().getName();
String message = super.getLocalizedMessage();
/**
* Constructor XMLSecurityException
*
* @param _msgID
* @param _originalException
*/
public XMLSecurityException(String _msgID, Exception _originalException) {
if (message != null) {
message = s + ": " + message;
} else {
message = s;
}
super(I18n.getExceptionMessage(_msgID, _originalException));
if (super.getCause() != null) {
message = message + "\nOriginal Exception was " + super.getCause().toString();
}
this.msgID = _msgID;
this.originalException = _originalException;
}
return message;
}
/**
* Constructor XMLSecurityException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public XMLSecurityException(String _msgID, Object exArgs[],
Exception _originalException) {
/**
* Method printStackTrace
*
*/
public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace(System.err);
}
}
super(MessageFormat.format(I18n.getExceptionMessage(_msgID), exArgs));
/**
* Method printStackTrace
*
* @param printwriter
*/
public void printStackTrace(PrintWriter printwriter) {
super.printStackTrace(printwriter);
}
this.msgID = _msgID;
this.originalException = _originalException;
}
/**
* Method printStackTrace
*
* @param printstream
*/
public void printStackTrace(PrintStream printstream) {
super.printStackTrace(printstream);
}
/**
* Method getMsgID
*
* @return the messageId
*/
public String getMsgID() {
if (msgID == null) {
return "Missing message ID";
}
return msgID;
}
/** @inheritDoc */
public String toString() {
String s = this.getClass().getName();
String message = super.getLocalizedMessage();
if (message != null) {
message = s + ": " + message;
} else {
message = s;
}
if (originalException != null) {
message = message + "\nOriginal Exception was "
+ originalException.toString();
}
return message;
}
/**
* Method printStackTrace
*
*/
public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace(System.err);
if (this.originalException != null) {
this.originalException.printStackTrace(System.err);
}
}
}
/**
* Method printStackTrace
*
* @param printwriter
*/
public void printStackTrace(PrintWriter printwriter) {
super.printStackTrace(printwriter);
if (this.originalException != null) {
this.originalException.printStackTrace(printwriter);
}
}
/**
* Method printStackTrace
*
* @param printstream
*/
public void printStackTrace(PrintStream printstream) {
super.printStackTrace(printstream);
if (this.originalException != null) {
this.originalException.printStackTrace(printstream);
}
}
/**
* Method getOriginalException
*
* @return the original exception
*/
public Exception getOriginalException() {
return originalException;
}
/**
* Method getOriginalException
*
* @return the original exception
*/
public Exception getOriginalException() {
if (this.getCause() instanceof Exception) {
return (Exception)this.getCause();
}
return null;
}
}

View File

@ -1,3 +1,25 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.exceptions;
import java.io.PrintStream;
@ -39,186 +61,152 @@ import com.sun.org.apache.xml.internal.security.utils.I18n;
*
* @author Christian Geuer-Pollmann
*/
public class XMLSecurityRuntimeException
extends RuntimeException {
/**
*
*/
public class XMLSecurityRuntimeException extends RuntimeException {
private static final long serialVersionUID = 1L;
/** Field originalException */
protected Exception originalException = null;
/** Field msgID */
protected String msgID;
/** Field msgID */
protected String msgID;
/**
* Constructor XMLSecurityRuntimeException
*
*/
public XMLSecurityRuntimeException() {
super("Missing message string");
/**
* Constructor XMLSecurityRuntimeException
*
*/
public XMLSecurityRuntimeException() {
this.msgID = null;
}
super("Missing message string");
/**
* Constructor XMLSecurityRuntimeException
*
* @param msgID
*/
public XMLSecurityRuntimeException(String msgID) {
super(I18n.getExceptionMessage(msgID));
this.msgID = null;
this.originalException = null;
}
this.msgID = msgID;
}
/**
* Constructor XMLSecurityRuntimeException
*
* @param _msgID
*/
public XMLSecurityRuntimeException(String _msgID) {
/**
* Constructor XMLSecurityRuntimeException
*
* @param msgID
* @param exArgs
*/
public XMLSecurityRuntimeException(String msgID, Object exArgs[]) {
super(MessageFormat.format(I18n.getExceptionMessage(msgID), exArgs));
super(I18n.getExceptionMessage(_msgID));
this.msgID = msgID;
}
this.msgID = _msgID;
this.originalException = null;
}
/**
* Constructor XMLSecurityRuntimeException
*
* @param originalException
*/
public XMLSecurityRuntimeException(Exception originalException) {
super("Missing message ID to locate message string in resource bundle \""
+ Constants.exceptionMessagesResourceBundleBase
+ "\". Original Exception was a "
+ originalException.getClass().getName() + " and message "
+ originalException.getMessage(), originalException);
}
/**
* Constructor XMLSecurityRuntimeException
*
* @param _msgID
* @param exArgs
*/
public XMLSecurityRuntimeException(String _msgID, Object exArgs[]) {
/**
* Constructor XMLSecurityRuntimeException
*
* @param msgID
* @param originalException
*/
public XMLSecurityRuntimeException(String msgID, Exception originalException) {
super(I18n.getExceptionMessage(msgID, originalException), originalException);
super(MessageFormat.format(I18n.getExceptionMessage(_msgID), exArgs));
this.msgID = msgID;
}
this.msgID = _msgID;
this.originalException = null;
}
/**
* Constructor XMLSecurityRuntimeException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public XMLSecurityRuntimeException(String msgID, Object exArgs[], Exception originalException) {
super(MessageFormat.format(I18n.getExceptionMessage(msgID), exArgs));
/**
* Constructor XMLSecurityRuntimeException
*
* @param _originalException
*/
public XMLSecurityRuntimeException(Exception _originalException) {
this.msgID = msgID;
}
super("Missing message ID to locate message string in resource bundle \""
+ Constants.exceptionMessagesResourceBundleBase
+ "\". Original Exception was a "
+ _originalException.getClass().getName() + " and message "
+ _originalException.getMessage());
/**
* Method getMsgID
*
* @return the messageId
*/
public String getMsgID() {
if (msgID == null) {
return "Missing message ID";
}
return msgID;
}
this.originalException = _originalException;
}
/** @inheritDoc */
public String toString() {
String s = this.getClass().getName();
String message = super.getLocalizedMessage();
/**
* Constructor XMLSecurityRuntimeException
*
* @param _msgID
* @param _originalException
*/
public XMLSecurityRuntimeException(String _msgID, Exception _originalException) {
if (message != null) {
message = s + ": " + message;
} else {
message = s;
}
super(I18n.getExceptionMessage(_msgID, _originalException));
if (this.getCause() != null) {
message = message + "\nOriginal Exception was " + this.getCause().toString();
}
this.msgID = _msgID;
this.originalException = _originalException;
}
return message;
}
/**
* Constructor XMLSecurityRuntimeException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public XMLSecurityRuntimeException(String _msgID, Object exArgs[],
Exception _originalException) {
/**
* Method printStackTrace
*
*/
public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace(System.err);
}
}
super(MessageFormat.format(I18n.getExceptionMessage(_msgID), exArgs));
/**
* Method printStackTrace
*
* @param printwriter
*/
public void printStackTrace(PrintWriter printwriter) {
super.printStackTrace(printwriter);
}
this.msgID = _msgID;
this.originalException = _originalException;
}
/**
* Method printStackTrace
*
* @param printstream
*/
public void printStackTrace(PrintStream printstream) {
super.printStackTrace(printstream);
}
/**
* Method getMsgID
*
* @return the messageId
*/
public String getMsgID() {
/**
* Method getOriginalException
*
* @return the original exception
*/
public Exception getOriginalException() {
if (this.getCause() instanceof Exception) {
return (Exception)this.getCause();
}
return null;
}
if (msgID == null) {
return "Missing message ID";
}
return msgID;
}
/** @inheritDoc */
public String toString() {
String s = this.getClass().getName();
String message = super.getLocalizedMessage();
if (message != null) {
message = s + ": " + message;
} else {
message = s;
}
if (originalException != null) {
message = message + "\nOriginal Exception was "
+ originalException.toString();
}
return message;
}
/**
* Method printStackTrace
*
*/
public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace(System.err);
if (this.originalException != null) {
this.originalException.printStackTrace(System.err);
}
}
}
/**
* Method printStackTrace
*
* @param printwriter
*/
public void printStackTrace(PrintWriter printwriter) {
super.printStackTrace(printwriter);
if (this.originalException != null) {
this.originalException.printStackTrace(printwriter);
}
}
/**
* Method printStackTrace
*
* @param printstream
*/
public void printStackTrace(PrintStream printstream) {
super.printStackTrace(printstream);
if (this.originalException != null) {
this.originalException.printStackTrace(printstream);
}
}
/**
* Method getOriginalException
*
* @return the original exception
*/
public Exception getOriginalException() {
return originalException;
}
}

View File

@ -2,89 +2,83 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
public class ContentHandlerAlreadyRegisteredException extends XMLSecurityException {
/**
*
* @author $Author: mullan $
*/
public class ContentHandlerAlreadyRegisteredException
extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
*/
public ContentHandlerAlreadyRegisteredException() {
super();
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
*/
public ContentHandlerAlreadyRegisteredException() {
super();
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param msgID
*/
public ContentHandlerAlreadyRegisteredException(String msgID) {
super(msgID);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param _msgID
*/
public ContentHandlerAlreadyRegisteredException(String _msgID) {
super(_msgID);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param msgID
* @param exArgs
*/
public ContentHandlerAlreadyRegisteredException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param _msgID
* @param exArgs
*/
public ContentHandlerAlreadyRegisteredException(String _msgID,
Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param msgID
* @param originalException
*/
public ContentHandlerAlreadyRegisteredException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param _msgID
* @param _originalException
*/
public ContentHandlerAlreadyRegisteredException(String _msgID,
Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public ContentHandlerAlreadyRegisteredException(
String msgID, Object exArgs[], Exception originalException
) {
super(msgID, exArgs, originalException);
}
/**
* Constructor ContentHandlerAlreadyRegisteredException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public ContentHandlerAlreadyRegisteredException(String _msgID,
Object exArgs[], Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys;
import java.io.PrintStream;
import java.security.PublicKey;
@ -31,57 +31,53 @@ import com.sun.org.apache.xml.internal.security.keys.content.KeyValue;
import com.sun.org.apache.xml.internal.security.keys.content.MgmtData;
import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
/**
* Utility class for for <CODE>com.sun.org.apache.xml.internal.security.keys</CODE> package.
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public class KeyUtils {
private KeyUtils() {
// no instantiation
}
private KeyUtils() {
// no instantiation
}
/**
* Method prinoutKeyInfo
*
* @param ki
* @param os
* @throws XMLSecurityException
*/
public static void prinoutKeyInfo(KeyInfo ki, PrintStream os)
throws XMLSecurityException {
/**
* Method prinoutKeyInfo
*
* @param ki
* @param os
* @throws XMLSecurityException
*/
public static void prinoutKeyInfo(KeyInfo ki, PrintStream os)
throws XMLSecurityException {
for (int i = 0; i < ki.lengthKeyName(); i++) {
KeyName x = ki.itemKeyName(i);
for (int i = 0; i < ki.lengthKeyName(); i++) {
KeyName x = ki.itemKeyName(i);
os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
}
os.println("KeyName(" + i + ")=\"" + x.getKeyName() + "\"");
}
for (int i = 0; i < ki.lengthKeyValue(); i++) {
KeyValue x = ki.itemKeyValue(i);
PublicKey pk = x.getPublicKey();
for (int i = 0; i < ki.lengthKeyValue(); i++) {
KeyValue x = ki.itemKeyValue(i);
PublicKey pk = x.getPublicKey();
os.println("KeyValue Nr. " + i);
os.println(pk);
}
os.println("KeyValue Nr. " + i);
os.println(pk);
}
for (int i = 0; i < ki.lengthMgmtData(); i++) {
MgmtData x = ki.itemMgmtData(i);
for (int i = 0; i < ki.lengthMgmtData(); i++) {
MgmtData x = ki.itemMgmtData(i);
os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
}
os.println("MgmtData(" + i + ")=\"" + x.getMgmtData() + "\"");
}
for (int i = 0; i < ki.lengthX509Data(); i++) {
X509Data x = ki.itemX509Data(i);
for (int i = 0; i < ki.lengthX509Data(); i++) {
X509Data x = ki.itemX509Data(i);
os.println("X509Data(" + i + ")=\"" + (x.containsCertificate()
? "Certificate "
: "") + (x
.containsIssuerSerial()
? "IssuerSerial "
: "") + "\"");
}
}
os.println("X509Data(" + i + ")=\"" + (x.containsCertificate()
? "Certificate " : "") + (x.containsIssuerSerial()
? "IssuerSerial " : "") + "\"");
}
}
}

View File

@ -0,0 +1,158 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.PublicKey;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.X509EncodedKeySpec;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.Signature11ElementProxy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Provides content model support for the <code>dsig11:DEREncodedKeyvalue</code> element.
*
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class DEREncodedKeyValue extends Signature11ElementProxy implements KeyInfoContent {
/** JCA algorithm key types supported by this implementation. */
public static final String supportedKeyTypes[] = { "RSA", "DSA", "EC"};
/**
* Constructor DEREncodedKeyValue
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public DEREncodedKeyValue(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor DEREncodedKeyValue
*
* @param doc
* @param publicKey
* @throws XMLSecurityException
*/
public DEREncodedKeyValue(Document doc, PublicKey publicKey) throws XMLSecurityException {
super(doc);
this.addBase64Text(getEncodedDER(publicKey));
}
/**
* Constructor DEREncodedKeyValue
*
* @param doc
* @param base64EncodedKey
*/
public DEREncodedKeyValue(Document doc, byte[] encodedKey) {
super(doc);
this.addBase64Text(encodedKey);
}
/**
* Sets the <code>Id</code> attribute
*
* @param Id ID
*/
public void setId(String id) {
if (id != null) {
this.constructionElement.setAttributeNS(null, Constants._ATT_ID, id);
this.constructionElement.setIdAttributeNS(null, Constants._ATT_ID, true);
} else {
this.constructionElement.removeAttributeNS(null, Constants._ATT_ID);
}
}
/**
* Returns the <code>Id</code> attribute
*
* @return the <code>Id</code> attribute
*/
public String getId() {
return this.constructionElement.getAttributeNS(null, Constants._ATT_ID);
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DERENCODEDKEYVALUE;
}
/**
* Method getPublicKey
*
* @return the public key
* @throws XMLSecurityException
*/
public PublicKey getPublicKey() throws XMLSecurityException {
byte[] encodedKey = getBytesFromTextChild();
// Iterate over the supported key types until one produces a public key.
for (String keyType : supportedKeyTypes) {
try {
KeyFactory keyFactory = KeyFactory.getInstance(keyType);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
PublicKey publicKey = keyFactory.generatePublic(keySpec);
if (publicKey != null) {
return publicKey;
}
} catch (NoSuchAlgorithmException e) {
// Do nothing, try the next type
} catch (InvalidKeySpecException e) {
// Do nothing, try the next type
}
}
throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedEncodedKey");
}
/**
* Method getEncodedDER
*
* @return the public key
* @throws XMLSecurityException
*/
protected byte[] getEncodedDER(PublicKey publicKey) throws XMLSecurityException {
try {
KeyFactory keyFactory = KeyFactory.getInstance(publicKey.getAlgorithm());
X509EncodedKeySpec keySpec = keyFactory.getKeySpec(publicKey, X509EncodedKeySpec.class);
return keySpec.getEncoded();
} catch (NoSuchAlgorithmException e) {
Object exArgs[] = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
} catch (InvalidKeySpecException e) {
Object exArgs[] = { publicKey.getAlgorithm(), publicKey.getFormat(), publicKey.getClass().getName() };
throw new XMLSecurityException("DEREncodedKeyValue.UnsupportedPublicKey", exArgs, e);
}
}
}

View File

@ -2,32 +2,30 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
/**
* Empty interface just to identify Elements that can be cildren of ds:KeyInfo.
* Empty interface just to identify Elements that can be children of ds:KeyInfo.
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public interface KeyInfoContent {
}

View File

@ -0,0 +1,107 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.Signature11ElementProxy;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Provides content model support for the <code>dsig11:KeyInfoReference</code> element.
*
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class KeyInfoReference extends Signature11ElementProxy implements KeyInfoContent {
/**
* Constructor RetrievalMethod
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public KeyInfoReference(Element element, String baseURI) throws XMLSecurityException {
super(element, baseURI);
}
/**
* Constructor RetrievalMethod
*
* @param doc
* @param URI
*/
public KeyInfoReference(Document doc, String URI) {
super(doc);
this.constructionElement.setAttributeNS(null, Constants._ATT_URI, URI);
}
/**
* Method getURIAttr
*
* @return the URI attribute
*/
public Attr getURIAttr() {
return this.constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
}
/**
* Method getURI
*
* @return URI string
*/
public String getURI() {
return this.getURIAttr().getNodeValue();
}
/**
* Sets the <code>Id</code> attribute
*
* @param Id ID
*/
public void setId(String id) {
if (id != null) {
this.constructionElement.setAttributeNS(null, Constants._ATT_ID, id);
this.constructionElement.setIdAttributeNS(null, Constants._ATT_ID, true);
} else {
this.constructionElement.removeAttributeNS(null, Constants._ATT_ID);
}
}
/**
* Returns the <code>Id</code> attribute
*
* @return the <code>Id</code> attribute
*/
public String getId() {
return this.constructionElement.getAttributeNS(null, Constants._ATT_ID);
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_KEYINFOREFERENCE;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
@ -27,46 +29,44 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public class KeyName extends SignatureElementProxy implements KeyInfoContent {
/**
* Constructor KeyName
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public KeyName(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor KeyName
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public KeyName(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor KeyName
*
* @param doc
* @param keyName
*/
public KeyName(Document doc, String keyName) {
/**
* Constructor KeyName
*
* @param doc
* @param keyName
*/
public KeyName(Document doc, String keyName) {
super(doc);
super(doc);
this.addText(keyName);
}
this.addText(keyName);
}
/**
* Method getKeyName
*
* @return key name
*/
public String getKeyName() {
return this.getTextFromTextChild();
}
/**
* Method getKeyName
*
* @return key name
*/
public String getKeyName() {
return this.getTextFromTextChild();
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_KEYNAME;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_KEYNAME;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
@ -39,7 +41,7 @@ import org.w3c.dom.Element;
* keys values represented as PCDATA or element types from an external
* namespace.
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
@ -50,12 +52,11 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
* @param dsaKeyValue
*/
public KeyValue(Document doc, DSAKeyValue dsaKeyValue) {
super(doc);
XMLUtils.addReturnToElement(this._constructionElement);
this._constructionElement.appendChild(dsaKeyValue.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
XMLUtils.addReturnToElement(this.constructionElement);
this.constructionElement.appendChild(dsaKeyValue.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
@ -65,12 +66,11 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
* @param rsaKeyValue
*/
public KeyValue(Document doc, RSAKeyValue rsaKeyValue) {
super(doc);
XMLUtils.addReturnToElement(this._constructionElement);
this._constructionElement.appendChild(rsaKeyValue.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
XMLUtils.addReturnToElement(this.constructionElement);
this.constructionElement.appendChild(rsaKeyValue.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
@ -80,12 +80,11 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
* @param unknownKeyValue
*/
public KeyValue(Document doc, Element unknownKeyValue) {
super(doc);
XMLUtils.addReturnToElement(this._constructionElement);
this._constructionElement.appendChild(unknownKeyValue);
XMLUtils.addReturnToElement(this._constructionElement);
XMLUtils.addReturnToElement(this.constructionElement);
this.constructionElement.appendChild(unknownKeyValue);
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
@ -95,21 +94,20 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
* @param pk
*/
public KeyValue(Document doc, PublicKey pk) {
super(doc);
XMLUtils.addReturnToElement(this._constructionElement);
XMLUtils.addReturnToElement(this.constructionElement);
if (pk instanceof java.security.interfaces.DSAPublicKey) {
DSAKeyValue dsa = new DSAKeyValue(this._doc, pk);
DSAKeyValue dsa = new DSAKeyValue(this.doc, pk);
this._constructionElement.appendChild(dsa.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
this.constructionElement.appendChild(dsa.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
} else if (pk instanceof java.security.interfaces.RSAPublicKey) {
RSAKeyValue rsa = new RSAKeyValue(this._doc, pk);
RSAKeyValue rsa = new RSAKeyValue(this.doc, pk);
this._constructionElement.appendChild(rsa.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
this.constructionElement.appendChild(rsa.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
}
@ -120,8 +118,7 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
* @param BaseURI
* @throws XMLSecurityException
*/
public KeyValue(Element element, String BaseURI)
throws XMLSecurityException {
public KeyValue(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
@ -132,22 +129,21 @@ public class KeyValue extends SignatureElementProxy implements KeyInfoContent {
* @throws XMLSecurityException
*/
public PublicKey getPublicKey() throws XMLSecurityException {
Element rsa = XMLUtils.selectDsNode
(this._constructionElement.getFirstChild(),
Constants._TAG_RSAKEYVALUE,0);
Element rsa =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
if (rsa != null) {
RSAKeyValue kv = new RSAKeyValue(rsa, this._baseURI);
RSAKeyValue kv = new RSAKeyValue(rsa, this.baseURI);
return kv.getPublicKey();
}
Element dsa = XMLUtils.selectDsNode
(this._constructionElement.getFirstChild(),
Constants._TAG_DSAKEYVALUE,0);
Element dsa =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
if (dsa != null) {
DSAKeyValue kv = new DSAKeyValue(dsa, this._baseURI);
DSAKeyValue kv = new DSAKeyValue(dsa, this.baseURI);
return kv.getPublicKey();
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
@ -27,47 +29,45 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public class MgmtData extends SignatureElementProxy implements KeyInfoContent {
/**
* Constructor MgmtData
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public MgmtData(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor MgmtData
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public MgmtData(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor MgmtData
*
* @param doc
* @param mgmtData
*/
public MgmtData(Document doc, String mgmtData) {
/**
* Constructor MgmtData
*
* @param doc
* @param mgmtData
*/
public MgmtData(Document doc, String mgmtData) {
super(doc);
super(doc);
this.addText(mgmtData);
}
this.addText(mgmtData);
}
/**
* Method getMgmtData
*
* @return the managment data
*/
public String getMgmtData() {
return this.getTextFromTextChild();
}
/**
* Method getMgmtData
*
* @return the managment data
*/
public String getMgmtData() {
return this.getTextFromTextChild();
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_MGMTDATA;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_MGMTDATA;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
@ -26,25 +28,24 @@ import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
* @author $Author: coheigea $
* $todo$ Implement
*/
public class PGPData extends SignatureElementProxy implements KeyInfoContent {
/**
* Constructor PGPData
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public PGPData(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor PGPData
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public PGPData(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_PGPDATA;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_PGPDATA;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
@ -30,118 +32,104 @@ import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class RetrievalMethod extends SignatureElementProxy
implements KeyInfoContent {
public class RetrievalMethod extends SignatureElementProxy implements KeyInfoContent {
//J-
/** DSA retrieval */
public static final String TYPE_DSA = Constants.SignatureSpecNS + "DSAKeyValue";
/** RSA retrieval */
public static final String TYPE_RSA = Constants.SignatureSpecNS + "RSAKeyValue";
/** PGP retrieval */
public static final String TYPE_PGP = Constants.SignatureSpecNS + "PGPData";
/** SPKI retrieval */
public static final String TYPE_SPKI = Constants.SignatureSpecNS + "SPKIData";
/** MGMT retrieval */
public static final String TYPE_MGMT = Constants.SignatureSpecNS + "MgmtData";
/** X509 retrieval */
public static final String TYPE_X509 = Constants.SignatureSpecNS + "X509Data";
/** RAWX509 retrieval */
public static final String TYPE_RAWX509 = Constants.SignatureSpecNS + "rawX509Certificate";
//J+
public static final String TYPE_DSA = Constants.SignatureSpecNS + "DSAKeyValue";
/** RSA retrieval */
public static final String TYPE_RSA = Constants.SignatureSpecNS + "RSAKeyValue";
/** PGP retrieval */
public static final String TYPE_PGP = Constants.SignatureSpecNS + "PGPData";
/** SPKI retrieval */
public static final String TYPE_SPKI = Constants.SignatureSpecNS + "SPKIData";
/** MGMT retrieval */
public static final String TYPE_MGMT = Constants.SignatureSpecNS + "MgmtData";
/** X509 retrieval */
public static final String TYPE_X509 = Constants.SignatureSpecNS + "X509Data";
/** RAWX509 retrieval */
public static final String TYPE_RAWX509 = Constants.SignatureSpecNS + "rawX509Certificate";
/**
* Constructor RetrievalMethod
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public RetrievalMethod(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor RetrievalMethod
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public RetrievalMethod(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor RetrievalMethod
*
* @param doc
* @param URI
* @param transforms
* @param Type
*/
public RetrievalMethod(Document doc, String URI, Transforms transforms,
String Type) {
/**
* Constructor RetrievalMethod
*
* @param doc
* @param URI
* @param transforms
* @param Type
*/
public RetrievalMethod(Document doc, String URI, Transforms transforms, String Type) {
super(doc);
super(doc);
this.constructionElement.setAttributeNS(null, Constants._ATT_URI, URI);
this._constructionElement.setAttributeNS(null, Constants._ATT_URI, URI);
if (Type != null) {
this.constructionElement.setAttributeNS(null, Constants._ATT_TYPE, Type);
}
if (Type != null) {
this._constructionElement.setAttributeNS(null, Constants._ATT_TYPE, Type);
}
if (transforms != null) {
this.constructionElement.appendChild(transforms.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
}
if (transforms != null) {
this._constructionElement.appendChild(transforms.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
}
}
/**
* Method getURIAttr
*
* @return the URI attribute
*/
public Attr getURIAttr() {
return this.constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
}
/**
* Method getURIAttr
*
* @return the URI attribute
*/
public Attr getURIAttr() {
return this._constructionElement.getAttributeNodeNS(null, Constants._ATT_URI);
}
/**
* Method getURI
*
* @return URI string
*/
public String getURI() {
return this.getURIAttr().getNodeValue();
}
/**
* Method getURI
*
*
* @return URI string
*/
public String getURI() {
return this.getURIAttr().getNodeValue();
}
/** @return the type*/
public String getType() {
return this.constructionElement.getAttributeNS(null, Constants._ATT_TYPE);
}
/** @return the type*/
public String getType() {
return this._constructionElement.getAttributeNS(null, Constants._ATT_TYPE);
}
/**
* Method getTransforms
*
* @throws XMLSecurityException
* @return the transformations
*/
public Transforms getTransforms() throws XMLSecurityException {
try {
Element transformsElem =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_TRANSFORMS, 0);
/**
* Method getTransforms
*
*
* @throws XMLSecurityException
* @return the transforamitons
*/
public Transforms getTransforms() throws XMLSecurityException {
if (transformsElem != null) {
return new Transforms(transformsElem, this.baseURI);
}
try {
Element transformsElem =
XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants
._TAG_TRANSFORMS, 0);
return null;
} catch (XMLSignatureException ex) {
throw new XMLSecurityException("empty", ex);
}
}
if (transformsElem != null) {
return new Transforms(transformsElem, this._baseURI);
}
return null;
} catch (XMLSignatureException ex) {
throw new XMLSecurityException("empty", ex);
}
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_RETRIEVALMETHOD;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_RETRIEVALMETHOD;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
@ -26,26 +28,25 @@ import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
* @author $Author: coheigea $
* $todo$ implement
*/
public class SPKIData extends SignatureElementProxy implements KeyInfoContent {
/**
* Constructor SPKIData
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public SPKIData(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor SPKIData
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public SPKIData(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_SPKIDATA;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_SPKIDATA;
}
}

View File

@ -2,32 +2,33 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509CRL;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Digest;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509IssuerSerial;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SubjectName;
@ -38,447 +39,501 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
*
* @author $Author: mullan $
*/
public class X509Data extends SignatureElementProxy implements KeyInfoContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(X509Data.class.getName());
/**
* Constructor X509Data
*
* @param doc
*/
public X509Data(Document doc) {
/**
* Constructor X509Data
*
* @param doc
*/
public X509Data(Document doc) {
super(doc);
super(doc);
XMLUtils.addReturnToElement(this.constructionElement);
}
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Constructor X509Data
*
* @param element
* @param baseURI
* @throws XMLSecurityException
*/
public X509Data(Element element, String baseURI) throws XMLSecurityException {
super(element, baseURI);
/**
* Constructor X509Data
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public X509Data(Element element, String BaseURI)
throws XMLSecurityException {
Node sibling = this.constructionElement.getFirstChild();
while (sibling != null) {
if (sibling.getNodeType() != Node.ELEMENT_NODE) {
sibling = sibling.getNextSibling();
continue;
}
return;
}
/* No Elements found */
Object exArgs[] = { "Elements", Constants._TAG_X509DATA };
throw new XMLSecurityException("xml.WrongContent", exArgs);
}
super(element, BaseURI);
Node sibling=this._constructionElement.getFirstChild();
while (sibling!=null) {
if (sibling.getNodeType()!=Node.ELEMENT_NODE) {
sibling=sibling.getNextSibling();
continue;
}
return;
}
/* No Elements found */
Object exArgs[] = { "Elements", Constants._TAG_X509DATA };
throw new XMLSecurityException("xml.WrongContent", exArgs);
}
/**
* Method addIssuerSerial
*
* @param X509IssuerName
* @param X509SerialNumber
*/
public void addIssuerSerial(String X509IssuerName, BigInteger X509SerialNumber) {
this.add(new XMLX509IssuerSerial(this.doc, X509IssuerName, X509SerialNumber));
}
/**
* Method addIssuerSerial
*
* @param X509IssuerName
* @param X509SerialNumber
*/
public void addIssuerSerial(String X509IssuerName,
BigInteger X509SerialNumber) {
this.add(new XMLX509IssuerSerial(this._doc, X509IssuerName,
X509SerialNumber));
}
/**
* Method addIssuerSerial
*
* @param X509IssuerName
* @param X509SerialNumber
*/
public void addIssuerSerial(String X509IssuerName, String X509SerialNumber) {
this.add(new XMLX509IssuerSerial(this.doc, X509IssuerName, X509SerialNumber));
}
/**
* Method addIssuerSerial
*
* @param X509IssuerName
* @param X509SerialNumber
*/
public void addIssuerSerial(String X509IssuerName, String X509SerialNumber) {
this.add(new XMLX509IssuerSerial(this._doc, X509IssuerName,
X509SerialNumber));
}
/**
* Method addIssuerSerial
*
* @param X509IssuerName
* @param X509SerialNumber
*/
public void addIssuerSerial(String X509IssuerName, int X509SerialNumber) {
this.add(new XMLX509IssuerSerial(this.doc, X509IssuerName, X509SerialNumber));
}
/**
* Method addIssuerSerial
*
* @param X509IssuerName
* @param X509SerialNumber
*/
public void addIssuerSerial(String X509IssuerName, int X509SerialNumber) {
this.add(new XMLX509IssuerSerial(this._doc, X509IssuerName,
X509SerialNumber));
}
/**
* Method add
*
* @param xmlX509IssuerSerial
*/
public void add(XMLX509IssuerSerial xmlX509IssuerSerial) {
/**
* Method add
*
* @param xmlX509IssuerSerial
*/
public void add(XMLX509IssuerSerial xmlX509IssuerSerial) {
this.constructionElement.appendChild(xmlX509IssuerSerial.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
this._constructionElement
.appendChild(xmlX509IssuerSerial.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Method addSKI
*
* @param skiBytes
*/
public void addSKI(byte[] skiBytes) {
this.add(new XMLX509SKI(this.doc, skiBytes));
}
/**
* Method addSKI
*
* @param skiBytes
*/
public void addSKI(byte[] skiBytes) {
this.add(new XMLX509SKI(this._doc, skiBytes));
}
/**
* Method addSKI
*
* @param x509certificate
* @throws XMLSecurityException
*/
public void addSKI(X509Certificate x509certificate)
throws XMLSecurityException {
this.add(new XMLX509SKI(this.doc, x509certificate));
}
/**
* Method addSKI
*
* @param x509certificate
* @throws XMLSecurityException
*/
public void addSKI(X509Certificate x509certificate)
throws XMLSecurityException {
this.add(new XMLX509SKI(this._doc, x509certificate));
}
/**
* Method add
*
* @param xmlX509SKI
*/
public void add(XMLX509SKI xmlX509SKI) {
this.constructionElement.appendChild(xmlX509SKI.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
* Method add
*
* @param xmlX509SKI
*/
public void add(XMLX509SKI xmlX509SKI) {
this._constructionElement.appendChild(xmlX509SKI.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Method addSubjectName
*
* @param subjectName
*/
public void addSubjectName(String subjectName) {
this.add(new XMLX509SubjectName(this.doc, subjectName));
}
/**
* Method addSubjectName
*
* @param subjectName
*/
public void addSubjectName(String subjectName) {
this.add(new XMLX509SubjectName(this._doc, subjectName));
}
/**
* Method addSubjectName
*
* @param x509certificate
*/
public void addSubjectName(X509Certificate x509certificate) {
this.add(new XMLX509SubjectName(this.doc, x509certificate));
}
/**
* Method addSubjectName
*
* @param x509certificate
*/
public void addSubjectName(X509Certificate x509certificate) {
this.add(new XMLX509SubjectName(this._doc, x509certificate));
}
/**
* Method add
*
* @param xmlX509SubjectName
*/
public void add(XMLX509SubjectName xmlX509SubjectName) {
this.constructionElement.appendChild(xmlX509SubjectName.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
* Method add
*
* @param xmlX509SubjectName
*/
public void add(XMLX509SubjectName xmlX509SubjectName) {
this._constructionElement.appendChild(xmlX509SubjectName.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Method addCertificate
*
* @param x509certificate
* @throws XMLSecurityException
*/
public void addCertificate(X509Certificate x509certificate)
throws XMLSecurityException {
this.add(new XMLX509Certificate(this.doc, x509certificate));
}
/**
* Method addCertificate
*
* @param x509certificate
* @throws XMLSecurityException
*/
public void addCertificate(X509Certificate x509certificate)
throws XMLSecurityException {
this.add(new XMLX509Certificate(this._doc, x509certificate));
}
/**
* Method addCertificate
*
* @param x509certificateBytes
*/
public void addCertificate(byte[] x509certificateBytes) {
this.add(new XMLX509Certificate(this.doc, x509certificateBytes));
}
/**
* Method addCertificate
*
* @param x509certificateBytes
*/
public void addCertificate(byte[] x509certificateBytes) {
this.add(new XMLX509Certificate(this._doc, x509certificateBytes));
}
/**
* Method add
*
* @param xmlX509Certificate
*/
public void add(XMLX509Certificate xmlX509Certificate) {
this.constructionElement.appendChild(xmlX509Certificate.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
* Method add
*
* @param xmlX509Certificate
*/
public void add(XMLX509Certificate xmlX509Certificate) {
this._constructionElement.appendChild(xmlX509Certificate.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Method addCRL
*
* @param crlBytes
*/
public void addCRL(byte[] crlBytes) {
this.add(new XMLX509CRL(this.doc, crlBytes));
}
/**
* Method addCRL
*
* @param crlBytes
*/
public void addCRL(byte[] crlBytes) {
this.add(new XMLX509CRL(this._doc, crlBytes));
}
/**
* Method add
*
* @param xmlX509CRL
*/
public void add(XMLX509CRL xmlX509CRL) {
this.constructionElement.appendChild(xmlX509CRL.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
* Method add
*
* @param xmlX509CRL
*/
public void add(XMLX509CRL xmlX509CRL) {
this._constructionElement.appendChild(xmlX509CRL.getElement());
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Method addDigest
*
* @param x509certificate
* @param algorithmURI
* @throws XMLSecurityException
*/
public void addDigest(X509Certificate x509certificate, String algorithmURI)
throws XMLSecurityException {
this.add(new XMLX509Digest(this.doc, x509certificate, algorithmURI));
}
/**
* Method addUnknownElement
*
* @param element
*/
public void addUnknownElement(Element element) {
this._constructionElement.appendChild(element);
XMLUtils.addReturnToElement(this._constructionElement);
}
/**
* Method addDigest
*
* @param x509CertificateDigestByes
* @param algorithmURI
*/
public void addDigest(byte[] x509certificateDigestBytes, String algorithmURI) {
this.add(new XMLX509Digest(this.doc, x509certificateDigestBytes, algorithmURI));
}
/**
* Method lengthIssuerSerial
*
* @return the number of IssuerSerial elements in this X509Data
*/
public int lengthIssuerSerial() {
return this.length(Constants.SignatureSpecNS,
Constants._TAG_X509ISSUERSERIAL);
}
/**
* Method add
*
* @param XMLX509Digest
*/
public void add(XMLX509Digest xmlX509Digest) {
this.constructionElement.appendChild(xmlX509Digest.getElement());
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
* Method lengthSKI
*
* @return the number of SKI elements in this X509Data
*/
public int lengthSKI() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509SKI);
}
/**
* Method addUnknownElement
*
* @param element
*/
public void addUnknownElement(Element element) {
this.constructionElement.appendChild(element);
XMLUtils.addReturnToElement(this.constructionElement);
}
/**
* Method lengthSubjectName
*
* @return the number of SubjectName elements in this X509Data
*/
public int lengthSubjectName() {
return this.length(Constants.SignatureSpecNS,
Constants._TAG_X509SUBJECTNAME);
}
/**
* Method lengthIssuerSerial
*
* @return the number of IssuerSerial elements in this X509Data
*/
public int lengthIssuerSerial() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509ISSUERSERIAL);
}
/**
* Method lengthCertificate
*
* @return the number of Certificate elements in this X509Data
*/
public int lengthCertificate() {
return this.length(Constants.SignatureSpecNS,
Constants._TAG_X509CERTIFICATE);
}
/**
* Method lengthSKI
*
* @return the number of SKI elements in this X509Data
*/
public int lengthSKI() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509SKI);
}
/**
* Method lengthCRL
*
* @return the number of CRL elements in this X509Data
*/
public int lengthCRL() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509CRL);
}
/**
* Method lengthSubjectName
*
* @return the number of SubjectName elements in this X509Data
*/
public int lengthSubjectName() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509SUBJECTNAME);
}
/**
* Method lengthUnknownElement
*
* @return the number of UnknownElement elements in this X509Data
*/
public int lengthUnknownElement() {
/**
* Method lengthCertificate
*
* @return the number of Certificate elements in this X509Data
*/
public int lengthCertificate() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509CERTIFICATE);
}
int result = 0;
Node n=this._constructionElement.getFirstChild();
while (n!=null){
/**
* Method lengthCRL
*
* @return the number of CRL elements in this X509Data
*/
public int lengthCRL() {
return this.length(Constants.SignatureSpecNS, Constants._TAG_X509CRL);
}
if ((n.getNodeType() == Node.ELEMENT_NODE)
&&!n.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
result += 1;
}
n=n.getNextSibling();
}
/**
* Method lengthDigest
*
* @return the number of X509Digest elements in this X509Data
*/
public int lengthDigest() {
return this.length(Constants.SignatureSpec11NS, Constants._TAG_X509DIGEST);
}
return result;
}
/**
* Method lengthUnknownElement
*
* @return the number of UnknownElement elements in this X509Data
*/
public int lengthUnknownElement() {
int result = 0;
Node n = this.constructionElement.getFirstChild();
while (n != null){
if ((n.getNodeType() == Node.ELEMENT_NODE)
&& !n.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
result++;
}
n = n.getNextSibling();
}
/**
* Method itemIssuerSerial
*
* @param i
* @return the X509IssuerSerial, null if not present
* @throws XMLSecurityException
*/
public XMLX509IssuerSerial itemIssuerSerial(int i)
throws XMLSecurityException {
return result;
}
Element e =
XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_X509ISSUERSERIAL,i);
/**
* Method itemIssuerSerial
*
* @param i
* @return the X509IssuerSerial, null if not present
* @throws XMLSecurityException
*/
public XMLX509IssuerSerial itemIssuerSerial(int i) throws XMLSecurityException {
Element e =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_X509ISSUERSERIAL, i);
if (e != null) {
return new XMLX509IssuerSerial(e, this._baseURI);
}
return null;
}
if (e != null) {
return new XMLX509IssuerSerial(e, this.baseURI);
}
return null;
}
/**
* Method itemSKI
*
* @param i
* @return the X509SKI, null if not present
* @throws XMLSecurityException
*/
public XMLX509SKI itemSKI(int i) throws XMLSecurityException {
/**
* Method itemSKI
*
* @param i
* @return the X509SKI, null if not present
* @throws XMLSecurityException
*/
public XMLX509SKI itemSKI(int i) throws XMLSecurityException {
Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_X509SKI,i);
Element e =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_X509SKI, i);
if (e != null) {
return new XMLX509SKI(e, this._baseURI);
}
return null;
}
if (e != null) {
return new XMLX509SKI(e, this.baseURI);
}
return null;
}
/**
* Method itemSubjectName
*
* @param i
* @return the X509SubjectName, null if not present
* @throws XMLSecurityException
*/
public XMLX509SubjectName itemSubjectName(int i)
throws XMLSecurityException {
/**
* Method itemSubjectName
*
* @param i
* @return the X509SubjectName, null if not present
* @throws XMLSecurityException
*/
public XMLX509SubjectName itemSubjectName(int i) throws XMLSecurityException {
Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_X509SUBJECTNAME,i);
Element e =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_X509SUBJECTNAME, i);
if (e != null) {
return new XMLX509SubjectName(e, this._baseURI);
}
return null;
}
if (e != null) {
return new XMLX509SubjectName(e, this.baseURI);
}
return null;
}
/**
* Method itemCertificate
*
* @param i
* @return the X509Certifacte, null if not present
* @throws XMLSecurityException
*/
public XMLX509Certificate itemCertificate(int i)
throws XMLSecurityException {
/**
* Method itemCertificate
*
* @param i
* @return the X509Certifacte, null if not present
* @throws XMLSecurityException
*/
public XMLX509Certificate itemCertificate(int i) throws XMLSecurityException {
Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_X509CERTIFICATE,i);
Element e =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_X509CERTIFICATE, i);
if (e != null) {
return new XMLX509Certificate(e, this._baseURI);
}
return null;
}
if (e != null) {
return new XMLX509Certificate(e, this.baseURI);
}
return null;
}
/**
* Method itemCRL
*
* @param i
* @return the X509CRL, null if not present
* @throws XMLSecurityException
*/
public XMLX509CRL itemCRL(int i) throws XMLSecurityException {
/**
* Method itemCRL
*
* @param i
* @return the X509CRL, null if not present
* @throws XMLSecurityException
*/
public XMLX509CRL itemCRL(int i) throws XMLSecurityException {
Element e = XMLUtils.selectDsNode(this._constructionElement.getFirstChild(),
Constants._TAG_X509CRL,i);
Element e =
XMLUtils.selectDsNode(
this.constructionElement.getFirstChild(), Constants._TAG_X509CRL, i);
if (e != null) {
return new XMLX509CRL(e, this._baseURI);
}
return null;
}
if (e != null) {
return new XMLX509CRL(e, this.baseURI);
}
return null;
}
/**
* Method itemUnknownElement
*
* @param i
* @return the Unknown Element at i
* TODO implement
**/
public Element itemUnknownElement(int i) {
log.log(java.util.logging.Level.FINE, "itemUnknownElement not implemented:"+i);
return null;
}
/**
* Method itemDigest
*
* @param i
* @return the X509Digest, null if not present
* @throws XMLSecurityException
*/
public XMLX509Digest itemDigest(int i) throws XMLSecurityException {
/**
* Method containsIssuerSerial
*
* @return true if this X509Data contains a IssuerSerial
*/
public boolean containsIssuerSerial() {
return this.lengthIssuerSerial() > 0;
}
Element e =
XMLUtils.selectDs11Node(
this.constructionElement.getFirstChild(), Constants._TAG_X509DIGEST, i);
/**
* Method containsSKI
*
* @return true if this X509Data contains a SKI
*/
public boolean containsSKI() {
return this.lengthSKI() > 0;
}
if (e != null) {
return new XMLX509Digest(e, this.baseURI);
}
return null;
}
/**
* Method containsSubjectName
*
* @return true if this X509Data contains a SubjectName
*/
public boolean containsSubjectName() {
return this.lengthSubjectName() > 0;
}
/**
* Method itemUnknownElement
*
* @param i
* @return the Unknown Element at i
* TODO implement
**/
public Element itemUnknownElement(int i) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "itemUnknownElement not implemented:" + i);
}
return null;
}
/**
* Method containsCertificate
*
* @return true if this X509Data contains a Certificate
*/
public boolean containsCertificate() {
return this.lengthCertificate() > 0;
}
/**
* Method containsIssuerSerial
*
* @return true if this X509Data contains a IssuerSerial
*/
public boolean containsIssuerSerial() {
return this.lengthIssuerSerial() > 0;
}
/**
* Method containsCRL
*
* @return true if this X509Data contains a CRL
*/
public boolean containsCRL() {
return this.lengthCRL() > 0;
}
/**
* Method containsSKI
*
* @return true if this X509Data contains a SKI
*/
public boolean containsSKI() {
return this.lengthSKI() > 0;
}
/**
* Method containsUnknownElement
*
* @return true if this X509Data contains an UnknownElement
*/
public boolean containsUnknownElement() {
return this.lengthUnknownElement() > 0;
}
/**
* Method containsSubjectName
*
* @return true if this X509Data contains a SubjectName
*/
public boolean containsSubjectName() {
return this.lengthSubjectName() > 0;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509DATA;
}
/**
* Method containsCertificate
*
* @return true if this X509Data contains a Certificate
*/
public boolean containsCertificate() {
return this.lengthCertificate() > 0;
}
/**
* Method containsDigest
*
* @return true if this X509Data contains an X509Digest
*/
public boolean containsDigest() {
return this.lengthDigest() > 0;
}
/**
* Method containsCRL
*
* @return true if this X509Data contains a CRL
*/
public boolean containsCRL() {
return this.lengthCRL() > 0;
}
/**
* Method containsUnknownElement
*
* @return true if this X509Data contains an UnknownElement
*/
public boolean containsUnknownElement() {
return this.lengthUnknownElement() > 0;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509DATA;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.keyvalues;
@ -37,104 +39,93 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class DSAKeyValue extends SignatureElementProxy
implements KeyValueContent {
public class DSAKeyValue extends SignatureElementProxy implements KeyValueContent {
/**
* Constructor DSAKeyValue
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public DSAKeyValue(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor DSAKeyValue
*
* @param element
* @param baseURI
* @throws XMLSecurityException
*/
public DSAKeyValue(Element element, String baseURI) throws XMLSecurityException {
super(element, baseURI);
}
/**
* Constructor DSAKeyValue
*
* @param doc
* @param P
* @param Q
* @param G
* @param Y
*/
public DSAKeyValue(Document doc, BigInteger P, BigInteger Q, BigInteger G,
BigInteger Y) {
/**
* Constructor DSAKeyValue
*
* @param doc
* @param P
* @param Q
* @param G
* @param Y
*/
public DSAKeyValue(Document doc, BigInteger P, BigInteger Q, BigInteger G, BigInteger Y) {
super(doc);
super(doc);
XMLUtils.addReturnToElement(this.constructionElement);
this.addBigIntegerElement(P, Constants._TAG_P);
this.addBigIntegerElement(Q, Constants._TAG_Q);
this.addBigIntegerElement(G, Constants._TAG_G);
this.addBigIntegerElement(Y, Constants._TAG_Y);
}
XMLUtils.addReturnToElement(this._constructionElement);
this.addBigIntegerElement(P, Constants._TAG_P);
this.addBigIntegerElement(Q, Constants._TAG_Q);
this.addBigIntegerElement(G, Constants._TAG_G);
this.addBigIntegerElement(Y, Constants._TAG_Y);
}
/**
* Constructor DSAKeyValue
*
* @param doc
* @param key
* @throws IllegalArgumentException
*/
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
super(doc);
/**
* Constructor DSAKeyValue
*
* @param doc
* @param key
* @throws IllegalArgumentException
*/
public DSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
XMLUtils.addReturnToElement(this.constructionElement);
super(doc);
if (key instanceof java.security.interfaces.DSAPublicKey) {
this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(), Constants._TAG_P);
this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(), Constants._TAG_Q);
this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(), Constants._TAG_G);
this.addBigIntegerElement(((DSAPublicKey) key).getY(), Constants._TAG_Y);
} else {
Object exArgs[] = { Constants._TAG_DSAKEYVALUE, key.getClass().getName() };
XMLUtils.addReturnToElement(this._constructionElement);
throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
}
}
if (key instanceof java.security.interfaces.DSAPublicKey) {
this.addBigIntegerElement(((DSAPublicKey) key).getParams().getP(),
Constants._TAG_P);
this.addBigIntegerElement(((DSAPublicKey) key).getParams().getQ(),
Constants._TAG_Q);
this.addBigIntegerElement(((DSAPublicKey) key).getParams().getG(),
Constants._TAG_G);
this.addBigIntegerElement(((DSAPublicKey) key).getY(),
Constants._TAG_Y);
} else {
Object exArgs[] = { Constants._TAG_DSAKEYVALUE,
key.getClass().getName() };
/** @inheritDoc */
public PublicKey getPublicKey() throws XMLSecurityException {
try {
DSAPublicKeySpec pkspec =
new DSAPublicKeySpec(
this.getBigIntegerFromChildElement(
Constants._TAG_Y, Constants.SignatureSpecNS
),
this.getBigIntegerFromChildElement(
Constants._TAG_P, Constants.SignatureSpecNS
),
this.getBigIntegerFromChildElement(
Constants._TAG_Q, Constants.SignatureSpecNS
),
this.getBigIntegerFromChildElement(
Constants._TAG_G, Constants.SignatureSpecNS
)
);
KeyFactory dsaFactory = KeyFactory.getInstance("DSA");
PublicKey pk = dsaFactory.generatePublic(pkspec);
throw new IllegalArgumentException(I18n
.translate("KeyValue.IllegalArgument", exArgs));
}
}
return pk;
} catch (NoSuchAlgorithmException ex) {
throw new XMLSecurityException("empty", ex);
} catch (InvalidKeySpecException ex) {
throw new XMLSecurityException("empty", ex);
}
}
/** @inheritDoc */
public PublicKey getPublicKey() throws XMLSecurityException {
try {
DSAPublicKeySpec pkspec =
new DSAPublicKeySpec(this
.getBigIntegerFromChildElement(Constants._TAG_Y, Constants
.SignatureSpecNS), this
.getBigIntegerFromChildElement(Constants._TAG_P, Constants
.SignatureSpecNS), this
.getBigIntegerFromChildElement(Constants._TAG_Q, Constants
.SignatureSpecNS), this
.getBigIntegerFromChildElement(Constants
._TAG_G, Constants.SignatureSpecNS));
KeyFactory dsaFactory = KeyFactory.getInstance("DSA");
PublicKey pk = dsaFactory.generatePublic(pkspec);
return pk;
} catch (NoSuchAlgorithmException ex) {
throw new XMLSecurityException("empty", ex);
} catch (InvalidKeySpecException ex) {
throw new XMLSecurityException("empty", ex);
}
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DSAKEYVALUE;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_DSAKEYVALUE;
}
}

View File

@ -2,46 +2,38 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.keyvalues;
import java.security.PublicKey;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
*
*
*
*
* @author $Author: mullan $
*
*/
public interface KeyValueContent {
/**
* Method getPublicKey
*
* @return the public key
* @throws XMLSecurityException
*/
public PublicKey getPublicKey()
throws XMLSecurityException;
/**
* Method getPublicKey
*
* @return the public key
* @throws XMLSecurityException
*/
PublicKey getPublicKey() throws XMLSecurityException;
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.keyvalues;
@ -37,93 +39,86 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class RSAKeyValue extends SignatureElementProxy
implements KeyValueContent {
public class RSAKeyValue extends SignatureElementProxy implements KeyValueContent {
/**
* Constructor RSAKeyValue
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public RSAKeyValue(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor RSAKeyValue
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public RSAKeyValue(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor RSAKeyValue
*
* @param doc
* @param modulus
* @param exponent
*/
public RSAKeyValue(Document doc, BigInteger modulus, BigInteger exponent) {
/**
* Constructor RSAKeyValue
*
* @param doc
* @param modulus
* @param exponent
*/
public RSAKeyValue(Document doc, BigInteger modulus, BigInteger exponent) {
super(doc);
super(doc);
XMLUtils.addReturnToElement(this.constructionElement);
this.addBigIntegerElement(modulus, Constants._TAG_MODULUS);
this.addBigIntegerElement(exponent, Constants._TAG_EXPONENT);
}
XMLUtils.addReturnToElement(this._constructionElement);
this.addBigIntegerElement(modulus, Constants._TAG_MODULUS);
this.addBigIntegerElement(exponent, Constants._TAG_EXPONENT);
}
/**
* Constructor RSAKeyValue
*
* @param doc
* @param key
* @throws IllegalArgumentException
*/
public RSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
super(doc);
/**
* Constructor RSAKeyValue
*
* @param doc
* @param key
* @throws IllegalArgumentException
*/
public RSAKeyValue(Document doc, Key key) throws IllegalArgumentException {
XMLUtils.addReturnToElement(this.constructionElement);
super(doc);
if (key instanceof java.security.interfaces.RSAPublicKey ) {
this.addBigIntegerElement(
((RSAPublicKey) key).getModulus(), Constants._TAG_MODULUS
);
this.addBigIntegerElement(
((RSAPublicKey) key).getPublicExponent(), Constants._TAG_EXPONENT
);
} else {
Object exArgs[] = { Constants._TAG_RSAKEYVALUE, key.getClass().getName() };
XMLUtils.addReturnToElement(this._constructionElement);
throw new IllegalArgumentException(I18n.translate("KeyValue.IllegalArgument", exArgs));
}
}
if (key instanceof java.security.interfaces.RSAPublicKey ) {
this.addBigIntegerElement(((RSAPublicKey) key).getModulus(),
Constants._TAG_MODULUS);
this.addBigIntegerElement(((RSAPublicKey) key).getPublicExponent(),
Constants._TAG_EXPONENT);
} else {
Object exArgs[] = { Constants._TAG_RSAKEYVALUE,
key.getClass().getName() };
/** @inheritDoc */
public PublicKey getPublicKey() throws XMLSecurityException {
try {
KeyFactory rsaFactory = KeyFactory.getInstance("RSA");
throw new IllegalArgumentException(I18n
.translate("KeyValue.IllegalArgument", exArgs));
}
}
RSAPublicKeySpec rsaKeyspec =
new RSAPublicKeySpec(
this.getBigIntegerFromChildElement(
Constants._TAG_MODULUS, Constants.SignatureSpecNS
),
this.getBigIntegerFromChildElement(
Constants._TAG_EXPONENT, Constants.SignatureSpecNS
)
);
PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);
/** @inheritDoc */
public PublicKey getPublicKey() throws XMLSecurityException {
return pk;
} catch (NoSuchAlgorithmException ex) {
throw new XMLSecurityException("empty", ex);
} catch (InvalidKeySpecException ex) {
throw new XMLSecurityException("empty", ex);
}
}
try {
KeyFactory rsaFactory = KeyFactory.getInstance("RSA");
// KeyFactory rsaFactory = KeyFactory.getInstance(JCE_RSA);
RSAPublicKeySpec rsaKeyspec =
new RSAPublicKeySpec(this
.getBigIntegerFromChildElement(Constants._TAG_MODULUS, Constants
.SignatureSpecNS), this
.getBigIntegerFromChildElement(Constants
._TAG_EXPONENT, Constants.SignatureSpecNS));
PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);
return pk;
} catch (NoSuchAlgorithmException ex) {
throw new XMLSecurityException("empty", ex);
} catch (InvalidKeySpecException ex) {
throw new XMLSecurityException("empty", ex);
}
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_RSAKEYVALUE;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_RSAKEYVALUE;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
@ -26,51 +28,43 @@ import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*
*/
public class XMLX509CRL extends SignatureElementProxy
implements XMLX509DataContent {
public class XMLX509CRL extends SignatureElementProxy implements XMLX509DataContent {
/**
* Constructor XMLX509CRL
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509CRL(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor XMLX509CRL
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509CRL(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor X509CRL
*
* @param doc
* @param crlBytes
*/
public XMLX509CRL(Document doc, byte[] crlBytes) {
/**
* Constructor X509CRL
*
* @param doc
* @param crlBytes
*/
public XMLX509CRL(Document doc, byte[] crlBytes) {
super(doc);
super(doc);
this.addBase64Text(crlBytes);
}
this.addBase64Text(crlBytes);
}
/**
* Method getCRLBytes
*
* @return the CRL bytes
* @throws XMLSecurityException
*/
public byte[] getCRLBytes() throws XMLSecurityException {
return this.getBytesFromTextChild();
}
/**
* Method getCRLBytes
*
* @return the CRL bytes
* @throws XMLSecurityException
*/
public byte[] getCRLBytes() throws XMLSecurityException {
return this.getBytesFromTextChild();
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509CRL;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509CRL;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
@ -25,6 +27,7 @@ import java.security.PublicKey;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
@ -32,135 +35,134 @@ import com.sun.org.apache.xml.internal.security.utils.SignatureElementProxy;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class XMLX509Certificate extends SignatureElementProxy
implements XMLX509DataContent {
public class XMLX509Certificate extends SignatureElementProxy implements XMLX509DataContent {
/** Field JCA_CERT_ID */
public static final String JCA_CERT_ID = "X.509";
/** Field JCA_CERT_ID */
public static final String JCA_CERT_ID = "X.509";
/**
* Constructor X509Certificate
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509Certificate(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor X509Certificate
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509Certificate(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor X509Certificate
*
* @param doc
* @param certificateBytes
*/
public XMLX509Certificate(Document doc, byte[] certificateBytes) {
/**
* Constructor X509Certificate
*
* @param doc
* @param certificateBytes
*/
public XMLX509Certificate(Document doc, byte[] certificateBytes) {
super(doc);
super(doc);
this.addBase64Text(certificateBytes);
}
this.addBase64Text(certificateBytes);
}
/**
* Constructor XMLX509Certificate
*
* @param doc
* @param x509certificate
* @throws XMLSecurityException
*/
public XMLX509Certificate(Document doc, X509Certificate x509certificate)
throws XMLSecurityException {
super(doc);
/**
* Constructor XMLX509Certificate
*
* @param doc
* @param x509certificate
* @throws XMLSecurityException
*/
public XMLX509Certificate(Document doc, X509Certificate x509certificate)
throws XMLSecurityException {
try {
this.addBase64Text(x509certificate.getEncoded());
} catch (java.security.cert.CertificateEncodingException ex) {
throw new XMLSecurityException("empty", ex);
}
}
super(doc);
/**
* Method getCertificateBytes
*
* @return the certificate bytes
* @throws XMLSecurityException
*/
public byte[] getCertificateBytes() throws XMLSecurityException {
return this.getBytesFromTextChild();
}
try {
this.addBase64Text(x509certificate.getEncoded());
} catch (java.security.cert.CertificateEncodingException ex) {
throw new XMLSecurityException("empty", ex);
}
}
/**
* Method getX509Certificate
*
* @return the x509 certificate
* @throws XMLSecurityException
*/
public X509Certificate getX509Certificate() throws XMLSecurityException {
try {
byte certbytes[] = this.getCertificateBytes();
CertificateFactory certFact =
CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
X509Certificate cert =
(X509Certificate) certFact.generateCertificate(
new ByteArrayInputStream(certbytes)
);
/**
* Method getCertificateBytes
*
* @return the certificate bytes
* @throws XMLSecurityException
*/
public byte[] getCertificateBytes() throws XMLSecurityException {
return this.getBytesFromTextChild();
}
if (cert != null) {
return cert;
}
/**
* Method getX509Certificate
*
* @return the x509 certificate
* @throws XMLSecurityException
*/
public X509Certificate getX509Certificate() throws XMLSecurityException {
return null;
} catch (CertificateException ex) {
throw new XMLSecurityException("empty", ex);
}
}
try {
byte certbytes[] = this.getCertificateBytes();
CertificateFactory certFact =
CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
X509Certificate cert =
(X509Certificate) certFact
.generateCertificate(new ByteArrayInputStream(certbytes));
/**
* Method getPublicKey
*
* @return the publickey
* @throws XMLSecurityException
*/
public PublicKey getPublicKey() throws XMLSecurityException {
X509Certificate cert = this.getX509Certificate();
if (cert != null) {
return cert;
}
if (cert != null) {
return cert.getPublicKey();
}
return null;
} catch (CertificateException ex) {
throw new XMLSecurityException("empty", ex);
}
}
/**
* Method getPublicKey
*
* @return teh publickey
* @throws XMLSecurityException
*/
public PublicKey getPublicKey() throws XMLSecurityException {
X509Certificate cert = this.getX509Certificate();
if (cert != null) {
return cert.getPublicKey();
}
return null;
}
return null;
}
/** @inheritDoc */
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!this.getClass().getName().equals(obj.getClass().getName())) {
if (!(obj instanceof XMLX509Certificate)) {
return false;
}
XMLX509Certificate other = (XMLX509Certificate) obj;
try {
/** $todo$ or should be create X509Certificates and use the equals() from the Certs */
return java.security.MessageDigest.isEqual
(other.getCertificateBytes(), this.getCertificateBytes());
return Arrays.equals(other.getCertificateBytes(), this.getCertificateBytes());
} catch (XMLSecurityException ex) {
return false;
}
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509CERTIFICATE;
}
public int hashCode() {
int result = 17;
try {
byte[] bytes = getCertificateBytes();
for (int i = 0; i < bytes.length; i++) {
result = 31 * result + bytes[i];
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, e.getMessage(), e);
}
}
return result;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509CERTIFICATE;
}
}

View File

@ -2,32 +2,30 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
/**
* Just used for tagging contents that are allowed inside a ds:X509Data Element.
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public interface XMLX509DataContent {
}

View File

@ -0,0 +1,139 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
import java.security.MessageDigest;
import java.security.cert.X509Certificate;
import com.sun.org.apache.xml.internal.security.algorithms.JCEMapper;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.Signature11ElementProxy;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
* Provides content model support for the <code>dsig11:X509Digest</code> element.
*
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class XMLX509Digest extends Signature11ElementProxy implements XMLX509DataContent {
/**
* Constructor XMLX509Digest
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509Digest(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor XMLX509Digest
*
* @param doc
* @param digestBytes
* @param algorithmURI
*/
public XMLX509Digest(Document doc, byte[] digestBytes, String algorithmURI) {
super(doc);
this.addBase64Text(digestBytes);
this.constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, algorithmURI);
}
/**
* Constructor XMLX509Digest
*
* @param doc
* @param x509certificate
* @param algorithmURI
* @throws XMLSecurityException
*/
public XMLX509Digest(Document doc, X509Certificate x509certificate, String algorithmURI) throws XMLSecurityException {
super(doc);
this.addBase64Text(getDigestBytesFromCert(x509certificate, algorithmURI));
this.constructionElement.setAttributeNS(null, Constants._ATT_ALGORITHM, algorithmURI);
}
/**
* Method getAlgorithmAttr
*
* @return the Algorithm attribute
*/
public Attr getAlgorithmAttr() {
return this.constructionElement.getAttributeNodeNS(null, Constants._ATT_ALGORITHM);
}
/**
* Method getAlgorithm
*
* @return Algorithm string
*/
public String getAlgorithm() {
return this.getAlgorithmAttr().getNodeValue();
}
/**
* Method getDigestBytes
*
* @return the digestbytes
* @throws XMLSecurityException
*/
public byte[] getDigestBytes() throws XMLSecurityException {
return this.getBytesFromTextChild();
}
/**
* Method getDigestBytesFromCert
*
* @param cert
* @param algorithmURI
* @return digest bytes from the given certificate
*
* @throws XMLSecurityException
*/
public static byte[] getDigestBytesFromCert(X509Certificate cert, String algorithmURI) throws XMLSecurityException {
String jcaDigestAlgorithm = JCEMapper.translateURItoJCEID(algorithmURI);
if (jcaDigestAlgorithm == null) {
Object exArgs[] = { algorithmURI };
throw new XMLSecurityException("XMLX509Digest.UnknownDigestAlgorithm", exArgs);
}
try {
MessageDigest md = MessageDigest.getInstance(jcaDigestAlgorithm);
return md.digest(cert.getEncoded());
} catch (Exception e) {
Object exArgs[] = { jcaDigestAlgorithm };
throw new XMLSecurityException("XMLX509Digest.FailedDigest", exArgs);
}
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509DIGEST;
}
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
@ -31,17 +33,11 @@ import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class XMLX509IssuerSerial extends SignatureElementProxy
implements XMLX509DataContent {
public class XMLX509IssuerSerial extends SignatureElementProxy implements XMLX509DataContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
XMLX509IssuerSerial.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(XMLX509IssuerSerial.class.getName());
/**
* Constructor XMLX509IssuerSerial
@ -50,8 +46,7 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @param baseURI
* @throws XMLSecurityException
*/
public XMLX509IssuerSerial(Element element, String baseURI)
throws XMLSecurityException {
public XMLX509IssuerSerial(Element element, String baseURI) throws XMLSecurityException {
super(element, baseURI);
}
@ -62,11 +57,9 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @param x509IssuerName
* @param x509SerialNumber
*/
public XMLX509IssuerSerial(Document doc, String x509IssuerName,
BigInteger x509SerialNumber) {
public XMLX509IssuerSerial(Document doc, String x509IssuerName, BigInteger x509SerialNumber) {
super(doc);
XMLUtils.addReturnToElement(this._constructionElement);
XMLUtils.addReturnToElement(this.constructionElement);
addTextElement(x509IssuerName, Constants._TAG_X509ISSUERNAME);
addTextElement(x509SerialNumber.toString(), Constants._TAG_X509SERIALNUMBER);
}
@ -78,8 +71,7 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @param x509IssuerName
* @param x509SerialNumber
*/
public XMLX509IssuerSerial(Document doc, String x509IssuerName,
String x509SerialNumber) {
public XMLX509IssuerSerial(Document doc, String x509IssuerName, String x509SerialNumber) {
this(doc, x509IssuerName, new BigInteger(x509SerialNumber));
}
@ -90,10 +82,8 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @param x509IssuerName
* @param x509SerialNumber
*/
public XMLX509IssuerSerial(Document doc, String x509IssuerName,
int x509SerialNumber) {
this(doc, x509IssuerName,
new BigInteger(Integer.toString(x509SerialNumber)));
public XMLX509IssuerSerial(Document doc, String x509IssuerName, int x509SerialNumber) {
this(doc, x509IssuerName, new BigInteger(Integer.toString(x509SerialNumber)));
}
/**
@ -103,10 +93,11 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @param x509certificate
*/
public XMLX509IssuerSerial(Document doc, X509Certificate x509certificate) {
this(doc,
RFC2253Parser.normalize(x509certificate.getIssuerDN().getName()),
x509certificate.getSerialNumber());
this(
doc,
x509certificate.getIssuerX500Principal().getName(),
x509certificate.getSerialNumber()
);
}
/**
@ -115,11 +106,11 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @return the serial number
*/
public BigInteger getSerialNumber() {
String text = this.getTextFromChildElement
(Constants._TAG_X509SERIALNUMBER, Constants.SignatureSpecNS);
if (log.isLoggable(java.util.logging.Level.FINE))
String text =
this.getTextFromChildElement(Constants._TAG_X509SERIALNUMBER, Constants.SignatureSpecNS);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "X509SerialNumber text: " + text);
}
return new BigInteger(text);
}
@ -139,27 +130,28 @@ public class XMLX509IssuerSerial extends SignatureElementProxy
* @return the issuer name
*/
public String getIssuerName() {
return RFC2253Parser
.normalize(this
.getTextFromChildElement(Constants._TAG_X509ISSUERNAME,
Constants.SignatureSpecNS));
return RFC2253Parser.normalize(
this.getTextFromChildElement(Constants._TAG_X509ISSUERNAME, Constants.SignatureSpecNS)
);
}
/** @inheritDoc */
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!this.getClass().getName().equals(obj.getClass().getName())) {
if (!(obj instanceof XMLX509IssuerSerial)) {
return false;
}
XMLX509IssuerSerial other = (XMLX509IssuerSerial) obj;
return this.getSerialNumber().equals(other.getSerialNumber())
&& this.getIssuerName().equals(other.getIssuerName());
&& this.getIssuerName().equals(other.getIssuerName());
}
public int hashCode() {
int result = 17;
result = 31 * result + getSerialNumber().hashCode();
result = 31 * result + getIssuerName().hashCode();
return result;
}
/** @inheritDoc */

View File

@ -2,30 +2,28 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
import java.io.IOException;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.security.cert.X509Certificate;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.utils.Base64;
@ -37,14 +35,13 @@ import org.w3c.dom.Element;
/**
* Handles SubjectKeyIdentifier (SKI) for X.509v3.
*
* @author $Author: mullan $
* @see <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/security/cert/X509Extension.html">Interface X509Extension</A>
* @see <A HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/security/cert/X509Extension.html">
* Interface X509Extension</A>
*/
public class XMLX509SKI extends SignatureElementProxy
implements XMLX509DataContent {
public class XMLX509SKI extends SignatureElementProxy implements XMLX509DataContent {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(XMLX509SKI.class.getName());
/**
@ -53,7 +50,7 @@ public class XMLX509SKI extends SignatureElementProxy
* distinct keys used by the same subject to be differentiated
* (e.g., as key updating occurs).
* <BR />
* A key identifer shall be unique with respect to all key identifiers
* A key identifier shall be unique with respect to all key identifiers
* for the subject with which it is used. This extension is always non-critical.
*/
public static final String SKI_OID = "2.5.29.14";
@ -77,7 +74,7 @@ public class XMLX509SKI extends SignatureElementProxy
* @throws XMLSecurityException
*/
public XMLX509SKI(Document doc, X509Certificate x509certificate)
throws XMLSecurityException {
throws XMLSecurityException {
super(doc);
this.addBase64Text(XMLX509SKI.getSKIBytesFromCert(x509certificate));
}
@ -89,8 +86,7 @@ public class XMLX509SKI extends SignatureElementProxy
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509SKI(Element element, String BaseURI)
throws XMLSecurityException {
public XMLX509SKI(Element element, String BaseURI) throws XMLSecurityException {
super(element, BaseURI);
}
@ -117,9 +113,8 @@ public class XMLX509SKI extends SignatureElementProxy
throws XMLSecurityException {
if (cert.getVersion() < 3) {
Object exArgs[] = { new Integer(cert.getVersion()) };
throw new XMLSecurityException("certificate.noSki.lowVersion",
exArgs);
Object exArgs[] = { Integer.valueOf(cert.getVersion()) };
throw new XMLSecurityException("certificate.noSki.lowVersion", exArgs);
}
/*
@ -137,7 +132,7 @@ public class XMLX509SKI extends SignatureElementProxy
* Strip away first four bytes from the extensionValue
* The first two bytes are the tag and length of the extensionValue
* OCTET STRING, and the next two bytes are the tag and length of
* the skid OCTET STRING.
* the ski OCTET STRING.
*/
byte skidValue[] = new byte[extensionValue.length - 4];
@ -152,23 +147,35 @@ public class XMLX509SKI extends SignatureElementProxy
/** @inheritDoc */
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!this.getClass().getName().equals(obj.getClass().getName())) {
if (!(obj instanceof XMLX509SKI)) {
return false;
}
XMLX509SKI other = (XMLX509SKI) obj;
try {
return java.security.MessageDigest.isEqual(other.getSKIBytes(),
this.getSKIBytes());
return Arrays.equals(other.getSKIBytes(), this.getSKIBytes());
} catch (XMLSecurityException ex) {
return false;
}
}
public int hashCode() {
int result = 17;
try {
byte[] bytes = getSKIBytes();
for (int i = 0; i < bytes.length; i++) {
result = 31 * result + bytes[i];
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, e.getMessage(), e);
}
}
return result;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509SKI;

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.content.x509;
@ -30,65 +32,57 @@ import org.w3c.dom.Document;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public class XMLX509SubjectName extends SignatureElementProxy
implements XMLX509DataContent {
public class XMLX509SubjectName extends SignatureElementProxy implements XMLX509DataContent {
/**
* Constructor X509SubjectName
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509SubjectName(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor X509SubjectName
*
* @param element
* @param BaseURI
* @throws XMLSecurityException
*/
public XMLX509SubjectName(Element element, String BaseURI)
throws XMLSecurityException {
super(element, BaseURI);
}
/**
* Constructor X509SubjectName
*
* @param doc
* @param X509SubjectNameString
*/
public XMLX509SubjectName(Document doc, String X509SubjectNameString) {
/**
* Constructor X509SubjectName
*
* @param doc
* @param X509SubjectNameString
*/
public XMLX509SubjectName(Document doc, String X509SubjectNameString) {
super(doc);
super(doc);
this.addText(X509SubjectNameString);
}
this.addText(X509SubjectNameString);
}
/**
* Constructor XMLX509SubjectName
*
* @param doc
* @param x509certificate
*/
public XMLX509SubjectName(Document doc, X509Certificate x509certificate) {
this(doc, x509certificate.getSubjectX500Principal().getName());
}
/**
* Constructor XMLX509SubjectName
*
* @param doc
* @param x509certificate
*/
public XMLX509SubjectName(Document doc, X509Certificate x509certificate) {
this(doc,
RFC2253Parser.normalize(x509certificate.getSubjectDN().getName()));
}
/**
* Method getSubjectName
*
*
* @return the subject name
*/
public String getSubjectName() {
return RFC2253Parser.normalize(this.getTextFromTextChild());
}
/**
* Method getSubjectName
*
*
* @return the subject name
*/
public String getSubjectName() {
return RFC2253Parser.normalize(this.getTextFromTextChild());
}
/** @inheritDoc */
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (!this.getClass().getName().equals(obj.getClass().getName())) {
if (!(obj instanceof XMLX509SubjectName)) {
return false;
}
@ -97,10 +91,16 @@ public class XMLX509SubjectName extends SignatureElementProxy
String thisSubject = this.getSubjectName();
return thisSubject.equals(otherSubject);
}
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509SUBJECTNAME;
}
public int hashCode() {
int result = 17;
result = 31 * result + this.getSubjectName().hashCode();
return result;
}
/** @inheritDoc */
public String getBaseLocalName() {
return Constants._TAG_X509SUBJECTNAME;
}
}

View File

@ -2,88 +2,80 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
*
*
* @author $Author: mullan $
*/
public class InvalidKeyResolverException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor InvalidKeyResolverException
*
*/
public InvalidKeyResolverException() {
super();
}
/**
* Constructor InvalidKeyResolverException
*
*/
public InvalidKeyResolverException() {
super();
}
/**
* Constructor InvalidKeyResolverException
*
* @param _msgID
*/
public InvalidKeyResolverException(String _msgID) {
super(_msgID);
}
/**
* Constructor InvalidKeyResolverException
*
* @param msgID
*/
public InvalidKeyResolverException(String msgID) {
super(msgID);
}
/**
* Constructor InvalidKeyResolverException
*
* @param _msgID
* @param exArgs
*/
public InvalidKeyResolverException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor InvalidKeyResolverException
*
* @param msgID
* @param exArgs
*/
public InvalidKeyResolverException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor InvalidKeyResolverException
*
* @param _msgID
* @param _originalException
*/
public InvalidKeyResolverException(String _msgID,
Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor InvalidKeyResolverException
*
* @param msgID
* @param originalException
*/
public InvalidKeyResolverException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor InvalidKeyResolverException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public InvalidKeyResolverException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
/**
* Constructor InvalidKeyResolverException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public InvalidKeyResolverException(String msgID, Object exArgs[], Exception originalException) {
super(msgID, exArgs, originalException);
}
}

View File

@ -31,10 +31,13 @@ import java.util.concurrent.CopyOnWriteArrayList;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.DEREncodedKeyValueResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.DSAKeyValueResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.KeyInfoReferenceResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.RSAKeyValueResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.RetrievalMethodResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509CertificateResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509DigestResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509IssuerSerialResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509SKIResolver;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations.X509SubjectNameResolver;
@ -277,6 +280,9 @@ public class KeyResolver {
keyResolverList.add(new KeyResolver(new RetrievalMethodResolver()));
keyResolverList.add(new KeyResolver(new X509SubjectNameResolver()));
keyResolverList.add(new KeyResolver(new X509IssuerSerialResolver()));
keyResolverList.add(new KeyResolver(new DEREncodedKeyValueResolver()));
keyResolverList.add(new KeyResolver(new KeyInfoReferenceResolver()));
keyResolverList.add(new KeyResolver(new X509DigestResolver()));
resolverVector.addAll(keyResolverList);
}

View File

@ -2,90 +2,80 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
*
*
*
*
* @author $Author: mullan $
*
*/
public class KeyResolverException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor KeyResolverException
*
*/
public KeyResolverException() {
super();
}
/**
* Constructor KeyResolverException
*
*/
public KeyResolverException() {
super();
}
/**
* Constructor KeyResolverException
*
* @param _msgID
*/
public KeyResolverException(String _msgID) {
super(_msgID);
}
/**
* Constructor KeyResolverException
*
* @param msgID
*/
public KeyResolverException(String msgID) {
super(msgID);
}
/**
* Constructor KeyResolverException
*
* @param _msgID
* @param exArgs
*/
public KeyResolverException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor KeyResolverException
*
* @param msgID
* @param exArgs
*/
public KeyResolverException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor KeyResolverException
*
* @param _msgID
* @param _originalException
*/
public KeyResolverException(String _msgID, Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor KeyResolverException
*
* @param msgID
* @param originalException
*/
public KeyResolverException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor KeyResolverException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public KeyResolverException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
/**
* Constructor KeyResolverException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public KeyResolverException(String msgID, Object exArgs[], Exception originalException) {
super(msgID, exArgs, originalException);
}
}

View File

@ -2,24 +2,27 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.HashMap;
@ -30,78 +33,89 @@ import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import org.w3c.dom.Element;
/**
* This class is abstract class for a child KeyInfo Elemnet.
* This class is an abstract class for a child KeyInfo Element.
*
* If you want your KeyResolver, at first you must extend this class, and register
* If you want the your KeyResolver, at firstly you must extend this class, and register
* as following in config.xml
* <PRE>
* &lt;KeyResolver URI="http://www.w3.org/2000/09/xmldsig#KeyValue"
* JAVACLASS="MyPackage.MyKeyValueImpl"//gt;
* </PRE>
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
public abstract class KeyResolverSpi {
/**
* This method helps the {@link com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver} to decide whether a
* {@link com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolverSpi} is able to perform the requested action.
*
* @param element
* @param BaseURI
* @param storage
* @return
*/
public boolean engineCanResolve(Element element, String BaseURI,
StorageResolver storage) {
throw new UnsupportedOperationException();
}
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return resolved public key from the registered from the element.
*
* @throws KeyResolverException
*/
public PublicKey engineResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
throw new UnsupportedOperationException();
/** Field properties */
protected java.util.Map<String, String> properties = null;
protected boolean globalResolver = false;
protected boolean secureValidation;
/**
* Set whether secure validation is enabled or not. The default is false.
*/
public void setSecureValidation(boolean secureValidation) {
this.secureValidation = secureValidation;
}
/**
* This method returns whether the KeyResolverSpi is able to perform the requested action.
*
* @param element
* @param baseURI
* @param storage
* @return whether the KeyResolverSpi is able to perform the requested action.
*/
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
throw new UnsupportedOperationException();
}
/**
* Method engineResolvePublicKey
*
* @param element
* @param baseURI
* @param storage
* @return resolved public key from the registered from the element.
*
* @throws KeyResolverException
*/
public PublicKey engineResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
throw new UnsupportedOperationException();
};
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return resolved public key from the registered from the element.
*
* @throws KeyResolverException
*/
/**
* Method engineLookupAndResolvePublicKey
*
* @param element
* @param baseURI
* @param storage
* @return resolved public key from the registered from the element.
*
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
KeyResolverSpi tmp = cloneIfNeeded();
if (!tmp.engineCanResolve(element, BaseURI, storage))
return null;
return tmp.engineResolvePublicKey(element, BaseURI, storage);
if (!tmp.engineCanResolve(element, baseURI, storage)) {
return null;
}
return tmp.engineResolvePublicKey(element, baseURI, storage);
}
private KeyResolverSpi cloneIfNeeded() throws KeyResolverException {
KeyResolverSpi tmp=this;
KeyResolverSpi tmp = this;
if (globalResolver) {
try {
tmp = (KeyResolverSpi) getClass().newInstance();
} catch (InstantiationException e) {
throw new KeyResolverException("",e);
} catch (IllegalAccessException e) {
throw new KeyResolverException("",e);
}
try {
tmp = getClass().newInstance();
} catch (InstantiationException e) {
throw new KeyResolverException("", e);
} catch (IllegalAccessException e) {
throw new KeyResolverException("", e);
}
}
return tmp;
}
@ -110,116 +124,138 @@ public abstract class KeyResolverSpi {
* Method engineResolveCertificate
*
* @param element
* @param BaseURI
* @param baseURI
* @param storage
* @return resolved X509Certificate key from the registered from the elements
*
* @throws KeyResolverException
*/
public X509Certificate engineResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException{
throw new UnsupportedOperationException();
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException{
throw new UnsupportedOperationException();
};
/**
* Method engineResolveCertificate
*
* @param element
* @param BaseURI
* @param storage
* @return resolved X509Certificate key from the registered from the elements
*
* @throws KeyResolverException
*/
/**
* Method engineLookupResolveX509Certificate
*
* @param element
* @param baseURI
* @param storage
* @return resolved X509Certificate key from the registered from the elements
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
KeyResolverSpi tmp = cloneIfNeeded();
if (!tmp.engineCanResolve(element, BaseURI, storage))
return null;
return tmp.engineResolveX509Certificate(element, BaseURI, storage);
if (!tmp.engineCanResolve(element, baseURI, storage)) {
return null;
}
return tmp.engineResolveX509Certificate(element, baseURI, storage);
}
/**
* Method engineResolveSecretKey
*
* @param element
* @param BaseURI
* @param baseURI
* @param storage
* @return resolved SecretKey key from the registered from the elements
*
* @throws KeyResolverException
*/
public SecretKey engineResolveSecretKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException{
throw new UnsupportedOperationException();
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException{
throw new UnsupportedOperationException();
};
/**
* Method engineResolveSecretKey
*
* @param element
* @param BaseURI
* @param storage
* @return resolved SecretKey key from the registered from the elements
*
* @throws KeyResolverException
*/
public SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
KeyResolverSpi tmp = cloneIfNeeded();
if (!tmp.engineCanResolve(element, BaseURI, storage))
return null;
return tmp.engineResolveSecretKey(element, BaseURI, storage);
}
/**
* Method engineLookupAndResolveSecretKey
*
* @param element
* @param baseURI
* @param storage
* @return resolved SecretKey key from the registered from the elements
*
* @throws KeyResolverException
*/
public SecretKey engineLookupAndResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
KeyResolverSpi tmp = cloneIfNeeded();
if (!tmp.engineCanResolve(element, baseURI, storage)) {
return null;
}
return tmp.engineResolveSecretKey(element, baseURI, storage);
}
/** Field _properties */
protected java.util.Map<String,String> _properties = null;
/**
* Method engineLookupAndResolvePrivateKey
*
* @param element
* @param baseURI
* @param storage
* @return resolved PrivateKey key from the registered from the elements
*
* @throws KeyResolverException
*/
public PrivateKey engineLookupAndResolvePrivateKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
// This method was added later, it has no equivalent
// engineResolvePrivateKey() in the old API.
// We cannot throw UnsupportedOperationException because
// KeyResolverSpi implementations who don't know about
// this method would stop the search too early.
return null;
}
protected boolean globalResolver=false;
/**
* Method engineSetProperty
*
* @param key
* @param value
*/
public void engineSetProperty(String key, String value) {
if (properties == null) {
properties = new HashMap<String, String>();
}
properties.put(key, value);
}
/**
* Method engineSetProperty
*
* @param key
* @param value
*/
public void engineSetProperty(String key, String value) {
if (_properties==null)
_properties=new HashMap<String,String>();
this._properties.put(key, value);
}
/**
* Method engineGetProperty
*
* @param key
* @return obtain the property appointed by key
*/
public String engineGetProperty(String key) {
if (properties == null) {
return null;
}
/**
* Method engineGetProperty
*
* @param key
* @return obtain the property appointed by key
*/
public String engineGetProperty(String key) {
if (_properties==null)
return null;
return properties.get(key);
}
return this._properties.get(key);
}
/**
* Method understandsProperty
*
* @param propertyToTest
* @return true if understood the property
*/
public boolean understandsProperty(String propertyToTest) {
if (properties == null) {
return false;
}
/**
* Method understandsProperty
*
* @param propertyToTest
* @return true if understood the property
*/
public boolean understandsProperty(String propertyToTest) {
if (_properties==null)
return false;
return properties.get(propertyToTest) != null;
}
return this._properties.get(propertyToTest)!=null;
}
public void setGlobalResolver(boolean globalResolver) {
public void setGlobalResolver(boolean globalResolver) {
this.globalResolver = globalResolver;
}
}
}

View File

@ -0,0 +1,83 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.DEREncodedKeyValue;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* KeyResolverSpi implementation which resolves public keys from a
* <code>dsig11:DEREncodedKeyValue</code> element.
*
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class DEREncodedKeyValueResolver extends KeyResolverSpi {
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(DEREncodedKeyValueResolver.class.getName());
/** {@inheritDoc}. */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_DERENCODEDKEYVALUE);
}
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
DEREncodedKeyValue derKeyValue = new DEREncodedKeyValue(element, baseURI);
return derKeyValue.getPublicKey();
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
return null;
}
/** {@inheritDoc}. */
public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
return null;
}
/** {@inheritDoc}. */
public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
return null;
}
}

View File

@ -2,30 +2,29 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.keyvalues.DSAKeyValue;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
@ -34,66 +33,70 @@ import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class DSAKeyValueResolver extends KeyResolverSpi {
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage) {
if (element == null) {
return null;
}
Element dsaKeyElement=null;
boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_KEYVALUE);
if (isKeyValue) {
dsaKeyElement =
XMLUtils.selectDsNode(element.getFirstChild(),Constants._TAG_DSAKEYVALUE,0);
} else if (XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_DSAKEYVALUE)) {
// this trick is needed to allow the RetrievalMethodResolver to eat a
// ds:DSAKeyValue directly (without KeyValue)
dsaKeyElement = element;
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(DSAKeyValueResolver.class.getName());
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage
) {
if (element == null) {
return null;
}
Element dsaKeyElement = null;
boolean isKeyValue =
XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
if (isKeyValue) {
dsaKeyElement =
XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_DSAKEYVALUE, 0);
} else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_DSAKEYVALUE)) {
// this trick is needed to allow the RetrievalMethodResolver to eat a
// ds:DSAKeyValue directly (without KeyValue)
dsaKeyElement = element;
}
if (dsaKeyElement == null) {
return null;
}
try {
DSAKeyValue dsaKeyValue = new DSAKeyValue(dsaKeyElement, BaseURI);
PublicKey pk = dsaKeyValue.getPublicKey();
return pk;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, ex.getMessage(), ex);
}
//do nothing
}
if (dsaKeyElement == null) {
return null;
}
try {
DSAKeyValue dsaKeyValue = new DSAKeyValue(dsaKeyElement,
BaseURI);
PublicKey pk = dsaKeyValue.getPublicKey();
return pk;
} catch (XMLSecurityException ex) {
//do nothing
}
return null;
}
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage) {
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage){
return null;
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
}

View File

@ -2,39 +2,43 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.Key;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.encryption.EncryptedKey;
import com.sun.org.apache.xml.internal.security.encryption.XMLCipher;
import com.sun.org.apache.xml.internal.security.encryption.XMLEncryptionException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.utils.EncryptionConstants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* The <code>EncryptedKeyResolver</code> is not a generic resolver. It can
* only be for specific instantiations, as the key being unwrapped will
@ -47,78 +51,100 @@ import org.w3c.dom.Element;
*
* @author Berin Lautenbach
*/
public class EncryptedKeyResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
RSAKeyValueResolver.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(EncryptedKeyResolver.class.getName());
private Key kek;
private String algorithm;
private List<KeyResolverSpi> internalKeyResolvers;
Key _kek;
String _algorithm;
/**
* Constructor for use when a KEK needs to be derived from a KeyInfo
* list
* @param algorithm
*/
public EncryptedKeyResolver(String algorithm) {
_kek = null;
_algorithm=algorithm;
}
/**
* Constructor used for when a KEK has been set
* @param algorithm
* @param kek
*/
public EncryptedKeyResolver(String algorithm, Key kek) {
_algorithm = algorithm;
_kek = kek;
/**
* Constructor for use when a KEK needs to be derived from a KeyInfo
* list
* @param algorithm
*/
public EncryptedKeyResolver(String algorithm) {
kek = null;
this.algorithm = algorithm;
}
/**
* Constructor used for when a KEK has been set
* @param algorithm
* @param kek
*/
public EncryptedKeyResolver(String algorithm, Key kek) {
this.algorithm = algorithm;
this.kek = kek;
}
/**
* This method is used to add a custom {@link KeyResolverSpi} to help
* resolve the KEK.
*
* @param realKeyResolver
*/
public void registerInternalKeyResolver(KeyResolverSpi realKeyResolver) {
if (internalKeyResolvers == null) {
internalKeyResolvers = new ArrayList<KeyResolverSpi>();
}
internalKeyResolvers.add(realKeyResolver);
}
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage) {
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage) {
return null;
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage
) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "EncryptedKeyResolver - Can I resolve " + element.getTagName());
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage) {
SecretKey key=null;
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "EncryptedKeyResolver - Can I resolve " + element.getTagName());
if (element == null) {
return null;
}
if (element == null) {
return null;
}
SecretKey key = null;
boolean isEncryptedKey =
XMLUtils.elementIsInEncryptionSpace(element, EncryptionConstants._TAG_ENCRYPTEDKEY);
if (isEncryptedKey) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Passed an Encrypted Key");
}
try {
XMLCipher cipher = XMLCipher.getInstance();
cipher.init(XMLCipher.UNWRAP_MODE, kek);
if (internalKeyResolvers != null) {
int size = internalKeyResolvers.size();
for (int i = 0; i < size; i++) {
cipher.registerInternalKeyResolver(internalKeyResolvers.get(i));
}
}
EncryptedKey ek = cipher.loadEncryptedKey(element);
key = (SecretKey) cipher.decryptKey(ek, algorithm);
} catch (XMLEncryptionException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, e.getMessage(), e);
}
}
}
boolean isEncryptedKey = XMLUtils.elementIsInEncryptionSpace(element,
EncryptionConstants._TAG_ENCRYPTEDKEY);
if (isEncryptedKey) {
log.log(java.util.logging.Level.FINE, "Passed an Encrypted Key");
try {
XMLCipher cipher = XMLCipher.getInstance();
cipher.init(XMLCipher.UNWRAP_MODE, _kek);
EncryptedKey ek = cipher.loadEncryptedKey(element);
key = (SecretKey) cipher.decryptKey(ek, _algorithm);
}
catch (Exception e) {}
}
return key;
}
return key;
}
}

View File

@ -0,0 +1,290 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import javax.crypto.SecretKey;
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.KeyInfo;
import com.sun.org.apache.xml.internal.security.keys.content.KeyInfoReference;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;
/**
* KeyResolverSpi implementation which resolves public keys, private keys, secret keys, and X.509 certificates from a
* <code>dsig11:KeyInfoReference</code> element.
*
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class KeyInfoReferenceResolver extends KeyResolverSpi {
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(KeyInfoReferenceResolver.class.getName());
/** {@inheritDoc}. */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
return XMLUtils.elementIsInSignature11Space(element, Constants._TAG_KEYINFOREFERENCE);
}
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
if (referent != null) {
return referent.getPublicKey();
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
if (referent != null) {
return referent.getX509Certificate();
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
/** {@inheritDoc}. */
public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
if (referent != null) {
return referent.getSecretKey();
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
/** {@inheritDoc}. */
public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
if (referent != null) {
return referent.getPrivateKey();
}
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
/**
* Resolve the KeyInfoReference Element's URI attribute into a KeyInfo instance.
*
* @param element
* @param baseURI
* @param storage
* @return the KeyInfo which is referred to by this KeyInfoReference, or null if can not be resolved
* @throws XMLSecurityException
*/
private KeyInfo resolveReferentKeyInfo(Element element, String baseURI, StorageResolver storage) throws XMLSecurityException {
KeyInfoReference reference = new KeyInfoReference(element, baseURI);
Attr uriAttr = reference.getURIAttr();
XMLSignatureInput resource = resolveInput(uriAttr, baseURI, secureValidation);
Element referentElement = null;
try {
referentElement = obtainReferenceElement(resource);
} catch (Exception e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
return null;
}
if (referentElement == null) {
log.log(java.util.logging.Level.FINE, "De-reference of KeyInfoReference URI returned null: " + uriAttr.getValue());
return null;
}
validateReference(referentElement);
KeyInfo referent = new KeyInfo(referentElement, baseURI);
referent.addStorageResolver(storage);
return referent;
}
/**
* Validate the Element referred to by the KeyInfoReference.
*
* @param referentElement
*
* @throws XMLSecurityException
*/
private void validateReference(Element referentElement) throws XMLSecurityException {
if (!XMLUtils.elementIsInSignatureSpace(referentElement, Constants._TAG_KEYINFO)) {
Object exArgs[] = { new QName(referentElement.getNamespaceURI(), referentElement.getLocalName()) };
throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.WrongType", exArgs);
}
KeyInfo referent = new KeyInfo(referentElement, "");
if (referent.containsKeyInfoReference()) {
if (secureValidation) {
throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithSecure");
} else {
// Don't support chains of references at this time. If do support in the future, this is where the code
// would go to validate that don't have a cycle, resulting in an infinite loop. This may be unrealistic
// to implement, and/or very expensive given remote URI references.
throw new XMLSecurityException("KeyInfoReferenceResolver.InvalidReferentElement.ReferenceWithoutSecure");
}
}
}
/**
* Resolve the XML signature input represented by the specified URI.
*
* @param uri
* @param baseURI
* @param secureValidation
* @return
* @throws XMLSecurityException
*/
private XMLSignatureInput resolveInput(Attr uri, String baseURI, boolean secureValidation)
throws XMLSecurityException {
ResourceResolver resRes = ResourceResolver.getInstance(uri, baseURI, secureValidation);
XMLSignatureInput resource = resRes.resolve(uri, baseURI, secureValidation);
return resource;
}
/**
* Resolve the Element effectively represented by the XML signature input source.
*
* @param resource
* @return
* @throws CanonicalizationException
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws KeyResolverException
*/
private Element obtainReferenceElement(XMLSignatureInput resource)
throws CanonicalizationException, ParserConfigurationException,
IOException, SAXException, KeyResolverException {
Element e;
if (resource.isElement()){
e = (Element) resource.getSubNode();
} else if (resource.isNodeSet()) {
log.log(java.util.logging.Level.FINE, "De-reference of KeyInfoReference returned an unsupported NodeSet");
return null;
} else {
// Retrieved resource is a byte stream
byte inputBytes[] = resource.getBytes();
e = getDocFromBytes(inputBytes);
}
return e;
}
/**
* Parses a byte array and returns the parsed Element.
*
* @param bytes
* @return the Document Element after parsing bytes
* @throws KeyResolverException if something goes wrong
*/
private Element getDocFromBytes(byte[] bytes) throws KeyResolverException {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(bytes));
return doc.getDocumentElement();
} catch (SAXException ex) {
throw new KeyResolverException("empty", ex);
} catch (IOException ex) {
throw new KeyResolverException("empty", ex);
} catch (ParserConfigurationException ex) {
throw new KeyResolverException("empty", ex);
}
}
}

View File

@ -0,0 +1,353 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.Key;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Enumeration;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509IssuerSerial;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SubjectName;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* Resolves a PrivateKey within a KeyStore based on the KeyInfo hints.
* For X509Data hints, the certificate associated with the private key entry must match.
* For a KeyName hint, the KeyName must match the alias of a PrivateKey entry within the KeyStore.
*/
public class PrivateKeyResolver extends KeyResolverSpi {
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(PrivateKeyResolver.class.getName());
private KeyStore keyStore;
private char[] password;
/**
* Constructor.
*/
public PrivateKeyResolver(KeyStore keyStore, char[] password) {
this.keyStore = keyStore;
this.password = password;
}
/**
* This method returns whether the KeyResolverSpi is able to perform the requested action.
*
* @param element
* @param BaseURI
* @param storage
* @return whether the KeyResolverSpi is able to perform the requested action.
*/
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)
|| XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
return true;
}
return false;
}
/**
* Method engineLookupAndResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolveSecretKey
*
* @param element
* @param BaseURI
* @param storage
* @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
*
* @throws KeyResolverException
*/
public SecretKey engineResolveSecretKey(
Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolvePrivateKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
* @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained
* @throws KeyResolverException
*/
public PrivateKey engineLookupAndResolvePrivateKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
PrivateKey privKey = resolveX509Data(element, baseURI);
if (privKey != null) {
return privKey;
}
} else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
log.log(java.util.logging.Level.FINE, "Can I resolve KeyName?");
String keyName = element.getFirstChild().getNodeValue();
try {
Key key = keyStore.getKey(keyName, password);
if (key instanceof PrivateKey) {
return (PrivateKey) key;
}
} catch (Exception e) {
log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
}
}
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
private PrivateKey resolveX509Data(Element element, String baseURI) {
log.log(java.util.logging.Level.FINE, "Can I resolve X509Data?");
try {
X509Data x509Data = new X509Data(element, baseURI);
int len = x509Data.lengthSKI();
for (int i = 0; i < len; i++) {
XMLX509SKI x509SKI = x509Data.itemSKI(i);
PrivateKey privKey = resolveX509SKI(x509SKI);
if (privKey != null) {
return privKey;
}
}
len = x509Data.lengthIssuerSerial();
for (int i = 0; i < len; i++) {
XMLX509IssuerSerial x509Serial = x509Data.itemIssuerSerial(i);
PrivateKey privKey = resolveX509IssuerSerial(x509Serial);
if (privKey != null) {
return privKey;
}
}
len = x509Data.lengthSubjectName();
for (int i = 0; i < len; i++) {
XMLX509SubjectName x509SubjectName = x509Data.itemSubjectName(i);
PrivateKey privKey = resolveX509SubjectName(x509SubjectName);
if (privKey != null) {
return privKey;
}
}
len = x509Data.lengthCertificate();
for (int i = 0; i < len; i++) {
XMLX509Certificate x509Cert = x509Data.itemCertificate(i);
PrivateKey privKey = resolveX509Certificate(x509Cert);
if (privKey != null) {
return privKey;
}
}
} catch (XMLSecurityException e) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
} catch (KeyStoreException e) {
log.log(java.util.logging.Level.FINE, "KeyStoreException", e);
}
return null;
}
/*
* Search for a private key entry in the KeyStore with the same Subject Key Identifier
*/
private PrivateKey resolveX509SKI(XMLX509SKI x509SKI) throws XMLSecurityException, KeyStoreException {
log.log(java.util.logging.Level.FINE, "Can I resolve X509SKI?");
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (keyStore.isKeyEntry(alias)) {
Certificate cert = keyStore.getCertificate(alias);
if (cert instanceof X509Certificate) {
XMLX509SKI certSKI = new XMLX509SKI(x509SKI.getDocument(), (X509Certificate) cert);
if (certSKI.equals(x509SKI)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
try {
Key key = keyStore.getKey(alias, password);
if (key instanceof PrivateKey) {
return (PrivateKey) key;
}
} catch (Exception e) {
log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
// Keep searching
}
}
}
}
}
return null;
}
/*
* Search for a private key entry in the KeyStore with the same Issuer/Serial Number pair.
*/
private PrivateKey resolveX509IssuerSerial(XMLX509IssuerSerial x509Serial) throws KeyStoreException {
log.log(java.util.logging.Level.FINE, "Can I resolve X509IssuerSerial?");
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (keyStore.isKeyEntry(alias)) {
Certificate cert = keyStore.getCertificate(alias);
if (cert instanceof X509Certificate) {
XMLX509IssuerSerial certSerial =
new XMLX509IssuerSerial(x509Serial.getDocument(), (X509Certificate) cert);
if (certSerial.equals(x509Serial)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
try {
Key key = keyStore.getKey(alias, password);
if (key instanceof PrivateKey) {
return (PrivateKey) key;
}
} catch (Exception e) {
log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
// Keep searching
}
}
}
}
}
return null;
}
/*
* Search for a private key entry in the KeyStore with the same Subject Name.
*/
private PrivateKey resolveX509SubjectName(XMLX509SubjectName x509SubjectName) throws KeyStoreException {
log.log(java.util.logging.Level.FINE, "Can I resolve X509SubjectName?");
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (keyStore.isKeyEntry(alias)) {
Certificate cert = keyStore.getCertificate(alias);
if (cert instanceof X509Certificate) {
XMLX509SubjectName certSN =
new XMLX509SubjectName(x509SubjectName.getDocument(), (X509Certificate) cert);
if (certSN.equals(x509SubjectName)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
try {
Key key = keyStore.getKey(alias, password);
if (key instanceof PrivateKey) {
return (PrivateKey) key;
}
} catch (Exception e) {
log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
// Keep searching
}
}
}
}
}
return null;
}
/*
* Search for a private key entry in the KeyStore with the same Certificate.
*/
private PrivateKey resolveX509Certificate(
XMLX509Certificate x509Cert
) throws XMLSecurityException, KeyStoreException {
log.log(java.util.logging.Level.FINE, "Can I resolve X509Certificate?");
byte[] x509CertBytes = x509Cert.getCertificateBytes();
Enumeration<String> aliases = keyStore.aliases();
while (aliases.hasMoreElements()) {
String alias = aliases.nextElement();
if (keyStore.isKeyEntry(alias)) {
Certificate cert = keyStore.getCertificate(alias);
if (cert instanceof X509Certificate) {
byte[] certBytes = null;
try {
certBytes = cert.getEncoded();
} catch (CertificateEncodingException e1) {
}
if (certBytes != null && Arrays.equals(certBytes, x509CertBytes)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
try {
Key key = keyStore.getKey(alias, password);
if (key instanceof PrivateKey) {
return (PrivateKey) key;
}
}
catch (Exception e) {
log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
// Keep searching
}
}
}
}
}
return null;
}
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
@ -34,69 +34,63 @@ import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class RSAKeyValueResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
RSAKeyValueResolver.class.getName());
/** Field _rsaKeyElement */
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(RSAKeyValueResolver.class.getName());
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage) {
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
if (element == null) {
return null;
}
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage
) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (element == null) {
return null;
}
boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_KEYVALUE);
Element rsaKeyElement=null;
if (isKeyValue) {
rsaKeyElement = XMLUtils.selectDsNode(element.getFirstChild(),
Constants._TAG_RSAKEYVALUE, 0);
} else if (XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_RSAKEYVALUE)) {
// this trick is needed to allow the RetrievalMethodResolver to eat a
// ds:RSAKeyValue directly (without KeyValue)
rsaKeyElement = element;
}
boolean isKeyValue = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYVALUE);
Element rsaKeyElement = null;
if (isKeyValue) {
rsaKeyElement =
XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_RSAKEYVALUE, 0);
} else if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RSAKEYVALUE)) {
// this trick is needed to allow the RetrievalMethodResolver to eat a
// ds:RSAKeyValue directly (without KeyValue)
rsaKeyElement = element;
}
if (rsaKeyElement == null) {
return null;
}
if (rsaKeyElement == null) {
return null;
}
try {
RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement, BaseURI);
try {
RSAKeyValue rsaKeyValue = new RSAKeyValue(rsaKeyElement,
BaseURI);
return rsaKeyValue.getPublicKey();
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
}
return rsaKeyValue.getPublicKey();
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
return null;
}
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage) {
return null;
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage) {
return null;
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
}

View File

@ -2,26 +2,26 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.security.PublicKey;
@ -35,6 +35,8 @@ import java.util.ListIterator;
import java.util.Set;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import com.sun.org.apache.xml.internal.security.c14n.CanonicalizationException;
@ -51,11 +53,11 @@ import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import com.sun.org.apache.xml.internal.security.utils.resolver.ResourceResolver;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
/**
* The RetrievalMethodResolver can retrieve public keys and certificates from
* other locations. The location is specified using the ds:RetrievalMethod
@ -65,252 +67,325 @@ import org.xml.sax.SAXException;
* RetrievalMethodResolver cannot handle itself, resolving of the extracted
* element is delegated back to the KeyResolver mechanism.
*
* @author $Author: mullan $ modified by Dave Garcia
* @author $Author: raul $ modified by Dave Garcia
*/
public class RetrievalMethodResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
RetrievalMethodResolver.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(RetrievalMethodResolver.class.getName());
/**
* Method engineResolvePublicKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
{
if (!XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_RETRIEVALMETHOD)) {
return null;
}
try {
//Create a retrieval method over the given element
RetrievalMethod rm = new RetrievalMethod(element, BaseURI);
String type = rm.getType();
XMLSignatureInput resource=resolveInput(rm,BaseURI);
if (RetrievalMethod.TYPE_RAWX509.equals(type)) {
//a raw certificate, direct parsing is done!
X509Certificate cert=getRawCertificate(resource);
if (cert != null) {
return cert.getPublicKey();
}
return null;
};
Element e = obtainRefrenceElement(resource);
return resolveKey(e,BaseURI,storage);
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
} catch (CertificateException ex) {
log.log(java.util.logging.Level.FINE, "CertificateException", ex);
} catch (IOException ex) {
log.log(java.util.logging.Level.FINE, "IOException", ex);
} catch (ParserConfigurationException e) {
log.log(java.util.logging.Level.FINE, "ParserConfigurationException", e);
} catch (SAXException e) {
log.log(java.util.logging.Level.FINE, "SAXException", e);
}
return null;
}
static private Element obtainRefrenceElement(XMLSignatureInput resource) throws CanonicalizationException, ParserConfigurationException, IOException, SAXException, KeyResolverException {
Element e;
if (resource.isElement()){
e=(Element) resource.getSubNode();
} else if (resource.isNodeSet()) {
//Retrieved resource is a nodeSet
e=getDocumentElement(resource.getNodeSet());
} else {
//Retrieved resource is an inputStream
byte inputBytes[] = resource.getBytes();
e = getDocFromBytes(inputBytes);
//otherwise, we parse the resource, create an Element and delegate
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "we have to parse " + inputBytes.length + " bytes");
}
return e;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
{
if (!XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_RETRIEVALMETHOD)) {
return null;
}
try {
RetrievalMethod rm = new RetrievalMethod(element, BaseURI);
String type = rm.getType();
XMLSignatureInput resource=resolveInput(rm,BaseURI);
if (RetrievalMethod.TYPE_RAWX509.equals(type)) {
X509Certificate cert=getRawCertificate(resource);
return cert;
}
Element e = obtainRefrenceElement(resource);
return resolveCertificate(e,BaseURI,storage);
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
} catch (CertificateException ex) {
log.log(java.util.logging.Level.FINE, "CertificateException", ex);
} catch (IOException ex) {
log.log(java.util.logging.Level.FINE, "IOException", ex);
} catch (ParserConfigurationException e) {
log.log(java.util.logging.Level.FINE, "ParserConfigurationException", e);
} catch (SAXException e) {
log.log(java.util.logging.Level.FINE, "SAXException", e);
}
return null;
}
/**
* Retrieves a x509Certificate from the given information
* @param e
* @param BaseURI
* @param storage
* @return
* @throws KeyResolverException
*/
static private X509Certificate resolveCertificate(Element e,String BaseURI,StorageResolver storage) throws KeyResolverException{
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Now we have a {" + e.getNamespaceURI() + "}"+ e.getLocalName() + " Element");
//An element has been provided
if (e != null) {
return KeyResolver.getX509Certificate(e,BaseURI, storage);
}
return null;
}
/**
* Retrieves a x509Certificate from the given information
* @param e
* @param BaseURI
* @param storage
* @return
* @throws KeyResolverException
*/
static private PublicKey resolveKey(Element e,String BaseURI,StorageResolver storage) throws KeyResolverException{
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Now we have a {" + e.getNamespaceURI() + "}"+ e.getLocalName() + " Element");
//An element has been provided
if (e != null) {
return KeyResolver.getPublicKey(e,BaseURI, storage);
}
return null;
}
static private X509Certificate getRawCertificate(XMLSignatureInput resource) throws CanonicalizationException, IOException, CertificateException{
byte inputBytes[] = resource.getBytes();
// if the resource stores a raw certificate, we have to handle it
CertificateFactory certFact =CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
X509Certificate cert =(X509Certificate) certFact.generateCertificate(new ByteArrayInputStream(inputBytes));
return cert;
}
/**
* Resolves the input from the given retrieval method
* @return
* @throws XMLSecurityException
*/
static private XMLSignatureInput resolveInput(RetrievalMethod rm,String BaseURI) throws XMLSecurityException{
Attr uri = rm.getURIAttr();
//Apply the trnasforms
Transforms transforms = rm.getTransforms();
ResourceResolver resRes = ResourceResolver.getInstance(uri, BaseURI);
if (resRes != null) {
XMLSignatureInput resource = resRes.resolve(uri, BaseURI);
if (transforms != null) {
log.log(java.util.logging.Level.FINE, "We have Transforms");
resource = transforms.performTransforms(resource);
}
return resource;
}
return null;
}
/**
* Parses a byte array and returns the parsed Element.
*
* @param bytes
* @return the Document Element after parsing bytes
* @throws KeyResolverException if something goes wrong
*/
static Element getDocFromBytes(byte[] bytes) throws KeyResolverException {
try {
javax.xml.parsers.DocumentBuilderFactory dbf =javax.xml.parsers.DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc =
db.parse(new java.io.ByteArrayInputStream(bytes));
return doc.getDocumentElement();
} catch (org.xml.sax.SAXException ex) {
throw new KeyResolverException("empty", ex);
} catch (java.io.IOException ex) {
throw new KeyResolverException("empty", ex);
} catch (javax.xml.parsers.ParserConfigurationException ex) {
throw new KeyResolverException("empty", ex);
}
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage)
{
return null;
}
static Element getDocumentElement(Set<Node> set) {
Iterator<Node> it=set.iterator();
Element e=null;
while (it.hasNext()) {
Node currentNode=it.next();
if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE) {
e=(Element)currentNode;
break;
}
}
List<Element> parents=new ArrayList<Element>(10);
//Obtain all the parents of the elemnt
while (e != null) {
parents.add(e);
Node n=e.getParentNode();
if (n == null || n.getNodeType() != Node.ELEMENT_NODE) {
break;
}
e=(Element)n;
}
//Visit them in reverse order.
ListIterator<Element> it2=parents.listIterator(parents.size()-1);
Element ele=null;
while (it2.hasPrevious()) {
ele=it2.previous();
if (set.contains(ele)) {
return ele;
}
/**
* Method engineResolvePublicKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) {
if (!XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RETRIEVALMETHOD)) {
return null;
}
try {
// Create a retrieval method over the given element
RetrievalMethod rm = new RetrievalMethod(element, baseURI);
String type = rm.getType();
XMLSignatureInput resource = resolveInput(rm, baseURI, secureValidation);
if (RetrievalMethod.TYPE_RAWX509.equals(type)) {
// a raw certificate, direct parsing is done!
X509Certificate cert = getRawCertificate(resource);
if (cert != null) {
return cert.getPublicKey();
}
return null;
}
}
Element e = obtainReferenceElement(resource);
// Check to make sure that the reference is not to another RetrievalMethod
// which points to this element
if (XMLUtils.elementIsInSignatureSpace(e, Constants._TAG_RETRIEVALMETHOD)) {
if (secureValidation) {
String error = "Error: It is forbidden to have one RetrievalMethod "
+ "point to another with secure validation";
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, error);
}
return null;
}
RetrievalMethod rm2 = new RetrievalMethod(e, baseURI);
XMLSignatureInput resource2 = resolveInput(rm2, baseURI, secureValidation);
Element e2 = obtainReferenceElement(resource2);
if (e2 == element) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Error: Can't have RetrievalMethods pointing to each other");
}
return null;
}
}
return resolveKey(e, baseURI, storage);
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
} catch (CertificateException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "CertificateException", ex);
}
} catch (IOException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "IOException", ex);
}
} catch (ParserConfigurationException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "ParserConfigurationException", e);
}
} catch (SAXException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "SAXException", e);
}
}
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String baseURI, StorageResolver storage) {
if (!XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_RETRIEVALMETHOD)) {
return null;
}
try {
RetrievalMethod rm = new RetrievalMethod(element, baseURI);
String type = rm.getType();
XMLSignatureInput resource = resolveInput(rm, baseURI, secureValidation);
if (RetrievalMethod.TYPE_RAWX509.equals(type)) {
return getRawCertificate(resource);
}
Element e = obtainReferenceElement(resource);
// Check to make sure that the reference is not to another RetrievalMethod
// which points to this element
if (XMLUtils.elementIsInSignatureSpace(e, Constants._TAG_RETRIEVALMETHOD)) {
if (secureValidation) {
String error = "Error: It is forbidden to have one RetrievalMethod "
+ "point to another with secure validation";
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, error);
}
return null;
}
RetrievalMethod rm2 = new RetrievalMethod(e, baseURI);
XMLSignatureInput resource2 = resolveInput(rm2, baseURI, secureValidation);
Element e2 = obtainReferenceElement(resource2);
if (e2 == element) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Error: Can't have RetrievalMethods pointing to each other");
}
return null;
}
}
return resolveCertificate(e, baseURI, storage);
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
} catch (CertificateException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "CertificateException", ex);
}
} catch (IOException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "IOException", ex);
}
} catch (ParserConfigurationException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "ParserConfigurationException", e);
}
} catch (SAXException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "SAXException", e);
}
}
return null;
}
/**
* Retrieves a x509Certificate from the given information
* @param e
* @param baseURI
* @param storage
* @return
* @throws KeyResolverException
*/
private static X509Certificate resolveCertificate(
Element e, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Now we have a {" + e.getNamespaceURI() + "}"
+ e.getLocalName() + " Element");
}
// An element has been provided
if (e != null) {
return KeyResolver.getX509Certificate(e, baseURI, storage);
}
return null;
}
/**
* Retrieves a PublicKey from the given information
* @param e
* @param baseURI
* @param storage
* @return
* @throws KeyResolverException
*/
private static PublicKey resolveKey(
Element e, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Now we have a {" + e.getNamespaceURI() + "}"
+ e.getLocalName() + " Element");
}
// An element has been provided
if (e != null) {
return KeyResolver.getPublicKey(e, baseURI, storage);
}
return null;
}
private static Element obtainReferenceElement(XMLSignatureInput resource)
throws CanonicalizationException, ParserConfigurationException,
IOException, SAXException, KeyResolverException {
Element e;
if (resource.isElement()){
e = (Element) resource.getSubNode();
} else if (resource.isNodeSet()) {
// Retrieved resource is a nodeSet
e = getDocumentElement(resource.getNodeSet());
} else {
// Retrieved resource is an inputStream
byte inputBytes[] = resource.getBytes();
e = getDocFromBytes(inputBytes);
// otherwise, we parse the resource, create an Element and delegate
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "we have to parse " + inputBytes.length + " bytes");
}
}
return e;
}
private static X509Certificate getRawCertificate(XMLSignatureInput resource)
throws CanonicalizationException, IOException, CertificateException {
byte inputBytes[] = resource.getBytes();
// if the resource stores a raw certificate, we have to handle it
CertificateFactory certFact =
CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
X509Certificate cert = (X509Certificate)
certFact.generateCertificate(new ByteArrayInputStream(inputBytes));
return cert;
}
/**
* Resolves the input from the given retrieval method
* @return
* @throws XMLSecurityException
*/
private static XMLSignatureInput resolveInput(
RetrievalMethod rm, String baseURI, boolean secureValidation
) throws XMLSecurityException {
Attr uri = rm.getURIAttr();
// Apply the transforms
Transforms transforms = rm.getTransforms();
ResourceResolver resRes = ResourceResolver.getInstance(uri, baseURI, secureValidation);
XMLSignatureInput resource = resRes.resolve(uri, baseURI, secureValidation);
if (transforms != null) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "We have Transforms");
}
resource = transforms.performTransforms(resource);
}
return resource;
}
/**
* Parses a byte array and returns the parsed Element.
*
* @param bytes
* @return the Document Element after parsing bytes
* @throws KeyResolverException if something goes wrong
*/
private static Element getDocFromBytes(byte[] bytes) throws KeyResolverException {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(bytes));
return doc.getDocumentElement();
} catch (SAXException ex) {
throw new KeyResolverException("empty", ex);
} catch (IOException ex) {
throw new KeyResolverException("empty", ex);
} catch (ParserConfigurationException ex) {
throw new KeyResolverException("empty", ex);
}
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) {
return null;
}
private static Element getDocumentElement(Set<Node> set) {
Iterator<Node> it = set.iterator();
Element e = null;
while (it.hasNext()) {
Node currentNode = it.next();
if (currentNode != null && Node.ELEMENT_NODE == currentNode.getNodeType()) {
e = (Element) currentNode;
break;
}
}
List<Node> parents = new ArrayList<Node>();
// Obtain all the parents of the elemnt
while (e != null) {
parents.add(e);
Node n = e.getParentNode();
if (n == null || Node.ELEMENT_NODE != n.getNodeType()) {
break;
}
e = (Element) n;
}
// Visit them in reverse order.
ListIterator<Node> it2 = parents.listIterator(parents.size()-1);
Element ele = null;
while (it2.hasPrevious()) {
ele = (Element) it2.previous();
if (set.contains(ele)) {
return ele;
}
}
return null;
}
}

View File

@ -0,0 +1,129 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.Key;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* Resolves a SecretKey within a KeyStore based on the KeyName.
* The KeyName is the key entry alias within the KeyStore.
*/
public class SecretKeyResolver extends KeyResolverSpi
{
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SecretKeyResolver.class.getName());
private KeyStore keyStore;
private char[] password;
/**
* Constructor.
*/
public SecretKeyResolver(KeyStore keyStore, char[] password) {
this.keyStore = keyStore;
this.password = password;
}
/**
* This method returns whether the KeyResolverSpi is able to perform the requested action.
*
* @param element
* @param baseURI
* @param storage
* @return whether the KeyResolverSpi is able to perform the requested action.
*/
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
return XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME);
}
/**
* Method engineLookupAndResolvePublicKey
*
* @param element
* @param baseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param baseURI
* @param storage
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolveSecretKey
*
* @param element
* @param baseURI
* @param storage
* @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
*
* @throws KeyResolverException
*/
public SecretKey engineResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
String keyName = element.getFirstChild().getNodeValue();
try {
Key key = keyStore.getKey(keyName, password);
if (key instanceof SecretKey) {
return (SecretKey) key;
}
} catch (Exception e) {
log.log(java.util.logging.Level.FINE, "Cannot recover the key", e);
}
}
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
/**
* Method engineResolvePrivateKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
* @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained
* @throws KeyResolverException
*/
public PrivateKey engineLookupAndResolvePrivateKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
}

View File

@ -0,0 +1,172 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* Resolves a single Key based on the KeyName.
*/
public class SingleKeyResolver extends KeyResolverSpi
{
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(SingleKeyResolver.class.getName());
private String keyName;
private PublicKey publicKey;
private PrivateKey privateKey;
private SecretKey secretKey;
/**
* Constructor.
* @param keyName
* @param publicKey
*/
public SingleKeyResolver(String keyName, PublicKey publicKey) {
this.keyName = keyName;
this.publicKey = publicKey;
}
/**
* Constructor.
* @param keyName
* @param privateKey
*/
public SingleKeyResolver(String keyName, PrivateKey privateKey) {
this.keyName = keyName;
this.privateKey = privateKey;
}
/**
* Constructor.
* @param keyName
* @param secretKey
*/
public SingleKeyResolver(String keyName, SecretKey secretKey) {
this.keyName = keyName;
this.secretKey = secretKey;
}
/**
* This method returns whether the KeyResolverSpi is able to perform the requested action.
*
* @param element
* @param BaseURI
* @param storage
* @return whether the KeyResolverSpi is able to perform the requested action.
*/
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
return XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME);
}
/**
* Method engineLookupAndResolvePublicKey
*
* @param element
* @param baseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (publicKey != null
&& XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
String name = element.getFirstChild().getNodeValue();
if (keyName.equals(name)) {
return publicKey;
}
}
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param baseURI
* @param storage
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolveSecretKey
*
* @param element
* @param baseURI
* @param storage
* @return resolved SecretKey key or null if no {@link SecretKey} could be obtained
*
* @throws KeyResolverException
*/
public SecretKey engineResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (secretKey != null
&& XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
String name = element.getFirstChild().getNodeValue();
if (keyName.equals(name)) {
return secretKey;
}
}
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
/**
* Method engineResolvePrivateKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
* @return resolved PrivateKey key or null if no {@link PrivateKey} could be obtained
* @throws KeyResolverException
*/
public PrivateKey engineLookupAndResolvePrivateKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (privateKey != null
&& XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME)) {
String name = element.getFirstChild().getNodeValue();
if (keyName.equals(name)) {
return privateKey;
}
}
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
}

View File

@ -2,30 +2,29 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.X509Certificate;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Certificate;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
@ -35,96 +34,93 @@ import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* Resolves Certificates which are directly contained inside a
* <CODE>ds:X509Certificate</CODE> Element.
*
* @author $Author: mullan $
* @author $Author: coheigea $
*/
public class X509CertificateResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(X509CertificateResolver.class.getName());
/**
* Method engineResolvePublicKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {
X509Certificate cert =
this.engineLookupResolveX509Certificate(element, BaseURI, storage);
/**
* Method engineResolvePublicKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
if (cert != null) {
return cert.getPublicKey();
}
X509Certificate cert = this.engineLookupResolveX509Certificate(element,
BaseURI, storage);
return null;
}
if (cert != null) {
return cert.getPublicKey();
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage
) throws KeyResolverException {
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
try {
Element[] els=XMLUtils.selectDsNodes(element.getFirstChild(),
Constants._TAG_X509CERTIFICATE);
if ((els == null) || (els.length == 0)) {
Element el=XMLUtils.selectDsNode(element.getFirstChild(),
Constants._TAG_X509DATA,0);
if (el!=null) {
return engineLookupResolveX509Certificate(el, BaseURI, storage);
}
return null;
}
// populate Object array
for (int i = 0; i < els.length; i++) {
XMLX509Certificate xmlCert=new XMLX509Certificate(els[i], BaseURI);
X509Certificate cert = xmlCert.getX509Certificate();
if (cert!=null) {
return cert;
try {
Element[] els =
XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509CERTIFICATE);
if ((els == null) || (els.length == 0)) {
Element el =
XMLUtils.selectDsNode(element.getFirstChild(), Constants._TAG_X509DATA, 0);
if (el != null) {
return engineLookupResolveX509Certificate(el, BaseURI, storage);
}
return null;
}
}
return null;
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
// populate Object array
for (int i = 0; i < els.length; i++) {
XMLX509Certificate xmlCert = new XMLX509Certificate(els[i], BaseURI);
X509Certificate cert = xmlCert.getX509Certificate();
if (cert != null) {
return cert;
}
}
return null;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage)
{
return null;
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage
) {
return null;
}
}

View File

@ -0,0 +1,164 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Iterator;
import javax.crypto.SecretKey;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
import com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509Digest;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverException;
import com.sun.org.apache.xml.internal.security.keys.keyresolver.KeyResolverSpi;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
* KeyResolverSpi implementation which resolves public keys and X.509 certificates from a
* <code>dsig11:X509Digest</code> element.
*
* @author Brent Putman (putmanb@georgetown.edu)
*/
public class X509DigestResolver extends KeyResolverSpi {
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(X509DigestResolver.class.getName());
/** {@inheritDoc}. */
public boolean engineCanResolve(Element element, String baseURI, StorageResolver storage) {
if (XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
try {
X509Data x509Data = new X509Data(element, baseURI);
return x509Data.containsDigest();
} catch (XMLSecurityException e) {
return false;
}
} else {
return false;
}
}
/** {@inheritDoc}. */
public PublicKey engineLookupAndResolvePublicKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
X509Certificate cert = this.engineLookupResolveX509Certificate(element, baseURI, storage);
if (cert != null) {
return cert.getPublicKey();
}
return null;
}
/** {@inheritDoc}. */
public X509Certificate engineLookupResolveX509Certificate(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName());
}
if (!engineCanResolve(element, baseURI, storage)) {
return null;
}
try {
return resolveCertificate(element, baseURI, storage);
} catch (XMLSecurityException e) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", e);
}
}
return null;
}
/** {@inheritDoc}. */
public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
throws KeyResolverException {
return null;
}
/**
* Resolves from the storage resolver the actual certificate represented by the digest.
*
* @param element
* @param baseURI
* @param storage
* @return
* @throws XMLSecurityException
*/
private X509Certificate resolveCertificate(Element element, String baseURI, StorageResolver storage)
throws XMLSecurityException {
XMLX509Digest x509Digests[] = null;
Element x509childNodes[] = XMLUtils.selectDs11Nodes(element.getFirstChild(), Constants._TAG_X509DIGEST);
if (x509childNodes == null || x509childNodes.length <= 0) {
return null;
}
try {
checkStorage(storage);
x509Digests = new XMLX509Digest[x509childNodes.length];
for (int i = 0; i < x509childNodes.length; i++) {
x509Digests[i] = new XMLX509Digest(x509childNodes[i], baseURI);
}
Iterator<Certificate> storageIterator = storage.getIterator();
while (storageIterator.hasNext()) {
X509Certificate cert = (X509Certificate) storageIterator.next();
for (int i = 0; i < x509Digests.length; i++) {
XMLX509Digest keyInfoDigest = x509Digests[i];
byte[] certDigestBytes = XMLX509Digest.getDigestBytesFromCert(cert, keyInfoDigest.getAlgorithm());
if (Arrays.equals(keyInfoDigest.getDigestBytes(), certDigestBytes)) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found certificate with: " + cert.getSubjectX500Principal().getName());
}
return cert;
}
}
}
} catch (XMLSecurityException ex) {
throw new KeyResolverException("empty", ex);
}
return null;
}
/**
* Method checkSrorage
*
* @param storage
* @throws KeyResolverException
*/
private void checkStorage(StorageResolver storage) throws KeyResolverException {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509DIGEST };
KeyResolverException ex = new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "", ex);
}
throw ex;
}
}
}

View File

@ -2,28 +2,30 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
import com.sun.org.apache.xml.internal.security.keys.content.X509Data;
@ -35,114 +37,114 @@ import com.sun.org.apache.xml.internal.security.signature.XMLSignatureException;
import com.sun.org.apache.xml.internal.security.utils.Constants;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class X509IssuerSerialResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
X509IssuerSerialResolver.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(X509IssuerSerialResolver.class.getName());
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
/** @inheritDoc */
public PublicKey engineLookupAndResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
X509Certificate cert = this.engineLookupResolveX509Certificate(element,
BaseURI, storage);
X509Certificate cert =
this.engineLookupResolveX509Certificate(element, baseURI, storage);
if (cert != null) {
return cert.getPublicKey();
}
if (cert != null) {
return cert.getPublicKey();
}
return null;
}
return null;
}
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
X509Data x509data = null;
try {
x509data = new X509Data(element, BaseURI);
} catch (XMLSignatureException ex) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
if (x509data == null) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
if (!x509data.containsIssuerSerial()) {
return null;
}
try {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509ISSUERSERIAL };
KeyResolverException ex =
new KeyResolverException("KeyResolver.needStorageResolver",
exArgs);
log.log(java.util.logging.Level.INFO, "", ex);
throw ex;
}
int noOfISS = x509data.lengthIssuerSerial();
while (storage.hasNext()) {
X509Certificate cert = storage.next();
XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert);
/** @inheritDoc */
public X509Certificate engineLookupResolveX509Certificate(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
X509Data x509data = null;
try {
x509data = new X509Data(element, baseURI);
} catch (XMLSignatureException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Certificate Issuer: "
+ certSerial.getIssuerName());
log.log(java.util.logging.Level.FINE, "Found Certificate Serial: "
+ certSerial.getSerialNumber().toString());
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
}
if (!x509data.containsIssuerSerial()) {
return null;
}
try {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509ISSUERSERIAL };
KeyResolverException ex =
new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "", ex);
}
throw ex;
}
for (int i=0; i<noOfISS; i++) {
XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
int noOfISS = x509data.lengthIssuerSerial();
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Element Issuer: "
+ xmliss.getIssuerName());
log.log(java.util.logging.Level.FINE, "Found Element Serial: "
+ xmliss.getSerialNumber().toString());
}
Iterator<Certificate> storageIterator = storage.getIterator();
while (storageIterator.hasNext()) {
X509Certificate cert = (X509Certificate)storageIterator.next();
XMLX509IssuerSerial certSerial = new XMLX509IssuerSerial(element.getOwnerDocument(), cert);
if (certSerial.equals(xmliss)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Certificate Issuer: " + certSerial.getIssuerName());
log.log(java.util.logging.Level.FINE, "Found Certificate Serial: " + certSerial.getSerialNumber().toString());
}
return cert;
}
log.log(java.util.logging.Level.FINE, "no match...");
for (int i = 0; i < noOfISS; i++) {
XMLX509IssuerSerial xmliss = x509data.itemIssuerSerial(i);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Element Issuer: "
+ xmliss.getIssuerName());
log.log(java.util.logging.Level.FINE, "Found Element Serial: "
+ xmliss.getSerialNumber().toString());
}
if (certSerial.equals(xmliss)) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
}
return cert;
}
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "no match...");
}
}
}
}
return null;
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
return null;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage) {
return null;
}
/** @inheritDoc */
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) {
return null;
}
}

View File

@ -2,28 +2,30 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
@ -35,124 +37,121 @@ import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
*
*
* @author $Author: mullan $
*/
public class X509SKIResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(X509SKIResolver.class.getName());
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
/**
* Method engineResolvePublicKey
*
* @param element
* @param baseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
X509Certificate cert = this.engineLookupResolveX509Certificate(element,
BaseURI, storage);
X509Certificate cert =
this.engineLookupResolveX509Certificate(element, baseURI, storage);
if (cert != null) {
return cert.getPublicKey();
}
if (cert != null) {
return cert.getPublicKey();
}
return null;
}
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (!XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_X509DATA)) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
/** Field _x509childObject[] */
XMLX509SKI x509childObject[] = null;
Element x509childNodes[] = null;
x509childNodes = XMLUtils.selectDsNodes(element.getFirstChild(),
Constants._TAG_X509SKI);
if (!((x509childNodes != null)
&& (x509childNodes.length > 0))) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
try {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509SKI };
KeyResolverException ex =
new KeyResolverException("KeyResolver.needStorageResolver",
exArgs);
log.log(java.util.logging.Level.INFO, "", ex);
throw ex;
}
x509childObject = new XMLX509SKI[x509childNodes.length];
for (int i = 0; i < x509childNodes.length; i++) {
x509childObject[i] =
new XMLX509SKI(x509childNodes[i], BaseURI);
}
while (storage.hasNext()) {
X509Certificate cert = storage.next();
XMLX509SKI certSKI = new XMLX509SKI(element.getOwnerDocument(), cert);
for (int i = 0; i < x509childObject.length; i++) {
if (certSKI.equals(x509childObject[i])) {
log.log(java.util.logging.Level.FINE, "Return PublicKey from "
+ cert.getSubjectDN().getName());
return cert;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
if (!XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
}
} catch (XMLSecurityException ex) {
throw new KeyResolverException("empty", ex);
}
return null;
}
/** Field _x509childObject[] */
XMLX509SKI x509childObject[] = null;
return null;
}
Element x509childNodes[] = null;
x509childNodes = XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509SKI);
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage)
{
return null;
}
if (!((x509childNodes != null) && (x509childNodes.length > 0))) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
}
try {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509SKI };
KeyResolverException ex =
new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "", ex);
}
throw ex;
}
x509childObject = new XMLX509SKI[x509childNodes.length];
for (int i = 0; i < x509childNodes.length; i++) {
x509childObject[i] = new XMLX509SKI(x509childNodes[i], baseURI);
}
Iterator<Certificate> storageIterator = storage.getIterator();
while (storageIterator.hasNext()) {
X509Certificate cert = (X509Certificate)storageIterator.next();
XMLX509SKI certSKI = new XMLX509SKI(element.getOwnerDocument(), cert);
for (int i = 0; i < x509childObject.length; i++) {
if (certSKI.equals(x509childObject[i])) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Return PublicKey from " + cert.getSubjectX500Principal().getName());
}
return cert;
}
}
}
} catch (XMLSecurityException ex) {
throw new KeyResolverException("empty", ex);
}
return null;
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) {
return null;
}
}

View File

@ -2,28 +2,30 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.keyresolver.implementations;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
@ -35,133 +37,140 @@ import com.sun.org.apache.xml.internal.security.utils.Constants;
import com.sun.org.apache.xml.internal.security.utils.XMLUtils;
import org.w3c.dom.Element;
/**
*
* @author $Author: mullan $
*/
public class X509SubjectNameResolver extends KeyResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
X509SubjectNameResolver.class.getName());
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(X509SubjectNameResolver.class.getName());
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
/**
* Method engineResolvePublicKey
*
* @param element
* @param BaseURI
* @param storage
* @return null if no {@link PublicKey} could be obtained
* @throws KeyResolverException
*/
public PublicKey engineLookupAndResolvePublicKey(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
X509Certificate cert = this.engineLookupResolveX509Certificate(element,
BaseURI, storage);
X509Certificate cert =
this.engineLookupResolveX509Certificate(element, baseURI, storage);
if (cert != null) {
return cert.getPublicKey();
}
if (cert != null) {
return cert.getPublicKey();
}
return null;
}
return null;
}
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String BaseURI, StorageResolver storage)
throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE))
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
Element[] x509childNodes = null;
XMLX509SubjectName x509childObject[] = null;
/**
* Method engineResolveX509Certificate
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*
* @throws KeyResolverException
*/
public X509Certificate engineLookupResolveX509Certificate(
Element element, String baseURI, StorageResolver storage
) throws KeyResolverException {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Can I resolve " + element.getTagName() + "?");
}
Element[] x509childNodes = null;
XMLX509SubjectName x509childObject[] = null;
if (!XMLUtils.elementIsInSignatureSpace(element,
Constants._TAG_X509DATA) ) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
}
x509childNodes = XMLUtils.selectDsNodes(element.getFirstChild(),
Constants._TAG_X509SUBJECTNAME);
if (!XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_X509DATA)) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
}
x509childNodes =
XMLUtils.selectDsNodes(element.getFirstChild(), Constants._TAG_X509SUBJECTNAME);
if (!((x509childNodes != null)
&& (x509childNodes.length > 0))) {
log.log(java.util.logging.Level.FINE, "I can't");
return null;
&& (x509childNodes.length > 0))) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "I can't");
}
return null;
}
try {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509SUBJECTNAME };
KeyResolverException ex =
new KeyResolverException("KeyResolver.needStorageResolver", exArgs);
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "", ex);
}
throw ex;
}
try {
if (storage == null) {
Object exArgs[] = { Constants._TAG_X509SUBJECTNAME };
KeyResolverException ex =
new KeyResolverException("KeyResolver.needStorageResolver",
exArgs);
x509childObject = new XMLX509SubjectName[x509childNodes.length];
log.log(java.util.logging.Level.INFO, "", ex);
throw ex;
}
x509childObject =
new XMLX509SubjectName[x509childNodes.length];
for (int i = 0; i < x509childNodes.length; i++) {
x509childObject[i] =
new XMLX509SubjectName(x509childNodes[i],
BaseURI);
}
while (storage.hasNext()) {
X509Certificate cert = storage.next();
XMLX509SubjectName certSN =
new XMLX509SubjectName(element.getOwnerDocument(), cert);
log.log(java.util.logging.Level.FINE, "Found Certificate SN: " + certSN.getSubjectName());
for (int i = 0; i < x509childObject.length; i++) {
log.log(java.util.logging.Level.FINE, "Found Element SN: "
+ x509childObject[i].getSubjectName());
if (certSN.equals(x509childObject[i])) {
log.log(java.util.logging.Level.FINE, "match !!! ");
return cert;
}
log.log(java.util.logging.Level.FINE, "no match...");
for (int i = 0; i < x509childNodes.length; i++) {
x509childObject[i] = new XMLX509SubjectName(x509childNodes[i], baseURI);
}
}
return null;
} catch (XMLSecurityException ex) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
Iterator<Certificate> storageIterator = storage.getIterator();
while (storageIterator.hasNext()) {
X509Certificate cert = (X509Certificate)storageIterator.next();
XMLX509SubjectName certSN =
new XMLX509SubjectName(element.getOwnerDocument(), cert);
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Certificate SN: " + certSN.getSubjectName());
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param BaseURI
* @param storage
*
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String BaseURI, StorageResolver storage)
{
return null;
}
for (int i = 0; i < x509childObject.length; i++) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Found Element SN: "
+ x509childObject[i].getSubjectName());
}
if (certSN.equals(x509childObject[i])) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "match !!! ");
}
return cert;
}
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "no match...");
}
}
}
return null;
} catch (XMLSecurityException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "XMLSecurityException", ex);
}
throw new KeyResolverException("generic.EmptyMessage", ex);
}
}
/**
* Method engineResolveSecretKey
* @inheritDoc
* @param element
* @param baseURI
* @param storage
*
*/
public javax.crypto.SecretKey engineLookupAndResolveSecretKey(
Element element, String baseURI, StorageResolver storage
) {
return null;
}
}

View File

@ -2,197 +2,187 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.storage;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import com.sun.org.apache.xml.internal.security.keys.storage.implementations.KeyStoreResolver;
import com.sun.org.apache.xml.internal.security.keys.storage.implementations.SingleCertificateResolver;
/**
* This class collects customized resolvers for Certificates.
*
* @author $Author: mullan $
*/
public class StorageResolver {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(StorageResolver.class.getName());
/** Field _storageResolvers */
List<Object> _storageResolvers = null;
/** Field storageResolvers */
private List<StorageResolverSpi> storageResolvers = null;
/** Field _iterator */
Iterator<Object> _iterator = null;
/**
* Constructor StorageResolver
*
*/
public StorageResolver() {}
/**
* Constructor StorageResolver
*
*/
public StorageResolver() {}
/**
* Constructor StorageResolver
*
* @param resolver
*/
public StorageResolver(StorageResolverSpi resolver) {
this.add(resolver);
}
/**
* Constructor StorageResolver
*
* @param resolver
*/
public StorageResolver(StorageResolverSpi resolver) {
this.add(resolver);
}
/**
* Method addResolver
*
* @param resolver
*/
public void add(StorageResolverSpi resolver) {
if (storageResolvers == null) {
storageResolvers = new ArrayList<StorageResolverSpi>();
}
this.storageResolvers.add(resolver);
}
/**
* Method addResolver
*
* @param resolver
*/
public void add(StorageResolverSpi resolver) {
if (_storageResolvers==null)
_storageResolvers=new ArrayList<Object>();
this._storageResolvers.add(resolver);
/**
* Constructor StorageResolver
*
* @param keyStore
*/
public StorageResolver(KeyStore keyStore) {
this.add(keyStore);
}
this._iterator = null;
}
/**
* Method addKeyStore
*
* @param keyStore
*/
public void add(KeyStore keyStore) {
try {
this.add(new KeyStoreResolver(keyStore));
} catch (StorageResolverException ex) {
log.log(java.util.logging.Level.SEVERE, "Could not add KeyStore because of: ", ex);
}
}
/**
* Constructor StorageResolver
*
* @param keyStore
*/
public StorageResolver(KeyStore keyStore) {
this.add(keyStore);
}
/**
* Constructor StorageResolver
*
* @param x509certificate
*/
public StorageResolver(X509Certificate x509certificate) {
this.add(x509certificate);
}
/**
* Method addKeyStore
*
* @param keyStore
*/
public void add(KeyStore keyStore) {
/**
* Method addCertificate
*
* @param x509certificate
*/
public void add(X509Certificate x509certificate) {
this.add(new SingleCertificateResolver(x509certificate));
}
try {
this.add(new KeyStoreResolver(keyStore));
} catch (StorageResolverException ex) {
log.log(java.util.logging.Level.SEVERE, "Could not add KeyStore because of: ", ex);
}
}
/**
* Method getIterator
* @return the iterator for the resolvers.
*/
public Iterator<Certificate> getIterator() {
return new StorageResolverIterator(this.storageResolvers.iterator());
}
/**
* Constructor StorageResolver
*
* @param x509certificate
*/
public StorageResolver(X509Certificate x509certificate) {
this.add(x509certificate);
}
/**
* Class StorageResolverIterator
* This iterates over all the Certificates found in all the resolvers.
*/
static class StorageResolverIterator implements Iterator<Certificate> {
/**
* Method addCertificate
*
* @param x509certificate
*/
public void add(X509Certificate x509certificate) {
this.add(new SingleCertificateResolver(x509certificate));
}
/** Field resolvers */
Iterator<StorageResolverSpi> resolvers = null;
/**
* Method getIterator
* @return the iterator for the resolvers.
*
*/
public Iterator<Object> getIterator() {
/** Field currentResolver */
Iterator<Certificate> currentResolver = null;
if (this._iterator == null) {
if (_storageResolvers==null)
_storageResolvers=new ArrayList<Object>();
this._iterator = new StorageResolverIterator(this._storageResolvers.iterator());
}
/**
* Constructor StorageResolverIterator
*
* @param resolvers
*/
public StorageResolverIterator(Iterator<StorageResolverSpi> resolvers) {
this.resolvers = resolvers;
currentResolver = findNextResolver();
}
return this._iterator;
}
/** @inheritDoc */
public boolean hasNext() {
if (currentResolver == null) {
return false;
}
/**
* Method hasNext
*
* @return true if there is more elements.
*/
public boolean hasNext() {
if (currentResolver.hasNext()) {
return true;
}
if (this._iterator == null) {
if (_storageResolvers==null)
_storageResolvers=new ArrayList<Object>();
this._iterator = new StorageResolverIterator(this._storageResolvers.iterator());
}
currentResolver = findNextResolver();
return (currentResolver != null);
}
return this._iterator.hasNext();
}
/** @inheritDoc */
public Certificate next() {
if (hasNext()) {
return currentResolver.next();
}
/**
* Method next
*
* @return the next element
*/
public X509Certificate next() {
return (X509Certificate) this._iterator.next();
}
throw new NoSuchElementException();
}
/**
* Class StorageResolverIterator
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
static class StorageResolverIterator implements Iterator<Object> {
/**
* Method remove
*/
public void remove() {
throw new UnsupportedOperationException("Can't remove keys from KeyStore");
}
/** Field _resolvers */
Iterator<Object> _resolvers = null;
// Find the next storage with at least one element and return its Iterator
private Iterator<Certificate> findNextResolver() {
while (resolvers.hasNext()) {
StorageResolverSpi resolverSpi = resolvers.next();
Iterator<Certificate> iter = resolverSpi.getIterator();
if (iter.hasNext()) {
return iter;
}
}
/**
* Constructor FilesystemIterator
*
* @param resolvers
*/
public StorageResolverIterator(Iterator<Object> resolvers) {
this._resolvers = resolvers;
}
/** @inheritDoc */
public boolean hasNext() {
return _resolvers.hasNext();
}
/** @inheritDoc */
public Object next() {
return _resolvers.next();
}
/**
* Method remove
*/
public void remove() {
throw new UnsupportedOperationException(
"Can't remove keys from KeyStore");
}
}
return null;
}
}
}

View File

@ -2,86 +2,82 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.storage;
import com.sun.org.apache.xml.internal.security.exceptions.XMLSecurityException;
/**
*
* @author $Author: mullan $
*/
public class StorageResolverException extends XMLSecurityException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* Constructor StorageResolverException
*
*/
public StorageResolverException() {
super();
}
/**
* Constructor StorageResolverException
*
*/
public StorageResolverException() {
super();
}
/**
* Constructor StorageResolverException
*
* @param _msgID
*/
public StorageResolverException(String _msgID) {
super(_msgID);
}
/**
* Constructor StorageResolverException
*
* @param msgID
*/
public StorageResolverException(String msgID) {
super(msgID);
}
/**
* Constructor StorageResolverException
*
* @param _msgID
* @param exArgs
*/
public StorageResolverException(String _msgID, Object exArgs[]) {
super(_msgID, exArgs);
}
/**
* Constructor StorageResolverException
*
* @param msgID
* @param exArgs
*/
public StorageResolverException(String msgID, Object exArgs[]) {
super(msgID, exArgs);
}
/**
* Constructor StorageResolverException
*
* @param _msgID
* @param _originalException
*/
public StorageResolverException(String _msgID, Exception _originalException) {
super(_msgID, _originalException);
}
/**
* Constructor StorageResolverException
*
* @param msgID
* @param originalException
*/
public StorageResolverException(String msgID, Exception originalException) {
super(msgID, originalException);
}
/**
* Constructor StorageResolverException
*
* @param _msgID
* @param exArgs
* @param _originalException
*/
public StorageResolverException(String _msgID, Object exArgs[],
Exception _originalException) {
super(_msgID, exArgs, _originalException);
}
/**
* Constructor StorageResolverException
*
* @param msgID
* @param exArgs
* @param originalException
*/
public StorageResolverException(String msgID, Object exArgs[],
Exception originalException) {
super(msgID, exArgs, originalException);
}
}

View File

@ -2,39 +2,35 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.storage;
import java.security.cert.Certificate;
import java.util.Iterator;
/**
*
* @author $Author: mullan $
*/
public abstract class StorageResolverSpi {
/**
* Method getIterator
*
* @return the iterator for the storage
*/
public abstract Iterator<?> getIterator();
/**
* Method getIterator
*
* @return the iterator for the storage
*/
public abstract Iterator<Certificate> getIterator();
}

View File

@ -2,21 +2,23 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.storage.implementations;
@ -24,6 +26,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateFactory;
@ -39,188 +42,188 @@ import com.sun.org.apache.xml.internal.security.utils.Base64;
/**
* This {@link StorageResolverSpi} makes all raw (binary) {@link X509Certificate}s
* which reside as files in a single directory available to the {@link com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver}.
*
* @author $Author: mullan $
* which reside as files in a single directory available to the
* {@link com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver}.
*/
public class CertsInFilesystemDirectoryResolver extends StorageResolverSpi {
/** {@link java.util.logging} logging facility */
static java.util.logging.Logger log =
/** {@link org.apache.commons.logging} logging facility */
private static java.util.logging.Logger log =
java.util.logging.Logger.getLogger(
CertsInFilesystemDirectoryResolver.class.getName());
CertsInFilesystemDirectoryResolver.class.getName()
);
/** Field _merlinsCertificatesDir */
String _merlinsCertificatesDir = null;
/** Field merlinsCertificatesDir */
private String merlinsCertificatesDir = null;
/** Field _certs */
private List<X509Certificate> _certs = new ArrayList<X509Certificate>();
/** Field certs */
private List<X509Certificate> certs = new ArrayList<X509Certificate>();
/** Field _iterator */
Iterator<X509Certificate> _iterator = null;
/**
* @param directoryName
* @throws StorageResolverException
*/
public CertsInFilesystemDirectoryResolver(String directoryName)
throws StorageResolverException {
this.merlinsCertificatesDir = directoryName;
/**
*
*
* @param directoryName
* @throws StorageResolverException
*/
public CertsInFilesystemDirectoryResolver(String directoryName)
throws StorageResolverException {
this.readCertsFromHarddrive();
}
this._merlinsCertificatesDir = directoryName;
/**
* Method readCertsFromHarddrive
*
* @throws StorageResolverException
*/
private void readCertsFromHarddrive() throws StorageResolverException {
this.readCertsFromHarddrive();
File certDir = new File(this.merlinsCertificatesDir);
List<String> al = new ArrayList<String>();
String[] names = certDir.list();
this._iterator = new FilesystemIterator(this._certs);
}
for (int i = 0; i < names.length; i++) {
String currentFileName = names[i];
/**
* Method readCertsFromHarddrive
*
* @throws StorageResolverException
*/
private void readCertsFromHarddrive() throws StorageResolverException {
if (currentFileName.endsWith(".crt")) {
al.add(names[i]);
}
}
File certDir = new File(this._merlinsCertificatesDir);
ArrayList<String> al = new ArrayList<String>();
String[] names = certDir.list();
CertificateFactory cf = null;
for (int i = 0; i < names.length; i++) {
String currentFileName = names[i];
try {
cf = CertificateFactory.getInstance("X.509");
} catch (CertificateException ex) {
throw new StorageResolverException("empty", ex);
}
if (currentFileName.endsWith(".crt")) {
al.add(names[i]);
}
}
if (cf == null) {
throw new StorageResolverException("empty");
}
CertificateFactory cf = null;
for (int i = 0; i < al.size(); i++) {
String filename = certDir.getAbsolutePath() + File.separator + al.get(i);
File file = new File(filename);
boolean added = false;
String dn = null;
try {
cf = CertificateFactory.getInstance("X.509");
} catch (CertificateException ex) {
throw new StorageResolverException("empty", ex);
}
FileInputStream fis = null;
try {
fis = new FileInputStream(file);
X509Certificate cert =
(X509Certificate) cf.generateCertificate(fis);
if (cf == null) {
throw new StorageResolverException("empty");
}
//add to ArrayList
cert.checkValidity();
this.certs.add(cert);
for (int i = 0; i < al.size(); i++) {
String filename = certDir.getAbsolutePath() + File.separator
+ al.get(i);
File file = new File(filename);
boolean added = false;
String dn = null;
dn = cert.getSubjectX500Principal().getName();
added = true;
} catch (FileNotFoundException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} catch (CertificateNotYetValidException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} catch (CertificateExpiredException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} catch (CertificateException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException ex) {
if (log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
}
}
try {
FileInputStream fis = new FileInputStream(file);
X509Certificate cert =
(X509Certificate) cf.generateCertificate(fis);
fis.close();
//add to ArrayList
cert.checkValidity();
this._certs.add(cert);
dn = cert.getSubjectDN().getName();
added = true;
} catch (FileNotFoundException ex) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
} catch (IOException ex) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
} catch (CertificateNotYetValidException ex) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
} catch (CertificateExpiredException ex) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
} catch (CertificateException ex) {
log.log(java.util.logging.Level.FINE, "Could not add certificate from file " + filename, ex);
}
if (added) {
if (log.isLoggable(java.util.logging.Level.FINE))
if (added && log.isLoggable(java.util.logging.Level.FINE)) {
log.log(java.util.logging.Level.FINE, "Added certificate: " + dn);
}
}
}
}
}
}
/** @inheritDoc */
public Iterator<X509Certificate> getIterator() {
return this._iterator;
}
/** @inheritDoc */
public Iterator<Certificate> getIterator() {
return new FilesystemIterator(this.certs);
}
/**
* Class FilesystemIterator
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
private static class FilesystemIterator implements Iterator<X509Certificate> {
/**
* Class FilesystemIterator
*/
private static class FilesystemIterator implements Iterator<Certificate> {
/** Field _certs */
List<X509Certificate> _certs = null;
/** Field certs */
List<X509Certificate> certs = null;
/** Field _i */
int _i;
/** Field i */
int i;
/**
* Constructor FilesystemIterator
*
* @param certs
*/
public FilesystemIterator(List<X509Certificate> certs) {
this._certs = certs;
this._i = 0;
}
/**
* Constructor FilesystemIterator
*
* @param certs
*/
public FilesystemIterator(List<X509Certificate> certs) {
this.certs = certs;
this.i = 0;
}
/** @inheritDoc */
public boolean hasNext() {
return (this._i < this._certs.size());
}
/** @inheritDoc */
public boolean hasNext() {
return (this.i < this.certs.size());
}
/** @inheritDoc */
public X509Certificate next() {
return this._certs.get(this._i++);
}
/** @inheritDoc */
public Certificate next() {
return this.certs.get(this.i++);
}
/**
* Method remove
*
*/
public void remove() {
throw new UnsupportedOperationException(
"Can't remove keys from KeyStore");
}
}
/**
* Method remove
*
*/
public void remove() {
throw new UnsupportedOperationException("Can't remove keys from KeyStore");
}
}
/**
* Method main
*
* @param unused
* @throws Exception
*/
public static void main(String unused[]) throws Exception {
/**
* Method main
*
* @param unused
* @throws Exception
*/
public static void main(String unused[]) throws Exception {
CertsInFilesystemDirectoryResolver krs =
new CertsInFilesystemDirectoryResolver(
"data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");
CertsInFilesystemDirectoryResolver krs =
new CertsInFilesystemDirectoryResolver(
"data/ie/baltimore/merlin-examples/merlin-xmldsig-eighteen/certs");
for (Iterator<X509Certificate> i = krs.getIterator(); i.hasNext(); ) {
X509Certificate cert = i.next();
byte[] ski =
com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI
.getSKIBytesFromCert(cert);
for (Iterator<Certificate> i = krs.getIterator(); i.hasNext(); ) {
X509Certificate cert = (X509Certificate) i.next();
byte[] ski =
com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI.getSKIBytesFromCert(cert);
System.out.println();
System.out.println("Base64(SKI())= \""
+ Base64.encode(ski) + "\"");
System.out.println("cert.getSerialNumber()= \""
+ cert.getSerialNumber().toString() + "\"");
System.out.println("cert.getSubjectDN().getName()= \""
+ cert.getSubjectDN().getName() + "\"");
System.out.println("cert.getIssuerDN().getName()= \""
+ cert.getIssuerDN().getName() + "\"");
}
}
System.out.println();
System.out.println("Base64(SKI())= \""
+ Base64.encode(ski) + "\"");
System.out.println("cert.getSerialNumber()= \""
+ cert.getSerialNumber().toString() + "\"");
System.out.println("cert.getSubjectX500Principal().getName()= \""
+ cert.getSubjectX500Principal().getName() + "\"");
System.out.println("cert.getIssuerX500Principal().getName()= \""
+ cert.getIssuerX500Principal().getName() + "\"");
}
}
}

View File

@ -2,147 +2,152 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.storage.implementations;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.cert.X509Certificate;
import java.security.cert.Certificate;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolverException;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolverSpi;
/**
* Makes the Certificates from a JAVA {@link KeyStore} object available to the
* {@link com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver}.
*
* @author $Author: mullan $
*/
public class KeyStoreResolver extends StorageResolverSpi {
/** Field _keyStore */
KeyStore _keyStore = null;
/** Field keyStore */
private KeyStore keyStore = null;
/** Field _iterator */
Iterator<X509Certificate> _iterator = null;
/**
* Constructor KeyStoreResolver
*
* @param keyStore is the keystore which contains the Certificates
* @throws StorageResolverException
*/
public KeyStoreResolver(KeyStore keyStore) throws StorageResolverException {
this._keyStore = keyStore;
this._iterator = new KeyStoreIterator(this._keyStore);
}
/** @inheritDoc */
public Iterator<X509Certificate> getIterator() {
return this._iterator;
}
/**
* Class KeyStoreIterator
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
static class KeyStoreIterator implements Iterator<X509Certificate> {
/** Field _keyStore */
KeyStore _keyStore = null;
/** Field _aliases */
Enumeration<String> _aliases = null;
/**
* Constructor KeyStoreIterator
*
* @param keyStore
* @throws StorageResolverException
*/
public KeyStoreIterator(KeyStore keyStore)
throws StorageResolverException {
try {
this._keyStore = keyStore;
this._aliases = this._keyStore.aliases();
} catch (KeyStoreException ex) {
/**
* Constructor KeyStoreResolver
*
* @param keyStore is the keystore which contains the Certificates
* @throws StorageResolverException
*/
public KeyStoreResolver(KeyStore keyStore) throws StorageResolverException {
this.keyStore = keyStore;
// Do a quick check on the keystore
try {
keyStore.aliases();
} catch (KeyStoreException ex) {
throw new StorageResolverException("generic.EmptyMessage", ex);
}
}
}
}
/** @inheritDoc */
public boolean hasNext() {
return this._aliases.hasMoreElements();
}
/** @inheritDoc */
public Iterator<Certificate> getIterator() {
return new KeyStoreIterator(this.keyStore);
}
/** @inheritDoc */
@SuppressWarnings("unchecked")
public X509Certificate next() {
/**
* Class KeyStoreIterator
*/
static class KeyStoreIterator implements Iterator<Certificate> {
String alias = this._aliases.nextElement();
/** Field keyStore */
KeyStore keyStore = null;
/** Field aliases */
Enumeration<String> aliases = null;
/** Field nextCert */
Certificate nextCert = null;
/**
* Constructor KeyStoreIterator
*
* @param keyStore
*/
public KeyStoreIterator(KeyStore keyStore) {
try {
this.keyStore = keyStore;
this.aliases = this.keyStore.aliases();
} catch (KeyStoreException ex) {
// empty Enumeration
this.aliases = new Enumeration<String>() {
public boolean hasMoreElements() {
return false;
}
public String nextElement() {
return null;
}
};
}
}
/** @inheritDoc */
public boolean hasNext() {
if (nextCert == null) {
nextCert = findNextCert();
}
return (nextCert != null);
}
/** @inheritDoc */
public Certificate next() {
if (nextCert == null) {
// maybe caller did not call hasNext()
nextCert = findNextCert();
if (nextCert == null) {
throw new NoSuchElementException();
}
}
Certificate ret = nextCert;
nextCert = null;
return ret;
}
/**
* Method remove
*/
public void remove() {
throw new UnsupportedOperationException("Can't remove keys from KeyStore");
}
// Find the next entry that contains a certificate and return it.
// In particular, this skips over entries containing symmetric keys.
private Certificate findNextCert() {
while (this.aliases.hasMoreElements()) {
String alias = this.aliases.nextElement();
try {
Certificate cert = this.keyStore.getCertificate(alias);
if (cert != null) {
return cert;
}
} catch (KeyStoreException ex) {
return null;
}
}
try {
return (X509Certificate)this._keyStore.getCertificate(alias);
} catch (KeyStoreException ex) {
return null;
}
}
}
/**
* Method remove
*
*/
public void remove() {
throw new UnsupportedOperationException(
"Can't remove keys from KeyStore");
}
}
}
/**
* Method main
*
* @param unused
* @throws Exception
*/
public static void main(String unused[]) throws Exception {
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(
new java.io.FileInputStream(
"data/com/sun/org/apache/xml/internal/security/samples/input/keystore.jks"),
"xmlsecurity".toCharArray());
KeyStoreResolver krs = new KeyStoreResolver(ks);
for (Iterator<X509Certificate> i = krs.getIterator(); i.hasNext(); ) {
X509Certificate cert = i.next();
byte[] ski =
com.sun.org.apache.xml.internal.security.keys.content.x509.XMLX509SKI
.getSKIBytesFromCert(cert);
System.out.println(com.sun.org.apache.xml.internal.security.utils.Base64.encode(ski));
}
}
}

View File

@ -2,102 +2,93 @@
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* 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.
* 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.
*/
package com.sun.org.apache.xml.internal.security.keys.storage.implementations;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import java.util.NoSuchElementException;
import com.sun.org.apache.xml.internal.security.keys.storage.StorageResolverSpi;
/**
* This {@link StorageResolverSpi} makes a single {@link X509Certificate}
* available to the {@link com.sun.org.apache.xml.internal.security.keys.storage.StorageResolver}.
*
* @author $Author: mullan $
*/
public class SingleCertificateResolver extends StorageResolverSpi {
/** Field _certificate */
X509Certificate _certificate = null;
/** Field certificate */
private X509Certificate certificate = null;
/** Field _iterator */
Iterator<X509Certificate> _iterator = null;
/**
* @param x509cert the single {@link X509Certificate}
*/
public SingleCertificateResolver(X509Certificate x509cert) {
this.certificate = x509cert;
}
/**
*
*
* @param x509cert the single {@link X509Certificate}
*/
public SingleCertificateResolver(X509Certificate x509cert) {
this._certificate = x509cert;
this._iterator = new InternalIterator(this._certificate);
}
/** @inheritDoc */
public Iterator<Certificate> getIterator() {
return new InternalIterator(this.certificate);
}
/** @inheritDoc */
public Iterator<X509Certificate> getIterator() {
return this._iterator;
}
/**
* Class InternalIterator
*/
static class InternalIterator implements Iterator<Certificate> {
/**
* Class InternalIterator
*
* @author $Author: mullan $
* @version $Revision: 1.5 $
*/
static class InternalIterator implements Iterator<X509Certificate> {
/** Field alreadyReturned */
boolean alreadyReturned = false;
/** Field _alreadyReturned */
boolean _alreadyReturned = false;
/** Field certificate */
X509Certificate certificate = null;
/** Field _certificate */
X509Certificate _certificate = null;
/**
* Constructor InternalIterator
*
* @param x509cert
*/
public InternalIterator(X509Certificate x509cert) {
this.certificate = x509cert;
}
/**
* Constructor InternalIterator
*
* @param x509cert
*/
public InternalIterator(X509Certificate x509cert) {
this._certificate = x509cert;
}
/** @inheritDoc */
public boolean hasNext() {
return !this.alreadyReturned;
}
/** @inheritDoc */
public boolean hasNext() {
return (!this._alreadyReturned);
}
/** @inheritDoc */
public Certificate next() {
if (this.alreadyReturned) {
throw new NoSuchElementException();
}
this.alreadyReturned = true;
return this.certificate;
}
/** @inheritDoc */
public X509Certificate next() {
this._alreadyReturned = true;
return this._certificate;
}
/**
* Method remove
*
*/
public void remove() {
throw new UnsupportedOperationException(
"Can't remove keys from KeyStore");
}
}
/**
* Method remove
*/
public void remove() {
throw new UnsupportedOperationException("Can't remove keys from KeyStore");
}
}
}

View File

@ -52,9 +52,6 @@
<TransformAlgorithm URI="http://www.w3.org/TR/1999/REC-xslt-19991116"
JAVACLASS="com.sun.org.apache.xml.internal.security.transforms.implementations.TransformXSLT" />
<!-- XPath version 2 -->
<TransformAlgorithm URI="http://www.w3.org/2002/04/xmldsig-filter2"
JAVACLASS="com.sun.org.apache.xml.internal.security.transforms.implementations.TransformXPath2Filter" />
<!-- XPath version 2b -->
<TransformAlgorithm URI="http://www.w3.org/2002/06/xmldsig-filter2"
JAVACLASS="com.sun.org.apache.xml.internal.security.transforms.implementations.TransformXPath2Filter" />
</TransformAlgorithms>
@ -78,6 +75,12 @@
JAVACLASS="com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureBaseRSA$SignatureRSASHA512" />
<SignatureAlgorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"
JAVACLASS="com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureECDSA$SignatureECDSASHA1" />
<SignatureAlgorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"
JAVACLASS="com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureECDSA$SignatureECDSASHA256" />
<SignatureAlgorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384"
JAVACLASS="com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureECDSA$SignatureECDSASHA384" />
<SignatureAlgorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"
JAVACLASS="com.sun.org.apache.xml.internal.security.algorithms.implementations.SignatureECDSA$SignatureECDSASHA512" />
<SignatureAlgorithm URI="http://www.w3.org/2001/04/xmldsig-more#hmac-md5"
JAVACLASS="com.sun.org.apache.xml.internal.security.algorithms.implementations.IntegrityHmac$IntegrityHmacMD5" />
@ -97,7 +100,7 @@
Description="MD5 message digest from RFC 1321"
AlgorithmClass="MessageDigest"
RequirementLevel="NOT RECOMMENDED"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="MD5"/>
<Algorithm URI="http://www.w3.org/2001/04/xmlenc#ripemd160"
@ -122,7 +125,7 @@
Description="SHA message digest with 384 bit"
AlgorithmClass="MessageDigest"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA-384"/>
<Algorithm URI="http://www.w3.org/2001/04/xmlenc#sha512"
@ -142,14 +145,14 @@
Description="RSA Signature with MD5 message digest"
AlgorithmClass="Signature"
RequirementLevel="NOT RECOMMENDED"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="MD5withRSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-ripemd160"
Description="RSA Signature with RIPEMD-160 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="RIPEMD160withRSA"/>
<Algorithm URI="http://www.w3.org/2000/09/xmldsig#rsa-sha1"
@ -162,43 +165,64 @@
Description="RSA Signature with SHA-256 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA256withRSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-sha384"
Description="RSA Signature with SHA-384 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA384withRSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
Description="RSA Signature with SHA-512 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA512withRSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha1"
Description="ECDSA Signature with SHA-1 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
JCEName="ECDSAwithSHA1"/>
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA1withECDSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256"
Description="ECDSA Signature with SHA-256 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA256withECDSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384"
Description="ECDSA Signature with SHA-384 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA384withECDSA"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512"
Description="ECDSA Signature with SHA-512 message digest"
AlgorithmClass="Signature"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="SHA512withECDSA"/>
<!-- MAC Algorithms -->
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#hmac-md5"
Description="Message Authentication code using MD5"
AlgorithmClass="Mac"
RequirementLevel="NOT RECOMMENDED"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="HmacMD5"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#hmac-ripemd160"
Description="Message Authentication code using RIPEMD-160"
AlgorithmClass="Mac"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="HMACRIPEMD160"/>
<Algorithm URI="http://www.w3.org/2000/09/xmldsig#hmac-sha1"
@ -211,21 +235,21 @@
Description="Message Authentication code using SHA-256"
AlgorithmClass="Mac"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="HmacSHA256"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#hmac-sha384"
Description="Message Authentication code using SHA-384"
AlgorithmClass="Mac"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="HmacSHA384"/>
<Algorithm URI="http://www.w3.org/2001/04/xmldsig-more#hmac-sha512"
Description="Message Authentication code using SHA-512"
AlgorithmClass="Mac"
RequirementLevel="OPTIONAL"
SpecificationURL="http://www.ietf.org/internet-drafts/draft-eastlake-xmldsig-uri-02.txt"
SpecificationURL="http://www.ietf.org/rfc/rfc4051.txt"
JCEName="HmacSHA512"/>
<!-- Block encryption Algorithms -->
@ -260,7 +284,31 @@
KeyLength="256"
RequiredKey="AES"
JCEName="AES/CBC/ISO10126Padding"/>
<Algorithm URI="http://www.w3.org/2009/xmlenc11#aes128-gcm"
Description="Block encryption using AES with a key length of 128 bit in GCM"
AlgorithmClass="BlockEncryption"
RequirementLevel="OPTIONAL"
KeyLength="128"
RequiredKey="AES"
JCEName="AES/GCM/NoPadding"/>
<Algorithm URI="http://www.w3.org/2009/xmlenc11#aes192-gcm"
Description="Block encryption using AES with a key length of 192 bit in GCM"
AlgorithmClass="BlockEncryption"
RequirementLevel="OPTIONAL"
KeyLength="192"
RequiredKey="AES"
JCEName="AES/GCM/NoPadding"/>
<Algorithm URI="http://www.w3.org/2009/xmlenc11#aes256-gcm"
Description="Block encryption using AES with a key length of 256 bit in GCM"
AlgorithmClass="BlockEncryption"
RequirementLevel="OPTIONAL"
KeyLength="256"
RequiredKey="AES"
JCEName="AES/GCM/NoPadding"/>
<Algorithm URI="http://www.w3.org/2001/04/xmlenc#rsa-1_5"
Description="Key Transport RSA-v1.5"
AlgorithmClass="KeyTransport"
@ -273,7 +321,14 @@
AlgorithmClass="KeyTransport"
RequirementLevel="REQUIRED"
RequiredKey="RSA"
JCEName="RSA/ECB/OAEPWithSHA1AndMGF1Padding"/>
JCEName="RSA/ECB/OAEPPadding"/>
<Algorithm URI="http://www.w3.org/2009/xmlenc11#rsa-oaep"
Description="Key Transport RSA-OAEP"
AlgorithmClass="KeyTransport"
RequirementLevel="OPTIONAL"
RequiredKey="RSA"
JCEName="RSA/ECB/OAEPPadding"/>
<Algorithm URI="http://www.w3.org/2001/04/xmlenc#dh"
Description="Key Agreement Diffie-Hellman"
@ -314,14 +369,7 @@
</Algorithms>
</JCEAlgorithmMappings>
<ResourceBundles defaultLanguageCode="en" defaultCountryCode="US">
<ResourceBundle LanguageCode="en"
CountryCode="US"
LOCATION="com.sun.org.apache.xml.internal.security/resource/xmlsecurity_en.properties" />
<ResourceBundle LanguageCode="de"
CountryCode="DE"
LOCATION="com.sun.org.apache.xml.internal.security/resource/xmlsecurity_de.properties" />
</ResourceBundles>
<ResourceBundles defaultLanguageCode="en" defaultCountryCode="US"/>
<ResourceResolvers>
<Resolver JAVACLASS="com.sun.org.apache.xml.internal.security.utils.resolver.implementations.ResolverDirectHTTP"
DESCRIPTION="A simple resolver for requests to HTTP space" />
@ -330,32 +378,8 @@
<Resolver JAVACLASS="com.sun.org.apache.xml.internal.security.utils.resolver.implementations.ResolverFragment"
DESCRIPTION="A simple resolver for requests of same-document URIs" />
<Resolver JAVACLASS="com.sun.org.apache.xml.internal.security.utils.resolver.implementations.ResolverXPointer"
DESCRIPTION="A simple resolver for requests of XPointer fragents" />
DESCRIPTION="A simple resolver for requests of XPointer fragments" />
</ResourceResolvers>
<!-- <defaultLocale languageCode="en" countryCode="US" /> -->
<KeyInfo>
<ContentHandler LOCALNAME="KeyName"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.KeyName" />
<ContentHandler LOCALNAME="KeyValue"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.KeyValue" />
<ContentHandler LOCALNAME="RetrievalMethod"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.RetrievalMethod" />
<ContentHandler LOCALNAME="X509Data"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.X509Data" />
<ContentHandler LOCALNAME="PGPData"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.PGPData" />
<ContentHandler LOCALNAME="SPKIData"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.SPKIData" />
<ContentHandler LOCALNAME="MgmtData"
NAMESPACE="http://www.w3.org/2000/09/xmldsig#"
JAVACLASS="com.sun.org.apache.xml.internal.security.keys.content.MgmtData" />
</KeyInfo>
<KeyResolver>
<!-- This section contains a list of KeyResolvers that are available in
every KeyInfo object -->

Some files were not shown because too many files have changed in this diff Show More