org.glite.slcs.pki
Class Certificate

java.lang.Object
  extended by org.glite.slcs.pki.Certificate

public class Certificate
extends java.lang.Object

Certificate is a wrapper class for the X509Certificate. Used to store a certificate with its chain and read/write it from/to file.

Version:
$Revision: 1.3 $
Author:
Valery Tschopp

Field Summary
static int CRT_FILE_PERMISSION
          Default unix file permissions for the certificate file
 
Constructor Summary
Certificate(java.security.cert.X509Certificate cert)
          Creates a certificate without chain.
Certificate(java.security.cert.X509Certificate cert, java.security.cert.X509Certificate[] chain)
          Creates a certificate with its chain.
 
Method Summary
 java.security.cert.X509Certificate getCertificate()
           
 java.security.cert.X509Certificate[] getCertificateChain()
           
 java.lang.String getPEM()
          Returns the PEM encoded certificate
static Certificate readPEM(java.io.Reader reader)
          Read a PEM source to extract the certificate and its chain.
 void storePEM(java.io.File file)
          Stores the ceritifcate and its chain in PEM format in the given file.
 void storePEM(java.lang.String filename)
          Stores the certificate and its chain in PEM format in the given file name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CRT_FILE_PERMISSION

public static final int CRT_FILE_PERMISSION
Default unix file permissions for the certificate file

See Also:
Constant Field Values
Constructor Detail

Certificate

public Certificate(java.security.cert.X509Certificate cert,
                   java.security.cert.X509Certificate[] chain)
            throws java.security.GeneralSecurityException
Creates a certificate with its chain.

Parameters:
cert - The X509Certificate
chain - The chain as an array of X509Ceritificate.
Throws:
java.security.GeneralSecurityException - If the certificate is null.

Certificate

public Certificate(java.security.cert.X509Certificate cert)
            throws java.security.GeneralSecurityException
Creates a certificate without chain.

Parameters:
cert - The X509Certificate.
Throws:
java.security.GeneralSecurityException - If the X509Certificate is null.
Method Detail

readPEM

public static Certificate readPEM(java.io.Reader reader)
                           throws java.io.IOException,
                                  java.security.GeneralSecurityException
Read a PEM source to extract the certificate and its chain. The certificate must be the first in the source, all others are considered as chain members.

Parameters:
reader - The Reader to read the source.
Returns:
The Certificate (with its chain)
Throws:
java.io.IOException - If an error occurs while reading the source.
java.security.GeneralSecurityException - If an error occurs while creating the Certificate.

storePEM

public void storePEM(java.lang.String filename)
              throws java.io.IOException
Stores the certificate and its chain in PEM format in the given file name. OpenSSL compatible.

Parameters:
filename - The file name to store into.
Throws:
java.io.IOException - If an error occurs while writing the cert.

storePEM

public void storePEM(java.io.File file)
              throws java.io.IOException
Stores the ceritifcate and its chain in PEM format in the given file. The file permission is set as CRT_FILE_PERMISSION (octal: 640). OpenSSL compatible.

Parameters:
file - The file to write into.
Throws:
java.io.IOException

getPEM

public java.lang.String getPEM()
Returns the PEM encoded certificate

Returns:
The PEM encoded string

getCertificateChain

public java.security.cert.X509Certificate[] getCertificateChain()
Returns:
the X509 certificate

getCertificate

public java.security.cert.X509Certificate getCertificate()
Returns:
the X509 certificate chain