Package org.bouncycastle.x509

Examples of org.bouncycastle.x509.X509V2AttributeCertificate


    }
   
    public void performTest()
        throws Exception
    {
        X509AttributeCertificate    aCert = new X509V2AttributeCertificate(attrCert);
        CertificateFactory          fact = CertificateFactory.getInstance("X.509","BC");
        X509Certificate             sCert = (X509Certificate)fact.generateCertificate(new ByteArrayInputStream(signCert));
       
        aCert.verify(sCert.getPublicKey(), "BC");
       
        //
        // search test
        //
       
        List      list = new ArrayList();
       
        list.add(sCert);
       
        CollectionCertStoreParameters ccsp = new CollectionCertStoreParameters(list);
        CertStore store = CertStore.getInstance("Collection", ccsp);
       
        Collection certs = store.getCertificates(aCert.getIssuer());
        if (certs.size() != 1 || !certs.contains(sCert))
        {
            fail("sCert not found by issuer");
        }
       
        X509Attribute[] attrs = aCert.getAttributes("1.3.6.1.4.1.6760.8.1.1");
        if (attrs == null || attrs.length != 1)
        {
            fail("attribute not found");
        }

        //
        // reencode test
        //
        aCert = new X509V2AttributeCertificate(aCert.getEncoded());
       
        aCert.verify(sCert.getPublicKey(), "BC");
       
        X509AttributeCertificate saCert = new X509V2AttributeCertificate(new ByteArrayInputStream(aCert.getEncoded()));
       
        if (!aCert.getNotAfter().equals(saCert.getNotAfter()))
        {
            fail("failed date comparison");
        }
       
        // base generator test
       
        //
        // a sample key pair.
        //
        RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(
            new BigInteger("b4a7e46170574f16a97082b22be58b6a2a629798419be12872a4bdba626cfae9900f76abfb12139dce5de56564fab2b6543165a040c606887420e33d91ed7ed7", 16),
            new BigInteger("11", 16));

        RSAPrivateCrtKeySpec privKeySpec = RSA_PRIVATE_KEY_SPEC;

        //
        // set up the keys
        //
        PrivateKey          privKey;
        PublicKey           pubKey;

        KeyFactory  kFact = KeyFactory.getInstance("RSA", "BC");

        privKey = kFact.generatePrivate(privKeySpec);
        pubKey = kFact.generatePublic(pubKeySpec);
       
        X509V2AttributeCertificateGenerator gen = new X509V2AttributeCertificateGenerator();
       
        gen.addAttribute(attrs[0]);
        gen.setHolder(aCert.getHolder());
        gen.setIssuer(aCert.getIssuer());
        gen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
        gen.setNotAfter(new Date(System.currentTimeMillis() + 50000));
        gen.setSerialNumber(aCert.getSerialNumber());
        gen.setSignatureAlgorithm("SHA1WithRSAEncryption");
       
        aCert = gen.generateCertificate(privKey, "BC");
       
        aCert.checkValidity();
       
        aCert.verify(pubKey, "BC");
       
        // as the issuer is the same this should still work (even though it is not
        // technically correct
       
        certs = store.getCertificates(aCert.getIssuer());
        if (certs.size() != 1 || !certs.contains(sCert))
        {
            fail("sCert not found by issuer");
        }
       
        attrs = aCert.getAttributes("1.3.6.1.4.1.6760.8.1.1");
        if (attrs == null || attrs.length != 1)
        {
            fail("attribute not found");
        }
       
        //
        // reencode test
        //
        aCert = new X509V2AttributeCertificate(aCert.getEncoded());
       
        aCert.verify(pubKey, "BC");
       
        AttributeCertificateIssuer  issuer = aCert.getIssuer();
       
View Full Code Here


     */
    private X509AttributeCertificate readAttributeCertificate(
        String  endMarker)
        throws IOException
    {
        return new X509V2AttributeCertificate(readBytes(endMarker));
    }
View Full Code Here

     */
    private X509AttributeCertificate readAttributeCertificate(
        String  endMarker)
        throws IOException
    {
        return new X509V2AttributeCertificate(readBytes(endMarker));
    }
View Full Code Here

     */
    private X509AttributeCertificate readAttributeCertificate(
        String  endMarker)
        throws IOException
    {
        return new X509V2AttributeCertificate(readBytes(endMarker));
    }
View Full Code Here

                new DERSequence(roleSyntax));

        acGen.addAttribute(attributes);

        // finally create the AC
        X509V2AttributeCertificate att = (X509V2AttributeCertificate) acGen
                .generate(caPrivKey, "BC");



        //String encoded = new String(att.getEncoded());
        //System.out.println("CERT CERT: " + encoded);
        //KeyStore store = KeyStore.getInstance("PKCS12");
        //String pass = "redhat";


        /*FileOutputStream fout = new FileOutputStream("/tmp/foo.file");
        store.load(null, null);
        store.store(fout, pass.toCharArray());
        X509CertificateObject ccert = new
            X509CertificateObject(new X509CertificateStructure(new DERSequence(att)));*/
        //
        // starting here, we parse the newly generated AC
        //

        // Holder

        AttributeCertificateHolder h = att.getHolder();
        if (h.match(clientCert)) {
            if (h.getEntityNames() != null) {
//                System.out.println(h.getEntityNames().length +
//                    " entity names found");
            }
            if (h.getIssuer() != null) {
//                System.out.println(h.getIssuer().length +
//                    " issuer names found, serial number " +
//                    h.getSerialNumber());
            }
//            System.out.println("Matches original client x509 cert");
        }

        // Issuer

        AttributeCertificateIssuer issuer = att.getIssuer();
        if (issuer.match(caCert)) {
            if (issuer.getPrincipals() != null) {
//                System.out.println(issuer.getPrincipals().length +
//                    " entity names found");
            }
//            System.out.println("Matches original ca x509 cert");
        }

        // Dates
//        System.out.println("valid not before: " + att.getNotBefore());
//        System.out.println("valid not before: " + att.getNotAfter());

        // check the dates, an exception is thrown in checkValidity()...

        try {
            att.checkValidity();
            att.checkValidity(new Date());
        }
        catch (Exception e) {
            System.out.println(e);
        }

        // verify

        try {
            att.verify(caPubKey, "BC");
        }
        catch (Exception e) {
            System.out.println(e);
        }

        // Attribute
        X509Attribute[] attribs = att.getAttributes();
//        System.out.println("cert has " + attribs.length + " attributes:");
        for (int i = 0; i < attribs.length; i++) {
            X509Attribute a = attribs[i];
//            System.out.println("OID: " + a.getOID());

View Full Code Here

                    {
                        ASN1TaggedObject tagged = (ASN1TaggedObject)obj;

                        if (tagged.getTagNo() == 2)
                        {
                            certs.add(new X509V2AttributeCertificate(ASN1Sequence.getInstance(tagged, false).getEncoded()));
                        }
                    }
                }
                catch (IOException ex)
                {
View Full Code Here

                return getCertificate();
            }
        }

        return new X509V2AttributeCertificate(seq.getEncoded());
    }
View Full Code Here

            {
                Object obj = sData.getObjectAt(sDataObjectCount++);

                if (obj instanceof ASN1TaggedObject && ((ASN1TaggedObject)obj).getTagNo() == 2)
                {
                   return new X509V2AttributeCertificate(
                          ASN1Sequence.getInstance((ASN1TaggedObject)obj, false).getEncoded());
                }
            }
        }
View Full Code Here

    {
        ASN1Sequence seq = PEM_PARSER.readPEMObject(in);

        if (seq != null)
        {
            return new X509V2AttributeCertificate(seq.getEncoded());
        }

        return null;
    }
View Full Code Here

     */
    private X509AttributeCertificate readAttributeCertificate(
        String  endMarker)
        throws IOException
    {
        return new X509V2AttributeCertificate(readBytes(endMarker));
    }
View Full Code Here

TOP

Related Classes of org.bouncycastle.x509.X509V2AttributeCertificate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.