我有一个 Clojure 程序,我正在尝试使用 GraalVM 将其编译为本机映像。该程序只是一个主要功能:
(defn -main [& args]
(println (Signature/getInstance "EDDSA" (Security/getProvider "BC"))))
我将其编译为本机映像,当我运行它时,我得到了这个:
Exception in thread "main" java.lang.IllegalArgumentException: missing provider
at [email protected]/sun.security.jca.GetInstance.getService(GetInstance.java:96)
at [email protected]/sun.security.jca.GetInstance.getInstance(GetInstance.java:218)
at [email protected]/java.security.Signature.getInstance(Signature.java:450)
at company.cli.release$_main.invokeStatic(release.clj:8)
at company.cli.release$_main.doInvoke(release.clj:7)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at company.cli.release.main(Unknown Source)
如果使用
-H:+TraceSecurityService
开关编译它,充气城堡不会出现在任何地方。我不明白为什么它没有被采纳。在报告中我可以看到:
Service factory method java.security.Signature.getInstance(java.lang.String, java.security.Provider) is reachable.
Analysis parsing context:
at java.security.Signature.getInstance(Signature.java:441)
at company.cli.release$_main.invokeStatic(release.clj:8)
at company.cli.release$_main.doInvoke(release.clj:7)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at company.cli.release.main(Unknown Source)
at com.oracle.svm.core.JavaMainWrapper.runCore0(JavaMainWrapper.java:180)
at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:137)
Reachability of Signature service type API triggers registration of following services:
所以可达性检测到了这段代码。但注册的签名服务不包含任何 BouncyCastle 算法。
如果我将代码更改为:
(defn -main [& args]
(println (Signature/getInstance "EDDSA" (BouncyCastleProvider.))))
运行时报告是相同的,我得到了具有相同堆栈跟踪的不同异常:
Exception in thread "main" java.security.NoSuchAlgorithmException: no such algorithm: EDDSA for provider BC
如果通过
java
命令正常运行,此代码就可以工作。
我也尝试过:
(defn -main [& args]
(Security/addProvider (BouncyCastleProvider.))
(println (Signature/getInstance "EDDSA" (BouncyCastleProvider.))))
和
(defn -main [& args]
(Security/addProvider (BouncyCastleProvider.))
(println (Signature/getInstance "EDDSA" (Security/getProvider "BC"))))
结果相同。我尝试添加选项
-H:AdditionalSecurityProviders=org.bouncycastle.jce.provider.BouncyCastleProvider
。
我收到上述两个错误之一,并且安全服务自动注册报告仍然没有提及 BouncyCastle
为什么不将 BC 添加到提供商中?