diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6d9ff20d --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +/target/ +# IDEA +.idea/ +/*.iml +# Netbeans +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +nbactions.xml +nb-configuration.xml +# Eclipse +.metadata +.settings/ diff --git a/README.md b/README.md new file mode 100644 index 00000000..4232215f --- /dev/null +++ b/README.md @@ -0,0 +1,94 @@ +jCardSim (Official repo of the [jCardSim](http://jcardsim.org) project) +======== + +### Congratulations! jCardSim has won [Duke's Choice 2013 Award](https://www.java.net//dukeschoice)! + +![alt text](https://licel.ru/wp-content/uploads/DCA2013_Badge_Winner.jpg "jCardSim is a winner of Duke's Choice 2013") + +**Please note** that we moved our code repository from Google Code to GitHub. + +jCardSim is an open source simulator for Java Card, v.2.2.1/2: + +* `javacard.framework.*` +* `javacard.framework.security.*` +* `javacardx.crypto.*` + +Key Features: + +* Rapid application prototyping +* Simplifies unit testing (5 lines of code) + +```java +// 1. create simulator +CardSimulator simulator = new CardSimulator(); + +// 2. install applet +AID appletAID = AIDUtil.create("F000000001"); +simulator.installApplet(appletAID, HelloWorldApplet.class); + +// 3. select applet +simulator.selectApplet(appletAID); + +// 4. send APDU +CommandAPDU commandAPDU = new CommandAPDU(0x00, 0x01, 0x00, 0x00); +ResponseAPDU response = simulator.transmitCommand(commandAPDU); + +// 5. check response +assertEquals(0x9000, response.getSW()); +``` + +* Emulation of Java Card Terminal, ability to use `javax.smartcardio` +* APDU scripting (scripts are compatible with `apdutool` from Java Card Development Kit) +* Simplifies verification tests creation (Common Criteria) + +*JavaDoc*: https://jcardsim.googlecode.com/svn/trunk/javadoc/index.html + +*Latest stable release 2.2.1*: https://github.com/licel/jcardsim/raw/master/jcardsim-2.2.1-all.jar + +*Latest stable release 2.2.2*: https://github.com/licel/jcardsim/raw/master/jcardsim-2.2.2-all.jar + +*Maven Central Repository* +```xml + + com.licel + jcardsim + 2.2.1 + +``` +```xml + + com.licel + jcardsim + 2.2.2 + +``` + +### What is the difference from Oracle Java Card Development Kit simulator? + +* **Implementation of javacard.security.*** + +One of the main differences is the implementation of `javacard.security.*`: the current version is analogous to an NXP JCOP 31/36k card. For example, in jCardSim we have support for on-card `KeyPair.ALG_EC_F2M/ALG_RSA_CRT` key generation. Oracle's simulator only supports `KeyPair.ALG_RSA` and `KeyPair.ALG_EC_FP`, which are not supported by real cards. + +* **Execution of Java Card applications without converting into CAP** + +jCardSim can work with class files without any conversions. This allows us to simplify and accelerate the development and writing of unit tests. + +* **Simulator API** + +jCardSim has a simple and usable API, which also allows you to work with the simulator using `javax.smartcardio.*`. + +* **Cross-platform** + +jCardSim is completely written in Java and can therefore be used on all platforms which support Java (Windows, Linux, MacOS, etc). + +### How to help jCardSim? + +* Join the team of jCardSim developers. +* Try out [DexProtector](http://dexprotector.com). The product is designed for strong and robust protection of Android applications against reverse engineering and modification. +* Licel has one more product you may be interested in - [Stringer Java Obfuscator](https://jfxstore.com/stringer). This tool provides all the features you need to comprehensively protect your Java applications. + +**License**: [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0) + +**Third-party libraries**: [Legion of the Bouncy Castle Java](http://www.bouncycastle.org/java.html) + +**Trademarks**: Oracle, Java and Java Card are trademarks of Oracle Corporation. diff --git a/javadoc/allclasses-frame.html b/javadoc/allclasses-frame.html index 52ace614..2a86482e 100644 --- a/javadoc/allclasses-frame.html +++ b/javadoc/allclasses-frame.html @@ -2,13 +2,13 @@ - + All Classes (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -22,11 +22,7 @@ -
A -
-AccountAccessor -
-AESKey +
AESKey
AID
@@ -44,20 +40,16 @@
AsymmetricSignatureImpl
-ATreeNode -
-B -
BasicService
-BTreeNode -
ByteContainer
-C +CAD
CardException
+CardInterface +
CardRemoteObject
CardRuntimeException @@ -66,16 +58,12 @@
Cipher
-ConnectionManager -
CRC16
CRC32
CryptoException
-CyclicFile -
DESKey
Dispatcher @@ -110,11 +98,15 @@
ISOException
-JavaLoyalty +JavaCardInterface
-JavaLoyaltyInterface +JavaCardRemoteClient
-JavaPurse +JavaCardRemoteInterface +
+JavaCardRemoteServer +
+JavaxSmartCardInterface
JCardSimProvider
@@ -148,58 +140,26 @@
KeyWithParameters
-Main -
MessageDigest
MessageDigestImpl
MultiSelectable
-MySecurityService -
-NullApp -
OwnerPIN
-ParametersFile -
-PhotoCard -
-PhotoCardApplet -
-PhotoCardImpl -
PIN
PINException
-PostProcess -
-PreProcess -
PrivateKey
PublicKey
-Purse -
-Purse -
-PurseApplet -
-PurseImpl -
RandomData
RandomDataImpl
-Record -
-Remote -
-RemoteException -
RemoteService
RMIService @@ -216,12 +176,10 @@
SecretKey
-SecurePurseApplet -
-SecurePurseImpl -
SecurityService
+SerializableAID +
Service
ServiceException @@ -244,20 +202,14 @@
SystemException
-TestService -
TransactionException
-TransientArrayElement -
TransientMemory
UserException
Util
-Wallet -
diff --git a/javadoc/allclasses-noframe.html b/javadoc/allclasses-noframe.html index 71b2ee68..5f472705 100644 --- a/javadoc/allclasses-noframe.html +++ b/javadoc/allclasses-noframe.html @@ -2,13 +2,13 @@ - + All Classes (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -22,11 +22,7 @@ -
A -
-AccountAccessor -
-AESKey +
AESKey
AID
@@ -44,20 +40,16 @@
AsymmetricSignatureImpl
-ATreeNode -
-B -
BasicService
-BTreeNode -
ByteContainer
-C +CAD
CardException
+CardInterface +
CardRemoteObject
CardRuntimeException @@ -66,16 +58,12 @@
Cipher
-ConnectionManager -
CRC16
CRC32
CryptoException
-CyclicFile -
DESKey
Dispatcher @@ -110,11 +98,15 @@
ISOException
-JavaLoyalty +JavaCardInterface
-JavaLoyaltyInterface +JavaCardRemoteClient
-JavaPurse +JavaCardRemoteInterface +
+JavaCardRemoteServer +
+JavaxSmartCardInterface
JCardSimProvider
@@ -148,58 +140,26 @@
KeyWithParameters
-Main -
MessageDigest
MessageDigestImpl
MultiSelectable
-MySecurityService -
-NullApp -
OwnerPIN
-ParametersFile -
-PhotoCard -
-PhotoCardApplet -
-PhotoCardImpl -
PIN
PINException
-PostProcess -
-PreProcess -
PrivateKey
PublicKey
-Purse -
-Purse -
-PurseApplet -
-PurseImpl -
RandomData
RandomDataImpl
-Record -
-Remote -
-RemoteException -
RemoteService
RMIService @@ -216,12 +176,10 @@
SecretKey
-SecurePurseApplet -
-SecurePurseImpl -
SecurityService
+SerializableAID +
Service
ServiceException @@ -244,20 +202,14 @@
SystemException
-TestService -
TransactionException
-TransientArrayElement -
TransientMemory
UserException
Util
-Wallet -
diff --git a/javadoc/com/licel/jcardsim/base/Simulator.html b/javadoc/com/licel/jcardsim/base/Simulator.html index 1ecf98ad..1c775731 100644 --- a/javadoc/com/licel/jcardsim/base/Simulator.html +++ b/javadoc/com/licel/jcardsim/base/Simulator.html @@ -2,13 +2,13 @@ - + Simulator (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -96,9 +96,15 @@

java.lang.Object extended by com.licel.jcardsim.base.Simulator +
+
All Implemented Interfaces:
CardInterface, JavaCardInterface
+
+
+
Direct Known Subclasses:
JavaxSmartCardInterface
+

-
public class Simulator
extends Object
+
public class Simulator
extends Object
implements JavaCardInterface

@@ -122,7 +128,7 @@

Simulator()
-          Construct Simulator object and init base systems +          Construct Simulator object and init base systems   @@ -143,7 +149,16 @@

byte bLength)
-          Create Applet instance in Simulator +          Create + Applet instance in Simulator + + + + byte[] +getATR() + +
+          Returns ATR @@ -152,7 +167,8 @@

Class appletClass)
-          Install Applet into Simulator without installing data +          Install + Applet into Simulator without installing data @@ -164,7 +180,35 @@

byte bLength)
-          Install Applet into Simulator. +          Install + Applet into Simulator. + + + + AID +installApplet(AID aid, + String appletClassName, + byte[] appletContents, + byte[] bArray, + short bOffset, + byte bLength) + +
+          Install + Applet into Simulator. + + + + AID +installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
+          Install + Applet into Simulator. @@ -173,7 +217,29 @@

Class appletClass)
-          Load Applet into Simulator +          Load + Applet into Simulator + + + + AID +loadApplet(AID aid, + String appletClassName) + +
+          Load + Applet into Simulator + + + + AID +loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
+          Load + Applet into Simulator @@ -181,7 +247,7 @@

reset()
-          powerdown/powerup +          Powerdown/Powerup @@ -197,13 +263,13 @@

selectApplet(AID aid)
-          Select applet by it's AID +          Select applet by it's AID It's method must be called before start working with applet instance - javax.smartcardio.ResponseAPDU -transmitCommand(javax.smartcardio.CommandAPDU commandAPDU) + byte[]
+transmitCommand(byte[] command)
          Transmit APDU to previous selected applet @@ -236,7 +302,7 @@

 public Simulator()
-
Construct Simulator object and init base systems +
Construct Simulator object and init base systems

@@ -250,6 +316,55 @@

+

+loadApplet

+
+public AID loadApplet(AID aid,
+                      String appletClassName,
+                      byte[] appletJarContents)
+               throws SystemException
+
+
Description copied from interface: JavaCardInterface
+
Load + Applet into Simulator +

+

+
Specified by:
loadApplet in interface JavaCardInterface
+
+
+
Parameters:
aid - applet aid
appletClassName - fully qualified applet class name Strin
appletJarContents - contains a byte array containing a jar file with an applet and its dependent classes +
Returns:
applet AID +
Throws: +
SystemException - if appletClass not instanceof + javacard.framework.Applet
+
+
+
+ +

+loadApplet

+
+public AID loadApplet(AID aid,
+                      String appletClassName)
+               throws SystemException
+
+
Description copied from interface: JavaCardInterface
+
Load + Applet into Simulator +

+

+
Specified by:
loadApplet in interface JavaCardInterface
+
+
+
Parameters:
aid - applet aid +
Returns:
applet AID +
Throws: +
SystemException - if appletClass not instanceof + javacard.framework.Applet
+
+
+
+

loadApplet

@@ -257,13 +372,17 @@ 

Class appletClass) throws SystemException

-
Load Applet into Simulator +
Load + Applet into Simulator

+
+
+
Parameters:
aid - applet aid
appletClass - applet class
Returns:
applet AID
Throws: -
SystemException - if appletClass not instanceof +
SystemException - if appletClass not instanceof javacard.framework.Applet
@@ -278,9 +397,14 @@

byte bLength) throws SystemException
-
Create Applet instance in Simulator +
Description copied from interface: JavaCardInterface
+
Create + Applet instance in Simulator

+
Specified by:
createApplet in interface JavaCardInterface
+
+
Parameters:
aid - applet aid
bArray - the array containing installation parameters
bOffset - the starting offset in bArray
bLength - the length in bytes of the parameter data in bArray
Returns:
applet AID
Throws: @@ -297,13 +421,17 @@

Class appletClass) throws SystemException
-
Install Applet into Simulator without installing data +
Install + Applet into Simulator without installing data

+
+
+
Parameters:
aid - applet aid or null
appletClass - applet class
Returns:
applet AID
Throws: -
SystemException - if appletClass not instanceof +
SystemException - if appletClass not instanceof javacard.framework.Applet
@@ -319,18 +447,86 @@

byte bLength) throws SystemException
-
Install Applet into Simulator. - This method is equal to: +
Install + Applet into Simulator. This method is equal to: loadApplet(...); createApplet(...);

+
+
+
Parameters:
aid - applet aid or null
appletClass - applet class
bArray - the array containing installation parameters
bOffset - the starting offset in bArray
bLength - the length in bytes of the parameter data in bArray
Returns:
applet AID
Throws: -
SystemException - if appletClass not instanceof +
SystemException - if appletClass not instanceof + javacard.framework.Applet
+
+
+
+ +

+installApplet

+
+public AID installApplet(AID aid,
+                         String appletClassName,
+                         byte[] bArray,
+                         short bOffset,
+                         byte bLength)
+                  throws SystemException
+
+
Description copied from interface: JavaCardInterface
+
Install + Applet into Simulator. + This method is equal to: + + loadApplet(...); + createApplet(...); + +

+

+
Specified by:
installApplet in interface JavaCardInterface
+
+
+
Parameters:
aid - applet aid or null
appletClassName - fully qualified applet class name Strin
bArray - the array containing installation parameters
bOffset - the starting offset in bArray
bLength - the length in bytes of the parameter data in bArray +
Returns:
applet AID +
Throws: +
SystemException - if appletClass not instanceof + javacard.framework.Applet
+
+
+
+ +

+installApplet

+
+public AID installApplet(AID aid,
+                         String appletClassName,
+                         byte[] appletContents,
+                         byte[] bArray,
+                         short bOffset,
+                         byte bLength)
+                  throws SystemException
+
+
Description copied from interface: JavaCardInterface
+
Install + Applet into Simulator. + This method is equal to: + + loadApplet(...); + createApplet(...); + +

+

+
Specified by:
installApplet in interface JavaCardInterface
+
+
+
Parameters:
aid - applet aid or null
appletClassName - fully qualified applet class name Strin
appletContents - Contains a byte array containing a jar file with an applet and its dependent classes
bArray - the array containing installation parameters
bOffset - the starting offset in bArray
bLength - the length in bytes of the parameter data in bArray +
Returns:
applet AID +
Throws: +
SystemException - if appletClass not instanceof javacard.framework.Applet
@@ -342,10 +538,14 @@

public boolean selectApplet(AID aid) throws SystemException
-
Select applet by it's AID +
Description copied from interface: JavaCardInterface
+
Select applet by it's AID It's method must be called before start working with applet instance

+
Specified by:
selectApplet in interface JavaCardInterface
+
+
Parameters:
aid - appletId
Returns:
true if applet selection success
Throws: @@ -354,19 +554,22 @@


-

+

transmitCommand

-public javax.smartcardio.ResponseAPDU transmitCommand(javax.smartcardio.CommandAPDU commandAPDU)
-                                               throws SystemException
+public byte[] transmitCommand(byte[] command) + throws SystemException
+
Description copied from interface: CardInterface
Transmit APDU to previous selected applet

-
Parameters:
commandAPDU - command apdu +
Specified by:
transmitCommand in interface CardInterface
+
+
+
Returns:
response apdu
Throws: -
SystemException.ILLEGAL_USE - if appplet not selected before
SystemException
See Also:
CommandAPDU, ResponseAPDU
@@ -378,9 +581,13 @@

 public void reset()
-
powerdown/powerup +
Description copied from interface: CardInterface
+
Powerdown/Powerup

+
Specified by:
reset in interface CardInterface
+
+
@@ -389,11 +596,31 @@

resetRuntime

-public void resetRuntime()
+public final void resetRuntime()
+
+
+
+
+
+ +

+getATR

+
+public byte[] getATR()
+
+
Description copied from interface: CardInterface
+
Returns ATR +

+

+
Specified by:
getATR in interface CardInterface
+
+
+
+

diff --git a/javadoc/com/licel/jcardsim/base/SimulatorRuntime.html b/javadoc/com/licel/jcardsim/base/SimulatorRuntime.html index 371fc10d..8084f62c 100644 --- a/javadoc/com/licel/jcardsim/base/SimulatorRuntime.html +++ b/javadoc/com/licel/jcardsim/base/SimulatorRuntime.html @@ -2,13 +2,13 @@ - + SimulatorRuntime (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/base/SimulatorSystem.html b/javadoc/com/licel/jcardsim/base/SimulatorSystem.html index 02627de9..dc2e5261 100644 --- a/javadoc/com/licel/jcardsim/base/SimulatorSystem.html +++ b/javadoc/com/licel/jcardsim/base/SimulatorSystem.html @@ -2,13 +2,13 @@ - + SimulatorSystem (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -387,15 +387,6 @@

-static short -receiveAPDU(byte[] buffer, - short bOff) - -
-            - - - static void registerApplet(Applet applet) @@ -1016,18 +1007,6 @@


-

-receiveAPDU

-
-public static short receiveAPDU(byte[] buffer,
-                                short bOff)
-
-
-
-
-
-
-

registerApplet

diff --git a/javadoc/com/licel/jcardsim/base/TransientMemory.html b/javadoc/com/licel/jcardsim/base/TransientMemory.html
index 21a70a93..ae80caeb 100644
--- a/javadoc/com/licel/jcardsim/base/TransientMemory.html
+++ b/javadoc/com/licel/jcardsim/base/TransientMemory.html
@@ -2,13 +2,13 @@
 
 
 
-
+
 
 
 TransientMemory (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API)
 
 
-
+
 
 
 
diff --git a/javadoc/com/licel/jcardsim/base/class-use/Simulator.html b/javadoc/com/licel/jcardsim/base/class-use/Simulator.html
index 8053b766..552ec0a3 100644
--- a/javadoc/com/licel/jcardsim/base/class-use/Simulator.html
+++ b/javadoc/com/licel/jcardsim/base/class-use/Simulator.html
@@ -2,13 +2,13 @@
 
 
 
-
+
 
 
 Uses of Class com.licel.jcardsim.base.Simulator (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API)
 
 
-
+
 
 
 
@@ -84,7 +84,43 @@
 

Uses of Class
com.licel.jcardsim.base.Simulator

-No usage of com.licel.jcardsim.base.Simulator + + + + + + + + + +
+Packages that use Simulator
com.licel.jcardsim.io  
+  +

+ + + + + +
+Uses of Simulator in com.licel.jcardsim.io
+  +

+ + + + + + + + + +
Subclasses of Simulator in com.licel.jcardsim.io
+ classJavaxSmartCardInterface + +
+          Class with javacardx.smartcardio Command/Response support


diff --git a/javadoc/com/licel/jcardsim/base/class-use/SimulatorRuntime.html b/javadoc/com/licel/jcardsim/base/class-use/SimulatorRuntime.html index a9af4643..6a05141c 100644 --- a/javadoc/com/licel/jcardsim/base/class-use/SimulatorRuntime.html +++ b/javadoc/com/licel/jcardsim/base/class-use/SimulatorRuntime.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.base.SimulatorRuntime (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/base/class-use/SimulatorSystem.html b/javadoc/com/licel/jcardsim/base/class-use/SimulatorSystem.html index 182877a3..ca5b0601 100644 --- a/javadoc/com/licel/jcardsim/base/class-use/SimulatorSystem.html +++ b/javadoc/com/licel/jcardsim/base/class-use/SimulatorSystem.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.base.SimulatorSystem (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/base/class-use/TransientMemory.html b/javadoc/com/licel/jcardsim/base/class-use/TransientMemory.html index ed3035c9..1ddedf8a 100644 --- a/javadoc/com/licel/jcardsim/base/class-use/TransientMemory.html +++ b/javadoc/com/licel/jcardsim/base/class-use/TransientMemory.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.base.TransientMemory (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/base/package-frame.html b/javadoc/com/licel/jcardsim/base/package-frame.html index 29e2881e..a681cf71 100644 --- a/javadoc/com/licel/jcardsim/base/package-frame.html +++ b/javadoc/com/licel/jcardsim/base/package-frame.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.base (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/base/package-summary.html b/javadoc/com/licel/jcardsim/base/package-summary.html index 1d580a67..8b5fd55b 100644 --- a/javadoc/com/licel/jcardsim/base/package-summary.html +++ b/javadoc/com/licel/jcardsim/base/package-summary.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.base (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/base/package-tree.html b/javadoc/com/licel/jcardsim/base/package-tree.html index f7e1eef6..4a221377 100644 --- a/javadoc/com/licel/jcardsim/base/package-tree.html +++ b/javadoc/com/licel/jcardsim/base/package-tree.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.base Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -93,7 +93,8 @@


diff --git a/javadoc/com/licel/jcardsim/base/package-use.html b/javadoc/com/licel/jcardsim/base/package-use.html index d326752d..ab9afbec 100644 --- a/javadoc/com/licel/jcardsim/base/package-use.html +++ b/javadoc/com/licel/jcardsim/base/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package com.licel.jcardsim.base (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -84,7 +84,33 @@

Uses of Package
com.licel.jcardsim.base

-No usage of com.licel.jcardsim.base + + + + + + + + + +
+Packages that use com.licel.jcardsim.base
com.licel.jcardsim.io  
+  +

+ + + + + + + + +
+Classes in com.licel.jcardsim.base used by com.licel.jcardsim.io
Simulator + +
+          Main class for deal with Applets


diff --git a/javadoc/com/licel/jcardsim/crypto/AssymetricCipherImpl.html b/javadoc/com/licel/jcardsim/crypto/AssymetricCipherImpl.html index 1f041cb0..96df6f3f 100644 --- a/javadoc/com/licel/jcardsim/crypto/AssymetricCipherImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/AssymetricCipherImpl.html @@ -2,13 +2,13 @@ - + AssymetricCipherImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.html b/javadoc/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.html index a52bb87f..5adf520e 100644 --- a/javadoc/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.html @@ -2,13 +2,13 @@ - + AsymmetricSignatureImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/ByteContainer.html b/javadoc/com/licel/jcardsim/crypto/ByteContainer.html index da3a285f..9d67cc3f 100644 --- a/javadoc/com/licel/jcardsim/crypto/ByteContainer.html +++ b/javadoc/com/licel/jcardsim/crypto/ByteContainer.html @@ -2,13 +2,13 @@ - + ByteContainer (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/CRC16.html b/javadoc/com/licel/jcardsim/crypto/CRC16.html index 056b2991..a38fe853 100644 --- a/javadoc/com/licel/jcardsim/crypto/CRC16.html +++ b/javadoc/com/licel/jcardsim/crypto/CRC16.html @@ -2,13 +2,13 @@ - + CRC16 (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/CRC32.html b/javadoc/com/licel/jcardsim/crypto/CRC32.html index b9fdc01b..46464ea4 100644 --- a/javadoc/com/licel/jcardsim/crypto/CRC32.html +++ b/javadoc/com/licel/jcardsim/crypto/CRC32.html @@ -2,13 +2,13 @@ - + CRC32 (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/DSAKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/DSAKeyImpl.html index 0beae454..007317f6 100644 --- a/javadoc/com/licel/jcardsim/crypto/DSAKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/DSAKeyImpl.html @@ -2,13 +2,13 @@ - + DSAKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -98,7 +98,7 @@

extended by com.licel.jcardsim.crypto.DSAKeyImpl

-
All Implemented Interfaces:
DSAKey, Key
+
All Implemented Interfaces:
KeyWithParameters, DSAKey, Key
Direct Known Subclasses:
DSAPrivateKeyImpl, DSAPublicKeyImpl
@@ -220,6 +220,15 @@

+ org.bouncycastle.crypto.KeyGenerationParameters +getKeyGenerationParameters(SecureRandom rnd) + +
+          Get + DSAKeyGenerationParameters + + +  short getP(byte[] buffer, short offset) @@ -614,13 +623,31 @@

Get DSAKeyParameters

-
+
Specified by:
getParameters in interface KeyWithParameters

Returns:
parameters for use with BouncyCastle API
See Also:
DSAKeyParameters
+
+ +

+getKeyGenerationParameters

+
+public org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
+
+
Get + DSAKeyGenerationParameters +

+

+
Specified by:
getKeyGenerationParameters in interface KeyWithParameters
+
+
+
Parameters:
rnd - Secure Random Generator +
Returns:
parameters for use with BouncyCastle API
+
+

diff --git a/javadoc/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.html index dd138e1b..eea97b40 100644 --- a/javadoc/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.html @@ -2,13 +2,13 @@ - + DSAPrivateKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -103,7 +103,7 @@


-
public class DSAPrivateKeyImpl
extends DSAKeyImpl
implements DSAPrivateKey, KeyWithParameters
+
public class DSAPrivateKeyImpl
extends DSAKeyImpl
implements DSAPrivateKey

@@ -234,7 +234,7 @@

Methods inherited from class com.licel.jcardsim.crypto.DSAKeyImpl -getG, getP, getQ, setG, setP, setQ +getG, getKeyGenerationParameters, getP, getQ, setG, setP, setQ   diff --git a/javadoc/com/licel/jcardsim/crypto/DSAPublicKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/DSAPublicKeyImpl.html index 439fbdc8..3355b9a7 100644 --- a/javadoc/com/licel/jcardsim/crypto/DSAPublicKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/DSAPublicKeyImpl.html @@ -2,13 +2,13 @@ - + DSAPublicKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -103,7 +103,7 @@


-
public class DSAPublicKeyImpl
extends DSAKeyImpl
implements DSAPublicKey, KeyWithParameters
+
public class DSAPublicKeyImpl
extends DSAKeyImpl
implements DSAPublicKey

@@ -234,7 +234,7 @@

Methods inherited from class com.licel.jcardsim.crypto.DSAKeyImpl -getG, getP, getQ, setG, setP, setQ +getG, getKeyGenerationParameters, getP, getQ, setG, setP, setQ   diff --git a/javadoc/com/licel/jcardsim/crypto/ECKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/ECKeyImpl.html index 6409c37e..47122469 100644 --- a/javadoc/com/licel/jcardsim/crypto/ECKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/ECKeyImpl.html @@ -2,13 +2,13 @@ - + ECKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -98,7 +98,7 @@

extended by com.licel.jcardsim.crypto.ECKeyImpl
-
All Implemented Interfaces:
ECKey, Key
+
All Implemented Interfaces:
KeyWithParameters, ECKey, Key
Direct Known Subclasses:
ECPrivateKeyImpl, ECPublicKeyImpl
@@ -109,8 +109,8 @@

-Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI +Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI

@@ -281,7 +281,8 @@

getDomainParameters()
-          Get ECDomainParameters +          Get + ECDomainParameters @@ -311,6 +312,15 @@

+ org.bouncycastle.crypto.KeyGenerationParameters +getKeyGenerationParameters(SecureRandom rnd) + +
+          Get + ECKeyGenerationParameters + + +  short getR(byte[] buffer, short offset) @@ -428,6 +438,15 @@

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait + + + + + + + +
Methods inherited from interface com.licel.jcardsim.crypto.KeyWithParameters
getParameters
 

@@ -559,7 +578,7 @@

Construct not-initialized ecc key

-
Parameters:
keyType - - key type
keySize - - key size in bits
See Also:
KeyPair, +
Parameters:
keyType - - key type
keySize - - key size in bits
See Also:
KeyPair, KeyBuilder


@@ -569,11 +588,10 @@

 public ECKeyImpl(org.bouncycastle.crypto.params.ECKeyParameters parameters)
-
Construct and initialize ecc key with ECKeyParameters. - Use in KeyPairImpl +
Construct and initialize ecc key with ECKeyParameters. Use in KeyPairImpl

-
See Also:
KeyPair, +
See Also:
KeyPair, ECKeyParameters
@@ -1121,7 +1139,8 @@

 public org.bouncycastle.crypto.params.ECDomainParameters getDomainParameters()
-
Get ECDomainParameters +
Get + ECDomainParameters

@@ -1131,6 +1150,24 @@

Returns:
parameters for use with BouncyCastle API
See Also:
ECDomainParameters

+
+ +

+getKeyGenerationParameters

+
+public org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
+
+
Get + ECKeyGenerationParameters +

+

+
Specified by:
getKeyGenerationParameters in interface KeyWithParameters
+
+
+
Parameters:
rnd - Secure Random Generator +
Returns:
parameters for use with BouncyCastle API
+
+

diff --git a/javadoc/com/licel/jcardsim/crypto/ECPrivateKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/ECPrivateKeyImpl.html index f33d6a7b..ece4a828 100644 --- a/javadoc/com/licel/jcardsim/crypto/ECPrivateKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/ECPrivateKeyImpl.html @@ -2,13 +2,13 @@ - + ECPrivateKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -103,7 +103,7 @@


-
public class ECPrivateKeyImpl
extends ECKeyImpl
implements ECPrivateKey, KeyWithParameters
+
public class ECPrivateKeyImpl
extends ECKeyImpl
implements ECPrivateKey

@@ -235,7 +235,7 @@

Methods inherited from class com.licel.jcardsim.crypto.ECKeyImpl -getA, getB, getDomainParameters, getField, getG, getK, getR, setA, setB, setFieldF2M, setFieldF2M, setFieldFP, setG, setK, setR +getA, getB, getDomainParameters, getField, getG, getK, getKeyGenerationParameters, getR, setA, setB, setFieldF2M, setFieldF2M, setFieldFP, setG, setK, setR   diff --git a/javadoc/com/licel/jcardsim/crypto/ECPublicKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/ECPublicKeyImpl.html index cac05b08..5ea5e10d 100644 --- a/javadoc/com/licel/jcardsim/crypto/ECPublicKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/ECPublicKeyImpl.html @@ -2,13 +2,13 @@ - + ECPublicKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -103,7 +103,7 @@


-
public class ECPublicKeyImpl
extends ECKeyImpl
implements ECPublicKey, KeyWithParameters
+
public class ECPublicKeyImpl
extends ECKeyImpl
implements ECPublicKey

@@ -235,7 +235,7 @@

Methods inherited from class com.licel.jcardsim.crypto.ECKeyImpl -getA, getB, getDomainParameters, getField, getG, getK, getR, setA, setB, setFieldF2M, setFieldF2M, setFieldFP, setG, setK, setR +getA, getB, getDomainParameters, getField, getG, getK, getKeyGenerationParameters, getR, setA, setB, setFieldF2M, setFieldF2M, setFieldFP, setG, setK, setR   diff --git a/javadoc/com/licel/jcardsim/crypto/KeyAgreementImpl.html b/javadoc/com/licel/jcardsim/crypto/KeyAgreementImpl.html index 921ef25b..ec4aad25 100644 --- a/javadoc/com/licel/jcardsim/crypto/KeyAgreementImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/KeyAgreementImpl.html @@ -2,13 +2,13 @@ - + KeyAgreementImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/KeyImpl.html b/javadoc/com/licel/jcardsim/crypto/KeyImpl.html index 80184dbf..13aa812d 100644 --- a/javadoc/com/licel/jcardsim/crypto/KeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/KeyImpl.html @@ -2,13 +2,13 @@ - + KeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -97,14 +97,14 @@

extended by com.licel.jcardsim.crypto.KeyImpl
-
All Implemented Interfaces:
Key
+
All Implemented Interfaces:
KeyWithParameters, Key
Direct Known Subclasses:
DSAKeyImpl, ECKeyImpl, RSAKeyImpl, SymmetricKeyImpl

-
public abstract class KeyImpl
extends Object
implements Key
+
public abstract class KeyImpl
extends Object
implements Key, KeyWithParameters

@@ -202,6 +202,15 @@

clearKey, isInitialized + + + + + + + +
Methods inherited from interface com.licel.jcardsim.crypto.KeyWithParameters
getKeyGenerationParameters, getParameters
 

diff --git a/javadoc/com/licel/jcardsim/crypto/KeyPairImpl.html b/javadoc/com/licel/jcardsim/crypto/KeyPairImpl.html index 05174678..f7e7eda2 100644 --- a/javadoc/com/licel/jcardsim/crypto/KeyPairImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/KeyPairImpl.html @@ -2,13 +2,13 @@ - + KeyPairImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -102,8 +102,8 @@

-Implementation KeyPair based - on BouncyCastle CryptoAPI +Implementation + KeyPair based on BouncyCastle CryptoAPI

@@ -129,7 +129,8 @@

short keyLength)
-          Constructs a KeyPair instance for the specified algorithm and keylength; +          Constructs a + KeyPair instance for the specified algorithm and keylength; the encapsulated keys are uninitialized. @@ -137,8 +138,9 @@

PrivateKey privateKey)
-          Constructs a new KeyPair object containing the specified - public key and private key. +          Constructs a new + KeyPair object containing the specified public key and + private key.   @@ -156,8 +158,8 @@

genKeyPair()
-          (Re)Initializes the key objects encapsulated in this KeyPair instance - with new key values. +          (Re)Initializes the key objects encapsulated in this + KeyPair instance with new key values. @@ -165,7 +167,8 @@

getPrivate()
-          Returns a reference to the private key component of this KeyPair object. +          Returns a reference to the private key component of this + KeyPair object. @@ -173,7 +176,8 @@

getPublic()
-          Returns a reference to the public key component of this KeyPair object. +          Returns a reference to the public key component of this + KeyPair object.   @@ -205,26 +209,31 @@

short keyLength) throws CryptoException
-
Constructs a KeyPair instance for the specified algorithm and keylength; - the encapsulated keys are uninitialized. - To initialize the KeyPair instance use the genKeyPair() method.

- The encapsulated key objects are of the specified keyLength size and - implement the appropriate Key interface associated with the specified algorithm - (example - RSAPublicKey interface for the public key and RSAPrivateKey - interface for the private key within an ALG_RSA key pair).

-

Notes:

    -
  • The key objects encapsulated in the generated KeyPair object - need not support the KeyEncryption interface. -
+
Constructs a + KeyPair instance for the specified algorithm and keylength; + the encapsulated keys are uninitialized. To initialize the + KeyPair instance use the + genKeyPair() method.

The encapsulated key objects are of + the specified + keyLength size and implement the appropriate + Key interface associated with the specified algorithm + (example - + RSAPublicKey interface for the public key and + RSAPrivateKey interface for the private key within an + ALG_RSA key pair).

Notes:

  • The key objects + encapsulated in the generated KeyPair object need + not support the KeyEncryption interface.

-
Parameters:
algorithm - the type of algorithm whose key pair needs to be generated. - Valid codes listed in ALG_.. constants above. KeyPair
keyLength - the key size in bits. The valid key bit lengths are key type dependent. - See the KeyBuilder class. +
Parameters:
algorithm - the type of algorithm whose key pair needs to be + generated. Valid codes listed in ALG_.. constants above. + KeyPair
keyLength - the key size in bits. The valid key bit lengths are key + type dependent. See the KeyBuilder class.
Throws:
CryptoException - with the following reason codes:
    -
  • CryptoException.NO_SUCH_ALGORITHM if the requested algorithm - associated with the specified type, size of key is not supported.
See Also:
KeyBuilder, +
  • CryptoException.NO_SUCH_ALGORITHM if the requested + algorithm associated with the specified type, size of key is not + supported.
    See Also:
    KeyBuilder, KeyBuilder, Signature, KeyEncryption, @@ -239,21 +248,21 @@

    PrivateKey privateKey) throws CryptoException
    -
    Constructs a new KeyPair object containing the specified - public key and private key. -

    Note that this constructor only stores references to the public - and private key components in the generated KeyPair object. It - does not throw an exception if the key parameter objects are uninitialized. +

    Constructs a new + KeyPair object containing the specified public key and + private key.

    Note that this constructor only stores references to the + public and private key components in the generated + KeyPair object. It does not throw an exception if the key + parameter objects are uninitialized.

    Parameters:
    publicKey - the public key.
    privateKey - the private key.
    Throws:
    CryptoException - with the following reason codes:
    • CryptoException.ILLEGAL_VALUE if the input parameter key - objects are inconsistent with each other - i.e mismatched algorithm, size etc. -
    • CryptoException.NO_SUCH_ALGORITHM if the algorithm - associated with the specified type, size of key is not supported. -
    + objects are inconsistent with each other - i.e mismatched algorithm, size + etc.
  • CryptoException.NO_SUCH_ALGORITHM if the algorithm + associated with the specified type, size of key is not supported.
  • @@ -272,35 +281,37 @@

    public final void genKeyPair() throws CryptoException
    -
    (Re)Initializes the key objects encapsulated in this KeyPair instance - with new key values. The initialized public and private key objects - encapsulated in this instance will then be suitable for use with the - Signature, Cipher and KeyAgreement objects. - An internal secure random number generator is used during new key pair generation. -

    Notes:

      -
    • For the RSA algorithm, if the exponent value in the public key object is pre-initialized, - it will be retained. Otherwise, a default value of 65537 will be used. -
    • For the DSA algorithm, if the p, q and g parameters of the public key object are pre-initialized, - they will be retained. Otherwise, default precomputed parameter sets will be used. The required - default precomputed values are listed in Appendix B of Java Cryptography Architecture - API Specification & Reference document. -
    • For the EC case, if the Field, A, B, G and R parameters of the - key pair are pre-initialized, then they will be retained. Otherwise - default pre-specified values MAY be used (e.g. WAP predefined curves), - since computation of random generic EC keys is infeasible on the smart - card platform. -
    • If the time taken to generate the key values is excessive, the implementation may automatically - request additional APDU processing time from the CAD. +
      (Re)Initializes the key objects encapsulated in this + KeyPair instance with new key values. The initialized public + and private key objects encapsulated in this instance will then be + suitable for use with the + Signature, + Cipher and + KeyAgreement objects. An internal secure random number + generator is used during new key pair generation.

      Notes:

        +
      • For the RSA algorithm, if the exponent value in the public key + object is pre-initialized, it will be retained. Otherwise, a default + value of 65537 will be used.
      • For the DSA algorithm, if the + p, q and g parameters of the public key object are pre-initialized, they + will be retained. Otherwise, default precomputed parameter sets will be + used. The required default precomputed values are listed in Appendix + B of Java Cryptography Architecture API Specification & + Reference document.
      • For the EC case, if the Field, A, B, + G and R parameters of the key pair are pre-initialized, then they will be + retained. Otherwise default pre-specified values MAY be used (e.g. WAP + predefined curves), since computation of random generic EC keys is + infeasible on the smart card platform.
      • If the time taken to + generate the key values is excessive, the implementation may + automatically request additional APDU processing time from the CAD.

      Throws:
      CryptoException - with the following reason codes:
        -
      • CryptoException.ILLEGAL_VALUE if the exponent - value parameter in RSA or the p, q, g parameter set in DSA or - the Field, A, B, G and R parameter set in EC is invalid. -
      See Also:
      APDU, +
    • CryptoException.ILLEGAL_VALUE if the exponent value + parameter in RSA or the p, q, g parameter set in DSA or the Field, A, B, + G and R parameter set in EC is invalid.
    See Also:
    APDU, Signature, Cipher, RSAPublicKey, @@ -315,7 +326,8 @@

     public PublicKey getPublic()
    -
    Returns a reference to the public key component of this KeyPair object. +
    Returns a reference to the public key component of this + KeyPair object.

    @@ -329,7 +341,8 @@

     public PrivateKey getPrivate()
    -
    Returns a reference to the private key component of this KeyPair object. +
    Returns a reference to the private key component of this + KeyPair object.

    diff --git a/javadoc/com/licel/jcardsim/crypto/KeyWithParameters.html b/javadoc/com/licel/jcardsim/crypto/KeyWithParameters.html index 3033fa54..4973ad13 100644 --- a/javadoc/com/licel/jcardsim/crypto/KeyWithParameters.html +++ b/javadoc/com/licel/jcardsim/crypto/KeyWithParameters.html @@ -2,13 +2,13 @@ - + KeyWithParameters (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -93,7 +93,7 @@


    Interface KeyWithParameters

    -
    All Known Implementing Classes:
    DSAPrivateKeyImpl, DSAPublicKeyImpl, ECPrivateKeyImpl, ECPublicKeyImpl, RSAKeyImpl, RSAPrivateCrtKeyImpl, SymmetricKeyImpl
    +
    All Known Implementing Classes:
    DSAKeyImpl, DSAPrivateKeyImpl, DSAPublicKeyImpl, ECKeyImpl, ECPrivateKeyImpl, ECPublicKeyImpl, KeyImpl, RSAKeyImpl, RSAPrivateCrtKeyImpl, SymmetricKeyImpl

    @@ -115,12 +115,19 @@

    + org.bouncycastle.crypto.KeyGenerationParameters +getKeyGenerationParameters(SecureRandom rnd) + +
    +          Get keypair generation parameters for use with BouncyCastle Crypto API + + +  org.bouncycastle.crypto.CipherParameters getParameters()
    -          Get cipher key parameters - for use with BouncyCastle Crypto API +          Get cipher key parameters for use with BouncyCastle Crypto API   @@ -141,8 +148,21 @@

     org.bouncycastle.crypto.CipherParameters getParameters()
    -
    Get cipher key parameters - for use with BouncyCastle Crypto API +
    Get cipher key parameters for use with BouncyCastle Crypto API +

    +

    + +
    Returns:
    key parameters
    +
    +
    +
    + +

    +getKeyGenerationParameters

    +
    +org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
    +
    +
    Get keypair generation parameters for use with BouncyCastle Crypto API

    diff --git a/javadoc/com/licel/jcardsim/crypto/MessageDigestImpl.html b/javadoc/com/licel/jcardsim/crypto/MessageDigestImpl.html index f5b1ad7a..540a871a 100644 --- a/javadoc/com/licel/jcardsim/crypto/MessageDigestImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/MessageDigestImpl.html @@ -2,13 +2,13 @@ - + MessageDigestImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/RSAKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/RSAKeyImpl.html index ce1d8845..ec8e77ce 100644 --- a/javadoc/com/licel/jcardsim/crypto/RSAKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/RSAKeyImpl.html @@ -2,13 +2,13 @@ - + RSAKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -105,12 +105,12 @@


    -
    public class RSAKeyImpl
    extends KeyImpl
    implements RSAPrivateKey, RSAPublicKey, KeyWithParameters
    +
    public class RSAKeyImpl
    extends KeyImpl
    implements RSAPrivateKey, RSAPublicKey

    -Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI

    @@ -214,6 +214,15 @@

    + org.bouncycastle.crypto.KeyGenerationParameters +getKeyGenerationParameters(SecureRandom rnd) + +
    +          Get + RSAKeyGenerationParameters + + +  short getModulus(byte[] buffer, short offset) @@ -227,7 +236,8 @@

    getParameters()
    -          Get RSAKeyParameters +          Get + RSAKeyParameters @@ -355,8 +365,8 @@

     public RSAKeyImpl(org.bouncycastle.crypto.params.RSAKeyParameters params)
    -
    Construct and initialize rsa key with RSAKeyParameters. - Use in KeyPairImpl +
    Construct and initialize rsa key with RSAKeyParameters. Use in + KeyPairImpl

    Parameters:
    params - key params from BouncyCastle API
    See Also:
    KeyPair, @@ -530,7 +540,8 @@

     public org.bouncycastle.crypto.CipherParameters getParameters()
    -
    Get RSAKeyParameters +
    Get + RSAKeyParameters

    Specified by:
    getParameters in interface KeyWithParameters
    @@ -540,6 +551,24 @@

    Returns:
    parameters for use with BouncyCastle API
    See Also:
    RSAKeyParameters

    +
    + +

    +getKeyGenerationParameters

    +
    +public org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
    +
    +
    Get + RSAKeyGenerationParameters +

    +

    +
    Specified by:
    getKeyGenerationParameters in interface KeyWithParameters
    +
    +
    +
    Parameters:
    rnd - Secure Random Generator +
    Returns:
    parameters for use with BouncyCastle API
    +
    +

    diff --git a/javadoc/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.html index 69e2bd40..481e89b2 100644 --- a/javadoc/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.html @@ -2,13 +2,13 @@ - + RSAPrivateCrtKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -265,7 +265,8 @@

    getParameters()
    -          Get RSAKeyParameters +          Get + RSAKeyParameters @@ -360,7 +361,7 @@

    Methods inherited from class com.licel.jcardsim.crypto.RSAKeyImpl -getExponent, getModulus, setExponent, setModulus +getExponent, getKeyGenerationParameters, getModulus, setExponent, setModulus   @@ -838,7 +839,8 @@

    public org.bouncycastle.crypto.CipherParameters getParameters()
    Description copied from class: RSAKeyImpl
    -
    Get RSAKeyParameters +
    Get + RSAKeyParameters

    Specified by:
    getParameters in interface KeyWithParameters
    Overrides:
    getParameters in class RSAKeyImpl
    diff --git a/javadoc/com/licel/jcardsim/crypto/RandomDataImpl.html b/javadoc/com/licel/jcardsim/crypto/RandomDataImpl.html index 27865ab4..8b1c5f6d 100644 --- a/javadoc/com/licel/jcardsim/crypto/RandomDataImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/RandomDataImpl.html @@ -2,13 +2,13 @@ - + RandomDataImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/SymmetricCipherImpl.html b/javadoc/com/licel/jcardsim/crypto/SymmetricCipherImpl.html index ab6d1ccf..40d1a903 100644 --- a/javadoc/com/licel/jcardsim/crypto/SymmetricCipherImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/SymmetricCipherImpl.html @@ -2,13 +2,13 @@ - + SymmetricCipherImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/SymmetricKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/SymmetricKeyImpl.html index 69085444..d12d2b09 100644 --- a/javadoc/com/licel/jcardsim/crypto/SymmetricKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/SymmetricKeyImpl.html @@ -2,13 +2,13 @@ - + SymmetricKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -102,7 +102,7 @@


    -
    public class SymmetricKeyImpl
    extends KeyImpl
    implements DESKey, AESKey, KeyWithParameters
    +
    public class SymmetricKeyImpl
    extends KeyImpl
    implements DESKey, AESKey

    @@ -195,6 +195,14 @@

    + org.bouncycastle.crypto.KeyGenerationParameters +getKeyGenerationParameters(SecureRandom rnd) + +
    +          Get keypair generation parameters for use with BouncyCastle Crypto API + + +  org.bouncycastle.crypto.CipherParameters getParameters() @@ -424,6 +432,24 @@

    Returns:
    true if the key has been initialized

    +
    + +

    +getKeyGenerationParameters

    +
    +public org.bouncycastle.crypto.KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd)
    +
    +
    Description copied from interface: KeyWithParameters
    +
    Get keypair generation parameters for use with BouncyCastle Crypto API +

    +

    +
    Specified by:
    getKeyGenerationParameters in interface KeyWithParameters
    +
    +
    + +
    Returns:
    key parameters
    +
    +

    diff --git a/javadoc/com/licel/jcardsim/crypto/SymmetricSignatureImpl.html b/javadoc/com/licel/jcardsim/crypto/SymmetricSignatureImpl.html index 970c68af..7ed284fd 100644 --- a/javadoc/com/licel/jcardsim/crypto/SymmetricSignatureImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/SymmetricSignatureImpl.html @@ -2,13 +2,13 @@ - + SymmetricSignatureImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/AssymetricCipherImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/AssymetricCipherImpl.html index bbb02f58..035132a5 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/AssymetricCipherImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/AssymetricCipherImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.AssymetricCipherImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/AsymmetricSignatureImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/AsymmetricSignatureImpl.html index f48e486a..d427c1aa 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/AsymmetricSignatureImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/AsymmetricSignatureImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.AsymmetricSignatureImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/ByteContainer.html b/javadoc/com/licel/jcardsim/crypto/class-use/ByteContainer.html index ef59416a..5c6424aa 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/ByteContainer.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/ByteContainer.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.ByteContainer (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/CRC16.html b/javadoc/com/licel/jcardsim/crypto/class-use/CRC16.html index 456b2362..9f6c5aef 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/CRC16.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/CRC16.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.CRC16 (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/CRC32.html b/javadoc/com/licel/jcardsim/crypto/class-use/CRC32.html index c67613d2..464d0775 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/CRC32.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/CRC32.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.CRC32 (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/DSAKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/DSAKeyImpl.html index 9573286a..3e86406f 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/DSAKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/DSAKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.DSAKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/DSAPrivateKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/DSAPrivateKeyImpl.html index b48486f0..288cd77b 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/DSAPrivateKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/DSAPrivateKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.DSAPrivateKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/DSAPublicKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/DSAPublicKeyImpl.html index 14e03318..47bddffa 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/DSAPublicKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/DSAPublicKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.DSAPublicKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/ECKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/ECKeyImpl.html index 041239f9..3380ddb9 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/ECKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/ECKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.ECKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/ECPrivateKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/ECPrivateKeyImpl.html index 1f2c3556..ce0877dd 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/ECPrivateKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/ECPrivateKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.ECPrivateKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/ECPublicKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/ECPublicKeyImpl.html index 184ef9fc..2dba20cf 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/ECPublicKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/ECPublicKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.ECPublicKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/KeyAgreementImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/KeyAgreementImpl.html index bf54acc4..ee2bf194 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/KeyAgreementImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/KeyAgreementImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.KeyAgreementImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/KeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/KeyImpl.html index cfec2cfb..62c9354a 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/KeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/KeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.KeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -144,8 +144,8 @@

    ECKeyImpl
    -          Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI +          Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI @@ -171,8 +171,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/KeyPairImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/KeyPairImpl.html index c86180e9..15f00f75 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/KeyPairImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/KeyPairImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.KeyPairImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/KeyWithParameters.html b/javadoc/com/licel/jcardsim/crypto/class-use/KeyWithParameters.html index 0c8a9d53..213b21a2 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/KeyWithParameters.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/KeyWithParameters.html @@ -2,13 +2,13 @@ - + Uses of Interface com.licel.jcardsim.crypto.KeyWithParameters (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -114,6 +114,15 @@

     class +DSAKeyImpl + +
    +          Base class for DSAPublicKeyImpl/DSAPrivateKeyImpl + on BouncyCastle CryptoAPI + + + + class DSAPrivateKeyImpl
    @@ -132,6 +141,15 @@

     class +ECKeyImpl + +
    +          Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI + + + + class ECPrivateKeyImpl
    @@ -150,11 +168,19 @@

     class +KeyImpl + +
    +          Base class for all Key instances + + + + class RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/MessageDigestImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/MessageDigestImpl.html index 4aa3244b..5c595152 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/MessageDigestImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/MessageDigestImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.MessageDigestImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/RSAKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/RSAKeyImpl.html index c967fb17..8c093cab 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/RSAKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/RSAKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.RSAKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/RSAPrivateCrtKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/RSAPrivateCrtKeyImpl.html index 3a13070d..a95a74ff 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/RSAPrivateCrtKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/RSAPrivateCrtKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/RandomDataImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/RandomDataImpl.html index f52a7d0b..8498b81d 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/RandomDataImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/RandomDataImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.RandomDataImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricCipherImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricCipherImpl.html index 32cba882..5634a70a 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricCipherImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricCipherImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.SymmetricCipherImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricKeyImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricKeyImpl.html index 491539e1..578db04f 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricKeyImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricKeyImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.SymmetricKeyImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricSignatureImpl.html b/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricSignatureImpl.html index 4056520a..62e462d3 100644 --- a/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricSignatureImpl.html +++ b/javadoc/com/licel/jcardsim/crypto/class-use/SymmetricSignatureImpl.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.crypto.SymmetricSignatureImpl (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/package-frame.html b/javadoc/com/licel/jcardsim/crypto/package-frame.html index af3ce9fa..5945ce4b 100644 --- a/javadoc/com/licel/jcardsim/crypto/package-frame.html +++ b/javadoc/com/licel/jcardsim/crypto/package-frame.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.crypto (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/crypto/package-summary.html b/javadoc/com/licel/jcardsim/crypto/package-summary.html index a398314d..2e45a75d 100644 --- a/javadoc/com/licel/jcardsim/crypto/package-summary.html +++ b/javadoc/com/licel/jcardsim/crypto/package-summary.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.crypto (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -57,7 +57,7 @@  PREV PACKAGE  - NEXT PACKAGENEXT PACKAGE FRAMES    NO FRAMES   @@ -141,8 +141,8 @@

    ECKeyImpl -Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI +Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI ECPrivateKeyImpl @@ -165,8 +165,8 @@

    KeyPairImpl -Implementation KeyPair based - on BouncyCastle CryptoAPI +Implementation + KeyPair based on BouncyCastle CryptoAPI MessageDigestImpl @@ -180,8 +180,8 @@

    RSAKeyImpl -Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI RSAPrivateCrtKeyImpl @@ -239,7 +239,7 @@

     PREV PACKAGE  - NEXT PACKAGENEXT PACKAGE FRAMES    NO FRAMES   diff --git a/javadoc/com/licel/jcardsim/crypto/package-tree.html b/javadoc/com/licel/jcardsim/crypto/package-tree.html index 2f7c9dee..57ac398c 100644 --- a/javadoc/com/licel/jcardsim/crypto/package-tree.html +++ b/javadoc/com/licel/jcardsim/crypto/package-tree.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.crypto Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -57,7 +57,7 @@  PREV  - NEXTNEXT FRAMES    NO FRAMES   @@ -99,23 +99,23 @@

  • com.licel.jcardsim.crypto.AssymetricCipherImpl
  • com.licel.jcardsim.crypto.SymmetricCipherImpl
  • javacard.security.KeyAgreement -
  • com.licel.jcardsim.crypto.KeyImpl (implements javacard.security.Key) +
  • com.licel.jcardsim.crypto.KeyImpl (implements javacard.security.Key, com.licel.jcardsim.crypto.KeyWithParameters)
  • com.licel.jcardsim.crypto.KeyPairImpl
  • javacard.security.MessageDigest @@ -161,7 +161,7 @@

     PREV  - NEXTNEXT FRAMES    NO FRAMES   diff --git a/javadoc/com/licel/jcardsim/crypto/package-use.html b/javadoc/com/licel/jcardsim/crypto/package-use.html index b4e0af22..d2545ae2 100644 --- a/javadoc/com/licel/jcardsim/crypto/package-use.html +++ b/javadoc/com/licel/jcardsim/crypto/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package com.licel.jcardsim.crypto (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -121,8 +121,8 @@

    ECKeyImpl
    -          Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI +          Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI KeyImpl @@ -140,8 +140,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI   diff --git a/javadoc/com/licel/jcardsim/io/CAD.html b/javadoc/com/licel/jcardsim/io/CAD.html new file mode 100644 index 00000000..f543a1e7 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/CAD.html @@ -0,0 +1,329 @@ + + + + + + + +CAD (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.io +
    +Class CAD

    +
    +java.lang.Object
    +  extended by com.licel.jcardsim.io.CAD
    +
    +
    +
    +
    public class CAD
    extends Object
    + + +

    +Card Acceptance Device (CAD) +

    + +

    +


    + +

    + + + + + + + + + + + + + + + + + + + +
    +Field Summary
    +static byteINTERNAL + +
    +           
    +static byteJAVAX_SMARTCARDIO + +
    +           
    +static byteRMI + +
    +           
    +  + + + + + + + + + + +
    +Constructor Summary
    CAD(Properties params) + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    + CardInterfacegetCardInterface() + +
    +           
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +INTERNAL

    +
    +public static final byte INTERNAL
    +
    +
    +
    See Also:
    Constant Field Values
    +
    +
    + +

    +RMI

    +
    +public static final byte RMI
    +
    +
    +
    See Also:
    Constant Field Values
    +
    +
    + +

    +JAVAX_SMARTCARDIO

    +
    +public static final byte JAVAX_SMARTCARDIO
    +
    +
    +
    See Also:
    Constant Field Values
    +
    + + + + + + + + +
    +Constructor Detail
    + +

    +CAD

    +
    +public CAD(Properties params)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getCardInterface

    +
    +public CardInterface getCardInterface()
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/CardInterface.html b/javadoc/com/licel/jcardsim/io/CardInterface.html new file mode 100644 index 00000000..ce75b4cb --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/CardInterface.html @@ -0,0 +1,265 @@ + + + + + + + +CardInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.io +
    +Interface CardInterface

    +
    +
    All Known Subinterfaces:
    JavaCardInterface
    +
    +
    +
    All Known Implementing Classes:
    JavaCardRemoteClient, JavaxSmartCardInterface, Simulator
    +
    +
    +
    +
    public interface CardInterface
    + + +

    +Basic SmartCard Interface +

    + +

    +


    + +

    + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + byte[]getATR() + +
    +          Returns ATR
    + voidreset() + +
    +          Powerdown/Powerup
    + byte[]transmitCommand(byte[] data) + +
    +          Transmit APDU to previous selected applet
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +reset

    +
    +void reset()
    +
    +
    Powerdown/Powerup +

    +

    +
    +
    +
    +
    + +

    +getATR

    +
    +byte[] getATR()
    +
    +
    Returns ATR +

    +

    +
    +
    +
    +
    + +

    +transmitCommand

    +
    +byte[] transmitCommand(byte[] data)
    +
    +
    Transmit APDU to previous selected applet +

    +

    +
    Parameters:
    commandAPDU - command apdu +
    Returns:
    response apdu +
    Throws: +
    SystemException.ILLEGAL_USE - if appplet not selected before
    See Also:
    CommandAPDU, +ResponseAPDU
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/JavaCardInterface.html b/javadoc/com/licel/jcardsim/io/JavaCardInterface.html new file mode 100644 index 00000000..eba50e07 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/JavaCardInterface.html @@ -0,0 +1,428 @@ + + + + + + + +JavaCardInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.io +
    +Interface JavaCardInterface

    +
    +
    All Superinterfaces:
    CardInterface
    +
    +
    +
    All Known Implementing Classes:
    JavaCardRemoteClient, JavaxSmartCardInterface, Simulator
    +
    +
    +
    +
    public interface JavaCardInterface
    extends CardInterface
    + + +

    +Interface with JavaCard-specific functions +

    + +

    +


    + +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + AIDcreateApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Create + Applet instance in Simulator
    + AIDinstallApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDinstallApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDloadApplet(AID aid, + String appletClass) + +
    +          Load + Applet into Simulator
    + AIDloadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Load + Applet into Simulator
    + booleanselectApplet(AID aid) + +
    +          Select applet by it's AID + It's method must be called before start working with applet instance
    + + + + + + + +
    Methods inherited from interface com.licel.jcardsim.io.CardInterface
    getATR, reset, transmitCommand
    +  +

    + + + + + + + + +
    +Method Detail
    + +

    +loadApplet

    +
    +AID loadApplet(AID aid,
    +               String appletClassName,
    +               byte[] appletJarContents)
    +               throws SystemException
    +
    +
    Load + Applet into Simulator +

    +

    +
    +
    +
    +
    Parameters:
    aid - applet aid
    appletClassName - fully qualified applet class name Strin
    appletJarContents - contains a byte array containing a jar file with an applet and its dependent classes +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +loadApplet

    +
    +AID loadApplet(AID aid,
    +               String appletClass)
    +
    +
    Load + Applet into Simulator +

    +

    +
    +
    +
    +
    Parameters:
    aid - applet aid
    appletClassName - fully qualified applet class name Strin +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +createApplet

    +
    +AID createApplet(AID aid,
    +                 byte[] bArray,
    +                 short bOffset,
    +                 byte bLength)
    +                 throws SystemException
    +
    +
    Create + Applet instance in Simulator +

    +

    +
    +
    +
    +
    Parameters:
    aid - applet aid
    bArray - the array containing installation parameters
    bOffset - the starting offset in bArray
    bLength - the length in bytes of the parameter data in bArray +
    Returns:
    applet AID +
    Throws: +
    SystemException - if exception in Applet.install(..) + method occurs.
    +
    +
    +
    + +

    +installApplet

    +
    +AID installApplet(AID aid,
    +                  String appletClassName,
    +                  byte[] bArray,
    +                  short bOffset,
    +                  byte bLength)
    +                  throws SystemException
    +
    +
    Install + Applet into Simulator. + This method is equal to: + + loadApplet(...); + createApplet(...); + +

    +

    +
    +
    +
    +
    Parameters:
    aid - applet aid or null
    appletClassName - fully qualified applet class name Strin
    bArray - the array containing installation parameters
    bOffset - the starting offset in bArray
    bLength - the length in bytes of the parameter data in bArray +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +installApplet

    +
    +AID installApplet(AID aid,
    +                  String appletClassName,
    +                  byte[] appletJarContents,
    +                  byte[] bArray,
    +                  short bOffset,
    +                  byte bLength)
    +                  throws SystemException
    +
    +
    Install + Applet into Simulator. + This method is equal to: + + loadApplet(...); + createApplet(...); + +

    +

    +
    +
    +
    +
    Parameters:
    aid - applet aid or null
    appletClassName - fully qualified applet class name Strin
    appletJarContents - Contains a byte array containing a jar file with an applet and its dependent classes
    bArray - the array containing installation parameters
    bOffset - the starting offset in bArray
    bLength - the length in bytes of the parameter data in bArray +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +selectApplet

    +
    +boolean selectApplet(AID aid)
    +
    +
    Select applet by it's AID + It's method must be called before start working with applet instance +

    +

    +
    +
    +
    +
    Parameters:
    aid - appletId +
    Returns:
    true if applet selection success
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/JavaxSmartCardInterface.html b/javadoc/com/licel/jcardsim/io/JavaxSmartCardInterface.html new file mode 100644 index 00000000..4b383a69 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/JavaxSmartCardInterface.html @@ -0,0 +1,273 @@ + + + + + + + +JavaxSmartCardInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.io +
    +Class JavaxSmartCardInterface

    +
    +java.lang.Object
    +  extended by com.licel.jcardsim.base.Simulator
    +      extended by com.licel.jcardsim.io.JavaxSmartCardInterface
    +
    +
    +
    All Implemented Interfaces:
    CardInterface, JavaCardInterface
    +
    +
    +
    +
    public class JavaxSmartCardInterface
    extends Simulator
    + + +

    +Class with javacardx.smartcardio Command/Response support +

    + +

    +


    + +

    + + + + + + + + + + + +
    +Constructor Summary
    JavaxSmartCardInterface() + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    + javax.smartcardio.ResponseAPDUtransmitCommand(javax.smartcardio.CommandAPDU commandApdu) + +
    +          Wraper for the transmitCommand(byte[])
    + + + + + + + +
    Methods inherited from class com.licel.jcardsim.base.Simulator
    createApplet, getATR, installApplet, installApplet, installApplet, installApplet, loadApplet, loadApplet, loadApplet, reset, resetRuntime, selectApplet, transmitCommand
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +JavaxSmartCardInterface

    +
    +public JavaxSmartCardInterface()
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +transmitCommand

    +
    +public javax.smartcardio.ResponseAPDU transmitCommand(javax.smartcardio.CommandAPDU commandApdu)
    +
    +
    Wraper for the transmitCommand(byte[]) +

    +

    +
    Parameters:
    commandApdu - CommandAPDU +
    Returns:
    ResponseAPDU
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/class-use/CAD.html b/javadoc/com/licel/jcardsim/io/class-use/CAD.html new file mode 100644 index 00000000..216537ac --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/class-use/CAD.html @@ -0,0 +1,145 @@ + + + + + + + +Uses of Class com.licel.jcardsim.io.CAD (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Class
    com.licel.jcardsim.io.CAD

    +
    +No usage of com.licel.jcardsim.io.CAD +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/class-use/CardInterface.html b/javadoc/com/licel/jcardsim/io/class-use/CardInterface.html new file mode 100644 index 00000000..913ddf27 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/class-use/CardInterface.html @@ -0,0 +1,271 @@ + + + + + + + +Uses of Interface com.licel.jcardsim.io.CardInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Interface
    com.licel.jcardsim.io.CardInterface

    +
    + + + + + + + + + + + + + + + + + +
    +Packages that use CardInterface
    com.licel.jcardsim.base  
    com.licel.jcardsim.io  
    com.licel.jcardsim.remote  
    +  +

    + + + + + +
    +Uses of CardInterface in com.licel.jcardsim.base
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.base that implement CardInterface
    + classSimulator + +
    +          Main class for deal with Applets
    +  +

    + + + + + +
    +Uses of CardInterface in com.licel.jcardsim.io
    +  +

    + + + + + + + + + +
    Subinterfaces of CardInterface in com.licel.jcardsim.io
    + interfaceJavaCardInterface + +
    +          Interface with JavaCard-specific functions
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.io that implement CardInterface
    + classJavaxSmartCardInterface + +
    +          Class with javacardx.smartcardio Command/Response support
    +  +

    + + + + + + + + + +
    Methods in com.licel.jcardsim.io that return CardInterface
    + CardInterfaceCAD.getCardInterface() + +
    +           
    +  +

    + + + + + +
    +Uses of CardInterface in com.licel.jcardsim.remote
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.remote that implement CardInterface
    + classJavaCardRemoteClient + +
    +          RMI client
    +  +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/class-use/JavaCardInterface.html b/javadoc/com/licel/jcardsim/io/class-use/JavaCardInterface.html new file mode 100644 index 00000000..47e9f7d4 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/class-use/JavaCardInterface.html @@ -0,0 +1,266 @@ + + + + + + + +Uses of Interface com.licel.jcardsim.io.JavaCardInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Interface
    com.licel.jcardsim.io.JavaCardInterface

    +
    + + + + + + + + + + + + + + + + + + + + + +
    +Packages that use JavaCardInterface
    com.licel.jcardsim.base  
    com.licel.jcardsim.io  
    com.licel.jcardsim.remote  
    com.licel.jcardsim.smartcardio  
    +  +

    + + + + + +
    +Uses of JavaCardInterface in com.licel.jcardsim.base
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.base that implement JavaCardInterface
    + classSimulator + +
    +          Main class for deal with Applets
    +  +

    + + + + + +
    +Uses of JavaCardInterface in com.licel.jcardsim.io
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.io that implement JavaCardInterface
    + classJavaxSmartCardInterface + +
    +          Class with javacardx.smartcardio Command/Response support
    +  +

    + + + + + +
    +Uses of JavaCardInterface in com.licel.jcardsim.remote
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.remote that implement JavaCardInterface
    + classJavaCardRemoteClient + +
    +          RMI client
    +  +

    + + + + + +
    +Uses of JavaCardInterface in com.licel.jcardsim.smartcardio
    +  +

    + + + + + + + + +
    Constructors in com.licel.jcardsim.smartcardio with parameters of type JavaCardInterface
    JCSCard(JavaCardInterface cardInterface) + +
    +           
    +  +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/class-use/JavaxSmartCardInterface.html b/javadoc/com/licel/jcardsim/io/class-use/JavaxSmartCardInterface.html new file mode 100644 index 00000000..cfcf1e04 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/class-use/JavaxSmartCardInterface.html @@ -0,0 +1,145 @@ + + + + + + + +Uses of Class com.licel.jcardsim.io.JavaxSmartCardInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Class
    com.licel.jcardsim.io.JavaxSmartCardInterface

    +
    +No usage of com.licel.jcardsim.io.JavaxSmartCardInterface +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/package-frame.html b/javadoc/com/licel/jcardsim/io/package-frame.html new file mode 100644 index 00000000..06099150 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/package-frame.html @@ -0,0 +1,48 @@ + + + + + + + +com.licel.jcardsim.io (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + +com.licel.jcardsim.io + + + + +
    +Interfaces  + +
    +CardInterface +
    +JavaCardInterface
    + + + + + + +
    +Classes  + +
    +CAD +
    +JavaxSmartCardInterface
    + + + + diff --git a/javadoc/com/licel/jcardsim/io/package-summary.html b/javadoc/com/licel/jcardsim/io/package-summary.html new file mode 100644 index 00000000..33e895a2 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/package-summary.html @@ -0,0 +1,180 @@ + + + + + + + +com.licel.jcardsim.io (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package com.licel.jcardsim.io +

    + + + + + + + + + + + + + +
    +Interface Summary
    CardInterfaceBasic SmartCard Interface
    JavaCardInterfaceInterface with JavaCard-specific functions
    +  + +

    + + + + + + + + + + + + + +
    +Class Summary
    CADCard Acceptance Device (CAD)
    JavaxSmartCardInterfaceClass with javacardx.smartcardio Command/Response support
    +  + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/package-tree.html b/javadoc/com/licel/jcardsim/io/package-tree.html new file mode 100644 index 00000000..74248765 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/package-tree.html @@ -0,0 +1,164 @@ + + + + + + + +com.licel.jcardsim.io Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package com.licel.jcardsim.io +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/io/package-use.html b/javadoc/com/licel/jcardsim/io/package-use.html new file mode 100644 index 00000000..bc5417c2 --- /dev/null +++ b/javadoc/com/licel/jcardsim/io/package-use.html @@ -0,0 +1,246 @@ + + + + + + + +Uses of Package com.licel.jcardsim.io (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Package
    com.licel.jcardsim.io

    +
    + + + + + + + + + + + + + + + + + + + + + +
    +Packages that use com.licel.jcardsim.io
    com.licel.jcardsim.base  
    com.licel.jcardsim.io  
    com.licel.jcardsim.remote  
    com.licel.jcardsim.smartcardio  
    +  +

    + + + + + + + + + + + +
    +Classes in com.licel.jcardsim.io used by com.licel.jcardsim.base
    CardInterface + +
    +          Basic SmartCard Interface
    JavaCardInterface + +
    +          Interface with JavaCard-specific functions
    +  +

    + + + + + + + + + + + +
    +Classes in com.licel.jcardsim.io used by com.licel.jcardsim.io
    CardInterface + +
    +          Basic SmartCard Interface
    JavaCardInterface + +
    +          Interface with JavaCard-specific functions
    +  +

    + + + + + + + + + + + +
    +Classes in com.licel.jcardsim.io used by com.licel.jcardsim.remote
    CardInterface + +
    +          Basic SmartCard Interface
    JavaCardInterface + +
    +          Interface with JavaCard-specific functions
    +  +

    + + + + + + + + +
    +Classes in com.licel.jcardsim.io used by com.licel.jcardsim.smartcardio
    JavaCardInterface + +
    +          Interface with JavaCard-specific functions
    +  +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/JavaCardRemoteClient.html b/javadoc/com/licel/jcardsim/remote/JavaCardRemoteClient.html new file mode 100644 index 00000000..f26dfd43 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/JavaCardRemoteClient.html @@ -0,0 +1,555 @@ + + + + + + + +JavaCardRemoteClient (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.remote +
    +Class JavaCardRemoteClient

    +
    +java.lang.Object
    +  extended by com.licel.jcardsim.remote.JavaCardRemoteClient
    +
    +
    +
    All Implemented Interfaces:
    CardInterface, JavaCardInterface
    +
    +
    +
    +
    public class JavaCardRemoteClient
    extends Object
    implements JavaCardInterface
    + + +

    +RMI client +

    + +

    +


    + +

    + + + + + + + + + + + +
    +Constructor Summary
    JavaCardRemoteClient(String serverHost, + int serverIp) + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + AIDcreateApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Create + Applet instance in Simulator
    + byte[]getATR() + +
    +          Returns ATR
    + AIDinstallApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDinstallApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDloadApplet(AID aid, + String appletClassName) + +
    +          Load + Applet into Simulator
    + AIDloadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Load + Applet into Simulator
    + voidreset() + +
    +          Powerdown/Powerup
    + booleanselectApplet(AID aid) + +
    +          Select applet by it's AID + It's method must be called before start working with applet instance
    + byte[]transmitCommand(byte[] data) + +
    +          Transmit APDU to previous selected applet
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +JavaCardRemoteClient

    +
    +public JavaCardRemoteClient(String serverHost,
    +                            int serverIp)
    +                     throws RemoteException,
    +                            NotBoundException
    +
    +
    + +
    Throws: +
    RemoteException +
    NotBoundException
    +
    + + + + + + + + +
    +Method Detail
    + +

    +loadApplet

    +
    +public AID loadApplet(AID aid,
    +                      String appletClassName)
    +               throws SystemException
    +
    +
    Description copied from interface: JavaCardInterface
    +
    Load + Applet into Simulator +

    +

    +
    Specified by:
    loadApplet in interface JavaCardInterface
    +
    +
    +
    Parameters:
    aid - applet aid +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +loadApplet

    +
    +public AID loadApplet(AID aid,
    +                      String appletClassName,
    +                      byte[] appletJarContents)
    +               throws SystemException
    +
    +
    Description copied from interface: JavaCardInterface
    +
    Load + Applet into Simulator +

    +

    +
    Specified by:
    loadApplet in interface JavaCardInterface
    +
    +
    +
    Parameters:
    aid - applet aid
    appletClassName - fully qualified applet class name Strin
    appletJarContents - contains a byte array containing a jar file with an applet and its dependent classes +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +createApplet

    +
    +public AID createApplet(AID aid,
    +                        byte[] bArray,
    +                        short bOffset,
    +                        byte bLength)
    +                 throws SystemException
    +
    +
    Description copied from interface: JavaCardInterface
    +
    Create + Applet instance in Simulator +

    +

    +
    Specified by:
    createApplet in interface JavaCardInterface
    +
    +
    +
    Parameters:
    aid - applet aid
    bArray - the array containing installation parameters
    bOffset - the starting offset in bArray
    bLength - the length in bytes of the parameter data in bArray +
    Returns:
    applet AID +
    Throws: +
    SystemException - if exception in Applet.install(..) + method occurs.
    +
    +
    +
    + +

    +installApplet

    +
    +public AID installApplet(AID aid,
    +                         String appletClassName,
    +                         byte[] bArray,
    +                         short bOffset,
    +                         byte bLength)
    +                  throws SystemException
    +
    +
    Description copied from interface: JavaCardInterface
    +
    Install + Applet into Simulator. + This method is equal to: + + loadApplet(...); + createApplet(...); + +

    +

    +
    Specified by:
    installApplet in interface JavaCardInterface
    +
    +
    +
    Parameters:
    aid - applet aid or null
    appletClassName - fully qualified applet class name Strin
    bArray - the array containing installation parameters
    bOffset - the starting offset in bArray
    bLength - the length in bytes of the parameter data in bArray +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +installApplet

    +
    +public AID installApplet(AID aid,
    +                         String appletClassName,
    +                         byte[] appletJarContents,
    +                         byte[] bArray,
    +                         short bOffset,
    +                         byte bLength)
    +                  throws SystemException
    +
    +
    Description copied from interface: JavaCardInterface
    +
    Install + Applet into Simulator. + This method is equal to: + + loadApplet(...); + createApplet(...); + +

    +

    +
    Specified by:
    installApplet in interface JavaCardInterface
    +
    +
    +
    Parameters:
    aid - applet aid or null
    appletClassName - fully qualified applet class name Strin
    appletJarContents - Contains a byte array containing a jar file with an applet and its dependent classes
    bArray - the array containing installation parameters
    bOffset - the starting offset in bArray
    bLength - the length in bytes of the parameter data in bArray +
    Returns:
    applet AID +
    Throws: +
    SystemException - if appletClass not instanceof + javacard.framework.Applet
    +
    +
    +
    + +

    +selectApplet

    +
    +public boolean selectApplet(AID aid)
    +
    +
    Description copied from interface: JavaCardInterface
    +
    Select applet by it's AID + It's method must be called before start working with applet instance +

    +

    +
    Specified by:
    selectApplet in interface JavaCardInterface
    +
    +
    +
    Parameters:
    aid - appletId +
    Returns:
    true if applet selection success
    +
    +
    +
    + +

    +getATR

    +
    +public byte[] getATR()
    +
    +
    Description copied from interface: CardInterface
    +
    Returns ATR +

    +

    +
    Specified by:
    getATR in interface CardInterface
    +
    +
    +
    +
    +
    +
    + +

    +transmitCommand

    +
    +public byte[] transmitCommand(byte[] data)
    +
    +
    Description copied from interface: CardInterface
    +
    Transmit APDU to previous selected applet +

    +

    +
    Specified by:
    transmitCommand in interface CardInterface
    +
    +
    + +
    Returns:
    response apdu
    See Also:
    CommandAPDU, +ResponseAPDU
    +
    +
    +
    + +

    +reset

    +
    +public void reset()
    +
    +
    Description copied from interface: CardInterface
    +
    Powerdown/Powerup +

    +

    +
    Specified by:
    reset in interface CardInterface
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/JavaCardRemoteInterface.html b/javadoc/com/licel/jcardsim/remote/JavaCardRemoteInterface.html new file mode 100644 index 00000000..2c18d272 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/JavaCardRemoteInterface.html @@ -0,0 +1,421 @@ + + + + + + + +JavaCardRemoteInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.remote +
    +Interface JavaCardRemoteInterface

    +
    +
    All Superinterfaces:
    Remote
    +
    +
    +
    All Known Implementing Classes:
    JavaCardRemoteServer
    +
    +
    +
    +
    public interface JavaCardRemoteInterface
    extends Remote
    + + +

    +RMI Wrapper for the JavaCardInterface +

    + +

    +


    + +

    + + + + + + + + + + + +
    +Field Summary
    +static StringRMI_SERVER_ID + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + SerializableAIDcreateApplet(SerializableAID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + byte[]getATR() + +
    +           
    + SerializableAIDloadApplet(SerializableAID aid, + String appletClassName) + +
    +           
    + SerializableAIDloadApplet(SerializableAID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    + voidreset() + +
    +           
    + booleanselectApplet(SerializableAID aid) + +
    +           
    + byte[]transmitCommand(byte[] data) + +
    +           
    +  +

    + + + + + + + + +
    +Field Detail
    + +

    +RMI_SERVER_ID

    +
    +static final String RMI_SERVER_ID
    +
    +
    +
    See Also:
    Constant Field Values
    +
    + + + + + + + + +
    +Method Detail
    + +

    +loadApplet

    +
    +SerializableAID loadApplet(SerializableAID aid,
    +                           String appletClassName)
    +                           throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +loadApplet

    +
    +SerializableAID loadApplet(SerializableAID aid,
    +                           String appletClassName,
    +                           byte[] appletJarContents)
    +                           throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +createApplet

    +
    +SerializableAID createApplet(SerializableAID aid,
    +                             byte[] bArray,
    +                             short bOffset,
    +                             byte bLength)
    +                             throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +transmitCommand

    +
    +byte[] transmitCommand(byte[] data)
    +                       throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +selectApplet

    +
    +boolean selectApplet(SerializableAID aid)
    +                     throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +reset

    +
    +void reset()
    +           throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +getATR

    +
    +byte[] getATR()
    +              throws RemoteException
    +
    +
    +
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/JavaCardRemoteServer.html b/javadoc/com/licel/jcardsim/remote/JavaCardRemoteServer.html new file mode 100644 index 00000000..2e613907 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/JavaCardRemoteServer.html @@ -0,0 +1,533 @@ + + + + + + + +JavaCardRemoteServer (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.remote +
    +Class JavaCardRemoteServer

    +
    +java.lang.Object
    +  extended by java.rmi.server.RemoteObject
    +      extended by java.rmi.server.RemoteServer
    +          extended by java.rmi.server.UnicastRemoteObject
    +              extended by com.licel.jcardsim.remote.JavaCardRemoteServer
    +
    +
    +
    All Implemented Interfaces:
    JavaCardRemoteInterface, Serializable, Remote
    +
    +
    +
    +
    public class JavaCardRemoteServer
    extends UnicastRemoteObject
    implements JavaCardRemoteInterface
    + + +

    +RMI Server +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + +
    +Field Summary
    + + + + + + + +
    Fields inherited from class java.rmi.server.RemoteObject
    ref
    + + + + + + + +
    Fields inherited from interface com.licel.jcardsim.remote.JavaCardRemoteInterface
    RMI_SERVER_ID
    +  + + + + + + + + + + +
    +Constructor Summary
    JavaCardRemoteServer(String host, + int port) + +
    +           
    +  + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +Method Summary
    + SerializableAIDcreateApplet(SerializableAID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Imlementation
    + byte[]getATR() + +
    +          Imlementation
    + SerializableAIDloadApplet(SerializableAID aid, + String appletClassName) + +
    +          Imlementation
    + SerializableAIDloadApplet(SerializableAID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Imlementation
    +static voidmain(String[] args) + +
    +           
    + voidreset() + +
    +          Imlementation
    + booleanselectApplet(SerializableAID aid) + +
    +          Imlementation
    + byte[]transmitCommand(byte[] data) + +
    +          Imlementation
    + + + + + + + +
    Methods inherited from class java.rmi.server.UnicastRemoteObject
    clone, exportObject, exportObject, exportObject, unexportObject
    + + + + + + + +
    Methods inherited from class java.rmi.server.RemoteServer
    getClientHost, getLog, setLog
    + + + + + + + +
    Methods inherited from class java.rmi.server.RemoteObject
    equals, getRef, hashCode, toString, toStub
    + + + + + + + +
    Methods inherited from class java.lang.Object
    finalize, getClass, notify, notifyAll, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +JavaCardRemoteServer

    +
    +public JavaCardRemoteServer(String host,
    +                            int port)
    +                     throws RemoteException
    +
    +
    + +
    Throws: +
    RemoteException
    +
    + + + + + + + + +
    +Method Detail
    + +

    +main

    +
    +public static void main(String[] args)
    +                 throws Exception
    +
    +
    +
    +
    +
    + +
    Throws: +
    Exception
    +
    +
    +
    + +

    +loadApplet

    +
    +public SerializableAID loadApplet(SerializableAID aid,
    +                                  String appletClassName)
    +                           throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    loadApplet in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +loadApplet

    +
    +public SerializableAID loadApplet(SerializableAID aid,
    +                                  String appletClassName,
    +                                  byte[] appletJarContents)
    +                           throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    loadApplet in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +createApplet

    +
    +public SerializableAID createApplet(SerializableAID aid,
    +                                    byte[] bArray,
    +                                    short bOffset,
    +                                    byte bLength)
    +                             throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    createApplet in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +transmitCommand

    +
    +public byte[] transmitCommand(byte[] data)
    +                       throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    transmitCommand in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +selectApplet

    +
    +public boolean selectApplet(SerializableAID aid)
    +                     throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    selectApplet in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +reset

    +
    +public void reset()
    +           throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    reset in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    +
    + +

    +getATR

    +
    +public byte[] getATR()
    +              throws RemoteException
    +
    +
    Imlementation +

    +

    +
    Specified by:
    getATR in interface JavaCardRemoteInterface
    +
    +
    + +
    Throws: +
    RemoteException
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/SerializableAID.html b/javadoc/com/licel/jcardsim/remote/SerializableAID.html new file mode 100644 index 00000000..7a1d670d --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/SerializableAID.html @@ -0,0 +1,279 @@ + + + + + + + +SerializableAID (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + + + + + +
    + +
    + + + +
    + +

    + +com.licel.jcardsim.remote +
    +Class SerializableAID

    +
    +java.lang.Object
    +  extended by com.licel.jcardsim.remote.SerializableAID
    +
    +
    +
    All Implemented Interfaces:
    Serializable
    +
    +
    +
    +
    public class SerializableAID
    extends Object
    implements Serializable
    + + +

    +Serializable AID container for the RMI calls +

    + +

    +

    +
    See Also:
    Serialized Form
    +
    + +

    + + + + + + + + + + + + + + +
    +Constructor Summary
    SerializableAID() + +
    +           
    SerializableAID(AID aid) + +
    +           
    +  + + + + + + + + + + + +
    +Method Summary
    + AIDgetAID() + +
    +           
    + + + + + + + +
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    +  +

    + + + + + + + + +
    +Constructor Detail
    + +

    +SerializableAID

    +
    +public SerializableAID()
    +
    +
    +
    + +

    +SerializableAID

    +
    +public SerializableAID(AID aid)
    +
    +
    + + + + + + + + +
    +Method Detail
    + +

    +getAID

    +
    +public AID getAID()
    +
    +
    +
    +
    +
    +
    +
    +
    + +
    + + + + + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteClient.html b/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteClient.html new file mode 100644 index 00000000..4a77cee6 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteClient.html @@ -0,0 +1,145 @@ + + + + + + + +Uses of Class com.licel.jcardsim.remote.JavaCardRemoteClient (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Class
    com.licel.jcardsim.remote.JavaCardRemoteClient

    +
    +No usage of com.licel.jcardsim.remote.JavaCardRemoteClient +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteInterface.html b/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteInterface.html new file mode 100644 index 00000000..4b690d74 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteInterface.html @@ -0,0 +1,181 @@ + + + + + + + +Uses of Interface com.licel.jcardsim.remote.JavaCardRemoteInterface (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Interface
    com.licel.jcardsim.remote.JavaCardRemoteInterface

    +
    + + + + + + + + + +
    +Packages that use JavaCardRemoteInterface
    com.licel.jcardsim.remote  
    +  +

    + + + + + +
    +Uses of JavaCardRemoteInterface in com.licel.jcardsim.remote
    +  +

    + + + + + + + + + +
    Classes in com.licel.jcardsim.remote that implement JavaCardRemoteInterface
    + classJavaCardRemoteServer + +
    +          RMI Server
    +  +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteServer.html b/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteServer.html new file mode 100644 index 00000000..2f6b1b00 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/class-use/JavaCardRemoteServer.html @@ -0,0 +1,145 @@ + + + + + + + +Uses of Class com.licel.jcardsim.remote.JavaCardRemoteServer (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Class
    com.licel.jcardsim.remote.JavaCardRemoteServer

    +
    +No usage of com.licel.jcardsim.remote.JavaCardRemoteServer +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/class-use/SerializableAID.html b/javadoc/com/licel/jcardsim/remote/class-use/SerializableAID.html new file mode 100644 index 00000000..59e9e2db --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/class-use/SerializableAID.html @@ -0,0 +1,317 @@ + + + + + + + +Uses of Class com.licel.jcardsim.remote.SerializableAID (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Class
    com.licel.jcardsim.remote.SerializableAID

    +
    + + + + + + + + + +
    +Packages that use SerializableAID
    com.licel.jcardsim.remote  
    +  +

    + + + + + +
    +Uses of SerializableAID in com.licel.jcardsim.remote
    +  +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Methods in com.licel.jcardsim.remote that return SerializableAID
    + SerializableAIDJavaCardRemoteServer.createApplet(SerializableAID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Imlementation
    + SerializableAIDJavaCardRemoteInterface.createApplet(SerializableAID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + SerializableAIDJavaCardRemoteServer.loadApplet(SerializableAID aid, + String appletClassName) + +
    +          Imlementation
    + SerializableAIDJavaCardRemoteInterface.loadApplet(SerializableAID aid, + String appletClassName) + +
    +           
    + SerializableAIDJavaCardRemoteServer.loadApplet(SerializableAID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Imlementation
    + SerializableAIDJavaCardRemoteInterface.loadApplet(SerializableAID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    +  +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Methods in com.licel.jcardsim.remote with parameters of type SerializableAID
    + SerializableAIDJavaCardRemoteServer.createApplet(SerializableAID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Imlementation
    + SerializableAIDJavaCardRemoteInterface.createApplet(SerializableAID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + SerializableAIDJavaCardRemoteServer.loadApplet(SerializableAID aid, + String appletClassName) + +
    +          Imlementation
    + SerializableAIDJavaCardRemoteInterface.loadApplet(SerializableAID aid, + String appletClassName) + +
    +           
    + SerializableAIDJavaCardRemoteServer.loadApplet(SerializableAID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Imlementation
    + SerializableAIDJavaCardRemoteInterface.loadApplet(SerializableAID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    + booleanJavaCardRemoteServer.selectApplet(SerializableAID aid) + +
    +          Imlementation
    + booleanJavaCardRemoteInterface.selectApplet(SerializableAID aid) + +
    +           
    +  +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/package-frame.html b/javadoc/com/licel/jcardsim/remote/package-frame.html new file mode 100644 index 00000000..7938ea12 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/package-frame.html @@ -0,0 +1,48 @@ + + + + + + + +com.licel.jcardsim.remote (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + +com.licel.jcardsim.remote + + + + +
    +Interfaces  + +
    +JavaCardRemoteInterface
    + + + + + + +
    +Classes  + +
    +JavaCardRemoteClient +
    +JavaCardRemoteServer +
    +SerializableAID
    + + + + diff --git a/javadoc/com/licel/jcardsim/remote/package-summary.html b/javadoc/com/licel/jcardsim/remote/package-summary.html new file mode 100644 index 00000000..21bf2d35 --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/package-summary.html @@ -0,0 +1,180 @@ + + + + + + + +com.licel.jcardsim.remote (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +

    +Package com.licel.jcardsim.remote +

    + + + + + + + + + +
    +Interface Summary
    JavaCardRemoteInterfaceRMI Wrapper for the JavaCardInterface
    +  + +

    + + + + + + + + + + + + + + + + + +
    +Class Summary
    JavaCardRemoteClientRMI client
    JavaCardRemoteServerRMI Server
    SerializableAIDSerializable AID container for the RMI calls
    +  + +

    +

    +
    +
    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/package-tree.html b/javadoc/com/licel/jcardsim/remote/package-tree.html new file mode 100644 index 00000000..0f9e0a1c --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/package-tree.html @@ -0,0 +1,171 @@ + + + + + + + +com.licel.jcardsim.remote Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Hierarchy For Package com.licel.jcardsim.remote +

    +
    +
    +
    Package Hierarchies:
    All Packages
    +
    +

    +Class Hierarchy +

    + +

    +Interface Hierarchy +

    + +
    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/remote/package-use.html b/javadoc/com/licel/jcardsim/remote/package-use.html new file mode 100644 index 00000000..62f538cc --- /dev/null +++ b/javadoc/com/licel/jcardsim/remote/package-use.html @@ -0,0 +1,177 @@ + + + + + + + +Uses of Package com.licel.jcardsim.remote (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) + + + + + + + + + + + + +
    + + + + + + + + + + + + + + + +
    + +
    + + + +
    +
    +

    +Uses of Package
    com.licel.jcardsim.remote

    +
    + + + + + + + + + +
    +Packages that use com.licel.jcardsim.remote
    com.licel.jcardsim.remote  
    +  +

    + + + + + + + + + + + +
    +Classes in com.licel.jcardsim.remote used by com.licel.jcardsim.remote
    JavaCardRemoteInterface + +
    +          RMI Wrapper for the JavaCardInterface
    SerializableAID + +
    +          Serializable AID container for the RMI calls
    +  +

    +


    + + + + + + + + + + + + + + + +
    +  +
    + + + +
    +  + + diff --git a/javadoc/com/licel/jcardsim/samples/HelloWorldApplet.html b/javadoc/com/licel/jcardsim/samples/HelloWorldApplet.html index 83b1e7f5..7a26916d 100644 --- a/javadoc/com/licel/jcardsim/samples/HelloWorldApplet.html +++ b/javadoc/com/licel/jcardsim/samples/HelloWorldApplet.html @@ -2,13 +2,13 @@ - + HelloWorldApplet (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/samples/class-use/HelloWorldApplet.html b/javadoc/com/licel/jcardsim/samples/class-use/HelloWorldApplet.html index 4eed56d3..d9f4a3a4 100644 --- a/javadoc/com/licel/jcardsim/samples/class-use/HelloWorldApplet.html +++ b/javadoc/com/licel/jcardsim/samples/class-use/HelloWorldApplet.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.samples.HelloWorldApplet (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/samples/package-frame.html b/javadoc/com/licel/jcardsim/samples/package-frame.html index b33eceba..18a58ff3 100644 --- a/javadoc/com/licel/jcardsim/samples/package-frame.html +++ b/javadoc/com/licel/jcardsim/samples/package-frame.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.samples (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/samples/package-summary.html b/javadoc/com/licel/jcardsim/samples/package-summary.html index 51dfb87a..a8050f16 100644 --- a/javadoc/com/licel/jcardsim/samples/package-summary.html +++ b/javadoc/com/licel/jcardsim/samples/package-summary.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.samples (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -56,8 +56,8 @@ PREV PACKAGE  - NEXT PACKAGEPREV PACKAGE  + NEXT PACKAGE
    FRAMES    NO FRAMES   @@ -129,8 +129,8 @@

    PREV PACKAGE  - NEXT PACKAGEPREV PACKAGE  + NEXT PACKAGE FRAMES    NO FRAMES   diff --git a/javadoc/com/licel/jcardsim/samples/package-tree.html b/javadoc/com/licel/jcardsim/samples/package-tree.html index 57a82ea2..359935bc 100644 --- a/javadoc/com/licel/jcardsim/samples/package-tree.html +++ b/javadoc/com/licel/jcardsim/samples/package-tree.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.samples Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -56,8 +56,8 @@ PREV  - NEXTPREV  + NEXT FRAMES    NO FRAMES   @@ -127,8 +127,8 @@

    PREV  - NEXTPREV  + NEXT FRAMES    NO FRAMES   diff --git a/javadoc/com/licel/jcardsim/samples/package-use.html b/javadoc/com/licel/jcardsim/samples/package-use.html index 4ba9cbad..574ddc06 100644 --- a/javadoc/com/licel/jcardsim/samples/package-use.html +++ b/javadoc/com/licel/jcardsim/samples/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package com.licel.jcardsim.samples (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/JCSCard.html b/javadoc/com/licel/jcardsim/smartcardio/JCSCard.html index cc324f1b..928d94c2 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/JCSCard.html +++ b/javadoc/com/licel/jcardsim/smartcardio/JCSCard.html @@ -2,13 +2,13 @@ - + JCSCard (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -120,7 +120,7 @@

    Constructor Summary -JCSCard() +JCSCard(JavaCardInterface cardInterface)
                @@ -165,8 +165,7 @@

    getATR()
    -          Returns ATR configured by system property com.licel.jcardsim.smartcardio.ATR - Default ATR - 3BFA1800008131FE454A434F5033315632333298. +            @@ -224,10 +223,10 @@

    -

    +

    JCSCard

    -public JCSCard()
    +public JCSCard(JavaCardInterface cardInterface)
    @@ -246,9 +245,6 @@

     public javax.smartcardio.ATR getATR()
    -
    Returns ATR configured by system property com.licel.jcardsim.smartcardio.ATR - Default ATR - 3BFA1800008131FE454A434F5033315632333298. -

    Specified by:
    getATR in class javax.smartcardio.Card
    diff --git a/javadoc/com/licel/jcardsim/smartcardio/JCSCardChannel.html b/javadoc/com/licel/jcardsim/smartcardio/JCSCardChannel.html index 74b4ea70..fd5d341d 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/JCSCardChannel.html +++ b/javadoc/com/licel/jcardsim/smartcardio/JCSCardChannel.html @@ -2,13 +2,13 @@ - + JCSCardChannel (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/JCSCardTerminals.html b/javadoc/com/licel/jcardsim/smartcardio/JCSCardTerminals.html index 85b0a576..fa90e53d 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/JCSCardTerminals.html +++ b/javadoc/com/licel/jcardsim/smartcardio/JCSCardTerminals.html @@ -2,13 +2,13 @@ - + JCSCardTerminals (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/JCSFactory.html b/javadoc/com/licel/jcardsim/smartcardio/JCSFactory.html index 2ff40175..521a2322 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/JCSFactory.html +++ b/javadoc/com/licel/jcardsim/smartcardio/JCSFactory.html @@ -2,13 +2,13 @@ - + JCSFactory (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/JCSTerminal.html b/javadoc/com/licel/jcardsim/smartcardio/JCSTerminal.html index 7bdc94f6..4cfc2b0e 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/JCSTerminal.html +++ b/javadoc/com/licel/jcardsim/smartcardio/JCSTerminal.html @@ -2,13 +2,13 @@ - + JCSTerminal (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/JCardSimProvider.html b/javadoc/com/licel/jcardsim/smartcardio/JCardSimProvider.html index 607cf114..196e3763 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/JCardSimProvider.html +++ b/javadoc/com/licel/jcardsim/smartcardio/JCardSimProvider.html @@ -2,13 +2,13 @@ - + JCardSimProvider (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCard.html b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCard.html index 02b91ce5..4fbe7773 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCard.html +++ b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCard.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.smartcardio.JCSCard (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardChannel.html b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardChannel.html index e5348daa..ff1588ae 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardChannel.html +++ b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardChannel.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.smartcardio.JCSCardChannel (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardTerminals.html b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardTerminals.html index 9208249f..af267350 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardTerminals.html +++ b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSCardTerminals.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.smartcardio.JCSCardTerminals (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSFactory.html b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSFactory.html index 06352e49..d2187021 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSFactory.html +++ b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSFactory.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.smartcardio.JCSFactory (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSTerminal.html b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSTerminal.html index 2087e500..f5bad0f5 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSTerminal.html +++ b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCSTerminal.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.smartcardio.JCSTerminal (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCardSimProvider.html b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCardSimProvider.html index d38eb786..3100e29a 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/class-use/JCardSimProvider.html +++ b/javadoc/com/licel/jcardsim/smartcardio/class-use/JCardSimProvider.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.smartcardio.JCardSimProvider (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/package-frame.html b/javadoc/com/licel/jcardsim/smartcardio/package-frame.html index bcd7753f..022e0e6b 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/package-frame.html +++ b/javadoc/com/licel/jcardsim/smartcardio/package-frame.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.smartcardio (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/smartcardio/package-summary.html b/javadoc/com/licel/jcardsim/smartcardio/package-summary.html index c5bcec69..40f0eb9b 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/package-summary.html +++ b/javadoc/com/licel/jcardsim/smartcardio/package-summary.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.smartcardio (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -56,7 +56,7 @@ PREV PACKAGE  + PREV PACKAGE   NEXT PACKAGE FRAMES   @@ -149,7 +149,7 @@

    PREV PACKAGE  + PREV PACKAGE   NEXT PACKAGE FRAMES   diff --git a/javadoc/com/licel/jcardsim/smartcardio/package-tree.html b/javadoc/com/licel/jcardsim/smartcardio/package-tree.html index bd5cdb33..9a393d0b 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/package-tree.html +++ b/javadoc/com/licel/jcardsim/smartcardio/package-tree.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.smartcardio Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -56,7 +56,7 @@ PREV  + PREV   NEXT FRAMES   @@ -144,7 +144,7 @@

    PREV  + PREV   NEXT FRAMES   diff --git a/javadoc/com/licel/jcardsim/smartcardio/package-use.html b/javadoc/com/licel/jcardsim/smartcardio/package-use.html index 94e8b20a..de88acde 100644 --- a/javadoc/com/licel/jcardsim/smartcardio/package-use.html +++ b/javadoc/com/licel/jcardsim/smartcardio/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package com.licel.jcardsim.smartcardio (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/utils/APDUScriptTool.html b/javadoc/com/licel/jcardsim/utils/APDUScriptTool.html index 0f900b75..faa9c333 100644 --- a/javadoc/com/licel/jcardsim/utils/APDUScriptTool.html +++ b/javadoc/com/licel/jcardsim/utils/APDUScriptTool.html @@ -2,13 +2,13 @@ - + APDUScriptTool (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/utils/class-use/APDUScriptTool.html b/javadoc/com/licel/jcardsim/utils/class-use/APDUScriptTool.html index 4ed146b0..1a5d49dd 100644 --- a/javadoc/com/licel/jcardsim/utils/class-use/APDUScriptTool.html +++ b/javadoc/com/licel/jcardsim/utils/class-use/APDUScriptTool.html @@ -2,13 +2,13 @@ - + Uses of Class com.licel.jcardsim.utils.APDUScriptTool (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/utils/package-frame.html b/javadoc/com/licel/jcardsim/utils/package-frame.html index 77747a7a..606bb56d 100644 --- a/javadoc/com/licel/jcardsim/utils/package-frame.html +++ b/javadoc/com/licel/jcardsim/utils/package-frame.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.utils (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/com/licel/jcardsim/utils/package-summary.html b/javadoc/com/licel/jcardsim/utils/package-summary.html index 5cdcd1ba..714a530a 100644 --- a/javadoc/com/licel/jcardsim/utils/package-summary.html +++ b/javadoc/com/licel/jcardsim/utils/package-summary.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.utils (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -57,7 +57,7 @@  PREV PACKAGE  - NEXT PACKAGENEXT PACKAGE FRAMES    NO FRAMES   @@ -130,7 +130,7 @@

     PREV PACKAGE  - NEXT PACKAGENEXT PACKAGE FRAMES    NO FRAMES   diff --git a/javadoc/com/licel/jcardsim/utils/package-tree.html b/javadoc/com/licel/jcardsim/utils/package-tree.html index f449ed9a..36b8d196 100644 --- a/javadoc/com/licel/jcardsim/utils/package-tree.html +++ b/javadoc/com/licel/jcardsim/utils/package-tree.html @@ -2,13 +2,13 @@ - + com.licel.jcardsim.utils Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -57,7 +57,7 @@  PREV  - NEXTNEXT FRAMES    NO FRAMES   @@ -126,7 +126,7 @@

     PREV  - NEXTNEXT FRAMES    NO FRAMES   diff --git a/javadoc/com/licel/jcardsim/utils/package-use.html b/javadoc/com/licel/jcardsim/utils/package-use.html index 84c49ae3..532e5309 100644 --- a/javadoc/com/licel/jcardsim/utils/package-use.html +++ b/javadoc/com/licel/jcardsim/utils/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package com.licel.jcardsim.utils (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/constant-values.html b/javadoc/constant-values.html index 4b28d348..244eca65 100644 --- a/javadoc/constant-values.html +++ b/javadoc/constant-values.html @@ -2,13 +2,13 @@ - + Constant Field Values (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -128,103 +128,25 @@

    - + - - - - - - -
    com.licel.jcardsim.samples.odSample.packageA.Acom.licel.jcardsim.io.CAD
    + public static final byteA_CLA-64
    - -

    - -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    com.licel.jcardsim.samples.photocard.PhotoCard
    -public static final shortINVALID_ARGUMENT24579
    -public static final shortINVALID_PHOTO_ID24578
    -public static final shortMAX_BUFFER_BYTES96
    -public static final shortMAX_PHOTO_COUNT4
    -public static final shortMAX_SIZE32767
    -public static final shortNO_PHOTO_STORED24577
    -public static final shortNO_SPACE_AVAILABLE24576
    - -

    - -

    - - - - - - - - - - - - - - + + - - - + + + - - - + + + @@ -236,43 +158,13 @@

    com.licel.jcardsim.samples.RMIDemo.Purse
    -public static final shortBAD_ARGUMENT24578
    -public static final shortMAX_AMOUNT400INTERNAL0
    -public static final shortOVERFLOW24577 +public static final byteJAVAX_SMARTCARDIO2
    -public static final shortUNDERFLOW24576 +public static final byteRMI1
    - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - + + + diff --git a/javadoc/deprecated-list.html b/javadoc/deprecated-list.html index 0d10926c..bc7212b1 100644 --- a/javadoc/deprecated-list.html +++ b/javadoc/deprecated-list.html @@ -2,13 +2,13 @@ - + Deprecated List (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/help-doc.html b/javadoc/help-doc.html index c212daaa..6bf0e493 100644 --- a/javadoc/help-doc.html +++ b/javadoc/help-doc.html @@ -2,13 +2,13 @@ - + API Help (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/index-all.html b/javadoc/index-all.html index 40c3ae0e..9d8c471c 100644 --- a/javadoc/index-all.html +++ b/javadoc/index-all.html @@ -2,13 +2,13 @@ - + Index (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -86,23 +86,12 @@
    a - Variable in class com.licel.jcardsim.crypto.ECKeyImpl
      -
    A - Class in com.licel.jcardsim.samples.odSample.packageA
    package AID 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x01 - applet AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x01 0x01 - - This applet used to demonstrate object deletion mechanism and also to - monitor memory usage as other packages/applets get added/deleted
    A_CLA - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
     
    abortTransaction() - Static method in class com.licel.jcardsim.base.SimulatorSystem
    Aborts the atomic transaction.
    abortTransaction() - Static method in class javacard.framework.JCSystem
    Aborts the atomic transaction. -
    AccountAccessor - Class in com.licel.jcardsim.samples.ChannelsDemo
    This applet keeps track of the account information for a - fictional wireless device connecting to a network service.
    addRecord(byte[]) - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.ParametersFile -
    Add (append) a new record to the file.
    addService(Service, byte) - Method in class javacard.framework.service.Dispatcher
      @@ -376,9 +365,6 @@
    AsymmetricSignatureImpl - Class in com.licel.jcardsim.crypto
     
    AsymmetricSignatureImpl(byte) - Constructor for class com.licel.jcardsim.crypto.AsymmetricSignatureImpl
      -
    ATreeNode - Class in com.licel.jcardsim.samples.odSample.packageA
    Class represents nodes of a binary tree.
    ATreeNode(short, short) - -Constructor for class com.licel.jcardsim.samples.odSample.packageA.ATreeNode -
    Constructor.

    @@ -387,24 +373,12 @@
    b - Variable in class com.licel.jcardsim.crypto.ECKeyImpl
      -
    B - Class in com.licel.jcardsim.samples.odSample.packageB
    package AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 - applet AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 0x01 - - Applet used to demonstrate applet deletion and package deletion.
    BAD_ARGUMENT - -Static variable in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    BAD_ARGUMENT - -Static variable in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
     
    BAD_LENGTH - Static variable in exception javacard.framework.APDUException
    This reason code is used by the APDU.setOutgoingLength() method to indicate that the length parameter is greater that 256 or if non BLOCK CHAINED data transfer is requested and len is greater than (IFSD-2), where IFSD is the Outgoing Block Size. -
    BApp1AID - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
     
    BasicService - Class in javacard.framework.service
     
    BasicService() - Constructor for class javacard.framework.service.BasicService
      @@ -417,9 +391,6 @@
    beginTransaction() - Static method in class javacard.framework.JCSystem
    Begins an atomic transaction. -
    BTreeNode - Class in com.licel.jcardsim.samples.odSample.packageB
    Class represents node in a tree contained in B.java
    BTreeNode() - -Constructor for class com.licel.jcardsim.samples.odSample.packageB.BTreeNode -
     
    BUFFER_BOUNDS - Static variable in exception javacard.framework.APDUException
    This reason code is used by the APDU.sendBytes() method to indicate @@ -455,11 +426,8 @@

    C

    -
    C - Class in com.licel.jcardsim.samples.odSample.libPackageC
    package AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x03 - - This class is the only one in this package which is used to demonstrate - dependencies on package and package deletion.
    C() - -Constructor for class com.licel.jcardsim.samples.odSample.libPackageC.C +
    CAD - Class in com.licel.jcardsim.io
    Card Acceptance Device (CAD)
    CAD(Properties) - +Constructor for class com.licel.jcardsim.io.CAD
     
    CANNOT_ACCESS_IN_COMMAND - Static variable in exception javacard.framework.service.ServiceException @@ -472,7 +440,7 @@ getReason() and setReason().
    CardException(short) - Constructor for exception javacard.framework.CardException
    Construct a CardException instance with the specified reason. -
    CardRemoteObject - Class in javacard.framework.service
     
    CardRemoteObject() - +
    CardInterface - Interface in com.licel.jcardsim.io
    Basic SmartCard Interface
    CardRemoteObject - Class in javacard.framework.service
     
    CardRemoteObject() - Constructor for class javacard.framework.service.CardRemoteObject
     
    CardRuntimeException - Exception in javacard.framework
    The CardRuntimeException class @@ -539,7 +507,7 @@
    close() - Method in class com.licel.jcardsim.smartcardio.JCSCardChannel
    Do nothing. -
    com.licel.jcardsim.base - package com.licel.jcardsim.base
     
    com.licel.jcardsim.crypto - package com.licel.jcardsim.crypto
     
    com.licel.jcardsim.samples - package com.licel.jcardsim.samples
     
    com.licel.jcardsim.samples.ChannelsDemo - package com.licel.jcardsim.samples.ChannelsDemo
     
    com.licel.jcardsim.samples.JavaLoyalty - package com.licel.jcardsim.samples.JavaLoyalty
     
    com.licel.jcardsim.samples.JavaPurse - package com.licel.jcardsim.samples.JavaPurse
     
    com.licel.jcardsim.samples.JavaPurseCrypto - package com.licel.jcardsim.samples.JavaPurseCrypto
     
    com.licel.jcardsim.samples.NullApp - package com.licel.jcardsim.samples.NullApp
     
    com.licel.jcardsim.samples.odSample.libPackageC - package com.licel.jcardsim.samples.odSample.libPackageC
     
    com.licel.jcardsim.samples.odSample.packageA - package com.licel.jcardsim.samples.odSample.packageA
     
    com.licel.jcardsim.samples.odSample.packageB - package com.licel.jcardsim.samples.odSample.packageB
     
    com.licel.jcardsim.samples.photocard - package com.licel.jcardsim.samples.photocard
     
    com.licel.jcardsim.samples.RMIDemo - package com.licel.jcardsim.samples.RMIDemo
     
    com.licel.jcardsim.samples.SampleLibrary - package com.licel.jcardsim.samples.SampleLibrary
     
    com.licel.jcardsim.samples.SecureRMIDemo - package com.licel.jcardsim.samples.SecureRMIDemo
     
    com.licel.jcardsim.samples.ServiceDemo - package com.licel.jcardsim.samples.ServiceDemo
     
    com.licel.jcardsim.samples.wallet - package com.licel.jcardsim.samples.wallet
     
    com.licel.jcardsim.smartcardio - package com.licel.jcardsim.smartcardio
     
    com.licel.jcardsim.utils - package com.licel.jcardsim.utils
     
    COMMAND_DATA_TOO_LONG - +
    com.licel.jcardsim.base - package com.licel.jcardsim.base
     
    com.licel.jcardsim.crypto - package com.licel.jcardsim.crypto
     
    com.licel.jcardsim.io - package com.licel.jcardsim.io
     
    com.licel.jcardsim.remote - package com.licel.jcardsim.remote
     
    com.licel.jcardsim.samples - package com.licel.jcardsim.samples
     
    com.licel.jcardsim.smartcardio - package com.licel.jcardsim.smartcardio
     
    com.licel.jcardsim.utils - package com.licel.jcardsim.utils
     
    COMMAND_DATA_TOO_LONG - Static variable in exception javacard.framework.service.ServiceException
     
    COMMAND_IS_FINISHED - @@ -554,10 +522,6 @@
    connect(String) - Method in class com.licel.jcardsim.smartcardio.JCSTerminal
      -
    ConnectionManager - Class in com.licel.jcardsim.samples.ChannelsDemo
    This applet keeps track of the network connection for a - fictional wireless device.
    CORRUPTED_DATA - -Static variable in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
     
    CRC16 - Class in com.licel.jcardsim.crypto
     
    CRC16() - Constructor for class com.licel.jcardsim.crypto.CRC16
      @@ -566,81 +530,34 @@
     
    createApplet(AID, byte[], short, byte) - Method in class com.licel.jcardsim.base.Simulator -
    Create Applet instance in Simulator -
    credit(short) - -Method in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    credit(short) - -Method in class com.licel.jcardsim.samples.RMIDemo.PurseImpl
      -
    credit(short) - -Method in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse +
    createApplet(AID, byte[], short, byte) - +Method in interface com.licel.jcardsim.io.JavaCardInterface +
    Create + Applet instance in Simulator +
    createApplet(AID, byte[], short, byte) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient
      -
    credit(short) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseImpl +
    createApplet(SerializableAID, byte[], short, byte) - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface
      +
    createApplet(SerializableAID, byte[], short, byte) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation
    CryptoException - Exception in javacard.security
    CryptoException represents a cryptography-related exception.
    CryptoException(short) - Constructor for exception javacard.security.CryptoException
    Constructs a CryptoException with the specified reason.
    currentChannel - Static variable in class com.licel.jcardsim.base.SimulatorSystem
      -
    CyclicFile - Class in com.licel.jcardsim.samples.JavaPurseCrypto
    Class CyclicFile implements ISO 7816 CyclicFile.
    CyclicFile(byte, byte) - -Constructor for class com.licel.jcardsim.samples.JavaPurseCrypto.CyclicFile -
    Constructor

    D

    -
    DATA - -Static variable in class com.licel.jcardsim.samples.odSample.libPackageC.C -
      -
    data - -Variable in class com.licel.jcardsim.samples.odSample.packageA.TransientArrayElement -
      -
    data - -Variable in class com.licel.jcardsim.samples.odSample.packageB.BTreeNode -
      -
    debit(short) - -Method in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    debit(short) - -Method in class com.licel.jcardsim.samples.RMIDemo.PurseImpl -
      -
    debit(short) - -Method in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
      -
    debit(short) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseImpl -
     
    DEFAULT_RMI_INVOKE_INSTRUCTION - Static variable in class javacard.framework.service.RMIService
      -
    deletePhoto(short) - -Method in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    This method deletes the photo whose ID is specified in the card. -
    deletePhoto(short) - -Method in class com.licel.jcardsim.samples.photocard.PhotoCardImpl -
      -
    deselect() - -Method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    deselect(boolean) - -Method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    deselect() - -Method in class com.licel.jcardsim.samples.ChannelsDemo.ConnectionManager -
      -
    deselect(boolean) - -Method in class com.licel.jcardsim.samples.ChannelsDemo.ConnectionManager -
      -
    deselect() - -Method in class com.licel.jcardsim.samples.JavaPurse.JavaPurse -
    Performs the session finalization. -
    deselect() - -Method in class com.licel.jcardsim.samples.wallet.Wallet -
     
    deselect() - Method in class javacard.framework.Applet
    Called by the Java Card runtime environment to inform that this currently selected applet is @@ -732,8 +649,8 @@ Variable in class com.licel.jcardsim.crypto.ECKeyImpl
     
    ECKey - Interface in javacard.security
    The ECKey interface is the base interface for the EC algorithm's private - and public key implementations.
    ECKeyImpl - Class in com.licel.jcardsim.crypto
    Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI
    ECKeyImpl(byte, short) - + and public key implementations.
    ECKeyImpl - Class in com.licel.jcardsim.crypto
    Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI
    ECKeyImpl(byte, short) - Constructor for class com.licel.jcardsim.crypto.ECKeyImpl
    Construct not-initialized ecc key
    ECKeyImpl(ECKeyParameters) - @@ -788,12 +705,6 @@
    fail(APDU, short) - Method in class javacard.framework.service.BasicService
      -
    findRecord(byte) - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.CyclicFile -
    Find the record. -
    findRecord(byte) - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.ParametersFile -
    Find the record.
    fp - Variable in class com.licel.jcardsim.crypto.ECKeyImpl
      @@ -824,8 +735,8 @@ provided.
    genKeyPair() - Method in class com.licel.jcardsim.crypto.KeyPairImpl -
    (Re)Initializes the key objects encapsulated in this KeyPair instance - with new key values. +
    (Re)Initializes the key objects encapsulated in this + KeyPair instance with new key values.
    genKeyPair() - Method in class javacard.security.KeyPair
    (Re)Initializes the key objects encapsulated in this KeyPair instance @@ -836,21 +747,6 @@
    getA(byte[], short) - Method in interface javacard.security.ECKey
    Returns the first coefficient of the curve of the key. -
    getAccount() - -Static method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    getAccountNumber() - -Method in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    getAccountNumber() - -Method in class com.licel.jcardsim.samples.RMIDemo.PurseImpl -
      -
    getAccountNumber() - -Method in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
      -
    getAccountNumber() - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseImpl -
     
    getAID() - Method in class com.licel.jcardsim.base.SimulatorRuntime
    Return current applet context AID or null @@ -860,6 +756,9 @@ the current applet context, or null if the Applet.register() method has not yet been invoked. +
    getAID() - +Method in class com.licel.jcardsim.remote.SerializableAID +
     
    getAID() - Static method in class javacard.framework.JCSystem
    Returns the Java Card runtime environment-owned instance of the AID object associated with @@ -919,10 +818,24 @@ Static method in class javacard.framework.JCSystem
    This method is called to obtain the logical channel number assigned to the currently selected applet instance. +
    getATR() - +Method in class com.licel.jcardsim.base.Simulator +
      +
    getATR() - +Method in interface com.licel.jcardsim.io.CardInterface +
    Returns ATR +
    getATR() - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    getATR() - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
      +
    getATR() - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation
    getATR() - Method in class com.licel.jcardsim.smartcardio.JCSCard -
    Returns ATR configured by system property com.licel.jcardsim.smartcardio.ATR - Default ATR - 3BFA1800008131FE454A434F5033315632333298. +
     
    getAvailableMemory(byte) - Static method in class javacard.framework.JCSystem
    Obtains the amount of memory of the specified @@ -942,18 +855,6 @@
    getB(byte[], short) - Method in interface javacard.security.ECKey
    Returns the second coefficient of the curve of the key. -
    getBalance() - -Method in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    getBalance() - -Method in class com.licel.jcardsim.samples.RMIDemo.PurseImpl -
      -
    getBalance() - -Method in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
      -
    getBalance() - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseImpl -
     
    getBasicChannel() - Method in class com.licel.jcardsim.smartcardio.JCSCard
      @@ -975,6 +876,9 @@
    getCard() - Method in class com.licel.jcardsim.smartcardio.JCSCardChannel
      +
    getCardInterface() - +Method in class com.licel.jcardsim.io.CAD +
     
    getChannelNumber() - Method in class com.licel.jcardsim.smartcardio.JCSCardChannel
      @@ -1004,7 +908,8 @@ APDU object.
    getDomainParameters() - Method in class com.licel.jcardsim.crypto.ECKeyImpl -
    Get ECDomainParameters +
    Get + ECDomainParameters
    getDP1(byte[], short) - Method in class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl
      @@ -1093,6 +998,24 @@ Method in interface javacardx.crypto.KeyEncryption
    Returns the Cipher object to be used to decrypt the input key data and key parameters in the set methods. +
    getKeyGenerationParameters(SecureRandom) - +Method in class com.licel.jcardsim.crypto.DSAKeyImpl +
    Get + DSAKeyGenerationParameters +
    getKeyGenerationParameters(SecureRandom) - +Method in class com.licel.jcardsim.crypto.ECKeyImpl +
    Get + ECKeyGenerationParameters +
    getKeyGenerationParameters(SecureRandom) - +Method in interface com.licel.jcardsim.crypto.KeyWithParameters +
    Get keypair generation parameters for use with BouncyCastle Crypto API +
    getKeyGenerationParameters(SecureRandom) - +Method in class com.licel.jcardsim.crypto.RSAKeyImpl +
    Get + RSAKeyGenerationParameters +
    getKeyGenerationParameters(SecureRandom) - +Method in class com.licel.jcardsim.crypto.SymmetricKeyImpl +
     
    getLength() - Method in class com.licel.jcardsim.crypto.AsymmetricSignatureImpl
      @@ -1130,12 +1053,6 @@
    getName() - Method in class com.licel.jcardsim.smartcardio.JCSTerminal
      -
    getNewLogRecord() - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.CyclicFile -
    Get a new record -
    getNumRecords() - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.ParametersFile -
    Get the actual number of records in this file.
    getOutBlockSize() - Static method in class javacard.framework.APDU
    Returns the configured outgoing block size. @@ -1177,11 +1094,11 @@
    Get ECPublicKeyParameters
    getParameters() - Method in interface com.licel.jcardsim.crypto.KeyWithParameters -
    Get cipher key parameters - for use with BouncyCastle Crypto API +
    Get cipher key parameters for use with BouncyCastle Crypto API
    getParameters() - Method in class com.licel.jcardsim.crypto.RSAKeyImpl -
    Get RSAKeyParameters +
    Get + RSAKeyParameters
    getParameters() - Method in class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl
      @@ -1192,19 +1109,6 @@ Method in class javacard.framework.AID
    Called to get part of the AID bytes encapsulated within the AID object starting at the specified offset for the specified length. -
    getPhoto(short, short, short) - -Method in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    This method retrueves a series of bytes belonging to the photo - from the smart card at the position specified. -
    getPhoto(short, short, short) - -Method in class com.licel.jcardsim.samples.photocard.PhotoCardImpl -
      -
    getPhotoSize(short) - -Method in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    This method retrieves the photo size whose ID is specified. -
    getPhotoSize(short) - -Method in class com.licel.jcardsim.samples.photocard.PhotoCardImpl -
     
    getPQ(byte[], short) - Method in class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl
      @@ -1224,7 +1128,8 @@ with the previously active applet context.
    getPrivate() - Method in class com.licel.jcardsim.crypto.KeyPairImpl -
    Returns a reference to the private key component of this KeyPair object. +
    Returns a reference to the private key component of this + KeyPair object.
    getPrivate() - Method in class javacard.security.KeyPair
    Returns a reference to the private key component of this KeyPair object. @@ -1237,7 +1142,8 @@ and the transport media in the upper nibble in use.
    getPublic() - Method in class com.licel.jcardsim.crypto.KeyPairImpl -
    Returns a reference to the public key component of this KeyPair object. +
    Returns a reference to the public key component of this + KeyPair object.
    getPublic() - Method in class javacard.security.KeyPair
    Returns a reference to the public key component of this KeyPair object. @@ -1265,24 +1171,12 @@
    getReason() - Method in exception javacard.framework.CardRuntimeException
    Get reason code -
    getRecord(byte) - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.CyclicFile -
    Get a record with the specified record number -
    getRecord(byte) - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.ParametersFile -
    Get the record byte array for the specified record number.
    getS(byte[], short) - Method in class com.licel.jcardsim.crypto.ECPrivateKeyImpl
     
    getS(byte[], short) - Method in interface javacard.security.ECPrivateKey
    Returns the value of the secret key in plaintext form. -
    getShareableInterfaceObject(AID, byte) - -Method in class com.licel.jcardsim.samples.JavaLoyalty.JavaLoyalty -
    Implements getShareableInterfaceObject method of Applet class. -
    getShareableInterfaceObject(AID, byte) - -Method in class com.licel.jcardsim.samples.odSample.packageB.B -
    method returns pointer to this instance, ignores the param
    getShareableInterfaceObject(AID, byte) - Method in class javacard.framework.Applet
    Called by the Java Card runtime environment to obtain a shareable interface object from this server applet, on @@ -1353,12 +1247,6 @@
    getY(byte[], short) - Method in interface javacard.security.DSAPublicKey
    Returns the value of the key in plain text. -
    grantPoints(byte[]) - -Method in class com.licel.jcardsim.samples.JavaLoyalty.JavaLoyalty -
    Implements main interaction with a client. -
    grantPoints(byte[]) - -Method in interface com.licel.jcardsim.samples.SampleLibrary.JavaLoyaltyInterface -
    Used to ask JavaLoyalty Card applet to grant points.

    @@ -1472,68 +1360,51 @@
    INS_SELECT - Static variable in interface javacard.framework.ISO7816
    APDU command INS : SELECT = 0xA4 -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.ChannelsDemo.ConnectionManager -
     
    install(byte[], short, byte) - Static method in class com.licel.jcardsim.samples.HelloWorldApplet
    This method is called once during applet instantiation process. -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.JavaLoyalty.JavaLoyalty -
    Installs Java Loyalty applet. -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.JavaPurse.JavaPurse -
    Installs Java Purse applet. -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.NullApp.NullApp -
    Installs this applet. -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.odSample.packageA.A -
    method instantiates aninstance of A -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.odSample.packageB.B -
    method instantiates aninstance of B passing the arguments -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.photocard.PhotoCardApplet -
      -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.RMIDemo.PurseApplet -
      -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseApplet -
      -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.ServiceDemo.Main -
      -
    install(byte[], short, byte) - -Static method in class com.licel.jcardsim.samples.wallet.Wallet -
     
    install(byte[], short, byte) - Static method in class javacard.framework.Applet
    To create an instance of the Applet subclass, the Java Card runtime environment will call this static method first.
    installApplet(AID, Class) - Method in class com.licel.jcardsim.base.Simulator -
    Install Applet into Simulator without installing data +
    Install + Applet into Simulator without installing data
    installApplet(AID, Class, byte[], short, byte) - Method in class com.licel.jcardsim.base.Simulator -
    Install Applet into Simulator. +
    Install + Applet into Simulator. +
    installApplet(AID, String, byte[], short, byte) - +Method in class com.licel.jcardsim.base.Simulator +
      +
    installApplet(AID, String, byte[], byte[], short, byte) - +Method in class com.licel.jcardsim.base.Simulator +
      +
    installApplet(AID, String, byte[], short, byte) - +Method in interface com.licel.jcardsim.io.JavaCardInterface +
    Install + Applet into Simulator. +
    installApplet(AID, String, byte[], byte[], short, byte) - +Method in interface com.licel.jcardsim.io.JavaCardInterface +
    Install + Applet into Simulator. +
    installApplet(AID, String, byte[], short, byte) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    installApplet(AID, String, byte[], byte[], short, byte) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    INTERNAL - +Static variable in class com.licel.jcardsim.io.CAD +
     
    INTERNAL_FAILURE - Static variable in exception javacard.framework.TransactionException
    This reason code is used during a transaction to indicate an internal Java Card runtime environment problem (fatal error). -
    INVALID_ARGUMENT - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    Invalid argument value
    INVALID_INIT - Static variable in exception javacard.security.CryptoException
    This reason code is used to indicate that the signature or cipher object has not been correctly initialized for the requested operation. -
    INVALID_PHOTO_ID - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    Invalid photo ID
    IO_ERROR - Static variable in exception javacard.framework.APDUException
    This reason code indicates that an unrecoverable error occurred in the @@ -1549,25 +1420,15 @@
    isAppletSelecting(Applet) - Static method in class com.licel.jcardsim.base.SimulatorSystem
      -
    isAuthenticated(short) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
    Checks whether or not the specified principal is currently authenticated.
    isAuthenticated(short) - Method in interface javacard.framework.service.SecurityService
     
    isCardPresent() - Method in class com.licel.jcardsim.smartcardio.JCSTerminal
    Always returns true -
    isChannelSecure(byte) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
     
    isChannelSecure(byte) - Method in interface javacard.framework.service.SecurityService
      -
    isCommandSecure(byte) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
    Checks whether a secure channel is in use between the card and the host for - the ongoing command that guarantees the indicated properties.
    isCommandSecure(byte) - Method in interface javacard.framework.service.SecurityService
      @@ -1646,19 +1507,22 @@

    J

    -
    java.rmi - package java.rmi
     
    javacard.framework - package javacard.framework
     
    javacard.framework.service - package javacard.framework.service
     
    javacard.security - package javacard.security
     
    javacardx.crypto - package javacardx.crypto
     
    JavaLoyalty - Class in com.licel.jcardsim.samples.JavaLoyalty
    Minimalistic loyalty applet.
    JavaLoyalty(byte[], short, byte) - -Constructor for class com.licel.jcardsim.samples.JavaLoyalty.JavaLoyalty -
    Performs memory allocations, initializations, and applet registration -
    JavaLoyaltyInterface - Interface in com.licel.jcardsim.samples.SampleLibrary
    Shareable Loyalty Interface
    JavaPurse - Class in com.licel.jcardsim.samples.JavaPurse
    This class is intended to demonstrate how an electronic cash application - might be developed using Java Card - See Java Card(TM) Development Kit User's Guide - for details.
    JavaPurse(byte[], short, byte) - -Constructor for class com.licel.jcardsim.samples.JavaPurse.JavaPurse -
    Performs memory allocations, initialization, and applet registration. +
    javacard.framework - package javacard.framework
     
    javacard.framework.service - package javacard.framework.service
     
    javacard.security - package javacard.security
     
    JavaCardInterface - Interface in com.licel.jcardsim.io
    Interface with JavaCard-specific functions
    JavaCardRemoteClient - Class in com.licel.jcardsim.remote
    RMI client
    JavaCardRemoteClient(String, int) - +Constructor for class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    JavaCardRemoteInterface - Interface in com.licel.jcardsim.remote
    RMI Wrapper for the JavaCardInterface
    JavaCardRemoteServer - Class in com.licel.jcardsim.remote
    RMI Server
    JavaCardRemoteServer(String, int) - +Constructor for class com.licel.jcardsim.remote.JavaCardRemoteServer +
      +
    javacardx.crypto - package javacardx.crypto
     
    JAVAX_SMARTCARDIO - +Static variable in class com.licel.jcardsim.io.CAD +
      +
    JavaxSmartCardInterface - Class in com.licel.jcardsim.io
    Class with javacardx.smartcardio Command/Response support
    JavaxSmartCardInterface() - +Constructor for class com.licel.jcardsim.io.JavaxSmartCardInterface +
     
    JCardSimProvider - Class in com.licel.jcardsim.smartcardio
    Provider object for the Java Card Terminal emulating.
    JCardSimProvider() - Constructor for class com.licel.jcardsim.smartcardio.JCardSimProvider
      -
    JCSCard - Class in com.licel.jcardsim.smartcardio
    Card implementation class.
    JCSCard() - +
    JCSCard - Class in com.licel.jcardsim.smartcardio
    Card implementation class.
    JCSCard(JavaCardInterface) - Constructor for class com.licel.jcardsim.smartcardio.JCSCard
     
    JCSCardChannel - Class in com.licel.jcardsim.smartcardio
    CardChannel implementation class.
    JCSCardChannel(JCSCard, int) - @@ -1717,15 +1581,17 @@ Constructor for class javacard.security.KeyPair
    Constructs a new KeyPair object containing the specified public key and private key. -
    KeyPairImpl - Class in com.licel.jcardsim.crypto
    Implementation KeyPair based - on BouncyCastle CryptoAPI
    KeyPairImpl(byte, short) - +
    KeyPairImpl - Class in com.licel.jcardsim.crypto
    Implementation + KeyPair based on BouncyCastle CryptoAPI
    KeyPairImpl(byte, short) - Constructor for class com.licel.jcardsim.crypto.KeyPairImpl -
    Constructs a KeyPair instance for the specified algorithm and keylength; +
    Constructs a + KeyPair instance for the specified algorithm and keylength; the encapsulated keys are uninitialized.
    KeyPairImpl(PublicKey, PrivateKey) - Constructor for class com.licel.jcardsim.crypto.KeyPairImpl -
    Constructs a new KeyPair object containing the specified - public key and private key. +
    Constructs a new + KeyPair object containing the specified public key and + private key.
    KeyWithParameters - Interface in com.licel.jcardsim.crypto
     

    @@ -1813,19 +1679,45 @@ Method in class com.licel.jcardsim.smartcardio.JCSCardTerminals
    Returns only one terminal with state ALL|CARD_PRESENT|CARD_INSERTION, in other case returns empty list. +
    loadApplet(AID, String, byte[]) - +Method in class com.licel.jcardsim.base.Simulator +
      +
    loadApplet(AID, String) - +Method in class com.licel.jcardsim.base.Simulator +
     
    loadApplet(AID, Class) - Method in class com.licel.jcardsim.base.Simulator -
    Load Applet into Simulator +
    Load + Applet into Simulator
    loadApplet(AID, Class) - Method in class com.licel.jcardsim.base.SimulatorRuntime
    Load applet -
    loadPhoto(short, byte[], short, short, boolean) - -Method in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    This method loads a series of bytes belonging to the photo - into the smart card at the position specified. -
    loadPhoto(short, byte[], short, short, boolean) - -Method in class com.licel.jcardsim.samples.photocard.PhotoCardImpl -
      +
    loadApplet(AID, String, byte[]) - +Method in interface com.licel.jcardsim.io.JavaCardInterface +
    Load + Applet into Simulator +
    loadApplet(AID, String) - +Method in interface com.licel.jcardsim.io.JavaCardInterface +
    Load + Applet into Simulator +
    loadApplet(AID, String) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    loadApplet(AID, String, byte[]) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    loadApplet(SerializableAID, String) - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
      +
    loadApplet(SerializableAID, String, byte[]) - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
      +
    loadApplet(SerializableAID, String) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation +
    loadApplet(SerializableAID, String, byte[]) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation
    lookupAID(byte[], short, byte) - Method in class com.licel.jcardsim.base.SimulatorRuntime
    Lookup applet by aid contains in byte array @@ -1849,8 +1741,8 @@

    M

    -
    Main - Class in com.licel.jcardsim.samples.ServiceDemo
     
    Main() - -Constructor for class com.licel.jcardsim.samples.ServiceDemo.Main +
    main(String[]) - +Static method in class com.licel.jcardsim.remote.JavaCardRemoteServer
     
    main(String[]) - Static method in class com.licel.jcardsim.utils.APDUScriptTool @@ -1882,21 +1774,6 @@
    makeTransientShortArray(short, byte) - Static method in class javacard.framework.JCSystem
    Creates a transient short array with the specified array length. -
    MAX_AMOUNT - -Static variable in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    MAX_AMOUNT - -Static variable in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
      -
    MAX_BUFFER_BYTES - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    Maximum bytes for transfer -
    MAX_PHOTO_COUNT - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    Maximum on-card photos -
    MAX_SIZE - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    Maximum photo size
    MEMORY_TYPE_PERSISTENT - Static variable in class javacard.framework.JCSystem
    Constant to indicate persistent memory type. @@ -1929,24 +1806,15 @@ Variable in class com.licel.jcardsim.crypto.RSAKeyImpl
     
    MultiSelectable - Interface in javacard.framework
    The MultiSelectable interface identifies the implementing - Applet subclass as being capable of concurrent selections.
    MySecurityService - Class in com.licel.jcardsim.samples.SecureRMIDemo
     
    MySecurityService() - -Constructor for class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
      -
    + Applet subclass as being capable of concurrent selections.

    N

    -
    NO_PHOTO_STORED - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    No photo stored in selected location
    NO_RESOURCE - Static variable in exception javacard.framework.SystemException
    This reason code is used to indicate that there is insufficient resource in the Card for the request. -
    NO_SPACE_AVAILABLE - -Static variable in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    No space available for photo storage
    NO_SUCH_ALGORITHM - Static variable in exception javacard.security.CryptoException
    This reason code is used to indicate that the requested algorithm or key type is not supported. @@ -1970,9 +1838,6 @@ Static variable in exception javacard.framework.TransactionException
    This reason code is used by the abortTransaction and commitTransaction methods when a transaction is not in progress. -
    NullApp - Class in com.licel.jcardsim.samples.NullApp
     
    NullApp(APDU) - -Constructor for class com.licel.jcardsim.samples.NullApp.NullApp -
    Only this class's install method should create the applet object.
    nullPointerException - Static variable in class com.licel.jcardsim.base.SimulatorSystem
      @@ -2002,12 +1867,6 @@
    openLogicalChannel() - Method in class com.licel.jcardsim.smartcardio.JCSCard
    Always returns basic channel with id = 0 -
    OVERFLOW - -Static variable in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    OVERFLOW - -Static variable in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
     
    OwnerPIN - Class in javacard.framework
    This class represents an Owner PIN, implements Personal Identification Number functionality as defined in the PIN interface, and provides the ability to update the PIN and thus owner functionality.
    OwnerPIN(byte, byte) - @@ -2024,31 +1883,16 @@
    p - Variable in class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl
      -
    ParametersFile - Class in com.licel.jcardsim.samples.JavaPurseCrypto
    This is the class for all linear variable-length record files, and the base class - for linear variable-fixed and cyclic record files.
    ParametersFile(byte) - -Constructor for class com.licel.jcardsim.samples.JavaPurseCrypto.ParametersFile -
    Constructor.
    partialEquals(byte[], short, byte) - Method in class javacard.framework.AID
    Checks if the specified partial AID byte sequence matches the first length bytes of the encapsulated AID bytes within this AID object. -
    PhotoCard - Interface in com.licel.jcardsim.samples.photocard
    PhotoCard interface - Defines methods to be used as interface between photo client - and storage smart card
    PhotoCardApplet - Class in com.licel.jcardsim.samples.photocard
     
    PhotoCardApplet() - -Constructor for class com.licel.jcardsim.samples.photocard.PhotoCardApplet -
      -
    PhotoCardImpl - Class in com.licel.jcardsim.samples.photocard
     
    PIN - Interface in javacard.framework
    This interface represents a PIN.
    PINException - Exception in javacard.framework
    PINException represents a OwnerPIN class access-related exception.
    PINException(short) - +
    PIN - Interface in javacard.framework
    This interface represents a PIN.
    PINException - Exception in javacard.framework
    PINException represents a OwnerPIN class access-related exception.
    PINException(short) - Constructor for exception javacard.framework.PINException
    Constructs a PINException. -
    PostProcess - Class in com.licel.jcardsim.samples.ServiceDemo
     
    PostProcess() - -Constructor for class com.licel.jcardsim.samples.ServiceDemo.PostProcess -
    Creates new PostProcess
    pq - Variable in class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl
      -
    PreProcess - Class in com.licel.jcardsim.samples.ServiceDemo
     
    PreProcess() - -Constructor for class com.licel.jcardsim.samples.ServiceDemo.PreProcess -
    Creates new PreProcess
    previousActiveObject - Static variable in class com.licel.jcardsim.base.SimulatorSystem
      @@ -2061,45 +1905,9 @@
    PRINCIPAL_CARDHOLDER - Static variable in interface javacard.framework.service.SecurityService
      -
    PrivateKey - Interface in javacard.security
    The PrivateKey interface is the base interface for private keys used in asymmetric algorithms.
    process(APDU) - -Method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    process(APDU) - -Method in class com.licel.jcardsim.samples.ChannelsDemo.ConnectionManager -
      -
    process(APDU) - +
    PrivateKey - Interface in javacard.security
    The PrivateKey interface is the base interface for private keys used in asymmetric algorithms.
    process(APDU) - Method in class com.licel.jcardsim.samples.HelloWorldApplet
    This method is called each time the applet receives APDU. -
    process(APDU) - -Method in class com.licel.jcardsim.samples.JavaLoyalty.JavaLoyalty -
    Dispatches APDU commands. -
    process(APDU) - -Method in class com.licel.jcardsim.samples.JavaPurse.JavaPurse -
    Dispatches APDU commands. -
    process(APDU) - -Method in class com.licel.jcardsim.samples.NullApp.NullApp -
    Returns <0x6D,INS> response status always. -
    process(APDU) - -Method in class com.licel.jcardsim.samples.odSample.packageA.A -
    method processes the APDU commands passed to this applet instance. -
    process(APDU) - -Method in class com.licel.jcardsim.samples.odSample.packageB.B -
    method processes the APDU commands passed to this applet instance. -
    process(APDU) - -Method in class com.licel.jcardsim.samples.photocard.PhotoCardApplet -
      -
    process(APDU) - -Method in class com.licel.jcardsim.samples.RMIDemo.PurseApplet -
      -
    process(APDU) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseApplet -
      -
    process(APDU) - -Method in class com.licel.jcardsim.samples.ServiceDemo.Main -
      -
    process(APDU) - -Method in class com.licel.jcardsim.samples.wallet.Wallet -
     
    process(APDU) - Method in class javacard.framework.Applet
    Called by the Java Card runtime environment to process an incoming APDU command. @@ -2118,12 +1926,6 @@
    PROCESS_OUTPUT_DATA - Static variable in class javacard.framework.service.Dispatcher
      -
    processCommand(APDU) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
      -
    processCommand(APDU) - -Method in class com.licel.jcardsim.samples.ServiceDemo.TestService -
     
    processCommand(APDU) - Method in class javacard.framework.service.BasicService
      @@ -2133,18 +1935,12 @@
    processCommand(APDU) - Method in interface javacard.framework.service.Service
      -
    processDataIn(APDU) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
    Pre-processes the input data for the command in the APDU object.
    processDataIn(APDU) - Method in class javacard.framework.service.BasicService
     
    processDataIn(APDU) - Method in interface javacard.framework.service.Service
      -
    processDataOut(APDU) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.MySecurityService -
     
    processDataOut(APDU) - Method in class javacard.framework.service.BasicService
      @@ -2191,13 +1987,7 @@
    publicExponent - Variable in class com.licel.jcardsim.crypto.RSAPrivateCrtKeyImpl
      -
    PublicKey - Interface in javacard.security
    The PublicKey interface is the base interface for public keys used in asymmetric algorithms.
    Purse - Interface in com.licel.jcardsim.samples.RMIDemo
     
    Purse - Interface in com.licel.jcardsim.samples.SecureRMIDemo
     
    PurseApplet - Class in com.licel.jcardsim.samples.RMIDemo
     
    PurseApplet() - -Constructor for class com.licel.jcardsim.samples.RMIDemo.PurseApplet -
      -
    PurseImpl - Class in com.licel.jcardsim.samples.RMIDemo
     
    PurseImpl() - -Constructor for class com.licel.jcardsim.samples.RMIDemo.PurseImpl -
      -
    +
    PublicKey - Interface in javacard.security
    The PublicKey interface is the base interface for public keys used in asymmetric algorithms.

    Q

    @@ -2223,21 +2013,12 @@ on BouncyCastle CryptoAPI
    RandomDataImpl() - Constructor for class com.licel.jcardsim.crypto.RandomDataImpl
      -
    receiveAPDU(byte[], short) - -Static method in class com.licel.jcardsim.base.SimulatorSystem -
     
    receiveBytes(short) - Method in class javacard.framework.APDU
     
    receiveInData(APDU) - Method in class javacard.framework.service.BasicService
      -
    Record - Class in com.licel.jcardsim.samples.JavaPurseCrypto
    A Record.
    Record(byte[]) - -Constructor for class com.licel.jcardsim.samples.JavaPurseCrypto.Record -
      -
    Record(short) - -Constructor for class com.licel.jcardsim.samples.JavaPurseCrypto.Record -
     
    register() - Method in class javacard.framework.Applet
    This method is used by the applet to register this applet instance with @@ -2259,18 +2040,12 @@ Static method in class com.licel.jcardsim.base.SimulatorSystem
    This method is used by the applet to register this applet instance with the Java Card runtime environment and assign the specified AID bytes as its instance AID bytes. -
    Remote - Interface in java.rmi
     
    REMOTE_OBJECT_NOT_EXPORTED - +
    REMOTE_OBJECT_NOT_EXPORTED - Static variable in exception javacard.framework.service.ServiceException
      -
    RemoteException - Exception in java.rmi
     
    RemoteException() - -Constructor for exception java.rmi.RemoteException -
     
    RemoteService - Interface in javacard.framework.service
     
    removeService(Service, byte) - Method in class javacard.framework.service.Dispatcher
      -
    REQUEST_DENIED - -Static variable in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
     
    requestObjectDeletion() - Static method in class com.licel.jcardsim.base.SimulatorSystem
    Always throw SystemException.ILLEGAL_USE @@ -2278,19 +2053,24 @@ Static method in class javacard.framework.JCSystem
    This method is invoked by the applet to trigger the object deletion service of the Java Card runtime environment. -
    requestPhotoStorage(short) - -Method in interface com.licel.jcardsim.samples.photocard.PhotoCard -
    This method requests the smart card to allocate space to store - a photo image of the specified size. -
    requestPhotoStorage(short) - -Method in class com.licel.jcardsim.samples.photocard.PhotoCardImpl -
     
    reset() - Method in class com.licel.jcardsim.base.Simulator -
    powerdown/powerup +
     
    reset() - Method in class com.licel.jcardsim.crypto.MessageDigestImpl
      +
    reset() - +Method in interface com.licel.jcardsim.io.CardInterface +
    Powerdown/Powerup +
    reset() - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    reset() - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
      +
    reset() - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation
    reset() - Method in class javacard.framework.APDU
    clear internal state of the APDU @@ -2309,9 +2089,6 @@ Method in class javacard.framework.OwnerPIN
    This method resets the validated flag and resets the PIN try counter to the value of the PIN try limit. -
    resetReference() - -Method in class com.licel.jcardsim.samples.odSample.packageB.B -
    method resets reference in bRef field to null.
    resetRuntime() - Method in class com.licel.jcardsim.base.Simulator
      @@ -2323,11 +2100,17 @@
    Checks if the RID (National Registered Application provider identifier) portion of the encapsulated AID bytes within the otherAID object matches that of this AID object. +
    RMI - +Static variable in class com.licel.jcardsim.io.CAD +
      +
    RMI_SERVER_ID - +Static variable in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
     
    RMIService - Class in javacard.framework.service
     
    RMIService(Remote) - Constructor for class javacard.framework.service.RMIService
      -
    RSAKeyImpl - Class in com.licel.jcardsim.crypto
    Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI
    RSAKeyImpl(boolean, short) - +
    RSAKeyImpl - Class in com.licel.jcardsim.crypto
    Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI
    RSAKeyImpl(boolean, short) - Constructor for class com.licel.jcardsim.crypto.RSAKeyImpl
    Construct not-initialized rsa key
    RSAKeyImpl(RSAKeyParameters) - @@ -2351,31 +2134,10 @@ Variable in class com.licel.jcardsim.crypto.ECPrivateKeyImpl
     
    SecretKey - Interface in javacard.security
    The SecretKey class is the base interface for keys - used in symmetric algorithms (DES, for example).
    SecurePurseApplet - Class in com.licel.jcardsim.samples.SecureRMIDemo
     
    SecurePurseApplet() - -Constructor for class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseApplet -
      -
    SecurePurseImpl - Class in com.licel.jcardsim.samples.SecureRMIDemo
     
    SecurePurseImpl(SecurityService) - -Constructor for class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseImpl -
      -
    securityException - + used in symmetric algorithms (DES, for example).
    securityException - Static variable in class com.licel.jcardsim.base.SimulatorSystem
      -
    SecurityService - Interface in javacard.framework.service
     
    select() - -Method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    select(boolean) - -Method in class com.licel.jcardsim.samples.ChannelsDemo.AccountAccessor -
      -
    select() - -Method in class com.licel.jcardsim.samples.ChannelsDemo.ConnectionManager -
      -
    select(boolean) - -Method in class com.licel.jcardsim.samples.ChannelsDemo.ConnectionManager -
      -
    select() - -Method in class com.licel.jcardsim.samples.wallet.Wallet -
      -
    select() - +
    SecurityService - Interface in javacard.framework.service
     
    select() - Method in class javacard.framework.Applet
    Called by the Java Card runtime environment to inform this applet that it has been selected when no applet from the same package is active on any other logical channel. @@ -2386,8 +2148,20 @@ active on another logical channel.
    selectApplet(AID) - Method in class com.licel.jcardsim.base.Simulator -
    Select applet by it's AID +
      +
    selectApplet(AID) - +Method in interface com.licel.jcardsim.io.JavaCardInterface +
    Select applet by it's AID It's method must be called before start working with applet instance +
    selectApplet(AID) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    selectApplet(SerializableAID) - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
      +
    selectApplet(SerializableAID) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation
    selectingApplet() - Method in class javacard.framework.Applet
    This method is used by the applet process() method to distinguish @@ -2406,6 +2180,12 @@ Method in class javacard.framework.APDU
    Sends len more bytes from outData byte array starting at specified offset bOff. +
    SerializableAID - Class in com.licel.jcardsim.remote
    Serializable AID container for the RMI calls
    SerializableAID() - +Constructor for class com.licel.jcardsim.remote.SerializableAID +
      +
    SerializableAID(AID) - +Constructor for class com.licel.jcardsim.remote.SerializableAID +
     
    Service - Interface in javacard.framework.service
     
    ServiceException - Exception in javacard.framework.service
     
    ServiceException(short) - Constructor for exception javacard.framework.service.ServiceException
      @@ -2415,18 +2195,6 @@
    setA(byte[], short, short) - Method in interface javacard.security.ECKey
    Sets the first coefficient of the curve of the key. -
    setAccountNumber(byte[]) - -Method in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    setAccountNumber(byte[]) - -Method in class com.licel.jcardsim.samples.RMIDemo.PurseImpl -
      -
    setAccountNumber(byte[]) - -Method in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
      -
    setAccountNumber(byte[]) - -Method in class com.licel.jcardsim.samples.SecureRMIDemo.SecurePurseImpl -
     
    setB(byte[], short, short) - Method in class com.licel.jcardsim.crypto.ECKeyImpl
      @@ -2602,9 +2370,6 @@
    setReason(short) - Method in exception javacard.framework.CardRuntimeException
    Set reason code -
    setReference(B) - -Method in class com.licel.jcardsim.samples.odSample.packageB.B -
    method sets reference in bRef field to input parameter B object.
    setS(byte[], short, short) - Method in class com.licel.jcardsim.crypto.ECPrivateKeyImpl
      @@ -2658,61 +2423,13 @@
    Protected Constructor
    Simulator - Class in com.licel.jcardsim.base
    Main class for deal with Applets
    Simulator() - Constructor for class com.licel.jcardsim.base.Simulator -
    Construct Simulator object and init base systems +
    Construct Simulator object and init base systems
    SimulatorRuntime - Class in com.licel.jcardsim.base
    Base implementation of Java Card Runtime
    SimulatorRuntime() - Constructor for class com.licel.jcardsim.base.SimulatorRuntime
     
    SimulatorSystem - Class in com.licel.jcardsim.base
    Base implementation of JCSystem
    size - Variable in class com.licel.jcardsim.crypto.KeyImpl
      -
    ST_ERROR_APPLET_AID_NOT_FOUND - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_BAD_TRANSIENT_MEM_DESELECT - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_BAD_TRANSIENT_MEM_DESELECT_ELEMENT - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_BAD_TRANSIENT_MEM_RESET - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_BAD_TRANSIENT_MEM_RESET_ELEMENT - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_MEM_MATCH_ALL_ATTRIBUTES - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_MEM_MATCH_BEFORE_PACK - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_MEM_MATCH_INITIAL - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_MEM_MATCH_OBJECTS - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_MEM_MATCH_TRANSIENT_DESELECT_OBJECTS - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_MEM_MATCH_TRANSIENT_RESET_OBJECTS - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_SHAREABLE_NOT_FOUND - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_TRANSIENT_DESELECT_MEM_NOT_RETURNED - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_TRANSIENT_DESELECT_OBJECTS_EXIST - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_TRANSIENT_RESET_MEM_NOT_RETURNED - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
      -
    ST_ERROR_TRANSIENT_RESET_OBJECTS_EXIST - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
     
    STATE_ERROR_IO - Static variable in class javacard.framework.APDU
    This error state of a APDU object occurs when an APDUException @@ -2767,9 +2484,6 @@
    succeedWithStatusWord(APDU, short) - Method in class javacard.framework.service.BasicService
      -
    SUCCESS - -Static variable in class com.licel.jcardsim.samples.odSample.packageA.A -
     
    SW_APPLET_CRATION_FAILED - Static variable in class com.licel.jcardsim.base.SimulatorSystem
    Response status : Applet creation failed = 0x6444 @@ -2868,9 +2582,6 @@ Static variable in exception javacard.framework.APDUException
    This reason code indicates that during T=1 protocol, the CAD returned an ABORT S-Block command and aborted the data transfer. -
    TestService - Class in com.licel.jcardsim.samples.ServiceDemo
     
    TestService() - -Constructor for class com.licel.jcardsim.samples.ServiceDemo.TestService -
     
    throwIt(short) - Static method in exception javacard.framework.APDUException
    Throws the Java Card runtime environment-owned instance of APDUException with the specified reason. @@ -2906,9 +2617,6 @@
    TransactionException - Exception in javacard.framework
    TransactionException represents an exception in the transaction subsystem.
    TransactionException(short) - Constructor for exception javacard.framework.TransactionException
    Constructs a TransactionException with the specified reason. -
    TransientArrayElement - Class in com.licel.jcardsim.samples.odSample.packageA
    Class represents object used as elements of transient array
    TransientArrayElement(short) - -Constructor for class com.licel.jcardsim.samples.odSample.packageA.TransientArrayElement -
     
    TransientMemory - Class in com.licel.jcardsim.base
    Basic implementation of storage transient memory of JCRE
    TransientMemory() - Constructor for class com.licel.jcardsim.base.TransientMemory
      @@ -2918,9 +2626,24 @@
    transmit(ByteBuffer, ByteBuffer) - Method in class com.licel.jcardsim.smartcardio.JCSCardChannel
      -
    transmitCommand(CommandAPDU) - +
    transmitCommand(byte[]) - Method in class com.licel.jcardsim.base.Simulator +
      +
    transmitCommand(byte[]) - +Method in interface com.licel.jcardsim.io.CardInterface
    Transmit APDU to previous selected applet +
    transmitCommand(CommandAPDU) - +Method in class com.licel.jcardsim.io.JavaxSmartCardInterface +
    Wraper for the transmitCommand(byte[]) +
    transmitCommand(byte[]) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteClient +
      +
    transmitCommand(byte[]) - +Method in interface com.licel.jcardsim.remote.JavaCardRemoteInterface +
      +
    transmitCommand(byte[]) - +Method in class com.licel.jcardsim.remote.JavaCardRemoteServer +
    Imlementation
    transmitControlCommand(int, byte[]) - Method in class com.licel.jcardsim.smartcardio.JCSCard
      @@ -2991,21 +2714,12 @@

    U

    -
    UNDERFLOW - -Static variable in interface com.licel.jcardsim.samples.RMIDemo.Purse -
      -
    UNDERFLOW - -Static variable in interface com.licel.jcardsim.samples.SecureRMIDemo.Purse -
     
    unexport(Remote) - Static method in class javacard.framework.service.CardRemoteObject
     
    UNINITIALIZED_KEY - Static variable in exception javacard.security.CryptoException
    This reason code is used to indicate that the key is uninitialized. -
    uninstall() - -Method in class com.licel.jcardsim.samples.odSample.packageB.B -
    uninstall method called before applet deletion
    uninstall() - Method in interface javacard.framework.AppletEvent
    Called by the Java Card runtime environment to inform this applet instance that the Applet Deletion @@ -3047,11 +2761,6 @@
    update(byte[], short, short, byte[], short) - Method in class javacardx.crypto.Cipher
    Generates encrypted/decrypted output from input data. -
    updateNewLogRecord() - -Method in class com.licel.jcardsim.samples.JavaPurseCrypto.CyclicFile -
    Update internal record pointers, so the new record - becomes the current record and the oldest - record in CyclicFile becomes the next new record
    UserException - Exception in javacard.framework
    UserException represents a User exception.
    UserException() - Constructor for exception javacard.framework.UserException
    Constructs a UserException with reason = 0. @@ -3095,7 +2804,7 @@
    waitForChange(long) - Method in class com.licel.jcardsim.smartcardio.JCSCardTerminals
    Immediately returns true -
    Wallet - Class in com.licel.jcardsim.samples.wallet
     
    +

    X

    diff --git a/javadoc/index.html b/javadoc/index.html index 5d5ba8ce..683e5bec 100644 --- a/javadoc/index.html +++ b/javadoc/index.html @@ -2,7 +2,7 @@ - + Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API diff --git a/javadoc/javacard/framework/AID.html b/javadoc/javacard/framework/AID.html index f2b75d56..8b17c0e5 100644 --- a/javadoc/javacard/framework/AID.html +++ b/javadoc/javacard/framework/AID.html @@ -2,13 +2,13 @@ <!--NewPage--> <HTML> <HEAD> -<!-- Generated by javadoc (build 1.6.0_51) on Wed Jul 17 16:16:48 MSK 2013 --> +<!-- Generated by javadoc (build 1.6.0_65) on Thu Dec 12 16:38:40 MSK 2013 --> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <TITLE> AID (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/APDU.html b/javadoc/javacard/framework/APDU.html index f81e1800..23cd628a 100644 --- a/javadoc/javacard/framework/APDU.html +++ b/javadoc/javacard/framework/APDU.html @@ -2,13 +2,13 @@ - + APDU (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/APDUException.html b/javadoc/javacard/framework/APDUException.html index bf2b03e8..604b0b2e 100644 --- a/javadoc/javacard/framework/APDUException.html +++ b/javadoc/javacard/framework/APDUException.html @@ -2,13 +2,13 @@ - + APDUException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/Applet.html b/javadoc/javacard/framework/Applet.html index 87f469f7..19a73de6 100644 --- a/javadoc/javacard/framework/Applet.html +++ b/javadoc/javacard/framework/Applet.html @@ -2,13 +2,13 @@ - + Applet (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -97,7 +97,7 @@

    extended by javacard.framework.Applet
    -
    Direct Known Subclasses:
    A, AccountAccessor, B, ConnectionManager, HelloWorldApplet, JavaLoyalty, JavaPurse, Main, NullApp, PhotoCardApplet, PurseApplet, SecurePurseApplet, Wallet
    +
    Direct Known Subclasses:
    HelloWorldApplet

    diff --git a/javadoc/javacard/framework/AppletEvent.html b/javadoc/javacard/framework/AppletEvent.html index 32ed5273..8edf2288 100644 --- a/javadoc/javacard/framework/AppletEvent.html +++ b/javadoc/javacard/framework/AppletEvent.html @@ -2,13 +2,13 @@ - + AppletEvent (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -92,9 +92,6 @@

    javacard.framework
    Interface AppletEvent

    -
    -
    All Known Implementing Classes:
    B
    -

    public interface AppletEvent
    diff --git a/javadoc/javacard/framework/CardException.html b/javadoc/javacard/framework/CardException.html index b6da6683..f71e2e38 100644 --- a/javadoc/javacard/framework/CardException.html +++ b/javadoc/javacard/framework/CardException.html @@ -2,13 +2,13 @@ - + CardException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/CardRuntimeException.html b/javadoc/javacard/framework/CardRuntimeException.html index a213f73c..7b2e98ab 100644 --- a/javadoc/javacard/framework/CardRuntimeException.html +++ b/javadoc/javacard/framework/CardRuntimeException.html @@ -2,13 +2,13 @@ - + CardRuntimeException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/ISO7816.html b/javadoc/javacard/framework/ISO7816.html index 57b5c646..1334720c 100644 --- a/javadoc/javacard/framework/ISO7816.html +++ b/javadoc/javacard/framework/ISO7816.html @@ -2,13 +2,13 @@ - + ISO7816 (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/ISOException.html b/javadoc/javacard/framework/ISOException.html index f2d3f540..0cfab55b 100644 --- a/javadoc/javacard/framework/ISOException.html +++ b/javadoc/javacard/framework/ISOException.html @@ -2,13 +2,13 @@ - + ISOException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/JCSystem.html b/javadoc/javacard/framework/JCSystem.html index 79179796..5b118980 100644 --- a/javadoc/javacard/framework/JCSystem.html +++ b/javadoc/javacard/framework/JCSystem.html @@ -2,13 +2,13 @@ - + JCSystem (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/MultiSelectable.html b/javadoc/javacard/framework/MultiSelectable.html index 002fc783..3cf379ab 100644 --- a/javadoc/javacard/framework/MultiSelectable.html +++ b/javadoc/javacard/framework/MultiSelectable.html @@ -2,13 +2,13 @@ - + MultiSelectable (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -92,9 +92,6 @@

    javacard.framework
    Interface MultiSelectable

    -
    -
    All Known Implementing Classes:
    AccountAccessor, ConnectionManager
    -

    public interface MultiSelectable
    diff --git a/javadoc/javacard/framework/OwnerPIN.html b/javadoc/javacard/framework/OwnerPIN.html index 966edd98..07d283d7 100644 --- a/javadoc/javacard/framework/OwnerPIN.html +++ b/javadoc/javacard/framework/OwnerPIN.html @@ -2,13 +2,13 @@ - + OwnerPIN (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/PIN.html b/javadoc/javacard/framework/PIN.html index ec6fbaac..4309f08f 100644 --- a/javadoc/javacard/framework/PIN.html +++ b/javadoc/javacard/framework/PIN.html @@ -2,13 +2,13 @@ - + PIN (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/PINException.html b/javadoc/javacard/framework/PINException.html index 308d04f1..6535d14c 100644 --- a/javadoc/javacard/framework/PINException.html +++ b/javadoc/javacard/framework/PINException.html @@ -2,13 +2,13 @@ - + PINException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/Shareable.html b/javadoc/javacard/framework/Shareable.html index 81eebe09..90961fa8 100644 --- a/javadoc/javacard/framework/Shareable.html +++ b/javadoc/javacard/framework/Shareable.html @@ -2,13 +2,13 @@ - + Shareable (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -92,12 +92,6 @@

    javacard.framework
    Interface Shareable

    -
    -
    All Known Subinterfaces:
    JavaLoyaltyInterface
    -
    -
    -
    All Known Implementing Classes:
    B, JavaLoyalty
    -

    public interface Shareable
    diff --git a/javadoc/javacard/framework/SystemException.html b/javadoc/javacard/framework/SystemException.html index 2ce5ca87..57655e74 100644 --- a/javadoc/javacard/framework/SystemException.html +++ b/javadoc/javacard/framework/SystemException.html @@ -2,13 +2,13 @@ - + SystemException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/TransactionException.html b/javadoc/javacard/framework/TransactionException.html index 8bfd5c79..529120c5 100644 --- a/javadoc/javacard/framework/TransactionException.html +++ b/javadoc/javacard/framework/TransactionException.html @@ -2,13 +2,13 @@ - + TransactionException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/UserException.html b/javadoc/javacard/framework/UserException.html index 7fd98d42..7cb81a21 100644 --- a/javadoc/javacard/framework/UserException.html +++ b/javadoc/javacard/framework/UserException.html @@ -2,13 +2,13 @@ - + UserException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/Util.html b/javadoc/javacard/framework/Util.html index 1dfcb402..802db913 100644 --- a/javadoc/javacard/framework/Util.html +++ b/javadoc/javacard/framework/Util.html @@ -2,13 +2,13 @@ - + Util (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/AID.html b/javadoc/javacard/framework/class-use/AID.html index 24b1da9c..a1844062 100644 --- a/javadoc/javacard/framework/class-use/AID.html +++ b/javadoc/javacard/framework/class-use/AID.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.AID (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -95,11 +95,11 @@

    - + - + @@ -132,7 +132,7 @@

    byte bLength)
    -          Create Applet instance in Simulator +           

    +          Install + Applet into Simulator without installing data +          Install + Applet into Simulator. + + + + + + + + +          Load + Applet into Simulator + + + + + + + + +            +          Install + Applet into Simulator without installing data +          Install + Applet into Simulator. + + + + + + + + +          Load + Applet into Simulator + + + + + + + + +           
    com.licel.jcardsim.samples.SecureRMIDemo.Purse
    -public static final shortBAD_ARGUMENT24578
    -public static final shortCORRUPTED_DATA24580
    -public static final shortMAX_AMOUNT400
    -public static final shortOVERFLOW24577com.licel.jcardsim.remote.JavaCardRemoteInterface
    -public static final shortREQUEST_DENIED24579
    -public static final shortUNDERFLOW24576 +public static final StringRMI_SERVER_ID"jCardSim.rmiServer"
      
    com.licel.jcardsim.samples.JavaLoyaltycom.licel.jcardsim.io   
    com.licel.jcardsim.samples.odSample.packageBcom.licel.jcardsim.remote   
    @@ -177,7 +177,8 @@

    Class appletClass)
    -          Install Applet into Simulator without installing data

    @@ -189,7 +190,33 @@

    byte bLength)
    -          Install Applet into Simulator.

    + AIDSimulator.installApplet(AID aid, + String appletClassName, + byte[] appletContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDSimulator.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    @@ -198,7 +225,27 @@

    Class appletClass)
    -          Load Applet into Simulator

    + AIDSimulator.loadApplet(AID aid, + String appletClassName) + +
    +           
    + AIDSimulator.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    @@ -248,7 +295,7 @@

    byte bLength)
    -          Create Applet instance in Simulator

    @@ -283,7 +330,8 @@

    Class appletClass)
    -          Install Applet into Simulator without installing data

    @@ -295,7 +343,33 @@

    byte bLength)
    -          Install Applet into Simulator.

    + AIDSimulator.installApplet(AID aid, + String appletClassName, + byte[] appletContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDSimulator.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    @@ -322,7 +396,27 @@

    Class appletClass)
    -          Load Applet into Simulator

    + AIDSimulator.loadApplet(AID aid, + String appletClassName) + +
    +           
    + AIDSimulator.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    @@ -347,17 +441,16 @@

    Simulator.selectApplet(AID aid)
    -          Select applet by it's AID - It's method must be called before start working with applet instance
     

    - + +Uses of AID in com.licel.jcardsim.io
    -Uses of AID in com.licel.jcardsim.samples.JavaLoyalty
      @@ -365,25 +458,153 @@

    - + - + + + + + + + + + + + + + + + + + + +
    Methods in com.licel.jcardsim.samples.JavaLoyalty with parameters of type AIDMethods in com.licel.jcardsim.io that return AID
    - ShareableJavaLoyalty.getShareableInterfaceObject(AID clientAID, - byte parameter) + AIDJavaCardInterface.createApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Create + Applet instance in Simulator
    + AIDJavaCardInterface.installApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDJavaCardInterface.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDJavaCardInterface.loadApplet(AID aid, + String appletClass) + +
    +          Load + Applet into Simulator
    + AIDJavaCardInterface.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Load + Applet into Simulator
    +  +

    + + + + + + + + + + + + + + + + + + + + +          Load + Applet into Simulator + + + + + + + +
    Methods in com.licel.jcardsim.io with parameters of type AID
    + AIDJavaCardInterface.createApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Create + Applet instance in Simulator
    + AIDJavaCardInterface.installApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDJavaCardInterface.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDJavaCardInterface.loadApplet(AID aid, + String appletClass)
    -          Implements getShareableInterfaceObject method of Applet class.
    + AIDJavaCardInterface.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Load + Applet into Simulator
    + booleanJavaCardInterface.selectApplet(AID aid) + +
    +          Select applet by it's AID + It's method must be called before start working with applet instance
     

    - + +Uses of AID in com.licel.jcardsim.remote
    -Uses of AID in com.licel.jcardsim.samples.odSample.packageB
      @@ -391,16 +612,155 @@

    - + - + + + + + + + + + +            + + + + + + + + + + + + + +
    Methods in com.licel.jcardsim.samples.odSample.packageB with parameters of type AIDMethods in com.licel.jcardsim.remote that return AID
    - ShareableB.getShareableInterfaceObject(AID client_aid, - byte param) + AIDJavaCardRemoteClient.createApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDSerializableAID.getAID() + +
    +           
    + AIDJavaCardRemoteClient.installApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength)
    -          method returns pointer to this instance, ignores the param
    + AIDJavaCardRemoteClient.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDJavaCardRemoteClient.loadApplet(AID aid, + String appletClassName) + +
    +           
    + AIDJavaCardRemoteClient.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    +  +

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Methods in com.licel.jcardsim.remote with parameters of type AID
    + AIDJavaCardRemoteClient.createApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDJavaCardRemoteClient.installApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDJavaCardRemoteClient.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDJavaCardRemoteClient.loadApplet(AID aid, + String appletClassName) + +
    +           
    + AIDJavaCardRemoteClient.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    + booleanJavaCardRemoteClient.selectApplet(AID aid) + +
    +           
    +  +

    + + + + + + +
    Constructors in com.licel.jcardsim.remote with parameters of type AID
    SerializableAID(AID aid) + +
    +           
      diff --git a/javadoc/javacard/framework/class-use/APDU.html b/javadoc/javacard/framework/class-use/APDU.html index e5f7e698..fd1a01d1 100644 --- a/javadoc/javacard/framework/class-use/APDU.html +++ b/javadoc/javacard/framework/class-use/APDU.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.APDU (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -95,50 +95,6 @@

       -com.licel.jcardsim.samples.ChannelsDemo -   - - -com.licel.jcardsim.samples.JavaLoyalty -   - - -com.licel.jcardsim.samples.JavaPurse -   - - -com.licel.jcardsim.samples.NullApp -   - - -com.licel.jcardsim.samples.odSample.packageA -   - - -com.licel.jcardsim.samples.odSample.packageB -   - - -com.licel.jcardsim.samples.photocard -   - - -com.licel.jcardsim.samples.RMIDemo -   - - -com.licel.jcardsim.samples.SecureRMIDemo -   - - -com.licel.jcardsim.samples.ServiceDemo -   - - -com.licel.jcardsim.samples.wallet -   - - javacard.framework    @@ -174,335 +130,6 @@

     

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.ChannelsDemo
    -  -

    - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.ChannelsDemo with parameters of type APDU
    - voidConnectionManager.process(APDU apdu) - -
    -           
    - voidAccountAccessor.process(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.JavaLoyalty
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.JavaLoyalty with parameters of type APDU
    - voidJavaLoyalty.process(APDU apdu) - -
    -          Dispatches APDU commands.
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.JavaPurse
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.JavaPurse with parameters of type APDU
    - voidJavaPurse.process(APDU apdu) - -
    -          Dispatches APDU commands.
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.NullApp
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.NullApp with parameters of type APDU
    - voidNullApp.process(APDU apdu) - -
    -          Returns <0x6D,INS> response status always.
    -  -

    - - - - - - - - -
    Constructors in com.licel.jcardsim.samples.NullApp with parameters of type APDU
    NullApp(APDU apdu) - -
    -          Only this class's install method should create the applet object.
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.odSample.packageA
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.odSample.packageA with parameters of type APDU
    - voidA.process(APDU apdu) - -
    -          method processes the APDU commands passed to this applet instance.
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.odSample.packageB
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.odSample.packageB with parameters of type APDU
    - voidB.process(APDU apdu) - -
    -          method processes the APDU commands passed to this applet instance.
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.photocard
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.photocard with parameters of type APDU
    - voidPhotoCardApplet.process(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.RMIDemo
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.RMIDemo with parameters of type APDU
    - voidPurseApplet.process(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.SecureRMIDemo with parameters of type APDU
    - voidSecurePurseApplet.process(APDU apdu) - -
    -           
    - booleanMySecurityService.processCommand(APDU apdu) - -
    -           
    - booleanMySecurityService.processDataIn(APDU apdu) - -
    -          Pre-processes the input data for the command in the APDU object.
    - booleanMySecurityService.processDataOut(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.ServiceDemo
    -  -

    - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.ServiceDemo with parameters of type APDU
    - voidMain.process(APDU apdu) - -
    -           
    - booleanTestService.processCommand(APDU command) - -
    -           
    -  -

    - - - - - -
    -Uses of APDU in com.licel.jcardsim.samples.wallet
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.wallet with parameters of type APDU
    - voidWallet.process(APDU apdu) - -
    -           
    -  -

    diff --git a/javadoc/javacard/framework/class-use/APDUException.html b/javadoc/javacard/framework/class-use/APDUException.html index 2cb55bbb..0fa9a313 100644 --- a/javadoc/javacard/framework/class-use/APDUException.html +++ b/javadoc/javacard/framework/class-use/APDUException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.APDUException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/Applet.html b/javadoc/javacard/framework/class-use/Applet.html index e4578ec7..fb54f80e 100644 --- a/javadoc/javacard/framework/class-use/Applet.html +++ b/javadoc/javacard/framework/class-use/Applet.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.Applet (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -98,50 +98,6 @@

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    com.licel.jcardsim.samples   
    com.licel.jcardsim.samples.ChannelsDemo  
    com.licel.jcardsim.samples.JavaLoyalty  
    com.licel.jcardsim.samples.JavaPurse  
    com.licel.jcardsim.samples.NullApp  
    com.licel.jcardsim.samples.odSample.packageA  
    com.licel.jcardsim.samples.odSample.packageB  
    com.licel.jcardsim.samples.photocard  
    com.licel.jcardsim.samples.RMIDemo  
    com.licel.jcardsim.samples.SecureRMIDemo  
    com.licel.jcardsim.samples.ServiceDemo  
    com.licel.jcardsim.samples.wallet  
     

    @@ -242,301 +198,6 @@

     

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.ChannelsDemo
    -  -

    - - - - - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.ChannelsDemo
    - classAccountAccessor - -
    -          This applet keeps track of the account information for a - fictional wireless device connecting to a network service.
    - classConnectionManager - -
    -          This applet keeps track of the network connection for a - fictional wireless device.
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.JavaLoyalty
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.JavaLoyalty
    - classJavaLoyalty - -
    -          Minimalistic loyalty applet.
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.JavaPurse
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.JavaPurse
    - classJavaPurse - -
    -          This class is intended to demonstrate how an electronic cash application - might be developed using Java Card - See Java Card(TM) Development Kit User's Guide - for details.
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.NullApp
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.NullApp
    - classNullApp - -
    -           
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.odSample.packageA
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.odSample.packageA
    - classA - -
    -          package AID 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x01 - applet AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x01 0x01 - - This applet used to demonstrate object deletion mechanism and also to - monitor memory usage as other packages/applets get added/deleted
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.odSample.packageB
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.odSample.packageB
    - classB - -
    -          package AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 - applet AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 0x01 - - Applet used to demonstrate applet deletion and package deletion.
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.photocard
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.photocard
    - classPhotoCardApplet - -
    -           
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.RMIDemo
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.RMIDemo
    - classPurseApplet - -
    -           
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.SecureRMIDemo
    - classSecurePurseApplet - -
    -           
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.ServiceDemo
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.ServiceDemo
    - classMain - -
    -           
    -  -

    - - - - - -
    -Uses of Applet in com.licel.jcardsim.samples.wallet
    -  -

    - - - - - - - - - -
    Subclasses of Applet in com.licel.jcardsim.samples.wallet
    - classWallet - -
    -           
    -  -


    diff --git a/javadoc/javacard/framework/class-use/AppletEvent.html b/javadoc/javacard/framework/class-use/AppletEvent.html index b0f81d53..387762e1 100644 --- a/javadoc/javacard/framework/class-use/AppletEvent.html +++ b/javadoc/javacard/framework/class-use/AppletEvent.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.AppletEvent (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -84,46 +84,7 @@

    Uses of Interface
    javacard.framework.AppletEvent

    - - - - - - - - - -
    -Packages that use AppletEvent
    com.licel.jcardsim.samples.odSample.packageB  
    -  -

    - - - - - -
    -Uses of AppletEvent in com.licel.jcardsim.samples.odSample.packageB
    -  -

    - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.odSample.packageB that implement AppletEvent
    - classB - -
    -          package AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 - applet AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 0x01 - - Applet used to demonstrate applet deletion and package deletion.
    -  +No usage of javacard.framework.AppletEvent


    diff --git a/javadoc/javacard/framework/class-use/CardException.html b/javadoc/javacard/framework/class-use/CardException.html index efe0026d..5f025184 100644 --- a/javadoc/javacard/framework/class-use/CardException.html +++ b/javadoc/javacard/framework/class-use/CardException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.CardException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/CardRuntimeException.html b/javadoc/javacard/framework/class-use/CardRuntimeException.html index d970158a..a7b757a1 100644 --- a/javadoc/javacard/framework/class-use/CardRuntimeException.html +++ b/javadoc/javacard/framework/class-use/CardRuntimeException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.CardRuntimeException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/ISO7816.html b/javadoc/javacard/framework/class-use/ISO7816.html index b787ff32..59734704 100644 --- a/javadoc/javacard/framework/class-use/ISO7816.html +++ b/javadoc/javacard/framework/class-use/ISO7816.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.ISO7816 (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/ISOException.html b/javadoc/javacard/framework/class-use/ISOException.html index 7d0f821b..bfb5b7a4 100644 --- a/javadoc/javacard/framework/class-use/ISOException.html +++ b/javadoc/javacard/framework/class-use/ISOException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.ISOException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -95,38 +95,6 @@

       -com.licel.jcardsim.samples.JavaPurseCrypto -   - - -com.licel.jcardsim.samples.NullApp -   - - -com.licel.jcardsim.samples.odSample.packageA -   - - -com.licel.jcardsim.samples.odSample.packageB -   - - -com.licel.jcardsim.samples.photocard -   - - -com.licel.jcardsim.samples.RMIDemo -   - - -com.licel.jcardsim.samples.SecureRMIDemo -   - - -com.licel.jcardsim.samples.ServiceDemo -   - - javacard.framework    @@ -164,206 +132,6 @@

     

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.JavaPurseCrypto
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.JavaPurseCrypto that throw ISOException
    - voidParametersFile.addRecord(byte[] record) - -
    -          Add (append) a new record to the file.
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.NullApp
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.NullApp that throw ISOException
    - voidNullApp.process(APDU apdu) - -
    -          Returns <0x6D,INS> response status always.
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.odSample.packageA
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.odSample.packageA that throw ISOException
    - voidA.process(APDU apdu) - -
    -          method processes the APDU commands passed to this applet instance.
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.odSample.packageB
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.odSample.packageB that throw ISOException
    - voidB.process(APDU apdu) - -
    -          method processes the APDU commands passed to this applet instance.
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.photocard
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.photocard that throw ISOException
    - voidPhotoCardApplet.process(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.RMIDemo
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.RMIDemo that throw ISOException
    - voidPurseApplet.process(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.SecureRMIDemo that throw ISOException
    - voidSecurePurseApplet.process(APDU apdu) - -
    -           
    -  -

    - - - - - -
    -Uses of ISOException in com.licel.jcardsim.samples.ServiceDemo
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.ServiceDemo that throw ISOException
    - voidMain.process(APDU apdu) - -
    -           
    -  -

    diff --git a/javadoc/javacard/framework/class-use/JCSystem.html b/javadoc/javacard/framework/class-use/JCSystem.html index 4814b056..cf930495 100644 --- a/javadoc/javacard/framework/class-use/JCSystem.html +++ b/javadoc/javacard/framework/class-use/JCSystem.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.JCSystem (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/MultiSelectable.html b/javadoc/javacard/framework/class-use/MultiSelectable.html index 1330d469..49fbaacf 100644 --- a/javadoc/javacard/framework/class-use/MultiSelectable.html +++ b/javadoc/javacard/framework/class-use/MultiSelectable.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.MultiSelectable (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -84,53 +84,7 @@

    Uses of Interface
    javacard.framework.MultiSelectable

    - -
    - - - - - - - -
    -Packages that use MultiSelectable
    com.licel.jcardsim.samples.ChannelsDemo  
    -  -

    - - - - - -
    -Uses of MultiSelectable in com.licel.jcardsim.samples.ChannelsDemo
    -  -

    - - - - - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.ChannelsDemo that implement MultiSelectable
    - classAccountAccessor - -
    -          This applet keeps track of the account information for a - fictional wireless device connecting to a network service.
    - classConnectionManager - -
    -          This applet keeps track of the network connection for a - fictional wireless device.
    -  +No usage of javacard.framework.MultiSelectable


    diff --git a/javadoc/javacard/framework/class-use/OwnerPIN.html b/javadoc/javacard/framework/class-use/OwnerPIN.html index 58c43f89..1ebce666 100644 --- a/javadoc/javacard/framework/class-use/OwnerPIN.html +++ b/javadoc/javacard/framework/class-use/OwnerPIN.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.OwnerPIN (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/PIN.html b/javadoc/javacard/framework/class-use/PIN.html index fda183dd..0f578702 100644 --- a/javadoc/javacard/framework/class-use/PIN.html +++ b/javadoc/javacard/framework/class-use/PIN.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.PIN (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/PINException.html b/javadoc/javacard/framework/class-use/PINException.html index 63dec179..4d87b280 100644 --- a/javadoc/javacard/framework/class-use/PINException.html +++ b/javadoc/javacard/framework/class-use/PINException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.PINException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/Shareable.html b/javadoc/javacard/framework/class-use/Shareable.html index 191a519d..98c7a413 100644 --- a/javadoc/javacard/framework/class-use/Shareable.html +++ b/javadoc/javacard/framework/class-use/Shareable.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.Shareable (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -95,18 +95,6 @@

       -com.licel.jcardsim.samples.JavaLoyalty -   - - -com.licel.jcardsim.samples.odSample.packageB -   - - -com.licel.jcardsim.samples.SampleLibrary -   - - javacard.framework    @@ -140,118 +128,6 @@

     

    - - - - - -
    -Uses of Shareable in com.licel.jcardsim.samples.JavaLoyalty
    -  -

    - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.JavaLoyalty that implement Shareable
    - classJavaLoyalty - -
    -          Minimalistic loyalty applet.
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.JavaLoyalty that return Shareable
    - ShareableJavaLoyalty.getShareableInterfaceObject(AID clientAID, - byte parameter) - -
    -          Implements getShareableInterfaceObject method of Applet class.
    -  -

    - - - - - -
    -Uses of Shareable in com.licel.jcardsim.samples.odSample.packageB
    -  -

    - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.odSample.packageB that implement Shareable
    - classB - -
    -          package AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 - applet AID - 0xA0 0x00 0x00 0x00 0x62 0x03 0x01 0x0C 0x07 0x02 0x01 - - Applet used to demonstrate applet deletion and package deletion.
    -  -

    - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.odSample.packageB that return Shareable
    - ShareableB.getShareableInterfaceObject(AID client_aid, - byte param) - -
    -          method returns pointer to this instance, ignores the param
    -  -

    - - - - - -
    -Uses of Shareable in com.licel.jcardsim.samples.SampleLibrary
    -  -

    - - - - - - - - - -
    Subinterfaces of Shareable in com.licel.jcardsim.samples.SampleLibrary
    - interfaceJavaLoyaltyInterface - -
    -          Shareable Loyalty Interface
    -  -

    diff --git a/javadoc/javacard/framework/class-use/SystemException.html b/javadoc/javacard/framework/class-use/SystemException.html index fbeb476d..ac7b7734 100644 --- a/javadoc/javacard/framework/class-use/SystemException.html +++ b/javadoc/javacard/framework/class-use/SystemException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.SystemException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -95,6 +95,14 @@

    + + + + + + + + @@ -124,7 +132,7 @@

    byte bLength)
    -          Create Applet instance in Simulator +           

    +          Install + Applet into Simulator without installing data +          Install + Applet into Simulator. + + + + + + + + +          Load + Applet into Simulator + + + + + + + + +            + + + + + +
      
    com.licel.jcardsim.io  
    com.licel.jcardsim.remote  
    javacard.framework   
    @@ -133,7 +141,8 @@

    Class appletClass)
    -          Install Applet into Simulator without installing data

    @@ -145,7 +154,33 @@

    byte bLength)
    -          Install Applet into Simulator.

    + AIDSimulator.installApplet(AID aid, + String appletClassName, + byte[] appletContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDSimulator.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    @@ -154,7 +189,27 @@

    Class appletClass)
    -          Load Applet into Simulator

    + AIDSimulator.loadApplet(AID aid, + String appletClassName) + +
    +           
    + AIDSimulator.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +           
    @@ -184,16 +239,154 @@

    Simulator.selectApplet(AID aid)
    -          Select applet by it's AID - It's method must be called before start working with applet instance
    + byte[]Simulator.transmitCommand(byte[] command) + +
    +           
    +  +

    + + + + + +
    +Uses of SystemException in com.licel.jcardsim.io
    +  +

    + + + + + + + + + + + + + + + + + + + + + +
    Methods in com.licel.jcardsim.io that throw SystemException
    + AIDJavaCardInterface.createApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Create + Applet instance in Simulator
    + AIDJavaCardInterface.installApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDJavaCardInterface.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +          Install + Applet into Simulator.
    + AIDJavaCardInterface.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents) + +
    +          Load + Applet into Simulator
    +  +

    + + + + + +
    +Uses of SystemException in com.licel.jcardsim.remote
    +  +

    + + + + + + + + + + + + - + + + + + + + + + +           
    Methods in com.licel.jcardsim.remote that throw SystemException
    + AIDJavaCardRemoteClient.createApplet(AID aid, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDJavaCardRemoteClient.installApplet(AID aid, + String appletClassName, + byte[] appletJarContents, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    - javax.smartcardio.ResponseAPDUSimulator.transmitCommand(javax.smartcardio.CommandAPDU commandAPDU) + AIDJavaCardRemoteClient.installApplet(AID aid, + String appletClassName, + byte[] bArray, + short bOffset, + byte bLength) + +
    +           
    + AIDJavaCardRemoteClient.loadApplet(AID aid, + String appletClassName) + +
    +           
    + AIDJavaCardRemoteClient.loadApplet(AID aid, + String appletClassName, + byte[] appletJarContents)
    -          Transmit APDU to previous selected applet
      diff --git a/javadoc/javacard/framework/class-use/TransactionException.html b/javadoc/javacard/framework/class-use/TransactionException.html index 210721c8..92cb44b2 100644 --- a/javadoc/javacard/framework/class-use/TransactionException.html +++ b/javadoc/javacard/framework/class-use/TransactionException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.TransactionException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/class-use/UserException.html b/javadoc/javacard/framework/class-use/UserException.html index 73fd5ce9..84e8f425 100644 --- a/javadoc/javacard/framework/class-use/UserException.html +++ b/javadoc/javacard/framework/class-use/UserException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.UserException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -91,298 +91,12 @@

    Packages that use UserException -com.licel.jcardsim.samples.photocard -   - - -com.licel.jcardsim.samples.RMIDemo -   - - -com.licel.jcardsim.samples.SecureRMIDemo -   - - javacard.framework     

    - - - - - -
    -Uses of UserException in com.licel.jcardsim.samples.photocard
    -  -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.photocard that throw UserException
    - voidPhotoCardImpl.deletePhoto(short photoID) - -
    -           
    - voidPhotoCard.deletePhoto(short photoID) - -
    -          This method deletes the photo whose ID is specified in the card.
    - byte[]PhotoCardImpl.getPhoto(short photoID, - short offset, - short size) - -
    -           
    - byte[]PhotoCard.getPhoto(short photoID, - short offset, - short size) - -
    -          This method retrueves a series of bytes belonging to the photo - from the smart card at the position specified.
    - shortPhotoCardImpl.getPhotoSize(short photoID) - -
    -           
    - shortPhotoCard.getPhotoSize(short photoID) - -
    -          This method retrieves the photo size whose ID is specified.
    - voidPhotoCardImpl.loadPhoto(short photoID, - byte[] data, - short size, - short offset, - boolean more) - -
    -           
    - voidPhotoCard.loadPhoto(short photoID, - byte[] data, - short size, - short offset, - boolean more) - -
    -          This method loads a series of bytes belonging to the photo - into the smart card at the position specified.
    - shortPhotoCardImpl.requestPhotoStorage(short size) - -
    -           
    - shortPhotoCard.requestPhotoStorage(short size) - -
    -          This method requests the smart card to allocate space to store - a photo image of the specified size.
    -  -

    - - - - - -
    -Uses of UserException in com.licel.jcardsim.samples.RMIDemo
    -  -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.RMIDemo that throw UserException
    - voidPurseImpl.credit(short m) - -
    -           
    - voidPurse.credit(short m) - -
    -           
    - voidPurseImpl.debit(short m) - -
    -           
    - voidPurse.debit(short m) - -
    -           
    - voidPurseImpl.setAccountNumber(byte[] number) - -
    -           
    - voidPurse.setAccountNumber(byte[] number) - -
    -           
    -  -

    - - - - - -
    -Uses of UserException in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.SecureRMIDemo that throw UserException
    - voidSecurePurseImpl.credit(short m) - -
    -           
    - voidPurse.credit(short m) - -
    -           
    - voidSecurePurseImpl.debit(short m) - -
    -           
    - voidPurse.debit(short m) - -
    -           
    - byte[]SecurePurseImpl.getAccountNumber() - -
    -           
    - byte[]Purse.getAccountNumber() - -
    -           
    - shortSecurePurseImpl.getBalance() - -
    -           
    - shortPurse.getBalance() - -
    -           
    - voidSecurePurseImpl.setAccountNumber(byte[] number) - -
    -           
    - voidPurse.setAccountNumber(byte[] number) - -
    -           
    -  -

    diff --git a/javadoc/javacard/framework/class-use/Util.html b/javadoc/javacard/framework/class-use/Util.html index e6c0ee7e..92f7da77 100644 --- a/javadoc/javacard/framework/class-use/Util.html +++ b/javadoc/javacard/framework/class-use/Util.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.Util (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/package-frame.html b/javadoc/javacard/framework/package-frame.html index 010625a3..6dffb62f 100644 --- a/javadoc/javacard/framework/package-frame.html +++ b/javadoc/javacard/framework/package-frame.html @@ -2,13 +2,13 @@ - + javacard.framework (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/package-summary.html b/javadoc/javacard/framework/package-summary.html index 4c10f1b1..88b31cb8 100644 --- a/javadoc/javacard/framework/package-summary.html +++ b/javadoc/javacard/framework/package-summary.html @@ -2,13 +2,13 @@ - + javacard.framework (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -56,7 +56,7 @@ - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -198,410 +154,74 @@

      
    com.licel.jcardsim.samples  
    com.licel.jcardsim.samples.ChannelsDemocom.licel.jcardsim.io   
    com.licel.jcardsim.samples.JavaLoyaltycom.licel.jcardsim.remote   
    com.licel.jcardsim.samples.JavaPurse  
    com.licel.jcardsim.samples.JavaPurseCrypto  
    com.licel.jcardsim.samples.NullApp  
    com.licel.jcardsim.samples.RMIDemo  
    com.licel.jcardsim.samples.SampleLibrary  
    com.licel.jcardsim.samples.SecureRMIDemo  
    com.licel.jcardsim.samples.ServiceDemo  
    com.licel.jcardsim.samples.odSample.packageA  
    com.licel.jcardsim.samples.odSample.packageB  
    com.licel.jcardsim.samples.photocard  
    com.licel.jcardsim.samples.walletcom.licel.jcardsim.samples   
     

    - - - - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    -  -

    - - - - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.ChannelsDemo
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    MultiSelectable - -
    -          The MultiSelectable interface identifies the implementing - Applet subclass as being capable of concurrent selections.
    -  -

    - + +Classes in javacard.framework used by com.licel.jcardsim.io - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.JavaLoyalty
    AID +AID
              This class encapsulates the Application Identifier (AID) associated with an applet.
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet +SystemException
    -          This abstract class defines an Java Card technology-based applet.
    Shareable - -
    -          The Shareable interface serves to identify all shared objects.
    -  -

    - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.JavaPurse
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    -  -

    - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.JavaPurseCrypto
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    -  -

    - - - - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.NullApp
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    -  -

    - - - - - - - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.RMIDemo
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    UserException - -
    -          UserException represents a User exception.
    -  -

    - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.SampleLibrary
    Shareable - -
    -          The Shareable interface serves to identify all shared objects.
    -  -

    - - - - - - - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.SecureRMIDemo
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    UserException - -
    -          UserException represents a User exception.
    -  -

    - - - - - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.ServiceDemo
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    -  -

    - - - - - - - - - - - - - +          SystemException represents a JCSystem class related exception.
    -Classes in javacard.framework used by com.licel.jcardsim.samples.odSample.packageA
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
     

    - + +Classes in javacard.framework used by com.licel.jcardsim.remote - - - - - - - - - - - - - - +          SystemException represents a JCSystem class related exception.
    -Classes in javacard.framework used by com.licel.jcardsim.samples.odSample.packageB
    AID +AID
              This class encapsulates the Application Identifier (AID) associated with an applet.
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
    AppletEvent +SystemException
    -          The AppletEvent interface provides a callback interface for - the Java Card runtime environment to inform the applet about life cycle events.
    ISOException - -
    -          ISOException class encapsulates an ISO 7816-4 response status word as - its reason code.
    Shareable - -
    -          The Shareable interface serves to identify all shared objects.
     

    - + +Classes in javacard.framework used by com.licel.jcardsim.samples - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.photocard
    APDU +APDU
              Application Protocol Data Unit (APDU) is the communication format between the card and the off-card applications.
    Applet +Applet
              This abstract class defines an Java Card technology-based applet.
    ISOException +ISOException
              ISOException class encapsulates an ISO 7816-4 response status word as its reason code.
    UserException - -
    -          UserException represents a User exception.
    -  -

    - - - - - - - - - - -
    -Classes in javacard.framework used by com.licel.jcardsim.samples.wallet
    APDU - -
    -          Application Protocol Data Unit (APDU) is - the communication format between the card and the off-card applications.
    Applet - -
    -          This abstract class defines an Java Card technology-based applet.
     

    diff --git a/javadoc/javacard/framework/service/BasicService.html b/javadoc/javacard/framework/service/BasicService.html index 6372ea8b..2c4ea3dd 100644 --- a/javadoc/javacard/framework/service/BasicService.html +++ b/javadoc/javacard/framework/service/BasicService.html @@ -2,13 +2,13 @@ - + BasicService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -100,7 +100,7 @@

    All Implemented Interfaces:
    Service

    -
    Direct Known Subclasses:
    MySecurityService, RMIService, TestService
    +
    Direct Known Subclasses:
    RMIService

    diff --git a/javadoc/javacard/framework/service/CardRemoteObject.html b/javadoc/javacard/framework/service/CardRemoteObject.html index 5fb17e1f..cfa9a015 100644 --- a/javadoc/javacard/framework/service/CardRemoteObject.html +++ b/javadoc/javacard/framework/service/CardRemoteObject.html @@ -2,13 +2,13 @@ - + CardRemoteObject (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -97,14 +97,11 @@

    extended by javacard.framework.service.CardRemoteObject
    -
    All Implemented Interfaces:
    Remote
    -
    -
    -
    Direct Known Subclasses:
    PhotoCardImpl, PurseImpl, SecurePurseImpl
    +
    All Implemented Interfaces:
    Remote

    -
    public class CardRemoteObject
    extends Object
    implements Remote
    +
    public class CardRemoteObject
    extends Object
    implements Remote

    @@ -139,7 +136,7 @@

    static void -export(Remote obj) +export(Remote obj)
                @@ -147,7 +144,7 @@

    static void -unexport(Remote obj) +unexport(Remote obj)
                @@ -195,7 +192,7 @@

    export

    -public static void export(Remote obj)
    +public static void export(Remote obj)
                        throws SecurityException
    @@ -212,7 +209,7 @@

    unexport

    -public static void unexport(Remote obj)
    +public static void unexport(Remote obj)
                          throws SecurityException
    diff --git a/javadoc/javacard/framework/service/Dispatcher.html b/javadoc/javacard/framework/service/Dispatcher.html index 637d49b2..333cc123 100644 --- a/javadoc/javacard/framework/service/Dispatcher.html +++ b/javadoc/javacard/framework/service/Dispatcher.html @@ -2,13 +2,13 @@ - + Dispatcher (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/RMIService.html b/javadoc/javacard/framework/service/RMIService.html index 278f5aa7..45427aed 100644 --- a/javadoc/javacard/framework/service/RMIService.html +++ b/javadoc/javacard/framework/service/RMIService.html @@ -2,13 +2,13 @@ - + RMIService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -136,7 +136,7 @@

    Constructor Summary -RMIService(Remote initialObject) +RMIService(Remote initialObject)
                @@ -230,7 +230,7 @@

    RMIService

    -public RMIService(Remote initialObject)
    +public RMIService(Remote initialObject)
                throws NullPointerException
    diff --git a/javadoc/javacard/framework/service/RemoteService.html b/javadoc/javacard/framework/service/RemoteService.html index d6ea0ce5..ff01b4a1 100644 --- a/javadoc/javacard/framework/service/RemoteService.html +++ b/javadoc/javacard/framework/service/RemoteService.html @@ -2,13 +2,13 @@ - + RemoteService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/SecurityService.html b/javadoc/javacard/framework/service/SecurityService.html index 2500edb0..7b76c296 100644 --- a/javadoc/javacard/framework/service/SecurityService.html +++ b/javadoc/javacard/framework/service/SecurityService.html @@ -2,13 +2,13 @@ - + SecurityService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -95,9 +95,6 @@

    All Superinterfaces:
    Service
    -
    -
    All Known Implementing Classes:
    MySecurityService
    -

    public interface SecurityService
    extends Service
    diff --git a/javadoc/javacard/framework/service/Service.html b/javadoc/javacard/framework/service/Service.html index 5389d1f7..37c9dc3c 100644 --- a/javadoc/javacard/framework/service/Service.html +++ b/javadoc/javacard/framework/service/Service.html @@ -2,13 +2,13 @@ - + Service (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -96,7 +96,7 @@

    All Known Subinterfaces:
    RemoteService, SecurityService

    -
    All Known Implementing Classes:
    BasicService, MySecurityService, RMIService, TestService
    +
    All Known Implementing Classes:
    BasicService, RMIService

    diff --git a/javadoc/javacard/framework/service/ServiceException.html b/javadoc/javacard/framework/service/ServiceException.html index b2ba27fd..46ddbf53 100644 --- a/javadoc/javacard/framework/service/ServiceException.html +++ b/javadoc/javacard/framework/service/ServiceException.html @@ -2,13 +2,13 @@ - + ServiceException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/class-use/BasicService.html b/javadoc/javacard/framework/service/class-use/BasicService.html index 33b1c898..1d82ee1f 100644 --- a/javadoc/javacard/framework/service/class-use/BasicService.html +++ b/javadoc/javacard/framework/service/class-use/BasicService.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.service.BasicService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -91,70 +91,12 @@

    Packages that use BasicService -com.licel.jcardsim.samples.SecureRMIDemo -   - - -com.licel.jcardsim.samples.ServiceDemo -   - - javacard.framework.service     

    - - - - - -
    -Uses of BasicService in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - -
    Subclasses of BasicService in com.licel.jcardsim.samples.SecureRMIDemo
    - classMySecurityService - -
    -           
    -  -

    - - - - - -
    -Uses of BasicService in com.licel.jcardsim.samples.ServiceDemo
    -  -

    - - - - - - - - - -
    Subclasses of BasicService in com.licel.jcardsim.samples.ServiceDemo
    - classTestService - -
    -           
    -  -

    diff --git a/javadoc/javacard/framework/service/class-use/CardRemoteObject.html b/javadoc/javacard/framework/service/class-use/CardRemoteObject.html index 81da8e80..b5406c50 100644 --- a/javadoc/javacard/framework/service/class-use/CardRemoteObject.html +++ b/javadoc/javacard/framework/service/class-use/CardRemoteObject.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.service.CardRemoteObject (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -84,101 +84,7 @@

    Uses of Class
    javacard.framework.service.CardRemoteObject

    - -
    - - - - - - - - - - - - - - - -
    -Packages that use CardRemoteObject
    com.licel.jcardsim.samples.photocard  
    com.licel.jcardsim.samples.RMIDemo  
    com.licel.jcardsim.samples.SecureRMIDemo  
    -  -

    - - - - - -
    -Uses of CardRemoteObject in com.licel.jcardsim.samples.photocard
    -  -

    - - - - - - - - - -
    Subclasses of CardRemoteObject in com.licel.jcardsim.samples.photocard
    - classPhotoCardImpl - -
    -           
    -  -

    - - - - - -
    -Uses of CardRemoteObject in com.licel.jcardsim.samples.RMIDemo
    -  -

    - - - - - - - - - -
    Subclasses of CardRemoteObject in com.licel.jcardsim.samples.RMIDemo
    - classPurseImpl - -
    -           
    -  -

    - - - - - -
    -Uses of CardRemoteObject in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - -
    Subclasses of CardRemoteObject in com.licel.jcardsim.samples.SecureRMIDemo
    - classSecurePurseImpl - -
    -           
    -  +No usage of javacard.framework.service.CardRemoteObject


    diff --git a/javadoc/javacard/framework/service/class-use/Dispatcher.html b/javadoc/javacard/framework/service/class-use/Dispatcher.html index 6cf88128..4140e2ad 100644 --- a/javadoc/javacard/framework/service/class-use/Dispatcher.html +++ b/javadoc/javacard/framework/service/class-use/Dispatcher.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.service.Dispatcher (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/class-use/RMIService.html b/javadoc/javacard/framework/service/class-use/RMIService.html index 1bca9c31..559e1b5a 100644 --- a/javadoc/javacard/framework/service/class-use/RMIService.html +++ b/javadoc/javacard/framework/service/class-use/RMIService.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.service.RMIService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/class-use/RemoteService.html b/javadoc/javacard/framework/service/class-use/RemoteService.html index 3a3579b7..0a58fc11 100644 --- a/javadoc/javacard/framework/service/class-use/RemoteService.html +++ b/javadoc/javacard/framework/service/class-use/RemoteService.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.service.RemoteService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/class-use/SecurityService.html b/javadoc/javacard/framework/service/class-use/SecurityService.html index 2f01309e..011d7099 100644 --- a/javadoc/javacard/framework/service/class-use/SecurityService.html +++ b/javadoc/javacard/framework/service/class-use/SecurityService.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.service.SecurityService (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -84,57 +84,7 @@

    Uses of Interface
    javacard.framework.service.SecurityService

    - - - - - - - - - -
    -Packages that use SecurityService
    com.licel.jcardsim.samples.SecureRMIDemo  
    -  -

    - - - - - -
    -Uses of SecurityService in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.SecureRMIDemo that implement SecurityService
    - classMySecurityService - -
    -           
    -  -

    - - - - - - - - -
    Constructors in com.licel.jcardsim.samples.SecureRMIDemo with parameters of type SecurityService
    SecurePurseImpl(SecurityService security) - -
    -           
    -  +No usage of javacard.framework.service.SecurityService


    diff --git a/javadoc/javacard/framework/service/class-use/Service.html b/javadoc/javacard/framework/service/class-use/Service.html index c0311043..e3c1ad50 100644 --- a/javadoc/javacard/framework/service/class-use/Service.html +++ b/javadoc/javacard/framework/service/class-use/Service.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.framework.service.Service (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -91,70 +91,12 @@

    Packages that use Service -com.licel.jcardsim.samples.SecureRMIDemo -   - - -com.licel.jcardsim.samples.ServiceDemo -   - - javacard.framework.service     

    - - - - - -
    -Uses of Service in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.SecureRMIDemo that implement Service
    - classMySecurityService - -
    -           
    -  -

    - - - - - -
    -Uses of Service in com.licel.jcardsim.samples.ServiceDemo
    -  -

    - - - - - - - - - -
    Classes in com.licel.jcardsim.samples.ServiceDemo that implement Service
    - classTestService - -
    -           
    -  -

    diff --git a/javadoc/javacard/framework/service/class-use/ServiceException.html b/javadoc/javacard/framework/service/class-use/ServiceException.html index 3be4ff75..10b226e2 100644 --- a/javadoc/javacard/framework/service/class-use/ServiceException.html +++ b/javadoc/javacard/framework/service/class-use/ServiceException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.framework.service.ServiceException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -91,50 +91,12 @@

    Packages that use ServiceException

    - - - -
    com.licel.jcardsim.samples.SecureRMIDemo  
    javacard.framework.service   
     

    - - - - - -
    -Uses of ServiceException in com.licel.jcardsim.samples.SecureRMIDemo
    -  -

    - - - - - - - - - - - - - -
    Methods in com.licel.jcardsim.samples.SecureRMIDemo that throw ServiceException
    - booleanMySecurityService.isAuthenticated(short principal) - -
    -          Checks whether or not the specified principal is currently authenticated.
    - booleanMySecurityService.isCommandSecure(byte properties) - -
    -          Checks whether a secure channel is in use between the card and the host for - the ongoing command that guarantees the indicated properties.
    -  -

    diff --git a/javadoc/javacard/framework/service/package-frame.html b/javadoc/javacard/framework/service/package-frame.html index 4f412ebe..4e87b3ae 100644 --- a/javadoc/javacard/framework/service/package-frame.html +++ b/javadoc/javacard/framework/service/package-frame.html @@ -2,13 +2,13 @@ - + javacard.framework.service (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/package-summary.html b/javadoc/javacard/framework/service/package-summary.html index f79ceca3..8c60eb29 100644 --- a/javadoc/javacard/framework/service/package-summary.html +++ b/javadoc/javacard/framework/service/package-summary.html @@ -2,13 +2,13 @@ - + javacard.framework.service (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/framework/service/package-tree.html b/javadoc/javacard/framework/service/package-tree.html index 4d20004a..f79f947f 100644 --- a/javadoc/javacard/framework/service/package-tree.html +++ b/javadoc/javacard/framework/service/package-tree.html @@ -2,13 +2,13 @@ - + javacard.framework.service Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -97,7 +97,7 @@

    -
  • javacard.framework.service.CardRemoteObject (implements java.rmi.Remote) +
  • javacard.framework.service.CardRemoteObject (implements java.rmi.Remote)
  • javacard.framework.service.Dispatcher
  • java.lang.Throwable (implements java.io.Serializable)
    • java.lang.Exception
        diff --git a/javadoc/javacard/framework/service/package-use.html b/javadoc/javacard/framework/service/package-use.html index bfee1c07..e25f68fc 100644 --- a/javadoc/javacard/framework/service/package-use.html +++ b/javadoc/javacard/framework/service/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package javacard.framework.service (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -91,118 +91,12 @@

        Packages that use javacard.framework.service

  • - - - - - - - - - - - - - - - -
    com.licel.jcardsim.samples.RMIDemo  
    com.licel.jcardsim.samples.SecureRMIDemo  
    com.licel.jcardsim.samples.ServiceDemo  
    com.licel.jcardsim.samples.photocard  
    javacard.framework.service   
     

    - - - - - - - - -
    -Classes in javacard.framework.service used by com.licel.jcardsim.samples.RMIDemo
    CardRemoteObject - -
    -           
    -  -

    - - - - - - - - - - - - - - - - - - - - -
    -Classes in javacard.framework.service used by com.licel.jcardsim.samples.SecureRMIDemo
    BasicService - -
    -           
    CardRemoteObject - -
    -           
    SecurityService - -
    -           
    Service - -
    -           
    ServiceException - -
    -           
    -  -

    - - - - - - - - - - - -
    -Classes in javacard.framework.service used by com.licel.jcardsim.samples.ServiceDemo
    BasicService - -
    -           
    Service - -
    -           
    -  -

    - - - - - - - - -
    -Classes in javacard.framework.service used by com.licel.jcardsim.samples.photocard
    CardRemoteObject - -
    -           
    -  -

    diff --git a/javadoc/javacard/security/AESKey.html b/javadoc/javacard/security/AESKey.html index a3117951..98c960fb 100644 --- a/javadoc/javacard/security/AESKey.html +++ b/javadoc/javacard/security/AESKey.html @@ -2,13 +2,13 @@ - + AESKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/Checksum.html b/javadoc/javacard/security/Checksum.html index 5d1704cc..7903dbb1 100644 --- a/javadoc/javacard/security/Checksum.html +++ b/javadoc/javacard/security/Checksum.html @@ -2,13 +2,13 @@ - + Checksum (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/CryptoException.html b/javadoc/javacard/security/CryptoException.html index fee0ee5e..ef0e4435 100644 --- a/javadoc/javacard/security/CryptoException.html +++ b/javadoc/javacard/security/CryptoException.html @@ -2,13 +2,13 @@ - + CryptoException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/DESKey.html b/javadoc/javacard/security/DESKey.html index 9d5743c6..4bf53efc 100644 --- a/javadoc/javacard/security/DESKey.html +++ b/javadoc/javacard/security/DESKey.html @@ -2,13 +2,13 @@ - + DESKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/DSAKey.html b/javadoc/javacard/security/DSAKey.html index cb2bbe95..eb74b14b 100644 --- a/javadoc/javacard/security/DSAKey.html +++ b/javadoc/javacard/security/DSAKey.html @@ -2,13 +2,13 @@ - + DSAKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/DSAPrivateKey.html b/javadoc/javacard/security/DSAPrivateKey.html index 26ab7c37..2a587b98 100644 --- a/javadoc/javacard/security/DSAPrivateKey.html +++ b/javadoc/javacard/security/DSAPrivateKey.html @@ -2,13 +2,13 @@ - + DSAPrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/DSAPublicKey.html b/javadoc/javacard/security/DSAPublicKey.html index 84416f59..ddf12f66 100644 --- a/javadoc/javacard/security/DSAPublicKey.html +++ b/javadoc/javacard/security/DSAPublicKey.html @@ -2,13 +2,13 @@ - + DSAPublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/ECKey.html b/javadoc/javacard/security/ECKey.html index 55fa2a16..e800ec19 100644 --- a/javadoc/javacard/security/ECKey.html +++ b/javadoc/javacard/security/ECKey.html @@ -2,13 +2,13 @@ - + ECKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/ECPrivateKey.html b/javadoc/javacard/security/ECPrivateKey.html index fa4e1c53..ba04288a 100644 --- a/javadoc/javacard/security/ECPrivateKey.html +++ b/javadoc/javacard/security/ECPrivateKey.html @@ -2,13 +2,13 @@ - + ECPrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/ECPublicKey.html b/javadoc/javacard/security/ECPublicKey.html index 75d1a1e3..e62720f8 100644 --- a/javadoc/javacard/security/ECPublicKey.html +++ b/javadoc/javacard/security/ECPublicKey.html @@ -2,13 +2,13 @@ - + ECPublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/Key.html b/javadoc/javacard/security/Key.html index c9aadb1c..b4c083e3 100644 --- a/javadoc/javacard/security/Key.html +++ b/javadoc/javacard/security/Key.html @@ -2,13 +2,13 @@ - + Key (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/KeyAgreement.html b/javadoc/javacard/security/KeyAgreement.html index 2170a8f3..a1572372 100644 --- a/javadoc/javacard/security/KeyAgreement.html +++ b/javadoc/javacard/security/KeyAgreement.html @@ -2,13 +2,13 @@ - + KeyAgreement (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/KeyBuilder.html b/javadoc/javacard/security/KeyBuilder.html index 1692f291..2b5425c7 100644 --- a/javadoc/javacard/security/KeyBuilder.html +++ b/javadoc/javacard/security/KeyBuilder.html @@ -2,13 +2,13 @@ - + KeyBuilder (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/KeyPair.html b/javadoc/javacard/security/KeyPair.html index b7714ef6..4ca43624 100644 --- a/javadoc/javacard/security/KeyPair.html +++ b/javadoc/javacard/security/KeyPair.html @@ -2,13 +2,13 @@ - + KeyPair (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/MessageDigest.html b/javadoc/javacard/security/MessageDigest.html index a171843f..2b183123 100644 --- a/javadoc/javacard/security/MessageDigest.html +++ b/javadoc/javacard/security/MessageDigest.html @@ -2,13 +2,13 @@ - + MessageDigest (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/PrivateKey.html b/javadoc/javacard/security/PrivateKey.html index 407090b7..097b140d 100644 --- a/javadoc/javacard/security/PrivateKey.html +++ b/javadoc/javacard/security/PrivateKey.html @@ -2,13 +2,13 @@ - + PrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/PublicKey.html b/javadoc/javacard/security/PublicKey.html index fd77a82a..efc19e9e 100644 --- a/javadoc/javacard/security/PublicKey.html +++ b/javadoc/javacard/security/PublicKey.html @@ -2,13 +2,13 @@ - + PublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/RSAPrivateCrtKey.html b/javadoc/javacard/security/RSAPrivateCrtKey.html index 7129c914..e7d2c52e 100644 --- a/javadoc/javacard/security/RSAPrivateCrtKey.html +++ b/javadoc/javacard/security/RSAPrivateCrtKey.html @@ -2,13 +2,13 @@ - + RSAPrivateCrtKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/RSAPrivateKey.html b/javadoc/javacard/security/RSAPrivateKey.html index 28bd4009..769d7f5f 100644 --- a/javadoc/javacard/security/RSAPrivateKey.html +++ b/javadoc/javacard/security/RSAPrivateKey.html @@ -2,13 +2,13 @@ - + RSAPrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/RSAPublicKey.html b/javadoc/javacard/security/RSAPublicKey.html index 6bf97d74..37183ec9 100644 --- a/javadoc/javacard/security/RSAPublicKey.html +++ b/javadoc/javacard/security/RSAPublicKey.html @@ -2,13 +2,13 @@ - + RSAPublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/RandomData.html b/javadoc/javacard/security/RandomData.html index 6675c06a..b9316fec 100644 --- a/javadoc/javacard/security/RandomData.html +++ b/javadoc/javacard/security/RandomData.html @@ -2,13 +2,13 @@ - + RandomData (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/SecretKey.html b/javadoc/javacard/security/SecretKey.html index ba599b62..e110178e 100644 --- a/javadoc/javacard/security/SecretKey.html +++ b/javadoc/javacard/security/SecretKey.html @@ -2,13 +2,13 @@ - + SecretKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/Signature.html b/javadoc/javacard/security/Signature.html index 034a253c..abd74be1 100644 --- a/javadoc/javacard/security/Signature.html +++ b/javadoc/javacard/security/Signature.html @@ -2,13 +2,13 @@ - + Signature (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/AESKey.html b/javadoc/javacard/security/class-use/AESKey.html index a97c3745..24621830 100644 --- a/javadoc/javacard/security/class-use/AESKey.html +++ b/javadoc/javacard/security/class-use/AESKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.AESKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/Checksum.html b/javadoc/javacard/security/class-use/Checksum.html index e61feafe..c6deda1b 100644 --- a/javadoc/javacard/security/class-use/Checksum.html +++ b/javadoc/javacard/security/class-use/Checksum.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.Checksum (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/CryptoException.html b/javadoc/javacard/security/class-use/CryptoException.html index 8fba5b41..679fa825 100644 --- a/javadoc/javacard/security/class-use/CryptoException.html +++ b/javadoc/javacard/security/class-use/CryptoException.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.CryptoException (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -171,8 +171,8 @@

    +          (Re)Initializes the key objects encapsulated in this + KeyPair instance with new key values. @@ -731,8 +732,9 @@

    PrivateKey privateKey)
    -          Constructs a new KeyPair object containing the specified - public key and private key. +          Constructs a new + KeyPair object containing the specified public key and + private key.

    KeyPairImpl.genKeyPair()
    -          (Re)Initializes the key objects encapsulated in this KeyPair instance - with new key values.
    @@ -723,7 +723,8 @@

    short keyLength)
    -          Constructs a KeyPair instance for the specified algorithm and keylength; +          Constructs a + KeyPair instance for the specified algorithm and keylength; the encapsulated keys are uninitialized.

      diff --git a/javadoc/javacard/security/class-use/DESKey.html b/javadoc/javacard/security/class-use/DESKey.html index a9c2e7b5..afba16d5 100644 --- a/javadoc/javacard/security/class-use/DESKey.html +++ b/javadoc/javacard/security/class-use/DESKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.DESKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/DSAKey.html b/javadoc/javacard/security/class-use/DSAKey.html index 6a8798ef..29135d99 100644 --- a/javadoc/javacard/security/class-use/DSAKey.html +++ b/javadoc/javacard/security/class-use/DSAKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.DSAKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/DSAPrivateKey.html b/javadoc/javacard/security/class-use/DSAPrivateKey.html index 1f676c3b..4c708f9d 100644 --- a/javadoc/javacard/security/class-use/DSAPrivateKey.html +++ b/javadoc/javacard/security/class-use/DSAPrivateKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.DSAPrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/DSAPublicKey.html b/javadoc/javacard/security/class-use/DSAPublicKey.html index fe3fe7c5..c99d8858 100644 --- a/javadoc/javacard/security/class-use/DSAPublicKey.html +++ b/javadoc/javacard/security/class-use/DSAPublicKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.DSAPublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/ECKey.html b/javadoc/javacard/security/class-use/ECKey.html index d56814c5..b2fc2115 100644 --- a/javadoc/javacard/security/class-use/ECKey.html +++ b/javadoc/javacard/security/class-use/ECKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.ECKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -121,8 +121,8 @@

    ECKeyImpl
    -          Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI +          Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI diff --git a/javadoc/javacard/security/class-use/ECPrivateKey.html b/javadoc/javacard/security/class-use/ECPrivateKey.html index 3668a049..53e9a739 100644 --- a/javadoc/javacard/security/class-use/ECPrivateKey.html +++ b/javadoc/javacard/security/class-use/ECPrivateKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.ECPrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/ECPublicKey.html b/javadoc/javacard/security/class-use/ECPublicKey.html index 635b05bf..5c264342 100644 --- a/javadoc/javacard/security/class-use/ECPublicKey.html +++ b/javadoc/javacard/security/class-use/ECPublicKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.ECPublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/Key.html b/javadoc/javacard/security/class-use/Key.html index 68ac3d6b..071e1d3b 100644 --- a/javadoc/javacard/security/class-use/Key.html +++ b/javadoc/javacard/security/class-use/Key.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.Key (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -152,8 +152,8 @@

    ECKeyImpl
    -          Base class for ECPublicKeyImpl/ECPrivateKeyImpl - on BouncyCastle CryptoAPI +          Base class for + ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI @@ -187,8 +187,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI diff --git a/javadoc/javacard/security/class-use/KeyAgreement.html b/javadoc/javacard/security/class-use/KeyAgreement.html index 74bc4d55..3b8ada03 100644 --- a/javadoc/javacard/security/class-use/KeyAgreement.html +++ b/javadoc/javacard/security/class-use/KeyAgreement.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.KeyAgreement (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/KeyBuilder.html b/javadoc/javacard/security/class-use/KeyBuilder.html index 3f83a991..2db5fe37 100644 --- a/javadoc/javacard/security/class-use/KeyBuilder.html +++ b/javadoc/javacard/security/class-use/KeyBuilder.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.KeyBuilder (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/KeyPair.html b/javadoc/javacard/security/class-use/KeyPair.html index d374ec76..940d7432 100644 --- a/javadoc/javacard/security/class-use/KeyPair.html +++ b/javadoc/javacard/security/class-use/KeyPair.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.KeyPair (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/MessageDigest.html b/javadoc/javacard/security/class-use/MessageDigest.html index 0716c658..3f3398f8 100644 --- a/javadoc/javacard/security/class-use/MessageDigest.html +++ b/javadoc/javacard/security/class-use/MessageDigest.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.MessageDigest (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/PrivateKey.html b/javadoc/javacard/security/class-use/PrivateKey.html index 888887de..d20dcc70 100644 --- a/javadoc/javacard/security/class-use/PrivateKey.html +++ b/javadoc/javacard/security/class-use/PrivateKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.PrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -139,8 +139,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI @@ -165,7 +165,8 @@

    KeyPairImpl.getPrivate()
    -          Returns a reference to the private key component of this KeyPair object. +          Returns a reference to the private key component of this + KeyPair object.   @@ -196,8 +197,9 @@

    PrivateKey privateKey)
    -          Constructs a new KeyPair object containing the specified - public key and private key. +          Constructs a new + KeyPair object containing the specified public key and + private key.   diff --git a/javadoc/javacard/security/class-use/PublicKey.html b/javadoc/javacard/security/class-use/PublicKey.html index 61010d19..152a53cc 100644 --- a/javadoc/javacard/security/class-use/PublicKey.html +++ b/javadoc/javacard/security/class-use/PublicKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.PublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -139,8 +139,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI @@ -165,7 +165,8 @@

    KeyPairImpl.getPublic()
    -          Returns a reference to the public key component of this KeyPair object. +          Returns a reference to the public key component of this + KeyPair object.   @@ -180,8 +181,9 @@

    PrivateKey privateKey)
    -          Constructs a new KeyPair object containing the specified - public key and private key. +          Constructs a new + KeyPair object containing the specified public key and + private key.   diff --git a/javadoc/javacard/security/class-use/RSAPrivateCrtKey.html b/javadoc/javacard/security/class-use/RSAPrivateCrtKey.html index f380864b..a2cf9466 100644 --- a/javadoc/javacard/security/class-use/RSAPrivateCrtKey.html +++ b/javadoc/javacard/security/class-use/RSAPrivateCrtKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.RSAPrivateCrtKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/RSAPrivateKey.html b/javadoc/javacard/security/class-use/RSAPrivateKey.html index 7ab8bb9f..86ca3a8b 100644 --- a/javadoc/javacard/security/class-use/RSAPrivateKey.html +++ b/javadoc/javacard/security/class-use/RSAPrivateKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.RSAPrivateKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -117,8 +117,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI diff --git a/javadoc/javacard/security/class-use/RSAPublicKey.html b/javadoc/javacard/security/class-use/RSAPublicKey.html index be1d0204..9afb038e 100644 --- a/javadoc/javacard/security/class-use/RSAPublicKey.html +++ b/javadoc/javacard/security/class-use/RSAPublicKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.RSAPublicKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -117,8 +117,8 @@

    RSAKeyImpl
    -          Implementation RSAPublic/RSAPrivate based - on BouncyCastle CryptoAPI +          Implementation + RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI diff --git a/javadoc/javacard/security/class-use/RandomData.html b/javadoc/javacard/security/class-use/RandomData.html index 502f6e3d..59cc5b05 100644 --- a/javadoc/javacard/security/class-use/RandomData.html +++ b/javadoc/javacard/security/class-use/RandomData.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.RandomData (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/SecretKey.html b/javadoc/javacard/security/class-use/SecretKey.html index 3d9085ea..2863a2d7 100644 --- a/javadoc/javacard/security/class-use/SecretKey.html +++ b/javadoc/javacard/security/class-use/SecretKey.html @@ -2,13 +2,13 @@ - + Uses of Interface javacard.security.SecretKey (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/class-use/Signature.html b/javadoc/javacard/security/class-use/Signature.html index 61a68f0b..b01d9d20 100644 --- a/javadoc/javacard/security/class-use/Signature.html +++ b/javadoc/javacard/security/class-use/Signature.html @@ -2,13 +2,13 @@ - + Uses of Class javacard.security.Signature (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/package-frame.html b/javadoc/javacard/security/package-frame.html index 2a36bdfb..23ff8f63 100644 --- a/javadoc/javacard/security/package-frame.html +++ b/javadoc/javacard/security/package-frame.html @@ -2,13 +2,13 @@ - + javacard.security (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/package-summary.html b/javadoc/javacard/security/package-summary.html index 14c731d9..bd165c7a 100644 --- a/javadoc/javacard/security/package-summary.html +++ b/javadoc/javacard/security/package-summary.html @@ -2,13 +2,13 @@ - + javacard.security (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/package-tree.html b/javadoc/javacard/security/package-tree.html index 7025945c..10a49f79 100644 --- a/javadoc/javacard/security/package-tree.html +++ b/javadoc/javacard/security/package-tree.html @@ -2,13 +2,13 @@ - + javacard.security Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacard/security/package-use.html b/javadoc/javacard/security/package-use.html index 6babce75..f3ff5e65 100644 --- a/javadoc/javacard/security/package-use.html +++ b/javadoc/javacard/security/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package javacard.security (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/Cipher.html b/javadoc/javacardx/crypto/Cipher.html index 7f82339b..45071823 100644 --- a/javadoc/javacardx/crypto/Cipher.html +++ b/javadoc/javacardx/crypto/Cipher.html @@ -2,13 +2,13 @@ - + Cipher (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/KeyEncryption.html b/javadoc/javacardx/crypto/KeyEncryption.html index cb95f805..730c4507 100644 --- a/javadoc/javacardx/crypto/KeyEncryption.html +++ b/javadoc/javacardx/crypto/KeyEncryption.html @@ -2,13 +2,13 @@ - + KeyEncryption (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/class-use/Cipher.html b/javadoc/javacardx/crypto/class-use/Cipher.html index 67a05d66..d4fe8b8c 100644 --- a/javadoc/javacardx/crypto/class-use/Cipher.html +++ b/javadoc/javacardx/crypto/class-use/Cipher.html @@ -2,13 +2,13 @@ - + Uses of Class javacardx.crypto.Cipher (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/class-use/KeyEncryption.html b/javadoc/javacardx/crypto/class-use/KeyEncryption.html index 0b2e08e5..2ece3540 100644 --- a/javadoc/javacardx/crypto/class-use/KeyEncryption.html +++ b/javadoc/javacardx/crypto/class-use/KeyEncryption.html @@ -2,13 +2,13 @@ - + Uses of Interface javacardx.crypto.KeyEncryption (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/package-frame.html b/javadoc/javacardx/crypto/package-frame.html index cb101765..af0ebc83 100644 --- a/javadoc/javacardx/crypto/package-frame.html +++ b/javadoc/javacardx/crypto/package-frame.html @@ -2,13 +2,13 @@ - + javacardx.crypto (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/package-summary.html b/javadoc/javacardx/crypto/package-summary.html index 3809bbde..a2db65d5 100644 --- a/javadoc/javacardx/crypto/package-summary.html +++ b/javadoc/javacardx/crypto/package-summary.html @@ -2,13 +2,13 @@ - + javacardx.crypto (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/package-tree.html b/javadoc/javacardx/crypto/package-tree.html index ccf74527..0c516ac7 100644 --- a/javadoc/javacardx/crypto/package-tree.html +++ b/javadoc/javacardx/crypto/package-tree.html @@ -2,13 +2,13 @@ - + javacardx.crypto Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/javacardx/crypto/package-use.html b/javadoc/javacardx/crypto/package-use.html index 727fd191..d96e1d5f 100644 --- a/javadoc/javacardx/crypto/package-use.html +++ b/javadoc/javacardx/crypto/package-use.html @@ -2,13 +2,13 @@ - + Uses of Package javacardx.crypto (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + diff --git a/javadoc/overview-frame.html b/javadoc/overview-frame.html index aa2276a6..2cdc6e8f 100644 --- a/javadoc/overview-frame.html +++ b/javadoc/overview-frame.html @@ -2,13 +2,13 @@ - + Overview List (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -35,42 +35,16 @@
    com.licel.jcardsim.crypto
    -com.licel.jcardsim.samples -
    -com.licel.jcardsim.samples.ChannelsDemo -
    -com.licel.jcardsim.samples.JavaLoyalty -
    -com.licel.jcardsim.samples.JavaPurse -
    -com.licel.jcardsim.samples.JavaPurseCrypto -
    -com.licel.jcardsim.samples.NullApp -
    -com.licel.jcardsim.samples.odSample.libPackageC -
    -com.licel.jcardsim.samples.odSample.packageA +com.licel.jcardsim.io
    -com.licel.jcardsim.samples.odSample.packageB +com.licel.jcardsim.remote
    -com.licel.jcardsim.samples.photocard -
    -com.licel.jcardsim.samples.RMIDemo -
    -com.licel.jcardsim.samples.SampleLibrary -
    -com.licel.jcardsim.samples.SecureRMIDemo -
    -com.licel.jcardsim.samples.ServiceDemo -
    -com.licel.jcardsim.samples.wallet +com.licel.jcardsim.samples
    com.licel.jcardsim.smartcardio
    com.licel.jcardsim.utils
    -java.rmi -
    javacard.framework
    javacard.framework.service diff --git a/javadoc/overview-summary.html b/javadoc/overview-summary.html index 24fa23b7..ebdf7538 100644 --- a/javadoc/overview-summary.html +++ b/javadoc/overview-summary.html @@ -2,13 +2,13 @@ - + Overview (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -100,63 +100,15 @@

      -com.licel.jcardsim.samples -  - - -com.licel.jcardsim.samples.ChannelsDemo +com.licel.jcardsim.io   -com.licel.jcardsim.samples.JavaLoyalty +com.licel.jcardsim.remote   -com.licel.jcardsim.samples.JavaPurse -  - - -com.licel.jcardsim.samples.JavaPurseCrypto -  - - -com.licel.jcardsim.samples.NullApp -  - - -com.licel.jcardsim.samples.odSample.libPackageC -  - - -com.licel.jcardsim.samples.odSample.packageA -  - - -com.licel.jcardsim.samples.odSample.packageB -  - - -com.licel.jcardsim.samples.photocard -  - - -com.licel.jcardsim.samples.RMIDemo -  - - -com.licel.jcardsim.samples.SampleLibrary -  - - -com.licel.jcardsim.samples.SecureRMIDemo -  - - -com.licel.jcardsim.samples.ServiceDemo -  - - -com.licel.jcardsim.samples.wallet +com.licel.jcardsim.samples   @@ -168,10 +120,6 @@

      -java.rmi -  - - javacard.framework   diff --git a/javadoc/overview-tree.html b/javadoc/overview-tree.html index a1e70795..11bbafb3 100644 --- a/javadoc/overview-tree.html +++ b/javadoc/overview-tree.html @@ -2,13 +2,13 @@ - + Class Hierarchy (Java Card Runime Environment Simulator 2.2.1-SNAPSHOT API) - + @@ -85,7 +85,7 @@

    Hierarchy For All Packages

    -
    Package Hierarchies:
    com.licel.jcardsim.base, com.licel.jcardsim.crypto, com.licel.jcardsim.samples, com.licel.jcardsim.samples.ChannelsDemo, com.licel.jcardsim.samples.JavaLoyalty, com.licel.jcardsim.samples.JavaPurse, com.licel.jcardsim.samples.JavaPurseCrypto, com.licel.jcardsim.samples.NullApp, com.licel.jcardsim.samples.odSample.libPackageC, com.licel.jcardsim.samples.odSample.packageA, com.licel.jcardsim.samples.odSample.packageB, com.licel.jcardsim.samples.photocard, com.licel.jcardsim.samples.RMIDemo, com.licel.jcardsim.samples.SampleLibrary, com.licel.jcardsim.samples.SecureRMIDemo, com.licel.jcardsim.samples.ServiceDemo, com.licel.jcardsim.samples.wallet, com.licel.jcardsim.smartcardio, com.licel.jcardsim.utils, java.rmi, javacard.framework, javacard.framework.service, javacard.security, javacardx.crypto
    +
    Package Hierarchies:
    com.licel.jcardsim.base, com.licel.jcardsim.crypto, com.licel.jcardsim.io, com.licel.jcardsim.remote, com.licel.jcardsim.samples, com.licel.jcardsim.smartcardio, com.licel.jcardsim.utils, javacard.framework, javacard.framework.service, javacard.security, javacardx.crypto


    Class Hierarchy @@ -93,26 +93,16 @@

    -byte[] objBytes
    +byte[] aidBytes

    -locBytes

    +aidLen

    -byte[] locBytes
    +byte aidLen
    -
    -

    -hash

    -
    -int hash
    -
    -
    -
    -
    - -

    - - - - - -
    -Class java.rmi.NoSuchObjectException extends RemoteException implements Serializable
    - -

    -serialVersionUID: 6619395951570472985L - -

    - -

    - - - - - -
    -Class java.rmi.NotBoundException extends Exception implements Serializable
    - -

    -serialVersionUID: -1857741824849069317L - -

    - -

    - - - - - -
    -Class java.rmi.RemoteException extends IOException implements Serializable
    - -

    - -

    - - - - - -
    -Class java.rmi.RMISecurityException extends SecurityException implements Serializable
    - -

    -serialVersionUID: -8433406075740433514L - -

    - -

    - - - - - -
    -Class java.rmi.ServerError extends RemoteException implements Serializable
    - -

    -serialVersionUID: 8455284893909696482L - -

    - -

    - - - - - -
    -Class java.rmi.ServerException extends RemoteException implements Serializable
    - -

    -serialVersionUID: -4775845313121906682L - -

    - -

    - - - - - -
    -Class java.rmi.ServerRuntimeException extends RemoteException implements Serializable
    - -

    -serialVersionUID: 7054464920481467219L - -

    - -

    - - - - - -
    -Class java.rmi.StubNotFoundException extends RemoteException implements Serializable
    - -

    -serialVersionUID: -7088199405468872373L - -

    +


    -

    - - - -
    -Class java.rmi.UnexpectedException extends RemoteException implements Serializable
    - -

    -serialVersionUID: 1800467484195073863L - -

    - -

    - - - - +
    -Class java.rmi.UnknownHostException extends RemoteException implements Serializable +Package com.licel.jcardsim.smartcardio

    -serialVersionUID: -8152710247442114228L - -

    - -

    - + +Class com.licel.jcardsim.smartcardio.JCardSimProvider extends Provider implements Serializable
    -Class java.rmi.UnmarshalException extends RemoteException implements Serializable
    -

    -serialVersionUID: 594380845140740218L -


    diff --git a/jcardsim-2.2.1-all.jar b/jcardsim-2.2.1-all.jar index db66f1c9..a66754d6 100644 Binary files a/jcardsim-2.2.1-all.jar and b/jcardsim-2.2.1-all.jar differ diff --git a/jcardsim-2.2.1-SNAPSHOT.jar b/jcardsim-2.2.2-all.jar similarity index 57% rename from jcardsim-2.2.1-SNAPSHOT.jar rename to jcardsim-2.2.2-all.jar index bddf0bab..0ac10c01 100644 Binary files a/jcardsim-2.2.1-SNAPSHOT.jar and b/jcardsim-2.2.2-all.jar differ diff --git a/jcardsim.cfg b/jcardsim.cfg index 889d064e..8e0ba916 100644 --- a/jcardsim.cfg +++ b/jcardsim.cfg @@ -1,2 +1,5 @@ -com.licel.jcardsim.smartcardio.applet.0.AID=010203040506070809 -com.licel.jcardsim.smartcardio.applet.0.Class=com.licel.jcardsim.samples.HelloWorldApplet +com.licel.jcardsim.card.applet.0.AID=010203040506070809 +com.licel.jcardsim.card.applet.0.Class=com.licel.jcardsim.samples.HelloWorldApplet +com.licel.jcardsim.terminal.type=2 +#com.licel.jcardsim.terminal.host=localhost +#com.licel.jcardsim.terminal.port=1234 diff --git a/pom.xml b/pom.xml index 2d677359..c23d918a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,24 +1,29 @@ - + 4.0.0 com.licel - 2.2.1-SNAPSHOT + 3.0.4-SNAPSHOT jar http://maven.apache.org - - org.sonatype.oss - oss-parent - 7 - - + jcardsim + Java Card Runime Environment Simulator + jCardSim is open-source library contains implementation of Java Card API + Licel LLC https://licel.ru + + + jcarsim@licelus.com + jCardSim Team + Licel LLC + + + Apache 2 @@ -30,13 +35,86 @@ UTF-8 apache20 + 2.10.1 + + + + bintray-jcardsim-maven-jCardSim + jcardsim-maven-jCardSim + https://api.bintray.com/maven/jcardsim/maven/jCardSim + + - scm:svn:http://jcardsim.googlecode.com/svn/trunk/ - scm:svn:https://jcardsim.googlecode.com/svn/trunk/ - http://jcardsim.googlecode.com/svn/trunk/ + scm:git:git@github.com:licel/jcardsim.git + scm:git:git@github.com:licel/jcardsim.git + git@github.com:licel/jcardsim.git + + + + sign + + + keystoreLocation + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + verify + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + false +   + + + + org.apache.maven.plugins + maven-jarsigner-plugin + 1.2 + + + sign + + sign + + + + verify + + verify + + + + + ${keystoreLocation} + ${keyAlias} + ${keystorePass} + ${keyPass} + ${storeType} + + + + + + @@ -50,16 +128,8 @@ bcprov-jdk14 1.46 - - com.google.android - android - 4.1.1.4 - jar - - jcardsim - Java Card Runime Environment Simulator - jCardSim is open-source library contains implementation of Java Card API + @@ -74,11 +144,13 @@ org.apache.maven.plugins maven-javadoc-plugin - 2.8.1 + ${maven-javadoc-plugin.version} -
     
    + + http://docs.oracle.com/javase/7/docs/api/ + http://docs.oracle.com/javase/7/docs/jre/api/security/smartcardio/spec/ + false -  
    @@ -112,32 +184,7 @@ - - org.apache.maven.plugins - maven-jarsigner-plugin - 1.2 - - - sign - - sign - - - - verify - - verify - - - - - ${keystoreLocation} - ${keyAlias} - ${keystorePass} - ${keyPass} - ${storeType} - -
    + diff --git a/sitedocs/getting_source_and_compiling.md b/sitedocs/getting_source_and_compiling.md new file mode 100644 index 00000000..1a048301 --- /dev/null +++ b/sitedocs/getting_source_and_compiling.md @@ -0,0 +1,17 @@ +jCardSim is an open source project and it would be pleasure for us to see you as commiters and contributors! + +### Source code +The official jCardSim source repository is located at [https://github.com/licel/jcardsim](https://github.com/licel/jcardsim). + +### Building +We are using [Maven](http://http://maven.apache.org/) for building. After downloading the source code, you have to enter the directory with jCardSim and execute the following command: + + mvn clean install + + +### Development standards +We are using the following principles in jCardSim's development process: + +- [Test-Driven Development](http://en.wikipedia.org/wiki/Test-driven_development) +- [Code Conventions for the Java Programming Language](http://www.oracle.com/technetwork/java/codeconvtoc-136057.html) + diff --git a/sitedocs/quick_start_guide_simulator_api.md b/sitedocs/quick_start_guide_simulator_api.md new file mode 100644 index 00000000..02b578a9 --- /dev/null +++ b/sitedocs/quick_start_guide_simulator_api.md @@ -0,0 +1,179 @@ +jCardSim is intended for rapid prototyping of Java Card applications and unit testing. + +There are three ways to use the simulator: + + - Using the Simulator API + - Using the `javax.smartcardio` API + - Using the remote API + +### Using the Simulator API + +Working with the simulator: + + // 1. Create simulator + CardSimulator simulator = new CardSimulator(); + + // 2. Install applet + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // 3. Select applet + simulator.selectApplet(appletAID); + + // 4. Send APDU + CommandAPDU commandAPDU = new CommandAPDU(0x00, 0x01, 0x00, 0x00); + ResponseAPDU response = simulator.transmitCommand(commandAPDU); + + // 5. Check response status word + assertEquals(0x9000, response.getSW()); + +An example of how to work with `HelloWorldApplet` from the first part of [Quick Start Guide: Using in CLI mode](http://jcardsim.org/docs/quick-start-guide-using-in-cli-mode): + + CardSimulator simulator = new CardSimulator(); + + byte[] appletAIDBytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}; + AID appletAID = new AID(appletAIDBytes, (short) 0, (byte) appletAIDBytes.length); + + simulator.installApplet(appletAID, HelloWorldApplet.class); + simulator.selectApplet(appletAID); + + // test NOP + ResponseAPDU response = simulator.transmitCommand(new CommandAPDU(0x00, 0x02, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + + // test hello world from card + response = simulator.transmitCommand(new CommandAPDU(0x00, 0x01, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello world !", new String(response.getData())); + + // test echo + CommandAPDU echo = new CommandAPDU(0x00, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes()); + response = simulator.transmitCommand(echo); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello javacard world !", new String(response.getData())); + +It is also possible to work with plain `byte` arrays, for example: + + // test NOP + byte[] response = simulator.transmitCommand(new byte[]{0,2,0,0}); + ByteUtil.requireSW(response, 0x9000); + +To simplify the handling of AIDs and byte arrays we provide `AIDUtil` and `ByteUtil`: + + // AID from byte array + AID applet1AID = AIDUtil.create(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); + + // AID form String + AID applet2AID = AIDUtil.create("010203040506070809"); + + assertEquals(applet1AID, applet2AID); + + // String to byte array + String hexString = ByteUtil.hexString(new byte[]{0,2,0,0}); + + // byte array from String + byte[] bytes = ByteUtil.byteArray("00 02 00 00"); + + assertEquals("00020000", hexString); + assertEquals("00020000", ByteUtil.hexString(bytes)); + +### Using `javax.smartcardio` for an interaction with JavaCard + +To simplify unit testing of applications that use `javax.smartcardio`, +we provide a simulated `TerminalFactory` via `CardTerminalSimulator`. + +Using the `CardSimulator` via the `CardTerminal` API: + + // 1. Create simulator and install applet + CardSimulator simulator = new CardSimulator(); + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // 2. Create Terminal + CardTerminal terminal = CardTerminalSimulator.terminal(simulator); + + // 3. Connect to Card + Card card = terminal.connect("T=1"); + CardChannel channel = card.getBasicChannel(); + + // 4. Select applet + CommandAPDU selectCommand = new CommandAPDU(AIDUtil.select(appletAID)); + channel.transmit(selectCommand); + + // 5. Send APDU + CommandAPDU commandAPDU = new CommandAPDU(0x00, 0x01, 0x00, 0x00); + ResponseAPDU response = simulator.transmitCommand(commandAPDU); + + // 6. Check response status word + assertEquals(0x9000, response.getSW()); + +> **Note:** Pre-installed applets can be configured using system properties: `System.setProperty(...)`, the format is equal to the configuration file of the CLI mode of jCardSim. + +It is also possible to simulate multiple terminals using `CardTerminals`. +In this case each `CardTerminal` starts in an empty state (`isCardPresent()` returns `false`). +Cards can be inserted via `CardSimulator#assignToTerminal(terminal)` and removed via +`CardSimulator#assignToTerminal(null)`. + +Working with `CardTerminals`: + + // Obtain CardTerminal + CardTerminals cardTerminals = CardTerminalSimulator.terminals("My terminal 1", "My terminal 2"); + CardTerminal terminal1 = cardTerminals.getTerminal("My terminal 1"); + CardTerminal terminal2 = cardTerminals.getTerminal("My terminal 2"); + + assertEquals(false, terminal1.isCardPresent()); + assertEquals(false, terminal2.isCardPresent()); + + // Create simulator and install applet + CardSimulator simulator = new CardSimulator(); + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // Insert Card into "My terminal 1" + simulator.assignToTerminal(terminal1); + assertEquals(true, terminal1.isCardPresent()); + assertEquals(false, terminal2.isCardPresent()); + +Creating a terminal via the `TerminalFactory` API: + + // Register security provider + if (Security.getProvider("CardTerminalSimulator") == null) { + Security.addProvider(new CardTerminalSimulator.SecurityProvider()); + } + + // Get TerminalFactory + Object params = null; + TerminalFactory factory = TerminalFactory.getInstance("CardTerminalSimulator", params); + + // Get CardTerminal + CardTerminals cardTerminals = factory.terminals(); + CardTerminal terminal = cardTerminals.getTerminal("jCardSim.Terminal"); + assertNotNull(terminal); + + // Insert Card + simulator.assignToTerminal(terminal); + +Creating multiple terminals via the `TerminalFactory` API: + + String[] names = new String[] {"My terminal 1", "My terminal 2"}; + TerminalFactory factory = TerminalFactory.getInstance("CardTerminalSimulator", names); + + CardTerminals cardTerminals = factory.terminals(); + assertNotNull(cardTerminals.getTerminal("My terminal 1")); + assertNotNull(cardTerminals.getTerminal("My terminal 2")); + +**Current version's limitations:** + +- The `Card#openLogicalChannel` method is not supported. +- The `Card#transmitControlCommand` method is not supported. + +**Legacy TerminalFactory** + +Previous versions of jCardSim provided a limited `TerminalFactory` implementation (`JCSTerminal`). An example is provided in [JCardSimProviderTest.java](https://github.com/licel/jcardsim/blob/master/src/test/java/com/licel/jcardsim/smartcardio/JCardSimProviderTest.java). + +### Using the remote API + +It is possible to interact with a remote instance of jCardSim. For example you may +run one or multiple instances of virtual Java Card and connect to it via TCP/IP. + +An example is provided in [JavaCardRemoteServerTest.java](https://github.com/licel/jcardsim/blob/master/src/test/java/com/licel/jcardsim/remote/JavaCardRemoteServerTest.java). diff --git a/sitedocs/quick_start_guide_using_in_cli_mode.md b/sitedocs/quick_start_guide_using_in_cli_mode.md new file mode 100644 index 00000000..cb5a46da --- /dev/null +++ b/sitedocs/quick_start_guide_using_in_cli_mode.md @@ -0,0 +1,83 @@ +### Downloading jCardSim +Follow the link to download jCardSim jar archive: +[https://github.com/licel/jcardsim/raw/master/jcardsim-2.2.2-all.jar](https://github.com/licel/jcardsim/raw/master/jcardsim-2.2.2-all.jar) + +### Starting jCardSim in a CLI mode +To simplify the development and debugging process, jCardSim works directly with class files. You do not need to convert your Java Card applet to CAP in order to use it in the simulator. + +The simulator has a CLI and an API, so you can choose what you want to use. See more about using API and unit testing in the second part of +the [Quick Start Guide](http://jcardsim.org/docs/quick-start-guide-simulator-api). +For sending APDUs via APDU scripts you should use the class `com.licel.jcardsim.utils.APDUScriptTool`. + +**Start parameters:** + + java -cp jcardsim-2.2.2-all.jar com.licel.jcardsim.utils.APDUScriptTool [out file] + + +*jcardsim.cfg*, is a file with settings for the simulator. In it you can set information about your applets. It has the following format: + + com.licel.jcardsim.card.applet.{index}.AID= + com.licel.jcardsim.card.applet.{index}.Class= + +where *{index}* is a number from 0 to 10. +>**NOTE:** Applet classes and it's dependencies must be in class path when simulator starts. + +An example settings file: + + com.licel.jcardsim.card.applet.0.AID=010203040506070809 + com.licel.jcardsim.card.applet.0.Class=com.licel.jcardsim.samples.HelloWorldApplet + +`` - file with APDU commands in C-APDU format. This file is compatible with the script format of *apdutool* from the Java Card Development Kit. + +C-APDUs ends with `(;)` and comments begin with `//` + +APDU commands can be represented by DEC or HEX characters. HEX characters start with `0x`. +One APDU command (C-APDU) can span multiple lines. + +A C-APDU has the following format: + + [ ... ] ; +where: +`` :: ISO 7816-4 class byte. +`` :: ISO 7816-4 instruction byte. +`` :: ISO 7816-4 P1 parameter byte. +`` :: ISO 7816-4 P2 parameter byte. +`` :: ISO 7816-4 input byte count. 1 byte +` ... ` :: input data bytes. +`` :: ISO 7816- 4 expected output length. 1 byte + +For this example we will use the `com.licel.jcardsim.samples.HelloWorld` Java Card Applet. It is a simple applet which processes the following APDU commands: + +- Do nothing `CLA=0x00 INS=0x02 P1=0x00 P2=0x00 LC=0x00` +- Return bytes of "Hello world!" `CLA=0x00 INS=0x01 P1=0x00 P2=0x00 LC=0x00` +- Return sended data (echo) `CLA=0x00 INS=0x01 P1=0x01 P2=0x00 LC= DATA=` + +Let's write a C-APDU script for our HelloWorld applet: + + // CREATE APPLET CMD + 0x80 0xb8 0x00 0x00 0x10 0x9 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x8 0x09 0x05 0x00 0x00 0x02 0xF 0xF 0x7f; + // SELECT APPLET CMD + 0x00 0xa4 0x00 0x00 0x09 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x8 0x09 0x2; + // TEST NOP + 0x00 0x02 0x00 0x00 0x00 0x2; + // test hello world from card + 0x00 0x01 0x00 0x00 0x00 0x0d; + // test echo + 0x00 0x01 0x01 0x00 0x0d 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x20 0x21 0x0d; + + +Now we save the C-APDU script into the file `helloworld.apdu` and start the simulator. If we do not provide a third parameter the results will be printed on the console. + + java -cp jcardsim-2.2.1-all.jar com.licel.jcardsim.utils.APDUScriptTool jcardsim.cfg helloworld.apdu + +**Result:** + + CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 10, 09, 01, 02, 03, 04, 05, 06, 07, 08, 09, 05, 00, 00, 02, 0f, 0f, Le: 09, 01, 02, 03, 04, 05, 06, 07, 08, 09, SW1: 90, SW2: 00 + CLA: 00, INS: a4, P1: 00, P2: 00, Lc: 09, 01, 02, 03, 04, 05, 06, 07, 08, 09, Le: 00, SW1: 90, SW2: 00 + CLA: 00, INS: 02, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00 + CLA: 00, INS: 01, P1: 00, P2: 00, Lc: 00, Le: 0d, 48, 65, 6c, 6c, 6f, 20, 77, 6f, 72, 6c, 64, 20, 21, SW1: 90, SW2: 00 + CLA: 00, INS: 01, P1: 01, P2: 00, Lc: 0d, 48, 65, 6c, 6c, 6f, 20, 77, 6f, 72, 6c, 64, 20, 21, Le: 0d, 48, 65, 6c, 6c, 6f, 20, 77, 6f, 72, 6c, 64, 20, 21, SW1: 90, SW2: 00 + +The output matches the format used by *apdutool*. + +> The second part: [Quick Start Guide: Simulator API](http://jcardsim.org/docs/quick-start-guide-simulator-api). diff --git a/src/main/java/com/licel/jcardsim/base/ApduCase.java b/src/main/java/com/licel/jcardsim/base/ApduCase.java new file mode 100644 index 00000000..b6ec95c2 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/base/ApduCase.java @@ -0,0 +1,112 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.base; + +import javacard.framework.ISO7816; +import javacard.framework.Util; + +/** + * Case of an APDU. + */ +public enum ApduCase { + /** + * Case 1 APDU (CLA, INS, P1, P2) + */ + Case1(false), + /** + * Case 2 APDU (CLA, INS, P1, P2, 1 byte Le) + */ + Case2(false), + /** + * Case 2 extended APDU (CLA, INS, P1, P2, 0, 2 byte Le) + */ + Case2Extended(true), + /** + * Case 3 APDU (CLA, INS, P1, P2, 1 byte Lc, Data) + */ + Case3(false), + /** + * Case 3 extended APDU (CLA, INS, P1, P2, 2 byte Lc, Data) + */ + Case3Extended(true), + /** + * Case 4 APDU (CLA, INS, P1, P2, 1 byte Lc, Data, 1 byte Le) + */ + Case4(false), + /** + * Case 4 extended APDU (CLA, INS, P1, P2, 0, 2 byte Lc, Data, 2 byte Le) + */ + Case4Extended(true); + + private final boolean extended; + + ApduCase(boolean extended) { + this.extended = extended; + } + + /** + * @return true for extended APDU + */ + public boolean isExtended() { + return extended; + } + + /** + * Determine case of APDU + * @param command command APDU byte buffer + * @return Case of command + * @throws java.lang.IllegalArgumentException if command is malformed + * @throws java.lang.NullPointerException if command is null + */ + public static ApduCase getCase(byte[] command) { + if (command == null) { + throw new NullPointerException("command"); + } + if (command.length < 4) { + throw new IllegalArgumentException("command: malformed APDU, length < 4"); + } + if (command.length == 4) { + return Case1; + } + if (command.length == 5) { + return Case2; + } + if (command.length == 7 && command[ISO7816.OFFSET_LC] == 0) { + return Case2Extended; + } + if (command[ISO7816.OFFSET_LC] == 0) { + int lc = Util.getShort(command, (short) (ISO7816.OFFSET_LC + 1)); + int offset = ISO7816.OFFSET_LC + 3; + if (lc + offset == command.length) { + return Case3Extended; + } else if (lc + offset + 2 == command.length) { + return Case4Extended; + } else { + throw new IllegalArgumentException("Invalid extended C-APDU: Lc or Le is invalid"); + } + } else { + int lc = (command[ISO7816.OFFSET_LC] & 0xFF); + int offset = ISO7816.OFFSET_LC + 1; + if (lc + offset == command.length) { + return Case3; + } else if (lc + offset + 1 == command.length) { + return Case4; + } else { + throw new IllegalArgumentException("Invalid C-APDU: Lc or Le is invalid"); + } + } + } +} diff --git a/src/main/java/com/licel/jcardsim/base/CardManager.java b/src/main/java/com/licel/jcardsim/base/CardManager.java new file mode 100644 index 00000000..eab0bc91 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/base/CardManager.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.io.JavaCardInterface; +import javacard.framework.AID; +import javacard.framework.ISO7816; +import javacard.framework.SystemException; +import javacard.framework.Util; + +/** + * CardManager. + */ +public class CardManager { + + // basic impl + public static byte[] dispatchApdu(JavaCardInterface sim, byte[] capdu) { + byte[] theSW = new byte[2]; + if (capdu[ISO7816.OFFSET_CLA] == (byte)0x80 && capdu[ISO7816.OFFSET_INS] == (byte)0xb8) { + // handle CREATE APPLET command + // command format: + // CLA INS P0 P1 + // 0x8x, 0xb8, 0x00, 0x00 + // Lc field + // AID length field + // AID field + // parameter length field + // [parameters] + // Le field + // parameters + try { + AID aid = new AID(capdu, (short)(ISO7816.OFFSET_CDATA + 1), capdu[ISO7816.OFFSET_CDATA]); + sim.createApplet(aid, capdu, ISO7816.OFFSET_CDATA, capdu[ISO7816.OFFSET_LC]); + byte[] response = new byte[capdu[ISO7816.OFFSET_CDATA] + 2]; + aid.getBytes(response, (short) 0); + Util.setShort(response, (short) (response.length - 2), ISO7816.SW_NO_ERROR); + return response; + } catch (SystemException e) { + Util.setShort(theSW, (short) 0, e.getReason()); + return theSW; + } + // forward -> applet. TODO: more clean implementation + } else { + return sim.transmitCommand(capdu); + } + } +} diff --git a/src/main/java/com/licel/jcardsim/base/LoadFile.java b/src/main/java/com/licel/jcardsim/base/LoadFile.java new file mode 100644 index 00000000..c1204cac --- /dev/null +++ b/src/main/java/com/licel/jcardsim/base/LoadFile.java @@ -0,0 +1,94 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.licel.jcardsim.base; + +import com.licel.jcardsim.utils.AIDUtil; +import javacard.framework.AID; +import javacard.framework.Applet; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Represents a LoadFile (a JavaCard package or library). + */ +public final class LoadFile { + private final AID aid; + private final List modules; + + /** + * Create a LoadFile containing 1..* modules (JavaCard applets) + * @param loadFileAID AID of the LoadFile (JavaCard Package AID) + * @param modules array of modules + * @throws java.lang.NullPointerException if any argument is null + * @throws java.lang.IllegalArgumentException if modules is empty + */ + public LoadFile(AID loadFileAID, Module... modules) { + if (loadFileAID == null) { + throw new NullPointerException("loadFileAID"); + } + if (modules == null) { + throw new NullPointerException("modules"); + } + if (modules.length == 0) { + throw new IllegalArgumentException("modules must not be empty"); + } + + this.aid = loadFileAID; + this.modules = Collections.unmodifiableList(Arrays.asList(modules)); + } + + /** + * Create a LoadFile containing one module (JavaCard applet) + * @param loadFileAID AID of the LoadFile (JavaCard Package AID) + * @param moduleAid AID of the module/class + * @param appletClass the Applet class + * @throws java.lang.NullPointerException if any argument is null + * @throws java.lang.IllegalArgumentException if modules is empty + */ + public LoadFile(AID loadFileAID, AID moduleAid, Class appletClass) { + this(loadFileAID, new Module(moduleAid, appletClass)); + } + + public AID getAid() { + return aid; + } + + public List getModules() { + return modules; + } + + public Module getModule(AID moduleAID) { + for (Module module : modules) { + if (module.getAid().equals(moduleAID)) { + return module; + } + } + return null; + } + + @Override + public String toString() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("LoadFile ").append(AIDUtil.toString(aid)).append("\n"); + for (Module module : modules) { + stringBuilder.append(" ").append(module.toString()).append("\n"); + } + return stringBuilder.toString(); + } +} diff --git a/src/main/java/com/licel/jcardsim/base/Module.java b/src/main/java/com/licel/jcardsim/base/Module.java new file mode 100644 index 00000000..46b2a042 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/base/Module.java @@ -0,0 +1,60 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.utils.AIDUtil; +import javacard.framework.AID; +import javacard.framework.Applet; + +/** + * Represents a module (JavaCard Applet class). + */ +public final class Module { + private final AID aid; + private final Class appletClass; + + /** + * Create a module + * @param moduleAID AID of the applet class + * @param appletClass Applet class + */ + public Module(AID moduleAID, Class appletClass) { + this.aid = moduleAID; + this.appletClass = appletClass; + if (moduleAID == null) { + throw new NullPointerException("moduleAID"); + } + if (appletClass == null) { + throw new NullPointerException("appletClass"); + } + if (!Applet.class.isAssignableFrom(appletClass)) { + throw new IllegalArgumentException("appletClass " + appletClass + " must derive from Applet."); + } + } + + public AID getAid() { + return aid; + } + + public Class getAppletClass() { + return appletClass; + } + + @Override + public String toString() { + return String.format("Module %s (%s)", AIDUtil.toString(aid), appletClass.getCanonicalName()); + } +} diff --git a/src/main/java/com/licel/jcardsim/base/ShareableProxy.java b/src/main/java/com/licel/jcardsim/base/ShareableProxy.java new file mode 100644 index 00000000..210b528c --- /dev/null +++ b/src/main/java/com/licel/jcardsim/base/ShareableProxy.java @@ -0,0 +1,49 @@ +/* + * Copyright 2015 Fidesmo AB. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.base; + +import javacard.framework.*; + +import java.lang.reflect.Method; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; + + +class ShareableProxy implements InvocationHandler { + + SimulatorRuntime runtime; + AID serverAID; + Shareable shareable; + + + protected ShareableProxy (SimulatorRuntime runtime, AID serverAID, Shareable shareable) { + this.runtime = runtime; + this.serverAID = serverAID; + this.shareable = shareable; + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + AID oldAID = runtime.previousAID; + runtime.previousAID = runtime.currentAID; + runtime.currentAID = serverAID; + + Object result = method.invoke(shareable, args); + + runtime.currentAID = runtime.previousAID; + runtime.previousAID = oldAID; + return result; + } +} diff --git a/src/main/java/com/licel/jcardsim/base/Simulator.java b/src/main/java/com/licel/jcardsim/base/Simulator.java index 4e51ca9e..1af9d297 100644 --- a/src/main/java/com/licel/jcardsim/base/Simulator.java +++ b/src/main/java/com/licel/jcardsim/base/Simulator.java @@ -15,130 +15,344 @@ */ package com.licel.jcardsim.base; -import java.lang.reflect.Method; -import javacard.framework.AID; -import javacard.framework.Applet; -import javacard.framework.JCSystem; -import javacard.framework.SystemException; +import com.licel.jcardsim.io.JavaCardInterface; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.net.URLClassLoader; +import java.text.MessageFormat; +import java.util.Locale; +import java.util.Properties; + +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.ByteUtil; +import javacard.framework.*; +import org.bouncycastle.util.encoders.Hex; /** - * Main class for deal with Applets + * Simulates a JavaCard. */ -public class Simulator { - +public class Simulator implements JavaCardInterface { + + // default ATR - NXP JCOP 31/36K + static final String DEFAULT_ATR = "3BFA1800008131FE454A434F5033315632333298"; + // ATR system property name + static final String ATR_SYSTEM_PROPERTY = "com.licel.jcardsim.card.ATR"; + // card ATR + private byte[] atr = null; + static final String PROPERTY_PREFIX = "com.licel.jcardsim.card.applet."; + static final String OLD_PROPERTY_PREFIX = "com.licel.jcardsim.smartcardio.applet."; + // Applet AID system property template + static final MessageFormat AID_SP_TEMPLATE = new MessageFormat("{0}.AID"); + // Applet ClassName system property template + static final MessageFormat APPLET_CLASS_SP_TEMPLATE = new MessageFormat("{0}.Class"); + // Applet Class Loader + final AppletClassLoader cl = new AppletClassLoader(new URL[]{}); + /** The simulator runtime */ + protected final SimulatorRuntime runtime; + // current protocol + private String protocol = "T=0"; + /** - * Construct Simulator object and init base systems + * Create a Simulator object using the default SimulatorRuntime. + * + *
      + *
    • All Simulator instances share one SimulatorRuntime.
    • + *
    • SimulatorRuntime#resetRuntime is called
    • + *
    • If your want multiple independent simulators use Simulator(SimulatorRuntime)
    • + *
    */ public Simulator() { - JCSystem.getVersion(); + this(SimulatorSystem.DEFAULT_RUNTIME, System.getProperties()); } /** - * Load Applet into Simulator - * @param aid applet aid - * @param appletClass applet class - * @return applet AID - * @throws SystemException if appletClass not instanceof - * javacard.framework.Applet + * Create a Simulator object using a provided Runtime. + * + *
      + *
    • SimulatorRuntime#resetRuntime is called
    • + *
    + * + * @param runtime SimulatorRuntime instance to use + * @throws java.lang.NullPointerException if runtime is null */ - public AID loadApplet(AID aid, Class appletClass) throws SystemException { - if (!(appletClass.getSuperclass() == Applet.class)) { + public Simulator(SimulatorRuntime runtime) { + this(runtime, System.getProperties()); + } + + protected Simulator(SimulatorRuntime runtime, Properties properties) { + if (runtime == null) { + throw new NullPointerException("runtime"); + } + + this.runtime = runtime; + synchronized (this.runtime) { + this.runtime.resetRuntime(); + } + + changeProtocol(protocol); + + atr = Hex.decode(properties.getProperty(ATR_SYSTEM_PROPERTY, DEFAULT_ATR)); + // init pre-installed applets + for (int i = 0; i < 10 && !properties.isEmpty(); i++) { + String selectedPrefix = PROPERTY_PREFIX; + String aidPropertyName = PROPERTY_PREFIX + AID_SP_TEMPLATE.format(new Object[]{i}); + String aidPropertyOldName = OLD_PROPERTY_PREFIX + AID_SP_TEMPLATE.format(new Object[]{i}); + String appletAID = properties.getProperty(aidPropertyName); + if (appletAID == null) { + appletAID = properties.getProperty(aidPropertyOldName); + if (appletAID != null) { + selectedPrefix = OLD_PROPERTY_PREFIX; + } + } + if (appletAID != null) { + String appletClassName = properties.getProperty(selectedPrefix + APPLET_CLASS_SP_TEMPLATE.format(new Object[]{i})); + if (appletClassName != null) { + byte[] aidBytes = Hex.decode(appletAID); + if (aidBytes == null || aidBytes.length < 5 || aidBytes.length > 16) { + // skip incorrect applet + continue; + } + loadApplet(new AID(aidBytes, (short) 0, (byte) aidBytes.length), appletClassName); + } + } + } + } + + public AID loadApplet(AID aid, String appletClassName, byte[] appletJarContents) throws SystemException { + // simple method, but emulate real card login + // download data + byte[] aidData = new byte[16]; + aid.getBytes(aidData, (short) 0); + Class appletClass = null; + try { + cl.addAppletContents(appletJarContents); + appletClass = requireExtendsApplet(cl.loadClass(appletClassName)); + } catch (Exception e) { SystemException.throwIt(SystemException.ILLEGAL_VALUE); + + } + if (appletClass != null) { + return loadApplet(aid, appletClass); + } else { + SystemException.throwIt(SystemException.ILLEGAL_VALUE); + return null; } - SimulatorSystem.getRuntime().loadApplet(aid, appletClass); - return aid; + } + + public AID loadApplet(AID aid, String appletClassName) throws SystemException { + Class appletClass = null; + try { + appletClass = requireExtendsApplet(cl.loadClass(appletClassName)); + } catch (ClassNotFoundException ex) { + SystemException.throwIt(SystemException.ILLEGAL_VALUE); + } + return loadApplet(aid, appletClass); } /** - * Create Applet instance in Simulator + * Load + * Applet into Simulator + * * @param aid applet aid - * @param bArray the array containing installation parameters - * @param bOffset the starting offset in bArray - * @param bLength the length in bytes of the parameter data in bArray + * @param appletClass applet class * @return applet AID - * @throws SystemException if exception in Applet.install(..) - * method occurs. + * @throws SystemException if appletClass not instanceof + * javacard.framework.Applet */ + public AID loadApplet(AID aid, Class appletClass) throws SystemException { + synchronized (runtime) { + runtime.loadApplet(aid, requireExtendsApplet(appletClass)); + } + return aid; + } + public AID createApplet(AID aid, byte bArray[], short bOffset, byte bLength) throws SystemException { try { - Class appletClass = SimulatorSystem.getRuntime().getAppletClass(aid); - if(appletClass == null) SystemException.throwIt(SystemException.ILLEGAL_AID); - SimulatorSystem.getRuntime().appletInstalling(aid); - Method initMethod = appletClass.getMethod("install", - new Class[]{byte[].class, short.class, byte.class}); - initMethod.invoke(null, new Object[]{bArray, new Short(bOffset), new Byte(bLength)}); - } catch (Exception ex) { - SystemException.throwIt(SimulatorSystem.SW_APPLET_CRATION_FAILED); + synchronized (runtime) { + runtime.installApplet(aid, bArray, bOffset, bLength); + } + } + catch (Exception e) { + SystemException.throwIt(SimulatorSystem.SW_APPLET_CREATION_FAILED); } return aid; } - + /** - * Install Applet into Simulator without installing data + * Install + * Applet into Simulator without installing data + * * @param aid applet aid or null * @param appletClass applet class * @return applet AID - * @throws SystemException if appletClass not instanceof + * @throws SystemException if appletClass not instanceof * javacard.framework.Applet */ - public AID installApplet(AID aid, Class appletClass) throws SystemException { + public AID installApplet(AID aid, Class appletClass) throws SystemException { return installApplet(aid, appletClass, new byte[]{}, (short) 0, (byte) 0); } /** - * Install Applet into Simulator. - * This method is equal to: + * Install + * Applet into Simulator. This method is equal to: * * loadApplet(...); * createApplet(...); * + * * @param aid applet aid or null * @param appletClass applet class * @param bArray the array containing installation parameters * @param bOffset the starting offset in bArray * @param bLength the length in bytes of the parameter data in bArray * @return applet AID - * @throws SystemException if appletClass not instanceof + * @throws SystemException if appletClass not instanceof * javacard.framework.Applet */ - public AID installApplet(AID aid, Class appletClass, byte bArray[], short bOffset, + public AID installApplet(AID aid, Class appletClass, byte bArray[], short bOffset, byte bLength) throws SystemException { - loadApplet(aid, appletClass); - return createApplet(aid, bArray, bOffset, bLength); + synchronized (runtime) { + loadApplet(aid, appletClass); + return createApplet(aid, bArray, bOffset, bLength); + } + } + + public AID installApplet(AID aid, String appletClassName, byte bArray[], short bOffset, + byte bLength) throws SystemException { + synchronized (runtime) { + loadApplet(aid, appletClassName); + return createApplet(aid, bArray, bOffset, bLength); + } + } + + public AID installApplet(AID aid, String appletClassName, byte[] appletContents, byte bArray[], short bOffset, + byte bLength) throws SystemException { + synchronized (runtime) { + loadApplet(aid, appletClassName, appletContents); + return createApplet(aid, bArray, bOffset, bLength); + } } /** - * Select applet by it's AID - * It's method must be called before start working with applet instance - * @param aid appletId - * @return true if applet selection success + * Delete an applet + * @param aid applet aid */ + public void deleteApplet(AID aid) { + synchronized (runtime) { + runtime.deleteApplet(aid); + } + } + public boolean selectApplet(AID aid) throws SystemException { - return SimulatorSystem.selectApplet(aid); + byte[] resp = selectAppletWithResult(aid); + return ByteUtil.getSW(resp) == ISO7816.SW_NO_ERROR; + } + + public byte[] selectAppletWithResult(AID aid) throws SystemException { + synchronized (runtime) { + return runtime.transmitCommand(AIDUtil.select(aid)); + } + } + + public byte[] transmitCommand(byte[] command) { + synchronized (runtime) { + return runtime.transmitCommand(command); + } + } + + public void reset() { + synchronized (runtime) { + runtime.reset(); + } + } + + public final void resetRuntime() { + synchronized (runtime) { + runtime.resetRuntime(); + } + } + + public byte[] getATR() { + return atr; + } + + protected byte getProtocolByte(String protocol) { + if (protocol == null) { + throw new NullPointerException("protocol"); + } + String p = protocol.toUpperCase(Locale.ENGLISH).replace(" ",""); + byte protocolByte; + + if (p.equals("T=0") || p.equals("*")) { + protocolByte = APDU.PROTOCOL_T0; + } + else if (p.equals("T=1")) { + protocolByte = APDU.PROTOCOL_T1; + } + else if (p.equals("T=CL,TYPE_A,T0") || p.equals("T=CL")) { + protocolByte = APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A; + protocolByte |= APDU.PROTOCOL_T0; + } + else if (p.equals("T=CL,TYPE_A,T1")) { + protocolByte = APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A; + protocolByte |= APDU.PROTOCOL_T1; + } + else if (p.equals("T=CL,TYPE_B,T0")) { + protocolByte = APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_B; + protocolByte |= APDU.PROTOCOL_T0; + } + else if (p.equals("T=CL,TYPE_B,T1")) { + protocolByte = APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_B; + protocolByte |= APDU.PROTOCOL_T1; + } + else { + throw new IllegalArgumentException("Unknown protocol: " + protocol); + } + return protocolByte; } /** - * Transmit APDU to previous selected applet - * @param commandAPDU command apdu - * @return response apdu - * @see CommandAPDU - * @see ResponseAPDU - * @throws SystemException.ILLEGAL_USE if appplet not selected before + * @see com.licel.jcardsim.io.JavaCardInterface#changeProtocol(String) */ - public byte[] transmitCommand(byte[] command) - throws SystemException { - return SimulatorSystem.transmitCommand(command); + public void changeProtocol(String protocol) { + synchronized (runtime) { + runtime.changeProtocol(getProtocolByte(protocol)); + this.protocol = protocol; + } } - + /** - * powerdown/powerup + * @see com.licel.jcardsim.io.JavaCardInterface#getProtocol() */ - public void reset() { - SimulatorSystem.getRuntime().reset(); + public String getProtocol() { + return protocol; + } + + @SuppressWarnings("unchecked") + private Class requireExtendsApplet(Class aClass) { + if (!Applet.class.isAssignableFrom(aClass)) { + throw new SystemException(SystemException.ILLEGAL_VALUE); + } + return (Class) aClass; } - public void resetRuntime() { - SimulatorSystem.getRuntime().resetRuntime(); + class AppletClassLoader extends URLClassLoader { + + AppletClassLoader(URL[] urls) { + super(urls, Simulator.class.getClassLoader()); + } + + void addAppletContents(byte[] appletJarContents) throws IOException { + File downloadedAppletJar = File.createTempFile("applet", "contents"); + downloadedAppletJar.deleteOnExit(); + FileOutputStream fos = new FileOutputStream(downloadedAppletJar); + fos.write(appletJarContents); + fos.close(); + addURL(downloadedAppletJar.toURI().toURL()); + + } } } diff --git a/src/main/java/com/licel/jcardsim/base/SimulatorRuntime.java b/src/main/java/com/licel/jcardsim/base/SimulatorRuntime.java index 33d1f672..6b06cd30 100644 --- a/src/main/java/com/licel/jcardsim/base/SimulatorRuntime.java +++ b/src/main/java/com/licel/jcardsim/base/SimulatorRuntime.java @@ -15,38 +15,96 @@ */ package com.licel.jcardsim.base; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.BiConsumer; import javacard.framework.*; +import javacardx.apdu.ExtendedLength; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.*; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; /** - * Base implementation of Java Card Runtime + * Base implementation of Java Card Runtime. * @see JCSystem * @see Applet */ public class SimulatorRuntime { + // holds the Applet registration callback + protected final ThreadLocal> registrationCallback; + /** storage for installed applets */ + protected final SortedMap applets = new TreeMap(AIDUtil.comparator()); + /** storage for load files */ + protected final SortedMap loadFiles = new TreeMap(AIDUtil.comparator()); + /** storage for automatically generated loadFile AIDs */ + protected final SortedMap generatedLoadFileAIDs = new TreeMap(AIDUtil.comparator()); + /** method for resetting APDUs */ + protected final Method apduPrivateResetMethod; + /** outbound response byte array buffer */ + protected final byte[] responseBuffer = new byte[Short.MAX_VALUE + 2]; + /** transient memory */ + protected final TransientMemory transientMemory; + /** regular APDU */ + protected final APDU shortAPDU; + /** extended APDU */ + protected final APDU extendedAPDU; + + /** current selected applet */ + protected AID currentAID; + /** previous selected applet */ + protected AID previousAID; + /** outbound response byte array buffer size */ + protected short responseBufferSize = 0; + /** if the applet is currently being selected */ + protected boolean selecting = false; + /** if extended APDUs are used */ + protected boolean usingExtendedAPDUs = false; + /** current protocol */ + protected byte currentProtocol = APDU.PROTOCOL_T0; + /** current depth of transaction */ + protected byte transactionDepth = 0; + /** previousActiveObject */ + protected Object previousActiveObject; + + public SimulatorRuntime() { + this(new TransientMemory()); + } + + @SuppressWarnings("unchecked") + public SimulatorRuntime(TransientMemory transientMemory) { + this.transientMemory = transientMemory; + try { + Constructor ctor = APDU.class.getDeclaredConstructors()[0]; + ctor.setAccessible(true); + + shortAPDU = (APDU) ctor.newInstance(false); + extendedAPDU = (APDU) ctor.newInstance(true); + + apduPrivateResetMethod = APDU.class.getDeclaredMethod("internalReset", byte.class, byte[].class); + apduPrivateResetMethod.setAccessible(true); + + Field f = Applet.class.getDeclaredField("registrationCallback"); + f.setAccessible(true); + registrationCallback = (ThreadLocal>) f.get(null); + } catch (Exception e) { + throw new RuntimeException("Internal reflection error", e); + } + } + + /** + * Register this with SimulatorRuntime + */ + protected final void activateSimulatorRuntimeInstance() { + SimulatorSystem.setCurrentInstance(this); + } - private static final byte[] DEFAULT_APPLET_AID = new byte[]{}; - // storage for registered applets - private HashMap applets = new HashMap(); - // current selected applet - private AID currentAID; - // previous selected applet - private AID previousAID; - // applet in INSTALL phase - private AID appletToInstallAID; - // inbound command byte array buffer - byte[] commandBuffer; - // outbound response byte array buffer - byte[] responseBuffer = JCSystem.makeTransientByteArray((short) 255, JCSystem.CLEAR_ON_RESET); - // outbound response byte array buffer size - short responseBufferSize = 0; - // SW - byte[] theSW = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); /** - * Return current applet context AID or null + * @return current applet context AID or null */ public AID getAID() { return currentAID; @@ -54,12 +112,14 @@ public AID getAID() { /** * Lookup applet by aid contains in byte array + * @param buffer the byte array containing the AID bytes + * @param offset the start of AID bytes in buffer + * @param length the length of the AID bytes in buffer + * @return Applet AID or null */ public AID lookupAID(byte buffer[], short offset, byte length) { // no construct new AID, iterate applets - Iterator aids = applets.keySet().iterator(); - while (aids.hasNext()) { - AID aid = (AID) aids.next(); + for (AID aid : applets.keySet()) { if (aid.equals(buffer, offset, length)) { return aid; } @@ -69,142 +129,178 @@ public AID lookupAID(byte buffer[], short offset, byte length) { /** * Lookup applet by aid + * @param lookupAid applet AID + * @return ApplicationInstance or null */ - public AppletHolder lookupApplet(AID lookupAid) { - Iterator aids = applets.keySet().iterator(); - while (aids.hasNext()) { - AID aid = (AID) aids.next(); + public ApplicationInstance lookupApplet(AID lookupAid) { + for (AID aid : applets.keySet()) { if (aid.equals(lookupAid)) { - return (AppletHolder) applets.get(aid); + return applets.get(aid); } } return null; } /** - * Return previous selected applet context AID or null + * @return previous selected applet context AID or null */ public AID getPreviousContextAID() { return previousAID; } - public void appletInstalling(AID aid) { - appletToInstallAID = aid; - } - /** * Return Applet by it's AID or null * @param aid applet AID + * @return Applet or null */ protected Applet getApplet(AID aid) { if (aid == null) { return null; } - AppletHolder a = lookupApplet(aid); + ApplicationInstance a = lookupApplet(aid); if(a == null) return null; else return a.getApplet(); } - /** - * Return Applet class by it's AID or null - * @param aid applet AID - */ - protected Class getAppletClass(AID aid) { - if (aid == null) { - return null; - } - return lookupApplet(aid).getAppletClass(); - } /** * Load applet + * @param aid Applet AID + * @param appletClass Applet class */ - protected void loadApplet(AID aid, Class appletClass) { - // see specification - if (lookupApplet(aid) != null) { - SystemException.throwIt(SystemException.ILLEGAL_AID); + public void loadApplet(AID aid, Class appletClass) { + if (generatedLoadFileAIDs.keySet().contains(aid)) { + throw new SystemException(SystemException.ILLEGAL_AID); } - applets.put(aid, new AppletHolder(appletClass)); + // generate a load file AID + byte[] generated = new byte[]{(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, 0, 0}; + Util.setShort(generated, (short) 3, (short) generatedLoadFileAIDs.size()); + AID generatedAID = AIDUtil.create(generated); + + generatedLoadFileAIDs.put(aid, generatedAID); + loadLoadFile(new LoadFile(generatedAID, generatedAID, appletClass)); } /** - * Register applet + * Load a LoadFile + * @param loadFile LoadFile to load */ - protected void registerApplet(AID aid, Applet applet) { - AppletHolder ah = null; - // if register(Applet applet); - if (aid == null && appletToInstallAID != null) { - ah = lookupApplet(appletToInstallAID); - } else if (aid != null) { - ah = lookupApplet(aid); - } - if (ah == null) { - SystemException.throwIt(SystemException.ILLEGAL_AID); + public void loadLoadFile(LoadFile loadFile) { + AID key = loadFile.getAid(); + if (loadFiles.keySet().contains(key) || applets.keySet().contains(key)) { + throw new IllegalStateException("LoadFile AID already used"); } - ah.setApplet(applet); - ah.register(); - ah.install(); - appletToInstallAID = null; + loadFiles.put(key, loadFile); } /** - * Select applet for using - * @param aid applet aid - * @return true if select sucess + * Delete applet + * @param aid Applet AID to delete */ - boolean selectApplet(AID aid) { - Applet newApplet = getApplet(aid); - // deselect previous selected applet - if (currentAID != null) { - try { - Applet applet = getApplet(currentAID); - applet.deselect(); - } catch (Exception e) { - // ignore all - } finally { - if (SimulatorSystem.getTransactionDepth() != 0) { - SimulatorSystem.abortTransaction(); - } - } + protected void deleteApplet(AID aid) { + activateSimulatorRuntimeInstance(); + ApplicationInstance applicationInstance = lookupApplet(aid); + if (applicationInstance == null) { + throw new SystemException(SystemException.ILLEGAL_AID); + } + + applets.remove(aid); + Applet applet = applicationInstance.getApplet(); + if (applet == null) { + return; } - if (newApplet == null) { - return false; + + if (getApplet(currentAID) == applet) { + deselect(applicationInstance); } - // select new applet - try { - newApplet.select(); - previousAID = currentAID; - currentAID = aid; - return true; - } catch (Exception e) { - } finally { - if (SimulatorSystem.getTransactionDepth() != 0) { - SimulatorSystem.abortTransaction(); + + if (applet instanceof AppletEvent) { + try { + ((AppletEvent) applet).uninstall(); + } + catch (Exception e) { + // ignore all } } - return false; + } + + /** + * Check if applet is currently being selected + * @param aThis applet + * @return true if applet is being selected + */ + public boolean isAppletSelecting(Applet aThis) { + return aThis == getApplet(getAID()) && selecting; } /** * Transmit APDU to previous selected applet - * @param commandAPDU command apdu + * @param command command apdu * @return response apdu - * @throws SystemException.ILLEGAL_USE if appplet not selected before */ - byte[] transmitCommand(byte[] command) throws SystemException { + public byte[] transmitCommand(byte[] command) throws SystemException { + activateSimulatorRuntimeInstance(); + + final ApduCase apduCase = ApduCase.getCase(command); + final byte[] theSW = new byte[2]; + byte[] response; + Applet applet = getApplet(getAID()); - byte[] response = null; - Util.arrayFillNonAtomic(theSW, (short) 0, (short) 2, (byte) 0); + + selecting = false; + // check if there is an applet to be selected + if (!apduCase.isExtended() && isAppletSelectionApdu(command)) { + AID newAid = findAppletForSelectApdu(command, apduCase); + if (newAid != null) { + deselect(lookupApplet(getAID())); + currentAID = newAid; + applet = getApplet(getAID()); + selecting = true; + } + else if (applet == null) { + Util.setShort(theSW, (short) 0, ISO7816.SW_APPLET_SELECT_FAILED); + return theSW; + } + } + if (applet == null) { - SystemException.throwIt(SystemException.ILLEGAL_USE); + Util.setShort(theSW, (short) 0, ISO7816.SW_COMMAND_NOT_ALLOWED); + return theSW; } + + if (apduCase.isExtended()) { + if (applet instanceof ExtendedLength) { + usingExtendedAPDUs = true; + } + else { + Util.setShort(theSW, (short)0, ISO7816.SW_WRONG_LENGTH); + return theSW; + } + } + else { + usingExtendedAPDUs = false; + } + + responseBufferSize = 0; + APDU apdu = getCurrentAPDU(); try { + if (selecting) { + boolean success; + try { + success = applet.select(); + } + catch (Exception e) { + success = false; + } + if (!success) { + throw new ISOException(ISO7816.SW_APPLET_SELECT_FAILED); + } + } + // set apdu - Util.arrayCopyNonAtomic(command, (short) 0, APDU.getCurrentAPDUBuffer(), - (short) 0, (short) command.length); - applet.process(APDU.getCurrentAPDU()); - response = JCSystem.makeTransientByteArray((short) (responseBufferSize + 2), JCSystem.CLEAR_ON_RESET); - Util.arrayCopyNonAtomic(responseBuffer, (short) 0, response, (short) 0, responseBufferSize); - Util.setShort(response, responseBufferSize, ISO7816.SW_NO_ERROR); + resetAPDU(apdu, command); + + applet.process(apdu); + Util.setShort(theSW, (short) 0, (short) 0x9000); } catch (Throwable e) { Util.setShort(theSW, (short) 0, ISO7816.SW_UNKNOWN); if (e instanceof CardException) { @@ -212,14 +308,62 @@ byte[] transmitCommand(byte[] command) throws SystemException { } else if (e instanceof CardRuntimeException) { Util.setShort(theSW, (short) 0, ((CardRuntimeException) e).getReason()); } + } + finally { + selecting = false; + resetAPDU(apdu, null); + } + + // if theSW = 0x61XX or 0x9XYZ than return data (ISO7816-3) + if(theSW[0] == 0x61 || (theSW[0] >= (byte)0x90 && theSW[0]<=0x9F)) { + response = new byte[responseBufferSize + 2]; + Util.arrayCopyNonAtomic(responseBuffer, (short) 0, response, (short) 0, responseBufferSize); + Util.arrayCopyNonAtomic(theSW, (short) 0, response, responseBufferSize, (short) 2); + } + else { response = theSW; } - APDU.getCurrentAPDU().reset(); - Util.arrayFillNonAtomic(responseBuffer, (short) 0, (short) 255, (byte) 0); - responseBufferSize = 0; + return response; } + protected AID findAppletForSelectApdu(byte[] selectApdu, ApduCase apduCase) { + if (apduCase == ApduCase.Case1 || apduCase == ApduCase.Case2) { + // on a regular Smartcard we would select the CardManager applet + // in this case we just select the first applet + return applets.isEmpty() ? null : applets.firstKey(); + } + + for (AID aid : applets.keySet()) { + if (aid.equals(selectApdu, ISO7816.OFFSET_CDATA, selectApdu[ISO7816.OFFSET_LC])) { + return aid; + } + } + + for (AID aid : applets.keySet()) { + if (aid.partialEquals(selectApdu, ISO7816.OFFSET_CDATA, selectApdu[ISO7816.OFFSET_LC])) { + return aid; + } + } + + return null; + } + + protected void deselect(ApplicationInstance applicationInstance) { + activateSimulatorRuntimeInstance(); + if (applicationInstance != null) { + try { + Applet applet = applicationInstance.getApplet(); + applet.deselect(); + } catch (Exception e) { + // ignore all + } + } + if (getTransactionDepth() != 0) { + abortTransaction(); + } + transientMemory.clearOnDeselect(); + } /** * Copy response bytes to internal buffer @@ -227,95 +371,315 @@ byte[] transmitCommand(byte[] command) throws SystemException { * @param bOff the starting offset in buffer * @param len the length in bytes of the response */ - void sendAPDU(byte[] buffer, short bOff, short len) { + public void sendAPDU(byte[] buffer, short bOff, short len) { responseBufferSize = Util.arrayCopyNonAtomic(buffer, bOff, responseBuffer, responseBufferSize, len); } /** * powerdown/powerup */ - void reset() { - Iterator aids = applets.keySet().iterator(); - ArrayList aidsToTrash = new ArrayList(); - while (aids.hasNext()) { - AID aid = (AID) aids.next(); - AppletHolder ah = lookupApplet(aid); - if (ah.getState() != AppletHolder.INSTALLED) { - aidsToTrash.add(aid); - } - } - for(int i=0;i aids = applets.keySet().iterator(); + ArrayList aidsToTrash = new ArrayList(); while (aids.hasNext()) { - AID aid = (AID) aids.next(); + AID aid = aids.next(); aidsToTrash.add(aid); } - for(int i=0;inull + */ + public Shareable getSharedObject(AID serverAID, byte parameter) { + Applet serverApplet = getApplet(serverAID); + if (serverApplet != null) { + + AID oldAID = previousAID; + previousAID = currentAID; + currentAID = serverAID; + + final Shareable shareable = serverApplet.getShareableInterfaceObject(getAID(), + parameter); + + currentAID = previousAID; + previousAID = oldAID; + + if (shareable != null) { + return (Shareable) Proxy.newProxyInstance( + shareable.getClass().getClassLoader(), + shareable.getClass().getInterfaces(), + new ShareableProxy(this, serverAID, shareable)); + } + return null; + } + return null; + } + + /** + * @see javacard.framework.JCSystem#isObjectDeletionSupported() + * @return always false + */ + public boolean isObjectDeletionSupported() { + return false; + } + + /** + * @see javacard.framework.JCSystem#requestObjectDeletion() + */ + public void requestObjectDeletion() { + if (!isObjectDeletionSupported()) { + throw new SystemException(SystemException.ILLEGAL_USE); + } + } + + public void setJavaOwner(Object obj, Object owner) {} + + public Object getJavaOwner(Object obj) { + return obj; + } + + public short getJavaContext(Object obj) { + return 0; + } + + public Object getPreviousActiveObject() { + return previousActiveObject; + } + + public void setPreviousActiveObject(Object previousActiveObject) { + this.previousActiveObject = previousActiveObject; + } + + protected static boolean isAppletSelectionApdu(byte[] apdu) { + final byte channelMask = (byte) 0xFC; // mask out %b000000xx + final byte p2Mask = (byte) 0xE3; // mask out %b000xxx00 + + final byte cla = (byte) (apdu[ISO7816.OFFSET_CLA] & channelMask); + final byte ins = apdu[ISO7816.OFFSET_INS]; + final byte p1 = apdu[ISO7816.OFFSET_P1]; + final byte p2 = (byte) (apdu[ISO7816.OFFSET_P2] & p2Mask); + + return cla == ISO7816.CLA_ISO7816 && ins == ISO7816.INS_SELECT && + p1 == 4 && p2 == 0; + } + + public void installApplet(final AID appletAid, byte[] bArray, short bOffset, byte bLength) { + AID generatedAID = generatedLoadFileAIDs.get(appletAid); + if (generatedAID == null || !loadFiles.keySet().contains(generatedAID)) { + throw new SystemException(SystemException.ILLEGAL_AID); + } + installApplet(generatedAID, generatedAID, appletAid, bArray, bOffset, bLength); + } + + public void installApplet(AID loadFileAID, AID moduleAID, final AID appletAID, + byte[] bArray, short bOffset, byte bLength) { + activateSimulatorRuntimeInstance(); + LoadFile loadFile = loadFiles.get(loadFileAID); + if (loadFile == null) { + throw new IllegalArgumentException("LoadFile AID not found " + AIDUtil.toString(loadFileAID)); + } + Module module = loadFile.getModule(moduleAID); + if (module == null) { + throw new IllegalArgumentException("Module AID not found " + AIDUtil.toString(moduleAID)); + } + + Class appletClass = module.getAppletClass(); + Method initMethod; + try { + initMethod = appletClass.getMethod("install", + new Class[]{byte[].class, short.class, byte.class}); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException("Class does not provide install method"); } - - void setApplet(Applet applet){ + + final AtomicInteger callCount = new AtomicInteger(0); + registrationCallback.set(new BiConsumer() { + public void accept(Applet applet, AID installAID) { + // disallow second call to register + if (callCount.incrementAndGet() != 1) { + throw new SystemException(SystemException.ILLEGAL_AID); + } + + // register applet + if (installAID != null) { + applets.put(installAID, new ApplicationInstance(installAID, applet)); + } + else { + applets.put(appletAID, new ApplicationInstance(appletAID, applet)); + } + } + }); + + try { + initMethod.invoke(null, bArray, bOffset, bLength); + } + catch (SystemException e) { + throw e; + } + catch (Exception e) { + throw new SystemException(SystemException.ILLEGAL_AID); + } + finally { + registrationCallback.set(null); + } + + if (callCount.get() != 1) { + throw new SystemException(SystemException.ILLEGAL_AID); + } + } + + /** Represents an Applet instance */ + public static class ApplicationInstance { + private final AID aid; + private final Applet applet; + + public ApplicationInstance(AID aid, Applet applet) { + this.aid = aid; this.applet = applet; } - - Applet getApplet(){ + + public Applet getApplet(){ return applet; } - - Class getAppletClass(){ - return appletClass; + + @Override + public String toString() { + return String.format("ApplicationInstance (%s)", AIDUtil.toString(aid)); } - } } diff --git a/src/main/java/com/licel/jcardsim/base/SimulatorSystem.java b/src/main/java/com/licel/jcardsim/base/SimulatorSystem.java index 5c7a6a9e..b637d4b4 100644 --- a/src/main/java/com/licel/jcardsim/base/SimulatorSystem.java +++ b/src/main/java/com/licel/jcardsim/base/SimulatorSystem.java @@ -17,473 +17,63 @@ import javacard.framework.*; +import java.lang.reflect.Constructor; + /** - * Base implementation of JCSystem - * @see JCsystem + * Base implementation of JCSystem. + * @see JCSystem */ public class SimulatorSystem { - /** * Response status : Applet creation failed = 0x6444 */ - public static final short SW_APPLET_CRATION_FAILED = 0x6444; - /** - * Response status : Exception occured = 0x6424 - */ - public static final short SW_EXCEPTION_OCCURED = 0x6424; - - // current depth of transaction - private static byte transactionDepth = 0; - // implementaion api version - private static final short API_VERSION = 0x202; - // transient memory storage - private static TransientMemory transientMemory = new TransientMemory(); - - private static SimulatorRuntime runtime = new SimulatorRuntime(); - - public static byte currentChannel = 0; - public static Object previousActiveObject; - - public static NullPointerException nullPointerException; - public static SecurityException securityException; - - private SimulatorSystem() { - nullPointerException = new NullPointerException(); - securityException = new SecurityException(); - } - - /** - * Checks if the specified object is transient. - *

    Note: - *

      - * This method returns NOT_A_TRANSIENT_OBJECT if the specified object is - * null or is not an array type. - *
    - * @param theObj the object being queried - * @return NOT_A_TRANSIENT_OBJECT, CLEAR_ON_RESET, or CLEAR_ON_DESELECT - * @see #makeTransientBooleanArray(short, byte) - * @see #makeByteArray(short, byte) - * @see #makeObjectArray(short, byte) - * @see #makeShortArray(short, byte) - */ - public static byte isTransient(Object theObj) { - return transientMemory.isTransient(theObj); - } - - /** - * Creates a transient boolean array with the specified array length. - * @param length the length of the boolean array - * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient boolean array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    - */ - public static boolean[] makeTransientBooleanArray(short length, byte event) { - return transientMemory.makeBooleanArray(length, event); - } + public static final short SW_APPLET_CREATION_FAILED = 0x6444; /** - * Creates a transient byte array with the specified array length. - * @param length the length of the byte array - * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient byte array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    + * Response status : Exception occurred = 0x6424 */ - public static byte[] makeTransientByteArray(short length, byte event) { - return transientMemory.makeByteArray(length, event); - } + public static final short SW_EXCEPTION_OCCURRED = 0x6424; - /** - * Creates a transient short array with the specified array length. - * @param length the length of the short array - * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient short array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    - */ - public static short[] makeTransientShortArray(short length, byte event) { - return transientMemory.makeShortArray(length, event); - } + /** @deprecated Use SW_APPLET_CREATION_FAILED */ + public static final short SW_APPLET_CRATION_FAILED = SW_APPLET_CREATION_FAILED; - /** - * Creates a transient array of Object with the specified array length. - * @param length the length of the Object array - * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient Object array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    - */ - public static Object[] makeTransientObjectArray(short length, byte event) { - return transientMemory.makeObjectArray(length, event); - } - - /** - * Returns the Java Card runtime environment-owned instance of the AID object associated with - * the current applet context, or - * null if the Applet.register() method - * has not yet been invoked. - *

    Java Card runtime environment-owned instances of AID are permanent Java Card runtime environment - * Entry Point Objects and can be accessed from any applet context. - * References to these permanent objects can be stored and re-used. - *

    See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. - * @return the AID object - */ - public static AID getAID() { - return runtime.getAID(); - } + /** @deprecated Use SW_EXCEPTION_OCCURRED */ + public static final short SW_EXCEPTION_OCCURED = SW_EXCEPTION_OCCURRED; - /** - * Returns the Java Card runtime environment-owned instance of the AID object, if any, - * encapsulating the specified AID bytes in the buffer parameter - * if there exists a successfully installed applet on the card whose instance AID - * exactly matches that of the specified AID bytes. - *

    Java Card runtime environment-owned instances of AID are permanent Java Card runtime environment - * Entry Point Objects and can be accessed from any applet context. - * References to these permanent objects can be stored and re-used. - *

    See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. - * @param buffer byte array containing the AID bytes - * @param offset offset within buffer where AID bytes begin - * @param length length of AID bytes in buffer - * @return the AID object, if any; null otherwise. A VM exception - * is thrown if buffer is null, - * or if offset or length are out of range. - */ - public static AID lookupAID(byte buffer[], short offset, byte length) { - return runtime.lookupAID(buffer, offset, length); - } /** - * Begins an atomic transaction. If a transaction is already in - * progress (transaction nesting depth level != 0), a TransactionException is - * thrown. - *

    Note: - *

      - *
    • This method may do nothing if the Applet.register() - * method has not yet been invoked. In case of tear or failure prior to successful - * registration, the Java Card runtime environment will roll back all atomically updated persistent state. - *
    - * @throws TransactionException with the following reason codes: - *
      - *
    • TransactionException.IN_PROGRESS if a transaction is already in progress. - *
    - * @see #abortTransaction() - * @see #commitTransaction() + * Holds the currently active instance */ - public static void beginTransaction() { - if (transactionDepth != 0) { - TransactionException.throwIt(TransactionException.IN_PROGRESS); - } - transactionDepth = 1; - } + private static final ThreadLocal currentRuntime = new ThreadLocal(); /** - * Aborts the atomic transaction. The contents of the commit - * buffer is discarded. - *

    Note: - *

      - *
    • This method may do nothing if the Applet.register() - * method has not yet been invoked. In case of tear or failure prior to successful - * registration, the Java Card runtime environment will roll back all atomically updated persistent state. - *
    • Do not call this method from within a transaction which creates new objects because - * the Java Card runtime environment may not recover the heap space used by the new object instances. - *
    • Do not call this method from within a transaction which creates new objects because - * the Java Card runtime environment may, to ensure the security of the card and to avoid heap space loss, - * lock up the card session to force tear/reset processing. - *
    • The Java Card runtime environment ensures that any variable of reference type which references an object - * instantiated from within this aborted transaction is equivalent to - * a null reference. - *
    - * @throws TransactionException - with the following reason codes: - *
      - *
    • TransactionException.NOT_IN_PROGRESS if a transaction is not in progress. - *
    - * @see #beginTransaction() - * @see #commitTransaction() + * the default instance. Used by Simulator */ - public static void abortTransaction() { - if (transactionDepth == 0) { - TransactionException.throwIt(TransactionException.NOT_IN_PROGRESS); - } - transactionDepth = 0; - } + public static final SimulatorRuntime DEFAULT_RUNTIME = setCurrentInstance(new SimulatorRuntime()); /** - * Commits an atomic transaction. The contents of commit - * buffer is atomically committed. If a transaction is not in - * progress (transaction nesting depth level == 0) then a TransactionException is - * thrown. - *

    Note: - *

      - *
    • This method may do nothing if the Applet.register() - * method has not yet been invoked. In case of tear or failure prior to successful - * registration, the Java Card runtime environment will roll back all atomically updated persistent state. - *
    - * @throws TransactionException ith the following reason codes: - *
      - *
    • TransactionException.NOT_IN_PROGRESS if a transaction is not in progress. - *
    - * @see #beginTransaction() - * @see #abortTransaction() + * Get the currently active SimulatorRuntime instance + * + * This method should be only called by JCE implementation classes like + * JCSystem + * + * @return current instance */ - public static void commitTransaction() { - if (transactionDepth == 0) { - TransactionException.throwIt(TransactionException.NOT_IN_PROGRESS); + public static SimulatorRuntime instance() { + SimulatorRuntime simulatorRuntime = currentRuntime.get(); + if (simulatorRuntime == null) { + throw new AssertionError("No current simulator instance"); } - transactionDepth = 0; - } - - /** - * Returns the current transaction nesting depth level. At present, - * only 1 transaction can be in progress at a time. - * @return 1 if transaction in progress, 0 if not - */ - public static byte getTransactionDepth() { - return transactionDepth; - } - - /** - * Returns the number of bytes left in the commit buffer. - *

    Note: - *

      - *
    • Current method implementation returns 32767. - *
    - * @return the number of bytes left in the commit buffer - * @see #getMaxCommitCapacity() - */ - public static short getUnusedCommitCapacity() { - return Short.MAX_VALUE; + return simulatorRuntime; } /** - * Returns the total number of bytes in the commit buffer. - * This is approximately the maximum number of bytes of - * persistent data which can be modified during a transaction. - * However, the transaction subsystem requires additional bytes - * of overhead data to be included in the commit buffer, and this - * depends on the number of fields modified and the implementation - * of the transaction subsystem. The application cannot determine - * the actual maximum amount of data which can be modified during - * a transaction without taking these overhead bytes into consideration. - *

    Note: - *

      - *
    • Current method implementation returns 32767. - *
    - * @return the total number of bytes in the commit buffer - * @see #getUnusedCommitCapacity() + * Internal method to set the currently active SimulatorRuntime + * @param simulatorRuntime simulatorRuntime to set + * @return simulatorRuntime */ - public static short getMaxCommitCapacity() { - return Short.MAX_VALUE; - } - - /** - * Obtains the Java Card runtime environment-owned instance of the AID object associated - * with the previously active applet context. This method is typically used by a server applet, - * while executing a shareable interface method to determine the identity of its client and - * thereby control access privileges. - *

    Java Card runtime environment-owned instances of AID are permanent Java Card runtime environment - * Entry Point Objects and can be accessed from any applet context. - * References to these permanent objects can be stored and re-used. - *

    See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. - * @return the AID object of the previous context, or null if Java Card runtime environment - */ - public static AID getPreviousContextAID() { - return runtime.getPreviousContextAID(); - } - - /** - * Current method implementation returns 32767. - * @return 32767 - */ - public static short getAvailablePersistentMemory() { - return Short.MAX_VALUE; - } - - /** - * Current method implementation returns 32767. - * @return 32767 - */ - public static short getAvailableTransientResetMemory() { - return Short.MAX_VALUE; - } - - /** - * Current method implementation returns 32767. - * @return 32767 - */ - public static short getAvailableTransientDeselectMemory() { - return Short.MAX_VALUE; - } - - /** - * Called by a client applet to get a server applet's - * shareable interface object.

    This method returns null - * if: - *

      - *
    • the Applet.register() has not yet been invoked
    • - *
    • the server does not exist
    • - *
    • the server returns null
    • - *
    - * @param serverAID the AID of the server applet - * @param parameter optional parameter data - * @return the shareable interface object or null - * @see Applet.getShareableInterfaceObject(AID, byte) - */ - public static Shareable getSharedObject(AID serverAID, byte parameter) { - Applet serverApplet = runtime.getApplet(serverAID); - if (serverApplet != null) { - return serverApplet.getShareableInterfaceObject(runtime.getAID(), - parameter); - } - return null; - } - - /** - * Alway return false - * @return false value - */ - public static boolean isObjectDeletionSupported() { - return false; - } - - /** - * Always throw SystemException.ILLEGAL_USE - */ - public static void requestObjectDeletion() { - // do nothing - } - - public static byte getCurrentlySelectedChannel() { - return currentChannel; - } - - /** - * This method is used to determine if the specified applet is - * active on the card. - *

    Note: - *

      - *
    • This method returns false if the specified applet is - * not active, even if its context is active. - *
    - * @param theApplet the AID of the applet object being queried - * @return true if and only if the applet specified by the - * AID parameter is currently active on this or another logical channel - */ - public static boolean isAppletActive(AID theApplet) { - return (theApplet == runtime.getAID()); - } - - public static void sendAPDU(byte[] buffer, short bOff, short len) { - runtime.sendAPDU(buffer, bOff, len); - } - - /** - * This method is used by the applet to register this applet instance with - * the Java Card runtime environment and to - * assign the Java Card platform name of the applet as its instance AID bytes. - * One of the register() methods must be called from within install() - * to be registered with the Java Card runtime environment. - * See Runtime Environment Specification for the Java Card Platform, section 3.1 for details. - *

    Note:

      - *
    • The phrase "Java Card platform name of the applet" is a reference to the AID[AID_length] - * item in the applets[] item of the applet_component, as documented in Section 6.5 - * Applet Component in the Virtual Machine Specification for the Java Card Platform. - *
    - * @throws SystemException with the following reason codes:
      - *
    • SystemException.ILLEGAL_AID if the Applet subclass AID bytes are in use or - * if the applet instance has previously successfully registered with the Java Card runtime environment via one of the - * register() methods or if a Java Card runtime environment initiated install() method execution is not in progress. - *
    - */ - public static void registerApplet(Applet applet) throws SystemException { - runtime.registerApplet(null, applet); - } - - /** - * This method is used by the applet to register this applet instance with the Java Card runtime environment and - * assign the specified AID bytes as its instance AID bytes. - * One of the register() methods must be called from within install() - * to be registered with the Java Card runtime environment. - * See Runtime Environment Specification for the Java Card Platform, section 3.1 for details. - *

    Note:

      - *
    • The implementation may require that the instance AID bytes specified are the same as that - * supplied in the install parameter data. An ILLEGAL_AID exception may be thrown otherwise. - *
    - */ - public static void registerApplet(Applet applet, byte[] bArray, short bOffset, byte bLength) - throws SystemException { - runtime.registerApplet(new AID(bArray, bOffset, bLength), applet); - } - - /** - * Select applet by it's AID - * This method must be called before start working with applet instance - * @param aid appletId - * @return true if applet selection success - * before - */ - static boolean selectApplet(AID aid) { - return runtime.selectApplet(aid); - } - - /** - * Transmit commandAPDU to previous selected applet - * @param commandAPDU - * @return responseAPDU - */ - static byte[] transmitCommand(byte[] command) { - return runtime.transmitCommand(command); - } - - public static boolean isAppletSelecting(Applet aThis) { - // TODO !!! rewrite - return false; - } - - /** - * Return SimulatorRuntime - * @return instance of the SimulatorRuntime - */ - static SimulatorRuntime getRuntime() { - return runtime; - } - - public static void resetRuntime() { - runtime.resetRuntime(); - } - - public static void setJavaOwner(Object obj, Object owner) { - } - - public static Object getJavaOwner(Object obj) { - return obj; - } - - public static short getJavaContext(Object obj) { - return 0; + static SimulatorRuntime setCurrentInstance(SimulatorRuntime simulatorRuntime) { + currentRuntime.set(simulatorRuntime); + return simulatorRuntime; } } diff --git a/src/main/java/com/licel/jcardsim/base/TransientMemory.java b/src/main/java/com/licel/jcardsim/base/TransientMemory.java index a017a8a6..4902686a 100644 --- a/src/main/java/com/licel/jcardsim/base/TransientMemory.java +++ b/src/main/java/com/licel/jcardsim/base/TransientMemory.java @@ -16,112 +16,75 @@ package com.licel.jcardsim.base; import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + import javacard.framework.JCSystem; import javacard.framework.SystemException; /** - * Basic implementation of storage transient memory of JCRE + * Basic implementation of storage transient memory of JCRE. */ public class TransientMemory { - - ArrayList clearOnDeselect = new ArrayList(); - ArrayList clearOnReset = new ArrayList(); + /** List of CLEAR_ON_DESELECT arrays */ + protected final ArrayList clearOnDeselect = new ArrayList(); + /** List of CLEAR_ON_RESET arrays */ + protected final ArrayList clearOnReset = new ArrayList(); /** - * Creates a transient boolean array with the specified array length. - * @param length the length of the boolean array + * @see javacard.framework.JCSystem#makeTransientBooleanArray(short, byte) + * @param length the length of the array * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient boolean array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    + * @return the new transient array */ - boolean[] makeBooleanArray(short length, byte event) { + public boolean[] makeBooleanArray(short length, byte event) { boolean[] array = new boolean[length]; storeArray(array, event); return array; } /** - * Creates a transient byte array with the specified array length. - * @param length the length of the byte array + * @see javacard.framework.JCSystem#makeTransientByteArray(short, byte) + * @param length the length of the array * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient byte array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    + * @return the new transient array */ - byte[] makeByteArray(short length, byte event) { + public byte[] makeByteArray(int length, byte event) { byte[] array = new byte[length]; storeArray(array, event); return array; } /** - * Creates a transient short array with the specified array length. - * @param length the length of the short array + * @see javacard.framework.JCSystem#makeTransientShortArray(short, byte) + * @param length the length of the array * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient short array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    + * @return the new transient array */ - short[] makeShortArray(short length, byte event) { + public short[] makeShortArray(short length, byte event) { short[] array = new short[length]; storeArray(array, event); return array; } /** - * Creates a transient array of Object with the specified array length. - * @param length the length of the Object array + * @see javacard.framework.JCSystem#makeTransientObjectArray(short, byte) + * @param length the length of the array * @param event the CLEAR_ON... event which causes the array elements to be cleared - * @return the new transient Object array - * @throws NegativeArraySizeException if the length parameter is negative - * @throws SystemException with the following reason codes: - *
      - *
    • SystemException.ILLEGAL_VALUE if event is not a valid event code. - *
    • SystemException.NO_TRANSIENT_SPACE if sufficient transient space is not available. - *
    • SystemException.ILLEGAL_TRANSIENT if the current applet context - * is not the currently selected applet context and CLEAR_ON_DESELECT is specified. - *
    + * @return the new transient array */ - Object[] makeObjectArray(short length, byte event) { + public Object[] makeObjectArray(short length, byte event) { Object[] array = new Object[length]; storeArray(array, event); return array; } /** - * Checks if the specified object is transient. - *

    Note: - *

      - * This method returns NOT_A_TRANSIENT_OBJECT if the specified object is - * null or is not an array type. - *
    + * @see javacard.framework.JCSystem#isTransient(Object) * @param theObj the object being queried * @return NOT_A_TRANSIENT_OBJECT, CLEAR_ON_RESET, or CLEAR_ON_DESELECT - * @see #makeTransientBooleanArray(short, byte) - * @see #makeByteArray(short, byte) - * @see #makeObjectArray(short, byte) - * @see #makeShortArray(short, byte) */ - byte isTransient(Object theObj) { + public byte isTransient(Object theObj) { if (clearOnDeselect.contains(theObj)) { return JCSystem.CLEAR_ON_DESELECT; } else if (clearOnReset.contains(theObj)) { @@ -135,7 +98,7 @@ byte isTransient(Object theObj) { * @param arrayRef array reference * @param event event type */ - private void storeArray(Object arrayRef, byte event) { + protected void storeArray(Object arrayRef, byte event) { switch (event) { case JCSystem.CLEAR_ON_DESELECT: clearOnDeselect.add(arrayRef); @@ -147,4 +110,53 @@ private void storeArray(Object arrayRef, byte event) { SystemException.throwIt(SystemException.ILLEGAL_VALUE); } } + + /** + * Zero CLEAR_ON_DESELECT buffers + */ + protected void clearOnDeselect() { + zero(clearOnDeselect); + } + + /** + * Zero CLEAR_ON_RESET and CLEAR_ON_DESELECT + * buffers + */ + protected void clearOnReset() { + zero(clearOnDeselect); + zero(clearOnReset); + } + + /** + * Perform clearOnReset and forget all buffers + */ + protected void forgetBuffers() { + clearOnReset(); + clearOnDeselect.clear(); + clearOnReset.clear(); + } + + /** + * Zero all arrays in list + * @param list list of arrays + */ + protected void zero(List list) { + for (Object obj : list) { + if (obj instanceof byte[]) { + Arrays.fill((byte[]) obj, (byte) 0); + } + else if (obj instanceof short[]) { + Arrays.fill((short[]) obj, (short) 0); + } + else if (obj instanceof Object[]) { + Arrays.fill((Object[])obj, null); + } + else if (obj instanceof boolean[]) { + boolean[] array = (boolean[]) obj; + for (int i = 0; i < array.length; ++i) { + array[i] = false; + } + } + } + } } diff --git a/src/main/java/com/licel/jcardsim/base/package-info.java b/src/main/java/com/licel/jcardsim/base/package-info.java new file mode 100644 index 00000000..3b7413c9 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/base/package-info.java @@ -0,0 +1,4 @@ +/** + * jCardSim simulator base classes. + */ +package com.licel.jcardsim.base; diff --git a/src/main/java/com/licel/jcardsim/crypto/AssymetricCipherImpl.java b/src/main/java/com/licel/jcardsim/crypto/AsymmetricCipherImpl.java similarity index 97% rename from src/main/java/com/licel/jcardsim/crypto/AssymetricCipherImpl.java rename to src/main/java/com/licel/jcardsim/crypto/AsymmetricCipherImpl.java index d35538ad..f7a089c3 100644 --- a/src/main/java/com/licel/jcardsim/crypto/AssymetricCipherImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/AsymmetricCipherImpl.java @@ -28,10 +28,10 @@ /* * Implementation Cipher with asymmetric keys based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see Cipher */ -public class AssymetricCipherImpl extends Cipher { +public class AsymmetricCipherImpl extends Cipher { byte algorithm; AsymmetricBlockCipher engine; @@ -40,7 +40,7 @@ public class AssymetricCipherImpl extends Cipher { byte[] buffer; short bufferPos; - public AssymetricCipherImpl(byte algorithm) { + public AsymmetricCipherImpl(byte algorithm) { this.algorithm = algorithm; switch (algorithm) { case ALG_RSA_NOPAD: diff --git a/src/main/java/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.java b/src/main/java/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.java index 50a7ece4..85583d8d 100644 --- a/src/main/java/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/AsymmetricSignatureImpl.java @@ -15,13 +15,16 @@ */ package com.licel.jcardsim.crypto; +import java.lang.reflect.Field; import javacard.framework.JCSystem; import javacard.framework.Util; import javacard.security.CryptoException; import javacard.security.Key; import javacard.security.Signature; +import javacard.security.SignatureMessageRecovery; import org.bouncycastle.crypto.DataLengthException; import org.bouncycastle.crypto.Signer; +import org.bouncycastle.crypto.SignerWithRecovery; import org.bouncycastle.crypto.digests.MD5Digest; import org.bouncycastle.crypto.digests.RIPEMD160Digest; import org.bouncycastle.crypto.digests.SHA1Digest; @@ -33,22 +36,29 @@ /* * Implementation Signature with asymmetric keys based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see Signature */ -public class AsymmetricSignatureImpl extends Signature { +public class AsymmetricSignatureImpl extends Signature implements SignatureMessageRecovery{ Signer engine; Key key; byte algorithm; boolean isInitialized; + boolean isRecovery; + byte[] preSig; public AsymmetricSignatureImpl(byte algorithm) { this.algorithm = algorithm; + isRecovery = false; switch (algorithm) { case ALG_RSA_SHA_ISO9796: engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest()); break; + case ALG_RSA_SHA_ISO9796_MR: + engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest()); + isRecovery = true; + break; case ALG_RSA_SHA_PKCS1: engine = new RSADigestSigner(new SHA1Digest()); break; @@ -119,6 +129,9 @@ public void update(byte[] inBuff, short inOffset, short inLength) throws CryptoE } public short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset) throws CryptoException { + if (isRecovery) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } if (!isInitialized) { CryptoException.throwIt(CryptoException.INVALID_INIT); } @@ -139,14 +152,89 @@ public short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, } public boolean verify(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset, short sigLength) throws CryptoException { + if (isRecovery) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } if (!isInitialized) { CryptoException.throwIt(CryptoException.INVALID_INIT); } engine.update(inBuff, inOffset, inLength); - byte[] sig = JCSystem.makeTransientByteArray(sigLength, JCSystem.CLEAR_ON_RESET); + byte[] sig = new byte[sigLength]; Util.arrayCopyNonAtomic(sigBuff, sigOffset, sig, (short) 0, sigLength); boolean b = engine.verifySignature(sig); engine.reset(); return b; } + + public short beginVerify(byte[] sigAndRecDataBuff, short buffOffset, short sigLength) throws CryptoException { + if (!isRecovery) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } + if (!isInitialized) { + CryptoException.throwIt(CryptoException.INVALID_INIT); + } + preSig = JCSystem.makeTransientByteArray(sigLength, JCSystem.CLEAR_ON_RESET); + Util.arrayCopyNonAtomic(sigAndRecDataBuff, buffOffset, preSig, (short) 0, sigLength); + try { + ((SignerWithRecovery) engine).updateWithRecoveredMessage(preSig); + return (short) ((SignerWithRecovery) engine).getRecoveredMessage().length; + } catch (Exception ex) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } + return -1; + } + + public short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset, short[] recMsgLen, + short recMsgLenOffset) throws CryptoException { + if (!isRecovery) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } + if (!isInitialized) { + CryptoException.throwIt(CryptoException.INVALID_INIT); + } + engine.update(inBuff, inOffset, inLength); + byte[] sig; + try { + sig = engine.generateSignature(); + Util.arrayCopyNonAtomic(sig, (short) 0, sigBuff, sigOffset, (short) sig.length); + // there is no direct way to obtain encoded message length + int keyBits = key.getSize(); + Field messageLengthField = engine.getClass().getDeclaredField("messageLength"); + messageLengthField.setAccessible(true); + int messageLength = messageLengthField.getInt(engine); + int digSize = 20; + int x = (digSize + messageLength) * 8 + 16 + 4 - keyBits; + int mR = messageLength; + if (x > 0) { + mR = messageLength - ((x + 7) / 8); + } + recMsgLen[recMsgLenOffset] = (short) mR; + return (short) sig.length; + } catch (org.bouncycastle.crypto.CryptoException ex) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } catch (DataLengthException ex) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } catch (Exception ex) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } finally { + engine.reset(); + } + return -1; + } + + public boolean verify(byte[] inBuff, short inOffset, short inLength) throws CryptoException { + if(!isRecovery){ + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } + if(preSig == null){ + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } + if (!isInitialized) { + CryptoException.throwIt(CryptoException.INVALID_INIT); + } + engine.update(inBuff, inOffset, inLength); + boolean b = engine.verifySignature(preSig); + engine.reset(); + return b; + } } diff --git a/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java b/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java index c661b08a..240fb74f 100644 --- a/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java +++ b/src/main/java/com/licel/jcardsim/crypto/ByteContainer.java @@ -22,13 +22,13 @@ /** * This class contains byte array, initialization flag of this - * array and memory type + * array and memory type. */ public final class ByteContainer { private byte[] data; - private boolean isInitialized; private byte memoryType; + private short length = 0; /** * Construct ByteContainer @@ -44,7 +44,6 @@ public ByteContainer() { * @param memoryType memoryType from JCSystem.MEMORY_.. */ public ByteContainer(byte memoryType) { - isInitialized = false; this.memoryType = memoryType; } @@ -53,9 +52,10 @@ public ByteContainer(byte memoryType) { * with memory type JCSystem.MEMORY_TYPE_PERSISTENT * and fills it by byte representation of BigInteger * @param bInteger BigInteger object + * @throws java.lang.IllegalArgumentException if bInteger is negative */ public ByteContainer(BigInteger bInteger) { - this(bInteger.toByteArray(), (short) 0, (short) bInteger.toByteArray().length); + setBigInteger(bInteger); } /** @@ -63,8 +63,8 @@ public ByteContainer(BigInteger bInteger) { * with memory type JCSystem.MEMORY_TYPE_PERSISTENT * and fills it by defined byte array * @param buff byte array - * @param offset - * @param length + * @param offset offset in byte array + * @param length length of data in byte array */ public ByteContainer(byte[] buff, short offset, short length) { setBytes(buff, offset, length); @@ -72,15 +72,28 @@ public ByteContainer(byte[] buff, short offset, short length) { /** * Fills ByteContainerby byte representation of BigInteger - * @param bInteger + * @param bInteger BigInteger object + * @throws java.lang.IllegalArgumentException if bInteger is negative */ public void setBigInteger(BigInteger bInteger) { - setBytes(bInteger.toByteArray()); + if (bInteger.signum() < 0) { + throw new IllegalArgumentException("Negative bInteger"); + } + + byte[] array = bInteger.toByteArray(); + if (array[0] == 0 && array.length > 1) { + byte[] trimmedArray = new byte[array.length - 1]; + System.arraycopy(array, 1, trimmedArray, 0, trimmedArray.length); + setBytes(trimmedArray); + } + else { + setBytes(array); + } } /** * Fills ByteContainerby defined byte array - * @param buff + * @param buff byte array */ public void setBytes(byte[] buff) { setBytes(buff, (short) 0, (short) buff.length); @@ -88,9 +101,9 @@ public void setBytes(byte[] buff) { /** * Fills ByteContainerby defined byte array - * @param buff - * @param offset - * @param length + * @param buff byte array + * @param offset offset in byte array + * @param length length of data in byte array */ public void setBytes(byte[] buff, short offset, short length) { if (data == null) { @@ -107,7 +120,8 @@ public void setBytes(byte[] buff, short offset, short length) { } } Util.arrayCopy(buff, offset, data, (short) 0, length); - isInitialized = true; + // current length + this.length = length; } /** @@ -115,7 +129,7 @@ public void setBytes(byte[] buff, short offset, short length) { * @return BigInteger */ public BigInteger getBigInteger() { - if (!isInitialized) { + if (length == 0) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } return new BigInteger(1, data); @@ -127,10 +141,10 @@ public BigInteger getBigInteger() { * @return plain byte array */ public byte[] getBytes(byte event) { - if (!isInitialized) { + if (length == 0) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } - byte[] result = JCSystem.makeTransientByteArray((short) data.length, event); + byte[] result = JCSystem.makeTransientByteArray(length, event); getBytes(result, (short) 0); return result; } @@ -138,19 +152,19 @@ public byte[] getBytes(byte event) { /** * Copy byte array representation of the ByteContainer * @param dest destination byte array - * @param offset - * @return bytes copies + * @param offset destination byte array offset + * @return bytes copied */ public short getBytes(byte[] dest, short offset) { - if (!isInitialized) { + if (length == 0) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } - if (dest.length - offset < data.length) { + if (dest.length - offset < length) { CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); } - Util.arrayCopy(data, (short) 0, dest, offset, (short) data.length); + Util.arrayCopy(data, (short) 0, dest, offset, length); // https://code.google.com/p/jcardsim/issues/detail?id=14 - return (short)data.length; + return length; } /** @@ -160,10 +174,14 @@ public void clear() { if (data != null) { Util.arrayFillNonAtomic(data, (short) 0, (short) data.length, (byte) 0); } - isInitialized = false; + length = 0; } + /** + * Reports the initialized state of the container. + * @return true if the container has been initialized + */ public boolean isInitialized() { - return isInitialized; + return length > 0; } } diff --git a/src/main/java/com/licel/jcardsim/crypto/CRC16.java b/src/main/java/com/licel/jcardsim/crypto/CRC16.java index a1936d4b..890ec2f7 100644 --- a/src/main/java/com/licel/jcardsim/crypto/CRC16.java +++ b/src/main/java/com/licel/jcardsim/crypto/CRC16.java @@ -22,8 +22,8 @@ /* * Implementation Checksum - * ISO/IEC 3309 compliant 16 bit CRC algorithm. - * on BouncyCastle CryptoAPI + * ISO/IEC 3309 compliant 16 bit CRC algorithm + * on BouncyCastle CryptoAPI. * @see Checksum */ public class CRC16 extends Checksum { diff --git a/src/main/java/com/licel/jcardsim/crypto/CRC32.java b/src/main/java/com/licel/jcardsim/crypto/CRC32.java index 1fe62588..4374cac5 100644 --- a/src/main/java/com/licel/jcardsim/crypto/CRC32.java +++ b/src/main/java/com/licel/jcardsim/crypto/CRC32.java @@ -23,7 +23,7 @@ /* * Implementation Checksum * ISO/IEC 3309 compliant 32 bit CRC algorithm. - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see Checksum */ public class CRC32 extends Checksum { diff --git a/src/main/java/com/licel/jcardsim/crypto/DSAKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/DSAKeyImpl.java index 20c229f9..02e9b7d2 100644 --- a/src/main/java/com/licel/jcardsim/crypto/DSAKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/DSAKeyImpl.java @@ -29,7 +29,7 @@ /** * Base class for DSAPublicKeyImpl/DSAPrivateKeyImpl - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see DSAKey */ public class DSAKeyImpl extends KeyImpl implements DSAKey { @@ -43,28 +43,32 @@ public class DSAKeyImpl extends KeyImpl implements DSAKey { * Construct not-initialized dsa key * @param keyType - key type * @param keySize - key size in bits - * @see KeyPair + * @see javacard.security.KeyPair * @see KeyBuilder */ - public DSAKeyImpl(byte keyType, short size) { - this.size = size; + public DSAKeyImpl(byte keyType, short keySize) { + this.size = keySize; type = keyType; } /** * Construct and initialize dsa key with DSAKeyParameters. * Use in KeyPairImpl - * @see KeyPair + * @see javacard.security.KeyPair * @see DSAKeyParameters - * @parameters params key params from BouncyCastle API + * @param params key params from BouncyCastle API */ public DSAKeyImpl(DSAKeyParameters params) { this(params.isPrivate() ? KeyBuilder.TYPE_DSA_PRIVATE : KeyBuilder.TYPE_DSA_PUBLIC, (short) params.getParameters().getP().bitLength()); - p.setBigInteger(params.getParameters().getP()); - q.setBigInteger(params.getParameters().getQ()); - g.setBigInteger(params.getParameters().getG()); + setParameters(params); } + public void setParameters(CipherParameters params){ + p.setBigInteger(((DSAKeyParameters)params).getParameters().getP()); + q.setBigInteger(((DSAKeyParameters)params).getParameters().getQ()); + g.setBigInteger(((DSAKeyParameters)params).getParameters().getG()); + } + public void clearKey() { p.clear(); q.clear(); @@ -188,5 +192,4 @@ static KeyGenerationParameters getDefaultKeyGenerationParameters(short keySize, new DSAParameters(p, q, g, new DSAValidationParameters(seed.toByteArray(), counter))); } - } diff --git a/src/main/java/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.java index d54fa18b..bfe82def 100644 --- a/src/main/java/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.java @@ -24,7 +24,7 @@ /** * Implementation DSAPrivateKey based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see DSAPrivateKey * @see DSAPrivateKeyParameters */ @@ -34,7 +34,7 @@ public class DSAPrivateKeyImpl extends DSAKeyImpl implements DSAPrivateKey { /** * Construct not-initialized dsa private key - * @param size key size it bits + * @param keySize key size it bits * @see KeyBuilder */ public DSAPrivateKeyImpl(short keySize) { @@ -44,15 +44,19 @@ public DSAPrivateKeyImpl(short keySize) { /** * Construct and initialize dsa key with DSAPrivateKeyParameters. * Use in KeyPairImpl - * @see KeyPair + * @see javacard.security.KeyPair * @see DSAPrivateKeyParameters * @param params key params from BouncyCastle API */ public DSAPrivateKeyImpl(DSAPrivateKeyParameters params) { super(params); - x.setBigInteger(params.getX()); + setParameters(params); } + public void setParameters(CipherParameters params) { + x.setBigInteger(((DSAPrivateKeyParameters) params).getX()); + } + public void setX(byte[] buffer, short offset, short length) throws CryptoException { x.setBytes(buffer, offset, length); } diff --git a/src/main/java/com/licel/jcardsim/crypto/DSAPublicKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/DSAPublicKeyImpl.java index 7cd267b8..0b17372f 100644 --- a/src/main/java/com/licel/jcardsim/crypto/DSAPublicKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/DSAPublicKeyImpl.java @@ -24,7 +24,7 @@ /** * Implementation DSAPublicKey based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see DSAPublicKey * @see DSAPublicKeyParameters */ @@ -34,7 +34,7 @@ public class DSAPublicKeyImpl extends DSAKeyImpl implements DSAPublicKey { /** * Construct not-initialized dsa public key - * @param size key size it bits + * @param keySize key size it bits * @see KeyBuilder */ public DSAPublicKeyImpl(short keySize) { @@ -44,15 +44,19 @@ public DSAPublicKeyImpl(short keySize) { /** * Construct and initialize ecc key with DSAPublicKeyParameters. * Use in KeyPairImpl - * @see KeyPair + * @see javacard.security.KeyPair * @see DSAPublicKeyParameters * @param params key params from BouncyCastle API */ public DSAPublicKeyImpl(DSAPublicKeyParameters params) { super(params); - y.setBigInteger(params.getY()); + setParameters(params); } + public void setParameters(CipherParameters params) { + y.setBigInteger(((DSAPublicKeyParameters) params).getY()); + } + public void setY(byte[] buffer, short offset, short length) throws CryptoException { y.setBytes(buffer, offset, length); } @@ -75,5 +79,5 @@ public CipherParameters getParameters() { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } return new DSAPublicKeyParameters(y.getBigInteger(), ((DSAKeyParameters) super.getParameters()).getParameters()); - } + } } diff --git a/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java index 60c889ad..70c03a77 100644 --- a/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/ECKeyImpl.java @@ -32,7 +32,7 @@ /** * Base class for - * ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI + * ECPublicKeyImpl/ECPrivateKeyImpl on BouncyCastle CryptoAPI. * * @see ECKey */ @@ -68,7 +68,7 @@ public ECKeyImpl(byte keyType, short keySize) { * * @see KeyPair * @see ECKeyParameters - * @parameters params key params from BouncyCastle API + * @param parameters key params from BouncyCastle API */ public ECKeyImpl(ECKeyParameters parameters) { boolean isPrivate = parameters.isPrivate(); @@ -91,10 +91,10 @@ public void clearKey() { e3 = 0; } - public boolean isInitialized() { + protected boolean isDomainParametersInitialized() { return (a.isInitialized() && b.isInitialized() && g.isInitialized() && r.isInitialized() && isKInitialized && (fp.isInitialized() || k != 0)); - } + } public void setFieldFP(byte[] buffer, short offset, short length) throws CryptoException { fp.setBytes(buffer, offset, length); @@ -166,7 +166,7 @@ public short getK() throws CryptoException { * @see ECDomainParameters */ public ECDomainParameters getDomainParameters() { - if (!isInitialized()) { + if (!isDomainParametersInitialized()) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } ECCurve curve = null; @@ -213,10 +213,10 @@ final void setDomainParameters(ECDomainParameters parameters) { * @return parameters for use with BouncyCastle API */ public KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd) { - if (isInitialized()) { + if (isDomainParametersInitialized()) { return new ECKeyGenerationParameters(getDomainParameters(), rnd); } - return getDefaultKeyGenerationParameters(type, size, rnd); + return new ECKeyGenerationParameters(getDefaultsDomainParameters(type, size), rnd); } /** @@ -259,6 +259,7 @@ static ECDomainParameters getDefaultsDomainParameters(byte keyType, short keySiz case 128: case 160: case 192: + case 256: if ((keyType != KeyBuilder.TYPE_EC_FP_PRIVATE) & (keyType != KeyBuilder.TYPE_EC_FP_PUBLIC)) { CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); } diff --git a/src/main/java/com/licel/jcardsim/crypto/ECPrivateKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/ECPrivateKeyImpl.java index dfbf9e49..5ff93ed7 100644 --- a/src/main/java/com/licel/jcardsim/crypto/ECPrivateKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/ECPrivateKeyImpl.java @@ -22,7 +22,7 @@ /** * Implementation ECPrivateKey based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see ECPrivateKey * @see ECPrivateKeyParameters */ @@ -32,8 +32,10 @@ public class ECPrivateKeyImpl extends ECKeyImpl implements ECPrivateKey { /** * Construct not-initialized ecc private key - * @param size key size it bits - * @see KeyBuilder + * @param keyType key type + * @param keySize key size it bits + * + * @see javacard.security.KeyBuilder */ public ECPrivateKeyImpl(byte keyType, short keySize) { super(keyType, keySize); @@ -42,13 +44,17 @@ public ECPrivateKeyImpl(byte keyType, short keySize) { /** * Construct and initialize ecc key with ECPrivateKeyParameters. * Use in KeyPairImpl - * @see KeyPair + * @see javacard.security.KeyPair * @see ECPrivateKeyParameters * @param params key params from BouncyCastle API */ public ECPrivateKeyImpl(ECPrivateKeyParameters params) { super(params); - s.setBigInteger(params.getD()); + setParameters(params); + } + + public void setParameters(CipherParameters params){ + s.setBigInteger(((ECPrivateKeyParameters)params).getD()); } public void setS(byte[] buffer, short offset, short length) throws CryptoException { @@ -60,7 +66,7 @@ public short getS(byte[] buffer, short offset) throws CryptoException { } public boolean isInitialized() { - return (super.isInitialized() && s.isInitialized()); + return (isDomainParametersInitialized() && s.isInitialized()); } public void clearKey() { diff --git a/src/main/java/com/licel/jcardsim/crypto/ECPublicKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/ECPublicKeyImpl.java index 10889cc8..335919d4 100644 --- a/src/main/java/com/licel/jcardsim/crypto/ECPublicKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/ECPublicKeyImpl.java @@ -24,7 +24,7 @@ /** * Implementation ECPublicKey based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see ECPublicKey * @see ECPublicKeyParameters */ @@ -34,8 +34,9 @@ public class ECPublicKeyImpl extends ECKeyImpl implements ECPublicKey { /** * Construct not-initialized ecc public key - * @param size key size it bits - * @see KeyBuilder + * @param keyType key type + * @param keySize key size it bits + * @see javacard.security.KeyBuilder */ public ECPublicKeyImpl(byte keyType, short keySize) { super(keyType, keySize); @@ -44,14 +45,19 @@ public ECPublicKeyImpl(byte keyType, short keySize) { /** * Construct and initialize ecc key with ECPublicKeyParameters. * Use in KeyPairImpl - * @see KeyPair + * @see javacard.security.KeyPair * @see ECPublicKeyParameters * @param params key params from BouncyCastle API */ public ECPublicKeyImpl(ECPublicKeyParameters params) { super(params); - w.setBytes(params.getQ().getEncoded()); + setParameters(params); } + + public void setParameters(CipherParameters params){ + w.setBytes(((ECPublicKeyParameters)params).getQ().getEncoded()); + } + public void setW(byte[] buffer, short offset, short length) throws CryptoException { w.setBytes(buffer, offset, length); @@ -62,7 +68,7 @@ public short getW(byte[] buffer, short offset) throws CryptoException { } public boolean isInitialized() { - return (super.isInitialized() && w.isInitialized()); + return (isDomainParametersInitialized() && w.isInitialized()); } public void clearKey() { diff --git a/src/main/java/com/licel/jcardsim/crypto/KeyAgreementImpl.java b/src/main/java/com/licel/jcardsim/crypto/KeyAgreementImpl.java index cdd222bc..80fbb026 100644 --- a/src/main/java/com/licel/jcardsim/crypto/KeyAgreementImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/KeyAgreementImpl.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.framework.Util; import javacard.security.CryptoException; import javacard.security.KeyAgreement; @@ -23,19 +22,22 @@ import org.bouncycastle.crypto.BasicAgreement; import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; import org.bouncycastle.crypto.agreement.ECDHCBasicAgreement; +import org.bouncycastle.crypto.digests.SHA1Digest; import org.bouncycastle.crypto.params.ECPrivateKeyParameters; import org.bouncycastle.crypto.params.ECPublicKeyParameters; /** * Implementation KeyAgreement based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see KeyAgreement * @see ECDHBasicAgreement - * @see ECHDCBasicAgreement + * @see ECDHCBasicAgreement */ public class KeyAgreementImpl extends KeyAgreement { BasicAgreement engine; + SHA1Digest digestEngine; + byte algorithm; ECPrivateKeyImpl privateKey; @@ -52,6 +54,7 @@ public KeyAgreementImpl(byte algorithm) { CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } + digestEngine = new SHA1Digest(); } public void init(PrivateKey privateKey) throws CryptoException { @@ -74,15 +77,16 @@ public short generateSecret(byte[] publicData, short publicLength, byte[] secret, short secretOffset) throws CryptoException { - byte[] publicKey = JCSystem.makeTransientByteArray(publicLength, JCSystem.CLEAR_ON_RESET); + byte[] publicKey = new byte[publicLength]; Util.arrayCopyNonAtomic(publicData, publicOffset, publicKey, (short) 0, publicLength); ECPublicKeyParameters ecp = new ECPublicKeyParameters( ((ECPrivateKeyParameters) privateKey.getParameters()).getParameters().getCurve().decodePoint(publicKey), ((ECPrivateKeyParameters) privateKey.getParameters()).getParameters()); byte[] result = engine.calculateAgreement(ecp).toByteArray(); - if (result.length > secret.length - secretOffset) { - CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); - } - Util.arrayCopyNonAtomic(result, (short) 0, secret, secretOffset, (short) result.length); - return (short) result.length; + // apply SHA1-hash (see spec) + byte[] hashResult = new byte[20]; + digestEngine.update(result, 0, result.length); + digestEngine.doFinal(hashResult, 0); + Util.arrayCopyNonAtomic(hashResult, (short) 0, secret, secretOffset, (short) hashResult.length); + return (short) hashResult.length; } } diff --git a/src/main/java/com/licel/jcardsim/crypto/KeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/KeyImpl.java index acd311d4..6a3c5ecb 100644 --- a/src/main/java/com/licel/jcardsim/crypto/KeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/KeyImpl.java @@ -18,7 +18,7 @@ import javacard.security.Key; /** - * Base class for all Key instances + * Base class for all Key instances. * @see Key */ public abstract class KeyImpl implements Key, KeyWithParameters { diff --git a/src/main/java/com/licel/jcardsim/crypto/KeyPairImpl.java b/src/main/java/com/licel/jcardsim/crypto/KeyPairImpl.java index 25c2698e..50a252e9 100644 --- a/src/main/java/com/licel/jcardsim/crypto/KeyPairImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/KeyPairImpl.java @@ -15,40 +15,22 @@ */ package com.licel.jcardsim.crypto; -import java.math.BigInteger; import java.security.SecureRandom; import javacard.security.CryptoException; import javacard.security.KeyBuilder; import javacard.security.KeyPair; import javacard.security.PrivateKey; import javacard.security.PublicKey; -import org.bouncycastle.asn1.sec.SECNamedCurves; -import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.AsymmetricCipherKeyPair; import org.bouncycastle.crypto.AsymmetricCipherKeyPairGenerator; import org.bouncycastle.crypto.KeyGenerationParameters; import org.bouncycastle.crypto.generators.DSAKeyPairGenerator; import org.bouncycastle.crypto.generators.ECKeyPairGenerator; import org.bouncycastle.crypto.generators.RSAKeyPairGenerator; -import org.bouncycastle.crypto.params.AsymmetricKeyParameter; -import org.bouncycastle.crypto.params.DSAKeyGenerationParameters; -import org.bouncycastle.crypto.params.DSAKeyParameters; -import org.bouncycastle.crypto.params.DSAParameters; -import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; -import org.bouncycastle.crypto.params.DSAPublicKeyParameters; -import org.bouncycastle.crypto.params.DSAValidationParameters; -import org.bouncycastle.crypto.params.ECDomainParameters; -import org.bouncycastle.crypto.params.ECKeyGenerationParameters; -import org.bouncycastle.crypto.params.ECKeyParameters; -import org.bouncycastle.crypto.params.ECPrivateKeyParameters; -import org.bouncycastle.crypto.params.ECPublicKeyParameters; -import org.bouncycastle.crypto.params.RSAKeyGenerationParameters; -import org.bouncycastle.crypto.params.RSAKeyParameters; -import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters; /** * Implementation - * KeyPair based on BouncyCastle CryptoAPI + * KeyPair based on BouncyCastle CryptoAPI. * * @see KeyPair * @see RSAKeyPairGenerator @@ -80,7 +62,7 @@ public final class KeyPairImpl { * p, q and g parameters of the public key object are pre-initialized, they * will be retained. Otherwise, default precomputed parameter sets will be * used. The required default precomputed values are listed in Appendix - * B of Java Cryptography Architecture API Specification & + * B of Java Cryptography Architecture API Specification & * Reference document.
  • For the EC case, if the Field, A, B, * G and R parameters of the key pair are pre-initialized, then they will be * retained. Otherwise default pre-specified values MAY be used (e.g. WAP @@ -94,36 +76,20 @@ public final class KeyPairImpl { *
  • CryptoException.ILLEGAL_VALUE if the exponent value * parameter in RSA or the p, q, g parameter set in DSA or the Field, A, B, * G and R parameter set in EC is invalid. - * @see APDU - * @see Signature - * @see Cipher - * @see RSAPublicKey - * @see ECKey - * @see DSAKey + * @see javacard.framework.APDU + * @see javacard.security.Signature + * @see javacardx.crypto.Cipher + * @see javacard.security.RSAPublicKey + * @see javacard.security.ECKey + * @see javacard.security.DSAKey */ public final void genKeyPair() throws CryptoException { initEngine(); + createKeys(); AsymmetricCipherKeyPair kp = engine.generateKeyPair(); - // rsa - if (kp.getPublic() instanceof RSAKeyParameters) { - publicKey = new RSAKeyImpl((RSAKeyParameters) kp.getPublic()); - if (kp.getPrivate() instanceof RSAPrivateCrtKeyParameters) { - privateKey = new RSAPrivateCrtKeyImpl((RSAPrivateCrtKeyParameters) kp.getPrivate()); - } else if (kp.getPrivate() instanceof RSAKeyParameters) { - privateKey = new RSAKeyImpl((RSAKeyParameters) kp.getPrivate()); - } - } else // dsa - if (kp.getPublic() instanceof DSAPublicKeyParameters) { - publicKey = new DSAPublicKeyImpl((DSAPublicKeyParameters) kp.getPublic()); - privateKey = new DSAPrivateKeyImpl((DSAPrivateKeyParameters) kp.getPrivate()); - } else // ecc - if (kp.getPublic() instanceof ECPublicKeyParameters) { - publicKey = new ECPublicKeyImpl((ECPublicKeyParameters) kp.getPublic()); - privateKey = new ECPrivateKeyImpl((ECPrivateKeyParameters) kp.getPrivate()); - } else { - CryptoException.throwIt(CryptoException.ILLEGAL_USE); - } + ((KeyWithParameters)publicKey).setParameters(kp.getPublic()); + ((KeyWithParameters)privateKey).setParameters(kp.getPrivate()); } /** @@ -138,9 +104,10 @@ public final void genKeyPair() * (example - * RSAPublicKey interface for the public key and * RSAPrivateKey interface for the private key within an - * ALG_RSA key pair).

    Notes:

    • The key objects + * ALG_RSA key pair). + *

      Notes:

      The key objects * encapsulated in the generated KeyPair object need - * not support the KeyEncryption interface.

    + * not support the KeyEncryption interface.

    * * @param algorithm the type of algorithm whose key pair needs to be * generated. Valid codes listed in ALG_.. constants above. @@ -153,14 +120,15 @@ public final void genKeyPair() * algorithm associated with the specified type, size of key is not * supported. * @see KeyBuilder - * @see Signature - * @see KeyEncryption - * @see Cipher + * @see javacard.security.Signature + * @see javacardx.crypto.KeyEncryption + * @see javacardx.crypto.Cipher */ public KeyPairImpl(byte algorithm, short keyLength) throws CryptoException { this.algorithm = algorithm; this.keyLength = keyLength; + createKeys(); } /** @@ -248,8 +216,9 @@ private void selectAlgorithmByType(byte keyType) { * Init key pair generation engine */ private void initEngine() { - if (publicKey != null || privateKey != null) { - keyGenerationParameters = ((KeyImpl) (privateKey == null ? publicKey : privateKey)).getKeyGenerationParameters(rnd); + // only public key params, see specification + if (publicKey != null) { + keyGenerationParameters = ((KeyImpl) publicKey).getKeyGenerationParameters(rnd); } switch (algorithm) { case KeyPair.ALG_RSA: @@ -286,4 +255,46 @@ private void initEngine() { engine.init(keyGenerationParameters); } + + /* + * Create uninitialized keys + */ + private void createKeys() { + byte privateKeyType = 0; + byte publicKeyType = 0; + switch (algorithm) { + case KeyPair.ALG_RSA: + publicKeyType = KeyBuilder.TYPE_RSA_PUBLIC; + privateKeyType = KeyBuilder.TYPE_RSA_PRIVATE; + break; + case KeyPair.ALG_RSA_CRT: + publicKeyType = KeyBuilder.TYPE_RSA_PUBLIC; + privateKeyType = KeyBuilder.TYPE_RSA_CRT_PRIVATE; + break; + case KeyPair.ALG_EC_FP: + publicKeyType = KeyBuilder.TYPE_EC_FP_PUBLIC; + privateKeyType = KeyBuilder.TYPE_EC_FP_PRIVATE; + break; + case KeyPair.ALG_EC_F2M: + publicKeyType = KeyBuilder.TYPE_EC_F2M_PUBLIC; + privateKeyType = KeyBuilder.TYPE_EC_F2M_PRIVATE; + break; + case KeyPair.ALG_DSA: + publicKeyType = KeyBuilder.TYPE_DSA_PUBLIC; + privateKeyType = KeyBuilder.TYPE_DSA_PRIVATE; + break; + default: + CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); + break; + } + if(publicKey!=null && keyLength == 0){ + keyLength = publicKey.getSize(); + } + if(publicKey == null){ + publicKey = (PublicKey) KeyBuilder.buildKey(publicKeyType, keyLength, false); + } + if(privateKey == null){ + privateKey = (PrivateKey) KeyBuilder.buildKey(privateKeyType, keyLength, false); + } + } } \ No newline at end of file diff --git a/src/main/java/com/licel/jcardsim/crypto/KeyWithParameters.java b/src/main/java/com/licel/jcardsim/crypto/KeyWithParameters.java index ab97b4a8..3e1489e5 100644 --- a/src/main/java/com/licel/jcardsim/crypto/KeyWithParameters.java +++ b/src/main/java/com/licel/jcardsim/crypto/KeyWithParameters.java @@ -20,7 +20,7 @@ import org.bouncycastle.crypto.KeyGenerationParameters; /** - * + * KeyWithParameters. */ public interface KeyWithParameters { @@ -33,9 +33,14 @@ public interface KeyWithParameters { /** * Get keypair generation parameters for use with BouncyCastle Crypto API - * + * @param rnd Secure Random Generator * @return key parameters */ public KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd); + /** + * Set cipher key for use with BouncyCastle Crypto API + * @param params key parameters + */ + public void setParameters(CipherParameters params); } diff --git a/src/main/java/com/licel/jcardsim/crypto/MessageDigestImpl.java b/src/main/java/com/licel/jcardsim/crypto/MessageDigestImpl.java index 02c9056b..0032e6f8 100644 --- a/src/main/java/com/licel/jcardsim/crypto/MessageDigestImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/MessageDigestImpl.java @@ -15,42 +15,80 @@ */ package com.licel.jcardsim.crypto; +import java.lang.reflect.Field; import javacard.security.CryptoException; +import javacard.security.InitializedMessageDigest; import javacard.security.MessageDigest; import org.bouncycastle.crypto.Digest; import org.bouncycastle.crypto.digests.MD5Digest; import org.bouncycastle.crypto.digests.RIPEMD160Digest; import org.bouncycastle.crypto.digests.SHA1Digest; +import org.bouncycastle.crypto.digests.SHA256Digest; +import org.bouncycastle.crypto.digests.SHA384Digest; +import org.bouncycastle.crypto.digests.SHA512Digest; +import org.bouncycastle.crypto.util.Pack; /** - * Implementation MessageDigest based - * on BouncyCastle CryptoAPI + * Implementation + * MessageDigest based + * on BouncyCastle CryptoAPI. * @see MessageDigest * @see MD5Digest * @see RIPEMD160Digest * @see SHA1Digest */ -public class MessageDigestImpl extends MessageDigest { +public class MessageDigestImpl extends InitializedMessageDigest { private Digest engine; private byte algorithm; + private short blockSize; + // internals BouncyCastle + private String byteCountFieldName = "byteCount"; + private Class digestClass; + private byte componentSize; + private byte componentCount; + private byte componentStartIdx; public MessageDigestImpl(byte algorithm) { this.algorithm = algorithm; + blockSize = 64; + componentStartIdx = 1; switch (algorithm) { case ALG_SHA: engine = new SHA1Digest(); + digestClass = engine.getClass(); break; case ALG_MD5: engine = new MD5Digest(); + digestClass = engine.getClass(); break; case ALG_RIPEMD160: engine = new RIPEMD160Digest(); + digestClass = engine.getClass(); + componentStartIdx = 0; + break; + case ALG_SHA_256: + engine = new SHA256Digest(); + digestClass = engine.getClass(); + break; + case ALG_SHA_384: + engine = new SHA384Digest(); + blockSize = 128; + byteCountFieldName = "byteCount1"; + digestClass = engine.getClass().getSuperclass(); + break; + case ALG_SHA_512: + engine = new SHA512Digest(); + blockSize = 128; + byteCountFieldName = "byteCount1"; + digestClass = engine.getClass().getSuperclass(); break; default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } + componentSize = (byte)(blockSize == 64 ? 4 : 8); + componentCount = (byte) (engine.getDigestSize() / componentSize); } public byte getAlgorithm() { @@ -74,4 +112,67 @@ public void update(byte inBuff[], short inOffset, short inLength) { public void reset() { engine.reset(); } + + public void setInitialDigest(byte[] initialDigestBuf, short initialDigestOffset, + short initialDigestLength, byte[] digestedMsgLenBuf, short digestedMsgLenOffset, + short digestedMsgLenLength) throws CryptoException { + // initialDigestLength must be == DIGEST_SIZE + if (engine.getDigestSize() != initialDigestLength) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } + // digestedMsgLenLength must be > 0 and < long value, more formal 2^64-1 bits + // TODO support length more 2^128-1 bits (SHA-384, SHA-512) + if (digestedMsgLenLength == 0 || digestedMsgLenLength > 8) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } + long byteCount = 0; + for (short i = 0; i < digestedMsgLenLength; i++) { + byteCount = (byteCount << 8) + (digestedMsgLenBuf[digestedMsgLenOffset + i] & 0xff); + } + // byte count % block size must be == 0 + if (byteCount % blockSize != 0) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } + // set hash state - BouncyCastle specific + try { + for (byte i = 0; i < componentCount; i++) { + // some reflection work + Field h = digestClass.getDeclaredField("H" + (i + componentStartIdx)); + h.setAccessible(true); + if (componentSize == 4) { + h.setInt(engine, Pack.bigEndianToInt(initialDigestBuf, initialDigestOffset + i * componentSize)); + } else { + h.setLong(engine, Pack.bigEndianToLong(initialDigestBuf, initialDigestOffset + i * componentSize)); + } + } + // set byteCount + Field h = digestClass.getSuperclass().getDeclaredField(byteCountFieldName); + h.setAccessible(true); + h.setLong(engine, byteCount); + } catch (Exception e) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } + } + + void getIntermediateDigest(byte[] intermediateDigest, int off) { + // get hash state - BouncyCastle specific + try { + for (byte i = 0; i < componentCount; i++) { + // some reflection work + Field h = digestClass.getDeclaredField("H" + (i + componentStartIdx)); + h.setAccessible(true); + if (componentSize == 4) { + Pack.intToBigEndian(h.getInt(engine), intermediateDigest, off + i * componentSize); + } else { + Pack.longToBigEndian(h.getLong(engine), intermediateDigest, off + i * componentSize); + } + } + } catch (Exception e) { + CryptoException.throwIt(CryptoException.ILLEGAL_USE); + } + } + + short getBlockSize(){ + return blockSize; + } } diff --git a/src/main/java/com/licel/jcardsim/crypto/RSAKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/RSAKeyImpl.java index 9921de6a..8eeb7ed7 100644 --- a/src/main/java/com/licel/jcardsim/crypto/RSAKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/RSAKeyImpl.java @@ -28,7 +28,7 @@ /** * Implementation - * RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI + * RSAPublic/RSAPrivate based on BouncyCastle CryptoAPI. * * @see RSAPrivateKey * @see RSAPublicKey @@ -57,14 +57,18 @@ public RSAKeyImpl(boolean isPrivate, short size) { * Construct and initialize rsa key with RSAKeyParameters. Use in * KeyPairImpl * - * @see KeyPair + * @see javacard.security.KeyPair * @see RSAKeyParameters * @param params key params from BouncyCastle API */ public RSAKeyImpl(RSAKeyParameters params) { this(params.isPrivate(), (short) params.getModulus().bitLength()); - modulus.setBigInteger(params.getModulus()); - exponent.setBigInteger(params.getExponent()); + setParameters(params); + } + + public void setParameters(CipherParameters params){ + modulus.setBigInteger(((RSAKeyParameters)params).getModulus()); + exponent.setBigInteger(((RSAKeyParameters)params).getExponent()); } public short getExponent(byte[] buffer, short offset) { diff --git a/src/main/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.java index ecfba0ff..fbc01af1 100644 --- a/src/main/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImpl.java @@ -24,7 +24,7 @@ /** * Implementation RSAPrivateCrtKey based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see RSAPrivateCrtKey * @see RSAPrivateCrtKeyParameters */ @@ -35,11 +35,10 @@ public class RSAPrivateCrtKeyImpl extends RSAKeyImpl implements RSAPrivateCrtKey protected ByteContainer dp1 = new ByteContainer(); protected ByteContainer dq1 = new ByteContainer(); protected ByteContainer pq = new ByteContainer(); - protected ByteContainer publicExponent = new ByteContainer(); /** * Construct not-initialized rsa private crt key - * @param size key size it bits (modulus size) + * @param keySize key size it bits (modulus size) * @see KeyBuilder */ public RSAPrivateCrtKeyImpl(short keySize) { @@ -50,25 +49,24 @@ public RSAPrivateCrtKeyImpl(short keySize) { /** * Construct and initialize rsa key with RSAPrivateCrtKeyParameters. * Use in KeyPairImpl - * @see KeyPair + * @see javacard.security.KeyPair * @see RSAPrivateCrtKeyParameters * @param params key params from BouncyCastle API */ public RSAPrivateCrtKeyImpl(RSAPrivateCrtKeyParameters params) { super(new RSAKeyParameters(true, params.getModulus(), params.getExponent())); type = KeyBuilder.TYPE_RSA_CRT_PRIVATE; - publicExponent.setBigInteger(params.getPublicExponent()); - p.setBigInteger(params.getP()); - q.setBigInteger(params.getQ()); - dp1.setBigInteger(params.getDP()); - dq1.setBigInteger(params.getDQ()); - pq.setBigInteger(params.getQInv()); + setParameters(params); } - public void setPublicExponent(byte[] buffer, short offset, short length) throws CryptoException { - publicExponent.setBytes(buffer, offset, length); + public void setParameters(CipherParameters params){ + p.setBigInteger(((RSAPrivateCrtKeyParameters)params).getP()); + q.setBigInteger(((RSAPrivateCrtKeyParameters)params).getQ()); + dp1.setBigInteger(((RSAPrivateCrtKeyParameters)params).getDP()); + dq1.setBigInteger(((RSAPrivateCrtKeyParameters)params).getDQ()); + pq.setBigInteger(((RSAPrivateCrtKeyParameters)params).getQInv()); } - + public void setP(byte[] buffer, short offset, short length) throws CryptoException { p.setBytes(buffer, offset, length); } @@ -111,7 +109,6 @@ public short getPQ(byte[] buffer, short offset) { public void clearKey() { super.clearKey(); - publicExponent.clear(); p.clear(); q.clear(); dp1.clear(); @@ -120,8 +117,8 @@ public void clearKey() { } public boolean isInitialized() { - return (super.isInitialized() && p.isInitialized() && q.isInitialized() - && publicExponent.isInitialized() && dp1.isInitialized() && dq1.isInitialized() + return (p.isInitialized() && q.isInitialized() + && dp1.isInitialized() && dq1.isInitialized() && pq.isInitialized()); } @@ -129,8 +126,9 @@ public CipherParameters getParameters() { if (!isInitialized()) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } - return new RSAPrivateCrtKeyParameters(modulus.getBigInteger(), publicExponent.getBigInteger(), - exponent.getBigInteger(), p.getBigInteger(), q.getBigInteger(), + // modulus = p * q; + return new RSAPrivateCrtKeyParameters(p.getBigInteger().multiply(q.getBigInteger()), null, + null, p.getBigInteger(), q.getBigInteger(), dp1.getBigInteger(), dq1.getBigInteger(), pq.getBigInteger()); } } diff --git a/src/main/java/com/licel/jcardsim/crypto/RandomDataImpl.java b/src/main/java/com/licel/jcardsim/crypto/RandomDataImpl.java index 5b778eb4..6d4bd96c 100644 --- a/src/main/java/com/licel/jcardsim/crypto/RandomDataImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/RandomDataImpl.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.framework.Util; import javacard.security.CryptoException; import javacard.security.RandomData; @@ -25,7 +24,7 @@ /** * Implementation RandomData based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see RandomData */ public class RandomDataImpl extends RandomData { @@ -41,7 +40,7 @@ public void generateData(byte[] buffer, short offset, short length) throws Crypt } public void setSeed(byte[] buffer, short offset, short length) { - byte[] seed = JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_RESET); + byte[] seed = new byte[length]; Util.arrayCopyNonAtomic(buffer, offset, seed, (short) 0, length); engine.addSeedMaterial(seed); } diff --git a/src/main/java/com/licel/jcardsim/crypto/SymmetricCipherImpl.java b/src/main/java/com/licel/jcardsim/crypto/SymmetricCipherImpl.java index 1ad2bcd3..f9a55c6c 100644 --- a/src/main/java/com/licel/jcardsim/crypto/SymmetricCipherImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/SymmetricCipherImpl.java @@ -30,7 +30,7 @@ /** * Implementation Cipher with symmetric keys based - * on BouncyCastle CryptoAPI + * on BouncyCastle CryptoAPI. * @see Cipher */ public class SymmetricCipherImpl extends Cipher { diff --git a/src/main/java/com/licel/jcardsim/crypto/SymmetricKeyImpl.java b/src/main/java/com/licel/jcardsim/crypto/SymmetricKeyImpl.java index 4cfa1177..67a35e7c 100644 --- a/src/main/java/com/licel/jcardsim/crypto/SymmetricKeyImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/SymmetricKeyImpl.java @@ -20,6 +20,7 @@ import javacard.security.AESKey; import javacard.security.CryptoException; import javacard.security.DESKey; +import javacard.security.HMACKey; import javacard.security.KeyBuilder; import org.bouncycastle.crypto.BlockCipher; import org.bouncycastle.crypto.CipherParameters; @@ -30,11 +31,11 @@ import org.bouncycastle.crypto.params.KeyParameter; /** - * Implementation of secret key + * Implementation of secret key. * @see DESKey * @see AESKey */ -public class SymmetricKeyImpl extends KeyImpl implements DESKey, AESKey { +public class SymmetricKeyImpl extends KeyImpl implements DESKey, AESKey, HMACKey { protected ByteContainer key; @@ -50,14 +51,17 @@ public SymmetricKeyImpl(byte keyType, short keySize) { switch (keyType) { case KeyBuilder.TYPE_DES_TRANSIENT_DESELECT: case KeyBuilder.TYPE_AES_TRANSIENT_DESELECT: + case KeyBuilder.TYPE_HMAC_TRANSIENT_DESELECT: key = new ByteContainer(JCSystem.MEMORY_TYPE_TRANSIENT_DESELECT); break; case KeyBuilder.TYPE_DES_TRANSIENT_RESET: case KeyBuilder.TYPE_AES_TRANSIENT_RESET: + case KeyBuilder.TYPE_HMAC_TRANSIENT_RESET: key = new ByteContainer(JCSystem.MEMORY_TYPE_TRANSIENT_RESET); break; case KeyBuilder.TYPE_DES: case KeyBuilder.TYPE_AES: + case KeyBuilder.TYPE_HMAC: key = new ByteContainer(JCSystem.MEMORY_TYPE_PERSISTENT); break; } @@ -77,6 +81,12 @@ public void setKey(byte[] keyData, short kOff) throws CryptoException, NullPoint key.setBytes(keyData, kOff, (short) (size / 8)); } + /** + * Sets the Key data. + */ + public void setKey(byte[] keyData, short kOff, short kLen) throws CryptoException, NullPointerException, ArrayIndexOutOfBoundsException { + key.setBytes(keyData, kOff, kLen); + } /** * Returns the Key data in plain text. */ @@ -84,6 +94,10 @@ public byte getKey(byte[] keyData, short kOff) { return (byte) key.getBytes(keyData, kOff); } + public void setParameters(CipherParameters params){ + key.setBytes(((KeyParameter)params).getKey()); + } + /** * Return the BouncyCastle KeyParameter of the key * @return parameter of the key @@ -99,7 +113,7 @@ public CipherParameters getParameters() throws CryptoException { /** * Return the BouncyCastle BlockCipher for using with this key - * @return BlockCipher for this key + * @return BlockCipher for this key, or null for HMACKey * @throws CryptoException if key not initialized * @see BlockCipher */ @@ -135,4 +149,5 @@ public boolean isInitialized() { public KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd) { return null; } + } diff --git a/src/main/java/com/licel/jcardsim/crypto/SymmetricSignatureImpl.java b/src/main/java/com/licel/jcardsim/crypto/SymmetricSignatureImpl.java index f418f575..e9b13a53 100644 --- a/src/main/java/com/licel/jcardsim/crypto/SymmetricSignatureImpl.java +++ b/src/main/java/com/licel/jcardsim/crypto/SymmetricSignatureImpl.java @@ -15,132 +15,149 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.framework.Util; import javacard.security.CryptoException; import javacard.security.Key; import javacard.security.Signature; +import org.bouncycastle.crypto.BlockCipher; +import org.bouncycastle.crypto.CipherParameters; import org.bouncycastle.crypto.Mac; +import org.bouncycastle.crypto.digests.MD5Digest; +import org.bouncycastle.crypto.digests.RIPEMD160Digest; +import org.bouncycastle.crypto.digests.SHA1Digest; +import org.bouncycastle.crypto.digests.SHA256Digest; +import org.bouncycastle.crypto.digests.SHA384Digest; +import org.bouncycastle.crypto.digests.SHA512Digest; +import org.bouncycastle.crypto.engines.DESEngine; import org.bouncycastle.crypto.macs.CBCBlockCipherMac; -import org.bouncycastle.crypto.paddings.BlockCipherPadding; +import org.bouncycastle.crypto.macs.HMac; +import org.bouncycastle.crypto.macs.ISO9797Alg3Mac; import org.bouncycastle.crypto.paddings.ISO7816d4Padding; import org.bouncycastle.crypto.paddings.PKCS7Padding; import org.bouncycastle.crypto.paddings.ZeroBytePadding; import org.bouncycastle.crypto.params.ParametersWithIV; /** - * Implementation Signature with symmetric keys based - * on BouncyCastle CryptoAPI + * Implementation + * Signature with symmetric keys based + * on BouncyCastle CryptoAPI. * @see Signature */ public class SymmetricSignatureImpl extends Signature { - + Mac engine; byte algorithm; boolean isInitialized; - BlockCipherPadding paddingEngine; - short macSize; - + public SymmetricSignatureImpl(byte algorithm) { this.algorithm = algorithm; + } + + public void init(Key theKey, byte theMode) throws CryptoException { + init(theKey, theMode, null, (short) 0, (short) 0); + } + + public void init(Key theKey, byte theMode, byte[] bArray, short bOff, short bLen) throws CryptoException { + if (theKey == null) { + CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); + } + if (!theKey.isInitialized()) { + CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); + } + if (!(theKey instanceof SymmetricKeyImpl)) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } + CipherParameters cipherParams = null; + BlockCipher cipher = ((SymmetricKeyImpl) theKey).getCipher(); + if (bArray == null) { + cipherParams = ((SymmetricKeyImpl) theKey).getParameters(); + } else { + if (bLen != cipher.getBlockSize()) { + CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); + } + cipherParams = new ParametersWithIV(((SymmetricKeyImpl) theKey).getParameters(), bArray, bOff, bLen); + } switch (algorithm) { case ALG_DES_MAC4_NOPAD: - macSize = 32; - paddingEngine = null; + engine = new CBCBlockCipherMac(cipher, 32, null); break; case ALG_DES_MAC8_NOPAD: - macSize = 64; - paddingEngine = null; + engine = new CBCBlockCipherMac(cipher, 64, null); break; case ALG_DES_MAC4_ISO9797_M1: - macSize = 32; - paddingEngine = new ZeroBytePadding(); + engine = new CBCBlockCipherMac(cipher, 32, new ZeroBytePadding()); break; case ALG_DES_MAC8_ISO9797_M1: - macSize = 64; - paddingEngine = new ZeroBytePadding(); + engine = new CBCBlockCipherMac(cipher, 64, new ZeroBytePadding()); break; case ALG_DES_MAC4_ISO9797_M2: - macSize = 32; - paddingEngine = new ISO7816d4Padding(); + engine = new CBCBlockCipherMac(cipher, 32, new ISO7816d4Padding()); break; case ALG_DES_MAC8_ISO9797_M2: - macSize = 64; - paddingEngine = new ISO7816d4Padding(); + engine = new CBCBlockCipherMac(cipher, 64, new ISO7816d4Padding()); + break; + case ALG_DES_MAC8_ISO9797_1_M2_ALG3: + engine = new ISO9797Alg3Mac(new DESEngine(), 64, new ISO7816d4Padding()); break; case ALG_DES_MAC4_PKCS5: - macSize = 32; - paddingEngine = new PKCS7Padding(); + engine = new CBCBlockCipherMac(cipher, 32, new PKCS7Padding()); break; case ALG_DES_MAC8_PKCS5: - macSize = 64; - paddingEngine = new PKCS7Padding(); + engine = new CBCBlockCipherMac(cipher, 64, new PKCS7Padding()); + break; + case ALG_AES_MAC_128_NOPAD: + engine = new CBCBlockCipherMac(cipher, 128, null); + break; + case ALG_HMAC_SHA1: + engine = new HMac(new SHA1Digest()); + break; + case ALG_HMAC_SHA_256: + engine = new HMac(new SHA256Digest()); + break; + case ALG_HMAC_SHA_384: + engine = new HMac(new SHA384Digest()); + break; + case ALG_HMAC_SHA_512: + engine = new HMac(new SHA512Digest()); + break; + case ALG_HMAC_MD5: + engine = new HMac(new MD5Digest()); + break; + case ALG_HMAC_RIPEMD160: + engine = new HMac(new RIPEMD160Digest()); break; default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } - } - - public void init(Key theKey, byte theMode) throws CryptoException { - if (theKey == null) { - CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); - } - if (!theKey.isInitialized()) { - CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); - } - if (!(theKey instanceof SymmetricKeyImpl)) { - CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); - } - SymmetricKeyImpl key = (SymmetricKeyImpl) theKey; - engine = new CBCBlockCipherMac(key.getCipher(), macSize, paddingEngine); - engine.init(key.getParameters()); - isInitialized = true; - } - - public void init(Key theKey, byte theMode, byte[] bArray, short bOff, short bLen) throws CryptoException { - if (theKey == null) { - CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); - } - if (!theKey.isInitialized()) { - CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); - } - if (!(theKey instanceof SymmetricKeyImpl)) { - CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); - } - if (bLen != 8) { - CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); - } - SymmetricKeyImpl key = (SymmetricKeyImpl) theKey; - engine = new CBCBlockCipherMac(key.getCipher(), macSize, paddingEngine); - engine.init(new ParametersWithIV(key.getParameters(), bArray, bOff, bLen)); + engine.init(cipherParams); isInitialized = true; } - + public short getLength() throws CryptoException { if (!isInitialized) { CryptoException.throwIt(CryptoException.INVALID_INIT); } return (short) engine.getMacSize(); } - + public byte getAlgorithm() { return algorithm; } - + public void update(byte[] inBuff, short inOffset, short inLength) throws CryptoException { if (!isInitialized) { CryptoException.throwIt(CryptoException.INVALID_INIT); } engine.update(inBuff, inOffset, inLength); } - + public short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset) throws CryptoException { if (!isInitialized) { CryptoException.throwIt(CryptoException.INVALID_INIT); } if ((algorithm == ALG_DES_MAC8_NOPAD || algorithm == ALG_DES_MAC4_NOPAD) - && ((inLength % 8) != 0)) { + && ((inLength % 8) != 0)) { CryptoException.throwIt(CryptoException.ILLEGAL_USE); } engine.update(inBuff, inOffset, inLength); @@ -148,19 +165,19 @@ public short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, engine.reset(); return processedBytes; } - + public boolean verify(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset, short sigLength) throws CryptoException { if (!isInitialized) { CryptoException.throwIt(CryptoException.INVALID_INIT); } if ((algorithm == ALG_DES_MAC8_NOPAD || algorithm == ALG_DES_MAC4_NOPAD) - && ((inLength % 8) != 0)) { + && ((inLength % 8) != 0)) { CryptoException.throwIt(CryptoException.ILLEGAL_USE); } engine.update(inBuff, inOffset, inLength); - byte[] sig = JCSystem.makeTransientByteArray((short) (macSize / 8), JCSystem.CLEAR_ON_RESET); + byte[] sig = new byte[getLength()]; engine.doFinal(sig, (short) 0); engine.reset(); return Util.arrayCompare(sig, (short) 0, sigBuff, sigOffset, (short) sig.length) == 0; } -} +} \ No newline at end of file diff --git a/src/main/java/com/licel/jcardsim/crypto/package-info.java b/src/main/java/com/licel/jcardsim/crypto/package-info.java new file mode 100644 index 00000000..8a4a69f7 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/crypto/package-info.java @@ -0,0 +1,4 @@ +/** + * jCardSim cryptography support classes. + */ +package com.licel.jcardsim.crypto; diff --git a/src/main/java/com/licel/jcardsim/io/CAD.java b/src/main/java/com/licel/jcardsim/io/CAD.java new file mode 100644 index 00000000..a1785f55 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/io/CAD.java @@ -0,0 +1,63 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.io; + +import com.licel.jcardsim.base.Simulator; +import com.licel.jcardsim.remote.JavaCardRemoteClient; +import java.util.Properties; + +/** + * Card Acceptance Device (CAD). + * + * @author LICEL LLC + */ +public class CAD { + + public final static byte INTERNAL = 0; + public final static byte RMI = 1; + public final static byte JAVAX_SMARTCARDIO = 2; + byte interfaceType; + CardInterface cardInterface; + + public CAD(Properties params) { + byte type = Byte.parseByte(params.getProperty("com.licel.jcardsim.terminal.type", Byte.toString(INTERNAL))); + switch (type) { + case INTERNAL: + cardInterface = new Simulator(); + break; + case RMI: + try { + String host = params.getProperty("com.licel.jcardsim.terminal.host"); + int port = Integer.parseInt(params.getProperty("com.licel.jcardsim.terminal.port")); + cardInterface = new JavaCardRemoteClient(host, port); + } catch (Exception e) { + throw new RuntimeException("RMI CardInterface init error", e); + } + break; + case JAVAX_SMARTCARDIO: + cardInterface = new JavaxSmartCardInterface(); + break; + default: + throw new IllegalArgumentException("Unknown CAD type: " + type); + } + this.interfaceType = type; + + } + + public CardInterface getCardInterface() { + return cardInterface; + } +} diff --git a/src/main/java/com/licel/jcardsim/io/CardInterface.java b/src/main/java/com/licel/jcardsim/io/CardInterface.java new file mode 100644 index 00000000..eaf0cef7 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/io/CardInterface.java @@ -0,0 +1,48 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.io; + +/** + * Basic SmartCard Interface. + * + * @author LICEL LLC + */ +public interface CardInterface { + + /** + * Powerdown/Powerup + */ + public void reset(); + + /** + * Returns ATR + * @return ATR bytes + */ + public byte[] getATR(); + + /** + * Transmit APDU to previous selected applet + * + * If no applet was selected returns byte[2] + * with status word 0x6986 (Command not allowed (no current EF)) + * + * @param commandAPDU command apdu + * @return response APDU + * @see javax.smartcardio.CommandAPDU + * @see javax.smartcardio.ResponseAPDU + */ + public byte[] transmitCommand(byte[] commandAPDU); +} diff --git a/src/main/java/com/licel/jcardsim/io/JavaCardInterface.java b/src/main/java/com/licel/jcardsim/io/JavaCardInterface.java new file mode 100644 index 00000000..941dc66e --- /dev/null +++ b/src/main/java/com/licel/jcardsim/io/JavaCardInterface.java @@ -0,0 +1,146 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.io; + +import javacard.framework.AID; +import javacard.framework.SystemException; + +/** + * Interface with JavaCard-specific functions. + * @author LICEL LLC + */ +public interface JavaCardInterface extends CardInterface { + + /** + * Load + * Applet into Simulator + * + * @param aid applet aid + * @param appletClassName fully qualified applet class name Strin + * @param appletJarContents contains a byte array containing a jar file with an applet and its dependent classes + * @return applet AID + * @throws SystemException if appletClass not instanceof + * javacard.framework.Applet + */ + public AID loadApplet(AID aid, String appletClassName, byte[] appletJarContents) throws SystemException; + + /** + * Load + * Applet into Simulator + * + * @param aid applet aid + * @param appletClassName fully qualified applet class name String + * @return applet AID + * @throws SystemException if appletClass not instanceof + * javacard.framework.Applet + */ + public AID loadApplet(AID aid, String appletClassName); + + /** + * Create + * Applet instance in Simulator + * @param aid applet aid + * @param bArray the array containing installation parameters + * @param bOffset the starting offset in bArray + * @param bLength the length in bytes of the parameter data in bArray + * @return applet AID + * @throws SystemException if exception in Applet.install(..) + * method occurs. + */ + public AID createApplet(AID aid, byte bArray[], short bOffset, + byte bLength) throws SystemException; + + /** + * Install + * Applet into Simulator. + * This method is equal to: + * + * loadApplet(...); + * createApplet(...); + * + * @param aid applet aid or null + * @param appletClassName fully qualified applet class name Strin + * @param bArray the array containing installation parameters + * @param bOffset the starting offset in bArray + * @param bLength the length in bytes of the parameter data in bArray + * @return applet AID + * @throws SystemException if appletClass not instanceof + * javacard.framework.Applet + */ + public AID installApplet(AID aid, String appletClassName, byte bArray[], short bOffset, + byte bLength) throws SystemException; + + /** + * Install + * Applet into Simulator. + * This method is equal to: + * + * loadApplet(...); + * createApplet(...); + * + * @param aid applet aid or null + * @param appletClassName fully qualified applet class name Strin + * @param appletJarContents Contains a byte array containing a jar file with an applet and its dependent classes + * @param bArray the array containing installation parameters + * @param bOffset the starting offset in bArray + * @param bLength the length in bytes of the parameter data in bArray + * @return applet AID + * @throws SystemException if appletClass not instanceof + * javacard.framework.Applet + */ + public AID installApplet(AID aid, String appletClassName, byte[] appletJarContents, byte bArray[], short bOffset, + byte bLength) throws SystemException; + + /** + * Select applet by it's AID + * It's method must be called before start working with applet instance + * @param aid appletId + * @return true if applet selection success + */ + public boolean selectApplet(AID aid); + + /** + * Select applet by it's AID + * It's method must be called before start working with applet instance + * @param aid appletId + * @return byte array + */ + public byte[] selectAppletWithResult(AID aid); + + /** + * Switch protocol + * + * Supported protocols are: + *
      + *
    • T=0 (alias: *)
    • + *
    • T=1
    • + *
    • T=CL, TYPE_A, T0 (alias: T=CL)
    • + *
    • T=CL, TYPE_A, T1
    • + *
    • T=CL, TYPE_B, T0
    • + *
    • T=CL, TYPE_B, T1
    • + *
    + * + * @param protocol protocol to use + * @throws java.lang.IllegalArgumentException for unknown protocols + */ + public void changeProtocol(String protocol); + + /** + * @return the current protocol string + * @see #changeProtocol(String) + */ + public String getProtocol(); +} diff --git a/src/main/java/com/licel/jcardsim/io/JavaxSmartCardInterface.java b/src/main/java/com/licel/jcardsim/io/JavaxSmartCardInterface.java new file mode 100644 index 00000000..34af76fc --- /dev/null +++ b/src/main/java/com/licel/jcardsim/io/JavaxSmartCardInterface.java @@ -0,0 +1,65 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.io; + +import com.licel.jcardsim.base.Simulator; +import com.licel.jcardsim.base.SimulatorRuntime; + +import javax.smartcardio.CommandAPDU; +import javax.smartcardio.ResponseAPDU; + +/** + * Simulator with javacardx.smartcardio Command/Response support. + * + * NOTE: New code should use {@link com.licel.jcardsim.smartcardio.CardSimulator} instead. + */ +public class JavaxSmartCardInterface extends Simulator { + /** + * Create a JavaxSmartCardInterface object using the default SimulatorRuntime. + * + *
      + *
    • All JavaxSmartCardInterface instances share one SimulatorRuntime.
    • + *
    • SimulatorRuntime#resetRuntime is called
    • + *
    • If your want multiple independent simulators use JavaxSmartCardInterface(SimulatorRuntime)
    • + *
    + */ + public JavaxSmartCardInterface() { + super(); + } + + /** + * Create a JavaxSmartCardInterface object using a provided Runtime. + * + *
      + *
    • SimulatorRuntime#resetRuntime is called
    • + *
    + * + * @param runtime SimulatorRuntime instance to use + * @throws java.lang.NullPointerException if runtime is null + */ + public JavaxSmartCardInterface(SimulatorRuntime runtime) { + super(runtime); + } + + /** + * Wrapper for transmitCommand(byte[]) + * @param commandApdu CommandAPDU + * @return ResponseAPDU + */ + public ResponseAPDU transmitCommand(CommandAPDU commandApdu) { + return new ResponseAPDU(transmitCommand(commandApdu.getBytes())); + } +} diff --git a/src/main/java/com/licel/jcardsim/io/package-info.java b/src/main/java/com/licel/jcardsim/io/package-info.java new file mode 100644 index 00000000..36e9cd13 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/io/package-info.java @@ -0,0 +1,4 @@ +/** + * jCardSim I/O support classes. + */ +package com.licel.jcardsim.io; diff --git a/src/main/java/com/licel/jcardsim/remote/BixVReaderCard.java b/src/main/java/com/licel/jcardsim/remote/BixVReaderCard.java new file mode 100644 index 00000000..9dfe98f5 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/BixVReaderCard.java @@ -0,0 +1,129 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.remote; + +import com.licel.jcardsim.base.CardManager; +import com.licel.jcardsim.base.Simulator; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Properties; + +/** + * BixVReader Card Implementation. + * + * @author LICEL LLC + */ +public class BixVReaderCard { + + Simulator sim; + + public BixVReaderCard(int idx) throws IOException { + sim = new Simulator(); + BixVReaderIPCProtocol driverProtocol = new BixVReaderIPCProtocol(); + driverProtocol.connect(idx); + final IOThread ioThread = new IOThread(sim, driverProtocol); + ShutDownHook hook = new ShutDownHook(ioThread); + Runtime.getRuntime().addShutdownHook(hook); + ioThread.start(); + driverProtocol.writeEventCommand(BixVReaderIPCProtocol.CARD_INSERTED); + } + + static public void main(String args[]) throws Exception { + if (args.length !=1) { + System.out.println("Usage: java com.licel.jcardsim.remote.BixVReaderCard "); + System.exit(-1); + } + Properties cfg = new Properties(); + // init Simulator + FileInputStream fis = null; + try { + fis = new FileInputStream(args[0]); + cfg.load(fis); + } catch (Throwable t) { + System.err.println("Unable to load configuration " + args[0] + " due to: " + t.getMessage()); + System.exit(-1); + } finally { + if (fis != null) { + fis.close(); + } + } + + Enumeration keys = cfg.propertyNames(); + while(keys.hasMoreElements()) { + String propertyName = (String) keys.nextElement(); + System.setProperty(propertyName, cfg.getProperty(propertyName)); + } + + int readerIdx = Integer.parseInt(System.getProperty("com.licel.jcardsim.bixvreader.idx", "0")); + + BixVReaderCard server = new BixVReaderCard(readerIdx); + } + + + static class ShutDownHook extends Thread { + + IOThread ioThread; + + public ShutDownHook(IOThread ioThread) { + this.ioThread = ioThread; + } + + public void run() { + ioThread.isRunning = false; + System.out.println("Shutdown connections"); + try { + ioThread.driverProtocol.writeEventCommand(BixVReaderIPCProtocol.CARD_REMOVED); + } catch (Exception ignored) { + } + ioThread.driverProtocol.disconnect(); + } + } + + + static class IOThread extends Thread { + + BixVReaderIPCProtocol driverProtocol; + Simulator sim; + boolean isRunning; + + public IOThread(Simulator sim, BixVReaderIPCProtocol driverProtocol) { + this.sim = sim; + this.driverProtocol = driverProtocol; + isRunning = true; + } + + @Override + public void run() { + while (isRunning) { + try { + int cmd = driverProtocol.readCommand(); + switch (cmd) { + case 0: + case 1: + driverProtocol.writeData(sim.getATR()); + break; + case 2: + byte[] apdu = driverProtocol.readData(); + driverProtocol.writeData(CardManager.dispatchApdu(sim, apdu)); + break; + } + } catch (Exception e) {} + } + } + } + +} diff --git a/src/main/java/com/licel/jcardsim/remote/BixVReaderIPCProtocol.java b/src/main/java/com/licel/jcardsim/remote/BixVReaderIPCProtocol.java new file mode 100644 index 00000000..1dc78ca6 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/BixVReaderIPCProtocol.java @@ -0,0 +1,105 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.remote; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * Client protocol impl (BixVReader (IPC)). + * + * See http://www.codeproject.com/Articles/134010/An-UMDF-Driver-for-a-Virtual-Smart-Card-Reader + * + * @author LICEL LLC + */ +public class BixVReaderIPCProtocol { + + public final static int CARD_INSERTED = 1; + public final static int ATR_REQUEST = 1; + public final static int TRANSMIT_DATA = 2; + public final static int RESET = 0; + public final static int CARD_REMOVED = 0; + RandomAccessFile dataPipe = null; + RandomAccessFile eventsPipe = null; + + public void connect(int readerIdx) throws FileNotFoundException { + dataPipe = new RandomAccessFile("\\\\.\\pipe\\SCardSimulatorDriver" + readerIdx, "rws"); + eventsPipe = new RandomAccessFile("\\\\.\\pipe\\SCardSimulatorDriverEvents" + readerIdx, "rws"); + } + + public void disconnect() { + closePipe(dataPipe); + closePipe(eventsPipe); + } + + public int readCommand() throws IOException { + byte[] cmdBuf = new byte[4]; + dataPipe.readFully(cmdBuf); + int cmd = cmdFromBytes(cmdBuf); + return cmd; + } + + public void writeDataCommand(int cmd) throws IOException { + writeCommand(dataPipe, cmd); + } + + public void writeEventCommand(int cmd) throws IOException { + writeCommand(eventsPipe, cmd); + } + + public byte[] readData() throws IOException { + int dataLen = readCommand(); + byte[] dataBuf = new byte[dataLen]; + dataPipe.readFully(dataBuf); + return dataBuf; + } + + public void writeData(byte[] data) throws IOException { + byte[] dataBuf = new byte[4 + data.length]; + byte[] dataLen = cmdToBytes(data.length); + System.arraycopy(dataLen, 0, dataBuf, 0, 4); + System.arraycopy(data, 0, dataBuf, 4, data.length); + dataPipe.write(dataBuf); + } + + private byte[] cmdToBytes(int cmd) { + return new byte[]{ + (byte) (cmd), + (byte) (cmd >>> 8), + (byte) (cmd >>> 16), + (byte) (cmd >>> 24)}; + } + + private int cmdFromBytes(byte[] cmd) { + return cmd[0] & 0xFF + | (cmd[1] & 0xFF) << 8 + | (cmd[2] & 0xFF) << 16 + | (cmd[3] & 0xFF) << 24; + } + + private void writeCommand(RandomAccessFile pipe, int cmd) throws IOException { + pipe.write(cmdToBytes(cmd)); + } + + private void closePipe(RandomAccessFile pipe) { + try { + pipe.close(); + } catch (IOException ignored) { + } + } +} diff --git a/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteClient.java b/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteClient.java new file mode 100644 index 00000000..df3fdc23 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteClient.java @@ -0,0 +1,147 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.remote; + +import com.licel.jcardsim.io.JavaCardInterface; +import java.rmi.NotBoundException; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import javacard.framework.AID; +import javacard.framework.SystemException; + +/** + * RMI client. + * + * @author LICEL LLC + */ +public class JavaCardRemoteClient implements JavaCardInterface { + + JavaCardRemoteInterface remote; + + public JavaCardRemoteClient(String serverHost, int serverIp) throws RemoteException, NotBoundException { + Registry registry = LocateRegistry.getRegistry(serverHost, serverIp); + remote = (JavaCardRemoteInterface) (registry.lookup(JavaCardRemoteInterface.RMI_SERVER_ID)); + } + + public AID loadApplet(AID aid, String appletClassName) throws SystemException { + try { + return remote.loadApplet(new SerializableAID(aid), appletClassName).getAID(); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } + + public AID loadApplet(AID aid, String appletClassName, byte[] appletJarContents) throws SystemException { + try { + return remote.loadApplet(new SerializableAID(aid), appletClassName, appletJarContents).getAID(); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } + + public AID createApplet(AID aid, byte[] bArray, short bOffset, byte bLength) throws SystemException { + try { + return remote.createApplet(new SerializableAID(aid), bArray, bOffset, bLength).getAID(); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } + + public AID installApplet(AID aid, String appletClassName, byte[] bArray, short bOffset, byte bLength) throws SystemException { + return createApplet(loadApplet(aid, appletClassName), bArray, bOffset, bLength); + } + + public AID installApplet(AID aid, String appletClassName, byte[] appletJarContents, byte[] bArray, short bOffset, byte bLength) throws SystemException { + return createApplet(loadApplet(aid, appletClassName), bArray, bOffset, bLength); + } + + public boolean selectApplet(AID aid) { + try { + return remote.selectApplet(new SerializableAID(aid)); + } catch (RemoteException e) { + handleRemoteException(e); + } + return false; + } + + public byte[] getATR() { + try { + return remote.getATR(); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } + + public byte[] transmitCommand(byte[] data) { + try { + return remote.transmitCommand(data); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } + + public void reset() { + try { + remote.reset(); + } catch (RemoteException e) { + handleRemoteException(e); + } + } + + private void handleRemoteException(RemoteException e) { + if (e.getCause() instanceof SystemException) { + throw (SystemException) e.getCause(); + } + else if (e.getCause() instanceof IllegalArgumentException) { + throw (IllegalArgumentException) e.getCause(); + } + else { + SystemException.throwIt(SystemException.NO_RESOURCE); + } + } + + public byte[] selectAppletWithResult(AID aid) { + try { + return remote.selectAppletWithResult(new SerializableAID(aid)); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } + + public void changeProtocol(String protocol) { + try { + remote.changeProtocol(protocol); + } catch (RemoteException e) { + handleRemoteException(e); + } + } + + public String getProtocol() { + try { + return remote.getProtocol(); + } catch (RemoteException e) { + handleRemoteException(e); + } + return null; + } +} diff --git a/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteInterface.java b/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteInterface.java new file mode 100644 index 00000000..050ad46e --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteInterface.java @@ -0,0 +1,49 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.remote; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * RMI Wrapper for the JavaCardInterface. + * + * @author LICEL LLC + */ +public interface JavaCardRemoteInterface extends Remote { + + public String RMI_SERVER_ID = "jCardSim.rmiServer"; + + public SerializableAID loadApplet(SerializableAID aid, String appletClassName) throws RemoteException; + + public SerializableAID loadApplet(SerializableAID aid, String appletClassName, byte[] appletJarContents) throws RemoteException; + + public SerializableAID createApplet(SerializableAID aid, byte[] bArray, short bOffset, byte bLength) throws RemoteException; + + public byte[] transmitCommand(byte[] data) throws RemoteException; + + public boolean selectApplet(SerializableAID aid) throws RemoteException; + + public byte[] selectAppletWithResult(SerializableAID aid) throws RemoteException; + + public void reset() throws RemoteException; + + public byte[] getATR() throws RemoteException; + + public void changeProtocol(String protocol) throws RemoteException; + + public String getProtocol() throws RemoteException; +} diff --git a/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteServer.java b/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteServer.java new file mode 100644 index 00000000..6c4962d0 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/JavaCardRemoteServer.java @@ -0,0 +1,154 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.remote; + +import com.licel.jcardsim.base.Simulator; +import com.licel.jcardsim.base.SimulatorRuntime; + +import java.io.FileInputStream; +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.util.Enumeration; +import java.util.Properties; + +/** + * RMI Server. + * @author LICEL LLC + */ +public class JavaCardRemoteServer extends java.rmi.server.UnicastRemoteObject + implements JavaCardRemoteInterface { + + protected final Simulator sim; + + public JavaCardRemoteServer(String host, int port) throws RemoteException { + sim = new Simulator(new SimulatorRuntime()); + System.setProperty("java.rmi.server.hostname", host); + Registry registry = LocateRegistry.createRegistry(port); + registry.rebind(RMI_SERVER_ID, this); + } + + static public void main(String args[]) throws Exception { + if (args.length !=1) { + System.out.println("Usage: java com.licel.jcardsim.remote.JavaCardRemoteServer "); + System.exit(-1); + } + Properties cfg = new Properties(); + // init Simulator + FileInputStream fis = null; + try { + fis = new FileInputStream(args[0]); + cfg.load(fis); + } catch (Throwable t) { + System.err.println("Unable to load configuration " + args[0] + " due to: " + t.getMessage()); + System.exit(-1); + } finally { + if (fis != null) { + fis.close(); + } + } + + Enumeration keys = cfg.propertyNames(); + while(keys.hasMoreElements()) { + String propertyName = (String) keys.nextElement(); + System.setProperty(propertyName, cfg.getProperty(propertyName)); + } + + String serverHost = System.getProperty("com.licel.jcardsim.terminal.host"); + if(serverHost == null) { + System.err.println("Invalid configuration: missing 'com.licel.jcardsim.terminal.host' property"); + System.exit(-1); + } + String serverPort = System.getProperty("com.licel.jcardsim.terminal.port"); + if(serverPort == null) { + System.err.println("Invalid configuration: missing 'com.licel.jcardsim.terminal.port' property"); + System.exit(-1); + } + + new JavaCardRemoteServer(serverHost, Integer.parseInt(serverPort)); + } + + /** + * Implementation + */ + public SerializableAID loadApplet(SerializableAID aid, String appletClassName) throws RemoteException { + return new SerializableAID(sim.loadApplet(aid.getAID(), appletClassName)); + } + + /** + * Implementation + */ + public SerializableAID loadApplet(SerializableAID aid, String appletClassName, byte[] appletJarContents) throws RemoteException { + return new SerializableAID(sim.loadApplet(aid.getAID(), appletClassName, appletJarContents)); + } + + /** + * Implementation + */ + public SerializableAID createApplet(SerializableAID aid, byte[] bArray, short bOffset, byte bLength) throws RemoteException { + return new SerializableAID(sim.createApplet(aid.getAID(), bArray, bOffset, bLength)); + } + + /** + * Implementation + */ + public byte[] transmitCommand(byte[] data) throws RemoteException { + return sim.transmitCommand(data); + } + + /** + * Implementation + */ + public boolean selectApplet(SerializableAID aid) throws RemoteException { + return sim.selectApplet(aid.getAID()); + } + + + /** + * Implementation + */ + public void reset() throws RemoteException { + sim.reset(); + } + + /** + * Implementation + */ + public byte[] getATR() throws RemoteException { + return sim.getATR(); + } + + /** + * Implementation + */ + public void changeProtocol(String protocol) throws RemoteException { + sim.changeProtocol(protocol); + } + + /** + * Implementation + */ + public String getProtocol() throws RemoteException { + return sim.getProtocol(); + } + + /** + * Implementation + */ + public byte[] selectAppletWithResult(SerializableAID aid) throws RemoteException { + return sim.selectAppletWithResult(aid.getAID()); + } +} diff --git a/src/main/java/com/licel/jcardsim/remote/SerializableAID.java b/src/main/java/com/licel/jcardsim/remote/SerializableAID.java new file mode 100644 index 00000000..4b1a1848 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/SerializableAID.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.remote; + +import java.io.Serializable; +import javacard.framework.AID; + +/** + * Serializable AID container for the RMI calls. + * + * @author LICEL LLC + */ +public class SerializableAID implements Serializable { + + byte[] aidBytes = new byte[16]; + byte aidLen = 0; + + public SerializableAID() { + } + + public SerializableAID(AID aid) { + aidLen = aid.getBytes(aidBytes, (short) 0); + } + + public AID getAID() { + if (aidLen == 0) { + throw new IllegalArgumentException("Aid length == 0"); + } + return new AID(aidBytes, (short) 0, aidLen); + } +} diff --git a/src/main/java/com/licel/jcardsim/remote/package-info.java b/src/main/java/com/licel/jcardsim/remote/package-info.java new file mode 100644 index 00000000..3a9d9a5a --- /dev/null +++ b/src/main/java/com/licel/jcardsim/remote/package-info.java @@ -0,0 +1,4 @@ +/** + * jCardSim remoting support classes. + */ +package com.licel.jcardsim.remote; diff --git a/src/main/java/java/rmi/Remote.java b/src/main/java/com/licel/jcardsim/samples/BaseApplet.java similarity index 74% rename from src/main/java/java/rmi/Remote.java rename to src/main/java/com/licel/jcardsim/samples/BaseApplet.java index de6b294f..4819ccb4 100644 --- a/src/main/java/java/rmi/Remote.java +++ b/src/main/java/com/licel/jcardsim/samples/BaseApplet.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 Licel LLC. + * Copyright 2014 Licel LLC. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,8 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +package com.licel.jcardsim.samples; -package java.rmi; +import javacard.framework.Applet; -public interface Remote { +/** + * Base class. + * @author LICEL LLC + */ + +public abstract class BaseApplet extends Applet { + } diff --git a/src/main/java/com/licel/jcardsim/samples/DualInterfaceApplet.java b/src/main/java/com/licel/jcardsim/samples/DualInterfaceApplet.java new file mode 100644 index 00000000..9300921e --- /dev/null +++ b/src/main/java/com/licel/jcardsim/samples/DualInterfaceApplet.java @@ -0,0 +1,105 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.samples; + +import javacard.framework.*; + + +/** + * Dual interface applet. + * + *

    Supported APDUs:

    + * + *
      + *
    • CLA=0x80 INS=0 read value
    • + *
    • + * CLA=0x80 INS=2 store value from CData. + * Only works on contacted interface + *
    • + *
    • CLA=0x80 INS=4 get interface information (protocol byte)
    • + *
    + */ +public class DualInterfaceApplet extends BaseApplet { + private static final byte CLA = (byte) 0x80; + private static final byte INS_READ = 0; + private static final byte INS_WRITE = 2; + private static final byte INS_INFO = 4; + + private static final byte CLA_MASK = (byte) 0xF0; + + private static final byte _0 = 0; + private static final byte _1 = 1; + + private final byte[] store; + private short storeLen = 0; + + public static void install(byte[] bArray, short bOffset, byte bLength) { + new DualInterfaceApplet().register(); + } + + protected DualInterfaceApplet() { + store = new byte[255]; + } + + public void process(APDU apdu) { + byte[] buffer = apdu.getBuffer(); + + final short readCount = apdu.setIncomingAndReceive(); + final short lc = apdu.getIncomingLength(); + final short offsetCData = apdu.getOffsetCdata(); + short read = readCount; + while(read < lc) { + read += apdu.receiveBytes(read); + } + + if (selectingApplet()) { + return; + } + + if ((buffer[ISO7816.OFFSET_CLA] & CLA_MASK) != CLA) { + ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); + } + + switch (buffer[ISO7816.OFFSET_INS]) { + case INS_READ: { + Util.arrayCopyNonAtomic(store, _0, buffer, _0, storeLen); + apdu.setOutgoingAndSend(_0, storeLen); + break; + } + case INS_WRITE: { + if (isContacted()) { + storeLen = lc; + Util.arrayCopyNonAtomic(buffer, offsetCData, store, _0, storeLen); + } + else { + ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED); + } + break; + } + case INS_INFO: { + buffer[0] = APDU.getProtocol(); + apdu.setOutgoingAndSend(_0, (short) 1); + break; + } + default: + ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); + } + } + + public boolean isContacted() { + return APDU.getProtocol() == APDU.PROTOCOL_T0 || APDU.getProtocol() == APDU.PROTOCOL_T1; + } +} diff --git a/src/main/java/com/licel/jcardsim/samples/HelloWorldApplet.java b/src/main/java/com/licel/jcardsim/samples/HelloWorldApplet.java index d11a791a..39ff47e3 100644 --- a/src/main/java/com/licel/jcardsim/samples/HelloWorldApplet.java +++ b/src/main/java/com/licel/jcardsim/samples/HelloWorldApplet.java @@ -18,10 +18,10 @@ import javacard.framework.*; /** - * Basic HelloWorld JavaCard Applet + * Basic HelloWorld JavaCard Applet. * @author LICEL LLC */ -public class HelloWorldApplet extends Applet { +public class HelloWorldApplet extends BaseApplet { /** * Instruction: say hello @@ -39,6 +39,22 @@ public class HelloWorldApplet extends Applet { * Instruction: NOP */ private final static byte NOP_INS = (byte) 0x02; + /** + * Instruction: queue data and return 61xx + */ + private final static byte SAY_CONTINUE_INS = (byte) 0x06; + /** + * Instruction: CKYListObjects (http://pki.fedoraproject.org/images/7/7a/CoolKeyApplet.pdf 2.6.17) + */ + private final static byte LIST_OBJECTS_INS = (byte) 0x58; + /** + * Instruction: "Hello Java Card world!" + Application Specific SW 9XYZ + */ + private final static byte APPLICATION_SPECIFIC_SW_INS = (byte) 0x7; + /** + * Instruction: return maximum data. + */ + private final static byte MAXIMUM_DATA_INS = (byte) 0x8; /** * Byte array representing "Hello Java Card world!" string. */ @@ -49,10 +65,14 @@ public class HelloWorldApplet extends Applet { private byte[] echoBytes; private byte[] initParamsBytes; + private final byte[] transientMemory; private static final short LENGTH_ECHO_BYTES = 256; /** * Only this class's install method should create the applet object. + * @param bArray the array containing installation parameters + * @param bOffset the starting offset in bArray + * @param bLength the length in bytes of the parameter data in bArray */ protected HelloWorldApplet(byte[] bArray, short bOffset, byte bLength) { echoBytes = new byte[LENGTH_ECHO_BYTES]; @@ -65,15 +85,16 @@ protected HelloWorldApplet(byte[] bArray, short bOffset, byte bLength) { initParamsBytes = new byte[aLen]; Util.arrayCopyNonAtomic(bArray, (short) (bOffset + 1), initParamsBytes, (short) 0, aLen); } + transientMemory = JCSystem.makeTransientByteArray(LENGTH_ECHO_BYTES, JCSystem.CLEAR_ON_RESET); register(); } /** * This method is called once during applet instantiation process. - * @param bArray - * @param bOffset - * @param bLength - * @throws ISOException + * @param bArray the array containing installation parameters + * @param bOffset the starting offset in bArray + * @param bLength the length in bytes of the parameter data in bArray + * @throws ISOException if the install method failed */ public static void install(byte[] bArray, short bOffset, byte bLength) throws ISOException { @@ -90,7 +111,7 @@ public void process(APDU apdu) { // Now determine the requested instruction: switch (buffer[ISO7816.OFFSET_INS]) { case SAY_HELLO_INS: - sayHello(apdu); + sayHello(apdu, (short)0x9000); return; case SAY_ECHO2_INS: sayEcho2(apdu); @@ -98,40 +119,57 @@ public void process(APDU apdu) { case SAY_IPARAMS_INS: sayIParams(apdu); return; + case SAY_CONTINUE_INS: + sayContinue(apdu); + return; + case LIST_OBJECTS_INS: + listObjects(apdu); + return; + case APPLICATION_SPECIFIC_SW_INS: + sayHello(apdu, (short)0x9B00); + return; + case MAXIMUM_DATA_INS: + maximumData(apdu); + return; case NOP_INS: return; default: // We do not support any other INS values ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); } - return; } /** * Sends hello message to host using given APDU. * * @param apdu APDU that requested hello message + * @param sw response sw code */ - private void sayHello(APDU apdu) { + private void sayHello(APDU apdu, short sw) { // Here all bytes of the APDU are stored byte[] buffer = apdu.getBuffer(); // receive all bytes // if P1 = 0x01 (echo) short incomeBytes = apdu.setIncomingAndReceive(); - byte[] echo; + byte[] echo = transientMemory; + short echoLength; if (buffer[ISO7816.OFFSET_P1] == 0x01) { - echo = JCSystem.makeTransientByteArray(incomeBytes, JCSystem.CLEAR_ON_RESET); + echoLength = incomeBytes; Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echo, (short) 0, incomeBytes); } else { - echo = JCSystem.makeTransientByteArray((short) helloMessage.length, JCSystem.CLEAR_ON_RESET); + echoLength = (short) helloMessage.length; Util.arrayCopyNonAtomic(helloMessage, (short) 0, echo, (short) 0, (short) helloMessage.length); } // Tell JVM that we will send data apdu.setOutgoing(); // Set the length of data to send - apdu.setOutgoingLength((short) echo.length); + apdu.setOutgoingLength(echoLength); // Send our message starting at 0 position - apdu.sendBytesLong(echo, (short) 0, (short) echo.length); + apdu.sendBytesLong(echo, (short) 0, echoLength); + // Set application specific sw + if(sw!=0x9000) { + ISOException.throwIt(sw); + } } @@ -151,7 +189,7 @@ private void sayEcho2(APDU apdu) { } apdu.setOutgoing(); - apdu.setOutgoingLength((short) echoOffset); + apdu.setOutgoingLength(echoOffset); // echo data apdu.sendBytesLong(echoBytes, (short) 0, echoOffset); @@ -167,4 +205,47 @@ private void sayIParams(APDU apdu) { apdu.sendBytesLong(initParamsBytes, (short) 0, (short)initParamsBytes.length); } + /** + * send some hello data, and indicate there's more + */ + private void sayContinue(APDU apdu) { + byte[] echo = transientMemory; + short echoLength = (short) 6; + Util.arrayCopyNonAtomic(helloMessage, (short)0, echo, (short)0, (short)6); + apdu.setOutgoing(); + apdu.setOutgoingLength(echoLength); + apdu.sendBytesLong(echo, (short) 0, echoLength); + ISOException.throwIt((short) (ISO7816.SW_BYTES_REMAINING_00 | 0x07)); + } + + + /** + * send the maximum amount of data the apdu will accept + * + * @param apdu APDU that requested hello message + */ + private void maximumData(APDU apdu) { + short maxData = APDU.getOutBlockSize(); + byte[] buffer = apdu.getBuffer(); + Util.arrayFillNonAtomic(buffer, (short) 0, maxData, (byte) 0); + apdu.setOutgoingAndSend((short) 0, maxData); + } + + // prototype + private void listObjects(APDU apdu) + { + byte buffer[] = apdu.getBuffer(); + + if (buffer[ISO7816.OFFSET_P2] != 0) { + ISOException.throwIt((short)0x9C11); + } + + byte expectedBytes = buffer[ISO7816.OFFSET_LC]; + + if (expectedBytes < 14) { + ISOException.throwIt(ISO7816.SW_WRONG_LENGTH); + } + + ISOException.throwIt((short)0x9C12); + } } diff --git a/src/main/java/com/licel/jcardsim/samples/MultiInstanceApplet.java b/src/main/java/com/licel/jcardsim/samples/MultiInstanceApplet.java new file mode 100644 index 00000000..bb6596bd --- /dev/null +++ b/src/main/java/com/licel/jcardsim/samples/MultiInstanceApplet.java @@ -0,0 +1,105 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.samples; + +import javacard.framework.*; + +/** + * Multi instance sample applet. + * + *

    Returns FCI (file control information) on SELECT

    + * + *

    Supported APDUs:

    + * + *
      + *
    • CLA=0x80 INS=0 return AID
    • + *
    • CLA=0x80 INS=2 return instance count
    • + *
    • CLA=0x80 INS=4 lock the applet
    • + *
    + */ +public class MultiInstanceApplet extends BaseApplet implements AppletEvent { + private static final byte CLA = (byte) 0x80; + private static final byte INS_GET_FULL_AID = 0; + private static final byte INS_GET_COUNT = 2; + private static final byte INS_MAKE_UNUSABLE = 4; + + private static final byte CLA_MASK = (byte) 0xF0; + private static short instanceCounter = 0; + + private boolean locked = false; + + public static void install(byte[] bArray, short bOffset, byte bLength) { + new MultiInstanceApplet().register(); + } + + protected MultiInstanceApplet() { + ++ instanceCounter; + } + + @Override + public boolean select() { + return !locked; + } + + public void process(APDU apdu) { + byte[] buffer = apdu.getBuffer(); + + final short readCount = apdu.setIncomingAndReceive(); + final short lc = apdu.getIncomingLength(); + final short offsetCData = apdu.getOffsetCdata(); + short read = readCount; + while (read < lc) { + read += apdu.receiveBytes(read); + } + + if (selectingApplet()) { + // return FCI with AID from SELECT + byte dataSize = buffer[ISO7816.OFFSET_LC]; + buffer[1] = 0x6F; // Tag: File Control Information (FCI) Template + buffer[2] = (byte) (dataSize + 2); + buffer[3] = (byte) 0x84; // Tag: Dedicated File (DF) Name + buffer[4] = dataSize; + apdu.setOutgoingAndSend((short) 1, (short)(dataSize + 4)); + return; + } + + if ((buffer[ISO7816.OFFSET_CLA] & CLA_MASK) != CLA) { + ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); + } + + switch (buffer[ISO7816.OFFSET_INS]) { + case INS_GET_FULL_AID: { + short dataSize = JCSystem.getAID().getBytes(buffer, (short) 0); + apdu.setOutgoingAndSend((short)0, dataSize); + break; + } + case INS_GET_COUNT: { + Util.setShort(buffer, (short)0, instanceCounter); + apdu.setOutgoingAndSend((short)0, (short) 2); + } + case INS_MAKE_UNUSABLE: { + locked = true; + break; + } + default: + ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); + } + } + + public void uninstall() { + -- instanceCounter; + } +} diff --git a/src/main/java/com/licel/jcardsim/samples/Sha1Applet.java b/src/main/java/com/licel/jcardsim/samples/Sha1Applet.java new file mode 100644 index 00000000..fb721a70 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/samples/Sha1Applet.java @@ -0,0 +1,104 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.samples; + +import javacard.framework.*; +import javacard.security.MessageDigest; +import javacardx.apdu.ExtendedLength; + + +/** + * Applet for calculating SHA1 digests. + * + *

    Supported APDUs:

    + * + *
      + *
    • CLA=0x80 INS=0 digest of CData
    • + *
    • CLA=0x80 INS=2 echo input
    • + *
    • CLA=0x80 INS=4 echo value of Le
    • + *
    • CLA=0x80 INS=8 return last digest
    • + *
    + */ +public class Sha1Applet extends BaseApplet implements ExtendedLength { + private static final byte CLA = (byte) 0x80; + private static final byte INS_DIGEST = 0; + private static final byte INS_ECHO = 2; + private static final byte INS_LEN = 4; + private static final byte INS_LAST_DIGEST = 6; + + private static final byte CLA_MASK = (byte) 0xF0; + + private MessageDigest digest; + private byte[] lastDigest; + + public static void install(byte[] bArray, short bOffset, byte bLength) { + new Sha1Applet().register(); + } + + protected Sha1Applet() { + digest = MessageDigest.getInstance(MessageDigest.ALG_SHA, false); + lastDigest = JCSystem.makeTransientByteArray(digest.getLength(), JCSystem.CLEAR_ON_DESELECT); + } + + public void process(APDU apdu) { + byte[] buffer = apdu.getBuffer(); + + final short readCount = apdu.setIncomingAndReceive(); + final short lc = apdu.getIncomingLength(); + final short offsetCData = apdu.getOffsetCdata(); + short read = readCount; + while(read < lc) { + read += apdu.receiveBytes(read); + } + + if (selectingApplet()) { + return; + } + + if ((buffer[ISO7816.OFFSET_CLA] & CLA_MASK) != CLA) { + ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED); + } + + switch (buffer[ISO7816.OFFSET_INS]) { + case INS_DIGEST: + short len = digest.doFinal(buffer, offsetCData, lc, lastDigest, (short)0); + Util.arrayCopy(lastDigest, (short)0, buffer, (short) 0, len); + apdu.setOutgoingAndSend((short)0, len); + break; + case INS_ECHO: { + apdu.setOutgoingAndSend(offsetCData, lc); + break; + } + case INS_LEN: { + short le = apdu.setOutgoing(); + apdu.setOutgoingLength((short)4); + + Util.setShort(buffer, (short)0, lc); + Util.setShort(buffer, (short)2, le); + + apdu.sendBytes((short)0, (short)4); + break; + } + case INS_LAST_DIGEST: { + Util.arrayCopy(lastDigest, (short)0, buffer, (short) 0, (short) lastDigest.length); + apdu.setOutgoingAndSend((short)0, (short) lastDigest.length); + break; + } + default: + ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); + } + } +} diff --git a/src/main/java/com/licel/jcardsim/samples/package-info.java b/src/main/java/com/licel/jcardsim/samples/package-info.java new file mode 100644 index 00000000..9cf0c029 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/samples/package-info.java @@ -0,0 +1,4 @@ +/** + * Example applets. + */ +package com.licel.jcardsim.samples; diff --git a/src/main/java/com/licel/jcardsim/smartcardio/CardSimulator.java b/src/main/java/com/licel/jcardsim/smartcardio/CardSimulator.java new file mode 100644 index 00000000..c1812134 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/smartcardio/CardSimulator.java @@ -0,0 +1,270 @@ +/* + * Copyright 2015 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.smartcardio; + +import com.licel.jcardsim.base.CardManager; +import com.licel.jcardsim.base.SimulatorRuntime; +import com.licel.jcardsim.io.JavaxSmartCardInterface; + +import javax.smartcardio.*; +import java.nio.ByteBuffer; +import java.util.concurrent.atomic.AtomicReference; + +/** + * Simulates a JavaCard. + * + * @see com.licel.jcardsim.smartcardio.CardTerminalSimulator + */ +public class CardSimulator extends JavaxSmartCardInterface { + private final CardImpl card = new CardImpl(); + private final AtomicReference owningCardTerminalReference + = new AtomicReference(); + private final AtomicReference threadReference = new AtomicReference(); + + /** + * Create a Simulator object using a new SimulatorRuntime. + *
      + *
    • SimulatorRuntime#resetRuntime is called
    • + *
    + */ + public CardSimulator() { + this(new SimulatorRuntime()); + } + + /** + * Create a Simulator object using a provided Runtime. + *
      + *
    • SimulatorRuntime#resetRuntime is called
    • + *
    + * + * @param runtime SimulatorRuntime instance to use + * @throws java.lang.NullPointerException if runtime is null + */ + public CardSimulator(SimulatorRuntime runtime) { + super(runtime); + } + + /** + * Wrapper for {@link #transmitCommand(byte[])} + * + * @param commandApdu CommandAPDU + * @return ResponseAPDU + */ + @Override + public ResponseAPDU transmitCommand(CommandAPDU commandApdu) { + return new ResponseAPDU(transmitCommand(commandApdu.getBytes())); + } + + /** + *

    Assigns this simulated card to a CardTerminal.

    + *

    If the card is already assigned to another CardTerminal, it will be ejected + * and inserted into the CardTerminal terminal.

    + * + * @param terminal card terminal or null + */ + public synchronized void assignToTerminal(CardTerminal terminal) { + final CardTerminal oldCardTerminal = owningCardTerminalReference.getAndSet(terminal); + + if (terminal == oldCardTerminal) { + return; + } + + if (oldCardTerminal != null) { + // eject card from old Terminal + ((CardTerminalSimulator.CardTerminalImpl) oldCardTerminal).assignSimulator(null); + } + + if (terminal != null) { + // reset card + card.disconnect(); + // assign to new terminal + ((CardTerminalSimulator.CardTerminalImpl) terminal).assignSimulator(this); + } + } + + /** + * @return the assigned CardTerminal or null if none is assigned + */ + public CardTerminal getAssignedCardTerminal() { + return owningCardTerminalReference.get(); + } + + final Card internalConnect(String protocol) { + card.connect(protocol); + return card; + } + + final void internalEject(CardTerminal oldTerminal) { + if (owningCardTerminalReference.compareAndSet(oldTerminal, null)) { + card.eject(); + } + } + + private enum CardState { + Connected, Disconnected, Ejected + } + + private static final class CardChannelImpl extends CardChannel { + private final CardImpl card; + private final int channelNr; + + public CardChannelImpl(CardImpl card, int channelNr) { + this.card = card; + this.channelNr = channelNr; + } + + @Override + public Card getCard() { + return card; + } + + @Override + public int getChannelNumber() { + card.ensureConnected(); + return channelNr; + } + + @Override + public ResponseAPDU transmit(CommandAPDU commandAPDU) throws CardException { + return new ResponseAPDU(card.transmitCommand(commandAPDU.getBytes())); + } + + @Override + public int transmit(ByteBuffer byteBuffer, ByteBuffer byteBuffer2) throws CardException { + byte[] result = card.transmitCommand(new CommandAPDU(byteBuffer).getBytes()); + byteBuffer2.put(result); + return result.length; + } + + @Override + public void close() throws CardException { + throw new CardException("Can not close basic channel"); + } + } + + private final class CardImpl extends Card { + private final CardChannel basicChannel; + private volatile String protocol = "T=0"; + private volatile byte protocolByte = 0; + private volatile CardState state = CardState.Connected; + + CardImpl() { + this.basicChannel = new CardChannelImpl(this, 0); + } + + void ensureConnected() { + CardState cardState = state; + if (cardState == CardState.Disconnected) { + throw new IllegalStateException("Card was disconnected"); + } else if (cardState == CardState.Ejected) { + throw new IllegalStateException("Card was removed"); + } + } + + @Override + public ATR getATR() { + return new ATR(CardSimulator.this.getATR()); + } + + @Override + public String getProtocol() { + return protocol; + } + + @Override + public CardChannel getBasicChannel() { + return basicChannel; + } + + @Override + public CardChannel openLogicalChannel() throws CardException { + throw new CardException("Logical channel not supported"); + } + + @Override + public void beginExclusive() throws CardException { + synchronized (runtime) { + if (!threadReference.compareAndSet(null, Thread.currentThread())) { + throw new CardException("Card is held exclusively by Thread " + threadReference.get()); + } + } + } + + @Override + public void endExclusive() throws CardException { + synchronized (runtime) { + if (!threadReference.compareAndSet(Thread.currentThread(), null)) { + throw new CardException("Card is held exclusively by Thread " + threadReference.get()); + } + } + } + + @Override + public byte[] transmitControlCommand(int i, byte[] bytes) throws CardException { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public void disconnect(boolean reset) throws CardException { + synchronized (runtime) { + if (reset) { + CardSimulator.this.reset(); + } + state = CardState.Disconnected; + } + } + + void connect(String protocol) { + synchronized (runtime) { + this.protocolByte = CardSimulator.this.getProtocolByte(protocol); + this.protocol = protocol; + this.state = CardState.Connected; + } + } + + void eject() { + synchronized (runtime) { + CardSimulator.this.reset(); + state = CardState.Ejected; + } + } + + void disconnect() { + synchronized (runtime) { + CardSimulator.this.reset(); + state = CardState.Disconnected; + } + } + + byte[] transmitCommand(byte[] capdu) throws CardException { + synchronized (runtime) { + ensureConnected(); + Thread thread = threadReference.get(); + if (thread != null && thread != Thread.currentThread()) { + throw new CardException("Card is held exclusively by Thread " + thread.getName()); + } + + byte currentProtocol = getProtocolByte(CardSimulator.this.getProtocol()); + try { + runtime.changeProtocol(protocolByte); + return CardManager.dispatchApdu(CardSimulator.this, capdu); + } finally { + runtime.changeProtocol(currentProtocol); + } + } + } + } +} diff --git a/src/main/java/com/licel/jcardsim/smartcardio/CardTerminalSimulator.java b/src/main/java/com/licel/jcardsim/smartcardio/CardTerminalSimulator.java new file mode 100644 index 00000000..8d57e5b2 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/smartcardio/CardTerminalSimulator.java @@ -0,0 +1,356 @@ +/* + * Copyright 2015 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.smartcardio; + +import com.licel.jcardsim.utils.AutoResetEvent; + +import javax.smartcardio.*; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.security.Provider; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; + +/** + *

    A simulated {@link javax.smartcardio.TerminalFactory}.

    + *

    Example: Obtaining a Card

    + *
    + * // create card simulator
    + * CardSimulator cardSimulator = new CardSimulator();
    + *
    + * // connect to a card
    + * CardTerminal terminal =
    + *   CardTerminalSimulator.terminal(cardSimulator);
    + * Card card = terminal.connect("*");
    + * 
    + *

    Example: Inserting/ejecting a Card

    + *
    + * // create card simulator
    + * CardSimulator cardSimulator = new CardSimulator();
    + *
    + * // create CardTerminal
    + * CardTerminals terminals = CardTerminalSimulator.terminals("my terminal")
    + * CardTerminal terminal = terminals.getTerminal("my terminal");
    + *
    + * // insert Card
    + * cardSimulator.assignToTerminal(terminal);
    + *
    + * // eject Card
    + * cardSimulator.assignToTerminal(null);
    + * 
    + * + * @see com.licel.jcardsim.smartcardio.CardSimulator + */ +public final class CardTerminalSimulator { + private CardTerminalSimulator() { + } + + /** + * Create a single CardTerminal. + * + * @param cardSimulator card to insert + * @param name the terminal name + * @return a new CardTerminal instance + * @throws java.lang.NullPointerException if name or cardSimulator is null + */ + public static CardTerminal terminal(CardSimulator cardSimulator, String name) { + if (name == null) { + throw new NullPointerException("name"); + } + if (cardSimulator == null) { + throw new NullPointerException("cardSimulator"); + } + CardTerminal cardTerminal = terminals(name).getTerminal(name); + cardSimulator.assignToTerminal(cardTerminal); + return cardTerminal; + } + + /** + * Create a CardTerminal with name "jCardSim.Terminal". + * + * @param cardSimulator card to insert + * @return a new CardTerminal instance + * @throws java.lang.NullPointerException if name or cardSimulator is null + */ + public static CardTerminal terminal(CardSimulator cardSimulator) { + return terminal(cardSimulator, "jCardSim.Terminal"); + } + + /** + *

    Create CardTerminals.

    + *

    Example:

    + *
    +     *  CardTerminals terminals = CardTerminalSimulator.terminals("1","2");
    +     *  CardTerminal terminal = terminals.getTerminal("1");
    +     *
    +     *  // assign simulator
    +     *  CardSimulator cardSimulator = new CardSimulator();
    +     *  cardSimulator.assignToTerminal(terminal);
    +     * 
    + * + * @param names the terminal names + * @return a new CardTerminals instance + * @throws java.lang.NullPointerException if names is null + * @throws java.lang.IllegalArgumentException if any name is null or duplicated + * @see javax.smartcardio.CardTerminals + */ + public static CardTerminals terminals(String... names) { + if (names == null) { + throw new NullPointerException("names"); + } + Set set = new HashSet(names.length); + for (String name : names) { + if (set.contains(name)) { + throw new IllegalArgumentException("Duplicate name '" + name + "'"); + } + set.add(name); + } + return new CardTerminalsImpl(names); + } + + /** + *

    Security provider.

    + *

    Register the SecurityProvider with:

    + *
    +     * if (Security.getProvider("CardTerminalSimulator") == null) {
    +     *     Security.addProvider(new CardTerminalSimulator.SecurityProvider());
    +     * }
    +     * 
    + */ + public static final class SecurityProvider extends Provider { + public SecurityProvider() { + super("CardTerminalSimulator", 1.0d, "jCardSim Virtual Terminal Provider"); + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + put("TerminalFactory." + "CardTerminalSimulator", Factory.class.getCanonicalName() + .replace(".Factory", "$Factory")); + return null; + } + }); + } + } + + /** + * {@link javax.smartcardio.TerminalFactorySpi} implementation. + * Applications do not access this class directly, instead see {@link javax.smartcardio.TerminalFactory}. + */ + @SuppressWarnings("unused") + public static final class Factory extends TerminalFactorySpi { + private final CardTerminals cardTerminals; + + public Factory(Object params) { + String[] names; + if (params == null) { + names = new String[]{"jCardSim.Terminal"}; + } else if (params instanceof String) { + names = new String[]{(String) params}; + } else if (params instanceof String[]) { + names = (String[]) params; + } else { + throw new IllegalArgumentException("Illegal parameter: " + params); + } + cardTerminals = terminals(names); + } + + @Override + protected CardTerminals engineTerminals() { + return cardTerminals; + } + } + + static boolean waitForLatch(AutoResetEvent autoResetEvent, long timeoutMilliseconds) throws InterruptedException { + if (timeoutMilliseconds < 0) { + throw new IllegalArgumentException("timeout is negative"); + } + if (timeoutMilliseconds == 0) { // wait forever + boolean success; + do { + success = autoResetEvent.await(1, TimeUnit.MINUTES); + } while (!success); + return true; + } + return autoResetEvent.await(timeoutMilliseconds, TimeUnit.MILLISECONDS); + } + + static final class CardTerminalsImpl extends CardTerminals { + private final AtomicBoolean waitCalled = new AtomicBoolean(false); + private final AutoResetEvent terminalsChangeAutoResetEvent = new AutoResetEvent(); + private final ArrayList simulatedTerminals; + private final HashMap terminalStateMap; + + CardTerminalsImpl(String[] names) { + simulatedTerminals = new ArrayList(names.length); + terminalStateMap = new HashMap(names.length); + for (String name : names) { + simulatedTerminals.add(new CardTerminalImpl(name, terminalStateMap, terminalsChangeAutoResetEvent)); + } + } + + @Override + public synchronized List list(State state) throws CardException { + if (state == null) { + throw new NullPointerException("state"); + } + synchronized (terminalStateMap) { + final ArrayList result = new ArrayList(simulatedTerminals.size()); + + for (CardTerminal terminal : simulatedTerminals) { + State terminalState = terminalStateMap.get(terminal); + switch (state) { + case ALL: + result.add(terminal); + break; + case CARD_ABSENT: + if (!terminal.isCardPresent() && terminalState != State.CARD_REMOVAL) { + result.add(terminal); + } + break; + case CARD_PRESENT: + if (terminal.isCardPresent() && terminalState != State.CARD_INSERTION) { + result.add(terminal); + } + break; + case CARD_INSERTION: + if (waitCalled.get()) { + if (terminalState == State.CARD_INSERTION) { + terminalStateMap.put(terminal, State.CARD_PRESENT); + result.add(terminal); + } + } else if (terminal.isCardPresent()) { + result.add(terminal); + } + break; + case CARD_REMOVAL: + if (waitCalled.get()) { + if (terminalState == State.CARD_REMOVAL) { + terminalStateMap.put(terminal, State.CARD_ABSENT); + result.add(terminal); + } + } else if (!terminal.isCardPresent()) { + result.add(terminal); + } + break; + } + } + return Collections.unmodifiableList(result); + } + } + + @Override + public boolean waitForChange(long timeoutMilliseconds) throws CardException { + try { + return waitForLatch(terminalsChangeAutoResetEvent, timeoutMilliseconds); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return false; + } finally { + waitCalled.set(true); + } + } + } + + static final class CardTerminalImpl extends CardTerminal { + private final String name; + private final Map terminalStateMap; + private final AutoResetEvent terminalsChangeAutoResetEvent; + private final AutoResetEvent cardPresent = new AutoResetEvent(); + private final AutoResetEvent cardAbsent = new AutoResetEvent(); + private final AtomicReference cardSimulatorReference = new AtomicReference(); + + CardTerminalImpl(String name, Map terminalStateMap, AutoResetEvent terminalsChangeAutoResetEvent) { + this.name = name; + this.terminalStateMap = terminalStateMap; + this.terminalsChangeAutoResetEvent = terminalsChangeAutoResetEvent; + cardAbsent.signal(); + terminalStateMap.put(this, CardTerminals.State.CARD_ABSENT); + } + + @Override + public String getName() { + return name; + } + + @Override + public Card connect(String protocol) throws CardException { + CardSimulator cardSimulator = cardSimulatorReference.get(); + if (cardSimulator == null) { + throw new CardNotPresentException("No card inserted. You need to call CardTerminalSimulator#assignToTerminal"); + } + return cardSimulator.internalConnect(protocol); + } + + @Override + public boolean isCardPresent() throws CardException { + return cardSimulatorReference.get() != null; + } + + @Override + public boolean waitForCardPresent(long timeoutMilliseconds) throws CardException { + try { + return waitForLatch(cardPresent, timeoutMilliseconds); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return false; + } + } + + @Override + public boolean waitForCardAbsent(long timeoutMilliseconds) throws CardException { + try { + return waitForLatch(cardAbsent, timeoutMilliseconds); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + return false; + } + } + + void assignSimulator(CardSimulator cardSimulator) { + synchronized (terminalStateMap) { + CardSimulator oldCardSimulator = cardSimulatorReference.getAndSet(cardSimulator); + boolean change = false; + boolean present = false; + + if (oldCardSimulator != null) { + oldCardSimulator.internalEject(this); + change = true; + } + if (cardSimulator != null) { + present = true; + change = true; + } + if (change) { + if (present) { + terminalStateMap.put(this, CardTerminals.State.CARD_INSERTION); + cardPresent.signal(); + cardAbsent.reset(); + } else { + terminalStateMap.put(this, CardTerminals.State.CARD_REMOVAL); + cardPresent.reset(); + cardAbsent.signal(); + } + terminalsChangeAutoResetEvent.signal(); + } + } + } + + @Override + public String toString() { + return "jCardSim Terminal: " + name; + } + } +} diff --git a/src/main/java/com/licel/jcardsim/smartcardio/JCSCard.java b/src/main/java/com/licel/jcardsim/smartcardio/JCSCard.java index ea3be6f1..28517fbb 100644 --- a/src/main/java/com/licel/jcardsim/smartcardio/JCSCard.java +++ b/src/main/java/com/licel/jcardsim/smartcardio/JCSCard.java @@ -15,46 +15,33 @@ */ package com.licel.jcardsim.smartcardio; -import com.licel.jcardsim.base.Simulator; -import java.text.MessageFormat; -import javacard.framework.AID; -import javacard.framework.ISO7816; -import javacard.framework.SystemException; -import javacard.framework.Util; +import com.licel.jcardsim.base.CardManager; +import com.licel.jcardsim.io.JavaCardInterface; import javax.smartcardio.*; -import org.bouncycastle.util.encoders.Hex; /** * Card implementation class. + * * @author LICEL LLC */ public class JCSCard extends Card { // default protocol - static final String T0_PROTOCOL = "T=0"; - // default ATR - NXP JCOP 31/36K - static final String DEFAULT_ATR = "3BFA1800008131FE454A434F5033315632333298"; - // ATR system property name - static final String ATR_SYSTEM_PROPERTY = "com.licel.jcardsim.smartcardio.ATR"; - // Applet AID system property template - static final MessageFormat AID_SP_TEMPLATE = new MessageFormat("com.licel.jcardsim.smartcardio.applet.{0}.AID"); - // Applet ClassName system property template - static final MessageFormat APPLET_CLASS_SP_TEMPLATE = new MessageFormat("com.licel.jcardsim.smartcardio.applet.{0}.Class"); + // ATR private ATR atr; // Simulator - private Simulator simulator; + private JavaCardInterface cardInterface; // private JCSCardChannel basicChannel; - public JCSCard() { - simulator = new Simulator(); - atr = new ATR(Hex.decode(System.getProperty(ATR_SYSTEM_PROPERTY, DEFAULT_ATR))); + public JCSCard(JavaCardInterface cardInterface) { + this.cardInterface = cardInterface; + atr = new ATR(cardInterface.getATR()); basicChannel = new JCSCardChannel(this, 0); } /** - * Returns ATR configured by system property com.licel.jcardsim.smartcardio.ATR - * Default ATR - 3BFA1800008131FE454A434F5033315632333298. + * */ public ATR getATR() { return atr; @@ -64,7 +51,7 @@ public ATR getATR() { * Always returns T=0. */ public String getProtocol() { - return T0_PROTOCOL; + return cardInterface.getProtocol(); } public CardChannel getBasicChannel() { @@ -73,7 +60,6 @@ public CardChannel getBasicChannel() { /** * Always returns basic channel with id = 0 - * @throws CardException */ public CardChannel openLogicalChannel() throws CardException { return basicChannel; @@ -96,105 +82,17 @@ public byte[] transmitControlCommand(int i, byte[] bytes) throws CardException { } /** - * Do nothing. + * Disconnect form the card + * @param reset true if the card should be reset + * @see Card#disconnect(boolean) */ - public void disconnect(boolean bln) throws CardException { - } - - ResponseAPDU transmitCommand(CommandAPDU capdu) { - byte[] theSW = new byte[2]; - // handles select applet command - if (((byte) capdu.getCLA()) == ISO7816.CLA_ISO7816 - && ((byte) capdu.getINS()) == ISO7816.INS_SELECT) { - byte[] aidBytes = capdu.getData(); - if (aidBytes.length < 5 || aidBytes.length > 16) { - Util.setShort(theSW, (short) 0, ISO7816.SW_DATA_INVALID); - return new ResponseAPDU(theSW); - } - AID aid = new AID(aidBytes, (short) 0, (byte) aidBytes.length); - boolean appletSelectionResult = false; - try { - appletSelectionResult = simulator.selectApplet(aid); - } catch (Throwable t) { - } - if (!appletSelectionResult) { - Util.setShort(theSW, (short) 0, ISO7816.SW_APPLET_SELECT_FAILED); - } else { - Util.setShort(theSW, (short) 0, ISO7816.SW_NO_ERROR); - } - return new ResponseAPDU(theSW); - } else if (capdu.getCLA() == 0x80 && capdu.getINS() == 0xb8) { - // handle CREATE APPLTE command - // command format: - // CLA INS P0 P1 - // 0x8x, 0xb8, 0x00, 0x00 - // Lc field - // AID length field - // AID field - // parameter length field - // [parameters] - // Le field - byte[] data = capdu.getData(); - // aid - if (data[0] < 5 || data[0] > 16) { - Util.setShort(theSW, (short) 0, ISO7816.SW_DATA_INVALID); - return new ResponseAPDU(theSW); - } - AID aid = new AID(data, (short) 1, data[0]); - // parameters - try { - simulator.createApplet(aid, data, (short) 0, (byte) data.length); - byte[] response = new byte[data[0] + 2]; - aid.getBytes(response, (short) 0); - Util.setShort(response, (short) (response.length - 2), ISO7816.SW_NO_ERROR); - ResponseAPDU resp = new ResponseAPDU(response); - return new ResponseAPDU(response); - } catch (SystemException e) { - Util.setShort(theSW, (short) 0, e.getReason()); - } - return new ResponseAPDU(theSW); - } else { - return new ResponseAPDU(simulator.transmitCommand(capdu.getBytes())); + public void disconnect(boolean reset) throws CardException { + if (reset) { + cardInterface.reset(); } } - /** - * powerdown/powerup - */ - void reset(){ - simulator.reset(); - // init applets - initApplets(); - } - - /** - * Init applets - */ - private void initApplets() { - for (int i = 0; i < 10; i++) { - String appletAID = System.getProperty(AID_SP_TEMPLATE.format(new Object[]{new Integer(i)})); - if (appletAID != null) { - String appletClassName = System.getProperty(APPLET_CLASS_SP_TEMPLATE.format(new Object[]{new Integer(i)})); - if (appletClassName != null) { - loadApplet(appletAID, appletClassName); - } - } - } - } - - /** - * Install applet - */ - private void loadApplet(String appletAID, String appletClassName) { - byte[] aidBytes = Hex.decode(appletAID); - if (aidBytes == null || aidBytes.length < 5 || aidBytes.length > 16) { - throw new IllegalArgumentException("AID must be in hex format 5..16 bytes length"); - } - try { - Class appletClass = Class.forName(appletClassName); - simulator.loadApplet(new AID(aidBytes, (short) 0, (byte) aidBytes.length), appletClass); - } catch (ClassNotFoundException ex) { - throw new IllegalArgumentException("Applet class: "+appletClassName+" not found!", ex); - } + ResponseAPDU transmitCommand(CommandAPDU capdu) { + return new ResponseAPDU(CardManager.dispatchApdu(cardInterface, capdu.getBytes())); } } diff --git a/src/main/java/com/licel/jcardsim/smartcardio/JCSCardTerminals.java b/src/main/java/com/licel/jcardsim/smartcardio/JCSCardTerminals.java index 012d3860..11c0a932 100644 --- a/src/main/java/com/licel/jcardsim/smartcardio/JCSCardTerminals.java +++ b/src/main/java/com/licel/jcardsim/smartcardio/JCSCardTerminals.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import javax.smartcardio.CardException; +import javax.smartcardio.CardTerminal; import javax.smartcardio.CardTerminals; /** @@ -30,8 +31,8 @@ public class JCSCardTerminals extends CardTerminals { * Returns only one terminal with state ALL|CARD_PRESENT|CARD_INSERTION, * in other case returns empty list. */ - public List list(State state) throws CardException { - List terminals = new ArrayList(); + public List list(State state) throws CardException { + List terminals = new ArrayList(); switch (state) { case ALL: case CARD_PRESENT: diff --git a/src/main/java/com/licel/jcardsim/smartcardio/JCSTerminal.java b/src/main/java/com/licel/jcardsim/smartcardio/JCSTerminal.java index 9a8c3908..58f51e9f 100644 --- a/src/main/java/com/licel/jcardsim/smartcardio/JCSTerminal.java +++ b/src/main/java/com/licel/jcardsim/smartcardio/JCSTerminal.java @@ -15,29 +15,51 @@ */ package com.licel.jcardsim.smartcardio; +import com.licel.jcardsim.io.CAD; +import com.licel.jcardsim.io.JavaCardInterface; import javax.smartcardio.Card; import javax.smartcardio.CardException; import javax.smartcardio.CardTerminal; /** * CardTerminal implementation class. + * * @author LICEL LLC */ public class JCSTerminal extends CardTerminal { - final static String NAME="jCardSim.Terminal"; - static JCSCard card = null; - + final static String NAME = "jCardSim.Terminal"; + CAD cad; + static JavaCardInterface cardInterface = null; + + public JCSTerminal() { + cad = new CAD(System.getProperties()); + } + public String getName() { return NAME; } - public Card connect(String string) throws CardException { - if (card == null) { - card = new JCSCard(); + /** + * @see javax.smartcardio.CardTerminal#connect(String) + * @see com.licel.jcardsim.io.JavaCardInterface#changeProtocol(String) + */ + public Card connect(String protocol) throws CardException { + if (cardInterface == null) { + cardInterface = (JavaCardInterface) cad.getCardInterface(); } - card.reset(); - return card; + + if (protocol == null) { + throw new NullPointerException("protocol"); + } + else if (protocol.equals("*")) { + cardInterface.changeProtocol("T=0"); + } + else { + cardInterface.changeProtocol(protocol); + } + + return new JCSCard(cardInterface); } /** diff --git a/src/main/java/com/licel/jcardsim/smartcardio/package-info.java b/src/main/java/com/licel/jcardsim/smartcardio/package-info.java new file mode 100644 index 00000000..7ea6a9a8 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/smartcardio/package-info.java @@ -0,0 +1,4 @@ +/** + * jCardSim card simulation and javax.smartcardio support. + */ +package com.licel.jcardsim.smartcardio; diff --git a/src/main/java/com/licel/jcardsim/utils/AIDUtil.java b/src/main/java/com/licel/jcardsim/utils/AIDUtil.java new file mode 100644 index 00000000..23392803 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/utils/AIDUtil.java @@ -0,0 +1,145 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.utils; + +import javacard.framework.AID; +import javacard.framework.ISO7816; +import org.bouncycastle.util.encoders.Hex; + +import java.util.Comparator; + +/** + * Utility methods for dealing with AIDs. + */ +public final class AIDUtil { + private static final Comparator aidComparator = new Comparator() { + public int compare(AID aid1, AID aid2) { + String s1 = (aid1 != null) ? AIDUtil.toString(aid1) : ""; + String s2 = (aid1 != null) ? AIDUtil.toString(aid2) : ""; + return s1.compareTo(s2); + } + }; + + /** + * Generate a SELECT APDU for aid + * @param aid AID to be selected + * @return SELECT APDU (CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc, AID, Le=0x00) + * @throws java.lang.NullPointerException if aid is null + */ + public static byte[] select(AID aid) { + if (aid == null) { + throw new NullPointerException("aid"); + } + + byte[] aidBuffer = new byte[16]; + byte length = aid.getBytes(aidBuffer, (short) 0); + + byte[] selectCmd = new byte[length + ISO7816.OFFSET_CDATA + 1]; + selectCmd[ISO7816.OFFSET_CLA] = ISO7816.CLA_ISO7816; + selectCmd[ISO7816.OFFSET_INS] = ISO7816.INS_SELECT; + selectCmd[ISO7816.OFFSET_P1] = 0x04; + selectCmd[ISO7816.OFFSET_P2] = 0x00; + selectCmd[ISO7816.OFFSET_LC] = length; + System.arraycopy(aidBuffer, 0, selectCmd, ISO7816.OFFSET_CDATA, length); + selectCmd[selectCmd.length - 1] = 0; + + return selectCmd; + } + + /** + * Generate a SELECT APDU for aid + * @param aid AID to be selected + * @return SELECT APDU (CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc, AID, Le=0x00) + * @throws java.lang.IllegalArgumentException if aid is invalid + * @throws java.lang.NullPointerException if aid is null + */ + public static byte[] select(String aid) { + if (aid == null) { + throw new NullPointerException("aid"); + } + + byte[] aidBuffer = ByteUtil.byteArray(aid); + if (aidBuffer.length > 16) { + throw new IllegalArgumentException("AID must not be larger than 16 bytes: " + ByteUtil.hexString(aidBuffer)); + } + + byte[] selectCmd = new byte[aidBuffer.length + ISO7816.OFFSET_CDATA + 1]; + selectCmd[ISO7816.OFFSET_CLA] = ISO7816.CLA_ISO7816; + selectCmd[ISO7816.OFFSET_INS] = ISO7816.INS_SELECT; + selectCmd[ISO7816.OFFSET_P1] = 0x04; + selectCmd[ISO7816.OFFSET_P2] = 0x00; + selectCmd[ISO7816.OFFSET_LC] = (byte) aidBuffer.length; + System.arraycopy(aidBuffer, 0, selectCmd, ISO7816.OFFSET_CDATA, aidBuffer.length); + selectCmd[selectCmd.length - 1] = 0; + + return selectCmd; + } + + /** + * Create an AID from a byte array + * @param aidBytes AID bytes + * @return aid + * @throws java.lang.NullPointerException if aidBytes is null + * @throws java.lang.IllegalArgumentException if aidBytes.length is incorrect + */ + public static AID create(byte[] aidBytes) { + if (aidBytes == null) { + throw new NullPointerException("aidString"); + } + if (aidBytes.length < 5 || aidBytes.length > 16) { + throw new IllegalArgumentException("AID size must be between 5 and 16 but was " + aidBytes.length); + } + return new AID(aidBytes, (short) 0, (byte) aidBytes.length); + } + + /** + * Create an AID from a byte array + * @param aidString AID bytes as hex string + * @return aid + * @throws java.lang.NullPointerException if aidString is null + * @throws java.lang.IllegalArgumentException if length is incorrect + */ + public static AID create(String aidString) { + if (aidString == null) { + throw new NullPointerException("aidString"); + } + return create(Hex.decode(aidString)); + } + + /** + * Convert AID to hex-string + * @param aid AID to convert + * @return hex string + * @throws java.lang.NullPointerException if aid is null + */ + public static String toString(AID aid) { + if (aid == null) { + throw new NullPointerException("aid"); + } + byte[] buffer = new byte[16]; + short len = aid.getBytes(buffer, (short) 0); + return ByteUtil.hexString(buffer, 0, len); + } + + /** + * @return a Comparator for AIDs + */ + public static Comparator comparator() { + return aidComparator; + } + + private AIDUtil() {} +} diff --git a/src/main/java/com/licel/jcardsim/utils/APDUScriptTool.java b/src/main/java/com/licel/jcardsim/utils/APDUScriptTool.java index 07de0ae0..dec0ab9a 100644 --- a/src/main/java/com/licel/jcardsim/utils/APDUScriptTool.java +++ b/src/main/java/com/licel/jcardsim/utils/APDUScriptTool.java @@ -117,7 +117,7 @@ public static void executeCommands(Properties cfg, InputStream commandsStream, } private static ArrayList parseAPDUStream(InputStreamReader in) throws IOException, ParseException { - ArrayList apduCommands = new ArrayList(); + ArrayList apduCommands = new ArrayList(); BufferedReader br = new BufferedReader(in); String line = br.readLine(); StringBuilder command = new StringBuilder(); diff --git a/src/main/java/com/licel/jcardsim/utils/AutoResetEvent.java b/src/main/java/com/licel/jcardsim/utils/AutoResetEvent.java new file mode 100644 index 00000000..c35ef6de --- /dev/null +++ b/src/main/java/com/licel/jcardsim/utils/AutoResetEvent.java @@ -0,0 +1,73 @@ +/* + * Copyright 2015 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.utils; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.AbstractQueuedSynchronizer; + +/** + * Java version of .Net's AutoResetEvent. + *

    See MSDN.

    + */ +public final class AutoResetEvent { + private final static int SIGNALED = 1; + private final static int NOT_SIGNALED = 0; + private final Sync sync = new Sync(); + + /** + * Wake up one thread that is waiting. + */ + public void signal() { + sync.releaseShared(SIGNALED); + } + + /** + * Reset. + */ + public void reset() { + sync.releaseShared(NOT_SIGNALED); + } + + /** + * Wait until thread is signaled or interrupted. + * @param time time to wait + * @param unit time unit of time + * @return true if signaled + * @throws InterruptedException if the thread is interrupted + */ + public boolean await(long time, TimeUnit unit) throws InterruptedException { + return sync.tryAcquireSharedNanos(1, unit.toNanos(time)); + } + + private static class Sync extends AbstractQueuedSynchronizer { + Sync() { + setState(NOT_SIGNALED); + } + + protected int tryAcquireShared(int ignore) { + if (compareAndSetState(SIGNALED, NOT_SIGNALED)) { + return 1; + } + return -1; + } + + protected boolean tryReleaseShared(int state) { + setState(state); + return true; + } + } +} diff --git a/src/main/java/com/licel/jcardsim/utils/BiConsumer.java b/src/main/java/com/licel/jcardsim/utils/BiConsumer.java new file mode 100644 index 00000000..075b3d3d --- /dev/null +++ b/src/main/java/com/licel/jcardsim/utils/BiConsumer.java @@ -0,0 +1,8 @@ +package com.licel.jcardsim.utils; + +/** + * Back-port of Java 8 java.util.function.BiConsumer. + */ +public interface BiConsumer { + void accept(T t, U u); +} diff --git a/src/main/java/com/licel/jcardsim/utils/ByteUtil.java b/src/main/java/com/licel/jcardsim/utils/ByteUtil.java new file mode 100644 index 00000000..110e9b5a --- /dev/null +++ b/src/main/java/com/licel/jcardsim/utils/ByteUtil.java @@ -0,0 +1,130 @@ +/* + * Copyright 2014 Robert Bachmann + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.utils; + +import org.bouncycastle.util.encoders.Hex; + +/** + * Utility methods for dealing with byte arrays. + */ +public final class ByteUtil { + private static final char[] hexArray = "0123456789ABCDEF".toCharArray(); + + /** + * Create byte array from hex string + * @param hexString hex string + * @return new byte array + * @throws java.lang.NullPointerException if hexString is null + */ + public static byte[] byteArray(String hexString) { + if (hexString == null) { + throw new NullPointerException("hexArray"); + } + return Hex.decode(hexString); + } + + /** + * Convert byte array into hex string + * @param bytes hex string + * @return hexString + * @throws java.lang.NullPointerException if bytes is null + */ + public static String hexString(byte[] bytes) { + if (bytes == null) { + throw new NullPointerException("bytes"); + } + return hexString(bytes, 0, bytes.length); + } + + /** + * Convert byte array into hex string + * @param bytes hex string + * @param offset offset + * @param length length + * @return hexString + * @throws java.lang.NullPointerException if bytes is null + */ + public static String hexString(byte[] bytes, int offset, int length) { + // http://stackoverflow.com/questions/9655181/convert-from-byte-array-to-hex-string-in-java + if (bytes == null) { + throw new NullPointerException("bytes"); + } + char[] hexChars = new char[length * 2]; + for ( int j = offset; j < (offset + length); j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + /** + * Extract status word from APDU + * @param apduBuffer APDU bytes + * @return status word + * @throws java.lang.NullPointerException if apduBuffer is null + * @throws java.lang.IllegalArgumentException if apduBuffer.length is < 2 + */ + public static short getSW(byte[] apduBuffer) { + if (apduBuffer == null) { + throw new NullPointerException("bytes"); + } + if (apduBuffer.length < 2) { + throw new IllegalArgumentException("bytes.length must be at least 2"); + } + return getShort(apduBuffer, apduBuffer.length - 2); + } + + /** + * Check status word from APDU + * @param apduBuffer APDU bytes + * @param expected expected status word + * @throws java.lang.NullPointerException if apduBuffer is null + * @throws java.lang.IllegalArgumentException if apduBuffer.length is < 2 + * @throws java.lang.AssertionError if expected does not match the status word from apduBuffer + */ + public static void requireSW(byte[] apduBuffer, int expected) { + int sw = getSW(apduBuffer) & 0xFFFF; + if (sw != expected) { + throw new AssertionError(String.format("Expected status word %x but got %x", expected, sw)); + } + } + + /** + * Check status word from APDU + * @param apduBuffer APDU bytes + * @param expected expected status word + * @throws java.lang.NullPointerException if apduBuffer is null + * @throws java.lang.IllegalArgumentException if apduBuffer.length is < 2 + * @throws java.lang.AssertionError if expected does not match the status word from apduBuffer + */ + public static void requireSW(byte[] apduBuffer, short expected) { + requireSW(apduBuffer, expected & 0xFFFF); + } + + /** + * Read short from array + * @see javacard.framework.Util#getShort(byte[], short) + * @param bArray byte array + * @param offset offset + * @return short value + */ + public static short getShort(byte[] bArray, int offset) { + return (short) (((short) bArray[offset] << 8) + ((short) bArray[offset + 1] & 0xff)); + } + + private ByteUtil() {} +} diff --git a/src/main/java/com/licel/jcardsim/utils/package-info.java b/src/main/java/com/licel/jcardsim/utils/package-info.java new file mode 100644 index 00000000..bb4b69b9 --- /dev/null +++ b/src/main/java/com/licel/jcardsim/utils/package-info.java @@ -0,0 +1,4 @@ +/** + * Utility classes. + */ +package com.licel.jcardsim.utils; diff --git a/src/main/java/java/rmi/RemoteException.java b/src/main/java/java/rmi/RemoteException.java deleted file mode 100644 index 0a1f6a8a..00000000 --- a/src/main/java/java/rmi/RemoteException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright 2013 Licel LLC. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package java.rmi; - -public class RemoteException extends java.io.IOException { - - public RemoteException() { - } - -} \ No newline at end of file diff --git a/src/main/java/javacard/framework/AID.java b/src/main/java/javacard/framework/AID.java index d8e0ad95..279b3c36 100644 --- a/src/main/java/javacard/framework/AID.java +++ b/src/main/java/javacard/framework/AID.java @@ -42,7 +42,6 @@ * */ public class AID { - byte aid[]; /** @@ -97,7 +96,7 @@ public final byte getBytes(byte dest[], short offset) * This method does not throw NullPointerException. * @param anObject the object to compare this AID against * @return true if the AID byte values are equal, false otherwise - * @throws SecurityException anObject object is not accessible in the caller's context + * @throws SecurityException if anObject object is not accessible in the caller's context */ public final boolean equals(Object anObject) throws SecurityException { diff --git a/src/main/java/javacard/framework/APDU.java b/src/main/java/javacard/framework/APDU.java index f882865c..852a8bf5 100644 --- a/src/main/java/javacard/framework/APDU.java +++ b/src/main/java/javacard/framework/APDU.java @@ -5,41 +5,47 @@ package javacard.framework; import com.licel.jcardsim.base.SimulatorSystem; +import com.licel.jcardsim.utils.ByteUtil; + +import java.util.Arrays; /** + * * Application Protocol Data Unit (APDU) is * the communication format between the card and the off-card applications. * The format of the APDU is defined in ISO specification 7816-4.

    - * + * * This class only supports messages which conform to the structure of * command and response defined in ISO 7816-4. The behavior of messages which - * use proprietary structure of messages ( for example with header CLA byte in range 0xD0-0xFE ) is - * undefined. This class does not support extended length fields.

    - * + * use proprietary structure of messages is + * undefined. This class optionally supports extended length fields but only when + * the currently selected applet implements the javacardx.apdu.ExtendedLength interface.

    + * * The APDU object is owned by the Java Card runtime environment. The APDU class maintains a byte array * buffer which is used to transfer incoming APDU header and data bytes as well as outgoing data. * The buffer length must be at least 133 bytes ( 5 bytes of header and 128 bytes of data ). * The Java Card runtime environment must zero out the APDU buffer before each new message received from the CAD.

    - * + * * The Java Card runtime environment designates the APDU object as a temporary Java Card runtime environment Entry Point Object - * (See Runtime + * (See Runtime Environment * Specification for the Java Card Platform, section 6.2.1 for details). * A temporary Java Card runtime environment Entry Point Object can be accessed from any applet context. References * to these temporary objects cannot be stored in class variables or instance variables * or array components. *

    The Java Card runtime environment similarly marks the APDU buffer as a global array - * (See Runtime + * (See Runtime Environment * Specification for the Java Card Platform, section 6.2.2 for details). * A global array * can be accessed from any applet context. References to global arrays * cannot be stored in class variables or instance variables or array components. *

    - * + * * The applet receives the APDU instance to process from * the Java Card runtime environment in the Applet.process(APDU) method, and - * the first five bytes [ CLA, INS, P1, P2, P3 ] are available - * in the APDU buffer.

    - * + * the first five header bytes [ CLA, INS, P1, P2, P3 ] are available + * in the APDU buffer. (The header format is the ISO7816-4 defined 7 byte extended APDU format + * with a 3 byte Lc field when the Lc field in the incoming APDU header is 3 bytes long).

    + * * The APDU class API is designed to be transport protocol independent. * In other words, applets can use the same APDU methods regardless of whether * the underlying protocol in use is T=0 or T=1 (as defined in ISO 7816-3).

    @@ -48,71 +54,84 @@ * outgoing response APDU data size may be bigger than the APDU buffer size and may * need to be written in portions by the applet. The APDU class has methods * to facilitate this.

    - * + * * For sending large byte arrays as response data, * the APDU class provides a special method sendBytesLong() which - * manages the APDU buffer.

    - * + * manages the APDU buffer. + * *

      * // The purpose of this example is to show most of the methods
      * // in use and not to depict any particular APDU processing
    - *
    + * 
    + * class MyApplet extends javacard.framework.Applet{
    + * // ...
      * public void process(APDU apdu){
    - *  // ...
    - *  byte[] buffer = apdu.getBuffer();
    - *  byte cla = buffer[ISO7816.OFFSET_CLA];
    - *  byte ins = buffer[ISO7816.OFFSET_INS];
    - *  ...
    - *  // assume this command has incoming data
    - *  // Lc tells us the incoming apdu command length
    - *  short bytesLeft = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
    - *  if (bytesLeft < (short)55) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );
    - *
    - *  short readCount = apdu.setIncomingAndReceive();
    - *  while ( bytesLeft > 0){
    - *      // process bytes in buffer[5] to buffer[readCount+4];
    - *      bytesLeft -= readCount;
    - *      readCount = apdu.receiveBytes ( ISO7816.OFFSET_CDATA );
    - *      }
    - *  //
    - *  //...
    - *  //
    - *  // Note that for a short response as in the case illustrated here
    - *  // the three APDU method calls shown : setOutgoing(),setOutgoingLength() & sendBytes()
    - *  // could be replaced by one APDU method call : setOutgoingAndSend().
    - *
    - *  // construct the reply APDU
    - *  short le = apdu.setOutgoing();
    - *  if (le < (short)2) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );
    - *  apdu.setOutgoingLength( (short)3 );
    - *
    - *  // build response data in apdu.buffer[ 0.. outCount-1 ];
    - *  buffer[0] = (byte)1; buffer[1] = (byte)2; buffer[3] = (byte)3;
    - *  apdu.sendBytes ( (short)0 , (short)3 );
    - *  // return good complete status 90 00
    - *  }
    + * // ...
    + * byte[] buffer = apdu.getBuffer();
    + * byte cla = buffer[ISO7816.OFFSET_CLA];
    + * byte ins = buffer[ISO7816.OFFSET_INS];
    + * ...
    + * // assume this command has incoming data
    + * // Lc tells us the incoming apdu command length
    + * short bytesLeft = (short) (buffer[ISO7816.OFFSET_LC] & 0x00FF);
    + * if (bytesLeft < (short)55) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );
    + * 
    + * short readCount = apdu.setIncomingAndReceive();
    + * while ( bytesLeft > 0){
    + * // process bytes in buffer[5] to buffer[readCount+4];
    + * bytesLeft -= readCount;
    + * readCount = apdu.receiveBytes ( ISO7816.OFFSET_CDATA );
    + * }
    + * //
    + * //...
    + * //
    + * // Note that for a short response as in the case illustrated here
    + * // the three APDU method calls shown : setOutgoing(),setOutgoingLength() & sendBytes()
    + * // could be replaced by one APDU method call : setOutgoingAndSend().
    + * 
    + * // construct the reply APDU
    + * short le = apdu.setOutgoing();
    + * if (le < (short)2) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH );
    + * apdu.setOutgoingLength( (short)3 );
    + * 
    + * // build response data in apdu.buffer[ 0.. outCount-1 ];
    + * buffer[0] = (byte)1; buffer[1] = (byte)2; buffer[3] = (byte)3;
    + * apdu.sendBytes ( (short)0 , (short)3 );
    + * // return good complete status 90 00
    + * }
    + * // ...
    + * }
      * 
    - * + * * The APDU class also defines a set of STATE_.. constants - * which represent the various processing states of the APDUobject based + * which represent the various processing states of the APDU object based * on the methods invoked and the state of the data transfers. The * getCurrentState() method returns the current state. *

    * Note that the state number assignments are ordered as follows: - * STATE_INITIAL < STATE_PARTIAL_INCOMING < STATE_FULL_INCOMING < - * STATE_OUTGOING < STATE_OUTGOING_LENGTH_KNOWN < STATE_PARTIAL_OUTGOING < + * STATE_INITIAL < STATE_PARTIAL_INCOMING < STATE_FULL_INCOMING < + * STATE_OUTGOING < STATE_OUTGOING_LENGTH_KNOWN < STATE_PARTIAL_OUTGOING < * STATE_FULL_OUTGOING. *

    * The following are processing error states and have negative state number * assignments : * STATE_ERROR_NO_T0_GETRESPONSE, STATE_ERROR_T1_IFD_ABORT, STATE_ERROR_IO and * STATE_ERROR_NO_T0_REISSUE. + *

    Note:

      + *
    • The method descriptions use the ISO7816-4 notation + * for the various APDU I/O cases of input and output directions. For example - + * T=0 (Case 2S) protocol - refers to short length outbound only case + * using the T=0 protocol. + * The perspective of the notation used in the method descriptions + * is that of the card(ICC) as seen at the transport layer(TPDU). External + * transformations of the APDU I/O case may have occurred at the CAD + * and therefore not visible to the card. + *
    * @see APDUException * @see ISOException - * - */ -public final class APDU { + */ +public final class APDU { /** * This is the state of a new APDU object when only the command * header is valid. @@ -207,28 +226,34 @@ public final class APDU { public static final byte PROTOCOL_MEDIA_USB = -96; // buffer size private static final short BUFFER_SIZE = 260; + // buffer size (extended APDU) + (CLA,INS,P1,P2,0,Lc_Hi,Lc_Low,CData,Le_Hi,Le_Lo) + private static final int BUFFER_EXTENDED_SIZE = Short.MAX_VALUE + 10; // input block size, for T0 protocol = 1 private static final short T0_IBS = 1; // output block size, for T0 protocol = 258 private static final short T0_OBS = 258; + // block size, for T1 protocol + private static final short T1_BLOCK_SIZE = 254; // NAD, for T0 protocol = 9 private static final byte T0_NAD = 0; // transient array to store variables - private byte[] ramVars; + private short[] ramVars; // LE variable offset in ramVars private static final byte LE = 0; // LR variable offset in ramVars private static final byte LR = 1; // LC variable offset in ramVars - private static final byte LC = 2; + private static final byte LC = 3; // PRE_READ_LENGTH variable offset in ramVars - private static final byte PRE_READ_LENGTH = 3; + private static final byte PRE_READ_LENGTH = 4; // CURRENT_STATE variable offset in ramVars - private static final byte CURRENT_STATE = 4; + private static final byte CURRENT_STATE = 5; // LOGICAL_CHN variable offset in ramVars - private static final byte LOGICAL_CHN = 5; + private static final byte LOGICAL_CHN = 6; + // ACTIVE_PROTOCOL variable offset in ramVars + private static final byte ACTIVE_PROTOCOL = 7; // total length ramVars - private static final byte RAM_VARS_LENGTH = 6; + private static final byte RAM_VARS_LENGTH = 8; // transient array to store boolean flags private boolean[] flags; // outgoingFlag; @@ -241,27 +266,30 @@ public final class APDU { private static final byte INCOMING_FLAG = 3; // notGetResponseFlag; private static final byte NO_GET_RESPONSE_FLAG = 4; + // accessAllowedFlag; + private static final byte ACCESS_ALLOWED_FLAG = 5; // total length flags - private static final byte FLAGS_LENGTH = 5; - // - private byte[] buffer; - // reference to this - private static APDU thisAPDU; - - APDU() { - buffer = JCSystem.makeTransientByteArray(BUFFER_SIZE, JCSystem.CLEAR_ON_RESET); - ramVars = JCSystem.makeTransientByteArray(RAM_VARS_LENGTH, JCSystem.CLEAR_ON_RESET); - flags = JCSystem.makeTransientBooleanArray(FLAGS_LENGTH, JCSystem.CLEAR_ON_RESET); - thisAPDU = this; + private static final byte FLAGS_LENGTH = 6; + // APDU input buffer + private final byte[] buffer; + // extended APDU flag + private final boolean extended; + + APDU(boolean extended) { + this.extended = extended; + buffer = new byte[extended ? BUFFER_EXTENDED_SIZE : BUFFER_SIZE]; + ramVars = new short[RAM_VARS_LENGTH]; + flags = new boolean[FLAGS_LENGTH]; + internalReset(PROTOCOL_T0, null); } /** * Returns the APDU buffer byte array. *

    Note:

      - *
    • References to the APDU buffer byte array + *
    • References to the APDU buffer byte array * cannot be stored in class variables or instance variables or array components. * See Runtime - * Specification for the Java Card Platform, section 6.2.2 for details. + * Specification for the Java Card Platform, section 6.2.2 for details. *
    * @return byte array containing the APDU buffer */ @@ -283,10 +311,10 @@ public byte[] getBuffer() { * should account for this potential blocksize.
    * * @return incoming block size setting - * @see APDU.receiveBytes(short) + * @see #receiveBytes(short) */ public static short getInBlockSize() { - return T0_IBS; + return (getProtocol() & PROTOCOL_T1) == PROTOCOL_T1 ? T1_BLOCK_SIZE : T0_IBS; } /** @@ -302,10 +330,10 @@ public static short getInBlockSize() { * should account for this potential blocksize. * * @return outgoing block size setting - * @see APDU.setOutgoingLength(short) + * @see #setOutgoingLength(short) */ public static short getOutBlockSize() { - return T0_OBS; + return (getProtocol() & PROTOCOL_T1) == PROTOCOL_T1 ? T1_BLOCK_SIZE : T0_OBS; } /** @@ -316,7 +344,8 @@ public static short getOutBlockSize() { * @see PROTOCOL_T0 */ public static byte getProtocol() { - return PROTOCOL_T0; + APDU apdu = SimulatorSystem.instance().getCurrentAPDU(); + return (byte) apdu.ramVars[ACTIVE_PROTOCOL]; } /** @@ -331,17 +360,27 @@ public byte getNAD() { /** * This method is used to set the data transfer direction to - * outbound and to obtain the expected length of response (Le). - *

    Notes. - *

      + * outbound and to obtain the expected length of response (Le). This method + * should only be called on a case 2 or case 4 command, otherwise erroneous + * behavior may result. + *

      Notes.

        + *
      • On a case 4 command, the setIncomingAndReceive() must + * be invoked prior to calling this method. Otherwise, erroneous + * behavior may result in T=0 protocol. *
      • Any remaining incoming data will be discarded. - *
      • In T=0 (Case 4) protocol, this method will return 256. - *
      • This method sets the state of the APDU object to - * STATE_OUTGOING. + *
      • In T=0 (Case 4S) protocol, this method will return 256 with normal + * semantics. + *
      • In T=0 (Case 2E, 4S) protocol, this method will return 32767 when + * the currently selected applet implements the + * javacardx.apdu.ExtendedLength interface. + *
      • In T=1 (Case 2E, 4E) protocol, this method will return 32767 when the + * Le field in the APDU command is 0x0000 and the currently selected applet implements the + * javacardx.apdu.ExtendedLength interface. + *
      • This method sets the state of the APDU object to + * STATE_OUTGOING. *
      * @return Le, the expected length of response - * @throws APDUException with the following reason codes: - *
        + * @throws APDUException with the following reason codes:
          *
        • APDUException.ILLEGAL_USE if this method, or setOutgoingNoChaining() method already invoked. *
        • APDUException.IO_ERROR on I/O error. *
        @@ -359,27 +398,35 @@ public short setOutgoing() /** * This method is used to set the data transfer direction to * outbound without using BLOCK CHAINING (See ISO 7816-3/4) and to obtain the expected length of response (Le). - * This method should be used in place of the setOutgoing() method by applets which need + * This method should be used in place of the + * setOutgoing() method by applets which need * to be compatible with legacy CAD/terminals which do not support ISO 7816-3/4 defined block chaining. - * See Runtime + * See Runtime Environment * Specification for the Java Card Platform, section 9.4 for details. - *

        Notes. - *

          + *

          Notes.

            + *
          • On a case 4 command, the setIncomingAndReceive() must + * be invoked prior to calling this method. Otherwise, erroneous + * behavior may result in T=0 protocol. *
          • Any remaining incoming data will be discarded. - *
          • In T=0 (Case 4) protocol, this method will return 256. + *
          • In T=0 (Case 4S) protocol, this method will return 256 with normal + * semantics. + *
          • In T=0 (Case 2E, 4S) protocol, this method will return 256 when + * the currently selected applet implements the + * javacardx.apdu.ExtendedLength interface. *
          • When this method is used, the waitExtension() method cannot be used. *
          • In T=1 protocol, retransmission on error may be restricted. *
          • In T=0 protocol, the outbound transfer must be performed - * without using (ISO7816.SW_BYTES_REMAINING_00+count) response status chaining. + * without using (ISO7816.SW_BYTES_REMAINING_00+count) response status chaining. *
          • In T=1 protocol, the outbound transfer must not set the More(M) Bit in the PCB of the I block. See ISO 7816-3. - *
          • This method sets the state of the APDU object to - * STATE_OUTGOING. + *
          • This method sets the state of the APDU object to + * STATE_OUTGOING. *
          + * * @return Le, the expected length of response data - * @throws APDUException with the following reason codes: - *
            - *
          • APDUException.ILLEGAL_USE if this method, or setOutgoing() method already invoked. - *
          • APDUException.IO_ERROR on I/O error
          + * @throws APDUException with the following reason codes:
            + *
          • APDUException.ILLEGAL_USE if this method, or setOutgoingNoChaining() method already invoked. + *
          • APDUException.IO_ERROR on I/O error. + *
          */ public short setOutgoingNoChaining() throws APDUException { @@ -393,45 +440,50 @@ public short setOutgoingNoChaining() } /** - * Sets the actual length of response data. If a length of 0 is specified, no data will be output. + * Sets the actual length of response data. If a length of + * 0 is specified, no data will be output. *

          Note:

            - *
          • In T=0 (Case 2&4) protocol, the length is used by the Java Card runtime environment to prompt the CAD for GET RESPONSE commands. - *
          • This method sets the state of the APDU object to + *
          • In T=0 (Case 2&4) protocol, the length is used by the Java Card runtime environment to prompt the CAD for GET RESPONSE commands. + *
          • This method sets the state of the + * APDU object to * STATE_OUTGOING_LENGTH_KNOWN. *
          + *

          + * * @param len the length of response data - * @throws APDUException with the following reason codes: - *

            - *
          • APDUException.ILLEGAL_USE if setOutgoing() not called or this method already invoked. - *
          • APDUException.BAD_LENGTH if len is greater than 256 or - * if non BLOCK CHAINED data transfer is requested and len is greater than - * (IFSD-2), where IFSD is the Outgoing Block Size. The -2 accounts for the status bytes in T=1. - * *
          • APDUException.NO_GETRESPONSE if T=0 protocol is in use and - * the CAD does not respond to (ISO7816.SW_BYTES_REMAINING_00+count) response status - * with GET RESPONSE command on the same origin logical channel number as that of the current - * APDU command. - *
          • APDUException.NO_T0_REISSUE if T=0 protocol is in use and - * the CAD does not respond to (ISO7816.SW_CORRECT_LENGTH_00+count) response status - * by re-issuing same APDU command on the same origin logical channel number as that of the current - * APDU command with the corrected length. + * @throws APDUException with the following reason codes:
              + *
            • APDUException.ILLEGAL_USE if setOutgoing() or setOutgoingNoChaining() not called + * or if setOutgoingAndSend() already invoked, or this method already invoked. + *
            • APDUException.BAD_LENGTH if any one of the following is true:
                + *
              • len is negative. + *
              • len is greater than 256 and the currently selected applet does not implement the javacardx.apdu.ExtendedLength interface. + *
              • T=0 protocol is in use, non BLOCK CHAINED data transfer is requested and len is greater than 256. + *
              • T=1 protocol is in use, non BLOCK CHAINED data transfer is requested and len is greater than (IFSD-2), where IFSD is the Outgoing Block Size. The -2 accounts for the status bytes in T=1. + *
              + *
            • APDUException.NO_T0_GETRESPONSE if T=0 protocol is in use and the CAD does not respond to (ISO7816.SW_BYTES_REMAINING_00+count) response status + * with GET RESPONSE command on the same origin logical channel number as that of the current APDU command. + *
            • APDUException.NO_T0_REISSUE if T=0 protocol + * is in use and the CAD does not respond to (ISO7816.SW_CORRECT_LENGTH_00+count) response status by re-issuing same APDU command on the same origin + * logical channel number as that of the current APDU command with the corrected length. *
            • APDUException.IO_ERROR on I/O error. *
            - * @see APDU.getOutBlockSize() + * @see #getOutBlockSize() */ public void setOutgoingLength(short len) throws APDUException { + final short max = extended ? Short.MAX_VALUE : T0_OBS; if (!flags[OUTGOING_FLAG]) { APDUException.throwIt(APDUException.ILLEGAL_USE); } if (flags[OUTGOING_LEN_SET_FLAG]) { APDUException.throwIt(APDUException.ILLEGAL_USE); } - if (len > 255 || len < 0) { + if (len > max || len < 0) { APDUException.throwIt(APDUException.BAD_LENGTH); } flags[OUTGOING_LEN_SET_FLAG] = true; ramVars[CURRENT_STATE] = STATE_OUTGOING_LENGTH_KNOWN; - ramVars[LR] = (byte) len; + ramVars[LR] = len; } public short receiveBytes(short bOff) @@ -439,13 +491,13 @@ public short receiveBytes(short bOff) if (!flags[INCOMING_FLAG] || flags[OUTGOING_FLAG]) { APDUException.throwIt(APDUException.ILLEGAL_USE); } - short Lc = (short) (ramVars[LC] & 0xff); - if (bOff < 0 || Lc >= 1 && (short) (bOff + 1) > 260) { + short Lc = ramVars[LC]; + if (bOff < 0 || Lc >= 1 && (bOff + 1) > buffer.length) { APDUException.throwIt(APDUException.BUFFER_BOUNDS); } short pre = (short) (ramVars[PRE_READ_LENGTH] & 0xff); if (pre != 0) { - ramVars[PRE_READ_LENGTH]=(byte) 0; + ramVars[PRE_READ_LENGTH] = 0; if (Lc == 0) { ramVars[CURRENT_STATE]= STATE_FULL_INCOMING; } else { @@ -454,12 +506,9 @@ public short receiveBytes(short bOff) return pre; } if (Lc != 0) { - short len = 0; - if(buffer[ISO7816.OFFSET_LC] != 0) { - len = buffer[ISO7816.OFFSET_LC]; - } + short len = getIncomingLength(); Lc -= len; - ramVars[LC] = (byte) Lc; + ramVars[LC] = Lc; if (Lc == 0) { ramVars[CURRENT_STATE]= STATE_FULL_INCOMING; } else { @@ -476,17 +525,19 @@ public short receiveBytes(short bOff) * This is the primary receive method. * Calling this method indicates that this APDU has incoming data. This method gets as many bytes * as will fit without buffer overflow in the APDU buffer following the header. - * It gets all the incoming bytes if they fit. + * It gets all the incoming bytes if they fit.

            + * This method should only be called on a case 3 or case 4 command, otherwise erroneous behavior may result. *

            Notes: *

              - *
            • In T=0 ( Case 3&4 ) protocol, the P3 param is assumed to be Lc. - *
            • Data is read into the buffer at offset 5. + *
            • In T=0 ( Case 3&4 ) protocol, the P3 param is assumed to be Lc. + *
            • Data is read into the buffer at offset 5 for normal APDU semantics. + *
            • Data is read into the buffer at offset 7 for an extended length APDU (Case 3E/4E). *
            • In T=1 protocol, if all the incoming bytes do not fit in the buffer, this method may * return less bytes than the maximum incoming block size (IFSC). *
            • In T=0 protocol, if all the incoming bytes do not fit in the buffer, this method may * return less than a full buffer of bytes to optimize and reduce protocol overhead. *
            • This method sets the transfer direction to be inbound - * and calls receiveBytes(5). + * and calls receiveBytes(5) for normal semantics or receiveBytes(7) for extended semantics. *
            • This method may only be called once in a Applet.process() method. *
            • This method sets the state of the APDU object to * STATE_PARTIAL_INCOMING if all incoming bytes are not received. @@ -511,16 +562,19 @@ public short setIncomingAndReceive() APDUException.throwIt(APDUException.ILLEGAL_USE); } flags[INCOMING_FLAG] = true; - byte Lc = (byte) (buffer[ISO7816.OFFSET_LC]); + short Lc = (short) (0xFF & buffer[ISO7816.OFFSET_LC]); + if (extended) { + Lc = Util.getShort(buffer, (short) (ISO7816.OFFSET_LC + 1)); + } ramVars[LC] = Lc; - ramVars[LE] = (byte) 0; } - return receiveBytes(ISO7816.OFFSET_CDATA); + return receiveBytes(getOffsetCdata()); } public void sendBytes(short bOff, short len) throws APDUException { - if (bOff < 0 || len < 0 || (short) (bOff + len) > 255) { + final short max = extended ? Short.MAX_VALUE : T0_OBS; + if (bOff < 0 || len < 0 || (short) (bOff + len) > max) { APDUException.throwIt(APDUException.BUFFER_BOUNDS); } if (!flags[OUTGOING_LEN_SET_FLAG] || flags[NO_GET_RESPONSE_FLAG]) { @@ -529,24 +583,20 @@ public void sendBytes(short bOff, short len) if (len == 0) { return; } - short Lr = getLr(); + short Lr = ramVars[LR]; if (len > Lr) { APDUException.throwIt(APDUException.ILLEGAL_USE); } - short Le = getLe(); - SimulatorSystem.sendAPDU(buffer, bOff, len); + SimulatorSystem.instance().sendAPDU(buffer, bOff, len); - bOff += len; Lr -= len; - Le = Lr; - if (Lr == 0) { ramVars[CURRENT_STATE] = STATE_FULL_OUTGOING; } else { ramVars[CURRENT_STATE] = STATE_PARTIAL_OUTGOING; } - ramVars[LE] = (byte) Le; - ramVars[LR] = (byte) Lr; + + ramVars[LR] = Lr; } /** @@ -651,13 +701,13 @@ public void setOutgoingAndSend(short bOff, short len) * @return the current processing state of the APDU */ public byte getCurrentState() { - return ramVars[CURRENT_STATE]; + return (byte) ramVars[CURRENT_STATE]; } /** - * This method is called to obtain a reference to the current APDU object. - * This method can only be called in the context of the currently - * selected applet. + * This method is called during the Applet.process(APDU) method + * to obtain a reference to the current APDU object. + * This method can only be called in the context of the currently selected applet. *

              Note: *

                *
              • Do not call this method directly or indirectly from within a method @@ -676,14 +726,17 @@ public byte getCurrentState() { */ public static APDU getCurrentAPDU() throws SecurityException { - return thisAPDU; + APDU currentAPDU = SimulatorSystem.instance().getCurrentAPDU(); + if (!currentAPDU.flags[ACCESS_ALLOWED_FLAG]) { + throw new SecurityException("getCurrentAPDU must not be called outside of Applet#process()"); + } + return currentAPDU; } /** - * This method is called to obtain a reference to the current - * APDU buffer. - * This method can only be called in the context of the currently - * selected applet. + * This method is called during the Applet.process(APDU) method + * to obtain a reference to the current APDU object. + * This method can only be called in the context of the currently selected applet. *

                Note:

                  *
                • Do not call this method directly or indirectly from within a method * invoked remotely via Java Card RMI method invocation from the client. The @@ -701,22 +754,22 @@ public static APDU getCurrentAPDU() */ public static byte[] getCurrentAPDUBuffer() throws SecurityException { - return thisAPDU.getBuffer(); + return getCurrentAPDU().getBuffer(); } /** * Returns the logical channel number associated with the current APDU command - * based on the CLA byte. A number in the range 0-3 based on the least - * significant two bits of the CLA byte is returned if the command contains - * logical channel encoding. If the command does not contain logical channel - * information, 0 is returned. + * based on the CLA byte. A number in the range 0-19 based on the CLA byte encoding + * is returned if the command contains logical channel encoding. + * If the command does not contain logical channel information, 0 is returned. * See Runtime * Specification for the Java Card Platform, section * 4.3 for encoding details. * @return logical channel number, if present, within the CLA byte, 0 otherwise */ public static byte getCLAChannel() { - return thisAPDU.ramVars[LOGICAL_CHN]; + APDU apdu = SimulatorSystem.instance().getCurrentAPDU(); + return (byte) apdu.ramVars[LOGICAL_CHN]; } /** @@ -736,32 +789,152 @@ public static byte getCLAChannel() { */ public static void waitExtension() throws APDUException { - if (thisAPDU.flags[NO_CHAINING_FLAG]) { - APDUException.throwIt((short) 1); + APDU apdu = SimulatorSystem.instance().getCurrentAPDU(); + if (!apdu.flags[ACCESS_ALLOWED_FLAG] || apdu.flags[NO_CHAINING_FLAG]) { + APDUException.throwIt(APDUException.ILLEGAL_USE); } } - // return Le variable - private short getLe() { - if (ramVars[LE] == 0) { - return 256; - } else { - return (short) (ramVars[LE] & 0xff); + /** + * Returns whether the current + * APDU command is the first or + * part of a command chain. Bit b5 of the CLA byte if set, indicates + * that the + * APDU is the first or part of a chain of commands. + * See Runtime Environment Specification for the Java Card Platform, section 4.3 for encoding details. + * @return true if this APDU is not the last APDU of a command chain, false otherwise. + * @since 2.2.2 + */ + @SuppressWarnings("unused") + public boolean isCommandChainingCLA() { + return (buffer[ISO7816.OFFSET_CLA] & 0x10) == 0x10; + } + + /** + * Returns + * true if the encoding of the current + * APDU + * command based on the + * CLA byte indicates secure messaging. The secure messaging information + * is in bits (b4,b3) for commands with origin channel numbers 0-3, and in bit + * b6 for origin channel numbers 4-19. + * See Runtime Environment Specification for the Java Card Platform, section 4.3 for encoding details. + * @return true if the secure messaging bit(s) is(are) nonzero, false otherwise + * @since 2.2.2 + */ + @SuppressWarnings("unused") + public boolean isSecureMessagingCLA() { + return (buffer[ISO7816.OFFSET_CLA] & 0x40) == 0x40 ? (buffer[ISO7816.OFFSET_CLA] & 0x20) == 0x20 : (buffer[ISO7816.OFFSET_CLA] & 0x0C) != 0; + + } + + /** + * Returns whether the current + * APDU command CLA byte corresponds + * to an interindustry command as defined in ISO 7816-4:2005 specification. + * Bit b8 of the CLA byte if + * 0, indicates that the + * APDU + * is an interindustry command. + * @return true if this APDU CLA byte corresponds to an interindustry command, false otherwise. + * @since 2.2.2 + */ + @SuppressWarnings("unused") + public boolean isISOInterindustryCLA() { + return (buffer[ISO7816.OFFSET_CLA]& 0x80) != 0x80; + } + + /** + * Returns the incoming data length(Lc). This method can be invoked + * whenever inbound data processing methods can be invoked during case 1, 3 or 4 + * processing. It is most useful for an extended length enabled applet to avoid + * parsing the variable length Lc format in the APDU header. + * @return the incoming byte length indicated by the Lc field in the APDU header. Return 0 if no incoming data (Case 1) + * @throws APDUException with the following reason codes:
                    + *
                  • APDUException.ILLEGAL_USE if setIncomingAndReceive() not called + * or if setOutgoing() or setOutgoingNoChaining() previously invoked. + *
                  + * @see #getOffsetCdata() + * @since 2.2.2 + */ + public short getIncomingLength() { + if (!flags[INCOMING_FLAG] || flags[OUTGOING_FLAG]) { + throw new APDUException(APDUException.ILLEGAL_USE); + } + return internalGetIncomingLength(); + } + + private short internalGetIncomingLength() { + if (extended) { + return Util.getShort(buffer, (short) (ISO7816.OFFSET_LC + 1)); + } + return buffer[ISO7816.OFFSET_LC]; + } + + /** + * Returns the offset within the APDU buffer for incoming command data. + * This method can be invoked whenever inbound data processing methods can be + * invoked during case 1, 3 or 4 processing. It is most useful for an extended + * length enabled applet to avoid parsing the variable length Lc format in the + * APDU header. + * + * @return the offset within the APDU buffer for incoming command data from the previous call to setIncomingAndReceive() method. The value returned is either 5 (Lc is 1 byte), or 7 (when Lc is 3 bytes) + * @throws APDUException with the following reason codes:
                    + *
                  • APDUException.ILLEGAL_USE if setIncomingAndReceive() not called + * or if setOutgoing() or setOutgoingNoChaining() previously invoked. + *
                  + * @see #getIncomingLength() + * @since 2.2.2 + */ + public short getOffsetCdata() { + if (!flags[INCOMING_FLAG] || flags[OUTGOING_FLAG]) { + throw new APDUException(APDUException.ILLEGAL_USE); } + return internalGetOffsetCdata(); } - // return Lr variable - private short getLr() { - return (short) (ramVars[LR] & 0xff); + private short internalGetOffsetCdata() { + if (extended) { + return ISO7816.OFFSET_CDATA + 2; + } + return ISO7816.OFFSET_CDATA; + } + + // return Le variable + private short getLe() { + short le = ramVars[LE]; + if (le == 0) { + return extended ? Short.MAX_VALUE : 256; + } + return le; } /** * clear internal state of the APDU + * called by SimulatorRuntime via reflection */ - public void reset(){ - Util.arrayFillNonAtomic(buffer, (short)0, (short) buffer.length, (byte)0); - Util.arrayFillNonAtomic(ramVars, (short)0, (short) ramVars.length, (byte)0); + private void internalReset(byte protocol, byte[] inputBuffer) { + if (inputBuffer == null) { + flags[ACCESS_ALLOWED_FLAG] = false; + ramVars[ACTIVE_PROTOCOL] = protocol; + return; + } + + Arrays.fill(buffer, (byte) 0); + Arrays.fill(ramVars, (short) 0); + System.arraycopy(inputBuffer, 0, buffer, 0, inputBuffer.length); for(byte i=0;i response status to send additional data. The outgoing + * command in response to a <61xx> response status to send additional data. The outgoing * transfer has been aborted. No more data or status can be sent to the CAD * in this Applet.process() method. */ @@ -65,7 +65,7 @@ public class APDUException extends CardRuntimeException { public static final short T1_IFD_ABORT = 171; /** * This reason code indicates that during T=0 protocol, the CAD did not reissue the - * same APDU command with the corrected length in response to a <6Cxx> response status + * same APDU command with the corrected length in response to a <6Cxx> response status * to request command reissue with the specified length. The outgoing * transfer has been aborted. No more data or status can be sent to the CAD * in this Applet.process() method diff --git a/src/main/java/javacard/framework/Applet.java b/src/main/java/javacard/framework/Applet.java index e3c4cd21..ec54a65a 100644 --- a/src/main/java/javacard/framework/Applet.java +++ b/src/main/java/javacard/framework/Applet.java @@ -16,6 +16,7 @@ package javacard.framework; import com.licel.jcardsim.base.SimulatorSystem; +import com.licel.jcardsim.utils.BiConsumer; /** * This abstract class defines an Java Card technology-based applet. @@ -23,7 +24,10 @@ * The Applet class must be extended by any applet that is intended to be * loaded onto, installed into and executed on a Java Card technology-compliant * smart card.

                  - * + * A compliant Java Card platform may optionally support the ISO7816-4 defined extended + * length APDU protocol. The applet subclass must implement the + * javacardx.apdu.ExtendedLength interface to access this extended length APDU + * protocol capability of the javacard.framework.APDU object. *

                  * Example usage of Applet *

                  
                  @@ -63,7 +67,7 @@
                    *             // send response data to select command
                    *             short Le =  apdu.setOutgoing();
                    *             // assume data containing response bytes in replyData[] array.
                  - *             if ( Le < ..) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH);
                  + *             if ( Le < ..) ISOException.throwIt( ISO7816.SW_WRONG_LENGTH);
                    *             apdu.setOutgoingLength( (short)replyData.length );
                    *             apdu.sendBytesLong(replyData, (short) 0, (short)replyData.length);
                    *             break;
                  @@ -78,6 +82,11 @@
                    * @see SystemException
                    */
                   public abstract class Applet {
                  +    /**
                  +     * The current registration callback, set by SimulatorRuntime via reflection.
                  +     */
                  +    private static final ThreadLocal> registrationCallback
                  +            = new ThreadLocal>();
                   
                       /**
                        * Only this class's install() method should create the applet object.
                  @@ -145,9 +154,9 @@ public static void install(byte bArray[], short bOffset, byte bLength)
                        * method the Java Card runtime environment sends the ISO 7816-4 defined success status (90 00) in APDU response.
                        * If this method throws an ISOException the Java Card runtime environment sends the associated reason code as the
                        * response status instead.

                  - * The Java Card runtime environment zeroes out the APDU buffer before receiving a new APDU command from the CAD. - * The five header bytes of the APDU command are available in APDU buffer[0..4] at the time - * this method is called.

                  + * The Java Card runtime environment zeroes out the APDU buffer before receiving a new APDU command from the CAD. + * The five header bytes (or optionally the 7 extended header bytes) of the APDU command are available + * in APDU buffer at the time this method is called.

                  * The APDU object parameter is a temporary Java Card runtime environment Entry Point Object. * A temporary Java Card runtime environment Entry Point Object can be accessed from any applet context. References * to these temporary objects cannot be stored in class variables or instance variables @@ -260,7 +269,13 @@ public Shareable getShareableInterfaceObject(AID clientAID, byte parameter) { */ protected final void register() throws SystemException { - SimulatorSystem.registerApplet(this); + BiConsumer callback = registrationCallback.get(); + if (callback == null) { // not called from install() + SystemException.throwIt(SystemException.ILLEGAL_AID); + } + else { + callback.accept(this, null); + } } /** @@ -287,9 +302,13 @@ protected final void register() protected final void register(byte bArray[], short bOffset, byte bLength) throws SystemException { if (bLength < 5 || bLength > 16) { - SystemException.throwIt(SystemException.ILLEGAL_VALUE); + throw new SystemException(SystemException.ILLEGAL_VALUE); + } + BiConsumer callback = registrationCallback.get(); + if (callback == null) { // not called from install() + throw new SystemException(SystemException.ILLEGAL_AID); } - SimulatorSystem.registerApplet(this, bArray, bOffset, bLength); + callback.accept(this, new AID(bArray, bOffset, bLength)); } /** @@ -299,6 +318,6 @@ protected final void register(byte bArray[], short bOffset, byte bLength) * @return true if this applet is being selected */ protected final boolean selectingApplet() { - return SimulatorSystem.isAppletSelecting(this); + return SimulatorSystem.instance().isAppletSelecting(this); } } diff --git a/src/main/java/javacard/framework/CardException.java b/src/main/java/javacard/framework/CardException.java index b7e25a9b..36c46269 100644 --- a/src/main/java/javacard/framework/CardException.java +++ b/src/main/java/javacard/framework/CardException.java @@ -30,7 +30,7 @@ */ public class CardException extends Exception { - private byte theSw[]; + private short reason; /** * Construct a CardException instance with the specified reason. @@ -39,8 +39,7 @@ public class CardException extends Exception { * @param reason the reason for the exception */ public CardException(short reason) { - theSw = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); - Util.setShort(theSw, (short) 0, reason); + this.reason = reason; } /** @@ -48,7 +47,7 @@ public CardException(short reason) { * @return the reason for the exception */ public short getReason() { - return Util.getShort(theSw, (short) 0); + return reason; } /** @@ -56,8 +55,7 @@ public short getReason() { * @param reason the reason for the exception */ public void setReason(short reason) { - Util.arrayFillNonAtomic(theSw, (short) 0, (short) 1, (byte) (reason >>> 8)); - Util.arrayFillNonAtomic(theSw, (short) 1, (short) 1, (byte) reason); + this.reason = reason; } /** diff --git a/src/main/java/javacard/framework/CardRuntimeException.java b/src/main/java/javacard/framework/CardRuntimeException.java index 351e67af..fff37922 100644 --- a/src/main/java/javacard/framework/CardRuntimeException.java +++ b/src/main/java/javacard/framework/CardRuntimeException.java @@ -29,7 +29,7 @@ */ public class CardRuntimeException extends RuntimeException { - private byte theSw[]; + private short reason; /** * Constructs a CardRuntimeException instance with the specified reason. @@ -38,8 +38,7 @@ public class CardRuntimeException extends RuntimeException { * @param reason the reason for the exception */ public CardRuntimeException(short reason) { - theSw = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); - Util.setShort(theSw, (short) 0, reason); + this.reason = reason; } /** @@ -47,7 +46,7 @@ public CardRuntimeException(short reason) { * @return the reason for the exception */ public short getReason() { - return Util.getShort(theSw, (short) 0); + return reason; } /** @@ -55,8 +54,7 @@ public short getReason() { * @param reason the reason for the exception */ public void setReason(short reason) { - Util.arrayFillNonAtomic(theSw, (short) 0, (short) 1, (byte) (reason >>> 8)); - Util.arrayFillNonAtomic(theSw, (short) 1, (short) 1, (byte) reason); + this.reason = reason; } /** diff --git a/src/main/java/javacard/framework/ISO7816.java b/src/main/java/javacard/framework/ISO7816.java index 937df31b..27b95b32 100644 --- a/src/main/java/javacard/framework/ISO7816.java +++ b/src/main/java/javacard/framework/ISO7816.java @@ -21,7 +21,7 @@ * ISO7816 interface contains only static fields.

                  * The static fields with SW_ prefixes define constants for the ISO 7816-4 defined response * status word. The fields which use the _00 suffix require the low order byte to be - * customized appropriately e.g (ISO7816.SW_CORRECT_LENGTH_00 + (0x0025 & 0xFF)).

                  + * customized appropriately e.g (ISO7816.SW_CORRECT_LENGTH_00 + (0x0025 & 0xFF)).

                  * The static fields with OFFSET_ prefixes define constants to be used to index into * the APDU buffer byte array to access ISO 7816-4 defined header information. * @@ -37,7 +37,7 @@ public interface ISO7816 */ public static final short SW_BYTES_REMAINING_00 = 24832; /** - * >Response status : Wrong length = 0x6700 + * Response status : Wrong length = 0x6700 */ public static final short SW_WRONG_LENGTH = 26368; /** @@ -100,6 +100,14 @@ public interface ISO7816 * Response status : CLA value not supported = 0x6E00 */ public static final short SW_CLA_NOT_SUPPORTED = 28160; + /** + * Response status : Command chaining not supported = 0x6884 + */ + static final short SW_COMMAND_CHAINING_NOT_SUPPORTED=26756; + /** + * Response status : Last command in chain expected = 0x6883 + */ + static final short SW_LAST_COMMAND_EXPECTED=26755; /** * Response status : No precise diagnosis = 0x6F00 */ @@ -109,7 +117,7 @@ public interface ISO7816 */ public static final short SW_FILE_FULL = 27268; /** - * Response status : Card does not support logical channels = 0x6881 + * Response status : Card does not support the operation on the specified logical channel = 0x6881 */ public static final short SW_LOGICAL_CHANNEL_NOT_SUPPORTED = 26753; /** diff --git a/src/main/java/javacard/framework/JCSystem.java b/src/main/java/javacard/framework/JCSystem.java index 45236700..d19d22a2 100644 --- a/src/main/java/javacard/framework/JCSystem.java +++ b/src/main/java/javacard/framework/JCSystem.java @@ -41,7 +41,6 @@ * is written or nothing at all is written. * The JCSystem includes methods to control an atomic transaction. * See Runtime Environment Specification for the Java Card Platform for details. - *

                  * */ public final class JCSystem { @@ -80,21 +79,15 @@ public final class JCSystem { *

                */ public static final byte CLEAR_ON_DESELECT = 2; - // implementaion api version + // implementation api version private static final short API_VERSION = 0x0202; - // APDU for I/O - private static APDU apdu; - - static { - apdu = new APDU(); - } /** * Checks if the specified object is transient. *

                Note: *

                  - * This method returns NOT_A_TRANSIENT_OBJECT if the specified object is - * null or is not an array type. + *
                • This method returns NOT_A_TRANSIENT_OBJECT if the specified object is + * null or is not an array type.
                • *
                * @param theObj the object being queried * @return NOT_A_TRANSIENT_OBJECT, CLEAR_ON_RESET, or CLEAR_ON_DESELECT @@ -104,7 +97,7 @@ public final class JCSystem { * @see #makeTransientShortArray(short, byte) */ public static byte isTransient(Object theObj) { - return SimulatorSystem.isTransient(theObj); + return SimulatorSystem.instance().getTransientMemory().isTransient(theObj); } /** @@ -123,7 +116,7 @@ public static byte isTransient(Object theObj) { */ public static boolean[] makeTransientBooleanArray(short length, byte event) throws NegativeArraySizeException, SystemException { - return SimulatorSystem.makeTransientBooleanArray(length, event); + return SimulatorSystem.instance().getTransientMemory().makeBooleanArray(length, event); } /** @@ -142,7 +135,7 @@ public static boolean[] makeTransientBooleanArray(short length, byte event) */ public static byte[] makeTransientByteArray(short length, byte event) throws NegativeArraySizeException, SystemException { - return SimulatorSystem.makeTransientByteArray(length, event); + return SimulatorSystem.instance().getTransientMemory().makeByteArray(length, event); } /** @@ -161,7 +154,7 @@ public static byte[] makeTransientByteArray(short length, byte event) */ public static short[] makeTransientShortArray(short length, byte event) throws NegativeArraySizeException, SystemException { - return SimulatorSystem.makeTransientShortArray(length, event); + return SimulatorSystem.instance().getTransientMemory().makeShortArray(length, event); } /** @@ -180,7 +173,7 @@ public static short[] makeTransientShortArray(short length, byte event) */ public static Object[] makeTransientObjectArray(short length, byte event) throws NegativeArraySizeException, SystemException { - return SimulatorSystem.makeTransientObjectArray(length, event); + return SimulatorSystem.instance().getTransientMemory().makeObjectArray(length, event); } /** @@ -203,7 +196,7 @@ public static short getVersion() { * @return the AID object */ public static AID getAID() { - return SimulatorSystem.getAID(); + return SimulatorSystem.instance().getAID(); } /** @@ -223,7 +216,7 @@ public static AID getAID() { * or if offset or length are out of range. */ public static AID lookupAID(byte buffer[], short offset, byte length) { - return SimulatorSystem.lookupAID(buffer, offset, length); + return SimulatorSystem.instance().lookupAID(buffer, offset, length); } /** @@ -245,7 +238,7 @@ public static AID lookupAID(byte buffer[], short offset, byte length) { */ public static void beginTransaction() throws TransactionException { - SimulatorSystem.beginTransaction(); + SimulatorSystem.instance().beginTransaction(); } /** @@ -274,7 +267,7 @@ public static void beginTransaction() */ public static void abortTransaction() throws TransactionException { - SimulatorSystem.abortTransaction(); + SimulatorSystem.instance().abortTransaction(); } /** @@ -297,7 +290,7 @@ public static void abortTransaction() */ public static void commitTransaction() throws TransactionException { - SimulatorSystem.commitTransaction(); + SimulatorSystem.instance().commitTransaction(); } /** @@ -306,7 +299,7 @@ public static void commitTransaction() * @return 1 if transaction in progress, 0 if not */ public static byte getTransactionDepth() { - return SimulatorSystem.getTransactionDepth(); + return SimulatorSystem.instance().getTransactionDepth(); } /** @@ -319,7 +312,7 @@ public static byte getTransactionDepth() { * @see #getMaxCommitCapacity() */ public static short getUnusedCommitCapacity() { - return SimulatorSystem.getUnusedCommitCapacity(); + return SimulatorSystem.instance().getUnusedCommitCapacity(); } /** @@ -340,7 +333,7 @@ public static short getUnusedCommitCapacity() { * @see #getUnusedCommitCapacity() */ public static short getMaxCommitCapacity() { - return SimulatorSystem.getMaxCommitCapacity(); + return SimulatorSystem.instance().getMaxCommitCapacity(); } /** @@ -355,7 +348,7 @@ public static short getMaxCommitCapacity() { * @return the AID object of the previous context, or null if Java Card runtime environment */ public static AID getPreviousContextAID() { - return SimulatorSystem.getPreviousContextAID(); + return SimulatorSystem.instance().getPreviousContextAID(); } /** @@ -387,13 +380,13 @@ public static short getAvailableMemory(byte memoryType) throws SystemException { switch (memoryType) { case MEMORY_TYPE_PERSISTENT: - return SimulatorSystem.getAvailablePersistentMemory(); + return SimulatorSystem.instance().getAvailablePersistentMemory(); case MEMORY_TYPE_TRANSIENT_RESET: - return SimulatorSystem.getAvailableTransientResetMemory(); + return SimulatorSystem.instance().getAvailableTransientResetMemory(); case MEMORY_TYPE_TRANSIENT_DESELECT: - return SimulatorSystem.getAvailableTransientDeselectMemory(); + return SimulatorSystem.instance().getAvailableTransientDeselectMemory(); } SystemException.throwIt(SystemException.ILLEGAL_VALUE); return 0; @@ -411,10 +404,10 @@ public static short getAvailableMemory(byte memoryType) * @param serverAID the AID of the server applet * @param parameter optional parameter data * @return the shareable interface object or null - * @see Applet.getShareableInterfaceObject(AID, byte) + * @see Applet#getShareableInterfaceObject(AID, byte) */ public static Shareable getAppletShareableInterfaceObject(AID serverAID, byte parameter) { - return SimulatorSystem.getSharedObject(serverAID, parameter); + return SimulatorSystem.instance().getSharedObject(serverAID, parameter); } /** @@ -423,7 +416,7 @@ public static Shareable getAppletShareableInterfaceObject(AID serverAID, byte pa * @return true if the object deletion mechanism is supported, false otherwise */ public static boolean isObjectDeletionSupported() { - return SimulatorSystem.isObjectDeletionSupported(); + return SimulatorSystem.instance().isObjectDeletionSupported(); } /** @@ -444,10 +437,11 @@ public static boolean isObjectDeletionSupported() { * @throws SystemException with the following reason codes:
                  *
                • SystemException.ILLEGAL_USE if the object deletion mechanism is * not implemented. + *
                */ public static void requestObjectDeletion() throws SystemException { - SimulatorSystem.requestObjectDeletion(); + SimulatorSystem.instance().requestObjectDeletion(); } /** @@ -465,7 +459,7 @@ public static void requestObjectDeletion() * currently selected applet instance */ public static byte getAssignedChannel() { - return SimulatorSystem.getCurrentlySelectedChannel(); + return SimulatorSystem.instance().getAssignedChannel(); } /** @@ -481,6 +475,8 @@ public static byte getAssignedChannel() { * AID parameter is currently active on this or another logical channel */ public static boolean isAppletActive(AID theApplet) { - return SimulatorSystem.isAppletActive(theApplet); + return (theApplet == SimulatorSystem.instance().getAID()); } + + private JCSystem() {} } diff --git a/src/main/java/javacard/framework/MultiSelectable.java b/src/main/java/javacard/framework/MultiSelectable.java index 52dc7b38..c0a8ba6a 100644 --- a/src/main/java/javacard/framework/MultiSelectable.java +++ b/src/main/java/javacard/framework/MultiSelectable.java @@ -61,8 +61,9 @@ public interface MultiSelectable *
              • The javacard.framework.Applet.select() method is not * called if this method is invoked.
              • *
              - * @param appInstStillActive boolean flag is true when the same applet + * @param appInstAlreadyActive boolean flag is true when the same applet * instance is already active on another logical channel and false otherwise + * @return true to indicate success, false otherwise */ public abstract boolean select(boolean appInstAlreadyActive); diff --git a/src/main/java/javacard/framework/OwnerPIN.java b/src/main/java/javacard/framework/OwnerPIN.java index cbac40dd..0be57011 100644 --- a/src/main/java/javacard/framework/OwnerPIN.java +++ b/src/main/java/javacard/framework/OwnerPIN.java @@ -59,8 +59,8 @@ public class OwnerPIN implements PIN { /** * Constructor. Allocates a new PIN instance with validated flag * set to false - * @param tryLimit the maximum number of times an incorrect PIN can be presented. tryLimit must be >=1 - * @param maxPINSize the maximum allowed PIN size. maxPINSize must be >=1 + * @param tryLimit the maximum number of times an incorrect PIN can be presented. tryLimit must be >=1 + * @param maxPINSize the maximum allowed PIN size. maxPINSize must be >=1 * @throws PINException with the following reason codes: *
                *
              • PINException.ILLEGAL_VALUE if tryLimit parameter is less than 1. diff --git a/src/main/java/javacard/framework/Util.java b/src/main/java/javacard/framework/Util.java index a09176f7..ed4039c4 100644 --- a/src/main/java/javacard/framework/Util.java +++ b/src/main/java/javacard/framework/Util.java @@ -47,7 +47,7 @@ public class Util { *
              • If destOff+length is greater than dest.length, the length * of the dest array an ArrayIndexOutOfBoundsException exception is thrown * and no copy is performed.
              • - *
              • If src or dest parameter is null
              • + *
              • If src or dest parameter is null * a NullPointerException exception is thrown.
              • *
              • If the src and dest arguments refer to the same array object, * then the copying is performed as if the components at positions srcOff @@ -68,7 +68,7 @@ public class Util { * @throws ArrayIndexOutOfBoundsException if copying would cause access of data outside array bounds * @throws NullPointerException if either src or dest is null * @throws TransactionException f copying would cause the commit capacity to be exceeded - * @see JCSystem.getUnusedCommitCapacity() + * @see JCSystem#getUnusedCommitCapacity() */ public static final short arrayCopy(byte src[], short srcOff, byte dest[], short destOff, short length) throws ArrayIndexOutOfBoundsException, NullPointerException, TransactionException { @@ -114,7 +114,7 @@ public static final short arrayCopy(byte src[], short srcOff, byte dest[], short * @throws ArrayIndexOutOfBoundsException if copying would cause access of data outside array bounds * @throws NullPointerException if either src or dest is null * @throws TransactionException f copying would cause the commit capacity to be exceeded - * @see JCSystem.getUnusedCommitCapacity() + * @see JCSystem#getUnusedCommitCapacity() */ public static final short arrayCopyNonAtomic(byte src[], short srcOff, byte dest[], short destOff, short length) throws ArrayIndexOutOfBoundsException, NullPointerException { @@ -147,7 +147,7 @@ public static final short arrayCopyNonAtomic(byte src[], short srcOff, byte dest * @return bOff+bLen * @throws ArrayIndexOutOfBoundsException if the fill operation would cause access of data outside array bounds * @throws NullPointerException if bArray is null - * @see JCSystem.getUnusedCommitCapacity() + * @see JCSystem#getUnusedCommitCapacity() */ public static final short arrayFillNonAtomic(byte bArray[], short bOff, short bLen, byte bValue) throws ArrayIndexOutOfBoundsException, NullPointerException { @@ -155,10 +155,12 @@ public static final short arrayFillNonAtomic(byte bArray[], short bOff, short bL if (bLen < 0) { throw new ArrayIndexOutOfBoundsException(); } - while (bLen-- > 0) { + while (bLen > 0) { bArray[bOff++] = bValue; + bLen--; } - return (short) (bOff + bLen); + // after loop bOff = bOff + bLen + return bOff; } /** @@ -200,7 +202,9 @@ public static final byte arrayCompare(byte src[], short srcOff, byte dest[], sho } for (short i = 0; i < length; i++) { if (src[srcOff + i] != dest[destOff + i]) { - return ((byte) (src[srcOff + i] >= dest[destOff + i] ? 1 : -1)); + short thisSrc = (short) (src[srcOff + i] & 0x00ff); + short thisDest = (short) (dest[destOff + i] & 0x00ff); + return (byte) (thisSrc >= thisDest ? 1 : -1); } } @@ -222,7 +226,7 @@ public static final short makeShort(byte b1, byte b2) { * @param bArray byte array * @param bOff offset within byte array containing first byte (the high order byte) * @return the short value the concatenated result - * @throws ArrayIndexOutOfBoundsException if the bOff parameter is negative or if bOff+1 is greater than the length + * @throws ArrayIndexOutOfBoundsException if the bOff parameter is negative or if bOff+2 is greater than the length of bArray * @throws NullPointerException if the bArray parameter is null */ public static final short getShort(byte bArray[], short bOff) throws ArrayIndexOutOfBoundsException, NullPointerException { @@ -239,11 +243,11 @@ public static final short getShort(byte bArray[], short bOff) throws ArrayIndexO *
              • If the byte array is persistent, this operation is performed atomically. * If the commit capacity is exceeded, no operation is performed and a TransactionException * exception is thrown.
              - * @throws ArrayIndexOutOfBoundsException if the bOff parameter is negative or if bOff+1 is greater than the length + * @throws ArrayIndexOutOfBoundsException if the bOff parameter is negative or if bOff+2 is greater than the length of bArray * of bArray * @throws NullPointerException if the bArray parameter is null * @throws TransactionException if the operation would cause the commit capacity to be exceeded - * @see JCSystem.getUnusedCommitCapacity() + * @see JCSystem#getUnusedCommitCapacity() */ public static final short setShort(byte bArray[], short bOff, short sValue) throws TransactionException, ArrayIndexOutOfBoundsException, NullPointerException { @@ -251,4 +255,6 @@ public static final short setShort(byte bArray[], short bOff, short sValue) bArray[bOff + 1] = (byte) sValue; return (short) (bOff + 2); } + + private Util() {} } diff --git a/src/main/java/javacard/framework/package-info.java b/src/main/java/javacard/framework/package-info.java new file mode 100644 index 00000000..df0bb1e6 --- /dev/null +++ b/src/main/java/javacard/framework/package-info.java @@ -0,0 +1,4 @@ +/** + * JavaCard API. + */ +package javacard.framework; diff --git a/src/main/java/javacard/framework/service/CardRemoteObject.java b/src/main/java/javacard/framework/service/CardRemoteObject.java index 543d543b..97fbfd07 100644 --- a/src/main/java/javacard/framework/service/CardRemoteObject.java +++ b/src/main/java/javacard/framework/service/CardRemoteObject.java @@ -17,6 +17,8 @@ package javacard.framework.service; import java.rmi.Remote; + +import com.licel.jcardsim.base.SimulatorRuntime; import com.licel.jcardsim.base.SimulatorSystem; public class CardRemoteObject implements Remote { @@ -26,16 +28,18 @@ public CardRemoteObject() { } public static void export(Remote obj) throws SecurityException { - if (SimulatorSystem.getJavaContext(SimulatorSystem.getJavaOwner(obj)) != SimulatorSystem - .getJavaContext(SimulatorSystem - .getJavaOwner(SimulatorSystem.previousActiveObject))) - throw SimulatorSystem.securityException; + SimulatorRuntime runtime = SimulatorSystem.instance(); + + if (runtime.getJavaContext(runtime.getJavaOwner(obj)) != + runtime.getJavaContext(runtime.getJavaOwner(runtime.getPreviousActiveObject()))) + throw new SecurityException(); } public static void unexport(Remote obj) throws SecurityException { - if (SimulatorSystem.getJavaContext(SimulatorSystem.getJavaOwner(obj)) != SimulatorSystem - .getJavaContext(SimulatorSystem - .getJavaOwner(SimulatorSystem.previousActiveObject))) - throw SimulatorSystem.securityException; + SimulatorRuntime runtime = SimulatorSystem.instance(); + + if (runtime.getJavaContext(runtime.getJavaOwner(obj)) != + runtime.getJavaContext(runtime.getJavaOwner(runtime.getPreviousActiveObject()))) + throw new SecurityException(); } } diff --git a/src/main/java/javacard/framework/service/Dispatcher.java b/src/main/java/javacard/framework/service/Dispatcher.java index e14981b2..6d799b52 100644 --- a/src/main/java/javacard/framework/service/Dispatcher.java +++ b/src/main/java/javacard/framework/service/Dispatcher.java @@ -39,9 +39,9 @@ public class Dispatcher { public Dispatcher(short maxServices) throws ServiceException { _services = new Service[maxServices]; - SimulatorSystem.setJavaOwner(_services, this); + SimulatorSystem.instance().setJavaOwner(_services, this); _phases = new byte[maxServices]; - SimulatorSystem.setJavaOwner(_phases, this); + SimulatorSystem.instance().setJavaOwner(_phases, this); _maxServices = maxServices; } diff --git a/src/main/java/javacard/framework/service/RMIService.java b/src/main/java/javacard/framework/service/RMIService.java index 3b696c99..5f007a50 100644 --- a/src/main/java/javacard/framework/service/RMIService.java +++ b/src/main/java/javacard/framework/service/RMIService.java @@ -32,7 +32,7 @@ public class RMIService extends BasicService implements RemoteService { public RMIService(Remote initialObject) throws NullPointerException { if (initialObject == null) - throw SimulatorSystem.nullPointerException; + throw new NullPointerException("initialObject"); _remoteObject = initialObject; } diff --git a/src/main/java/javacard/framework/service/package-info.java b/src/main/java/javacard/framework/service/package-info.java new file mode 100644 index 00000000..96b7cbb9 --- /dev/null +++ b/src/main/java/javacard/framework/service/package-info.java @@ -0,0 +1,4 @@ +/** + * JavaCard API. + */ +package javacard.framework.service; diff --git a/src/main/java/javacard/security/AESKey.java b/src/main/java/javacard/security/AESKey.java index aa4ae0e4..f50bbce1 100644 --- a/src/main/java/javacard/security/AESKey.java +++ b/src/main/java/javacard/security/AESKey.java @@ -19,12 +19,11 @@ /** * AESKey contains a 16/24/32 byte key for AES computations based * on the Rijndael algorithm. - *

              When the key data is set, the key is initialized and ready for use. - *

              + *

              When the key data is set, the key is initialized and ready for use.

              * @see KeyBuilder * @see Signature - * @see Cipher - * @see KeyEncryption + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption */ public interface AESKey extends SecretKey { diff --git a/src/main/java/javacard/security/Checksum.java b/src/main/java/javacard/security/Checksum.java index 52b83c1e..122ca9c2 100644 --- a/src/main/java/javacard/security/Checksum.java +++ b/src/main/java/javacard/security/Checksum.java @@ -138,7 +138,7 @@ public abstract void init(byte bArray[], short bOff, short bLen) *

              This method requires temporary storage of intermediate results. * This may result in additional resource consumption and/or slow performance. * This method should only be used if all the input data required for the checksum - * is not available in one byte array. The {@link Checksum.html#doFinal(byte[], short, short, byte[], short)} + * is not available in one byte array. The {@link #doFinal(byte[], short, short, byte[], short)} * doFinal(byte[], short, short, byte[], short) method is recommended whenever possible. *

              Note: *

                diff --git a/src/main/java/javacard/security/CryptoException.java b/src/main/java/javacard/security/CryptoException.java index 3438e820..f2ebd2a3 100644 --- a/src/main/java/javacard/security/CryptoException.java +++ b/src/main/java/javacard/security/CryptoException.java @@ -26,7 +26,7 @@ * @see MessageDigest * @see Signature * @see RandomData - * @see Cipher + * @see javacardx.crypto.Cipher */ public class CryptoException extends CardRuntimeException { diff --git a/src/main/java/javacard/security/DESKey.java b/src/main/java/javacard/security/DESKey.java index 5d7c21c7..20f3b6ac 100644 --- a/src/main/java/javacard/security/DESKey.java +++ b/src/main/java/javacard/security/DESKey.java @@ -22,8 +22,8 @@ *

                When the key data is set, the key is initialized and ready for use. * @see KeyBuilder * @see Signature - * @see Cipher - * @see KeyEncryption + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption * */ public interface DESKey diff --git a/src/main/java/javacard/security/DSAKey.java b/src/main/java/javacard/security/DSAKey.java index e3b5c717..06098186 100644 --- a/src/main/java/javacard/security/DSAKey.java +++ b/src/main/java/javacard/security/DSAKey.java @@ -17,18 +17,18 @@ package javacard.security; /** - * The DSAKey interface is the base interface for the DSA algorithm's private and + * The DSAKey interface is the base interface for the DSA algorithm's private and * public key implementations. A DSA private key implementation must also implement * the DSAPrivateKey interface methods. A DSA public key implementation must also implement * the DSAPublicKey interface methods. *

                When all four components of the key (X or Y,P,Q,G) are set, the key is - * initialized and ready for use. - *

                + * initialized and ready for use.

                + * * @see DSAPublicKey * @see DSAPrivateKey * @see KeyBuilder * @see Signature - * @see KeyEncryption + * @see javacardx.crypto.KeyEncryption */ public interface DSAKey { diff --git a/src/main/java/javacard/security/DSAPrivateKey.java b/src/main/java/javacard/security/DSAPrivateKey.java index 3d479930..9ca0a4f8 100644 --- a/src/main/java/javacard/security/DSAPrivateKey.java +++ b/src/main/java/javacard/security/DSAPrivateKey.java @@ -23,11 +23,11 @@ * the DSAKey interface methods. *

                When all four components of the key (X,P,Q,G) are set, the key is * initialized and ready for use. - *

                + * * @see DSAPublicKey * @see KeyBuilder * @see Signature - * @see KeyEncryption + * @see javacardx.crypto.KeyEncryption */ public interface DSAPrivateKey extends PrivateKey, DSAKey { diff --git a/src/main/java/javacard/security/DSAPublicKey.java b/src/main/java/javacard/security/DSAPublicKey.java index b9a54613..1c279c2b 100644 --- a/src/main/java/javacard/security/DSAPublicKey.java +++ b/src/main/java/javacard/security/DSAPublicKey.java @@ -26,7 +26,7 @@ * @see DSAPrivateKey * @see KeyBuilder * @see Signature - * @see KeyEncryption + * @see javacardx.crypto.KeyEncryption */ public interface DSAPublicKey extends PublicKey, DSAKey { diff --git a/src/main/java/javacard/security/ECKey.java b/src/main/java/javacard/security/ECKey.java index c24ab29f..b606e6a9 100644 --- a/src/main/java/javacard/security/ECKey.java +++ b/src/main/java/javacard/security/ECKey.java @@ -32,7 +32,7 @@ * @see ECPrivateKey * @see KeyBuilder * @see Signature - * @see KeyEncryption + * @see javacardx.crypto.KeyEncryption * @see KeyAgreement * */ @@ -71,12 +71,12 @@ public abstract void setFieldFP(byte[] buffer, short offset, short length) * of type TYPE_EC_F2M_PUBLIC or TYPE_EC_F2M_PRIVATE in * the case where the polynomial is a trinomial, of the form * x^n + x^e + 1 (where n is the bit length of the key). - * It is required that n > e > 0. + * It is required that n > e > 0. * @param e the value of the intermediate exponent of the trinomial * @throws CryptoException with the following reason codes: *

                  *
                • CryptoException.ILLEGAL_VALUE if the input parameter e - * is not such that 0 < e < n. + * is not such that 0 < e < n. *
                • CryptoException.NO_SUCH_ALGORITHM if the key is neither * of type TYPE_EC_F2M_PUBLIC nor TYPE_EC_F2M_PRIVATE.
                */ @@ -88,7 +88,7 @@ public abstract void setFieldF2M(short e) * of type TYPE_EC_F2M_PUBLIC or TYPE_EC_F2M_PRIVATE in * the case where the polynomial is a pentanomial, of the form * x^n + x^e1 + x^e2 + x^e3 + 1 (where n is the bit length of the key). - * It is required for all ei where ei = {e1, e2, e3} that n > ei > 0. + * It is required for all ei where ei = {e1, e2, e3} that n > ei > 0. * @param e1 the value of the first of the intermediate exponents of the * pentanomial * @param e2 the value of the second of the intermediate exponent of the @@ -98,7 +98,7 @@ public abstract void setFieldF2M(short e) *
                  *
                • CryptoException.ILLEGAL_VALUE if the input parameters * ei where ei = {e1, e2, e3} - * are not such that for all ei, n > ei > 0. + * are not such that for all ei, n > ei > 0. *
                • CryptoException.NO_SUCH_ALGORITHM if the key is neither * of type TYPE_EC_F2M_PUBLIC nor TYPE_EC_F2M_PRIVATE. *
                diff --git a/src/main/java/javacard/security/ECPrivateKey.java b/src/main/java/javacard/security/ECPrivateKey.java index 1de10365..03e0d47c 100644 --- a/src/main/java/javacard/security/ECPrivateKey.java +++ b/src/main/java/javacard/security/ECPrivateKey.java @@ -32,7 +32,7 @@ * @see ECPublicKey * @see KeyBuilder * @see Signature - * @see KeyEncryption + * @see javacardx.crypto.KeyEncryption * @see KeyAgreement */ public interface ECPrivateKey diff --git a/src/main/java/javacard/security/ECPublicKey.java b/src/main/java/javacard/security/ECPublicKey.java index cc02898c..66c3b212 100644 --- a/src/main/java/javacard/security/ECPublicKey.java +++ b/src/main/java/javacard/security/ECPublicKey.java @@ -28,7 +28,7 @@ * @see ECPrivateKey * @see KeyBuilder * @see Signature - * @see KeyEncryption + * @see javacardx.crypto.KeyEncryption * @see KeyAgreement */ public interface ECPublicKey diff --git a/src/main/java/javacard/security/HMACKey.java b/src/main/java/javacard/security/HMACKey.java new file mode 100644 index 00000000..f175c436 --- /dev/null +++ b/src/main/java/javacard/security/HMACKey.java @@ -0,0 +1,74 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javacard.security; + +/** + * + * HMACKey contains a key for HMAC operations. This key can be of + * any length, but it is strongly recommended that the key is not shorter than the + * byte length of the hash output used in the HMAC implementation. + * Keys with length greater than the hash block length are first hashed with the + * hash algorithm used for the HMAC implementation. + *

                Implementations must support an HMAC key length equal to the length of + * the supported hash algorithm block size (e.g 64 bits for SHA-1) + *

                When the key data is set, the key is initialized and ready for use. + * + * @see KeyBuilder + * @see Signature + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption + * @since 2.2.2 + */ + +public interface HMACKey extends SecretKey { + + /** + * Sets the + * Key data. + * The data format is big-endian and right-aligned (the least significant bit is the least significant + * bit of last byte). Input key data is copied into the internal representation. + *

                Note:

                  + *
                • If the key object implements the javacardx.crypto.KeyEncryption + * interface and the Cipher object specified via setKeyCipher() + * is not null, keyData is decrypted using the Cipher object. + *
                + *

                + * + * @param keyData byte array containing key initialization data + * @param kOff offset within keyData to start + * @param kLen the byte length of the key initialization data + * @throws CryptoException - with the following reason code: CryptoException.ILLEGAL_VALUE if input data decryption is required and fails. + * @throws ArrayIndexOutOfBoundsException - if kOff is negative or the keyData array is too short + * @throws NullPointerException - if the keyData parameter is null + */ + void setKey(byte[] keyData, short kOff, short kLen) throws CryptoException, NullPointerException, ArrayIndexOutOfBoundsException; + + /** + * Returns the + * Key data in plain text. The key can be any length, but + * should be longer than the byte length of the hash algorithm output used. The data + * format is big-endian and right-aligned (the least significant bit is the least + * significant bit of last byte). + *

                + * + * @param keyData byte array to return key data + * @param kOff offset within keyData to start + * @return the byte length of the key data returned + * @throws CryptoException - with the following reason code: CryptoException.UNINITIALIZED_KEY if the key data has not been successfully initialized since the time the initialized state of the key was set to false. + * @see Key + */ + byte getKey(byte[] keyData, short kOff); +} diff --git a/src/main/java/javacard/security/InitializedMessageDigest.java b/src/main/java/javacard/security/InitializedMessageDigest.java new file mode 100644 index 00000000..c09222a6 --- /dev/null +++ b/src/main/java/javacard/security/InitializedMessageDigest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javacard.security; + +/** + * + * The + * InitializedMessageDigest class is a subclass of the base + * class + * MessageDigest. This class is used to generate a hash representing + * a specified message but with the additional + * capability to initialize the starting hash value corresponding to a previously + * hashed part of the message. + * Implementations of + * InitializedMessageDigest + * algorithms must extend this class and implement all the abstract methods. + *

                A tear or card reset event resets a + * InitializedMessageDigest object to the initial state (state upon construction). + *

                Even if a transaction is in progress, update of intermediate result state in the implementation + * instance shall not participate in the transaction. + * + * @since 2.2.2 + */ +public abstract class InitializedMessageDigest extends MessageDigest { + + /** + * protected constructor + */ + protected InitializedMessageDigest() { + } + + /** + * This method initializes the starting hash value in place of the default + * value used by the + * MessageDigest superclass. The starting + * hash value represents the previously computed + * hash (using the same algorithm) of the first part of the message. The remaining + * bytes of the message must be presented to this + * InitializedMessageDigest + * object via the + * update and + * doFinal methods to + * generate the final message digest. + *

                Note:

                  + *
                • The maximum allowed value of the byte length of the first part of the message is + * algorithm specific + *
                + *

                + * + * @param initialDigestBuf input buffer containing the starting hash value representing the previously + * computed hash (using the same algorithm) of first part of the message + * @param initialDigestOffset offset into initialDigestBuf array where initial digest value data begins + * @param initialDigestLength the length of data in initialDigestBuf array. + * @param digestedMsgLenBuf the byte array containing the number of bytes in the first part of the message that + * has previously been hashed to obtain the specified initial digest value value + * @param digestedMsgLenOffset the offset within digestedMsgLenBuf where the digested length + * begins(the bytes starting at this offset for digestedMsgLenLength bytes are concatenated to form + * the actual digested message length value) + * @param digestedMsgLenLength byte length of the digested length + * @throws CryptoException with the following reason codes: CryptoException.ILLEGAL_VALUE + * if the parameter initialDigestLength is not equal to the length of message digest of the algorithm + * (see LENGTH_* constants {@link MessageDigest#LENGTH_SHA}) or if the number of bytes in the first part of the message that + * has previously been hashed is 0 or not a multiple of the algorithm's block size or greater than the maximum length + * supported by the algorithm (see ALG_* algorithm descriptions {@link MessageDigest#ALG_SHA}). + */ + public abstract void setInitialDigest(byte[] initialDigestBuf, short initialDigestOffset, + short initialDigestLength, byte[] digestedMsgLenBuf, short digestedMsgLenOffset, + short digestedMsgLenLength) throws CryptoException; +} diff --git a/src/main/java/javacard/security/Key.java b/src/main/java/javacard/security/Key.java index 1cf94310..081214af 100644 --- a/src/main/java/javacard/security/Key.java +++ b/src/main/java/javacard/security/Key.java @@ -18,7 +18,7 @@ /** * The Key interface is the base interface for all keys. - *

                + * *

                A Key object sets its initialized state to true only when all the associated * Key object parameters have been set at least once since the time the initialized state was set to false. *

                A newly created Key object sets its initialized state to false. Invocation of the @@ -43,7 +43,6 @@ public interface Key { * Returns the key interface type. * @return the key interface type. Valid codes listed in TYPE.. constants * See KeyBuilder.TYPE_DES_TRANSIENT_RESET - *

                * @see KeyBuilder */ public abstract byte getType(); diff --git a/src/main/java/javacard/security/KeyBuilder.java b/src/main/java/javacard/security/KeyBuilder.java index 563f4c65..e0d169f6 100644 --- a/src/main/java/javacard/security/KeyBuilder.java +++ b/src/main/java/javacard/security/KeyBuilder.java @@ -203,6 +203,10 @@ public class KeyBuilder { * EC Key Length LENGTH_EC_F2M_193 = 193. */ public static final short LENGTH_EC_F2M_193 = 193; + /** + * EC Key Length LENGTH_EC_FP_256 = 256. + */ + public static final short LENGTH_EC_FP_256 = 256; /** * AES Key Length LENGTH_AES_128 = 128. */ @@ -216,6 +220,62 @@ public class KeyBuilder { */ public static final short LENGTH_AES_256 = 256; + /** + * Key object which implements interface type KoreanSEEDKey with + * CLEAR_ON_RESET transient key data. This Key object implicitly performs a + * clearKey() on power on or card reset. + */ + public static final byte TYPE_KOREAN_SEED_TRANSIENT_RESET=16; + /** + * Key object which implements interface type KoreanSEEDKey with + * CLEAR_ON_DESELECT transient key data. This Key object implicitly performs + * a clearKey() on power on or card reset. + */ + public static final byte TYPE_KOREAN_SEED_TRANSIENT_DESELECT = 17; + /** + * Key object which implements interface type KoreanSEEDKey with persistent + * key data. + */ + public static final byte TYPE_KOREAN_SEED = 18; + /** + * Key object which implements interface type HMACKey with CLEAR_ON_RESET + * transient key data. This Key object implicitly performs a clearKey() on + * power on or card reset. Note, there is no length constant associated with + * HMAC, since the specification states that the key can have any length. + */ + public static final byte TYPE_HMAC_TRANSIENT_RESET = 19; + /** + * Key object which implements interface type HMACKey with CLEAR_ON_DESELECT + * transient key data. This Key object implicitly performs a clearKey() on + * power on or card reset. + */ + public static final byte TYPE_HMAC_TRANSIENT_DESELECT = 20; + /** + * Key object which implements interface type HMACKey with persistent key + * data. + */ + public static final byte TYPE_HMAC = 21; + /** + * HMAC Key Length LENGTH_HMAC_SHA_1_BLOCK_64 = 64. + */ + public static final short LENGTH_HMAC_SHA_1_BLOCK_64 = 64; + /** + * HMAC Key Length LENGTH_HMAC_SHA_256_BLOCK_64 = 64. + */ + public static final short LENGTH_HMAC_SHA_256_BLOCK_64 = 64; + /** + * HMAC Key Length LENGTH_HMAC_SHA_384_BLOCK_128 = 64. + */ + public static final short LENGTH_HMAC_SHA_384_BLOCK_128 = 128; + /** + * HMAC Key Length LENGTH_HMAC_SHA_512_BLOCK_128 = 64. + */ + public static final short LENGTH_HMAC_SHA_512_BLOCK_128 = 128; + /** + * Korean Seed Key Length LENGTH_KOREAN_SEED_128 = 128. + */ + public static final short LENGTH_KOREAN_SEED_128 = 128; + /** * Creates uninitialized cryptographic keys for signature and cipher algorithms. Only instances created * by this method may be the key objects used to initialize instances of @@ -286,13 +346,13 @@ public static Key buildKey(byte keyType, short keyLength, boolean keyEncryption) break; case TYPE_EC_FP_PUBLIC: - if (keyLength != 112 && keyLength != 128 && keyLength != 160 && keyLength != 192) { + if (keyLength != 112 && keyLength != 128 && keyLength != 160 && keyLength != 192 && keyLength != 256) { CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); } key = new ECPublicKeyImpl(keyType, keyLength); break; case TYPE_EC_FP_PRIVATE: - if (keyLength != 112 && keyLength != 128 && keyLength != 160 && keyLength != 192) { + if (keyLength != 112 && keyLength != 128 && keyLength != 160 && keyLength != 192 && keyLength != 256) { CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); } key = new ECPrivateKeyImpl(keyType, keyLength); @@ -308,10 +368,19 @@ public static Key buildKey(byte keyType, short keyLength, boolean keyEncryption) key = new SymmetricKeyImpl(keyType, keyLength); break; + // hmac + case TYPE_HMAC_TRANSIENT_RESET: + case TYPE_HMAC_TRANSIENT_DESELECT: + case TYPE_HMAC: + key = new SymmetricKeyImpl(keyType, keyLength); + break; + default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } return key; } + + private KeyBuilder() {} } \ No newline at end of file diff --git a/src/main/java/javacard/security/KeyPair.java b/src/main/java/javacard/security/KeyPair.java index 94dc77f4..ce42c1b4 100644 --- a/src/main/java/javacard/security/KeyPair.java +++ b/src/main/java/javacard/security/KeyPair.java @@ -67,7 +67,7 @@ public final class KeyPair { *

              • For the DSA algorithm, if the p, q and g parameters of the public key object are pre-initialized, * they will be retained. Otherwise, default precomputed parameter sets will be used. The required * default precomputed values are listed in Appendix B of Java Cryptography Architecture - * API Specification & Reference document. + * API Specification & Reference document. *
              • For the EC case, if the Field, A, B, G and R parameters of the * key pair are pre-initialized, then they will be retained. Otherwise * default pre-specified values MAY be used (e.g. WAP predefined curves), @@ -81,9 +81,9 @@ public final class KeyPair { * value parameter in RSA or the p, q, g parameter set in DSA or * the Field, A, B, G and R parameter set in EC is invalid. *
              - * @see APDU + * @see javacard.framework.APDU * @see Signature - * @see Cipher + * @see javacardx.crypto.Cipher * @see RSAPublicKey * @see ECKey * @see DSAKey @@ -100,7 +100,7 @@ public final void genKeyPair() * The encapsulated key objects are of the specified keyLength size and * implement the appropriate Key interface associated with the specified algorithm * (example - RSAPublicKey interface for the public key and RSAPrivateKey - * interface for the private key within an ALG_RSA key pair).

              + * interface for the private key within an ALG_RSA key pair). *

              Notes:

                *
              • The key objects encapsulated in the generated KeyPair object * need not support the KeyEncryption interface. @@ -115,8 +115,8 @@ public final void genKeyPair() * associated with the specified type, size of key is not supported.
              * @see KeyBuilder * @see Signature - * @see KeyEncryption - * @see Cipher + * @see javacardx.crypto.KeyEncryption + * @see javacardx.crypto.Cipher */ public KeyPair(byte algorithm, short keyLength) throws CryptoException { diff --git a/src/main/java/javacard/security/KoreanSEEDKey.java b/src/main/java/javacard/security/KoreanSEEDKey.java new file mode 100644 index 00000000..f5e593f9 --- /dev/null +++ b/src/main/java/javacard/security/KoreanSEEDKey.java @@ -0,0 +1,73 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javacard.security; + +/** + * + * KoreanSEEDKey contains an 16-byte key for Korean Seed Algorithm + * operations. + *

              When the key data is set, the key is initialized and ready for use. + *

              + * + * @since 2.2.2 + * @see KeyBuilder + * @see Signature + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption + * + */ +public interface KoreanSEEDKey extends SecretKey +{ + /** + * Sets the Key data. The plain text length of input key data is + * The data format is big-endian and right-aligned (the least significant bit is the least significant + * bit of last byte). Input key data is copied into the internal representation. + *

              Note:

                + *
              • If the key object implements the javacardx.crypto.KeyEncryption + * interface and the Cipher object specified via setKeyCipher() + * is not null, keyData is decrypted using the Cipher object. + *
              + *

              + * + * @param keyData byte array containing key initialization data + * @param kOff offset within keyData to start + * @throws CryptoException with the following reason code:

                + *
              • CryptoException.ILLEGAL_VALUE if input data decryption is required and fails. + *
              + * @throws ArrayIndexOutOfBoundsException if kOff is negative or the keyData array is too short + * @throws NullPointerException if the keyData parameter is null + */ + void setKey(byte[] keyData, short kOff) throws CryptoException, NullPointerException, ArrayIndexOutOfBoundsException; + + /** + * Returns the Key data in plain text. The length of output key data + * is 16 bytes for Korean Seed Algorithm. + * The data format is big-endian and right-aligned + * (the least significant bit is the least significant + * bit of last byte). + *

              + * + * @param keyData byte array to return key data + * @param kOff offset within keyData to start + * @return the byte length of the key data returned + * @throws CryptoException with the following reason code:

                + *
              • CryptoException.UNINITIALIZED_KEY if the key data has not been successfully initialized since the time the initialized state of the key was set to false. + *
              + * @see Key + */ + byte getKey(byte[] keyData, short kOff); + +} diff --git a/src/main/java/javacard/security/MessageDigest.java b/src/main/java/javacard/security/MessageDigest.java index 42f46297..11cdfba9 100644 --- a/src/main/java/javacard/security/MessageDigest.java +++ b/src/main/java/javacard/security/MessageDigest.java @@ -27,7 +27,7 @@ * instance shall not participate in the transaction. */ public abstract class MessageDigest { - + /** * Message Digest algorithm SHA. */ @@ -40,13 +40,52 @@ public abstract class MessageDigest { * Message Digest algorithm RIPE MD-160. */ public static final byte ALG_RIPEMD160 = 3; - + /** + * Message Digest algorithm SHA-256. The block size used by this algorithm + * is 64 bytes. + */ + public static final byte ALG_SHA_256 = 4; + /** + * Message Digest algorithm SHA-384. The block size used by this algorithm + * is 128 bytes. + */ + public static final byte ALG_SHA_384 = 5; + /** + * Message Digest algorithm SHA-512. The block size used by this algorithm + * is 128 bytes. + */ + public static final byte ALG_SHA_512 = 6; + /** + * Length of digest in bytes for MD5 + */ + public static final byte LENGTH_MD5 = 16; + /** + * Length of digest in bytes for RIPE MD-160 + */ + public static final byte LENGTH_RIPEMD160 = 20; + /** + * Length of digest in bytes for SHA + */ + public static final byte LENGTH_SHA = 20; + /** + * Length of digest in bytes for SHA-256 + */ + public static final byte LENGTH_SHA_256 = 32; + /** + * Length of digest in bytes for SHA-384 + */ + public static final byte LENGTH_SHA_384 = 48; + /** + * Length of digest in bytes for SHA-512 + */ + public static final byte LENGTH_SHA_512 = 64; + /** * Protected Constructor */ protected MessageDigest() { } - + /** * Creates a MessageDigest object instance of the selected algorithm. * @param algorithm the desired message digest algorithm. @@ -61,26 +100,51 @@ protected MessageDigest() { * or shared access mode is not supported.
            */ public static final MessageDigest getInstance(byte algorithm, boolean externalAccess) - throws CryptoException { + throws CryptoException { if (externalAccess) { CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); } MessageDigest instance = new MessageDigestImpl(algorithm); return instance; } - + + /** + * Creates a + * InitializedMessageDigest object instance of the selected algorithm. + *

            + * + * @param algorithm the desired message digest algorithm. Valid codes listed in ALG_* constants above, + * for example, {@link #ALG_SHA}. + * @param externalAccess true indicates that the instance will be shared among multiple applet + * instances and that the InitializedMessageDigest instance will also be accessed (via a Shareable. interface) + * when the owner of the InitializedMessageDigest instance is not the currently selected applet. + * If true the implementation must not allocate CLEAR_ON_DESELECT transient space for internal data. + * @return the InitializedMessageDigest object instance of the requested algorithm + * @throws CryptoException with the following reason codes: CryptoException.NO_SUCH_ALGORITHM + * if the requested algorithm or shared access mode is not supported. + * @since 2.2.2 + */ + public static final InitializedMessageDigest getInitializedMessageDigestInstance(byte algorithm, + boolean externalAccess) throws CryptoException { + if (externalAccess) { + CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); + } + InitializedMessageDigest instance = new MessageDigestImpl(algorithm); + return instance; + } + /** * Gets the Message digest algorithm. * @return the algorithm code defined above */ public abstract byte getAlgorithm(); - + /** * Returns the byte length of the hash. * @return hash length */ public abstract byte getLength(); - + /** * Generates a hash of all/last input data. * Completes and returns the hash computation after performing final operations such as padding. @@ -92,9 +156,12 @@ public static final MessageDigest getInstance(byte algorithm, boolean externalAc * @param outBuff the output buffer, may be the same as the input buffer * @param outOffset the offset into the output buffer where the resulting hash value begins * @return number of bytes of hash output in outBuff + * @throws CryptoException with the following reason codes:

              + *
            • CryptoException.ILLEGAL_USE if the accumulated message length is greater than the maximum length supported by the algorithm. + *
            */ - public abstract short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset); - + public abstract short doFinal(byte[] inBuff, short inOffset, short inLength, byte[] outBuff, short outOffset) throws CryptoException; + /** * Accumulates a hash of the input data. This method requires temporary storage of * intermediate results. In addition, if the input data length is not block aligned @@ -114,13 +181,16 @@ public static final MessageDigest getInstance(byte algorithm, boolean externalAc * @param inBuff the input buffer of data to be hashed * @param inOffset the offset into the input buffer at which to begin hash generation * @param inLength the byte length to hash - * See also: {@link #doFinal(byte[], short, short, byte[], short)} + * @throws CryptoException with the following reason codes:
              + *
            • CryptoException.ILLEGAL_USE if the accumulated message length is greater than the maximum length supported by the algorithm. + *
            + * @see #doFinal(byte[], short, short, byte[], short) */ - public abstract void update(byte[] inBuff, short inOffset, short inLength); - + public abstract void update(byte[] inBuff, short inOffset, short inLength) throws CryptoException; + /** * Resets the MessageDigest object to the initial state for further use. */ public abstract void reset(); - -} \ No newline at end of file + +} diff --git a/src/main/java/javacard/security/RSAPrivateCrtKey.java b/src/main/java/javacard/security/RSAPrivateCrtKey.java index 71016b47..91eea459 100644 --- a/src/main/java/javacard/security/RSAPrivateCrtKey.java +++ b/src/main/java/javacard/security/RSAPrivateCrtKey.java @@ -40,8 +40,8 @@ * @see RSAPublicKey * @see KeyBuilder * @see Signature - * @see Cipher - * @see KeyEncryption + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption * */ public interface RSAPrivateCrtKey diff --git a/src/main/java/javacard/security/RSAPrivateKey.java b/src/main/java/javacard/security/RSAPrivateKey.java index 2dff9ec4..ecacff04 100644 --- a/src/main/java/javacard/security/RSAPrivateKey.java +++ b/src/main/java/javacard/security/RSAPrivateKey.java @@ -27,8 +27,8 @@ * @see RSAPrivateCrtKey * @see KeyBuilder * @see Signature - * @see Cipher - * @see KeyEncryption + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption */ public interface RSAPrivateKey extends PrivateKey { diff --git a/src/main/java/javacard/security/RSAPublicKey.java b/src/main/java/javacard/security/RSAPublicKey.java index 02203585..36be4435 100644 --- a/src/main/java/javacard/security/RSAPublicKey.java +++ b/src/main/java/javacard/security/RSAPublicKey.java @@ -25,8 +25,8 @@ * @see RSAPrivateCrtKey * @see KeyBuilder * @see Signature - * @see Cipher - * @see KeyEncryption + * @see javacardx.crypto.Cipher + * @see javacardx.crypto.KeyEncryption * */ public interface RSAPublicKey diff --git a/src/main/java/javacard/security/Signature.java b/src/main/java/javacard/security/Signature.java index 39261682..0ab70f44 100644 --- a/src/main/java/javacard/security/Signature.java +++ b/src/main/java/javacard/security/Signature.java @@ -100,7 +100,7 @@ public abstract class Signature { */ public static final byte ALG_DES_MAC4_PKCS5 = 7; /** - * Signature algorithm ALG_DES_MAC8_PKCS5 generates an 8-byte MAC + * Signature algorithm ALG_DES_MAC8_PKCS5 generates an 8-byte MAC * using DES in CBC mode or triple DES in outer CBC mode. * Input data is padded according to the PKCS#5 scheme. *

            Note: @@ -141,7 +141,7 @@ public abstract class Signature { * and encrypts it using RSA. *

            Note:

              *
            • The encryption block(EB) during signing is built as follows:
              - * <  EB = 00 || 01 || PS || 00 || T
              + * <  EB = 00 || 01 || PS || 00 || T
              *       :: where T is the DER encoding of :
              *             digestInfo ::= SEQUENCE {
              *             digestAlgorithm AlgorithmIdentifier of MD5,
              @@ -166,7 +166,7 @@ public abstract class Signature { * and encrypts it using RSA. *

              Note:

                *
              • The encryption block(EB) during signing is built as follows:
                - * <  EB = 00 || 01 || PS || 00 || T
                + * <  EB = 00 || 01 || PS || 00 || T
                *       :: where T is the DER encoding of :
                *             digestInfo ::= SEQUENCE {
                *             digestAlgorithm AlgorithmIdentifier of RIPEMD160,
                @@ -249,6 +249,73 @@ public abstract class Signature { * and encrypts it using RSA. */ public static final byte ALG_RSA_RIPEMD160_PKCS1_PSS = 23; + /** + * HMAC message authentication algorithm ALG_HMAC_SHA1 This algorithm + * generates an HMAC following the steps found in RFC: 2104 using SHA1 as + * the hashing algorithm. Since: 2.2.2 + */ + public static final byte ALG_HMAC_SHA1 = 24; + /** + * HMAC message authentication algorithm ALG_HMAC_SHA_256 This algorithm + * generates an HMAC following the steps found in RFC: 2104 using SHA-256 as + * the hashing algorithm. + */ + public static final byte ALG_HMAC_SHA_256 = 25; + /** + * HMAC message authentication algorithm ALG_HMAC_SHA_384 This algorithm + * generates an HMAC following the steps found in RFC: 2104 using SHA-384 as + * the hashing algorithm. + */ + public static final byte ALG_HMAC_SHA_384 = 26; + /** + * HMAC message authentication algorithm ALG_HMAC_SHA_512 This algorithm + * generates an HMAC following the steps found in RFC: 2104 using SHA-512 as + * the hashing algorithm. + */ + public static final byte ALG_HMAC_SHA_512 = 27; + /** + * HMAC message authentication algorithm ALG_HMAC_MD5 This algorithm + * generates an HMAC following the steps found in RFC: 2104 using MD5 as the + * hashing algorithm. + */ + public static final byte ALG_HMAC_MD5 = 28; + /** + * HMAC message authentication algorithm ALG_HMAC_RIPEMD160 This algorithm + * generates an HMAC following the steps found in RFC: 2104 using RIPEMD160 + * as the hashing algorithm. + */ + public static final byte ALG_HMAC_RIPEMD160 = 29; + /** + * Signature algorithmALG_RSA_SHA_ISO9796_MR generates 20-byte SHA-1 digest, + * pads it according to the ISO9796-2 specification and encrypts using RSA. + * This algorithm is conformant with EMV2000. This algorithm uses the first + * part of the input message as padding bytes during signing. During + * verification, these message bytes (recoverable message) can be recovered + * to reconstruct the message. To use this algorithm the Signature object + * instance returned by the getInstance method must be cast to the + * SignatureMessageRecovery interface to invoke the applicable methods. + */ + public static final byte ALG_RSA_SHA_ISO9796_MR = 30; + /** + * Signature algorithmALG_RSA_RIPEMD160_ISO9796_MR generates 20-byte RIPE + * MD-160 digest, pads it according to the ISO9796-2 specification and + * encrypts using RSA. This algorithm uses the first part of the input + * message as padding bytes during signing. During verification, these + * message bytes (recoverable message) can be recovered to reconstruct the + * message. To use this algorithm the Signature object instance returned by + * the getInstance method must be cast to the SignatureMessageRecovery + * interface to invoke the applicable methods. + */ + public static final byte ALG_RSA_RIPEMD160_ISO9796_MR = 31; + /** + * Signature algorithm ALG_KOREAN_SEED_MAC_NOPAD generates an 16-byte MAC + * using Korean SEED in CBC mode. This algorithm does not pad input data. If + * the input data is not (16 byte) block aligned it throws CryptoException + * with the reason code ILLEGAL_USE. Note: This algorithm must not be + * implemented if export restrictions apply. + */ + public static final byte ALG_KOREAN_SEED_MAC_NOPAD = 32; + /** * Used in init() methods to indicate signature sign mode. */ @@ -290,6 +357,7 @@ public static final Signature getInstance(byte algorithm, boolean externalAccess case ALG_RSA_RIPEMD160_ISO9796: case ALG_RSA_RIPEMD160_PKCS1: case ALG_ECDSA_SHA: + case ALG_RSA_SHA_ISO9796_MR: instance = new AsymmetricSignatureImpl(algorithm); break; case ALG_DES_MAC4_NOPAD: @@ -298,8 +366,16 @@ public static final Signature getInstance(byte algorithm, boolean externalAccess case ALG_DES_MAC8_ISO9797_M1: case ALG_DES_MAC4_ISO9797_M2: case ALG_DES_MAC8_ISO9797_M2: + case ALG_DES_MAC8_ISO9797_1_M2_ALG3: case ALG_DES_MAC4_PKCS5: case ALG_DES_MAC8_PKCS5: + case ALG_AES_MAC_128_NOPAD: + case ALG_HMAC_SHA1: + case ALG_HMAC_SHA_256: + case ALG_HMAC_SHA_384: + case ALG_HMAC_SHA_512: + case ALG_HMAC_MD5: + case ALG_HMAC_RIPEMD160: instance = new SymmetricSignatureImpl(algorithm); break; @@ -324,6 +400,8 @@ public static final Signature getInstance(byte algorithm, boolean externalAccess *

                Note:

                  *
                • AES, DES, and triple DES algorithms in CBC mode will use 0 for initial vector(IV) if this * method is used. + *
                • For optimal performance, when the theKey parameter is a transient key, the implementation should, + * whenever possible, use transient space for internal storage. *
                * @param theKey the key object to use for signing or verifying * @param theMode one of MODE_SIGN or MODE_VERIFY @@ -350,6 +428,8 @@ public abstract void init(Key theKey, byte theMode) *
              • AES algorithms in CBC mode expect a 16-byte parameter value for * the initial vector(IV) in bArray. *
              • ECDSA, RSA, and DSA algorithms throw CryptoException.ILLEGAL_VALUE. + *
              • For optimal performance, when the theKey parameter is a transient key, the implementation should, + * whenever possible, use transient space for internal storage. *
              * @param theKey the key object to use for signing * @param theMode one of MODE_SIGN or MODE_VERIFY @@ -487,4 +567,4 @@ public abstract short sign(byte[] inBuff, short inOffset, short inLength, byte[] public abstract boolean verify(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset, short sigLength) throws CryptoException; -} \ No newline at end of file +} diff --git a/src/main/java/javacard/security/SignatureMessageRecovery.java b/src/main/java/javacard/security/SignatureMessageRecovery.java new file mode 100644 index 00000000..79ebc613 --- /dev/null +++ b/src/main/java/javacard/security/SignatureMessageRecovery.java @@ -0,0 +1,215 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javacard.security; + +/** + * A subclass of the abstract + * Signature class must implement this + * SignatureMessageRecovery interface to provide message recovery functionality. + * An instance implementing this interface is returned by the + * {@link javacard.security.Signature#getInstance(byte, boolean)} method when algorithm type with suffix + * *_MR is specified. e.g.{@link javacard.security.Signature#ALG_RSA_SHA_ISO9796_MR}. + * + *

              This interface provides specialized versions of some of the methods defined in the + * Signature + * class to provide message recovery functions. An alternate version of the + * sign() and + * verify() methods is supported here along with a + * new + * beginVerify method to allow the message encoded in the signature to be recovered. + * + *

              For signing a message with message recovery functionality, the user must cast the + * Signature object to this interface, initialize the object for signing with a + * private key using the + * init() method, and issue 0 or more + * update() method + * calls and then finally call the + * sign() method to obtain the signature. + * + *

              For recovering the encoded message and verifying functionality, the user must + * cast the + * Signature object to this interface, initialize the object for + * verifying with a public key using the + * init() method, first recover the + * message using the + * beginVerify() method and then issue 0 or more + * update() + * method calls and then finally call the + * verify() method to verify the + * signature. + * + *

              Note:
              + * A + * Signature object implementing this interface must throw + * CryptoException with + * CryptoException.ILLEGAL_USE reason code when one of the + * following methods applicable only to a + * Signature object which does not + * include message recovery functionality, is called: + *

                + *
              • init(Key, byte, byte[] short, short) + *
              • sign(byte[], short, short, byte[], short) + *
              • verify(byte[], short, short, byte[], short, short) + *
              + * + * @since 2.2.2 + */ +public interface SignatureMessageRecovery { + + /** + * Initializes the + * Signature object with the appropriate + * Key. + * This method should be used for algorithms which do not need initialization parameters + * or use default parameter values. + *

              init() must be used to update the + * Signature object with a new key. + * If the + * Key object is modified after invoking the + * init() method, + * the behavior of the + * update(), + * sign(), and + * verify() + * methods is unspecified. + *

              + * + * @param theKey the key object to use for signing or verifying + * @param theMode one of MODE_SIGN or MODE_VERIFY + * @throws CryptoException with the following reason codes: CryptoException.ILLEGAL_VALUE if theMode option is an undefined value or if the Key is inconsistent with theMode or with the Signature implementation. CryptoException.UNINITIALIZED_KEY if theKey instance is uninitialized. + */ + void init(Key theKey, byte theMode) throws CryptoException; + + /** + * This method begins the verification sequence by recovering the message + * encoded within the signature itself and initializing the internal hash + * function. The recovered message data overwrites the signature data in the + * sigAndRecDataBuff input byte array. + *

              Notes:

                + *
              • This method must be called during the verification sequence + * prior to either the update() or the verify() methods during verification. + *
              • The trailing (sigLength - recovered message length) bytes of + * signature data in sigAndRecDataBuff may also be overwritten + * by this method. + *
              + *

              + * + * @param sigAndRecDataBuff contains the signature data as input and also contains the recoverable part of the message as output. + * @param buffOffset offset into the sigAndRecDataBuff array where data begins for signature and where this method will start writing recovered message data. + * @param sigLength the length of signature data + * @return byte length of recovered message data written to sigAndRecDataBuff + * @throws CryptoException with the following reason codes: CryptoException.ILLEGAL_USE for the following conditions: if this object is initialized for signature sign mode if sigLength is inconsistent with this Signature algorithm if the decrypted message representative does not meet the algorithm specifications if the bit length of the decrypted message representative is not a multiple of 8. CryptoException.UNINITIALIZED_KEY if key not initialized. CryptoException.INVALID_INIT if this Signature object is not initialized. + */ + short beginVerify(byte[] sigAndRecDataBuff, short buffOffset, short sigLength) throws CryptoException; + + /** + * Generates the signature of all/last input data. In addition, this method + * returns the number of bytes beginning with the first byte of the message + * that was encoded into the signature itself. The encoded message is called + * the recoverable message and its length is called + * the recoverable message length. This recoverable message + * need not be transmitted and can be recovered during verification. + *

              A call to this method also resets this + * Signature object to the state it was in + * when previously initialized via a call to + * init(). + * That is, the object is reset and available to sign another message. + *

              The input and output buffer data may overlap. + *

              + * + * @param inBuff the input buffer of data to be signed + * @param inOffset the offset into the input buffer at which to begin signature generation + * @param inLength the byte length to sign + * @param sigBuff the output buffer to store signature data + * @param sigOffset the offset into sigBuff at which to begin signature data + * @param recMsgLen the output buffer containing the number of bytes of the recoverable message beginning with the first byte of the message that was encoded into the signature itself + * @param recMsgLenOffset offset into the recMsgLen output buffer where the byte length of the recoverable message is stored. Note that a single short value is stored at recMsgLenOffset offset. + * @return number of bytes of signature output in sigBuff + * @throws CryptoException with the following reason codes: CryptoException.UNINITIALIZED_KEY if key not initialized. CryptoException.INVALID_INIT if this Signature object is not initialized or initialized for signature verify mode. + */ + short sign(byte[] inBuff, short inOffset, short inLength, byte[] sigBuff, short sigOffset, short[] recMsgLen, short recMsgLenOffset) throws CryptoException; + + /** + * Verifies the signature of all/last input data against the passed in signature. + *

              A call to this method also resets this + * Signature object to the state it was in + * when previously initialized via a call to + * init(). + * That is, the object is reset and available to verify another message. + *

              + * + * @param inBuff the input buffer of data to be verified + * @param inOffset the offset into the input buffer at which to begin signature generation + * @param inLength the byte length to sign + * @return true if the signature verifies, false otherwise + * @throws CryptoException with the following reason codes: CryptoException.UNINITIALIZED_KEY if key not initialized. CryptoException.INVALID_INIT if this Signature object is not initialized or initialized for signature sign mode. CryptoException.ILLEGAL_USE if one of the following conditions is met: if beginVerify method has not been called. + */ + boolean verify(byte[] inBuff, short inOffset, short inLength) throws CryptoException; + + /** + * Gets the Signature algorithm. + *

              + * + * + * @return the algorithm code implemented by this Signature instance. + */ + byte getAlgorithm(); + + /** + * Returns the byte length of the signature data. + *

              + * + * + * @return the byte length of the signature data + * @throws CryptoException with the following reason codes: CryptoException.INVALID_INIT if this Signature object is not initialized. CryptoException.UNINITIALIZED_KEY if key not initialized. + */ + short getLength() throws CryptoException; + + /** + * Accumulates a signature of the input data. This method requires temporary storage of + * intermediate results. In addition, if the input data length is not block aligned + * (multiple of block size) + * then additional internal storage may be allocated at this time to store a partial + * input data block. + * This may result in additional resource consumption and/or slow performance. + * This method should only be used if all the input data required for signing/verifying + * is not available in one byte array. If all of the input data required for + * signing/verifying is located in a single byte array, use of the + * sign() + * or + * beginVerify method and + * verify() method is recommended. + * The + * sign() or + * verify() + * method must be called to complete processing of input data accumulated by one or more + * calls to the + * update() method. + *

              Note:

                + *
              • If + * inLength is 0 this method does nothing. + *
              + *

              + * + * @param inBuff the input buffer of data to be signed/verified + * @param inOffset the offset into the input buffer where input data begins + * @param inLength the byte length to sign/verify + * @throws CryptoException with the following reason codes: CryptoException.UNINITIALIZED_KEY if key not initialized. CryptoException.INVALID_INIT if this Signature object is not initialized. CryptoException.ILLEGAL_USE if the mode set in the init() method is MODE_VERIFY and the beginVerify() method is not yet called. + * @see #sign(byte[], short, short, byte[], short, short[], short) + * @see #verify(byte[], short, short) + */ + void update(byte[] inBuff, short inOffset, short inLength) throws CryptoException; +} diff --git a/src/main/java/javacard/security/package-info.java b/src/main/java/javacard/security/package-info.java new file mode 100644 index 00000000..9191d315 --- /dev/null +++ b/src/main/java/javacard/security/package-info.java @@ -0,0 +1,4 @@ +/** + * JavaCard API. + */ +package javacard.security; diff --git a/src/main/java/javacardx/apdu/ExtendedLength.java b/src/main/java/javacardx/apdu/ExtendedLength.java new file mode 100644 index 00000000..1c19f62b --- /dev/null +++ b/src/main/java/javacardx/apdu/ExtendedLength.java @@ -0,0 +1,34 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package javacardx.apdu; + +/** + * The ExtendedLength interface serves as a tagging interface to indicate that + * the applet supports extended length APDU. If this interface is implemented by + * the applet instance, the applet may receive and send up to 32767 bytes of + * APDU data. + * + *

              The APDU command header in the APDU buffer will use the variable + * length header defined in ISO7816-4 with a 3 byte Lc value when the Lc field + * in the incoming APDU header is 3 bytes long. The incoming data in that case + * will begin at APDU buffer offset 7. + * + *

              See Runtime Environment Specification for the Java Card Platform for details. + * + * @since 2.2.2 + */ +public interface ExtendedLength { +} \ No newline at end of file diff --git a/src/main/java/javacardx/apdu/package-info.java b/src/main/java/javacardx/apdu/package-info.java new file mode 100644 index 00000000..42c5858c --- /dev/null +++ b/src/main/java/javacardx/apdu/package-info.java @@ -0,0 +1,4 @@ +/** + * JavaCard API. + */ +package javacardx.apdu; diff --git a/src/main/java/javacardx/crypto/Cipher.java b/src/main/java/javacardx/crypto/Cipher.java index 718c8584..fdc0cfd5 100644 --- a/src/main/java/javacardx/crypto/Cipher.java +++ b/src/main/java/javacardx/crypto/Cipher.java @@ -15,7 +15,7 @@ */ package javacardx.crypto; -import com.licel.jcardsim.crypto.AssymetricCipherImpl; +import com.licel.jcardsim.crypto.AsymmetricCipherImpl; import com.licel.jcardsim.crypto.SymmetricCipherImpl; import javacard.security.CryptoException; import javacard.security.Key; @@ -160,6 +160,30 @@ public abstract class Cipher { * pads input data according to the PKCS#1-OAEP scheme (IEEE 1363-2000). */ public static final byte ALG_RSA_PKCS1_OAEP = 15; + + /** + * Cipher algorithm ALG_KOREAN_SEED_ECB_NOPAD provides a cipher using the + * Korean SEED algorithm specified in the Korean SEED Algorithm + * specification provided by KISA, Korea Information Security Agency in ECB + * mode and does not pad input data. If the input data is not block aligned + * it throws CryptoException with the reason code ILLEGAL_USE. + * + * @since 2.2.2 + */ + public static final byte ALG_KOREAN_SEED_ECB_NOPAD = 16; + + /** + * Cipher algorithm ALG_KOREAN_SEED_CBC_NOPAD provides a cipher using the + * Korean SEED algorithm specified in the Korean SEED Algorithm + * specification provided by KISA, Korea Information Security Agency in ECB + * mode and does not pad input data. If the input data is not block aligned + * it throws CryptoException with the reason code ILLEGAL_USE. + * + * + * @since 2.2.2 + */ + public static final byte ALG_KOREAN_SEED_CBC_NOPAD = 17; + /** * Used in init() methods to indicate decryption mode. */ @@ -214,7 +238,7 @@ public static final Cipher getInstance(byte algorithm, boolean externalAccess) case ALG_RSA_ISO14888: case ALG_RSA_ISO9796: case ALG_RSA_PKCS1_OAEP: - instance = new AssymetricCipherImpl(algorithm); + instance = new AsymmetricCipherImpl(algorithm); break; default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); @@ -236,6 +260,8 @@ public static final Cipher getInstance(byte algorithm, boolean externalAccess) *

                *
              • AES, DES, and triple DES algorithms in CBC mode will use 0 for initial vector(IV) if this * method is used. + *
              • For optimal performance, when the theKey parameter is a transient key, the implementation should, + * whenever possible, use transient space for internal storage. *
              * @param theKey the key object to use for encrypting or decrypting * @param theMode one of MODE_DECRYPT or MODE_ENCRYPT @@ -264,6 +290,8 @@ public abstract void init(Key theKey, byte theMode) * the initial vector(IV) in
              bArray. *
            • AES algorithms in ECB mode, DES algorithms in ECB mode, * RSA and DSA algorithms throw CryptoException.ILLEGAL_VALUE. + *
            • For optimal performance, when the theKey parameter is a transient key, the implementation should, + * whenever possible, use transient space for internal storage. *
            * @param theKey the key object to use for encrypting or decrypting. * @param theMode one of MODE_DECRYPT or MODE_ENCRYPT @@ -305,11 +333,11 @@ public abstract void init(Key theKey, byte theMode, byte[] bArray, short bOff, s * outBuff * are the same array, then the output data area must not partially overlap the input data area such that * the input data is modified before it is used; - * if inBuff==outBuff and
            inOffset < outOffset < inOffset+inLength, + * if inBuff==outBuff and
            inOffset < outOffset < inOffset+inLength, * incorrect output may result. *
          • When non-block aligned data is presented as input data, no amount of input * and output buffer data overlap is allowed; - * if inBuff==outBuff and
            outOffset < inOffset+inLength, + * if inBuff==outBuff and
            outOffset < inOffset+inLength, * incorrect output may result. *
          • AES, DES, and triple DES algorithms in CBC mode reset the initial vector(IV) * to 0. The initial vector(IV) can be re-initialized using the @@ -368,11 +396,11 @@ public abstract short doFinal(byte[] inBuff, short inOffset, short inLength, byt * outBuff * are the same array, then the output data area must not partially overlap the input data area such that * the input data is modified before it is used; - * if inBuff==outBuff and
            inOffset < outOffset < inOffset+inLength, + * if inBuff==outBuff and
            inOffset < outOffset < inOffset+inLength, * incorrect output may result. *
          • When non-block aligned data is presented as input data, no amount of input * and output buffer data overlap is allowed; - * if inBuff==outBuff and
            outOffset < inOffset+inLength, + * if inBuff==outBuff and
            outOffset < inOffset+inLength, * incorrect output may result. *
          • On decryption operations(except when ISO 9797 method 1 padding is used), * the padding bytes are not written to outBuff. diff --git a/src/main/java/javacardx/crypto/KeyEncryption.java b/src/main/java/javacardx/crypto/KeyEncryption.java index c4059364..c06ebe66 100644 --- a/src/main/java/javacardx/crypto/KeyEncryption.java +++ b/src/main/java/javacardx/crypto/KeyEncryption.java @@ -19,7 +19,6 @@ /** *KeyEncryption interface defines the methods used to enable encrypted * key data access to a key implementation. - *

            */ public interface KeyEncryption { diff --git a/src/main/java/javacardx/crypto/package-info.java b/src/main/java/javacardx/crypto/package-info.java new file mode 100644 index 00000000..ef7c2e0e --- /dev/null +++ b/src/main/java/javacardx/crypto/package-info.java @@ -0,0 +1,4 @@ +/** + * JavaCard API. + */ +package javacardx.crypto; diff --git a/src/test/java/com/licel/jcardsim/DocumentationCodeSamplesTest.java b/src/test/java/com/licel/jcardsim/DocumentationCodeSamplesTest.java new file mode 100644 index 00000000..0c895d14 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/DocumentationCodeSamplesTest.java @@ -0,0 +1,189 @@ +package com.licel.jcardsim; + +import com.licel.jcardsim.samples.HelloWorldApplet; +import com.licel.jcardsim.smartcardio.CardSimulator; +import com.licel.jcardsim.smartcardio.CardTerminalSimulator; +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.ByteUtil; +import javacard.framework.AID; +import junit.framework.TestCase; + +import javax.smartcardio.*; +import java.security.NoSuchAlgorithmException; +import java.security.Security; + +/** + * Contains all listing from the documentation + */ +public class DocumentationCodeSamplesTest extends TestCase { + public void testCodeListingReadme() { + // 1. Create simulator + CardSimulator simulator = new CardSimulator(); + + // 2. Install applet + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // 3. Select applet + simulator.selectApplet(appletAID); + + // 4. Send APDU + CommandAPDU commandAPDU = new CommandAPDU(0x00, 0x01, 0x00, 0x00); + ResponseAPDU response = simulator.transmitCommand(commandAPDU); + + // 5. Check response status word + assertEquals(0x9000, response.getSW()); + } + + public void testCodeListing1() { + // 1. Create simulator + CardSimulator simulator = new CardSimulator(); + + // 2. Install applet + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // 3. Select applet + simulator.selectApplet(appletAID); + + // 4. Send APDU + CommandAPDU commandAPDU = new CommandAPDU(0x00, 0x01, 0x00, 0x00); + ResponseAPDU response = simulator.transmitCommand(commandAPDU); + + // 5. Check response status word + assertEquals(0x9000, response.getSW()); + } + + + public void testCodeListing2() { + CardSimulator simulator = new CardSimulator(); + + byte[] appletAIDBytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}; + AID appletAID = new AID(appletAIDBytes, (short) 0, (byte) appletAIDBytes.length); + + simulator.installApplet(appletAID, HelloWorldApplet.class); + simulator.selectApplet(appletAID); + + // test NOP + ResponseAPDU response = simulator.transmitCommand(new CommandAPDU(0x00, 0x02, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + + // test hello world from card + response = simulator.transmitCommand(new CommandAPDU(0x00, 0x01, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello world !", new String(response.getData())); + + // test echo + CommandAPDU echo = new CommandAPDU(0x00, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes()); + response = simulator.transmitCommand(echo); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello javacard world !", new String(response.getData())); + } + + public void testCodeListing3() { + CardSimulator simulator = new CardSimulator(); + + byte[] appletAIDBytes = new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}; + AID appletAID = new AID(appletAIDBytes, (short) 0, (byte) appletAIDBytes.length); + + simulator.installApplet(appletAID, HelloWorldApplet.class); + simulator.selectApplet(appletAID); + + // test NOP + byte[] response = simulator.transmitCommand(new byte[]{0x00, 0x02, 0x00, 0x00}); + ByteUtil.requireSW(response, 0x9000); + } + + public void testCodeListing4() { + // AID from byte array + AID applet1AID = AIDUtil.create(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9}); + + // AID form String + AID applet2AID = AIDUtil.create("010203040506070809"); + + assertEquals(applet1AID, applet2AID); + + // String to byte array + String hexString = ByteUtil.hexString(new byte[]{0,2,0,0}); + + // byte array from String + byte[] bytes = ByteUtil.byteArray("00 02 00 00"); + + assertEquals("00020000", hexString); + assertEquals("00020000", ByteUtil.hexString(bytes)); + } + + public void testCodeListing5() throws CardException { + // 1. Create simulator and install applet + CardSimulator simulator = new CardSimulator(); + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // 2. Create Terminal + CardTerminal terminal = CardTerminalSimulator.terminal(simulator); + + // 3. Connect to Card + Card card = terminal.connect("T=1"); + CardChannel channel = card.getBasicChannel(); + + // 4. Select applet + CommandAPDU selectCommand = new CommandAPDU(AIDUtil.select(appletAID)); + channel.transmit(selectCommand); + + // 5. Send APDU + CommandAPDU commandAPDU = new CommandAPDU(0x00, 0x01, 0x00, 0x00); + ResponseAPDU response = simulator.transmitCommand(commandAPDU); + + // 6. Check response status word + assertEquals(0x9000, response.getSW()); + } + + public void testCodeListing6() throws CardException { + // Obtain CardTerminal + CardTerminals cardTerminals = CardTerminalSimulator.terminals("My terminal 1", "My terminal 2"); + CardTerminal terminal1 = cardTerminals.getTerminal("My terminal 1"); + CardTerminal terminal2 = cardTerminals.getTerminal("My terminal 2"); + + assertEquals(false, terminal1.isCardPresent()); + assertEquals(false, terminal2.isCardPresent()); + + // Create simulator and install applet + CardSimulator simulator = new CardSimulator(); + AID appletAID = AIDUtil.create("F000000001"); + simulator.installApplet(appletAID, HelloWorldApplet.class); + + // Insert Card into "My terminal 1" + simulator.assignToTerminal(terminal1); + assertEquals(true, terminal1.isCardPresent()); + assertEquals(false, terminal2.isCardPresent()); + } + + public void testCodeListing7() throws CardException, NoSuchAlgorithmException { + // Register provider + if (Security.getProvider("CardTerminalSimulator") == null) { + Security.addProvider(new CardTerminalSimulator.SecurityProvider()); + } + + // Get TerminalFactory + TerminalFactory factory = TerminalFactory.getInstance("CardTerminalSimulator", null); + CardTerminals cardTerminals = factory.terminals(); + + // Get CardTerminal + CardTerminal terminal = cardTerminals.getTerminal("jCardSim.Terminal"); + assertNotNull(terminal); + } + + public void testCodeListing8() throws CardException, NoSuchAlgorithmException { + // Register provider + if (Security.getProvider("CardTerminalSimulator") == null) { + Security.addProvider(new CardTerminalSimulator.SecurityProvider()); + } + + // Get TerminalFactory with custom names + String[] names = new String[] {"My terminal 1", "My terminal 2"}; + TerminalFactory factory = TerminalFactory.getInstance("CardTerminalSimulator", names); + CardTerminals cardTerminals = factory.terminals(); + assertNotNull(cardTerminals.getTerminal("My terminal 1")); + assertNotNull(cardTerminals.getTerminal("My terminal 2")); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/ApduContextTest.java b/src/test/java/com/licel/jcardsim/base/ApduContextTest.java new file mode 100644 index 00000000..f8c926fe --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/ApduContextTest.java @@ -0,0 +1,116 @@ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.HelloWorldApplet; +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.ByteUtil; +import javacard.framework.*; +import junit.framework.TestCase; + +public class ApduContextTest extends TestCase { + private static class DummyApplet extends Applet implements AppletEvent { + public static boolean exceptionInSelect = false; + public static boolean exceptionInInstall = false; + public static boolean exceptionInDeselect = false; + public static boolean exceptionInUninstall = false; + public static boolean exceptionIllegalUse1 = false; + public static boolean exceptionIllegalUse2 = false; + + @SuppressWarnings("unused") + public static void install(byte[] bArray, short bOffset, byte bLength) { + exceptionInSelect = false; + exceptionInInstall = false; + exceptionInDeselect = false; + exceptionInUninstall = false; + + + try { + APDU.getCurrentAPDU(); + } + catch (SecurityException se) { + exceptionInInstall = true; + } + + new DummyApplet().register(); + } + + @Override + public boolean select() { + try { + APDU.getCurrentAPDU(); + } + catch (SecurityException se) { + exceptionInSelect = true; + } + return true; + } + + @Override + public void process(APDU a) throws ISOException { + APDU apdu = APDU.getCurrentAPDU(); + try { + apdu.getIncomingLength(); + exceptionIllegalUse1 = false; + } + catch (APDUException e) { + exceptionIllegalUse1 = e.getReason() == APDUException.ILLEGAL_USE; + } + try { + apdu.getOffsetCdata(); + exceptionIllegalUse2 = false; + } + catch (APDUException e) { + exceptionIllegalUse2 = e.getReason() == APDUException.ILLEGAL_USE; + } + apdu.setIncomingAndReceive(); + apdu.getIncomingLength(); + apdu.getOffsetCdata(); + } + + @Override + public void deselect() { + try { + APDU.getCurrentAPDU(); + } + catch (SecurityException se) { + exceptionInDeselect = true; + } + } + + public void uninstall() { + try { + APDU.getCurrentAPDU(); + } + catch (SecurityException se) { + exceptionInUninstall = true; + } + } + } + + public ApduContextTest(String name) { + super(name); + } + + public void testCallingGetCurrentAPDUinWrongContextThrows() { + Simulator simulator = new Simulator(); + AID otherAppletAID = AIDUtil.create("d0000cafe00001"); + AID dummyAppletAID = AIDUtil.create("d0000cafe00002"); + + simulator.installApplet(otherAppletAID, HelloWorldApplet.class); + simulator.installApplet(dummyAppletAID, DummyApplet.class); + assertTrue(DummyApplet.exceptionInInstall); + + simulator.selectApplet(dummyAppletAID); + assertTrue(DummyApplet.exceptionInSelect); + + byte[] response = simulator.transmitCommand(new byte[]{(byte) 0x80,0,0,0}); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(response)); + assertTrue(DummyApplet.exceptionIllegalUse1); + assertTrue(DummyApplet.exceptionIllegalUse2); + + simulator.selectApplet(otherAppletAID); + assertTrue(DummyApplet.exceptionInDeselect); + + simulator.deleteApplet(dummyAppletAID); + assertTrue(DummyApplet.exceptionInUninstall); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/DeleteTest.java b/src/test/java/com/licel/jcardsim/base/DeleteTest.java new file mode 100644 index 00000000..2156f255 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/DeleteTest.java @@ -0,0 +1,51 @@ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.MultiInstanceApplet; +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.ByteUtil; +import javacard.framework.AID; +import javacard.framework.ISO7816; +import junit.framework.TestCase; + +public class DeleteTest extends TestCase { + private static final byte CLA = (byte) 0x80; + private static final byte INS_GET_COUNT = 2; + + public DeleteTest(String name) { + super(name); + } + + public void testDeleteWorks() { + byte[] result; + AID aid1 = AIDUtil.create("d0000cafe00001"); + AID aid2 = AIDUtil.create("d0000cafe00002"); + + Simulator simulator = new Simulator(); + + // install first instance + simulator.installApplet(aid1, MultiInstanceApplet.class); + simulator.selectApplet(aid1); + + // check instance counter == 1 + result = simulator.transmitCommand(new byte[]{CLA, INS_GET_COUNT, 0, 0}); + assertEquals(1, ByteUtil.getShort(result, 0)); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(result)); + + // install second instance + simulator.installApplet(aid2, MultiInstanceApplet.class); + + // check instance counter == 2 + result = simulator.transmitCommand(new byte[]{CLA, INS_GET_COUNT, 0, 0}); + assertEquals(2, ByteUtil.getShort(result, 0)); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(result)); + + // delete instance 1 + simulator.deleteApplet(aid1); + + // check instance counter == 1 + simulator.selectApplet(aid2); + result = simulator.transmitCommand(new byte[]{CLA, INS_GET_COUNT, 0, 0}); + assertEquals(1, ByteUtil.getShort(result, 0)); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(result)); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/ExtendedLengthTest.java b/src/test/java/com/licel/jcardsim/base/ExtendedLengthTest.java new file mode 100644 index 00000000..fb14786a --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/ExtendedLengthTest.java @@ -0,0 +1,160 @@ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.Sha1Applet; +import javacard.framework.AID; +import junit.framework.TestCase; +import org.bouncycastle.util.encoders.Hex; + +import javax.smartcardio.ResponseAPDU; +import java.nio.ByteBuffer; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +public class ExtendedLengthTest extends TestCase { + private static final byte CLA = (byte) 0x80; + private static final byte INS_DIGEST = 0; + private static final byte INS_ECHO = 2; + private static final byte INS_LEN = 4; + private static final byte P1 = (byte) 0; + private static final byte P2 = (byte) 0; + private static final byte DUMMY = (byte) 0x41; + + private static final byte[] TEST_APPLET_AID_BYTES = Hex.decode("0102030405cafe01"); + + public ExtendedLengthTest(String testName) { + super(testName); + } + + private Simulator prepareSimulator() { + Simulator instance = new Simulator(); + AID aid = new AID(TEST_APPLET_AID_BYTES, (short) 0, (byte) TEST_APPLET_AID_BYTES.length); + instance.installApplet(aid, Sha1Applet.class); + instance.selectApplet(aid); + return instance; + } + + public void testRegularApduDigest() throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + byte[] expectedOutput = sha1.digest(new byte[]{DUMMY}); + + Simulator instance = prepareSimulator(); + + byte[] apdu = new byte[]{CLA, INS_DIGEST, P1, P2, 1, DUMMY}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testRegularApduLcLe() { + byte lc = 1; + byte le = (byte) 0xA0; + byte[] expectedOutput = new byte[]{0, lc, 0, le}; + + Simulator instance = prepareSimulator(); + + byte[] apdu = new byte[]{CLA, INS_LEN, P1, P2, lc, 0, le}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testRegularApduEcho() throws NoSuchAlgorithmException { + byte[] expectedOutput = new byte[]{DUMMY}; + + Simulator instance = prepareSimulator(); + + byte[] apdu = new byte[]{CLA, INS_ECHO, 0, 0, 1, DUMMY}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testExtendedApduDigestWith1Byte() throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + byte[] input = new byte[]{DUMMY}; + byte[] expectedOutput = sha1.digest(input); + + Simulator instance = prepareSimulator(); + + byte[] apdu = new byte[]{CLA, INS_DIGEST, 0, 0, 0, 0, 1, DUMMY}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testExtendedApduLcLe() { + byte[] expectedOutput = {0x0, 0x1, 0x1F, (byte) 0xCA}; + + Simulator instance = prepareSimulator(); + + byte[] apdu = new byte[]{CLA, INS_LEN, P1, P2, 0, 0, 1, DUMMY, 0x1F, (byte) 0xCA}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testExtendedApduEchoWith1Byte() throws NoSuchAlgorithmException { + byte[] expectedOutput = {0x41}; + + Simulator instance = prepareSimulator(); + byte[] apdu = new byte[]{CLA, INS_ECHO, 0, 0, 0, 0, 1, DUMMY}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testExtendedApduDigest() throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + byte[] input = new byte[Short.MAX_VALUE]; + Arrays.fill(input, DUMMY); + byte[] expectedOutput = sha1.digest(input); + + Simulator instance = prepareSimulator(); + + ByteBuffer inputApdu = ByteBuffer.wrap(new byte[input.length + 7]); + inputApdu.put(CLA); + inputApdu.put(INS_DIGEST); + inputApdu.put(P1); + inputApdu.put(P2); + inputApdu.put((byte) 0).putShort((short) input.length); // Lc + inputApdu.put(input); + + byte[] result = instance.transmitCommand(inputApdu.array()); + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + } + + public void testExtendedApduEcho() { + byte[] input = new byte[Short.MAX_VALUE - 2]; + Arrays.fill(input, (byte) 0x41); + + Simulator instance = prepareSimulator(); + + ByteBuffer inputApdu = ByteBuffer.wrap(new byte[input.length + 7]); + inputApdu.put(CLA); + inputApdu.put(INS_ECHO); + inputApdu.put(P1); + inputApdu.put(P2); + inputApdu.put((byte) 0).putShort((short) input.length); // Lc + inputApdu.put(input); + + byte[] result = instance.transmitCommand(inputApdu.array()); + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(input), Arrays.toString(responseApdu.getData())); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/ProtocolTest.java b/src/test/java/com/licel/jcardsim/base/ProtocolTest.java new file mode 100644 index 00000000..35f189f4 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/ProtocolTest.java @@ -0,0 +1,58 @@ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.DualInterfaceApplet; +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.ByteUtil; +import javacard.framework.AID; +import javacard.framework.APDU; +import javacard.framework.ISO7816; +import junit.framework.TestCase; + +public class ProtocolTest extends TestCase { + private static final byte CLA = (byte) 0x80; + private static final byte INS_READ = 0; + private static final byte INS_WRITE = 2; + private static final byte INS_INFO = 4; + + private final AID aid = AIDUtil.create("D0000CAFE00001"); + + public ProtocolTest(String name) { + super(name); + } + + public void testDualInterfaceApplet() { + final String expectedOutput = "CAFE9000"; + byte[] response; + + Simulator simulator = new Simulator(); + simulator.installApplet(aid, DualInterfaceApplet.class); + simulator.selectApplet(aid); + + // check interface is T=0 (contacted) + response = simulator.transmitCommand(new byte[]{CLA, INS_INFO, 0, 0}); + assertEquals(APDU.PROTOCOL_T0, response[0]); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(response)); + + // store data + response = simulator.transmitCommand(new byte[]{CLA,INS_WRITE,0,0,2, (byte) 0xCA, (byte) 0xFE}); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(response)); + + // read data + response = simulator.transmitCommand(new byte[]{CLA, INS_READ, 0, 0}); + assertEquals(expectedOutput, ByteUtil.hexString(response)); + + // change protocol + simulator.changeProtocol("T=CL"); + response = simulator.transmitCommand(new byte[]{CLA, INS_INFO, 0, 0}); + assertEquals(APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A, response[0]); + assertEquals(ISO7816.SW_NO_ERROR, ByteUtil.getSW(response)); + + // read data + response = simulator.transmitCommand(new byte[]{CLA, INS_READ, 0, 0}); + assertEquals(expectedOutput, ByteUtil.hexString(response)); + + // store data should fail + response = simulator.transmitCommand(new byte[]{CLA,INS_WRITE,0,0,2, (byte) 0xBA, (byte) 0xD0}); + assertEquals(ISO7816.SW_CONDITIONS_NOT_SATISFIED, ByteUtil.getSW(response)); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/SelectTest.java b/src/test/java/com/licel/jcardsim/base/SelectTest.java new file mode 100644 index 00000000..a781c077 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/SelectTest.java @@ -0,0 +1,134 @@ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.MultiInstanceApplet; +import com.licel.jcardsim.utils.AIDUtil; +import com.licel.jcardsim.utils.ByteUtil; +import javacard.framework.*; +import junit.framework.TestCase; +import org.bouncycastle.util.encoders.Hex; + +import java.util.Arrays; + +public class SelectTest extends TestCase { + private static final byte CLA = (byte) 0x80; + private static final byte INS_GET_FULL_AID = 0; + + private static boolean selectedCalled; + + private static class UnselectableApplet extends Applet { + @SuppressWarnings("unused") + public static void install(byte[] bArray, short bOffset, byte bLength) { + new UnselectableApplet().register(); + } + + @Override + public boolean select() { + selectedCalled = true; + return false; + } + + @Override + public void process(APDU apdu) throws ISOException { + } + } + + public SelectTest(String name) { + super(name); + } + + public void testAidComparator() { + AID[] input = new AID[] { + AIDUtil.create("A000008812"), + AIDUtil.create("FF00066767"), + AIDUtil.create("D0000CAFE001"), + AIDUtil.create("D0000CAFE000"), + AIDUtil.create("D0000CAFE00023"), + AIDUtil.create("D0000CAFE00001"), + AIDUtil.create("0100CAFE01"), + AIDUtil.create("0200888888") + }; + Arrays.sort(input, AIDUtil.comparator()); + + String[] tmp = new String[input.length]; + for (int i = 0; i < input.length; i++) { + tmp[i] = AIDUtil.toString(input[i]); + } + String expected = "[0100CAFE01, 0200888888, A000008812, " + + "D0000CAFE000, D0000CAFE00001, D0000CAFE00023, D0000CAFE001, FF00066767]"; + + assertEquals(expected, Arrays.toString(tmp)); + } + + private Simulator prepareSimulator() { + AID aid0 = AIDUtil.create("010203040506070809"); + AID aid1 = AIDUtil.create("d0000cafe00001"); + AID aid2 = AIDUtil.create("d0000cafe00002"); + + Simulator simulator = new Simulator(); + simulator.installApplet(aid0, MultiInstanceApplet.class); + simulator.installApplet(aid2, MultiInstanceApplet.class); + simulator.installApplet(aid1, MultiInstanceApplet.class); + return simulator; + } + + public void testPartialSelectWorks1() { + Simulator simulator = prepareSimulator(); + + // should select d0000cafe00001 + assertTrue(simulator.selectApplet(AIDUtil.create("d0000cafe0"))); + byte[] expected = Hex.decode("d0000cafe000019000"); + byte[] actual = simulator.transmitCommand(new byte[]{CLA,INS_GET_FULL_AID,0,0}); + assertEquals(Arrays.toString(expected), Arrays.toString(actual)); + } + + public void testPartialSelectWorks2() { + Simulator simulator = prepareSimulator(); + + // should select d0000cafe00001 + simulator.transmitCommand(new byte[]{0, ISO7816.INS_SELECT, 4, 0, 1, (byte) 0xD0}); + + byte[] expected = Hex.decode("d0000cafe000019000"); + byte[] actual = simulator.transmitCommand(new byte[]{CLA,INS_GET_FULL_AID,0,0}); + assertEquals(Arrays.toString(expected), Arrays.toString(actual)); + } + + public void testEmptySelectWorks() { + final byte[] expected = Hex.decode("0102030405060708099000"); + Simulator simulator = prepareSimulator(); + + // should select 010203040506070809 + simulator.transmitCommand(new byte[]{0, ISO7816.INS_SELECT, 4, 0}); + byte[] actual = simulator.transmitCommand(new byte[]{CLA,INS_GET_FULL_AID, 0, 0}); + assertEquals(Arrays.toString(expected), Arrays.toString(actual)); + + // should select 010203040506070809 + simulator.transmitCommand(new byte[]{0, ISO7816.INS_SELECT, 4, 0, 0}); + actual = simulator.transmitCommand(new byte[]{CLA,INS_GET_FULL_AID,0,0}); + assertEquals(Arrays.toString(expected), Arrays.toString(actual)); + } + + public void testCanNotSelectUnselectableApplet() { + selectedCalled = false; + + AID aid = AIDUtil.create("010203040506070809"); + Simulator simulator = new Simulator(); + simulator.installApplet(aid, UnselectableApplet.class); + + byte[] result = simulator.selectAppletWithResult(aid); + assertEquals(2, result.length); + assertEquals(ISO7816.SW_APPLET_SELECT_FAILED, Util.getShort(result, (short)0)); + assertTrue(selectedCalled); + } + + public void testApduWithoutSelectedAppletFails() { + Simulator simulator = new Simulator(); + byte[] cmd = new byte[]{CLA, INS_GET_FULL_AID, 0, 0}; + byte[] result; + + result = simulator.transmitCommand(cmd); + assertEquals(ISO7816.SW_COMMAND_NOT_ALLOWED, ByteUtil.getSW(result)); + + result = CardManager.dispatchApdu(simulator, new byte[]{CLA,INS_GET_FULL_AID, 0, 0}); + assertEquals(ISO7816.SW_COMMAND_NOT_ALLOWED, ByteUtil.getSW(result)); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/SimulatorTest.java b/src/test/java/com/licel/jcardsim/base/SimulatorTest.java new file mode 100644 index 00000000..dbd094d3 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/SimulatorTest.java @@ -0,0 +1,266 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.HelloWorldApplet; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import javacard.framework.AID; +import javacard.framework.Applet; +import javacard.framework.ISO7816; +import javacard.framework.Util; +import junit.framework.TestCase; +import org.bouncycastle.util.Arrays; +import org.bouncycastle.util.encoders.Hex; + +/** + * + */ +public class SimulatorTest extends TestCase { + + private static final byte[] ETALON_ATR = Hex.decode("3BFA1800008131FE454A434F5033315632333298"); + private static final byte[] TEST_APPLET_AID_BYTES = Hex.decode("010203040506070809"); + private static final Class TEST_APPLET_CLASS = HelloWorldApplet.class; + private static final String TEST_APPLET_CLASSNAME = "com.licel.jcardsim.samples.HelloWorldApplet"; + private static final AID TEST_APPLET_AID = new AID(TEST_APPLET_AID_BYTES, (short)0, (byte) TEST_APPLET_AID_BYTES.length); + private static final byte[] TEST_APPLET1_AID_BYTES = Hex.decode("01020304050607080A"); + private static final String TEST_APPLET1_CLASSNAME = "com.licel.jcardsim.samples.HelloWorldApplet1"; + private static final AID TEST_APPLET1_AID = new AID(TEST_APPLET1_AID_BYTES, (short)0, (byte) TEST_APPLET1_AID_BYTES.length); + + byte[] createData = null; + byte[] appletJarContents = null; + + public SimulatorTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + createData = new byte[1+TEST_APPLET_AID_BYTES.length+1+2+3]; + createData[0] = (byte) TEST_APPLET_AID_BYTES.length; + System.arraycopy(TEST_APPLET_AID_BYTES, 0, createData, 1, TEST_APPLET_AID_BYTES.length); + createData[1+TEST_APPLET_AID_BYTES.length] = (byte) 5; + createData[2+TEST_APPLET_AID_BYTES.length] = 0; // aid + createData[3+TEST_APPLET_AID_BYTES.length] = 0; // control + createData[4+TEST_APPLET_AID_BYTES.length] = 2; // params + createData[5+TEST_APPLET_AID_BYTES.length] = 0xF; // params + createData[6+TEST_APPLET_AID_BYTES.length] = 0xF; // params + InputStream is = SimulatorTest.class.getResourceAsStream("helloworld.jar"); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] chunk = new byte[1024]; + int readed = is.read(chunk); + while (readed > 0) { + bos.write(chunk, 0, readed); + readed = is.read(chunk); + } + appletJarContents = bos.toByteArray(); + bos.close(); + is.close(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test of loadApplet method, of class Simulator. + */ + public void testLoadApplet_3args() { + System.out.println("loadApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.loadApplet(TEST_APPLET1_AID, TEST_APPLET1_CLASSNAME, appletJarContents).equals(TEST_APPLET1_AID),true); + } + + /** + * Test of loadApplet method, of class Simulator. + */ + public void testLoadApplet_AID_String() { + System.out.println("loadApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.loadApplet(TEST_APPLET_AID, TEST_APPLET_CLASSNAME).equals(TEST_APPLET_AID),true); + } + + /** + * Test of loadApplet method, of class Simulator. + */ + public void testLoadApplet_AID_Class() { + System.out.println("loadApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.loadApplet(TEST_APPLET_AID, TEST_APPLET_CLASS).equals(TEST_APPLET_AID),true); + } + + /** + * Test of createApplet method, of class Simulator. + */ + public void testCreateApplet() { + System.out.println("createApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.loadApplet(TEST_APPLET_AID, TEST_APPLET_CLASS).equals(TEST_APPLET_AID),true); + assertEquals(instance.createApplet(TEST_APPLET_AID, createData, (short)0, (byte) createData.length).equals(TEST_APPLET_AID),true); + } + + /** + * Test of installApplet method, of class Simulator. + */ + public void testInstallApplet_AID_Class() { + System.out.println("installApplet"); + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + assertEquals(instance.selectApplet(TEST_APPLET_AID), true); + } + + /** + * Test of installApplet method, of class Simulator. + */ + public void testInstallApplet_5args_1() { + System.out.println("installApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS, createData, (short)0, (byte) createData.length).equals(TEST_APPLET_AID),true); + } + + /** + * Test of installApplet method, of class Simulator. + */ + public void testInstallApplet_5args_2() { + System.out.println("installApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASSNAME, createData, (short)0, (byte) createData.length).equals(TEST_APPLET_AID),true); + } + + /** + * Test of installApplet method, of class Simulator. + */ + public void testInstallApplet_6args() { + System.out.println("installApplet"); + Simulator instance = new Simulator(); + assertEquals(instance.installApplet(TEST_APPLET1_AID, TEST_APPLET1_CLASSNAME, appletJarContents, createData, (short)0, (byte) createData.length).equals(TEST_APPLET1_AID),true); + assertEquals(instance.selectApplet(TEST_APPLET1_AID), true); + // test NOP + byte[] response = instance.transmitCommand(new byte[]{0x01, 0x02, 0x00, 0x00}); + assertEquals(Arrays.areEqual(new byte[]{(byte)0x90, 0x00}, response), true); + } + + public void testNopWithLengthExtensionsFails() { + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + instance.selectApplet(TEST_APPLET_AID); + // test NOP with Lc=1 + byte[] response1 = instance.transmitCommand(new byte[]{0x01, 0x02, 0x00, 0x00, 0, 0, 1, 0xA}); + assertEquals(ISO7816.SW_WRONG_LENGTH, Util.getShort(response1, (short) 0)); + // test NOP with Le=1 + byte[] response2 = instance.transmitCommand(new byte[]{0x01, 0x02, 0x00, 0x00, 0, 0, 1}); + assertEquals(ISO7816.SW_WRONG_LENGTH, Util.getShort(response2, (short) 0)); + // test NOP with Lc=1, Le=1 + byte[] response3 = instance.transmitCommand(new byte[]{0x01, 0x02, 0x00, 0x00, 0, 0, 1, 0xA, 0, 1}); + assertEquals(ISO7816.SW_WRONG_LENGTH, Util.getShort(response3, (short) 0)); + } + + /** + * Test of selectApplet method, of class Simulator. + */ + public void testSelectApplet() { + System.out.println("selectApplet"); + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + assertEquals(instance.selectApplet(TEST_APPLET_AID), true); + } + + /** + * Test of selectAppletWithResult method, of class Simulator. + */ + public void testSelectAppletWithResult() { + System.out.println("selectApplet"); + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + byte[] result = instance.selectAppletWithResult(TEST_APPLET_AID); + assertEquals(result[0], (byte)0x90); + assertEquals(result[1], 0x00); + } + + /** + * Test of transmitCommand method, of class Simulator. + */ + public void testTransmitCommand() { + System.out.println("transmitCommand"); + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + assertEquals(instance.selectApplet(TEST_APPLET_AID), true); + // test NOP + byte[] response = instance.transmitCommand(new byte[]{0x01, 0x02, 0x00, 0x00}); + assertEquals(Arrays.areEqual(new byte[]{(byte)0x90, 0x00}, response), true); + } + + /** + * Test of reset method, of class Simulator. + */ + public void testReset() { + System.out.println("reset"); + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + instance.reset(); + // after reset installed applets not deleted + assertEquals(instance.selectApplet(TEST_APPLET_AID), true); + } + + /** + * Test of resetRuntime method, of class Simulator. + */ + public void testResetRuntime() { + System.out.println("resetRuntime"); + Simulator instance = new Simulator(); + instance.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + instance.resetRuntime(); + // after reset runtime all applets removed + assertEquals(instance.selectApplet(TEST_APPLET_AID), false); + } + + /** + * Test of getATR method, of class Simulator. + */ + public void testGetATR() { + System.out.println("getATR"); + Simulator instance = new Simulator(); + byte[] result = instance.getATR(); + assertEquals(Arrays.areEqual(ETALON_ATR, result), true); + } + + /** + * Test of selectApplet method, of class Simulator. + */ + public void testSelectAppletWith2Simulators() { + System.out.println("selectAppletWith2Simulators"); + Simulator instance1 = new Simulator(new SimulatorRuntime()); + Simulator instance2 = new Simulator(new SimulatorRuntime()); + + instance1.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + assertTrue(instance1.selectApplet(TEST_APPLET_AID)); + assertFalse(instance2.selectApplet(TEST_APPLET_AID)); + + instance2.installApplet(TEST_APPLET_AID, TEST_APPLET_CLASS); + assertTrue(instance1.selectApplet(TEST_APPLET_AID)); + assertTrue(instance2.selectApplet(TEST_APPLET_AID)); + + instance2.resetRuntime(); + assertTrue(instance1.selectApplet(TEST_APPLET_AID)); + assertFalse(instance2.selectApplet(TEST_APPLET_AID)); + + instance1.resetRuntime(); + assertFalse(instance1.selectApplet(TEST_APPLET_AID)); + assertFalse(instance2.selectApplet(TEST_APPLET_AID)); + } +} diff --git a/src/test/java/com/licel/jcardsim/base/TransientMemoryTest.java b/src/test/java/com/licel/jcardsim/base/TransientMemoryTest.java new file mode 100644 index 00000000..b83009e8 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/base/TransientMemoryTest.java @@ -0,0 +1,161 @@ +package com.licel.jcardsim.base; + +import com.licel.jcardsim.samples.Sha1Applet; +import com.licel.jcardsim.utils.AIDUtil; +import javacard.framework.AID; +import javacard.framework.JCSystem; +import javacard.framework.SystemException; +import junit.framework.TestCase; + +import javax.smartcardio.ResponseAPDU; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; + +public class TransientMemoryTest extends TestCase { + private static final byte CLA = (byte) 0x80; + private static final byte INS_DIGEST = 0; + private static final byte INS_LAST_DIGEST = 6; + + public TransientMemoryTest(String name) { + super(name); + } + + public void testMemoryManagementWorks() { + final Object dummy1 = new Object(); + + final short size = 1; + TransientMemory transientMemory = new TransientMemory(); + + byte[] corBytes = transientMemory.makeByteArray(size, JCSystem.CLEAR_ON_RESET); + short[] corShorts = transientMemory.makeShortArray(size, JCSystem.CLEAR_ON_RESET); + boolean[] corBooleans = transientMemory.makeBooleanArray(size, JCSystem.CLEAR_ON_RESET); + + Object[] corObjects = transientMemory.makeObjectArray(size, JCSystem.CLEAR_ON_RESET); + corBytes[0] = 123; + corShorts[0] = 123; + corBooleans[0] = true; + corObjects[0] = dummy1; + + byte[] codBytes = transientMemory.makeByteArray(size, JCSystem.CLEAR_ON_DESELECT); + short[] codShorts = transientMemory.makeShortArray(size, JCSystem.CLEAR_ON_DESELECT); + boolean[] codBooleans = transientMemory.makeBooleanArray(size, JCSystem.CLEAR_ON_DESELECT); + + Object[] codObjects = transientMemory.makeObjectArray(size, JCSystem.CLEAR_ON_DESELECT); + codBytes[0] = 123; + codShorts[0] = 123; + codBooleans[0] = true; + codObjects[0] = dummy1; + + transientMemory.clearOnDeselect(); + assertTrue(codBytes[0] == 0 && corBytes[0] != 0); + assertTrue(codShorts[0] == 0 && corShorts[0] != 0); + assertTrue(codObjects[0] == null && corObjects[0] == dummy1); + assertTrue(!codBooleans[0] && corBooleans[0]); + + codBytes[0] = 123; + codShorts[0] = 123; + codBooleans[0] = true; + codObjects[0] = dummy1; + + transientMemory.clearOnReset(); + assertTrue(codBytes[0] == 0 && corBytes[0] == 0); + assertTrue(codShorts[0] == 0 && corShorts[0] == 0); + assertTrue(codObjects[0] == null && corObjects[0] == null); + assertTrue(!codBooleans[0] && !corBooleans[0]); + + assertEquals(JCSystem.CLEAR_ON_RESET, transientMemory.isTransient(corBytes)); + assertEquals(JCSystem.CLEAR_ON_RESET, transientMemory.isTransient(corShorts)); + assertEquals(JCSystem.CLEAR_ON_RESET, transientMemory.isTransient(corBooleans)); + assertEquals(JCSystem.CLEAR_ON_RESET, transientMemory.isTransient(corObjects)); + + assertEquals(JCSystem.CLEAR_ON_DESELECT, transientMemory.isTransient(codBytes)); + assertEquals(JCSystem.CLEAR_ON_DESELECT, transientMemory.isTransient(codShorts)); + assertEquals(JCSystem.CLEAR_ON_DESELECT, transientMemory.isTransient(codBooleans)); + assertEquals(JCSystem.CLEAR_ON_DESELECT, transientMemory.isTransient(codObjects)); + + transientMemory.forgetBuffers(); + + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(corBytes)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(corShorts)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(corBooleans)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(corObjects)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(codBytes)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(codShorts)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(codBooleans)); + assertEquals(JCSystem.NOT_A_TRANSIENT_OBJECT, transientMemory.isTransient(codObjects)); + } + + + public void testInvalidEventThrows() { + final byte invalid = JCSystem.CLEAR_ON_DESELECT + JCSystem.CLEAR_ON_RESET; + TransientMemory transientMemory = new TransientMemory(); + + try { + transientMemory.makeByteArray(2, invalid); + fail("No exception"); + } + catch (SystemException e) { + assertEquals(SystemException.ILLEGAL_VALUE, e.getReason()); + } + + try { + transientMemory.makeBooleanArray((short) 1, invalid); + fail("No exception"); + } + catch (SystemException e) { + assertEquals(SystemException.ILLEGAL_VALUE, e.getReason()); + } + + try { + transientMemory.makeObjectArray((short) 1, invalid); + fail("No exception"); + } + catch (SystemException e) { + assertEquals(SystemException.ILLEGAL_VALUE, e.getReason()); + } + + try { + transientMemory.makeBooleanArray((short) 1, invalid); + fail("No exception"); + } + catch (SystemException e) { + assertEquals(SystemException.ILLEGAL_VALUE, e.getReason()); + } + } + + public void testCleanOnDeselectWorks() throws NoSuchAlgorithmException { + MessageDigest sha1 = MessageDigest.getInstance("SHA1"); + byte[] expectedOutput = sha1.digest(new byte[]{'A'}); + AID aid = AIDUtil.create("0102030405"); + + Simulator instance = new Simulator(); + instance.installApplet(aid, Sha1Applet.class); + instance.selectApplet(aid); + + // calculate SHA1 + byte[] apdu = new byte[]{CLA, INS_DIGEST, 0, 0, 1, 'A'}; + byte[] result = instance.transmitCommand(apdu); + + ResponseAPDU responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + + // check last digest + apdu = new byte[]{CLA, INS_LAST_DIGEST, 0, 0}; + result = instance.transmitCommand(apdu); + responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(expectedOutput), Arrays.toString(responseApdu.getData())); + + // trigger clean on deselect + instance.selectApplet(aid); + + // check last digest is all zero + apdu = new byte[]{CLA, INS_LAST_DIGEST, 0, 0}; + result = instance.transmitCommand(apdu); + responseApdu = new ResponseAPDU(result); + assertEquals(0x9000, responseApdu.getSW()); + assertEquals(Arrays.toString(new byte[20]), Arrays.toString(responseApdu.getData())); + } +} diff --git a/src/test/java/com/licel/jcardsim/crypto/AssymetricCipherImplTest.java b/src/test/java/com/licel/jcardsim/crypto/AsymmetricCipherImplTest.java similarity index 78% rename from src/test/java/com/licel/jcardsim/crypto/AssymetricCipherImplTest.java rename to src/test/java/com/licel/jcardsim/crypto/AsymmetricCipherImplTest.java index fd144530..da4f7291 100644 --- a/src/test/java/com/licel/jcardsim/crypto/AssymetricCipherImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/AsymmetricCipherImplTest.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.KeyBuilder; import javacard.security.KeyPair; import javacard.security.RandomData; @@ -27,9 +26,9 @@ * Test for AsymmetricCipherImpl * Test data from NXP JCOP31-36 JavaCard */ -public class AssymetricCipherImplTest extends TestCase { +public class AsymmetricCipherImplTest extends TestCase { - public AssymetricCipherImplTest(String testName) { + public AsymmetricCipherImplTest(String testName) { super(testName); } @@ -42,7 +41,7 @@ protected void tearDown() throws Exception { } /** - * SelfTest of RSA Encryption/Decryption, of class AssymetricCipherImpl. + * SelfTest of RSA Encryption/Decryption, of class AsymmetricCipherImpl. */ public void testSelftRSA() { Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false); @@ -50,14 +49,14 @@ public void testSelftRSA() { kp.genKeyPair(); cipher.init(kp.getPublic(), Cipher.MODE_ENCRYPT); - byte[] msg = JCSystem.makeTransientByteArray((short) 127, JCSystem.CLEAR_ON_RESET); - byte[] encryptedMsg = JCSystem.makeTransientByteArray((short) 128, JCSystem.CLEAR_ON_RESET); + byte[] msg = new byte[127]; + byte[] encryptedMsg = new byte[128]; RandomData rnd = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); rnd.generateData(msg, (short) 0, (short) msg.length); cipher.doFinal(msg, (short) 0, (short) msg.length, encryptedMsg, (short) 0); cipher.init(kp.getPrivate(), Cipher.MODE_DECRYPT); - byte[] decryptedMsg = JCSystem.makeTransientByteArray((short) msg.length, JCSystem.CLEAR_ON_RESET); + byte[] decryptedMsg = new byte[msg.length]; cipher.doFinal(encryptedMsg, (short) 0, (short) encryptedMsg.length, decryptedMsg, (short) 0); assertEquals(true, Arrays.areEqual(msg, decryptedMsg)); diff --git a/src/test/java/com/licel/jcardsim/crypto/AsymmetricSignatureImplTest.java b/src/test/java/com/licel/jcardsim/crypto/AsymmetricSignatureImplTest.java index 744fe3e8..2cb1d62b 100644 --- a/src/test/java/com/licel/jcardsim/crypto/AsymmetricSignatureImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/AsymmetricSignatureImplTest.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.KeyBuilder; import javacard.security.KeyPair; import javacard.security.PrivateKey; @@ -48,6 +47,11 @@ public class AsymmetricSignatureImplTest extends TestCase { "2BCBD3220787D8D621526FBF88E852158FB37B46A339EAAF64742548155C7A48DA3ED9D41B9A29BAB2582A81329411C9FB0FDE0BFCF962438440C68828C1FDC3B33A4F0FEE318FA9DA3802A5CBAA9E9D6EA3618A2626E9FDA6F5613335F868442E20B3EB2E5C0580CE6E999BBD33A9BD5C633FE18930916586D91527781F1081" }; + // RSA 2048-bit public key data from card + final static String RSA_2048_MODULUS = "8D4E29049C1C1861557F78B399665AAF957B73EBCCF5A436ED204A3B2C88F7A73ACE693147A6A731FFC297FBDFEABBA3658FDA68F0C3A60C2D8A96F874293FADE00F6AF600091A59118E8388DC69FD2D737882FBBB624A1A8BBD89641CFE33FC9C85BBC99017FCFE5CD5D13A3FE70524BE870171B0DBC870CB2F123CA5540C3B0759B71871A08EE3521C66261DCC1BD8F95DC850B730D8B8F0CF80F19C71B35FCB0439F419E7BD8E7B6A55203EFC6191D79DEF46B8A8F47EDF38F9E618A885BDFB8B212919D41CA1AB2B9B48328A9F4CF552FC157B8A1361A5ACABEE27725E835622D633569291532384EE47817AEB75119294E8522444FCCCB4F54073C2E121"; + // RSA 2048-bit Signature + final static String RSA_2048_SIGNATURE = "27E3B9410C261BE66534B9FC8CB272902B8BFB06077CA973B39B512C48DD878FA4B00259E7B58ECD5F236127990DC6E10DAB1CAF4C967689C1D1A03A5C5EBD6EA617D5F0AEE09851207EC4BCE67287687F21AC450693B9B22CEC7EA87679FC6BCE1B2DA56F41BF9BD433932370379C103D269E9E529E46699E03E243B589DE5469B12E27B1F95E8FE6F872010A64126760AC51AEF44CDABE4D9FBC7568B12A077943E8CF3A4C3C1674B3600B1AA01CB2D290A0DC7968F1509BEB5ECC47C48789870D5279E675D67E262AF96CD8750D9C4CE450D64FDC8D135573B9BB0497B4A6F3F3034832707C116D2E3E51EC85D6BCF8AF681AC96245CD03D50CF5D391B0AF"; + public AsymmetricSignatureImplTest(String testName) { super(testName); } @@ -71,6 +75,13 @@ public void testVerifyRSA() { byte[] exponent = Hex.decode(RSA_ETALON_EXP); publicKey.setModulus(modulus, (short) 0, (short) modulus.length); publicKey.setExponent(exponent, (short) 0, (short) exponent.length); + + RSAPublicKey publicKey2048 = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, + KeyBuilder.LENGTH_RSA_2048, false); + byte[] modulus2048 = Hex.decode(RSA_2048_MODULUS); + publicKey2048.setModulus(modulus2048, (short) 0, (short) modulus2048.length); + publicKey2048.setExponent(exponent, (short) 0, (short) exponent.length); + // verify signs Signature signature = Signature.getInstance(Signature.ALG_RSA_SHA_ISO9796, false); testEngineVerify(signature, publicKey, Hex.decode(MESSAGE), @@ -80,6 +91,10 @@ public void testVerifyRSA() { testEngineVerify(signature, publicKey, Hex.decode(MESSAGE), Hex.decode(RSA_SIGNATURES[1]), (short) 0); + signature = Signature.getInstance(Signature.ALG_RSA_SHA_PKCS1, false); + testEngineVerify(signature, publicKey2048, new byte[24], + Hex.decode(RSA_2048_SIGNATURE), (short) 0); + signature = Signature.getInstance(Signature.ALG_RSA_MD5_PKCS1, false); testEngineVerify(signature, publicKey, Hex.decode(MESSAGE), Hex.decode(RSA_SIGNATURES[2]), (short) 0); @@ -90,15 +105,16 @@ public void testVerifyRSA() { * SelfTest of RSA sign/verify method, of class AsymmetricSignatureImpl. */ public void testSelfSignVerifyRSA() { - System.out.println("selft test sign/verify rsa"); + System.out.println("self test sign/verify rsa"); testSelfSignVerify(KeyPair.ALG_RSA_CRT, RSA_ETALON_KEY_SIZE, Signature.ALG_RSA_SHA_PKCS1); } + /** * SelfTest of ECDSA sign/verify method, of class AsymmetricSignatureImpl. */ public void testSelfSignVerifyECDSA() { - System.out.println("selft test sign/verify ecdsa"); + System.out.println("self test sign/verify ecdsa"); // ecf2m keys testSelfSignVerify(KeyPair.ALG_EC_F2M, KeyBuilder.LENGTH_EC_F2M_113, Signature.ALG_ECDSA_SHA); // ecfp keys @@ -122,8 +138,8 @@ public void testSelfSignVerify(byte keyAlg, short keySize, byte signAlg) { Signature signEngine = Signature.getInstance(signAlg, false); signEngine.init(privateKey, Signature.MODE_SIGN); // sign length + extra space - byte[] signature = JCSystem.makeTransientByteArray((short) (128 + 10), JCSystem.CLEAR_ON_RESET); - byte[] msg = JCSystem.makeTransientByteArray((short) 65, JCSystem.CLEAR_ON_RESET); + byte[] signature = new byte[128 + 10]; + byte[] msg = new byte[65]; RandomData rnd = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); rnd.generateData(msg, (short) 0, (short) msg.length); short signLen = signEngine.sign(msg, (short) 0, (short) msg.length, signature, (short) 10); @@ -163,5 +179,5 @@ public void testEngineVerify(Signature engine, PublicKey publicKey, boolean result = engine.verify(etalonMsg, (short) 0, (short) etalonMsg.length, etalonSign, etalonSignOffset, (short)(etalonSignLength!=0?etalonSignLength:etalonSign.length)); assertEquals(true, result); - } + } } diff --git a/src/test/java/com/licel/jcardsim/crypto/ByteContainerTest.java b/src/test/java/com/licel/jcardsim/crypto/ByteContainerTest.java new file mode 100644 index 00000000..08e9c3c7 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/crypto/ByteContainerTest.java @@ -0,0 +1,55 @@ +package com.licel.jcardsim.crypto; + +import junit.framework.TestCase; + +import java.math.BigInteger; + +public class ByteContainerTest extends TestCase { + public ByteContainerTest(String name) { + super(name); + } + + public void testPositiveIntegerWithLeadingZero() { + BigInteger expected = new BigInteger("4720643197658441292834747278018339"); + assertTrue(expected.toByteArray()[0] == 0); + checkRoundTrip(expected); + } + + public void testPositiveIntegerWithoutLeadingZero() { + BigInteger expected = new BigInteger("5192296858534827689835882578830703"); + assertTrue(expected.toByteArray()[0] != 0); + checkRoundTrip(expected); + } + + public void testZero() { + BigInteger expected = new BigInteger("0"); + assertTrue(expected.toByteArray()[0] == 0); + checkRoundTrip(expected); + } + + public void testNegativeNumber() { + BigInteger expected = new BigInteger("-123"); + + try { + new ByteContainer().setBigInteger(expected); + fail("No exception"); + } + catch (IllegalArgumentException ignore) { + } + + try { + new ByteContainer(expected); + fail("No exception"); + } + catch (IllegalArgumentException ignore) { + } + } + + private void checkRoundTrip(BigInteger expected) { + ByteContainer byteContainer = new ByteContainer(); + byteContainer.setBigInteger(expected); + assertEquals(expected, byteContainer.getBigInteger()); + + assertEquals(expected, new ByteContainer(expected).getBigInteger()); + } +} diff --git a/src/test/java/com/licel/jcardsim/crypto/CRC16Test.java b/src/test/java/com/licel/jcardsim/crypto/CRC16Test.java index a189aec1..296ffbe9 100644 --- a/src/test/java/com/licel/jcardsim/crypto/CRC16Test.java +++ b/src/test/java/com/licel/jcardsim/crypto/CRC16Test.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.Checksum; import junit.framework.TestCase; import org.bouncycastle.util.Arrays; @@ -50,7 +49,7 @@ protected void tearDown() throws Exception { public void testCrc16() { System.out.println("test crc16"); Checksum crcEngine = Checksum.getInstance(Checksum.ALG_ISO3309_CRC16, false); - byte[] crc = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); + byte[] crc = new byte[2]; byte[] msg = Hex.decode(MESSAGE); crcEngine.doFinal(msg, (short) 0, (short) msg.length, crc, (short) 0); assertEquals(true, Arrays.areEqual(Hex.decode(CRC), crc)); diff --git a/src/test/java/com/licel/jcardsim/crypto/CRC32Test.java b/src/test/java/com/licel/jcardsim/crypto/CRC32Test.java index 945d456e..e15f1a88 100644 --- a/src/test/java/com/licel/jcardsim/crypto/CRC32Test.java +++ b/src/test/java/com/licel/jcardsim/crypto/CRC32Test.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.Checksum; import junit.framework.TestCase; import org.bouncycastle.util.Arrays; @@ -50,7 +49,7 @@ protected void tearDown() throws Exception { public void testCrc32() { System.out.println("test crc32"); Checksum crcEngine = Checksum.getInstance(Checksum.ALG_ISO3309_CRC32, false); - byte[] crc = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_RESET); + byte[] crc = new byte[4]; byte[] msg = Hex.decode(MESSAGE); crcEngine.doFinal(msg, (short) 0, (short) msg.length, crc, (short) 0); assertEquals(true, Arrays.areEqual(Hex.decode(CRC), crc)); diff --git a/src/test/java/com/licel/jcardsim/crypto/ECKeyImplTest.java b/src/test/java/com/licel/jcardsim/crypto/ECKeyImplTest.java new file mode 100644 index 00000000..f45f3d9b --- /dev/null +++ b/src/test/java/com/licel/jcardsim/crypto/ECKeyImplTest.java @@ -0,0 +1,64 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.crypto; + +import java.security.SecureRandom; +import javacard.security.KeyBuilder; +import junit.framework.TestCase; +import org.bouncycastle.crypto.params.ECKeyGenerationParameters; +import org.bouncycastle.math.ec.ECCurve; + +/** + * Test for ECKeyImplTest. + */ +public class ECKeyImplTest extends TestCase { + + public ECKeyImplTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + /** + * Test of getKeyGenerationParameters method, of class ECKeyImpl. + */ + public void testGetKeyGenerationParameters() { + System.out.println("getKeyGenerationParameters"); + SecureRandom rnd = new SecureRandom(); + // public + ECKeyImpl instance = new ECPublicKeyImpl(KeyBuilder.TYPE_EC_F2M_PUBLIC, KeyBuilder.LENGTH_EC_F2M_193); + ECKeyGenerationParameters result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); + assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.F2m, true); + instance = new ECPublicKeyImpl(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_192); + result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); + assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.Fp, true); + //private + instance = new ECPrivateKeyImpl(KeyBuilder.TYPE_EC_F2M_PRIVATE, KeyBuilder.LENGTH_EC_F2M_193); + result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); + assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.F2m, true); + instance = new ECPrivateKeyImpl(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_192); + result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); + assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.Fp, true); + } + +} diff --git a/src/test/java/com/licel/jcardsim/crypto/KeyAgreementImplTest.java b/src/test/java/com/licel/jcardsim/crypto/KeyAgreementImplTest.java index 24acec16..7b094a7a 100644 --- a/src/test/java/com/licel/jcardsim/crypto/KeyAgreementImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/KeyAgreementImplTest.java @@ -71,17 +71,20 @@ public void testGenerateSecret(byte keyAlg, short keySize, byte keyAgreementAlg) ECPublicKey publicKey2 = (ECPublicKey) kp.getPublic(); // generate first secret KeyAgreement ka = KeyAgreement.getInstance(keyAgreementAlg, false); - byte[] secret1 = new byte[128]; + byte[] secret1 = new byte[20]; byte[] public2 = new byte[128]; short publicKeyLength = publicKey2.getW(public2, (short) 0); ka.init(privateKey1); - ka.generateSecret(public2, (short) 0, publicKeyLength, secret1, (short) 0); + short secret1Size = ka.generateSecret(public2, (short) 0, publicKeyLength, secret1, (short) 0); // generate second secret - byte[] secret2 = new byte[128]; + byte[] secret2 = new byte[20]; byte[] public1 = new byte[128]; publicKeyLength = publicKey1.getW(public1, (short) 0); ka.init(privateKey2); - ka.generateSecret(public1, (short) 0, publicKeyLength, secret2, (short) 0); + short secret2Size = ka.generateSecret(public1, (short) 0, publicKeyLength, secret2, (short) 0); + // sha1 size = 20 + assertEquals(secret1Size, 20); + assertEquals(secret2Size, 20); assertEquals(true, Arrays.areEqual(secret1, secret2)); } } \ No newline at end of file diff --git a/src/test/java/com/licel/jcardsim/crypto/KeyPairImplTest.java b/src/test/java/com/licel/jcardsim/crypto/KeyPairImplTest.java index 5a572b58..4ae6b432 100644 --- a/src/test/java/com/licel/jcardsim/crypto/KeyPairImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/KeyPairImplTest.java @@ -16,6 +16,7 @@ */ import java.util.Arrays; +import javacard.framework.Util; import javacard.security.DSAPrivateKey; import javacard.security.DSAPublicKey; import javacard.security.ECPrivateKey; @@ -27,9 +28,7 @@ import javacard.security.RSAPrivateCrtKey; import javacard.security.RSAPrivateKey; import javacard.security.RSAPublicKey; -import javax.xml.bind.DatatypeConverter; import junit.framework.TestCase; -import org.bouncycastle.util.encoders.Hex; /** * Test for KeyPairImpl @@ -62,6 +61,32 @@ protected void tearDown() throws Exception { super.tearDown(); } + + public void testConstructor(){ + testConstructorRSA(KeyPair.ALG_RSA); + testConstructorRSA(KeyPair.ALG_RSA_CRT); + } + /** + * Test of constructor RSA/RSA_CRT + */ + private void testConstructorRSA(byte algo){ + KeyPair instance = null; + byte[] expBuf = new byte[3]; + byte[] customExp = new byte[]{0x03}; + for (int i = 0; i < RSA_SIZES.length; i++) { + instance = new KeyPair(algo, RSA_SIZES[i]); + // https://github.com/licel/jcardsim/issues/42 + PublicKey publicKey = instance.getPublic(); + assertEquals(true, publicKey!=null); + assertEquals(true, publicKey instanceof RSAPublicKey); + ((RSAPublicKey)publicKey).setExponent(customExp, (short)0, (short)customExp.length); + instance.genKeyPair(); + short expSize = ((RSAPublicKey)publicKey).getExponent(expBuf, (short) 0); + assertEquals(customExp.length, expSize); + assertEquals(0, Util.arrayCompare(expBuf, (short)0, customExp, (short) 0, expSize)); + } + } + /** * Test of genKeyPair method, of class KeyPairImpl. * algorithm RSA - NXP JCOP not support this algorithm @@ -116,6 +141,26 @@ public void testGenKeyPairRSAWithCustomPublicExponent() { publicKey.getExponent(generatedExponent, (short)0); assertEquals(Arrays.equals(customExponent, generatedExponent), true); } + + /** + * Test of genKeyPair method, of class KeyPairImpl. + * algorithm EC - NXP JCOP not support this algorithm + * for on-card key generation + */ + public void testGenKeyPairECWithCustomDomainParameters() { + System.out.println("genKeyPair EC (Custom Domain Parameters)"); + KeyPair instance = new KeyPair(KeyPair.ALG_EC_F2M, KeyBuilder.LENGTH_EC_F2M_193); + instance.genKeyPair(); + ECPublicKey ecPublicKey = (ECPublicKey)instance.getPublic(); + KeyPair instance1 = new KeyPair(ecPublicKey, null); + instance1.genKeyPair(); + ECPublicKey ecPublicKey1 = (ECPublicKey)instance1.getPublic(); + byte[] a = new byte[266]; + byte[] a1 = new byte[266]; + ecPublicKey.getA(a, (short)0); + ecPublicKey1.getA(a1, (short)0); + assertEquals(Arrays.equals(a, a1), true); + } /** * Test of genKeyPair method, of class KeyPairImpl. diff --git a/src/test/java/com/licel/jcardsim/crypto/MessageDigestImplTest.java b/src/test/java/com/licel/jcardsim/crypto/MessageDigestImplTest.java index 55ca986c..2d06f387 100644 --- a/src/test/java/com/licel/jcardsim/crypto/MessageDigestImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/MessageDigestImplTest.java @@ -15,7 +15,8 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; +import java.security.SecureRandom; + import javacard.security.MessageDigest; import junit.framework.TestCase; import org.bouncycastle.util.Arrays; @@ -26,7 +27,7 @@ * Test data from NXP JCOP31-36 JavaCard */ public class MessageDigestImplTest extends TestCase { - + static final String MESSAGE1 = "F9607F6E66B4162C"; static final String MESSAGE2 = "26C69FC4C14399A399B5B28AD9CC5B91796BC2565C5580BAC1BE10808F71949D8B"; // card response with algorithm MD5 @@ -35,21 +36,44 @@ public class MessageDigestImplTest extends TestCase { // card response with algorithm SHA1 static final String MD_1_NXP_SHA1 = "94FF92DC796929290990BA74F4B125F04F9B510A"; static final String MD_2_NXP_SHA1 = "01793FF98B954C3F60F276B179186C499F619A9D"; - MessageDigest engineMD5 = new MessageDigestImpl(MessageDigest.ALG_MD5); - MessageDigest engineSHA1 = new MessageDigestImpl(MessageDigest.ALG_SHA); - + // card response with algorithm SHA256 + static final String MD_1_NXP_SHA256 = "E700E0E6E5A4F3FF05CCBD4DA9CDBBEC712189DE65EF1ED19C351F7966270EF0"; + static final String MD_2_NXP_SHA256 = "17CB067C5E384B85DF370B96A5C91817D908F0C760CB2D7539EF8B9A7C02AB80"; + // NIST SHA-384 SHA ETALON MESSAGES + static final String MESSAGE_64_NIST_SHA384 = "DE60275BDAFCE4B1"; + static final String MESSAGE_256_NIST_SHA384 = "BE01E520E69F04174CCF95455B1C81445298264D9ADC4958574A52843D95B8BA"; + // NIST SHA-384 ETALON DIGESTS + static final String MD_64_NIST_SHA384 = "A3D861D866C1362423EB21C6BEC8E44B74CE993C55BAA2B6640567560EBECDAEDA07183DBBBD95E0F522CAEE5DDBDAF0"; + static final String MD_256_NIST_SHA384 = "C5CF54B8E3105B1C7BF7A43754D915B0947F28B6DC94A019182929B5C848E11441C9E4E90C7449F4C3CD12954F0F5D99"; + // NIST SHA-512 ETALON MESSAGES + static final String MESSAGE_64_NIST_SHA512 = "6F8D58B7CAB1888C"; + static final String MESSAGE_256_NIST_SHA512 = "8CCB08D2A1A282AA8CC99902ECAF0F67A9F21CFFE28005CB27FCF129E963F99D"; + // NIST SHA-512 ETALON DIGESTS + static final String MD_64_NIST_SHA512 = "A3941DEF2803C8DFC08F20C06BA7E9A332AE0C67E47AE57365C243EF40059B11BE22C91DA6A80C2CFF0742A8F4BCD941BDEE0B861EC872B215433CE8DCF3C031"; + static final String MD_256_NIST_SHA512 = "4551DEF2F9127386EEA8D4DAE1EA8D8E49B2ADD0509F27CCBCE7D9E950AC7DB01D5BCA579C271B9F2D806730D88F58252FD0C2587851C3AC8A0E72B4E1DC0DA6"; + + + MessageDigestImpl engineMD5 = new MessageDigestImpl(MessageDigest.ALG_MD5); + MessageDigestImpl engineRIPEMD160 = new MessageDigestImpl(MessageDigest.ALG_RIPEMD160); + MessageDigestImpl engineSHA1 = new MessageDigestImpl(MessageDigest.ALG_SHA); + MessageDigestImpl engineSHA256 = new MessageDigestImpl(MessageDigest.ALG_SHA_256); + MessageDigestImpl engineSHA384 = new MessageDigestImpl(MessageDigest.ALG_SHA_384); + MessageDigestImpl engineSHA512 = new MessageDigestImpl(MessageDigest.ALG_SHA_512); + + SecureRandom rnd = new SecureRandom(); + public MessageDigestImplTest(String testName) { super(testName); } - + protected void setUp() throws Exception { super.setUp(); } - + protected void tearDown() throws Exception { super.tearDown(); } - + /** * Test of getAlgorithm method, of class MessageDigestImpl. */ @@ -63,24 +87,39 @@ public void testGetAlgorithm() { expResult = MessageDigest.ALG_SHA; result = engineSHA1.getAlgorithm(); assertEquals(expResult, result); - + // sha256 + expResult = MessageDigest.ALG_SHA_256; + result = engineSHA256.getAlgorithm(); + assertEquals(expResult, result); + // sha384 + expResult = MessageDigest.ALG_SHA_384; + result = engineSHA384.getAlgorithm(); + assertEquals(expResult, result); + // sha512 + expResult = MessageDigest.ALG_SHA_512; + result = engineSHA512.getAlgorithm(); + assertEquals(expResult, result); } - + /** * Test of getLength method, of class MessageDigestImpl. */ public void testGetLength() { System.out.println("getLength"); // md5 - byte expResult = 16; - byte result = engineMD5.getLength(); - assertEquals(expResult, result); + assertEquals(engineMD5.getLength(), MessageDigest.LENGTH_MD5); + // ripemd160 + assertEquals(engineRIPEMD160.getLength(), MessageDigest.LENGTH_RIPEMD160); // sha1 - expResult = 20; - result = engineSHA1.getLength(); - assertEquals(expResult, result); + assertEquals(engineSHA1.getLength(), MessageDigest.LENGTH_SHA); + // sha256 + assertEquals(engineSHA256.getLength(), MessageDigest.LENGTH_SHA_256); + // sha384 + assertEquals(engineSHA384.getLength(), MessageDigest.LENGTH_SHA_384); + // sha512 + assertEquals(engineSHA512.getLength(), MessageDigest.LENGTH_SHA_512); } - + /** * Test MD5 algorithm with card response */ @@ -90,7 +129,7 @@ public void testMD5() { System.out.println("test MD5 doUpdate() + doFinal()"); testEngineDoUpdateFinal(engineMD5, Hex.decode(MESSAGE2), Hex.decode(MD_2_NXP_MD5)); } - + /** * Test SHA1 algorithm with card response */ @@ -100,7 +139,37 @@ public void testSHA() { System.out.println("test SHA1 doUpdate() + doFinal()"); testEngineDoUpdateFinal(engineSHA1, Hex.decode(MESSAGE2), Hex.decode(MD_2_NXP_SHA1)); } - + + /** + * Test SHA256 algorithm with card response + */ + public void testSHA256() { + System.out.println("test SHA256 doFinal()"); + testEngineDoFinal(engineSHA256, Hex.decode(MESSAGE1), Hex.decode(MD_1_NXP_SHA256)); + System.out.println("test SHA256 doUpdate() + doFinal()"); + testEngineDoUpdateFinal(engineSHA256, Hex.decode(MESSAGE2), Hex.decode(MD_2_NXP_SHA256)); + } + + /** + * Test SHA384 algorithm with card response + */ + public void testSHA384() { + System.out.println("test SHA384 doFinal()"); + testEngineDoFinal(engineSHA384, Hex.decode(MESSAGE_64_NIST_SHA384), Hex.decode(MD_64_NIST_SHA384)); + System.out.println("test SHA384 doUpdate() + doFinal()"); + testEngineDoUpdateFinal(engineSHA384, Hex.decode(MESSAGE_256_NIST_SHA384), Hex.decode(MD_256_NIST_SHA384)); + } + + /** + * Test SHA512 algorithm with card response + */ + public void testSHA512() { + System.out.println("test SHA512 doFinal()"); + testEngineDoFinal(engineSHA512, Hex.decode(MESSAGE_64_NIST_SHA512), Hex.decode(MD_64_NIST_SHA512)); + System.out.println("test SHA512 doUpdate() + doFinal()"); + testEngineDoUpdateFinal(engineSHA512, Hex.decode(MESSAGE_256_NIST_SHA512), Hex.decode(MD_256_NIST_SHA512)); + } + /** * Test method doFinal * @param engine tested engine @@ -108,11 +177,11 @@ public void testSHA() { * @param etalonDigest byte array contains etalon digest */ public void testEngineDoFinal(MessageDigest engine, byte[] msg, byte[] etalonDigest) { - byte[] digest = JCSystem.makeTransientByteArray(engine.getLength(), JCSystem.CLEAR_ON_RESET); + byte[] digest = new byte[engine.getLength()]; engine.doFinal(msg, (short) 0, (short) msg.length, digest, (short) 0); assertEquals(true, Arrays.areEqual(etalonDigest, digest)); } - + /** * Test sequence method's calls doUpdate();doFinal() * @param engine tested engine @@ -120,9 +189,41 @@ public void testEngineDoFinal(MessageDigest engine, byte[] msg, byte[] etalonDig * @param etalonDigest byte array contains etalon digest */ public void testEngineDoUpdateFinal(MessageDigest engine, byte[] msg, byte[] etalonDigest) { - byte[] digest = JCSystem.makeTransientByteArray(engine.getLength(), JCSystem.CLEAR_ON_RESET); + byte[] digest = new byte[engine.getLength()]; engine.update(msg, (short) 0, (short) 7); engine.doFinal(msg, (short) 7, (short) (msg.length - 7), digest, (short) 0); assertEquals(true, Arrays.areEqual(etalonDigest, digest)); } -} + + /** + * Test of setInitialDigest method, of class MessageDigestImpl. + */ + public void testSetInitialDigest() { + byte[] initialDigestBuf = new byte[128]; + byte[] inputData = new byte[254]; + rnd.nextBytes(inputData); + + MessageDigestImpl[] digests = new MessageDigestImpl[]{engineSHA1, engineMD5, engineRIPEMD160, + engineSHA256, engineSHA384, engineSHA512}; + + for (short i = 0; i < digests.length; i++) { + System.out.println("testSetInitialDigest() - "+digests[i].getAlgorithm()); + byte[] digest = new byte[digests[i].getLength()]; + byte[] etalonDigest = new byte[digests[i].getLength()]; + // calc first part + short part = digests[i].getBlockSize(); + digests[i].update(inputData, (short) 0, part); + short initialDigestOff = (short) rnd.nextInt(initialDigestBuf.length - digests[i].getLength()); + digests[i].getIntermediateDigest(initialDigestBuf, initialDigestOff); + // doFinal + digests[i].doFinal(inputData, part, (short) (inputData.length - part), digest, (short) 0); + // etalon + digests[i].reset(); + digests[i].update(inputData, (short) 0, part); + digests[i].doFinal(inputData, part, (short) (inputData.length - part), etalonDigest, (short) 0); + assertEquals(true, Arrays.areEqual(etalonDigest, digest)); + } + } + + +} \ No newline at end of file diff --git a/src/test/java/com/licel/jcardsim/crypto/RSACipherPKCS1Test.java b/src/test/java/com/licel/jcardsim/crypto/RSACipherPKCS1Test.java index a1f048a3..f3868570 100644 --- a/src/test/java/com/licel/jcardsim/crypto/RSACipherPKCS1Test.java +++ b/src/test/java/com/licel/jcardsim/crypto/RSACipherPKCS1Test.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.KeyBuilder; import javacard.security.RandomData; import javacard.security.RSAPrivateKey; @@ -76,7 +75,7 @@ protected void tearDown() throws Exception { } /** - * SelfTest of RSA Encryption/Decryption, of class AssymetricCipherImpl and ALG_RSA_PKCS1 algorithm implementation. + * SelfTest of RSA Encryption/Decryption, of class AsymmetricCipherImpl and ALG_RSA_PKCS1 algorithm implementation. */ public void testRSAPKCS1() { Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_PKCS1, false); @@ -90,14 +89,14 @@ public void testRSAPKCS1() { publicKey.setModulus(rsaPrivateKeyModulus, (short) 0,(short) rsaPrivateKeyModulus.length); cipher.init(publicKey, Cipher.MODE_ENCRYPT); - byte[] msg = JCSystem.makeTransientByteArray((short) 53, JCSystem.CLEAR_ON_RESET); - byte[] encryptedMsg = JCSystem.makeTransientByteArray((short) 64, JCSystem.CLEAR_ON_RESET); + byte[] msg = new byte[53]; + byte[] encryptedMsg = new byte[64]; RandomData rnd = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); rnd.generateData(msg, (short) 0, (short) msg.length); cipher.doFinal(msg, (short) 0, (short) msg.length, encryptedMsg, (short) 0); cipher.init(privateKey, Cipher.MODE_DECRYPT); - byte[] decryptedMsg = JCSystem.makeTransientByteArray((short) msg.length, JCSystem.CLEAR_ON_RESET); + byte[] decryptedMsg = new byte[msg.length]; cipher.doFinal(encryptedMsg, (short) 0, (short) encryptedMsg.length, decryptedMsg, (short) 0); assertEquals(true, Arrays.areEqual(msg, decryptedMsg)); diff --git a/src/test/java/com/licel/jcardsim/crypto/RSACipherTest.java b/src/test/java/com/licel/jcardsim/crypto/RSACipherTest.java index 3904c46a..a2b477e7 100644 --- a/src/test/java/com/licel/jcardsim/crypto/RSACipherTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/RSACipherTest.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.KeyBuilder; import javacard.security.RandomData; import javacard.security.RSAPrivateKey; @@ -76,7 +75,7 @@ protected void tearDown() throws Exception { } /** - * SelfTest of RSA Encryption/Decryption, of class AssymetricCipherImpl and ByteContainer.getBigInteger() method. + * SelfTest of RSA Encryption/Decryption, of class AsymmetricCipherImpl and ByteContainer.getBigInteger() method. */ public void testSelfRSA() { Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false); @@ -90,14 +89,14 @@ public void testSelfRSA() { publicKey.setModulus(rsaPrivateKeyModulus, (short) 0,(short) rsaPrivateKeyModulus.length); cipher.init(publicKey, Cipher.MODE_ENCRYPT); - byte[] msg = JCSystem.makeTransientByteArray((short) 63, JCSystem.CLEAR_ON_RESET); - byte[] encryptedMsg = JCSystem.makeTransientByteArray((short) 64, JCSystem.CLEAR_ON_RESET); + byte[] msg = new byte[63]; + byte[] encryptedMsg = new byte[64]; RandomData rnd = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); rnd.generateData(msg, (short) 0, (short) msg.length); cipher.doFinal(msg, (short) 0, (short) msg.length, encryptedMsg, (short) 0); cipher.init(privateKey, Cipher.MODE_DECRYPT); - byte[] decryptedMsg = JCSystem.makeTransientByteArray((short) msg.length, JCSystem.CLEAR_ON_RESET); + byte[] decryptedMsg = new byte[msg.length]; cipher.doFinal(encryptedMsg, (short) 0, (short) encryptedMsg.length, decryptedMsg, (short) 0); assertEquals(true, Arrays.areEqual(msg, decryptedMsg)); diff --git a/src/test/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImplTest.java b/src/test/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImplTest.java new file mode 100644 index 00000000..ecffd639 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImplTest.java @@ -0,0 +1,62 @@ +/* + * Copyright 2013 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.crypto; + +import junit.framework.TestCase; +import org.bouncycastle.util.encoders.Hex; + +/** + * Test for RSAPrivateCrtKeyImpl + * Test data from NXP JCOP31-36 JavaCard* + */ +public class RSAPrivateCrtKeyImplTest extends TestCase { + // RSA CRT Private Key Components (2048-bit) + + final static String P = "DA2CBBE7572AE9441538EFE23943A6C72B564482E482D50954769920AD4A45179D2842327BF8271C592FA9D6DCCAE737B45BCA4A3B026CF5C32E6008284D8ABA3A1B249EF900CCF40746C599D9217EC3D1179DC35976AE05A50CF6F8AE23E15B8E0D4481D1D6035826AB7F43CECEB511699814BF2EFCF0EA37E230C4F586E6C7"; + final static String Q = "A5CDB97E613BDE20D7938C102DBB1D4F3B7BE88A1E7919329F7207F044B2A1560FB370C742A7E15C5BBF77AC2463AB9C00B7FF2B765E1EECF4ED5F2F5DDA8476BCF6F154286154C4CC9C51FDEBEAFE8630D299A03AE306B7179D83328A1D18301E2C66AA94A802EB4FF34291C43E2BA4A3642965B5322DBBDCF5D016718070D7"; + final static String DP = "AA732286557A87ED91EAFEB6ADE865A6DAFBB5E0D12849C9D53C26DBF9A6B99DFE41129EA06DBA1892B1032E8326DE478DD7DC8DEBD6344C3925C50EFA75C23945E628D12E566AC907DA49CCAD6F56BB236320F51AB2F6B8203FA5BF99451CEE4B67A02B1045F42CED6134B7441E08264769F2637F114C22A0704D8BC30A96C7"; + final static String DQ = "94B23E9437F1B011B6246E2DA845B25077A1757841420BB619C6F395A896A7187EB648037C2501788A13D9E8B92DE61EDF8A243F3F45C3E870F45D3426B0ADB1AB60B027F09AF1A2197A6C1214BD488CE2464D5EA4D12C199205423F561C27B027AF5C57C940307606DABC2DEC58715D92E76634FFDEC3A342D3F54DDB76FC3B"; + final static String PQ = "92CC66692E8D14EB93D0705EFA58276CD7A1A8B82C17544E8D181C3F987ED62E83355844D2E89380A17169614D8367709CB62A3DF9339BD537078AD1629D1B87DCA66E31809ADB78746633C28A6EA064B34EF750C27E32800ECE3C5F17524D35EE3CEAE8989745EAECD411D519210D4FCD699F4218A22249F76BE75A2F8160A0"; + + public RSAPrivateCrtKeyImplTest(String testName) { + super(testName); + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Test of isInitialized method, of class RSAPrivateCrtKeyImpl. + */ + public void testIsInitialized() { + System.out.println("isInitialized"); + RSAPrivateCrtKeyImpl key = new RSAPrivateCrtKeyImpl((short)2048); + short compLen = (short) Hex.decode(P).length; + key.setP(Hex.decode(P), (short)0, compLen); + key.setQ(Hex.decode(Q), (short)0, compLen); + key.setDP1(Hex.decode(DP), (short)0, compLen); + key.setDQ1(Hex.decode(DQ), (short)0, compLen); + key.setPQ(Hex.decode(PQ), (short)0, compLen); + assertEquals(true, key.isInitialized()); + } +} diff --git a/src/test/java/com/licel/jcardsim/crypto/RandomDataImplTest.java b/src/test/java/com/licel/jcardsim/crypto/RandomDataImplTest.java index 1f9c2165..ab6c06b9 100644 --- a/src/test/java/com/licel/jcardsim/crypto/RandomDataImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/RandomDataImplTest.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.security.RandomData; import junit.framework.TestCase; @@ -41,7 +40,7 @@ protected void tearDown() throws Exception { */ public void testGenerateData() { System.out.println("generateData"); - byte[] buffer = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] buffer = new byte[8]; RandomData instance = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); instance.generateData(buffer, (short) 0, (short) buffer.length); instance = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM); @@ -53,7 +52,7 @@ public void testGenerateData() { */ public void testSetSeed() { System.out.println("setSeed"); - byte[] buffer = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] buffer = new byte[8]; RandomData instance = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); instance.setSeed(buffer, (short) 0, (short) buffer.length); instance.generateData(buffer, (short) 0, (short) buffer.length); diff --git a/src/test/java/com/licel/jcardsim/crypto/SignatureMessageRecoveryTest.java b/src/test/java/com/licel/jcardsim/crypto/SignatureMessageRecoveryTest.java new file mode 100644 index 00000000..16083409 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/crypto/SignatureMessageRecoveryTest.java @@ -0,0 +1,188 @@ +/* + * Copyright 2014 Licel LLC. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.licel.jcardsim.crypto; + +import javacard.framework.JCSystem; +import javacard.security.KeyBuilder; +import javacard.security.KeyPair; +import javacard.security.RSAPrivateKey; +import javacard.security.RSAPublicKey; +import javacard.security.Signature; +import javacard.security.SignatureMessageRecovery; +import junit.framework.TestCase; + +/** + * SignatureMessageRecovery Test + * based on JCDK Sample + */ +public class SignatureMessageRecoveryTest extends TestCase { + + //--RSA Keypair data + private static final byte[] RSA_PUB_KEY_EXP = {(byte) 0x01, (byte) 0x00, (byte) 0x01}; + private static final byte[] RSA_PUB_PRIV_KEY_MOD = {(byte) 0xbe, (byte) 0xdf, + (byte) 0xd3, (byte) 0x7a, (byte) 0x08, (byte) 0xe2, (byte) 0x9a, (byte) 0x58, + (byte) 0x27, (byte) 0x54, (byte) 0x2a, (byte) 0x49, (byte) 0x18, (byte) 0xce, + (byte) 0xe4, (byte) 0x1a, (byte) 0x60, (byte) 0xdc, (byte) 0x62, (byte) 0x75, + (byte) 0xbd, (byte) 0xb0, (byte) 0x8d, (byte) 0x15, (byte) 0xa3, (byte) 0x65, + (byte) 0xe6, (byte) 0x7b, (byte) 0xa9, (byte) 0xdc, (byte) 0x09, (byte) 0x11, + (byte) 0x5f, (byte) 0x9f, (byte) 0xbf, (byte) 0x29, (byte) 0xe6, (byte) 0xc2, + (byte) 0x82, (byte) 0xc8, (byte) 0x35, (byte) 0x6b, (byte) 0x0f, (byte) 0x10, + (byte) 0x9b, (byte) 0x19, (byte) 0x62, (byte) 0xfd, (byte) 0xbd, (byte) 0x96, + (byte) 0x49, (byte) 0x21, (byte) 0xe4, (byte) 0x22, (byte) 0x08, (byte) 0x08, + (byte) 0x80, (byte) 0x6c, (byte) 0xd1, (byte) 0xde, (byte) 0xa6, (byte) 0xd3, + (byte) 0xc3, (byte) 0x8f}; + private static final byte[] RSA_PRIV_KEY_EXP = {(byte) 0x84, (byte) 0x21, + (byte) 0xfe, (byte) 0x0b, (byte) 0xa4, (byte) 0xca, (byte) 0xf9, (byte) 0x7d, + (byte) 0xbc, (byte) 0xfc, (byte) 0x0e, (byte) 0xa9, (byte) 0xbb, (byte) 0x7a, + (byte) 0xbd, (byte) 0x7d, (byte) 0x65, (byte) 0x40, (byte) 0x2b, (byte) 0x08, + (byte) 0xc6, (byte) 0xdf, (byte) 0xc9, (byte) 0x4b, (byte) 0x09, (byte) 0x6a, + (byte) 0x29, (byte) 0x3b, (byte) 0xc2, (byte) 0x42, (byte) 0x88, (byte) 0x23, + (byte) 0x44, (byte) 0xaf, (byte) 0x08, (byte) 0x82, (byte) 0x4c, (byte) 0xff, + (byte) 0x42, (byte) 0xa4, (byte) 0xb8, (byte) 0xd2, (byte) 0xda, (byte) 0xcc, + (byte) 0xee, (byte) 0xc5, (byte) 0x34, (byte) 0xed, (byte) 0x71, (byte) 0x01, + (byte) 0xab, (byte) 0x3b, (byte) 0x76, (byte) 0xde, (byte) 0x6c, (byte) 0xa2, + (byte) 0xcb, (byte) 0x7c, (byte) 0x38, (byte) 0xb6, (byte) 0x9a, (byte) 0x4b, + (byte) 0x28, (byte) 0x01}; + RSAPublicKey pubKey; + RSAPrivateKey privKey; + SignatureMessageRecovery sig; + KeyPair selfTestKeys; + + /** + * Only this class's install method should create the applet object. + */ + protected void setUp() throws Exception { + super.setUp(); + pubKey = (RSAPublicKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PUBLIC, KeyBuilder.LENGTH_RSA_512, false); + privKey = (RSAPrivateKey) KeyBuilder.buildKey(KeyBuilder.TYPE_RSA_PRIVATE, KeyBuilder.LENGTH_RSA_512, false); + privKey.setExponent(RSA_PRIV_KEY_EXP, (short) 0, (short) RSA_PRIV_KEY_EXP.length); + privKey.setModulus(RSA_PUB_PRIV_KEY_MOD, (short) 0, (short) RSA_PUB_PRIV_KEY_MOD.length); + pubKey.setExponent(RSA_PUB_KEY_EXP, (short) 0, (short) RSA_PUB_KEY_EXP.length); + pubKey.setModulus(RSA_PUB_PRIV_KEY_MOD, (short) 0, (short) RSA_PUB_PRIV_KEY_MOD.length); + sig = (SignatureMessageRecovery) Signature.getInstance(Signature.ALG_RSA_SHA_ISO9796_MR, false); + selfTestKeys = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_2048); + selfTestKeys.genKeyPair(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * + */ + public void testCryptoSignAndVerifyFullMsgRecovery() { + byte[] buffer = new byte[1]; + + sig.init(pubKey, Signature.MODE_VERIFY); + byte[] etalonSign = {(byte) 0xa3, (byte) 0x49, (byte) 0x1d, (byte) 0x51, (byte) 0x55, + (byte) 0x05, (byte) 0x49, (byte) 0x71, (byte) 0xba, (byte) 0xdc, (byte) 0x77, (byte) 0x22, + (byte) 0xce, (byte) 0x9a, (byte) 0x51, (byte) 0x71, (byte) 0xf8, (byte) 0xb1, (byte) 0x88, + (byte) 0x8d, (byte) 0x55, (byte) 0x05, (byte) 0xd5, (byte) 0x2b, (byte) 0xae, (byte) 0xf6, + (byte) 0xb7, (byte) 0x04, (byte) 0xd9, (byte) 0x1d, (byte) 0x09, (byte) 0x35, (byte) 0x17, + (byte) 0xec, (byte) 0x73, (byte) 0x11, (byte) 0xd5, (byte) 0x7f, (byte) 0xfd, (byte) 0xeb, + (byte) 0xb3, (byte) 0xd9, (byte) 0x98, (byte) 0x45, (byte) 0xf7, (byte) 0x8a, (byte) 0xb6, + (byte) 0x72, (byte) 0x21, (byte) 0x44, (byte) 0xa1, (byte) 0x32, (byte) 0xb3, (byte) 0xa1, + (byte) 0xce, (byte) 0x72, (byte) 0xc5, (byte) 0x6d, (byte) 0xcc, (byte) 0xee, (byte) 0x18, + (byte) 0x64, (byte) 0x2e, (byte) 0x76}; + + short m1Length = sig.beginVerify(etalonSign, (short) 0, (short) etalonSign.length); + boolean verified = sig.verify(buffer, (short) 0, (short) 0); + + assertEquals(m1Length, 1); + + assertEquals(true, verified); + + } + + public void testSelfCryptoSignAndVerifyFullMsgRecovery() { + byte[] data = new byte[41]; + for (byte i = 0; i < data.length; i++) { + data[i] = i; + } + short[] m1Data = JCSystem.makeTransientShortArray((short) 1, JCSystem.CLEAR_ON_DESELECT); + byte[] signature = new byte[(short)256]; + + sig.init(selfTestKeys.getPrivate(), Signature.MODE_SIGN); + short sigLen = sig.sign(data, (short) 0, (short) data.length, signature, (short) 0, m1Data, (short) 0); + + sig.init(selfTestKeys.getPublic(), Signature.MODE_VERIFY); + short m1Length = sig.beginVerify(signature, (short) 0, sigLen); + + boolean verified = sig.verify(data, (short) 0, (short) 0); + + assertEquals(m1Length, m1Data[0]); + + assertEquals(true, verified); + + } + + public void testCryptoVerifyPartMsgRecovery() { + byte[] data = new byte[70]; + for (byte i = 0; i < data.length; i++) { + data[i] = i; + } + + byte[] etalonSign = new byte[]{(byte) 0x2d, (byte) 0x15, (byte) 0x79, (byte) 0x89, + (byte) 0xba, (byte) 0x71, (byte) 0x6d, (byte) 0x31, (byte) 0x6c, (byte) 0x0e, (byte) 0x29, + (byte) 0x55, (byte) 0xc0, (byte) 0x0e, (byte) 0x80, (byte) 0xc3, (byte) 0x5c, (byte) 0xa3, + (byte) 0xe8, (byte) 0xa1, (byte) 0x12, (byte) 0x65, (byte) 0xe3, (byte) 0x6f, (byte) 0xb2, + (byte) 0x51, (byte) 0x44, (byte) 0x7d, (byte) 0x30, (byte) 0x4a, (byte) 0x24, (byte) 0xcf, + (byte) 0xa1, (byte) 0x1b, (byte) 0xaa, (byte) 0x30, (byte) 0x48, (byte) 0xd3, (byte) 0x70, + (byte) 0x4a, (byte) 0x0b, (byte) 0xe7, (byte) 0x9a, (byte) 0x05, (byte) 0x1f, (byte) 0x5f, + (byte) 0x87, (byte) 0xc7, (byte) 0x8f, (byte) 0xe4, (byte) 0xae, (byte) 0xbc, (byte) 0xde, + (byte) 0x0a, (byte) 0x63, (byte) 0x6a, (byte) 0x28, (byte) 0x48, (byte) 0x52, (byte) 0xc0, + (byte) 0xe7, (byte) 0xd2, (byte) 0x7f, (byte) 0xfe}; + + //recover the recoverable message from signature + sig.init(pubKey, Signature.MODE_VERIFY); + short m1Length = sig.beginVerify(etalonSign, (short) 0, (short) etalonSign.length); + + assertEquals(m1Length, 42); + + + byte[] etalonNonRecMsg = new byte[]{(byte) 0x2b, (byte) 0x2c, (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) 0x3a, (byte) 0x3b, (byte) 0x3c, (byte) 0x3d, (byte) 0x3e, + (byte) 0x3f, (byte) 0x40, (byte) 0x41, (byte) 0x42, (byte) 0x43, (byte) 0x44, (byte) 0x45, (byte) 0x46}; + + boolean verified = sig.verify(etalonNonRecMsg, (short) 0, (short) etalonNonRecMsg.length); + assertEquals(true, verified); + + } + + public void testSelfCCryptoVerifyPartMsgRecovery() { + byte[] data = new byte[(short)256]; + for (short i = 0; i < data.length; i++) { + data[i] = (byte)i; + } + short[] m1Data = JCSystem.makeTransientShortArray((short) 1, JCSystem.CLEAR_ON_DESELECT); + byte[] signature = new byte[(short)256]; + + sig.init(selfTestKeys.getPrivate(), Signature.MODE_SIGN); + short sigLen = sig.sign(data, (short) 0, (short) data.length, signature, (short) 0, m1Data, (short) 0); + + sig.init(selfTestKeys.getPublic(), Signature.MODE_VERIFY); + short m1Length = sig.beginVerify(signature, (short) 0, sigLen); + + boolean verified = sig.verify(data, m1Length, (short) (data.length - m1Length)); + + assertEquals(m1Length, m1Data[0]); + + assertEquals(true, verified); + + } +} diff --git a/src/test/java/com/licel/jcardsim/crypto/SymmetricCipherImplTest.java b/src/test/java/com/licel/jcardsim/crypto/SymmetricCipherImplTest.java index d5ed92b1..212ead99 100644 --- a/src/test/java/com/licel/jcardsim/crypto/SymmetricCipherImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/SymmetricCipherImplTest.java @@ -15,7 +15,6 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.framework.Util; import javacard.security.AESKey; import javacard.security.Key; @@ -97,19 +96,20 @@ public class SymmetricCipherImplTest extends TestCase { // ALG_DES_CBC_NOPAD "81B2369E2773858F" }; - // AES test data from NIST - // AESVS VarTxt test data for ECB (Key length: 128bit) - String[] AES_ECB_128_TEST = {"00000000000000000000000000000000", "80000000000000000000000000000000", "3ad78e726c1ec02b7ebfe92b23d9ec34"}; - // AESVS VarTxt test data for ECB (Key length: 192bit) - String[] AES_ECB_192_TEST = {"000000000000000000000000000000000000000000000000", "80000000000000000000000000000000", "6cd02513e8d4dc986b4afe087a60bd0c"}; - // AESVS VarTxt test data for ECB (Key length: 256bit) - String[] AES_ECB_256_TEST = {"0000000000000000000000000000000000000000000000000000000000000000", "80000000000000000000000000000000", "ddc6bf790c15760d8d9aeb6f9a75fd4e"}; - // AESVS VarKey test data for CBC (Key length: 128bit) - String[] AES_CBC_128_TEST = {"80000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "0edd33d3c621e546455bd8ba1418bec8"}; - // AESVS VarKey test data for CBC (Key length: 192bit) - String[] AES_CBC_192_TEST = {"800000000000000000000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "de885dc87f5a92594082d02cc1e1b42c"}; - // AESVS VarKey test data for CBC (Key length: 256bit) - String[] AES_CBC_256_TEST = {"8000000000000000000000000000000000000000000000000000000000000000", "00000000000000000000000000000000", "00000000000000000000000000000000", "e35a6dcb19b201a01ebcfa8aa22b5759"}; + // AES test data from NIST (sp800-38a) + // FORMAT: key:[iv]:data:result + // Appendix F.1 + String[] AES_ECB_128_TEST = {"2b7e151628aed2a6abf7158809cf4f3c", "6bc1bee22e409f96e93d7e117393172a", "3ad77bb40d7a3660a89ecaf32466ef97"}; + // Appendix F.1.3 + String[] AES_ECB_192_TEST = {"8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", "6bc1bee22e409f96e93d7e117393172a", "bd334f1d6e45f25ff712a214571fa5cc"}; + // Appendix F.1.5 + String[] AES_ECB_256_TEST = {"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "6bc1bee22e409f96e93d7e117393172a", "f3eed1bdb5d2a03c064b5a7e3db181f8"}; + // Appendix F.2.1 + String[] AES_CBC_128_TEST = {"2b7e151628aed2a6abf7158809cf4f3c", "000102030405060708090a0b0c0d0e0f", "6bc1bee22e409f96e93d7e117393172a", "7649abac8119b246cee98e9b12e9197d"}; + // Appendix F.2.3 + String[] AES_CBC_192_TEST = {"8e73b0f7da0e6452c810f32b809079e562f8ead2522c6b7b", "000102030405060708090a0b0c0d0e0f", "6bc1bee22e409f96e93d7e117393172a", "4f021db243bc633d7178183a9fa071e8"}; + // Appendix F.2.5 + String[] AES_CBC_256_TEST = {"603deb1015ca71be2b73aef0857d77811f352c073b6108d72d9810a30914dff4", "000102030405060708090a0b0c0d0e0f", "6bc1bee22e409f96e93d7e117393172a", "f58c4c04d6e5f1ba779eabfb5f7bfbd6"}; public SymmetricCipherImplTest(String testName) { super(testName); @@ -213,7 +213,12 @@ public void testAESMode(short keyLen, byte mode, String[] testData) { short processedBytes = engine.doFinal(Hex.decode(testData[needIV?2:1]), (short) 0, (short) 16, encrypted, (short) 0); assertEquals(processedBytes, 16); assertEquals(true, Arrays.areEqual(encrypted, Hex.decode(testData[needIV?3:2]))); - engine.init(aesKey, Cipher.MODE_DECRYPT); + if (needIV) { + byte[] iv = Hex.decode(testData[1]); + engine.init(aesKey, Cipher.MODE_DECRYPT, iv, (short)0, (short)iv.length); + } else { + engine.init(aesKey, Cipher.MODE_DECRYPT); + } byte[] decrypted = new byte[16]; // AES 128 processedBytes = engine.doFinal(Hex.decode(testData[needIV?3:2]), (short) 0, (short) 16, decrypted, (short) 0); assertEquals(processedBytes, 16); @@ -237,7 +242,7 @@ public void testEngineDoFinal(Cipher engine, Key key, byte[] iv, byte[] msg, byt } else { engine.init(key, Cipher.MODE_ENCRYPT, iv, (short) 0, (short) iv.length); } - byte[] encrypted = JCSystem.makeTransientByteArray((short) encryptedEtalonMsg.length, JCSystem.CLEAR_ON_RESET); + byte[] encrypted = new byte[encryptedEtalonMsg.length]; short processedBytes = engine.doFinal(msg, (short) 0, (short) msg.length, encrypted, (short) 0); assertEquals(true, Arrays.areEqual(encrypted, encryptedEtalonMsg)); assertEquals(processedBytes, encryptedEtalonMsg.length); @@ -247,7 +252,7 @@ public void testEngineDoFinal(Cipher engine, Key key, byte[] iv, byte[] msg, byt } else { engine.init(key, Cipher.MODE_DECRYPT, iv, (short) 0, (short) iv.length); } - byte[] decrypted = JCSystem.makeTransientByteArray((short) msg.length, JCSystem.CLEAR_ON_RESET); + byte[] decrypted = new byte[msg.length]; processedBytes = engine.doFinal(encryptedEtalonMsg, (short) 0, (short) encryptedEtalonMsg.length, decrypted, (short) 0); assertEquals(processedBytes, msg.length); assertEquals(true, Arrays.areEqual(decrypted, msg)); diff --git a/src/test/java/com/licel/jcardsim/crypto/SymmetricKeyImplTest.java b/src/test/java/com/licel/jcardsim/crypto/SymmetricKeyImplTest.java index 0cad46cf..439f7754 100644 --- a/src/test/java/com/licel/jcardsim/crypto/SymmetricKeyImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/SymmetricKeyImplTest.java @@ -15,12 +15,10 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; import javacard.framework.Util; import javacard.security.AESKey; import javacard.security.KeyBuilder; import junit.framework.TestCase; -import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.engines.DESEngine; import org.bouncycastle.crypto.engines.DESedeEngine; import org.bouncycastle.util.Arrays; @@ -48,7 +46,7 @@ protected void tearDown() throws Exception { public void testClearKey() { System.out.println("clearKey"); SymmetricKeyImpl desKey = new SymmetricKeyImpl(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES); - byte[] key = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] key = new byte[8]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); desKey.setKey(key, (short) 0); desKey.clearKey(); @@ -61,7 +59,7 @@ public void testClearKey() { public void testSetKey() { System.out.println("setKey"); SymmetricKeyImpl desKey = new SymmetricKeyImpl(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES); - byte[] key = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] key = new byte[8]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); desKey.setKey(key, (short) 0); assertEquals(true, desKey.isInitialized()); @@ -73,10 +71,10 @@ public void testSetKey() { public void testGetKey() { System.out.println("getKey"); SymmetricKeyImpl desKey = new SymmetricKeyImpl(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES); - byte[] key = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] key = new byte[8]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); desKey.setKey(key, (short) 0); - byte[] testKey = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] testKey = new byte[8]; desKey.getKey(testKey, (short) 0); assertEquals(true, Arrays.areEqual(testKey, key)); } @@ -88,31 +86,31 @@ public void testGetCipher() { System.out.println("getCipher"); // des key SymmetricKeyImpl desKey = new SymmetricKeyImpl(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES); - byte[] key = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); + byte[] key = new byte[8]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); desKey.setKey(key, (short) 0); boolean isValidCipher = (desKey.getCipher() instanceof DESEngine); assertEquals(true, isValidCipher); // 3des key SymmetricKeyImpl des3Key = new SymmetricKeyImpl(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_3KEY); - key = JCSystem.makeTransientByteArray((short) 24, JCSystem.CLEAR_ON_RESET); + key = new byte[24]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); des3Key.setKey(key, (short) 0); isValidCipher = (des3Key.getCipher() instanceof DESedeEngine); assertEquals(true, isValidCipher); // aes key - 128 AESKey aesKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_128, false); - key = JCSystem.makeTransientByteArray((short) 16, JCSystem.CLEAR_ON_RESET); + key = new byte[16]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); aesKey.setKey(key, (short) 0); // aes key - 192 aesKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_192, false); - key = JCSystem.makeTransientByteArray((short) 24, JCSystem.CLEAR_ON_RESET); + key = new byte[24]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); aesKey.setKey(key, (short) 0); // aes key - 256 aesKey = (AESKey)KeyBuilder.buildKey(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_256, false); - key = JCSystem.makeTransientByteArray((short) 32, JCSystem.CLEAR_ON_RESET); + key = new byte[32]; Util.arrayFillNonAtomic(key, (short) 0, (short) key.length, (byte) 7); aesKey.setKey(key, (short) 0); // aes key - 256 diff --git a/src/test/java/com/licel/jcardsim/crypto/SymmetricSignatureImplTest.java b/src/test/java/com/licel/jcardsim/crypto/SymmetricSignatureImplTest.java index e326ef5d..2a475c68 100644 --- a/src/test/java/com/licel/jcardsim/crypto/SymmetricSignatureImplTest.java +++ b/src/test/java/com/licel/jcardsim/crypto/SymmetricSignatureImplTest.java @@ -15,7 +15,7 @@ */ package com.licel.jcardsim.crypto; -import javacard.framework.JCSystem; +import javacard.security.HMACKey; import javacard.security.Key; import javacard.security.KeyBuilder; import javacard.security.Signature; @@ -24,8 +24,9 @@ import org.bouncycastle.util.encoders.Hex; /** - * Test for SymmetricSignatureImpl - * Test data from NXP JCOP31-36 JavaCard + * Test for + * SymmetricSignatureImpl + * Test data from NXP JCOP31-36/41 JavaCard */ public class SymmetricSignatureImplTest extends TestCase { @@ -51,7 +52,10 @@ public class SymmetricSignatureImplTest extends TestCase { // ALG_DES_MAC8_ISO9797_M1 "165DD117D24198B1", // ALG_DES_MAC8_ISO9797_M2 - "C8D247D6209E2E44",}; + "C8D247D6209E2E44", + // ALG_DES_MAC8_ISO9797_1_M2_ALG3 + "706CAC8246DE7427", + }; // MESSAGE_15 MAC by card (DES key) with non-zero IV String[] DES_MAC_15_IV = new String[]{ // ALG_DES_MAC8_ISO9797_M1 @@ -82,6 +86,214 @@ public class SymmetricSignatureImplTest extends TestCase { // ALG_DES_MAC8_NOPAD "81B2369E2773858F" }; + // etalon message for AES-CBC + String MESSAGE_16 = "6BC1BEE22E409F96E93D7E117393172A"; + // etalon aes 128 key + String AES_128_KEY = "2B7E151628AED2A6ABF7158809CF4F3C"; + // etalon mac + String AES_CBC_MAC = "3AD77BB40D7A3660A89ECAF32466EF97"; + // hmac test vectors + // {SIGNATUTE_ID, ..} + byte[] HMAC_IDS = { + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_RIPEMD160, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_MD5, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA1, + Signature.ALG_HMAC_SHA_256, + Signature.ALG_HMAC_SHA_384, + Signature.ALG_HMAC_SHA_512, + Signature.ALG_HMAC_SHA_256, + Signature.ALG_HMAC_SHA_384, + Signature.ALG_HMAC_SHA_512, + Signature.ALG_HMAC_SHA_256, + Signature.ALG_HMAC_SHA_384, + Signature.ALG_HMAC_SHA_512, + Signature.ALG_HMAC_SHA_256, + Signature.ALG_HMAC_SHA_384, + Signature.ALG_HMAC_SHA_512, + Signature.ALG_HMAC_SHA_256, + Signature.ALG_HMAC_SHA_384, + Signature.ALG_HMAC_SHA_512, + Signature.ALG_HMAC_SHA_256, + Signature.ALG_HMAC_SHA_384, + Signature.ALG_HMAC_SHA_512, + }; + // {KEY, TEXT, MAC}, .. + String[][] HMAC_TESTS = { + // RFC - 2286 HMAC-RIPEMD160 test case 1 + {"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B", + "4869205468657265", + "24CB4BD67D20FC1A5D2ED7732DCC39377F0A5668"}, + // RFC - 2286 HMAC-RIPEMD160 test case 2 + {"4A656665", + "7768617420646F2079612077616E7420666F72206E6F7468696E673F", + "DDA6C0213A485A9E24F4742064A7F033B43C4069"}, + // RFC - 2286 HMAC-RIPEMD160 test case 3 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", + "B0B105360DE759960AB4F35298E116E295D8E7C1"}, + // RFC - 2286 HMAC-RIPEMD160 test case 4 + {"0102030405060708090A0B0C0D0E0F10111213141516171819", + "CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD", + "D5CA862F4D21D5E610E18B4CF1BEB97A4365ECF4"}, + // RFC - 2286 HMAC-RIPEMD160 test case 5 + {"0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C", + "546573742057697468205472756E636174696F6E", + "7619693978F91D90539AE786500FF3D8E0518E39"}, + // RFC - 2286 HMAC-RIPEMD160 test case 6 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B6579202D2048617368204B6579204669727374", + "6466CA07AC5EAC29E1BD523E5ADA7605B791FD8B"}, + // RFC - 2286 HMAC-RIPEMD160 test case 7 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B657920616E64204C6172676572205468616E204F6E6520426C6F636B2D53697A652044617461", + "69EA60798D71616CCE5FD0871E23754CD75D5A0A"}, + // RFC - 2202 HMAC-MD5 test case 1 + {"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B", + "4869205468657265", + "9294727A3638BB1C13F48EF8158BFC9D"}, + // RFC - 2202 HMAC-MD5 test case 2 + {"4A656665", + "7768617420646F2079612077616E7420666F72206E6F7468696E673F", + "750C783E6AB0B503EAA86E310A5DB738"}, + // RFC - 2202 HMAC-MD5 test case 3 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", + "56BE34521D144C88DBB8C733F0E8B3F6"}, + // RFC - 2202 HMAC-MD5 test case 4 + {"0102030405060708090A0B0C0D0E0F10111213141516171819", + "CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD", + "697EAF0ACA3A3AEA3A75164746FFAA79"}, + // RFC - 2202 HMAC-MD5 test case 5 + {"0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C", + "546573742057697468205472756E636174696F6E", + "56461EF2342EDC00F9BAB995690EFD4C"}, + // RFC - 2202 HMAC-MD5 test case 6 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B6579202D2048617368204B6579204669727374", + "6B1AB7FE4BD7BF8F0B62E6CE61B9D0CD"}, + // RFC - 2202 HMAC-MD5 test case 7 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B657920616E64204C6172676572205468616E204F6E6520426C6F636B2D53697A652044617461", + "6F630FAD67CDA0EE1FB1F562DB3AA53E"}, + // RFC - 2202 HMAC-SHA1 test case 1 + {"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B", + "4869205468657265", + "B617318655057264E28BC0B6FB378C8EF146BE00"}, + // RFC - 2202 HMAC-SHA1 test case 2 + {"4A656665", + "7768617420646F2079612077616E7420666F72206E6F7468696E673F", + "EFFCDF6AE5EB2FA2D27416D5F184DF9C259A7C79"}, + // RFC - 2202 HMAC-SHA1 test case 3 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", + "125D7342B9AC11CD91A39AF48AA17B4F63F175D3"}, + // RFC - 2202 HMAC-SHA1 test case 4 + {"0102030405060708090A0B0C0D0E0F10111213141516171819", + "CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD", + "4C9007F4026250C6BC8414F9BF50C86C2D7235DA"}, + // RFC - 2202 HMAC-SHA1 test case 5 + {"0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C", + "546573742057697468205472756E636174696F6E", + "4C1A03424B55E07FE7F27BE1D58BB9324A9A5A04"}, + // RFC - 2202 HMAC-SHA1 test case 6 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B6579202D2048617368204B6579204669727374", + "AA4AE5E15272D00E95705637CE8A3B55ED402112"}, + // RFC - 2202 HMAC-SHA1 test case 7 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B657920616E64204C6172676572205468616E204F6E6520426C6F636B2D53697A652044617461", + "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91"}, + // RFC - 4231 HMAC-SHA-256 test case 1 + {"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B", + "4869205468657265", + "B0344C61D8DB38535CA8AFCEAF0BF12B881DC200C9833DA726E9376C2E32CFF7"}, + // RFC - 4231 HMAC-SHA-384 test case 1 + {"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B", + "4869205468657265", + "AFD03944D84895626B0825F4AB46907F15F9DADBE4101EC682AA034C7CEBC59CFAEA9EA9076EDE7F4AF152E8B2FA9CB6"}, + // RFC - 4231 HMAC-SHA-512 test case 1 + {"0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B", + "4869205468657265", + "87AA7CDEA5EF619D4FF0B4241A1D6CB02379F4E2CE4EC2787AD0B30545E17CDEDAA833B7D6B8A702038B274EAEA3F4E4BE9D914EEB61F1702E696C203A126854"}, + // RFC - 4231 HMAC-SHA-256 test case 2 + {"4A656665", + "7768617420646F2079612077616E7420666F72206E6F7468696E673F", + "5BDCC146BF60754E6A042426089575C75A003F089D2739839DEC58B964EC3843"}, + // RFC - 4231 HMAC-SHA-384 test case 2 + {"4A656665", + "7768617420646F2079612077616E7420666F72206E6F7468696E673F", + "AF45D2E376484031617F78D2B58A6B1B9C7EF464F5A01B47E42EC3736322445E8E2240CA5E69E2C78B3239ECFAB21649"}, + // RFC - 4231 HMAC-SHA-512 test case 2 + {"4A656665", + "7768617420646F2079612077616E7420666F72206E6F7468696E673F", + "164B7A7BFCF819E2E395FBE73B56E0A387BD64222E831FD610270CD7EA2505549758BF75C05A994A6D034F65F8F0E6FDCAEAB1A34D4A6B4B636E070A38BCE737"}, + // RFC - 4231 HMAC-SHA-256 test case 3 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", + "773EA91E36800E46854DB8EBD09181A72959098B3EF8C122D9635514CED565FE"}, + // RFC - 4231 HMAC-SHA-384 test case 3 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", + "88062608D3E6AD8A0AA2ACE014C8A86F0AA635D947AC9FEBE83EF4E55966144B2A5AB39DC13814B94E3AB6E101A34F27"}, + // RFC - 4231 HMAC-SHA-512 test case 3 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD", + "FA73B0089D56A284EFB0F0756C890BE9B1B5DBDD8EE81A3655F83E33B2279D39BF3E848279A722C806B485A47E67C807B946A337BEE8942674278859E13292FB"}, + // RFC - 4231 HMAC-SHA-256 test case 4 + {"0102030405060708090A0B0C0D0E0F10111213141516171819", + "CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD", + "82558A389A443C0EA4CC819899F2083A85F0FAA3E578F8077A2E3FF46729665B"}, + // RFC - 4231 HMAC-SHA-384 test case 4 + {"0102030405060708090a0b0c0d0e0f10111213141516171819", + "CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD", + "3E8A69B7783C25851933AB6290AF6CA77A9981480850009CC5577C6E1F573B4E6801DD23C4A7D679CCF8A386C674CFFB"}, + // RFC - 4231 HMAC-SHA-512 test case 4 + {"0102030405060708090a0b0c0d0e0f10111213141516171819", + "CDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCDCD", + "B0BA465637458C6990E5A8C5F61D4AF7E576D97FF94B872DE76F8050361EE3DBA91CA5C11AA25EB4D679275CC5788063A5F19741120C4F2DE2ADEBEB10A298DD"}, + // RFC - 4231 HMAC-SHA-256 test case 6 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B6579202D2048617368204B6579204669727374", + "60E431591EE0B67F0D8A26AACBF5B77F8E0BC6213728C5140546040F0EE37F54"}, + // RFC - 4231 HMAC-SHA-384 test case 6 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B6579202D2048617368204B6579204669727374", + "4ECE084485813E9088D2C63A041BC5B44F9EF1012A2B588F3CD11F05033AC4C60C2EF6AB4030FE8296248DF163F44952"}, + // RFC - 4231 HMAC-SHA-512 test case 6 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "54657374205573696E67204C6172676572205468616E20426C6F636B2D53697A65204B6579202D2048617368204B6579204669727374", + "80B24263C7C1A3EBB71493C1DD7BE8B49B46D1F41B4AEEC1121B013783F8F3526B56D037E05F2598BD0FD2215D6A1E5295E64F73F63F0AEC8B915A985D786598"}, + // RFC - 4231 HMAC-SHA-256 test case 7 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "5468697320697320612074657374207573696E672061206C6172676572207468616E20626C6F636B2D73697A65206B657920616E642061206C6172676572207468616E20626C6F636B2D73697A6520646174612E20546865206B6579206E6565647320746F20626520686173686564206265666F7265206265696E6720757365642062792074686520484D414320616C676F726974686D2E", + "9B09FFA71B942FCB27635FBCD5B0E944BFDC63644F0713938A7F51535C3A35E2"}, + // RFC - 4231 HMAC-SHA-384 test case 7 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "5468697320697320612074657374207573696E672061206C6172676572207468616E20626C6F636B2D73697A65206B657920616E642061206C6172676572207468616E20626C6F636B2D73697A6520646174612E20546865206B6579206E6565647320746F20626520686173686564206265666F7265206265696E6720757365642062792074686520484D414320616C676F726974686D2E", + "6617178E941F020D351E2F254E8FD32C602420FEB0B8FB9ADCCEBB82461E99C5A678CC31E799176D3860E6110C46523E"}, + // RFC - 4231 HMAC-SHA-512 test case 7 + {"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", + "5468697320697320612074657374207573696E672061206C6172676572207468616E20626C6F636B2D73697A65206B657920616E642061206C6172676572207468616E20626C6F636B2D73697A6520646174612E20546865206B6579206E6565647320746F20626520686173686564206265666F7265206265696E6720757365642062792074686520484D414320616C676F726974686D2E", + "E37B6A775DC87DBAA4DFA9F96E5E3FFDDEBD71F8867289865DF5A32D20CDC944B6022CAC3C4982B10D5EEB55C3E4DE15134676FB6DE0446065C97440FA8C6A58"}, + }; public SymmetricSignatureImplTest(String testName) { super(testName); @@ -105,6 +317,18 @@ public void testSignVerify3DES() { DES3_MAC_15, DES3_MAC_8_IV, DES3_MAC_15_IV); } + /** + * Test of sign/verify methods, of class SymmetricSignatureImpl with 2-key 3DES + */ + public void testSignVerify2x3DES() { + SymmetricKeyImpl desKey = new SymmetricKeyImpl(KeyBuilder.TYPE_DES, KeyBuilder.LENGTH_DES3_2KEY); + desKey.setKey(Hex.decode(DES3_KEY), (short) 0); + + Signature engine = Signature.getInstance(Signature.ALG_DES_MAC8_ISO9797_1_M2_ALG3, false); + testEngineSignVerify(engine, desKey, null, Hex.decode(MESSAGE_15), Hex.decode(DES3_MAC_15[2])); + + } + /** * Test of sign/verifys methods, of class SymmetricSignatureImpl with DES Key */ @@ -115,6 +339,29 @@ public void testSignVerifyDES() { DES_MAC_15, DES_MAC_8_IV, DES_MAC_15_IV); } + /** + * Test of sign/verifys methods, of class SymmetricSignatureImpl with AES Key + */ + public void testSignVerifyAES() { + SymmetricKeyImpl aesKey = new SymmetricKeyImpl(KeyBuilder.TYPE_AES, KeyBuilder.LENGTH_AES_128); + aesKey.setKey(Hex.decode(AES_128_KEY), (short) 0); + Signature engine = Signature.getInstance(Signature.ALG_AES_MAC_128_NOPAD, false); + testEngineSignVerify(engine, aesKey, null, Hex.decode(MESSAGE_16), Hex.decode(AES_CBC_MAC)); + } + + /** + * Test of sign/verifys methods, of class SymmetricSignatureImpl with HMAC Key + */ + public void testSignVerifyHMAC() { + for (int i = 0; i < HMAC_IDS.length; i++) { + byte[] hmacKeyBytes = Hex.decode(HMAC_TESTS[i][0]); + HMACKey hmacKey = (HMACKey)KeyBuilder.buildKey(KeyBuilder.TYPE_HMAC, (short)hmacKeyBytes.length, false); + hmacKey.setKey(hmacKeyBytes, (short) 0, (short)hmacKeyBytes.length); + Signature engine = Signature.getInstance(HMAC_IDS[i], false); + testEngineSignVerify(engine, hmacKey, null, Hex.decode(HMAC_TESTS[i][1]), Hex.decode(HMAC_TESTS[i][2])); + } + } + /** * Test of sign/verify methods, of class SymmetricSignatureImpl with specified key * and etalon data @@ -131,7 +378,7 @@ public void testSignVerify(SymmetricKeyImpl desKey, String msg8, String msg15, engine = Signature.getInstance(Signature.ALG_DES_MAC8_ISO9797_M2, false); testEngineSignVerify(engine, desKey, null, Hex.decode(msg15), Hex.decode(enc15[1])); - + // test DES MAC CBC with non-zero IV byte[] iv = Hex.decode(IV); engine = Signature.getInstance(Signature.ALG_DES_MAC8_NOPAD, false); @@ -160,7 +407,7 @@ public void testEngineSignVerify(Signature engine, Key key, byte[] iv, byte[] ms } else { engine.init(key, Signature.MODE_SIGN, iv, (short) 0, (short) iv.length); } - byte[] mac = JCSystem.makeTransientByteArray((short) macEtalon.length, JCSystem.CLEAR_ON_RESET); + byte[] mac = new byte[macEtalon.length]; // engine.sign(msg, (short) 0, (short) msg.length, mac, (short) 0); assertEquals(true, Arrays.areEqual(mac, macEtalon)); diff --git a/src/test/java/com/licel/jcardsim/remote/JavaCardRemoteServerTest.java b/src/test/java/com/licel/jcardsim/remote/JavaCardRemoteServerTest.java new file mode 100644 index 00000000..a2249446 --- /dev/null +++ b/src/test/java/com/licel/jcardsim/remote/JavaCardRemoteServerTest.java @@ -0,0 +1,38 @@ +package com.licel.jcardsim.remote; + +import com.licel.jcardsim.utils.AIDUtil; +import javacard.framework.AID; +import junit.framework.TestCase; +import org.bouncycastle.util.Arrays; + +import java.rmi.NotBoundException; +import java.rmi.RemoteException; + +public class JavaCardRemoteServerTest extends TestCase { + private static final String TEST_APPLET_AID = "010203040506070809"; + private static final String TEST_APPLET_CLASS = "com.licel.jcardsim.samples.HelloWorldApplet"; + + public JavaCardRemoteServerTest(String name) { + super(name); + } + + public void testServer() throws RemoteException, NotBoundException, InterruptedException { + System.out.println("testServer ..."); + System.setProperty("com.licel.jcardsim.card.applet.0.AID", TEST_APPLET_AID); + System.setProperty("com.licel.jcardsim.card.applet.0.Class", TEST_APPLET_CLASS); + + String host = "127.0.0.1"; + int port = 7777; + new JavaCardRemoteServer(host, port); + JavaCardRemoteClient client = new JavaCardRemoteClient(host, port); + + final AID aid = AIDUtil.create(TEST_APPLET_AID); + client.createApplet(aid, new byte[0], (short) 0, (byte) 0); + + assertEquals(true, client.selectApplet(aid)); + // test NOP + byte[] response = client.transmitCommand(new byte[]{0x01, 0x02, 0x00, 0x00}); + assertEquals(Arrays.areEqual(new byte[]{(byte) 0x90, 0x00}, response), true); + System.out.println("testServer ... done"); + } +} diff --git a/src/test/java/com/licel/jcardsim/smartcardio/CardTerminalSimulatorTest.java b/src/test/java/com/licel/jcardsim/smartcardio/CardTerminalSimulatorTest.java new file mode 100644 index 00000000..17ef56cf --- /dev/null +++ b/src/test/java/com/licel/jcardsim/smartcardio/CardTerminalSimulatorTest.java @@ -0,0 +1,325 @@ +package com.licel.jcardsim.smartcardio; + +import com.licel.jcardsim.utils.AutoResetEvent; +import javacard.framework.ISO7816; +import junit.framework.TestCase; +import org.bouncycastle.util.encoders.Hex; + +import javax.smartcardio.*; +import java.security.NoSuchAlgorithmException; +import java.security.Security; +import java.util.Arrays; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + +public class CardTerminalSimulatorTest extends TestCase { + private static final ATR ETALON_ATR = new ATR(Hex.decode("3BFA1800008131FE454A434F5033315632333298")); + private static final String TEST_APPLET_AID = "010203040506070809"; + + public CardTerminalSimulatorTest(String name) { + super(name); + } + + @Override + protected void setUp() throws Exception { + System.setProperty("com.licel.jcardsim.card.applet.0.AID", TEST_APPLET_AID); + System.setProperty("com.licel.jcardsim.card.applet.0.Class", "com.licel.jcardsim.samples.HelloWorldApplet"); + } + + public void testCreateSingleTerminal() throws CardException, InterruptedException { + final AutoResetEvent autoResetEvent = new AutoResetEvent(); + + // get instance + final CardTerminals terminals = CardTerminalSimulator.terminals("my terminal"); + final CardTerminal terminal = terminals.getTerminal("my terminal"); + + // create and insert card + CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal); + assertSame(terminal, cardSimulator.getAssignedCardTerminal()); + + // connect to card + Card card = terminal.connect("T=1"); + test(card); + + // assign same card + new Thread() { + @Override + public void run() { + try { + if (terminals.waitForChange(0)) { + autoResetEvent.signal(); + } + } catch (CardException e) { + throw new RuntimeException(e); + } + } + }.start(); + cardSimulator.assignToTerminal(terminal); + assertTrue(autoResetEvent.await(1, TimeUnit.SECONDS)); + assertSame(terminal, cardSimulator.getAssignedCardTerminal()); + + // assign different card + CardSimulator cardSimulator2 = new CardSimulator(); + assertNull(cardSimulator2.getAssignedCardTerminal()); + cardSimulator2.assignToTerminal(terminal); + + assertSame(terminal, cardSimulator2.getAssignedCardTerminal()); + assertNull(cardSimulator.getAssignedCardTerminal()); + } + + public void testCreateTerminals() throws CardException { + // get instance + CardTerminals terminals = CardTerminalSimulator.terminals("terminal #1", "terminal #2"); + CardTerminal terminal = terminals.getTerminal("terminal #2"); + + // create and insert card + CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal); + + // connect to card + Card card = terminal.connect("T=1"); + test(card); + } + + public void testProvider() throws CardException, NoSuchAlgorithmException { + // register security provider + if (Security.getProvider("CardTerminalSimulator") == null) { + Security.addProvider(new CardTerminalSimulator.SecurityProvider()); + } + + // get instance + TerminalFactory tf = TerminalFactory.getInstance("CardTerminalSimulator", null); + CardTerminals terminals = tf.terminals(); + CardTerminal terminal = terminals.getTerminal("jCardSim.Terminal"); + + // create and insert card + CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal); + + // connect to card + Card card = terminal.connect("T=1"); + test(card); + } + + public void testProviderCustomNames() throws CardException, NoSuchAlgorithmException { + // register security provider + if (Security.getProvider("CardTerminalSimulator") == null) { + Security.addProvider(new CardTerminalSimulator.SecurityProvider()); + } + + // get instance + TerminalFactory tf = TerminalFactory.getInstance("CardTerminalSimulator", new String[]{"x", "y"}); + CardTerminals terminals = tf.terminals(); + CardTerminal terminal = terminals.getTerminal("y"); + + // create and insert card + CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal); + + // connect to card + Card card = terminal.connect("T=1"); + + test(card); + assertEquals(2, terminals.list().size()); + assertEquals("x", terminals.list().get(0).getName()); + assertEquals("y", terminals.list().get(1).getName()); + } + + public void testWaitForInsert() throws CardException, InterruptedException { + final AutoResetEvent autoResetEvent = new AutoResetEvent(); + final CardTerminals terminals = CardTerminalSimulator.terminals("my terminal"); + final CardTerminal terminal = terminals.getTerminal("my terminal"); + assertEquals(true, terminal.waitForCardAbsent(1)); + assertEquals(false, terminal.waitForCardPresent(1)); + + final CardSimulator cardSimulator = new CardSimulator(); + new Thread() { + @Override + public void run() { + cardSimulator.assignToTerminal(terminal); + autoResetEvent.signal(); + } + }.start(); + + autoResetEvent.await(1, TimeUnit.MINUTES); + assertEquals(true, terminal.waitForCardPresent(1)); + + // connect to card + Card card = terminal.connect("T=1"); + test(card); + } + + public void testWaitForCardAbsent() throws CardException, InterruptedException { + final CardTerminals terminals = CardTerminalSimulator.terminals("my terminal"); + final CardTerminal terminal = terminals.getTerminal("my terminal"); + + final CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal); + + assertEquals(true, terminal.waitForCardPresent(1)); + assertEquals(false, terminal.waitForCardAbsent(1)); + + new Thread() { + @Override + public void run() { + cardSimulator.assignToTerminal(null); + } + }.start(); + + assertEquals(true, terminal.waitForCardAbsent(0)); + } + + public void testWaitForCardChange() throws CardException, InterruptedException { + final CardTerminals terminals = CardTerminalSimulator.terminals("my terminal"); + + final CardSimulator cardSimulator = new CardSimulator(); + assertEquals(false, terminals.waitForChange(1)); + + CardTerminal terminal = terminals.getTerminal("my terminal"); + cardSimulator.assignToTerminal(terminal); + + assertEquals(true, terminals.waitForChange(1)); + assertEquals(false, terminals.waitForChange(1)); + cardSimulator.assignToTerminal(null); + assertEquals(true, terminals.waitForChange(1)); + } + + public void testList() throws CardException, InterruptedException { + final CardTerminals terminals = CardTerminalSimulator.terminals("1", "2", "3", "4"); + + CardTerminal terminal1 = terminals.getTerminal("1"); + + assertEquals(4, terminals.list().size()); + assertEquals(4, terminals.list(CardTerminals.State.ALL).size()); + + CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal1); + assertTrue(terminal1.isCardPresent()); + assertEquals(3, terminals.list(CardTerminals.State.CARD_ABSENT).size()); + assertEquals(3, terminals.list(CardTerminals.State.CARD_REMOVAL).size()); + assertEquals(0, terminals.list(CardTerminals.State.CARD_PRESENT).size()); + assertEquals(1, terminals.list(CardTerminals.State.CARD_INSERTION).size()); + assertEquals(0, terminals.list(CardTerminals.State.CARD_PRESENT).size()); + + assertEquals(true, terminals.waitForChange(1)); + assertEquals(1, terminals.list(CardTerminals.State.CARD_INSERTION).size()); + assertEquals(0, terminals.list(CardTerminals.State.CARD_REMOVAL).size()); + + cardSimulator.assignToTerminal(null); + assertFalse(terminal1.isCardPresent()); + assertEquals(true, terminals.waitForChange(1)); + + assertEquals(4, terminals.list(CardTerminals.State.ALL).size()); + assertEquals(3, terminals.list(CardTerminals.State.CARD_ABSENT).size()); + assertEquals(1, terminals.list(CardTerminals.State.CARD_REMOVAL).size()); + + assertEquals(0, terminals.list(CardTerminals.State.CARD_INSERTION).size()); + assertEquals(0, terminals.list(CardTerminals.State.CARD_PRESENT).size()); + assertEquals(4, terminals.list(CardTerminals.State.CARD_ABSENT).size()); + } + + public void testExclusive() throws CardException, InterruptedException { + final CardTerminal terminal = CardTerminalSimulator.terminal(new CardSimulator()); + final AutoResetEvent autoResetEvent = new AutoResetEvent(); + final AtomicBoolean gotException = new AtomicBoolean(false); + + final CardSimulator cardSimulator = new CardSimulator(); + cardSimulator.assignToTerminal(terminal); + final Card card = terminal.connect("T=1"); + final CommandAPDU commandAPDU = new CommandAPDU(0, 0, 0, 0); + + card.beginExclusive(); + card.getBasicChannel().transmit(commandAPDU); + + new Thread() { + @Override + public void run() { + try { + card.getBasicChannel().transmit(commandAPDU); + } catch (CardException e) { + gotException.set(true); + } finally { + autoResetEvent.signal(); + } + autoResetEvent.signal(); + } + }.start(); + + autoResetEvent.await(1, TimeUnit.MINUTES); + card.endExclusive(); + } + + private void test(Card jcsCard) throws CardException { + assertTrue(jcsCard != null); + // check card ATR + assertEquals(jcsCard.getATR(), ETALON_ATR); + // check card protocol + assertEquals(jcsCard.getProtocol(), "T=1"); + // get basic channel + CardChannel jcsChannel = jcsCard.getBasicChannel(); + assertTrue(jcsChannel != null); + // create applet data = aid len (byte), aid bytes, params length (byte), param + byte[] aidBytes = Hex.decode(TEST_APPLET_AID); + byte[] createData = new byte[1 + aidBytes.length + 1 + 2 + 3]; + createData[0] = (byte) aidBytes.length; + System.arraycopy(aidBytes, 0, createData, 1, aidBytes.length); + createData[1 + aidBytes.length] = (byte) 5; + createData[2 + aidBytes.length] = 0; // aid + createData[3 + aidBytes.length] = 0; // control + createData[4 + aidBytes.length] = 2; // params + createData[5 + aidBytes.length] = 0xF; // params + createData[6 + aidBytes.length] = 0xF; // params + CommandAPDU createApplet = new CommandAPDU(0x80, 0xb8, 0, 0, createData); + ResponseAPDU response = jcsChannel.transmit(createApplet); + assertEquals(response.getSW(), 0x9000); + assertEquals(true, Arrays.equals(response.getData(), aidBytes)); + // select applet + CommandAPDU selectApplet = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 4, 0, Hex.decode(TEST_APPLET_AID)); + response = jcsChannel.transmit(selectApplet); + assertEquals(response.getSW(), 0x9000); + // test NOP + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x02, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + // test SW_INS_NOT_SUPPORTED + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x05, 0x00, 0x00)); + assertEquals(ISO7816.SW_INS_NOT_SUPPORTED, response.getSW()); + // test hello world from card + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x01, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello world !", new String(response.getData())); + // test echo + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes())); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello javacard world !", new String(response.getData())); + // test echo v2 + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x03, 0x00, 0x00, ("Hello javacard world !").getBytes())); + assertEquals(0x9000, response.getSW()); + assertEquals("Hello javacard world !", new String(response.getData())); + // test echo install params + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x04, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + assertEquals(0xF, response.getData()[0]); + assertEquals(0xF, response.getData()[1]); + // test continued data + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x06, 0x00, 0x00)); + assertEquals(0x6107, response.getSW()); + assertEquals("Hello ", new String(response.getData())); + // test https://github.com/licel/jcardsim/issues/13 + byte[] listObjectsCmd = new byte[5]; + listObjectsCmd[0] = (byte) 0xb0; + listObjectsCmd[1] = (byte) 0x58; + listObjectsCmd[2] = (byte) 0x00; + listObjectsCmd[3] = (byte) 0x00; + listObjectsCmd[4] = (byte) 0x0E; + response = jcsChannel.transmit(new CommandAPDU(listObjectsCmd)); + assertEquals(0x9C12, response.getSW()); + // application specific sw + data + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x07, 0x00, 0x00)); + assertEquals(0x9B00, response.getSW()); + assertEquals("Hello world !", new String(response.getData())); + // sending maximum data + response = jcsChannel.transmit(new CommandAPDU(0x01, 0x08, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); + } +} diff --git a/src/test/java/com/licel/jcardsim/smartcardio/JCardSimProviderTest.java b/src/test/java/com/licel/jcardsim/smartcardio/JCardSimProviderTest.java index 6c07cb5f..74eb42fa 100644 --- a/src/test/java/com/licel/jcardsim/smartcardio/JCardSimProviderTest.java +++ b/src/test/java/com/licel/jcardsim/smartcardio/JCardSimProviderTest.java @@ -15,6 +15,8 @@ */ package com.licel.jcardsim.smartcardio; +import com.licel.jcardsim.base.SimulatorSystem; +import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; import java.security.Security; import java.util.Arrays; @@ -23,7 +25,6 @@ import javax.smartcardio.*; import junit.framework.TestCase; import org.bouncycastle.util.encoders.Hex; -import com.licel.jcardsim.base.SimulatorSystem; /** * Test Java Card Terminal emulation. @@ -32,7 +33,7 @@ */ public class JCardSimProviderTest extends TestCase { - private static final ATR ETALON_ATR = new ATR(Hex.decode(JCSCard.DEFAULT_ATR)); + private static final ATR ETALON_ATR = new ATR(Hex.decode("3BFA1800008131FE454A434F5033315632333298")); private static final String TEST_APPLET_AID = "010203040506070809"; protected void setUp() throws Exception { @@ -43,10 +44,9 @@ protected void tearDown() throws Exception { super.tearDown(); } - public void testProvider() throws CardException, NoSuchAlgorithmException { - SimulatorSystem.resetRuntime(); - System.setProperty("com.licel.jcardsim.smartcardio.applet.0.AID", TEST_APPLET_AID); - System.setProperty("com.licel.jcardsim.smartcardio.applet.0.Class", "com.licel.jcardsim.samples.HelloWorldApplet"); + public void testProvider() throws CardException, NoSuchAlgorithmException, UnsupportedEncodingException { + System.setProperty("com.licel.jcardsim.card.applet.0.AID", TEST_APPLET_AID); + System.setProperty("com.licel.jcardsim.card.applet.0.Class", "com.licel.jcardsim.samples.HelloWorldApplet"); if (Security.getProvider("jCardSim") == null) { JCardSimProvider provider = new JCardSimProvider(); Security.addProvider(provider); @@ -75,7 +75,7 @@ public void testProvider() throws CardException, NoSuchAlgorithmException { // get basic channel CardChannel jcsChannel = jcsCard.getBasicChannel(); assertTrue(jcsChannel != null); - // create applet data = aid len (byte), aid bytes, params lenth (byte), param + // create applet data = aid len (byte), aid bytes, params length (byte), param byte[] aidBytes = Hex.decode(TEST_APPLET_AID); byte[] createData = new byte[1+aidBytes.length+1+2+3]; createData[0] = (byte) aidBytes.length; @@ -91,31 +91,51 @@ public void testProvider() throws CardException, NoSuchAlgorithmException { assertEquals(response.getSW(), 0x9000); assertEquals(true, Arrays.equals(response.getData(), aidBytes)); // select applet - CommandAPDU selectApplet = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 0, 0, Hex.decode(TEST_APPLET_AID)); + CommandAPDU selectApplet = new CommandAPDU(ISO7816.CLA_ISO7816, ISO7816.INS_SELECT, 4, 0, Hex.decode(TEST_APPLET_AID)); response = jcsChannel.transmit(selectApplet); assertEquals(response.getSW(), 0x9000); // test NOP - response = jcsChannel.transmit(new CommandAPDU(0x01, 0x02, 0x00, 0x00)); + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x02, 0x00, 0x00)); assertEquals(0x9000, response.getSW()); // test SW_INS_NOT_SUPPORTED - response = jcsChannel.transmit(new CommandAPDU(0x01, 0x05, 0x00, 0x00)); + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x05, 0x00, 0x00)); assertEquals(ISO7816.SW_INS_NOT_SUPPORTED, response.getSW()); // test hello world from card - response = jcsChannel.transmit(new CommandAPDU(0x01, 0x01, 0x00, 0x00)); + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x01, 0x00, 0x00)); assertEquals(0x9000, response.getSW()); assertEquals("Hello world !", new String(response.getData())); // test echo - response = jcsChannel.transmit(new CommandAPDU(0x01, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes())); + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x01, 0x01, 0x00, ("Hello javacard world !").getBytes())); assertEquals(0x9000, response.getSW()); assertEquals("Hello javacard world !", new String(response.getData())); // test echo v2 - response = jcsChannel.transmit(new CommandAPDU(0x01, 0x03, 0x00, 0x00, ("Hello javacard world !").getBytes())); + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x03, 0x00, 0x00, ("Hello javacard world !").getBytes())); assertEquals(0x9000, response.getSW()); assertEquals("Hello javacard world !", new String(response.getData())); - // test echo intall params - response = jcsChannel.transmit(new CommandAPDU(0x01, 0x04, 0x00, 0x00)); + // test echo install params + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x04, 0x00, 0x00)); assertEquals(0x9000, response.getSW()); assertEquals(0xF, response.getData()[0]); assertEquals(0xF, response.getData()[1]); + // test continued data + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x06, 0x00, 0x00)); + assertEquals(0x6107, response.getSW()); + assertEquals("Hello ", new String(response.getData())); + // test https://github.com/licel/jcardsim/issues/13 + byte[] listObjectsCmd = new byte[5]; + listObjectsCmd[0] = (byte) 0xb0; + listObjectsCmd[1] = (byte) 0x58; + listObjectsCmd[2] = (byte) 0x00; + listObjectsCmd[3] = (byte) 0x00; + listObjectsCmd[4] = (byte) 0x0E; + response = jcsChannel.transmit(new CommandAPDU(listObjectsCmd)); + assertEquals(0x9C12, response.getSW()); + // application specific sw + data + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x07, 0x00, 0x00)); + assertEquals(0x9B00, response.getSW()); + assertEquals("Hello world !", new String(response.getData())); + // sending maximum data + response = jcsChannel.transmit(new CommandAPDU(0x00, 0x08, 0x00, 0x00)); + assertEquals(0x9000, response.getSW()); } } diff --git a/src/test/java/com/licel/jcardsim/utils/AIDUtilTest.java b/src/test/java/com/licel/jcardsim/utils/AIDUtilTest.java new file mode 100644 index 00000000..b5483e5a --- /dev/null +++ b/src/test/java/com/licel/jcardsim/utils/AIDUtilTest.java @@ -0,0 +1,21 @@ +package com.licel.jcardsim.utils; + +import javacard.framework.AID; +import junit.framework.TestCase; + +public class AIDUtilTest extends TestCase { + public AIDUtilTest(String name) { + super(name); + } + + public void testSelectString() { + assertEquals("00A4040005CAFECAFE0100" ,ByteUtil.hexString(AIDUtil.select("cafecafe01"))); + assertEquals("00A4040001CA00" ,ByteUtil.hexString(AIDUtil.select("ca"))); + assertEquals("00A404000000", ByteUtil.hexString(AIDUtil.select(""))); + } + + public void testSelectAID() { + AID aid = AIDUtil.create("cafecafe01"); + assertEquals("00A4040005CAFECAFE0100" ,ByteUtil.hexString(AIDUtil.select(aid))); + } +} diff --git a/src/test/java/com/licel/jcardsim/utils/APDUScriptToolTest.java b/src/test/java/com/licel/jcardsim/utils/APDUScriptToolTest.java index 17319b27..4d0585f8 100644 --- a/src/test/java/com/licel/jcardsim/utils/APDUScriptToolTest.java +++ b/src/test/java/com/licel/jcardsim/utils/APDUScriptToolTest.java @@ -15,11 +15,14 @@ */ package com.licel.jcardsim.utils; +import com.licel.jcardsim.base.SimulatorSystem; +import junit.framework.TestCase; + import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.InputStream; +import java.io.PrintStream; import java.util.Properties; -import junit.framework.TestCase; -import com.licel.jcardsim.base.SimulatorSystem; /** * Test class APDUScriptTool. @@ -52,28 +55,44 @@ public void testExecuteCommands() throws Exception { sb.append("//CREATE APPLET CMD\n"); sb.append("0x80 0xb8 0x00 0x00 0x10 0x9 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x8 0x09 0x05 0x00 0x00 0x02 0xF 0xF 0x7f;\n"); sb.append("// SELECT APPLET CMD\n"); - sb.append("0x00 0xa4 0x00 0x00 0x09 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x8 0x09 0x7f;\n"); + sb.append("0x00 0xa4 0x04 0x00 0x09 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x8 0x09 0x7f;\n"); sb.append("// TEST NOP\n"); - sb.append("0x01 0x02 0x00 0x00 0x00 0x2; \n"); + sb.append("0x00 0x02 0x00 0x00 0x00 0x2; \n"); sb.append("// TEST SW_INS_NOT_SUPPORTED\n"); - sb.append("0x01 0x05 0x00 0x00 0x00 0x2 ;\n"); + sb.append("0x00 0x05 0x00 0x00 0x00 0x2 ;\n"); sb.append("// test hello world from card\n"); - sb.append("0x01 0x01 0x00 0x00 0x00 0x0d;\n"); + sb.append("0x00 0x01 0x00 0x00 0x00 0x0d;\n"); sb.append("// test echo\n"); - sb.append("0x01 0x01 0x01 0x00 0x0d 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x20 0x21 0x0d;\n"); + sb.append("0x00 0x01 0x01 0x00 0x0d 0x48 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x20 0x21 0x0d;\n"); sb.append("// test echo2\n"); - sb.append("0x01 0x03 0x01 0x02 0x05 0x01 0x02 0x03 0x04 0x05 0x7F;"); + sb.append("0x00 0x03 0x01 0x02 0x05 0x01 0x02 0x03 0x04 0x05 0x7F;"); sb.append("powerdown;\n"); InputStream commandsStream = new ByteArrayInputStream(sb.toString().replaceAll("\n", System.getProperty("line.separator")).getBytes()); boolean isException = true; + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { - SimulatorSystem.resetRuntime(); - APDUScriptTool.executeCommands(cfg, commandsStream, null); + APDUScriptTool.executeCommands(cfg, commandsStream, new PrintStream(baos)); isException = false; } catch (Throwable t) { t.printStackTrace(); } + finally { + commandsStream.close(); + } assertEquals(isException, false); - commandsStream.close(); + + String expectedOutput = + "CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 10, 09, 01, 02, 03, 04, 05, 06, 07, 08, 09, 05, 00, 00, 02, 0f, 0f, Le: 09, 01, 02, 03, 04, 05, 06, 07, 08, 09, SW1: 90, SW2: 00\n" + + "CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 09, 01, 02, 03, 04, 05, 06, 07, 08, 09, Le: 00, SW1: 90, SW2: 00\n" + + "CLA: 00, INS: 02, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 90, SW2: 00\n" + + "CLA: 00, INS: 05, P1: 00, P2: 00, Lc: 00, Le: 00, SW1: 6d, SW2: 00\n" + + "CLA: 00, INS: 01, P1: 00, P2: 00, Lc: 00, Le: 0d, 48, 65, 6c, 6c, 6f, 20, 77, 6f, 72, 6c, 64, 20, 21, SW1: 90, SW2: 00\n" + + "CLA: 00, INS: 01, P1: 01, P2: 00, Lc: 0d, 48, 65, 6c, 6c, 6f, 20, 77, 6f, 72, 6c, 64, 20, 21, Le: 0d, 48, 65, 6c, 6c, 6f, 20, 77, 6f, 72, 6c, 64, 20, 21, SW1: 90, SW2: 00\n" + + "CLA: 00, INS: 03, P1: 01, P2: 02, Lc: 05, 01, 02, 03, 04, 05, Le: 05, 01, 02, 03, 04, 05, SW1: 90, SW2: 00\n"; + + String output = baos.toString("UTF-8"); + System.out.print(output); + assertEquals(expectedOutput, output.replace("\r\n","\n")); } } diff --git a/src/test/java/javacard/framework/UtilTest.java b/src/test/java/javacard/framework/UtilTest.java new file mode 100644 index 00000000..6aa87af5 --- /dev/null +++ b/src/test/java/javacard/framework/UtilTest.java @@ -0,0 +1,44 @@ +package javacard.framework; + +import junit.framework.TestCase; + +public class UtilTest extends TestCase { + + /** + * + */ + public void testArrayCompare1() { + byte[] src = new byte[]{0x01}; + byte[] dest = new byte[]{0x02}; + byte res = Util.arrayCompare(src, (short) 0, dest, (short) 0, (short) 1); + assertEquals(-1, res); + } + + /** + * + */ + public void testArrayCompare2() { + byte[] src = new byte[]{(byte) 0xff}; + byte[] dest = new byte[]{0x01}; + byte res = Util.arrayCompare(src, (short) 0, dest, (short) 0, (short) 1); + assertEquals(1, res); + } + + /** + * Test of arrayFillNonAtomic method, of class Util. + */ + public void testArrayFillNonAtomic() { + System.out.println("arrayFillNonAtomic"); + byte[] etalonArray = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0}; + System.out.println(etalonArray.length); + byte[] bArray = new byte[16]; + short bOff = 8; + short bLen = 7; + byte bValue = 1; + short expResult = (short) (bOff + bLen); + short result = Util.arrayFillNonAtomic(bArray, bOff, bLen, bValue); + assertEquals(expResult, result); + byte res = Util.arrayCompare(bArray, (short) 0, etalonArray, (short) 0, (short) 16); + assertEquals(0, res); + } +} diff --git a/src/test/resources/com/licel/jcardsim/base/helloworld.jar b/src/test/resources/com/licel/jcardsim/base/helloworld.jar new file mode 100644 index 00000000..06762d6c Binary files /dev/null and b/src/test/resources/com/licel/jcardsim/base/helloworld.jar differ