├── lib ├── vjcre.jar └── openkms-globalplatform.jar ├── .gitignore ├── ext ├── ant-javacard.jar ├── globalplatform-2_1_1 │ ├── gp211.jar │ └── org │ │ └── globalplatform │ │ └── javacard │ │ └── globalplatform.exp ├── java_card_kit-2_2_1 │ ├── bin │ │ ├── capgen │ │ ├── cref │ │ ├── jcwde │ │ ├── apdutool │ │ ├── capdump │ │ ├── exp2text │ │ ├── converter │ │ ├── scriptgen │ │ ├── verifycap │ │ ├── verifyexp │ │ └── verifyrev │ ├── lib │ │ ├── api.jar │ │ ├── apduio.jar │ │ ├── capdump.jar │ │ ├── jcwde.jar │ │ ├── apdutool.jar │ │ ├── converter.jar │ │ ├── installer.jar │ │ ├── scriptgen.jar │ │ ├── javacardframework.jar │ │ ├── jcclientsamples.jar │ │ ├── offcardverifier.jar │ │ └── jcrmiclientframework.jar │ └── api_export_files │ │ ├── java │ │ ├── io │ │ │ └── javacard │ │ │ │ └── io.exp │ │ ├── rmi │ │ │ └── javacard │ │ │ │ └── rmi.exp │ │ └── lang │ │ │ └── javacard │ │ │ └── lang.exp │ │ ├── javacardx │ │ └── crypto │ │ │ └── javacard │ │ │ └── crypto.exp │ │ └── javacard │ │ ├── security │ │ └── javacard │ │ │ └── security.exp │ │ └── framework │ │ ├── javacard │ │ └── framework.exp │ │ └── service │ │ └── javacard │ │ └── service.exp ├── java_card_kit-2_2_2 │ ├── bin │ │ ├── cref │ │ ├── libjpcsclite.so │ │ ├── jcwde │ │ ├── apdutool │ │ ├── capdump │ │ ├── capgen │ │ ├── scriptgen │ │ ├── converter │ │ ├── exp2text │ │ ├── verifycap │ │ ├── verifyexp │ │ └── verifyrev │ ├── lib │ │ ├── api.jar │ │ ├── apduio.jar │ │ ├── api_16.jar │ │ ├── capdump.jar │ │ ├── jcwde.jar │ │ ├── apdutool.jar │ │ ├── converter.jar │ │ ├── installer.jar │ │ ├── jcwde_16.jar │ │ ├── scriptgen.jar │ │ ├── javacardframework.jar │ │ ├── jcclientsamples.jar │ │ ├── offcardverifier.jar │ │ └── jcrmiclientframework.jar │ └── api_export_files │ │ ├── java │ │ ├── io │ │ │ └── javacard │ │ │ │ └── io.exp │ │ ├── rmi │ │ │ └── javacard │ │ │ │ └── rmi.exp │ │ └── lang │ │ │ └── javacard │ │ │ └── lang.exp │ │ ├── javacardx │ │ ├── apdu │ │ │ └── javacard │ │ │ │ └── apdu.exp │ │ ├── crypto │ │ │ └── javacard │ │ │ │ └── crypto.exp │ │ ├── biometry │ │ │ └── javacard │ │ │ │ └── biometry.exp │ │ ├── external │ │ │ └── javacard │ │ │ │ └── external.exp │ │ └── framework │ │ │ ├── tlv │ │ │ └── javacard │ │ │ │ └── tlv.exp │ │ │ ├── math │ │ │ └── javacard │ │ │ │ └── math.exp │ │ │ └── util │ │ │ ├── javacard │ │ │ └── util.exp │ │ │ └── intx │ │ │ └── javacard │ │ │ └── intx.exp │ │ └── javacard │ │ ├── security │ │ └── javacard │ │ │ └── security.exp │ │ └── framework │ │ ├── javacard │ │ └── framework.exp │ │ └── service │ │ └── javacard │ │ └── service.exp ├── java_card_kit-3_0_3 │ ├── lib │ │ ├── tools.jar │ │ ├── api_classic.jar │ │ ├── api_connected.jar │ │ └── logging.properties │ ├── shared │ │ ├── oracle.gif │ │ ├── downicon.gif │ │ ├── topicon.gif │ │ ├── Java_clr_hori.gif │ │ ├── smallOracleLogo.gif │ │ ├── Java_clr_hori_small.gif │ │ └── Java_clr_hori_interval.gif │ ├── api_export_files │ │ ├── java │ │ │ ├── io │ │ │ │ └── javacard │ │ │ │ │ └── io.exp │ │ │ ├── rmi │ │ │ │ └── javacard │ │ │ │ │ └── rmi.exp │ │ │ └── lang │ │ │ │ └── javacard │ │ │ │ └── lang.exp │ │ ├── javacardx │ │ │ ├── apdu │ │ │ │ └── javacard │ │ │ │ │ └── apdu.exp │ │ │ ├── crypto │ │ │ │ └── javacard │ │ │ │ │ └── crypto.exp │ │ │ ├── biometry │ │ │ │ └── javacard │ │ │ │ │ └── biometry.exp │ │ │ ├── external │ │ │ │ └── javacard │ │ │ │ │ └── external.exp │ │ │ └── framework │ │ │ │ ├── tlv │ │ │ │ └── javacard │ │ │ │ │ └── tlv.exp │ │ │ │ ├── math │ │ │ │ └── javacard │ │ │ │ │ └── math.exp │ │ │ │ └── util │ │ │ │ ├── javacard │ │ │ │ └── util.exp │ │ │ │ └── intx │ │ │ │ └── javacard │ │ │ │ └── intx.exp │ │ └── javacard │ │ │ ├── security │ │ │ └── javacard │ │ │ │ └── security.exp │ │ │ └── framework │ │ │ ├── javacard │ │ │ └── framework.exp │ │ │ └── service │ │ │ └── javacard │ │ │ └── service.exp │ └── legal │ │ └── Distribution_ReadME.txt └── visa_openplatform-2_0 │ ├── visaop20.jar │ └── visa │ └── openplatform │ └── javacard │ └── openplatform.exp ├── src ├── plaid804 │ └── PLAID804.java ├── org │ ├── satochip │ │ └── applet │ │ │ ├── CardEdge.java │ │ │ ├── HmacSha160.java │ │ │ └── HmacSha512.java │ ├── isodl │ │ └── applet │ │ │ ├── BERTLVScanner.java │ │ │ ├── KeyStore.java │ │ │ └── LicenseUtil.java │ └── aispring │ │ └── javacard │ │ └── ndef │ │ └── UtilTLV.java ├── net │ ├── pwendland │ │ └── javacard │ │ │ └── pki │ │ │ └── isoapplet │ │ │ ├── IsoApplet.opt │ │ │ ├── Record.java │ │ │ ├── FileNotFoundException.java │ │ │ ├── NotEnoughSpaceException.java │ │ │ ├── ElementaryFile.java │ │ │ ├── ElementaryFileLinearVariable.java │ │ │ ├── ElementaryFileLinearFixed.java │ │ │ ├── ElementaryFileTransparent.java │ │ │ ├── ElementaryFileCyclicFixed.java │ │ │ └── File.java │ └── sourceforge │ │ └── javacardsign │ │ └── applet │ │ └── FileNotFoundException.java ├── sos │ └── passportapplet │ │ ├── ATRGlobal.java │ │ ├── Log.java │ │ ├── BERTLVScanner.java │ │ ├── JCOP41PassportCrypto.java │ │ ├── KeyStore.java │ │ └── CREFPassportCrypto.java ├── de │ └── spline │ │ └── uves │ │ └── ndef │ │ ├── SelectRequest.java │ │ ├── State.java │ │ ├── Request.java │ │ ├── ContainerSelectRequest.java │ │ ├── ReadBinaryRequest.java │ │ └── Ndef.java ├── be │ └── fedict │ │ └── eidapplet │ │ ├── MasterFile.java │ │ ├── File.java │ │ ├── DedicatedFile.java │ │ └── ElementaryFile.java ├── com │ ├── mysmartlogon │ │ └── gidsApplet │ │ │ ├── ErrorCode.java │ │ │ ├── InvalidArgumentsException.java │ │ │ ├── NotFoundException.java │ │ │ ├── Record.java │ │ │ ├── NotEnoughSpaceException.java │ │ │ ├── ElementaryFile.java │ │ │ ├── GidsPIN.java │ │ │ └── ApplicationFile.java │ ├── btchip │ │ └── applet │ │ │ └── poc │ │ │ ├── Uint64Helper.java │ │ │ ├── Uint32Helper.java │ │ │ ├── GenericBEHelper.java │ │ │ ├── BCDUtils.java │ │ │ ├── WrappingKeyRepository.java │ │ │ ├── TC.java │ │ │ ├── Base58.java │ │ │ └── BTChipNFCForumApplet.java │ └── redhat │ │ └── ckey │ │ └── applet │ │ └── ASN1.java └── openemv │ ├── EMVConstants.java │ ├── EMVProtocolState.java │ └── EMVStaticData.java ├── .project ├── .classpath ├── .travis.yml └── README.md /lib/vjcre.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/lib/vjcre.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /applet-playground-caps.jar 2 | /applet-playground.jar 3 | /*.cap 4 | /tmp 5 | /bin 6 | *~ 7 | -------------------------------------------------------------------------------- /ext/ant-javacard.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/ant-javacard.jar -------------------------------------------------------------------------------- /src/plaid804/PLAID804.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/src/plaid804/PLAID804.java -------------------------------------------------------------------------------- /lib/openkms-globalplatform.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/lib/openkms-globalplatform.jar -------------------------------------------------------------------------------- /ext/globalplatform-2_1_1/gp211.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/globalplatform-2_1_1/gp211.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/capgen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/capgen -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/cref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/cref -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/jcwde: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/jcwde -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/cref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/bin/cref -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/apdutool: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/apdutool -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/capdump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/capdump -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/exp2text: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/exp2text -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/api.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/api.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/converter: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/converter -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/scriptgen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/scriptgen -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/verifycap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/verifycap -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/verifyexp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/verifyexp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/bin/verifyrev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/bin/verifyrev -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/apduio.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/apduio.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/capdump.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/capdump.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/jcwde.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/jcwde.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/apduio.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/apduio.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/api_16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/api_16.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/capdump.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/capdump.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/jcwde.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/jcwde.jar -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/lib/tools.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/lib/tools.jar -------------------------------------------------------------------------------- /ext/visa_openplatform-2_0/visaop20.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/visa_openplatform-2_0/visaop20.jar -------------------------------------------------------------------------------- /src/org/satochip/applet/CardEdge.java: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/src/org/satochip/applet/CardEdge.java -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/apdutool.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/apdutool.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/converter.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/converter.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/installer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/installer.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/scriptgen.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/scriptgen.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/apdutool.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/apdutool.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/converter.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/converter.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/installer.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/installer.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/jcwde_16.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/jcwde_16.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/scriptgen.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/scriptgen.jar -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/oracle.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/oracle.gif -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/libjpcsclite.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/bin/libjpcsclite.so -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/lib/api_classic.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/lib/api_classic.jar -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/downicon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/downicon.gif -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/topicon.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/topicon.gif -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/lib/api_connected.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/lib/api_connected.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/javacardframework.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/javacardframework.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/jcclientsamples.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/jcclientsamples.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/offcardverifier.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/offcardverifier.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/javacardframework.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/javacardframework.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/jcclientsamples.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/jcclientsamples.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/offcardverifier.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/offcardverifier.jar -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/Java_clr_hori.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/Java_clr_hori.gif -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/smallOracleLogo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/smallOracleLogo.gif -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/lib/jcrmiclientframework.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/lib/jcrmiclientframework.jar -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/lib/jcrmiclientframework.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/lib/jcrmiclientframework.jar -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/Java_clr_hori_small.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/Java_clr_hori_small.gif -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/shared/Java_clr_hori_interval.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/shared/Java_clr_hori_interval.gif -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/java/io/javacard/io.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/java/io/javacard/io.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/java/io/javacard/io.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/java/io/javacard/io.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/java/io/javacard/io.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/java/io/javacard/io.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/java/rmi/javacard/rmi.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/java/rmi/javacard/rmi.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/java/rmi/javacard/rmi.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/java/rmi/javacard/rmi.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/java/rmi/javacard/rmi.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/java/rmi/javacard/rmi.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/java/lang/javacard/lang.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/java/lang/javacard/lang.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/java/lang/javacard/lang.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/java/lang/javacard/lang.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/java/lang/javacard/lang.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/java/lang/javacard/lang.exp -------------------------------------------------------------------------------- /ext/visa_openplatform-2_0/visa/openplatform/javacard/openplatform.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/visa_openplatform-2_0/visa/openplatform/javacard/openplatform.exp -------------------------------------------------------------------------------- /ext/globalplatform-2_1_1/org/globalplatform/javacard/globalplatform.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/globalplatform-2_1_1/org/globalplatform/javacard/globalplatform.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/apdu/javacard/apdu.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/apdu/javacard/apdu.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/apdu/javacard/apdu.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/apdu/javacard/apdu.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/javacardx/crypto/javacard/crypto.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/javacardx/crypto/javacard/crypto.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/crypto/javacard/crypto.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/crypto/javacard/crypto.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/crypto/javacard/crypto.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/crypto/javacard/crypto.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/javacard/security/javacard/security.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/javacard/security/javacard/security.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacard/security/javacard/security.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacard/security/javacard/security.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/biometry/javacard/biometry.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/biometry/javacard/biometry.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/external/javacard/external.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/external/javacard/external.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/tlv/javacard/tlv.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/tlv/javacard/tlv.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacard/security/javacard/security.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacard/security/javacard/security.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/biometry/javacard/biometry.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/biometry/javacard/biometry.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/external/javacard/external.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/external/javacard/external.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/tlv/javacard/tlv.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/tlv/javacard/tlv.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/javacard/framework/javacard/framework.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/javacard/framework/javacard/framework.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacard/framework/javacard/framework.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacard/framework/javacard/framework.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/math/javacard/math.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/math/javacard/math.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/util/javacard/util.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/util/javacard/util.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacard/framework/javacard/framework.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacard/framework/javacard/framework.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/math/javacard/math.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/math/javacard/math.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/util/javacard/util.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/util/javacard/util.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_1/api_export_files/javacard/framework/service/javacard/service.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_1/api_export_files/javacard/framework/service/javacard/service.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacard/framework/service/javacard/service.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacard/framework/service/javacard/service.exp -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/util/intx/javacard/intx.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-2_2_2/api_export_files/javacardx/framework/util/intx/javacard/intx.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacard/framework/service/javacard/service.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacard/framework/service/javacard/service.exp -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/util/intx/javacard/intx.exp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinpaljak/AppletPlayground/HEAD/ext/java_card_kit-3_0_3/api_export_files/javacardx/framework/util/intx/javacard/intx.exp -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/IsoApplet.opt: -------------------------------------------------------------------------------- 1 | -d ../dist 2 | -out EXP JCA CAP 3 | -exportpath . 4 | -applet 0xf2:0x76:0xa2:0x88:0xbc:0xfb:0xa6:0x9d:0x34:0xf3:0x10:0x1 net.pwendland.javacard.pki.isoapplet.IsoApplet 5 | net.pwendland.javacard.pki.isoapplet 6 | 0xf2:0x76:0xa2:0x88:0xbc:0xfb:0xa6:0x9d:0x34:0xf3:0x10 1.0 7 | -------------------------------------------------------------------------------- /src/sos/passportapplet/ATRGlobal.java: -------------------------------------------------------------------------------- 1 | package sos.passportapplet; 2 | 3 | /* buffer for ATR Historical Bytes (ATS) must be a global */ 4 | 5 | public class ATRGlobal { 6 | public static byte[] ATR_HIST= {(byte) 0x4a,(byte) 0x4d,(byte) 0x52, (byte) 0x54, (byte) 0x44}; // "JMRTD" 7 | public static byte ATR_HIST_LEN= 0x05; 8 | } 9 | -------------------------------------------------------------------------------- /src/de/spline/uves/ndef/SelectRequest.java: -------------------------------------------------------------------------------- 1 | package de.spline.uves.ndef; 2 | 3 | import javacard.framework.*; 4 | 5 | public class SelectRequest extends Request { 6 | static byte insbyte = ISO7816.INS_SELECT; 7 | 8 | public State process(APDU apdu, State state) { 9 | state.application = State.SELECTED; 10 | return state; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/de/spline/uves/ndef/State.java: -------------------------------------------------------------------------------- 1 | package de.spline.uves.ndef; 2 | 3 | import javacard.framework.*; 4 | 5 | public class State { 6 | 7 | // constant for state codings 8 | static final byte IDLE = 0; 9 | static final byte SELECTED = 1; 10 | static final byte EF_SELECTED = 2; 11 | 12 | protected byte application = IDLE; 13 | protected short ef = (short) 0; 14 | } 15 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | AppletPlayground 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/jcwde: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.jcwde.Main "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/apdutool: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.apdutool.Main "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/capdump: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.capdump.CapDump "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/capgen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.jcasm.cap.Main "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/scriptgen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.scriptgen.Main "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/converter: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.converter.Converter "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/exp2text: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.converter.Exp2Text "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/verifycap: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.offcardverifier.Verifier "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/verifyexp: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.offcardverifier.VerifyExp "$@" 16 | -------------------------------------------------------------------------------- /ext/java_card_kit-2_2_2/bin/verifyrev: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 4 | # Use is subject to license terms. 5 | # 6 | 7 | JAVA_HOME=${JAVA_HOME:-/usr/j2se} 8 | 9 | bin_home=`dirname $0` 10 | JC_HOME=${JC_HOME:-$bin_home/..} 11 | 12 | JC_PATH=$JC_HOME/lib/apdutool.jar:$JC_HOME/lib/apduio.jar:$JC_HOME/lib/converter.jar:$JC_HOME/lib/jcwde.jar:$JC_HOME/lib/scriptgen.jar:$JC_HOME/lib/offcardverifier.jar:$JC_HOME/lib/api.jar:$JC_HOME/lib/installer.jar:$JC_HOME/lib/capdump.jar:$JC_HOME/samples/classes:$CLASSPATH 13 | 14 | JFLAGS="-classpath $JC_PATH" 15 | $JAVA_HOME/bin/java $JFLAGS com.sun.javacard.offcardverifier.VerifyRev "$@" 16 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - openjdk7 4 | - oraclejdk8 5 | - oraclejdk7 6 | script: ant 7 | 8 | env: 9 | global: 10 | # The next declration is the encrypted COVERITY_SCAN_TOKEN, created 11 | # via the "travis encrypt" command using the project repo's public key 12 | - secure: "Bic6Pmjyfj/WG5OK+XtgcogE8Qn9eD1UTwB+WQ+E5TZSgmcb02wzNFvma9d9+ZsgTnLPPPK0PIeVGuf5tc2Vff4Cn9vByxEDZ38fQNoHZJD78pTTUlFIJk1nu7NNozmlplHjRp46/TBDnPem6LcMK+WywS9YXs3MKhVr602ZytY=" 13 | 14 | addons: 15 | coverity_scan: 16 | project: 17 | name: "martinpaljak/AppletPlayground" 18 | description: "Applet PLayground" 19 | notification_email: martin@martinpaljak.net 20 | build_command_prepend: 21 | build_command: ant 22 | branch_pattern: coverity 23 | -------------------------------------------------------------------------------- /src/de/spline/uves/ndef/Request.java: -------------------------------------------------------------------------------- 1 | package de.spline.uves.ndef; 2 | 3 | import javacard.framework.*; 4 | 5 | public abstract class Request { 6 | 7 | static final byte classbyte = ISO7816.CLA_ISO7816; 8 | static byte insbyte; 9 | 10 | public boolean isApplicable(APDU apdu, State state) { 11 | byte buffer[] = apdu.getBuffer(); 12 | 13 | if (buffer[ISO7816.OFFSET_CLA] != classbyte) { 14 | return false; 15 | } 16 | 17 | if (buffer[ISO7816.OFFSET_INS] != insbyte) { 18 | return false; 19 | } 20 | 21 | return true; 22 | } 23 | 24 | public abstract State process(APDU apdu, State state); 25 | 26 | // -- usefull helpers --------------------------- 27 | 28 | protected short decodeLcLength(byte[] buffer) { 29 | return buffer[ISO7816.OFFSET_LC]; 30 | // TODO: decode propperly three bytes values 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/be/fedict/eidapplet/MasterFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Quick-Key Toolset Project. 3 | * Copyright (C) 2010 FedICT. 4 | * 5 | * This is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License version 7 | * 3.0 as published by the Free Software Foundation. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this software; if not, see 16 | * http://www.gnu.org/licenses/. 17 | */ 18 | package be.fedict.eidapplet; 19 | 20 | public class MasterFile extends DedicatedFile { 21 | private static final short MF_FID = 0x3F00; 22 | public MasterFile() { 23 | // file identifier of MasterFile is hard coded to 3F00 24 | super(MF_FID); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/be/fedict/eidapplet/File.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Quick-Key Toolset Project. 3 | * Copyright (C) 2010 FedICT. 4 | * 5 | * This is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License version 7 | * 3.0 as published by the Free Software Foundation. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this software; if not, see 16 | * http://www.gnu.org/licenses/. 17 | */ 18 | package be.fedict.eidapplet; 19 | 20 | public abstract class File { 21 | // file identifier 22 | private short fileID; 23 | protected boolean active = true; 24 | public File(short fid) { 25 | fileID = fid; 26 | } 27 | public short getFileID() { 28 | return fileID; 29 | } 30 | public abstract short[] getPath(); 31 | public void setActive(boolean b) { 32 | active = b; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/de/spline/uves/ndef/ContainerSelectRequest.java: -------------------------------------------------------------------------------- 1 | package de.spline.uves.ndef; 2 | 3 | import javacard.framework.*; 4 | 5 | public class ContainerSelectRequest extends SelectRequest { 6 | 7 | // constants for elementary files 8 | static final short CAPABILITY_CONTAINER_EF = (short) 0xE103; 9 | 10 | public boolean isApplicable(APDU apdu, State state) { 11 | byte buffer[] = apdu.getBuffer(); 12 | if (super.isApplicable(apdu, state)) { 13 | 14 | if (buffer[ISO7816.OFFSET_P1] == (byte) 0x00 && /* select by file identfier */ 15 | buffer[ISO7816.OFFSET_P2] == (byte) 0x0C && /* first and only occourence */ 16 | decodeLcLength(buffer) == (short) 0x02 /* Lc = 2 */) { 17 | return true; 18 | } 19 | } 20 | return false; 21 | } 22 | 23 | public State process(APDU apdu, State state) { 24 | byte buffer[] = apdu.getBuffer(); 25 | state.ef = (short) ((buffer[ISO7816.OFFSET_CDATA] << 8) + buffer[ISO7816.OFFSET_CDATA + 1]); 26 | 27 | // filter for vlalid file identifiers 28 | switch (state.ef) { 29 | case CAPABILITY_CONTAINER_EF : 30 | state.application = State.EF_SELECTED; 31 | break; 32 | default : 33 | ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND); 34 | break; 35 | } 36 | 37 | return state; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/net/sourceforge/javacardsign/applet/FileNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Java Card PKI applet - ISO7816 compliant Java Card applet. 3 | * 4 | * Copyright (C) 2009 Wojciech Mostowski, woj@cs.ru.nl 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | */ 21 | 22 | package net.sourceforge.javacardsign.applet; 23 | 24 | /** 25 | * Tagging class for file not found exceptions. 26 | * 27 | * @author Wojciech Mostowski 28 | * 29 | */ 30 | class FileNotFoundException extends Exception { 31 | } 32 | -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/legal/Distribution_ReadME.txt: -------------------------------------------------------------------------------- 1 | DistributionREADME 2 | 3 | DISTRIBUTION BY DEVELOPERS. Subject to the terms and conditions of the Software License Agreement and the obligations, restrictions, and exceptions set forth below, You may reproduce and distribute the portions of Software identified below ("Redistributable"), provided that: 4 | 5 | (a) You distribute Redistributable complete and unmodified and only bundled as part of Your Programs, 6 | 7 | (b) Your Programs add significant and primary functionality to the Redistributable, 8 | 9 | (c) You do not distribute additional software intended to replace any 10 | component(s) of the Redistributable, 11 | 12 | (d) You do not remove or alter any proprietary legends or notices contained in or on the Redistributable. 13 | 14 | (e) You only distribute the Redistributable subject to a license agreement that protects Oracle's interests consistent with the terms contained in this 15 | Agreement, and 16 | 17 | (f) You agree to defend and indemnify Oracle and its licensors from and against any damages, costs, liabilities, settlement amounts and/or expenses (including attorneys' fees) incurred in connection with any claim, lawsuit or action by any third party that arises or results from the use or distribution of any and all Programs and/or Redistributable. 18 | 19 | The following files are Redistributables: 20 | 21 | Java Card Development Kit 3.0.3 22 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/Record.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief A Record. 24 | * 25 | * This class is necessary because multidimensional arrays are not supported by the JCVM. 26 | */ 27 | public class Record { 28 | byte[] data; 29 | 30 | /** 31 | * \brief Constructor. 32 | * 33 | * \param data The byte array to store. No copy is made. 34 | */ 35 | Record(byte[] data) { 36 | this.data = data; 37 | } 38 | 39 | /** 40 | * \brief Constructor. 41 | * 42 | * A new byte array is being allocated. Use the data-field to fill it up with data. 43 | * 44 | * \param size The size of the data array. 45 | */ 46 | Record(short size) { 47 | this.data = new byte[size]; 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/ErrorCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | /** 28 | * \brief Definition of some error codes 29 | * Note: use an interface instead of a class to save space on the card 30 | */ 31 | public interface ErrorCode { 32 | public static final short SW_PIN_TRIES_REMAINING = 0x63C0; // See ISO 7816-4 section 7.5.1 33 | public static final short SW_REFERENCE_DATA_NOT_FOUND = 0x6A88; 34 | public static final short SW_COMMAND_NOT_ALLOWED_GENERAL = 0x6900; 35 | public static final short SW_TERMINATION_STATE = 0x6285; 36 | public static final short SW_COMMAND_INCOMPATIBLE_WITH_FILE_STRUCTURE = 0x6981; 37 | public static final short SW_COMMAND_CHAINING_NOT_SUPPORTED = 0x6884; 38 | } 39 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/FileNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief The FileNotFoundException class. 24 | * 25 | * Should be thrown whenever a specified file could not be found. 26 | * This class is a singleton in order to save resources. 27 | * 28 | * \attention This singleton is not thread-safe. 29 | */ 30 | public class FileNotFoundException extends Exception { 31 | public static FileNotFoundException instance; 32 | 33 | /** 34 | * \brief Private access constructor (Singleton pattern). 35 | */ 36 | private FileNotFoundException() { 37 | 38 | } 39 | 40 | /** 41 | * \brief Get the instance. 42 | * 43 | * \return The FileNotFoundException instance. 44 | */ 45 | public static FileNotFoundException getInstance() { 46 | if(instance == null) { 47 | instance = new FileNotFoundException(); 48 | } 49 | return instance; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/NotEnoughSpaceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief Exception class. 24 | * 25 | * This class is a singleton in order to save resources. 26 | * Should be thrown whenever: 27 | * - A limit for the maximum amount of children of a DedicatedFile is exceeded. 28 | * - An array can not hold that amount of data. 29 | * - Memory allocation failed due to full RAM/EEPROM. 30 | * 31 | * \attention This singleton is not thread-safe. 32 | */ 33 | public class NotEnoughSpaceException extends Exception { 34 | public static NotEnoughSpaceException instance; 35 | 36 | 37 | /** 38 | * \brief Private access constructor (Singleton pattern). 39 | */ 40 | private NotEnoughSpaceException() { 41 | 42 | } 43 | 44 | /** 45 | * \brief Get the instance. 46 | * 47 | * \return The FileNotFoundException instance. 48 | */ 49 | public static NotEnoughSpaceException getInstance() { 50 | if(instance == null) { 51 | instance = new NotEnoughSpaceException(); 52 | } 53 | return instance; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/InvalidArgumentsException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | /** 28 | * \brief The InvalidArgumentsException class. 29 | * 30 | * \attention This singleton is not thread-safe. 31 | */ 32 | public class InvalidArgumentsException extends Exception { 33 | /** 34 | * 35 | */ 36 | public static InvalidArgumentsException instance; 37 | 38 | /** 39 | * \brief Private access constructor (Singleton pattern). 40 | */ 41 | private InvalidArgumentsException() { 42 | 43 | } 44 | 45 | /** 46 | * \brief Get the instance. 47 | * 48 | * \return The InvalidArgumentsException instance. 49 | */ 50 | public static InvalidArgumentsException getInstance() { 51 | if(instance == null) { 52 | instance = new InvalidArgumentsException(); 53 | } 54 | return instance; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/NotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | /** 28 | * \brief The NotFoundException class. 29 | * 30 | * Should be thrown whenever a specified file or tag in a TLV structure 31 | * could not be found. This class is a singleton in order to save resources. 32 | * 33 | * \attention This singleton is not thread-safe. 34 | */ 35 | public class NotFoundException extends Exception { 36 | /** 37 | * 38 | */ 39 | public static NotFoundException instance; 40 | 41 | /** 42 | * \brief Private access constructor (Singleton pattern). 43 | */ 44 | private NotFoundException() { 45 | 46 | } 47 | 48 | /** 49 | * \brief Get the instance. 50 | * 51 | * \return The NotFoundException instance. 52 | */ 53 | public static NotFoundException getInstance() { 54 | if(instance == null) { 55 | instance = new NotFoundException(); 56 | } 57 | return instance; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/Record.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | import javacard.framework.Util; 28 | 29 | /** 30 | * \brief A Record. 31 | * 32 | * This class is necessary because multidimensional arrays are not supported by the JCVM. 33 | */ 34 | public class Record { 35 | byte[] data; 36 | 37 | /** 38 | * \brief Constructor. 39 | * 40 | * \param data The byte array to store. No copy is made. 41 | */ 42 | Record(byte[] data) { 43 | this.data = data; 44 | } 45 | 46 | /** 47 | * \brief Constructor. 48 | * 49 | * A new byte array is being allocated. Use the data-field to fill it up with data. 50 | * 51 | * \param size The size of the data array. 52 | */ 53 | Record(short size) { 54 | this.data = new byte[size]; 55 | } 56 | 57 | byte[] GetData() { 58 | return this.data; 59 | } 60 | 61 | public void clearContents() { 62 | Util.arrayFillNonAtomic(data, (short)0, (short)data.length, (byte)0); 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/be/fedict/eidapplet/DedicatedFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Quick-Key Toolset Project. 3 | * Copyright (C) 2010 FedICT. 4 | * 5 | * This is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License version 7 | * 3.0 as published by the Free Software Foundation. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this software; if not, see 16 | * http://www.gnu.org/licenses/. 17 | */ 18 | package be.fedict.eidapplet; 19 | 20 | public class DedicatedFile extends File { 21 | // link to parent DF 22 | private DedicatedFile parentFile; 23 | // list of sibling files (either EF or DF) 24 | private static final byte MAX_SIBLINGS = 10; 25 | private File[] siblings = new File[MAX_SIBLINGS]; 26 | // number of siblings 27 | private byte number = 0; 28 | // constructor only used by MasterFile 29 | protected DedicatedFile(short fid) { 30 | super(fid); 31 | // MasterFile does not have a parent, as it is the root of all files 32 | parentFile = null; 33 | } 34 | public DedicatedFile(short fid, DedicatedFile parent) { 35 | super(fid); 36 | parentFile = parent; 37 | parent.addSibling(this); 38 | } 39 | public short[] getPath() { 40 | short[] path; 41 | if (parentFile != null) { 42 | path = parentFile.getPath(); 43 | path[(short) (path.length + 1)] = getFileID(); 44 | } else 45 | path = new short[] { getFileID() }; 46 | return path; 47 | } 48 | public DedicatedFile getParent() { 49 | return parentFile; 50 | } 51 | public byte getNumberOfSiblings() { 52 | return number; 53 | } 54 | public File getSibling(short fid) { 55 | for (byte i = 0; i < number; i++) { 56 | if (siblings[i].getFileID() == fid) 57 | return siblings[i]; 58 | } 59 | return null; 60 | } 61 | protected void addSibling(File s) { 62 | if (number < MAX_SIBLINGS) 63 | siblings[number++] = s; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/NotEnoughSpaceException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | /** 28 | * \brief Exception class. 29 | * 30 | * This class is a singleton in order to save resources. 31 | * Should be thrown whenever: 32 | * - A limit for the maximum amount of children of a DedicatedFile is exceeded. 33 | * - An array can not hold that amount of data. 34 | * - Memory allocation failed due to full RAM/EEPROM. 35 | * 36 | * \attention This singleton is not thread-safe. 37 | */ 38 | public class NotEnoughSpaceException extends Exception { 39 | /** 40 | * 41 | */ 42 | public static NotEnoughSpaceException instance; 43 | 44 | 45 | /** 46 | * \brief Private access constructor (Singleton pattern). 47 | */ 48 | private NotEnoughSpaceException() { 49 | 50 | } 51 | 52 | /** 53 | * \brief Get the instance. 54 | * 55 | * \return The FileNotFoundException instance. 56 | */ 57 | public static NotEnoughSpaceException getInstance() { 58 | if(instance == null) { 59 | instance = new NotEnoughSpaceException(); 60 | } 61 | return instance; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/Uint64Helper.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.Util; 24 | 25 | /** 26 | * Basic operations on 64 bits unsigned integers 27 | * @author BTChip 28 | * 29 | */ 30 | public class Uint64Helper { 31 | 32 | public static void clear(byte[] buffer, short offset) { 33 | Util.arrayFillNonAtomic(buffer, offset, (short)8, (byte)0x00); 34 | } 35 | 36 | public static void add(byte[] a, short aOffset, byte[] b, short bOffset) { 37 | GenericBEHelper.add((byte)8, a, aOffset, a, aOffset, b, bOffset); 38 | } 39 | 40 | public static void add(byte[] target, short targetOffset, byte[] a, short aOffset, byte[] b, short bOffset) { 41 | GenericBEHelper.add((byte)8, target, targetOffset, a, aOffset, b, bOffset); 42 | } 43 | 44 | public static void sub(byte[] target, short targetOffset, byte[] a, short aOffset, byte[] b, short bOffset) { 45 | GenericBEHelper.sub((byte)8, target, targetOffset, a, aOffset, b, bOffset); 46 | } 47 | 48 | public static void swap(byte[] target, short targetOffset, byte[] a, short aOffset) { 49 | GenericBEHelper.swap((byte)8, target, targetOffset, a, aOffset); 50 | } 51 | 52 | public static boolean isZero(byte[] a, short aOffset) { 53 | return GenericBEHelper.isZero((byte)8, a, aOffset); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/ElementaryFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief The abstract ElementaryFile class. 24 | * 25 | * It's main purpose is to be able to easily differentiate between EFs and DFs. 26 | */ 27 | public abstract class ElementaryFile extends File { 28 | private byte shortFileID; 29 | 30 | /** 31 | * \brief Abstract constructor to be called by subclasses. 32 | * 33 | * \param fileControlInformation The array of bytes containing the valid (!) File Control Information. 34 | * No Copy is made. 35 | * 36 | * \param fileID The ID of the file. Consistency with tag 0x83 from the FCI is NOT checked. 37 | * 38 | * \attention No copy of the FCI is made. Do not pass any buffer that is altered 39 | * later (e.g. the apdu buffer). Max length 257 bytes as the length 40 | * of the FCI Tag (6F) must be a byte. 41 | * 42 | * \attention To be safe, use IsoFileSystem.getSafeFile() to instantiate files. 43 | */ 44 | public ElementaryFile(short fileID, byte[] fileControlInformation) { 45 | super(fileID, fileControlInformation); 46 | // If not specified otherwise, the SFI should be the last 5 bits of the FID. 47 | this.shortFileID = (byte) (fileID & 0x001F); 48 | } 49 | 50 | /** 51 | * \brief Get the short file Identifier (SFI). 52 | * 53 | * \return The SFI. 54 | */ 55 | public byte getShortFileID() { 56 | return shortFileID; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /ext/java_card_kit-3_0_3/lib/logging.properties: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2010, 2010, Oracle and/or its affiliates. All rights reserved. 2 | 3 | # Properties file which configures the operation of the JDK 4 | # logging facility. 5 | 6 | # The system will look for this config file, first using 7 | # a System property specified at startup: 8 | # 9 | # >java -Djava.util.logging.config.file=myLoggingConfigFilePath 10 | # 11 | # If this property is not specified, then the config file is 12 | # retrieved from its default location at: 13 | # 14 | # JDK_HOME/jre/lib/logging.properties 15 | 16 | # Global logging properties. 17 | # ------------------------------------------ 18 | # The set of handlers to be loaded upon startup. 19 | # Comma-separated list of class names. 20 | # java.util.logging.ConsoleHandler 21 | handlers=com.sun.javacard.tools.util.JCConsoleHandler, java.util.logging.FileHandler 22 | 23 | # Default global logging level. 24 | # Loggers and Handlers may override this level 25 | .level=ALL 26 | 27 | # Loggers 28 | # ------------------------------------------ 29 | # Loggers are usually attached to packages. 30 | # Here, the level for each package is specified. 31 | # The global level is used by default, so levels 32 | # specified here simply act as an override. 33 | #com.sun.javacard.offcardinstaller=ALL 34 | 35 | # Handlers 36 | # ----------------------------------------- 37 | 38 | com.sun.javacard.tools.util.JCConsoleHandler.level=ALL 39 | com.sun.javacard.tools.util.JCConsoleHandler.formatter=com.sun.javacard.tools.util.JCToolsFormatter 40 | com.sun.javacard.tools.util.JCConsoleHandler.filter=com.sun.javacard.tools.util.ConsoleFilter 41 | 42 | # --- FileHandler --- 43 | # Override of global logging level 44 | java.util.logging.FileHandler.level=ALL 45 | 46 | # Naming style for the output file: 47 | # (The output file is placed in the directory 48 | # defined by the "user.home" System property.) 49 | java.util.logging.FileHandler.pattern=%h/java%u.log 50 | 51 | # Limiting size of output file in bytes: 52 | java.util.logging.FileHandler.limit=50000 53 | 54 | # Number of output files to cycle through, by appending an 55 | # integer to the base file name: 56 | java.util.logging.FileHandler.count=10 57 | 58 | # Style of output (Simple or XML): 59 | java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter 60 | 61 | java.util.logging.FileHandler.append=true 62 | 63 | #--------------print class method info 64 | printCurrentClassAndMethod = false 65 | -------------------------------------------------------------------------------- /src/de/spline/uves/ndef/ReadBinaryRequest.java: -------------------------------------------------------------------------------- 1 | package de.spline.uves.ndef; 2 | 3 | import javacard.framework.*; 4 | 5 | public class ReadBinaryRequest extends Request { 6 | 7 | static byte insbyte = Ndef.INS_READ_BINARY; 8 | 9 | // constant container 10 | static final byte[] capabilityContainer = {(byte) 0x00, (byte) 0x0F, // size of cc 11 | (byte) 0x20, // mapping version 2.0 12 | (byte) 0xFF, (byte) 0xFF, // maximum le (TODO: get from manual) 13 | (byte) 0x00, (byte) 0xFF, // maximum lc (TODO: get from manual) 14 | (byte) 0x04, (byte) 0x06, // extended ndef file (TLV header) 15 | (byte) 0x00, (byte) 0x01, // file identifier 16 | (byte) 0xFF, (byte) 0xFF, // maximum file length 17 | (byte) 0x00, // read access condition [any] 18 | (byte) 0xFF // write access condition [none] 19 | }; 20 | 21 | public boolean isApplicable(APDU apdu, State state) { 22 | byte buffer[] = apdu.getBuffer(); 23 | if (super.isApplicable(apdu, state)) { 24 | if (state.application == State.EF_SELECTED) { 25 | return true; 26 | } 27 | } 28 | 29 | return false; 30 | } 31 | 32 | public State process(APDU apdu, State state) { 33 | byte buffer[] = apdu.getBuffer(); 34 | if (state.ef == ContainerSelectRequest.CAPABILITY_CONTAINER_EF) { 35 | short offset = (short) (buffer[ISO7816.OFFSET_P1] << 8 + buffer[ISO7816.OFFSET_P2]); 36 | byte offset_byte3; 37 | short le = 0; 38 | 39 | if (0x0000 <= offset && offset <= 0x7FFF) { // short offset 40 | le = buffer[ISO7816.OFFSET_CDATA]; // Todo: proper le decoding 41 | 42 | apdu.setOutgoing(); 43 | apdu.setOutgoingLength(le); 44 | sendCapabilityContainer(buffer, offset, le); 45 | apdu.sendBytes((short) 0, le); 46 | 47 | } else if (offset == 0x0000 48 | && // long offsets 49 | buffer[ISO7816.OFFSET_CDATA] == 5 50 | && buffer[ISO7816.OFFSET_CDATA + 1] == 0x54 51 | && buffer[ISO7816.OFFSET_CDATA + 2] == 0x03) { 52 | 53 | offset = (short) (buffer[ISO7816.OFFSET_CDATA + 1] << 8 | buffer[ISO7816.OFFSET_CDATA + 2]); 54 | 55 | offset_byte3 = buffer[ISO7816.OFFSET_CDATA + 3]; 56 | 57 | le = buffer[ISO7816.OFFSET_CDATA + 5]; // Todo: proper le decoding 58 | 59 | // feature not supported yet 60 | ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); 61 | } else { // invalid encoded offset 62 | ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); 63 | } 64 | } else { 65 | ISOException.throwIt(ISO7816.SW_FILE_INVALID); 66 | } 67 | 68 | return state; 69 | } 70 | 71 | protected short sendCapabilityContainer(byte[] buffer, short offset, 72 | short length) { 73 | return Util.arrayCopyNonAtomic(capabilityContainer, offset, buffer, 74 | (short) 0, length); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/sos/passportapplet/Log.java: -------------------------------------------------------------------------------- 1 | package sos.passportapplet; 2 | 3 | /** 4 | * This class saves a log of the instruction sent to the passport as follows: 5 | * 6 | * [session nr byte] [length of data byte] [data] ... 7 | * 8 | * The data is a sequence of the instruction bytes, special cases: 9 | * 10 | * SELECT_FILE: followed by the file identifier (2 bytes) 11 | * 12 | * When the same instruction is called consequtively, only one is recorded, 13 | * but this byte is followed by FF 14 | * 15 | * FIXME: When the log exceeds log.length, the counter is wrapped, but this 16 | * breaks the format. 17 | * 18 | * @author ceesb 19 | * 20 | */ 21 | class Log { 22 | private byte[] log; 23 | private short sessionBase; 24 | private short sessionOffset; 25 | private short sessions; 26 | private short insCount; 27 | private short prevIns; 28 | boolean enabled; 29 | 30 | Log(FileSystem filesystem) { 31 | filesystem.createFile(FileSystem.SOS_LOG_FID, (short) 128); 32 | log = filesystem.getFile(FileSystem.SOS_LOG_FID); 33 | } 34 | 35 | private void writeLogByte(byte b) { 36 | writeLogByteNoUpdate(b); 37 | sessionOffset++; 38 | sessionOffset %= log.length; 39 | } 40 | 41 | private void writeLogByteNoUpdate(byte b) { 42 | log[(byte) ((sessionBase + sessionOffset) & 0xff)] = b; 43 | log[(byte) (sessionBase + 1)] = (byte) (sessionOffset & 0xff); 44 | } 45 | 46 | 47 | public void enabled(boolean v) { 48 | enabled = v; 49 | } 50 | 51 | public void newSession() { 52 | if (!enabled) { 53 | return; 54 | } 55 | sessionBase = sessionOffset; 56 | sessionOffset = 0; 57 | writeLogByteNoUpdate((byte) (sessions++ & 0xff)); 58 | sessionOffset = 2; 59 | } 60 | 61 | public void insByte(byte ins) { 62 | if (!enabled) { 63 | return; 64 | } 65 | 66 | if(ins == prevIns) { 67 | writeLogByte((byte)0xff); 68 | writeLogByte((byte)(++insCount & 0xff)); 69 | sessionOffset -= 2; 70 | } 71 | else if(insCount > 0) { 72 | sessionOffset += 2; 73 | insCount = 0; 74 | writeLogByte(ins); 75 | } 76 | else { 77 | writeLogByte(ins); 78 | } 79 | 80 | prevIns = ins; 81 | 82 | } 83 | 84 | public void selectFile(short fid) { 85 | if (!enabled) { 86 | return; 87 | } 88 | writeLogByte((byte) ((fid >>> 8) & 0xff)); 89 | writeLogByte((byte) (fid & 0xff)); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/ElementaryFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | /** 28 | * \brief The abstract class ElementaryFile. 29 | * 30 | * It's main purpose is to be able to easily differentiate between EFs and DFs. 31 | */ 32 | public abstract class ElementaryFile extends File { 33 | private byte shortFileID; 34 | 35 | /** 36 | * \brief Abstract constructor to be called by subclasses. 37 | * 38 | * \param fileControlInformation The array of bytes containing the valid (!) File Control Information. 39 | * No Copy is made. 40 | * 41 | * \param fileID The ID of the file. Consistency with tag 0x83 from the FCI is NOT checked. 42 | * 43 | * \attention No copy of the FCI is made. Do not pass any buffer that is altered 44 | * later (e.g. the apdu buffer). Max length 257 bytes as the length 45 | * of the FCI Tag (6F) must be a byte. 46 | * 47 | * \attention To be safe, use IsoFileSystem.getSafeFile() to instantiate files. 48 | */ 49 | public ElementaryFile(short fileID, byte[] fileControlInformation) { 50 | super(fileID, fileControlInformation); 51 | // If not specified otherwise, the SFI should be the last 5 bits of the FID. 52 | this.shortFileID = (byte) (fileID & 0x001F); 53 | } 54 | 55 | /** 56 | * \brief Get the short file Identifier (SFI). 57 | * 58 | * \return The SFI. 59 | */ 60 | public byte getShortFileID() { 61 | return shortFileID; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/be/fedict/eidapplet/ElementaryFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Quick-Key Toolset Project. 3 | * Copyright (C) 2010 FedICT. 4 | * 5 | * This is free software; you can redistribute it and/or modify it 6 | * under the terms of the GNU Lesser General Public License version 7 | * 3.0 as published by the Free Software Foundation. 8 | * 9 | * This software is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this software; if not, see 16 | * http://www.gnu.org/licenses/. 17 | */ 18 | package be.fedict.eidapplet; 19 | import javacard.framework.ISO7816; 20 | import javacard.framework.ISOException; 21 | import javacard.framework.Util; 22 | 23 | public class ElementaryFile extends File { 24 | // link to parent DF 25 | private DedicatedFile parentFile; 26 | // data stored in file 27 | private byte[] data; 28 | // current size of data stored in file 29 | short size; 30 | public ElementaryFile(short fid, DedicatedFile parent, byte[] d) { 31 | super(fid); 32 | parentFile = parent; 33 | parent.addSibling(this); 34 | data = d; 35 | size = (short) d.length; 36 | } 37 | public ElementaryFile(short fid, DedicatedFile parent, short maxSize) { 38 | super(fid); 39 | parentFile = parent; 40 | parent.addSibling(this); 41 | data = new byte[maxSize]; 42 | size = (short) 0; 43 | } 44 | public DedicatedFile getParent() { 45 | return parentFile; 46 | } 47 | public byte[] getData() { 48 | if (active == true) 49 | return data; 50 | else { 51 | ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); 52 | return null; 53 | } 54 | } 55 | public short getCurrentSize() { 56 | if (active == true) 57 | return size; 58 | else { 59 | ISOException.throwIt(ISO7816.SW_SECURITY_STATUS_NOT_SATISFIED); 60 | return 0; 61 | } 62 | } 63 | public short getMaxSize() { 64 | return (short) data.length; 65 | } 66 | public short[] getPath() { 67 | short[] path = parentFile.getPath(); 68 | path[(short) (path.length + 1)] = getFileID(); 69 | return path; 70 | } 71 | public void eraseData(short offset) { 72 | Util.arrayFillNonAtomic(data, offset, size, (byte) 0); 73 | } 74 | public void updateData(short dataOffset, byte[] newData, short newDataOffset, short length) { 75 | // update size 76 | size = (short) (dataOffset + length); 77 | // copy new data 78 | Util.arrayCopy(newData, newDataOffset, data, dataOffset, length); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/GidsPIN.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | import javacard.framework.ISO7816; 28 | import javacard.framework.ISOException; 29 | import javacard.framework.OwnerPIN; 30 | import javacard.framework.PIN; 31 | 32 | /** 33 | * \brief The GidsPIN class. 34 | * 35 | */ 36 | 37 | public class GidsPIN extends OwnerPIN implements PIN { 38 | 39 | 40 | private byte currentPINLen = 0; 41 | private byte minPINSize = 0; 42 | private byte maxPINSize = 0; 43 | private byte tryLimit = 0; 44 | 45 | public GidsPIN(byte tryLimit, byte maxPINSize, byte minPINSize) { 46 | super(tryLimit, maxPINSize); 47 | this.maxPINSize = maxPINSize; 48 | this.tryLimit = tryLimit; 49 | this.minPINSize = minPINSize; 50 | } 51 | 52 | public byte GetCurrentPINLen() { 53 | return currentPINLen; 54 | } 55 | 56 | public byte GetMinPINSize() { 57 | return minPINSize; 58 | } 59 | 60 | public byte GetMaxPINSize() { 61 | return maxPINSize; 62 | } 63 | 64 | public void CheckLength(byte len) { 65 | if (len < minPINSize || len > maxPINSize) { 66 | ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); 67 | } 68 | } 69 | 70 | public void setAsAuthenticated() { 71 | this.setValidatedFlag(true); 72 | } 73 | 74 | public void update(byte[] pin, 75 | short offset, 76 | byte length) { 77 | super.update(pin, offset, length); 78 | currentPINLen = length; 79 | } 80 | 81 | public byte getTryLimit() { 82 | return tryLimit; 83 | } 84 | 85 | } 86 | -------------------------------------------------------------------------------- /src/openemv/EMVConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Digital Security group, Radboud University 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package openemv; 20 | 21 | import javacard.framework.ISO7816; 22 | 23 | /* EMVConstants defines a constants used in the EMV standard and 24 | * constants specific to this implementation. It extends ISO7816 25 | * as some ISO7816 constants are also used by EMV. 26 | * 27 | * @author joeri (joeri@cs.ru.nl) 28 | * @author erikpoll (erikpoll@cs.ru.nl) 29 | * 30 | */ 31 | 32 | public interface EMVConstants extends ISO7816 { 33 | 34 | // commands 35 | byte INS_GENERATE_AC = (byte) 0xAE; 36 | byte INS_GET_DATA = (byte) 0xCA; 37 | byte INS_GET_PROCESSING_OPTIONS = (byte) 0xA8; 38 | byte INS_INTERNAL_AUTHENTICATE = (byte) 0x88; 39 | byte INS_VERIFY = (byte) 0x20; 40 | byte INS_GET_CHALLENGE = (byte) 0x84 ; 41 | byte INS_READ_RECORD = (byte) 0xB2; 42 | 43 | // Already defined in ISO7816.java: 44 | // INS_SELECT = A4 45 | // INS_EXTERNAL_AUTHENTICATE = 82 46 | 47 | // post-issuance commands 48 | byte INS_APPLICATION_BLOCK = (byte)0x1E; 49 | byte INS_APPLICATION_UNBLOCK = (byte)0x18; 50 | byte INS_CARD_BLOCK = (byte)0x16; 51 | byte INS_PIN_CHANGE_UNBLOCK = (byte)0x24; 52 | 53 | // status words 54 | short SW_ISSUER_AUTHENTICATION_FAILED = (short)0x6300; 55 | 56 | // constants to record the (persistent) lifecycle state 57 | byte PERSONALISATION = (byte)0x00; 58 | byte READY = (byte)0x01; 59 | byte BLOCKED = (byte)0x02; 60 | 61 | /* codes for cryptogram types used in P1*/ 62 | byte ARQC_CODE = (byte)0x80; 63 | byte TC_CODE = (byte)0x40; 64 | byte AAC_CODE = (byte)0x00; 65 | byte RFU_CODE = (byte)0xC0; 66 | 67 | /* types of AC */ 68 | byte NONE = (byte)0x00; 69 | byte ARQC = (byte)0x01; 70 | byte TC = (byte)0x02; 71 | byte AAC = (byte)0x03; 72 | 73 | // types of CVM performed; NONE for none. 74 | public final static byte PLAINTEXT_PIN = (byte)0x01; 75 | public final static byte ENCRYPTED_PIN = (byte)0x02; 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/org/satochip/applet/HmacSha160.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SatoChip Bitcoin Hardware Wallet based on javacard 3 | * (c) 2015 by Toporin - 16DMCk4WUaHofchAhpMaQS4UPm4urcy2dN 4 | * Sources available on https://github.com/Toporin 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package org.satochip.applet; 22 | 23 | import javacard.framework.ISOException; 24 | import javacard.framework.JCSystem; 25 | import javacard.security.MessageDigest; 26 | 27 | // very limited Hmac-SHA160 implementation 28 | public class HmacSha160 { 29 | 30 | private static MessageDigest sha160; 31 | public static final short BLOCKSIZE=64; // 64 bytes 32 | public static final short HASHSIZE=20; 33 | public static final short MAXMSGSIZE=192; 34 | private static final short SW_UNSUPPORTED_KEYSIZE = (short) 0x9c0E; 35 | private static final short SW_UNSUPPORTED_MSGSIZE = (short) 0x9c0F; 36 | private static byte[] data; 37 | 38 | 39 | public static void init(byte[] tmp){ 40 | sha160= MessageDigest.getInstance(MessageDigest.ALG_SHA, false); 41 | data= tmp; 42 | } 43 | 44 | public static short computeHmacSha160( 45 | byte[] key, short key_offset, short key_length, 46 | byte[] message, short message_offset, short message_length, 47 | byte[] mac, short mac_offset){ 48 | 49 | if (key_length>BLOCKSIZE || key_length<0){ 50 | ISOException.throwIt(SW_UNSUPPORTED_KEYSIZE); // don't accept keys bigger than block size 51 | } 52 | if (message_length>MAXMSGSIZE || message_length<0){ 53 | ISOException.throwIt(SW_UNSUPPORTED_MSGSIZE); 54 | } 55 | 56 | // compute inner hash 57 | for (short i=0; i 7 | * @author Wojciech Mostowski 8 | * 9 | */ 10 | public class BERTLVScanner { 11 | 12 | /** Universal tag class. */ 13 | public static final short UNIVERSAL_CLASS = 0; 14 | /** Application tag class. */ 15 | public static final short APPLICATION_CLASS = 1; 16 | /** Context specific tag class. */ 17 | public static final short CONTEXT_SPECIFIC_CLASS = 2; 18 | /** Private tag class. */ 19 | public static final short PRIVATE_CLASS = 3; 20 | 21 | // Tag data 22 | static short tag; 23 | static short tagClass; 24 | static boolean isPrimitive; 25 | 26 | // Offset and length for the value 27 | static short valueOffset; 28 | static short valueLength; 29 | 30 | private BERTLVScanner() { } 31 | 32 | public static short readTag(byte[] in, short offset) { 33 | short in_p = offset; 34 | short b = (short) (in[in_p] & 0xff); 35 | while (b == 0 || b == 0xff) { 36 | in_p++; 37 | b = in[in_p]; /* skip 00 and FF */ 38 | } 39 | switch (b & 0xC0) { 40 | case 0: 41 | tagClass = UNIVERSAL_CLASS; 42 | break; 43 | case 0x40: 44 | tagClass = APPLICATION_CLASS; 45 | break; 46 | case 0x80: 47 | tagClass = CONTEXT_SPECIFIC_CLASS; 48 | break; 49 | case 0xC0: 50 | tagClass = PRIVATE_CLASS; 51 | break; 52 | } 53 | switch (b & 0x20) { 54 | case 0: 55 | isPrimitive = true; 56 | break; 57 | case 0x20: 58 | isPrimitive = false; 59 | break; 60 | } 61 | switch (b & 0x1F) { 62 | case 0x1F: 63 | tag = b; 64 | in_p++; 65 | b = in[in_p]; 66 | while ((b & 0x80) == 0x80) { 67 | tag <<= 8; 68 | tag |= (b & 0x7F); 69 | in_p++; 70 | b = in[in_p]; 71 | } 72 | tag <<= 8; 73 | tag |= (b & 0x7F); 74 | break; 75 | default: 76 | tag = b; 77 | break; 78 | } 79 | in_p++; 80 | return in_p; 81 | } 82 | 83 | public static short readLength(byte[] in, short offset) { 84 | short in_p = offset; 85 | short b = (short) (in[offset] & 0xff); 86 | if ((b & 0x80) == 0) { 87 | /* short form */ 88 | valueLength = b; 89 | } else { 90 | /* long form */ 91 | short count = (short) (b & 0x7F); 92 | valueLength = 0; 93 | for (short i = 0; i < count; i++) { 94 | in_p++; 95 | b = (short) (in[in_p] & 0xff); 96 | valueLength <<= 8; 97 | valueLength += b; 98 | } 99 | } 100 | valueOffset = (short) (in_p + 1); 101 | return valueOffset; 102 | } 103 | 104 | public static short skipValue() { 105 | return (short) (valueOffset + valueLength); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /src/org/satochip/applet/HmacSha512.java: -------------------------------------------------------------------------------- 1 | /* 2 | * SatoChip Bitcoin Hardware Wallet based on javacard 3 | * (c) 2015 by Toporin - 16DMCk4WUaHofchAhpMaQS4UPm4urcy2dN 4 | * Sources available on https://github.com/Toporin 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | package org.satochip.applet; 22 | 23 | import javacard.framework.ISOException; 24 | import javacard.framework.JCSystem; 25 | import javacard.framework.Util; 26 | 27 | // very limited Hmac-SHA512 implementation 28 | public class HmacSha512 { 29 | 30 | public static final short BLOCKSIZE=128; // 128 bytes 31 | public static final short HASHSIZE=64; 32 | private static final short SW_UNSUPPORTED_KEYSIZE = (short) 0x9c0E; 33 | private static final short SW_UNSUPPORTED_MSGSIZE = (short) 0x9c0F; 34 | private static byte[] data; 35 | 36 | 37 | public static void init(byte[] tmp){ 38 | data= tmp; 39 | } 40 | 41 | public static short computeHmacSha512(byte[] key, short key_offset, short key_length, 42 | byte[] message, short message_offset, short message_length, 43 | byte[] mac, short mac_offset){ 44 | 45 | if (key_length>BLOCKSIZE || key_length<0){ 46 | ISOException.throwIt(SW_UNSUPPORTED_KEYSIZE); // don't accept keys bigger than block size 47 | } 48 | if (message_length>HASHSIZE || message_length<0){ 49 | ISOException.throwIt(SW_UNSUPPORTED_MSGSIZE); // don't accept messsage bigger than block size (should be sufficient for BIP32) 50 | } 51 | 52 | // compute inner hash 53 | for (short i=0; i. 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.Util; 24 | 25 | /** 26 | * Basic operations on 32 bits unsigned integers 27 | * @author BTChip 28 | * 29 | */ 30 | public class Uint32Helper { 31 | 32 | public static void clear(byte[] buffer, short offset) { 33 | Util.arrayFillNonAtomic(buffer, offset, (short)4, (byte)0x00); 34 | } 35 | 36 | public static void swap(byte[] target, short targetOffset, byte[] a, short aOffset) { 37 | GenericBEHelper.swap((byte)4, target, targetOffset, a, aOffset); 38 | } 39 | 40 | public static void setByte(byte[] buffer, short offset, byte value) { 41 | clear(buffer, offset); 42 | buffer[(short)(offset + 3)] = value; 43 | } 44 | 45 | public static void setShort(byte[] buffer, short offset, byte high, byte low) { 46 | clear(buffer, offset); 47 | buffer[(short)(offset + 2)] = high; 48 | buffer[(short)(offset + 3)] = low; 49 | } 50 | 51 | public static void setInt(byte[] buffer, short offset, byte hh, byte hl, byte lh, byte ll) { 52 | buffer[offset] = hh; 53 | buffer[(short)(offset + 1)] = hl; 54 | buffer[(short)(offset + 2)] = lh; 55 | buffer[(short)(offset + 3)] = ll; 56 | } 57 | 58 | public static boolean isZero(byte[] buffer, short offset) { 59 | return GenericBEHelper.isZero((byte)4, buffer, offset); 60 | } 61 | 62 | public static void increase(byte[] buffer, short offset) { 63 | GenericBEHelper.add((byte)4, buffer, offset, buffer, offset, ONE, (short)0); 64 | } 65 | 66 | public static void decrease(byte[] buffer, short offset) { 67 | GenericBEHelper.sub((byte)4, buffer, offset, buffer, offset, ONE, (short)0); 68 | } 69 | 70 | public static void sub(byte[] a, short aOffset, byte[] b, short bOffset) { 71 | GenericBEHelper.sub((byte)4, a, aOffset, a, aOffset, b, bOffset); 72 | } 73 | 74 | public static short getU8(byte[] buffer, short offset) { 75 | if ((buffer[offset] != 0) || (buffer[(short)(offset + 1)] != 0) || (buffer[(short)(offset + 2)] != 0)) { 76 | return (short)0xff; 77 | } 78 | return (short)(buffer[(short)(offset + 3)] & 0xff); 79 | } 80 | 81 | private static final byte ONE[] = { (byte)0, (byte)0, (byte)0, (byte)1 }; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/sos/passportapplet/JCOP41PassportCrypto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * passportapplet - A reference implementation of the MRTD standards. 3 | * 4 | * Copyright (C) 2006 SoS group, Radboud University 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * $Id: FileSystem.java 143 2006-08-03 15:52:19Z ceesb $ 21 | */ 22 | 23 | package sos.passportapplet; 24 | 25 | import javacard.framework.JCSystem; 26 | import javacard.framework.Util; 27 | import javacard.security.DESKey; 28 | import javacard.security.Signature; 29 | import javacardx.crypto.Cipher; 30 | 31 | /*** 32 | * Class that implements creation signatures of ALG_DES_MAC8_ISO9797_M2_ALG3 33 | * using ALG_DES_MAC8_ISO9797_M2. 34 | * 35 | * @author ceesb 36 | * 37 | */public class JCOP41PassportCrypto extends PassportCrypto { 38 | private Cipher macCiphECB; 39 | private byte[] tempSpace_verifyMac; 40 | 41 | JCOP41PassportCrypto(KeyStore keyStore) { 42 | super(keyStore); 43 | 44 | tempSpace_verifyMac = JCSystem.makeTransientByteArray((short)8, JCSystem.CLEAR_ON_RESET); 45 | } 46 | 47 | protected void init() { 48 | ciph = Cipher.getInstance(Cipher.ALG_DES_CBC_NOPAD, false); 49 | 50 | sig = Signature.getInstance(Signature.ALG_DES_MAC8_ISO9797_M2, 51 | false); 52 | 53 | macCiphECB = Cipher.getInstance(Cipher.ALG_DES_ECB_NOPAD, false); 54 | 55 | } 56 | 57 | public void initMac(byte mode) { 58 | DESKey k = keyStore.getMacKey(KeyStore.KEY_A); 59 | 60 | sig.init(k, Signature.MODE_SIGN); 61 | } 62 | 63 | public void createMacFinal(byte[] msg, short msg_offset, short msg_len, 64 | byte[] mac, short mac_offset) { 65 | DESKey kA = keyStore.getMacKey(KeyStore.KEY_A); 66 | DESKey kB = keyStore.getMacKey(KeyStore.KEY_B); 67 | 68 | updateMac(msg, msg_offset, msg_len); 69 | sig.sign(null, (short)0, (short)0, mac, mac_offset); 70 | 71 | macCiphECB.init(kB, Cipher.MODE_DECRYPT); 72 | macCiphECB.doFinal(mac, mac_offset, (short)8, mac, mac_offset); 73 | 74 | macCiphECB.init(kA, Cipher.MODE_ENCRYPT); 75 | macCiphECB.doFinal(mac, mac_offset, (short)8, mac, mac_offset); 76 | } 77 | 78 | 79 | public boolean verifyMacFinal(byte[] msg, short msg_offset, short msg_len, 80 | byte[] mac, short mac_offset) { 81 | 82 | createMacFinal(msg, msg_offset, msg_len, tempSpace_verifyMac, (short)0); 83 | 84 | if(Util.arrayCompare(mac, mac_offset, tempSpace_verifyMac, (short)0, (short)8) == 0) { 85 | return true; 86 | } 87 | return false; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/GenericBEHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.ISO7816; 24 | import javacard.framework.ISOException; 25 | 26 | /** 27 | * Basic operations on large unsigned integers 28 | * @author BTChip 29 | * 30 | */ 31 | public class GenericBEHelper { 32 | 33 | public static boolean isZero(byte size, byte[] buffer, short offset) { 34 | for (byte i=0; i 255); 56 | target[(short)(targetOffset + size - 1 - i)] = (byte)val; 57 | } 58 | if (carry) { 59 | ISOException.throwIt(ISO7816.SW_WRONG_DATA); 60 | } 61 | } 62 | 63 | public static void sub(byte size, byte[] target, short targetOffset, byte[] a, short aOffset, byte[] b, short bOffset) { 64 | boolean borrow = false; 65 | for (byte i=0; i currentRecordCount)) { 90 | return null; 91 | } 92 | return this.records[recordNum].data; 93 | } 94 | 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/ElementaryFileLinearFixed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief The ElementaryFileLinearFixed class. 24 | * 25 | * It stores linear fixed-size records. 26 | */ 27 | public class ElementaryFileLinearFixed extends ElementaryFileLinearVariable { 28 | private final short recordLength; 29 | 30 | /** 31 | * \brief Instantiate a new linear EF (fixed record size). No data is being added at this point. 32 | * 33 | * \param fileID The ID of the file. 34 | * 35 | * \param fileControlInformation The array of bytes containing the valid (!) File Control Information. 36 | * No Copy is made. 37 | * 38 | * \param maxRecords The maximum amount of saved records. 39 | * 40 | * \param recordLength The length of the fixed-size records. 41 | * 42 | * \attention No copy of the FCI is made. Do not pass any buffer that is altered 43 | * later (e.g. the apdu buffer). Max length 257 bytes as the length 44 | * of the FCI Tag (6F) must be a byte. 45 | * 46 | * \attention To be safe, use FileFactory.getSafeFile() to instantiate files. 47 | * 48 | * \throw IllegalArgumentException If necessary tags in the FCI are missing. 49 | */ 50 | public ElementaryFileLinearFixed(short fileID, byte[] fileControlInformation, byte maxRecords, short recordLength) { 51 | super(fileID, fileControlInformation, maxRecords); 52 | this.recordLength = recordLength; 53 | } 54 | 55 | /** 56 | * \brief Get the record length. 57 | * 58 | * \return The length of any attached record. 59 | */ 60 | public short getRecordLength() { 61 | return this.recordLength; 62 | } 63 | 64 | /** 65 | * \brief Add a record to this EF (fixed record size). 66 | * 67 | * \attention No record will be added if it is of the wrong size. 68 | * Make sure that the record to add is of the correct length (e.g. by using getRecordLength() beforehand). 69 | * 70 | * \attention Only references are being stored, no copy is made (for perfomance reasons). 71 | * 72 | * \param record The byte array containing the data to save. 73 | * 74 | * \return true If the record had been added. 75 | * false An error occurred, no record had been added. 76 | */ 77 | @Override 78 | public boolean addRecord(byte[] record) { 79 | if(records.length == currentRecordCount) { 80 | // No space left. 81 | return false; 82 | } 83 | if(record.length == recordLength) { 84 | // Create a new Record with the byte array as data and append it to the records array, increasing currentRecordCount. 85 | records[currentRecordCount++] = new Record(record); 86 | return true; 87 | } else { 88 | return false; 89 | } 90 | } 91 | 92 | } 93 | 94 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/ElementaryFileTransparent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief The ElementaryFileTransparent class. 24 | * 25 | * It stores a single byte array that is not being interpreted by the filesystem. 26 | */ 27 | public class ElementaryFileTransparent extends ElementaryFile { 28 | byte[] data; 29 | 30 | /** 31 | * \brief Instantiate a new transparent EF and store a reference to the data. 32 | * 33 | * \param fileControlInformation The array of bytes containing the valid (!) File Control Information. 34 | * No Copy is made. 35 | * 36 | * \param data The byte array to be saved. No copy is made, only a reference is stored. 37 | * 38 | * \attention No copy of the FCI is made. Do not pass any buffer that is altered 39 | * later (e.g. the apdu buffer). Max length 257 bytes as the length 40 | * of the FCI Tag (6F) must be a byte. 41 | * 42 | * \attention To be safe, use FileFactory.getSafeFile() to instantiate files. 43 | * 44 | * \throw IllegalArgumentException If necessary tags in the FCI are missing. 45 | */ 46 | public ElementaryFileTransparent(short fileID, byte[] fileControlInformation, byte[] data) { 47 | super(fileID, fileControlInformation); 48 | this.data = data; 49 | } 50 | 51 | /** 52 | * \brief Instantiate a new transparent EF and allocate a new data array of the given length. 53 | * 54 | * No actual data is being added at this point. Call getData() the get a reference and fill the array. 55 | * 56 | * \para, fileID The ID of the file. 57 | * 58 | * \param fileControlInformation The array of bytes containing the valid (!) File Control Information. 59 | * No Copy is made. 60 | * 61 | * \param dataLength The length of the data array to allocate. 62 | * 63 | * \attention No copy of the FCI is made. Do not pass any buffer that is altered 64 | * later (e.g. the apdu buffer). Max length 257 bytes as the length 65 | * of the FCI Tag (6F) must be a byte. 66 | * 67 | * \attention To be safe, use FileFactory.getSafeFile() to instantiate files. 68 | * 69 | * \throw IllegalArgumentException If necessary tags in the FCI are missing. 70 | */ 71 | public ElementaryFileTransparent(short fileID, byte[] fileControlInformation, short dataLength) { 72 | super(fileID, fileControlInformation); 73 | this.data = new byte[dataLength]; 74 | } 75 | 76 | /** 77 | * \brief Get a reference to the data of this file. 78 | * 79 | * After obtraining the reference, even write operations can directly performed i.e. 80 | * the actual data of the file can be changed using the reference. 81 | * 82 | * \return The reference to the data. 83 | */ 84 | public byte[] getData() { 85 | return data; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/ElementaryFileCyclicFixed.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | /** 23 | * \brief The ElementaryFileCyclicFixed class. 24 | * 25 | * It stores records of a fixed size and overwrites the oldest record if the maximum number of records is exceeded. 26 | */ 27 | public class ElementaryFileCyclicFixed extends ElementaryFileLinearFixed { 28 | byte currentRecordPos; 29 | 30 | /** 31 | * \brief Instantiate a new cyclic EF (fixed record size). No data is being added at this point. 32 | * 33 | * \param fileID The ID of the file. 34 | * 35 | * \param fileControlInformation The array of bytes containing the valid (!) File Control Information. 36 | * No Copy is made. 37 | * 38 | * \param maxRecords The maximum amount of saved records before overwriting happens. 39 | * 40 | * \param recordLength The length of the fixed-size records. 41 | * 42 | * \attention No copy of the FCI is made. Do not pass any buffer that is altered 43 | * later (e.g. the apdu buffer). Max length 257 bytes as the length 44 | * of the FCI Tag (6F) must be a byte. 45 | * 46 | * \attention To be safe, use IsoFilesystem.getSafeFile() to instantiate files. 47 | * 48 | * \throw IllegalArgumentException If necessary tags in the FCI are missing. 49 | */ 50 | public ElementaryFileCyclicFixed(short fileID, byte[] fileControlInformation, byte maxRecords, short recordLength) { 51 | super(fileID, fileControlInformation, maxRecords, recordLength); 52 | this.currentRecordPos = 0; 53 | } 54 | 55 | /** 56 | * \brief Add a record to this cyclic EF (fixed record size). 57 | * 58 | * \attention No record will be added if it is of the wrong size. 59 | * Make sure that the record to add is of the correct length (e.g. by using getRecordLength() beforehand). 60 | * 61 | * \attention As this file is cyclic, the oldest record might get overwritten. 62 | * 63 | * \param record The byte array containing the data to add. Must be of the right size. 64 | * 65 | * \return true If the record had been added. 66 | * false An error occurred, no record had been added. 67 | */ 68 | @Override 69 | public boolean addRecord(byte[] record) { 70 | if(record.length == super.getRecordLength()) { 71 | // Create a new record with the byte array as data and append it to the records array. 72 | records[currentRecordPos] = new Record(record); 73 | // Update the current position (cyclic/modulo operation). 74 | currentRecordPos = (byte)((currentRecordPos + (byte) 1) % (byte) records.length); 75 | // Only increase currentRecordCount if the array was not full before the operation. 76 | // (If it was full, the oldest record had been overwritten, so the amount of records did not change.) 77 | currentRecordCount = currentRecordCount == (byte) records.length ? currentRecordCount : (byte) (currentRecordCount + 1); 78 | return true; 79 | } 80 | return false; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/com/mysmartlogon/gidsApplet/ApplicationFile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GidsApplet: A Java Card implementation of the GIDS (Generic Identity 3 | * Device Specification) specification 4 | * https://msdn.microsoft.com/en-us/library/windows/hardware/dn642100%28v=vs.85%29.aspx 5 | * Copyright (C) 2016 Vincent Le Toux(vincent.letoux@mysmartlogon.com) 6 | * 7 | * It has been based on the IsoApplet 8 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 9 | * 10 | * This program is free software; you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation; either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program; if not, write to the Free Software Foundation, 22 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 | */ 24 | 25 | package com.mysmartlogon.gidsApplet; 26 | 27 | import javacard.framework.Util; 28 | 29 | /** 30 | * \brief Class used to overwrite the behavior of the select command 31 | * Indeed if the partial AID of the applet is found on a select command 32 | * when the applet is already selected, it should work 33 | * 34 | **/ 35 | public class ApplicationFile extends DedicatedFile { 36 | 37 | 38 | byte[] fileControlInformation = null; 39 | byte[] fileManagementData = null; 40 | public ApplicationFile(short fileID, byte[] fileControlParameter, byte[] fileControlInformation, byte[] fileManagementData) { 41 | super(fileID, fileControlParameter); 42 | this.fileControlInformation = fileControlInformation; 43 | this.fileManagementData = fileManagementData; 44 | } 45 | 46 | /** 47 | * \brief Check if this is the AID of the application 48 | * 49 | * \param name The array containing the name to compare with the file's name. 50 | * 51 | * \param offset The offset at where the name begins. 52 | * 53 | * \param length The length of the name. 54 | * 55 | * \return false if the DF has no name or the names do not match, 56 | * true else. 57 | */ 58 | public boolean isName(byte[] name, short offset, short length) { 59 | short namePos; 60 | short aidlen = 0; 61 | short i; 62 | // Find the position of the AID tag (4F) in the fci. 63 | try { 64 | namePos = UtilTLV.findTag(fileControlInformation, (short)2, fileControlInformation[(short)1], (byte) 0x4F); 65 | } catch (NotFoundException e) { 66 | // This DF has no name. 67 | return false; 68 | } catch (InvalidArgumentsException e) { 69 | return false; 70 | } 71 | // This ADF has a AID. 72 | try { 73 | aidlen = UtilTLV.decodeLengthField(fileControlInformation, (short)(namePos+1)); 74 | if (aidlen < length) { 75 | // aid len to check is to big to match 76 | return false; 77 | } 78 | } catch (InvalidArgumentsException e) { 79 | return false; 80 | } 81 | // Advance namePos from "tag" to value. 82 | try { 83 | namePos += 1 + UtilTLV.getEncodingLengthFieldLength(length); 84 | } catch(InvalidArgumentsException e) { 85 | return false; 86 | } 87 | // check if the name can be a part of the AID 88 | for (i = 0; i < (short)(aidlen - length +1); i++) { 89 | if ((byte)0 == Util.arrayCompare(name, offset, fileControlInformation, (short)(namePos + i), length) ) { 90 | return true; 91 | } 92 | } 93 | return false; 94 | } 95 | 96 | public byte[] getFileManagementData() { 97 | return fileManagementData; 98 | } 99 | 100 | public byte[] getFileControlInformation() { 101 | return fileControlInformation; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/BCDUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.JCSystem; 24 | 25 | /** 26 | * Convert a bitcoin amount to a displyable representation for the second factor validation 27 | * @author BTChip 28 | * 29 | */ 30 | public class BCDUtils { 31 | 32 | public static void init() { 33 | scratch = JCSystem.makeTransientShortArray((short)(8 * 8 / 3), JCSystem.CLEAR_ON_DESELECT); 34 | } 35 | 36 | private static void doubleDabble(byte[] source, short sourceOffset) { 37 | for (byte i=0; i<(short)scratch.length; i++) { 38 | scratch[i] = (short)0; 39 | } 40 | byte nscratch = (byte)(8 * 8 / 3); 41 | byte smin = (byte)(nscratch - 2); 42 | for (byte i=0; i<8; i++) { 43 | for (byte j=0; j<8; j++) { 44 | short shifted_in = (((source[(short)(sourceOffset + i)] & 0xff) & ((short)(1 << (7 - j)))) != 0) ? (short)1 : (short)0; 45 | for (byte k=smin; k= 5) ? 3 : 0); 47 | } 48 | if (scratch[smin] >= 8) { 49 | smin -= 1; 50 | } 51 | for (byte k=smin; k < (short)(nscratch - 1); k++) { 52 | scratch[k] <<= 1; 53 | scratch[k] &= 0x0f; 54 | scratch[k] |= ((scratch[(short)(k + 1)] >= 8) ? 1 : 0); 55 | } 56 | scratch[(short)(nscratch - 1)] <<= 1; 57 | scratch[(short)(nscratch - 1)] &= 0x0f; 58 | scratch[(short)(nscratch - 1)] |= (shifted_in == 1 ? 1 : 0); 59 | } 60 | } 61 | } 62 | 63 | public static short hexAmountToDisplayable(byte[] source, short sourceOffset, byte[] target, short targetOffset) { 64 | short start = targetOffset; 65 | doubleDabble(source, sourceOffset); 66 | short offset = (short)0; 67 | boolean nonZero = false; 68 | for (byte i=0; i<13; i++) { 69 | if (!nonZero && (scratch[offset] == 0)) { 70 | offset++; 71 | } 72 | else { 73 | nonZero = true; 74 | target[targetOffset++] = (byte)(scratch[offset++] + '0'); 75 | } 76 | } 77 | if (targetOffset == start) { 78 | target[targetOffset++] = '0'; 79 | } 80 | target[targetOffset++] = '.'; 81 | short workOffset = offset; 82 | for (byte i=0; i<8; i++) { 83 | boolean allZero = true; 84 | for (byte j=i; j<8; j++) { 85 | if (scratch[(short)(workOffset + j)] != 0) { 86 | allZero = false; 87 | break; 88 | } 89 | } 90 | if (allZero) { 91 | break; 92 | } 93 | target[targetOffset++] = (byte)(scratch[offset++] + '0'); 94 | } 95 | if ((short)(targetOffset - start) == 2) { 96 | targetOffset--; // only 0 97 | } 98 | return targetOffset; 99 | } 100 | 101 | private static short scratch[]; 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/WrappingKeyRepository.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | // REMOVE DEBUGGING VALUE 22 | 23 | package com.btchip.applet.poc; 24 | 25 | import javacard.framework.JCSystem; 26 | import javacard.security.DESKey; 27 | import javacard.security.Key; 28 | import javacard.security.KeyBuilder; 29 | import javacardx.crypto.Cipher; 30 | 31 | /** 32 | * Management of internal wrapping keys 33 | * @author BTChip 34 | * 35 | */ 36 | public class WrappingKeyRepository { 37 | 38 | public static class WrappingKey { 39 | 40 | protected WrappingKey(byte id, byte role, Key key) { 41 | this.id = id; 42 | this.role = role; 43 | this.key = key; 44 | if (wrappingKeyList == null) { 45 | wrappingKeyList = this; 46 | } 47 | else { 48 | wrappingKeyList.next = this; 49 | } 50 | } 51 | 52 | public boolean match(byte id, byte role) { 53 | boolean match1 = (this.id == id); 54 | boolean match2 = (this.role == role); 55 | return (match1 && match2); 56 | } 57 | 58 | public void initCipher(boolean encrypt) { 59 | Crypto.blobEncryptDecrypt.init(key, (encrypt ? Cipher.MODE_ENCRYPT : Cipher.MODE_DECRYPT), IV_ZERO, (short)0, (short)IV_ZERO.length); 60 | } 61 | 62 | public Key getKey() { 63 | return key; 64 | } 65 | 66 | public WrappingKey getNext() { 67 | return next; 68 | } 69 | 70 | private static final byte[] IV_ZERO = { 0, 0, 0, 0, 0, 0, 0, 0 }; 71 | 72 | private byte id; 73 | private byte role; 74 | private Key key; 75 | private WrappingKey next; 76 | } 77 | 78 | public static WrappingKey add(byte id, byte role, byte[] value, short valueOffset) { 79 | DESKey newKey = (DESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY, false); 80 | newKey.setKey(value, valueOffset); 81 | return new WrappingKey(id, role, newKey); 82 | } 83 | 84 | public static WrappingKey find(byte id, byte role) { 85 | WrappingKey current = wrappingKeyList; 86 | while (current != null) { 87 | if (current.match(id, role)) { 88 | return current; 89 | } 90 | current = current.getNext(); 91 | } 92 | return null; 93 | } 94 | 95 | public static final byte ROLE_PRIVATE_KEY_ENCRYPTION = (byte)0x20; 96 | public static final byte ROLE_CONTEXT_EXCHANGE_ENCRYPTION = (byte)0x21; 97 | public static final byte ROLE_AUTHORIZED_ADDRESS_ENCRYPTION = (byte)0x22; 98 | public static final byte ROLE_TRUSTED_INPUT_ENCRYPTION = (byte)0x23; 99 | public static final byte ROLE_TRANSACTION_AUTHORIZATION_SIGNATURE = (byte)0x24; 100 | public static final byte ROLE_TRUSTED_SECURE_CHANNEL = (byte)0x25; 101 | public static final byte ROLE_PRIVATE_KEY_SIGNATURE = (byte)0x26; 102 | public static final byte ROLE_MODE_SIGNATURE = (byte)0x27; 103 | public static final byte ROLE_PRIVATE_KEY_DIVERSIFICATION = (byte)0x28; 104 | 105 | private static WrappingKey wrappingKeyList = null; 106 | } 107 | -------------------------------------------------------------------------------- /src/org/isodl/applet/BERTLVScanner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DrivingLicenseApplet - A reference implementation of the ISO18013 standards. 3 | * Based on the passport applet code developed by the JMRTD team, see 4 | * http://jmrtd.org 5 | * 6 | * Copyright (C) 2006 SoS group, Radboud University 7 | * Copyright (C) 2009 Wojciech Mostowski, Radboud University 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | package org.isodl.applet; 26 | 27 | /** 28 | * A very rough, zero extra memory use, TLV array scanner. 29 | * 30 | * @author Cees-Bart Breunesse 31 | * @author Wojciech Mostowski 32 | * 33 | */ 34 | public class BERTLVScanner { 35 | 36 | /** Universal tag class. */ 37 | static final short UNIVERSAL_CLASS = 0; 38 | /** Application tag class. */ 39 | static final short APPLICATION_CLASS = 1; 40 | /** Context specific tag class. */ 41 | static final short CONTEXT_SPECIFIC_CLASS = 2; 42 | /** Private tag class. */ 43 | static final short PRIVATE_CLASS = 3; 44 | 45 | // Tag data 46 | static short tag; 47 | static short tagClass; 48 | static boolean isPrimitive; 49 | 50 | // Offset and length for the value 51 | static short valueOffset; 52 | static short valueLength; 53 | 54 | private BERTLVScanner() { } 55 | 56 | static short readTag(byte[] in, short offset) { 57 | short in_p = offset; 58 | short b = (short) (in[in_p] & 0xff); 59 | while (b == 0 || b == 0xff) { 60 | in_p++; 61 | b = in[in_p]; /* skip 00 and FF */ 62 | } 63 | switch (b & 0xC0) { 64 | case 0: 65 | tagClass = UNIVERSAL_CLASS; 66 | break; 67 | case 0x40: 68 | tagClass = APPLICATION_CLASS; 69 | break; 70 | case 0x80: 71 | tagClass = CONTEXT_SPECIFIC_CLASS; 72 | break; 73 | case 0xC0: 74 | tagClass = PRIVATE_CLASS; 75 | break; 76 | } 77 | switch (b & 0x20) { 78 | case 0: 79 | isPrimitive = true; 80 | break; 81 | case 0x20: 82 | isPrimitive = false; 83 | break; 84 | } 85 | switch (b & 0x1F) { 86 | case 0x1F: 87 | tag = b; 88 | in_p++; 89 | b = in[in_p]; 90 | while ((b & 0x80) == 0x80) { 91 | tag <<= 8; 92 | tag |= (b & 0x7F); 93 | in_p++; 94 | b = in[in_p]; 95 | } 96 | tag <<= 8; 97 | tag |= (b & 0x7F); 98 | break; 99 | default: 100 | tag = b; 101 | break; 102 | } 103 | in_p++; 104 | return in_p; 105 | } 106 | 107 | static short readLength(byte[] in, short offset) { 108 | short in_p = offset; 109 | short b = (short) (in[offset] & 0xff); 110 | if ((b & 0x80) == 0) { 111 | /* short form */ 112 | valueLength = b; 113 | } else { 114 | /* long form */ 115 | short count = (short) (b & 0x7F); 116 | valueLength = 0; 117 | for (short i = 0; i < count; i++) { 118 | in_p++; 119 | b = (short) (in[in_p] & 0xff); 120 | valueLength <<= 8; 121 | valueLength += b; 122 | } 123 | } 124 | valueOffset = (short) (in_p + 1); 125 | return valueOffset; 126 | } 127 | 128 | static short skipValue() { 129 | return (short) (valueOffset + valueLength); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/de/spline/uves/ndef/Ndef.java: -------------------------------------------------------------------------------- 1 | package de.spline.uves.ndef; 2 | 3 | import javacard.framework.*; 4 | 5 | /** Implementation of NDEF (Nfc Data Exchange Format) as JavaCard applet. This Applets allows to send 6 | * static data (set at compile time) to an NDEF enabled reader (eg. Android Smartphones). An example 7 | * application is the transmissions of links over NFC. 8 | * 9 | * @author Yves Müller 10 | * @version 0.0.1 11 | * 12 | * This code is released in 2014 under the WTFPL (Version 2) 13 | */ 14 | 15 | public class Ndef extends Applet { 16 | 17 | // constants for instructions 18 | static final byte INS_READ_BINARY = (byte) 0xB0; 19 | 20 | // mutable state of applet 21 | private State state; 22 | 23 | protected Request handlers[] = {new SelectRequest()}; 24 | 25 | protected Ndef() { 26 | register(); 27 | } 28 | 29 | /** 30 | * Installs this applet. 31 | * 32 | * @param bArray the array containing installation parameters 33 | * @param bOffset the starting offset in bArray 34 | * @param bLength the length in bytes of the parameter data in bArray 35 | */ 36 | public static void install(byte[] bArray, short bOffset, byte bLength) { 37 | new Ndef(); 38 | } 39 | 40 | // TODO: add javadoc 41 | /* protected short processReadBinary(byte[] buffer) { 42 | 43 | if (state == EF_SELECTED && ef == CAPABILITY_CONTAINER_EF) { 44 | short offset = (short)(buffer[ISO7816.OFFSET_P1] << 8 + buffer[ISO7816.OFFSET_P2]); 45 | byte offset_byte3; 46 | short le = 0; 47 | 48 | if (0x0000 <= offset && offset <= 0x7FFF) { // short offset 49 | le = buffer[ISO7816.OFFSET_CDATA]; // Todo: proper le decoding 50 | return sendCapabilityContainer(buffer, offset, le); 51 | 52 | } else if ( offset == 0x0000 && // long offsets 53 | buffer[ISO7816.OFFSET_CDATA] == 5 && 54 | buffer[ISO7816.OFFSET_CDATA + 1] == 0x54 && 55 | buffer[ISO7816.OFFSET_CDATA + 2] == 0x03){ 56 | 57 | 58 | offset = (short)( 59 | buffer[ISO7816.OFFSET_CDATA + 1] << 8 | 60 | buffer[ISO7816.OFFSET_CDATA + 2]); 61 | 62 | offset_byte3 = buffer[ISO7816.OFFSET_CDATA + 3]; 63 | 64 | le = buffer[ISO7816.OFFSET_CDATA + 5]; // Todo: proper le decoding 65 | 66 | // feature not supported yet 67 | ISOException.throwIt(ISO7816.SW_FUNC_NOT_SUPPORTED); 68 | } else { // invalid encoded offset 69 | ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); 70 | } 71 | } else { 72 | ISOException.throwIt(ISO7816.SW_FILE_INVALID); 73 | } 74 | return 0; 75 | }*/ 76 | 77 | /** 78 | * Process incoming APDU messages from the reader. 79 | * 80 | * @see APDU 81 | * @param apdu the incoming APDU 82 | * @exception ISOException with the response bytes per ISO 7816-4 83 | */ 84 | public void process(APDU apdu) { 85 | 86 | short recivedNow = apdu.setIncomingAndReceive(); 87 | byte buffer[] = apdu.getBuffer(); 88 | short responseLength = 0; 89 | 90 | Request handler = null; 91 | 92 | for (byte i = 0; i < handlers.length; i++) { 93 | if (handlers[i].isApplicable(apdu, state)) { 94 | handler = handlers[i]; 95 | } 96 | } 97 | 98 | if (handler == null) { 99 | state.application = State.IDLE; 100 | ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 101 | 102 | } else { 103 | state = handler.process(apdu, state); 104 | } 105 | } 106 | // validate class 107 | /* if (buffer[ISO7816.OFFSET_CLA] != ISO7816.CLA_ISO7816) { 108 | ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 109 | } 110 | 111 | if (handler[0].isApplicable(apdu)) { 112 | processSelect(buffer); 113 | apdu.setOutgoing(); 114 | apdu.setOutgoingLength(responseLength); 115 | } else { 116 | 117 | // dispatch by instruction 118 | switch (buffer[ISO7816.OFFSET_INS]) { 119 | 120 | case ISO7816.INS_SELECT: 121 | processSelect(buffer); 122 | 123 | apdu.setOutgoing(); 124 | apdu.setOutgoingLength(responseLength); 125 | break; 126 | 127 | case INS_READ_BINARY: 128 | responseLength = processReadBinary(buffer); 129 | 130 | apdu.setOutgoing(); 131 | apdu.setOutgoingLength(responseLength); 132 | break; 133 | 134 | case (byte)0x90: 135 | apdu.setOutgoing(); 136 | apdu.setOutgoingLength((short)3); 137 | buffer[0] = state; 138 | buffer[1] = (byte)(ef >> 8); 139 | buffer[2] = (byte)(ef); 140 | apdu.sendBytes((short)0, (short)3); 141 | break; 142 | 143 | default: // unkown instruction 144 | state = IDLE; 145 | ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 146 | } 147 | } 148 | 149 | }*/ 150 | } 151 | -------------------------------------------------------------------------------- /src/net/pwendland/javacard/pki/isoapplet/File.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package net.pwendland.javacard.pki.isoapplet; 21 | 22 | import net.pwendland.javacard.pki.isoapplet.UtilTLV; 23 | 24 | /** 25 | * \brief The File class acting as superclass for any file. 26 | */ 27 | public abstract class File { 28 | private final short fileID; 29 | private DedicatedFile parentDF; 30 | 31 | final byte[] fci; 32 | private final short aclPos; 33 | 34 | /* Access Control Operations */ 35 | public static final byte ACL_OP_DELETE_SELF = (byte) 0x01; 36 | 37 | public static final byte ACL_OP_CREATE_DF = (byte) 0x02; 38 | public static final byte ACL_OP_CREATE_EF = (byte) 0x03; 39 | public static final byte ACL_OP_DELETE_CHILD = (byte) 0x04; 40 | 41 | public static final byte ACL_OP_WRITE = (byte) 0x05; 42 | public static final byte ACL_OP_UPDATE_ERASE = (byte) 0x06; 43 | public static final byte ACL_OP_READ_SEARCH = (byte) 0x07; 44 | 45 | /** 46 | * \brief Abstract constructor to be called by subclasses. 47 | * 48 | * \param fileID The ID of the file. 49 | * 50 | * \param fileControlInformation The FCI according to ISO 7816-4 table 12. Necessary tags: 82, 83. No copy is made. 51 | */ 52 | public File(short fileID, byte[] fileControlInformation) { 53 | this.fileID = fileID; 54 | this.parentDF = null; 55 | this.fci = fileControlInformation; 56 | // Save the position of the ACL (Value field) in the FCI for performance reasons. 57 | // If the position is -1, then every action may be performed. 58 | this.aclPos = UtilTLV.findTag(fci, (short) 2, fci[(short)1], (byte) 0x86); 59 | } 60 | 61 | /** 62 | * \brief Get the relevant ACL byte for the operation. 63 | * 64 | * \param flag_operation The operation. One of ACL_OP_*. 65 | * 66 | * \return The ACL byte. 67 | */ 68 | public byte getACLRequirements(byte flag_operation) { 69 | if(aclPos == -1) { 70 | return (byte) 0x00; // Any operation is allowed if there is no ACL. 71 | } 72 | 73 | switch(flag_operation) { 74 | case ACL_OP_DELETE_SELF: 75 | return fci[(short)(aclPos+3)]; 76 | 77 | case ACL_OP_WRITE: 78 | case ACL_OP_CREATE_DF: 79 | return fci[(short)(aclPos+7)]; 80 | 81 | case ACL_OP_UPDATE_ERASE: 82 | case ACL_OP_CREATE_EF: 83 | return fci[(short)(aclPos+8)]; 84 | 85 | case ACL_OP_READ_SEARCH: 86 | case ACL_OP_DELETE_CHILD: 87 | return fci[(short)(aclPos+9)]; 88 | 89 | default: 90 | return (byte) 0xFF; // No access for unknown actions. 91 | } 92 | } 93 | 94 | /** 95 | * \brief Get the file identifier. 96 | * 97 | * \return The file ID. 98 | */ 99 | public short getFileID() { 100 | return this.fileID; 101 | } 102 | 103 | /** 104 | * \brief Get the parent Dedicated File (DF). 105 | * 106 | * \return The parent DF or null if the file had not been added yet. 107 | */ 108 | public DedicatedFile getParentDF() { 109 | return this.parentDF; 110 | } 111 | 112 | /** 113 | * \brief Set the parent Dedicated File (DF). 114 | * 115 | * \param parent the parent DF. 116 | */ 117 | public void setParentDF(DedicatedFile parent) { 118 | this.parentDF = parent; 119 | } 120 | 121 | /** 122 | * \brief Get the File Control Information (FCI). 123 | * 124 | * \return The FCI array. 125 | */ 126 | public byte[] getFileControlInformation() { 127 | return this.fci; 128 | } 129 | 130 | 131 | } 132 | -------------------------------------------------------------------------------- /src/org/isodl/applet/KeyStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DrivingLicenseApplet - A reference implementation of the ISO18013 standards. 3 | * Based on the passport applet code developed by the JMRTD team, see 4 | * http://jmrtd.org 5 | * 6 | * Copyright (C) 2006 SoS group, Radboud University 7 | * Copyright (C) 2009 Wojciech Mostowski, Radboud University 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | package org.isodl.applet; 26 | 27 | import javacard.framework.JCSystem; 28 | import javacard.security.DESKey; 29 | import javacard.security.ECPrivateKey; 30 | import javacard.security.ECPublicKey; 31 | import javacard.security.KeyBuilder; 32 | import javacard.security.RSAPrivateKey; 33 | import javacard.security.RSAPublicKey; 34 | 35 | /** 36 | * Class that implements a Very Simple key store. Keys for passive authentication (BAP), 37 | * active authentication, and Extended Access Protection are stored here. 38 | * 39 | * @author ceesb 40 | * @author Wojciech Mostowski 41 | * 42 | */ 43 | public class KeyStore { 44 | 45 | // static byte CA_EC_KEYTYPE_PRIVATE = KeyBuilder.TYPE_EC_F2M_PRIVATE; 46 | // static byte CA_EC_KEYTYPE_PUBLIC = KeyBuilder.TYPE_EC_F2M_PUBLIC; 47 | // static short CA_EC_KEYLENGTH = KeyBuilder.LENGTH_EC_F2M_163; 48 | 49 | static byte CA_EC_KEYTYPE_PRIVATE = KeyBuilder.TYPE_EC_FP_PRIVATE; 50 | static byte CA_EC_KEYTYPE_PUBLIC = KeyBuilder.TYPE_EC_FP_PUBLIC; 51 | static short CA_EC_KEYLENGTH = KeyBuilder.LENGTH_EC_FP_192; 52 | 53 | private DESKey sm_kMac, sm_kEnc; 54 | private DESKey ma_kMac, ma_kEnc; 55 | byte[] tmpKeys; 56 | RSAPrivateKey rsaPrivateKey; 57 | RSAPublicKey rsaPublicKey; 58 | ECPrivateKey ecPrivateKey; 59 | ECPublicKey ecPublicKey; 60 | 61 | KeyStore() { 62 | sm_kEnc = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 63 | KeyBuilder.LENGTH_DES3_2KEY, 64 | false); 65 | sm_kMac = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_DESELECT, 66 | KeyBuilder.LENGTH_DES3_2KEY, 67 | false); 68 | ma_kEnc = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, 69 | KeyBuilder.LENGTH_DES3_2KEY, 70 | false); 71 | ma_kMac = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, 72 | KeyBuilder.LENGTH_DES3_2KEY, 73 | false); 74 | 75 | rsaPrivateKey = (RSAPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_1024, false); 76 | rsaPublicKey = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_1024, false); 77 | ecPrivateKey = (ECPrivateKey)KeyBuilder.buildKey(CA_EC_KEYTYPE_PRIVATE, CA_EC_KEYLENGTH, false); 78 | ecPublicKey = (ECPublicKey)KeyBuilder.buildKey(CA_EC_KEYTYPE_PUBLIC, CA_EC_KEYLENGTH, false); 79 | 80 | tmpKeys = JCSystem.makeTransientByteArray((short)32, JCSystem.CLEAR_ON_DESELECT); 81 | } 82 | 83 | 84 | DESKey getMacKey() { 85 | if(LicenseApplet.hasMutuallyAuthenticated()) { 86 | return sm_kMac; 87 | } 88 | else { 89 | return ma_kMac; 90 | } 91 | } 92 | 93 | DESKey getCryptKey() { 94 | if(LicenseApplet.hasMutuallyAuthenticated()) { 95 | return sm_kEnc; 96 | } 97 | else { 98 | return ma_kEnc; 99 | } 100 | } 101 | 102 | void setMutualAuthenticationKeys(byte[] kMac, short kMac_offset, byte[] kEnc, short kEnc_offset) { 103 | ma_kEnc.setKey(kEnc, kEnc_offset); 104 | ma_kMac.setKey(kMac, kMac_offset); 105 | } 106 | 107 | void setSecureMessagingKeys(byte[] kMac, short kMac_offset, byte[] kEnc, short kEnc_offset) { 108 | sm_kEnc.setKey(kEnc, kEnc_offset); 109 | sm_kMac.setKey(kMac, kMac_offset); 110 | } 111 | } 112 | 113 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Applet Playground [![Build Status](https://travis-ci.org/martinpaljak/AppletPlayground.svg?branch=master)](https://travis-ci.org/martinpaljak/AppletPlayground) 2 | 3 | AppletPlayground is an educational repository for getting to know JavaCard development by learning from existing open source software. 4 | 5 | It includes various open source applets from the internet, bundled into ready to use package. Everything you need to edit, compile and load the applets to real JavaCard-s or test with an emulator. 6 | 7 | 8 | 9 | ## Time to experiment! 10 | ![Experiments!](http://www.freevector.com/site_media/preview_images/FreeVector-Evil-Doctor.jpg) 11 | Mad Genius Vector by Vectorya.com (CC 3.0 Attribution Non-Commercial) 12 | 13 | ## Included applets 14 | * MuscleApplet - as was found in [martinpaljak/MuscleApplet@d005f36209bdd7020bac0d783b228243126fd2f8](https://github.com/martinpaljak/MuscleApplet/commit/d005f36209bdd7020bac0d783b228243126fd2f8) (BSD) 15 | * CoolKeyApplet - [r105](http://svn.fedorahosted.org/svn/coolkey/!svn/bc/105/trunk/applet/) from http://svn.fedorahosted.org/svn/coolkey/trunk/applet (BSD/LGPL2.1) 16 | * PKIApplet - [r65](http://svn.code.sf.net/p/javacardsign/code/!svn/bc/65/pkiapplet/src/) from http://svn.code.sf.net/p/javacardsign/code/pkiapplet/src (LGPL2.1) 17 | * OpenPGPApplet - [Yubico/ykneo-openpgp@25e3f74](https://github.com/Yubico/ykneo-openpgp) (GPL2) 18 | * FluffyPGPApplet* - [FluffyKaon/OpenPGP-Card@545da17f82ff4627758674bbcbb0e602e959d9dd](https://github.com/FluffyKaon/OpenPGP-Card/commit/545da17f82ff4627758674bbcbb0e602e959d9dd) (GPL3) 19 | * YkneoOath - [Yubico/ykneo-oath](https://github.com/Yubico/ykneo-oath/) (GPL3) 20 | * PassportApplet - http://sourceforge.net/p/jmrtd/code/HEAD/tree/trunk/passportapplet/ (LGPL3) 21 | * BTChip* - [LedgerHQ/btchipJC](https://github.com/LedgerHQ/btchipJC) (AGPL3) 22 | * NDEF - [slomo/ndef-javacard](https://github.com/slomo/ndef-javacard) (DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE :)) 23 | * BeID* - [r62](https://code.google.com/p/eid-quick-key-toolset) (LGPL) 24 | * OpenEMV - [r3](svn://svn.code.sf.net/p/openemv/code/trunk) from svn://svn.code.sf.net/p/openemv/code/trunk (LGPL2) 25 | * ISOApplet - [philipWendland/IsoApplet](https://github.com/philipWendland/IsoApplet) (GPL3) 26 | * DriversLicense* [r175](svn://svn.code.sf.net/p/isodl/code/) from svn://svn.code.sf.net/p/isodl/code/ (LGPL2) 27 | * PLAID - [DHS Reference Implementation](http://www.humanservices.gov.au/corporate/publications-and-resources/plaid/reference-implementation-dhs) ([License](http://www.humanservices.gov.au/corporate/publications-and-resources/plaid/licence-terms)) 28 | * AlgTest 29 | * readertest - [r3223](https://anonscm.debian.org/viewvc/pcsclite/trunk/HandlerTest/JavaCard/src/org/debian/alioth/pcsclite/readertest/readertest.java?view=markup&pathrev=3223) 30 | * javacard-ndef - [promovicz/javacard-ndef@e3b271d](https://github.com/promovicz/javacard-ndef) (GPL) 31 | * GidsApplet [vletoux/GidsApplet@f467573](https://github.com/vletoux/GidsApplet) (GPL3) 32 | * SatoChipApplet [Toporin/SatoChipApplet@0f34d40](https://github.com/Toporin/SatoChipApplet) (AGPL3) 33 | 34 | Note: applets marked with * have obvious blocking errors (missing casts from int to short for 2.2.X target) removed from source. 35 | 36 | # FEASIBILITY NOTICE 37 | The above applets and the overall package comes "AS-IS". I make no claims about the feasibility, usability, security, correctness whatsoever of the whole package or any of the components. Use at your own risk. Everything here is only for educational purposes. 38 | 39 | ## What you need ? 40 | * Preferrably a Unix-like operating system like a recent Linux or OS X with installed JDK 1.7+ (but works also with Windows) 41 | * A working smart card reader* with a driver - preferably a [well-behaving CCID one](http://pcsclite.alioth.debian.org/ccid/section.html) 42 | * A JavaCard card* (v2.2.2 or better) 43 | * [a list of webshops and compatible JavaCards](https://github.com/martinpaljak/GlobalPlatform/wiki/TestedCards) 44 | * Eclipse - get from [eclipse.org](http://eclipse.org/downloads/) 45 | 46 | \* you can work with source code without a card and reader, but for actual testing having one is preferable. 47 | 48 | ## Included extras: 49 | * [ant-javacard](https://github.com/martinpaljak/ant-javacard) - for building CAP files (MIT) 50 | * [GlobalPlatformPro](https://github.com/martinpaljak/GlobalPlatformPro) - for loading the applets to the card (LGPL3) 51 | * JavaCard SDK 2.2.2 and 3.0.3 (Oracle-owns-you-and-your-grandma license) 52 | 53 | ## How to use 54 | * Import this project from Git (or directly into Eclipse) and execute the "toys" ANT target. 55 | * Or use command line and issue `ant` 56 | * Use the included [GlobalPlatform utility](https://github.com/martinpaljak/GlobalPlatform#usage) to load any of the generated applets (```.cap``` files) to a card 57 | 58 | ## In the pipeline: 59 | * Automatic code hardening with http://sourceforge.net/projects/cesta/ (BSD) 60 | * Automatic card simulation with [vJCRE](https://github.com/martinpaljak/vJCRE#import-projavacardvre) (MIT/GPL) 61 | * Automatic card simulation with [jcardsim](http://jcardsim.org) 62 | 63 | ## Contact 64 | * martin@martinpaljak.net 65 | * For improvements file an issue. Better yet - a pull request! 66 | -------------------------------------------------------------------------------- /src/org/isodl/applet/LicenseUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * DrivingLicenseApplet - A reference implementation of the ISO18013 standards. 3 | * Based on the passport applet code developed by the JMRTD team, see 4 | * http://jmrtd.org 5 | * 6 | * Copyright (C) 2006 SoS group, Radboud University 7 | * Copyright (C) 2009 Wojciech Mostowski, Radboud University 8 | * 9 | * This library is free software; you can redistribute it and/or 10 | * modify it under the terms of the GNU Lesser General Public 11 | * License as published by the Free Software Foundation; either 12 | * version 2.1 of the License, or (at your option) any later version. 13 | * 14 | * This library is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * Lesser General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU Lesser General Public 20 | * License along with this library; if not, write to the Free Software 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 | * 23 | */ 24 | 25 | package org.isodl.applet; 26 | 27 | import javacard.framework.ISO7816; 28 | 29 | /** 30 | * Generic helpers for the License. 31 | * 32 | * @author Cees-Bart Breunese (ceesb@cs.ru.nl) 33 | * 34 | */ 35 | public class LicenseUtil implements ISO7816 { 36 | /** 37 | * Counts the number of set bits in a byte 38 | * 39 | * @param b byte to be counted 40 | * @return 0 when number of bits in b is even 41 | */ 42 | static byte evenBits(byte b) { 43 | short count = 0; 44 | 45 | for (short i = 0; i < 8; i++) { 46 | count += (b >>> i) & 0x1; 47 | } 48 | 49 | return (byte) (count % 2); 50 | } 51 | 52 | /** 53 | * Calculates the xor of byte arrays in1 and in2 into out. 54 | * 55 | * Arrays may be the same, but regions may not overlap. 56 | * 57 | * 58 | * @param in1 input array 59 | * @param in1_o offset of input array 60 | * @param in2 input array 61 | * @param in2_o offset of inputarray 62 | * @param out output array 63 | * @param out_o offset of output array 64 | * @param len length of xor 65 | */ 66 | static void xor(byte[] in1, short in1_o, byte[] in2, 67 | short in2_o, byte[] out, short out_o, short len) { 68 | for(short s=0; s < len; s++) { 69 | out[(short)(out_o + s)] = (byte)(in1[(short)(in1_o + s)] ^ in2[(short)(in2_o + s)]); 70 | } 71 | } 72 | 73 | /** 74 | * Swaps two non-overlapping segments of the same length in the same byte array 75 | * in place. 76 | * 77 | * @param buffer a byte array 78 | * @param offset1 offset to first byte array 79 | * @param offset2 offset to the second byte array 80 | * @param len length of the segments 81 | */ 82 | static void swap(byte[] buffer, short offset1, short offset2, short len) { 83 | byte byte1, byte2; 84 | for(short i=0; i>> (short)15) & 1); 99 | } 100 | 101 | /** 102 | * Returns the smallest unsigned short argument. 103 | * 104 | * @param a a short 105 | * @param b another short 106 | * @return smallest unsigned value a or b. 107 | */ 108 | static short min(short a, short b) { 109 | if(sign(a) == sign(b)) 110 | return (a < b ? a : b); 111 | else if(sign(a) == 1) 112 | return b; 113 | else 114 | return a; 115 | } 116 | 117 | /*** 118 | * Pads an input buffer with max 8 and min 1 byte padding (0x80 followed by optional zeros) 119 | * relative to the offset and length given. Always pad with at least a 0x80 byte. 120 | * 121 | * See 6.2.3.1 in ISO7816-4 122 | * 123 | * @param buffer array to pad 124 | * @param offset to data 125 | * @param length of data 126 | * @return new length, with padding, of data 127 | * 128 | */ 129 | static short pad(byte[] buffer, short offset, short len) { 130 | short padbytes = (short)(lengthWithPadding(len) - len); 131 | 132 | for(short i=0; i=0; i--) 154 | if(apdu[(short)(offset + i)] != 0) 155 | if((apdu[(short)(offset + i)] & 0xff)!= 0x80) 156 | // not padded 157 | return (byte)(length & 0xff); 158 | else 159 | return (byte)(i & 0xff); 160 | 161 | return 0; 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/TC.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.JCSystem; 24 | import javacard.framework.Util; 25 | 26 | /** 27 | * Storage of transaction context 28 | * @author BTChip 29 | * 30 | */ 31 | public class TC { 32 | 33 | public static void init() { 34 | ctx = JCSystem.makeTransientByteArray(TX_CONTEXT_SIZE, JCSystem.CLEAR_ON_DESELECT); 35 | ctxP = new byte[P_TX_CONTEXT_SIZE]; 36 | } 37 | 38 | public static void clear() { 39 | Util.arrayFillNonAtomic(ctx, (short)0, (short)ctx.length, (byte)0x00); 40 | if (ctxP[P_TX_Z_USED] == TRUE) { 41 | ctxP[P_TX_Z_USED] = FALSE; 42 | } 43 | } 44 | 45 | protected static final byte SIZEOF_U32 = 4; 46 | protected static final byte SIZEOF_U8 = 1; 47 | protected static final byte SIZEOF_AMOUNT = 8; 48 | protected static final byte SIZEOF_NONCE = 8; 49 | protected static final byte SIZEOF_SHA256 = 32; 50 | protected static final byte SIZEOF_RIPEMD = 20; 51 | protected static final byte SIZEOF_ENCODED_PRIVATEKEY = 40; 52 | 53 | protected static final byte TRUE = (byte)0x37; 54 | protected static final byte FALSE = (byte)0xda; 55 | 56 | protected static final short TX_B_HASH_OPTION = (short)0; 57 | protected static final short TX_B_OPERATION_PARAMETER = (short)(TX_B_HASH_OPTION + SIZEOF_U8); 58 | protected static final short TX_B_TRUSTED_INPUT_PROCESSED = (short)(TX_B_OPERATION_PARAMETER + SIZEOF_U8); 59 | protected static final short TX_B_TRUSTED_INPUT_KEYSET = (short)(TX_B_TRUSTED_INPUT_PROCESSED + SIZEOF_U8); 60 | protected static final short TX_I_TRANSACTION_TARGET_INPUT = (short)(TX_B_TRUSTED_INPUT_KEYSET + SIZEOF_U8); 61 | protected static final short TX_I_REMAINING_IO = (short)(TX_I_TRANSACTION_TARGET_INPUT + SIZEOF_U32); 62 | protected static final short TX_I_CURRENT_IO = (short)(TX_I_REMAINING_IO + SIZEOF_U32); 63 | protected static final short TX_I_SCRIPT_REMAINING = (short)(TX_I_CURRENT_IO + SIZEOF_U32); 64 | protected static final short TX_B_TRANSACTION_STATE = (short)(TX_I_SCRIPT_REMAINING + SIZEOF_U32); 65 | protected static final short TX_A_TRANSACTION_AMOUNT = (short)(TX_B_TRANSACTION_STATE + SIZEOF_U8); 66 | protected static final short TX_A_AUTHORIZATION_HASH = (short)(TX_A_TRANSACTION_AMOUNT + SIZEOF_AMOUNT); 67 | protected static final short TX_Z_FIRST_SIGNED = (short)(TX_A_AUTHORIZATION_HASH + SIZEOF_SHA256); 68 | protected static final short TX_Z_HAS_CHANGE = (short)(TX_Z_FIRST_SIGNED + SIZEOF_U8); 69 | protected static final short TX_Z_IS_P2SH = (short)(TX_Z_HAS_CHANGE + SIZEOF_U8); 70 | protected static final short TX_Z_IS_RAM = (short)(TX_Z_IS_P2SH + SIZEOF_U8); 71 | protected static final short TX_A_AUTH_NONCE = (short)(TX_Z_IS_RAM + SIZEOF_U8); // must be a counter 72 | protected static final short TX_A_AUTH_OUTPUT_ADDRESS = (short)(TX_A_AUTH_NONCE + SIZEOF_NONCE); 73 | protected static final short TX_A_AUTH_OUTPUT_AMOUNT = (short)(TX_A_AUTH_OUTPUT_ADDRESS + SIZEOF_RIPEMD + 1); 74 | protected static final short TX_A_AUTH_FEE_AMOUNT = (short)(TX_A_AUTH_OUTPUT_AMOUNT + SIZEOF_AMOUNT); 75 | protected static final short TX_A_AUTH_CHANGE_AMOUNT = (short)(TX_A_AUTH_FEE_AMOUNT + SIZEOF_AMOUNT); 76 | protected static final short TX_A_AUTH_CHANGE_ADDRESS = (short)(TX_A_AUTH_CHANGE_AMOUNT + SIZEOF_AMOUNT); 77 | protected static final short TX_CONTEXT_SIZE = (short)(TX_A_AUTH_CHANGE_ADDRESS + SIZEOF_RIPEMD + 1); 78 | protected static final short TX_AUTH_CONTEXT_SIZE = (short)(TX_CONTEXT_SIZE - TX_A_AUTH_NONCE); 79 | 80 | protected static final short P_TX_Z_USED = (short)0; 81 | protected static final short P_TX_A_AUTHORIZATION_HASH = (short)(P_TX_Z_USED + SIZEOF_U8); 82 | protected static final short P_TX_B_TRANSACTION_STATE = (short)(P_TX_A_AUTHORIZATION_HASH + SIZEOF_SHA256); 83 | protected static final short P_TX_Z_FIRST_SIGNED = (short)(P_TX_B_TRANSACTION_STATE + SIZEOF_U8); 84 | protected static final short P_TX_Z_HAS_CHANGE = (short)(P_TX_Z_FIRST_SIGNED + SIZEOF_U8); 85 | protected static final short P_TX_Z_IS_P2SH = (short)(P_TX_Z_HAS_CHANGE + SIZEOF_U8); 86 | protected static final short P_TX_A_AUTH_NONCE = (short)(P_TX_Z_IS_P2SH + SIZEOF_U8); // must be a counter 87 | protected static final short P_TX_A_AUTH_OUTPUT_ADDRESS = (short)(P_TX_A_AUTH_NONCE + SIZEOF_NONCE); 88 | protected static final short P_TX_A_AUTH_OUTPUT_AMOUNT = (short)(P_TX_A_AUTH_OUTPUT_ADDRESS + SIZEOF_RIPEMD + 1); 89 | protected static final short P_TX_A_AUTH_FEE_AMOUNT = (short)(P_TX_A_AUTH_OUTPUT_AMOUNT + SIZEOF_AMOUNT); 90 | protected static final short P_TX_A_AUTH_CHANGE_AMOUNT = (short)(P_TX_A_AUTH_FEE_AMOUNT + SIZEOF_AMOUNT); 91 | protected static final short P_TX_A_AUTH_CHANGE_ADDRESS = (short)(P_TX_A_AUTH_CHANGE_AMOUNT + SIZEOF_AMOUNT); 92 | protected static final short P_TX_CONTEXT_SIZE = (short)(P_TX_A_AUTH_CHANGE_ADDRESS + SIZEOF_RIPEMD + 1); 93 | protected static final short P_TX_AUTH_CONTEXT_SIZE = (short)(P_TX_CONTEXT_SIZE - P_TX_A_AUTH_NONCE); 94 | 95 | protected static byte[] ctx; 96 | protected static byte[] ctxP; 97 | 98 | } 99 | -------------------------------------------------------------------------------- /src/com/redhat/ckey/applet/ASN1.java: -------------------------------------------------------------------------------- 1 | // SmartCard Applet 2 | // Authors: Robert Relyea 3 | // Package: CardEdgeApplet 4 | // Description: CardEdge implementation with JavaCard 5 | // 6 | // BEGIN LICENSE BLOCK 7 | // Copyright (C) 2006 Red Hat, Inc. 8 | // All rights reserved. 9 | // 10 | // Redistribution and use in source and binary forms, with or without 11 | // modification, are permitted provided that the following conditions 12 | // are met: 13 | // 14 | // 1. Redistributions of source code must retain the above copyright 15 | // notice, this list of conditions and the following disclaimer. 16 | // 2. Redistributions in binary form must reproduce the above copyright 17 | // notice, this list of conditions and the following disclaimer in the 18 | // documentation and/or other materials provided with the distribution. 19 | // 3. The name of the author may not be used to endorse or promote products 20 | // derived from this software without specific prior written permission. 21 | // 22 | // Changes to this license can be made only by the copyright author with 23 | // explicit written consent. 24 | // 25 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 26 | // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 27 | // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 28 | // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 29 | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 31 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 32 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 33 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 34 | // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | // Alternatively, the contents of this file may be used under the terms of 37 | // the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which 38 | // case the provisions of the LGPL are applicable instead of those above. If 39 | // you wish to allow use of your version of this file only under the terms 40 | // of the LGPL, and not to allow others to use your version of this file 41 | // under the terms of the BSD license, indicate your decision by deleting 42 | // the provisions above and replace them with the notice and other 43 | // provisions required by the LGPL. If you do not delete the provisions 44 | // above, a recipient may use your version of this file under the terms of 45 | // either the BSD license or the LGPL. 46 | // 47 | // You should have received a copy of the GNU Lesser General Public 48 | // License along with this library; if not, write to the Free Software 49 | // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 50 | // END LICENSE_BLOCK 51 | 52 | package com.redhat.ckey.applet; 53 | 54 | import javacard.framework.ISOException; 55 | import javacard.framework.JCSystem; 56 | import javacard.framework.Util; 57 | 58 | /** 59 | * ASN1 parser Class 60 | * 61 | *

This Simplistic ASN.1 parser does not interpret tags, it simply finds 62 | * elements based on where their fields are supposed to wind up at.

63 | * 64 | * 65 | * Object fields: 66 | *
 67 |  *    short[] newSize; // way to get around java's restrictions on pass by ref. 
 68 |  *    byte[] data
 69 |  * 
70 | * 71 | * @author Robert Relyea 72 | * @version 0.0.1 73 | * 74 | */ 75 | public class ASN1 76 | { 77 | public static final short SW_BAD_DER_DATA = (short)0x9cd0; 78 | private final short NEXT = 0; 79 | private final short SIZE = 1; 80 | private final short END = 2; 81 | private short[] params; 82 | 83 | public ASN1() 84 | { 85 | params=JCSystem.makeTransientShortArray((short)3, 86 | JCSystem.CLEAR_ON_DESELECT); 87 | } 88 | 89 | public short GetEnd() 90 | { 91 | return params[END]; 92 | } 93 | 94 | public short GetSize() 95 | { 96 | return params[SIZE]; 97 | } 98 | 99 | public short GetNext() 100 | { 101 | return params[NEXT]; 102 | } 103 | 104 | public byte GetTag(byte buf[], short offset, short end) 105 | { 106 | if (end <= offset) { 107 | ISOException.throwIt(SW_BAD_DER_DATA); 108 | } 109 | return buf[offset]; 110 | } 111 | 112 | public short Unwrap(byte buf[], short offset, short end, short dbg) 113 | { 114 | byte tag; 115 | byte len; 116 | short length = 0; 117 | 118 | if (end < (short)(offset+2)) { 119 | ISOException.throwIt(SW_BAD_DER_DATA); 120 | } 121 | tag = buf[offset++]; 122 | if (tag == 0) { 123 | ISOException.throwIt(SW_BAD_DER_DATA); 124 | } 125 | len = buf[offset++]; 126 | length = Util.makeShort((byte)0,len); 127 | 128 | if ((len & 0x80) != 0) { 129 | short count = Util.makeShort((byte)0,(byte)(len & 0x7f)); 130 | if (end < (short)(offset+count)) { 131 | ISOException.throwIt(SW_BAD_DER_DATA); 132 | } 133 | if (count > 2) { 134 | ISOException.throwIt(SW_BAD_DER_DATA); 135 | } 136 | length = 0; 137 | while (count-- > 0) { 138 | length = (short)((length << 8) 139 | | Util.makeShort((byte)0,buf[offset++])); 140 | } 141 | } 142 | params[SIZE] = length; 143 | params[NEXT] = ((short)(offset+length)); 144 | params[END] = ((short)(offset+length)); 145 | return offset; 146 | } 147 | 148 | public short Skip(byte buf[], short offset, short end, short dbg) 149 | { 150 | Unwrap(buf,offset,end,dbg); 151 | return params[NEXT]; 152 | } 153 | 154 | public short UnwrapBitString(byte buf[], short offset, short end, short dbg) 155 | { 156 | if (buf[offset] != 0) { 157 | ISOException.throwIt(SW_BAD_DER_DATA); 158 | } 159 | if (end < (short)(offset+1)) { 160 | ISOException.throwIt(SW_BAD_DER_DATA); 161 | } 162 | params[SIZE]--; 163 | return (short)(offset+1); 164 | } 165 | 166 | public short Signed2Unsigned(byte buf[], short offset, short end, short dbg) 167 | { 168 | short startOffset = offset; 169 | short startSize=params[SIZE]; 170 | for (; offset < end && buf[offset] == 0 ; offset++){ 171 | params[SIZE]--; 172 | } 173 | if (offset >= end) { 174 | ISOException.throwIt(SW_BAD_DER_DATA); 175 | } 176 | return offset; 177 | } 178 | } 179 | 180 | 181 | -------------------------------------------------------------------------------- /src/org/aispring/javacard/ndef/UtilTLV.java: -------------------------------------------------------------------------------- 1 | /* 2 | * IsoApplet: A Java Card PKI applet aimiing for ISO 7816 compliance. 3 | * Copyright (C) 2014 Philip Wendland (wendlandphilip@gmail.com) 4 | * 5 | * This program is free software; you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation; either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, write to the Free Software Foundation, 17 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | package org.aispring.javacard.ndef; 21 | 22 | import javacard.framework.Util; 23 | 24 | /** 25 | * \brief Utility class for TLV-related operations. 26 | * 27 | * This code originally comes from IsoApplet by Philip Wendland. 28 | * 29 | * It has been modified to eliminate the use of exceptions. 30 | */ 31 | public final class UtilTLV { 32 | 33 | /** \brief Find the position of the tag at level 1. 34 | * 35 | * \attention This method only searches level 1 of TLV encoded arrays (i.e. no nested TLVs are searched). 36 | * 37 | * \param tlv The array containing the TLV-encoded object to search. 38 | * 39 | * \param tlvOffset The position at which the TLV structure begins. 40 | * 41 | * \param tlvLength The length of the TLV structure. 42 | * 43 | * \param tag The tag to search for. 44 | * 45 | * \return The position of the tag. 46 | * 47 | * \throw NotFoundException If the tag could not be found. 48 | * 49 | * \throw InvalidArgumentsException Malformatted TLV data. 50 | */ 51 | public static short findTag(byte[] tlv, short tlvOffset, short tlvLength, byte tag) { 52 | short tagPos = tlvOffset; 53 | short len; 54 | 55 | while(tagPos < (short)(tlvLength+tlvOffset-1)) { 56 | if(tlv[tagPos] == tag) { 57 | return tagPos; 58 | } 59 | len = decodeLengthField(tlv, (short)(tagPos+1)); 60 | // Increase the position by: T length (1), L length, V length. 61 | // I.e. look at the next Tag, jump over current L and V field. 62 | // This saves execution time and ensures that no byte from V is misinterpreted. 63 | tagPos += 1 + getLengthFieldLength(len) + len; 64 | } 65 | return -1; 66 | } 67 | 68 | /** 69 | * \brief Check the consistency of the TLV structure. 70 | * 71 | * Basically, we jump from one tag to the next. At the end, we must be at the position 72 | * where the next tag would be, if it was there. If the position is any other than that, 73 | * the TLV structure is not consistent. 74 | * 75 | * \param tlv The array containing the TLV-encoded object to search. 76 | * 77 | * \param offset The position at which the TLV structure begins. 78 | * 79 | * \param length The length of the TLV structure. 80 | * 81 | * \return True if the TLV structure is valid, else false. 82 | */ 83 | public static boolean isTLVconsistent(byte[] tlv, short offset, short length) { 84 | short pos = offset; 85 | short len; 86 | 87 | while(pos < (short)(length+offset-1)) { 88 | len = decodeLengthField(tlv, (short)(pos+1)); 89 | if(len < -1) { 90 | return false; 91 | } 92 | pos += 1 + getLengthFieldLength(len) + len; 93 | } 94 | return (pos == (short)(offset+length)); 95 | } 96 | 97 | /** 98 | * \brief Decode the length field of a TLV-entry. 99 | * 100 | * The length field itself can be 1, 2 or 3 bytes long: 101 | * - If the length is between 0 and 127, it is 1 byte long. 102 | * - If the length is between 128 and 255, it is 2 bytes long. 103 | * The first byte is 0x81 to indicate this. 104 | * - If the length is between 256 and 65535, it is 3 bytes long. 105 | * The first byte is 0x82, the following 2 contain the actual length. 106 | * Note: Only lengths up to 0x7FFF (32767) are supported here, because a short in Java is signed. 107 | * 108 | * \param buf The buffer containing the length field. 109 | * 110 | * \param offset The offset at where the length field starts. 111 | * 112 | * \param length The length of the buffer (buf). This is to prevent that the index gets out of bounds. 113 | * 114 | * \return The (positive) length encoded by the length field, or in case of an error, -1. 115 | * 116 | * \throw InvalidArgumentsException If offset is too big for a signed Java short 117 | * If the first byte of the length field is invalid 118 | */ 119 | public static short decodeLengthField(byte[] buf, short offset) { 120 | if(buf[offset] == (byte)0x82) { // 256..65535 121 | // Check for short overflow 122 | // (In Java, a short is signed: positive values are 0000..7FFF) 123 | if(buf[(short)(offset+1)] < 0) { // 80..FF 124 | return -1; 125 | } 126 | return Util.getShort(buf, (short)(offset+1)); 127 | } else if(buf[offset] == (byte)0x81) { 128 | return (short) ( 0x00FF & buf[(short)(offset+1)]); 129 | } else if(buf[offset] > 0) { // 00..7F 130 | return (short) ( 0x007F & buf[offset]); 131 | } else { 132 | return -1; 133 | } 134 | } 135 | 136 | /** 137 | * \brief Get the length of the length field of a TLV-entry. 138 | * 139 | * \attention Not the length of the value-field is returned, 140 | * but the length of the length field itself. 141 | * 142 | * \see decodeLengthField() 143 | * 144 | * \param length The decoded length from the TLV-entry. 145 | * 146 | * \return The length of the length field. 147 | * 148 | * \throw InvalidArgumentsException If the length would overflow the signed 149 | * short of Java. 150 | */ 151 | public static short getLengthFieldLength(short length) { 152 | if(length < 0) { 153 | return -1; 154 | } else if(length < 128) { 155 | return 1; 156 | } else if(length < 256) { 157 | return 2; 158 | } else { 159 | return 3; 160 | } 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/Base58.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.Util; 24 | 25 | /** 26 | * Base 58 encoding and decoding 27 | * @author BTChip 28 | * 29 | */ 30 | public class Base58 { 31 | 32 | public static short encode(byte[] in, short inOffset, short inLength, byte[] out, short outOffset, byte[] scratch, short scratchOffset) { 33 | short zeroCount = (short)0, j, startAt; 34 | while ((zeroCount < inLength) && (in[(short)(inOffset + zeroCount)] == 0)) { 35 | ++zeroCount; 36 | } 37 | Util.arrayCopyNonAtomic(in, inOffset, scratch, scratchOffset, inLength); 38 | j = (short)(2 * inLength); 39 | startAt = zeroCount; 40 | while(startAt < inLength) { 41 | short remainder = 0; 42 | short divLoop; 43 | for (divLoop = startAt ; divLoop < inLength; divLoop++) { 44 | short digit256 = (short)(scratch[(short)(scratchOffset + divLoop)] & 0xff); 45 | short tmpDiv = (short)(remainder * 256 + digit256); 46 | scratch[(short)(scratchOffset + divLoop)] = (byte)(tmpDiv / 58); 47 | remainder = (short)(tmpDiv % 58); 48 | } 49 | if (scratch[(short)(scratchOffset + startAt)] == 0) { 50 | ++startAt; 51 | } 52 | out[(short)(outOffset + --j)] = (byte)ALPHABET[remainder]; 53 | } 54 | while ((j < ((short)(2 * inLength))) && (out[(short)(outOffset + j)] == ALPHABET[0])) { 55 | ++j; 56 | } 57 | while (--zeroCount >= 0) { 58 | out[(short)(outOffset + --j)] = (byte)ALPHABET[0]; 59 | } 60 | short resultLength = (short)((2 * inLength) - j); 61 | Util.arrayCopyNonAtomic(out, (short)(outOffset + j), out, outOffset, resultLength); 62 | return (short)(outOffset + resultLength); 63 | } 64 | 65 | public static short decode(byte[] in, short inOffset, short inLength, byte[] out, short outOffset, byte[] scratch, short scratchOffset) { 66 | try { 67 | short zeroCount = (short)0, j, startAt; 68 | for (short i=0; i 128) { 71 | return (short)-1; 72 | } 73 | byte base58Value = BASE58TABLE[value]; 74 | if (base58Value == (byte)0xff) { 75 | return (short)-1; 76 | } 77 | scratch[(short)(scratchOffset + i)] = base58Value; 78 | } 79 | while ((zeroCount < inLength) && (scratch[(short)(scratchOffset + zeroCount)] == 0)) { 80 | ++zeroCount; 81 | } 82 | j = inLength; 83 | startAt = zeroCount; 84 | while (startAt < inLength) { 85 | short remainder = 0; 86 | short divLoop; 87 | for (divLoop = startAt ; divLoop < inLength; divLoop++) { 88 | short digit256 = (short)(scratch[(short)(scratchOffset + divLoop)] & 0xff); 89 | short tmpDiv = (short)(remainder * 58 + digit256); 90 | scratch[(short)(scratchOffset + divLoop)] = (byte)(tmpDiv / 256); 91 | remainder = (short)(tmpDiv % 256); 92 | } 93 | if (scratch[(short)(scratchOffset + startAt)] == 0) { 94 | ++startAt; 95 | } 96 | out[(short)(outOffset + --j)] = (byte)remainder; 97 | } 98 | while ((j < inLength) && (out[(short)(outOffset + j)] == 0)) { 99 | j++; 100 | } 101 | short resultLength = (short)(inLength - (j - zeroCount)); 102 | Util.arrayCopyNonAtomic(out, (short)(outOffset + j - zeroCount), out, outOffset, resultLength); 103 | return resultLength; 104 | } 105 | catch(Throwable t) { 106 | return (short)-1; 107 | } 108 | } 109 | 110 | private static final byte BASE58TABLE[] = { 111 | (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 112 | (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 113 | (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0x0,(byte)0x1,(byte)0x2,(byte)0x3,(byte)0x4,(byte)0x5,(byte)0x6,(byte)0x7,(byte)0x8,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 114 | (byte)0x9,(byte)0xa,(byte)0xb,(byte)0xc,(byte)0xd,(byte)0xe,(byte)0xf,(byte)0x10,(byte)0xff,(byte)0x11,(byte)0x12,(byte)0x13,(byte)0x14,(byte)0x15,(byte)0xff,(byte)0x16,(byte)0x17,(byte)0x18,(byte)0x19,(byte)0x1a,(byte)0x1b,(byte)0x1c,(byte)0x1d, 115 | (byte)0x1e,(byte)0x1f,(byte)0x20,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0x21,(byte)0x22,(byte)0x23,(byte)0x24,(byte)0x25,(byte)0x26,(byte)0x27,(byte)0x28,(byte)0x29,(byte)0x2a,(byte)0x2b,(byte)0xff,(byte)0x2c, 116 | (byte)0x2d,(byte)0x2e,(byte)0x2f,(byte)0x30,(byte)0x31,(byte)0x32,(byte)0x33,(byte)0x34,(byte)0x35,(byte)0x36,(byte)0x37,(byte)0x38,(byte)0x39,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff 117 | }; 118 | 119 | private static final byte ALPHABET[] = { 120 | '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 121 | 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 122 | 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'm', 'n', 'o', 'p', 'q', 'r', 's', 123 | 't', 'u', 'v', 'w', 'x', 'y', 'z' 124 | }; 125 | } 126 | 127 | -------------------------------------------------------------------------------- /src/sos/passportapplet/KeyStore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * passportapplet - A reference implementation of the MRTD standards. 3 | * 4 | * Copyright (C) 2006 SoS group, Radboud University 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * $Id: FileSystem.java 143 2006-08-03 15:52:19Z ceesb $ 21 | */ 22 | package sos.passportapplet; 23 | 24 | import javacard.framework.JCSystem; 25 | import javacard.security.DESKey; 26 | import javacard.security.ECPrivateKey; 27 | import javacard.security.ECPublicKey; 28 | import javacard.security.KeyBuilder; 29 | import javacard.security.RSAPrivateKey; 30 | import javacard.security.RSAPublicKey; 31 | 32 | /** 33 | * Class that implements a Very Simple key store. 34 | * 35 | * @author ceesb 36 | * 37 | */ 38 | public class KeyStore { 39 | public static final byte KEY_A = 0; 40 | public static final byte KEY_B = 1; 41 | 42 | private DESKey sm_kMac_a, sm_kMac_b, sm_kMac; 43 | private DESKey ma_kMac_a, ma_kMac_b, ma_kMac; 44 | private DESKey ma_kEnc, sm_kEnc; 45 | private byte mode; 46 | RSAPrivateKey rsaPrivateKey; 47 | RSAPublicKey rsaPublicKey; 48 | 49 | byte[] tmpKeys; 50 | ECPrivateKey ecPrivateKey; 51 | ECPublicKey ecPublicKey; 52 | 53 | KeyStore(byte mode) { 54 | this.mode = mode; 55 | sm_kEnc = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_RESET, 56 | KeyBuilder.LENGTH_DES3_2KEY, 57 | false); 58 | ma_kEnc = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, 59 | KeyBuilder.LENGTH_DES3_2KEY, 60 | false); 61 | 62 | switch(mode) { 63 | case PassportCrypto.JCOP41_MODE: 64 | case PassportCrypto.PERFECTWORLD_MODE: 65 | rsaPrivateKey = (RSAPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_1024, false); 66 | rsaPublicKey = (RSAPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_1024, false); 67 | ecPrivateKey = (ECPrivateKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_F2M_PRIVATE, KeyBuilder.LENGTH_EC_F2M_163, false); 68 | ecPublicKey = (ECPublicKey)KeyBuilder.buildKey(KeyBuilder.TYPE_EC_F2M_PUBLIC, KeyBuilder.LENGTH_EC_F2M_163, false); 69 | break; 70 | } 71 | 72 | switch(mode) { 73 | case PassportCrypto.PERFECTWORLD_MODE: 74 | sm_kMac = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_RESET, 75 | KeyBuilder.LENGTH_DES3_2KEY, 76 | false); 77 | ma_kMac = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, 78 | KeyBuilder.LENGTH_DES3_2KEY, 79 | false); 80 | break; 81 | case PassportCrypto.CREF_MODE: 82 | case PassportCrypto.JCOP41_MODE: 83 | sm_kMac_a = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_RESET, 84 | KeyBuilder.LENGTH_DES, 85 | false); 86 | sm_kMac_b = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES_TRANSIENT_RESET, 87 | KeyBuilder.LENGTH_DES, 88 | false); 89 | ma_kMac_a = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, 90 | KeyBuilder.LENGTH_DES, 91 | false); 92 | ma_kMac_b = (DESKey) KeyBuilder.buildKey(KeyBuilder.TYPE_DES, 93 | KeyBuilder.LENGTH_DES, 94 | false); 95 | break; 96 | } 97 | tmpKeys = JCSystem.makeTransientByteArray((short)32, JCSystem.CLEAR_ON_DESELECT); 98 | } 99 | 100 | 101 | public DESKey getMacKey() { 102 | if(PassportApplet.hasMutuallyAuthenticated()) { 103 | return sm_kMac; 104 | } 105 | else { 106 | return ma_kMac; 107 | } 108 | } 109 | 110 | public DESKey getMacKey(byte aOrb) { 111 | if(PassportApplet.hasMutuallyAuthenticated()) { 112 | if(aOrb == KEY_A) { 113 | return sm_kMac_a; 114 | } 115 | else { 116 | return sm_kMac_b; 117 | } 118 | } 119 | else { 120 | if(aOrb == KEY_A) { 121 | return ma_kMac_a; 122 | } 123 | else { 124 | return ma_kMac_b; 125 | } 126 | } 127 | } 128 | 129 | public DESKey getCryptKey() { 130 | if(PassportApplet.hasMutuallyAuthenticated()) { 131 | return sm_kEnc; 132 | } 133 | else { 134 | return ma_kEnc; 135 | } 136 | } 137 | 138 | public void setMutualAuthenticationKeys(byte[] kMac, short kMac_offset, byte[] kEnc, short kEnc_offset) { 139 | ma_kEnc.setKey(kEnc, kEnc_offset); 140 | switch(mode) { 141 | case PassportCrypto.PERFECTWORLD_MODE: 142 | ma_kMac.setKey(kMac, kMac_offset); 143 | break; 144 | case PassportCrypto.CREF_MODE: 145 | case PassportCrypto.JCOP41_MODE: 146 | ma_kMac_a.setKey(kMac, kMac_offset); 147 | ma_kMac_b.setKey(kMac, (short)(kMac_offset + 8)); 148 | break; 149 | } 150 | } 151 | 152 | public void setSecureMessagingKeys(byte[] kMac, short kMac_offset, byte[] kEnc, short kEnc_offset) { 153 | sm_kEnc.setKey(kEnc, kEnc_offset); 154 | switch(mode) { 155 | case PassportCrypto.PERFECTWORLD_MODE: 156 | sm_kMac.setKey(kMac, kMac_offset); 157 | break; 158 | case PassportCrypto.CREF_MODE: 159 | case PassportCrypto.JCOP41_MODE: 160 | sm_kMac_a.setKey(kMac, kMac_offset); 161 | sm_kMac_b.setKey(kMac, (short)(kMac_offset + 8)); 162 | break; 163 | } 164 | } 165 | } 166 | 167 | -------------------------------------------------------------------------------- /src/com/btchip/applet/poc/BTChipNFCForumApplet.java: -------------------------------------------------------------------------------- 1 | /* 2 | ******************************************************************************* 3 | * BTChip Bitcoin Hardware Wallet Java Card implementation 4 | * (c) 2013 BTChip - 1BTChip7VfTnrPra5jqci7ejnMguuHogTn 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU Affero General Public License as 8 | * published by the Free Software Foundation, either version 3 of the 9 | * License, or (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU Affero General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Affero General Public License 17 | * along with this program. If not, see . 18 | ******************************************************************************* 19 | */ 20 | 21 | package com.btchip.applet.poc; 22 | 23 | import javacard.framework.APDU; 24 | import javacard.framework.Applet; 25 | import javacard.framework.ISO7816; 26 | import javacard.framework.ISOException; 27 | import javacard.framework.JCSystem; 28 | import javacard.framework.Util; 29 | 30 | /** 31 | * Applet simulating an NFC Forum Type 4 tag for the second factor validation 32 | * @author BTChip 33 | * 34 | */ 35 | public class BTChipNFCForumApplet extends Applet { 36 | 37 | public BTChipNFCForumApplet() { 38 | scratch = JCSystem.makeTransientByteArray((short)1, JCSystem.CLEAR_ON_DESELECT); 39 | FILE_DATA = new byte[500]; 40 | // Header initialization 41 | short offset = 0; 42 | offset += (short)2; 43 | FILE_DATA[offset++] = (byte)0xC1; // beginning of well known record, short record bit not set 44 | FILE_DATA[offset++] = (byte)0x01; 45 | FILE_DATA[offset++] = (byte)0x00; // start of 4 bytes length 46 | FILE_DATA[offset++] = (byte)0x00; 47 | offset += (short)2; 48 | Util.arrayCopyNonAtomic(LANG, (short)0, FILE_DATA, offset, (short)LANG.length); 49 | BTChipPocApplet.writeIdleText(); 50 | } 51 | 52 | public static void writeHeader(short textSize) { 53 | short offset = (short)0; 54 | Util.setShort(FILE_DATA, offset, (short)(textSize + 1 + 5 + 4 + 2 + 1)); // prefix with size of full record 55 | offset += (short)(2 + 4); 56 | Util.setShort(FILE_DATA, offset, (short)(textSize + 1 + 5)); // size of text record payload 57 | } 58 | 59 | @Override 60 | public boolean select() { // only grant access on the contactless interface 61 | return (BTChipPocApplet.isContactless()); 62 | } 63 | 64 | @Override 65 | public void process(APDU apdu) throws ISOException { 66 | if (selectingApplet()) { 67 | return; 68 | } 69 | byte[] buffer = apdu.getBuffer(); 70 | if (buffer[ISO7816.OFFSET_CLA] != NFCFORUM_CLA) { 71 | ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); 72 | } 73 | switch(buffer[ISO7816.OFFSET_INS]) { 74 | case INS_SELECT: { 75 | apdu.setIncomingAndReceive(); 76 | short selectedFile = Util.getShort(buffer, ISO7816.OFFSET_CDATA); 77 | switch(selectedFile) { 78 | case EF_CONTAINER: 79 | scratch[OFFSET_SELECTED_FILE] = SELECTED_FILE_CONTAINER; 80 | break; 81 | case EF_NDEF: 82 | scratch[OFFSET_SELECTED_FILE] = SELECTED_FILE_NDEF; 83 | break; 84 | default: 85 | ISOException.throwIt(ISO7816.SW_FILE_NOT_FOUND); 86 | } 87 | } 88 | break; 89 | 90 | case INS_READ: { 91 | short offset = Util.makeShort(buffer[ISO7816.OFFSET_P1], buffer[ISO7816.OFFSET_P2]); 92 | if (scratch[OFFSET_SELECTED_FILE] == SELECTED_FILE_NONE) { 93 | ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED); 94 | } 95 | byte[] fileData = null; 96 | switch(scratch[OFFSET_SELECTED_FILE]) { 97 | case SELECTED_FILE_CONTAINER: 98 | fileData = CONTAINER_DATA; 99 | break; 100 | case SELECTED_FILE_NDEF: 101 | fileData = FILE_DATA; 102 | break; 103 | } 104 | if (offset >= (short)fileData.length) { 105 | ISOException.throwIt(ISO7816.SW_INCORRECT_P1P2); 106 | } 107 | short sizeRead = (short)(buffer[ISO7816.OFFSET_LC] & 0xff); 108 | short blockLength = (((short)(offset + sizeRead) > (short)fileData.length) ? (short)(fileData.length - offset) : sizeRead); 109 | Util.arrayCopyNonAtomic(fileData, offset, buffer, (short)0, blockLength); 110 | apdu.setOutgoingAndSend((short)0, blockLength); 111 | } 112 | break; 113 | 114 | } 115 | } 116 | 117 | public static void install (byte bArray[], short bOffset, byte bLength) throws ISOException { 118 | new BTChipNFCForumApplet().register(bArray, (short)(bOffset + 1), bArray[bOffset]); 119 | } 120 | 121 | public static final byte OFFSET_TEXT = (byte)15; 122 | 123 | private static final byte NFCFORUM_CLA = (byte)0x00; 124 | private static final byte INS_SELECT = (byte)0xA4; 125 | private static final byte INS_READ = (byte)0xB0; 126 | 127 | private static final short EF_CONTAINER = (short)0xE103; 128 | private static final short EF_NDEF = (short)0xE104; 129 | 130 | private static final byte SELECTED_FILE_NONE = (byte)0x00; 131 | private static final byte SELECTED_FILE_CONTAINER = (byte)0x01; 132 | private static final byte SELECTED_FILE_NDEF = (byte)0x02; 133 | 134 | private static final byte OFFSET_SELECTED_FILE = (byte)0x00; 135 | 136 | private static final byte CONTAINER_DATA[] = { 137 | (byte)0x00, (byte)0x0F, // length 138 | (byte)0x20, // mapping version 2.0 139 | (byte)0x00, (byte)0xFF, // max R-APDU data size 140 | (byte)0x00, (byte)0xFF, // max C-APDU data size 141 | (byte)0x04, (byte)0x06, // NDEF File Control TL 142 | (byte)0xE1, (byte)0x04, // EF_NDEF 143 | (byte)0x01, (byte)0xF4, // Max NDEF size (update with FILE_DATA size) 144 | (byte)0x00, // Read always 145 | (byte)0xFF // Write never 146 | }; 147 | 148 | private static final byte LANG[] = { 149 | (byte)'T', (byte)0x05, (byte)'e', (byte)'n', (byte)'-', (byte)'U', (byte)'S' // en-US text record 150 | }; 151 | 152 | public static byte FILE_DATA[]; 153 | 154 | private static byte scratch[]; 155 | 156 | } 157 | -------------------------------------------------------------------------------- /src/sos/passportapplet/CREFPassportCrypto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * passportapplet - A reference implementation of the MRTD standards. 3 | * 4 | * Copyright (C) 2006 SoS group, Radboud University 5 | * 6 | * This library is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU Lesser General Public 8 | * License as published by the Free Software Foundation; either 9 | * version 2.1 of the License, or (at your option) any later version. 10 | * 11 | * This library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this library; if not, write to the Free Software 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 | * 20 | * $Id: CREFPassportCrypto.java 945 2009-05-12 08:31:57Z woj76 $ 21 | */ 22 | 23 | package sos.passportapplet; 24 | 25 | import javacard.framework.ISO7816; 26 | import javacard.framework.ISOException; 27 | import javacard.framework.JCSystem; 28 | import javacard.framework.Util; 29 | import javacard.security.CryptoException; 30 | import javacard.security.DESKey; 31 | import javacard.security.Signature; 32 | import javacardx.crypto.Cipher; 33 | 34 | /** 35 | * This class is a hack. It (probably) implements 36 | * => encrypt/decrypt of ALG_DES_CBC_NOPAD using ALG_DES_CBC_ISO9797_M2 37 | 38 | * This is because ALG_DES_CBC_NOPAD and ALG_DES_MAC8_ISO9797_1_M2_ALG3 do not 39 | * exist on CREF. 40 | * 41 | * @author Cees-Bart Breunesse 42 | * @author Ronny Wichers Schreur 43 | * 44 | * @version $Revision: 945 $ 45 | */ 46 | public class CREFPassportCrypto extends JCOP41PassportCrypto implements ISO7816 { 47 | private byte padding; 48 | 49 | protected void init() { 50 | ciph = Cipher.getInstance(Cipher.ALG_DES_CBC_ISO9797_M2, false); 51 | 52 | sig = Signature.getInstance(Signature.ALG_DES_MAC8_ISO9797_M2, 53 | false); 54 | } 55 | 56 | CREFPassportCrypto(KeyStore keyStore) { 57 | super(keyStore); 58 | 59 | tempSpace_decryptDES = JCSystem.makeTransientByteArray((short) 16, 60 | JCSystem.CLEAR_ON_RESET); 61 | tempSpace_doMacFinal = JCSystem.makeTransientByteArray((short) 24, 62 | JCSystem.CLEAR_ON_RESET); 63 | } 64 | 65 | private short decryptDESusingDESCBCM2(DESKey key, byte[] in, 66 | short in_offset, byte[] out, short out_offset, short length) { 67 | if ((ciph.getAlgorithm() != Cipher.ALG_DES_CBC_ISO9797_M2) 68 | || ((short) (length + out_offset + 16) > (short) (out.length)) 69 | || ((short) (length + in_offset) > (short) in.length)) 70 | ISOException.throwIt((short) 0x6d69); 71 | 72 | ciph.init(key, Cipher.MODE_ENCRYPT); 73 | ciph.doFinal(ZERO, 74 | (short) 0, 75 | (short) 8, 76 | tempSpace_decryptDES, 77 | (short) 0); 78 | 79 | ciph.init(key, Cipher.MODE_DECRYPT); 80 | short written = ciph.update(in, in_offset, length, out, out_offset); 81 | written += ciph.doFinal(tempSpace_decryptDES, 82 | (short) 0, 83 | (short) (16), 84 | out, 85 | (short) (out_offset + written)); 86 | 87 | return (short)(written - 8); // FIXME: hack, compensate for padding 88 | } 89 | 90 | private static byte[] tempSpace_decryptDES; 91 | private static final byte[] ZERO = { 0, 0, 0, 0, 0, 0, 0, 0 }; 92 | private DESKey k; 93 | private byte[] tempSpace_doMacFinal; 94 | 95 | private void decryptInit(DESKey k) { 96 | this.k = k; 97 | } 98 | 99 | private void encryptInit(DESKey k) { 100 | this.k = k; 101 | } 102 | 103 | public void decryptInit() { 104 | k=keyStore.getCryptKey(); 105 | } 106 | 107 | public short decrypt(byte[] ctext, short ctext_offset, short ctext_len, 108 | byte[] ptext, short ptext_offset) { 109 | CryptoException.throwIt((short)0x6d66); 110 | return 0; 111 | } 112 | 113 | public short encrypt(byte[] ctext, short ctext_offset, short ctext_len, 114 | byte[] ptext, short ptext_offset) { 115 | CryptoException.throwIt((short)0x6d66); 116 | return 0; 117 | } 118 | 119 | public short decryptFinal(byte[] ctext, short ctext_offset, short ctext_len, 120 | byte[] ptext, short ptext_offset) { 121 | return decryptDESusingDESCBCM2(k, ctext, ctext_offset, ptext, ptext_offset, ctext_len); 122 | } 123 | 124 | public short encryptInit(byte padding, byte[] plainText, short plaintextOffset, short plaintextLength) { 125 | return encryptInit(keyStore.getCryptKey(), padding, plainText, plaintextOffset, plaintextLength); 126 | 127 | } 128 | 129 | private short encryptInit(DESKey k, byte padding, byte[] plainText, short plaintextOffset, short plaintextLength) { 130 | this.k = k; 131 | this.padding = padding; 132 | return plaintextLength; 133 | } 134 | 135 | public short encryptFinal(byte[] ptext, short ptext_offset, short ptext_len, 136 | byte[] ctext, short ctext_offset) { 137 | 138 | ciph.init(k, Cipher.MODE_ENCRYPT); 139 | short len = ciph.doFinal(ptext, ptext_offset, ptext_len, ctext, ctext_offset); 140 | 141 | if(padding == PAD_INPUT) { 142 | // ALG_DES_CBC_ISO9797_M2 does padding 143 | return len; 144 | } 145 | else if (padding == DONT_PAD_INPUT) { 146 | return (short)(len - 8); // FIXME: hack 147 | } 148 | return 0; 149 | } 150 | 151 | public void createMacFinal(byte[] msg, short msg_offset, short msg_len, 152 | byte[] mac, short mac_offset) { 153 | DESKey kA = keyStore.getMacKey(KeyStore.KEY_A); 154 | DESKey kB = keyStore.getMacKey(KeyStore.KEY_B); 155 | 156 | // updateMac(msg, msg_offset, msg_len); 157 | sig.sign(msg, msg_offset, msg_len, mac, mac_offset); 158 | 159 | decryptInit(kB); 160 | short tempmac_offset = 0; 161 | //macCiphECB.init(kB, Cipher.MODE_DECRYPT); 162 | decryptFinal(mac, mac_offset, (short)8, tempSpace_doMacFinal, tempmac_offset ); 163 | //macCiphECB.doFinal(mac, mac_offset, (short)8, mac, mac_offset); 164 | 165 | encryptInit(kA); 166 | //macCiphECB.init(kA, Cipher.MODE_ENCRYPT); 167 | encryptFinal(tempSpace_doMacFinal, tempmac_offset, (short)8, tempSpace_doMacFinal, tempmac_offset); 168 | //macCiphECB.doFinal(mac, mac_offset, (short)8, mac, mac_offset); 169 | 170 | Util.arrayCopyNonAtomic(tempSpace_doMacFinal, tempmac_offset, mac, mac_offset, (short)8); 171 | } 172 | 173 | } 174 | -------------------------------------------------------------------------------- /src/openemv/EMVStaticData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2011 Digital Security group, Radboud University 3 | * 4 | * This library is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU Lesser General Public 6 | * License as published by the Free Software Foundation; either 7 | * version 2.1 of the License, or (at your option) any later version. 8 | * 9 | * This library is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 | * Lesser General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU Lesser General Public 15 | * License along with this library; if not, write to the Free Software 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | package openemv; 20 | 21 | import javacard.framework.ISOException; 22 | import javacard.framework.Util; 23 | 24 | /* Class to record all the static data of an EMV applet, ie. the card details that 25 | * do not change over time (such as PAN, expiry date, etc.), with the exception 26 | * of the cryptographic keys. 27 | * 28 | * This static data is organised in the simplest possible way, using some public byte 29 | * arrays to record exact APDUs that the card has to produce. 30 | * 31 | * This class does not offer personalisation support - everything is hard-coded. 32 | * 33 | * @author joeri (joeri@cs.ru.nl) 34 | * @author erikpoll (erikpoll@cs.ru.nl) 35 | * 36 | */ 37 | 38 | public class EMVStaticData implements EMVConstants { 39 | 40 | private final byte[] theAFL = new byte[]{ (byte)0x08, 0x01, 0x03, 0x01}; // AFL from Dutch bank cards; 41 | 42 | /** Returns the 4 byte AFL (Application File Locator) */ 43 | public byte[] getAFL(){ 44 | return theAFL; 45 | } 46 | 47 | /** Returns the 2 byte AIP (Application Interchange Profile) 48 | * See Book 3, Annex C1 for details 49 | * */ 50 | public short getAIP() { 51 | return 0x5800; 52 | // 4000 SDA supported 53 | // 1000 Cardholder verification supported 54 | // 0800 Terminal risk management is to be performed 55 | } 56 | 57 | private final byte[] fci = new byte[]{ 58 | 0x6F, // FCI Template 59 | 0x25, // Length 60 | (byte)0x84, 0x07, (byte)0xA0, 0x00, 0x00, 0x00, 0x04, (byte)0x80, 0x02, // Dedicated File name 61 | (byte)0xA5, 0x1A, // File Control Information Proprietary Template 62 | 0x50, 0x0E, 0x53, 0x65, 0x63, 0x75, 0x72, 0x65, 0x43, 0x6F, 0x64, 0x65, 0x20, 0x41, 0x75, 0x74, // Application Label 63 | (byte)0x87, 0x01, 0x00, // Application Priority Indicator 64 | 0x5F, 0x2D, 0x04, 0x6E, 0x6C, 0x65, 0x6E // Language Preference 65 | }; 66 | 67 | // File for EMV-CAP 68 | private final byte[] record1 = new byte[]{ 69 | 0x70, // Read record message template 70 | 0x00, // Record length 71 | (byte)0x8C, 0x21, (byte)0x9F, 0x02, 0x06, (byte)0x9F, 0x03, 0x06, (byte)0x9F, 0x1A, 0x02, (byte)0x95, 0x05, 0x5F, 0x2A, 0x02, (byte)0x9A, 0x03, (byte)0x9C, 0x01, (byte)0x9F, 0x37, 0x04, (byte)0x9F, 0x35, 0x01, (byte)0x9F, 0x45, 0x02, (byte)0x9F, 0x4C, 0x08, (byte)0x9F, 0x34, 0x03, // Card Risk Management Data Object List 1 72 | (byte)0x8D, 0x0C, (byte)0x91, 0x0A, (byte)0x8A, 0x02, (byte)0x95, 0x05, (byte)0x9F, 0x37, 0x04, (byte)0x9F, 0x4C, 0x08, // Card Risk Management Data Object List 2 73 | 0x5A, 0x05, 0x12, 0x34, 0x56, 0x78, (byte)0x90, // 5A Primary account number 74 | 0x5F, 0x34, 0x01, 0x02, // Bank identifier code 75 | (byte)0x8E, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, // Cardholder Verification Method (CVM) List (Always transaction_data PIN performed by ICC) 76 | (byte)0x9F, 0x55, 0x01, (byte)0x80, // Unknown field 77 | (byte)0x9F, 0x56, 0x0C, 0x00, 0x00, 0x7F, (byte)0xFF, (byte)0xFF, (byte)0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Bit filter 78 | }; 79 | 80 | /* 81 | // File for EMV 82 | private final byte[] record1 = new byte[]{ 83 | 0x70, // Read record message template 84 | 0x00, // Record length 85 | // Mandatory data objects 86 | 0x5F, 0x24, 0x03, // Application Expiry Date 87 | 0x5A, 0x05, 0x12, 0x34, 0x56, 0x78, (byte)0x90, // 5A Primary account number 88 | (byte)0x8C, 0x21, (byte)0x9F, 0x02, 0x06, (byte)0x9F, 0x03, 0x06, (byte)0x9F, 0x1A, 0x02, (byte)0x95, 0x05, 0x5F, 0x2A, 0x02, (byte)0x9A, 0x03, (byte)0x9C, 0x01, (byte)0x9F, 0x37, 0x04, (byte)0x9F, 0x35, 0x01, (byte)0x9F, 0x45, 0x02, (byte)0x9F, 0x4C, 0x08, (byte)0x9F, 0x34, 0x03, // Card Risk Management Data Object List 1 89 | (byte)0x8D, 0x18, (byte)0x91, 0x0A, (byte)0x8A, 0x02, (byte)0x95, 0x05, (byte)0x9F, 0x37, 0x04, (byte)0x9F, 0x4C, 0x08, // Card Risk Management Data Object List 2 90 | // Other data 91 | (byte)0x8E, 0x02, 0x01, 0x00, // Cardholder Verification Method (CVM) List (Always transaction_data PIN performed by ICC) 92 | (byte)0x9F, 0x4A, 0x01, (byte)0x82, // Static Data Authentication Tag List 93 | }; 94 | */ 95 | 96 | private final byte[] record2 = new byte[]{ 97 | 0x70, // Read record message template 98 | 0x00, // Record length 99 | // Data required for DDA/CDA 100 | (byte)0x8F, 0x00, // Certification Authority Public Key Index 101 | (byte)0x90, 0x00, // Issuer Public Key Certificate 102 | (byte)0x92, 0x00, // Issuer Public Key Remainder 103 | (byte)0x9F, 0x32, 0x00, // Issuer Public Key Exponent 104 | }; 105 | 106 | private final byte[] record3 = new byte[]{ 107 | 0x70, // Read record message template 108 | 0x00, // Record length 109 | // Data required for DDA/CDA (continued) 110 | (byte)0x9F, 0x46, 0x00, // ICC Public Key Certificate 111 | (byte)0x9F, 0x47, 0x00, // ICC Public Key Exponent 112 | (byte)0x9F, 0x48, 0x00, // ICC Public Key Remainder 113 | (byte)0x9F, 0x49, 0x03, (byte)0x9F, 0x37, 0x04, // Dynamic Data Authentication Data Object List (DDOL) 114 | }; 115 | 116 | /** Return the length of the data specified in the CDOL1 117 | * 118 | */ 119 | public short getCDOL1DataLength() { 120 | return 0x2B; 121 | //return 43; 122 | } 123 | 124 | /** Return the length of the data specified in the CDOL2 125 | * 126 | */ 127 | public short getCDOL2DataLength() { 128 | return 0x1D; 129 | //return 29; 130 | } 131 | 132 | public byte[] getFCI() { 133 | return fci; 134 | } 135 | 136 | public short getFCILength() { 137 | return (short)fci.length; 138 | } 139 | 140 | /** Provide the response to INS_READ_RECORD in the response buffer 141 | * 142 | */ 143 | public void readRecord(byte[] apduBuffer, byte[] response){ 144 | if(apduBuffer[OFFSET_P2] == 0x0C && apduBuffer[OFFSET_P1] == 0x01) { // SFI 1, Record 1 145 | Util.arrayCopyNonAtomic(record1, (short)0, 146 | response, (short)0, (short)record1.length); 147 | response[1] = (byte)(record1.length - 2); 148 | } 149 | else if(apduBuffer[OFFSET_P2] == 0x0C && apduBuffer[OFFSET_P1] == 0x02) { // SFI 1, Record 2 150 | Util.arrayCopyNonAtomic(record2, (short)0, 151 | response, (short)0, (short)record2.length); 152 | response[1] = (byte)(record2.length - 2); 153 | } 154 | else if(apduBuffer[OFFSET_P2] == 0x0C && apduBuffer[OFFSET_P1] == 0x03) { // SFI 1, Record 3 155 | Util.arrayCopyNonAtomic(record3, (short)0, 156 | response, (short)0, (short)record3.length); 157 | response[1] = (byte)(record3.length - 2); 158 | } 159 | else { 160 | // File does not exist 161 | ISOException.throwIt(SW_FILE_NOT_FOUND); 162 | } 163 | } 164 | 165 | 166 | } 167 | --------------------------------------------------------------------------------