当前位置: 首页>>代码示例>>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;未经允许,请勿转载。