Femto Java Developing Java applications for tiny footprint platforms Eduard de Jong QC Technology B.V. BOF 2187 http://java.net/projects/femto-java This BoF session • Learn about a different way to develop Java code for tiny platforms e.g. smart cards – With unit testing of on-platform code – In multiple packages in the same project • See it used for Java Cardtm platform code Tiny Java platform: • A Java programmable platform with a restricted and/or modified run time • Deployment of Java code by optional pre-load processing of class files 29-09-14 Femto Java—BOF 2187 2 Eduard de Jong • Invented & patented core technology used in Java Card – 1994 • Designed Java Card 2.0 – 1996 • With the Java Card team at Sun Mircosystems Inc. – Architect for DMDC deployment of smart cards (CAC) – Till 2006 • Active in ISO smart card standardization – Since 1994 • Designed electronic cash system for smart cards and mobile phones – Implemented in UK with Java for Android and the Java Card Platform – Deployments soon 29-09-14 Femto Java—BOF 2187 3 The Plan for this session • • • • Background Femto Java basics Femto Java Card Conclusion 29-09-14 Femto Java—BOF 2187 4 Progress • Background – Java Card vision – Java Card practices – Small Java • Femto Java basics • Femto Java Card • Conclusion 29-09-14 Femto Java—BOF 2187 5 Java Card vision • Run java applications in a very restricted device – Initial constraints: • • • • 8 bit CPU <64K Program <16K Non-volatile memory <1K RAM • Specify a framework for smart card application generic operations – IO – Crypto – Memory transactions • Develop code for both sides at the same time – Communication code generated from same source • Card Applet • Card terminal application • Bypass explicit use of APDUs 29-09-14 Femto Java—BOF 2187 6 JC Development practice • IDE project for Java Card platform one package at a time – All tools aimed at single-package development • Design choice in Java Card to equate Java Card’s “fire wall” with a Java package • No support for unit testing – No test driven development – Marginal support for refactoring • No compile on save 29-09-14 Femto Java—BOF 2187 7 History of small Java efforts – Java Card (1996) • JC 2.0 (1997) – Femto Java I (1997) – Pico Java (1999) – Spotless (1999) • • – – – – KVM Java ME Femto Java II (2000) Squawk (2003) Embedded Java (2011) Femto Java III (2014) 29-09-14 Femto Java—BOF 2187 8 Progress of this session Background • Femto Java basics – Femto Java platform – Femto Java Code development process – Net Beans integration • Femto Java Card • Conclusion 29-09-14 Femto Java—BOF 2187 9 Femto Java Femto Java: Principles & tools for developing Java code, programs and libraries, on restricted computing platforms: – – – – Not the full Java runtime environment Modified runtime functions Java API with framework dedicated to platform purpose Written in Java • • Executed using a Java-like interpreter Executable code created with post-compilation 29-09-14 Femto Java—BOF 2187 10 Femto Java Development Code, Compile & test • Target code, unit test code, functional test code, support code • Java SE runtime • Processes annotations • Restricted Platform runtime as library • (Unit) tests • Functional tests • Restricted Platform runtime • +java.lang.annotation Compile • Reveals Restricted Platform Java subset errors • Includes generated code Test on target platform 29-09-14 • Post compile (convert) • Load • Function tests • Reuse test and support code Femto Java—BOF 2187 11 Femto in NetBeans • NB Code development project for Java SE project • Code for restricted platform is in one or more earmarked packages • Creates a sub project type within the NB project Femto core modules • Mark packages for sub project type processing • Perform Restricted Platform runtime compilation Restricted Platform I Restricted Platform II 29-09-14 • e.g. Java card • e.g. Embedded Java for smart card terminal Femto Java—BOF 2187 12 Progress of this session Background Femto Java basics • Femto Java Card – Java Card tools – Java Card emulator • Runtime reference • Unit test support – Demo • Conclusion 29-09-14 Femto Java—BOF 2187 13 Femto Java Card tools • Tools need to support multiple packages • Rethink CAP file • Java Card Converter – Wrapper around current tool – Calling order constraints enforced. • CAP tools – Load APDU scripts generated in proper package calling order • Dependency importer – Recognizes multi-package CAP files • On-card platform enhancements – AbstractApplet • Overridable initialization code • TestApplet – On-card debugging support 29-09-14 Femto Java—BOF 2187 14 Femto Java Card emulator • Java Card platform API reference library • Java Card platform implementation – In Java • Implements almost all Java Card features – For (unit) testing • Platform runtime environment instantiated per test • External access to runtime static data 29-09-14 Femto Java—BOF 2187 15 Unit testing The Java card runtime is instantiated at the start of each test. class ShowFemtoUnitTest { @Before void initJavaCardRuntime() { //Create the runtime for the current test (Thread) JavaCardTestContext.getInstance(); } @Test void aMethodTest(){ //e.g. call a runtime static method byte[] bArr = JCSystem.makeTransientByteArray(10, 1); //Dispatched to the current runtime instance //test code … } } 29-09-14 Femto Java—BOF 2187 16 APDU Unit testing Explicit reference to Java card runtime to access APDU buffer class ShowFemtoUnitTest { JavaCardTestContext context; @Before void initJavaCardRuntime() { //Keep reference to runtime context context = JavaCardTestContext.getInstance(); } @Test void aMethodTest(){ //Set the current APDU. APDU apdu = context.makeApdu(10, 0x80, 4, 0, 0, …); //test code … assertEquals(apdu, APDU.getCurrentAPDU()); } } 29-09-14 Femto Java—BOF 2187 17 APDU level testing The emulated Java Card runtime supports – – – – Loading Java Card Applet instance Specifying AID for the applet under test. Specifying Shareable interface implementations Initiating a session with an Applet • With answer to SELECT command – Manufacturing APDUs for Applet session 29-09-14 Femto Java—BOF 2187 18 Demo Time • Opening a Java SE Project – Project prepared with Femto plugin modules – Marking packages for Java Card processing • Run unit tests for Java Card library – Existing Java Card development with deployed code 29-09-14 Femto Java—BOF 2187 19 Progress of this session Background Femto Java basics Femto Java Card • Conclusion 29-09-14 Femto Java—BOF 2187 20 Conclusion With the “Femto” principle development of code for the Java Card platform can benefit from all the powerful present day development tools in an IDE such as unit testing and refactoring. Principle applicable to a range of constrained Java platforms 29-09-14 Femto Java—BOF 2187 21 Questions? 29-09-14 Femto Java—BOF 2187 22 Thank you for your attention Eduard de Jong eduard@dejongfrz.nl http://java.net/projects/femto-java 29-09-14 Femto Java—BOF 2187 23