FileDocCategorySizeDatePackage
AttributeCertificateIssuer.javaAPI DocAndroid 1.5 API4884Wed May 06 22:41:06 BST 2009org.bouncycastle.x509

AttributeCertificateIssuer

public class AttributeCertificateIssuer extends Object implements CertSelector
Carrying class for an attribute certificate issuer.

Fields Summary
final org.bouncycastle.asn1.ASN1Encodable
form
Constructors Summary
AttributeCertificateIssuer(org.bouncycastle.asn1.x509.AttCertIssuer issuer)

param
issuer

        form = issuer.getIssuer();
    
public AttributeCertificateIssuer(X500Principal principal)

        
        this(new X509Principal(principal.getEncoded()));
    
public AttributeCertificateIssuer(org.bouncycastle.jce.X509Principal principal)

        
        form = new V2Form(new GeneralNames(new DERSequence(new GeneralName(principal))));
    
Methods Summary
public java.lang.Objectclone()

        return new AttributeCertificateIssuer(AttCertIssuer.getInstance(form));
    
private java.lang.Object[]getNames()

        GeneralNames    name;
        
        if (form instanceof V2Form)
        {
            name = ((V2Form)form).getIssuerName();
        }
        else
        {
            name = (GeneralNames)form;
        }
        
        GeneralName[]   names = name.getNames();
        
        List        l = new ArrayList(names.length);
        
        for (int i = 0; i != names.length; i++)
        {
            if (names[i].getTagNo() == GeneralName.directoryName)
            {
                try
                {
                    l.add(new X500Principal(((ASN1Encodable)names[i].getName()).getEncoded()));
                }
                catch (IOException e)
                {
                    throw new RuntimeException("badly formed Name object");
                }
            }
        }
        
        return l.toArray(new Object[l.size()]);
    
public java.security.Principal[]getPrincipals()
Return any principal objects inside the attribute certificate issuer object.

return
an array of Principal objects (usually X500Principal)

        Object[]    p = this.getNames();
        List        l = new ArrayList();
        
        for (int i = 0; i != p.length; i++)
        {
            if (p[i] instanceof Principal)
            {
                l.add(p[i]);
            }
        }

        return (Principal[])l.toArray(new Principal[l.size()]);
    
public booleanmatch(java.security.cert.Certificate cert)

        if (!(cert instanceof X509Certificate))
        {
            return false;
        }
        
        X509Certificate x509Cert = (X509Certificate)cert;
        
        if (form instanceof V2Form)
        {
            V2Form issuer = (V2Form)form;
            if (issuer.getBaseCertificateID() != null)
            {
                return issuer.getBaseCertificateID().getSerial().getValue().equals(x509Cert.getSerialNumber())
                    && matchesDN(x509Cert.getIssuerX500Principal(), issuer.getBaseCertificateID().getIssuer());
            }
            
            GeneralNames name = issuer.getIssuerName();
            if (matchesDN(x509Cert.getSubjectX500Principal(), name))
            {
                return true;
            }
        }
        else
        {
            GeneralNames name = (GeneralNames)form;
            if (matchesDN(x509Cert.getSubjectX500Principal(), name))
            {
                return true;
            }
        }

        return false;
    
private booleanmatchesDN(javax.security.auth.x500.X500Principal subject, org.bouncycastle.asn1.x509.GeneralNames targets)

        GeneralName[]   names = targets.getNames();

        for (int i = 0; i != names.length; i++)
        {
            GeneralName gn = names[i];

            if (gn.getTagNo() == GeneralName.directoryName)
            {
                try
                {
                    if (new X500Principal(((ASN1Encodable)gn.getName()).getEncoded()).equals(subject))
                    {
                        return true;
                    }
                }
                catch (IOException e)
                {
                }
            }
        }

        return false;