Package org.bouncycastle.asn1.x509

Examples of org.bouncycastle.asn1.x509.X509Name


            // Add the signerInfo version
            //
            signerinfo.add(new DERInteger(signerversion));

            IssuerAndSerialNumber isAnds = new IssuerAndSerialNumber(
                        new X509Name((ASN1Sequence)getIssuer(signCert.getTBSCertificate())),
                        new DERInteger(signCert.getSerialNumber()));
            signerinfo.add(isAnds);

            // Add the digestAlgorithm
            //
View Full Code Here


            X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
            X500Principal principal = new X500Principal(identifier);

//            certGen.setIssuerDN(PrincipalUtil.getSubjectX509Principal(caCert));
            certGen.setIssuerDN(new X509Name(PrincipalUtil.getSubjectX509Principal(caCert).getName()));
            certGen.setSerialNumber(serialNumber);
            certGen.setNotBefore(startDate);
            certGen.setNotAfter(expiryDate);

//            certGen.setSubjectDN(principal);
            certGen.setSubjectDN(new X509Name(principal.getName()));
            certGen.setPublicKey(key);
            certGen.setSignatureAlgorithm("SHA1withRSA");

            certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false,
                    new AuthorityKeyIdentifierStructure(caCert));
View Full Code Here

            gen.setSerialNumber(new DERInteger(1));
           
            gen.setStartDate(new Time(startDate));
            gen.setEndDate(new Time(endDate));
           
            gen.setIssuer(new X509Name("CN=AU,O=Bouncy Castle"));
            gen.setSubject(new X509Name("CN=AU,O=Bouncy Castle,OU=Test 1"));
           
            gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.md5WithRSAEncryption, new DERNull()));
           
            SubjectPublicKeyInfo    info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, new DERNull()),
                                                         new RSAPublicKeyStructure(BigInteger.valueOf(1), BigInteger.valueOf(2)));
View Full Code Here

            gen.setSerialNumber(new DERInteger(2));
           
            gen.setStartDate(new Time(startDate));
            gen.setEndDate(new Time(endDate));
           
            gen.setIssuer(new X509Name("CN=AU,O=Bouncy Castle"));
            gen.setSubject(new X509Name("CN=AU,O=Bouncy Castle,OU=Test 2"));
           
            gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.md5WithRSAEncryption, new DERNull()));
          
            SubjectPublicKeyInfo    info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(BigInteger.valueOf(1), BigInteger.valueOf(2))), new DERInteger(3));

            gen.setSubjectPublicKeyInfo(info);
           
            //
            // add extensions
            //
            Vector          order = new Vector();
            Hashtable       extensions = new Hashtable();
           
            order.addElement(X509Extensions.AuthorityKeyIdentifier);
            order.addElement(X509Extensions.SubjectKeyIdentifier);
            order.addElement(X509Extensions.KeyUsage);
           
            extensions.put(X509Extensions.AuthorityKeyIdentifier, new X509Extension(true, new DEROctetString(createAuthorityKeyId(info, new X509Name("CN=AU,O=Bouncy Castle,OU=Test 2"), 2))));
            extensions.put(X509Extensions.SubjectKeyIdentifier, new X509Extension(true, new DEROctetString(new SubjectKeyIdentifier(info))));
            extensions.put(X509Extensions.KeyUsage, new X509Extension(false, new DEROctetString(new KeyUsage(KeyUsage.dataEncipherment))));
           
            X509Extensions  ex = new X509Extensions(order, extensions);
           
View Full Code Here

    {
        try
        {
            V2TBSCertListGenerator  gen = new V2TBSCertListGenerator();
           
            gen.setIssuer(new X509Name("CN=AU,O=Bouncy Castle"));
           
            gen.addCRLEntry(new DERInteger(1), new Time(new Date(1000)), ReasonFlags.AA_COMPROMISE);
           
            gen.setNextUpdate(new Time(new Date(2000)));
           
            gen.setThisUpdate(new Time(new Date(500)));
           
            gen.setSignature(new AlgorithmIdentifier(PKCSObjectIdentifiers.sha1WithRSAEncryption, new DERNull()));
           
            //
            // extensions
            //
            Vector                  order = new Vector();
            Hashtable               extensions = new Hashtable();
            SubjectPublicKeyInfo    info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(OIWObjectIdentifiers.elGamalAlgorithm, new ElGamalParameter(BigInteger.valueOf(1), BigInteger.valueOf(2))), new DERInteger(3));

            order.addElement(X509Extensions.AuthorityKeyIdentifier);
            order.addElement(X509Extensions.IssuerAlternativeName);
            order.addElement(X509Extensions.CRLNumber);
            order.addElement(X509Extensions.IssuingDistributionPoint);
           
            extensions.put(X509Extensions.AuthorityKeyIdentifier, new X509Extension(true, new DEROctetString(createAuthorityKeyId(info, new X509Name("CN=AU,O=Bouncy Castle,OU=Test 2"), 2))));
            extensions.put(X509Extensions.IssuerAlternativeName, new X509Extension(false, new DEROctetString(new GeneralNames(new DERSequence(new GeneralName(new X509Name("CN=AU,O=Bouncy Castle,OU=Test 3")))))));
            extensions.put(X509Extensions.CRLNumber, new X509Extension(false, new DEROctetString(new DERInteger(1))));
            extensions.put(X509Extensions.IssuingDistributionPoint, new X509Extension(true, new DEROctetString(new IssuingDistributionPoint(new DERSequence()))));

            X509Extensions          ex = new X509Extensions(order, extensions);
           
View Full Code Here

        attrs.put(X509Name.O, "The Legion of the Bouncy Castle");
        attrs.put(X509Name.L, "Melbourne");
        attrs.put(X509Name.ST, "Victoria");
        attrs.put(X509Name.E, "feedback-crypto@bouncycastle.org");

        X509Name    name1 = new X509Name(attrs);

        if (!name1.equals(name1))
        {
            return new SimpleTestResult(false, getName() + ": Failed same object test");
        }

        X509Name    name2 = new X509Name(attrs);

        if (!name1.equals(name2))
        {
            return new SimpleTestResult(false, getName() + ": Failed same name test");
        }

        Vector  ord1 = new Vector();

        ord1.addElement(X509Name.C);
        ord1.addElement(X509Name.O);
        ord1.addElement(X509Name.L);
        ord1.addElement(X509Name.ST);
        ord1.addElement(X509Name.E);

        Vector  ord2 = new Vector();

        ord2.addElement(X509Name.E);
        ord2.addElement(X509Name.ST);
        ord2.addElement(X509Name.L);
        ord2.addElement(X509Name.O);
        ord2.addElement(X509Name.C);

        name1 = new X509Name(ord1, attrs);
        name2 = new X509Name(ord2, attrs);

        if (!name1.equals(name2))
        {
            return new SimpleTestResult(false, getName() + ": Failed reverse name test");
        }

        ord2 = new Vector();

        ord2.addElement(X509Name.ST);
        ord2.addElement(X509Name.ST);
        ord2.addElement(X509Name.L);
        ord2.addElement(X509Name.O);
        ord2.addElement(X509Name.C);

        name1 = new X509Name(ord1, attrs);
        name2 = new X509Name(ord2, attrs);

        if (name1.equals(name2))
        {
            return new SimpleTestResult(false, getName() + ": Failed different name test");
        }

        ord2 = new Vector();

        ord2.addElement(X509Name.ST);
        ord2.addElement(X509Name.L);
        ord2.addElement(X509Name.O);
        ord2.addElement(X509Name.C);

        name1 = new X509Name(ord1, attrs);
        name2 = new X509Name(ord2, attrs);

        if (name1.equals(name2))
        {
            return new SimpleTestResult(false, getName() + ": Failed subset name test");
        }
       
        //
        // composite test
        //
        try
        {
            byte[]  enc = Hex.decode("305e310b300906035504061302415531283026060355040a131f546865204c6567696f6e206f662074686520426f756e637920436173746c6531253010060355040713094d656c626f75726e653011060355040b130a4173636f742056616c65");
           
            ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(enc));
           
            X509Name    n = X509Name.getInstance(aIn.readObject());
           
            if (!n.toString().equals("C=AU,O=The Legion of the Bouncy Castle,L=Melbourne+OU=Ascot Vale"))
            {
                return new SimpleTestResult(false, getName() + ": Failed composite to string test");
            }
           
            n = new X509Name("C=AU, O=The Legion of the Bouncy Castle, L=Melbourne + OU=Ascot Vale");
           
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            ASN1OutputStream        aOut = new ASN1OutputStream(bOut);
           
            aOut.writeObject(n);
           
            byte[]  enc2 = bOut.toByteArray();
           
            if (enc.length != enc2.length)
            {
                return new SimpleTestResult(false, getName() + ": Failed composite string to encoding test");
            }
           
            for (int i = 0; i != enc.length; i++)
            {
                if (enc[i] != enc2[i])
                {
                    return new SimpleTestResult(false, getName() + ": Failed composite string to encoding test");
                }
            }

            //
            // general subjects test
            //
            for (int i = 0; i != subjects.length; i++)
            {
                X509Name    name = new X509Name(subjects[i]);

                bOut = new ByteArrayOutputStream();
                aOut = new ASN1OutputStream(bOut);
           
                aOut.writeObject(name);

                aIn = new ASN1InputStream(new ByteArrayInputStream(bOut.toByteArray()));

                name = X509Name.getInstance(aIn.readObject());

                if (!name.toString().equals(subjects[i]))
                {
                    return new SimpleTestResult(false, getName() + ": failed regeneration test " + i);
                }
            }

            //
            // sort test
            //
            X509Name unsorted = new X509Name("SN=BBB + CN=AA");

            if (!fromBytes(unsorted.getEncoded()).toString().equals("CN=AA+SN=BBB"))
            {
                return new SimpleTestResult(false, getName() + ": failed sort test 1");
            }

            unsorted = new X509Name("CN=AA + SN=BBB");

            if (!fromBytes(unsorted.getEncoded()).toString().equals("CN=AA+SN=BBB"))
            {
                return new SimpleTestResult(false, getName() + ": failed sort test 2");
            }

            unsorted = new X509Name("SN=B + CN=AA");

            if (!fromBytes(unsorted.getEncoded()).toString().equals("SN=B+CN=AA"))
            {
                return new SimpleTestResult(false, getName() + ": failed sort test 3");
            }
           
            unsorted = new X509Name("CN=AA + SN=B");

            if (!fromBytes(unsorted.getEncoded()).toString().equals("SN=B+CN=AA"))
            {
                return new SimpleTestResult(false, getName() + ": failed sort test 4");
            }
        }
        catch (Exception e)
View Full Code Here

     */
    public static String createSigningRequest(X509Certificate cert, PrivateKey privKey) throws Exception {
        StringBuilder sb = new StringBuilder();

        String subject = cert.getSubjectDN().getName();
        X509Name xname = new X509Name(subject);

        PublicKey pubKey = cert.getPublicKey();

        String signatureAlgorithm = "DSA".equals(pubKey.getAlgorithm()) ? "SHA1withDSA" : "SHA1WITHRSAENCRYPTION";

View Full Code Here

        X509V3CertificateGenerator certGenerator = new X509V3CertificateGenerator();
        certGenerator.reset();

        certGenerator.setSerialNumber(serial);
        certGenerator.setIssuerDN(new X509Name(issuerDN));
        certGenerator.setNotBefore(new Date(System.currentTimeMillis()));
        certGenerator.setNotAfter(
                new Date(System.currentTimeMillis() + months * (1000L * 60 * 60 * 24 * 30)));
        certGenerator.setSubjectDN(new X509Name(subjectDN));
        certGenerator.setPublicKey(pubKey);
        certGenerator.setSignatureAlgorithm(signAlgoritm);

        // Generate the subject alternative name
        boolean critical = subjectDN == null || "".equals(subjectDN.trim());
View Full Code Here

      */

      DERInteger serialNumber = null;
      AlgorithmIdentifier algorithmIdentifier = null;
      X509Name issuerNm = null;
      OptionalValidity optionalValidity = null;
      X509Name subject = null;
      SubjectPublicKeyInfo subjectPublicKeyInfo = null;
      X509Extensions extensions = null;

      ASN1Sequence certTemplateSeq = (ASN1Sequence) certTemplate
        .getDERObject();
View Full Code Here

    System.out.println("not before=" + notbefore);
  }


  public void testDN() throws Exception {
    X509Name x509Name = new X509Name(KeygenService.issuer);
    //todo some testing on this way of doing things.
  }
View Full Code Here

TOP

Related Classes of org.bouncycastle.asn1.x509.X509Name

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.