FileDocCategorySizeDatePackage
X509V2AttributeCertificate.javaAPI DocAndroid 1.5 API8406Wed May 06 22:41:06 BST 2009org.bouncycastle.x509

X509V2AttributeCertificate

public class X509V2AttributeCertificate extends Object implements X509AttributeCertificate

Fields Summary
private org.bouncycastle.asn1.x509.AttributeCertificate
cert
private Date
notBefore
private Date
notAfter
Constructors Summary
public X509V2AttributeCertificate(InputStream encIn)

        this(AttributeCertificate.getInstance(new ASN1InputStream(encIn).readObject()));
    
public X509V2AttributeCertificate(byte[] encoded)

        this(new ByteArrayInputStream(encoded));
    
X509V2AttributeCertificate(org.bouncycastle.asn1.x509.AttributeCertificate cert)

        this.cert = cert;
        
        try
        {
            this.notAfter = cert.getAcinfo().getAttrCertValidityPeriod().getNotAfterTime().getDate();
            this.notBefore = cert.getAcinfo().getAttrCertValidityPeriod().getNotBeforeTime().getDate();
        }
        catch (ParseException e)
        {
            throw new IOException("invalid data structure in certificate!");
        }
    
Methods Summary
public voidcheckValidity()

        this.checkValidity(new Date());
    
public voidcheckValidity(java.util.Date date)

        if (date.after(this.getNotAfter()))
        {
            throw new CertificateExpiredException("certificate expired on " + this.getNotAfter());
        }

        if (date.before(this.getNotBefore()))
        {
            throw new CertificateNotYetValidException("certificate not valid till " + this.getNotBefore());
        }
    
public X509Attribute[]getAttributes()

        ASN1Sequence    seq = cert.getAcinfo().getAttributes();
        X509Attribute[] attrs = new X509Attribute[seq.size()];
        
        for (int i = 0; i != seq.size(); i++)
        {
            attrs[i] = new X509Attribute((ASN1Encodable)seq.getObjectAt(i));
        }
        
        return attrs;
    
public X509Attribute[]getAttributes(java.lang.String oid)

        ASN1Sequence    seq = cert.getAcinfo().getAttributes();
        List            list = new ArrayList();
        
        for (int i = 0; i != seq.size(); i++)
        {
            X509Attribute attr = new X509Attribute((ASN1Encodable)seq.getObjectAt(i));
            if (attr.getOID().equals(oid))
            {
                list.add(attr);
            }
        }
        
        if (list.size() == 0)
        {
            return null;
        }
        
        return (X509Attribute[])list.toArray(new X509Attribute[list.size()]);
    
public java.util.SetgetCriticalExtensionOIDs()

        return getExtensionOIDs(true);
    
public byte[]getEncoded()

        return cert.getEncoded();
    
private java.util.SetgetExtensionOIDs(boolean critical)

        X509Extensions  extensions = cert.getAcinfo().getExtensions();

        if (extensions != null)
        {
            Set             set = new HashSet();
            Enumeration     e = extensions.oids();

            while (e.hasMoreElements())
            {
                DERObjectIdentifier oid = (DERObjectIdentifier)e.nextElement();
                X509Extension       ext = extensions.getExtension(oid);

                if (ext.isCritical() == critical)
                {
                    set.add(oid.getId());
                }
            }

            return set;
        }

        return null;
    
public byte[]getExtensionValue(java.lang.String oid)

        X509Extensions  extensions = cert.getAcinfo().getExtensions();

        if (extensions != null)
        {
            X509Extension   ext = extensions.getExtension(new DERObjectIdentifier(oid));

            if (ext != null)
            {
                ByteArrayOutputStream    bOut = new ByteArrayOutputStream();
                DEROutputStream            dOut = new DEROutputStream(bOut);
                
                try
                {
                    dOut.writeObject(ext.getValue());

                    return bOut.toByteArray();
                }
                catch (Exception e)
                {
                    throw new RuntimeException("error encoding " + e.toString());
                }
            }
        }

        return null;
    
public AttributeCertificateHoldergetHolder()

        return new AttributeCertificateHolder((ASN1Sequence)cert.getAcinfo().getHolder().toASN1Object());
    
public AttributeCertificateIssuergetIssuer()

        return new AttributeCertificateIssuer(cert.getAcinfo().getIssuer());
    
public boolean[]getIssuerUniqueID()

        DERBitString    id = cert.getAcinfo().getIssuerUniqueID();

        if (id != null)
        {
            byte[]          bytes = id.getBytes();
            boolean[]       boolId = new boolean[bytes.length * 8 - id.getPadBits()];

            for (int i = 0; i != boolId.length; i++)
            {
                boolId[i] = (bytes[i / 8] & (0x80 >>> (i % 8))) != 0;
            }

            return boolId;
        }
            
        return null;
    
public java.util.SetgetNonCriticalExtensionOIDs()

        return getExtensionOIDs(false);
    
public java.util.DategetNotAfter()

        return notAfter;
    
public java.util.DategetNotBefore()

        return notBefore;
    
public java.math.BigIntegergetSerialNumber()

        return cert.getAcinfo().getSerialNumber().getValue();
    
public byte[]getSignature()

        return cert.getSignatureValue().getBytes();
    
public intgetVersion()

        return cert.getAcinfo().getVersion().getValue().intValue();
    
public booleanhasUnsupportedCriticalExtension()

        Set  extensions = getCriticalExtensionOIDs();

        return extensions != null && !extensions.isEmpty();
    
public final voidverify(java.security.PublicKey key, java.lang.String provider)

        Signature   signature = null;

        if (!cert.getSignatureAlgorithm().equals(cert.getAcinfo().getSignature()))
        {
            throw new CertificateException("Signature algorithm in certificate info not same as outer certificate");
        }

        signature = Signature.getInstance(cert.getSignatureAlgorithm().getObjectId().getId(), provider);

        signature.initVerify(key);

        try
        {
            signature.update(cert.getAcinfo().getEncoded());
        }
        catch (IOException e)
        {
            throw new SignatureException("Exception encoding certificate info object");
        }

        if (!signature.verify(this.getSignature()))
        {
            throw new InvalidKeyException("Public key presented not for certificate signature");
        }