当前位置: 首页>>代码示例>>Java>>正文


Java GeneralNames类代码示例

本文整理汇总了Java中org.apache.harmony.security.x509.GeneralNames的典型用法代码示例。如果您正苦于以下问题:Java GeneralNames类的具体用法?Java GeneralNames怎么用?Java GeneralNames使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GeneralNames类属于org.apache.harmony.security.x509包,在下文中一共展示了GeneralNames类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_EncodeDecode

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
public void test_EncodeDecode() throws IOException {
    
    GeneralNames subj_alt_names = new GeneralNames(Arrays
            .asList(new GeneralName[] { new GeneralName(1, "[email protected]"),
                    new GeneralName(2, "dNSName"),
                    new GeneralName(4, "O=Organization"),
                    new GeneralName(6, "http://uniform.Resource.Id"),
                    new GeneralName(7, "255.255.255.0"),
                    new GeneralName(8, "1.2.3.4444.55555") }));
    
    byte[] encoding = GeneralNames.ASN1.encode(subj_alt_names);
    
    GeneralNames gnames = (GeneralNames) GeneralNames.ASN1.decode(encoding);
    
    assertEquals("Names: ", subj_alt_names.getNames(), gnames.getNames());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:17,代码来源:GeneralNamesTest.java

示例2: testORAddress

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * ORAddress() method testing.
 */
public void testORAddress() {
    ORAddress ora = new ORAddress();
    System.out.println("");
    System.out.println("ORAddress:");
    printAsHex(8, "", " ", ora.getEncoded());
    System.out.println("");
    
    GeneralName gName = new GeneralName(ora);
    System.out.println("GeneralName:");
    printAsHex(8, "", " ", gName.getEncoded());
    System.out.println("");

    GeneralNames gNames = new GeneralNames();
    gNames.addName(gName);
    System.out.println("GeneralNames:");
    printAsHex(8, "", " ", gNames.getEncoded());
    System.out.println("");
}
 
开发者ID:shannah,项目名称:cn1,代码行数:22,代码来源:ORAddressTest.java

示例3: testORAddress

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * ORAddress() method testing.
 */
public void testORAddress() {
    try {
        ORAddress ora = new ORAddress();
        System.out.println("");
        System.out.println("ORAddress:");
        printAsHex(8, "", " ", ora.getEncoded());
        System.out.println("");
        
        GeneralName gName = new GeneralName(ora);
        System.out.println("GeneralName:");
        printAsHex(8, "", " ", gName.getEncoded());
        System.out.println("");

        GeneralNames gNames = new GeneralNames();
        gNames.addName(gName);
        System.out.println("GeneralNames:");
        printAsHex(8, "", " ", gNames.getEncoded());
        System.out.println("");

    } catch (Exception e) {
        e.printStackTrace();
        fail("Exception was thrown.");
    }
}
 
开发者ID:freeVM,项目名称:freeVM,代码行数:28,代码来源:ORAddressTest.java

示例4: test_getSubjectAlternativeNames

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * @tests java.security.cert.X509CertSelector#getSubjectAlternativeNames()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getSubjectAlternativeNames",
    args = {}
)
public void test_getSubjectAlternativeNames() {
    try {
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");

        GeneralNames sans = new GeneralNames();
        sans.addName(san1);
        sans.addName(san2);

        TestCert cert_1 = new TestCert(sans);
        X509CertSelector selector = new X509CertSelector();

        assertNull("Selector should return null", selector
                .getSubjectAlternativeNames());

        selector.setSubjectAlternativeNames(sans.getPairsList());
        assertTrue("The certificate should match the selection criteria.",
                selector.match(cert_1));
        selector.getSubjectAlternativeNames().clear();
        assertTrue("The modification of initialization object "
                + "should not affect the modification "
                + "of internal object.", selector.match(cert_1));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:37,代码来源:X509CertSelectorTest.java

示例5: test_addSubjectAlternativeNameLintLjava_lang_String2

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * @tests java.security.cert.X509CertSelector#addSubjectAlternativeName(int, String)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "addSubjectAlternativeName",
    args = {int.class, java.lang.String.class}
)
public void test_addSubjectAlternativeNameLintLjava_lang_String2() throws Exception{
    GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
    GeneralName san2 = new GeneralName(2, "dNSName");

    GeneralNames sans1 = new GeneralNames();
    sans1.addName(san6);
    sans1.addName(san2);

    X509CertSelector selector = new X509CertSelector();

    selector.addSubjectAlternativeName(6, "http://uniform.Resource.Id");
    selector.addSubjectAlternativeName(2, "dNSName");

    GeneralNames sans2 = new GeneralNames();
    sans2.addName(san2);

    TestCert cert1 = new TestCert(sans1);
    TestCert cert2 = new TestCert(sans2);

    assertTrue(selector.match(cert1));
    assertFalse(selector.match(cert2));

    selector.setSubjectAlternativeNames(null);

    GeneralName name = new GeneralName(new Name("O=Android"));
    try {
        selector.addSubjectAlternativeName(0, (name.toString()));
    } catch (IOException e) {
        // ok
    }

}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:42,代码来源:X509CertSelectorTest.java

示例6: testGeneralName

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
public void testGeneralName() {
    try {
        GeneralName san0 =
            new GeneralName(new OtherName("1.2.3.4.5", new byte[] {1, 2, 0, 1}));
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");
        GeneralName san3 = new GeneralName(new ORAddress());
        GeneralName san4 = new GeneralName(new Name("O=Organization"));
        GeneralName san5 =
            new GeneralName(new EDIPartyName("assigner", "party"));
        GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
        GeneralName san7 = new GeneralName(7, "1.1.1.1");
        GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");

        GeneralNames sans_1 = new GeneralNames();
        sans_1.addName(san0);
        sans_1.addName(san1);
        sans_1.addName(san2);
        sans_1.addName(san3);
        sans_1.addName(san4);
        sans_1.addName(san5);
        sans_1.addName(san6);
        sans_1.addName(san7);
        sans_1.addName(san8);

        byte[] encoding =  GeneralNames.ASN1.encode(sans_1);
        GeneralNames.ASN1.decode(encoding);
    } catch (Exception e) {
        // should not be thrown:
        // provided string representations are correct
        e.printStackTrace();
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:34,代码来源:GeneralNameTest.java

示例7: testGetSubjectAlternativeNames

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * getSubjectAlternativeNames() method testing.
 */
public void testGetSubjectAlternativeNames() {
    try {
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");

        GeneralNames sans = new GeneralNames();
        sans.addName(san1);
        sans.addName(san2);

        TestCert cert_1 = new TestCert(sans);
        X509CertSelector selector = new X509CertSelector();

        assertNull("Selector should return null", 
                                    selector.getSubjectAlternativeNames());

        selector.setSubjectAlternativeNames(sans.getPairsList());
        assertTrue("The certificate should match the selection criteria.",
                                                    selector.match(cert_1));
        selector.getSubjectAlternativeNames().clear();
        assertTrue("The modification of initialization object "
                    + "should not affect the modification "
                    + "of internal object.",        selector.match(cert_1));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:X509CertSelectorTest.java

示例8: testSetMatchAllSubjectAltNames

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * setMatchAllSubjectAltNames(boolean matchAllNames) method testing.
 */
public void testSetMatchAllSubjectAltNames() {
    try {
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");

        GeneralNames sans_1 = new GeneralNames();
        sans_1.addName(san1);
        GeneralNames sans_2 = new GeneralNames();
        sans_2.addName(san1);
        sans_2.addName(san2);

        TestCert cert = new TestCert(sans_1);
        X509CertSelector selector = new X509CertSelector();
        selector.setMatchAllSubjectAltNames(true);

        selector.setSubjectAlternativeNames(sans_2.getPairsList());
        assertFalse("Only certificate which contain all of the specified "
                   + "subject alternative names should match.",
                                                    selector.match(cert));
        selector.setMatchAllSubjectAltNames(false);
        /*
        assertTrue("The certificate which contain at least one of the "
                   + "specified subject alternative names must match.",
                                                    selector.match(cert));
                                                    */
    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:34,代码来源:X509CertSelectorTest.java

示例9: getCertEncoding

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * Constructs the encoded form of certificate with specified subject field
 * of TBSCertificate and specified alternative names.
 */
private byte[] getCertEncoding(Name subject, GeneralNames subjectAltNames)
                                                    throws IOException {
    // make the TBSCertificate for Certificate
    int version = 2; //v3
    BigInteger serialNumber = BigInteger.valueOf(555L); 
    AlgorithmIdentifier signature = new AlgorithmIdentifier("1.2.3.44.555");
    Name issuer = new Name("O=Certificate Issuer");
    Validity validity = new Validity(new Date(100000000), 
                                     new Date(200000000));
    SubjectPublicKeyInfo subjectPublicKeyInfo = 
        new SubjectPublicKeyInfo(
                new AlgorithmIdentifier("1.2.840.113549.1.1.2"), 
                                        new byte[10]);
    boolean[] issuerUniqueID  = new boolean[] 
                {true, false, true, false, true, false, true, false};
    boolean[] subjectUniqueID = new boolean[]
                {false, true, false, true, false, true, false, true};

    Extension extension = new Extension("2.5.29.17", 
                                        true, subjectAltNames.getEncoded());
    Extensions extensions = new Extensions();
    extensions.addExtension(extension);
   
    TBSCertificate tbsCertificate = new TBSCertificate(version, 
            serialNumber, signature, issuer, validity, subject, 
            subjectPublicKeyInfo, issuerUniqueID, subjectUniqueID, 
            extensions);

    // make the Certificate
    org.apache.harmony.security.x509.Certificate certificate = 
                    new org.apache.harmony.security.x509.Certificate
                                (tbsCertificate, signature, new byte[10]);

    return certificate.getEncoded();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:40,代码来源:X509CertSelectorTest.java

示例10: test_getPathToNames

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * @tests java.security.cert.X509CertSelector#getPathToNames()
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "getPathToNames",
    args = {}
)
public void test_getPathToNames() {
    try {
        GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5",
                new byte[] { 1, 2, 0, 1 }));
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");
        GeneralName san3 = new GeneralName(new ORAddress());
        GeneralName san4 = new GeneralName(new Name("O=Organization"));
        GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
        GeneralName san7 = new GeneralName(7, "1.1.1.1");
        GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");

        GeneralNames sans1 = new GeneralNames();
        sans1.addName(san0);
        sans1.addName(san1);
        sans1.addName(san2);
        sans1.addName(san3);
        sans1.addName(san4);
        sans1.addName(san6);
        sans1.addName(san7);
        sans1.addName(san8);
        GeneralNames sans2 = new GeneralNames();
        sans2.addName(san0);

        TestCert cert1 = new TestCert(sans1);
        TestCert cert2 = new TestCert(sans2);
        X509CertSelector selector = new X509CertSelector();
        selector.setMatchAllSubjectAltNames(true);

        selector.setPathToNames(null);
        assertTrue("Any certificate should match in the case of null "
                + "subjectAlternativeNames criteria.", selector
                .match(cert1)
                && selector.match(cert2));

        Collection<List<?>> sans = sans1.getPairsList();

        selector.setPathToNames(sans);

        Collection<List<?>> col = selector.getPathToNames();
        Iterator<List<?>> i = col.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (!(o instanceof List)) {
                fail("expected a List");
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:63,代码来源:X509CertSelectorTest.java

示例11: test_setPathToNamesLjava_util_Collection

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * @tests java.security.cert.X509CertSelector#setPathToNames(Collection<List<?>>)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "setPathToNames",
    args = {java.util.Collection.class}
)
public void test_setPathToNamesLjava_util_Collection() {
    try {
        GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5",
                new byte[] { 1, 2, 0, 1 }));
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");
        GeneralName san3 = new GeneralName(new ORAddress());
        GeneralName san4 = new GeneralName(new Name("O=Organization"));
        GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
        GeneralName san7 = new GeneralName(7, "1.1.1.1");
        GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");

        GeneralNames sans1 = new GeneralNames();
        sans1.addName(san0);
        sans1.addName(san1);
        sans1.addName(san2);
        sans1.addName(san3);
        sans1.addName(san4);
        sans1.addName(san6);
        sans1.addName(san7);
        sans1.addName(san8);
        GeneralNames sans2 = new GeneralNames();
        sans2.addName(san0);

        TestCert cert1 = new TestCert(sans1);
        TestCert cert2 = new TestCert(sans2);
        X509CertSelector selector = new X509CertSelector();
        selector.setMatchAllSubjectAltNames(true);

        selector.setPathToNames(null);
        assertTrue("Any certificate should match in the case of null "
                + "subjectAlternativeNames criteria.", selector
                .match(cert1)
                && selector.match(cert2));

        Collection<List<?>> sans = sans1.getPairsList();

        selector.setPathToNames(sans);

        Collection<List<?>> col = selector.getPathToNames();
        Iterator<List<?>> i = col.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (!(o instanceof List)) {
                fail("expected a List");
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:63,代码来源:X509CertSelectorTest.java

示例12: test_setSubjectAlternativeNamesLjava_util_Collection

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
/**
 * @tests java.security.cert.X509CertSelector#setSubjectAlternativeNames(Collection<List<?>>)
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "",
    method = "setSubjectAlternativeNames",
    args = {java.util.Collection.class}
)
public void test_setSubjectAlternativeNamesLjava_util_Collection() {

    try {
        GeneralName san0 = new GeneralName(new OtherName("1.2.3.4.5",
                new byte[] { 1, 2, 0, 1 }));
        GeneralName san1 = new GeneralName(1, "[email protected]");
        GeneralName san2 = new GeneralName(2, "dNSName");
        GeneralName san3 = new GeneralName(new ORAddress());
        GeneralName san4 = new GeneralName(new Name("O=Organization"));
        GeneralName san6 = new GeneralName(6, "http://uniform.Resource.Id");
        GeneralName san7 = new GeneralName(7, "1.1.1.1");
        GeneralName san8 = new GeneralName(8, "1.2.3.4444.55555");

        GeneralNames sans1 = new GeneralNames();
        sans1.addName(san0);
        sans1.addName(san1);
        sans1.addName(san2);
        sans1.addName(san3);
        sans1.addName(san4);
        sans1.addName(san6);
        sans1.addName(san7);
        sans1.addName(san8);
        GeneralNames sans2 = new GeneralNames();
        sans2.addName(san0);

        TestCert cert1 = new TestCert(sans1);
        TestCert cert2 = new TestCert(sans2);
        X509CertSelector selector = new X509CertSelector();
        selector.setMatchAllSubjectAltNames(true);

        selector.setSubjectAlternativeNames(null);
        assertTrue("Any certificate should match in the case of null "
                + "subjectAlternativeNames criteria.", selector
                .match(cert1)
                && selector.match(cert2));

        Collection<List<?>> sans = sans1.getPairsList();

        selector.setSubjectAlternativeNames(sans);

        Collection<List<?>> col = selector.getSubjectAlternativeNames();
        Iterator<List<?>> i = col.iterator();
        while (i.hasNext()) {
            Object o = i.next();
            if (!(o instanceof List)) {
                fail("expected a List");
            }
        }

    } catch (IOException e) {
        e.printStackTrace();
        fail("Unexpected IOException was thrown.");
    }
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:64,代码来源:X509CertSelectorTest.java

示例13: TestCert

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
public TestCert(GeneralNames sans) {
    setSubjectAlternativeNames(sans);
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:4,代码来源:X509CertSelectorTest.java

示例14: setSubjectAlternativeNames

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
public void setSubjectAlternativeNames(GeneralNames sans) {
    this.sans = sans;
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:4,代码来源:X509CertSelectorTest.java

示例15: getExtensionValue

import org.apache.harmony.security.x509.GeneralNames; //导入依赖的package包/类
public byte[] getExtensionValue(String oid) {

            if (("2.5.29.14".equals(oid)) || ("2.5.29.35".equals(oid))) {
                // Extension value is represented as an OctetString
                return ASN1OctetString.getInstance().encode(keyIdentifier);
            }
            if ("2.5.29.16".equals(oid)) {
                PrivateKeyUsagePeriod pkup = new PrivateKeyUsagePeriod(
                        notBefore, notAfter);
                byte[] encoded = pkup.getEncoded();
                return ASN1OctetString.getInstance().encode(encoded);
            }
            if (("2.5.29.37".equals(oid)) && (extKeyUsage != null)) {
                ASN1Oid[] oa = new ASN1Oid[extKeyUsage.size()];
                String[] val = new String[extKeyUsage.size()];
                Iterator it = extKeyUsage.iterator();
                int id = 0;
                while (it.hasNext()) {
                    oa[id] = ASN1Oid.getInstanceForString();
                    val[id++] = (String) it.next();
                }
                return ASN1OctetString.getInstance().encode(
                        new ASN1Sequence(oa).encode(val));
            }
            if ("2.5.29.19".equals(oid)) {
                return ASN1OctetString.getInstance().encode(
                        new ASN1Sequence(new ASN1Type[] {
                                ASN1Boolean.getInstance(),
                                ASN1Integer.getInstance() })
                                .encode(new Object[] {
                                        new Boolean(pathLen != 1),
                                        BigInteger.valueOf(pathLen)
                                                .toByteArray() }));
            }
            if ("2.5.29.17".equals(oid) && (sans != null)) {
                if (sans.getNames() == null) {
                    return null;
                }
                return ASN1OctetString.getInstance().encode(
                        GeneralNames.ASN1.encode(sans));
            }
            if ("2.5.29.32".equals(oid) && (policies != null)
                    && (policies.length > 0)) {
                // Certificate Policies Extension (as specified in rfc 3280)
                CertificatePolicies certificatePolicies = new CertificatePolicies();
                for (int i = 0; i < policies.length; i++) {
                    PolicyInformation policyInformation = new PolicyInformation(
                            policies[i]);
                    certificatePolicies.addPolicyInformation(policyInformation);
                }
                return ASN1OctetString.getInstance().encode(
                        certificatePolicies.getEncoded());
            }
            if ("2.5.29.30".equals(oid) && (nameConstraints != null)) { //
                // Name
                // Constraints
                // Extension
                // (as
                // specified
                // in
                // rfc
                // 3280)
                return ASN1OctetString.getInstance().encode(
                        nameConstraints.getEncoded());
            }

            return null;
        }
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:69,代码来源:X509CertSelectorTest.java


注:本文中的org.apache.harmony.security.x509.GeneralNames类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。