jdk/src/java.base/share/classes/java/security/KeyStoreSpi.java
author vinnie
Tue, 23 Dec 2014 16:30:57 +0000
changeset 28243 47080f9ae750
parent 25859 3317bb8137f4
child 29492 a4bf9a570035
permissions -rw-r--r--
8044445: JEP 229: Create PKCS12 Keystores by Default Reviewed-by: mullan, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
28243
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
     2
 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.KeyStore.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.Certificate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.cert.CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.crypto.SecretKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.security.auth.callback.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    41
 * for the {@code KeyStore} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * All the abstract methods in this class must be implemented by each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * cryptographic service provider who wishes to supply the implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * of a keystore for a particular keystore type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * @see KeyStore
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public abstract class KeyStoreSpi {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Returns the key associated with the given alias, using the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * password to recover it.  The key must have been associated with
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    59
     * the alias by a call to {@code setKeyEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    60
     * or by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    61
     * {@code PrivateKeyEntry} or {@code SecretKeyEntry}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @param password the password for recovering the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @return the requested key, or null if the given alias does not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * or does not identify a key-related entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @exception NoSuchAlgorithmException if the algorithm for recovering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * key cannot be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @exception UnrecoverableKeyException if the key cannot be recovered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * (e.g., the given password is wrong).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public abstract Key engineGetKey(String alias, char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        throws NoSuchAlgorithmException, UnrecoverableKeyException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Returns the certificate chain associated with the given alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * The certificate chain must have been associated with the alias
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    80
     * by a call to {@code setKeyEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    81
     * or by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    82
     * {@code PrivateKeyEntry}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @return the certificate chain (ordered with the user's certificate first
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * and the root certificate authority last), or null if the given alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * does not exist or does not contain a certificate chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public abstract Certificate[] engineGetCertificateChain(String alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Returns the certificate associated with the given alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <p> If the given alias name identifies an entry
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    96
     * created by a call to {@code setCertificateEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    97
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
    98
     * {@code TrustedCertificateEntry},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * then the trusted certificate contained in that entry is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <p> If the given alias name identifies an entry
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   102
     * created by a call to {@code setKeyEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   103
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   104
     * {@code PrivateKeyEntry},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * then the first element of the certificate chain in that entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * (if a chain exists) is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @return the certificate, or null if the given alias does not exist or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * does not contain a certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public abstract Certificate engineGetCertificate(String alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns the creation date of the entry identified by the given alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @return the creation date of this entry, or null if the given alias does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * not exist
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public abstract Date engineGetCreationDate(String alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Assigns the given key to the given alias, protecting it with the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   129
     * <p>If the given key is of type {@code java.security.PrivateKey},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * it must be accompanied by a certificate chain certifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * corresponding public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * <p>If the given alias already exists, the keystore information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * associated with it is overridden by the given key (and possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * certificate chain).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param key the key to be associated with the alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param password the password to protect the key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param chain the certificate chain for the corresponding public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * key (only required if the given key is of type
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   142
     * {@code java.security.PrivateKey}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @exception KeyStoreException if the given key cannot be protected, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * this operation fails for some other reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public abstract void engineSetKeyEntry(String alias, Key key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                                           char[] password,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                           Certificate[] chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        throws KeyStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Assigns the given key (that has already been protected) to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p>If the protected key is of type
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   157
     * {@code java.security.PrivateKey},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * it must be accompanied by a certificate chain certifying the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * corresponding public key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p>If the given alias already exists, the keystore information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * associated with it is overridden by the given key (and possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * certificate chain).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param key the key (in protected format) to be associated with the alias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param chain the certificate chain for the corresponding public
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * key (only useful if the protected key is of type
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   169
     * {@code java.security.PrivateKey}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @exception KeyStoreException if this operation fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public abstract void engineSetKeyEntry(String alias, byte[] key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                           Certificate[] chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        throws KeyStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Assigns the given certificate to the given alias.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <p> If the given alias identifies an existing entry
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   181
     * created by a call to {@code setCertificateEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   182
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   183
     * {@code TrustedCertificateEntry},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * the trusted certificate in the existing entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * is overridden by the given certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @param cert the certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @exception KeyStoreException if the given alias already exists and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * not identify an entry containing a trusted certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * or this operation fails for some other reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public abstract void engineSetCertificateEntry(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                                   Certificate cert)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        throws KeyStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Deletes the entry identified by the given alias from this keystore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @exception KeyStoreException if the entry cannot be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public abstract void engineDeleteEntry(String alias)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        throws KeyStoreException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Lists all the alias names of this keystore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return enumeration of the alias names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    public abstract Enumeration<String> engineAliases();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * Checks if the given alias exists in this keystore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @return true if the alias exists, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public abstract boolean engineContainsAlias(String alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Retrieves the number of entries in this keystore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return the number of entries in this keystore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public abstract int engineSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns true if the entry identified by the given alias
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   233
     * was created by a call to {@code setKeyEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   234
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   235
     * {@code PrivateKeyEntry} or a {@code SecretKeyEntry}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * @param alias the alias for the keystore entry to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return true if the entry identified by the given alias is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * key-related, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public abstract boolean engineIsKeyEntry(String alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns true if the entry identified by the given alias
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   246
     * was created by a call to {@code setCertificateEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   247
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   248
     * {@code TrustedCertificateEntry}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param alias the alias for the keystore entry to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return true if the entry identified by the given alias contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * trusted certificate, false otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public abstract boolean engineIsCertificateEntry(String alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * Returns the (alias) name of the first keystore entry whose certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * matches the given certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * <p>This method attempts to match the given certificate with each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * keystore entry. If the entry being considered was
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   263
     * created by a call to {@code setCertificateEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   264
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   265
     * {@code TrustedCertificateEntry},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * then the given certificate is compared to that entry's certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * <p> If the entry being considered was
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   269
     * created by a call to {@code setKeyEntry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   270
     * or created by a call to {@code setEntry} with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   271
     * {@code PrivateKeyEntry},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * then the given certificate is compared to the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * element of that entry's certificate chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param cert the certificate to match with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return the alias name of the first entry with matching certificate,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * or null if no such entry exists in this keystore.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public abstract String engineGetCertificateAlias(Certificate cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Stores this keystore to the given output stream, and protects its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * integrity with the given password.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param stream the output stream to which this keystore is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @param password the password to generate the keystore integrity check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @exception IOException if there was an I/O problem with data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @exception NoSuchAlgorithmException if the appropriate data integrity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * algorithm could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @exception CertificateException if any of the certificates included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * the keystore data could not be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public abstract void engineStore(OutputStream stream, char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        throws IOException, NoSuchAlgorithmException, CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Stores this keystore using the given
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   300
     * {@code KeyStore.LoadStoreParmeter}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   302
     * @param param the {@code KeyStore.LoadStoreParmeter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *          that specifies how to store the keystore,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   304
     *          which may be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * @exception IllegalArgumentException if the given
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   307
     *          {@code KeyStore.LoadStoreParmeter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *          input is not recognized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @exception IOException if there was an I/O problem with data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @exception NoSuchAlgorithmException if the appropriate data integrity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *          algorithm could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @exception CertificateException if any of the certificates included in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *          the keystore data could not be stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void engineStore(KeyStore.LoadStoreParameter param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                throws IOException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Loads the keystore from the given input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <p>A password may be given to unlock the keystore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * (e.g. the keystore resides on a hardware token device),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * or to check the integrity of the keystore data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * If a password is not given for integrity checking,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * then integrity checking is not performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param stream the input stream from which the keystore is loaded,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   333
     * or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @param password the password used to check the integrity of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * the keystore, the password used to unlock the keystore,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   336
     * or {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @exception IOException if there is an I/O or format problem with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * keystore data, if a password is required but not given,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * or if the given password was incorrect. If the error is due to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * wrong password, the {@link Throwable#getCause cause} of the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   342
     * {@code IOException} should be an
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   343
     * {@code UnrecoverableKeyException}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * @exception NoSuchAlgorithmException if the algorithm used to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * the integrity of the keystore cannot be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @exception CertificateException if any of the certificates in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * keystore could not be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public abstract void engineLoad(InputStream stream, char[] password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        throws IOException, NoSuchAlgorithmException, CertificateException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Loads the keystore using the given
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   354
     * {@code KeyStore.LoadStoreParameter}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <p> Note that if this KeyStore has already been loaded, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * reinitialized and loaded again from the given parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   359
     * @param param the {@code KeyStore.LoadStoreParameter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *          that specifies how to load the keystore,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   361
     *          which may be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @exception IllegalArgumentException if the given
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   364
     *          {@code KeyStore.LoadStoreParameter}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *          input is not recognized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @exception IOException if there is an I/O or format problem with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     *          keystore data. If the error is due to an incorrect
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   368
     *         {@code ProtectionParameter} (e.g. wrong password)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *         the {@link Throwable#getCause cause} of the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   370
     *         {@code IOException} should be an
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   371
     *         {@code UnrecoverableKeyException}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception NoSuchAlgorithmException if the algorithm used to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *          the integrity of the keystore cannot be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @exception CertificateException if any of the certificates in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *          keystore could not be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public void engineLoad(KeyStore.LoadStoreParameter param)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                throws IOException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (param == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            engineLoad((InputStream)null, (char[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        if (param instanceof KeyStore.SimpleLoadStoreParameter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            ProtectionParameter protection = param.getProtectionParameter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            char[] password;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            if (protection instanceof PasswordProtection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                password = ((PasswordProtection)protection).getPassword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            } else if (protection instanceof CallbackHandlerProtection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                CallbackHandler handler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                    ((CallbackHandlerProtection)protection).getCallbackHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                PasswordCallback callback =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                    new PasswordCallback("Password: ", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                    handler.handle(new Callback[] {callback});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                } catch (UnsupportedCallbackException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                    throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                        ("Could not obtain password", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                password = callback.getPassword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                callback.clearPassword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                if (password == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                    throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                        ("No password provided");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                throw new NoSuchAlgorithmException("ProtectionParameter must"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    + " be PasswordProtection or CallbackHandlerProtection");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            engineLoad(null, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   422
     * Gets a {@code KeyStore.Entry} for the specified alias
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * with the specified protection parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   425
     * @param alias get the {@code KeyStore.Entry} for this alias
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   426
     * @param protParam the {@code ProtectionParameter}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   427
     *          used to protect the {@code Entry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   428
     *          which may be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   430
     * @return the {@code KeyStore.Entry} for the specified alias,
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   431
     *          or {@code null} if there is no such entry
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * @exception KeyStoreException if the operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @exception NoSuchAlgorithmException if the algorithm for recovering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *          entry cannot be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @exception UnrecoverableEntryException if the specified
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   437
     *          {@code protParam} were insufficient or invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception UnrecoverableKeyException if the entry is a
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   439
     *          {@code PrivateKeyEntry} or {@code SecretKeyEntry}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   440
     *          and the specified {@code protParam} does not contain
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     *          the information needed to recover the key (e.g. wrong password)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public KeyStore.Entry engineGetEntry(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                        KeyStore.ProtectionParameter protParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                throws KeyStoreException, NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                UnrecoverableEntryException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        if (!engineContainsAlias(alias)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (protParam == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (engineIsCertificateEntry(alias)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                return new KeyStore.TrustedCertificateEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                                (engineGetCertificate(alias));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                throw new UnrecoverableKeyException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                        ("requested entry requires a password");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        if (protParam instanceof KeyStore.PasswordProtection) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            if (engineIsCertificateEntry(alias)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                throw new UnsupportedOperationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    ("trusted certificate entries are not password-protected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            } else if (engineIsKeyEntry(alias)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                KeyStore.PasswordProtection pp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                        (KeyStore.PasswordProtection)protParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                char[] password = pp.getPassword();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                Key key = engineGetKey(alias, password);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                if (key instanceof PrivateKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    Certificate[] chain = engineGetCertificateChain(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                    return new KeyStore.PrivateKeyEntry((PrivateKey)key, chain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                } else if (key instanceof SecretKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                    return new KeyStore.SecretKeyEntry((SecretKey)key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   487
     * Saves a {@code KeyStore.Entry} under the specified alias.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * The specified protection parameter is used to protect the
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   489
     * {@code Entry}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <p> If an entry already exists for the specified alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * it is overridden.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   494
     * @param alias save the {@code KeyStore.Entry} under this alias
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   495
     * @param entry the {@code Entry} to save
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   496
     * @param protParam the {@code ProtectionParameter}
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   497
     *          used to protect the {@code Entry},
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   498
     *          which may be {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @exception KeyStoreException if this operation fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    public void engineSetEntry(String alias, KeyStore.Entry entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        KeyStore.ProtectionParameter protParam)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                throws KeyStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // get password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        if (protParam != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            !(protParam instanceof KeyStore.PasswordProtection)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            throw new KeyStoreException("unsupported protection parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        KeyStore.PasswordProtection pProtect = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        if (protParam != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            pProtect = (KeyStore.PasswordProtection)protParam;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        // set entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (entry instanceof KeyStore.TrustedCertificateEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if (protParam != null && pProtect.getPassword() != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                // pre-1.5 style setCertificateEntry did not allow password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                throw new KeyStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    ("trusted certificate entries are not password-protected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                KeyStore.TrustedCertificateEntry tce =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        (KeyStore.TrustedCertificateEntry)entry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                engineSetCertificateEntry(alias, tce.getTrustedCertificate());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        } else if (entry instanceof KeyStore.PrivateKeyEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            if (pProtect == null || pProtect.getPassword() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                // pre-1.5 style setKeyEntry required password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                throw new KeyStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    ("non-null password required to create PrivateKeyEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                engineSetKeyEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    (alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    ((KeyStore.PrivateKeyEntry)entry).getPrivateKey(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    pProtect.getPassword(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    ((KeyStore.PrivateKeyEntry)entry).getCertificateChain());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        } else if (entry instanceof KeyStore.SecretKeyEntry) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            if (pProtect == null || pProtect.getPassword() == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                // pre-1.5 style setKeyEntry required password
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                throw new KeyStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    ("non-null password required to create SecretKeyEntry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                engineSetKeyEntry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    (alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    ((KeyStore.SecretKeyEntry)entry).getSecretKey(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    pProtect.getPassword(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    (Certificate[])null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        throw new KeyStoreException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                ("unsupported entry type: " + entry.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   563
     * Determines if the keystore {@code Entry} for the specified
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   564
     * {@code alias} is an instance or subclass of the specified
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   565
     * {@code entryClass}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @param alias the alias name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @param entryClass the entry class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   570
     * @return true if the keystore {@code Entry} for the specified
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   571
     *          {@code alias} is an instance or subclass of the
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 5506
diff changeset
   572
     *          specified {@code entryClass}, false otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    public boolean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        engineEntryInstanceOf(String alias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                              Class<? extends KeyStore.Entry> entryClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        if (entryClass == KeyStore.TrustedCertificateEntry.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            return engineIsCertificateEntry(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (entryClass == KeyStore.PrivateKeyEntry.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            return engineIsKeyEntry(alias) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        engineGetCertificate(alias) != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (entryClass == KeyStore.SecretKeyEntry.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            return engineIsKeyEntry(alias) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                        engineGetCertificate(alias) == null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
28243
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   593
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   594
    /**
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   595
     * Probes the specified input stream to determine whether it contains a
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   596
     * keystore that is supported by this implementation, or not.
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   597
     *
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   598
     * <p>
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   599
     * @implSpec
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   600
     * This method returns false by default. Keystore implementations should
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   601
     * override this method to peek at the data stream directly or to use other
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   602
     * content detection mechanisms.
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   603
     *
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   604
     * @param  stream the keystore data to be probed
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   605
     *
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   606
     * @return true if the keystore data is supported, otherwise false
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   607
     *
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   608
     * @throws IOException if there is an I/O problem with the keystore data.
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   609
     * @throws NullPointerException if stream is {@code null}.
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   610
     *
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   611
     * @since 1.9
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   612
     */
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   613
    public boolean engineProbe(InputStream stream) throws IOException {
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   614
        return false;
47080f9ae750 8044445: JEP 229: Create PKCS12 Keystores by Default
vinnie
parents: 25859
diff changeset
   615
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
}