public final class PKCS12KeyStore extends KeyStoreSpi
KeyStoreSpi| 限定符和类型 | 类和说明 |
|---|---|
private static class |
PKCS12KeyStore.CertEntry |
private static class |
PKCS12KeyStore.Entry |
private static class |
PKCS12KeyStore.KeyEntry |
private static class |
PKCS12KeyStore.PrivateKeyEntry |
private static interface |
PKCS12KeyStore.RetryWithZero<T>
Retries an action with password "\0" if "" fails.
|
private static class |
PKCS12KeyStore.SecretKeyEntry |
| 限定符和类型 | 字段和说明 |
|---|---|
private static int[] |
AnyExtendedKeyUsage |
private static sun.security.util.ObjectIdentifier[] |
AnyUsage |
private static int[] |
certBag |
private static sun.security.util.ObjectIdentifier |
CertBag_OID |
private ArrayList<PKCS12KeyStore.CertEntry> |
certEntries |
private int |
certificateCount |
private int |
certPbeIterationCount |
private String |
certProtectionAlgorithm |
private LinkedHashMap<X500Principal,X509Certificate> |
certsMap |
private static String[] |
CORE_ATTRIBUTES |
private int |
counter |
private static sun.security.util.Debug |
debug |
private static String |
DEFAULT_CERT_PBE_ALGORITHM |
private static int |
DEFAULT_CERT_PBE_ITERATION_COUNT |
private static String |
DEFAULT_KEY_PBE_ALGORITHM |
private static int |
DEFAULT_KEY_PBE_ITERATION_COUNT |
private static String |
DEFAULT_MAC_ALGORITHM |
private static int |
DEFAULT_MAC_ITERATION_COUNT |
private Map<String,PKCS12KeyStore.Entry> |
entries
Private keys and certificates are stored in a map.
|
private static int[] |
gmpbes2 |
private static sun.security.util.ObjectIdentifier |
gmpbes2_OID |
private static int[] |
keyBag |
private ArrayList<PKCS12KeyStore.KeyEntry> |
keyList |
private static String |
LEGACY_CERT_PBE_ALGORITHM |
private static String |
LEGACY_KEY_PBE_ALGORITHM |
private static String |
LEGACY_MAC_ALGORITHM |
private static int |
LEGACY_MAC_ITERATION_COUNT |
private static int |
LEGACY_PBE_ITERATION_COUNT |
private String |
macAlgorithm |
private int |
macIterationCount |
private static int |
MAX_ITERATION_COUNT |
private static int[] |
pbes2 |
private static sun.security.util.ObjectIdentifier |
pbes2_OID |
private static Set<sun.security.util.ObjectIdentifier> |
PBES2_OID_LIST |
private static long[][] |
PKCS12_HEADER_MASKS |
private static long[][] |
PKCS12_HEADER_PATTERNS |
private static sun.security.util.ObjectIdentifier |
PKCS8ShroudedKeyBag_OID |
private static int[] |
pkcs9certType |
private static sun.security.util.ObjectIdentifier |
PKCS9CertType_OID |
private static sun.security.util.ObjectIdentifier |
PKCS9FriendlyName_OID |
private static int[] |
pkcs9KeyId |
private static sun.security.util.ObjectIdentifier |
PKCS9LocalKeyId_OID |
private static int[] |
pkcs9Name |
private int |
privateKeyCount |
private SecureRandom |
random |
private static int |
SALT_LEN |
private static int[] |
secretBag |
private static sun.security.util.ObjectIdentifier |
SecretBag_OID |
private int |
secretKeyCount |
private static int[] |
TrustedKeyUsage |
private static sun.security.util.ObjectIdentifier |
TrustedKeyUsage_OID |
private static String |
USE_LEGACY_PROP |
static int |
VERSION_3 |
| 构造器和说明 |
|---|
PKCS12KeyStore() |
| 限定符和类型 | 方法和说明 |
|---|---|
private byte[] |
calculateMac(char[] passwd,
byte[] data) |
private static void |
checkX509Certs(Certificate[] certs) |
private byte[] |
createEncryptedData(char[] password) |
private byte[] |
createSafeContent() |
private static int |
defaultCertPbeIterationCount() |
private static String |
defaultCertProtectionAlgorithm() |
private static int |
defaultKeyPbeIterationCount() |
private static String |
defaultKeyProtectionAlgorithm() |
private static String |
defaultMacAlgorithm() |
private static int |
defaultMacIterationCount() |
private byte[] |
encryptContent(byte[] data,
char[] password) |
private byte[] |
encryptPrivateKey(byte[] data,
KeyStore.PasswordProtection passwordProtection) |
Enumeration<String> |
engineAliases()
Lists all the alias names of this keystore.
|
boolean |
engineContainsAlias(String alias)
Checks if the given alias exists in this keystore.
|
void |
engineDeleteEntry(String alias)
Deletes the entry identified by the given alias from this keystore.
|
boolean |
engineEntryInstanceOf(String alias,
Class<? extends KeyStore.Entry> entryClass)
Determines if the keystore
Entry for the specified
alias is an instance or subclass of the specified
entryClass. |
Certificate |
engineGetCertificate(String alias)
Returns the certificate associated with the given alias.
|
String |
engineGetCertificateAlias(Certificate cert)
Returns the (alias) name of the first keystore entry whose certificate
matches the given certificate.
|
Certificate[] |
engineGetCertificateChain(String alias)
Returns the certificate chain associated with the given alias.
|
Date |
engineGetCreationDate(String alias)
Returns the creation date of the entry identified by the given alias.
|
KeyStore.Entry |
engineGetEntry(String alias,
KeyStore.ProtectionParameter protParam)
Gets a
KeyStore.Entry for the specified alias
with the specified protection parameter. |
Key |
engineGetKey(String alias,
char[] password)
Returns the key associated with the given alias, using the given
password to recover it.
|
boolean |
engineIsCertificateEntry(String alias)
Returns true if the entry identified by the given alias is a
trusted certificate entry, and false otherwise.
|
boolean |
engineIsKeyEntry(String alias)
Returns true if the entry identified by the given alias is a
key entry, and false otherwise.
|
void |
engineLoad(InputStream stream,
char[] password)
Loads the keystore from the given input stream.
|
boolean |
engineProbe(InputStream stream)
Probe the first few bytes of the keystore data stream for a valid
PKCS12 keystore encoding.
|
void |
engineSetCertificateEntry(String alias,
Certificate cert)
Assigns the given certificate to the given alias.
|
void |
engineSetEntry(String alias,
KeyStore.Entry entry,
KeyStore.ProtectionParameter protParam)
Saves a
KeyStore.Entry under the specified alias. |
void |
engineSetKeyEntry(String alias,
byte[] key,
Certificate[] chain)
Assigns the given key (that has already been protected) to the given
alias.
|
void |
engineSetKeyEntry(String alias,
Key key,
char[] password,
Certificate[] chain)
Assigns the given key to the given alias, protecting it with the given
password.
|
int |
engineSize()
Retrieves the number of entries in this keystore.
|
void |
engineStore(OutputStream stream,
char[] password)
Stores this keystore to the given output stream, and protects its
integrity with the given password.
|
private X509Certificate |
findMatchedCertificate(PKCS12KeyStore.PrivateKeyEntry entry)
Locates a matched CertEntry from certEntries, and returns its cert.
|
private Set<KeyStore.Entry.Attribute> |
getAttributes(PKCS12KeyStore.Entry entry) |
private byte[] |
getBagAttributes(String alias,
byte[] keyId,
sun.security.util.ObjectIdentifier[] trustedUsage,
Set<KeyStore.Entry.Attribute> attributes) |
private byte[] |
getBagAttributes(String alias,
byte[] keyId,
Set<KeyStore.Entry.Attribute> attributes) |
private AlgorithmParameters |
getPBEAlgorithmParameters(String algorithm,
int iterationCount) |
private SecretKey |
getPBEKey(char[] password) |
private byte[] |
getSalt() |
private String |
getUnfriendlyName() |
static boolean |
isPasswordless(File f)
Returns if a pkcs12 file is password-less.
|
private void |
loadSafeContents(sun.security.util.DerInputStream stream) |
private static sun.security.util.ObjectIdentifier |
mapPBEAlgorithmToOID(String algorithm) |
private static String |
mapPBEParamsToAlgorithm(sun.security.util.ObjectIdentifier algorithm,
AlgorithmParameters algParams) |
private AlgorithmParameters |
parseAlgParameters(sun.security.util.ObjectIdentifier algorithm,
sun.security.util.DerInputStream in) |
private void |
setCertEntry(String alias,
Certificate cert,
Set<KeyStore.Entry.Attribute> attributes) |
private void |
setKeyEntry(String alias,
Key key,
KeyStore.PasswordProtection passwordProtection,
Certificate[] chain,
Set<KeyStore.Entry.Attribute> attributes) |
private static int |
string2IC(String type,
String value) |
private static boolean |
useLegacy() |
private boolean |
validateChain(Certificate[] certChain) |
engineLoad, engineStoreprivate static String DEFAULT_CERT_PBE_ALGORITHM
private static String DEFAULT_KEY_PBE_ALGORITHM
private static String DEFAULT_MAC_ALGORITHM
private static int DEFAULT_CERT_PBE_ITERATION_COUNT
private static int DEFAULT_KEY_PBE_ITERATION_COUNT
private static int DEFAULT_MAC_ITERATION_COUNT
private static final int LEGACY_PBE_ITERATION_COUNT
private static final int LEGACY_MAC_ITERATION_COUNT
public static final int VERSION_3
private static final int MAX_ITERATION_COUNT
private static final int SALT_LEN
private static final String[] CORE_ATTRIBUTES
private static final sun.security.util.Debug debug
private static final int[] keyBag
private static final int[] certBag
private static final int[] secretBag
private static final int[] pkcs9Name
private static final int[] pkcs9KeyId
private static final int[] pkcs9certType
private static final int[] pbes2
private static final int[] TrustedKeyUsage
private static final int[] AnyExtendedKeyUsage
private static final sun.security.util.ObjectIdentifier PKCS8ShroudedKeyBag_OID
private static final sun.security.util.ObjectIdentifier CertBag_OID
private static final sun.security.util.ObjectIdentifier SecretBag_OID
private static final sun.security.util.ObjectIdentifier PKCS9FriendlyName_OID
private static final sun.security.util.ObjectIdentifier PKCS9LocalKeyId_OID
private static final sun.security.util.ObjectIdentifier PKCS9CertType_OID
private static final sun.security.util.ObjectIdentifier pbes2_OID
private static final sun.security.util.ObjectIdentifier TrustedKeyUsage_OID
private static final sun.security.util.ObjectIdentifier[] AnyUsage
private static final int[] gmpbes2
private static final sun.security.util.ObjectIdentifier gmpbes2_OID
private static final Set<sun.security.util.ObjectIdentifier> PBES2_OID_LIST
private int counter
private int privateKeyCount
private int secretKeyCount
private int certificateCount
private String certProtectionAlgorithm
private int certPbeIterationCount
private String macAlgorithm
private int macIterationCount
private SecureRandom random
private Map<String,PKCS12KeyStore.Entry> entries
private ArrayList<PKCS12KeyStore.KeyEntry> keyList
private LinkedHashMap<X500Principal,X509Certificate> certsMap
private ArrayList<PKCS12KeyStore.CertEntry> certEntries
private static final long[][] PKCS12_HEADER_PATTERNS
private static final long[][] PKCS12_HEADER_MASKS
public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException
engineGetKey 在类中 KeyStoreSpialias - the alias namepassword - the password for recovering the keyNoSuchAlgorithmException - if the algorithm for recovering the
key cannot be foundUnrecoverableKeyException - if the key cannot be recovered
(e.g., the given password is wrong).public Certificate[] engineGetCertificateChain(String alias)
engineGetCertificateChain 在类中 KeyStoreSpialias - the alias namepublic Certificate engineGetCertificate(String 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.
engineGetCertificate 在类中 KeyStoreSpialias - the alias namepublic Date engineGetCreationDate(String alias)
engineGetCreationDate 在类中 KeyStoreSpialias - the alias namepublic void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException
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).
engineSetKeyEntry 在类中 KeyStoreSpialias - the alias namekey - the key to be associated with the aliaspassword - the password to protect the keychain - the certificate chain for the corresponding public
key (only required if the given key is of type
java.security.PrivateKey).KeyStoreException - if the given key cannot be protected, or
this operation fails for some other reasonprivate void setKeyEntry(String alias, Key key, KeyStore.PasswordProtection passwordProtection, Certificate[] chain, Set<KeyStore.Entry.Attribute> attributes) throws KeyStoreException
public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException
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
underlying keystore implementation is of type jks,
key must be encoded as an
EncryptedPrivateKeyInfo as defined in the PKCS #8 standard.
If the given alias already exists, the keystore information associated with it is overridden by the given key (and possibly certificate chain).
engineSetKeyEntry 在类中 KeyStoreSpialias - the alias namekey - the key (in protected format) to be associated with the aliaschain - the certificate chain for the corresponding public
key (only useful if the protected key is of type
java.security.PrivateKey).KeyStoreException - if this operation fails.private byte[] getSalt()
private AlgorithmParameters getPBEAlgorithmParameters(String algorithm, int iterationCount) throws IOException
IOExceptionprivate AlgorithmParameters parseAlgParameters(sun.security.util.ObjectIdentifier algorithm, sun.security.util.DerInputStream in) throws IOException
IOExceptionprivate SecretKey getPBEKey(char[] password) throws IOException
IOExceptionprivate byte[] encryptPrivateKey(byte[] data,
KeyStore.PasswordProtection passwordProtection)
throws IOException,
NoSuchAlgorithmException,
UnrecoverableKeyException
private static sun.security.util.ObjectIdentifier mapPBEAlgorithmToOID(String algorithm) throws NoSuchAlgorithmException
private static String mapPBEParamsToAlgorithm(sun.security.util.ObjectIdentifier algorithm, AlgorithmParameters algParams) throws NoSuchAlgorithmException
public void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException
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.
engineSetCertificateEntry 在类中 KeyStoreSpialias - the alias namecert - the certificateKeyStoreException - if the given alias already exists and does
not identify a trusted certificate entry, or this operation fails
for some other reason.private void setCertEntry(String alias, Certificate cert, Set<KeyStore.Entry.Attribute> attributes) throws KeyStoreException
public void engineDeleteEntry(String alias) throws KeyStoreException
engineDeleteEntry 在类中 KeyStoreSpialias - the alias nameKeyStoreException - if the entry cannot be removed.public Enumeration<String> engineAliases()
engineAliases 在类中 KeyStoreSpipublic boolean engineContainsAlias(String alias)
engineContainsAlias 在类中 KeyStoreSpialias - the alias namepublic int engineSize()
engineSize 在类中 KeyStoreSpipublic boolean engineIsKeyEntry(String alias)
engineIsKeyEntry 在类中 KeyStoreSpipublic boolean engineIsCertificateEntry(String alias)
engineIsCertificateEntry 在类中 KeyStoreSpipublic boolean engineEntryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass)
Entry for the specified
alias is an instance or subclass of the specified
entryClass.engineEntryInstanceOf 在类中 KeyStoreSpialias - the alias nameentryClass - the entry classEntry for the specified
alias is an instance or subclass of the
specified entryClass, false otherwisepublic String engineGetCertificateAlias(Certificate cert)
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).
engineGetCertificateAlias 在类中 KeyStoreSpicert - the certificate to match with.public void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
engineStore 在类中 KeyStoreSpistream - the output stream to which this keystore is written.password - the password to generate the keystore integrity checkIOException - if there was an I/O problem with dataNoSuchAlgorithmException - if the appropriate data integrity
algorithm could not be foundCertificateException - if any of the certificates included in
the keystore data could not be storedpublic KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException
KeyStore.Entry for the specified alias
with the specified protection parameter.engineGetEntry 在类中 KeyStoreSpialias - get the KeyStore.Entry for this aliasprotParam - the ProtectionParameter
used to protect the Entry,
which may be nullKeyStore.Entry for the specified alias,
or null if there is no such entryKeyStoreException - if the operation failedNoSuchAlgorithmException - if the algorithm for recovering the
entry cannot be foundUnrecoverableEntryException - if the specified
protParam were insufficient or invalidUnrecoverableKeyException - if the entry is a
PrivateKeyEntry or SecretKeyEntry
and the specified protParam does not contain
the information needed to recover the key (e.g. wrong password)public void engineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreException
KeyStore.Entry under the specified alias.
The specified protection parameter is used to protect the
Entry.
If an entry already exists for the specified alias, it is overridden.
engineSetEntry 在类中 KeyStoreSpialias - save the KeyStore.Entry under this aliasentry - the Entry to saveprotParam - the ProtectionParameter
used to protect the Entry,
which may be nullKeyStoreException - if this operation failsprivate Set<KeyStore.Entry.Attribute> getAttributes(PKCS12KeyStore.Entry entry)
private byte[] calculateMac(char[] passwd,
byte[] data)
throws IOException
IOExceptionprivate boolean validateChain(Certificate[] certChain)
private static void checkX509Certs(Certificate[] certs) throws KeyStoreException
private byte[] getBagAttributes(String alias, byte[] keyId, Set<KeyStore.Entry.Attribute> attributes) throws IOException
IOExceptionprivate byte[] getBagAttributes(String alias, byte[] keyId, sun.security.util.ObjectIdentifier[] trustedUsage, Set<KeyStore.Entry.Attribute> attributes) throws IOException
IOExceptionprivate byte[] createEncryptedData(char[] password)
throws CertificateException,
IOException
private byte[] createSafeContent()
throws CertificateException,
IOException
private byte[] encryptContent(byte[] data,
char[] password)
throws IOException
IOExceptionpublic void engineLoad(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
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.
engineLoad 在类中 KeyStoreSpistream - the input stream from which the keystore is loadedpassword - the (optional) password used to check the integrity of
the keystore.IOException - if there is an I/O or format problem with the
keystore dataNoSuchAlgorithmException - if the algorithm used to check
the integrity of the keystore cannot be foundCertificateException - if any of the certificates in the
keystore could not be loadedpublic static boolean isPasswordless(File f) throws IOException
engineLoad(java.io.InputStream, char[]) that only looks
at the ContentInfo types.f - the pkcs12 fileIOExceptionprivate X509Certificate findMatchedCertificate(PKCS12KeyStore.PrivateKeyEntry entry)
entry - the KeyEntry to matchprivate void loadSafeContents(sun.security.util.DerInputStream stream)
throws IOException,
NoSuchAlgorithmException,
CertificateException
private String getUnfriendlyName()
public boolean engineProbe(InputStream stream) throws IOException
IOExceptionprivate static boolean useLegacy()
private static String defaultCertProtectionAlgorithm()
private static int defaultCertPbeIterationCount()
private static String defaultKeyProtectionAlgorithm()
private static int defaultKeyPbeIterationCount()
private static String defaultMacAlgorithm()
private static int defaultMacIterationCount()
Copyright © 2023. All rights reserved.