加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

JDK 7u79中javax.smartcardio.Card.disconnect(boolean reset)的

发布时间:2020-12-15 02:17:23 所属栏目:Java 来源:网络整理
导读:根据 release notes of JRE 7u72: Change in javax.smartcardio.Card.disconnect(boolean reset) method behavior Prior to the JDK 8u20 and JDK 7u72 releases,the javax.smartcardio.Card.disconnect(boolean reset) method had inverted logic for the
根据 release notes of JRE 7u72:

Change in javax.smartcardio.Card.disconnect(boolean reset) method
behavior

Prior to the JDK 8u20 and JDK 7u72 releases,the
javax.smartcardio.Card.disconnect(boolean reset) method had inverted
logic for the ‘reset’ boolean value passed to it. The card was reset
upon a disconnect if false was passed to it and vice versa. Starting
with JDK 7u72 and JDK 8u20,the correct behavior as per API
documentation has been implemented.

In order to provide backwards compatibility to users who rely on the
old behavior,a new system property has been introduced. The following
command-line option can be used to enforce the old broken behavior:

-Dsun.security.smartcardio.invertCardReset=true

This property is set by default for 7u72 and later JDK 7 update
releases. By default,no behavioral change will be noticed in this
area for JDK 7 update releases.

Also the following command-line option can be used to enforce the new
correct behavior:

-Dsun.security.smartcardio.invertCardReset=false

This is default for 8u20 and later JDK 8 update releases. In future
Java releases,the property will be ignored/disabled and default
disconnect method behavior will be as specified by API.

当调用javax.smartcardio.Card.disconnect(true)时,即使我有JDK 7u79,卡也不会重置.当我传递false或使用选项-Dsun.security.smartcardio.invertCardReset = true到VM时,一切正常.怎么会这样? JDK 7u79附带了旧版本的JRE吗?

解决方法

在我看来,JRE表现得像预期的那样.

拥有版本>的Java 7 JRE; 7u72,你必须调用disconnect(false)来重置(默认情况下.你可能会被系统属性覆盖).原因在于,您必须调用断开连接(false)以实际断开连接的错误已经很老了,所以很多软件都采用并调用disconnect(false)来重置.如果Oracle在一些次要的发布/错误修复中改变了这种行为,他们就会为所有软件项目创建一个安全漏洞,他们通过调用disconnect(false)修复了代码中的这个JRE / JDK错误.为此原因:

By default,no behavioral change will be noticed in this area for JDK 7 update releases.

(这是您从文档中引用的内容的一部分)

如果你有一些Java 8 JRE,你必须默认调用disconnect(true),可能被系统属性覆盖.

所以,如果你现在想要创建一些代码,确保你的卡将被重置,这适用于java 7和8(甚至更老和更新版本),你必须评估,你必须提交什么,即:

final static boolean TRUE;
static{
    String ven = System.getProperty("java.vendor");
    String ver = System.getProperty("java.runtime.version");
    String r = System.getProperty("sun.security.smartcardio.invertCardReset");
    TRUE=!invertReset(ven,ver,r);
}

static boolean invertReset(String vendor,String version,String reset){
    if("Oracle Corporation".equals(vendor)){
        String[] javaVersionElements = version.split(".|_|-b");

        //String discard = javaVersionElements[0];
        int major   = Integer.parseInt(javaVersionElements[1]);
        //String minor   = javaVersionElements[2];
        int update  = Integer.parseInt(javaVersionElements[3]);
        //String build   = javaVersionElements[4];

        // version to small for existing reset property:
        if((major == 7 && update<72) || major < 7){
            return true;
        }

        if(null != reset){
            // version recent enough and we have property:
            return "true".equals(reset);
        }else{
            // version recent enough,but no property:
            return major<8;
        }
    }
    return false;
}

现在,你可以拨打card.disconnect(TRUE);如果需要,则TRUE应为false.使用前请仔细测试.我没有.

请注意,我从SO文章Getting Java version at runtime中获取了版本检测/拆分代码

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读