org.glite.security.delegation
Class GrDPX509Util

java.lang.Object
  extended byorg.glite.security.delegation.GrDPX509Util

public class GrDPX509Util
extends java.lang.Object

Author:
Mehran Ahsant

Constructor Summary
GrDPX509Util()
           
 
Method Summary
static byte[] certChainToByte(java.security.cert.X509Certificate[] x509Cert)
          Convert array of x509certificates into byte format of PEMs
static java.lang.String certProxyResponse(java.lang.String proxyCert)
          Returns a proxy certificate in HTTP MIME type format
static java.lang.String certReqResponse(java.lang.String certReq)
          Returns a certificate request in HTTP MIME type format
static boolean changeFileMode(java.lang.String file, int mode)
          Change fime permission
static java.lang.String digestFileName(java.lang.String delegationid_in, java.lang.String DN_in)
          Returns SHA1 hash digest of file name based on given delegationID and DER encoded DN in form of SHA1_HASH(DelegationID)+"-"+SHA1_HASH(DN)
static java.lang.String errorResponse(java.lang.String errorMsg)
          Returns an error message in case of fails
static java.lang.String findPrivateKeyInCache(java.lang.String strDirCache, java.lang.String delegationID, java.lang.String userDN)
          Search for associated private key in cache
static java.lang.String findProxyInCache(java.lang.String strDirCache, java.lang.String delegationID, java.lang.String userDN)
          Search for a generated proxy in cache
static java.lang.String getDefaultCertFile()
          Retrieves the location of the user cert file.
static java.lang.String getDefaultCertLocation()
          Retrieves the location of the CA cert files.
static java.lang.String getDefaultKeyFile()
          Retrieves the location of the user key file.
static java.lang.String getDefaultProxyFile()
          Retrieves the location of the proxy file.
static java.lang.String getDlgeePropertyFile()
          Retrieve the path to the delegatee property file
static java.lang.String getDlgorPropertyFile()
          Retrieve the path to the delegator property file
static byte[] getFilesBytes(java.io.File file)
          Reading IO file in byte
static java.lang.String getOSEnvironment(java.lang.String envName)
          Retrieve the value of environment variable
static java.security.cert.X509Certificate loadCertificate(java.io.InputStream cert)
          Load x509 certificate
static java.security.cert.X509Certificate[] loadCertificateChain(java.io.BufferedInputStream bisCerts)
          Load a chain of certificates from BIS
static java.security.cert.X509Certificate[] loadCertificateChain(byte[] bCerts)
          Load chain of certificates from byte
static org.bouncycastle.asn1.x509.X509Name makeGridCertDN(java.lang.String DN)
          Create an X509 Certificate DN
static org.bouncycastle.asn1.x509.X509Name makeGridCertDN(java.lang.String organization, java.lang.String orgUnit, java.lang.String commonName, java.lang.String country, java.lang.String email)
          Create an X509 Certificate DN
static byte[] readPEM(java.io.InputStream is, java.lang.String hdr, java.lang.String ftr)
          Read a PEM encoded base64 stream and decode it
static void saveCertProxyTofile(java.lang.String certProxy, java.lang.String fileLocation, java.lang.String delegationID, java.lang.String userDN, boolean append)
          save a proxy certificate in specific location
static void saveCertProxyTofile(java.security.cert.X509Certificate certProxy, java.lang.String fileLocation)
          save a proxy certificate in specific location
static void saveCertReqToFile(java.lang.String certReq, java.lang.String fileLocation)
          Save a certificate request in specific location
static void savePrivateKey(java.security.PrivateKey pk, java.lang.String fileLocation, java.lang.String delegationID, java.lang.String userDN)
          save a private key in specific location
static java.lang.String writePEM(byte[] bytes, java.lang.String hdr, java.lang.String ftr)
          Generate a PEM encoded string of certificate from a header and a footer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GrDPX509Util

public GrDPX509Util()
Method Detail

writePEM

public static java.lang.String writePEM(byte[] bytes,
                                        java.lang.String hdr,
                                        java.lang.String ftr)
                                 throws java.io.IOException
Generate a PEM encoded string of certificate from a header and a footer

Parameters:
bytes - input stream
hdr - Header delimeter of certificate
ftr - footer delimeter of certificate
Returns:
encoded byte in pem
Throws:
java.io.IOException

readPEM

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

Parameters:
is - Base64 PEM encoded stream
hdr - Header delimeter
ftr - Footer delimeter
Returns:
decoded DER bytes
Throws:
java.io.IOException - if a read error occurs

makeGridCertDN

public static org.bouncycastle.asn1.x509.X509Name makeGridCertDN(java.lang.String organization,
                                                                 java.lang.String orgUnit,
                                                                 java.lang.String commonName,
                                                                 java.lang.String country,
                                                                 java.lang.String email)
Create an X509 Certificate DN

Parameters:
orgUnit - Organization Unit
email - Email address
Returns:
X509Name of generated DN

makeGridCertDN

public static org.bouncycastle.asn1.x509.X509Name makeGridCertDN(java.lang.String DN)
Create an X509 Certificate DN

Returns:
X509Name of DN

saveCertReqToFile

public static void saveCertReqToFile(java.lang.String certReq,
                                     java.lang.String fileLocation)
                              throws java.io.IOException
Save a certificate request in specific location

Parameters:
certReq - given certificate request to save
fileLocation - location of certificare request
Throws:
java.io.IOException

saveCertProxyTofile

public static void saveCertProxyTofile(java.security.cert.X509Certificate certProxy,
                                       java.lang.String fileLocation)
save a proxy certificate in specific location

Parameters:
certProxy - Given proxy certificate to save
fileLocation - location of proxy certificate

saveCertProxyTofile

public static void saveCertProxyTofile(java.lang.String certProxy,
                                       java.lang.String fileLocation,
                                       java.lang.String delegationID,
                                       java.lang.String userDN,
                                       boolean append)
save a proxy certificate in specific location

Parameters:
certProxy - Given proxy certificate to save
fileLocation - location of proxy certificate
delegationID -
userDN -

savePrivateKey

public static void savePrivateKey(java.security.PrivateKey pk,
                                  java.lang.String fileLocation,
                                  java.lang.String delegationID,
                                  java.lang.String userDN)
save a private key in specific location

Parameters:
pk - Given private key to save
fileLocation - location of private key
delegationID -
userDN -

findProxyInCache

public static java.lang.String findProxyInCache(java.lang.String strDirCache,
                                                java.lang.String delegationID,
                                                java.lang.String userDN)
Search for a generated proxy in cache

Parameters:
strDirCache - cache directory
delegationID - Delegation ID
userDN - UserDN
Returns:
File name of proxy

findPrivateKeyInCache

public static java.lang.String findPrivateKeyInCache(java.lang.String strDirCache,
                                                     java.lang.String delegationID,
                                                     java.lang.String userDN)
Search for associated private key in cache

Parameters:
strDirCache - cache directory
delegationID - Delegation ID
userDN - UserDN
Returns:
File name of private key

loadCertificate

public static java.security.cert.X509Certificate loadCertificate(java.io.InputStream cert)
                                                          throws java.io.IOException,
                                                                 java.security.GeneralSecurityException
Load x509 certificate

Parameters:
cert - certificate to load
Returns:
X509 Certificate
Throws:
java.io.IOException
java.security.GeneralSecurityException

loadCertificateChain

public static java.security.cert.X509Certificate[] loadCertificateChain(byte[] bCerts)
                                                                 throws java.io.IOException,
                                                                        java.security.GeneralSecurityException
Load chain of certificates from byte

Parameters:
bCerts -
Returns:
Array of loaded certificates
Throws:
java.io.IOException
java.security.GeneralSecurityException

loadCertificateChain

public static java.security.cert.X509Certificate[] loadCertificateChain(java.io.BufferedInputStream bisCerts)
                                                                 throws java.io.IOException,
                                                                        java.security.GeneralSecurityException
Load a chain of certificates from BIS

Parameters:
bisCerts -
Returns:
Array of loaded certificates
Throws:
java.io.IOException
java.security.GeneralSecurityException

changeFileMode

public static boolean changeFileMode(java.lang.String file,
                                     int mode)
Change fime permission

Parameters:
file - File name
mode - New Permission
Returns:
True if file mode has changed

getDefaultCertFile

public static java.lang.String getDefaultCertFile()
Retrieves the location of the user cert file. from X509_USER_CERT.

Returns:
String the location of the user cert file

getDefaultKeyFile

public static java.lang.String getDefaultKeyFile()
Retrieves the location of the user key file. from X509_USER_KEY.

Returns:
String the location of the user key file

getDefaultCertLocation

public static java.lang.String getDefaultCertLocation()
Retrieves the location of the CA cert files. from X509_CERT_DIR.

Returns:
String the locations of the CA certificates

getDefaultProxyFile

public static java.lang.String getDefaultProxyFile()
Retrieves the location of the proxy file. from X509_USER_PROXY.

Returns:
String the location of the proxy file

digestFileName

public static java.lang.String digestFileName(java.lang.String delegationid_in,
                                              java.lang.String DN_in)
Returns SHA1 hash digest of file name based on given delegationID and DER encoded DN in form of SHA1_HASH(DelegationID)+"-"+SHA1_HASH(DN)

Parameters:
delegationid_in - delegationID of proxy certificate
DN_in - DER encoded DN
Returns:
Digested file name

certReqResponse

public static java.lang.String certReqResponse(java.lang.String certReq)
Returns a certificate request in HTTP MIME type format

Parameters:
certReq - certificate request to response
Returns:
http response format
Throws:
java.lang.Exception

certProxyResponse

public static java.lang.String certProxyResponse(java.lang.String proxyCert)
Returns a proxy certificate in HTTP MIME type format

Parameters:
proxyCert - proxy certificate to response
Returns:
http response format
Throws:
java.lang.Exception

errorResponse

public static java.lang.String errorResponse(java.lang.String errorMsg)
Returns an error message in case of fails

Parameters:
errorMsg - to send
Returns:
error
Throws:
java.lang.Exception

getFilesBytes

public static byte[] getFilesBytes(java.io.File file)
                            throws java.io.IOException
Reading IO file in byte

Parameters:
file - File name
Returns:
File contents in byte
Throws:
java.io.IOException

certChainToByte

public static byte[] certChainToByte(java.security.cert.X509Certificate[] x509Cert)
Convert array of x509certificates into byte format of PEMs

Parameters:
x509Cert -
Returns:
x509Certificates in byte format

getDlgeePropertyFile

public static java.lang.String getDlgeePropertyFile()
Retrieve the path to the delegatee property file

Returns:
Path to the porperty file

getDlgorPropertyFile

public static java.lang.String getDlgorPropertyFile()
Retrieve the path to the delegator property file

Returns:
Path to the porperty file

getOSEnvironment

public static java.lang.String getOSEnvironment(java.lang.String envName)
Retrieve the value of environment variable

Parameters:
envName - Environment variable name
Returns:
Value of environment variable