org.eclipse.emf.emfstore.internal.client.model.connectionmanager
Class KeyStoreManager

java.lang.Object
  extended by org.eclipse.emf.emfstore.internal.client.model.connectionmanager.KeyStoreManager
All Implemented Interfaces:
ESKeyStoreManager

public final class KeyStoreManager
extends Object
implements ESKeyStoreManager

The KeyStoreManager manages the client's KeyStore in which the SSL certificates for multiple EMFStore servers can be stored.

Author:
wesendon

Field Summary
static String DEFAULT_CERTIFICATE
          Certificate Alias for development test certificate.
static String KEYSTORENAME
          Name of keyStore file.
 
Method Summary
 void addCertificate(String alias, InputStream certificate)
          Adds a certificate to the KeyStore.
 void addCertificate(String alias, String path)
          Adds a certificate to the KeyStore.
 boolean certificateExists(String alias)
          Checks whether a certificate for a given alias exists.
 boolean contains(String alias)
          Returns true if the given alias maps to an existing certificate.
 void deleteCertificate(String alias)
          Deletes a certificate in the keystore.
 String encrypt(String password, ServerInfo server)
          Encrypts a password.
 Certificate getCertificate(String alias)
          Returns the certificate mapped by the given alias.
 ArrayList<String> getCertificates()
          Lists all certificates in the client's KeyStore.
 String getDefaultCertificate()
          Returns the default certificate alias.
static KeyStoreManager getInstance()
          Returns an instance of the KeyStoreManager.
 String getPathToKeyStore()
          Returns the path to the KeyStore.
 SSLContext getSSLContext()
          Returns a SSL Context.
 boolean isDefaultCertificate(String alias)
          Test whether a given alias is the default certificate alias.
 boolean keyStoreExists()
          True if a KeyStore file exists.
 void reloadKeyStore()
          Reloads the keystore.
 void removeCertificate(String alias)
          Remove certificate with the given alias.
 void setDefaultCertificate(String defaultCertificate)
          Sets the alias for the default certificate.
 void setupKeys()
          This method sets the JVM properties in order to use SSL encryption.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEYSTORENAME

public static final String KEYSTORENAME
Name of keyStore file.

See Also:
Constant Field Values

DEFAULT_CERTIFICATE

public static final String DEFAULT_CERTIFICATE
Certificate Alias for development test certificate.

See Also:
Constant Field Values
Method Detail

getInstance

public static KeyStoreManager getInstance()
Returns an instance of the KeyStoreManager.

Returns:
KeyStoreManager

setupKeys

public void setupKeys()
This method sets the JVM properties in order to use SSL encryption.


getCertificates

public ArrayList<String> getCertificates()
                                  throws ESCertificateException
Lists all certificates in the client's KeyStore.

Returns:
string representation of the certificates
Throws:
ESCertificateException - is thrown when problems occur with the CertificateStore, i.e. illegal operations.

deleteCertificate

public void deleteCertificate(String alias)
                       throws ESCertificateException
Deletes a certificate in the keystore.

Parameters:
alias - alias of certificate
Throws:
ESCertificateException - is thrown when problems occur with the CertificateStore, i.e. illegal operations.

addCertificate

public void addCertificate(String alias,
                           String path)
                    throws ESCertificateException
Adds a certificate to the KeyStore.

Specified by:
addCertificate in interface ESKeyStoreManager
Parameters:
alias - alias for the certificate
path - path to the certificate file
Throws:
ESCertificateException - if problems occur with storing, accessing or identifying the certificate
See Also:
ESKeyStoreManager.addCertificate(java.lang.String, java.lang.String)

removeCertificate

public void removeCertificate(String alias)
                       throws ESCertificateException
Remove certificate with the given alias.

Parameters:
alias - the certificate alias
Throws:
ESCertificateException - if removal fails

addCertificate

public void addCertificate(String alias,
                           InputStream certificate)
                    throws ESCertificateException
Adds a certificate to the KeyStore.

Specified by:
addCertificate in interface ESKeyStoreManager
Parameters:
alias - alias for the certificate
certificate - InputStream delivering the certificate. Stream is used by CertificateFactory.generateCertificate(InputStream).
Throws:
ESCertificateException - if problems occur with storing, accessing or identifying the certificate
See Also:
ESKeyStoreManager.addCertificate(java.lang.String, java.io.InputStream)

reloadKeyStore

public void reloadKeyStore()
                    throws ESCertificateException
Reloads the keystore.

Throws:
ESCertificateException - in case of failure

getSSLContext

public SSLContext getSSLContext()
                         throws ESCertificateException
Returns a SSL Context. This is need for encryption, used by the SSLSocketFactory.

Returns:
SSL Context
Throws:
ESCertificateException - in case of failure retrieving the context

keyStoreExists

public boolean keyStoreExists()
True if a KeyStore file exists.

Returns:
boolean

getPathToKeyStore

public String getPathToKeyStore()
Returns the path to the KeyStore.

Returns:
a path

encrypt

public String encrypt(String password,
                      ServerInfo server)
Encrypts a password.

Parameters:
password - the password to be encrypted
server - the server from which to fetch the public key that is used for encryption
Returns:
the encrypted password

isDefaultCertificate

public boolean isDefaultCertificate(String alias)
Test whether a given alias is the default certificate alias.

Parameters:
alias - alias under test
Returns:
true if default, false else

getDefaultCertificate

public String getDefaultCertificate()
Returns the default certificate alias.

Specified by:
getDefaultCertificate in interface ESKeyStoreManager
Returns:
the alias of the default certificate
See Also:
ESKeyStoreManager.getDefaultCertificate()

contains

public boolean contains(String alias)
                 throws ESCertificateException
Returns true if the given alias maps to an existing certificate.

Parameters:
alias - Certificate alias
Returns:
boolean
Throws:
ESCertificateException - is thrown when problems occur with the CertificateStore, i.e. illegal operations.

setDefaultCertificate

public void setDefaultCertificate(String defaultCertificate)
Sets the alias for the default certificate.

Specified by:
setDefaultCertificate in interface ESKeyStoreManager
Parameters:
defaultCertificate - certificate alias, use null to unset the currently set default certificate
See Also:
ESKeyStoreManager.setDefaultCertificate(java.lang.String)

getCertificate

public Certificate getCertificate(String alias)
                           throws ESCertificateException
Returns the certificate mapped by the given alias. Returns null if no such certificate exists.

Parameters:
alias - String
Returns:
Certificate
Throws:
ESCertificateException - is thrown when problems occur with the CertificateStore, i.e. illegal operations.

certificateExists

public boolean certificateExists(String alias)
                          throws ESCertificateException
Checks whether a certificate for a given alias exists.

Specified by:
certificateExists in interface ESKeyStoreManager
Parameters:
alias - the alias which needs to be check
Returns:
true if a certificate with the given alias exists, false otherwise
Throws:
ESCertificateException - in case of failure
See Also:
ESKeyStoreManager.certificateExists(java.lang.String)


Copyright © 2015. All Rights Reserved.