0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A
0N/Apackage javax.security.cert;
0N/A
0N/Aimport java.security.PublicKey;
0N/Aimport java.security.NoSuchAlgorithmException;
0N/Aimport java.security.NoSuchProviderException;
0N/Aimport java.security.InvalidKeyException;
0N/Aimport java.security.SignatureException;
0N/A
0N/A/**
0N/A * <p>Abstract class for managing a variety of identity certificates.
0N/A * An identity certificate is a guarantee by a principal that
0N/A * a public key is that of another principal. (A principal represents
0N/A * an entity such as an individual user, a group, or a corporation.)
0N/A *<p>
0N/A * This class is an abstraction for certificates that have different
0N/A * formats but important common uses. For example, different types of
0N/A * certificates, such as X.509 and PGP, share general certificate
0N/A * functionality (like encoding and verifying) and
0N/A * some types of information (like a public key).
0N/A * <p>
0N/A * X.509, PGP, and SDSI certificates can all be implemented by
0N/A * subclassing the Certificate class, even though they contain different
0N/A * sets of information, and they store and retrieve the information in
0N/A * different ways.
0N/A *
0N/A * <p><em>Note: The classes in the package <code>javax.security.cert</code>
0N/A * exist for compatibility with earlier versions of the
0N/A * Java Secure Sockets Extension (JSSE). New applications should instead
0N/A * use the standard Java SE certificate classes located in
0N/A * <code>java.security.cert</code>.</em></p>
0N/A *
0N/A * @since 1.4
0N/A * @see X509Certificate
0N/A *
0N/A * @author Hemma Prafullchandra
0N/A */
0N/Apublic abstract class Certificate {
0N/A
0N/A /**
0N/A * Compares this certificate for equality with the specified
0N/A * object. If the <code>other</code> object is an
0N/A * <code>instanceof</code> <code>Certificate</code>, then
0N/A * its encoded form is retrieved and compared with the
0N/A * encoded form of this certificate.
0N/A *
0N/A * @param other the object to test for equality with this certificate.
0N/A * @return true if the encoded forms of the two certificates
0N/A * match, false otherwise.
0N/A */
0N/A public boolean equals(Object other) {
0N/A if (this == other)
0N/A return true;
0N/A if (!(other instanceof Certificate))
0N/A return false;
0N/A try {
0N/A byte[] thisCert = this.getEncoded();
0N/A byte[] otherCert = ((Certificate)other).getEncoded();
0N/A
0N/A if (thisCert.length != otherCert.length)
0N/A return false;
0N/A for (int i = 0; i < thisCert.length; i++)
0N/A if (thisCert[i] != otherCert[i])
0N/A return false;
0N/A return true;
0N/A } catch (CertificateException e) {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a hashcode value for this certificate from its
0N/A * encoded form.
0N/A *
0N/A * @return the hashcode value.
0N/A */
0N/A public int hashCode() {
0N/A int retval = 0;
0N/A try {
0N/A byte[] certData = this.getEncoded();
0N/A for (int i = 1; i < certData.length; i++) {
0N/A retval += certData[i] * i;
0N/A }
0N/A return (retval);
0N/A } catch (CertificateException e) {
0N/A return (retval);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the encoded form of this certificate. It is
0N/A * assumed that each certificate type would have only a single
0N/A * form of encoding; for example, X.509 certificates would
0N/A * be encoded as ASN.1 DER.
0N/A *
0N/A * @return encoded form of this certificate
0N/A * @exception CertificateEncodingException on internal certificate
0N/A * encoding failure
0N/A */
0N/A public abstract byte[] getEncoded() throws CertificateEncodingException;
0N/A
0N/A /**
0N/A * Verifies that this certificate was signed using the
0N/A * private key that corresponds to the specified public key.
0N/A *
0N/A * @param key the PublicKey used to carry out the verification.
0N/A *
0N/A * @exception NoSuchAlgorithmException on unsupported signature
0N/A * algorithms.
0N/A * @exception InvalidKeyException on incorrect key.
0N/A * @exception NoSuchProviderException if there's no default provider.
0N/A * @exception SignatureException on signature errors.
0N/A * @exception CertificateException on encoding errors.
0N/A */
0N/A public abstract void verify(PublicKey key)
0N/A throws CertificateException, NoSuchAlgorithmException,
0N/A InvalidKeyException, NoSuchProviderException,
0N/A SignatureException;
0N/A
0N/A /**
0N/A * Verifies that this certificate was signed using the
0N/A * private key that corresponds to the specified public key.
0N/A * This method uses the signature verification engine
0N/A * supplied by the specified provider.
0N/A *
0N/A * @param key the PublicKey used to carry out the verification.
0N/A * @param sigProvider the name of the signature provider.
0N/A * @exception NoSuchAlgorithmException on unsupported signature algorithms.
0N/A * @exception InvalidKeyException on incorrect key.
0N/A * @exception NoSuchProviderException on incorrect provider.
0N/A * @exception SignatureException on signature errors.
0N/A * @exception CertificateException on encoding errors.
0N/A */
0N/A public abstract void verify(PublicKey key, String sigProvider)
0N/A throws CertificateException, NoSuchAlgorithmException,
0N/A InvalidKeyException, NoSuchProviderException,
0N/A SignatureException;
0N/A
0N/A /**
0N/A * Returns a string representation of this certificate.
0N/A *
0N/A * @return a string representation of this certificate.
0N/A */
0N/A public abstract String toString();
0N/A
0N/A /**
0N/A * Gets the public key from this certificate.
0N/A *
0N/A * @return the public key.
0N/A */
0N/A public abstract PublicKey getPublicKey();
0N/A}