Path: blob/master/src/java.base/share/classes/java/security/Certificate.java
41152 views
/*1* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.security;2627import java.io.*;28import java.util.Date;2930/**31* <p>This is an interface of abstract methods for managing a32* variety of identity certificates.33* An identity certificate is a guarantee by a principal that34* a public key is that of another principal. (A principal represents35* an entity such as an individual user, a group, or a corporation.)36*37* <p>In particular, this interface is intended to be a common38* abstraction for constructs that have different formats but39* important common uses. For example, different types of40* certificates, such as X.509 certificates and PGP certificates,41* share general certificate functionality (the need to encode and42* decode certificates) and some types of information, such as a43* public key, the principal whose key it is, and the guarantor44* guaranteeing that the public key is that of the specified45* principal. So an implementation of X.509 certificates and an46* implementation of PGP certificates can both utilize the Certificate47* interface, even though their formats and additional types and48* amounts of information stored are different.49*50* <p><b>Important</b>: This interface is useful for cataloging and51* grouping objects sharing certain common uses. It does not have any52* semantics of its own. In particular, a Certificate object does not53* make any statement as to the <i>validity</i> of the binding. It is54* the duty of the application implementing this interface to verify55* the certificate and satisfy itself of its validity.56*57* @author Benjamin Renaud58* @since 1.159* @deprecated This class is deprecated and subject to removal in a future60* version of Java SE. It has been replaced by61* {@code java.security.cert.Certificate} and related classes.62* @see java.security.cert.Certificate63*/64@Deprecated(since="1.2", forRemoval=true)65public interface Certificate {6667/**68* Returns the guarantor of the certificate, that is, the principal69* guaranteeing that the public key associated with this certificate70* is that of the principal associated with this certificate. For X.50971* certificates, the guarantor will typically be a Certificate Authority72* (such as the United States Postal Service or Verisign, Inc.).73*74* @return the guarantor which guaranteed the principal-key75* binding.76*/77public abstract Principal getGuarantor();7879/**80* Returns the principal of the principal-key pair being guaranteed by81* the guarantor.82*83* @return the principal to which this certificate is bound.84*/85public abstract Principal getPrincipal();8687/**88* Returns the key of the principal-key pair being guaranteed by89* the guarantor.90*91* @return the public key that this certificate certifies belongs92* to a particular principal.93*/94public abstract PublicKey getPublicKey();9596/**97* Encodes the certificate to an output stream in a format that can98* be decoded by the {@code decode} method.99*100* @param stream the output stream to which to encode the101* certificate.102*103* @throws KeyException if the certificate is not104* properly initialized, or data is missing, etc.105*106* @throws IOException if a stream exception occurs while107* trying to output the encoded certificate to the output stream.108*109* @see #decode110* @see #getFormat111*/112public abstract void encode(OutputStream stream)113throws KeyException, IOException;114115/**116* Decodes a certificate from an input stream. The format should be117* that returned by {@code getFormat} and produced by118* {@code encode}.119*120* @param stream the input stream from which to fetch the data121* being decoded.122*123* @throws KeyException if the certificate is not properly initialized,124* or data is missing, etc.125*126* @throws IOException if an exception occurs while trying to input127* the encoded certificate from the input stream.128*129* @see #encode130* @see #getFormat131*/132public abstract void decode(InputStream stream)133throws KeyException, IOException;134135136/**137* Returns the name of the coding format. This is used as a hint to find138* an appropriate parser. It could be "X.509", "PGP", etc. This is139* the format produced and understood by the {@code encode}140* and {@code decode} methods.141*142* @return the name of the coding format.143*/144public abstract String getFormat();145146/**147* Returns a string that represents the contents of the certificate.148*149* @param detailed whether or not to give detailed information150* about the certificate151*152* @return a string representing the contents of the certificate153*/154public String toString(boolean detailed);155}156157158