org.glite.security.util
Class FileCertReader

java.lang.Object
  extended by org.glite.security.util.FileCertReader

public class FileCertReader
extends java.lang.Object

Reads all certificates from given files, accepts binary form of DER encoded certs and the Base64 form of the DER encoded certs (PEM). The base64 certs can contain garbage in front of the actual certificate that has to begin with "-----BEGIN". Should accept multiple certs in one file, not tested!

Author:
Joni Hahkala Created on March 27, 2002, 8:24 PM

Constructor Summary
FileCertReader()
          Creates a new instance of CertReader.
FileCertReader(java.security.Provider provider)
          Creates a new instance of CertReader with the specified provider.
FileCertReader(java.lang.String provider)
          Creates a new instance of CertReader with the specified provider
 
Method Summary
 java.lang.Object objectReader(java.io.BufferedInputStream binStream, int type)
          Reads a certificate or a CRL from the stream, doing some error correction.
 java.util.Vector readAnchors(java.lang.String files)
          Reads the certificates from the files defined in the argument and makes TrustAnchors from them.
 java.util.Vector readCerts(java.lang.String files)
          Reads the certificates from the files defined in the argument.
 java.util.Vector readCRLs(java.lang.String files)
          Reads the certificate revocation lists (CRLs) from the files defined in the argument.
 java.util.Vector readFile(java.io.File certFile, int type)
          Reads the objects of given type from the File.
 java.lang.Object readObject(java.io.BufferedInputStream binStream, int type)
          Does the actual reading of the object.
 java.security.KeyStore readProxy(java.io.BufferedInputStream stream, java.lang.String storePasswd)
          Reads a grid proxy from a stream.
static void skipEmptyLines(java.io.BufferedInputStream stream)
          Skips empty lines in the stream.
static void skipToCertBeginning(java.io.BufferedInputStream stream)
          Skips everything in front of "-----BEGIN" in the stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileCertReader

public FileCertReader()
               throws java.security.cert.CertificateException
Creates a new instance of CertReader.

Throws:
java.security.cert.CertificateException

FileCertReader

public FileCertReader(java.security.Provider provider)
               throws java.security.cert.CertificateException
Creates a new instance of CertReader with the specified provider.

Parameters:
provider - the provider to be used in creating the certificates etc.
Throws:
java.security.cert.CertificateException

FileCertReader

public FileCertReader(java.lang.String provider)
               throws java.security.cert.CertificateException
Creates a new instance of CertReader with the specified provider

Parameters:
provider - the provider to be used in creating the certificates etc.
Throws:
java.security.cert.CertificateException
Method Detail

readCerts

public java.util.Vector readCerts(java.lang.String files)
                           throws java.io.IOException,
                                  java.security.cert.CertificateException
Reads the certificates from the files defined in the argument. See DirectoryList for file definition format.

Parameters:
files - The file definition.
Returns:
Returns the Vector of certificates read.
Throws:
java.lang.Exception - Thrown if certificate reading from the files fails.
java.io.IOException
java.security.cert.CertificateException
See Also:
DirectoryList

readAnchors

public java.util.Vector readAnchors(java.lang.String files)
                             throws java.io.IOException,
                                    java.security.cert.CertificateException
Reads the certificates from the files defined in the argument and makes TrustAnchors from them. See DirectoryList for file definition format.

Parameters:
files - The file definition.
Returns:
Returns a Vector of TrustAnchors read from the files.
Throws:
java.lang.Exception - Thrown if the certificate reading fails.
java.io.IOException
java.security.cert.CertificateException
See Also:
DirectoryList

readCRLs

public java.util.Vector readCRLs(java.lang.String files)
                          throws java.io.IOException,
                                 java.security.cert.CertificateException
Reads the certificate revocation lists (CRLs) from the files defined in the argument. See DirectoryList for file definition format.

Parameters:
files - The file definition.
Returns:
Returns a vector of CRLs read from the files.
Throws:
java.lang.Exception - Thrown if the CRL reading failed.
java.io.IOException
java.security.cert.CertificateException
See Also:
DirectoryList

readFile

public java.util.Vector readFile(java.io.File certFile,
                                 int type)
                          throws java.io.IOException
Reads the objects of given type from the File.

Parameters:
certFile - The file to read.
type - The type of objects to read form the file.
Returns:
Returns the Vector of objects read form the file.
Throws:
java.io.IOException - Thrown if the reading of objects of given type fails.

objectReader

public java.lang.Object objectReader(java.io.BufferedInputStream binStream,
                                     int type)
                              throws java.security.cert.CertificateException,
                                     java.io.IOException
Reads a certificate or a CRL from the stream, doing some error correction.

Parameters:
binStream - The stream to read the object from.
type - The type of object to read from the stream.
Returns:
Returns the object read.
Throws:
java.security.cert.CertificateException - Thrown if an error occurs while reading the object.
java.io.IOException - Thrown if an error occurs while reading the object.

readObject

public java.lang.Object readObject(java.io.BufferedInputStream binStream,
                                   int type)
                            throws java.security.cert.CertificateException
Does the actual reading of the object.

Parameters:
binStream - The stream to read the object from.
type - The type of the object.
Returns:
Returns the object read or null if no object was found.
Throws:
java.security.cert.CertificateException - Thrown if there is a problem reading the object.

skipToCertBeginning

public static void skipToCertBeginning(java.io.BufferedInputStream stream)
                                throws java.io.IOException
Skips everything in front of "-----BEGIN" in the stream.

Parameters:
stream - The stream to read and skip.
Throws:
java.io.IOException - Thrown if there is a problem skipping.

skipEmptyLines

public static void skipEmptyLines(java.io.BufferedInputStream stream)
                           throws java.io.IOException
Skips empty lines in the stream.

Parameters:
stream - The stream possibly containing empty lines.
Throws:
java.io.IOException - Thrown if a problem occurs.

readProxy

public java.security.KeyStore readProxy(java.io.BufferedInputStream stream,
                                        java.lang.String storePasswd)
                                 throws java.io.IOException
Reads a grid proxy from a stream.

Parameters:
stream - the stream to read the proxy from.
storePasswd - the password used for the private key if any.
Returns:
a keystore containing the credentials read.
Throws:
java.io.IOException - in case of error.