Package org.globus.gsi

# Class X509Credential

java.lang.Object
org.globus.gsi.X509Credential

All Implemented Interfaces:
  `Serializable`

public class X509Credential extends Object implements Serializable
FILL ME

This class equivalent was called GlobusCredential in CoG -maybe a better name?

Author:
  ranantha@mcs.anl.gov
See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`BUFFER_SIZE`

## Constructor Summary

Constructors
Constructor
Description
`X509Credential(InputStream input)`
`X509Credential(InputStream certInputStream, InputStream keyInputStream)`
`X509Credential(String proxyFile)`
`X509Credential(String certFile, String keyFile)`
`X509Credential(PrivateKey initKey, X509Certificate[] initCertChain)`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`equals(Object object)`
`X509Certificate[]`
`getCertificateChain()`
`int`
`getCertNum()`
Returns the number of certificates in the credential without the self-signed certificates.
`static X509Credential`
`getDefaultCredential()`
Returns the default credential.
`String`
`getIdentity()`
Returns the identity of this credential.
`X509Certificate`
`getIdentityCertificate()`
Returns the identity certificate of this credential.
`String`
`getIssuer()`
Returns the issuer DN of the first certificate in the chain.
`Date`
`getNotBefore()`
`int`
`getPathConstraint()`
Returns the path length constraint.
`PrivateKey`
`getPrivateKey()`
`PrivateKey`
`getPrivateKey(String password)`
`GSIConstants.CertificateType`
`getProxyType()`
Returns the certificate type of the first certificate in the chain.
`int`
`getStrength()`
Returns strength of the private/public key in bits.
`int`
`getStrength(String password)`
Returns strength of the private/public key in bits.
`String`
`getSubject()`
Returns the subject DN of the first certificate in the chain.
`long`
`getTimeLeft()`
Returns time left of this credential.
`int`
`hashCode()`
`boolean`
`isEncryptedKey()`
`protected void`
`load(InputStream input)`
`protected void`
`loadCertificate(InputStream input)`
`protected void`
`loadKey(InputStream input)`
`void`
`save(OutputStream out)`
`void`
`saveCertificateChain(OutputStream out)`
`void`
`saveKey(OutputStream out)`
`static void`
`setDefaultCredential(X509Credential cred)`
Sets default credential.
`String`
`toString()`
`void`
`verify()`
Verifies the validity of the credentials.
`void`
`writeToFile(File file)`
`void`
`writeToFile(File certFile, File keyFile)`

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### BUFFER_SIZE

public static final int BUFFER_SIZE

See Also:
  - Constant Field Values

## Constructor Details

### X509Credential

public X509Credential(PrivateKey initKey, X509Certificate[] initCertChain)

### X509Credential

public X509Credential(InputStream certInputStream, InputStream keyInputStream) throws CredentialException

Throws:
  `CredentialException`

### X509Credential

public X509Credential(String certFile, String keyFile) throws CredentialException, IOException

Throws:
  `CredentialException`
  `IOException`

### X509Credential

public X509Credential(String proxyFile) throws CredentialException

Throws:
  `CredentialException`

### X509Credential

public X509Credential(InputStream input) throws CredentialException

Throws:
  `CredentialException`

## Method Details

### getCertificateChain

public X509Certificate[] getCertificateChain()

### getPrivateKey

public PrivateKey getPrivateKey() throws CredentialException

Throws:
  `CredentialException`

### getPrivateKey

public PrivateKey getPrivateKey(String password) throws CredentialException

Throws:
  `CredentialException`

### isEncryptedKey

public boolean isEncryptedKey()

### saveKey

public void saveKey(OutputStream out) throws IOException

Throws:
  `IOException`

### saveCertificateChain

public void saveCertificateChain(OutputStream out) throws IOException, CertificateEncodingException

Throws:
  `IOException`
  `CertificateEncodingException`

### save

public void save(OutputStream out) throws IOException, CertificateEncodingException

Throws:
  `IOException`
  `CertificateEncodingException`

### writeToFile

public void writeToFile(File file) throws IOException, CertificateEncodingException

Throws:
  `IOException`
  `CertificateEncodingException`

### writeToFile

public void writeToFile(File certFile, File keyFile) throws IOException, CertificateEncodingException

Throws:
  `IOException`
  `CertificateEncodingException`

### getNotBefore

public Date getNotBefore()

### getCertNum

public int getCertNum()
Returns the number of certificates in the credential without the self-signed certificates.

Returns:
  number of certificates without counting self-signed certificates

### getStrength

public int getStrength() throws CredentialException
Returns strength of the private/public key in bits.

Returns:
  strength of the key in bits. Returns -1 if unable to determine it.
Throws:
  `CredentialException`

### getStrength

public int getStrength(String password) throws CredentialException
Returns strength of the private/public key in bits.

Returns:
  strength of the key in bits. Returns -1 if unable to determine it.
Throws:
  `CredentialException`

### getSubject

public String getSubject()
Returns the subject DN of the first certificate in the chain.

Returns:
  subject DN.

### getIssuer

public String getIssuer()
Returns the issuer DN of the first certificate in the chain.

Returns:
  issuer DN.

### getProxyType

public GSIConstants.CertificateType getProxyType()
Returns the certificate type of the first certificate in the chain. Returns -1 if unable to determine the certificate type (an error occurred)

Returns:
  the type of first certificate in the chain. -1 if unable to determine the certificate type.
See Also:
  - `BouncyCastleUtil.getCertificateType(X509Certificate)`

### getTimeLeft

public long getTimeLeft()
Returns time left of this credential. The time left of the credential is based on the certificate with the shortest validity time.

Returns:
  time left in seconds. Returns 0 if the certificate has expired.

### getIdentity

public String getIdentity()
Returns the identity of this credential.

Returns:
  The identity cert in Globus format (e.g. /C=US/..). Null, if unable to get the identity (an error occurred)
See Also:
  - `getIdentityCertificate()`

### getIdentityCertificate

public X509Certificate getIdentityCertificate()
Returns the identity certificate of this credential. The identity certificate is the first certificate in the chain that is not an impersonation proxy certificate.

Returns:
  `X509Certificate` the identity cert. Null, if unable to get the identity certificate (an error occurred)

### getPathConstraint

public int getPathConstraint()
Returns the path length constraint. The shortest length in the chain of certificates is returned as the credential's path length.

Returns:
  The path length constraint of the credential. -1 is any error occurs.

### verify

public void verify() throws CredentialException
Verifies the validity of the credentials. All certificate path validation is performed using trusted certificates in default locations.

Throws:
  `CredentialException` - if one of the certificates in the chain expired or if path validiation fails.

### getDefaultCredential

public static X509Credential getDefaultCredential() throws CredentialException
Returns the default credential. The default credential is usually the user proxy certificate.
The credential will be loaded on the initial call. It must not be expired. All subsequent calls to this function return cached credential object. Once the credential is cached, and the underlying file changes, the credential will be reloaded.

Returns:
  the default credential.
Throws:
  `CredentialException` - if the credential expired or some other error with the credential.

### setDefaultCredential

public static void setDefaultCredential(X509Credential cred)
Sets default credential.

Parameters:
  `cred` - the credential to set a default.

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### load

protected void load(InputStream input) throws CredentialException

Throws:
  `CredentialException`

### loadCertificate

protected void loadCertificate(InputStream input) throws CredentialException

Throws:
  `CredentialException`

### loadKey

protected void loadKey(InputStream input) throws CredentialException

Throws:
  `CredentialException`

### equals

public boolean equals(Object object)

Overrides:
  `equals` in class `Object`

### hashCode

public int hashCode()

Overrides:
  `hashCode` in class `Object`