java.security.cert.Certificate Maven / Gradle / Ivy
/*
This is not an official specification document, and usage is restricted.
NOTICE
(c) 2005-2007 Sun Microsystems, Inc. All Rights Reserved.
Neither this file nor any files generated from it describe a complete
specification, and they may only be used as described below. For
example, no permission is given for you to incorporate this file, in
whole or in part, in an implementation of a Java specification.
Sun Microsystems Inc. owns the copyright in this file and it is provided
to you for informative, as opposed to normative, use. The file and any
files generated from it may be used to generate other informative
documentation, such as a unified set of documents of API signatures for
a platform that includes technologies expressed as Java APIs. The file
may also be used to produce "compilation stubs," which allow
applications to be compiled and validated for such platforms.
Any work generated from this file, such as unified javadocs or compiled
stub files, must be accompanied by this notice in its entirety.
This work corresponds to the API signatures of JSR 219: Foundation
Profile 1.1. In the event of a discrepency between this work and the
JSR 219 specification, which is available at
http://www.jcp.org/en/jsr/detail?id=219, the latter takes precedence.
*/
package java.security.cert;
import java.util.Arrays;
import java.security.PublicKey;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.InvalidKeyException;
import java.security.SignatureException;
/**
*
Abstract class for managing a variety of identity certificates.
* An identity certificate is a binding of a principal to a public key which
* is vouched for by another principal. (A principal represents
* an entity such as an individual user, a group, or a corporation.)
*
* This class is an abstraction for certificates that have different
* formats but important common uses. For example, different types of
* certificates, such as X.509 and PGP, share general certificate
* functionality (like encoding and verifying) and
* some types of information (like a public key).
*
* X.509, PGP, and SDSI certificates can all be implemented by
* subclassing the Certificate class, even though they contain different
* sets of information, and they store and retrieve the information in
* different ways.
*
* @see X509Certificate
* @see CertificateFactory
*
* @author Hemma Prafullchandra
* @version 1.23, 03/12/05
*/
public abstract class Certificate implements java.io.Serializable
{
private final String type = null;
/**
* Creates a certificate of the specified type.
*
* @param type the standard name of the certificate type.
* See Appendix A in the
* Java Cryptography Architecture API Specification & Reference
* for information about standard certificate types.
*/
protected Certificate(String type) { }
/**
* Returns the type of this certificate.
*
* @return the type of this certificate.
*/
public final String getType() {
return null;
}
/**
* Compares this certificate for equality with the specified
* object. If the other
object is an
* instanceof
Certificate
, then
* its encoded form is retrieved and compared with the
* encoded form of this certificate.
*
* @param other the object to test for equality with this certificate.
* @return true iff the encoded forms of the two certificates
* match, false otherwise.
*/
public boolean equals(Object other) {
return false;
}
/**
* Returns a hashcode value for this certificate from its
* encoded form.
*
* @return the hashcode value.
*/
public int hashCode() {
return 0;
}
/**
* Returns the encoded form of this certificate. It is
* assumed that each certificate type would have only a single
* form of encoding; for example, X.509 certificates would
* be encoded as ASN.1 DER.
*
* @return the encoded form of this certificate
*
* @exception CertificateEncodingException if an encoding error occurs.
*/
public abstract byte[] getEncoded() throws CertificateEncodingException;
/**
* Verifies that this certificate was signed using the
* private key that corresponds to the specified public key.
*
* @param key the PublicKey used to carry out the verification.
*
* @exception NoSuchAlgorithmException on unsupported signature
* algorithms.
* @exception InvalidKeyException on incorrect key.
* @exception NoSuchProviderException if there's no default provider.
* @exception SignatureException on signature errors.
* @exception CertificateException on encoding errors.
*/
public abstract void verify(PublicKey key)
throws CertificateException, NoSuchAlgorithmException,
InvalidKeyException, NoSuchProviderException, SignatureException;
/**
* Verifies that this certificate was signed using the
* private key that corresponds to the specified public key.
* This method uses the signature verification engine
* supplied by the specified provider.
*
* @param key the PublicKey used to carry out the verification.
* @param sigProvider the name of the signature provider.
*
* @exception NoSuchAlgorithmException on unsupported signature
* algorithms.
* @exception InvalidKeyException on incorrect key.
* @exception NoSuchProviderException on incorrect provider.
* @exception SignatureException on signature errors.
* @exception CertificateException on encoding errors.
*/
public abstract void verify(PublicKey key, String sigProvider)
throws CertificateException, NoSuchAlgorithmException,
InvalidKeyException, NoSuchProviderException, SignatureException;
/**
* Returns a string representation of this certificate.
*
* @return a string representation of this certificate.
*/
public abstract String toString();
/**
* Gets the public key from this certificate.
*
* @return the public key.
*/
public abstract PublicKey getPublicKey();
/**
* Replace the Certificate to be serialized.
*
* @return the alternate Certificate object to be serialized
*
* @throws java.io.ObjectStreamException if a new object representing
* this Certificate could not be created
*/
protected Object writeReplace() throws java.io.ObjectStreamException {
return null;
}
/**
* Alternate Certificate class for serialization.
*/
protected static class CertificateRep implements java.io.Serializable
{
private String type;
private byte[] data;
/**
* Construct the alternate Certificate class with the Certificate
* type and Certificate encoding bytes.
*
*
*
* @param type the standard name of the Certificate type.
*
* @param data the Certificate data.
*/
protected CertificateRep(String type, byte[] data) { }
/**
* Resolve the Certificate Object.
*
*
*
* @return the resolved Certificate Object
*
* @throws java.io.ObjectStreamException if the Certificate
* could not be resolved
*/
protected Object readResolve() throws java.io.ObjectStreamException {
return null;
}
}
}