How to build native-image via client-maven-plugin that uses BouncyCastle

0

I'm working on a java Gluon project built using the maven client plugin targeting desktop, iOS, and Android. I'm now trying to add a dependency on an internal java library that uses BouncyCastle for crypto.

Executing the code via mvn clean javafx:run results in a functional app that does all the crypto just fine.

Running mvn clean client:build -Pios client:run -Pios runs the app on iOS but throws java.security.NoSuchAlgorithmException: no such algorithm: AES for provider BC several times when our library tries to generate ciphers.

Things I've tried:

  • Add <nativeImageArgs>--enable-all-security-services</nativeImageArgs> to client-maven-plugin configuration.
  • Add various BouncyCastle classes to the <reflectionList> in the plugin configs

System Info:

  • MacOS 10.15.5
  • IntelliJ IDEA Ultimate 2020.2.2
  • java -version:
    openjdk version "11.0.8" 2020-07-14
    OpenJDK Runtime Environment GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03)
    OpenJDK 64-Bit Server VM GraalVM CE 20.2.0 (build 11.0.8+10-jvmci-20.2-b03, mixed mode, sharing)

Edit(09/29/20):

Adding AES to the reflection list seems to have gotten me one step further but I am still hitting a security error:

[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Fatal error: javax.crypto.JceSecurity.getCodeBase(Class) is reached at runtime. This should not happen. The contents of JceSecurity.verificationResults are computed and cached at image build time. Try enabling all security services with --enable-all-security-services.
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] JavaFrameAnchor dump:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   No anchors
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] TopFrame info:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   TotalFrameSize in CodeInfoTable 32
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] VMThreads info:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   VMThread 0000000283fa1ba0  STATUS_IN_NATIVE  java.lang.Thread@0x116001028
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   VMThread 0000000283fa0f70  STATUS_IN_NATIVE  java.lang.Thread@0x115b043d0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   VMThread 0000000283fa0ea0  STATUS_IN_JAVA (safepoints disabled)  java.lang.Thread@0x115a02e10
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   VMThread 0000000283fa0dd0  STATUS_IN_NATIVE  java.lang.Thread@0x107ce30a0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] VM Thread State for current thread 0000000283fa0ea0:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   0 (8 bytes): com.oracle.svm.jni.JNIThreadLocalEnvironment.jniFunctions = (bytes) 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     0000000283fa0ea0: 00000001070a6c88
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   8 (32 bytes): com.oracle.svm.core.genscavenge.ThreadLocalAllocation.regularTLAB = (bytes) 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     0000000283fa0ea8: 0000000116600000 0000000116700000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     0000000283fa0eb8: 000000011660b960 0000000000000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   40 (8 bytes): com.oracle.svm.core.heap.NoAllocationVerifier.openVerifiers = (Object) null
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   48 (8 bytes): com.oracle.svm.core.jdk.IdentityHashCodeSupport.hashCodeGeneratorTL = (Object) java.util.SplittableRandom  0000000115b04600
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   56 (8 bytes): com.oracle.svm.core.snippets.ExceptionUnwind.currentException = (Object) null
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   64 (8 bytes): com.oracle.svm.core.thread.JavaThreads.currentThread = (Object) java.lang.Thread  0000000115a02e10
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   72 (8 bytes): com.oracle.svm.core.thread.ThreadingSupportImpl.activeTimer = (Object) null
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   80 (8 bytes): com.oracle.svm.jni.JNIObjectHandles.handles = (Object) com.oracle.svm.core.handles.ThreadLocalHandles  0000000115b02360
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   88 (8 bytes): com.oracle.svm.jni.JNIThreadLocalPendingException.pendingException = (Object) null
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   96 (8 bytes): com.oracle.svm.jni.JNIThreadLocalPinnedObjects.pinnedObjectsListHead = (Object) null
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   104 (8 bytes): com.oracle.svm.jni.JNIThreadOwnedMonitors.ownedMonitors = (Object) null
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   112 (8 bytes): com.oracle.svm.core.genscavenge.ThreadLocalAllocation.freeList = (Word) 0  0000000000000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   120 (8 bytes): com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.stackBoundaryTL = (Word) 1  0000000000000001
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   128 (8 bytes): com.oracle.svm.core.stack.JavaFrameAnchors.lastAnchor = (Word) 0  0000000000000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   136 (8 bytes): com.oracle.svm.core.thread.VMThreads.IsolateTL = (Word) 94598687557484880  0150150150150150
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   144 (8 bytes): com.oracle.svm.core.thread.VMThreads.OSThreadHandleTL = (Word) 6105214976  000000016be63000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   152 (8 bytes): com.oracle.svm.core.thread.VMThreads.OSThreadIdTL = (Word) 6105214976  000000016be63000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   160 (8 bytes): com.oracle.svm.core.thread.VMThreads.nextTL = (Word) 10804137424  0000000283fa0dd0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   168 (4 bytes): com.oracle.svm.core.graal.snippets.StackOverflowCheckImpl.yellowZoneStateTL = (int) -16843010  fefefefe
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   172 (4 bytes): com.oracle.svm.core.snippets.ImplicitExceptions.implicitExceptionsAreFatal = (int) 0  00000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   176 (4 bytes): com.oracle.svm.core.thread.Safepoint.safepointRequested = (int) 2147255657  7ffc8569
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   180 (4 bytes): com.oracle.svm.core.thread.ThreadingSupportImpl.currentPauseDepth = (int) 0  00000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   184 (4 bytes): com.oracle.svm.core.thread.VMThreads$ActionOnTransitionToJavaSupport.actionTL = (int) 0  00000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   188 (4 bytes): com.oracle.svm.core.thread.VMThreads$StatusSupport.safepointsDisabledTL = (int) 1  00000001
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   192 (4 bytes): com.oracle.svm.core.thread.VMThreads$StatusSupport.statusTL = (int) 1  00000001
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] VMOperation dump:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   No VMOperation in progress
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Dump Counters:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Raw Stacktrace:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62ba0: 000000011660b940 0000000000000000
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62bb0: 000000016be62be0 00000001045c4a48
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62bc0: 0000000283fa0f60 000000011660b4e0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62bd0: 000000011660b4e0 000000011660b940
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62be0: 000000016be62c40 000000010569556c
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62bf0: 000000016be62c40 0000000107351138
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62c00: 0000000107d0be88 0000000107d0be48
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   000000016be62c10: 0000000107351040 0000000115b11578
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Stacktrace Stage 0:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62ba0 IP 00000001045ec738  FrameSize 32
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bc0 IP 00000001045c4a48  FrameSize 48
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bf0 IP 000000010569556c  FrameSize 96
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62c50 IP 0000000105695144  FrameSize 64
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62c90 IP 00000001056990f8  FrameSize 48
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62cc0 IP 000000010452012c  FrameSize 176
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62d70 IP 000000010451fbd8  FrameSize 48
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 0000000  SP 000000016be62f20 IP 0000000104fa6b2c  FrameSize 32
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f40 IP 00000001045e4a10  FrameSize 80
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f90 IP 00000001045a9c9c  FrameSize 64
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Stacktrace Stage 1:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62ba0 IP 00000001045ec738  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bc0 IP 00000001045c4a48  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bf0 IP 000000010569556c  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62c50 IP 0000000105695144  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62c90 IP 00000001056990f8  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62cc0 IP 000000010452012c  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62d70 IP 000000010451fbd8  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62da0 IP 0000000104826860  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62e80 IP 00000001048230b4  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62ee0 IP 0000000104822718  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f20 IP 0000000104fa6b2c  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f40 IP 00000001045e4a10  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f90 IP 00000001045a9c9c  com.oracle.svm.core.code.CodeInfo@0x107cbf7f8 name = image code
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Stacktrace Stage 2:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62ba0 IP 00000001045ec738  [image code] com.oracle.svm.core.jdk.VMErrorSubstitutions.shutdown(VMErrorSubstitutions.java:96)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62ba0 IP 00000001045ec738  [image code] com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:75)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bc0 IP 00000001045c4a48  [image code] com.oracle.svm.core.util.VMError.shouldNotReachHere(VMError.java:59)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bc0 IP 00000001045c4a48  [image code] com.oracle.svm.core.jdk.JceSecurityUtil.shouldNotReach(SecuritySubstitutions.java:387)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bf0 IP 000000010569556c  [image code] javax.crypto.JceSecurity.getCodeBase(JceSecurity.java:351)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62bf0 IP 000000010569556c  [image code] javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:216)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62c50 IP 0000000105695144  [image code] javax.crypto.JceSecurity.getInstance(JceSecurity.java:141)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62c90 IP 00000001056990f8  [image code] javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:326)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62cc0 IP 000000010452012c  [image code] com.gluonapplication.GluonApplication.securityTest(GluonApplication.java:85)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62d70 IP 000000010451fbd8  [image code] com.gluonapplication.GluonApplication.init(GluonApplication.java:45)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62da0 IP 0000000104826860  [image code] com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:824)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62e80 IP 00000001048230b4  [image code] com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62ee0 IP 0000000104822718  [image code] com.sun.javafx.application.LauncherImpl$$Lambda$6b52b8b751707d234c1e536df5c7bfccab052d36.run(Unknown Source)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f20 IP 0000000104fa6b2c  [image code] java.lang.Thread.run(Thread.java:834)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f40 IP 00000001045e4a10  [image code] com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:517)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f90 IP 00000001045a9c9c  [image code] com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:192)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   SP 000000016be62f90 IP 00000001045a9c9c  [image code] com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(IsolateEnterStub.java:0)
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] [Native image heap boundaries: 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   ReadOnly Primitives: 0x106054008 .. 0x1070a4940
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   ReadOnly References: 0x1070a4978 .. 0x1076e01a8
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   ReadOnly Relocatables: 0x0 .. 0x0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   Writable Primitives: 0x107730000 .. 0x107cd4ba0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   Writable References: 0x107cd4bb8 .. 0x10838c328
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   Writable Huge: 0x0 .. 0x0
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   ReadOnly Huge: 0x0 .. 0x0]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] [Heap:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   [Young generation: 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     [Eden: 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]       [edenSpace:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]         aligned: 0/0 unaligned: 0/0]]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     [Survivors: 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]       ]]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   [Old generation: 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     [oldFromSpace:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]       aligned: 0/0 unaligned: 0/0]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     [oldToSpace:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]       aligned: 0/0 unaligned: 0/0]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     ]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]   [Unused:
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB]     aligned: 0/0]]
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] 
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Fatal error: javax.crypto.JceSecurity.getCodeBase(Class) is reached at runtime. This should not happen. The contents of JceSecurity.verificationResults are computed and cached at image build time. Try enabling all security services with --enable-all-security-services.
[Tue Sep 29 11:01:06 EDT 2020][INFO] [SUB] Process 1187 exited with status = 99 (0x00000063) 
[Tue Sep 29 11:01:06 EDT 2020][INFO] result = true

This might be a known issue with GraalVM as discussed here

Below is the plugin configuration in my pom file:

            <plugin>
                <groupId>com.gluonhq</groupId>
                <artifactId>client-maven-plugin</artifactId>
                <version>${client.plugin.version}</version>
                <configuration>
                    <target>${client.target}</target>
                    <nativeImageArgs>-J-Djava.security.properties=java.security.overrides</nativeImageArgs>
                    <nativeImageArgs>--enable-all-security-services</nativeImageArgs>
                    <attachList>
                        <list>display</list>
                        <list>lifecycle</list>
                        <list>statusbar</list>
                        <list>storage</list>
                    </attachList>
                    <bundlesList>
                        <list>com.gluonapplication.views.primary</list>
                        <list>com.gluonapplication.views.secondary</list>
                    </bundlesList>
                    <reflectionList>
                        <list>com.gluonapplication.views.PrimaryPresenter</list>
                        <list>com.gluonapplication.views.SecondaryPresenter</list>
                        <list>org.bouncycastle.jcajce.provider.symmetric.AES$Mappings</list>
                    </reflectionList>
                    <mainClass>${mainClassName}</mainClass>
                </configuration>
            </plugin>

And the source code from the sample application I've built for sharing code here (based on the gluon plugin's autogenerated app setup):

public class GluonApplication extends MobileApplication {

    private Provider provider;
    private static final String CIPHER_ALGORITHM = "AES";
    private static final String KEYPAIR_GENERATOR_ALGORITHM = "RSA";
    private static final String KEY_GENERATOR_ALGORITHM = "AES";
    private static final String KEY_FACTORY_ALGORITHM = "RSA";
    private static final String KEY_STORE_TYPE = "PKCS12";
    private static final String SIGNATURE_ALGORITHM = "SHA256withRSA";
    private static final String HASH_ALGORITHM = "PBKDF2WithHmacSHA256";
    private static final String TEMPORAL_KEY_ALGORITHM = "RSA";
    private static final int AES_KEY_SIZE = 256;
    private static final int RSA_KEY_SIZE = 2048;
    private File KEY_STORE_FILE;
    private static final String KEY_STORE_NAME = "keyStore";
    private static final String KEY_STORE_DIRECTORY_NAME = "security";
    private final KeyGenerator[] keyGenerators = new KeyGenerator[TOTAL_CIPHER_UNITS];
    private final Cipher[] temporalKeyEncrypters = new Cipher[TOTAL_CIPHER_UNITS];
    private final Cipher[] temporalKeyDecrypters = new Cipher[TOTAL_CIPHER_UNITS];
    private final Cipher[] payloadEncrypters = new Cipher[TOTAL_CIPHER_UNITS];
    private final Cipher[] payloadDecrypters = new Cipher[TOTAL_CIPHER_UNITS];
    private final KeyFactory[] keyFactories = new KeyFactory[TOTAL_CIPHER_UNITS];
    private final Signature[] signers = new Signature[TOTAL_CIPHER_UNITS];
    private static final int TOTAL_CIPHER_UNITS = 14;

    @Override
    public void init() {
        securityTest();
        AppViewManager.registerViewsAndDrawer(this);
    }

    @Override
    public void postInit(Scene scene) {
        Swatch.BLUE.assignTo(scene);

        scene.getStylesheets().add(GluonApplication.class.getResource("style.css").toExternalForm());
        ((Stage) scene.getWindow()).getIcons().add(new Image(GluonApplication.class.getResourceAsStream("/icon.png")));
    }

    public static void main(String args[]) {
        launch(args);
    }

    private void securityTest() {
        Security.removeProvider("BC");
        // also remove not sufficient AndroidOpenSSL provider for X.509 - most likely only needed if BouncyCastleJsseProvider is used
        Security.removeProvider("AndroidOpenSSL");
        // touch the internal Providers class to trigger the static provider loading
        // see http://androidxref.com/9.0.0_r3/xref/libcore/ojluni/src/main/java/sun/security/jca/Providers.java#SYSTEM_BOUNCY_CASTLE_PROVIDER
        try {
            Class.forName("sun.security.jca.Providers");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(String.format("%s to patch not found.", "sun.security.jca.Providers"), e);
        }
        provider = new BouncyCastleProvider();

        Security.insertProviderAt(provider, 0);

        final File keyStoreDirectory = new File(System.getProperty("user.home"), KEY_STORE_DIRECTORY_NAME);
        // make sure that the path to the directory
        keyStoreDirectory.mkdirs();
        // create the key store file object
        KEY_STORE_FILE = new File(keyStoreDirectory, KEY_STORE_NAME);

        for (int i = 0; i < TOTAL_CIPHER_UNITS; i++) {
            try {
                // we init the key generator with the AES key size
                keyGenerators[i] = KeyGenerator.getInstance(KEY_GENERATOR_ALGORITHM, provider);
                keyGenerators[i].init(AES_KEY_SIZE);
                temporalKeyEncrypters[i] = Cipher.getInstance(TEMPORAL_KEY_ALGORITHM, provider);
                temporalKeyDecrypters[i] = Cipher.getInstance(TEMPORAL_KEY_ALGORITHM, provider);
                payloadEncrypters[i] = Cipher.getInstance(CIPHER_ALGORITHM, provider);
                payloadDecrypters[i] = Cipher.getInstance(CIPHER_ALGORITHM, provider);
                keyFactories[i] = KeyFactory.getInstance(KEY_FACTORY_ALGORITHM, provider);
                signers[i] = Signature.getInstance(SIGNATURE_ALGORITHM, provider);
            } catch (NoSuchPaddingException | NoSuchAlgorithmException ex) {
                ex.printStackTrace();
            }
        }
    }
}
bouncycastle
gluon
graalvm
graalvm-native-image
asked on Stack Overflow Sep 28, 2020 by freddig • edited Sep 29, 2020 by freddig

1 Answer

0

It would be better if you post your code and also the full stack trace.

You can take a look this issue and also this solution.

Normally from your stack trace, you can check the BC source code, and then you will be able to find out which class that you need to add in for the reflection.

I encounter many situation which the error message doesn't show something related to reflection but in fact, it is caused by reflection.

answered on Stack Overflow Sep 29, 2020 by Sam YC

User contributions licensed under CC BY-SA 3.0