Javax. In JDK 7u79 smartcardio. Card. Disconnect (Boolean reset) behavior?

According to the release notes of JRE 7u72:

When calling javax smartcardio. Card. When disconnect (true), even if I have JDK 7u79, the card will not be reset When I pass false or use the option - dsun security. smartcardio. Invertcardreset = true. Everything is normal when it reaches VM How did this happen? Does the JDK 7u79 come with an older version of JRE?

Solution

In my opinion, JRE performed as expected

Java 7 JRE with version >; 7u72, you must call disconnect (false) to reset (by default, you may be overwritten by system properties) The reason is that the error that you must call disconnect (false) to actually disconnect is very old, so many software use and call disconnect (false) to reset If Oracle changes this behavior in some minor releases / bug fixes, they will create a security vulnerability for all software projects. They fix this JRE / JDK error in the code by calling disconnect (false) For this reason:

(this is part of what you reference from the document)

If you have some Java 8 jres, you must call disconnect (true) by default, which may be overridden by system properties

So if you want to create some code now to ensure that your card will be reset, which applies to Java 7 and 8 (or even older and newer versions), you must evaluate what you must submit, that is:

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;
}

Now, you can call card disconnect(TRUE); True should be false if required Please test carefully before use I didn't.

Please note that I got the version detection / splitting code from the so article getting java version at runtime

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>