org.glite.security.delegation
Class GrDPX509Util

java.lang.Object
  extended by org.glite.security.delegation.GrDPX509Util

public class GrDPX509Util
extends java.lang.Object

Utility to manage X509 certificates

Author:
Mehran Ahsant, Akos Frohner , Joni Hahkala

Field Summary
static java.lang.String CERT_CHAIN_CONTENT_TYPE
           
static java.lang.String CERT_REQ_CONTENT_TYPE
           
 
Constructor Summary
GrDPX509Util()
           
 
Method Summary
static byte[] certChainToByte(java.security.cert.X509Certificate[] x509Cert)
          Deprecated. use org.glite.security.util.proxy.ProxyCertificateGenerator.
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 the access mode of a file in the filesystem (!!!
static java.lang.String createCertificateRequest(java.security.cert.X509Certificate subjectCert, java.lang.String sigAlgName, java.security.KeyPair keyPair)
          Create a new certificate request.
static java.lang.String createCertificateRequest(org.bouncycastle.asn1.x509.X509Name subjectDN, java.lang.String sigAlgName, java.security.KeyPair keyPair)
          Deprecated. use the method with certificate input instead to avoid problems with DN encoding.
static byte[] digest(byte[] input)
          A synchronizer wrapper for the static digester, only access it through this utility method.
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)
          Makes an HTTP error message out of the error message.
static java.lang.String findPrivateKeyInCache(java.lang.String strDirCache, java.lang.String delegationID, java.lang.String userDN)
          Deprecated. Use delegation storage.
static java.lang.String findProxyInCache(java.lang.String strDirCache, java.lang.String delegationID, java.lang.String userDN)
          Deprecated. Use delegation storage.
static java.lang.String[] fromStringVOMSAttrs(java.lang.String vomsAttributesStr)
          Returns the list of VOMS attributes from a single string representation.
static java.lang.String genDlgID(java.lang.String dn, java.lang.String[] vomsAttributes)
          Generates a new delegation ID starting from the given DN and list of VOMS attributes.
static java.lang.String generateSessionID(java.security.PublicKey pk)
          Generates a new session ID based on the public key.
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)
          Deprecated. use relevant functions in util-java or bouncycastle.
static GrDPStorageFactory getGrDPStorageFactory(java.lang.String factoryClass)
          Get the factory to create storage instances.
static java.security.KeyPair getKeyPair(int size)
          Generate a new key pair.
static java.lang.String[] getVOMSAttributes(org.glite.security.SecurityContext sc)
          Returns the list of VOMS attributes exposed in the given SecurityContext.
static java.security.cert.X509Certificate loadCertificate(java.io.InputStream cert)
          Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.
static java.security.cert.X509Certificate[] loadCertificateChain(java.io.BufferedInputStream bisCerts)
          Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.
static java.security.cert.X509Certificate[] loadCertificateChain(byte[] bCerts)
          Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.
static org.bouncycastle.jce.PKCS10CertificationRequest loadCertificateRequest(java.lang.String request)
          Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.
static org.bouncycastle.asn1.x509.X509Name makeGridCertDN(java.lang.String DN)
          Deprecated. Use org.glite.security.util.proxy.ProxyCertificateGenerator
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)
          Deprecated. Use org.glite.security.util.proxy.ProxyCertificateGenerator
static byte[] readPEM(java.io.InputStream is, java.lang.String hdr, java.lang.String ftr)
          Deprecated. Use org.glite.security.util.FileCertReader
static byte[] readPEM(java.lang.String in, java.lang.String hdr, java.lang.String ftr)
          Deprecated. Use org.bouncycastle.openssl.PEMWriter
static void saveCertProxyTofile(java.lang.String inCertProxy, java.lang.String fileLocation, java.lang.String delegationID, java.lang.String userDN, boolean append)
          Deprecated. use org.glite.security.util.proxy.ProxyCertificateGenerator.
static void saveCertProxyTofile(java.security.cert.X509Certificate certProxy, java.lang.String fileLocation)
          Deprecated. use org.glite.security.util.proxy.ProxyCertificateGenerator
static void saveCertReqToFile(java.lang.String certReq, java.lang.String fileLocation)
          Deprecated. Use delegation storage, don't write to file.
static void savePrivateKey(java.security.PrivateKey pk, java.lang.String fileLocation, java.lang.String delegationID, java.lang.String userDN)
          Deprecated. Use delegation storage.
static java.lang.String toStringVOMSAttrs(java.lang.String[] vomsAttributes)
          Returns a single string representation of the VOMS attributes list.
static java.lang.String writePEM(byte[] bytes, java.lang.String hdr, java.lang.String ftr)
          Deprecated. Use org.bouncycastle.openssl.PEMWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CERT_CHAIN_CONTENT_TYPE

public static final java.lang.String CERT_CHAIN_CONTENT_TYPE
See Also:
Constant Field Values

CERT_REQ_CONTENT_TYPE

public static final java.lang.String CERT_REQ_CONTENT_TYPE
See Also:
Constant Field Values
Constructor Detail

GrDPX509Util

public GrDPX509Util()
Method Detail

writePEM

public static java.lang.String writePEM(byte[] bytes,
                                        java.lang.String hdr,
                                        java.lang.String ftr)
Deprecated. Use org.bouncycastle.openssl.PEMWriter

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
Deprecated. Use org.glite.security.util.FileCertReader

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

readPEM

public static byte[] readPEM(java.lang.String in,
                             java.lang.String hdr,
                             java.lang.String ftr)
Deprecated. Use org.bouncycastle.openssl.PEMWriter

Read a PEM encoded base64 stream and decode it

Parameters:
in - Base64 PEM encoded string
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)
Deprecated. Use org.glite.security.util.proxy.ProxyCertificateGenerator

Create an X509 Certificate DN

Parameters:
organization - Organization
orgUnit - Organization Unit
commonName - X509 Common Name
country - Country
email - Email address
Returns:
X509Name of generated DN

makeGridCertDN

public static org.bouncycastle.asn1.x509.X509Name makeGridCertDN(java.lang.String DN)
Deprecated. Use org.glite.security.util.proxy.ProxyCertificateGenerator

Create an X509 Certificate DN

Parameters:
DN - The client's distiungished name.
Returns:
X509Name of DN

saveCertReqToFile

public static void saveCertReqToFile(java.lang.String certReq,
                                     java.lang.String fileLocation)
                              throws java.io.IOException
Deprecated. Use delegation storage, don't write to file.

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)
Deprecated. use org.glite.security.util.proxy.ProxyCertificateGenerator

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 inCertProxy,
                                       java.lang.String fileLocation,
                                       java.lang.String delegationID,
                                       java.lang.String userDN,
                                       boolean append)
Deprecated. use org.glite.security.util.proxy.ProxyCertificateGenerator.

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)
                           throws java.io.FileNotFoundException,
                                  java.io.IOException
Deprecated. Use delegation storage.

save a private key in specific location

Parameters:
pk - Given private key to save
fileLocation - location of private key
delegationID - the ID of the delegation
userDN - the DN of the client's certificate
Throws:
java.io.FileNotFoundException
java.io.IOException

findProxyInCache

public static java.lang.String findProxyInCache(java.lang.String strDirCache,
                                                java.lang.String delegationID,
                                                java.lang.String userDN)
Deprecated. Use delegation storage.

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)
Deprecated. Use delegation storage.

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.security.NoSuchProviderException
Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.

Load x509 certificate

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

loadCertificateChain

public static java.security.cert.X509Certificate[] loadCertificateChain(byte[] bCerts)
                                                                 throws java.io.IOException,
                                                                        java.security.cert.CertificateException,
                                                                        java.security.NoSuchProviderException
Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.

Load chain of certificates from byte

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

loadCertificateChain

public static java.security.cert.X509Certificate[] loadCertificateChain(java.io.BufferedInputStream bisCerts)
                                                                 throws java.io.IOException,
                                                                        java.security.cert.CertificateException,
                                                                        java.security.NoSuchProviderException
Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.

Load a chain of certificates from BIS

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

loadCertificateRequest

public static org.bouncycastle.jce.PKCS10CertificationRequest loadCertificateRequest(java.lang.String request)
Deprecated. Use delegation storage or org.glite.security.util.FileCertReader.

Reconstruct a certificate request from a PEM encoded string.

Parameters:
request - BASE64 PEM encoded string
Returns:
certificate request

getFilesBytes

public static byte[] getFilesBytes(java.io.File file)
                            throws java.io.IOException
Deprecated. use relevant functions in util-java or bouncycastle.

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)
                              throws java.security.cert.CertificateEncodingException
Deprecated. use org.glite.security.util.proxy.ProxyCertificateGenerator.

Convert array of x509certificates into byte format of PEMs

Parameters:
x509Cert -
Returns:
x509Certificates in byte format
Throws:
java.security.cert.CertificateEncodingException

digest

public static byte[] digest(byte[] input)
A synchronizer wrapper for the static digester, only access it through this utility method.

Parameters:
input - The bytes to digest.
Returns:
the digested bytes.

changeFileMode

public static boolean changeFileMode(java.lang.String file,
                                     int mode)
Change the access mode of a file in the filesystem (!!! system specific !!!).

Parameters:
file - Location of the file to be changed.
mode - New mode for the file.
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

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

errorResponse

public static java.lang.String errorResponse(java.lang.String errorMsg)
Makes an HTTP error message out of the error message.

Parameters:
errorMsg - to send
Returns:
The HTTP error message.

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

getGrDPStorageFactory

public static GrDPStorageFactory getGrDPStorageFactory(java.lang.String factoryClass)
                                                throws java.lang.ClassNotFoundException,
                                                       java.lang.NoSuchMethodException,
                                                       java.lang.reflect.InvocationTargetException,
                                                       java.lang.IllegalAccessException,
                                                       java.lang.InstantiationException
Get the factory to create storage instances.

Parameters:
factoryClass - The full name of the class implementing the storage factory.
Returns:
A factory for creating storage object instances.
Throws:
java.lang.ClassNotFoundException - Could not find the specified class in classpath
java.lang.NoSuchMethodException - Failed to instantiate a factory object
java.lang.reflect.InvocationTargetException - Failed to instantiate a factory object
java.lang.IllegalAccessException - Failed to instantiate a factory object
java.lang.InstantiationException - Failed to instantiate a factory object

createCertificateRequest

public static java.lang.String createCertificateRequest(org.bouncycastle.asn1.x509.X509Name subjectDN,
                                                        java.lang.String sigAlgName,
                                                        java.security.KeyPair keyPair)
                                                 throws java.security.GeneralSecurityException
Deprecated. use the method with certificate input instead to avoid problems with DN encoding.

Create a new certificate request.

Parameters:
subjectDN - The dn to include in the certificate request.
sigAlgName - The algorithm to be used.
keyPair - The keypair to include in the certificate.
Returns:
A PEM encoded certificate request.
Throws:
java.security.GeneralSecurityException - Failed to generate the certificate request.

createCertificateRequest

public static java.lang.String createCertificateRequest(java.security.cert.X509Certificate subjectCert,
                                                        java.lang.String sigAlgName,
                                                        java.security.KeyPair keyPair)
                                                 throws java.security.GeneralSecurityException
Create a new certificate request.

Parameters:
subjectDN - The dn to include in the certificate request.
sigAlgName - The algorithm to be used.
keyPair - The keypair to include in the certificate.
Returns:
A PEM encoded certificate request.
Throws:
java.security.GeneralSecurityException - Failed to generate the certificate request.

getKeyPair

public static java.security.KeyPair getKeyPair(int size)
Generate a new key pair.

Returns:
The generated KeyPair object.

generateSessionID

public static java.lang.String generateSessionID(java.security.PublicKey pk)
                                          throws java.security.NoSuchAlgorithmException
Generates a new session ID based on the public key.

Parameters:
pk - public key of a certificate (request)
Returns:
The generated session ID
Throws:
java.security.NoSuchAlgorithmException

genDlgID

public static java.lang.String genDlgID(java.lang.String dn,
                                        java.lang.String[] vomsAttributes)
Generates a new delegation ID starting from the given DN and list of VOMS attributes.

Parameters:
dn - The dn to be used in the hashing process.
vomsAttributes - The list of attributes to be used in the hashing process.
Returns:
The generated delegation ID.

getVOMSAttributes

public static java.lang.String[] getVOMSAttributes(org.glite.security.SecurityContext sc)
Returns the list of VOMS attributes exposed in the given SecurityContext.

Parameters:
sc - The SecurityContext object from which to take the attributes
Returns:
A String list containing the attributes. Empty (0 element) array if no attributes.

toStringVOMSAttrs

public static java.lang.String toStringVOMSAttrs(java.lang.String[] vomsAttributes)
Returns a single string representation of the VOMS attributes list.

Parameters:
vomsAttributes - The VOMS attributes array
Returns:
A single string representation of the VOMS attributes list

fromStringVOMSAttrs

public static java.lang.String[] fromStringVOMSAttrs(java.lang.String vomsAttributesStr)
Returns the list of VOMS attributes from a single string representation.

Parameters:
vomsAttributesStr - A single string representation of a VOMS attributes list.
Returns:
A string array containing the VOMS attributes


Copyright © 2004-2008. EU-EGEE