eu.xtreemos.xosd.utilities.security
Class ServiceTrustStore

java.lang.Object
  extended by eu.xtreemos.xosd.utilities.security.ServiceTrustStore

public class ServiceTrustStore
extends java.lang.Object

Provides tools for checking the validity of the certificates inside service calls.

Author:
ales.cernivec@xlab.si

Field Summary
private static java.lang.String clientCertificateFile
          These are for testing purposes.
private static java.lang.String localTrustStore
           
(package private) static org.apache.log4j.Logger logger
           
private static java.lang.String serverCertificateFile
           
private  javax.net.ssl.TrustManager[] trustManagers
           
private static java.security.KeyStore trustStore
           
 
Constructor Summary
ServiceTrustStore()
           
 
Method Summary
static boolean checkValidity(java.security.cert.X509Certificate clientCertificate)
          Method checks validity of the clientCertificate cert with the KeyStore initiated using initiateTrustStore(HashMap) method.
private  javax.net.ssl.SSLContext createTruestContext(java.security.cert.X509Certificate cdaCert)
          Creating context which provides secure sockets for the CDA server connection used in connectToCDA method.
private  javax.net.ssl.TrustManager[] createTrustManagers(java.security.KeyStore trustStore)
          Initialize trust manager.
private  java.security.KeyStore createTrustStore(java.security.cert.X509Certificate trustedServerCertificate, java.lang.String alias)
          This creates KeyStore into which trustedServerCertificate is added as trusted key certificate.
private static java.util.HashMap<java.lang.String,java.security.cert.X509Certificate> getCertMap(java.io.File policyStorageDirectory)
          Reads a directory for PEM certificates and ads them to hashmap (with aliases).
static java.security.KeyStore getTrustedCertKeyStore()
          Retrieve the keystore containing the trusted certificates.
static java.security.KeyStore getTrustedCertKeyStore(java.lang.String path)
          Retrieve a custom keystore containing certificates in a provided path.
static void initiate(java.lang.String pathToTrustStore)
          Calls getCertMap(File) and initiateTrustStore(HashMap) respectively.
private static java.security.KeyStore initiateTrustStore(java.util.HashMap<java.lang.String,java.security.cert.X509Certificate> certMap)
          Initiates KeyStore with certificates, provided with certMap parameter.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

static org.apache.log4j.Logger logger

trustManagers

private javax.net.ssl.TrustManager[] trustManagers

trustStore

private static java.security.KeyStore trustStore

clientCertificateFile

private static java.lang.String clientCertificateFile
These are for testing purposes.


serverCertificateFile

private static java.lang.String serverCertificateFile

localTrustStore

private static java.lang.String localTrustStore
Constructor Detail

ServiceTrustStore

public ServiceTrustStore()
Method Detail

getCertMap

private static java.util.HashMap<java.lang.String,java.security.cert.X509Certificate> getCertMap(java.io.File policyStorageDirectory)
                                                                                          throws java.lang.Exception
Reads a directory for PEM certificates and ads them to hashmap (with aliases). If there exist private keys or files other than valid public certificates (X509Certificate)

Returns:
hash map of certificates.
Throws:
java.lang.Exception

initiateTrustStore

private static java.security.KeyStore initiateTrustStore(java.util.HashMap<java.lang.String,java.security.cert.X509Certificate> certMap)
                                                  throws java.lang.Exception
Initiates KeyStore with certificates, provided with certMap parameter.

Parameters:
HashMap - containing aliases and public certificates.
Throws:
java.lang.Exception

initiate

public static void initiate(java.lang.String pathToTrustStore)
                     throws java.lang.Exception
Calls getCertMap(File) and initiateTrustStore(HashMap) respectively.

Parameters:
pathToTrustStore - path to keystore.
Throws:
java.lang.Exception

checkValidity

public static boolean checkValidity(java.security.cert.X509Certificate clientCertificate)
                             throws java.lang.Exception
Method checks validity of the clientCertificate cert with the KeyStore initiated using initiateTrustStore(HashMap) method.

Parameters:
trustedServerCertificate -
clientCertificate -
Returns:
Throws:
java.lang.Exception

createTrustStore

private java.security.KeyStore createTrustStore(java.security.cert.X509Certificate trustedServerCertificate,
                                                java.lang.String alias)
This creates KeyStore into which trustedServerCertificate is added as trusted key certificate.

Parameters:
trustedServerCertificate -
alias - for the certificate
Returns:

createTrustManagers

private javax.net.ssl.TrustManager[] createTrustManagers(java.security.KeyStore trustStore)
Initialize trust manager.

Parameters:
trustStore -
Returns:

createTruestContext

private javax.net.ssl.SSLContext createTruestContext(java.security.cert.X509Certificate cdaCert)
Creating context which provides secure sockets for the CDA server connection used in connectToCDA method.

Parameters:
cdaCert - Certificate to use as handshake certificate.
Returns:

getTrustedCertKeyStore

public static java.security.KeyStore getTrustedCertKeyStore()
Retrieve the keystore containing the trusted certificates.

Returns:
The keystore containing the trusted certificates.

getTrustedCertKeyStore

public static java.security.KeyStore getTrustedCertKeyStore(java.lang.String path)
                                                     throws java.lang.Exception
Retrieve a custom keystore containing certificates in a provided path. Unlike getTrustedCertKeyStore(), this call actually reads the certificate files in each call.

Parameters:
path - The path containing the certificates of the trusted CAs.
Returns:
The keystore containing the trusted certificates.
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Parameters:
args -
Throws:
java.lang.Exception