KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > xml > crypto > dsig > XMLSignature


1 /*
2  * Portions copyright 2006 Sun Microsystems, Inc. All rights reserved.
3  */

4 /*
5  * ===========================================================================
6  *
7  * (C) Copyright IBM Corp. 2003 All Rights Reserved.
8  *
9  * ===========================================================================
10  */

11 /*
12  * $Id: XMLSignature.java,v 1.10 2005/05/10 16:03:48 mullan Exp $
13  */

14 package javax.xml.crypto.dsig;
15
16 import javax.xml.crypto.KeySelector;
17 import javax.xml.crypto.KeySelectorResult;
18 import javax.xml.crypto.MarshalException;
19 import javax.xml.crypto.XMLStructure;
20 import javax.xml.crypto.dsig.keyinfo.KeyInfo;
21 import java.security.Signature JavaDoc;
22 import java.util.List JavaDoc;
23
24 /**
25  * A representation of the XML <code>Signature</code> element as
26  * defined in the <a HREF="http://www.w3.org/TR/xmldsig-core/">
27  * W3C Recommendation for XML-Signature Syntax and Processing</a>.
28  * This class contains methods for signing and validating XML signatures
29  * with behavior as defined by the W3C specification. The XML Schema Definition
30  * is defined as:
31  * <pre><code>
32  * &lt;element name="Signature" type="ds:SignatureType"/&gt;
33  * &lt;complexType name="SignatureType"&gt;
34  * &lt;sequence&gt;
35  * &lt;element ref="ds:SignedInfo"/&gt;
36  * &lt;element ref="ds:SignatureValue"/&gt;
37  * &lt;element ref="ds:KeyInfo" minOccurs="0"/&gt;
38  * &lt;element ref="ds:Object" minOccurs="0" maxOccurs="unbounded"/&gt;
39  * &lt;/sequence&gt;
40  * &lt;attribute name="Id" type="ID" use="optional"/&gt;
41  * &lt;/complexType&gt;
42  * </code></pre>
43  * <p>
44  * An <code>XMLSignature</code> instance may be created by invoking one of the
45  * {@link XMLSignatureFactory#newXMLSignature newXMLSignature} methods of the
46  * {@link XMLSignatureFactory} class.
47  *
48  * <p>If the contents of the underlying document containing the
49  * <code>XMLSignature</code> are subsequently modified, the behavior is
50  * undefined.
51  *
52  * <p>Note that this class is named <code>XMLSignature</code> rather than
53  * <code>Signature</code> to avoid naming clashes with the existing
54  * {@link Signature java.security.Signature} class.
55  *
56  * @see XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo)
57  * @see XMLSignatureFactory#newXMLSignature(SignedInfo, KeyInfo, List, String, String)
58  * @author Joyce L. Leung
59  * @author Sean Mullan
60  * @author Erwin van der Koogh
61  * @author JSR 105 Expert Group
62  * @since 1.6
63  */

64 public interface XMLSignature extends XMLStructure {
65
66     /**
67      * The XML Namespace URI of the W3C Recommendation for XML-Signature
68      * Syntax and Processing.
69      */

70     final static String JavaDoc XMLNS = "http://www.w3.org/2000/09/xmldsig#";
71
72     /**
73      * Validates the signature according to the
74      * <a HREF="http://www.w3.org/TR/xmldsig-core/#sec-CoreValidation">
75      * core validation processing rules</a>. This method validates the
76      * signature using the existing state, it does not unmarshal and
77      * reinitialize the contents of the <code>XMLSignature</code> using the
78      * location information specified in the context.
79      *
80      * <p>This method only validates the signature the first time it is
81      * invoked. On subsequent invocations, it returns a cached result.
82      *
83      * @param validateContext the validating context
84      * @return <code>true</code> if the signature passed core validation,
85      * otherwise <code>false</code>
86      * @throws ClassCastException if the type of <code>validateContext</code>
87      * is not compatible with this <code>XMLSignature</code>
88      * @throws NullPointerException if <code>validateContext</code> is
89      * <code>null</code>
90      * @throws XMLSignatureException if an unexpected error occurs during
91      * validation that prevented the validation operation from completing
92      */

93     boolean validate(XMLValidateContext validateContext)
94     throws XMLSignatureException;
95
96     /**
97      * Returns the key info of this <code>XMLSignature</code>.
98      *
99      * @return the key info (may be <code>null</code> if not specified)
100      */

101     KeyInfo getKeyInfo();
102
103     /**
104      * Returns the signed info of this <code>XMLSignature</code>.
105      *
106      * @return the signed info (never <code>null</code>)
107      */

108     SignedInfo getSignedInfo();
109     
110     /**
111      * Returns an {@link java.util.Collections#unmodifiableList unmodifiable
112      * list} of {@link XMLObject}s contained in this <code>XMLSignature</code>.
113      *
114      * @return an unmodifiable list of <code>XMLObject</code>s (may be empty
115      * but never <code>null</code>)
116      */

117     List JavaDoc getObjects();
118
119     /**
120      * Returns the optional Id of this <code>XMLSignature</code>.
121      *
122      * @return the Id (may be <code>null</code> if not specified)
123      */

124     String JavaDoc getId();
125       
126     /**
127      * Returns the signature value of this <code>XMLSignature</code>.
128      *
129      * @return the signature value
130      */

131     SignatureValue getSignatureValue();
132
133     /**
134      * Signs this <code>XMLSignature</code>.
135      *
136      * <p>If this method throws an exception, this <code>XMLSignature</code> and
137      * the <code>signContext</code> parameter will be left in the state that
138      * it was in prior to the invocation.
139      *
140      * @param signContext the signing context
141      * @throws ClassCastException if the type of <code>signContext</code> is
142      * not compatible with this <code>XMLSignature</code>
143      * @throws NullPointerException if <code>signContext</code> is
144      * <code>null</code>
145      * @throws MarshalException if an exception occurs while marshalling
146      * @throws XMLSignatureException if an unexpected exception occurs while
147      * generating the signature
148      */

149     void sign(XMLSignContext signContext) throws MarshalException,
150     XMLSignatureException;
151
152     /**
153      * Returns the result of the {@link KeySelector}, if specified, after
154      * this <code>XMLSignature</code> has been signed or validated.
155      *
156      * @return the key selector result, or <code>null</code> if a key
157      * selector has not been specified or this <code>XMLSignature</code>
158      * has not been signed or validated
159      */

160     KeySelectorResult getKeySelectorResult();
161
162     /**
163      * A representation of the XML <code>SignatureValue</code> element as
164      * defined in the <a HREF="http://www.w3.org/TR/xmldsig-core/">
165      * W3C Recommendation for XML-Signature Syntax and Processing</a>.
166      * The XML Schema Definition is defined as:
167      * <p>
168      * <pre>
169      * &lt;element name="SignatureValue" type="ds:SignatureValueType"/&gt;
170      * &lt;complexType name="SignatureValueType"&gt;
171      * &lt;simpleContent&gt;
172      * &lt;extension base="base64Binary"&gt;
173      * &lt;attribute name="Id" type="ID" use="optional"/&gt;
174      * &lt;/extension&gt;
175      * &lt;/simpleContent&gt;
176      * &lt;/complexType&gt;
177      * </pre>
178      *
179      * @author Sean Mullan
180      * @author JSR 105 Expert Group
181      */

182     public interface SignatureValue extends XMLStructure {
183         /**
184          * Returns the optional <code>Id</code> attribute of this
185          * <code>SignatureValue</code>, which permits this element to be
186          * referenced from elsewhere.
187          *
188          * @return the <code>Id</code> attribute (may be <code>null</code> if
189      * not specified)
190          */

191         String JavaDoc getId();
192
193         /**
194          * Returns the signature value of this <code>SignatureValue</code>.
195          *
196          * @return the signature value (may be <code>null</code> if the
197          * <code>XMLSignature</code> has not been signed yet). Each
198      * invocation of this method returns a new clone of the array to
199      * prevent subsequent modification.
200          */

201         byte[] getValue();
202
203         /**
204          * Validates the signature value. This method performs a
205          * cryptographic validation of the signature calculated over the
206          * <code>SignedInfo</code> of the <code>XMLSignature</code>.
207          *
208          * <p>This method only validates the signature the first
209          * time it is invoked. On subsequent invocations, it returns a cached
210          * result.
211          *
212          * @return <code>true</code> if the signature was
213          * validated successfully; <code>false</code> otherwise
214          * @param validateContext the validating context
215          * @throws NullPointerException if <code>validateContext</code> is
216          * <code>null</code>
217          * @throws XMLSignatureException if an unexpected exception occurs while
218          * validating the signature
219          */

220         boolean validate(XMLValidateContext validateContext)
221             throws XMLSignatureException;
222     }
223 }
224
Popular Tags