FileDocCategorySizeDatePackage
AttributeCertificateHolder.javaAPI DocAndroid 1.5 API7597Wed May 06 22:41:06 BST 2009org.bouncycastle.x509

AttributeCertificateHolder

public class AttributeCertificateHolder extends Object implements CertSelector
The Holder object.
Holder ::= SEQUENCE {
baseCertificateID [0] IssuerSerial OPTIONAL,
-- the issuer and serial number of
-- the holder's Public Key Certificate
entityName [1] GeneralNames OPTIONAL,
-- the name of the claimant or role
objectDigestInfo [2] ObjectDigestInfo OPTIONAL
-- used to directly authenticate the holder,
-- for example, an executable
}
This holder currently supports use of the baseCertificateID and the entityName.

Fields Summary
final org.bouncycastle.asn1.x509.Holder
holder
Constructors Summary
AttributeCertificateHolder(org.bouncycastle.asn1.ASN1Sequence seq)

        holder = Holder.getInstance(seq);
    
public AttributeCertificateHolder(org.bouncycastle.jce.X509Principal issuerName, BigInteger serialNumber)

        holder = new org.bouncycastle.asn1.x509.Holder(new IssuerSerial(
                new GeneralNames(new DERSequence(new GeneralName(issuerName))),
                new DERInteger(serialNumber)));        
    
public AttributeCertificateHolder(X500Principal issuerName, BigInteger serialNumber)

        this(X509Util.convertPrincipal(issuerName), serialNumber);
    
public AttributeCertificateHolder(X509Certificate cert)

        
        X509Principal   name;
        
        try
        {
            name = PrincipalUtil.getIssuerX509Principal(cert);
        }
        catch (Exception e)
        {
            throw new CertificateParsingException(e.getMessage());
        }
        
        holder = new Holder(new IssuerSerial(generateGeneralNames(name), new DERInteger(cert.getSerialNumber())));
    
public AttributeCertificateHolder(org.bouncycastle.jce.X509Principal principal)

        
        holder = new Holder(generateGeneralNames(principal));
    
public AttributeCertificateHolder(X500Principal principal)

        this(X509Util.convertPrincipal(principal));
    
Methods Summary
public java.lang.Objectclone()

        return new AttributeCertificateHolder((ASN1Sequence)holder.toASN1Object());
    
private org.bouncycastle.asn1.x509.GeneralNamesgenerateGeneralNames(org.bouncycastle.jce.X509Principal principal)

        return new GeneralNames(new DERSequence(new GeneralName(principal)));
    
public java.security.Principal[]getEntityNames()
Return any principal objects inside the attribute certificate holder entity names field.

return
an array of Principal objects (usually X500Principal), null if no entity names field is set.

        if (holder.getEntityName() != null)
        {
            return getPrincipals(holder.getEntityName());
        }
        
        return null;
    
public java.security.Principal[]getIssuer()
Return the principals associated with the issuer attached to this holder

return
an array of principals, null if no BaseCertificateID is set.

        if (holder.getBaseCertificateID() != null)
        {
            return getPrincipals(holder.getBaseCertificateID().getIssuer());
        }
        
        return null;
    
private java.lang.Object[]getNames(org.bouncycastle.asn1.x509.GeneralName[] names)

        
        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()]);
    
private java.security.Principal[]getPrincipals(org.bouncycastle.asn1.x509.GeneralNames names)

        Object[]    p = this.getNames(names.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 java.math.BigIntegergetSerialNumber()
Return the serial number associated with the issuer attached to this holder.

return
the certificate serial number, null if no BaseCertificateID is set.

        if (holder.getBaseCertificateID() != null)
        {
            return holder.getBaseCertificateID().getSerial().getValue();
        }
        
        return null;
    
public booleanmatch(java.security.cert.Certificate cert)

        if (!(cert instanceof X509Certificate))
        {
            return false;
        }
        
        X509Certificate x509Cert = (X509Certificate)cert;
        
        try
        {
            if (holder.getBaseCertificateID() != null)
            {
                return holder.getBaseCertificateID().getSerial().getValue().equals(x509Cert.getSerialNumber())
                    && matchesDN(PrincipalUtil.getIssuerX509Principal(x509Cert), holder.getBaseCertificateID().getIssuer());
            }
    
            if (holder.getEntityName() != null)
            {
                if (matchesDN(PrincipalUtil.getSubjectX509Principal(x509Cert), holder.getEntityName()))
                {
                    return true;
                }
            }
        }
        catch (CertificateEncodingException e)
        {
            return false;
        }
        
        /**
         * objectDigestInfo not supported
         */
        return false;
    
private booleanmatchesDN(org.bouncycastle.jce.X509Principal 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 X509Principal(((ASN1Encodable)gn.getName()).getEncoded()).equals(subject))
                    {
                        return true;
                    }
                }
                catch (IOException e)
                {
                }
            }
        }

        return false;