當前位置: 首頁>>代碼示例>>Java>>正文


Java X509CertSelector.addSubjectAlternativeName方法代碼示例

本文整理匯總了Java中java.security.cert.X509CertSelector.addSubjectAlternativeName方法的典型用法代碼示例。如果您正苦於以下問題:Java X509CertSelector.addSubjectAlternativeName方法的具體用法?Java X509CertSelector.addSubjectAlternativeName怎麽用?Java X509CertSelector.addSubjectAlternativeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.cert.X509CertSelector的用法示例。


在下文中一共展示了X509CertSelector.addSubjectAlternativeName方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testSubjectAltName

import java.security.cert.X509CertSelector; //導入方法依賴的package包/類
private void testSubjectAltName() throws IOException {
    System.out.println("X.509 Certificate Match on subjectAltName");
    // bad match
    X509CertSelector selector = new X509CertSelector();
    GeneralNameInterface dnsName = new DNSName("foo.com");
    DerOutputStream tmp = new DerOutputStream();
    dnsName.encode(tmp);
    selector.addSubjectAlternativeName(2, tmp.toByteArray());
    checkMatch(selector, cert, false);

    // good match
    DerInputStream in = new DerInputStream(cert.getExtensionValue("2.5.29.17"));
    byte[] encoded = in.getOctetString();
    SubjectAlternativeNameExtension ext = new SubjectAlternativeNameExtension(false, encoded);
    GeneralNames names = (GeneralNames) ext.get(SubjectAlternativeNameExtension.SUBJECT_NAME);
    GeneralName name = (GeneralName) names.get(0);
    selector.setSubjectAlternativeNames(null);
    DerOutputStream tmp2 = new DerOutputStream();
    name.getName().encode(tmp2);
    selector.addSubjectAlternativeName(name.getType(), tmp2.toByteArray());
    checkMatch(selector, cert, true);

    // good match 2 (matches at least one)
    selector.setMatchAllSubjectAltNames(false);
    selector.addSubjectAlternativeName(2, "foo.com");
    checkMatch(selector, cert, true);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:X509CertSelectorTest.java

示例2: test_addSubjectAlternativeNameLintLjava_lang_String2

import java.security.cert.X509CertSelector; //導入方法依賴的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

示例3: test_addSubjectAlternativeNameLintLbyte_array2

import java.security.cert.X509CertSelector; //導入方法依賴的package包/類
/**
 * @tests java.security.cert.X509CertSelector#addSubjectAlternativeName(int, byte[])
 */
@TestTargetNew(
    level = TestLevel.COMPLETE,
    notes = "IOException checking missed",
    method = "addSubjectAlternativeName",
    args = {int.class, byte[].class}
)
public void test_addSubjectAlternativeNameLintLbyte_array2()
        throws Exception {


    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");

    GeneralNames sans1 = new GeneralNames();
    sans1.addName(san0);
    sans1.addName(san1);
    sans1.addName(san2);

    X509CertSelector selector = new X509CertSelector();

    selector.addSubjectAlternativeName(0, san0.getEncodedName());
    selector.addSubjectAlternativeName(1, san1.getEncodedName());
    selector.addSubjectAlternativeName(2, san2.getEncodedName());

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

    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.getEncodedName());
    } catch (IOException e) {
        // ok
    }

}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:49,代碼來源:X509CertSelectorTest.java


注:本文中的java.security.cert.X509CertSelector.addSubjectAlternativeName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。