Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing method on java.security.KeyPairGenerator? #533

Closed
jazdw opened this issue Jul 9, 2018 · 3 comments · Fixed by O330oei/graal#1
Closed

Missing method on java.security.KeyPairGenerator? #533

jazdw opened this issue Jul 9, 2018 · 3 comments · Fixed by O330oei/graal#1
Assignees

Comments

@jazdw
Copy link

jazdw commented Jul 9, 2018

Running a native image with graalvm-ce-1.0.0-rc3

Caused by: java.lang.NoSuchMethodException: java.security.KeyPairGenerator.getInstance(java.lang.String, java.lang.String)
        at java.lang.Throwable.<init>(Throwable.java:265)
        at java.lang.Exception.<init>(Exception.java:66)
        at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:56)
        at java.lang.NoSuchMethodException.<init>(NoSuchMethodException.java:51)
        at java.lang.Class.getDeclaredMethod(Class.java:2130)
        at org.apache.sshd.common.util.security.SecurityEntityFactory.toNamedProviderFactory(SecurityEntityFactory.java:117)
        at org.apache.sshd.common.util.security.SecurityEntityFactory.toFactory(SecurityEntityFactory.java:69)
        at org.apache.sshd.common.util.security.SecurityUtils.createSecurityEntityFactory(SecurityUtils.java:699)
        ... 32 more
@cstancu
Copy link
Member

cstancu commented Jul 9, 2018

Can you please provide more context? Is this an error that you see when trying to build a native image or did you successfully built the image and you see this at runtime? If it is the later you probably need to configure java.security.KeyPairGenerator.getInstance for reflective access. See REFLECTION.md.

@cstancu cstancu assigned cstancu and unassigned olpaw Jul 9, 2018
@jazdw
Copy link
Author

jazdw commented Jul 10, 2018

It was occurring after I built the native image and was trying to run it. I got it working by adding a reflection config file.

Now I am getting another exception running the native image due to the bouncy castle classes not being available -

Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.lang.Throwable.<init>(Throwable.java:310)
        at java.lang.Exception.<init>(Exception.java:102)
        at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:89)
        at java.lang.reflect.InvocationTargetException.<init>(InvocationTargetException.java:72)
        at com.oracle.svm.reflect.proxies.Proxy_98_TunnelServer_main.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:173)
Caused by: java.security.NoSuchAlgorithmException: class configured for KeyFactory (provider: BC) cannot be found.
        at java.lang.Throwable.<init>(Throwable.java:287)
        at java.lang.Exception.<init>(Exception.java:84)
        at java.security.GeneralSecurityException.<init>(GeneralSecurityException.java:71)
        at java.security.NoSuchAlgorithmException.<init>(NoSuchAlgorithmException.java:72)
        at java.security.Provider$Service.getImplClass(Provider.java:1649)
        at java.security.Provider$Service.newInstance(Provider.java:1592)
        at sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
        at sun.security.jca.GetInstance.getInstance(GetInstance.java:206)
        at java.security.KeyFactory.getInstance(KeyFactory.java:211)
        at com.oracle.svm.reflect.proxies.Proxy_118_KeyFactory_getInstance.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.apache.sshd.common.util.security.SecurityEntityFactory$2.getInstance(SecurityEntityFactory.java:131)
        at org.apache.sshd.common.util.security.SecurityUtils.getKeyFactory(SecurityUtils.java:715)
        at org.apache.sshd.common.config.keys.loader.pem.RSAPEMResourceKeyPairParser.extractKeyPairs(RSAPEMResourceKeyPairParser.java:74)
        at org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs(AbstractKeyPairResourceParser.java:163)
        at org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs(AbstractKeyPairResourceParser.java:140)
        at org.apache.sshd.common.config.keys.loader.pem.AbstractPEMResourceKeyPairParser.extractKeyPairs(AbstractPEMResourceKeyPairParser.java:147)
        at org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.loadKeyPairs(AbstractKeyPairResourceParser.java:106)
        at org.apache.sshd.common.config.keys.loader.KeyPairResourceParser$2.loadKeyPairs(KeyPairResourceParser.java:160)
        at org.apache.sshd.common.config.keys.loader.pem.PEMResourceParserUtils$1.loadKeyPairs(PEMResourceParserUtils.java:50)
        at org.apache.sshd.common.config.keys.loader.KeyPairResourceParser$2.loadKeyPairs(KeyPairResourceParser.java:160)
        at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:109)
        at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:103)
        at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:96)
        at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:89)
        at org.apache.sshd.common.util.security.SecurityUtils.loadKeyPairIdentity(SecurityUtils.java:488)
        ... 3 more
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyFactorySpi
        at java.lang.Throwable.<init>(Throwable.java:287)
        at java.lang.Exception.<init>(Exception.java:84)
        at java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:75)
        at java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:82)
        at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:51)
        at com.oracle.svm.core.hub.DynamicHub.forName(DynamicHub.java:906)
        at java.security.Provider$Service.getImplClass(Provider.java:1634)
        ... 27 more

Is there anyway to include all classes and methods from a package using the reflection config?

@cstancu
Copy link
Member

cstancu commented Sep 18, 2018

The original error should be fixed in 76d0435 which adds support for HTTPS and JCA security services. These features will be available in the rc7 realease. See JCA-SECURITY-SERVICES.md for details. You need to run native-image with --enable-all-security-services.

Regarding including all classes and methods from a package using reflection config, that is not possible. It is better to register only those classes/methods/fields that actually need reflection, otherwise you risk adding too much unused code to the image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants