java.security.KeyStoreSpi 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;
import java.io.*;
import java.util.*;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
/**
* This class defines the Service Provider Interface (SPI)
* for the KeyStore
class.
* All the abstract methods in this class must be implemented by each
* cryptographic service provider who wishes to supply the implementation
* of a keystore for a particular keystore type.
*
* @author Jan Luehe
*
* @version 1.9, 02/02/00
*
* @see KeyStore
*
* @since 1.2
*/
public abstract class KeyStoreSpi
{
public KeyStoreSpi() { }
/**
* Returns the key associated with the given alias, using the given
* password to recover it.
*
* @param alias the alias name
* @param password the password for recovering the key
*
* @return the requested key, or null if the given alias does not exist
* or does not identify a key entry.
*
* @exception NoSuchAlgorithmException if the algorithm for recovering the
* key cannot be found
* @exception UnrecoverableKeyException if the key cannot be recovered
* (e.g., the given password is wrong).
*/
public abstract Key engineGetKey(String alias, char[] password)
throws NoSuchAlgorithmException, UnrecoverableKeyException;
/**
* Returns the certificate chain associated with the given alias.
*
* @param alias the alias name
*
* @return the certificate chain (ordered with the user's certificate first
* and the root certificate authority last), or null if the given alias
* does not exist or does not contain a certificate chain (i.e., the given
* alias identifies either a trusted certificate entry or a
* key entry without a certificate chain).
*/
public abstract Certificate[] engineGetCertificateChain(String alias);
/**
* Returns the certificate associated with the given alias.
*
*
If the given alias name identifies a
* trusted certificate entry, the certificate associated with that
* entry is returned. If the given alias name identifies a
* key entry, the first element of the certificate chain of that
* entry is returned, or null if that entry does not have a certificate
* chain.
*
* @param alias the alias name
*
* @return the certificate, or null if the given alias does not exist or
* does not contain a certificate.
*/
public abstract Certificate engineGetCertificate(String alias);
/**
* Returns the creation date of the entry identified by the given alias.
*
* @param alias the alias name
*
* @return the creation date of this entry, or null if the given alias does
* not exist
*/
public abstract Date engineGetCreationDate(String alias);
/**
* Assigns the given key to the given alias, protecting it with the given
* password.
*
*
If the given key is of type java.security.PrivateKey
,
* it must be accompanied by a certificate chain certifying the
* corresponding public key.
*
*
If the given alias already exists, the keystore information
* associated with it is overridden by the given key (and possibly
* certificate chain).
*
* @param alias the alias name
* @param key the key to be associated with the alias
* @param password the password to protect the key
* @param chain the certificate chain for the corresponding public
* key (only required if the given key is of type
* java.security.PrivateKey
).
*
* @exception KeyStoreException if the given key cannot be protected, or
* this operation fails for some other reason
*/
public abstract void engineSetKeyEntry(String alias, Key key, char[]
password, Certificate[] chain) throws KeyStoreException;
/**
* Assigns the given key (that has already been protected) to the given
* alias.
*
*
If the protected key is of type
* java.security.PrivateKey
,
* it must be accompanied by a certificate chain certifying the
* corresponding public key.
*
*
If the given alias already exists, the keystore information
* associated with it is overridden by the given key (and possibly
* certificate chain).
*
* @param alias the alias name
* @param key the key (in protected format) to be associated with the alias
* @param chain the certificate chain for the corresponding public
* key (only useful if the protected key is of type
* java.security.PrivateKey
).
*
* @exception KeyStoreException if this operation fails.
*/
public abstract void engineSetKeyEntry(String alias, byte[] key,
Certificate[] chain) throws KeyStoreException;
/**
* Assigns the given certificate to the given alias.
*
*
If the given alias already exists in this keystore and identifies a
* trusted certificate entry, the certificate associated with it is
* overridden by the given certificate.
*
* @param alias the alias name
* @param cert the certificate
*
* @exception KeyStoreException if the given alias already exists and does
* not identify a trusted certificate entry, or this operation
* fails for some other reason.
*/
public abstract void engineSetCertificateEntry(String alias, Certificate
cert) throws KeyStoreException;
/**
* Deletes the entry identified by the given alias from this keystore.
*
* @param alias the alias name
*
* @exception KeyStoreException if the entry cannot be removed.
*/
public abstract void engineDeleteEntry(String alias)
throws KeyStoreException;
/**
* Lists all the alias names of this keystore.
*
* @return enumeration of the alias names
*/
public abstract Enumeration engineAliases();
/**
* Checks if the given alias exists in this keystore.
*
* @param alias the alias name
*
* @return true if the alias exists, false otherwise
*/
public abstract boolean engineContainsAlias(String alias);
/**
* Retrieves the number of entries in this keystore.
*
* @return the number of entries in this keystore
*/
public abstract int engineSize();
/**
* Returns true if the entry identified by the given alias is a
* key entry, and false otherwise.
*
* @param alias the alias for the keystore entry to be checked
*
* @return true if the entry identified by the given alias is a
* key entry, false otherwise.
*/
public abstract boolean engineIsKeyEntry(String alias);
/**
* Returns true if the entry identified by the given alias is a
* trusted certificate entry, and false otherwise.
*
* @param alias the alias for the keystore entry to be checked
*
* @return true if the entry identified by the given alias is a
* trusted certificate entry, false otherwise.
*/
public abstract boolean engineIsCertificateEntry(String alias);
/**
* Returns the (alias) name of the first keystore entry whose certificate
* matches the given certificate.
*
*
This method attempts to match the given certificate with each
* keystore entry. If the entry being considered
* is a trusted certificate entry, the given certificate is
* compared to that entry's certificate. If the entry being considered is
* a key entry, the given certificate is compared to the first
* element of that entry's certificate chain (if a chain exists).
*
* @param cert the certificate to match with.
*
* @return the (alias) name of the first entry with matching certificate,
* or null if no such entry exists in this keystore.
*/
public abstract String engineGetCertificateAlias(Certificate cert);
/**
* Stores this keystore to the given output stream, and protects its
* integrity with the given password.
*
* @param stream the output stream to which this keystore is written.
* @param password the password to generate the keystore integrity check
*
* @exception IOException if there was an I/O problem with data
* @exception NoSuchAlgorithmException if the appropriate data integrity
* algorithm could not be found
* @exception CertificateException if any of the certificates included in
* the keystore data could not be stored
*/
public abstract void engineStore(OutputStream stream, char[] password)
throws IOException, NoSuchAlgorithmException,
java.security.cert.CertificateException;
/**
* Loads the keystore from the given input stream.
*
*
If a password is given, it is used to check the integrity of the
* keystore data. Otherwise, the integrity of the keystore is not checked.
*
* @param stream the input stream from which the keystore is loaded
* @param password the (optional) password used to check the integrity of
* the keystore.
*
* @exception IOException if there is an I/O or format problem with the
* keystore data
* @exception NoSuchAlgorithmException if the algorithm used to check
* the integrity of the keystore cannot be found
* @exception CertificateException if any of the certificates in the
* keystore could not be loaded
*/
public abstract void engineLoad(InputStream stream, char[] password)
throws IOException, NoSuchAlgorithmException,
java.security.cert.CertificateException;
}