├── .gitignore ├── NOTICE ├── README.md ├── javadoc ├── allclasses-frame.html ├── allclasses-noframe.html ├── at │ ├── fhooe │ │ └── usmile │ │ │ ├── app │ │ │ └── se_performance │ │ │ │ ├── TestPerformer2Activity.html │ │ │ │ ├── TestPerformerActivity.html │ │ │ │ ├── class-use │ │ │ │ ├── TestPerformer2Activity.html │ │ │ │ └── TestPerformerActivity.html │ │ │ │ ├── connection │ │ │ │ ├── SEConnection.html │ │ │ │ ├── class-use │ │ │ │ │ └── SEConnection.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ ├── package-use.html │ │ │ │ ├── tests │ │ │ │ ├── AEStest.html │ │ │ │ ├── CryptoTest.html │ │ │ │ ├── ECDHTest.html │ │ │ │ ├── RSA1024Test.html │ │ │ │ ├── RoundTripTest.html │ │ │ │ ├── SHAtest.html │ │ │ │ ├── SimpleEchoTest.html │ │ │ │ ├── TrippleDEStest.html │ │ │ │ ├── class-use │ │ │ │ │ ├── AEStest.html │ │ │ │ │ ├── CryptoTest.html │ │ │ │ │ ├── ECDHTest.html │ │ │ │ │ ├── RSA1024Test.html │ │ │ │ │ ├── RoundTripTest.html │ │ │ │ │ ├── SHAtest.html │ │ │ │ │ ├── SimpleEchoTest.html │ │ │ │ │ └── TrippleDEStest.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ │ │ └── util │ │ │ │ ├── APDU.html │ │ │ │ ├── Converter.html │ │ │ │ ├── Operations.OperationType.html │ │ │ │ ├── Operations.html │ │ │ │ ├── class-use │ │ │ │ ├── APDU.html │ │ │ │ ├── Converter.html │ │ │ │ ├── Operations.OperationType.html │ │ │ │ └── Operations.html │ │ │ │ ├── package-frame.html │ │ │ │ ├── package-summary.html │ │ │ │ ├── package-tree.html │ │ │ │ └── package-use.html │ │ │ ├── cryptotest │ │ │ ├── CryptoTest.html │ │ │ ├── class-use │ │ │ │ └── CryptoTest.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ │ ├── rsa1024 │ │ │ ├── RSA1024.html │ │ │ ├── class-use │ │ │ │ └── RSA1024.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ │ └── simpleecho │ │ │ ├── SimpleEcho.html │ │ │ ├── class-use │ │ │ └── SimpleEcho.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ └── mroland │ │ ├── jcemulator │ │ └── test │ │ │ ├── EmulatorPerformanceTest.html │ │ │ ├── EmulatorPerformanceTest2.html │ │ │ ├── EmulatorPerformanceTest2Install.html │ │ │ ├── EmulatorPerformanceTestInstall.html │ │ │ ├── EmulatorSCPTest.html │ │ │ ├── EmulatorSCPTestInstall.html │ │ │ ├── MemoryStatusDebugRunner.html │ │ │ ├── class-use │ │ │ ├── EmulatorPerformanceTest.html │ │ │ ├── EmulatorPerformanceTest2.html │ │ │ ├── EmulatorPerformanceTest2Install.html │ │ │ ├── EmulatorPerformanceTestInstall.html │ │ │ ├── EmulatorSCPTest.html │ │ │ ├── EmulatorSCPTestInstall.html │ │ │ └── MemoryStatusDebugRunner.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ ├── logging │ │ ├── Logging.html │ │ ├── class-use │ │ │ └── Logging.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ ├── objectstaterecovery │ │ ├── ArrayState.html │ │ ├── ClassState.html │ │ ├── FieldState.DeserializedFieldState.html │ │ ├── FieldState.html │ │ ├── ObjectReferenceState.html │ │ ├── ObjectStateRecoveryReflection.html │ │ ├── PersistentMemory.html │ │ ├── PersistentMemory_Disabled.html │ │ ├── PrimitiveValueState.html │ │ ├── TransientArrayState.html │ │ ├── TransientMemory.html │ │ ├── XmlSchemaPersistentMemory.html │ │ ├── XmlSchemaTransientMemory.html │ │ ├── class-use │ │ │ ├── ArrayState.html │ │ │ ├── ClassState.html │ │ │ ├── FieldState.DeserializedFieldState.html │ │ │ ├── FieldState.html │ │ │ ├── ObjectReferenceState.html │ │ │ ├── ObjectStateRecoveryReflection.html │ │ │ ├── PersistentMemory.html │ │ │ ├── PersistentMemory_Disabled.html │ │ │ ├── PrimitiveValueState.html │ │ │ ├── TransientArrayState.html │ │ │ ├── TransientMemory.html │ │ │ ├── XmlSchemaPersistentMemory.html │ │ │ └── XmlSchemaTransientMemory.html │ │ ├── helper │ │ │ ├── IdentityObjectIntMap.html │ │ │ ├── ObjectMap.Entries.html │ │ │ ├── ObjectMap.Entry.html │ │ │ ├── ObjectMap.Keys.html │ │ │ ├── ObjectMap.Values.html │ │ │ ├── ObjectMap.html │ │ │ ├── UniqueObjectIdentifier.html │ │ │ ├── class-use │ │ │ │ ├── IdentityObjectIntMap.html │ │ │ │ ├── ObjectMap.Entries.html │ │ │ │ ├── ObjectMap.Entry.html │ │ │ │ ├── ObjectMap.Keys.html │ │ │ │ ├── ObjectMap.Values.html │ │ │ │ ├── ObjectMap.html │ │ │ │ └── UniqueObjectIdentifier.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ └── utils │ │ ├── ArrayUtils.html │ │ ├── StringUtils.html │ │ ├── class-use │ │ ├── ArrayUtils.html │ │ └── StringUtils.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── com │ └── licel │ │ └── jcardsim │ │ ├── base │ │ ├── AppletDefinition.html │ │ ├── ISO7816Extended.html │ │ ├── PackageDefinition.html │ │ ├── SimulatorConfig.html │ │ ├── SimulatorRuntime.html │ │ ├── SimulatorSystem.html │ │ ├── TransactionManager.html │ │ ├── class-use │ │ │ ├── AppletDefinition.html │ │ │ ├── ISO7816Extended.html │ │ │ ├── PackageDefinition.html │ │ │ ├── SimulatorConfig.html │ │ │ ├── SimulatorRuntime.html │ │ │ ├── SimulatorSystem.html │ │ │ └── TransactionManager.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ └── crypto │ │ ├── AsymmetricCipherImpl.html │ │ ├── AsymmetricSignatureImpl.html │ │ ├── ByteContainer.html │ │ ├── CRC16.html │ │ ├── CRC32.html │ │ ├── DSAKeyImpl.html │ │ ├── DSAPrivateKeyImpl.html │ │ ├── DSAPublicKeyImpl.html │ │ ├── ECKeyImpl.html │ │ ├── ECPrivateKeyImpl.html │ │ ├── ECPublicKeyImpl.html │ │ ├── KeyAgreementImpl.html │ │ ├── KeyImpl.html │ │ ├── KeyPairImpl.html │ │ ├── KeyWithParameters.html │ │ ├── MessageDigestImpl.html │ │ ├── RSAKeyImpl.html │ │ ├── RSAPrivateCrtKeyImpl.html │ │ ├── RandomDataImpl.html │ │ ├── SymmetricCipherImpl.html │ │ ├── SymmetricKeyImpl.html │ │ ├── SymmetricSignatureImpl.html │ │ ├── class-use │ │ ├── AsymmetricCipherImpl.html │ │ ├── AsymmetricSignatureImpl.html │ │ ├── ByteContainer.html │ │ ├── CRC16.html │ │ ├── CRC32.html │ │ ├── DSAKeyImpl.html │ │ ├── DSAPrivateKeyImpl.html │ │ ├── DSAPublicKeyImpl.html │ │ ├── ECKeyImpl.html │ │ ├── ECPrivateKeyImpl.html │ │ ├── ECPublicKeyImpl.html │ │ ├── KeyAgreementImpl.html │ │ ├── KeyImpl.html │ │ ├── KeyPairImpl.html │ │ ├── KeyWithParameters.html │ │ ├── MessageDigestImpl.html │ │ ├── RSAKeyImpl.html │ │ ├── RSAPrivateCrtKeyImpl.html │ │ ├── RandomDataImpl.html │ │ ├── SymmetricCipherImpl.html │ │ ├── SymmetricKeyImpl.html │ │ └── SymmetricSignatureImpl.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-all.html ├── index.html ├── java │ └── rmi │ │ ├── Remote.html │ │ ├── RemoteException.html │ │ ├── class-use │ │ ├── Remote.html │ │ └── RemoteException.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── javacard │ ├── framework │ │ ├── AID.html │ │ ├── APDU.html │ │ ├── APDUException.html │ │ ├── Applet.html │ │ ├── AppletEvent.html │ │ ├── CardException.html │ │ ├── CardRuntimeException.html │ │ ├── ISO7816.html │ │ ├── ISOException.html │ │ ├── JCSystem.html │ │ ├── MultiSelectable.html │ │ ├── OwnerPIN.html │ │ ├── PIN.html │ │ ├── PINException.html │ │ ├── Shareable.html │ │ ├── SystemException.html │ │ ├── TransactionException.html │ │ ├── UserException.html │ │ ├── Util.html │ │ ├── __AIDWrapper.html │ │ ├── class-use │ │ │ ├── AID.html │ │ │ ├── APDU.html │ │ │ ├── APDUException.html │ │ │ ├── Applet.html │ │ │ ├── AppletEvent.html │ │ │ ├── CardException.html │ │ │ ├── CardRuntimeException.html │ │ │ ├── ISO7816.html │ │ │ ├── ISOException.html │ │ │ ├── JCSystem.html │ │ │ ├── MultiSelectable.html │ │ │ ├── OwnerPIN.html │ │ │ ├── PIN.html │ │ │ ├── PINException.html │ │ │ ├── Shareable.html │ │ │ ├── SystemException.html │ │ │ ├── TransactionException.html │ │ │ ├── UserException.html │ │ │ ├── Util.html │ │ │ └── __AIDWrapper.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ └── security │ │ ├── AESKey.html │ │ ├── Checksum.html │ │ ├── CryptoException.html │ │ ├── DESKey.html │ │ ├── DSAKey.html │ │ ├── DSAPrivateKey.html │ │ ├── DSAPublicKey.html │ │ ├── ECKey.html │ │ ├── ECPrivateKey.html │ │ ├── ECPublicKey.html │ │ ├── HMACKey.html │ │ ├── InitializedMessageDigest.html │ │ ├── Key.html │ │ ├── KeyAgreement.html │ │ ├── KeyBuilder.html │ │ ├── KeyPair.html │ │ ├── KoreanSEEDKey.html │ │ ├── MessageDigest.html │ │ ├── PrivateKey.html │ │ ├── PublicKey.html │ │ ├── RSAPrivateCrtKey.html │ │ ├── RSAPrivateKey.html │ │ ├── RSAPublicKey.html │ │ ├── RandomData.html │ │ ├── SecretKey.html │ │ ├── Signature.html │ │ ├── SignatureMessageRecovery.html │ │ ├── class-use │ │ ├── AESKey.html │ │ ├── Checksum.html │ │ ├── CryptoException.html │ │ ├── DESKey.html │ │ ├── DSAKey.html │ │ ├── DSAPrivateKey.html │ │ ├── DSAPublicKey.html │ │ ├── ECKey.html │ │ ├── ECPrivateKey.html │ │ ├── ECPublicKey.html │ │ ├── HMACKey.html │ │ ├── InitializedMessageDigest.html │ │ ├── Key.html │ │ ├── KeyAgreement.html │ │ ├── KeyBuilder.html │ │ ├── KeyPair.html │ │ ├── KoreanSEEDKey.html │ │ ├── MessageDigest.html │ │ ├── PrivateKey.html │ │ ├── PublicKey.html │ │ ├── RSAPrivateCrtKey.html │ │ ├── RSAPrivateKey.html │ │ ├── RSAPublicKey.html │ │ ├── RandomData.html │ │ ├── SecretKey.html │ │ ├── Signature.html │ │ └── SignatureMessageRecovery.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── javacardx │ ├── apdu │ │ ├── ExtendedLength.html │ │ ├── class-use │ │ │ └── ExtendedLength.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ ├── crypto │ │ ├── Cipher.html │ │ ├── KeyEncryption.html │ │ ├── class-use │ │ │ ├── Cipher.html │ │ │ └── KeyEncryption.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ └── framework │ │ └── math │ │ ├── BCDUtil.html │ │ ├── BigNumber.html │ │ ├── ParityBit.html │ │ ├── class-use │ │ ├── BCDUtil.html │ │ ├── BigNumber.html │ │ └── ParityBit.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── resources │ ├── background.gif │ ├── tab.gif │ ├── titlebar.gif │ └── titlebar_end.gif ├── serialized-form.html └── stylesheet.css ├── lib └── objenesis-1.3.jar ├── pom.xml └── src ├── main └── java │ ├── at │ ├── fhooe │ │ └── usmile │ │ │ ├── app │ │ │ └── se_performance │ │ │ │ ├── TestPerformer2Activity.java │ │ │ │ ├── TestPerformerActivity.java │ │ │ │ ├── connection │ │ │ │ └── SEConnection.java │ │ │ │ ├── tests │ │ │ │ ├── AEStest.java │ │ │ │ ├── CryptoTest.java │ │ │ │ ├── ECDHTest.java │ │ │ │ ├── RSA1024Test.java │ │ │ │ ├── RoundTripTest.java │ │ │ │ ├── SHAtest.java │ │ │ │ ├── SimpleEchoTest.java │ │ │ │ └── TrippleDEStest.java │ │ │ │ └── util │ │ │ │ ├── APDU.java │ │ │ │ ├── Converter.java │ │ │ │ └── Operations.java │ │ │ ├── cryptotest │ │ │ └── CryptoTest.java │ │ │ ├── rsa1024 │ │ │ └── RSA1024.java │ │ │ └── simpleecho │ │ │ └── SimpleEcho.java │ └── mroland │ │ ├── jcemulator │ │ └── test │ │ │ ├── AccountManagerTest.java │ │ │ ├── EmulatorPerformanceTest.java │ │ │ ├── EmulatorPerformanceTest2.java │ │ │ ├── EmulatorPerformanceTest2Install.java │ │ │ ├── EmulatorPerformanceTestInstall.java │ │ │ ├── EmulatorSCPTest.java │ │ │ ├── EmulatorSCPTestInstall.java │ │ │ └── MemoryStatusDebugRunner.java │ │ ├── logging │ │ └── Logging.java │ │ ├── objectstaterecovery │ │ ├── ArrayState.java │ │ ├── ClassState.java │ │ ├── FieldState.java │ │ ├── ObjectReferenceState.java │ │ ├── ObjectStateRecoveryReflection.java │ │ ├── PersistentMemory.java │ │ ├── PersistentMemory_Disabled.java │ │ ├── PrimitiveValueState.java │ │ ├── TransientArrayState.java │ │ ├── TransientMemory.java │ │ ├── XmlSchemaPersistentMemory.java │ │ ├── XmlSchemaTransientMemory.java │ │ └── helper │ │ │ ├── IdentityObjectIntMap.java │ │ │ ├── ObjectMap.java │ │ │ └── UniqueObjectIdentifier.java │ │ └── utils │ │ ├── ArrayUtils.java │ │ └── StringUtils.java │ ├── com │ └── licel │ │ └── jcardsim │ │ ├── base │ │ ├── AppletDefinition.java │ │ ├── AppletInstanceHolder.java │ │ ├── CardChannel.java │ │ ├── CardInterface.java │ │ ├── CommandAPDU.java │ │ ├── ISO7816Extended.java │ │ ├── PackageDefinition.java │ │ ├── PackageHolder.java │ │ ├── ResponseAPDU.java │ │ ├── SimulatorConfig.java │ │ ├── SimulatorRuntime.java │ │ ├── SimulatorSystem.java │ │ └── TransactionManager.java │ │ └── crypto │ │ ├── AsymmetricCipherImpl.java │ │ ├── AsymmetricSignatureImpl.java │ │ ├── ByteContainer.java │ │ ├── CRC16.java │ │ ├── CRC32.java │ │ ├── DSAKeyImpl.java │ │ ├── DSAPrivateKeyImpl.java │ │ ├── DSAPublicKeyImpl.java │ │ ├── ECKeyImpl.java │ │ ├── ECPrivateKeyImpl.java │ │ ├── ECPublicKeyImpl.java │ │ ├── KeyAgreementImpl.java │ │ ├── KeyImpl.java │ │ ├── KeyPairImpl.java │ │ ├── KeyWithParameters.java │ │ ├── MessageDigestImpl.java │ │ ├── RSAKeyImpl.java │ │ ├── RSAPrivateCrtKeyImpl.java │ │ ├── RandomDataImpl.java │ │ ├── SymmetricCipherImpl.java │ │ ├── SymmetricKeyImpl.java │ │ └── SymmetricSignatureImpl.java │ ├── java │ └── rmi │ │ ├── Remote.java │ │ └── RemoteException.java │ ├── javacard │ ├── framework │ │ ├── AID.java │ │ ├── APDU.java │ │ ├── APDUException.java │ │ ├── Applet.java │ │ ├── AppletEvent.java │ │ ├── CardException.java │ │ ├── CardRuntimeException.java │ │ ├── ISO7816.java │ │ ├── ISOException.java │ │ ├── JCSystem.java │ │ ├── MultiSelectable.java │ │ ├── OwnerPIN.java │ │ ├── PIN.java │ │ ├── PINException.java │ │ ├── Shareable.java │ │ ├── SystemException.java │ │ ├── TransactionException.java │ │ ├── UserException.java │ │ ├── Util.java │ │ └── __AIDWrapper.java │ └── security │ │ ├── AESKey.java │ │ ├── Checksum.java │ │ ├── CryptoException.java │ │ ├── DESKey.java │ │ ├── DSAKey.java │ │ ├── DSAPrivateKey.java │ │ ├── DSAPublicKey.java │ │ ├── ECKey.java │ │ ├── ECPrivateKey.java │ │ ├── ECPublicKey.java │ │ ├── HMACKey.java │ │ ├── InitializedMessageDigest.java │ │ ├── Key.java │ │ ├── KeyAgreement.java │ │ ├── KeyBuilder.java │ │ ├── KeyPair.java │ │ ├── KoreanSEEDKey.java │ │ ├── MessageDigest.java │ │ ├── PrivateKey.java │ │ ├── PublicKey.java │ │ ├── RSAPrivateCrtKey.java │ │ ├── RSAPrivateKey.java │ │ ├── RSAPublicKey.java │ │ ├── RandomData.java │ │ ├── SecretKey.java │ │ ├── Signature.java │ │ └── SignatureMessageRecovery.java │ └── javacardx │ ├── apdu │ └── ExtendedLength.java │ ├── crypto │ ├── Cipher.java │ └── KeyEncryption.java │ └── framework │ └── math │ ├── BCDUtil.java │ ├── BigNumber.java │ └── ParityBit.java └── test └── java ├── com └── licel │ └── jcardsim │ └── crypto │ ├── AsymmetricCipherImplTest.java │ ├── AsymmetricSignatureImplTest.java │ ├── CRC16Test.java │ ├── CRC32Test.java │ ├── ECKeyImplTest.java │ ├── KeyAgreementImplTest.java │ ├── KeyPairImplTest.java │ ├── MessageDigestImplTest.java │ ├── RSACipherPKCS1Test.java │ ├── RSACipherTest.java │ ├── RSAPrivateCrtKeyImplTest.java │ ├── RandomDataImplTest.java │ ├── SignatureMessageRecoveryTest.java │ ├── SymmetricCipherImplTest.java │ ├── SymmetricKeyImplTest.java │ └── SymmetricSignatureImplTest.java └── javacard └── framework └── UtilTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | The following software included in this product: 2 | Bouncy Castle Crypto APIs 3 | 4 | 5 | Please note: our license is an adaptation of the MIT X11 License and 6 | should be read as such. 7 | 8 | License Copyright (c) 2000 - 2009 The Legion Of The Bouncy Castle 9 | (http://www.bouncycastle.org) 10 | Permission is hereby granted, free of charge, to any person obtaining 11 | a copy of this software and associated documentation files (the 12 | "Software"), to deal in the Software without restriction, including 13 | without limitation the rights to use, copy, modify, merge, publish, 14 | distribute, sublicense, and/or sell copies of the Software, and to 15 | permit persons to whom the Software is furnished to do so, subject to 16 | the following conditions: The above copyright notice and this 17 | permission notice shall be included in all copies or substantial 18 | portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 24 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 25 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 26 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobilesec/secure-element-emulator/d22e1b2c1b1b73c7d64229818cd50d492f1d6d41/README.md -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/app/se_performance/connection/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.app.se_performance.connection (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.app.se_performance.connection

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/app/se_performance/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.app.se_performance (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.app.se_performance

13 |
14 |

Classes

15 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/app/se_performance/tests/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.app.se_performance.tests (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.app.se_performance.tests

13 |
14 |

Classes

15 | 25 |
26 | 27 | 28 | -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/app/se_performance/util/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.app.se_performance.util (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.app.se_performance.util

13 |
14 |

Classes

15 | 20 |

Enums

21 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/cryptotest/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.cryptotest (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.cryptotest

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/rsa1024/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.rsa1024 (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.rsa1024

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javadoc/at/fhooe/usmile/simpleecho/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.fhooe.usmile.simpleecho (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.fhooe.usmile.simpleecho

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javadoc/at/mroland/jcemulator/test/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.mroland.jcemulator.test (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.mroland.jcemulator.test

13 |
14 |

Classes

15 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /javadoc/at/mroland/logging/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.mroland.logging (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.mroland.logging

13 |
14 |

Classes

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javadoc/at/mroland/objectstaterecovery/helper/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.mroland.objectstaterecovery.helper (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.mroland.objectstaterecovery.helper

13 |
14 |

Classes

15 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /javadoc/at/mroland/objectstaterecovery/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.mroland.objectstaterecovery (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.mroland.objectstaterecovery

13 |
14 |

Interfaces

15 | 19 |

Classes

20 | 33 |
34 | 35 | 36 | -------------------------------------------------------------------------------- /javadoc/at/mroland/utils/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | at.mroland.utils (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

at.mroland.utils

13 |
14 |

Classes

15 | 19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /javadoc/com/licel/jcardsim/base/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.licel.jcardsim.base (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

com.licel.jcardsim.base

13 |
14 |

Interfaces

15 | 19 |

Classes

20 | 27 |
28 | 29 | 30 | -------------------------------------------------------------------------------- /javadoc/com/licel/jcardsim/crypto/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | com.licel.jcardsim.crypto (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

com.licel.jcardsim.crypto

13 |
14 |

Interfaces

15 | 18 |

Classes

19 | 42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /javadoc/deprecated-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Deprecated List (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 | 18 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 37 |
38 | 65 | 66 |
67 |

Deprecated API

68 |

Contents

69 |
70 | 71 |
72 | 73 | 74 | 75 | 76 | 86 |
 
87 |
88 | 115 | 116 |

 

117 | 118 | 119 | -------------------------------------------------------------------------------- /javadoc/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | jCardSim-2.2.1-r2-mroland 2.2.2 API 8 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | <noscript> 62 | <div>JavaScript is disabled on your browser.</div> 63 | </noscript> 64 | <h2>Frame Alert</h2> 65 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to <a href="overview-summary.html">Non-frame version</a>.</p> 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /javadoc/java/rmi/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | java.rmi (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

java.rmi

13 |
14 |

Interfaces

15 | 18 |

Exceptions

19 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /javadoc/javacard/framework/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | javacard.framework (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

javacard.framework

13 |
14 |

Interfaces

15 | 22 |

Classes

23 | 32 |

Exceptions

33 | 43 |
44 | 45 | 46 | -------------------------------------------------------------------------------- /javadoc/javacard/security/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | javacard.security (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

javacard.security

13 |
14 |

Interfaces

15 | 35 |

Classes

36 | 46 |

Exceptions

47 | 50 |
51 | 52 | 53 | -------------------------------------------------------------------------------- /javadoc/javacardx/apdu/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | javacardx.apdu (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

javacardx.apdu

13 |
14 |

Interfaces

15 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /javadoc/javacardx/crypto/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | javacardx.crypto (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

javacardx.crypto

13 |
14 |

Interfaces

15 | 18 |

Classes

19 | 22 |
23 | 24 | 25 | -------------------------------------------------------------------------------- /javadoc/javacardx/framework/math/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | javacardx.framework.math (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |

javacardx.framework.math

13 |
14 |

Classes

15 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /javadoc/overview-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Overview List (jCardSim-2.2.1-r2-mroland 2.2.2 API) 8 | 9 | 10 | 11 | 12 |
All Classes
13 |
14 |

Packages

15 | 39 |
40 |

 

41 | 42 | 43 | -------------------------------------------------------------------------------- /javadoc/package-list: -------------------------------------------------------------------------------- 1 | at.fhooe.usmile.app.se_performance 2 | at.fhooe.usmile.app.se_performance.connection 3 | at.fhooe.usmile.app.se_performance.tests 4 | at.fhooe.usmile.app.se_performance.util 5 | at.fhooe.usmile.app.securechannel 6 | at.fhooe.usmile.cryptotest 7 | at.fhooe.usmile.rsa1024 8 | at.fhooe.usmile.securechannel.sc_srp_6a 9 | at.fhooe.usmile.simpleecho 10 | at.mroland.jcemulator.test 11 | at.mroland.logging 12 | at.mroland.objectstaterecovery 13 | at.mroland.objectstaterecovery.helper 14 | at.mroland.utils 15 | com.licel.jcardsim.base 16 | com.licel.jcardsim.crypto 17 | java.rmi 18 | javacard.framework 19 | javacard.security 20 | javacardx.apdu 21 | javacardx.crypto 22 | javacardx.framework.math 23 | -------------------------------------------------------------------------------- /javadoc/resources/background.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobilesec/secure-element-emulator/d22e1b2c1b1b73c7d64229818cd50d492f1d6d41/javadoc/resources/background.gif -------------------------------------------------------------------------------- /javadoc/resources/tab.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobilesec/secure-element-emulator/d22e1b2c1b1b73c7d64229818cd50d492f1d6d41/javadoc/resources/tab.gif -------------------------------------------------------------------------------- /javadoc/resources/titlebar.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobilesec/secure-element-emulator/d22e1b2c1b1b73c7d64229818cd50d492f1d6d41/javadoc/resources/titlebar.gif -------------------------------------------------------------------------------- /javadoc/resources/titlebar_end.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobilesec/secure-element-emulator/d22e1b2c1b1b73c7d64229818cd50d492f1d6d41/javadoc/resources/titlebar_end.gif -------------------------------------------------------------------------------- /lib/objenesis-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mobilesec/secure-element-emulator/d22e1b2c1b1b73c7d64229818cd50d492f1d6d41/lib/objenesis-1.3.jar -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/app/se_performance/TestPerformer2Activity.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.app.se_performance; 2 | 3 | 4 | 5 | import at.fhooe.usmile.app.se_performance.connection.SEConnection; 6 | import at.fhooe.usmile.app.se_performance.tests.CryptoTest; 7 | 8 | /** 9 | * @author Local2013 10 | * 11 | */ 12 | public class TestPerformer2Activity extends TestPerformerActivity { 13 | 14 | final static int REPEAT = 20; 15 | 16 | @Override 17 | public void run() { 18 | cryptoTest = new CryptoTest(this, new SEConnection(null), 0); 19 | 20 | for (int i = 0; i < REPEAT; ++i) { 21 | cryptoTest.performSimpleEchoTest(0, 500); 22 | while (cryptoTest.simpleechoTestRunning()) {} 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/app/se_performance/TestPerformerActivity.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.app.se_performance; 2 | 3 | 4 | 5 | import at.fhooe.usmile.app.se_performance.connection.SEConnection; 6 | import at.fhooe.usmile.app.se_performance.tests.CryptoTest; 7 | import at.mroland.logging.Logging; 8 | 9 | /** 10 | * @author Local2013 11 | * 12 | */ 13 | public class TestPerformerActivity { 14 | 15 | final static int DATALENGTH[] = { 16, 23, 48, 64, 128 }; 16 | final static int DATALENGTH_RSA1024[] = { 16, 23, 48, 64, 87 }; 17 | final static int REPEAT = DATALENGTH.length; 18 | final static int ITERATIONS = 20; 19 | 20 | CryptoTest cryptoTest ; 21 | 22 | public void run() { 23 | cryptoTest = new CryptoTest(this, new SEConnection(null), 0); 24 | 25 | for (int i = 0; i < REPEAT; ++i) { 26 | // cryptoTest.performSimpleEchoTest(0, 1); 27 | // while (cryptoTest.simpleechoTestRunning()) {} 28 | // cryptoTest.performSimpleEchoTest(0, 500); 29 | // while (cryptoTest.simpleechoTestRunning()) {} 30 | 31 | cryptoTest.performAESTest(DATALENGTH[i], ITERATIONS, 128); 32 | while (cryptoTest.aesTestRunning()) {} 33 | cryptoTest.performAESTest(DATALENGTH[i], ITERATIONS, 256); 34 | while (cryptoTest.aesTestRunning()) {} 35 | cryptoTest.performSHAtest(DATALENGTH[i], ITERATIONS); 36 | while (cryptoTest.SHAtestRunning()) {} 37 | cryptoTest.perform3DEStest(DATALENGTH[i], ITERATIONS); 38 | while (cryptoTest.trippleDESTestRunning()) {} 39 | cryptoTest.performECDHTest(ITERATIONS); 40 | while (cryptoTest.ecdhTestRunning()) {} 41 | cryptoTest.performRoundTripTest(DATALENGTH[i], ITERATIONS); 42 | while (cryptoTest.roundtripTestRunning()) {} 43 | // RSA test 44 | cryptoTest.performRSA1024test(DATALENGTH_RSA1024[i], ITERATIONS); 45 | while (cryptoTest.RSA1024TestRunning()) {} 46 | } 47 | } 48 | 49 | public void logText(String msg) { 50 | Logging.info("SEPerformanceTester", msg); 51 | } 52 | 53 | public void logTextSpecial(String msg) { 54 | Logging.info("SEPerformanceTester", msg); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/app/se_performance/connection/SEConnection.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.app.se_performance.connection; 2 | 3 | import at.mroland.logging.Logging; 4 | import at.mroland.utils.ArrayUtils; 5 | import com.licel.jcardsim.base.SimulatorConfig; 6 | import com.licel.jcardsim.base.SimulatorSystem; 7 | 8 | 9 | 10 | public class SEConnection { 11 | 12 | byte[] AID; 13 | 14 | 15 | 16 | long elapsedTime = 0L; 17 | 18 | 19 | public SEConnection(byte[] aid ){ 20 | AID = aid; 21 | if (AID != null) { 22 | selectApplet(AID, 0); 23 | } 24 | } 25 | 26 | public void closeConnection(){ 27 | } 28 | 29 | public final boolean selectApplet(byte[] _aid, int _readerIndex){ 30 | 31 | SimulatorSystem.transceiveAPDU(SimulatorConfig.INTERFACE_INTERNAL_NAME, ArrayUtils.concatenate(new byte[]{ (byte)0x00, (byte)0xA4, (byte)0x04, (byte)0x00, (byte)(_aid.length & 0x0ff) }, _aid )); 32 | return true; 33 | } 34 | 35 | public byte[] sendCommand(byte[] cmdApdu){ 36 | byte[] respApdu = new byte[0]; 37 | 38 | try { 39 | 40 | long commandTime = 0L; 41 | long responseTime = 0L; 42 | commandTime = System.nanoTime(); 43 | respApdu = SimulatorSystem.transceiveAPDU(SimulatorConfig.INTERFACE_INTERNAL_NAME, cmdApdu); 44 | responseTime = System.nanoTime(); 45 | elapsedTime = responseTime - commandTime; 46 | 47 | 48 | } catch (Exception e) { 49 | Logging.error("SEConnection", "Exception: " + e.toString(), e); 50 | } 51 | return respApdu; 52 | } 53 | 54 | public long getElapsedTime(){ 55 | return elapsedTime; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/app/se_performance/util/APDU.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.app.se_performance.util; 2 | 3 | 4 | 5 | public class APDU { 6 | 7 | public static byte[] getCommandApdu(byte CLA, byte INS, byte P1, byte P2, byte[] data, byte Le){ 8 | 9 | byte[] apduByte = null; 10 | if(data.length == 0){ 11 | apduByte = new byte[5]; 12 | }else{ 13 | apduByte = new byte[data.length + 6]; 14 | } 15 | apduByte[0] = CLA; 16 | apduByte[1] = INS; 17 | apduByte[2] = P1; 18 | apduByte[3] = P2; 19 | if(data.length > 0){ 20 | apduByte[4] = (byte) data.length; 21 | System.arraycopy(data, 0, apduByte, 5, data.length); 22 | apduByte[5 + data.length] = Le; 23 | }else{ 24 | apduByte[4] = Le; 25 | } 26 | 27 | 28 | return apduByte; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/app/se_performance/util/Converter.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.app.se_performance.util; 2 | 3 | 4 | 5 | /** 6 | * @author Local2013 7 | * 8 | */ 9 | public class Converter { 10 | public static String byteArrayToHexString(byte[] b) { 11 | StringBuilder sb = new StringBuilder(b.length * 2); 12 | for (int i = 0; i < b.length; i++) { 13 | int v = b[i] & 0xff; 14 | if (v < 16) { 15 | sb.append('0'); 16 | } 17 | 18 | 19 | sb.append(Integer.toHexString(v)); 20 | sb.append(' '); 21 | } 22 | return sb.toString().toUpperCase(); 23 | 24 | 25 | 26 | } 27 | 28 | 29 | 30 | public static byte[] hexStringToByteArray(String s) { 31 | int len = s.length(); 32 | byte[] data = new byte[len / 2]; 33 | for (int i = 0; i < len; i += 2) { 34 | data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4) 35 | + Character.digit(s.charAt(i+1), 16)); 36 | } 37 | return data; 38 | } 39 | 40 | public static byte[] concatArray(byte[] first, byte[]second){ 41 | byte[] result = new byte[first.length + second.length]; 42 | System.arraycopy(first, 0 , result, 0, first.length); 43 | System.arraycopy(second, 0, result, first.length, second.length); 44 | return result; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/app/se_performance/util/Operations.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.app.se_performance.util; 2 | 3 | 4 | 5 | public class Operations { 6 | public static enum OperationType{ 7 | AES128, AES256, SHA128, SHA_256, TRIPLEDES, ECDH192, ROUNDTRIP; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/at/fhooe/usmile/simpleecho/SimpleEcho.java: -------------------------------------------------------------------------------- 1 | package at.fhooe.usmile.simpleecho; 2 | 3 | import javacard.framework.APDU; 4 | import javacard.framework.Applet; 5 | import javacard.framework.ISO7816; 6 | import javacard.framework.ISOException; 7 | 8 | public class SimpleEcho extends Applet { 9 | 10 | final static byte SEND_TEST = 0x51; 11 | final static byte RECIEVE_TEST = 0x52; 12 | final static byte ECHO_TEST = 0x53; 13 | 14 | private static class innerClass { 15 | short field1 = 0; 16 | byte field2 = 1; 17 | } 18 | 19 | private innerClass[] field1; 20 | private short field2; 21 | SimpleEcho field3; 22 | 23 | public SimpleEcho() { 24 | field1 = new innerClass[1000]; 25 | field2 = (short)42; 26 | for (short i = 0; i < (short)field1.length; ++i) { 27 | field1[i] = new innerClass(); 28 | field1[i].field1 = (short)(i * field2); 29 | field1[i].field2 *= i; 30 | } 31 | field2 = (short)42; 32 | field3 = this; 33 | } 34 | 35 | public static void install(byte[] bArray, short bOffset, byte bLength) { 36 | // GP-compliant JavaCard applet registration 37 | 38 | new SimpleEcho().register(); 39 | } 40 | 41 | public void process(APDU apdu) { 42 | field2 += 123; 43 | for (short i = 0; i < (short)field1.length; ++i) { 44 | if ((field2 & 0x001) == (i & 0x001)) { 45 | field1[i] = new innerClass(); 46 | } 47 | field1[i].field1 = (short)(i * field2); 48 | field1[i].field2 *= (i+1); 49 | } 50 | 51 | 52 | // Good practice: Return 9000 on SELECT 53 | if (selectingApplet()) { 54 | return; 55 | } 56 | 57 | byte[] incomingBuf = apdu.getBuffer(); 58 | short len; 59 | switch (incomingBuf[ISO7816.OFFSET_INS]) { 60 | case RECIEVE_TEST: 61 | len = apdu.setOutgoing(); 62 | apdu.setOutgoingLength(len); 63 | apdu.sendBytes((short) 0, len); 64 | break; 65 | case SEND_TEST: 66 | apdu.setIncomingAndReceive(); 67 | apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, (short) 0); 68 | break; 69 | case ECHO_TEST: 70 | len = apdu.setIncomingAndReceive(); 71 | apdu.setOutgoingAndSend(ISO7816.OFFSET_CDATA, len); 72 | break; 73 | default: 74 | // good practice: If you don't know the INStruction, say so: 75 | ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED); 76 | } 77 | 78 | } 79 | } -------------------------------------------------------------------------------- /src/main/java/at/mroland/jcemulator/test/EmulatorPerformanceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package at.mroland.jcemulator.test; 17 | 18 | import at.fhooe.usmile.app.se_performance.TestPerformerActivity; 19 | import at.mroland.logging.Logging; 20 | import at.mroland.objectstaterecovery.PersistentMemory; 21 | import at.mroland.objectstaterecovery.TransientMemory; 22 | import com.licel.jcardsim.base.SimulatorSystem; 23 | import java.io.File; 24 | 25 | 26 | /** 27 | * @author mroland 28 | */ 29 | public class EmulatorPerformanceTest { 30 | private final static boolean DEBUG = false; 31 | 32 | static { 33 | Logging.DEBUG = DEBUG; 34 | } 35 | 36 | private final static File CONFIG_PATH = new File("."); 37 | 38 | public static void main(String args[]) { 39 | Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 40 | public void run() { 41 | cleanup(); 42 | } 43 | })); 44 | 45 | startup(); 46 | 47 | TestPerformerActivity testPerformer = new TestPerformerActivity(); 48 | testPerformer.run(); 49 | 50 | boolean run = true; 51 | // PersistentMemory pm = SimulatorSystem.getPersistentMemoryInstance(); 52 | // TransientMemory tm = SimulatorSystem.getTransientMemoryInstance(); 53 | while (run) { 54 | try { 55 | Thread.sleep(100); 56 | run = System.in.read() == -1; 57 | } catch (Exception e) { 58 | } 59 | } 60 | 61 | System.exit(0); 62 | } 63 | 64 | 65 | private static void startup() { 66 | MemoryStatusDebugRunner.start(); 67 | Logging.info("EmulatorPerformenceTest", "Start loading from persistent storage."); 68 | SimulatorSystem.loadFromPersistentStorage(CONFIG_PATH); 69 | Logging.info("EmulatorPerformenceTest", "End loading from persistent storage."); 70 | } 71 | 72 | private static void cleanup() { 73 | Logging.info("EmulatorPerformenceTest", "Start saving to persistent storage."); 74 | SimulatorSystem.saveToPersistentStorage(CONFIG_PATH); 75 | Logging.info("EmulatorPerformenceTest", "End saving to persistent storage."); 76 | MemoryStatusDebugRunner.stop(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/jcemulator/test/EmulatorPerformanceTest2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package at.mroland.jcemulator.test; 17 | 18 | import at.fhooe.usmile.app.se_performance.TestPerformer2Activity; 19 | import at.mroland.logging.Logging; 20 | import at.mroland.objectstaterecovery.PersistentMemory; 21 | import at.mroland.objectstaterecovery.TransientMemory; 22 | import com.licel.jcardsim.base.AppletDefinition; 23 | import com.licel.jcardsim.base.PackageDefinition; 24 | import com.licel.jcardsim.base.SimulatorSystem; 25 | import java.io.File; 26 | import javacard.framework.__AIDWrapper; 27 | 28 | 29 | /** 30 | * @author mroland 31 | */ 32 | public class EmulatorPerformanceTest2 { 33 | private final static boolean DEBUG = false; 34 | 35 | static { 36 | Logging.DEBUG = DEBUG; 37 | } 38 | 39 | private final static File CONFIG_PATH = new File("."); 40 | 41 | public static void main(String args[]) { 42 | Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 43 | public void run() { 44 | cleanup(); 45 | } 46 | })); 47 | 48 | startup(); 49 | 50 | TestPerformer2Activity testPerformer = new TestPerformer2Activity(); 51 | testPerformer.run(); 52 | 53 | boolean run = true; 54 | // PersistentMemory pm = SimulatorSystem.getPersistentMemoryInstance(); 55 | // TransientMemory tm = SimulatorSystem.getTransientMemoryInstance(); 56 | while (run) { 57 | try { 58 | Thread.sleep(100); 59 | run = System.in.read() == -1; 60 | } catch (Exception e) { 61 | } 62 | } 63 | 64 | System.exit(0); 65 | } 66 | 67 | 68 | private static void startup() { 69 | MemoryStatusDebugRunner.start(); 70 | Logging.info("EmulatorPerformenceTest", "Start loading from persistent storage."); 71 | SimulatorSystem.loadFromPersistentStorage(CONFIG_PATH); 72 | Logging.info("EmulatorPerformenceTest", "End loading from persistent storage."); 73 | } 74 | 75 | private static void cleanup() { 76 | Logging.info("EmulatorPerformenceTest", "Start saving to persistent storage."); 77 | SimulatorSystem.saveToPersistentStorage(CONFIG_PATH); 78 | Logging.info("EmulatorPerformenceTest", "End saving to persistent storage."); 79 | MemoryStatusDebugRunner.stop(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/jcemulator/test/EmulatorPerformanceTest2Install.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package at.mroland.jcemulator.test; 17 | 18 | import at.fhooe.usmile.app.se_performance.TestPerformer2Activity; 19 | import at.mroland.logging.Logging; 20 | import at.mroland.objectstaterecovery.PersistentMemory; 21 | import at.mroland.objectstaterecovery.TransientMemory; 22 | import com.licel.jcardsim.base.AppletDefinition; 23 | import com.licel.jcardsim.base.PackageDefinition; 24 | import com.licel.jcardsim.base.SimulatorSystem; 25 | import java.io.File; 26 | import javacard.framework.__AIDWrapper; 27 | 28 | 29 | /** 30 | * @author mroland 31 | */ 32 | public class EmulatorPerformanceTest2Install { 33 | private final static boolean DEBUG = false; 34 | 35 | static { 36 | Logging.DEBUG = DEBUG; 37 | } 38 | 39 | private final static File CONFIG_PATH = new File("."); 40 | 41 | public static void main(String args[]) { 42 | Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 43 | public void run() { 44 | cleanup(); 45 | } 46 | })); 47 | 48 | startup(); 49 | 50 | ////////////////////////////////////////////////////////////////////////////////////////////////////// 51 | // install applets 52 | ////////////////////////////////////////////////////////////////////////////////////////////////////// 53 | // CryptoTest 54 | PackageDefinition pkg2 = new PackageDefinition( 55 | "0102030405020000", 56 | new AppletDefinition[] { 57 | new AppletDefinition("0102030405020001", at.fhooe.usmile.simpleecho.SimpleEcho.class), 58 | }, 59 | new Class[] { 60 | }); 61 | SimulatorSystem.installForLoad(pkg2); 62 | byte[] appletData2 = null; 63 | SimulatorSystem.installForInstall(pkg2.APPLETS[0].APPLET_AID, __AIDWrapper.getAIDBytes(pkg2.APPLETS[0].APPLET_AID), null, appletData2); 64 | SimulatorSystem.installForMakeSelectable(pkg2.APPLETS[0].APPLET_AID, true); 65 | ////////////////////////////////////////////////////////////////////////////////////////////////////// 66 | 67 | TestPerformer2Activity testPerformer = new TestPerformer2Activity(); 68 | testPerformer.run(); 69 | 70 | // boolean run = true; 71 | //// PersistentMemory pm = SimulatorSystem.getPersistentMemoryInstance(); 72 | //// TransientMemory tm = SimulatorSystem.getTransientMemoryInstance(); 73 | // while (run) { 74 | // try { 75 | // Thread.sleep(100); 76 | // run = System.in.read() == -1; 77 | // } catch (Exception e) { 78 | // } 79 | // } 80 | 81 | System.exit(0); 82 | } 83 | 84 | 85 | private static void startup() { 86 | MemoryStatusDebugRunner.start(); 87 | Logging.info("EmulatorPerformenceTest", "Start loading from persistent storage."); 88 | SimulatorSystem.loadFromPersistentStorage(CONFIG_PATH); 89 | Logging.info("EmulatorPerformenceTest", "End loading from persistent storage."); 90 | } 91 | 92 | private static void cleanup() { 93 | Logging.info("EmulatorPerformenceTest", "Start saving to persistent storage."); 94 | SimulatorSystem.saveToPersistentStorage(CONFIG_PATH); 95 | Logging.info("EmulatorPerformenceTest", "End saving to persistent storage."); 96 | MemoryStatusDebugRunner.stop(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/jcemulator/test/EmulatorSCPTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package at.mroland.jcemulator.test; 17 | 18 | import at.fhooe.usmile.app.securechannel.SecureChannelTesterActivity; 19 | import at.mroland.logging.Logging; 20 | import at.mroland.objectstaterecovery.PersistentMemory; 21 | import at.mroland.objectstaterecovery.TransientMemory; 22 | import com.licel.jcardsim.base.SimulatorSystem; 23 | import java.io.File; 24 | 25 | 26 | /** 27 | * @author mroland 28 | */ 29 | public class EmulatorSCPTest { 30 | private final static boolean DEBUG = false; 31 | 32 | static { 33 | Logging.DEBUG = DEBUG; 34 | } 35 | 36 | private final static File CONFIG_PATH = new File("."); 37 | 38 | public static void main(String args[]) { 39 | Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { 40 | public void run() { 41 | cleanup(); 42 | } 43 | })); 44 | 45 | startup(); 46 | 47 | SecureChannelTesterActivity secureChannelTester = new SecureChannelTesterActivity(); 48 | secureChannelTester.run(); 49 | 50 | boolean run = true; 51 | // PersistentMemory pm = SimulatorSystem.getPersistentMemoryInstance(); 52 | // TransientMemory tm = SimulatorSystem.getTransientMemoryInstance(); 53 | while (run) { 54 | try { 55 | Thread.sleep(100); 56 | run = System.in.read() == -1; 57 | } catch (Exception e) { 58 | } 59 | } 60 | 61 | System.exit(0); 62 | } 63 | 64 | 65 | private static void startup() { 66 | MemoryStatusDebugRunner.start(); 67 | SimulatorSystem.loadFromPersistentStorage(CONFIG_PATH); 68 | } 69 | 70 | private static void cleanup() { 71 | SimulatorSystem.saveToPersistentStorage(CONFIG_PATH); 72 | MemoryStatusDebugRunner.stop(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/objectstaterecovery/XmlSchemaPersistentMemory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package at.mroland.objectstaterecovery; 17 | 18 | /** 19 | * 20 | * @author mroland 21 | */ 22 | public interface XmlSchemaPersistentMemory { 23 | public static final String URI = "http://mroland.at/xml/persistentmemory"; 24 | 25 | public static final String TAG_ROOT = "PersistentMemory"; 26 | 27 | // general attributes 28 | public static final String ATTRIBUTE_HASH_CODE = "hashCode"; 29 | public static final String ATTRIBUTE_NAME = "name"; 30 | public static final String ATTRIBUTE_TYPE = "type"; 31 | 32 | // FieldStates 33 | public static final String TAG_REFERENCES = "References"; 34 | public static final String TAG_FIELDSTATE_OBJECT = "ObjectReferenceState"; 35 | public static final String TAG_FIELDSTATE_ARRAY = "ArrayState"; 36 | public static final String TAG_FIELDSTATE_TRANSIENT_ARRAY = "TransientArrayState"; 37 | public static final String TAG_FIELDSTATE_PRIMITIVE = "PrimitiveValueState"; 38 | 39 | // Class bound to FieldState 40 | public static final String TAG_BOUNDCLASS = "BoundClass"; 41 | 42 | // PrimitiveValue 43 | public static final String TAG_PRIMITIVE_VALUE = "Value"; 44 | 45 | // PrimitiveValue attributes 46 | public static final String ATTRIBUTE_PRIMITIVE_VALUE_TYPE = "primitiveType"; 47 | 48 | // Array 49 | public static final String TAG_ARRAY_ELEMENT = "Element"; 50 | 51 | // Array attributes 52 | public static final String ATTRIBUTE_ARRAY_ELEMENT_TYPE = "elementType"; 53 | 54 | // Object 55 | public static final String TAG_OBJECT_FIELD = "Field"; 56 | 57 | // ClassState 58 | public static final String TAG_CLASSES = "Classes"; 59 | public static final String TAG_CLASSSTATE_CLASS = "ClassState"; 60 | 61 | // NamedInstances 62 | public static final String TAG_NAMED_INSTANCES = "NamedInstances"; 63 | public static final String TAG_NAMED_INSTANCE = "NamedInstance"; 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/objectstaterecovery/XmlSchemaTransientMemory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package at.mroland.objectstaterecovery; 17 | 18 | /** 19 | * 20 | * @author mroland 21 | */ 22 | public interface XmlSchemaTransientMemory { 23 | public static final String URI = "http://mroland.at/xml/transientmemory"; 24 | 25 | public static final String TAG_ROOT = "TransientMemory"; 26 | 27 | // general attributes 28 | public static final String ATTRIBUTE_AID = "aid"; 29 | public static final String ATTRIBUTE_HASH_CODE = "hashCode"; 30 | 31 | // Segments 32 | public static final String TAG_SEGMENT_CLEARONDESELECT = "ClearOnDeselect"; 33 | public static final String TAG_SEGMENT_CLEARONRESET = "ClearOnReset"; 34 | 35 | // Reference 36 | public static final String TAG_REFERENCE = "Reference"; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/utils/ArrayUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version $Id: ArrayUtils.java 123 2011-04-30 08:02:44Z mroland $ 3 | * 4 | * @author Michael Roland 5 | * 6 | * Copyright (c) 2009-2011 Michael Roland 7 | * 8 | * ALL RIGHTS RESERVED. 9 | */ 10 | 11 | package at.mroland.utils; 12 | 13 | import java.util.ArrayList; 14 | 15 | /** 16 | * Utilities for arrays. 17 | */ 18 | public class ArrayUtils { 19 | private ArrayUtils() {} 20 | 21 | public static byte[] toByteArray (ArrayList ... list) { 22 | int len = 0; 23 | for (ArrayList l : list) { 24 | if (l != null) { 25 | len += l.size(); 26 | } 27 | } 28 | 29 | byte[] result = new byte[len]; 30 | 31 | int index = 0; 32 | for (ArrayList l : list) { 33 | if (l != null) { 34 | for (Byte b : l) { 35 | result[index++] = b.byteValue(); 36 | } 37 | } 38 | } 39 | return result; 40 | } 41 | 42 | public static byte[] toByteArray (ArrayList list) { 43 | int len = 0; 44 | for (byte[] array : list) { 45 | if (array != null) { 46 | len += array.length; 47 | } 48 | } 49 | 50 | byte[] result = new byte[len]; 51 | 52 | int index = 0; 53 | for (byte[] array : list) { 54 | if (array != null) { 55 | java.lang.System.arraycopy(array, 0, result, index, array.length); 56 | index += array.length; 57 | } 58 | } 59 | return result; 60 | } 61 | 62 | public static ArrayList concatenate (ArrayList ... list) { 63 | ArrayList result = new ArrayList(); 64 | for (ArrayList l : list) { 65 | if (l != null) { 66 | result.addAll(l); 67 | } 68 | } 69 | return result; 70 | } 71 | 72 | public static byte[] concatenate (byte[] ... array) { 73 | int len = 0; 74 | for (byte[] a : array) { 75 | if (a != null) { 76 | len += a.length; 77 | } 78 | } 79 | 80 | byte[] result = new byte[len]; 81 | 82 | int index = 0; 83 | for (byte[] a : array) { 84 | if (a != null) { 85 | java.lang.System.arraycopy(a, 0, result, index, a.length); 86 | index += a.length; 87 | } 88 | } 89 | 90 | return result; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/at/mroland/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | /** 2 | * @version $Id: StringUtils.java 218 2012-04-25 16:19:29Z mroland $ 3 | * 4 | * @author Michael Roland 5 | * 6 | * Copyright (c) 2009-2012 Michael Roland 7 | * 8 | * ALL RIGHTS RESERVED. 9 | */ 10 | 11 | package at.mroland.utils; 12 | 13 | import java.nio.charset.Charset; 14 | 15 | /** 16 | * Utilities for conversions between byte-arrays and strings. 17 | */ 18 | public class StringUtils { 19 | private StringUtils() {} 20 | 21 | public static String convertByteArrayToHexString (byte[] b) { 22 | if (b != null) { 23 | StringBuilder s = new StringBuilder(2 * b.length); 24 | 25 | for (int i = 0; i < b.length; ++i) { 26 | final String t = Integer.toHexString(b[i]); 27 | final int l = t.length(); 28 | if (l > 2) { 29 | s.append(t.substring(l - 2)); 30 | } else { 31 | if (l == 1) { 32 | s.append("0"); 33 | } 34 | s.append(t); 35 | } 36 | } 37 | 38 | return s.toString(); 39 | } else { 40 | return ""; 41 | } 42 | } 43 | 44 | public static String convertByteArrayToReverseHexString (byte[] b) { 45 | if (b != null) { 46 | StringBuilder s = new StringBuilder(2 * b.length); 47 | 48 | for (int i = (b.length - 1); i >= 0; --i) { 49 | final String t = Integer.toHexString(b[i]); 50 | final int l = t.length(); 51 | if (l > 2) { 52 | s.append(t.substring(l - 2)); 53 | } else { 54 | if (l == 1) { 55 | s.append("0"); 56 | } 57 | s.append(t); 58 | } 59 | } 60 | 61 | return s.toString(); 62 | } else { 63 | return ""; 64 | } 65 | } 66 | 67 | public static String convertByteArrayToASCIIString (byte[] b) { 68 | String s = ""; 69 | 70 | try { 71 | s = new String(b, Charset.forName("US-ASCII")); 72 | } catch (Exception e) {} 73 | 74 | return s; 75 | } 76 | 77 | public static byte[] convertASCIIStringToByteArray (String s) { 78 | byte[] b = new byte[0]; 79 | 80 | try { 81 | b = s.getBytes(Charset.forName("US-ASCII")); 82 | } catch (Exception e) {} 83 | 84 | return b; 85 | } 86 | 87 | public static String convertByteArrayToUTF8String (byte[] b) { 88 | String s = ""; 89 | 90 | try { 91 | s = new String(b, Charset.forName("UTF-8")); 92 | } catch (Exception e) {} 93 | 94 | return s; 95 | } 96 | 97 | public static byte[] convertUTF8StringToByteArray (String s) { 98 | byte[] b = new byte[0]; 99 | 100 | try { 101 | b = s.getBytes(Charset.forName("UTF-8")); 102 | } catch (Exception e) {} 103 | 104 | return b; 105 | } 106 | 107 | public static String convertByteArrayToUTF16String (byte[] b) { 108 | String s = ""; 109 | 110 | try { 111 | s = new String(b, Charset.forName("UTF-16")); 112 | } catch (Exception e) {} 113 | 114 | return s; 115 | } 116 | 117 | public static byte[] convertUTF16StringToByteArray (String s) { 118 | byte[] b = new byte[0]; 119 | 120 | try { 121 | b = s.getBytes(Charset.forName("UTF-16")); 122 | } catch (Exception e) {} 123 | 124 | return b; 125 | } 126 | 127 | public static byte[] convertHexStringToByteArray (String s) { 128 | s = s.replace(" 0x", ""); 129 | s = s.replace(":0x", ""); 130 | s = s.replace(" ", ""); 131 | s = s.replace(":", ""); 132 | final int len = s.length(); 133 | final int rem = len % 2; 134 | 135 | byte[] ret = new byte[len / 2 + rem]; 136 | 137 | if (rem != 0) { 138 | try { 139 | ret[0] = (byte)(Integer.parseInt(s.substring(0, 1), 16) & 0x00F); 140 | } catch (Exception e) { 141 | ret[0] = 0; 142 | } 143 | } 144 | 145 | for (int i = rem; i < len; i += 2) { 146 | try { 147 | ret[i / 2 + rem] = (byte)(Integer.parseInt(s.substring(i, i + 2), 16) & 0x0FF); 148 | } catch (Exception e) { 149 | ret[i / 2 + rem] = 0; 150 | } 151 | } 152 | 153 | return ret; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/base/AppletDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.base; 17 | 18 | import at.mroland.utils.StringUtils; 19 | import javacard.framework.AID; 20 | 21 | /** 22 | * Java Card applet class definition. 23 | */ 24 | public class AppletDefinition { 25 | /** 26 | * Applet class AID. 27 | */ 28 | public final AID APPLET_AID; 29 | 30 | /** 31 | * Applet class. 32 | */ 33 | public final Class APPLET_CLASS; 34 | 35 | /** 36 | * 37 | * @param aidApplet 38 | * @param classApplet 39 | */ 40 | public AppletDefinition(byte[] aidApplet, Class classApplet) { 41 | APPLET_AID = new AID(aidApplet, (short)0, (byte)aidApplet.length); 42 | APPLET_CLASS = classApplet; 43 | } 44 | 45 | /** 46 | * 47 | * @param aidApplet 48 | * @param classApplet 49 | */ 50 | public AppletDefinition(String aidApplet, Class classApplet) { 51 | byte[] aidAppletBytes = StringUtils.convertHexStringToByteArray(aidApplet); 52 | APPLET_AID = new AID(aidAppletBytes, (short)0, (byte)aidAppletBytes.length); 53 | APPLET_CLASS = classApplet; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/base/CardChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.base; 17 | 18 | /** 19 | * Internal class for handling state of logical channels. 20 | */ 21 | class CardChannel { 22 | 23 | /** 24 | * 25 | */ 26 | public final static byte BASIC_CHANNEL = 0; 27 | 28 | /** 29 | * 30 | */ 31 | private boolean channelIsOpen; 32 | /** 33 | * 34 | */ 35 | private AppletInstanceHolder defaultSelectedApplet; 36 | /** 37 | * 38 | */ 39 | private AppletInstanceHolder currentSelectedApplet; 40 | /** 41 | * 42 | */ 43 | private AppletInstanceHolder previousSelectedApplet; 44 | 45 | /** 46 | * 47 | */ 48 | CardChannel() { 49 | channelIsOpen = false; 50 | } 51 | 52 | /** 53 | * 54 | * @param applet 55 | */ 56 | void setDefaultApplet(AppletInstanceHolder applet) { 57 | defaultSelectedApplet = applet; 58 | } 59 | 60 | /** 61 | * 62 | * @return 63 | */ 64 | AppletInstanceHolder getDefaultApplet() { 65 | return defaultSelectedApplet; 66 | } 67 | 68 | /** 69 | * 70 | * @return 71 | */ 72 | AppletInstanceHolder getCurrentSelectedApplet() { 73 | return currentSelectedApplet; 74 | } 75 | 76 | /** 77 | * 78 | * @return 79 | */ 80 | AppletInstanceHolder getPreviousSelectedApplet() { 81 | return previousSelectedApplet; 82 | } 83 | 84 | /** 85 | * 86 | * @return 87 | */ 88 | boolean isOpen() { 89 | return channelIsOpen; 90 | } 91 | 92 | /** 93 | * 94 | */ 95 | void open() { 96 | channelIsOpen = true; 97 | previousSelectedApplet = null; 98 | currentSelectedApplet = null; 99 | } 100 | 101 | /** 102 | * 103 | * @param applet 104 | */ 105 | void select(AppletInstanceHolder applet) { 106 | previousSelectedApplet = currentSelectedApplet; 107 | currentSelectedApplet = applet; 108 | } 109 | 110 | /** 111 | * 112 | */ 113 | void close() { 114 | channelIsOpen = false; 115 | previousSelectedApplet = null; 116 | currentSelectedApplet = null; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/base/ISO7816Extended.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.base; 17 | 18 | /** 19 | * ISO7816Extended encapsulates constants related to ISO 7816-3 and 20 | * ISO 7816-4 beyond javacard.framework.ISO7816. 21 | */ 22 | public interface ISO7816Extended { 23 | /** 24 | * APDU command INS: MANAGE_CHANNNEL = 0x70 25 | */ 26 | public static final byte INS_MANAGE_CHANNEL = (byte)0x70; 27 | 28 | /** 29 | * APDU command P1: SELECT by DF name = 0x04 30 | */ 31 | public static final byte P1_SELECT_BY_DF_NAME = (byte)0x04; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/base/PackageDefinition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.base; 17 | 18 | import at.mroland.utils.StringUtils; 19 | import javacard.framework.AID; 20 | 21 | /** 22 | * Java Card package definition. 23 | */ 24 | public class PackageDefinition { 25 | /** 26 | * Package AID. 27 | */ 28 | public final AID PACKAGE_AID; 29 | 30 | /** 31 | * Applets contained in this package. 32 | */ 33 | public final AppletDefinition[] APPLETS; 34 | 35 | /** 36 | * Classes contained in this package. 37 | */ 38 | public final Class[] CLASSES; 39 | 40 | /** 41 | * 42 | * @param aidPackage 43 | * @param applets 44 | * @param classes 45 | */ 46 | public PackageDefinition(byte[] aidPackage, AppletDefinition[] applets, Class[] classes) { 47 | PACKAGE_AID = new AID(aidPackage, (short)0, (byte)aidPackage.length); 48 | APPLETS = applets; 49 | CLASSES = classes; 50 | } 51 | 52 | /** 53 | * 54 | * @param aidPackage 55 | * @param applets 56 | * @param classes 57 | */ 58 | public PackageDefinition(String aidPackage, AppletDefinition[] applets, Class[] classes) { 59 | byte[] aidPackageBytes = StringUtils.convertHexStringToByteArray(aidPackage); 60 | PACKAGE_AID = new AID(aidPackageBytes, (short)0, (byte)aidPackageBytes.length); 61 | APPLETS = applets; 62 | CLASSES = classes; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/base/ResponseAPDU.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.base; 17 | 18 | import java.util.Arrays; 19 | import javacard.framework.Util; 20 | 21 | /** 22 | * Internal class to parse command APDUs. 23 | */ 24 | class ResponseAPDU { 25 | private final byte[] responseAPDU; 26 | private final short statusWord; 27 | 28 | ResponseAPDU(byte[] responseData, int responseBufferSize, short statusWord) { 29 | this.statusWord = statusWord; 30 | if (responseData == null) { 31 | responseAPDU = new byte[2]; 32 | Util.setShort(responseAPDU, (short)0, statusWord); 33 | } else { 34 | if (responseBufferSize > responseData.length) responseBufferSize = responseData.length; 35 | responseAPDU = new byte[2 + responseBufferSize]; 36 | Util.arrayCopyNonAtomic(responseData, (short)0, responseAPDU, (short)0, (short)responseBufferSize); 37 | Util.setShort(responseAPDU, (short)responseBufferSize, statusWord); 38 | } 39 | } 40 | 41 | byte[] toBytes() { 42 | return responseAPDU; 43 | } 44 | 45 | short getSW() { 46 | return statusWord; 47 | } 48 | 49 | byte[] getData() { 50 | return Arrays.copyOf(responseAPDU, responseAPDU.length - 2); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/base/SimulatorConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.base; 17 | 18 | import javacard.framework.APDU; 19 | import javacard.framework.JCSystem; 20 | 21 | /** 22 | * Configuration options for SimulatorSystem 23 | * @see JCSystem 24 | */ 25 | public interface SimulatorConfig { 26 | 27 | /** 28 | * Java Card API version. 29 | */ 30 | public static final short API_VERSION = 0x0202; 31 | /** 32 | * APDU Buffer size. 33 | */ 34 | public static final short APDU_BUFFER_SIZE = 262; 35 | //public static final short APDU_BUFFER_SIZE = 32768; 36 | /** 37 | * Information field size IFD to ICC for T=1. 38 | */ 39 | public static final short IFSD_T1 = 254; 40 | /** 41 | * Information field size ICC to IFD for T=1. 42 | */ 43 | public static final short IFSC_T1 = 254; 44 | /** 45 | * Information field size IFD to ICC for T=CL. 46 | */ 47 | public static final short IFSD_TCL = 256; 48 | /** 49 | * Information field size ICC to IFD for T=CL. 50 | */ 51 | public static final short IFSC_TCL = 256; 52 | /** 53 | * Indicate object deletion support by not throwing an exception upon JCSystem.requestObjectDeletion(). 54 | */ 55 | public static final boolean OBJECT_DELETION_SUPPORT = true; 56 | /** 57 | * Maximum number of logical channels. 58 | */ 59 | public static final byte MAX_LOGICAL_CHANNELS = 20; 60 | /** 61 | * Support for extended-length APDUs. 62 | */ 63 | public static final boolean EXTENDED_LENGTH_SUPPORT = true; 64 | /** 65 | * Maximum size of extended length APDUs. 66 | */ 67 | public static final int EXTENDED_LENGTH_MAXIMUM = 32767; 68 | /** 69 | * Interface name of internal interface. 70 | */ 71 | public static final String INTERFACE_INTERNAL_NAME = "internal"; 72 | /** 73 | * Interface protocol of internal interface. 74 | */ 75 | public static final byte INTERFACE_INTERNAL_PROTOCOL = (byte)(APDU.PROTOCOL_T1 | APDU.PROTOCOL_MEDIA_DEFAULT); 76 | /** 77 | * Interface name of software card emulation interface. 78 | */ 79 | public static final String INTERFACE_EXTERNAL_NAME = "external"; 80 | /** 81 | * Interface protocol of software card emulation interface. 82 | */ 83 | public static final byte INTERFACE_EXTERNAL_PROTOCOL = (byte)(APDU.PROTOCOL_T1 | APDU.PROTOCOL_MEDIA_CONTACTLESS_TYPE_A); 84 | /** 85 | * Interface configuration. 86 | */ 87 | public static final CardInterface.InterfaceConfig[] INTERFACES = new CardInterface.InterfaceConfig[] { 88 | new CardInterface.InterfaceConfig(INTERFACE_INTERNAL_NAME, INTERFACE_INTERNAL_PROTOCOL, MAX_LOGICAL_CHANNELS), 89 | new CardInterface.InterfaceConfig(INTERFACE_EXTERNAL_NAME, INTERFACE_EXTERNAL_PROTOCOL, MAX_LOGICAL_CHANNELS), 90 | }; 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/CRC16.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.framework.Util; 20 | import javacard.security.Checksum; 21 | import javacard.security.CryptoException; 22 | 23 | /* 24 | * Implementation Checksum 25 | * ISO/IEC 3309 compliant 16 bit CRC algorithm. 26 | * on BouncyCastle CryptoAPI 27 | * @see Checksum 28 | */ 29 | public class CRC16 extends Checksum { 30 | 31 | static final byte LENGTH = 2; 32 | private byte crc16[]; 33 | 34 | public CRC16() { 35 | crc16 = JCSystem.makeTransientByteArray(LENGTH, JCSystem.CLEAR_ON_DESELECT); 36 | } 37 | 38 | public byte getAlgorithm() { 39 | return ALG_ISO3309_CRC16; 40 | } 41 | 42 | public void init(byte bArray[], short bOff, short bLen) 43 | throws CryptoException { 44 | if (bLen != LENGTH) { 45 | CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); 46 | } 47 | Util.arrayCopyNonAtomic(bArray, bOff, crc16, (short) 0, bLen); 48 | } 49 | 50 | public short doFinal(byte inBuff[], short inOffset, short inLength, byte outBuff[], short outOffset) { 51 | update(inBuff, inOffset, inLength); 52 | short temp = Util.getShort(crc16, (short) 0); 53 | temp = (short) (~temp); 54 | Util.setShort(crc16, (short) 0, temp); 55 | Util.arrayCopy(crc16, (short) 0, outBuff, outOffset, (short) 2); 56 | Util.arrayFillNonAtomic(crc16, (short) 0, (short) LENGTH, (byte) 0); 57 | return LENGTH; 58 | } 59 | 60 | public void update(byte inBuff[], short inOffset, short inLength) { 61 | crc16(inBuff, inOffset, inLength); 62 | } 63 | 64 | void crc16(byte inBuf[], short inOff, short inLen) { 65 | short fcs = Util.getShort(crc16, (short) 0); 66 | for (short i = inOff; i < (short) (inOff + inLen); i++) { 67 | short d = (short) (inBuf[i] << 8); 68 | for (short k = 0; k < 8; k++) { 69 | if ((short) ((fcs ^ d) & 0x8000) != 0) { 70 | fcs = (short) ((short) (fcs << 1) ^ 0x1021); 71 | } else { 72 | fcs <<= 1; 73 | } 74 | d <<= 1; 75 | } 76 | 77 | } 78 | Util.setShort(crc16, (short) 0, fcs); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/CRC32.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.framework.Util; 20 | import javacard.security.Checksum; 21 | import javacard.security.CryptoException; 22 | 23 | /* 24 | * Implementation Checksum 25 | * ISO/IEC 3309 compliant 32 bit CRC algorithm. 26 | * on BouncyCastle CryptoAPI 27 | * @see Checksum 28 | */ 29 | public class CRC32 extends Checksum { 30 | 31 | final static byte LENGTH = 4; 32 | private byte crc32[]; 33 | private final byte polynom[] = { 34 | 4, -63, 29, -73 35 | }; 36 | 37 | public CRC32() { 38 | crc32 = JCSystem.makeTransientByteArray(LENGTH, JCSystem.CLEAR_ON_DESELECT); 39 | } 40 | 41 | public byte getAlgorithm() { 42 | return ALG_ISO3309_CRC32; 43 | } 44 | 45 | public void init(byte bArray[], short bOff, short bLen) 46 | throws CryptoException { 47 | if (bLen != LENGTH) { 48 | CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); 49 | } 50 | Util.arrayCopyNonAtomic(bArray, bOff, crc32, (short) 0, bLen); 51 | } 52 | 53 | public short doFinal(byte inBuff[], short inOffset, short inLength, byte outBuff[], short outOffset) { 54 | update(inBuff, inOffset, inLength); 55 | for (short i = 0; i < 4; i++) { 56 | crc32[i] ^= 0xff; 57 | } 58 | 59 | Util.arrayCopy(crc32, (short) 0, outBuff, outOffset, (short) 4); 60 | Util.arrayFillNonAtomic(crc32, (short) 0, LENGTH, (byte) 0); 61 | return LENGTH; 62 | } 63 | 64 | public void update(byte inBuff[], short inOffset, short inLength) { 65 | crc32(inBuff, inOffset, inLength); 66 | } 67 | 68 | private void crc32(byte inBuf[], short inOff, short inLen) { 69 | short fcs_h = Util.getShort(crc32, (short) 0); 70 | short fcs_l = Util.getShort(crc32, (short) 2); 71 | short poly_h = Util.getShort(polynom, (short) 0); 72 | short poly_l = Util.getShort(polynom, (short) 2); 73 | byte carry = 0; 74 | for (short i = inOff; i < (short) (inOff + inLen); i++) { 75 | short d_h = (short) (inBuf[i] << 8); 76 | for (short k = 0; k < 8; k++) { 77 | if (((fcs_h ^ d_h) & 0x8000) != 0) { 78 | carry = 0; 79 | short lfcs_h = shift(fcs_h); 80 | if ((fcs_l & 0x8000) != 0) { 81 | carry = 1; 82 | } 83 | short lfcs_l = shift(fcs_l); 84 | if (carry == 1) { 85 | lfcs_h++; 86 | } 87 | fcs_h = (short) (lfcs_h ^ poly_h); 88 | fcs_l = (short) (lfcs_l ^ poly_l); 89 | } else { 90 | carry = 0; 91 | short lfcs_h = shift(fcs_h); 92 | if ((fcs_l & 0x8000) != 0) { 93 | carry = 1; 94 | } 95 | short lfcs_l = shift(fcs_l); 96 | if (carry == 1) { 97 | lfcs_h++; 98 | } 99 | fcs_h = lfcs_h; 100 | fcs_l = lfcs_l; 101 | } 102 | d_h <<= 1; 103 | } 104 | 105 | } 106 | 107 | Util.setShort(crc32, (short) 2, fcs_l); 108 | Util.setShort(crc32, (short) 0, fcs_h); 109 | } 110 | 111 | short shift(short s) { 112 | return s <<= 1; 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/DSAPrivateKeyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.Util; 19 | import javacard.security.CryptoException; 20 | import javacard.security.DSAPrivateKey; 21 | import javacard.security.KeyBuilder; 22 | import org.bouncycastle.crypto.CipherParameters; 23 | import org.bouncycastle.crypto.params.DSAKeyParameters; 24 | import org.bouncycastle.crypto.params.DSAPrivateKeyParameters; 25 | 26 | /** 27 | * Implementation DSAPrivateKey based 28 | * on BouncyCastle CryptoAPI 29 | * @see DSAPrivateKey 30 | * @see DSAPrivateKeyParameters 31 | */ 32 | public class DSAPrivateKeyImpl extends DSAKeyImpl implements DSAPrivateKey { 33 | 34 | protected ByteContainer x = new ByteContainer(); 35 | 36 | /** 37 | * Construct not-initialized dsa private key 38 | * @param keySize key size it bits 39 | * @see KeyBuilder 40 | */ 41 | public DSAPrivateKeyImpl(short keySize) { 42 | super(KeyBuilder.TYPE_DSA_PRIVATE, keySize); 43 | } 44 | 45 | /** 46 | * Construct and initialize dsa key with DSAPrivateKeyParameters. 47 | * Use in KeyPairImpl 48 | * @see javacard.security.KeyPair 49 | * @see DSAPrivateKeyParameters 50 | * @param params key params from BouncyCastle API 51 | */ 52 | public DSAPrivateKeyImpl(DSAPrivateKeyParameters params) { 53 | super(params); 54 | x.setBigInteger(params.getX()); 55 | } 56 | 57 | public void setX(byte[] buffer, short offset, short length) throws CryptoException { 58 | x.setBytes(buffer, offset, length); 59 | } 60 | 61 | public short getX(byte[] buffer, short offset) { 62 | return x.getBytes(buffer, offset); 63 | } 64 | 65 | public boolean isInitialized() { 66 | return (super.isInitialized() && x.isInitialized()); 67 | } 68 | 69 | public void clearKey() { 70 | super.clearKey(); 71 | x.clear(); 72 | } 73 | 74 | public CipherParameters getParameters() { 75 | if (!isInitialized()) { 76 | CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); 77 | } 78 | return new DSAPrivateKeyParameters(x.getBigInteger(), ((DSAKeyParameters) super.getParameters()).getParameters()); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/DSAPublicKeyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.Util; 19 | import javacard.security.CryptoException; 20 | import javacard.security.DSAPublicKey; 21 | import javacard.security.KeyBuilder; 22 | import org.bouncycastle.crypto.CipherParameters; 23 | import org.bouncycastle.crypto.params.DSAKeyParameters; 24 | import org.bouncycastle.crypto.params.DSAPublicKeyParameters; 25 | 26 | /** 27 | * Implementation DSAPublicKey based 28 | * on BouncyCastle CryptoAPI 29 | * @see DSAPublicKey 30 | * @see DSAPublicKeyParameters 31 | */ 32 | public class DSAPublicKeyImpl extends DSAKeyImpl implements DSAPublicKey { 33 | 34 | protected ByteContainer y = new ByteContainer(); 35 | 36 | /** 37 | * Construct not-initialized dsa public key 38 | * @param keySize key size it bits 39 | * @see KeyBuilder 40 | */ 41 | public DSAPublicKeyImpl(short keySize) { 42 | super(KeyBuilder.TYPE_DSA_PUBLIC, keySize); 43 | } 44 | 45 | /** 46 | * Construct and initialize ecc key with DSAPublicKeyParameters. 47 | * Use in KeyPairImpl 48 | * @see javacard.security.KeyPair 49 | * @see DSAPublicKeyParameters 50 | * @param params key params from BouncyCastle API 51 | */ 52 | public DSAPublicKeyImpl(DSAPublicKeyParameters params) { 53 | super(params); 54 | byte[] yBytes = params.getY().toByteArray(); 55 | int byteLength = size / 8; 56 | if ((size % 8) != 0) ++byteLength; 57 | if (yBytes.length < byteLength) { 58 | byte[] bytesPadded = new byte[byteLength]; 59 | Util.arrayCopy(yBytes, (short)0, bytesPadded, (short)(bytesPadded.length - yBytes.length), (short)yBytes.length); 60 | y.setBytes(bytesPadded); 61 | } else if ((yBytes.length > byteLength) && (yBytes[0] == 0) && ((yBytes[1] & 0x80) != 0)) { 62 | y.setBytes(yBytes, (short)1, (short)(yBytes.length - 1)); 63 | } else { 64 | y.setBytes(yBytes); 65 | } 66 | } 67 | 68 | public void setY(byte[] buffer, short offset, short length) throws CryptoException { 69 | y.setBytes(buffer, offset, length); 70 | } 71 | 72 | public short getY(byte[] buffer, short offset) { 73 | return y.getBytes(buffer, offset); 74 | } 75 | 76 | public boolean isInitialized() { 77 | return (super.isInitialized() && y.isInitialized()); 78 | } 79 | 80 | public void clearKey() { 81 | super.clearKey(); 82 | y.clear(); 83 | } 84 | 85 | public CipherParameters getParameters() { 86 | if (!isInitialized()) { 87 | CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); 88 | } 89 | return new DSAPublicKeyParameters(y.getBigInteger(), ((DSAKeyParameters) super.getParameters()).getParameters()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/ECPrivateKeyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.Util; 19 | import javacard.security.CryptoException; 20 | import javacard.security.ECPrivateKey; 21 | import org.bouncycastle.crypto.CipherParameters; 22 | import org.bouncycastle.crypto.params.ECPrivateKeyParameters; 23 | 24 | /** 25 | * Implementation ECPrivateKey based 26 | * on BouncyCastle CryptoAPI 27 | * @see ECPrivateKey 28 | * @see ECPrivateKeyParameters 29 | */ 30 | public class ECPrivateKeyImpl extends ECKeyImpl implements ECPrivateKey { 31 | 32 | protected ByteContainer s = new ByteContainer(); 33 | 34 | /** 35 | * Construct not-initialized ecc private key 36 | * @param keyType 37 | * @param keySize key size it bits 38 | * @see javacard.security.KeyBuilder 39 | */ 40 | public ECPrivateKeyImpl(byte keyType, short keySize) { 41 | super(keyType, keySize); 42 | } 43 | 44 | /** 45 | * Construct and initialize ecc key with ECPrivateKeyParameters. 46 | * Use in KeyPairImpl 47 | * @see javacard.security.KeyPair 48 | * @see ECPrivateKeyParameters 49 | * @param params key params from BouncyCastle API 50 | */ 51 | public ECPrivateKeyImpl(ECPrivateKeyParameters params) { 52 | super(params); 53 | byte[] sBytes = params.getD().toByteArray(); 54 | int byteLength = size / 8; 55 | if ((size % 8) != 0) ++byteLength; 56 | if (sBytes.length < byteLength) { 57 | byte[] bytesPadded = new byte[byteLength]; 58 | Util.arrayCopy(sBytes, (short)0, bytesPadded, (short)(bytesPadded.length - sBytes.length), (short)sBytes.length); 59 | s.setBytes(bytesPadded); 60 | } else if ((sBytes.length > byteLength) && (sBytes[0] == 0) && ((sBytes[1] & 0x80) != 0)) { 61 | s.setBytes(sBytes, (short)1, (short)(sBytes.length - 1)); 62 | } else { 63 | s.setBytes(sBytes); 64 | } 65 | } 66 | 67 | public void setS(byte[] buffer, short offset, short length) throws CryptoException { 68 | s.setBytes(buffer, offset, length); 69 | } 70 | 71 | public short getS(byte[] buffer, short offset) throws CryptoException { 72 | return s.getBytes(buffer, offset); 73 | } 74 | 75 | public boolean isInitialized() { 76 | return (isDomainParametersInitialized() && s.isInitialized()); 77 | } 78 | 79 | public void clearKey() { 80 | super.clearKey(); 81 | s.clear(); 82 | } 83 | 84 | /** 85 | * Get ECPrivateKeyParameters 86 | * @return parameters for use with BouncyCastle API 87 | * @see ECPrivateKeyParameters 88 | */ 89 | public CipherParameters getParameters() { 90 | if (!isInitialized()) { 91 | CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); 92 | } 93 | return new ECPrivateKeyParameters(s.getBigInteger(), getDomainParameters()); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/ECPublicKeyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.security.CryptoException; 20 | import javacard.security.ECPublicKey; 21 | import org.bouncycastle.crypto.CipherParameters; 22 | import org.bouncycastle.crypto.params.ECDomainParameters; 23 | import org.bouncycastle.crypto.params.ECPublicKeyParameters; 24 | 25 | /** 26 | * Implementation ECPublicKey based 27 | * on BouncyCastle CryptoAPI 28 | * @see ECPublicKey 29 | * @see ECPublicKeyParameters 30 | */ 31 | public class ECPublicKeyImpl extends ECKeyImpl implements ECPublicKey { 32 | 33 | protected ByteContainer w = new ByteContainer(); 34 | 35 | /** 36 | * Construct not-initialized ecc public key 37 | * @param keyType 38 | * @param keySize key size it bits 39 | * @see javacard.security.KeyBuilder 40 | */ 41 | public ECPublicKeyImpl(byte keyType, short keySize) { 42 | super(keyType, keySize); 43 | } 44 | 45 | /** 46 | * Construct and initialize ecc key with ECPublicKeyParameters. 47 | * Use in KeyPairImpl 48 | * @see javacard.security.KeyPair 49 | * @see ECPublicKeyParameters 50 | * @param params key params from BouncyCastle API 51 | */ 52 | public ECPublicKeyImpl(ECPublicKeyParameters params) { 53 | super(params); 54 | w.setBytes(params.getQ().getEncoded()); 55 | } 56 | 57 | public void setW(byte[] buffer, short offset, short length) throws CryptoException { 58 | w.setBytes(buffer, offset, length); 59 | } 60 | 61 | public short getW(byte[] buffer, short offset) throws CryptoException { 62 | return w.getBytes(buffer, offset); 63 | } 64 | 65 | public boolean isInitialized() { 66 | return (isDomainParametersInitialized() && w.isInitialized()); 67 | } 68 | 69 | public void clearKey() { 70 | super.clearKey(); 71 | w.clear(); 72 | } 73 | 74 | /** 75 | * Get ECPublicKeyParameters 76 | * @return parameters for use with BouncyCastle API 77 | * @see ECPublicKeyParameters 78 | */ 79 | public CipherParameters getParameters() { 80 | if (!isInitialized()) { 81 | CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); 82 | } 83 | ECDomainParameters dp = getDomainParameters(); 84 | return new ECPublicKeyParameters(dp.getCurve().decodePoint(w.getBytes(JCSystem.CLEAR_ON_RESET)), dp); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/KeyAgreementImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.framework.Util; 20 | import javacard.security.CryptoException; 21 | import javacard.security.KeyAgreement; 22 | import javacard.security.PrivateKey; 23 | import org.bouncycastle.crypto.BasicAgreement; 24 | import org.bouncycastle.crypto.agreement.ECDHBasicAgreement; 25 | import org.bouncycastle.crypto.agreement.ECDHCBasicAgreement; 26 | import org.bouncycastle.crypto.params.ECPrivateKeyParameters; 27 | import org.bouncycastle.crypto.params.ECPublicKeyParameters; 28 | 29 | /** 30 | * Implementation KeyAgreement based 31 | * on BouncyCastle CryptoAPI 32 | * @see KeyAgreement 33 | * @see ECDHBasicAgreement 34 | * @see ECDHCBasicAgreement 35 | */ 36 | public class KeyAgreementImpl extends KeyAgreement { 37 | 38 | BasicAgreement engine; 39 | byte algorithm; 40 | ECPrivateKeyImpl privateKey; 41 | 42 | public KeyAgreementImpl(byte algorithm) { 43 | this.algorithm = algorithm; 44 | switch (algorithm) { 45 | case ALG_EC_SVDP_DH: 46 | engine = new ECDHBasicAgreement(); 47 | break; 48 | case ALG_EC_SVDP_DHC: 49 | engine = new ECDHCBasicAgreement(); 50 | break; 51 | default: 52 | CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); 53 | break; 54 | } 55 | } 56 | 57 | public void init(PrivateKey privateKey) throws CryptoException { 58 | if (privateKey == null) { 59 | CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); 60 | } 61 | if (!(privateKey instanceof ECPrivateKeyImpl)) { 62 | CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); 63 | } 64 | engine.init(((ECPrivateKeyImpl) privateKey).getParameters()); 65 | this.privateKey = (ECPrivateKeyImpl) privateKey; 66 | } 67 | 68 | public byte getAlgorithm() { 69 | return algorithm; 70 | } 71 | 72 | public short generateSecret(byte[] publicData, 73 | short publicOffset, 74 | short publicLength, 75 | byte[] secret, 76 | short secretOffset) throws CryptoException { 77 | byte[] publicKey = JCSystem.makeTransientByteArray(publicLength, JCSystem.CLEAR_ON_RESET); 78 | Util.arrayCopyNonAtomic(publicData, publicOffset, publicKey, (short) 0, publicLength); 79 | ECPublicKeyParameters ecp = new ECPublicKeyParameters( 80 | ((ECPrivateKeyParameters) privateKey.getParameters()).getParameters().getCurve().decodePoint(publicKey), ((ECPrivateKeyParameters) privateKey.getParameters()).getParameters()); 81 | byte[] result = engine.calculateAgreement(ecp).toByteArray(); 82 | if (result.length > secret.length - secretOffset) { 83 | CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); 84 | } 85 | Util.arrayCopyNonAtomic(result, (short) 0, secret, secretOffset, (short) result.length); 86 | return (short) result.length; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/KeyImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.security.Key; 19 | 20 | /** 21 | * Base class for all Key instances 22 | * @see Key 23 | */ 24 | public abstract class KeyImpl implements Key, KeyWithParameters { 25 | 26 | protected short size; 27 | protected byte type; 28 | 29 | public short getSize() { 30 | return size; 31 | } 32 | 33 | public byte getType() { 34 | return type; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/KeyWithParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import java.security.SecureRandom; 19 | import org.bouncycastle.crypto.CipherParameters; 20 | import org.bouncycastle.crypto.KeyGenerationParameters; 21 | 22 | /** 23 | * 24 | */ 25 | public interface KeyWithParameters { 26 | 27 | /** 28 | * Get cipher key parameters for use with BouncyCastle Crypto API 29 | * 30 | * @return key parameters 31 | */ 32 | public CipherParameters getParameters(); 33 | 34 | /** 35 | * Get keypair generation parameters for use with BouncyCastle Crypto API 36 | * 37 | * @return key parameters 38 | */ 39 | public KeyGenerationParameters getKeyGenerationParameters(SecureRandom rnd); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/com/licel/jcardsim/crypto/RandomDataImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.framework.Util; 20 | import javacard.security.CryptoException; 21 | import javacard.security.RandomData; 22 | import org.bouncycastle.crypto.digests.SHA1Digest; 23 | import org.bouncycastle.crypto.prng.DigestRandomGenerator; 24 | import org.bouncycastle.crypto.prng.RandomGenerator; 25 | 26 | /** 27 | * Implementation RandomData based 28 | * on BouncyCastle CryptoAPI 29 | * @see RandomData 30 | */ 31 | public class RandomDataImpl extends RandomData { 32 | 33 | RandomGenerator engine; 34 | 35 | public RandomDataImpl() { 36 | engine = new DigestRandomGenerator(new SHA1Digest()); 37 | } 38 | 39 | public void generateData(byte[] buffer, short offset, short length) throws CryptoException { 40 | engine.nextBytes(buffer, offset, length); 41 | } 42 | 43 | public void setSeed(byte[] buffer, short offset, short length) { 44 | byte[] seed = JCSystem.makeTransientByteArray(length, JCSystem.CLEAR_ON_RESET); 45 | Util.arrayCopyNonAtomic(buffer, offset, seed, (short) 0, length); 46 | engine.addSeedMaterial(seed); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/java/rmi/Remote.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package java.rmi; 18 | 19 | public interface Remote { 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/java/rmi/RemoteException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package java.rmi; 18 | 19 | public class RemoteException extends java.io.IOException { 20 | 21 | public RemoteException() { 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /src/main/java/javacard/framework/AppletEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.framework; 18 | 19 | /** 20 | * The AppletEvent interface provides a callback interface for 21 | * the Java Card runtime environment to inform the applet about life cycle events. 22 | * An applet instance - subclass of Applet - should implement 23 | * this interface if it needs to be informed about supported life cycle events. 24 | * 25 | *

26 | * See Runtime Environment Specification for the Java Card Platform for details. 27 | */ 28 | public interface AppletEvent 29 | { 30 | /** 31 | * Called by the Java Card runtime environment to inform this applet instance that the Applet Deletion 32 | * Manager has been requested to delete it. 33 | */ 34 | public abstract void uninstall(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/CardException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.framework; 17 | 18 | /** 19 | * The CardException class 20 | * defines a field reason and two accessor methods 21 | * getReason() and setReason(). The reason 22 | * field encapsulates an exception cause identifier in the Java Card platform. 23 | * All Java Card platform checked Exception classes should extend 24 | * CardException. This class also provides a resource-saving mechanism 25 | * (throwIt() method) for using a Java Card runtime environment-owned instance of this class. 26 | *

Even if a transaction is in progress, the update of the internal reason 27 | * field shall not participate in the transaction. The value of the internal reason 28 | * field of Java Card runtime environment-owned instance is reset to 0 on a tear or reset. 29 | * 30 | */ 31 | public class CardException extends Exception { 32 | 33 | private byte theSw[]; 34 | 35 | /** 36 | * Construct a CardException instance with the specified reason. 37 | * To conserve on resources, use the throwIt() method 38 | * to use the Java Card runtime environment-owned instance of this class. 39 | * @param reason the reason for the exception 40 | */ 41 | public CardException(short reason) { 42 | theSw = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); 43 | Util.setShort(theSw, (short) 0, reason); 44 | } 45 | 46 | /** 47 | * Get reason code 48 | * @return the reason for the exception 49 | */ 50 | public short getReason() { 51 | return Util.getShort(theSw, (short) 0); 52 | } 53 | 54 | /** 55 | * Set reason code 56 | * @param reason the reason for the exception 57 | */ 58 | public void setReason(short reason) { 59 | Util.arrayFillNonAtomic(theSw, (short) 0, (short) 1, (byte) (reason >>> 8)); 60 | Util.arrayFillNonAtomic(theSw, (short) 1, (short) 1, (byte) reason); 61 | } 62 | 63 | /** 64 | * Throw the Java Card runtime environment-owned instance of CardException class with the 65 | * specified reason. 66 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 67 | * and can be accessed from any applet context. References to these temporary objects 68 | * cannot be stored in class variables or instance variables or array components. 69 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 70 | * @param reason the reason for the exception 71 | * @throws CardException always 72 | */ 73 | public static void throwIt(short reason) 74 | throws CardException { 75 | throw new CardException(reason); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/CardRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.framework; 17 | 18 | /** 19 | * The CardRuntimeException class 20 | * defines a field reason and two accessor methods 21 | * getReason() and setReason(). The reason 22 | * field encapsulates an exception cause identifier in the Java Card platform. 23 | * All Java Card platform unchecked Exception classes should extend 24 | * CardRuntimeException. This class also provides a resource-saving mechanism 25 | * (throwIt() method) for using a Java Card runtime environment-owned instance of this class. 26 | *

Even if a transaction is in progress, the update of the internal reason 27 | * field shall not participate in the transaction. The value of the internal reason 28 | * field of Java Card runtime environment-owned instance is reset to 0 on a tear or reset. 29 | */ 30 | public class CardRuntimeException extends RuntimeException { 31 | 32 | private byte theSw[]; 33 | 34 | /** 35 | * Constructs a CardRuntimeException instance with the specified reason. 36 | * To conserve on resources, use the throwIt() method 37 | * to employ the Java Card runtime environment-owned instance of this class. 38 | * @param reason the reason for the exception 39 | */ 40 | public CardRuntimeException(short reason) { 41 | theSw = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); 42 | Util.setShort(theSw, (short) 0, reason); 43 | } 44 | 45 | /** 46 | * Get reason code 47 | * @return the reason for the exception 48 | */ 49 | public short getReason() { 50 | return Util.getShort(theSw, (short) 0); 51 | } 52 | 53 | /** 54 | * Set reason code 55 | * @param reason the reason for the exception 56 | */ 57 | public void setReason(short reason) { 58 | Util.arrayFillNonAtomic(theSw, (short) 0, (short) 1, (byte) (reason >>> 8)); 59 | Util.arrayFillNonAtomic(theSw, (short) 1, (short) 1, (byte) reason); 60 | } 61 | 62 | /** 63 | * Throws the Java Card runtime environment-owned instance of the CardRuntimeException class with the 64 | * specified reason. 65 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 66 | * and can be accessed from any applet context. References to these temporary objects 67 | * cannot be stored in class variables or instance variables or array components. 68 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 69 | * @param reason the reason for the exception 70 | * @throws CardRuntimeException always 71 | */ 72 | public static void throwIt(short reason) 73 | throws CardRuntimeException { 74 | throw new CardRuntimeException(reason); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/ISOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.framework; 17 | 18 | /** 19 | * ISOException class encapsulates an ISO 7816-4 response status word as 20 | * its reason code. 21 | *

The APDU class throws Java Card runtime environment-owned instances of ISOException. 22 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 23 | * and can be accessed from any applet context. References to these temporary objects 24 | * cannot be stored in class variables or instance variables or array components. 25 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 26 | */ 27 | public class ISOException extends CardRuntimeException { 28 | 29 | /** 30 | * Constructs an ISOException instance with the specified status word. 31 | * To conserve on resources use throwIt() 32 | * to employ the Java Card runtime environment-owned instance of this class. 33 | * @param sw the ISO 7816-4 defined status word 34 | */ 35 | public ISOException(short sw) { 36 | super(sw); 37 | } 38 | 39 | /** 40 | * Throws the Java Card runtime environment-owned instance of the ISOException class with the specified status word. 41 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 42 | * and can be accessed from any applet context. References to these temporary objects 43 | * cannot be stored in class variables or instance variables or array components. 44 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 45 | * @param sw the ISO 7816-4 defined status word 46 | * @throws ISOException always 47 | */ 48 | public static void throwIt(short sw) throws ISOException { 49 | throw new ISOException(sw); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/PINException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.framework; 17 | 18 | /** 19 | * PINException represents a OwnerPIN class access-related exception. 20 | *

The OwnerPIN class throws Java Card runtime environment-owned instances of PINException. 21 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 22 | * and can be accessed from any applet context. References to these temporary objects 23 | * cannot be stored in class variables or instance variables or array components. 24 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 25 | */ 26 | public class PINException extends CardRuntimeException { 27 | 28 | /** 29 | * This reason code is used to indicate that one or more input parameters 30 | * is out of allowed bounds. 31 | */ 32 | public static final short ILLEGAL_VALUE = 1; 33 | 34 | /** 35 | * Constructs a PINException. 36 | * To conserve on resources use throwIt() 37 | * to employ the Java Card runtime environment-owned instance of this class. 38 | * @param reason the reason for the exception 39 | */ 40 | public PINException(short reason) { 41 | super(reason); 42 | } 43 | 44 | /** 45 | * Throws the Java Card runtime environment-owned instance of PINException with the specified reason. 46 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 47 | * and can be accessed from any applet context. References to these temporary objects 48 | * cannot be stored in class variables or instance variables or array components. 49 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 50 | * @param reason the reason for the exception 51 | * @throws PINException always 52 | */ 53 | public static void throwIt(short reason) throws PINException { 54 | throw new PINException(reason); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/Shareable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.framework; 18 | 19 | /** 20 | * The Shareable interface serves to identify all shared objects. 21 | * Any object that needs to be shared through the applet firewall 22 | * must directly or indirectly implement this interface. Only those 23 | * methods specified in a shareable interface are available through 24 | * the firewall. 25 | * 26 | * Implementation classes can implement any number of shareable 27 | * interfaces and can extend other shareable implementation classes. 28 | * 29 | */ 30 | public interface Shareable { 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/TransactionException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.framework; 18 | 19 | /** 20 | * TransactionException represents an exception in the transaction subsystem. 21 | * The methods referred to in this class are in the JCSystem class. 22 | *

The JCSystem class and the transaction facility throw Java Card runtime environment-owned instances 23 | * of TransactionException. 24 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 25 | * and can be accessed from any applet context. References to these temporary objects 26 | * cannot be stored in class variables or instance variables or array components. 27 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 28 | * 29 | */ 30 | public class TransactionException extends CardRuntimeException { 31 | 32 | /** 33 | * This reason code is used by the beginTransaction method to indicate 34 | * a transaction is already in progress. 35 | */ 36 | public static final short IN_PROGRESS = 1; 37 | /** 38 | * This reason code is used by the abortTransaction and commitTransaction methods 39 | * when a transaction is not in progress. 40 | */ 41 | public static final short NOT_IN_PROGRESS = 2; 42 | /** 43 | * This reason code is used during a transaction to indicate that the commit buffer is full. 44 | */ 45 | public static final short BUFFER_FULL = 3; 46 | /** 47 | * This reason code is used during a transaction to indicate 48 | * an internal Java Card runtime environment problem (fatal error). 49 | */ 50 | public static final short INTERNAL_FAILURE = 4; 51 | 52 | 53 | /** 54 | * Constructs a TransactionException with the specified reason. 55 | * To conserve on resources use throwIt() 56 | * to use the Java Card runtime environment-owned instance of this class. 57 | * @param reason the reason for the exception 58 | */ 59 | public TransactionException(short reason) { 60 | super(reason); 61 | } 62 | 63 | /** 64 | * Throws the Java Card runtime environment-owned instance of TransactionException with the specified reason. 65 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 66 | * and can be accessed from any applet context. References to these temporary objects 67 | * cannot be stored in class variables or instance variables or array components. 68 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 69 | * @param reason the reason for the exception 70 | * @throws TransactionException always 71 | */ 72 | public static void throwIt(short reason) throws TransactionException { 73 | throw new TransactionException(reason); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/UserException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.framework; 17 | 18 | /** 19 | * UserException represents a User exception. 20 | * This class also provides a resource-saving mechanism (the throwIt() method) for user 21 | * exceptions by using a Java Card runtime environment-owned instance. 22 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 23 | * and can be accessed from any applet context. References to these temporary objects 24 | * cannot be stored in class variables or instance variables or array components. 25 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 26 | */ 27 | public class UserException extends CardException { 28 | 29 | /** 30 | * Constructs a UserException with reason = 0. 31 | * To conserve on resources use throwIt() 32 | * to use the Java Card runtime environment-owned instance of this class. 33 | */ 34 | public UserException() { 35 | this((short) 0); 36 | } 37 | 38 | /** 39 | * Constructs a UserException with the specified reason. 40 | * To conserve on resources use throwIt() 41 | * to use the Java Card runtime environment-owned instance of this class. 42 | * @param reason the reason for the exception 43 | */ 44 | public UserException(short reason) { 45 | super(reason); 46 | } 47 | 48 | /** 49 | * Throws the Java Card runtime environment-owned instance of UserException with the specified reason. 50 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 51 | * and can be accessed from any applet context. References to these temporary objects 52 | * cannot be stored in class variables or instance variables or array components. 53 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 54 | * @param reason the reason for the exception 55 | * @throws UserException always 56 | */ 57 | public static void throwIt(short reason) 58 | throws UserException { 59 | throw new UserException(reason); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/javacard/framework/__AIDWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.framework; 17 | 18 | import at.mroland.utils.StringUtils; 19 | import com.licel.jcardsim.base.SimulatorSystem; 20 | import java.util.Arrays; 21 | 22 | /** 23 | * 24 | */ 25 | public class __AIDWrapper { 26 | private __AIDWrapper() { 27 | } 28 | 29 | public static byte[] getAIDBytes(AID aid) { 30 | if (aid != null) { 31 | return Arrays.copyOf(aid.aid, aid.aid.length); 32 | } else { 33 | return null; 34 | } 35 | } 36 | 37 | public static String getAIDString(AID aid) { 38 | if (aid != null) { 39 | return StringUtils.convertByteArrayToHexString(aid.aid).toUpperCase(); 40 | } else { 41 | return ""; 42 | } 43 | } 44 | 45 | public static AID getAIDInstance(String aidString) { 46 | return getAIDInstance(StringUtils.convertHexStringToByteArray(aidString)); 47 | } 48 | 49 | public static AID getAIDInstance(byte[] aidBytes) { 50 | if (aidBytes != null) { 51 | AID aidInstance = SimulatorSystem.lookupAnyAID(aidBytes, (short)0, (byte)(aidBytes.length & 0x0ff)); 52 | if (aidInstance == null) { 53 | aidInstance = new AID(aidBytes, (short)0, (byte)(aidBytes.length & 0x0ff)); 54 | } 55 | return aidInstance; 56 | } else { 57 | return null; 58 | } 59 | } 60 | 61 | public static AID getAIDInstance(byte[] aidBytes, short offset, byte length) { 62 | if ((aidBytes == null) || (offset < 0) || (length < 0) || (aidBytes.length < (offset + length))) return null; 63 | 64 | AID aidInstance = SimulatorSystem.lookupAnyAID(aidBytes, offset, length); 65 | if (aidInstance == null) { 66 | aidInstance = new AID(aidBytes, offset, length); 67 | } 68 | return aidInstance; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/javacard/security/AESKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * AESKey contains a 16/24/32 byte key for AES computations based 21 | * on the Rijndael algorithm. 22 | *

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

24 | * @see KeyBuilder 25 | * @see Signature 26 | * @see javacardx.crypto.Cipher 27 | * @see javacardx.crypto.KeyEncryption 28 | */ 29 | public interface AESKey 30 | extends SecretKey { 31 | 32 | /** 33 | * Sets the Key data. The plaintext length of input key data is 16/24/32 bytes. 34 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 35 | * bit of last byte). Input key data is copied into the internal representation. 36 | *

Note: 37 | *

    38 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 39 | * interface and the Cipher object specified via setKeyCipher() 40 | * is not null, keyData is decrypted using the Cipher object. 41 | *
42 | * @param keyData byte array containing key initialization data 43 | * @param kOff offset within keyData to start 44 | * @throws CryptoException with the following reason code: 45 | *
    46 | *
  • CryptoException.ILLEGAL_VALUE if input data decryption is required and fails. 47 | *
48 | * @throws NullPointerException if the keyData parameter is 49 | * null. 50 | * @throws ArrayIndexOutOfBoundsException if kOff is negative 51 | * or the keyData array is too short. 52 | */ 53 | public abstract void setKey(byte[] keyData, short kOff) 54 | throws CryptoException, NullPointerException, ArrayIndexOutOfBoundsException; 55 | 56 | /** 57 | * Returns the Key data in plain text. The length of output key data is 16/24/32 bytes. 58 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 59 | * bit of last byte). 60 | * 61 | * @param keyData byte array to return key data 62 | * @param kOff offset within keyData to start 63 | * @return the byte length of the key data returned 64 | * @throws CryptoException with the following reason code: 65 | *
    66 | *
  • CryptoException.UNINITIALIZED_KEY if the key data has not been 67 | * successfully initialized since the 68 | * time the initialized state of the key was set to false. 69 | *
70 | */ 71 | public abstract byte getKey(byte[] keyData, short kOff) 72 | throws CryptoException; 73 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/CryptoException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.security; 17 | 18 | import javacard.framework.CardRuntimeException; 19 | 20 | /** 21 | * CryptoException represents a cryptography-related exception. 22 | *

The API classes throw Java Card runtime environment-owned instances of CryptoException. 23 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 24 | * and can be accessed from any applet context. References to these temporary objects 25 | * cannot be stored in class variables or instance variables or array components. 26 | * @see MessageDigest 27 | * @see Signature 28 | * @see RandomData 29 | * @see javacardx.crypto.Cipher 30 | */ 31 | public class CryptoException extends CardRuntimeException { 32 | 33 | /** 34 | * This reason code is used to indicate that one or more input parameters is out of allowed bounds. 35 | */ 36 | public static final short ILLEGAL_VALUE = 1; 37 | /** 38 | * This reason code is used to indicate that the key is uninitialized. 39 | */ 40 | public static final short UNINITIALIZED_KEY = 2; 41 | /** 42 | * This reason code is used to indicate that the requested algorithm or key type is not supported. 43 | */ 44 | public static final short NO_SUCH_ALGORITHM = 3; 45 | /** 46 | * This reason code is used to indicate that the signature or cipher object has not been correctly initialized for the requested operation. 47 | */ 48 | public static final short INVALID_INIT = 4; 49 | /** 50 | * This reason code is used to indicate that the signature or cipher algorithm does not pad the incoming message and the input message is not block aligned. 51 | */ 52 | public static final short ILLEGAL_USE = 5; 53 | 54 | /** 55 | * Constructs a CryptoException with the specified reason. 56 | * To conserve on resources use throwIt() 57 | * to use the Java Card runtime environment-owned instance of this class. 58 | * @param reason the reason for the exception 59 | */ 60 | public CryptoException(short reason) { 61 | super(reason); 62 | } 63 | 64 | /** 65 | * Throws the Java Card runtime environment-owned instance of CryptoException with the specified reason. 66 | *

Java Card runtime environment-owned instances of exception classes are temporary Java Card runtime environment Entry Point Objects 67 | * and can be accessed from any applet context. References to these temporary objects 68 | * cannot be stored in class variables or instance variables or array components. 69 | * See Runtime Environment Specification for the Java Card Platform, section 6.2.1 for details. 70 | * @param reason the reason for the exception 71 | * @throws CryptoException always 72 | */ 73 | public static void throwIt(short reason) { 74 | throw new CryptoException(reason); 75 | } 76 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/DESKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * DESKey contains an 8/16/24-byte key for single/2 key triple DES/3 key triple DES 21 | * operations. 22 | *

When the key data is set, the key is initialized and ready for use. 23 | * @see KeyBuilder 24 | * @see Signature 25 | * @see javacardx.crypto.Cipher 26 | * @see javacardx.crypto.KeyEncryption 27 | * 28 | */ 29 | public interface DESKey 30 | extends SecretKey { 31 | 32 | /** 33 | * Sets the Key data. The plain text length of input key data is 8 bytes for DES, 34 | * 16 bytes for 2-key triple DES and 24 bytes for 3-key triple DES. 35 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 36 | * bit of last byte). Input key data is copied into the internal representation. 37 | *

Note:

    38 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 39 | * interface and the Cipher object specified via setKeyCipher() 40 | * is not null, keyData is decrypted using the Cipher object. 41 | *
42 | * @param keyData byte array containing key initialization data 43 | * @param kOff offset within keyData to start 44 | * @throws CryptoException with the following reason code: 45 | *
    46 | *
  • CryptoException.ILLEGAL_VALUE if input data decryption is required and fails. 47 | *
48 | * @throws NullPointerException - if the keyData parameter is null 49 | * @throws ArrayIndexOutOfBoundsException if kOff is negative 50 | * or the keyData array is too short 51 | */ 52 | public abstract void setKey(byte[] keyData, short kOff) 53 | throws CryptoException, NullPointerException, ArrayIndexOutOfBoundsException; 54 | 55 | /** 56 | * Returns the Key data in plain text. The length of output key data is 8 bytes for DES, 57 | * 16 bytes for 2-key triple DES and 24 bytes for 3-key triple DES. 58 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 59 | * bit of last byte). 60 | * @param keyData byte array to return key data 61 | * @param kOff offset within keyData to start 62 | * @return the byte length of the key data returned 63 | * @throws CryptoException with the following reason code: 64 | *
    65 | *
  • CryptoException.UNINITIALIZED_KEY if the key data has not been 66 | * successfully initialized since the 67 | * time the initialized state of the key was set to false.
  • 68 | *
69 | * @see Key 70 | */ 71 | public abstract byte getKey(byte[] keyData, short kOff) 72 | throws CryptoException; 73 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/DSAPrivateKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * 21 | * The DSAPrivateKey interface is used to sign data using the DSA algorithm. An 22 | * implementation of DSAPrivateKey interface must also implement 23 | * the DSAKey interface methods. 24 | *

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

27 | * @see DSAPublicKey 28 | * @see KeyBuilder 29 | * @see Signature 30 | * @see javacardx.crypto.KeyEncryption 31 | */ 32 | public interface DSAPrivateKey 33 | extends PrivateKey, DSAKey { 34 | 35 | /** 36 | * Sets the value of the key. When the base, prime and subprime parameters are initialized 37 | * and the key value is set, the key is ready for use. 38 | * The plain text data format is big-endian and right-aligned (the least significant bit is the least significant 39 | * bit of last byte). Input key data is copied into the internal representation. 40 | *

Note: 41 | *

    42 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 43 | * interface and the Cipher object specified via setKeyCipher() 44 | * is not null, the key value is decrypted using the Cipher object. 45 | *
46 | * @param buffer the input buffer 47 | * @param offset the offset into the input buffer at which the modulus value begins 48 | * @param length the length of the modulus 49 | * @throws CryptoException with the following reason code: 50 | *
    51 | *
  • CryptoException.ILLEGAL_VALUE if the input key data length is inconsistent 52 | * with the implementation or if input data decryption is required and fails. 53 | *
54 | */ 55 | public abstract void setX(byte[] buffer, short offset, short length) 56 | throws CryptoException; 57 | 58 | /** 59 | * Returns the value of the key in plain text. 60 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 61 | * bit of last byte). 62 | * @param buffer the output buffer 63 | * @param offset the offset into the output buffer at which the key value starts 64 | * @return the byte length of the key value returned 65 | * @throws CryptoException with the following reason code: 66 | *
    67 | *
  • CryptoException.UNINITIALIZED_KEY if the value of the key has not been 68 | * successfully initialized since the 69 | * time the initialized state of the key was set to false. 70 | *
71 | * @see Key 72 | */ 73 | public abstract short getX(byte[] buffer, short offset) 74 | throws CryptoException; 75 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/DSAPublicKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * The DSAPublicKey interface is used to verify signatures 21 | * on signed data using the DSA algorithm. 22 | * An implementation of DSAPublicKey interface must also implement 23 | * the DSAKey interface methods. 24 | *

When all four components of the key (Y,P,Q,G) are set, the key is 25 | * initialized and ready for use. 26 | * @see DSAPrivateKey 27 | * @see KeyBuilder 28 | * @see Signature 29 | * @see javacardx.crypto.KeyEncryption 30 | */ 31 | public interface DSAPublicKey 32 | extends PublicKey, DSAKey { 33 | 34 | /** 35 | * Sets the value of the key. When the base, prime and subprime parameters are initialized 36 | * and the key value is set, the key is ready for use. 37 | * The plain text data format is big-endian and right-aligned (the least significant bit is the least significant 38 | * bit of last byte). Input key data is copied into the internal representation. 39 | *

Note: 40 | *

    41 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 42 | * interface and the Cipher object specified via setKeyCipher() 43 | * is not null, the key value is decrypted using the Cipher object. 44 | *
45 | * @param buffer the input buffer 46 | * @param offset the offset into the input buffer at which the key value begins 47 | * @param length the length of the key value 48 | * @throws CryptoException with the following reason code: 49 | *
    50 | *
  • CryptoException.ILLEGAL_VALUE if the input key data length is inconsistent 51 | * with the implementation or if input data decryption is required and fails. 52 | *
53 | */ 54 | public abstract void setY(byte[] buffer, short offset, short length) 55 | throws CryptoException; 56 | 57 | /** 58 | * Returns the value of the key in plain text. 59 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 60 | * bit of last byte). 61 | * @param buffer the output buffer 62 | * @param offset the offset into the input buffer at which the key value starts 63 | * @return the byte length of the key value returned 64 | * @throws CryptoException with the following reason code: 65 | *
    66 | *
  • CryptoException.UNINITIALIZED_KEY if the value of the key has not been 67 | * successfully initialized since the 68 | * time the initialized state of the key was set to false. 69 | *
70 | * @see Key 71 | */ 72 | public abstract short getY(byte[] buffer, short offset) 73 | throws CryptoException; 74 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/ECPrivateKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * 21 | * The ECPrivateKey interface is used to generate signatures on data using 22 | * the ECDSA (Elliptic Curve Digital Signature Algorithm) and to generate shared secrets 23 | * using the ECDH (Elliptic Curve Diffie-Hellman) algorithm. An implementation of 24 | * ECPrivateKey interface must also implement 25 | * the ECKey interface methods. 26 | *

When all components of the key (S, A, B, G, R, Field) are 27 | * set, the key is initialized and ready for use. 28 | * In addition, the KeyAgreement algorithm type 29 | * ALG_EC_SVDP_DHC requires that the cofactor, K, be initialized. 30 | *

The notation used to describe parameters specific to the EC algorithm is 31 | * based on the naming conventions established in [IEEE P1363]. 32 | * @see ECPublicKey 33 | * @see KeyBuilder 34 | * @see Signature 35 | * @see javacardx.crypto.KeyEncryption 36 | * @see KeyAgreement 37 | */ 38 | public interface ECPrivateKey 39 | extends PrivateKey, ECKey { 40 | 41 | /** 42 | * Sets the value of the secret key. 43 | * The plain text data format is big-endian and right-aligned 44 | * (the least significant bit is the least significant bit of last byte). 45 | * Input parameter data is copied into the internal representation. 46 | *

Note:

    47 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 48 | * interface and the Cipher object specified via setKeyCipher() 49 | * is not null, the key value is decrypted using the Cipher object. 50 | *
51 | * @param buffer the input buffer 52 | * @param offset the offset into the input buffer at which the 53 | * secret value is to begin 54 | * @param length the byte length of the secret value 55 | * @throws CryptoException with the following reason code: 56 | *
    57 | *
  • CryptoException.ILLEGAL_VALUE if the input key data is inconsistent 58 | * with the key length or if input data decryption is required and fails. 59 | *
60 | */ 61 | public abstract void setS(byte[] buffer, short offset, short length) 62 | throws CryptoException; 63 | 64 | /** 65 | * Returns the value of the secret key in plaintext form. 66 | * The data format is big-endian and right-aligned 67 | * (the least significant bit is the least significant bit of last byte). 68 | * @param buffer the output buffer 69 | * @param offset the offset into the input buffer at which the 70 | * secret value is to begin 71 | * @return the byte length of the secret value 72 | * @throws CryptoException with the following reason code: 73 | *
    74 | *
  • CryptoException.UNINITIALIZED_KEY if the value of the secret key 75 | * has not been 76 | * successfully initialized since the 77 | * time the initialized state of the key was set to false. 78 | *
79 | * @see Key 80 | */ 81 | public abstract short getS(byte[] buffer, short offset) 82 | throws CryptoException; 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/main/java/javacard/security/ECPublicKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * The ECPublicKey interface is used to verify signatures on signed data 21 | * using the ECDSA algorithm and to generate shared secrets using the ECDH 22 | * algorithm. An implementation of ECPublicKey interface must also implement 23 | * the ECKey interface methods. 24 | *

When all components of the key (W, A, B, G, R, Field) are 25 | * set, the key is initialized and ready for use. 26 | *

The notation used to describe parameters specific to the EC algorithm is 27 | * based on the naming conventions established in [IEEE P1363]. 28 | * @see ECPrivateKey 29 | * @see KeyBuilder 30 | * @see Signature 31 | * @see javacardx.crypto.KeyEncryption 32 | * @see KeyAgreement 33 | */ 34 | public interface ECPublicKey 35 | extends PublicKey, ECKey { 36 | 37 | /** 38 | * Sets the point of the curve comprising the public key. The point 39 | * should be specified as an octet string as per ANSI X9.62. A specific implementation need 40 | * not support the compressed form, but must support the uncompressed form 41 | * of the point. 42 | * The plain text data format is big-endian and right-aligned 43 | * (the least significant bit is the least significant bit of last byte). 44 | * Input parameter data is copied into the internal representation. 45 | *

Note: 46 | *

    47 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 48 | * interface and the Cipher object specified via setKeyCipher() 49 | * is not null, the key value is decrypted using the Cipher object. 50 | *
51 | * @param buffer the input buffer 52 | * @param offset the offset into the input buffer at which the 53 | * point specification begins 54 | * @param length the byte length of the point specification 55 | * @throws CryptoException with the following reason code: 56 | *
    57 | *
  • CryptoException.ILLEGAL_VALUE if the input parameter 58 | * data format is incorrect, or if the input parameter data is inconsistent with the key length, 59 | * or if input data decryption is required and fails. 60 | *
61 | */ 62 | public abstract void setW(byte[] buffer, short offset, short length) 63 | throws CryptoException; 64 | 65 | /** 66 | * Returns the point of the curve comprising the public key in plain text form. 67 | * The point is represented as an octet string in compressed or 68 | * uncompressed forms as per ANSI X9.62. 69 | * The data format is big-endian and right-aligned 70 | * (the least significant bit is the least significant bit of last byte). 71 | * @param buffer the output buffer 72 | * @param offset the offset into the output buffer at which the 73 | * point specification data is to begin 74 | * @return the byte length of the point specificiation 75 | * @throws CryptoException with the following reason code: 76 | *
    77 | *
  • CryptoException.UNINITIALIZED_KEY if the point of the curve 78 | * comprising the public key has not been 79 | * successfully initialized since the 80 | * time the initialized state of the key was set to false. 81 | *
82 | * @see Key 83 | */ 84 | public abstract short getW(byte[] buffer, short offset) 85 | throws CryptoException; 86 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/HMACKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.security; 17 | 18 | /** 19 | * 20 | * HMACKey contains a key for HMAC operations. This key can be of 21 | * any length, but it is strongly recommended that the key is not shorter than the 22 | * byte length of the hash output used in the HMAC implementation. 23 | * Keys with length greater than the hash block length are first hashed with the 24 | * hash algorithm used for the HMAC implementation.

25 | *

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

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

29 | * 30 | * @see KeyBuilder 31 | * @see Signature 32 | * @see javacardx.crypto.Cipher 33 | * @see javacardx.crypto.KeyEncryption 34 | * @since 2.2.2 35 | */ 36 | 37 | public interface HMACKey extends SecretKey { 38 | 39 | /** 40 | * Sets the 41 | * Key data. 42 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 43 | * bit of last byte). Input key data is copied into the internal representation. 44 | *

Note:

    45 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 46 | * interface and the Cipher object specified via setKeyCipher() 47 | * is not null, keyData is decrypted using the Cipher object. 48 | *
49 | *

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

67 | * 68 | * @param keyData byte array to return key data 69 | * @param kOff offset within keyData to start 70 | * @return the byte length of the key data returned 71 | * @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. 72 | * @see Key 73 | */ 74 | byte getKey(byte[] keyData, short kOff); 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/javacard/security/Key.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * The Key interface is the base interface for all keys. 21 | *

22 | *

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

A newly created Key object sets its initialized state to false. Invocation of the 25 | * clearKey() method sets the initialized state to false. A key with transient key data 26 | * sets its initialized state to false on the associated clear events. 27 | * 28 | */ 29 | public interface Key { 30 | 31 | /** 32 | * Clears the key and sets its initialized state to false. 33 | */ 34 | public abstract void clearKey(); 35 | 36 | /** 37 | * Returns the key size in number of bits. 38 | * @return the key size in number of bits 39 | */ 40 | public abstract short getSize(); 41 | 42 | /** 43 | * Returns the key interface type. 44 | * @return the key interface type. Valid codes listed in TYPE.. constants 45 | * See KeyBuilder.TYPE_DES_TRANSIENT_RESET 46 | *

47 | * @see KeyBuilder 48 | */ 49 | public abstract byte getType(); 50 | 51 | /** 52 | * Reports the initialized state of the key. Keys must be initialized before 53 | * being used. 54 | *

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

A newly created Key object sets its initialized state to false. Invocation of the 57 | * clearKey() method sets the initialized state to false. A key with transient key data 58 | * sets its initialized state to false on the associated clear events. 59 | * @return true if the key has been initialized 60 | */ 61 | public abstract boolean isInitialized(); 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/javacard/security/KoreanSEEDKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacard.security; 17 | 18 | /** 19 | * 20 | * KoreanSEEDKey contains an 16-byte key for Korean Seed Algorithm 21 | * operations. 22 | *

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

24 | * 25 | * @since 2.2.2 26 | * @see KeyBuilder 27 | * @see Signature 28 | * @see javacardx.crypto.Cipher 29 | * @see javacardx.crypto.KeyEncryption 30 | * 31 | */ 32 | public interface KoreanSEEDKey extends SecretKey 33 | { 34 | /** 35 | * Sets the Key data. The plain text length of input key data is 36 | * The data format is big-endian and right-aligned (the least significant bit is the least significant 37 | * bit of last byte). Input key data is copied into the internal representation. 38 | *

Note:

    39 | *
  • If the key object implements the javacardx.crypto.KeyEncryption 40 | * interface and the Cipher object specified via setKeyCipher() 41 | * is not null, keyData is decrypted using the Cipher object. 42 | *
43 | *

44 | * 45 | * @param keyData byte array containing key initialization data 46 | * @param kOff offset within keyData to start 47 | * @throws CryptoException with the following reason code:

    48 | *
  • CryptoException.ILLEGAL_VALUE if input data decryption is required and fails. 49 | *
50 | * @throws ArrayIndexOutOfBoundsException if kOff is negative or the keyData array is too short 51 | * @throws NullPointerException if the keyData parameter is null 52 | */ 53 | void setKey(byte[] keyData, short kOff) throws CryptoException, NullPointerException, ArrayIndexOutOfBoundsException; 54 | 55 | /** 56 | * Returns the Key data in plain text. The length of output key data 57 | * is 16 bytes for Korean Seed Algorithm. 58 | * The data format is big-endian and right-aligned 59 | * (the least significant bit is the least significant 60 | * bit of last byte). 61 | *

62 | * 63 | * @param keyData byte array to return key data 64 | * @param kOff offset within keyData to start 65 | * @return the byte length of the key data returned 66 | * @throws CryptoException with the following reason code:

    67 | *
  • 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. 68 | *
69 | * @see Key 70 | */ 71 | byte getKey(byte[] keyData, short kOff); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/javacard/security/PrivateKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * 21 | * The PrivateKey interface is the base interface for private keys used in asymmetric algorithms. 22 | */ 23 | public interface PrivateKey 24 | extends Key 25 | { 26 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/PublicKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * 21 | * The PublicKey interface is the base interface for public keys used in asymmetric algorithms. 22 | */ 23 | public interface PublicKey 24 | extends Key 25 | { 26 | } -------------------------------------------------------------------------------- /src/main/java/javacard/security/RandomData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | import com.licel.jcardsim.crypto.RandomDataImpl; 20 | 21 | 22 | /** 23 | * 24 | * The RandomData abstract class is the base class for random number generation. 25 | * Implementations of RandomData 26 | * algorithms must extend this class and implement all the abstract methods. 27 | */ 28 | public abstract class RandomData { 29 | 30 | /** 31 | * Utility pseudo-random number generation algorithms. The random number sequence 32 | * generated by this algorithm need not be the same even if seeded with the same 33 | * seed data. 34 | *

Even if a transaction is in progress, the update of the internal state 35 | * shall not participate in the transaction. 36 | */ 37 | public static final byte ALG_PSEUDO_RANDOM = 1; 38 | /** 39 | * Cryptographically secure random number generation algorithms. 40 | */ 41 | public static final byte ALG_SECURE_RANDOM = 2; 42 | 43 | /** 44 | * Protected constructor for subclassing. 45 | */ 46 | protected RandomData() { 47 | } 48 | 49 | /** 50 | * Creates a RandomData instance of the selected algorithm. 51 | * The pseudo random RandomData instance's seed is initialized to a internal default value. 52 | * @param algorithm the desired random number algorithm. Valid codes listed in ALG_ .. constants above. See ALG_PSEUDO_RANDOM. 53 | * @return the RandomData object instance of the requested algorithm 54 | * @throws CryptoException with the following reason codes:

    55 | *
  • CryptoException.NO_SUCH_ALGORITHM if the requested algorithm is not supported.
56 | */ 57 | public static final RandomData getInstance(byte algorithm) 58 | throws CryptoException { 59 | RandomData instance = null; 60 | switch (algorithm) { 61 | case ALG_PSEUDO_RANDOM: 62 | case ALG_SECURE_RANDOM: // WARNING: ALG_SECURE_RANDOM implemented as PRNG!!! 63 | instance = new RandomDataImpl(); 64 | break; 65 | default: 66 | CryptoException.throwIt((short) 3); 67 | break; 68 | } 69 | return instance; 70 | } 71 | 72 | /** 73 | * Generates random data. 74 | * @param buffer the output buffer 75 | * @param offset the offset into the output buffer 76 | * @param length the length of random data to generate 77 | * @throws CryptoException with the following reason codes:
    78 | *
  • CryptoException.ILLEGAL_VALUE if the length parameter is 79 | * zero.
80 | */ 81 | public abstract void generateData(byte[] buffer, short offset, short length) 82 | throws CryptoException; 83 | 84 | /** 85 | * Seeds the random data generator. 86 | * @param buffer the input buffer 87 | * @param offset the offset into the input buffer 88 | * @param length the length of the seed data 89 | */ 90 | public abstract void setSeed(byte[] buffer, short offset, short length); 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/javacard/security/SecretKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacard.security; 18 | 19 | /** 20 | * 21 | * The SecretKey class is the base interface for keys 22 | * used in symmetric algorithms (DES, for example). 23 | */ 24 | public interface SecretKey 25 | extends Key 26 | { 27 | } -------------------------------------------------------------------------------- /src/main/java/javacardx/apdu/ExtendedLength.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacardx.apdu; 17 | 18 | /** 19 | * The ExtendedLength interface serves as a tagging interface to indicate that the applet 20 | * supports extended length APDU. If this interface is implemented by the applet instance, 21 | * the applet may receive and send up to 32767 bytes of APDU data. 22 | * 23 | *

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

26 | * 27 | * @see "Runtime Environment Specification for the Java Card Platform for details." 28 | * @since 2.2.2 29 | */ 30 | public interface ExtendedLength { 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/javacardx/crypto/KeyEncryption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package javacardx.crypto; 18 | 19 | /** 20 | *KeyEncryption interface defines the methods used to enable encrypted 21 | * key data access to a key implementation. 22 | *

23 | */ 24 | public interface KeyEncryption { 25 | 26 | /** 27 | * Sets the Cipher object to be used to decrypt the input key data 28 | * and key parameters in the set methods.

29 | * Default Cipher object is null - no decryption performed. 30 | * @param keyCipher the decryption Cipher object to decrypt the input key data. 31 | * The null parameter indicates that no decryption is required. 32 | */ 33 | public void setKeyCipher(Cipher keyCipher); 34 | 35 | /** 36 | * Returns the Cipher object to be used to decrypt the input key data 37 | * and key parameters in the set methods.

38 | * Default is null - no decryption performed. 39 | * @return keyCipher, the decryption Cipher object to decrypt the input key data. 40 | * The null return indicates that no decryption is performed. 41 | */ 42 | public Cipher getKeyCipher(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/javacardx/framework/math/ParityBit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 FH OOe Forschungs & Entwicklungs GmbH, Michael Roland. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package javacardx.framework.math; 17 | 18 | /** 19 | * The ParityBit class is a utility to assist with DES key parity bit generation. 20 | * 21 | * @since 2.2.2 22 | */ 23 | public final class ParityBit { 24 | public ParityBit() { 25 | } 26 | 27 | /** 28 | * Inserts the computed parity bit of the specified type as the last bit(LSB) in each 29 | * of the bytes of the specified byte array. The parity is computed over the first(MS) 30 | * 7 bits of each byte. The incoming last bit of each byte is ignored. 31 | * 32 | *

Note: 33 | *

    34 | *
  • If bOff or bLen is negative an ArrayIndexOutOfBoundsException exception is thrown.
  • 35 | *
  • If bLen is equal to 0 no parity bits are inserted.
  • 36 | *
  • If bOff+bLen is greater than bArray.length, the length of 37 | * the bArray array a ArrayIndexOutOfBoundsException exception is 38 | * thrown and no parity bits are inserted.
  • 39 | *
  • If bArray is null a NullPointerException exception is thrown.
  • 40 | *

41 | * 42 | * @param bArray input/output byte array 43 | * @param bOff offset within byte array to start setting parity on 44 | * @param bLen byte length of input/output bytes 45 | * @param isEven true if even parity is required and false if odd parity is required 46 | * @throws NullPointerException if bArray is null 47 | * @throws ArrayIndexOutOfBoundsException if accessing the input array would cause access of data outside array bounds or if bLen is negative 48 | */ 49 | public static void set(byte[] bArray, short bOff, short bLen, boolean isEven) { 50 | if ((bOff < 0) || (bLen < 0)) throw new ArrayIndexOutOfBoundsException(); 51 | if ((bOff + bLen) > bArray.length) throw new ArrayIndexOutOfBoundsException(); 52 | 53 | for (short i = bOff; i < (short)(bOff + bLen); ++i) { 54 | byte c = (byte)((byte)(bArray[i] >> 1) & 0x7F); 55 | byte p = 0; 56 | while (c != 0) { 57 | if ((byte)(c & 0x1) == 1) { 58 | p = (byte)(1 - p); 59 | } 60 | c = (byte)(c >> 1); 61 | } 62 | bArray[i] = (byte)((byte)(bArray[i] & 0xFE) | (isEven ? p : (byte)(1 - p))); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/AsymmetricCipherImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.security.KeyBuilder; 20 | import javacard.security.KeyPair; 21 | import javacard.security.RandomData; 22 | import javacardx.crypto.Cipher; 23 | import junit.framework.TestCase; 24 | import org.bouncycastle.util.Arrays; 25 | 26 | /** 27 | * Test for AsymmetricCipherImpl 28 | * Test data from NXP JCOP31-36 JavaCard 29 | */ 30 | public class AsymmetricCipherImplTest extends TestCase { 31 | 32 | public AsymmetricCipherImplTest(String testName) { 33 | super(testName); 34 | } 35 | 36 | protected void setUp() throws Exception { 37 | super.setUp(); 38 | } 39 | 40 | protected void tearDown() throws Exception { 41 | super.tearDown(); 42 | } 43 | 44 | /** 45 | * SelfTest of RSA Encryption/Decryption, of class AsymmetricCipherImpl. 46 | */ 47 | public void testSelftRSA() { 48 | Cipher cipher = Cipher.getInstance(Cipher.ALG_RSA_NOPAD, false); 49 | KeyPair kp = new KeyPair(KeyPair.ALG_RSA_CRT, KeyBuilder.LENGTH_RSA_1024); 50 | kp.genKeyPair(); 51 | 52 | cipher.init(kp.getPublic(), Cipher.MODE_ENCRYPT); 53 | byte[] msg = JCSystem.makeTransientByteArray((short) 127, JCSystem.CLEAR_ON_RESET); 54 | byte[] encryptedMsg = JCSystem.makeTransientByteArray((short) 128, JCSystem.CLEAR_ON_RESET); 55 | RandomData rnd = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); 56 | rnd.generateData(msg, (short) 0, (short) msg.length); 57 | cipher.doFinal(msg, (short) 0, (short) msg.length, encryptedMsg, (short) 0); 58 | 59 | cipher.init(kp.getPrivate(), Cipher.MODE_DECRYPT); 60 | byte[] decryptedMsg = JCSystem.makeTransientByteArray((short) msg.length, JCSystem.CLEAR_ON_RESET); 61 | cipher.doFinal(encryptedMsg, (short) 0, (short) encryptedMsg.length, decryptedMsg, (short) 0); 62 | 63 | assertEquals(true, Arrays.areEqual(msg, decryptedMsg)); 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/CRC16Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.security.Checksum; 20 | import junit.framework.TestCase; 21 | import org.bouncycastle.util.Arrays; 22 | import org.bouncycastle.util.encoders.Hex; 23 | 24 | /** 25 | * Test for CRC16 26 | * Test data from NXP JCOP31-36 JavaCard 27 | */ 28 | public class CRC16Test extends TestCase { 29 | 30 | // etalon msg 31 | String MESSAGE = "C46A3D01F5494013F9DFF3C5392C64"; 32 | // etalon crc 33 | String CRC = "0B93"; 34 | 35 | public CRC16Test(String testName) { 36 | super(testName); 37 | } 38 | 39 | protected void setUp() throws Exception { 40 | super.setUp(); 41 | } 42 | 43 | protected void tearDown() throws Exception { 44 | super.tearDown(); 45 | } 46 | 47 | /** 48 | * Test of of class CRC16. 49 | */ 50 | public void testCrc16() { 51 | System.out.println("test crc16"); 52 | Checksum crcEngine = Checksum.getInstance(Checksum.ALG_ISO3309_CRC16, false); 53 | byte[] crc = JCSystem.makeTransientByteArray((short) 2, JCSystem.CLEAR_ON_RESET); 54 | byte[] msg = Hex.decode(MESSAGE); 55 | crcEngine.doFinal(msg, (short) 0, (short) msg.length, crc, (short) 0); 56 | assertEquals(true, Arrays.areEqual(Hex.decode(CRC), crc)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/CRC32Test.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.security.Checksum; 20 | import junit.framework.TestCase; 21 | import org.bouncycastle.util.Arrays; 22 | import org.bouncycastle.util.encoders.Hex; 23 | 24 | /** 25 | * Test for CRC32 26 | * Test data from NXP JCOP31-36 JavaCard 27 | */ 28 | public class CRC32Test extends TestCase { 29 | 30 | // etalon msg 31 | String MESSAGE = "C46A3D01F5494013F9DFF3C5392C64"; 32 | // etalon crc 33 | String CRC = "7C6277D0"; 34 | 35 | public CRC32Test(String testName) { 36 | super(testName); 37 | } 38 | 39 | protected void setUp() throws Exception { 40 | super.setUp(); 41 | } 42 | 43 | protected void tearDown() throws Exception { 44 | super.tearDown(); 45 | } 46 | 47 | /** 48 | * Test of of class CRC16. 49 | */ 50 | public void testCrc32() { 51 | System.out.println("test crc32"); 52 | Checksum crcEngine = Checksum.getInstance(Checksum.ALG_ISO3309_CRC32, false); 53 | byte[] crc = JCSystem.makeTransientByteArray((short) 4, JCSystem.CLEAR_ON_RESET); 54 | byte[] msg = Hex.decode(MESSAGE); 55 | crcEngine.doFinal(msg, (short) 0, (short) msg.length, crc, (short) 0); 56 | assertEquals(true, Arrays.areEqual(Hex.decode(CRC), crc)); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/ECKeyImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import java.security.SecureRandom; 19 | import javacard.security.KeyBuilder; 20 | import junit.framework.TestCase; 21 | import org.bouncycastle.crypto.params.ECKeyGenerationParameters; 22 | import org.bouncycastle.math.ec.ECCurve; 23 | 24 | /** 25 | * Test for ECKeyImplTest. 26 | */ 27 | public class ECKeyImplTest extends TestCase { 28 | 29 | public ECKeyImplTest(String testName) { 30 | super(testName); 31 | } 32 | 33 | @Override 34 | protected void setUp() throws Exception { 35 | super.setUp(); 36 | } 37 | 38 | @Override 39 | protected void tearDown() throws Exception { 40 | super.tearDown(); 41 | } 42 | /** 43 | * Test of getKeyGenerationParameters method, of class ECKeyImpl. 44 | */ 45 | public void testGetKeyGenerationParameters() { 46 | System.out.println("getKeyGenerationParameters"); 47 | SecureRandom rnd = new SecureRandom(); 48 | // public 49 | ECKeyImpl instance = new ECPublicKeyImpl(KeyBuilder.TYPE_EC_F2M_PUBLIC, KeyBuilder.LENGTH_EC_F2M_193); 50 | ECKeyGenerationParameters result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); 51 | assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.F2m, true); 52 | instance = new ECPublicKeyImpl(KeyBuilder.TYPE_EC_FP_PUBLIC, KeyBuilder.LENGTH_EC_FP_192); 53 | result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); 54 | assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.Fp, true); 55 | //private 56 | instance = new ECPrivateKeyImpl(KeyBuilder.TYPE_EC_F2M_PRIVATE, KeyBuilder.LENGTH_EC_F2M_193); 57 | result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); 58 | assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.F2m, true); 59 | instance = new ECPrivateKeyImpl(KeyBuilder.TYPE_EC_FP_PRIVATE, KeyBuilder.LENGTH_EC_FP_192); 60 | result = (ECKeyGenerationParameters) instance.getKeyGenerationParameters(rnd); 61 | assertEquals(result.getDomainParameters().getCurve()instanceof ECCurve.Fp, true); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/KeyAgreementImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.security.ECPublicKey; 19 | import javacard.security.KeyAgreement; 20 | import javacard.security.KeyBuilder; 21 | import javacard.security.KeyPair; 22 | import javacard.security.PrivateKey; 23 | import junit.framework.TestCase; 24 | import org.bouncycastle.util.Arrays; 25 | 26 | /** 27 | * Test for KeyAgreementImpl 28 | * Test data from NXP JCOP31-36 JavaCard 29 | */ 30 | public class KeyAgreementImplTest extends TestCase { 31 | 32 | public KeyAgreementImplTest(String testName) { 33 | super(testName); 34 | } 35 | 36 | protected void setUp() throws Exception { 37 | super.setUp(); 38 | } 39 | 40 | protected void tearDown() throws Exception { 41 | super.tearDown(); 42 | } 43 | 44 | /** 45 | * SelfTest of generateSecret method with ECDH algorithm, 46 | * of class KeyAgreementImpl. 47 | */ 48 | public void testGenerateSecretECDH() { 49 | System.out.println("test ecdh"); 50 | testGenerateSecret(KeyPair.ALG_EC_F2M, KeyBuilder.LENGTH_EC_F2M_113, KeyAgreement.ALG_EC_SVDP_DH); 51 | testGenerateSecret(KeyPair.ALG_EC_FP, KeyBuilder.LENGTH_EC_FP_112, KeyAgreement.ALG_EC_SVDP_DH); 52 | System.out.println("test ecdhc"); 53 | testGenerateSecret(KeyPair.ALG_EC_F2M, KeyBuilder.LENGTH_EC_F2M_113, KeyAgreement.ALG_EC_SVDP_DHC); 54 | testGenerateSecret(KeyPair.ALG_EC_FP, KeyBuilder.LENGTH_EC_FP_112, KeyAgreement.ALG_EC_SVDP_DHC); 55 | } 56 | 57 | /** 58 | * Base method generateSecret 59 | * @param keyAlg - key generation algorithm 60 | * @param keySize - key size 61 | * @param keyAgreementAlg - key agreement algorithm 62 | */ 63 | public void testGenerateSecret(byte keyAlg, short keySize, byte keyAgreementAlg) { 64 | // generate keys 65 | KeyPair kp = new KeyPair(keyAlg, keySize); 66 | kp.genKeyPair(); 67 | PrivateKey privateKey1 = kp.getPrivate(); 68 | ECPublicKey publicKey1 = (ECPublicKey) kp.getPublic(); 69 | kp.genKeyPair(); 70 | PrivateKey privateKey2 = kp.getPrivate(); 71 | ECPublicKey publicKey2 = (ECPublicKey) kp.getPublic(); 72 | // generate first secret 73 | KeyAgreement ka = KeyAgreement.getInstance(keyAgreementAlg, false); 74 | byte[] secret1 = new byte[128]; 75 | byte[] public2 = new byte[128]; 76 | short publicKeyLength = publicKey2.getW(public2, (short) 0); 77 | ka.init(privateKey1); 78 | ka.generateSecret(public2, (short) 0, publicKeyLength, secret1, (short) 0); 79 | // generate second secret 80 | byte[] secret2 = new byte[128]; 81 | byte[] public1 = new byte[128]; 82 | publicKeyLength = publicKey1.getW(public1, (short) 0); 83 | ka.init(privateKey2); 84 | ka.generateSecret(public1, (short) 0, publicKeyLength, secret2, (short) 0); 85 | assertEquals(true, Arrays.areEqual(secret1, secret2)); 86 | } 87 | } -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/RSAPrivateCrtKeyImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import junit.framework.TestCase; 19 | import org.bouncycastle.util.encoders.Hex; 20 | 21 | /** 22 | * Test for RSAPrivateCrtKeyImpl 23 | * Test data from NXP JCOP31-36 JavaCard* 24 | */ 25 | public class RSAPrivateCrtKeyImplTest extends TestCase { 26 | // RSA CRT Private Key Components (2048-bit) 27 | 28 | final static String P = "DA2CBBE7572AE9441538EFE23943A6C72B564482E482D50954769920AD4A45179D2842327BF8271C592FA9D6DCCAE737B45BCA4A3B026CF5C32E6008284D8ABA3A1B249EF900CCF40746C599D9217EC3D1179DC35976AE05A50CF6F8AE23E15B8E0D4481D1D6035826AB7F43CECEB511699814BF2EFCF0EA37E230C4F586E6C7"; 29 | final static String Q = "A5CDB97E613BDE20D7938C102DBB1D4F3B7BE88A1E7919329F7207F044B2A1560FB370C742A7E15C5BBF77AC2463AB9C00B7FF2B765E1EECF4ED5F2F5DDA8476BCF6F154286154C4CC9C51FDEBEAFE8630D299A03AE306B7179D83328A1D18301E2C66AA94A802EB4FF34291C43E2BA4A3642965B5322DBBDCF5D016718070D7"; 30 | final static String DP = "AA732286557A87ED91EAFEB6ADE865A6DAFBB5E0D12849C9D53C26DBF9A6B99DFE41129EA06DBA1892B1032E8326DE478DD7DC8DEBD6344C3925C50EFA75C23945E628D12E566AC907DA49CCAD6F56BB236320F51AB2F6B8203FA5BF99451CEE4B67A02B1045F42CED6134B7441E08264769F2637F114C22A0704D8BC30A96C7"; 31 | final static String DQ = "94B23E9437F1B011B6246E2DA845B25077A1757841420BB619C6F395A896A7187EB648037C2501788A13D9E8B92DE61EDF8A243F3F45C3E870F45D3426B0ADB1AB60B027F09AF1A2197A6C1214BD488CE2464D5EA4D12C199205423F561C27B027AF5C57C940307606DABC2DEC58715D92E76634FFDEC3A342D3F54DDB76FC3B"; 32 | final static String PQ = "92CC66692E8D14EB93D0705EFA58276CD7A1A8B82C17544E8D181C3F987ED62E83355844D2E89380A17169614D8367709CB62A3DF9339BD537078AD1629D1B87DCA66E31809ADB78746633C28A6EA064B34EF750C27E32800ECE3C5F17524D35EE3CEAE8989745EAECD411D519210D4FCD699F4218A22249F76BE75A2F8160A0"; 33 | 34 | public RSAPrivateCrtKeyImplTest(String testName) { 35 | super(testName); 36 | } 37 | 38 | @Override 39 | protected void setUp() throws Exception { 40 | super.setUp(); 41 | } 42 | 43 | @Override 44 | protected void tearDown() throws Exception { 45 | super.tearDown(); 46 | } 47 | 48 | /** 49 | * Test of isInitialized method, of class RSAPrivateCrtKeyImpl. 50 | */ 51 | public void testIsInitialized() { 52 | System.out.println("isInitialized"); 53 | RSAPrivateCrtKeyImpl key = new RSAPrivateCrtKeyImpl((short)2048); 54 | short compLen = (short) Hex.decode(P).length; 55 | key.setP(Hex.decode(P), (short)0, compLen); 56 | key.setQ(Hex.decode(Q), (short)0, compLen); 57 | key.setDP1(Hex.decode(DP), (short)0, compLen); 58 | key.setDQ1(Hex.decode(DQ), (short)0, compLen); 59 | key.setPQ(Hex.decode(PQ), (short)0, compLen); 60 | assertEquals(true, key.isInitialized()); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/test/java/com/licel/jcardsim/crypto/RandomDataImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2011 Licel LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package com.licel.jcardsim.crypto; 17 | 18 | import javacard.framework.JCSystem; 19 | import javacard.security.RandomData; 20 | import junit.framework.TestCase; 21 | 22 | /** 23 | * Test for RandomDataImpl 24 | */ 25 | public class RandomDataImplTest extends TestCase { 26 | 27 | public RandomDataImplTest(String testName) { 28 | super(testName); 29 | } 30 | 31 | protected void setUp() throws Exception { 32 | super.setUp(); 33 | } 34 | 35 | protected void tearDown() throws Exception { 36 | super.tearDown(); 37 | } 38 | 39 | /** 40 | * Test of generateData method, of class RandomDataImpl. 41 | */ 42 | public void testGenerateData() { 43 | System.out.println("generateData"); 44 | byte[] buffer = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); 45 | RandomData instance = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); 46 | instance.generateData(buffer, (short) 0, (short) buffer.length); 47 | instance = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM); 48 | instance.generateData(buffer, (short) 0, (short) buffer.length); 49 | } 50 | 51 | /** 52 | * Test of setSeed method, of class RandomDataImpl. 53 | */ 54 | public void testSetSeed() { 55 | System.out.println("setSeed"); 56 | byte[] buffer = JCSystem.makeTransientByteArray((short) 8, JCSystem.CLEAR_ON_RESET); 57 | RandomData instance = RandomData.getInstance(RandomData.ALG_PSEUDO_RANDOM); 58 | instance.setSeed(buffer, (short) 0, (short) buffer.length); 59 | instance.generateData(buffer, (short) 0, (short) buffer.length); 60 | instance = RandomData.getInstance(RandomData.ALG_SECURE_RANDOM); 61 | instance.setSeed(buffer, (short) 0, (short) buffer.length); 62 | instance.generateData(buffer, (short) 0, (short) buffer.length); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/java/javacard/framework/UtilTest.java: -------------------------------------------------------------------------------- 1 | package javacard.framework; 2 | 3 | import junit.framework.TestCase; 4 | 5 | public class UtilTest extends TestCase { 6 | 7 | /** 8 | * 9 | */ 10 | public void testArrayCompare1() { 11 | byte[] src = new byte[]{0x01}; 12 | byte[] dest = new byte[]{0x02}; 13 | byte res = Util.arrayCompare(src, (short) 0, dest, (short) 0, (short) 1); 14 | assertEquals(-1, res); 15 | } 16 | 17 | /** 18 | * 19 | */ 20 | public void testArrayCompare2() { 21 | byte[] src = new byte[]{(byte) 0xff}; 22 | byte[] dest = new byte[]{0x01}; 23 | byte res = Util.arrayCompare(src, (short) 0, dest, (short) 0, (short) 1); 24 | assertEquals(1, res); 25 | } 26 | 27 | /** 28 | * Test of arrayFillNonAtomic method, of class Util. 29 | */ 30 | public void testArrayFillNonAtomic() { 31 | System.out.println("arrayFillNonAtomic"); 32 | byte[] etalonArray = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0}; 33 | System.out.println(etalonArray.length); 34 | byte[] bArray = new byte[16]; 35 | short bOff = 8; 36 | short bLen = 7; 37 | byte bValue = 1; 38 | short expResult = (short) (bOff + bLen); 39 | short result = Util.arrayFillNonAtomic(bArray, bOff, bLen, bValue); 40 | assertEquals(expResult, result); 41 | byte res = Util.arrayCompare(bArray, (short) 0, etalonArray, (short) 0, (short) 16); 42 | assertEquals(0, res); 43 | } 44 | } 45 | --------------------------------------------------------------------------------