org.openoces.ooapi.cert
Class OcesCertificateFactory

java.lang.Object
  extended byorg.openoces.ooapi.cert.OcesCertificateFactory

public class OcesCertificateFactory
extends java.lang.Object

This is a singleton class used to construct OCES certificates. Use this class to instantiate high-level OcesCertificate objects from a raw X.509 OCES certificate.

The following example instantiates a certificate object given a PEM encoded certificate.

// assume cPEM contains the PEM encoded certificate
String cPEM;
OcesCertificate oc = OcesCertificateFactory.getInstance().generate(cPEM);

After construction you may assert that the certificate is signed by the OCES root certificate. No other validation occurs automatically.

It it also possible to instantiate a certificate object from a DER encoded certificate available in a byte array:

// assume bs contains the DER encoded certificate
byte[] bs;
OcesCertificate oc = OcesCertificateFactory.getInstance().generate(bs);

In case you already have a X509Certificate object, you can also use that to instantiate an OcesCertificate object:

// assume x509c contains an OCES certificate
X509Certificate x509c;
OcesCertificate oc = OcesCertificateFactory.getInstance().generate(x509c);

In all cases the type of the returned certificate will be of one:

You typically use an instanceof expression to determine the exact type:

// assume bs contains the DER encoded certificate
byte[] bs;
OcesCertificate oc = OcesCertificateFactory.getInstance().generate(bs);
if ( oc instanceof PersonalOcesCertificate ) {
// handle personal OCES certificate case
} else if ( oc instanceof EmployeeOcesCertificate ) {
// handle employee OCES certiticate case
} else if ( oc instanceof OrganizationalOcesCertificate ) {
// handle organizational OCES certificate case
}

Author:
Carsten Raskgaard

Field Summary
protected  java.security.cert.CertificateFactory cf
          the X.509 cerficate factory used to instantiate X.509 certificate objects
 
Method Summary
 OcesCertificate generate(byte[] derEncodedCertificate)
          Constructs an OcesCertificate object from a raw PEM encoded X.509 OCES certificate.
 OcesCertificate generate(java.lang.String pemEncodedCertificate)
          Constructs an OcesCertificate object from a raw PEM encoded X.509 OCES certificate.
 OcesCertificate generate(java.security.cert.X509Certificate certObj)
          Constructs an OcesCertificate object from X509Certificate object.
protected  OcesCertificate generateFromObject(java.security.cert.X509Certificate crt)
           
static OcesCertificateFactory getInstance()
          Returns the singleton factory object
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cf

protected java.security.cert.CertificateFactory cf
the X.509 cerficate factory used to instantiate X.509 certificate objects

Method Detail

getInstance

public static OcesCertificateFactory getInstance()
Returns the singleton factory object

Returns:
the singleton

generate

public OcesCertificate generate(java.lang.String pemEncodedCertificate)
                         throws InternalException,
                                NonOcesCertificateException,
                                SignatureVerificationException
Constructs an OcesCertificate object from a raw PEM encoded X.509 OCES certificate. The method will verify that the passed X.509 certificate has been signed by the OCES root certificate and throw an exception if this is not the case. No other processing of the certificate is being done. Before trusting the certificate, you should use the RevocationChecker class to verify the validity of the certificate.

Parameters:
pemEncodedCertificate - a PEM encoded X.509 certificate
Returns:
an object representing the specified certificate
Throws:
InternalException - if an internal error occurred. Please report this
NonOcesCertificateException - if the specified certificate is not recognized as an OCES certificate
SignatureVerificationException - if the key is incorrect
See Also:
OcesCertificate, RevocationChecker

generate

public OcesCertificate generate(java.security.cert.X509Certificate certObj)
                         throws InternalException,
                                NonOcesCertificateException,
                                SignatureVerificationException
Constructs an OcesCertificate object from X509Certificate object. The method will verify that the passed X.509 certificate has been signed by the OCES root certificate and throw an exception if this is not the case. No other processing of the certificate is being done. Before trusting the certificate, you should use the RevocationChecker class to verify the validity of the certificate.

Parameters:
certObj - a X.509 object
Returns:
an object representing the specified certificate
Throws:
InternalException - if an internal error occurred. Please report this
NonOcesCertificateException - if the specified certificate is not recognized as an OCES certificate
SignatureVerificationException - if the key is incorrect
See Also:
OcesCertificate, RevocationChecker

generateFromObject

protected OcesCertificate generateFromObject(java.security.cert.X509Certificate crt)
                                      throws InternalException,
                                             SignatureVerificationException,
                                             NonOcesCertificateException
Throws:
InternalException
SignatureVerificationException
NonOcesCertificateException

generate

public OcesCertificate generate(byte[] derEncodedCertificate)
                         throws InternalException,
                                NonOcesCertificateException,
                                SignatureVerificationException
Constructs an OcesCertificate object from a raw PEM encoded X.509 OCES certificate. The method will verify that the passed X.509 certificate has been signed by the OCES root certificate and throw an exception if this is not the case. No other processing of the certificate is being done. Before trusting the certificate, you should use the RevocationChecker class to verify the validity of the certificate.

Parameters:
derEncodedCertificate - a DER encoded X.509 certificate
Returns:
an object representing the specified certificate
Throws:
InternalException - if an internal error occurred. Please report this
NonOcesCertificateException - if the specified certificate is not recognized as an OCES certificate
SignatureVerificationException - if the key is incorrect
See Also:
OcesCertificate, RevocationChecker