001 /*
002 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 /*
026 * $Id: KeyValue.java,v 1.4 2005/05/10 16:35:35 mullan Exp $
027 */
028 package javax.xml.crypto.dsig.keyinfo;
029
030 import java.security.KeyException;
031 import java.security.KeyStore;
032 import java.security.PublicKey;
033 import java.security.interfaces.DSAPublicKey;
034 import java.security.interfaces.RSAPublicKey;
035 import javax.xml.crypto.XMLStructure;
036
037 /**
038 * A representation of the XML <code>KeyValue</code> element as defined
039 * in the <a href="http://www.w3.org/TR/xmldsig-core/">
040 * W3C Recommendation for XML-Signature Syntax and Processing</a>. A
041 * <code>KeyValue</code> object contains a single public key that may be
042 * useful in validating the signature. The XML schema definition is defined as:
043 *
044 * <pre>
045 * <element name="KeyValue" type="ds:KeyValueType"/>
046 * <complexType name="KeyValueType" mixed="true">
047 * <choice>
048 * <element ref="ds:DSAKeyValue"/>
049 * <element ref="ds:RSAKeyValue"/>
050 * <any namespace="##other" processContents="lax"/>
051 * </choice>
052 * </complexType>
053 *
054 * <element name="DSAKeyValue" type="ds:DSAKeyValueType"/>
055 * <complexType name="DSAKeyValueType">
056 * <sequence>
057 * <sequence minOccurs="0">
058 * <element name="P" type="ds:CryptoBinary"/>
059 * <element name="Q" type="ds:CryptoBinary"/>
060 * </sequence>
061 * <element name="G" type="ds:CryptoBinary" minOccurs="0"/>
062 * <element name="Y" type="ds:CryptoBinary"/>
063 * <element name="J" type="ds:CryptoBinary" minOccurs="0"/>
064 * <sequence minOccurs="0">
065 * <element name="Seed" type="ds:CryptoBinary"/>
066 * <element name="PgenCounter" type="ds:CryptoBinary"/>
067 * </sequence>
068 * </sequence>
069 * </complexType>
070 *
071 * <element name="RSAKeyValue" type="ds:RSAKeyValueType"/>
072 * <complexType name="RSAKeyValueType">
073 * <sequence>
074 * <element name="Modulus" type="ds:CryptoBinary"/>
075 * <element name="Exponent" type="ds:CryptoBinary"/>
076 * </sequence>
077 * </complexType>
078 * </pre>
079 * A <code>KeyValue</code> instance may be created by invoking the
080 * {@link KeyInfoFactory#newKeyValue newKeyValue} method of the
081 * {@link KeyInfoFactory} class, and passing it a {@link
082 * java.security.PublicKey} representing the value of the public key. Here is
083 * an example of creating a <code>KeyValue</code> from a {@link DSAPublicKey}
084 * of a {@link java.security.cert.Certificate} stored in a
085 * {@link java.security.KeyStore}:
086 * <pre>
087 * KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
088 * PublicKey dsaPublicKey = keyStore.getCertificate("myDSASigningCert").getPublicKey();
089 * KeyInfoFactory factory = KeyInfoFactory.getInstance("DOM");
090 * KeyValue keyValue = factory.newKeyValue(dsaPublicKey);
091 * </pre>
092 *
093 * This class returns the <code>DSAKeyValue</code> and
094 * <code>RSAKeyValue</code> elements as objects of type
095 * {@link DSAPublicKey} and {@link RSAPublicKey}, respectively. Note that not
096 * all of the fields in the schema are accessible as parameters of these
097 * types.
098 *
099 * @author Sean Mullan
100 * @author JSR 105 Expert Group
101 * @since 1.6
102 * @see KeyInfoFactory#newKeyValue(PublicKey)
103 */
104 public 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 = "http://www.w3.org/2000/09/xmldsig#DSAKeyValue";
114
115 /**
116 * URI identifying the RSA KeyValue KeyInfo type:
117 * http://www.w3.org/2000/09/xmldsig#RSAKeyValue. This can be specified as
118 * the value of the <code>type</code> parameter of the
119 * {@link RetrievalMethod} class to describe a remote
120 * <code>RSAKeyValue</code> structure.
121 */
122 final static String RSA_TYPE = "http://www.w3.org/2000/09/xmldsig#RSAKeyValue";
123
124 /**
125 * Returns the public key of this <code>KeyValue</code>.
126 *
127 * @return the public key of this <code>KeyValue</code>
128 * @throws KeyException if this <code>KeyValue</code> cannot be converted
129 * to a <code>PublicKey</code>
130 */
131 PublicKey getPublicKey() throws KeyException;
132 }
|