blob: 2323c98afc93cdc75811dc2d02fa9ec94c2b7077 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25/*
26 * $Id: KeyValue.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
27 */
28package javax.xml.crypto.dsig.keyinfo;
29
30import java.security.KeyException;
31import java.security.KeyStore;
32import java.security.PublicKey;
33import java.security.interfaces.DSAPublicKey;
34import java.security.interfaces.RSAPublicKey;
35import javax.xml.crypto.XMLStructure;
36
37/**
38 * A representation of the XML <code>KeyValue</code> element as defined
39 * in the <a href="http://www.w3.org/TR/xmldsig-core/">
40 * W3C Recommendation for XML-Signature Syntax and Processing</a>. A
41 * <code>KeyValue</code> object contains a single public key that may be
42 * useful in validating the signature. The XML schema definition is defined as:
43 *
44 * <pre>
45 * &lt;element name="KeyValue" type="ds:KeyValueType"/&gt;
46 * &lt;complexType name="KeyValueType" mixed="true"&gt;
47 * &lt;choice&gt;
48 * &lt;element ref="ds:DSAKeyValue"/&gt;
49 * &lt;element ref="ds:RSAKeyValue"/&gt;
50 * &lt;any namespace="##other" processContents="lax"/&gt;
51 * &lt;/choice&gt;
52 * &lt;/complexType&gt;
53 *
54 * &lt;element name="DSAKeyValue" type="ds:DSAKeyValueType"/&gt;
55 * &lt;complexType name="DSAKeyValueType"&gt;
56 * &lt;sequence&gt;
57 * &lt;sequence minOccurs="0"&gt;
58 * &lt;element name="P" type="ds:CryptoBinary"/&gt;
59 * &lt;element name="Q" type="ds:CryptoBinary"/&gt;
60 * &lt;/sequence&gt;
61 * &lt;element name="G" type="ds:CryptoBinary" minOccurs="0"/&gt;
62 * &lt;element name="Y" type="ds:CryptoBinary"/&gt;
63 * &lt;element name="J" type="ds:CryptoBinary" minOccurs="0"/&gt;
64 * &lt;sequence minOccurs="0"&gt;
65 * &lt;element name="Seed" type="ds:CryptoBinary"/&gt;
66 * &lt;element name="PgenCounter" type="ds:CryptoBinary"/&gt;
67 * &lt;/sequence&gt;
68 * &lt;/sequence&gt;
69 * &lt;/complexType&gt;
70 *
71 * &lt;element name="RSAKeyValue" type="ds:RSAKeyValueType"/&gt;
72 * &lt;complexType name="RSAKeyValueType"&gt;
73 * &lt;sequence&gt;
74 * &lt;element name="Modulus" type="ds:CryptoBinary"/&gt;
75 * &lt;element name="Exponent" type="ds:CryptoBinary"/&gt;
76 * &lt;/sequence&gt;
77 * &lt;/complexType&gt;
78 * </pre>
79 * A <code>KeyValue</code> instance may be created by invoking the
80 * {@link KeyInfoFactory#newKeyValue newKeyValue} method of the
81 * {@link KeyInfoFactory} class, and passing it a {@link
82 * java.security.PublicKey} representing the value of the public key. Here is
83 * an example of creating a <code>KeyValue</code> from a {@link DSAPublicKey}
84 * of a {@link java.security.cert.Certificate} stored in a
85 * {@link java.security.KeyStore}:
86 * <pre>
87 * KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
88 * PublicKey dsaPublicKey = keyStore.getCertificate("myDSASigningCert").getPublicKey();
89 * KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
90 * KeyValue keyValue = factory.newKeyValue(dsaPublicKey);
91 * </pre>
92 *
93 * This class returns the <code>DSAKeyValue</code> and
94 * <code>RSAKeyValue</code> elements as objects of type
95 * {@link DSAPublicKey} and {@link RSAPublicKey}, respectively. Note that not
96 * all of the fields in the schema are accessible as parameters of these
97 * types.
98 *
99 * @author Sean Mullan
100 * @author JSR 105 Expert Group
101 * @since 1.6
102 * @see KeyInfoFactory#newKeyValue(PublicKey)
103 */
104public interface KeyValue extends XMLStructure {
105
106 /**
107 * URI identifying the DSA KeyValue KeyInfo type:
108 * http://www.w3.org/2000/09/xmldsig#DSAKeyValue. This can be specified as
109 * the value of the <code>type</code> parameter of the
110 * {@link RetrievalMethod} class to describe a remote
111 * <code>DSAKeyValue</code> structure.
112 */
113 final static String DSA_TYPE =
114 "http://www.w3.org/2000/09/xmldsig#DSAKeyValue";
115
116 /**
117 * URI identifying the RSA KeyValue KeyInfo type:
118 * http://www.w3.org/2000/09/xmldsig#RSAKeyValue. This can be specified as
119 * the value of the <code>type</code> parameter of the
120 * {@link RetrievalMethod} class to describe a remote
121 * <code>RSAKeyValue</code> structure.
122 */
123 final static String RSA_TYPE =
124 "http://www.w3.org/2000/09/xmldsig#RSAKeyValue";
125
126 /**
127 * Returns the public key of this <code>KeyValue</code>.
128 *
129 * @return the public key of this <code>KeyValue</code>
130 * @throws KeyException if this <code>KeyValue</code> cannot be converted
131 * to a <code>PublicKey</code>
132 */
133 PublicKey getPublicKey() throws KeyException;
134}