FileDocCategorySizeDatePackage
Certificate.javaAPI DocphoneME MR2 API (J2ME)7423Wed May 02 18:00:38 BST 2007com.sun.satsa.pki

Certificate

public class Certificate extends Object
This class represents WIM certificate.

Fields Summary
String
label
Certificate label.
byte[]
id
Certificate ID.
byte[]
requestId
Issuer certificate ID.
TLV
cert
Parsed X.509 certificate or null if its not loaded.
Location
header
Location (path, offset, length) of certificate DF entry on card.
Location
body
Location (path, offset, length) of certificate on card.
Constructors Summary
Methods Summary
static java.lang.StringgetInfo(TLV cert)
Returns description of given certificate (subject, issuer, serial number and validity).

param
cert parsed certificate
return
certificate description or null if any error occurs


        try {
            TLV sn = cert.child.child.skipOptional(0xa0);
            TLV issuer = sn.next.next;
            TLV subject = issuer.next.next;

            String result;
            result = 
                // "Subject" 
                Resource.getString(
                    ResourceConstants.JSR177_CERTIFICATE_SUBJECT) + 
                ": " + RFC2253Name.NameToString(subject);
            result += 
                "\n\n" + 
                // "Issuer" 
                Resource.getString(
                    ResourceConstants.JSR177_CERTIFICATE_ISSUER) +
                ": " + RFC2253Name.NameToString(issuer);

            String s;
            try {
                s = "" + sn.getInteger();
            } catch (TLVException e) {
                s = "0x" + Utils.hexNumber(sn.data, sn.valueOffset, sn.length);
            }
            result += 
                "\n\n" + 
                // "Serial number"
                Resource.getString(ResourceConstants.JSR177_CERTIFICATE_SN) +
                ": " + s;

            return 
                result + "\n\n" + 
                // "Valid from"
                Resource.getString(
                    ResourceConstants.JSR177_CERTIFICATE_VALIDFROM) +
                " " +
                Utils.calendarToString(getValidity(cert, true)) +
                " " + 
                // "through"
                Resource.getString(
                    ResourceConstants.JSR177_CERTIFICATE_VALIDTILL) +
                " " + 
                Utils.calendarToString(getValidity(cert, false));
        } catch (TLVException tlve) { // ignored
        } catch (IllegalArgumentException iae) { // ignored
        } catch (NullPointerException npe) { // ignored
        }
        return null;
    
TLVgetIssuer()
Returns issuer name for this certificate which can be used only for comparison.

return
TLV object containing issuer name.

        return cert.child.child.skipOptional(0xa0).next.next;
    
TLVgetIssuerAndSerialNumber()
Returns new IssuerAndSerialNumber TLV object which can be used as element of new data structure.

return
IssuerAndSerialNumber TLV object


        TLV t = TLV.createSequence();
        t.setChild(getIssuer().copy()).
            setNext(getSerialNumber().copy());
        return t;
    
TLVgetKeyAlgorithmID()
Returns key algorithm identifier for this certificate which can be used as element of new data structure.

return
key algorithm identifier

        return getSubject().next.child.copy();
    
TLVgetSerialNumber()
Returns serial number of this certificate. The result can be used only for comparison, not for the construction of new DER structure.

return
TLV object containing serial number.

        return cert.child.child.skipOptional(0xa0);
    
TLVgetSubject()
Returns subject name for this certificate which can be used only for comparison.

return
TLV object containing subject name.

        return getIssuer().next.next;
    
static java.util.CalendargetValidity(TLV cert, boolean notBefore)
Returns notBefore or notAfter date for the given certificate.

param
cert parsed x.509 certificate.
param
notBefore if true returns notBefore field value, otherwise - notAfter.
return
the requested date
throws
TLVException in case of parsing error


        try {
            TLV t = cert.child.child.skipOptional(0xa0).next.next.next.child;
            if (! notBefore) {
                t = t.next;
            }
            return t.getTime();
        } catch (NullPointerException npe) {
            throw new TLVException("Invalid certificate");
        }
    
booleanisExpired()
Verifies if this certificate is expired.

return
true if the certificate is expired.


        Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
        try {
            return c.before(getValidity(cert, true)) ||
                   c.after(getValidity(cert, false));
        } catch (TLVException e) {
            return true;
        }
    
booleanisIssuedBy(com.sun.satsa.pki.Certificate next)
Verifies if this certificate was issued by subject of the specified certificate. Returns false for self-signed certificates.

param
next certificate
return
true if the certificate was issued by subject of the specified certificate.

        TLV issuer = getIssuer();
        return (requestId != null) &&
               Utils.byteMatch(requestId, next.id) &&
               (! RFC2253Name.compare(issuer, getSubject())) &&
               RFC2253Name.compare(issuer, next.getSubject());