Package sun.security.x509

Examples of sun.security.x509.GeneralName


     * 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

        List<AccessDescription> descriptions = aia.getAccessDescriptions();
        for (AccessDescription description : descriptions) {
            if (description.getAccessMethod().equals(
                AccessDescription.Ad_OCSP_Id)) {

                GeneralName generalName = description.getAccessLocation();
                if (generalName.getType() == GeneralNameInterface.NAME_URI) {
                    URIName uri = (URIName) generalName.getName();
                    return uri.getURI();
                }
            }
        }
        return null;
View Full Code Here

public class NamedBitList {
    public static void main(String[] args) throws Exception {

        boolean[] bb = (new boolean[] {true, false, true, false, false, false});
        GeneralNames gns = new GeneralNames();
        gns.add(new GeneralName(new DNSName("dns")));
        DerOutputStream out;

        // length should be 5 since only {T,F,T} should be encoded
        KeyUsageExtension x1 = new KeyUsageExtension(bb);
        check(new DerValue(x1.getExtensionValue()).getUnalignedBitString().length(), 3);
View Full Code Here

            }
            //                InetAddress ipAddress = new InetAddress.getByName(alternativeName.substring(3));
            //                IPAddressName ipAddressName = new IPAddressName(ipAddress.getAddress());
            IPAddressName ipAddressName = new IPAddressName(alternativeName);
            if( alternativeNames == null ) { alternativeNames = new GeneralNames(); }
            alternativeNames.add(new GeneralName(ipAddressName));
            SubjectAlternativeNameExtension san = new SubjectAlternativeNameExtension(alternativeNames);
            if( certificateExtensions == null ) { certificateExtensions = new CertificateExtensions(); }
            certificateExtensions.set(san.getExtensionId().toString(), san);
            info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
            //   ObjectIdentifier("2.5.29.17") , false, "ipaddress".getBytes()                           
View Full Code Here

            if (dns.startsWith("dns:")) {
                alternativeName = dns.substring(4);
            }
            DNSName dnsName = new DNSName(alternativeName);
            if( alternativeNames == null ) { alternativeNames = new GeneralNames(); }
            alternativeNames.add(new GeneralName(dnsName));
            SubjectAlternativeNameExtension san = new SubjectAlternativeNameExtension(alternativeNames);
            if( certificateExtensions == null ) { certificateExtensions = new CertificateExtensions(); }
            certificateExtensions.set(san.getExtensionId().toString(), san);
            info.set(X509CertInfo.EXTENSIONS, certificateExtensions);
        }       
View Full Code Here

            case "uri": gn = new URIName(v); break;
            case "dns": gn = new DNSName(v); break;
            case "ip": gn = new IPAddressName(v); break;
            default: gn = new OIDName(v);
        }
        return new GeneralName(gn);
    }
View Full Code Here

TOP

Related Classes of sun.security.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.