/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
/*
*/
/*
* ===========================================================================
*
* (C) Copyright IBM Corp. 2003 All Rights Reserved.
*
* ===========================================================================
*/
/*
* $Id: DOMReference.java,v 1.2 2008/07/24 15:20:32 mullan Exp $
*/
/**
* DOM-based implementation of Reference.
*
* @author Sean Mullan
* @author Joyce Leung
*/
implements Reference, DOMURIReference {
/**
* The maximum number of transforms per reference, if secure validation
* is enabled.
*/
/**
* Look up useC14N11 system property. If true, an explicit C14N11 transform
* will be added if necessary when generating the signature. See section
* 3.1.1 of http://www.w3.org/2007/xmlsec/Drafts/xmldsig-core/ for more info.
*
* If true, overrides the same property if set in the XMLSignContext.
*/
private static boolean useC14N11 =
return Boolean.getBoolean
("com.sun.org.apache.xml.internal.security.useC14N11");
}
});
private byte[] digestValue;
private byte[] calcDigestValue;
private boolean digested = false;
private boolean validated = false;
private boolean validationStatus;
/**
* Creates a <code>Reference</code> from the specified parameters.
*
* @param uri the URI (may be null)
* @param type the type (may be null)
* @param dm the digest method
* @param transforms a list of {@link Transform}s. The list
* is defensively copied to protect against subsequent modification.
* May be <code>null</code> or empty.
* @param id the reference ID (may be <code>null</code>)
* @return a <code>Reference</code>
* @throws NullPointerException if <code>dm</code> is <code>null</code>
* @throws ClassCastException if any of the <code>transforms</code> are
* not of type <code>Transform</code>
*/
}
}
throw new NullPointerException("DigestMethod must be non-null");
}
this.allTransforms = new ArrayList();
if (appliedTransforms != null) {
throw new ClassCastException
("appliedTransforms["+i+"] is not a valid type");
}
}
this.allTransforms = transformsCopy;
}
if (transforms == null) {
} else {
throw new ClassCastException
("transforms["+i+"] is not a valid type");
}
}
this.transforms = transformsCopy;
}
this.digestMethod = dm;
try {
} catch (URISyntaxException e) {
throw new IllegalArgumentException(e.getMessage());
}
}
if (digestValue != null) {
this.digested = true;
}
this.appliedTransformData = result;
}
/**
* Creates a <code>DOMReference</code> from an element.
*
* @param refElem a Reference element
*/
// unmarshal Transforms, if specified
int transformCount = 0;
while (transformElem != null) {
" transforms per Reference are allowed" +
" with secure validation";
throw new MarshalException(error);
}
}
}
// unmarshal DigestMethod
if (secVal
{
throw new MarshalException("It is forbidden to use algorithm " +
" when secure validation is enabled");
}
// unmarshal DigestValue
try {
} catch (Base64DecodingException bde) {
throw new MarshalException(bde);
}
// unmarshal attributes
} else {
}
this.transforms = transforms;
this.allTransforms = transforms;
this.appliedTransformData = null;
}
return digestMethod;
}
return id;
}
return uri;
}
return type;
}
}
public byte[] getDigestValue() {
}
public byte[] getCalculatedDigestValue() {
: (byte[]) calcDigestValue.clone());
}
throws MarshalException {
}
// set attributes
// create and append Transforms element
if (!allTransforms.isEmpty()) {
}
}
// create and append DigestMethod element
// create and append DigestValue element
}
if (digestValue != null) {
}
}
throws XMLSignatureException {
if (appliedTransformData == null) {
} else {
}
// insert digestValue into DigestValue element
}
if (digestElem == null) {
throw new XMLSignatureException("DigestValue element expected");
}
digested = true;
}
}
throws XMLSignatureException {
if (validateContext == null) {
throw new NullPointerException("validateContext cannot be null");
}
if (validated) {
return validationStatus;
}
}
validated = true;
return validationStatus;
}
return derefData;
}
return dis;
}
throws XMLSignatureException {
// use user-specified URIDereferencer if specified; otherwise use deflt
}
try {
}
} catch (URIReferenceException ure) {
throw new XMLSignatureException(ure);
}
return data;
}
try {
} catch (NoSuchAlgorithmException nsae) {
throw new XMLSignatureException(nsae);
}
}
} else {
}
try {
if (i < size - 1) {
} else {
}
} catch (TransformException te) {
throw new XMLSignatureException(te);
}
}
try {
// explicitly use C14N 1.1 when generating signature
// first check system property, then context property
if (context instanceof XMLSignContext) {
if (!c14n11) {
("com.sun.org.apache.xml.internal.security.useC14N11");
if (c14n11) {
}
} else {
}
}
if (data instanceof ApacheData) {
} else if (data instanceof OctetStreamData) {
xi = new XMLSignatureInput
} else if (data instanceof NodeSetData) {
try {
} catch (NoSuchAlgorithmException nsae) {
}
xi = new XMLSignatureInput
} else {
throw new XMLSignatureException("unrecognized Data type");
}
DOMTransform t = new DOMTransform
if (allTransforms.isEmpty()) {
} else {
}
allTransforms.add(t);
} else {
}
}
}
return dos.getDigestValue();
} catch (Exception e) {
throw new XMLSignatureException(e);
}
}
return here;
}
if (this == o) {
return true;
}
if (!(o instanceof Reference)) {
return false;
}
boolean digestValuesEqual =
}
boolean isDigested() {
return digested;
}
if (dereferencedData instanceof ApacheData) {
// need to make a copy of the Data
try {
return new NodeSetData() {
};
} catch (Exception e) {
// log a warning
"cannot cache dereferenced data: " + e);
return null;
}
return new DOMSubTreeData
try {
return new OctetStreamData
} catch (IOException ioe) {
// log a warning
"cannot cache dereferenced data: " + ioe);
return null;
}
}
}
return dereferencedData;
}
}