lzaoral / JCProfilerNext

Profiler for JavaCard code and a rewrite of OpenCryptoProject/JCProfiler with easier usage and much more!
GNU General Public License v3.0
8 stars 3 forks source link

java.lang.NoClassDefFoundError: pro/javacard/AID when uploading applet to a real card #87

Closed petrs closed 3 weeks ago

petrs commented 1 month ago

An exception Exception in thread "main" java.lang.NoClassDefFoundError: pro/javacard/AID at pro.javacard.gp.GPSession.discover(GPSession.java:166) is thrown when using jcprofilernext with real card. Same command with --simulator is finishing correctly.

The problem might be caused by move of pro/javacard/AID to pro/javacard/captools/AID in GPTools at some point in time with inconsistency introduced.

Two different cards and readers tested (with same issue persisting)

>java -jar build/libs/JCProfilerNext-1.0-SNAPSHOT.jar   --work-dir example3 --jckit jc304_kit --mode time --cla 0xb0 --ins 0x61 --data-regex 00[0-9A-F]{2} --repeat-count 100 --executable ASCONEncryption
06:41:04.203 [main] INFO  jcprofiler.Main - Welcome to JCProfilerNext!
06:41:04.207 [main] INFO  jcprofiler.Main - Command-line arguments parsed successfully.
06:41:04.221 [main] INFO  jcprofiler.Main - Found JavaCard SDK 3.0.4 (\JCProfilerNext-main\jc304_kit)
06:41:04.221 [main] INFO  jcprofiler.Main - Working directory: \JCProfilerNext-main\example3
06:41:04.222 [main] INFO  jcprofiler.Main - Executed in time mode.
06:41:04.222 [main] INFO  jcprofiler.Main - Start from: instrumentation
06:41:04.222 [main] INFO  jcprofiler.Main - Stop after: visualisation
06:41:04.223 [main] INFO  jcprofiler.JCProfiler - Instrumentation started.
06:41:04.347 [main] INFO  jcprofiler.instrumentation.Instrumenter - Generating additional classes.
06:41:05.239 [main] INFO  jcprofiler.instrumentation.Instrumenter - Validating '--entry-point' and '--executable' arguments.
06:41:05.284 [main] INFO  jcprofiler.instrumentation.Instrumenter - Instrumenting existing classes.
06:41:05.358 [main] INFO  jcprofiler.instrumentation.processors.AbstractInsertTrapProcessor - Instrumenting ascon.AsconApplet#ASCONEncryption(javacard.framework.APDU).
06:41:05.372 [main] INFO  jcprofiler.instrumentation.processors.AbstractModifyEntryPointProcessor - Instrumenting entry point class ascon.AsconApplet.
06:41:05.403 [main] INFO  jcprofiler.instrumentation.Instrumenter - Saving instrumented classes.
06:41:05.479 [main] INFO  jcprofiler.JCProfiler - Instrumentation complete.
06:41:05.480 [main] INFO  jcprofiler.util.JCProfilerUtil - Validating Spoon model.
06:41:05.568 [main] INFO  jcprofiler.JCProfiler - Compilation started.

javacard:
     [echo] Java version: 1.8.0_411
 [JavaCard] INFO: using JavaCard 3.0.4 SDK in \JCProfilerNext-main\jc304_kit with JDK 8
 [JavaCard] INFO: generated applet AID: 12345678900101 for ascon.AsconApplet
 [JavaCard] Building CAP with 1 applet from package ascon (AID: 123456789001)
 [JavaCard] ascon.AsconApplet 12345678900101
  [compile] Compiling files from \JCProfilerNext-main\example3\sources_instr
  [compile] Warning: ascon\AsconApplet.java modified in the future.
  [compile] Warning: ascon\AsconCore.java modified in the future.
  [compile] Warning: ascon\PM.java modified in the future.
  [compile] Warning: ascon\PMC.java modified in the future.
  [compile] Compiling 4 source files to \JCProfilerNext-main\example3\applet\classes
  [compile] \JCProfilerNext-main\example3\sources_instr\ascon\AsconApplet.java
  [compile] \JCProfilerNext-main\example3\sources_instr\ascon\AsconCore.java
  [compile] \JCProfilerNext-main\example3\sources_instr\ascon\PM.java
  [compile] \JCProfilerNext-main\example3\sources_instr\ascon\PMC.java
  [convert] [ INFO: ] Converter [v3.0.4]
  [convert] [ INFO: ]     Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
  [convert]
  [convert]
  [convert] [ INFO: ] conversion completed with 0 errors and 0 warnings.
   [verify] Verification passed
      [cap] CAP saved to \JCProfilerNext-main\example3\applet\AsconApplet.cap
      [exp] EXP saved to \JCProfilerNext-main\example3\applet\ascon\javacard\ascon.exp
      [jca] JCA saved to \JCProfilerNext-main\example3\applet\ascon.jca
      [jar] Building jar: \JCProfilerNext-main\example3\applet\ascon.jar
      [jar] JAR saved to \JCProfilerNext-main\example3\applet\ascon.jar
06:41:06.971 [main] INFO  jcprofiler.JCProfiler - Compilation complete.
06:41:06.971 [main] INFO  jcprofiler.JCProfiler - Installation started.
06:41:06.974 [main] INFO  jcprofiler.installation.Installer - Connecting to a physical card reader.
06:41:07.088 [main] INFO  jcprofiler.installation.Installer - Looking for terminal with a card.
06:41:07.093 [main] INFO  jcprofiler.installation.Installer - Connecting to a card in terminal OMNIKEY AG Smart Card Reader USB 0.
06:41:07.095 [main] INFO  jcprofiler.installation.Installer - Successfully connected.
06:41:07.095 [main] INFO  jcprofiler.installation.Installer - Card ATR: 3BF81300008131FE454A434F5076323431B7
06:41:07.155 [main] INFO  jcprofiler.installation.Installer - Executing GlobalPlatformPro to install \JCProfilerNext-main\example3\applet\AsconApplet.cap.
# GlobalPlatformPro 325fe84
# Running on Windows 11 10.0 amd64, Java 1.8.0_411 by Oracle Corporation
Exception in thread "main" java.lang.NoClassDefFoundError: pro/javacard/AID
        at pro.javacard.gp.GPSession.discover(GPSession.java:166)
        at pro.javacard.gp.GPTool.run(GPTool.java:208)
        at jcprofiler.installation.Installer.installOnCard(Installer.java:96)
        at jcprofiler.JCProfiler.run(JCProfiler.java:83)
        at jcprofiler.Main.main(Main.java:79)
Caused by: java.lang.ClassNotFoundException: pro.javacard.AID
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 5 more

Thank you very much for looking at this issue

lzaoral commented 1 month ago

I'm afraid I can't test this myself since I do not have a reader nor a smartcard any more. 😞

Somehow, the pro.javacard.AID package used by JCProfilerNext was not compatible with GPPro that JCProfilerNext used. However, that should not happen because I did not change versions of these dependencies since they were introduced in the codebase. 🤔 The main reason is that newer versions no longer support Java 8.

Some ideas:

edit: add more context

petrs commented 1 month ago

Thank you for looking at that. I did not edited build.gradle (tried later but with no success and still same issue). The version of gppro reported in error log is # GlobalPlatformPro 325fe84 which is 20.08.12 as set in build.gradle

We shall get you reader and card so you can still test it.

lzaoral commented 1 month ago

I have probably found the cause. Could you try the profiling with 4aef4cf reverted, please?

petrs commented 1 month ago

yes, this works and fixed the problem! Thank you for finding the issue