feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,104 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: CanonicalizationMethod.java,v 1.6 2005/05/10 16:03:45 mullan Exp $
*/
package javax.xml.crypto.dsig;
import java.security.spec.AlgorithmParameterSpec;
import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
/**
* A representation of the XML <code>CanonicalizationMethod</code>
* element as defined in the
* <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>. The XML
* Schema Definition is defined as:
* <p>
* <pre>
* &lt;element name="CanonicalizationMethod" type="ds:CanonicalizationMethodType"/&gt;
* &lt;complexType name="CanonicalizationMethodType" mixed="true"&gt;
* &lt;sequence&gt;
* &lt;any namespace="##any" minOccurs="0" maxOccurs="unbounded"/&gt;
* &lt;!-- (0,unbounded) elements from (1,1) namespace --&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Algorithm" type="anyURI" use="required"/&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>CanonicalizationMethod</code> instance may be created by invoking
* the {@link XMLSignatureFactory#newCanonicalizationMethod
* newCanonicalizationMethod} method of the {@link XMLSignatureFactory} class.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newCanonicalizationMethod(String, C14NMethodParameterSpec)
*/
public interface CanonicalizationMethod extends Transform {
/**
* The <a href="http://www.w3.org/TR/2001/REC-xml-c14n-20010315">Canonical
* XML (without comments)</a> canonicalization method algorithm URI.
*/
final static String INCLUSIVE =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315";
/**
* The
* <a href="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments">
* Canonical XML with comments</a> canonicalization method algorithm URI.
*/
final static String INCLUSIVE_WITH_COMMENTS =
"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments";
/**
* The <a href="http://www.w3.org/2001/10/xml-exc-c14n#">Exclusive
* Canonical XML (without comments)</a> canonicalization method algorithm
* URI.
*/
final static String EXCLUSIVE =
"http://www.w3.org/2001/10/xml-exc-c14n#";
/**
* The <a href="http://www.w3.org/2001/10/xml-exc-c14n#WithComments">
* Exclusive Canonical XML with comments</a> canonicalization method
* algorithm URI.
*/
final static String EXCLUSIVE_WITH_COMMENTS =
"http://www.w3.org/2001/10/xml-exc-c14n#WithComments";
/**
* Returns the algorithm-specific input parameters associated with this
* <code>CanonicalizationMethod</code>.
*
* <p>The returned parameters can be typecast to a
* {@link C14NMethodParameterSpec} object.
*
* @return the algorithm-specific input parameters (may be
* <code>null</code> if not specified)
*/
AlgorithmParameterSpec getParameterSpec();
}

View File

@@ -0,0 +1,100 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: DigestMethod.java,v 1.6 2005/05/10 16:03:46 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.AlgorithmMethod;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;
import java.security.spec.AlgorithmParameterSpec;
/**
* A representation of the XML <code>DigestMethod</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <p>
* <pre>
* &lt;element name="DigestMethod" type="ds:DigestMethodType"/&gt;
* &lt;complexType name="DigestMethodType" mixed="true"&gt;
* &lt;sequence&gt;
* &lt;any namespace="##any" minOccurs="0" maxOccurs="unbounded"/&gt;
* &lt;!-- (0,unbounded) elements from (1,1) namespace --&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Algorithm" type="anyURI" use="required"/&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>DigestMethod</code> instance may be created by invoking the
* {@link XMLSignatureFactory#newDigestMethod newDigestMethod} method
* of the {@link XMLSignatureFactory} class.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newDigestMethod(String, DigestMethodParameterSpec)
*/
public interface DigestMethod extends XMLStructure, AlgorithmMethod {
// All methods can be found in RFC 6931.
/**
* The <a href="http://www.w3.org/2000/09/xmldsig#sha1">
* SHA1</a> digest method algorithm URI.
*/
String SHA1 = "http://www.w3.org/2000/09/xmldsig#sha1";
/**
* The <a href="http://www.w3.org/2001/04/xmlenc#sha256">
* SHA256</a> digest method algorithm URI.
*/
String SHA256 = "http://www.w3.org/2001/04/xmlenc#sha256";
/**
* The <a href="http://www.w3.org/2001/04/xmlenc#sha512">
* SHA512</a> digest method algorithm URI.
*/
String SHA512 = "http://www.w3.org/2001/04/xmlenc#sha512";
/**
* The <a href="http://www.w3.org/2001/04/xmlenc#ripemd160">
* RIPEMD-160</a> digest method algorithm URI.
*/
String RIPEMD160 = "http://www.w3.org/2001/04/xmlenc#ripemd160";
/**
* Returns the algorithm-specific input parameters associated with this
* <code>DigestMethod</code>.
*
* <p>The returned parameters can be typecast to a {@link
* DigestMethodParameterSpec} object.
*
* @return the algorithm-specific parameters (may be <code>null</code> if
* not specified)
*/
AlgorithmParameterSpec getParameterSpec();
}

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: Manifest.java,v 1.7 2005/05/10 16:03:46 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.XMLStructure;
import java.util.List;
/**
* A representation of the XML <code>Manifest</code> element as defined in
* the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <pre>{@code
* <element name="Manifest" type="ds:ManifestType"/>
* <complexType name="ManifestType">
* <sequence>
* <element ref="ds:Reference" maxOccurs="unbounded"/>
* </sequence>
* <attribute name="Id" type="ID" use="optional"/>
* </complexType>
* }</pre>
*
* A <code>Manifest</code> instance may be created by invoking
* one of the {@link XMLSignatureFactory#newManifest newManifest}
* methods of the {@link XMLSignatureFactory} class; for example:
*
* <pre>
* XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
* List references = Collections.singletonList(factory.newReference
* ("#reference-1", DigestMethod.SHA1));
* Manifest manifest = factory.newManifest(references, "manifest-1");
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newManifest(List)
* @see XMLSignatureFactory#newManifest(List, String)
*/
public interface Manifest extends XMLStructure {
/**
* URI that identifies the <code>Manifest</code> element (this can be
* specified as the value of the <code>type</code> parameter of the
* {@link Reference} class to identify the referent's type).
*/
final static String TYPE = "http://www.w3.org/2000/09/xmldsig#Manifest";
/**
* Returns the Id of this <code>Manifest</code>.
*
* @return the Id of this <code>Manifest</code> (or <code>null</code>
* if not specified)
*/
String getId();
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of one or more {@link Reference}s that are contained in this
* <code>Manifest</code>.
*
* @return an unmodifiable list of one or more <code>Reference</code>s
*/
@SuppressWarnings("rawtypes")
List getReferences();
}

View File

@@ -0,0 +1,169 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: Reference.java,v 1.9 2005/05/10 16:03:46 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.Data;
import javax.xml.crypto.URIReference;
import javax.xml.crypto.XMLStructure;
import java.io.InputStream;
import java.util.List;
/**
* A representation of the <code>Reference</code> element as defined in the
* <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML schema is defined as:
* <code><pre>
* &lt;element name="Reference" type="ds:ReferenceType"/&gt;
* &lt;complexType name="ReferenceType"&gt;
* &lt;sequence&gt;
* &lt;element ref="ds:Transforms" minOccurs="0"/&gt;
* &lt;element ref="ds:DigestMethod"/&gt;
* &lt;element ref="ds:DigestValue"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;attribute name="URI" type="anyURI" use="optional"/&gt;
* &lt;attribute name="Type" type="anyURI" use="optional"/&gt;
* &lt;/complexType&gt;
*
* &lt;element name="DigestValue" type="ds:DigestValueType"/&gt;
* &lt;simpleType name="DigestValueType"&gt;
* &lt;restriction base="base64Binary"/&gt;
* &lt;/simpleType&gt;
* </pre></code>
*
* <p>A <code>Reference</code> instance may be created by invoking one of the
* {@link XMLSignatureFactory#newReference newReference} methods of the
* {@link XMLSignatureFactory} class; for example:
*
* <pre>
* XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
* Reference ref = factory.newReference
* ("http://www.ietf.org/rfc/rfc3275.txt",
* factory.newDigestMethod(DigestMethod.SHA1, null));
* </pre>
*
* @author Sean Mullan
* @author Erwin van der Koogh
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newReference(String, DigestMethod)
* @see XMLSignatureFactory#newReference(String, DigestMethod, List, String, String)
*/
public interface Reference extends URIReference, XMLStructure {
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of {@link Transform}s that are contained in this
* <code>Reference</code>.
*
* @return an unmodifiable list of <code>Transform</code>s
* (may be empty but never <code>null</code>)
*/
@SuppressWarnings("rawtypes")
List getTransforms();
/**
* Returns the digest method of this <code>Reference</code>.
*
* @return the digest method
*/
DigestMethod getDigestMethod();
/**
* Returns the optional <code>Id</code> attribute of this
* <code>Reference</code>, which permits this reference to be
* referenced from elsewhere.
*
* @return the <code>Id</code> attribute (may be <code>null</code> if not
* specified)
*/
String getId();
/**
* Returns the digest value of this <code>Reference</code>.
*
* @return the raw digest value, or <code>null</code> if this reference has
* not been digested yet. Each invocation of this method returns a new
* clone to protect against subsequent modification.
*/
byte[] getDigestValue();
/**
* Returns the calculated digest value of this <code>Reference</code>
* after a validation operation. This method is useful for debugging if
* the reference fails to validate.
*
* @return the calculated digest value, or <code>null</code> if this
* reference has not been validated yet. Each invocation of this method
* returns a new clone to protect against subsequent modification.
*/
byte[] getCalculatedDigestValue();
/**
* Validates this reference. This method verifies the digest of this
* reference.
*
* <p>This method only validates the reference the first time it is
* invoked. On subsequent invocations, it returns a cached result.
*
* @return <code>true</code> if this reference was validated successfully;
* <code>false</code> otherwise
* @param validateContext the validating context
* @throws NullPointerException if <code>validateContext</code> is
* <code>null</code>
* @throws XMLSignatureException if an unexpected exception occurs while
* validating the reference
*/
boolean validate(XMLValidateContext validateContext)
throws XMLSignatureException;
/**
* Returns the dereferenced data, if
* <a href="XMLSignContext.html#Supported Properties">reference caching</a>
* is enabled. This is the result of dereferencing the URI of this
* reference during a validation or generation operation.
*
* @return the dereferenced data, or <code>null</code> if reference
* caching is not enabled or this reference has not been generated or
* validated
*/
Data getDereferencedData();
/**
* Returns the pre-digested input stream, if
* <a href="XMLSignContext.html#Supported Properties">reference caching</a>
* is enabled. This is the input to the digest operation during a
* validation or signing operation.
*
* @return an input stream containing the pre-digested input, or
* <code>null</code> if reference caching is not enabled or this
* reference has not been generated or validated
*/
InputStream getDigestInputStream();
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: SignatureMethod.java,v 1.5 2005/05/10 16:03:46 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.AlgorithmMethod;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec;
import java.security.spec.AlgorithmParameterSpec;
/**
* A representation of the XML <code>SignatureMethod</code> element
* as defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <p>
* <pre>
* &lt;element name="SignatureMethod" type="ds:SignatureMethodType"/&gt;
* &lt;complexType name="SignatureMethodType" mixed="true"&gt;
* &lt;sequence&gt;
* &lt;element name="HMACOutputLength" minOccurs="0" type="ds:HMACOutputLengthType"/&gt;
* &lt;any namespace="##any" minOccurs="0" maxOccurs="unbounded"/&gt;
* &lt;!-- (0,unbounded) elements from (1,1) namespace --&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Algorithm" type="anyURI" use="required"/&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>SignatureMethod</code> instance may be created by invoking the
* {@link XMLSignatureFactory#newSignatureMethod newSignatureMethod} method
* of the {@link XMLSignatureFactory} class.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newSignatureMethod(String, SignatureMethodParameterSpec)
*/
public interface SignatureMethod extends XMLStructure, AlgorithmMethod {
// All methods can be found in RFC 6931.
/**
* The <a href="http://www.w3.org/2000/09/xmldsig#dsa-sha1">DSA-SHA1</a>
* (DSS) signature method algorithm URI.
*/
String DSA_SHA1 =
"http://www.w3.org/2000/09/xmldsig#dsa-sha1";
/**
* The <a href="http://www.w3.org/2000/09/xmldsig#rsa-sha1">RSA-SHA1</a>
* (PKCS #1) signature method algorithm URI.
*/
String RSA_SHA1 =
"http://www.w3.org/2000/09/xmldsig#rsa-sha1";
/**
* The <a href="http://www.w3.org/2000/09/xmldsig#hmac-sha1">HMAC-SHA1</a>
* MAC signature method algorithm URI
*/
String HMAC_SHA1 =
"http://www.w3.org/2000/09/xmldsig#hmac-sha1";
/**
* Returns the algorithm-specific input parameters of this
* <code>SignatureMethod</code>.
*
* <p>The returned parameters can be typecast to a {@link
* SignatureMethodParameterSpec} object.
*
* @return the algorithm-specific input parameters of this
* <code>SignatureMethod</code> (may be <code>null</code> if not
* specified)
*/
AlgorithmParameterSpec getParameterSpec();
}

View File

@@ -0,0 +1,92 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: SignatureProperties.java,v 1.4 2005/05/10 16:03:46 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.XMLStructure;
import java.util.List;
/**
* A representation of the XML <code>SignatureProperties</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <pre><code>
*&lt;element name="SignatureProperties" type="ds:SignaturePropertiesType"/&gt;
* &lt;complexType name="SignaturePropertiesType"&gt;
* &lt;sequence&gt;
* &lt;element ref="ds:SignatureProperty" maxOccurs="unbounded"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;/complexType&gt;
* </code></pre>
*
* A <code>SignatureProperties</code> instance may be created by invoking the
* {@link XMLSignatureFactory#newSignatureProperties newSignatureProperties}
* method of the {@link XMLSignatureFactory} class; for example:
*
* <pre>
* XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
* SignatureProperties properties =
* factory.newSignatureProperties(props, "signature-properties-1");
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newSignatureProperties(List, String)
* @see SignatureProperty
*/
public interface SignatureProperties extends XMLStructure {
/**
* URI that identifies the <code>SignatureProperties</code> element (this
* can be specified as the value of the <code>type</code> parameter of the
* {@link Reference} class to identify the referent's type).
*/
final static String TYPE =
"http://www.w3.org/2000/09/xmldsig#SignatureProperties";
/**
* Returns the Id of this <code>SignatureProperties</code>.
*
* @return the Id of this <code>SignatureProperties</code> (or
* <code>null</code> if not specified)
*/
String getId();
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of one or more {@link SignatureProperty}s that are contained in
* this <code>SignatureProperties</code>.
*
* @return an unmodifiable list of one or more
* <code>SignatureProperty</code>s
*/
@SuppressWarnings("rawtypes")
List getProperties();
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: SignatureProperty.java,v 1.4 2005/05/10 16:03:46 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.XMLStructure;
import java.util.List;
/**
* A representation of the XML <code>SignatureProperty</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <pre><code>
*&lt;element name="SignatureProperty" type="ds:SignaturePropertyType"/&gt;
* &lt;complexType name="SignaturePropertyType" mixed="true"&gt;
* &lt;choice maxOccurs="unbounded"&gt;
* &lt;any namespace="##other" processContents="lax"/&gt;
* &lt;!-- (1,1) elements from (1, unbounded) namespaces --&gt;
* &lt;/choice&gt;
* &lt;attribute name="Target" type="anyURI" use="required"/&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;/complexType&gt;
* </code></pre>
*
* A <code>SignatureProperty</code> instance may be created by invoking the
* {@link XMLSignatureFactory#newSignatureProperty newSignatureProperty}
* method of the {@link XMLSignatureFactory} class; for example:
*
* <pre>
* XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
* SignatureProperty property = factory.newSignatureProperty
* (Collections.singletonList(content), "#Signature-1", "TimeStamp");
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newSignatureProperty(List, String, String)
* @see SignatureProperties
*/
public interface SignatureProperty extends XMLStructure {
/**
* Returns the target URI of this <code>SignatureProperty</code>.
*
* @return the target URI of this <code>SignatureProperty</code> (never
* <code>null</code>)
*/
String getTarget();
/**
* Returns the Id of this <code>SignatureProperty</code>.
*
* @return the Id of this <code>SignatureProperty</code> (or
* <code>null</code> if not specified)
*/
String getId();
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of one or more {@link XMLStructure}s that are contained in
* this <code>SignatureProperty</code>. These represent additional
* information items concerning the generation of the {@link XMLSignature}
* (i.e. date/time stamp or serial numbers of cryptographic hardware used
* in signature generation).
*
* @return an unmodifiable list of one or more <code>XMLStructure</code>s
*/
@SuppressWarnings("rawtypes")
List getContent();
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: SignedInfo.java,v 1.7 2005/05/10 16:03:47 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.XMLStructure;
import java.io.InputStream;
import java.util.List;
/**
* An representation of the XML <code>SignedInfo</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <pre><code>
* &lt;element name="SignedInfo" type="ds:SignedInfoType"/&gt;
* &lt;complexType name="SignedInfoType"&gt;
* &lt;sequence&gt;
* &lt;element ref="ds:CanonicalizationMethod"/&gt;
* &lt;element ref="ds:SignatureMethod"/&gt;
* &lt;element ref="ds:Reference" maxOccurs="unbounded"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;/complexType&gt;
* </code></pre>
*
* A <code>SignedInfo</code> instance may be created by invoking one of the
* {@link XMLSignatureFactory#newSignedInfo newSignedInfo} methods of the
* {@link XMLSignatureFactory} class.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newSignedInfo(CanonicalizationMethod, SignatureMethod, List)
* @see XMLSignatureFactory#newSignedInfo(CanonicalizationMethod, SignatureMethod, List, String)
*/
public interface SignedInfo extends XMLStructure {
/**
* Returns the canonicalization method of this <code>SignedInfo</code>.
*
* @return the canonicalization method
*/
CanonicalizationMethod getCanonicalizationMethod();
/**
* Returns the signature method of this <code>SignedInfo</code>.
*
* @return the signature method
*/
SignatureMethod getSignatureMethod();
/**
* Returns an {@link java.util.Collections#unmodifiableList
* unmodifiable list} of one or more {@link Reference}s.
*
* @return an unmodifiable list of one or more {@link Reference}s
*/
@SuppressWarnings("rawtypes")
List getReferences();
/**
* Returns the optional <code>Id</code> attribute of this
* <code>SignedInfo</code>.
*
* @return the id (may be <code>null</code> if not specified)
*/
String getId();
/**
* Returns the canonicalized signed info bytes after a signing or
* validation operation. This method is useful for debugging.
*
* @return an <code>InputStream</code> containing the canonicalized bytes,
* or <code>null</code> if this <code>SignedInfo</code> has not been
* signed or validated yet
*/
InputStream getCanonicalizedData();
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: Transform.java,v 1.5 2005/05/10 16:03:48 mullan Exp $
*/
package javax.xml.crypto.dsig;
import java.io.OutputStream;
import java.security.spec.AlgorithmParameterSpec;
import javax.xml.crypto.AlgorithmMethod;
import javax.xml.crypto.Data;
import javax.xml.crypto.OctetStreamData;
import javax.xml.crypto.XMLCryptoContext;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.spec.TransformParameterSpec;
/**
* A representation of the XML <code>Transform</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
*
* <pre>
* &lt;element name="Transform" type="ds:TransformType"/&gt;
* &lt;complexType name="TransformType" mixed="true"&gt;
* &lt;choice minOccurs="0" maxOccurs="unbounded"&gt;
* &lt;any namespace="##other" processContents="lax"/&gt;
* &lt;!-- (1,1) elements from (0,unbounded) namespaces --&gt;
* &lt;element name="XPath" type="string"/&gt;
* &lt;/choice&gt;
* &lt;attribute name="Algorithm" type="anyURI" use="required"/&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>Transform</code> instance may be created by invoking the
* {@link XMLSignatureFactory#newTransform newTransform} method
* of the {@link XMLSignatureFactory} class.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#newTransform(String, TransformParameterSpec)
*/
public interface Transform extends XMLStructure, AlgorithmMethod {
/**
* The <a href="http://www.w3.org/2000/09/xmldsig#base64">Base64</a>
* transform algorithm URI.
*/
final static String BASE64 = "http://www.w3.org/2000/09/xmldsig#base64";
/**
* The <a href="http://www.w3.org/2000/09/xmldsig#enveloped-signature">
* Enveloped Signature</a> transform algorithm URI.
*/
final static String ENVELOPED =
"http://www.w3.org/2000/09/xmldsig#enveloped-signature";
/**
* The <a href="http://www.w3.org/TR/1999/REC-xpath-19991116">XPath</a>
* transform algorithm URI.
*/
final static String XPATH = "http://www.w3.org/TR/1999/REC-xpath-19991116";
/**
* The <a href="http://www.w3.org/2002/06/xmldsig-filter2">
* XPath Filter 2</a> transform algorithm URI.
*/
final static String XPATH2 = "http://www.w3.org/2002/06/xmldsig-filter2";
/**
* The <a href="http://www.w3.org/TR/1999/REC-xslt-19991116">XSLT</a>
* transform algorithm URI.
*/
final static String XSLT = "http://www.w3.org/TR/1999/REC-xslt-19991116";
/**
* Returns the algorithm-specific input parameters associated with this
* <code>Transform</code>.
* <p>
* The returned parameters can be typecast to a
* {@link TransformParameterSpec} object.
*
* @return the algorithm-specific input parameters (may be <code>null</code>
* if not specified)
*/
AlgorithmParameterSpec getParameterSpec();
/**
* Transforms the specified data using the underlying transform algorithm.
*
* @param data the data to be transformed
* @param context the <code>XMLCryptoContext</code> containing
* additional context (may be <code>null</code> if not applicable)
* @return the transformed data
* @throws NullPointerException if <code>data</code> is <code>null</code>
* @throws TransformException if an error occurs while executing the
* transform
*/
public abstract Data transform(Data data, XMLCryptoContext context)
throws TransformException;
/**
* Transforms the specified data using the underlying transform algorithm.
* If the output of this transform is an <code>OctetStreamData</code>, then
* this method returns <code>null</code> and the bytes are written to the
* specified <code>OutputStream</code>. Otherwise, the
* <code>OutputStream</code> is ignored and the method behaves as if
* {@link #transform(Data, XMLCryptoContext)} were invoked.
*
* @param data the data to be transformed
* @param context the <code>XMLCryptoContext</code> containing
* additional context (may be <code>null</code> if not applicable)
* @param os the <code>OutputStream</code> that should be used to write
* the transformed data to
* @return the transformed data (or <code>null</code> if the data was
* written to the <code>OutputStream</code> parameter)
* @throws NullPointerException if <code>data</code> or <code>os</code>
* is <code>null</code>
* @throws TransformException if an error occurs while executing the
* transform
*/
public abstract Data transform
(Data data, XMLCryptoContext context, OutputStream os)
throws TransformException;
}

View File

@@ -0,0 +1,156 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: TransformException.java,v 1.3 2005/05/10 16:03:48 mullan Exp $
*/
package javax.xml.crypto.dsig;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* Indicates an exceptional condition that occurred while executing a
* transform algorithm.
*
* <p>A {@code TransformException} can contain a cause: another
* throwable that caused this {@code TransformException} to get thrown.
*
* @see Transform#transform
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
*/
public class TransformException extends Exception {
private static final long serialVersionUID = 5082634801360427800L;
/**
* The throwable that caused this exception to get thrown, or null if this
* exception was not caused by another throwable or if the causative
* throwable is unknown.
*
* @serial
*/
private Throwable cause;
/**
* Constructs a new {@code TransformException} with
* {@code null} as its detail message.
*/
public TransformException() {
super();
}
/**
* Constructs a new {@code TransformException} with the specified
* detail message.
*
* @param message the detail message
*/
public TransformException(String message) {
super(message);
}
/**
* Constructs a new {@code TransformException} with the
* specified detail message and cause.
* <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this exception's detail message.
*
* @param message the detail message
* @param cause the cause (A {@code null} value is permitted, and
* indicates that the cause is nonexistent or unknown.)
*/
public TransformException(String message, Throwable cause) {
super(message);
this.cause = cause;
}
/**
* Constructs a new {@code TransformException} with the specified
* cause and a detail message of
* {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of
* {@code cause}).
*
* @param cause the cause (A {@code null} value is permitted, and
* indicates that the cause is nonexistent or unknown.)
*/
public TransformException(Throwable cause) {
super(cause==null ? null : cause.toString());
this.cause = cause;
}
/**
* Returns the cause of this {@code TransformException} or
* {@code null} if the cause is nonexistent or unknown. (The
* cause is the throwable that caused this
* {@code TransformException} to get thrown.)
*
* @return the cause of this {@code TransformException} or
* {@code null} if the cause is nonexistent or unknown.
*/
public Throwable getCause() {
return cause;
}
/**
* Prints this {@code TransformException}, its backtrace and
* the cause's backtrace to the standard error stream.
*/
public void printStackTrace() {
super.printStackTrace();
if (cause != null) {
cause.printStackTrace();
}
}
/**
* Prints this {@code TransformException}, its backtrace and
* the cause's backtrace to the specified print stream.
*
* @param s {@code PrintStream} to use for output
*/
public void printStackTrace(PrintStream s) {
super.printStackTrace(s);
if (cause != null) {
cause.printStackTrace(s);
}
}
/**
* Prints this {@code TransformException}, its backtrace and
* the cause's backtrace to the specified print writer.
*
* @param s {@code PrintWriter} to use for output
*/
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
if (cause != null) {
cause.printStackTrace(s);
}
}
}

View File

@@ -0,0 +1,393 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: TransformService.java,v 1.6.4.1 2005/09/15 12:42:11 mullan Exp $
*/
package javax.xml.crypto.dsig;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Provider.Service;
import java.security.Security;
import java.util.*;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.XMLCryptoContext;
import javax.xml.crypto.dsig.spec.TransformParameterSpec;
import sun.security.jca.*;
import sun.security.jca.GetInstance.Instance;
/**
* A Service Provider Interface for transform and canonicalization algorithms.
*
* <p>Each instance of <code>TransformService</code> supports a specific
* transform or canonicalization algorithm and XML mechanism type. To create a
* <code>TransformService</code>, call one of the static
* {@link #getInstance getInstance} methods, passing in the algorithm URI and
* XML mechanism type desired, for example:
*
* <blockquote><code>
* TransformService ts = TransformService.getInstance(Transform.XPATH2, "DOM");
* </code></blockquote>
*
* <p><code>TransformService</code> implementations are registered and loaded
* using the {@link java.security.Provider} mechanism. Each
* <code>TransformService</code> service provider implementation should include
* a <code>MechanismType</code> service attribute that identifies the XML
* mechanism type that it supports. If the attribute is not specified,
* "DOM" is assumed. For example, a service provider that supports the
* XPath Filter 2 Transform and DOM mechanism would be specified in the
* <code>Provider</code> subclass as:
* <pre>
* put("TransformService." + Transform.XPATH2,
* "org.example.XPath2TransformService");
* put("TransformService." + Transform.XPATH2 + " MechanismType", "DOM");
* </pre>
* <code>TransformService</code> implementations that support the DOM
* mechanism type must abide by the DOM interoperability requirements defined
* in the
* <a href="../../../../../technotes/guides/security/xmldsig/overview.html#DOM Mechanism Requirements">
* DOM Mechanism Requirements</a> section of the API overview. See the
* <a href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of standard
* mechanism types.
* <p>
* Once a <code>TransformService</code> has been created, it can be used
* to process <code>Transform</code> or <code>CanonicalizationMethod</code>
* objects. If the <code>Transform</code> or <code>CanonicalizationMethod</code>
* exists in XML form (for example, when validating an existing
* <code>XMLSignature</code>), the {@link #init(XMLStructure, XMLCryptoContext)}
* method must be first called to initialize the transform and provide document
* context (even if there are no parameters). Alternatively, if the
* <code>Transform</code> or <code>CanonicalizationMethod</code> is being
* created from scratch, the {@link #init(TransformParameterSpec)} method
* is called to initialize the transform with parameters and the
* {@link #marshalParams marshalParams} method is called to marshal the
* parameters to XML and provide the transform with document context. Finally,
* the {@link #transform transform} method is called to perform the
* transformation.
* <p>
* <b>Concurrent Access</b>
* <p>The static methods of this class are guaranteed to be thread-safe.
* Multiple threads may concurrently invoke the static methods defined in this
* class with no ill effects.
*
* <p>However, this is not true for the non-static methods defined by this
* class. Unless otherwise documented by a specific provider, threads that
* need to access a single <code>TransformService</code> instance
* concurrently should synchronize amongst themselves and provide the
* necessary locking. Multiple threads each manipulating a different
* <code>TransformService</code> instance need not synchronize.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
*/
public abstract class TransformService implements Transform {
private String algorithm;
private String mechanism;
private Provider provider;
/**
* Default constructor, for invocation by subclasses.
*/
protected TransformService() {}
/**
* Returns a <code>TransformService</code> that supports the specified
* algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
* (ex: DOM).
*
* <p>This method uses the standard JCA provider lookup mechanism to
* locate and instantiate a <code>TransformService</code> implementation
* of the desired algorithm and <code>MechanismType</code> service
* attribute. It traverses the list of registered security
* <code>Provider</code>s, starting with the most preferred
* <code>Provider</code>. A new <code>TransformService</code> object
* from the first <code>Provider</code> that supports the specified
* algorithm and mechanism type is returned.
*
* <p> Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param algorithm the URI of the algorithm
* @param mechanismType the type of the XML processing mechanism and
* representation
* @return a new <code>TransformService</code>
* @throws NullPointerException if <code>algorithm</code> or
* <code>mechanismType</code> is <code>null</code>
* @throws NoSuchAlgorithmException if no <code>Provider</code> supports a
* <code>TransformService</code> implementation for the specified
* algorithm and mechanism type
* @see Provider
*/
public static TransformService getInstance
(String algorithm, String mechanismType)
throws NoSuchAlgorithmException {
if (mechanismType == null || algorithm == null) {
throw new NullPointerException();
}
boolean dom = false;
if (mechanismType.equals("DOM")) {
dom = true;
}
List<Service> services = GetInstance.getServices("TransformService", algorithm);
for (Iterator<Service> t = services.iterator(); t.hasNext(); ) {
Service s = t.next();
String value = s.getAttribute("MechanismType");
if ((value == null && dom) ||
(value != null && value.equals(mechanismType))) {
Instance instance = GetInstance.getInstance(s, null);
TransformService ts = (TransformService) instance.impl;
ts.algorithm = algorithm;
ts.mechanism = mechanismType;
ts.provider = instance.provider;
return ts;
}
}
throw new NoSuchAlgorithmException
(algorithm + " algorithm and " + mechanismType
+ " mechanism not available");
}
/**
* Returns a <code>TransformService</code> that supports the specified
* algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
* (ex: DOM) as supplied by the specified provider. Note that the specified
* <code>Provider</code> object does not have to be registered in the
* provider list.
*
* @param algorithm the URI of the algorithm
* @param mechanismType the type of the XML processing mechanism and
* representation
* @param provider the <code>Provider</code> object
* @return a new <code>TransformService</code>
* @throws NullPointerException if <code>provider</code>,
* <code>algorithm</code>, or <code>mechanismType</code> is
* <code>null</code>
* @throws NoSuchAlgorithmException if a <code>TransformService</code>
* implementation for the specified algorithm and mechanism type is not
* available from the specified <code>Provider</code> object
* @see Provider
*/
public static TransformService getInstance
(String algorithm, String mechanismType, Provider provider)
throws NoSuchAlgorithmException {
if (mechanismType == null || algorithm == null || provider == null) {
throw new NullPointerException();
}
boolean dom = false;
if (mechanismType.equals("DOM")) {
dom = true;
}
Service s = GetInstance.getService
("TransformService", algorithm, provider);
String value = s.getAttribute("MechanismType");
if ((value == null && dom) ||
(value != null && value.equals(mechanismType))) {
Instance instance = GetInstance.getInstance(s, null);
TransformService ts = (TransformService) instance.impl;
ts.algorithm = algorithm;
ts.mechanism = mechanismType;
ts.provider = instance.provider;
return ts;
}
throw new NoSuchAlgorithmException
(algorithm + " algorithm and " + mechanismType
+ " mechanism not available");
}
/**
* Returns a <code>TransformService</code> that supports the specified
* algorithm URI (ex: {@link Transform#XPATH2}) and mechanism type
* (ex: DOM) as supplied by the specified provider. The specified provider
* must be registered in the security provider list.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param algorithm the URI of the algorithm
* @param mechanismType the type of the XML processing mechanism and
* representation
* @param provider the string name of the provider
* @return a new <code>TransformService</code>
* @throws NoSuchProviderException if the specified provider is not
* registered in the security provider list
* @throws NullPointerException if <code>provider</code>,
* <code>mechanismType</code>, or <code>algorithm</code> is
* <code>null</code>
* @throws NoSuchAlgorithmException if a <code>TransformService</code>
* implementation for the specified algorithm and mechanism type is not
* available from the specified provider
* @see Provider
*/
public static TransformService getInstance
(String algorithm, String mechanismType, String provider)
throws NoSuchAlgorithmException, NoSuchProviderException {
if (mechanismType == null || algorithm == null || provider == null) {
throw new NullPointerException();
} else if (provider.length() == 0) {
throw new NoSuchProviderException();
}
boolean dom = false;
if (mechanismType.equals("DOM")) {
dom = true;
}
Service s = GetInstance.getService
("TransformService", algorithm, provider);
String value = s.getAttribute("MechanismType");
if ((value == null && dom) ||
(value != null && value.equals(mechanismType))) {
Instance instance = GetInstance.getInstance(s, null);
TransformService ts = (TransformService) instance.impl;
ts.algorithm = algorithm;
ts.mechanism = mechanismType;
ts.provider = instance.provider;
return ts;
}
throw new NoSuchAlgorithmException
(algorithm + " algorithm and " + mechanismType
+ " mechanism not available");
}
private static class MechanismMapEntry implements Map.Entry<String,String> {
private final String mechanism;
private final String algorithm;
private final String key;
MechanismMapEntry(String algorithm, String mechanism) {
this.algorithm = algorithm;
this.mechanism = mechanism;
this.key = "TransformService." + algorithm + " MechanismType";
}
public boolean equals(Object o) {
if (!(o instanceof Map.Entry)) {
return false;
}
Map.Entry<?,?> e = (Map.Entry<?,?>) o;
return (getKey()==null ?
e.getKey()==null : getKey().equals(e.getKey())) &&
(getValue()==null ?
e.getValue()==null : getValue().equals(e.getValue()));
}
public String getKey() {
return key;
}
public String getValue() {
return mechanism;
}
public String setValue(String value) {
throw new UnsupportedOperationException();
}
public int hashCode() {
return (getKey()==null ? 0 : getKey().hashCode()) ^
(getValue()==null ? 0 : getValue().hashCode());
}
}
/**
* Returns the mechanism type supported by this <code>TransformService</code>.
*
* @return the mechanism type
*/
public final String getMechanismType() {
return mechanism;
}
/**
* Returns the URI of the algorithm supported by this
* <code>TransformService</code>.
*
* @return the algorithm URI
*/
public final String getAlgorithm() {
return algorithm;
}
/**
* Returns the provider of this <code>TransformService</code>.
*
* @return the provider
*/
public final Provider getProvider() {
return provider;
}
/**
* Initializes this <code>TransformService</code> with the specified
* parameters.
*
* <p>If the parameters exist in XML form, the
* {@link #init(XMLStructure, XMLCryptoContext)} method should be used to
* initialize the <code>TransformService</code>.
*
* @param params the algorithm parameters (may be <code>null</code> if
* not required or optional)
* @throws InvalidAlgorithmParameterException if the specified parameters
* are invalid for this algorithm
*/
public abstract void init(TransformParameterSpec params)
throws InvalidAlgorithmParameterException;
/**
* Marshals the algorithm-specific parameters. If there are no parameters
* to be marshalled, this method returns without throwing an exception.
*
* @param parent a mechanism-specific structure containing the parent
* node that the marshalled parameters should be appended to
* @param context the <code>XMLCryptoContext</code> containing
* additional context (may be <code>null</code> if not applicable)
* @throws ClassCastException if the type of <code>parent</code> or
* <code>context</code> is not compatible with this
* <code>TransformService</code>
* @throws NullPointerException if <code>parent</code> is <code>null</code>
* @throws MarshalException if the parameters cannot be marshalled
*/
public abstract void marshalParams
(XMLStructure parent, XMLCryptoContext context)
throws MarshalException;
/**
* Initializes this <code>TransformService</code> with the specified
* parameters and document context.
*
* @param parent a mechanism-specific structure containing the parent
* structure
* @param context the <code>XMLCryptoContext</code> containing
* additional context (may be <code>null</code> if not applicable)
* @throws ClassCastException if the type of <code>parent</code> or
* <code>context</code> is not compatible with this
* <code>TransformService</code>
* @throws NullPointerException if <code>parent</code> is <code>null</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are invalid for this algorithm
*/
public abstract void init(XMLStructure parent, XMLCryptoContext context)
throws InvalidAlgorithmParameterException;
}

View File

@@ -0,0 +1,129 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* ===========================================================================
*
* (C) Copyright IBM Corp. 2003 All Rights Reserved.
*
* ===========================================================================
*/
/*
* $Id: XMLObject.java,v 1.5 2005/05/10 16:03:48 mullan Exp $
*/
package javax.xml.crypto.dsig;
import java.util.List;
import javax.xml.crypto.XMLStructure;
/**
* A representation of the XML <code>Object</code> element as defined in
* the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* An <code>XMLObject</code> may contain any data and may include optional
* MIME type, ID, and encoding attributes. The XML Schema Definition is
* defined as:
*
* <pre><code>
* &lt;element name="Object" type="ds:ObjectType"/&gt;
* &lt;complexType name="ObjectType" mixed="true"&gt;
* &lt;sequence minOccurs="0" maxOccurs="unbounded"&gt;
* &lt;any namespace="##any" processContents="lax"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;attribute name="MimeType" type="string" use="optional"/&gt;
* &lt;attribute name="Encoding" type="anyURI" use="optional"/&gt;
* &lt;/complexType&gt;
* </code></pre>
*
* A <code>XMLObject</code> instance may be created by invoking the
* {@link XMLSignatureFactory#newXMLObject newXMLObject} method of the
* {@link XMLSignatureFactory} class; for example:
*
* <pre>
* XMLSignatureFactory fac = XMLSignatureFactory.getInstance("DOM");
* List content = Collections.singletonList(fac.newManifest(references)));
* XMLObject object = factory.newXMLObject(content, "object-1", null, null);
* </pre>
*
* <p>Note that this class is named <code>XMLObject</code> rather than
* <code>Object</code> to avoid naming clashes with the existing
* {@link java.lang.Object java.lang.Object} class.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @author Joyce L. Leung
* @since 1.6
* @see XMLSignatureFactory#newXMLObject(List, String, String, String)
*/
public interface XMLObject extends XMLStructure {
/**
* URI that identifies the <code>Object</code> element (this can be
* specified as the value of the <code>type</code> parameter of the
* {@link Reference} class to identify the referent's type).
*/
final static String TYPE = "http://www.w3.org/2000/09/xmldsig#Object";
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of {@link XMLStructure}s contained in this <code>XMLObject</code>,
* which represent elements from any namespace.
*
*<p>If there is a public subclass representing the type of
* <code>XMLStructure</code>, it is returned as an instance of that class
* (ex: a <code>SignatureProperties</code> element would be returned
* as an instance of {@link javax.xml.crypto.dsig.SignatureProperties}).
*
* @return an unmodifiable list of <code>XMLStructure</code>s (may be empty
* but never <code>null</code>)
*/
@SuppressWarnings("rawtypes")
List getContent();
/**
* Returns the Id of this <code>XMLObject</code>.
*
* @return the Id (or <code>null</code> if not specified)
*/
String getId();
/**
* Returns the mime type of this <code>XMLObject</code>. The
* mime type is an optional attribute which describes the data within this
* <code>XMLObject</code> (independent of its encoding).
*
* @return the mime type (or <code>null</code> if not specified)
*/
String getMimeType();
/**
* Returns the encoding URI of this <code>XMLObject</code>. The encoding
* URI identifies the method by which the object is encoded.
*
* @return the encoding URI (or <code>null</code> if not specified)
*/
String getEncoding();
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XMLSignContext.java,v 1.8 2005/05/10 16:03:48 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.XMLCryptoContext;
/**
* Contains context information for generating XML Signatures. This interface
* is primarily intended for type-safety.
*
* <p>Note that <code>XMLSignContext</code> instances can contain
* information and state specific to the XML signature structure it is
* used with. The results are unpredictable if an
* <code>XMLSignContext</code> is used with different signature structures
* (for example, you should not use the same <code>XMLSignContext</code>
* instance to sign two different {@link XMLSignature} objects).
* <p>
* <b><a name="Supported Properties"></a>Supported Properties</b>
* <p>The following properties can be set using the
* {@link #setProperty setProperty} method.
* <ul>
* <li><code>javax.xml.crypto.dsig.cacheReference</code>: value must be a
* {@link Boolean}. This property controls whether or not the digested
* {@link Reference} objects will cache the dereferenced content and
* pre-digested input for subsequent retrieval via the
* {@link Reference#getDereferencedData Reference.getDereferencedData} and
* {@link Reference#getDigestInputStream Reference.getDigestInputStream}
* methods. The default value if not specified is
* <code>Boolean.FALSE</code>.
* </ul>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignature#sign(XMLSignContext)
*/
public interface XMLSignContext extends XMLCryptoContext {}

View File

@@ -0,0 +1,246 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* ===========================================================================
*
* (C) Copyright IBM Corp. 2003 All Rights Reserved.
*
* ===========================================================================
*/
/*
* $Id: XMLSignature.java,v 1.10 2005/05/10 16:03:48 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.KeySelectorResult;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import java.security.Signature;
import java.util.List;
/**
* A representation of the XML <code>Signature</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* This class contains methods for signing and validating XML signatures
* with behavior as defined by the W3C specification. The XML Schema Definition
* is defined as:
* <pre><code>
* &lt;element name="Signature" type="ds:SignatureType"/&gt;
* &lt;complexType name="SignatureType"&gt;
* &lt;sequence&gt;
* &lt;element ref="ds:SignedInfo"/&gt;
* &lt;element ref="ds:SignatureValue"/&gt;
* &lt;element ref="ds:KeyInfo" minOccurs="0"/&gt;
* &lt;element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;/complexType&gt;
* </code></pre>
* <p>
* An <code>XMLSignature</code> instance may be created by invoking one of the
* {@link XMLSignatureFactory#newXMLSignature newXMLSignature} methods of the
* {@link XMLSignatureFactory} class.
*
* <p>If the contents of the underlying document containing the
* <code>XMLSignature</code> are subsequently modified, the behavior is
* undefined.
*
* <p>Note that this class is named <code>XMLSignature</code> rather than
* <code>Signature</code> to avoid naming clashes with the existing
* {@link Signature java.security.Signature} class.
*
* @see XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo)
* @see XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo, List, String, String)
* @author Joyce L. Leung
* @author Sean Mullan
* @author Erwin van der Koogh
* @author JSR 105 Expert Group
* @since 1.6
*/
public interface XMLSignature extends XMLStructure {
/**
* The XML Namespace URI of the W3C Recommendation for XML-Signature
* Syntax and Processing.
*/
final static String XMLNS = "http://www.w3.org/2000/09/xmldsig#";
/**
* Validates the signature according to the
* <a href="http://www.w3.org/TR/xmldsig-core/#sec-CoreValidation">
* core validation processing rules</a>. This method validates the
* signature using the existing state, it does not unmarshal and
* reinitialize the contents of the <code>XMLSignature</code> using the
* location information specified in the context.
*
* <p>This method only validates the signature the first time it is
* invoked. On subsequent invocations, it returns a cached result.
*
* @param validateContext the validating context
* @return <code>true</code> if the signature passed core validation,
* otherwise <code>false</code>
* @throws ClassCastException if the type of <code>validateContext</code>
* is not compatible with this <code>XMLSignature</code>
* @throws NullPointerException if <code>validateContext</code> is
* <code>null</code>
* @throws XMLSignatureException if an unexpected error occurs during
* validation that prevented the validation operation from completing
*/
boolean validate(XMLValidateContext validateContext)
throws XMLSignatureException;
/**
* Returns the key info of this <code>XMLSignature</code>.
*
* @return the key info (may be <code>null</code> if not specified)
*/
KeyInfo getKeyInfo();
/**
* Returns the signed info of this <code>XMLSignature</code>.
*
* @return the signed info (never <code>null</code>)
*/
SignedInfo getSignedInfo();
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of {@link XMLObject}s contained in this <code>XMLSignature</code>.
*
* @return an unmodifiable list of <code>XMLObject</code>s (may be empty
* but never <code>null</code>)
*/
@SuppressWarnings("rawtypes")
List getObjects();
/**
* Returns the optional Id of this <code>XMLSignature</code>.
*
* @return the Id (may be <code>null</code> if not specified)
*/
String getId();
/**
* Returns the signature value of this <code>XMLSignature</code>.
*
* @return the signature value
*/
SignatureValue getSignatureValue();
/**
* Signs this <code>XMLSignature</code>.
*
* <p>If this method throws an exception, this <code>XMLSignature</code> and
* the <code>signContext</code> parameter will be left in the state that
* it was in prior to the invocation.
*
* @param signContext the signing context
* @throws ClassCastException if the type of <code>signContext</code> is
* not compatible with this <code>XMLSignature</code>
* @throws NullPointerException if <code>signContext</code> is
* <code>null</code>
* @throws MarshalException if an exception occurs while marshalling
* @throws XMLSignatureException if an unexpected exception occurs while
* generating the signature
*/
void sign(XMLSignContext signContext) throws MarshalException,
XMLSignatureException;
/**
* Returns the result of the {@link KeySelector}, if specified, after
* this <code>XMLSignature</code> has been signed or validated.
*
* @return the key selector result, or <code>null</code> if a key
* selector has not been specified or this <code>XMLSignature</code>
* has not been signed or validated
*/
KeySelectorResult getKeySelectorResult();
/**
* A representation of the XML <code>SignatureValue</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* The XML Schema Definition is defined as:
* <p>
* <pre>
* &lt;element name="SignatureValue" type="ds:SignatureValueType"/&gt;
* &lt;complexType name="SignatureValueType"&gt;
* &lt;simpleContent&gt;
* &lt;extension base="base64Binary"&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;/extension&gt;
* &lt;/simpleContent&gt;
* &lt;/complexType&gt;
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
*/
public interface SignatureValue extends XMLStructure {
/**
* Returns the optional <code>Id</code> attribute of this
* <code>SignatureValue</code>, which permits this element to be
* referenced from elsewhere.
*
* @return the <code>Id</code> attribute (may be <code>null</code> if
* not specified)
*/
String getId();
/**
* Returns the signature value of this <code>SignatureValue</code>.
*
* @return the signature value (may be <code>null</code> if the
* <code>XMLSignature</code> has not been signed yet). Each
* invocation of this method returns a new clone of the array to
* prevent subsequent modification.
*/
byte[] getValue();
/**
* Validates the signature value. This method performs a
* cryptographic validation of the signature calculated over the
* <code>SignedInfo</code> of the <code>XMLSignature</code>.
*
* <p>This method only validates the signature the first
* time it is invoked. On subsequent invocations, it returns a cached
* result.
*
* @return <code>true</code> if the signature was
* validated successfully; <code>false</code> otherwise
* @param validateContext the validating context
* @throws NullPointerException if <code>validateContext</code> is
* <code>null</code>
* @throws XMLSignatureException if an unexpected exception occurs while
* validating the signature
*/
boolean validate(XMLValidateContext validateContext)
throws XMLSignatureException;
}
}

View File

@@ -0,0 +1,153 @@
/*
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XMLSignatureException.java,v 1.5 2005/05/10 16:03:48 mullan Exp $
*/
package javax.xml.crypto.dsig;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* Indicates an exceptional condition that occurred during the XML
* signature generation or validation process.
*
* <p>An {@code XMLSignatureException} can contain a cause: another
* throwable that caused this {@code XMLSignatureException} to get thrown.
*
* @since 1.6
*/
public class XMLSignatureException extends Exception {
private static final long serialVersionUID = -3438102491013869995L;
/**
* The throwable that caused this exception to get thrown, or null if this
* exception was not caused by another throwable or if the causative
* throwable is unknown.
*
* @serial
*/
private Throwable cause;
/**
* Constructs a new {@code XMLSignatureException} with
* {@code null} as its detail message.
*/
public XMLSignatureException() {
super();
}
/**
* Constructs a new {@code XMLSignatureException} with the specified
* detail message.
*
* @param message the detail message
*/
public XMLSignatureException(String message) {
super(message);
}
/**
* Constructs a new {@code XMLSignatureException} with the
* specified detail message and cause.
* <p>Note that the detail message associated with
* {@code cause} is <i>not</i> automatically incorporated in
* this exception's detail message.
*
* @param message the detail message
* @param cause the cause (A {@code null} value is permitted, and
* indicates that the cause is nonexistent or unknown.)
*/
public XMLSignatureException(String message, Throwable cause) {
super(message);
this.cause = cause;
}
/**
* Constructs a new {@code XMLSignatureException} with the specified
* cause and a detail message of
* {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of
* {@code cause}).
*
* @param cause the cause (A {@code null} value is permitted, and
* indicates that the cause is nonexistent or unknown.)
*/
public XMLSignatureException(Throwable cause) {
super(cause==null ? null : cause.toString());
this.cause = cause;
}
/**
* Returns the cause of this {@code XMLSignatureException} or
* {@code null} if the cause is nonexistent or unknown. (The
* cause is the throwable that caused this
* {@code XMLSignatureException} to get thrown.)
*
* @return the cause of this {@code XMLSignatureException} or
* {@code null} if the cause is nonexistent or unknown.
*/
public Throwable getCause() {
return cause;
}
/**
* Prints this {@code XMLSignatureException}, its backtrace and
* the cause's backtrace to the standard error stream.
*/
public void printStackTrace() {
super.printStackTrace();
if (cause != null) {
cause.printStackTrace();
}
}
/**
* Prints this {@code XMLSignatureException}, its backtrace and
* the cause's backtrace to the specified print stream.
*
* @param s {@code PrintStream} to use for output
*/
public void printStackTrace(PrintStream s) {
super.printStackTrace(s);
if (cause != null) {
cause.printStackTrace(s);
}
}
/**
* Prints this {@code XMLSignatureException}, its backtrace and
* the cause's backtrace to the specified print writer.
*
* @param s {@code PrintWriter} to use for output
*/
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
if (cause != null) {
cause.printStackTrace(s);
}
}
}

View File

@@ -0,0 +1,804 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XMLSignatureFactory.java,v 1.14 2005/09/15 14:29:01 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.Data;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.NoSuchMechanismException;
import javax.xml.crypto.URIDereferencer;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dom.DOMStructure;
import javax.xml.crypto.dsig.keyinfo.KeyInfo;
import javax.xml.crypto.dsig.keyinfo.KeyInfoFactory;
import javax.xml.crypto.dsig.spec.*;
import javax.xml.crypto.dsig.dom.DOMValidateContext;
import javax.xml.crypto.dsig.dom.DOMSignContext;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.Security;
import java.util.List;
import sun.security.jca.*;
import sun.security.jca.GetInstance.Instance;
/**
* A factory for creating {@link XMLSignature} objects from scratch or
* for unmarshalling an <code>XMLSignature</code> object from a corresponding
* XML representation.
*
* <h2>XMLSignatureFactory Type</h2>
*
* <p>Each instance of <code>XMLSignatureFactory</code> supports a specific
* XML mechanism type. To create an <code>XMLSignatureFactory</code>, call one
* of the static {@link #getInstance getInstance} methods, passing in the XML
* mechanism type desired, for example:
*
* <blockquote><code>
* XMLSignatureFactory factory = XMLSignatureFactory.getInstance("DOM");
* </code></blockquote>
*
* <p>The objects that this factory produces will be based
* on DOM and abide by the DOM interoperability requirements as defined in the
* <a href="../../../../../technotes/guides/security/xmldsig/overview.html#DOM Mechanism Requirements">
* DOM Mechanism Requirements</a> section of the API overview. See the
* <a href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of standard
* mechanism types.
*
* <p><code>XMLSignatureFactory</code> implementations are registered and loaded
* using the {@link java.security.Provider} mechanism.
* For example, a service provider that supports the
* DOM mechanism would be specified in the <code>Provider</code> subclass as:
* <pre>
* put("XMLSignatureFactory.DOM", "org.example.DOMXMLSignatureFactory");
* </pre>
*
* <p>An implementation MUST minimally support the default mechanism type: DOM.
*
* <p>Note that a caller must use the same <code>XMLSignatureFactory</code>
* instance to create the <code>XMLStructure</code>s of a particular
* <code>XMLSignature</code> that is to be generated. The behavior is
* undefined if <code>XMLStructure</code>s from different providers or
* different mechanism types are used together.
*
* <p>Also, the <code>XMLStructure</code>s that are created by this factory
* may contain state specific to the <code>XMLSignature</code> and are not
* intended to be reusable.
*
* <h2>Creating XMLSignatures from scratch</h2>
*
* <p>Once the <code>XMLSignatureFactory</code> has been created, objects
* can be instantiated by calling the appropriate method. For example, a
* {@link Reference} instance may be created by invoking one of the
* {@link #newReference newReference} methods.
*
* <h2>Unmarshalling XMLSignatures from XML</h2>
*
* <p>Alternatively, an <code>XMLSignature</code> may be created from an
* existing XML representation by invoking the {@link #unmarshalXMLSignature
* unmarshalXMLSignature} method and passing it a mechanism-specific
* {@link XMLValidateContext} instance containing the XML content:
*
* <pre>
* DOMValidateContext context = new DOMValidateContext(key, signatureElement);
* XMLSignature signature = factory.unmarshalXMLSignature(context);
* </pre>
*
* Each <code>XMLSignatureFactory</code> must support the required
* <code>XMLValidateContext</code> types for that factory type, but may support
* others. A DOM <code>XMLSignatureFactory</code> must support {@link
* DOMValidateContext} objects.
*
* <h2>Signing and marshalling XMLSignatures to XML</h2>
*
* Each <code>XMLSignature</code> created by the factory can also be
* marshalled to an XML representation and signed, by invoking the
* {@link XMLSignature#sign sign} method of the
* {@link XMLSignature} object and passing it a mechanism-specific
* {@link XMLSignContext} object containing the signing key and
* marshalling parameters (see {@link DOMSignContext}).
* For example:
*
* <pre>
* DOMSignContext context = new DOMSignContext(privateKey, document);
* signature.sign(context);
* </pre>
*
* <b>Concurrent Access</b>
* <p>The static methods of this class are guaranteed to be thread-safe.
* Multiple threads may concurrently invoke the static methods defined in this
* class with no ill effects.
*
* <p>However, this is not true for the non-static methods defined by this
* class. Unless otherwise documented by a specific provider, threads that
* need to access a single <code>XMLSignatureFactory</code> instance
* concurrently should synchronize amongst themselves and provide the
* necessary locking. Multiple threads each manipulating a different
* <code>XMLSignatureFactory</code> instance need not synchronize.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
*/
public abstract class XMLSignatureFactory {
private String mechanismType;
private Provider provider;
/**
* Default constructor, for invocation by subclasses.
*/
protected XMLSignatureFactory() {}
/**
* Returns an <code>XMLSignatureFactory</code> that supports the
* specified XML processing mechanism and representation type (ex: "DOM").
*
* <p>This method uses the standard JCA provider lookup mechanism to
* locate and instantiate an <code>XMLSignatureFactory</code>
* implementation of the desired mechanism type. It traverses the list of
* registered security <code>Provider</code>s, starting with the most
* preferred <code>Provider</code>. A new <code>XMLSignatureFactory</code>
* object from the first <code>Provider</code> that supports the specified
* mechanism is returned.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @return a new <code>XMLSignatureFactory</code>
* @throws NullPointerException if <code>mechanismType</code> is
* <code>null</code>
* @throws NoSuchMechanismException if no <code>Provider</code> supports an
* <code>XMLSignatureFactory</code> implementation for the specified
* mechanism
* @see Provider
*/
public static XMLSignatureFactory getInstance(String mechanismType) {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
}
Instance instance;
try {
instance = GetInstance.getInstance
("XMLSignatureFactory", null, mechanismType);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
/**
* Returns an <code>XMLSignatureFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. Note that the specified
* <code>Provider</code> object does not have to be registered in the
* provider list.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @param provider the <code>Provider</code> object
* @return a new <code>XMLSignatureFactory</code>
* @throws NullPointerException if <code>provider</code> or
* <code>mechanismType</code> is <code>null</code>
* @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
* implementation for the specified mechanism is not available
* from the specified <code>Provider</code> object
* @see Provider
*/
public static XMLSignatureFactory getInstance(String mechanismType,
Provider provider) {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
}
Instance instance;
try {
instance = GetInstance.getInstance
("XMLSignatureFactory", null, mechanismType, provider);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
/**
* Returns an <code>XMLSignatureFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. The specified provider must be
* registered in the security provider list.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @param provider the string name of the provider
* @return a new <code>XMLSignatureFactory</code>
* @throws NoSuchProviderException if the specified provider is not
* registered in the security provider list
* @throws NullPointerException if <code>provider</code> or
* <code>mechanismType</code> is <code>null</code>
* @throws NoSuchMechanismException if an <code>XMLSignatureFactory</code>
* implementation for the specified mechanism is not
* available from the specified provider
* @see Provider
*/
public static XMLSignatureFactory getInstance(String mechanismType,
String provider) throws NoSuchProviderException {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
} else if (provider.length() == 0) {
throw new NoSuchProviderException();
}
Instance instance;
try {
instance = GetInstance.getInstance
("XMLSignatureFactory", null, mechanismType, provider);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
XMLSignatureFactory factory = (XMLSignatureFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
/**
* Returns an <code>XMLSignatureFactory</code> that supports the
* default XML processing mechanism and representation type ("DOM").
*
* <p>This method uses the standard JCA provider lookup mechanism to
* locate and instantiate an <code>XMLSignatureFactory</code>
* implementation of the default mechanism type. It traverses the list of
* registered security <code>Provider</code>s, starting with the most
* preferred <code>Provider</code>. A new <code>XMLSignatureFactory</code>
* object from the first <code>Provider</code> that supports the DOM
* mechanism is returned.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @return a new <code>XMLSignatureFactory</code>
* @throws NoSuchMechanismException if no <code>Provider</code> supports an
* <code>XMLSignatureFactory</code> implementation for the DOM
* mechanism
* @see Provider
*/
public static XMLSignatureFactory getInstance() {
return getInstance("DOM");
}
/**
* Returns the type of the XML processing mechanism and representation
* supported by this <code>XMLSignatureFactory</code> (ex: "DOM").
*
* @return the XML processing mechanism type supported by this
* <code>XMLSignatureFactory</code>
*/
public final String getMechanismType() {
return mechanismType;
}
/**
* Returns the provider of this <code>XMLSignatureFactory</code>.
*
* @return the provider of this <code>XMLSignatureFactory</code>
*/
public final Provider getProvider() {
return provider;
}
/**
* Creates an <code>XMLSignature</code> and initializes it with the contents
* of the specified <code>SignedInfo</code> and <code>KeyInfo</code>
* objects.
*
* @param si the signed info
* @param ki the key info (may be <code>null</code>)
* @return an <code>XMLSignature</code>
* @throws NullPointerException if <code>si</code> is <code>null</code>
*/
public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki);
/**
* Creates an <code>XMLSignature</code> and initializes it with the
* specified parameters.
*
* @param si the signed info
* @param ki the key info (may be <code>null</code>)
* @param objects a list of {@link XMLObject}s (may be empty or
* <code>null</code>)
* @param id the Id (may be <code>null</code>)
* @param signatureValueId the SignatureValue Id (may be <code>null</code>)
* @return an <code>XMLSignature</code>
* @throws NullPointerException if <code>si</code> is <code>null</code>
* @throws ClassCastException if any of the <code>objects</code> are not of
* type <code>XMLObject</code>
*/
@SuppressWarnings("rawtypes")
public abstract XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki,
List objects, String id, String signatureValueId);
/**
* Creates a <code>Reference</code> with the specified URI and digest
* method.
*
* @param uri the reference URI (may be <code>null</code>)
* @param dm the digest method
* @return a <code>Reference</code>
* @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
* compliant
* @throws NullPointerException if <code>dm</code> is <code>null</code>
*/
public abstract Reference newReference(String uri, DigestMethod dm);
/**
* Creates a <code>Reference</code> with the specified parameters.
*
* @param uri the reference URI (may be <code>null</code>)
* @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 type the reference type, as a URI (may be <code>null</code>)
* @param id the reference ID (may be <code>null</code>)
* @return a <code>Reference</code>
* @throws ClassCastException if any of the <code>transforms</code> are
* not of type <code>Transform</code>
* @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
* compliant
* @throws NullPointerException if <code>dm</code> is <code>null</code>
*/
@SuppressWarnings("rawtypes")
public abstract Reference newReference(String uri, DigestMethod dm,
List transforms, String type, String id);
/**
* Creates a <code>Reference</code> with the specified parameters and
* pre-calculated digest value.
*
* <p>This method is useful when the digest value of a
* <code>Reference</code> has been previously computed. See for example,
* the
* <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=dss">
* OASIS-DSS (Digital Signature Services)</a> specification.
*
* @param uri the reference URI (may be <code>null</code>)
* @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 type the reference type, as a URI (may be <code>null</code>)
* @param id the reference ID (may be <code>null</code>)
* @param digestValue the digest value. The array is cloned to protect
* against subsequent modification.
* @return a <code>Reference</code>
* @throws ClassCastException if any of the <code>transforms</code> are
* not of type <code>Transform</code>
* @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
* compliant
* @throws NullPointerException if <code>dm</code> or
* <code>digestValue</code> is <code>null</code>
*/
@SuppressWarnings("rawtypes")
public abstract Reference newReference(String uri, DigestMethod dm,
List transforms, String type, String id, byte[] digestValue);
/**
* Creates a <code>Reference</code> with the specified parameters.
*
* <p>This method is useful when a list of transforms have already been
* applied to the <code>Reference</code>. See for example,
* the
* <a href="http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=dss">
* OASIS-DSS (Digital Signature Services)</a> specification.
*
* <p>When an <code>XMLSignature</code> containing this reference is
* generated, the specified <code>transforms</code> (if non-null) are
* applied to the specified <code>result</code>. The
* <code>Transforms</code> element of the resulting <code>Reference</code>
* element is set to the concatenation of the
* <code>appliedTransforms</code> and <code>transforms</code>.
*
* @param uri the reference URI (may be <code>null</code>)
* @param dm the digest method
* @param appliedTransforms a list of {@link Transform}s that have
* already been applied. The list is defensively
* copied to protect against subsequent modification. The list must
* contain at least one entry.
* @param result the result of processing the sequence of
* <code>appliedTransforms</code>
* @param transforms a list of {@link Transform}s that are to be applied
* when generating the signature. The list is defensively copied to
* protect against subsequent modification. May be <code>null</code>
* or empty.
* @param type the reference type, as a URI (may be <code>null</code>)
* @param id the reference ID (may be <code>null</code>)
* @return a <code>Reference</code>
* @throws ClassCastException if any of the transforms (in either list)
* are not of type <code>Transform</code>
* @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
* compliant or <code>appliedTransforms</code> is empty
* @throws NullPointerException if <code>dm</code>,
* <code>appliedTransforms</code> or <code>result</code> is
* <code>null</code>
*/
@SuppressWarnings("rawtypes")
public abstract Reference newReference(String uri, DigestMethod dm,
List appliedTransforms, Data result, List transforms, String type,
String id);
/**
* Creates a <code>SignedInfo</code> with the specified canonicalization
* and signature methods, and list of one or more references.
*
* @param cm the canonicalization method
* @param sm the signature method
* @param references a list of one or more {@link Reference}s. The list is
* defensively copied to protect against subsequent modification.
* @return a <code>SignedInfo</code>
* @throws ClassCastException if any of the references are not of
* type <code>Reference</code>
* @throws IllegalArgumentException if <code>references</code> is empty
* @throws NullPointerException if any of the parameters
* are <code>null</code>
*/
@SuppressWarnings("rawtypes")
public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm,
SignatureMethod sm, List references);
/**
* Creates a <code>SignedInfo</code> with the specified parameters.
*
* @param cm the canonicalization method
* @param sm the signature method
* @param references a list of one or more {@link Reference}s. The list is
* defensively copied to protect against subsequent modification.
* @param id the id (may be <code>null</code>)
* @return a <code>SignedInfo</code>
* @throws ClassCastException if any of the references are not of
* type <code>Reference</code>
* @throws IllegalArgumentException if <code>references</code> is empty
* @throws NullPointerException if <code>cm</code>, <code>sm</code>, or
* <code>references</code> are <code>null</code>
*/
@SuppressWarnings("rawtypes")
public abstract SignedInfo newSignedInfo(CanonicalizationMethod cm,
SignatureMethod sm, List references, String id);
// Object factory methods
/**
* Creates an <code>XMLObject</code> from the specified parameters.
*
* @param content a list of {@link XMLStructure}s. The list
* is defensively copied to protect against subsequent modification.
* May be <code>null</code> or empty.
* @param id the Id (may be <code>null</code>)
* @param mimeType the mime type (may be <code>null</code>)
* @param encoding the encoding (may be <code>null</code>)
* @return an <code>XMLObject</code>
* @throws ClassCastException if <code>content</code> contains any
* entries that are not of type {@link XMLStructure}
*/
@SuppressWarnings("rawtypes")
public abstract XMLObject newXMLObject(List content, String id,
String mimeType, String encoding);
/**
* Creates a <code>Manifest</code> containing the specified
* list of {@link Reference}s.
*
* @param references a list of one or more <code>Reference</code>s. The list
* is defensively copied to protect against subsequent modification.
* @return a <code>Manifest</code>
* @throws NullPointerException if <code>references</code> is
* <code>null</code>
* @throws IllegalArgumentException if <code>references</code> is empty
* @throws ClassCastException if <code>references</code> contains any
* entries that are not of type {@link Reference}
*/
@SuppressWarnings("rawtypes")
public abstract Manifest newManifest(List references);
/**
* Creates a <code>Manifest</code> containing the specified
* list of {@link Reference}s and optional id.
*
* @param references a list of one or more <code>Reference</code>s. The list
* is defensively copied to protect against subsequent modification.
* @param id the id (may be <code>null</code>)
* @return a <code>Manifest</code>
* @throws NullPointerException if <code>references</code> is
* <code>null</code>
* @throws IllegalArgumentException if <code>references</code> is empty
* @throws ClassCastException if <code>references</code> contains any
* entries that are not of type {@link Reference}
*/
@SuppressWarnings("rawtypes")
public abstract Manifest newManifest(List references, String id);
/**
* Creates a <code>SignatureProperty</code> containing the specified
* list of {@link XMLStructure}s, target URI and optional id.
*
* @param content a list of one or more <code>XMLStructure</code>s. The list
* is defensively copied to protect against subsequent modification.
* @param target the target URI of the Signature that this property applies
* to
* @param id the id (may be <code>null</code>)
* @return a <code>SignatureProperty</code>
* @throws NullPointerException if <code>content</code> or
* <code>target</code> is <code>null</code>
* @throws IllegalArgumentException if <code>content</code> is empty
* @throws ClassCastException if <code>content</code> contains any
* entries that are not of type {@link XMLStructure}
*/
@SuppressWarnings("rawtypes")
public abstract SignatureProperty newSignatureProperty
(List content, String target, String id);
/**
* Creates a <code>SignatureProperties</code> containing the specified
* list of {@link SignatureProperty}s and optional id.
*
* @param properties a list of one or more <code>SignatureProperty</code>s.
* The list is defensively copied to protect against subsequent
* modification.
* @param id the id (may be <code>null</code>)
* @return a <code>SignatureProperties</code>
* @throws NullPointerException if <code>properties</code>
* is <code>null</code>
* @throws IllegalArgumentException if <code>properties</code> is empty
* @throws ClassCastException if <code>properties</code> contains any
* entries that are not of type {@link SignatureProperty}
*/
@SuppressWarnings("rawtypes")
public abstract SignatureProperties newSignatureProperties
(List properties, String id);
// Algorithm factory methods
/**
* Creates a <code>DigestMethod</code> for the specified algorithm URI
* and parameters.
*
* @param algorithm the URI identifying the digest algorithm
* @param params algorithm-specific digest parameters (may be
* <code>null</code>)
* @return the <code>DigestMethod</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are inappropriate for the requested algorithm
* @throws NoSuchAlgorithmException if an implementation of the
* specified algorithm cannot be found
* @throws NullPointerException if <code>algorithm</code> is
* <code>null</code>
*/
public abstract DigestMethod newDigestMethod(String algorithm,
DigestMethodParameterSpec params) throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException;
/**
* Creates a <code>SignatureMethod</code> for the specified algorithm URI
* and parameters.
*
* @param algorithm the URI identifying the signature algorithm
* @param params algorithm-specific signature parameters (may be
* <code>null</code>)
* @return the <code>SignatureMethod</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are inappropriate for the requested algorithm
* @throws NoSuchAlgorithmException if an implementation of the
* specified algorithm cannot be found
* @throws NullPointerException if <code>algorithm</code> is
* <code>null</code>
*/
public abstract SignatureMethod newSignatureMethod(String algorithm,
SignatureMethodParameterSpec params) throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException;
/**
* Creates a <code>Transform</code> for the specified algorithm URI
* and parameters.
*
* @param algorithm the URI identifying the transform algorithm
* @param params algorithm-specific transform parameters (may be
* <code>null</code>)
* @return the <code>Transform</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are inappropriate for the requested algorithm
* @throws NoSuchAlgorithmException if an implementation of the
* specified algorithm cannot be found
* @throws NullPointerException if <code>algorithm</code> is
* <code>null</code>
*/
public abstract Transform newTransform(String algorithm,
TransformParameterSpec params) throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException;
/**
* Creates a <code>Transform</code> for the specified algorithm URI
* and parameters. The parameters are specified as a mechanism-specific
* <code>XMLStructure</code> (ex: {@link DOMStructure}). This method is
* useful when the parameters are in XML form or there is no standard
* class for specifying the parameters.
*
* @param algorithm the URI identifying the transform algorithm
* @param params a mechanism-specific XML structure from which to
* unmarshal the parameters from (may be <code>null</code> if
* not required or optional)
* @return the <code>Transform</code>
* @throws ClassCastException if the type of <code>params</code> is
* inappropriate for this <code>XMLSignatureFactory</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are inappropriate for the requested algorithm
* @throws NoSuchAlgorithmException if an implementation of the
* specified algorithm cannot be found
* @throws NullPointerException if <code>algorithm</code> is
* <code>null</code>
*/
public abstract Transform newTransform(String algorithm,
XMLStructure params) throws NoSuchAlgorithmException,
InvalidAlgorithmParameterException;
/**
* Creates a <code>CanonicalizationMethod</code> for the specified
* algorithm URI and parameters.
*
* @param algorithm the URI identifying the canonicalization algorithm
* @param params algorithm-specific canonicalization parameters (may be
* <code>null</code>)
* @return the <code>CanonicalizationMethod</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are inappropriate for the requested algorithm
* @throws NoSuchAlgorithmException if an implementation of the
* specified algorithm cannot be found
* @throws NullPointerException if <code>algorithm</code> is
* <code>null</code>
*/
public abstract CanonicalizationMethod newCanonicalizationMethod(
String algorithm, C14NMethodParameterSpec params)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException;
/**
* Creates a <code>CanonicalizationMethod</code> for the specified
* algorithm URI and parameters. The parameters are specified as a
* mechanism-specific <code>XMLStructure</code> (ex: {@link DOMStructure}).
* This method is useful when the parameters are in XML form or there is
* no standard class for specifying the parameters.
*
* @param algorithm the URI identifying the canonicalization algorithm
* @param params a mechanism-specific XML structure from which to
* unmarshal the parameters from (may be <code>null</code> if
* not required or optional)
* @return the <code>CanonicalizationMethod</code>
* @throws ClassCastException if the type of <code>params</code> is
* inappropriate for this <code>XMLSignatureFactory</code>
* @throws InvalidAlgorithmParameterException if the specified parameters
* are inappropriate for the requested algorithm
* @throws NoSuchAlgorithmException if an implementation of the
* specified algorithm cannot be found
* @throws NullPointerException if <code>algorithm</code> is
* <code>null</code>
*/
public abstract CanonicalizationMethod newCanonicalizationMethod(
String algorithm, XMLStructure params)
throws NoSuchAlgorithmException, InvalidAlgorithmParameterException;
/**
* Returns a <code>KeyInfoFactory</code> that creates <code>KeyInfo</code>
* objects. The returned <code>KeyInfoFactory</code> has the same
* mechanism type and provider as this <code>XMLSignatureFactory</code>.
*
* @return a <code>KeyInfoFactory</code>
* @throws NoSuchMechanismException if a <code>KeyFactory</code>
* implementation with the same mechanism type and provider
* is not available
*/
public final KeyInfoFactory getKeyInfoFactory() {
return KeyInfoFactory.getInstance(getMechanismType(), getProvider());
}
/**
* Unmarshals a new <code>XMLSignature</code> instance from a
* mechanism-specific <code>XMLValidateContext</code> instance.
*
* @param context a mechanism-specific context from which to unmarshal the
* signature from
* @return the <code>XMLSignature</code>
* @throws NullPointerException if <code>context</code> is
* <code>null</code>
* @throws ClassCastException if the type of <code>context</code> is
* inappropriate for this factory
* @throws MarshalException if an unrecoverable exception occurs
* during unmarshalling
*/
public abstract XMLSignature unmarshalXMLSignature
(XMLValidateContext context) throws MarshalException;
/**
* Unmarshals a new <code>XMLSignature</code> instance from a
* mechanism-specific <code>XMLStructure</code> instance.
* This method is useful if you only want to unmarshal (and not
* validate) an <code>XMLSignature</code>.
*
* @param xmlStructure a mechanism-specific XML structure from which to
* unmarshal the signature from
* @return the <code>XMLSignature</code>
* @throws NullPointerException if <code>xmlStructure</code> is
* <code>null</code>
* @throws ClassCastException if the type of <code>xmlStructure</code> is
* inappropriate for this factory
* @throws MarshalException if an unrecoverable exception occurs
* during unmarshalling
*/
public abstract XMLSignature unmarshalXMLSignature
(XMLStructure xmlStructure) throws MarshalException;
/**
* Indicates whether a specified feature is supported.
*
* @param feature the feature name (as an absolute URI)
* @return <code>true</code> if the specified feature is supported,
* <code>false</code> otherwise
* @throws NullPointerException if <code>feature</code> is <code>null</code>
*/
public abstract boolean isFeatureSupported(String feature);
/**
* Returns a reference to the <code>URIDereferencer</code> that is used by
* default to dereference URIs in {@link Reference} objects.
*
* @return a reference to the default <code>URIDereferencer</code> (never
* <code>null</code>)
*/
public abstract URIDereferencer getURIDereferencer();
}

View File

@@ -0,0 +1,63 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XMLValidateContext.java,v 1.8 2005/05/10 16:03:49 mullan Exp $
*/
package javax.xml.crypto.dsig;
import javax.xml.crypto.XMLCryptoContext;
/**
* Contains context information for validating XML Signatures. This interface
* is primarily intended for type-safety.
*
* <p>Note that <code>XMLValidateContext</code> instances can contain
* information and state specific to the XML signature structure it is
* used with. The results are unpredictable if an
* <code>XMLValidateContext</code> is used with different signature structures
* (for example, you should not use the same <code>XMLValidateContext</code>
* instance to validate two different {@link XMLSignature} objects).
* <p>
* <b><a name="Supported Properties"></a>Supported Properties</b>
* <p>The following properties can be set by an application using the
* {@link #setProperty setProperty} method.
* <ul>
* <li><code>javax.xml.crypto.dsig.cacheReference</code>: value must be a
* {@link Boolean}. This property controls whether or not the
* {@link Reference#validate Reference.validate} method will cache the
* dereferenced content and pre-digested input for subsequent retrieval via
* the {@link Reference#getDereferencedData Reference.getDereferencedData}
* and {@link Reference#getDigestInputStream
* Reference.getDigestInputStream} methods. The default value if not
* specified is <code>Boolean.FALSE</code>.
* </ul>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignature#validate(XMLValidateContext)
* @see Reference#validate(XMLValidateContext)
*/
public interface XMLValidateContext extends XMLCryptoContext {}

View File

@@ -0,0 +1,209 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: DOMSignContext.java,v 1.9 2005/05/10 16:31:14 mullan Exp $
*/
package javax.xml.crypto.dsig.dom;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.dom.DOMCryptoContext;
import javax.xml.crypto.dsig.XMLSignContext;
import javax.xml.crypto.dsig.XMLSignature;
import java.security.Key;
import org.w3c.dom.Node;
/**
* A DOM-specific {@link XMLSignContext}. This class contains additional methods
* to specify the location in a DOM tree where an {@link XMLSignature}
* object is to be marshalled when generating the signature.
*
* <p>Note that <code>DOMSignContext</code> instances can contain
* information and state specific to the XML signature structure it is
* used with. The results are unpredictable if a
* <code>DOMSignContext</code> is used with different signature structures
* (for example, you should not use the same <code>DOMSignContext</code>
* instance to sign two different {@link XMLSignature} objects).
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
*/
public class DOMSignContext extends DOMCryptoContext implements XMLSignContext {
private Node parent;
private Node nextSibling;
/**
* Creates a <code>DOMSignContext</code> with the specified signing key
* and parent node. The signing key is stored in a
* {@link KeySelector#singletonKeySelector singleton KeySelector} that is
* returned by the {@link #getKeySelector getKeySelector} method.
* The marshalled <code>XMLSignature</code> will be added as the last
* child element of the specified parent node unless a next sibling node is
* specified by invoking the {@link #setNextSibling setNextSibling} method.
*
* @param signingKey the signing key
* @param parent the parent node
* @throws NullPointerException if <code>signingKey</code> or
* <code>parent</code> is <code>null</code>
*/
public DOMSignContext(Key signingKey, Node parent) {
if (signingKey == null) {
throw new NullPointerException("signingKey cannot be null");
}
if (parent == null) {
throw new NullPointerException("parent cannot be null");
}
setKeySelector(KeySelector.singletonKeySelector(signingKey));
this.parent = parent;
}
/**
* Creates a <code>DOMSignContext</code> with the specified signing key,
* parent and next sibling nodes. The signing key is stored in a
* {@link KeySelector#singletonKeySelector singleton KeySelector} that is
* returned by the {@link #getKeySelector getKeySelector} method.
* The marshalled <code>XMLSignature</code> will be inserted as a child
* element of the specified parent node and immediately before the
* specified next sibling node.
*
* @param signingKey the signing key
* @param parent the parent node
* @param nextSibling the next sibling node
* @throws NullPointerException if <code>signingKey</code>,
* <code>parent</code> or <code>nextSibling</code> is <code>null</code>
*/
public DOMSignContext(Key signingKey, Node parent, Node nextSibling) {
if (signingKey == null) {
throw new NullPointerException("signingKey cannot be null");
}
if (parent == null) {
throw new NullPointerException("parent cannot be null");
}
if (nextSibling == null) {
throw new NullPointerException("nextSibling cannot be null");
}
setKeySelector(KeySelector.singletonKeySelector(signingKey));
this.parent = parent;
this.nextSibling = nextSibling;
}
/**
* Creates a <code>DOMSignContext</code> with the specified key selector
* and parent node. The marshalled <code>XMLSignature</code> will be added
* as the last child element of the specified parent node unless a next
* sibling node is specified by invoking the
* {@link #setNextSibling setNextSibling} method.
*
* @param ks the key selector
* @param parent the parent node
* @throws NullPointerException if <code>ks</code> or <code>parent</code>
* is <code>null</code>
*/
public DOMSignContext(KeySelector ks, Node parent) {
if (ks == null) {
throw new NullPointerException("key selector cannot be null");
}
if (parent == null) {
throw new NullPointerException("parent cannot be null");
}
setKeySelector(ks);
this.parent = parent;
}
/**
* Creates a <code>DOMSignContext</code> with the specified key selector,
* parent and next sibling nodes. The marshalled <code>XMLSignature</code>
* will be inserted as a child element of the specified parent node and
* immediately before the specified next sibling node.
*
* @param ks the key selector
* @param parent the parent node
* @param nextSibling the next sibling node
* @throws NullPointerException if <code>ks</code>, <code>parent</code> or
* <code>nextSibling</code> is <code>null</code>
*/
public DOMSignContext(KeySelector ks, Node parent, Node nextSibling) {
if (ks == null) {
throw new NullPointerException("key selector cannot be null");
}
if (parent == null) {
throw new NullPointerException("parent cannot be null");
}
if (nextSibling == null) {
throw new NullPointerException("nextSibling cannot be null");
}
setKeySelector(ks);
this.parent = parent;
this.nextSibling = nextSibling;
}
/**
* Sets the parent node.
*
* @param parent the parent node. The marshalled <code>XMLSignature</code>
* will be added as a child element of this node.
* @throws NullPointerException if <code>parent</code> is <code>null</code>
* @see #getParent
*/
public void setParent(Node parent) {
if (parent == null) {
throw new NullPointerException("parent is null");
}
this.parent = parent;
}
/**
* Sets the next sibling node.
*
* @param nextSibling the next sibling node. The marshalled
* <code>XMLSignature</code> will be inserted immediately before this
* node. Specify <code>null</code> to remove the current setting.
* @see #getNextSibling
*/
public void setNextSibling(Node nextSibling) {
this.nextSibling = nextSibling;
}
/**
* Returns the parent node.
*
* @return the parent node (never <code>null</code>)
* @see #setParent(Node)
*/
public Node getParent() {
return parent;
}
/**
* Returns the nextSibling node.
*
* @return the nextSibling node, or <code>null</code> if not specified.
* @see #setNextSibling(Node)
*/
public Node getNextSibling() {
return nextSibling;
}
}

View File

@@ -0,0 +1,135 @@
/*
* Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: DOMValidateContext.java,v 1.8 2005/05/10 16:31:14 mullan Exp $
*/
package javax.xml.crypto.dsig.dom;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.dom.DOMCryptoContext;
import javax.xml.crypto.dsig.XMLSignature;
import javax.xml.crypto.dsig.XMLSignatureFactory;
import javax.xml.crypto.dsig.XMLValidateContext;
import java.security.Key;
import org.w3c.dom.Node;
/**
* A DOM-specific {@link XMLValidateContext}. This class contains additional
* methods to specify the location in a DOM tree where an {@link XMLSignature}
* is to be unmarshalled and validated from.
*
* <p>Note that the behavior of an unmarshalled <code>XMLSignature</code>
* is undefined if the contents of the underlying DOM tree are modified by the
* caller after the <code>XMLSignature</code> is created.
*
* <p>Also, note that <code>DOMValidateContext</code> instances can contain
* information and state specific to the XML signature structure it is
* used with. The results are unpredictable if a
* <code>DOMValidateContext</code> is used with different signature structures
* (for example, you should not use the same <code>DOMValidateContext</code>
* instance to validate two different {@link XMLSignature} objects).
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XMLSignatureFactory#unmarshalXMLSignature(XMLValidateContext)
*/
public class DOMValidateContext extends DOMCryptoContext
implements XMLValidateContext {
private Node node;
/**
* Creates a <code>DOMValidateContext</code> containing the specified key
* selector and node.
*
* @param ks a key selector for finding a validation key
* @param node the node
* @throws NullPointerException if <code>ks</code> or <code>node</code> is
* <code>null</code>
*/
public DOMValidateContext(KeySelector ks, Node node) {
if (ks == null) {
throw new NullPointerException("key selector is null");
}
init(node, ks);
}
/**
* Creates a <code>DOMValidateContext</code> containing the specified key
* and node. The validating key will be stored in a
* {@link KeySelector#singletonKeySelector singleton KeySelector} that
* is returned when the {@link #getKeySelector getKeySelector}
* method is called.
*
* @param validatingKey the validating key
* @param node the node
* @throws NullPointerException if <code>validatingKey</code> or
* <code>node</code> is <code>null</code>
*/
public DOMValidateContext(Key validatingKey, Node node) {
if (validatingKey == null) {
throw new NullPointerException("validatingKey is null");
}
init(node, KeySelector.singletonKeySelector(validatingKey));
}
private void init(Node node, KeySelector ks) {
if (node == null) {
throw new NullPointerException("node is null");
}
this.node = node;
super.setKeySelector(ks);
if (System.getSecurityManager() != null) {
super.setProperty("org.jcp.xml.dsig.secureValidation",
Boolean.TRUE);
}
}
/**
* Sets the node.
*
* @param node the node
* @throws NullPointerException if <code>node</code> is <code>null</code>
* @see #getNode
*/
public void setNode(Node node) {
if (node == null) {
throw new NullPointerException();
}
this.node = node;
}
/**
* Returns the node.
*
* @return the node (never <code>null</code>)
* @see #setNode(Node)
*/
public Node getNode() {
return node;
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: KeyInfo.java,v 1.7 2005/05/10 16:35:34 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import java.util.List;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.XMLCryptoContext;
import javax.xml.crypto.XMLStructure;
/**
* A representation of the XML <code>KeyInfo</code> element as defined in
* the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* A <code>KeyInfo</code> contains a list of {@link XMLStructure}s, each of
* which contain information that enables the recipient(s) to obtain the key
* needed to validate an XML signature. The XML Schema Definition is defined as:
*
* <pre>
* &lt;element name="KeyInfo" type="ds:KeyInfoType"/&gt;
* &lt;complexType name="KeyInfoType" mixed="true"&gt;
* &lt;choice maxOccurs="unbounded"&gt;
* &lt;element ref="ds:KeyName"/&gt;
* &lt;element ref="ds:KeyValue"/&gt;
* &lt;element ref="ds:RetrievalMethod"/&gt;
* &lt;element ref="ds:X509Data"/&gt;
* &lt;element ref="ds:PGPData"/&gt;
* &lt;element ref="ds:SPKIData"/&gt;
* &lt;element ref="ds:MgmtData"/&gt;
* &lt;any processContents="lax" namespace="##other"/&gt;
* &lt;!-- (1,1) elements from (0,unbounded) namespaces --&gt;
* &lt;/choice&gt;
* &lt;attribute name="Id" type="ID" use="optional"/&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>KeyInfo</code> instance may be created by invoking one of the
* {@link KeyInfoFactory#newKeyInfo newKeyInfo} methods of the
* {@link KeyInfoFactory} class, and passing it a list of one or more
* <code>XMLStructure</code>s and an optional id parameter;
* for example:
* <pre>
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* KeyInfo keyInfo = factory.newKeyInfo
* (Collections.singletonList(factory.newKeyName("Alice"), "keyinfo-1"));
* </pre>
*
* <p><code>KeyInfo</code> objects can also be marshalled to XML by invoking
* the {@link #marshal marshal} method.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see KeyInfoFactory#newKeyInfo(List)
* @see KeyInfoFactory#newKeyInfo(List, String)
*/
public interface KeyInfo extends XMLStructure {
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} containing the key information. Each entry of the list is
* an {@link XMLStructure}.
*
* <p>If there is a public subclass representing the type of
* <code>XMLStructure</code>, it is returned as an instance of that
* class (ex: an <code>X509Data</code> element would be returned as an
* instance of {@link javax.xml.crypto.dsig.keyinfo.X509Data}).
*
* @return an unmodifiable list of one or more <code>XMLStructure</code>s
* in this <code>KeyInfo</code>. Never returns <code>null</code> or an
* empty list.
*/
@SuppressWarnings("rawtypes")
List getContent();
/**
* Return the optional Id attribute of this <code>KeyInfo</code>, which
* may be useful for referencing this <code>KeyInfo</code> from other
* XML structures.
*
* @return the Id attribute of this <code>KeyInfo</code> (may be
* <code>null</code> if not specified)
*/
String getId();
/**
* Marshals the key info to XML.
*
* @param parent a mechanism-specific structure containing the parent node
* that the marshalled key info will be appended to
* @param context the <code>XMLCryptoContext</code> containing additional
* context (may be null if not applicable)
* @throws ClassCastException if the type of <code>parent</code> or
* <code>context</code> is not compatible with this key info
* @throws MarshalException if the key info cannot be marshalled
* @throws NullPointerException if <code>parent</code> is <code>null</code>
*/
void marshal(XMLStructure parent, XMLCryptoContext context)
throws MarshalException;
}

View File

@@ -0,0 +1,528 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: KeyInfoFactory.java,v 1.12 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import java.math.BigInteger;
import java.security.KeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Provider;
import java.security.PublicKey;
import java.security.Security;
import java.security.cert.X509CRL;
import java.util.List;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.NoSuchMechanismException;
import javax.xml.crypto.URIDereferencer;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dom.DOMStructure;
import javax.xml.crypto.dsig.*;
import sun.security.jca.*;
import sun.security.jca.GetInstance.Instance;
/**
* A factory for creating {@link KeyInfo} objects from scratch or for
* unmarshalling a <code>KeyInfo</code> object from a corresponding XML
* representation.
*
* <p>Each instance of <code>KeyInfoFactory</code> supports a specific
* XML mechanism type. To create a <code>KeyInfoFactory</code>, call one of the
* static {@link #getInstance getInstance} methods, passing in the XML
* mechanism type desired, for example:
*
* <blockquote><code>
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* </code></blockquote>
*
* <p>The objects that this factory produces will be based
* on DOM and abide by the DOM interoperability requirements as defined in the
* <a href="../../../../../../technotes/guides/security/xmldsig/overview.html#DOM Mechanism Requirements">
* DOM Mechanism Requirements</a> section of the API overview. See the
* <a href="../../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of standard
* mechanism types.
*
* <p><code>KeyInfoFactory</code> implementations are registered and loaded
* using the {@link java.security.Provider} mechanism.
* For example, a service provider that supports the
* DOM mechanism would be specified in the <code>Provider</code> subclass as:
* <pre>
* put("KeyInfoFactory.DOM", "org.example.DOMKeyInfoFactory");
* </pre>
*
* <p>Also, the <code>XMLStructure</code>s that are created by this factory
* may contain state specific to the <code>KeyInfo</code> and are not
* intended to be reusable.
*
* <p>An implementation MUST minimally support the default mechanism type: DOM.
*
* <p>Note that a caller must use the same <code>KeyInfoFactory</code>
* instance to create the <code>XMLStructure</code>s of a particular
* <code>KeyInfo</code> object. The behavior is undefined if
* <code>XMLStructure</code>s from different providers or different mechanism
* types are used together.
*
* <p><b>Concurrent Access</b>
* <p>The static methods of this class are guaranteed to be thread-safe.
* Multiple threads may concurrently invoke the static methods defined in this
* class with no ill effects.
*
* <p>However, this is not true for the non-static methods defined by this
* class. Unless otherwise documented by a specific provider, threads that
* need to access a single <code>KeyInfoFactory</code> instance concurrently
* should synchronize amongst themselves and provide the necessary locking.
* Multiple threads each manipulating a different <code>KeyInfoFactory</code>
* instance need not synchronize.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
*/
public abstract class KeyInfoFactory {
private String mechanismType;
private Provider provider;
/**
* Default constructor, for invocation by subclasses.
*/
protected KeyInfoFactory() {}
/**
* Returns a <code>KeyInfoFactory</code> that supports the
* specified XML processing mechanism and representation type (ex: "DOM").
*
* <p>This method uses the standard JCA provider lookup mechanism to
* locate and instantiate a <code>KeyInfoFactory</code> implementation of
* the desired mechanism type. It traverses the list of registered security
* <code>Provider</code>s, starting with the most preferred
* <code>Provider</code>. A new <code>KeyInfoFactory</code> object
* from the first <code>Provider</code> that supports the specified
* mechanism is returned.
*
* <p> Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @return a new <code>KeyInfoFactory</code>
* @throws NullPointerException if <code>mechanismType</code> is
* <code>null</code>
* @throws NoSuchMechanismException if no <code>Provider</code> supports a
* <code>KeyInfoFactory</code> implementation for the specified mechanism
* @see Provider
*/
public static KeyInfoFactory getInstance(String mechanismType) {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
}
Instance instance;
try {
instance = GetInstance.getInstance
("KeyInfoFactory", null, mechanismType);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
KeyInfoFactory factory = (KeyInfoFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
/**
* Returns a <code>KeyInfoFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. Note that the specified
* <code>Provider</code> object does not have to be registered in the
* provider list.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @param provider the <code>Provider</code> object
* @return a new <code>KeyInfoFactory</code>
* @throws NullPointerException if <code>mechanismType</code> or
* <code>provider</code> are <code>null</code>
* @throws NoSuchMechanismException if a <code>KeyInfoFactory</code>
* implementation for the specified mechanism is not available from the
* specified <code>Provider</code> object
* @see Provider
*/
public static KeyInfoFactory getInstance(String mechanismType,
Provider provider) {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
}
Instance instance;
try {
instance = GetInstance.getInstance
("KeyInfoFactory", null, mechanismType, provider);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
KeyInfoFactory factory = (KeyInfoFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
/**
* Returns a <code>KeyInfoFactory</code> that supports the
* requested XML processing mechanism and representation type (ex: "DOM"),
* as supplied by the specified provider. The specified provider must be
* registered in the security provider list.
*
* <p>Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @param mechanismType the type of the XML processing mechanism and
* representation. See the <a
* href="../../../../../../technotes/guides/security/xmldsig/overview.html#Service Provider">
* Service Providers</a> section of the API overview for a list of
* standard mechanism types.
* @param provider the string name of the provider
* @return a new <code>KeyInfoFactory</code>
* @throws NoSuchProviderException if the specified provider is not
* registered in the security provider list
* @throws NullPointerException if <code>mechanismType</code> or
* <code>provider</code> are <code>null</code>
* @throws NoSuchMechanismException if a <code>KeyInfoFactory</code>
* implementation for the specified mechanism is not available from the
* specified provider
* @see Provider
*/
public static KeyInfoFactory getInstance(String mechanismType,
String provider) throws NoSuchProviderException {
if (mechanismType == null) {
throw new NullPointerException("mechanismType cannot be null");
} else if (provider == null) {
throw new NullPointerException("provider cannot be null");
} else if (provider.length() == 0) {
throw new NoSuchProviderException();
}
Instance instance;
try {
instance = GetInstance.getInstance
("KeyInfoFactory", null, mechanismType, provider);
} catch (NoSuchAlgorithmException nsae) {
throw new NoSuchMechanismException(nsae);
}
KeyInfoFactory factory = (KeyInfoFactory) instance.impl;
factory.mechanismType = mechanismType;
factory.provider = instance.provider;
return factory;
}
/**
* Returns a <code>KeyInfoFactory</code> that supports the
* default XML processing mechanism and representation type ("DOM").
*
* <p>This method uses the standard JCA provider lookup mechanism to
* locate and instantiate a <code>KeyInfoFactory</code> implementation of
* the default mechanism type. It traverses the list of registered security
* <code>Provider</code>s, starting with the most preferred
* <code>Provider</code>. A new <code>KeyInfoFactory</code> object
* from the first <code>Provider</code> that supports the DOM mechanism is
* returned.
*
* <p> Note that the list of registered providers may be retrieved via
* the {@link Security#getProviders() Security.getProviders()} method.
*
* @return a new <code>KeyInfoFactory</code>
* @throws NoSuchMechanismException if no <code>Provider</code> supports a
* <code>KeyInfoFactory</code> implementation for the DOM mechanism
* @see Provider
*/
public static KeyInfoFactory getInstance() {
return getInstance("DOM");
}
/**
* Returns the type of the XML processing mechanism and representation
* supported by this <code>KeyInfoFactory</code> (ex: "DOM")
*
* @return the XML processing mechanism type supported by this
* <code>KeyInfoFactory</code>
*/
public final String getMechanismType() {
return mechanismType;
}
/**
* Returns the provider of this <code>KeyInfoFactory</code>.
*
* @return the provider of this <code>KeyInfoFactory</code>
*/
public final Provider getProvider() {
return provider;
}
/**
* Creates a <code>KeyInfo</code> containing the specified list of
* key information types.
*
* @param content a list of one or more {@link XMLStructure}s representing
* key information types. The list is defensively copied to protect
* against subsequent modification.
* @return a <code>KeyInfo</code>
* @throws NullPointerException if <code>content</code> is <code>null</code>
* @throws IllegalArgumentException if <code>content</code> is empty
* @throws ClassCastException if <code>content</code> contains any entries
* that are not of type {@link XMLStructure}
*/
@SuppressWarnings("rawtypes")
public abstract KeyInfo newKeyInfo(List content);
/**
* Creates a <code>KeyInfo</code> containing the specified list of key
* information types and optional id. The
* <code>id</code> parameter represents the value of an XML
* <code>ID</code> attribute and is useful for referencing
* the <code>KeyInfo</code> from other XML structures.
*
* @param content a list of one or more {@link XMLStructure}s representing
* key information types. The list is defensively copied to protect
* against subsequent modification.
* @param id the value of an XML <code>ID</code> (may be <code>null</code>)
* @return a <code>KeyInfo</code>
* @throws NullPointerException if <code>content</code> is <code>null</code>
* @throws IllegalArgumentException if <code>content</code> is empty
* @throws ClassCastException if <code>content</code> contains any entries
* that are not of type {@link XMLStructure}
*/
@SuppressWarnings("rawtypes")
public abstract KeyInfo newKeyInfo(List content, String id);
/**
* Creates a <code>KeyName</code> from the specified name.
*
* @param name the name that identifies the key
* @return a <code>KeyName</code>
* @throws NullPointerException if <code>name</code> is <code>null</code>
*/
public abstract KeyName newKeyName(String name);
/**
* Creates a <code>KeyValue</code> from the specified public key.
*
* @param key the public key
* @return a <code>KeyValue</code>
* @throws KeyException if the <code>key</code>'s algorithm is not
* recognized or supported by this <code>KeyInfoFactory</code>
* @throws NullPointerException if <code>key</code> is <code>null</code>
*/
public abstract KeyValue newKeyValue(PublicKey key) throws KeyException;
/**
* Creates a <code>PGPData</code> from the specified PGP public key
* identifier.
*
* @param keyId a PGP public key identifier as defined in <a href=
* "http://www.ietf.org/rfc/rfc2440.txt">RFC 2440</a>, section 11.2.
* The array is cloned to protect against subsequent modification.
* @return a <code>PGPData</code>
* @throws NullPointerException if <code>keyId</code> is <code>null</code>
* @throws IllegalArgumentException if the key id is not in the correct
* format
*/
public abstract PGPData newPGPData(byte[] keyId);
/**
* Creates a <code>PGPData</code> from the specified PGP public key
* identifier, and optional key material packet and list of external
* elements.
*
* @param keyId a PGP public key identifier as defined in <a href=
* "http://www.ietf.org/rfc/rfc2440.txt">RFC 2440</a>, section 11.2.
* The array is cloned to protect against subsequent modification.
* @param keyPacket a PGP key material packet as defined in <a href=
* "http://www.ietf.org/rfc/rfc2440.txt">RFC 2440</a>, section 5.5.
* The array is cloned to protect against subsequent modification. May
* be <code>null</code>.
* @param other a list of {@link XMLStructure}s representing elements from
* an external namespace. The list is defensively copied to protect
* against subsequent modification. May be <code>null</code> or empty.
* @return a <code>PGPData</code>
* @throws NullPointerException if <code>keyId</code> is <code>null</code>
* @throws IllegalArgumentException if the <code>keyId</code> or
* <code>keyPacket</code> is not in the correct format. For
* <code>keyPacket</code>, the format of the packet header is
* checked and the tag is verified that it is of type key material. The
* contents and format of the packet body are not checked.
* @throws ClassCastException if <code>other</code> contains any
* entries that are not of type {@link XMLStructure}
*/
@SuppressWarnings("rawtypes")
public abstract PGPData newPGPData(byte[] keyId, byte[] keyPacket,
List other);
/**
* Creates a <code>PGPData</code> from the specified PGP key material
* packet and optional list of external elements.
*
* @param keyPacket a PGP key material packet as defined in <a href=
* "http://www.ietf.org/rfc/rfc2440.txt">RFC 2440</a>, section 5.5.
* The array is cloned to protect against subsequent modification.
* @param other a list of {@link XMLStructure}s representing elements from
* an external namespace. The list is defensively copied to protect
* against subsequent modification. May be <code>null</code> or empty.
* @return a <code>PGPData</code>
* @throws NullPointerException if <code>keyPacket</code> is
* <code>null</code>
* @throws IllegalArgumentException if <code>keyPacket</code> is not in the
* correct format. For <code>keyPacket</code>, the format of the packet
* header is checked and the tag is verified that it is of type key
* material. The contents and format of the packet body are not checked.
* @throws ClassCastException if <code>other</code> contains any
* entries that are not of type {@link XMLStructure}
*/
@SuppressWarnings("rawtypes")
public abstract PGPData newPGPData(byte[] keyPacket, List other);
/**
* Creates a <code>RetrievalMethod</code> from the specified URI.
*
* @param uri the URI that identifies the <code>KeyInfo</code> information
* to be retrieved
* @return a <code>RetrievalMethod</code>
* @throws NullPointerException if <code>uri</code> is <code>null</code>
* @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
* compliant
*/
public abstract RetrievalMethod newRetrievalMethod(String uri);
/**
* Creates a <code>RetrievalMethod</code> from the specified parameters.
*
* @param uri the URI that identifies the <code>KeyInfo</code> information
* to be retrieved
* @param type a URI that identifies the type of <code>KeyInfo</code>
* information to be retrieved (may be <code>null</code>)
* @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.
* @return a <code>RetrievalMethod</code>
* @throws NullPointerException if <code>uri</code> is <code>null</code>
* @throws IllegalArgumentException if <code>uri</code> is not RFC 2396
* compliant
* @throws ClassCastException if <code>transforms</code> contains any
* entries that are not of type {@link Transform}
*/
@SuppressWarnings("rawtypes")
public abstract RetrievalMethod newRetrievalMethod(String uri, String type,
List transforms);
/**
* Creates a <code>X509Data</code> containing the specified list of
* X.509 content.
*
* @param content a list of one or more X.509 content types. Valid types are
* {@link String} (subject names), <code>byte[]</code> (subject key ids),
* {@link java.security.cert.X509Certificate}, {@link X509CRL},
* or {@link XMLStructure} ({@link X509IssuerSerial}
* objects or elements from an external namespace). Subject names are
* distinguished names in RFC 2253 String format. Implementations MUST
* support the attribute type keywords defined in RFC 2253 (CN, L, ST,
* O, OU, C, STREET, DC and UID). Implementations MAY support additional
* keywords. The list is defensively copied to protect against
* subsequent modification.
* @return a <code>X509Data</code>
* @throws NullPointerException if <code>content</code> is <code>null</code>
* @throws IllegalArgumentException if <code>content</code> is empty, or
* if a subject name is not RFC 2253 compliant or one of the attribute
* type keywords is not recognized.
* @throws ClassCastException if <code>content</code> contains any entries
* that are not of one of the valid types mentioned above
*/
@SuppressWarnings("rawtypes")
public abstract X509Data newX509Data(List content);
/**
* Creates an <code>X509IssuerSerial</code> from the specified X.500 issuer
* distinguished name and serial number.
*
* @param issuerName the issuer's distinguished name in RFC 2253 String
* format. Implementations MUST support the attribute type keywords
* defined in RFC 2253 (CN, L, ST, O, OU, C, STREET, DC and UID).
* Implementations MAY support additional keywords.
* @param serialNumber the serial number
* @return an <code>X509IssuerSerial</code>
* @throws NullPointerException if <code>issuerName</code> or
* <code>serialNumber</code> are <code>null</code>
* @throws IllegalArgumentException if the issuer name is not RFC 2253
* compliant or one of the attribute type keywords is not recognized.
*/
public abstract X509IssuerSerial newX509IssuerSerial
(String issuerName, BigInteger serialNumber);
/**
* Indicates whether a specified feature is supported.
*
* @param feature the feature name (as an absolute URI)
* @return <code>true</code> if the specified feature is supported,
* <code>false</code> otherwise
* @throws NullPointerException if <code>feature</code> is <code>null</code>
*/
public abstract boolean isFeatureSupported(String feature);
/**
* Returns a reference to the <code>URIDereferencer</code> that is used by
* default to dereference URIs in {@link RetrievalMethod} objects.
*
* @return a reference to the default <code>URIDereferencer</code>
*/
public abstract URIDereferencer getURIDereferencer();
/**
* Unmarshals a new <code>KeyInfo</code> instance from a
* mechanism-specific <code>XMLStructure</code> (ex: {@link DOMStructure})
* instance.
*
* @param xmlStructure a mechanism-specific XML structure from which to
* unmarshal the keyinfo from
* @return the <code>KeyInfo</code>
* @throws NullPointerException if <code>xmlStructure</code> is
* <code>null</code>
* @throws ClassCastException if the type of <code>xmlStructure</code> is
* inappropriate for this factory
* @throws MarshalException if an unrecoverable exception occurs during
* unmarshalling
*/
public abstract KeyInfo unmarshalKeyInfo(XMLStructure xmlStructure)
throws MarshalException;
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: KeyName.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import javax.xml.crypto.XMLStructure;
/**
* A representation of the XML <code>KeyName</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* A <code>KeyName</code> object contains a string value which may be used
* by the signer to communicate a key identifier to the recipient. The
* XML Schema Definition is defined as:
*
* <pre>
* &lt;element name="KeyName" type="string"/&gt;
* </pre>
*
* A <code>KeyName</code> instance may be created by invoking the
* {@link KeyInfoFactory#newKeyName newKeyName} method of the
* {@link KeyInfoFactory} class, and passing it a <code>String</code>
* representing the name of the key; for example:
* <pre>
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* KeyName keyName = factory.newKeyName("Alice");
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see KeyInfoFactory#newKeyName(String)
*/
public interface KeyName extends XMLStructure {
/**
* Returns the name of this <code>KeyName</code>.
*
* @return the name of this <code>KeyName</code> (never
* <code>null</code>)
*/
String getName();
}

View File

@@ -0,0 +1,134 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: KeyValue.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import java.security.KeyException;
import java.security.KeyStore;
import java.security.PublicKey;
import java.security.interfaces.DSAPublicKey;
import java.security.interfaces.RSAPublicKey;
import javax.xml.crypto.XMLStructure;
/**
* A representation of the XML <code>KeyValue</code> element as defined
* in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>. A
* <code>KeyValue</code> object contains a single public key that may be
* useful in validating the signature. The XML schema definition is defined as:
*
* <pre>
* &lt;element name="KeyValue" type="ds:KeyValueType"/&gt;
* &lt;complexType name="KeyValueType" mixed="true"&gt;
* &lt;choice&gt;
* &lt;element ref="ds:DSAKeyValue"/&gt;
* &lt;element ref="ds:RSAKeyValue"/&gt;
* &lt;any namespace="##other" processContents="lax"/&gt;
* &lt;/choice&gt;
* &lt;/complexType&gt;
*
* &lt;element name="DSAKeyValue" type="ds:DSAKeyValueType"/&gt;
* &lt;complexType name="DSAKeyValueType"&gt;
* &lt;sequence&gt;
* &lt;sequence minOccurs="0"&gt;
* &lt;element name="P" type="ds:CryptoBinary"/&gt;
* &lt;element name="Q" type="ds:CryptoBinary"/&gt;
* &lt;/sequence&gt;
* &lt;element name="G" type="ds:CryptoBinary" minOccurs="0"/&gt;
* &lt;element name="Y" type="ds:CryptoBinary"/&gt;
* &lt;element name="J" type="ds:CryptoBinary" minOccurs="0"/&gt;
* &lt;sequence minOccurs="0"&gt;
* &lt;element name="Seed" type="ds:CryptoBinary"/&gt;
* &lt;element name="PgenCounter" type="ds:CryptoBinary"/&gt;
* &lt;/sequence&gt;
* &lt;/sequence&gt;
* &lt;/complexType&gt;
*
* &lt;element name="RSAKeyValue" type="ds:RSAKeyValueType"/&gt;
* &lt;complexType name="RSAKeyValueType"&gt;
* &lt;sequence&gt;
* &lt;element name="Modulus" type="ds:CryptoBinary"/&gt;
* &lt;element name="Exponent" type="ds:CryptoBinary"/&gt;
* &lt;/sequence&gt;
* &lt;/complexType&gt;
* </pre>
* A <code>KeyValue</code> instance may be created by invoking the
* {@link KeyInfoFactory#newKeyValue newKeyValue} method of the
* {@link KeyInfoFactory} class, and passing it a {@link
* java.security.PublicKey} representing the value of the public key. Here is
* an example of creating a <code>KeyValue</code> from a {@link DSAPublicKey}
* of a {@link java.security.cert.Certificate} stored in a
* {@link java.security.KeyStore}:
* <pre>
* KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
* PublicKey dsaPublicKey = keyStore.getCertificate("myDSASigningCert").getPublicKey();
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* KeyValue keyValue = factory.newKeyValue(dsaPublicKey);
* </pre>
*
* This class returns the <code>DSAKeyValue</code> and
* <code>RSAKeyValue</code> elements as objects of type
* {@link DSAPublicKey} and {@link RSAPublicKey}, respectively. Note that not
* all of the fields in the schema are accessible as parameters of these
* types.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see KeyInfoFactory#newKeyValue(PublicKey)
*/
public interface KeyValue extends XMLStructure {
/**
* URI identifying the DSA KeyValue KeyInfo type:
* http://www.w3.org/2000/09/xmldsig#DSAKeyValue. This can be specified as
* the value of the <code>type</code> parameter of the
* {@link RetrievalMethod} class to describe a remote
* <code>DSAKeyValue</code> structure.
*/
final static String DSA_TYPE =
"http://www.w3.org/2000/09/xmldsig#DSAKeyValue";
/**
* URI identifying the RSA KeyValue KeyInfo type:
* http://www.w3.org/2000/09/xmldsig#RSAKeyValue. This can be specified as
* the value of the <code>type</code> parameter of the
* {@link RetrievalMethod} class to describe a remote
* <code>RSAKeyValue</code> structure.
*/
final static String RSA_TYPE =
"http://www.w3.org/2000/09/xmldsig#RSAKeyValue";
/**
* Returns the public key of this <code>KeyValue</code>.
*
* @return the public key of this <code>KeyValue</code>
* @throws KeyException if this <code>KeyValue</code> cannot be converted
* to a <code>PublicKey</code>
*/
PublicKey getPublicKey() throws KeyException;
}

View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: PGPData.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import java.util.Collections;
import java.util.List;
import javax.xml.crypto.XMLStructure;
/**
* A representation of the XML <code>PGPData</code> element as defined in
* the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>. A
* <code>PGPData</code> object is used to convey information related to
* PGP public key pairs and signatures on such keys. The XML Schema Definition
* is defined as:
*
* <pre>
* &lt;element name="PGPData" type="ds:PGPDataType"/&gt;
* &lt;complexType name="PGPDataType"&gt;
* &lt;choice&gt;
* &lt;sequence&gt;
* &lt;element name="PGPKeyID" type="base64Binary"/&gt;
* &lt;element name="PGPKeyPacket" type="base64Binary" minOccurs="0"/&gt;
* &lt;any namespace="##other" processContents="lax" minOccurs="0"
* maxOccurs="unbounded"/&gt;
* &lt;/sequence&gt;
* &lt;sequence&gt;
* &lt;element name="PGPKeyPacket" type="base64Binary"/&gt;
* &lt;any namespace="##other" processContents="lax" minOccurs="0"
* maxOccurs="unbounded"/&gt;
* &lt;/sequence&gt;
* &lt;/choice&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>PGPData</code> instance may be created by invoking one of the
* {@link KeyInfoFactory#newPGPData newPGPData} methods of the {@link
* KeyInfoFactory} class, and passing it
* <code>byte</code> arrays representing the contents of the PGP public key
* identifier and/or PGP key material packet, and an optional list of
* elements from an external namespace.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see KeyInfoFactory#newPGPData(byte[])
* @see KeyInfoFactory#newPGPData(byte[], byte[], List)
* @see KeyInfoFactory#newPGPData(byte[], List)
*/
public interface PGPData extends XMLStructure {
/**
* URI identifying the PGPData KeyInfo type:
* http://www.w3.org/2000/09/xmldsig#PGPData. This can be specified as the
* value of the <code>type</code> parameter of the {@link RetrievalMethod}
* class to describe a remote <code>PGPData</code> structure.
*/
final static String TYPE = "http://www.w3.org/2000/09/xmldsig#PGPData";
/**
* Returns the PGP public key identifier of this <code>PGPData</code> as
* defined in <a href="http://www.ietf.org/rfc/rfc2440.txt">RFC 2440</a>,
* section 11.2.
*
* @return the PGP public key identifier (may be <code>null</code> if
* not specified). Each invocation of this method returns a new clone
* to protect against subsequent modification.
*/
byte[] getKeyId();
/**
* Returns the PGP key material packet of this <code>PGPData</code> as
* defined in <a href="http://www.ietf.org/rfc/rfc2440.txt">RFC 2440</a>,
* section 5.5.
*
* @return the PGP key material packet (may be <code>null</code> if not
* specified). Each invocation of this method returns a new clone to
* protect against subsequent modification.
*/
byte[] getKeyPacket();
/**
* Returns an {@link Collections#unmodifiableList unmodifiable list}
* of {@link XMLStructure}s representing elements from an external
* namespace.
*
* @return an unmodifiable list of <code>XMLStructure</code>s (may be
* empty, but never <code>null</code>)
*/
@SuppressWarnings("rawtypes")
List getExternalElements();
}

View File

@@ -0,0 +1,113 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: RetrievalMethod.java,v 1.8 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import javax.xml.crypto.Data;
import javax.xml.crypto.URIReference;
import javax.xml.crypto.URIReferenceException;
import javax.xml.crypto.XMLCryptoContext;
import javax.xml.crypto.XMLStructure;
import javax.xml.crypto.dsig.Transform;
import java.util.List;
/**
* A representation of the XML <code>RetrievalMethod</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* A <code>RetrievalMethod</code> object is used to convey a reference to
* <code>KeyInfo</code> information that is stored at another location.
* The XML schema definition is defined as:
*
* <pre>
* &lt;element name="RetrievalMethod" type="ds:RetrievalMethodType"/&gt;
* &lt;complexType name="RetrievalMethodType"&gt;
* &lt;sequence&gt;
* &lt;element name="Transforms" type="ds:TransformsType" minOccurs="0"/&gt;
* &lt;/sequence&gt;
* &lt;attribute name="URI" type="anyURI"/&gt;
* &lt;attribute name="Type" type="anyURI" use="optional"/&gt;
* &lt;/complexType&gt;
* </pre>
*
* A <code>RetrievalMethod</code> instance may be created by invoking one of the
* {@link KeyInfoFactory#newRetrievalMethod newRetrievalMethod} methods
* of the {@link KeyInfoFactory} class, and passing it the URI
* identifying the location of the KeyInfo, an optional type URI identifying
* the type of KeyInfo, and an optional list of {@link Transform}s; for example:
* <pre>
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* RetrievalMethod rm = factory.newRetrievalMethod
* ("#KeyValue-1", KeyValue.DSA_TYPE, Collections.singletonList(Transform.BASE64));
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see KeyInfoFactory#newRetrievalMethod(String)
* @see KeyInfoFactory#newRetrievalMethod(String, String, List)
*/
public interface RetrievalMethod extends URIReference, XMLStructure {
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of {@link Transform}s of this <code>RetrievalMethod</code>.
*
* @return an unmodifiable list of <code>Transform</code> objects (may be
* empty but never <code>null</code>).
*/
@SuppressWarnings("rawtypes")
List getTransforms();
/**
* Returns the URI of the referenced <code>KeyInfo</code> information.
*
* @return the URI of the referenced <code>KeyInfo</code> information in
* RFC 2396 format (never <code>null</code>)
*/
String getURI();
/**
* Dereferences the <code>KeyInfo</code> information referenced by this
* <code>RetrievalMethod</code> and applies the specified
* <code>Transform</code>s.
*
* @param context an <code>XMLCryptoContext</code> that may contain
* additional useful information for dereferencing the URI. The
* context's <code>baseURI</code> and <code>dereferencer</code>
* parameters (if specified) are used to resolve and dereference this
* <code>RetrievalMethod</code>
* @return a <code>Data</code> object representing the raw contents of the
* <code>KeyInfo</code> information referenced by this
* <code>RetrievalMethod</code>. It is the caller's responsibility to
* convert the returned data to an appropriate
* <code>KeyInfo</code> object.
* @throws NullPointerException if <code>context</code> is <code>null</code>
* @throws URIReferenceException if there is an error while dereferencing
*/
Data dereference(XMLCryptoContext context) throws URIReferenceException;
}

View File

@@ -0,0 +1,114 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: X509Data.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import javax.xml.crypto.XMLStructure;
import java.security.cert.X509CRL;
import java.util.List;
/**
* A representation of the XML <code>X509Data</code> element as defined in
* the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>. An
* <code>X509Data</code> object contains one or more identifers of keys
* or X.509 certificates (or certificates' identifiers or a revocation list).
* The XML Schema Definition is defined as:
*
* <pre>
* &lt;element name="X509Data" type="ds:X509DataType"/&gt;
* &lt;complexType name="X509DataType"&gt;
* &lt;sequence maxOccurs="unbounded"&gt;
* &lt;choice&gt;
* &lt;element name="X509IssuerSerial" type="ds:X509IssuerSerialType"/&gt;
* &lt;element name="X509SKI" type="base64Binary"/&gt;
* &lt;element name="X509SubjectName" type="string"/&gt;
* &lt;element name="X509Certificate" type="base64Binary"/&gt;
* &lt;element name="X509CRL" type="base64Binary"/&gt;
* &lt;any namespace="##other" processContents="lax"/&gt;
* &lt;/choice&gt;
* &lt;/sequence&gt;
* &lt;/complexType&gt;
*
* &lt;complexType name="X509IssuerSerialType"&gt;
* &lt;sequence&gt;
* &lt;element name="X509IssuerName" type="string"/&gt;
* &lt;element name="X509SerialNumber" type="integer"/&gt;
* &lt;/sequence&gt;
* &lt;/complexType&gt;
* </pre>
*
* An <code>X509Data</code> instance may be created by invoking the
* {@link KeyInfoFactory#newX509Data newX509Data} methods of the
* {@link KeyInfoFactory} class and passing it a list of one or more
* {@link XMLStructure}s representing X.509 content; for example:
* <pre>
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* X509Data x509Data = factory.newX509Data
* (Collections.singletonList("cn=Alice"));
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see KeyInfoFactory#newX509Data(List)
*/
//@@@ check for illegal combinations of data violating MUSTs in W3c spec
public interface X509Data extends XMLStructure {
/**
* URI identifying the X509Data KeyInfo type:
* http://www.w3.org/2000/09/xmldsig#X509Data. This can be specified as
* the value of the <code>type</code> parameter of the
* {@link RetrievalMethod} class to describe a remote
* <code>X509Data</code> structure.
*/
final static String TYPE = "http://www.w3.org/2000/09/xmldsig#X509Data";
/**
* URI identifying the binary (ASN.1 DER) X.509 Certificate KeyInfo type:
* http://www.w3.org/2000/09/xmldsig#rawX509Certificate. This can be
* specified as the value of the <code>type</code> parameter of the
* {@link RetrievalMethod} class to describe a remote X509 Certificate.
*/
final static String RAW_X509_CERTIFICATE_TYPE =
"http://www.w3.org/2000/09/xmldsig#rawX509Certificate";
/**
* Returns an {@link java.util.Collections#unmodifiableList unmodifiable
* list} of the content in this <code>X509Data</code>. Valid types are
* {@link String} (subject names), <code>byte[]</code> (subject key ids),
* {@link java.security.cert.X509Certificate}, {@link X509CRL},
* or {@link XMLStructure} ({@link X509IssuerSerial}
* objects or elements from an external namespace).
*
* @return an unmodifiable list of the content in this <code>X509Data</code>
* (never <code>null</code> or empty)
*/
@SuppressWarnings("rawtypes")
List getContent();
}

View File

@@ -0,0 +1,89 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: X509IssuerSerial.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
*/
package javax.xml.crypto.dsig.keyinfo;
import java.math.BigInteger;
import java.security.cert.X509Certificate;
import javax.xml.crypto.XMLStructure;
/**
* A representation of the XML <code>X509IssuerSerial</code> element as
* defined in the <a href="http://www.w3.org/TR/xmldsig-core/">
* W3C Recommendation for XML-Signature Syntax and Processing</a>.
* An <code>X509IssuerSerial</code> object contains an X.509 issuer
* distinguished name (DN) and serial number pair. The XML schema definition is
* defined as:
*
* <pre>
* &lt;element name="X509IssuerSerial" type="ds:X509IssuerSerialType"/&gt;
* &lt;complexType name="X509IssuerSerialType"&gt;
* &lt;sequence&gt;
* &lt;element name="X509IssuerName" type="string"/&gt;
* &lt;element name="X509SerialNumber" type="integer"/&gt;
* &lt;/sequence&gt;
* &lt;/complexType&gt;
* </pre>
*
* An <code>X509IssuerSerial</code> instance may be created by invoking the
* {@link KeyInfoFactory#newX509IssuerSerial newX509IssuerSerial} method
* of the {@link KeyInfoFactory} class, and passing it a
* <code>String</code> and <code>BigInteger</code> representing the X.500
* DN and serial number. Here is an example of creating an
* <code>X509IssuerSerial</code> from the issuer DN and serial number of an
* existing {@link X509Certificate}:
* <pre>
* KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
* X509IssuerSerial issuer = factory.newX509IssuerSerial
* (cert.getIssuerX500Principal().getName(), cert.getSerialNumber());
* </pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see X509Data#getContent
* @see KeyInfoFactory#newX509IssuerSerial(String, BigInteger)
*/
public interface X509IssuerSerial extends XMLStructure {
/**
* Returns the X.500 distinguished name of this
* <code>X509IssuerSerial</code> in
* <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a> String format.
*
* @return the X.500 distinguished name in RFC 2253 String format (never
* <code>null</code>)
*/
String getIssuerName();
/**
* Returns the serial number of this <code>X509IssuerSerial</code>.
*
* @return the serial number (never <code>null</code>)
*/
BigInteger getSerialNumber();
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: C14NMethodParameterSpec.java,v 1.3 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.CanonicalizationMethod;
/**
* A specification of algorithm parameters for a {@link CanonicalizationMethod}
* Algorithm. The purpose of this interface is to group (and provide type
* safety for) all canonicalization (C14N) parameter specifications. All
* canonicalization parameter specifications must implement this interface.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see CanonicalizationMethod
*/
public interface C14NMethodParameterSpec extends TransformParameterSpec {}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: DigestMethodParameterSpec.java,v 1.3 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.DigestMethod;
import java.security.spec.AlgorithmParameterSpec;
/**
* A specification of algorithm parameters for a {@link DigestMethod}
* algorithm. The purpose of this interface is to group (and provide type
* safety for) all digest method parameter specifications. All digest method
* parameter specifications must implement this interface.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see DigestMethod
*/
public interface DigestMethodParameterSpec extends AlgorithmParameterSpec {}

View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: ExcC14NParameterSpec.java,v 1.7 2005/05/13 18:45:42 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.CanonicalizationMethod;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Parameters for the W3C Recommendation:
* <a href="http://www.w3.org/TR/xml-exc-c14n/">
* Exclusive XML Canonicalization (C14N) algorithm</a>. The
* parameters include an optional inclusive namespace prefix list. The XML
* Schema Definition of the Exclusive XML Canonicalization parameters is
* defined as:
* <pre><code>
* &lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
* xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#"
* targetNamespace="http://www.w3.org/2001/10/xml-exc-c14n#"
* version="0.1" elementFormDefault="qualified"&gt;
*
* &lt;element name="InclusiveNamespaces" type="ec:InclusiveNamespaces"/&gt;
* &lt;complexType name="InclusiveNamespaces"&gt;
* &lt;attribute name="PrefixList" type="xsd:string"/&gt;
* &lt;/complexType&gt;
* &lt;/schema&gt;
* </code></pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see CanonicalizationMethod
*/
public final class ExcC14NParameterSpec implements C14NMethodParameterSpec {
private List<String> preList;
/**
* Indicates the default namespace ("#default").
*/
public static final String DEFAULT = "#default";
/**
* Creates a <code>ExcC14NParameterSpec</code> with an empty prefix
* list.
*/
public ExcC14NParameterSpec() {
preList = Collections.emptyList();
}
/**
* Creates a <code>ExcC14NParameterSpec</code> with the specified list
* of prefixes. The list is copied to protect against subsequent
* modification.
*
* @param prefixList the inclusive namespace prefix list. Each entry in
* the list is a <code>String</code> that represents a namespace prefix.
* @throws NullPointerException if <code>prefixList</code> is
* <code>null</code>
* @throws ClassCastException if any of the entries in the list are not
* of type <code>String</code>
*/
@SuppressWarnings("rawtypes")
public ExcC14NParameterSpec(List prefixList) {
if (prefixList == null) {
throw new NullPointerException("prefixList cannot be null");
}
List<?> copy = new ArrayList<>((List<?>)prefixList);
for (int i = 0, size = copy.size(); i < size; i++) {
if (!(copy.get(i) instanceof String)) {
throw new ClassCastException("not a String");
}
}
@SuppressWarnings("unchecked")
List<String> temp = (List<String>)copy;
preList = Collections.unmodifiableList(temp);
}
/**
* Returns the inclusive namespace prefix list. Each entry in the list
* is a <code>String</code> that represents a namespace prefix.
*
* <p>This implementation returns an {@link
* java.util.Collections#unmodifiableList unmodifiable list}.
*
* @return the inclusive namespace prefix list (may be empty but never
* <code>null</code>)
*/
@SuppressWarnings("rawtypes")
public List getPrefixList() {
return preList;
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: HMACParameterSpec.java,v 1.4 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.SignatureMethod;
/**
* Parameters for the <a href="http://www.w3.org/TR/xmldsig-core/#sec-MACs">
* XML Signature HMAC Algorithm</a>. The parameters include an optional output
* length which specifies the MAC truncation length in bits. The resulting
* HMAC will be truncated to the specified number of bits. If the parameter is
* not specified, then this implies that all the bits of the hash are to be
* output. The XML Schema Definition of the <code>HMACOutputLength</code>
* element is defined as:
* <pre><code>
* &lt;element name="HMACOutputLength" minOccurs="0" type="ds:HMACOutputLengthType"/&gt;
* &lt;simpleType name="HMACOutputLengthType"&gt;
* &lt;restriction base="integer"/&gt;
* &lt;/simpleType&gt;
* </code></pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see SignatureMethod
* @see <a href="http://www.ietf.org/rfc/rfc2104.txt">RFC 2104</a>
*/
public final class HMACParameterSpec implements SignatureMethodParameterSpec {
private int outputLength;
/**
* Creates an <code>HMACParameterSpec</code> with the specified truncation
* length.
*
* @param outputLength the truncation length in number of bits
*/
public HMACParameterSpec(int outputLength) {
this.outputLength = outputLength;
}
/**
* Returns the truncation length.
*
* @return the truncation length in number of bits
*/
public int getOutputLength() {
return outputLength;
}
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: SignatureMethodParameterSpec.java,v 1.3 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.SignatureMethod;
import java.security.spec.AlgorithmParameterSpec;
/**
* A specification of algorithm parameters for an XML {@link SignatureMethod}
* algorithm. The purpose of this interface is to group (and provide type
* safety for) all signature method parameter specifications. All signature
* method parameter specifications must implement this interface.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see SignatureMethod
*/
public interface SignatureMethodParameterSpec extends AlgorithmParameterSpec {}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: TransformParameterSpec.java,v 1.3 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.Transform;
import java.security.spec.AlgorithmParameterSpec;
/**
* A specification of algorithm parameters for a {@link Transform}
* algorithm. The purpose of this interface is to group (and provide type
* safety for) all transform parameter specifications. All transform parameter
* specifications must implement this interface.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see Transform
*/
public interface TransformParameterSpec extends AlgorithmParameterSpec {}

View File

@@ -0,0 +1,98 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XPathFilter2ParameterSpec.java,v 1.7 2005/05/13 18:45:42 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javax.xml.crypto.dsig.Transform;
/**
* Parameters for the W3C Recommendation
* <a href="http://www.w3.org/TR/xmldsig-filter2/">
* XPath Filter 2.0 Transform Algorithm</a>.
* The parameters include a list of one or more {@link XPathType} objects.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see Transform
* @see XPathFilterParameterSpec
*/
public final class XPathFilter2ParameterSpec implements TransformParameterSpec {
private final List<XPathType> xPathList;
/**
* Creates an <code>XPathFilter2ParameterSpec</code>.
*
* @param xPathList a list of one or more {@link XPathType} objects. The
* list is defensively copied to protect against subsequent modification.
* @throws ClassCastException if <code>xPathList</code> contains any
* entries that are not of type {@link XPathType}
* @throws IllegalArgumentException if <code>xPathList</code> is empty
* @throws NullPointerException if <code>xPathList</code> is
* <code>null</code>
*/
@SuppressWarnings("rawtypes")
public XPathFilter2ParameterSpec(List xPathList) {
if (xPathList == null) {
throw new NullPointerException("xPathList cannot be null");
}
List<?> xPathListCopy = new ArrayList<>((List<?>)xPathList);
if (xPathListCopy.isEmpty()) {
throw new IllegalArgumentException("xPathList cannot be empty");
}
int size = xPathListCopy.size();
for (int i = 0; i < size; i++) {
if (!(xPathListCopy.get(i) instanceof XPathType)) {
throw new ClassCastException
("xPathList["+i+"] is not a valid type");
}
}
@SuppressWarnings("unchecked")
List<XPathType> temp = (List<XPathType>)xPathListCopy;
this.xPathList = Collections.unmodifiableList(temp);
}
/**
* Returns a list of one or more {@link XPathType} objects.
* <p>
* This implementation returns an {@link Collections#unmodifiableList
* unmodifiable list}.
*
* @return a <code>List</code> of <code>XPathType</code> objects
* (never <code>null</code> or empty)
*/
@SuppressWarnings("rawtypes")
public List getXPathList() {
return xPathList;
}
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XPathFilterParameterSpec.java,v 1.4 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.Transform;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
/**
* Parameters for the <a href="http://www.w3.org/TR/xmldsig-core/#sec-XPath">
* XPath Filtering Transform Algorithm</a>.
* The parameters include the XPath expression and an optional <code>Map</code>
* of additional namespace prefix mappings. The XML Schema Definition of
* the XPath Filtering transform parameters is defined as:
* <pre><code>
* &lt;element name="XPath" type="string"/&gt;
* </code></pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see Transform
*/
public final class XPathFilterParameterSpec implements TransformParameterSpec {
private String xPath;
private Map<String,String> nsMap;
/**
* Creates an <code>XPathFilterParameterSpec</code> with the specified
* XPath expression.
*
* @param xPath the XPath expression to be evaluated
* @throws NullPointerException if <code>xPath</code> is <code>null</code>
*/
public XPathFilterParameterSpec(String xPath) {
if (xPath == null) {
throw new NullPointerException();
}
this.xPath = xPath;
this.nsMap = Collections.emptyMap();
}
/**
* Creates an <code>XPathFilterParameterSpec</code> with the specified
* XPath expression and namespace map. The map is copied to protect against
* subsequent modification.
*
* @param xPath the XPath expression to be evaluated
* @param namespaceMap the map of namespace prefixes. Each key is a
* namespace prefix <code>String</code> that maps to a corresponding
* namespace URI <code>String</code>.
* @throws NullPointerException if <code>xPath</code> or
* <code>namespaceMap</code> are <code>null</code>
* @throws ClassCastException if any of the map's keys or entries are not
* of type <code>String</code>
*/
@SuppressWarnings("rawtypes")
public XPathFilterParameterSpec(String xPath, Map namespaceMap) {
if (xPath == null || namespaceMap == null) {
throw new NullPointerException();
}
this.xPath = xPath;
Map<?,?> copy = new HashMap<>((Map<?,?>)namespaceMap);
Iterator<? extends Map.Entry<?,?>> entries = copy.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<?,?> me = entries.next();
if (!(me.getKey() instanceof String) ||
!(me.getValue() instanceof String)) {
throw new ClassCastException("not a String");
}
}
@SuppressWarnings("unchecked")
Map<String,String> temp = (Map<String,String>)copy;
nsMap = Collections.unmodifiableMap(temp);
}
/**
* Returns the XPath expression to be evaluated.
*
* @return the XPath expression to be evaluated
*/
public String getXPath() {
return xPath;
}
/**
* Returns a map of namespace prefixes. Each key is a namespace prefix
* <code>String</code> that maps to a corresponding namespace URI
* <code>String</code>.
* <p>
* This implementation returns an {@link Collections#unmodifiableMap
* unmodifiable map}.
*
* @return a <code>Map</code> of namespace prefixes to namespace URIs (may
* be empty, but never <code>null</code>)
*/
@SuppressWarnings("rawtypes")
public Map getNamespaceMap() {
return nsMap;
}
}

View File

@@ -0,0 +1,205 @@
/*
* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XPathType.java,v 1.4 2005/05/10 16:40:17 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import java.util.Collections;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
/**
* The XML Schema Definition of the <code>XPath</code> element as defined in the
* <a href="http://www.w3.org/TR/xmldsig-filter2">
* W3C Recommendation for XML-Signature XPath Filter 2.0</a>:
* <pre><code>
* &lt;schema xmlns="http://www.w3.org/2001/XMLSchema"
* xmlns:xf="http://www.w3.org/2002/06/xmldsig-filter2"
* targetNamespace="http://www.w3.org/2002/06/xmldsig-filter2"
* version="0.1" elementFormDefault="qualified"&gt;
*
* &lt;element name="XPath"
* type="xf:XPathType"/&gt;
*
* &lt;complexType name="XPathType"&gt;
* &lt;simpleContent&gt;
* &lt;extension base="string"&gt;
* &lt;attribute name="Filter"&gt;
* &lt;simpleType&gt;
* &lt;restriction base="string"&gt;
* &lt;enumeration value="intersect"/&gt;
* &lt;enumeration value="subtract"/&gt;
* &lt;enumeration value="union"/&gt;
* &lt;/restriction&gt;
* &lt;/simpleType&gt;
* &lt;/attribute&gt;
* &lt;/extension&gt;
* &lt;/simpleContent&gt;
* &lt;/complexType&gt;
* </code></pre>
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see XPathFilter2ParameterSpec
*/
public class XPathType {
/**
* Represents the filter set operation.
*/
public static class Filter {
private final String operation;
private Filter(String operation) {
this.operation = operation;
}
/**
* Returns the string form of the operation.
*
* @return the string form of the operation
*/
public String toString() {
return operation;
}
/**
* The intersect filter operation.
*/
public static final Filter INTERSECT = new Filter("intersect");
/**
* The subtract filter operation.
*/
public static final Filter SUBTRACT = new Filter("subtract");
/**
* The union filter operation.
*/
public static final Filter UNION = new Filter("union");
}
private final String expression;
private final Filter filter;
private Map<String,String> nsMap;
/**
* Creates an <code>XPathType</code> instance with the specified XPath
* expression and filter.
*
* @param expression the XPath expression to be evaluated
* @param filter the filter operation ({@link Filter#INTERSECT},
* {@link Filter#SUBTRACT}, or {@link Filter#UNION})
* @throws NullPointerException if <code>expression</code> or
* <code>filter</code> is <code>null</code>
*/
public XPathType(String expression, Filter filter) {
if (expression == null) {
throw new NullPointerException("expression cannot be null");
}
if (filter == null) {
throw new NullPointerException("filter cannot be null");
}
this.expression = expression;
this.filter = filter;
this.nsMap = Collections.emptyMap();
}
/**
* Creates an <code>XPathType</code> instance with the specified XPath
* expression, filter, and namespace map. The map is copied to protect
* against subsequent modification.
*
* @param expression the XPath expression to be evaluated
* @param filter the filter operation ({@link Filter#INTERSECT},
* {@link Filter#SUBTRACT}, or {@link Filter#UNION})
* @param namespaceMap the map of namespace prefixes. Each key is a
* namespace prefix <code>String</code> that maps to a corresponding
* namespace URI <code>String</code>.
* @throws NullPointerException if <code>expression</code>,
* <code>filter</code> or <code>namespaceMap</code> are
* <code>null</code>
* @throws ClassCastException if any of the map's keys or entries are
* not of type <code>String</code>
*/
@SuppressWarnings("rawtypes")
public XPathType(String expression, Filter filter, Map namespaceMap) {
this(expression, filter);
if (namespaceMap == null) {
throw new NullPointerException("namespaceMap cannot be null");
}
Map<?,?> copy = new HashMap<>((Map<?,?>)namespaceMap);
Iterator<? extends Map.Entry<?,?>> entries = copy.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<?,?> me = entries.next();
if (!(me.getKey() instanceof String) ||
!(me.getValue() instanceof String)) {
throw new ClassCastException("not a String");
}
}
@SuppressWarnings("unchecked")
Map<String,String> temp = (Map<String,String>)copy;
nsMap = Collections.unmodifiableMap(temp);
}
/**
* Returns the XPath expression to be evaluated.
*
* @return the XPath expression to be evaluated
*/
public String getExpression() {
return expression;
}
/**
* Returns the filter operation.
*
* @return the filter operation
*/
public Filter getFilter() {
return filter;
}
/**
* Returns a map of namespace prefixes. Each key is a namespace prefix
* <code>String</code> that maps to a corresponding namespace URI
* <code>String</code>.
* <p>
* This implementation returns an {@link Collections#unmodifiableMap
* unmodifiable map}.
*
* @return a <code>Map</code> of namespace prefixes to namespace URIs
* (may be empty, but never <code>null</code>)
*/
@SuppressWarnings("rawtypes")
public Map getNamespaceMap() {
return nsMap;
}
}

View File

@@ -0,0 +1,78 @@
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* $Id: XSLTTransformParameterSpec.java,v 1.4 2005/05/10 16:40:18 mullan Exp $
*/
package javax.xml.crypto.dsig.spec;
import javax.xml.crypto.dsig.Transform;
import javax.xml.crypto.XMLStructure;
/**
* Parameters for the <a href="http://www.w3.org/TR/1999/REC-xslt-19991116">
* XSLT Transform Algorithm</a>.
* The parameters include a namespace-qualified stylesheet element.
*
* <p>An <code>XSLTTransformParameterSpec</code> is instantiated with a
* mechanism-dependent (ex: DOM) stylesheet element. For example:
* <pre>
* DOMStructure stylesheet = new DOMStructure(element)
* XSLTTransformParameterSpec spec = new XSLTransformParameterSpec(stylesheet);
* </pre>
* where <code>element</code> is an {@link org.w3c.dom.Element} containing
* the namespace-qualified stylesheet element.
*
* @author Sean Mullan
* @author JSR 105 Expert Group
* @since 1.6
* @see Transform
*/
public final class XSLTTransformParameterSpec implements TransformParameterSpec{
private XMLStructure stylesheet;
/**
* Creates an <code>XSLTTransformParameterSpec</code> with the specified
* stylesheet.
*
* @param stylesheet the XSLT stylesheet to be used
* @throws NullPointerException if <code>stylesheet</code> is
* <code>null</code>
*/
public XSLTTransformParameterSpec(XMLStructure stylesheet) {
if (stylesheet == null) {
throw new NullPointerException();
}
this.stylesheet = stylesheet;
}
/**
* Returns the stylesheet.
*
* @return the stylesheet
*/
public XMLStructure getStylesheet() {
return stylesheet;
}
}