Upload
mabel-martin
View
221
Download
1
Tags:
Embed Size (px)
Citation preview
Femto JavaDeveloping Java applications for tiny footprint platforms
Eduard de JongQC Technology B.V.
BOF 2187
http://java.net/projects/femto-java
Femto Java—BOF 2187 2
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
29-09-14
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
Femto Java—BOF 2187 3
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 4
The Plan for this session
• Background• Femto Java basics• Femto Java Card • Conclusion
29-09-14
Femto Java—BOF 2187 5
Progress
• Background– Java Card vision– Java Card practices– Small Java
• Femto Java basics• Femto Java Card • Conclusion
29-09-14
Femto Java—BOF 2187 6
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 7
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 8
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 9
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 10
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 11
Femto Java Development
29-09-14
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
Compile
• Restricted Platform runtime• +java.lang.annotation
• Reveals Restricted Platform Java subset errors
• Includes generated code
Test on target platform
• Post compile (convert)• Load• Function tests• Reuse test and support code
Femto Java—BOF 2187 12
Femto in NetBeans
29-09-14
Femto core modules
• Mark packages for sub project type processing
• Perform Restricted Platform runtime compilation
Restricted Platform I • e.g. Java card
Restricted Platform II • e.g. Embedded Java for smart card
terminal
• NB Code development project for Java SE project• Code for restricted platform is in one or more ear-
marked packages• Creates a sub project type within the NB project
Femto Java—BOF 2187 13
Progress of this session
BackgroundFemto 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 14
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 15
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 16
Unit testingThe Java card runtime is instantiated at the start of each test.
29-09-14
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 … }}
Femto Java—BOF 2187 17
APDU Unit testingExplicit reference to Java card runtime to access APDU buffer
29-09-14
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()); }}
Femto Java—BOF 2187 18
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 19
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 20
Progress of this session
BackgroundFemto Java basicsFemto Java Card • Conclusion
29-09-14
Femto Java—BOF 2187 21
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 23
Thank you for your attention
29-09-14
http://java.net/projects/femto-java
Eduard de [email protected]