Package codec.x509

Examples of codec.x509.GeneralName


    /**
     * setMatchAllSubjectAltNames(boolean matchAllNames) method testing.
     */
    public void testSetMatchAllSubjectAltNames() {
        try {
            GeneralName san1 = new GeneralName(1, "rfc@822.Name");
            GeneralName san2 = new GeneralName(2, "dNSName");

            GeneralNames sans_1 = new GeneralNames();
            sans_1.addName(san1);
            GeneralNames sans_2 = new GeneralNames();
            sans_2.addName(san1);
View Full Code Here


        // Restrictions apply only when the specified name form is present. 
        // If no name of the type is in the certificate,
        // the certificate is acceptable (rfc 3280).
       
        GeneralName [] name_constraints = new GeneralName[] {
            new GeneralName(1, "822.Name"),
            new GeneralName(1, "rfc@822.Name"),
            new GeneralName(2, "Name.org"),
            new GeneralName(2, "dNS.Name.org"),
            //new GeneralName(4, "O=Organization"),
            new GeneralName(6, "http://.Resource.Id"),
            new GeneralName(6, "http://uniform.Resource.Id"),
            new GeneralName(7, "1.1.1.1"),
            // new GeneralName(7, new byte[] {1, 1, 1, 1, 3, 3, 3, 3}),
            new GeneralName(new byte[] {1, 1, 1, 1, 1, 1, 1, 1,
                                        1, 1, 1, 1, 1, 1, 1, 1}),
            // new GeneralName(7, new byte[] {1, 1, 1, 1, 1, 1, 1, 1,
            //                                1, 1, 1, 1, 1, 1, 1, 1,
            //                                3, 3, 3, 3, 3, 3, 3, 3,
            //                                3, 3, 3, 3, 3, 3, 3, 3})
        };

        // names which should match divided from names which should not
        // match by null
        GeneralName[][] alternative_names = new GeneralName[][] {
            {
                new GeneralName(1, "rfc@822.Name"),
                null,
                new GeneralName(1, "rfc@Other.Name")
            }, {
                new GeneralName(1, "rfc@822.Name"),
                null,
                new GeneralName(1, "rfc@Other.Name")
            }, {
                new GeneralName(2, "Name.org"),
                new GeneralName(2, "dNS.Name.org"),
                null,
                new GeneralName(2, "dNS.OtherName.org")
            }, {
                new GeneralName(2, "dNS.Name.org"),
                null,
                new GeneralName(2, "Name.org"),
                new GeneralName(2, "dNS.OtherName.org")
            }, {
               
            //    new GeneralName(4, "O=Organization"),
            //    null,
            //    new GeneralName(4, "O=OtherOrganization")
            //}, {
           
                new GeneralName(6, "http://uniform.Resource.Id/location"),
                null,
                //new GeneralName(6, "http://Resource.Id")
            }, {
                new GeneralName(6, "http://uniform.Resource.Id"),
                null,
                new GeneralName(6, "http://Resource.Id")
            }, {
                new GeneralName(new byte[] {1, 1, 1, 1}),
                null,
                new GeneralName(new byte[] {2, 2, 2, 2})
            // }, {
            //     new GeneralName(7, new byte[] {1, 1, 1, 1}),
            //     new GeneralName(7, new byte[] {2, 2, 2, 2}),
            //     new GeneralName(7, new byte[] {3, 3, 3, 3}),
            //     null,
            //     new GeneralName(7, new byte[] {4, 4, 4, 4})
            }, {
                new GeneralName(new byte[] {1, 1, 1, 1, 1, 1, 1, 1,
                                            1, 1, 1, 1, 1, 1, 1, 1}),
                null,
                new GeneralName(new byte[] {2, 2, 2, 2, 2, 2, 2, 2,
                                            2, 2, 2, 2, 2, 2, 2, 2}),
            // }, {
            //     new GeneralName(7, new byte[] {1, 1, 1, 1, 1, 1, 1, 1,
            //                                    1, 1, 1, 1, 1, 1, 1, 1}),
            //     new GeneralName(7, new byte[] {2, 2, 2, 2, 2, 2, 2, 2,
View Full Code Here

     * GeneralNames of types: 1, 2, 6, 7 and set it as a criterion.
     */
    public void testSetNameConstraints1() throws IOException {

        GeneralName [] name_constraints = new GeneralName[] {
            new GeneralName(1, "822.Name"),
            new GeneralName(1, "rfc@822.Name"),
            new GeneralName(2, "Name.org"),
            new GeneralName(2, "dNS.Name.org"),
            new GeneralName(6, "http://.Resource.Id"),
            new GeneralName(6, "http://uniform.Resource.Id"),
            new GeneralName(7, "1.1.1.1"),
            new GeneralName(7, "1.1.1.1/3.3.3.3"),
            new GeneralName(7, "0101:0101:0101:0101:0101:0101:0101:0101"),
            new GeneralName(7, "0101:0101:0101:0101:0101:0101:0101:0101"
                            + "/0303:0303:0303:0303:0303:0303:0303:0303"),
        };

        // Names which should match divided from names which should not
        // match by null.
        // Restrictions apply only when the specified name form is present. 
        // If no name of the type is in the certificate, the certificate
        // is acceptable (rfc 3280). This assertion is checked during processing
        // of null GeneralName object (it also serves as separator).
        GeneralName[][] alternative_names = new GeneralName[][] {
            {
                new GeneralName(1, "rfc@822.Name"),
                null,
                new GeneralName(1, "rfc@Other.Name")
            }, {
                new GeneralName(1, "rfc@822.Name"),
                null,
                new GeneralName(1, "rfc@Other.Name")
            }, {
                new GeneralName(2, "Name.org"),
                new GeneralName(2, "dNS.Name.org"),
                null,
                new GeneralName(2, "dNS.OtherName.org")
            }, {
                new GeneralName(2, "dNS.Name.org"),
                null,
                new GeneralName(2, "Name.org"),
                new GeneralName(2, "dNS.OtherName.org")
            }, {
               
                new GeneralName(6, "http://uniform.Resource.Id/location"),
                null,
                new GeneralName(6, "http://Resource.Id")
            }, {
                new GeneralName(6, "http://uniform.Resource.Id"),
                null,
                new GeneralName(6, "http://Resource.Id")
            }, {
                new GeneralName(new byte[] {1, 1, 1, 1}),
                null,
                new GeneralName(new byte[] {2, 2, 2, 2})
            }, {
                new GeneralName(new byte[] {1, 1, 1, 1}),
                new GeneralName(new byte[] {2, 2, 2, 2}),
                new GeneralName(new byte[] {3, 3, 3, 3}),
                null,
                new GeneralName(new byte[] {4, 4, 4, 4})
            }, {
                new GeneralName(new byte[] {1, 1, 1, 1, 1, 1, 1, 1,
                                            1, 1, 1, 1, 1, 1, 1, 1}),
                null,
                new GeneralName(new byte[] {2, 2, 2, 2, 2, 2, 2, 2,
                                            2, 2, 2, 2, 2, 2, 2, 2}),
            }, {
                new GeneralName(new byte[] {1, 1, 1, 1, 1, 1, 1, 1,
                                            1, 1, 1, 1, 1, 1, 1, 1}),
                new GeneralName(new byte[] {2, 2, 2, 2, 2, 2, 2, 2,
                                            2, 2, 2, 2, 2, 2, 2, 2}),
                new GeneralName(new byte[] {3, 3, 3, 3, 3, 3, 3, 3,
                                            3, 3, 3, 3, 3, 3, 3, 3}),
                null,
                new GeneralName(new byte[] {4, 4, 4, 4, 4, 4, 4, 4,
                                            4, 4, 4, 4, 4, 4, 4, 4}),
            }
        };

        X509CertSelector selector = new X509CertSelector();
View Full Code Here

        try {
            for (int i=0; i<variants.length; i++) {
                // make the names objects
                X500Principal subject = new X500Principal(variants[i][0]);
                Name subject_name = new Name(variants[i][0]);
                GeneralName alt_name = new GeneralName(4, variants[i][1]);
                // make the certificate to be checked
                GeneralNames alt_names_extension = new GeneralNames();
                alt_names_extension.addName(alt_name);
                TestCert certificate = new TestCert(alt_names_extension);
                certificate.setSubject(subject);
                certificate.setEncoding(getCertEncoding(subject_name,
                                                 alt_names_extension));
                // make the subtrees (part of name constraints)
                // this subtrees will be used as permited and as excluded
                // name which is presented in certificate:
                GeneralSubtrees pos_subtrees = new GeneralSubtrees();
                pos_subtrees.addSubtree(
                        new GeneralSubtree(
                            new GeneralName(4, variants[i][2])));
                // name which is absent in certificate:
                GeneralSubtrees neg_subtrees = new GeneralSubtrees();
                neg_subtrees.addSubtree(
                        new GeneralSubtree(
                            new GeneralName(4, variants[i][3])));

                NameConstraints constraints;
                // Work with name which is presented in certificate
                // first check if certificate with permited name matches:
                constraints = new NameConstraints(pos_subtrees, null);
View Full Code Here

     * setPathToNames(Collection<List<?>> names) method testing.
     */
    public void testSetPathToNames() {
        try {
            GeneralName[] names = new GeneralName[] {
                new GeneralName(1, "rfc@822.Name"),
                new GeneralName(1, "rfc@822.AnotherName"),
                new GeneralName(2, "dNSName"),
                new GeneralName(2, "AnotherdNSName"),
                new GeneralName(4, "O=Organization"),
                new GeneralName(4, "O=Another Organization"),
                new GeneralName(6, "http://uniform.Resource.Id"),
                new GeneralName(6, "http://another.uniform.Resource.Id"),
                new GeneralName(7, "1.1.1.1"),
                new GeneralName(7, "2.2.2.2")
            };

            X509CertSelector selector = new X509CertSelector();

            TestCert cert;
View Full Code Here

                subtrees = new GeneralSubtrees();
                for (int j=i+2; j<names.length; j++) {
                    if (i != j && i+1 != j) {
                        subtrees.addSubtree(
                                new GeneralSubtree(
                                    new GeneralName(types[j], names[j])));
                    }
                }
                constraints = new NameConstraints(subtrees, null);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the names "
                            + "of such type so method match() should "
                            + "return true.", selector.match(cert));

                constraints = new NameConstraints(subtrees, subtrees);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the names "
                            + "of such type so method match() should "
                            + "return true.", selector.match(cert));

                constraints = new NameConstraints(null, subtrees);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the names "
                            + "of such type so method match() should "
                            + "return true.", selector.match(cert));

                subtrees.addSubtree(
                        new GeneralSubtree(
                            new GeneralName(types[i+1], names[i+1])));

                constraints = new NameConstraints(subtrees, null);
                cert = new TestCert(constraints);
                assertFalse("The Name Constraints Extension of the "
                            + "certificate does not contain the name "
                            + "as a permitted name so method match() "
                            + "should return false", selector.match(cert));

                constraints = new NameConstraints(subtrees, subtrees);
                cert = new TestCert(constraints);
                assertFalse("The Name Constraints Extension of the "
                            + "certificate does not contain the name "
                            + "as an excluded name but it does not "
                            + "contain this name as a permitted so match()"
                            + "should return false", selector.match(cert));

                constraints = new NameConstraints(null, subtrees);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the name "
                            + "as an excluded name so method match() "
                            + "should return true", selector.match(cert));

                subtrees.addSubtree(
                        new GeneralSubtree(
                            new GeneralName(types[i], names[i])));

                constraints = new NameConstraints(subtrees, null);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate contains the name "
View Full Code Here

     */
    public void testAddPathToName2() {
        try {
            int[] types = new int[] {1, 1, 2, 2, 4, 4, 6, 6, 7, 7};
            byte[][] names = new byte[][] {
                new GeneralName(1, "rfc@822.Name").getEncodedName(),
                new GeneralName(1, "rfc@822.AnotherName").getEncodedName(),
                new GeneralName(2, "dNSName").getEncodedName(),
                new GeneralName(2, "AnotherdNSName").getEncodedName(),
                new GeneralName(4, "O=Organization").getEncodedName(),
                new GeneralName(4, "O=Another Organization").getEncodedName(),
                new GeneralName(6, "http://uniform.Resource.Id")
                                                            .getEncodedName(),
                new GeneralName(6, "http://another.uniform.Resource.Id")
                                                            .getEncodedName(),
                new GeneralName(7, "1.1.1.1").getEncodedName(),
                new GeneralName(7, "2.2.2.2").getEncodedName()
            };

            X509CertSelector selector = new X509CertSelector();

            TestCert cert;
            GeneralSubtrees subtrees;
            NameConstraints constraints;
            for (int i=0; i<names.length-2; i+=2) {
                // Set up the pathToNames criterion
                selector.addPathToName(types[i], names[i]);
               
                // Construct the subtrees without the current name
                subtrees = new GeneralSubtrees();
                for (int j=i+2; j<names.length; j++) {
                    if (i != j && i+1 != j) {
                        subtrees.addSubtree(
                                new GeneralSubtree(
                                    new GeneralName(types[j], names[j])));
                    }
                }
                constraints = new NameConstraints(subtrees, null);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the names "
                            + "of such type so method match() should "
                            + "return true.", selector.match(cert));

                constraints = new NameConstraints(subtrees, subtrees);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the names "
                            + "of such type so method match() should "
                            + "return true.", selector.match(cert));

                constraints = new NameConstraints(null, subtrees);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the names "
                            + "of such type so method match() should "
                            + "return true.", selector.match(cert));

                subtrees.addSubtree(
                        new GeneralSubtree(
                            new GeneralName(types[i+1], names[i+1])));

                constraints = new NameConstraints(subtrees, null);
                cert = new TestCert(constraints);
                assertFalse("The Name Constraints Extension of the "
                            + "certificate does not contain the name "
                            + "as a permitted name so method match() "
                            + "should return false", selector.match(cert));

                constraints = new NameConstraints(subtrees, subtrees);
                cert = new TestCert(constraints);
                assertFalse("The Name Constraints Extension of the "
                            + "certificate does not contain the name "
                            + "as an excluded name but it does not "
                            + "contain this name as a permitted so match()"
                            + "should return false", selector.match(cert));

                constraints = new NameConstraints(null, subtrees);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate does not contain the name "
                            + "as an excluded name so method match() "
                            + "should return true", selector.match(cert));

                subtrees.addSubtree(
                        new GeneralSubtree(
                            new GeneralName(types[i], names[i])));

                constraints = new NameConstraints(subtrees, null);
                cert = new TestCert(constraints);
                assertTrue("The Name Constraints Extension of the "
                            + "certificate contains the name "
View Full Code Here

     * getPathToNames() method testing.
     */
    public void testGetPathToNames() {
        try {
            byte[] encoding =
                new GeneralName(1, "rfc@822.Name").getEncodedName();

            X509CertSelector selector = new X509CertSelector();

            selector.addPathToName(1, encoding);
            encoding[0]++;
View Full Code Here

                "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9",
                "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7"}
        ));
        GeneralNames subjectAltNames = new GeneralNames(Arrays.asList(
            new GeneralName[] {
                new GeneralName(1, "rfc@822.Name"),
                new GeneralName(2, "dNSName"),
                new GeneralName(6, "http://uniform.Resource.Id"),
                new GeneralName(7, "1.1.1.1")
            }
        ));
        String[] policies = new String[] {
            "0.0.0.0.0.0",
            "1.1.1.1.1.1",
View Full Code Here

                "1.3.6.1.5.5.7.3.4", "1.3.6.1.5.5.7.3.8", "1.3.6.1.5.5.7.3.9",
                "1.3.6.1.5.5.7.3.5", "1.3.6.1.5.5.7.3.6", "1.3.6.1.5.5.7.3.7"}
        ));
        GeneralNames subjectAltNames = new GeneralNames(Arrays.asList(
            new GeneralName[] {
                new GeneralName(1, "rfc@822.Name"),
                new GeneralName(2, "dNSName"),
                new GeneralName(6, "http://uniform.Resource.Id"),
                new GeneralName(7, "1.1.1.1")
            }
        ));
        String[] policies = new String[] {
            "0.0.0.0.0.0",
            "1.1.1.1.1.1",
View Full Code Here

TOP

Related Classes of codec.x509.GeneralName

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.