Pep*_*rez 19 java pkcs#11 java-9 sunpkcs11
在Java 8之前,SunPKCS11提供程序的加载方式如下:
Provider provider = new sun.security.pkcs11.SunPKCS11 (new ByteArrayInputStream (configFile.getBytes ()));
Security.addProvider (provider);
Run Code Online (Sandbox Code Playgroud)
configFile是带有配置参数的String.因此,如果应用程序需要使用多个连接的智能卡,它可以创建多个提供程序.要访问每个提供程序,使用的名称是"SunPKCS11-",后跟我们在配置中指示的名称.
在Java 8中,sun.security.pkcs11.SunPKCS11该类已在JDK中删除.所以,我不得不通过反思来编程前一个调用.
Java 9中PKCS#11提供程序的操作似乎非常不同:
该SunPKCS11构造已更改为空单.配置由"configure"方法加载,因此必须将它放在磁盘上的文件中,我不能再通过流将其加载到字符串.
如果我们尝试使用反射,则会出现以下警告:
Run Code Online (Sandbox Code Playgroud)WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by PruebaTarjeta (file:/C:/temp/pkcs11java9/classes/) to constructor sun.security.pkcs11.SunPKCS11() WARNING: Please consider reporting this to the maintainers of PruebaTarjeta WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release
这也发生在其他人身上吗?有解决方案吗
Jor*_*nee 15
我注意到看了javadoc configure:
将提供的配置参数应用于此提供程序实例并返回已配置的提供程序.请注意,如果无法就地配置此提供程序,则将创建并返回新的提供程序.因此,调用者应始终使用返回的提供者.
这向我表明原型模式在这里使用,并且用于创建多个提供者的新控制流程将类似于:
Provider prototype = Security.getProvider("SunPKCS11");
Provider provider1 = prototype.configure(...);
Provider provider2 = prototype.configure(...);
...
Run Code Online (Sandbox Code Playgroud)
至于直接使用参数而不是文件名,我做了一些挖掘源代码并发现sun.security.pkcs11.Config:
Config(String fn) throws IOException {
this.filename = fn;
if (filename.startsWith("--")) {
// inline config
String config = filename.substring(2).replace("\\n", "\n");
reader = new StringReader(config);
Run Code Online (Sandbox Code Playgroud)
注意这一行filename.startsWith("--"),这个文件名直接来自参数configure.所以,你应该能够在配置参数作为字符串来传递,只要你开始的字符串--,然后你的划定key=value与对\n.(我目前无法测试这个).
但是,我无法在任何地方公开记录这一事实,因此它可能会发生变化,以及它对不同的提供商有不同的工作方式,即使用风险自负!.