Package org.globus.gsi.stores
Class PEMKeyStore
- java.lang.Object
-
- java.security.KeyStoreSpi
-
- org.globus.gsi.stores.PEMKeyStore
-
public class PEMKeyStore extends java.security.KeyStoreSpiThis class provides a KeyStore implementation that supports trusted certificates stored in PEM format and proxy certificates stored in PEM format. It reads trusted certificates from multiple directories and a proxy certificate from a file.- Since:
- 1.0
- Version:
- ${version}
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,SecurityObjectWrapper<?>>aliasObjectMapprivate ResourceSecurityWrapperStore<ResourceTrustAnchor,java.security.cert.TrustAnchor>caDelegateprivate java.util.Map<java.security.cert.Certificate,java.lang.String>certFilenameMapstatic java.lang.StringCERTIFICATE_FILENAMEstatic java.lang.StringDEFAULT_DIRECTORY_KEYprivate java.io.FiledefaultDirectorystatic java.lang.StringDIRECTORY_LIST_KEYprivate booleaninMemoryOnlystatic java.lang.StringKEY_FILENAMEprivate static org.apache.commons.logging.Logloggerstatic java.lang.StringPROXY_FILENAMEprivate ResourceSecurityWrapperStore<ResourceProxyCredential,X509Credential>proxyDelegate
-
Constructor Summary
Constructors Constructor Description PEMKeyStore()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private CredentialWrappercreateCertKeyCredential(java.lang.String s, X509Credential credential)private CredentialWrappercreateProxyCredential(java.lang.String s, X509Credential credential)java.util.Enumeration<java.lang.String>engineAliases()Get an enumertion of all of the aliases in this keystore.booleanengineContainsAlias(java.lang.String s)Does the specified alias exist in this keystore?voidengineDeleteEntry(java.lang.String s)Delete a security object from this keystore.java.security.cert.CertificateengineGetCertificate(java.lang.String s)Get the certificate referenced by the supplied alias.java.lang.StringengineGetCertificateAlias(java.security.cert.Certificate certificate)Get the alias associated with the supplied certificate.java.security.cert.Certificate[]engineGetCertificateChain(java.lang.String s)Get the certificateChain for the key referenced by the alias.java.util.DateengineGetCreationDate(java.lang.String s)Get the creation date for the object referenced by the alias.java.security.KeyengineGetKey(java.lang.String s, char[] chars)Get the key referenced by the specified alias.booleanengineIsCertificateEntry(java.lang.String s)Does the supplied alias refer to a certificate in this keystore?booleanengineIsKeyEntry(java.lang.String s)Does the supplied alias refer to a key in this key store.voidengineLoad(java.io.InputStream inputStream, char[] chars)Load the keystore from the supplied input stream.voidengineLoad(java.security.KeyStore.LoadStoreParameter loadStoreParameter)Load the keystore based on parameters in the LoadStoreParameter.voidengineSetCertificateEntry(java.lang.String alias, java.security.cert.Certificate certificate)Add a certificate to the keystore.voidengineSetKeyEntry(java.lang.String s, byte[] bytes, java.security.cert.Certificate[] certificates)currently unsupported.voidengineSetKeyEntry(java.lang.String s, java.security.Key key, char[] chars, java.security.cert.Certificate[] certificates)Add a new private key to the keystore.intengineSize()Get the number of security objects stored in this keystore.voidengineStore(java.io.OutputStream outputStream, char[] chars)Persist the security material in this keystore.private ResourceTrustAnchorgetCertificateEntry(java.lang.String alias)private CredentialWrappergetKeyEntry(java.lang.String alias)private voidinitialize(java.lang.String defaultDirectoryString, java.lang.String directoryListString, java.lang.String proxyFilename, java.lang.String certFilename, java.lang.String keyFilename)Initialize resources from filename, proxyfile nameprivate voidloadCertificateKey(java.lang.String userCertFilename, java.lang.String userKeyFilename)private voidloadDirectories(java.lang.String directoryList)private voidloadProxyCertificate(java.lang.String proxyFilename)voidsetCACertStore(ResourceSecurityWrapperStore<ResourceTrustAnchor,java.security.cert.TrustAnchor> caCertStore)voidsetProxyDelegate(ResourceSecurityWrapperStore<ResourceProxyCredential,X509Credential> proxyDelegate)private voidstoreWrapper(CredentialWrapper wrapper)
-
-
-
Field Detail
-
DEFAULT_DIRECTORY_KEY
public static final java.lang.String DEFAULT_DIRECTORY_KEY
- See Also:
- Constant Field Values
-
DIRECTORY_LIST_KEY
public static final java.lang.String DIRECTORY_LIST_KEY
- See Also:
- Constant Field Values
-
CERTIFICATE_FILENAME
public static final java.lang.String CERTIFICATE_FILENAME
- See Also:
- Constant Field Values
-
KEY_FILENAME
public static final java.lang.String KEY_FILENAME
- See Also:
- Constant Field Values
-
PROXY_FILENAME
public static final java.lang.String PROXY_FILENAME
- See Also:
- Constant Field Values
-
logger
private static org.apache.commons.logging.Log logger
-
aliasObjectMap
private java.util.Map<java.lang.String,SecurityObjectWrapper<?>> aliasObjectMap
-
certFilenameMap
private java.util.Map<java.security.cert.Certificate,java.lang.String> certFilenameMap
-
defaultDirectory
private java.io.File defaultDirectory
-
caDelegate
private ResourceSecurityWrapperStore<ResourceTrustAnchor,java.security.cert.TrustAnchor> caDelegate
-
proxyDelegate
private ResourceSecurityWrapperStore<ResourceProxyCredential,X509Credential> proxyDelegate
-
inMemoryOnly
private boolean inMemoryOnly
-
-
Method Detail
-
setCACertStore
public void setCACertStore(ResourceSecurityWrapperStore<ResourceTrustAnchor,java.security.cert.TrustAnchor> caCertStore)
-
setProxyDelegate
public void setProxyDelegate(ResourceSecurityWrapperStore<ResourceProxyCredential,X509Credential> proxyDelegate)
-
getKeyEntry
private CredentialWrapper getKeyEntry(java.lang.String alias)
-
getCertificateEntry
private ResourceTrustAnchor getCertificateEntry(java.lang.String alias)
-
engineGetKey
public java.security.Key engineGetKey(java.lang.String s, char[] chars) throws java.security.NoSuchAlgorithmException, java.security.UnrecoverableKeyExceptionGet the key referenced by the specified alias.- Specified by:
engineGetKeyin classjava.security.KeyStoreSpi- Parameters:
s- The key's alias.chars- The key's password.- Returns:
- The key reference by the alias or null.
- Throws:
java.security.NoSuchAlgorithmException- If the key is encoded with an invalid algorithm.java.security.UnrecoverableKeyException- If the key can not be retrieved.
-
engineIsKeyEntry
public boolean engineIsKeyEntry(java.lang.String s)
Does the supplied alias refer to a key in this key store.- Specified by:
engineIsKeyEntryin classjava.security.KeyStoreSpi- Parameters:
s- The alias.- Returns:
- True if the alias refers to a key.
-
engineStore
public void engineStore(java.io.OutputStream outputStream, char[] chars) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionPersist the security material in this keystore. If the object has a path associated with it, the object will be persisted to that path. Otherwise it will be stored in the default certificate directory. As a result, the parameters of this method are ignored.- Specified by:
engineStorein classjava.security.KeyStoreSpi- Parameters:
outputStream- This parameter is ignored.chars- This parameter is ignored.- Throws:
java.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
engineGetCreationDate
public java.util.Date engineGetCreationDate(java.lang.String s)
Get the creation date for the object referenced by the alias.- Specified by:
engineGetCreationDatein classjava.security.KeyStoreSpi- Parameters:
s- The alias of the security object.- Returns:
- The creation date of the security object.
-
engineGetCertificateAlias
public java.lang.String engineGetCertificateAlias(java.security.cert.Certificate certificate)
Get the alias associated with the supplied certificate.- Specified by:
engineGetCertificateAliasin classjava.security.KeyStoreSpi- Parameters:
certificate- The certificate to query- Returns:
- The certificate's alias or null if the certificate is not present in this keystore.
-
engineGetCertificateChain
public java.security.cert.Certificate[] engineGetCertificateChain(java.lang.String s)
Get the certificateChain for the key referenced by the alias.- Specified by:
engineGetCertificateChainin classjava.security.KeyStoreSpi- Parameters:
s- The key alias.- Returns:
- The key's certificate chain or a 0 length array if the key is not in the keystore.
-
engineGetCertificate
public java.security.cert.Certificate engineGetCertificate(java.lang.String s)
Get the certificate referenced by the supplied alias.- Specified by:
engineGetCertificatein classjava.security.KeyStoreSpi- Parameters:
s- The alias.- Returns:
- The Certificate or null if the alias does not exist in the keyStore.
-
engineLoad
public void engineLoad(java.security.KeyStore.LoadStoreParameter loadStoreParameter) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionLoad the keystore based on parameters in the LoadStoreParameter. The parameter object must be an instance of FileBasedKeyStoreParameters.- Overrides:
engineLoadin classjava.security.KeyStoreSpi- Parameters:
loadStoreParameter- The parameters to load.- Throws:
java.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
engineLoad
public void engineLoad(java.io.InputStream inputStream, char[] chars) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionLoad the keystore from the supplied input stream. Unlike many other implementations of keystore (most notably the default JKS implementation), the input stream does not hold the keystore objects. Instead, it must be a properties file defining the locations of the keystore objects. The password is not used.- Specified by:
engineLoadin classjava.security.KeyStoreSpi- Parameters:
inputStream- An input stream to the properties file.chars- The password is not used.- Throws:
java.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
initialize
private void initialize(java.lang.String defaultDirectoryString, java.lang.String directoryListString, java.lang.String proxyFilename, java.lang.String certFilename, java.lang.String keyFilename) throws java.io.IOException, java.security.cert.CertificateExceptionInitialize resources from filename, proxyfile name- Parameters:
defaultDirectoryString- Name of the default directory name as: "file: directory name"directoryListString-proxyFilename-certFilename-keyFilename-- Throws:
java.io.IOExceptionjava.security.cert.CertificateException
-
loadProxyCertificate
private void loadProxyCertificate(java.lang.String proxyFilename) throws ResourceStoreException- Throws:
ResourceStoreException
-
loadCertificateKey
private void loadCertificateKey(java.lang.String userCertFilename, java.lang.String userKeyFilename) throws CredentialException, ResourceStoreException
-
loadDirectories
private void loadDirectories(java.lang.String directoryList) throws java.security.cert.CertificateException- Throws:
java.security.cert.CertificateException
-
engineDeleteEntry
public void engineDeleteEntry(java.lang.String s) throws java.security.KeyStoreExceptionDelete a security object from this keystore.- Specified by:
engineDeleteEntryin classjava.security.KeyStoreSpi- Parameters:
s- The alias of the object to delete.- Throws:
java.security.KeyStoreException
-
engineAliases
public java.util.Enumeration<java.lang.String> engineAliases()
Get an enumertion of all of the aliases in this keystore.- Specified by:
engineAliasesin classjava.security.KeyStoreSpi- Returns:
- An enumeration of the aliases in this keystore.
-
engineSetKeyEntry
public void engineSetKeyEntry(java.lang.String s, java.security.Key key, char[] chars, java.security.cert.Certificate[] certificates) throws java.security.KeyStoreExceptionAdd a new private key to the keystore.- Specified by:
engineSetKeyEntryin classjava.security.KeyStoreSpi- Parameters:
s- The alias for the object.key- The private key.chars- The password.certificates- The key's certificate chain.- Throws:
java.security.KeyStoreException
-
createProxyCredential
private CredentialWrapper createProxyCredential(java.lang.String s, X509Credential credential) throws java.security.KeyStoreException
- Throws:
java.security.KeyStoreException
-
createCertKeyCredential
private CredentialWrapper createCertKeyCredential(java.lang.String s, X509Credential credential) throws java.security.KeyStoreException
- Throws:
java.security.KeyStoreException
-
storeWrapper
private void storeWrapper(CredentialWrapper wrapper) throws java.security.KeyStoreException
- Throws:
java.security.KeyStoreException
-
engineSetKeyEntry
public void engineSetKeyEntry(java.lang.String s, byte[] bytes, java.security.cert.Certificate[] certificates) throws java.security.KeyStoreExceptioncurrently unsupported.- Specified by:
engineSetKeyEntryin classjava.security.KeyStoreSpi- Parameters:
s- The key's aliasbytes- The encoded private key.certificates- The key's certificate chain.- Throws:
java.security.KeyStoreException
-
engineContainsAlias
public boolean engineContainsAlias(java.lang.String s)
Does the specified alias exist in this keystore?- Specified by:
engineContainsAliasin classjava.security.KeyStoreSpi- Parameters:
s- The alias.- Returns:
- True if the alias refers to a security object in the keystore.
-
engineSize
public int engineSize()
Get the number of security objects stored in this keystore.- Specified by:
engineSizein classjava.security.KeyStoreSpi- Returns:
- The number of security objects.
-
engineIsCertificateEntry
public boolean engineIsCertificateEntry(java.lang.String s)
Does the supplied alias refer to a certificate in this keystore?- Specified by:
engineIsCertificateEntryin classjava.security.KeyStoreSpi- Parameters:
s- The alias.- Returns:
- True if this store contains a certificate with the specified alias.
-
engineSetCertificateEntry
public void engineSetCertificateEntry(java.lang.String alias, java.security.cert.Certificate certificate) throws java.security.KeyStoreExceptionAdd a certificate to the keystore.- Specified by:
engineSetCertificateEntryin classjava.security.KeyStoreSpi- Parameters:
alias- The certificate alias.certificate- The certificate to store.- Throws:
java.security.KeyStoreException
-
-