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


Java X509Certificate.getExtendedKeyUsage方法代碼示例

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


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

示例1: verifyKeyUsage

import java.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * If an EKU extension is present in the end-entity certificate, it MUST contain either the
 * anyEKU or serverAuth or netscapeSGC or Microsoft SGC EKUs.
 *
 * @return true if there is no EKU extension or if any of the EKU extensions is one of the valid
 * OIDs for web server certificates.
 *
 * TODO(palmer): This can be removed after the equivalent change is made to the Android default
 * TrustManager and that change is shipped to a large majority of Android users.
 */
static boolean verifyKeyUsage(X509Certificate certificate) throws CertificateException {
    List<String> ekuOids;
    try {
        ekuOids = certificate.getExtendedKeyUsage();
    } catch (NullPointerException e) {
        // getExtendedKeyUsage() can crash due to an Android platform bug. This probably
        // happens when the EKU extension data is malformed so return false here.
        // See http://crbug.com/233610
        return false;
    }
    if (ekuOids == null) return true;

    for (String ekuOid : ekuOids) {
        if (ekuOid.equals(OID_TLS_SERVER_AUTH)
                || ekuOid.equals(OID_ANY_EKU)
                || ekuOid.equals(OID_SERVER_GATED_NETSCAPE)
                || ekuOid.equals(OID_SERVER_GATED_MICROSOFT)) {
            return true;
        }
    }

    return false;
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:34,代碼來源:X509Util.java


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