cgl.narada.service.security.securityprovider
Class CertificateUtil

java.lang.Object
  extended by cgl.narada.service.security.securityprovider.CertificateUtil

public class CertificateUtil
extends Object

Util Class to write Certificates and private keys from keystore to files
Created on Apr 15, 2005
Acknowledgement: Ideas borrowed from the jCertServices package


Constructor Summary
CertificateUtil()
           
 
Method Summary
static Certificate getCertificate(CertificateManager certMan, String entity)
          Returns the X.509 certificate of specified entity from the keystore
static PrivateKey getPrivateKey(CertificateManager certMan, String alias)
          Generates a certificate for the specified entity.
static PublicKey getPublicKey(CertificateManager certMan, String entity)
          Returns the public key of the entity
static byte[] readPEM(InputStream is, String hdr, String ftr)
          readPEM: Read a PEM encoded base64 stream and decode it
static void saveCertsToFile(CertificateManager certMan, String alias, String outputCert, String outputKey)
           
static void savePrivateKey(PrivateKey priv, String outputFile)
           
static void saveX509Cert(X509Certificate cert, String outputFile)
           
static void SignCertificate(CertificateManager certMan, String csrFilePath, String alias)
           
static boolean ValidateCertificate(Certificate creds, PublicKey rootPubKey)
          Verifies the supplied Certificate against a root public key
static String writePEM(byte[] bytes, String hdr, String ftr)
          Write certficate bytes into a PEM encoded string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CertificateUtil

public CertificateUtil()
Method Detail

ValidateCertificate

public static boolean ValidateCertificate(Certificate creds,
                                          PublicKey rootPubKey)
Verifies the supplied Certificate against a root public key

Parameters:
creds - - Supplied Credentials
rootPubKey - - Root CA public key
Returns:
TRUE if the entity is verified, FALSE otherwise

SignCertificate

public static void SignCertificate(CertificateManager certMan,
                                   String csrFilePath,
                                   String alias)

saveCertsToFile

public static void saveCertsToFile(CertificateManager certMan,
                                   String alias,
                                   String outputCert,
                                   String outputKey)

getPrivateKey

public static PrivateKey getPrivateKey(CertificateManager certMan,
                                       String alias)
Generates a certificate for the specified entity. The only place where a Private key is returned

Parameters:
alias - - The entity for whom the certificate is to be created
D_NAME - - The comma seperated D_NAME of the entity
Returns:
- The private key of the generated entity. NULL if error occurs

getPublicKey

public static PublicKey getPublicKey(CertificateManager certMan,
                                     String entity)
Returns the public key of the entity

Parameters:
entity -
Returns:
The public key if found, NULL otherwise

getCertificate

public static Certificate getCertificate(CertificateManager certMan,
                                         String entity)
Returns the X.509 certificate of specified entity from the keystore

Parameters:
entity -
Returns:
X.509 certificate if found, NULL otherwise

saveX509Cert

public static void saveX509Cert(X509Certificate cert,
                                String outputFile)
                         throws GeneralSecurityException,
                                IOException
Throws:
GeneralSecurityException
IOException

savePrivateKey

public static void savePrivateKey(PrivateKey priv,
                                  String outputFile)
                           throws GeneralSecurityException,
                                  IOException
Throws:
GeneralSecurityException
IOException

writePEM

public static String writePEM(byte[] bytes,
                              String hdr,
                              String ftr)
                       throws IOException
Write certficate bytes into a PEM encoded string

Throws:
IOException

readPEM

public static byte[] readPEM(InputStream is,
                             String hdr,
                             String ftr)
                      throws IOException
readPEM: Read a PEM encoded base64 stream and decode it

Parameters:
is - Base64 PEM encoded stream
hdr - Header delimeter (e.g. ----------CERTIFICATE---------)
ftr - Footer delimeter (e.g. ----------END CERTIFICATE---------)
Returns:
decoded DER bytes
Throws:
IOException - if a read error occurs


For comments and suggestions please send e-mail to The NaradaBrokering Project