Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API 1_SUCCESS_TEST jcardsim #7

Open
wants to merge 47 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d64f58d
API 1_SUCCESS_TEST jcardsim
Jan 3, 2020
834a4cb
Call Applet::register() outside constructor
Jan 6, 2020
cd81ec1
Save 3 bytes in applet
Jan 6, 2020
65745f4
gradle-javacard version 1.6.8 is ok but 1.6.3 has lesser false warnings
Jan 6, 2020
55c985c
Update jcsh scripts
Jan 7, 2020
1d8b27e
Check if secure messaging (gpspec211 9.1.4 Class Byte Coding)
Jan 8, 2020
c763c3f
Add gathered notes
Jan 8, 2020
f74dae1
Added initial datastorage test cases
Jan 8, 2020
3eac937
Add ICardConnection interface; rename applet appropriately
Jan 9, 2020
8f8ac42
Use annotations to declare config; add tracer applet; remove un-used …
Jan 10, 2020
ae3a328
Add DecodeApplet.java development applet for diagnostic use
Jan 10, 2020
6b1fd89
Group static member fields; improve checks
Jan 13, 2020
3c3b597
Add plumbing code for physical card
Jan 14, 2020
b79745f
Instantiate Security provider in CryptoAPI class
Jan 14, 2020
7e12484
Change static to singleton instance; transfer secure channel from app…
Jan 15, 2020
00f46f6
Changes for a unified design, common code between physical and simulator
Jan 16, 2020
c13d157
Delete Physical.java because OffCard.java is physical, one-less state…
Jan 16, 2020
2821e52
Consistent variable naming
Jan 16, 2020
8cf95a2
Stronger type check with enum instead of System.getProperty()
Jan 16, 2020
dad898d
Add keyset management plumbing.
Jan 19, 2020
fb22fcf
Completely start new jcardsim per test case
Jan 19, 2020
7c843bd
Better placement of applet's simulated secureChannel from OffCard.jav…
Jan 20, 2020
a46ebe9
Disable physical test in circleci
Jan 20, 2020
260d587
Rename method names to match mirror classes
Jan 21, 2020
b170396
Add readme content; changes intended to increase code symmetry
Jan 21, 2020
db0f775
Add logic in gradle for smoother testing
Jan 21, 2020
207a183
Set CLA to 0x00 as OffCard can set new CLA based on scp02
Jan 21, 2020
e9af9d7
Remove unwanted try/catch blocks
Jan 22, 2020
a6746d1
Fix typo in a CommandAPDU
Jan 22, 2020
8d056fd
Gradually pulling-out inner assertions to be able to express these in…
Jan 22, 2020
b4e927a
Remove filter of gradle test
Jan 22, 2020
34857f3
Add protection check in circleci no PCSC
Jan 22, 2020
5dbfd6b
Add card-sign-applet repo
Feb 3, 2020
b25dffc
Implement scp02 unwrap; Add more physical test cases
Feb 4, 2020
d3e59b6
Fix typo verifierTemplateData
Feb 4, 2020
dc5c905
Normalize return array to be []; Add TODO comments; Rename to Dump.java
Feb 5, 2020
36b1052
Updating track of card-sign-applet submodule
Feb 5, 2020
205197d
Fix install params on physical card testing
Feb 6, 2020
6fbe00d
Add physical card signing test case to check JCSystem.CLEAR_ON_RESET …
Feb 6, 2020
21078ab
Add signTransactionTest Ethereum signing test case for SignApplet::si…
Feb 10, 2020
21ac358
Use GPSystem.SecureChannel security level bit flags for readability; …
Feb 10, 2020
6ff2879
Pin these constants in SCP02 for readability
Feb 10, 2020
a4e4cfe
Readability: Unscope from SCP02 to express clearly that value is from…
Feb 10, 2020
5dd3250
Remove hardcoded pub/priv key
Feb 11, 2020
51b240f
Add Data Element TLV encoding
Feb 12, 2020
0a9ebe7
TLV testing on physical card using dev applet
Feb 13, 2020
428da6e
Add TLV construct
Feb 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
jobs:
build:
docker:
- image: circleci/openjdk:8u232-jdk
- image: mingc/android-build-box
steps:
- checkout
- run: git submodule update --init
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ build

# gradle stuff
/.gradle
*.swp
libs/globalplatform-2_1_1/META-INF/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "datastorage"]
path = datastorage
url = ssh://[email protected]/idpass/card-storage-applet.git
[submodule "sign"]
path = sign
url = ssh://[email protected]/idpass/card-sign-applet.git
2 changes: 1 addition & 1 deletion auth
60 changes: 55 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,59 @@
def getGitHash = { p ->
def stdout = new ByteArrayOutputStream()
exec {
if (p) workingDir p
commandLine 'git','rev-parse','HEAD'
standardOutput = stdout
}
return stdout.toString().trim()
}

def getUri = { p ->
def stdout = new ByteArrayOutputStream()
exec {
if (p) workingDir p
commandLine 'git','remote','-v'
standardOutput = stdout
}
def repoUri = stdout.toString().trim().split("\n")[0].split()[1]
return repoUri
}

def getHostname = {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'hostname'
standardOutput = stdout
}
def x = stdout.toString().trim()
return x
}

subprojects {
final def rootPath = rootDir.absolutePath
final def libs = rootPath + '/libs'
final def libs_gp211 = rootPath + '/libs/globalplatform-2_1_1'
final def libsSdk = rootPath + '/libs-sdks'
final def libs_classes = rootPath + '/build/javacard/tools.exp'

final def JC211 = libsSdk + '/jc211_kit'
final def JC212 = libsSdk + '/jc212_kit'
final def JC221 = libsSdk + '/jc221_kit'
final def JC222 = libsSdk + '/jc222_kit'
final def JC303 = libsSdk + '/jc303_kit'
final def JC304 = libsSdk + '/jc304_kit'
final def JC305u1 = libsSdk + '/jc305u1_kit'
final def JC305u2 = libsSdk + '/jc305u2_kit'
final def JC305u3 = libsSdk + '/jc305u3_kit'

ext {
_getUri = getUri
_getGitHash = getGitHash
_getHostname = getHostname
_sourceCompatibility = 1.7
_targetCompatibility = 1.7
_JC_SELECTED = JC304
}

buildscript {
repositories {
Expand All @@ -11,7 +63,7 @@ subprojects {
}

dependencies {
classpath 'com.fidesmo:gradle-javacard:0.2.7'
classpath 'com.klinec:gradle-javacard:1.6.3'
}
}

Expand All @@ -23,14 +75,12 @@ subprojects {
flatDir {
dirs libs
dirs libs_gp211
dirs libs_classes
}
}

task wrapper(type: Wrapper) {
gradleVersion = '4.7'
}
}

allprojects {
buildDir = new File(rootProject.projectDir, "build")
}

12 changes: 8 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ export JC_HOME=$(pwd)/libs-sdks/jc304_kit/
export _JAVA_OPTIONS=-Djc.home=$JC_HOME

buildoutputs='
build/javacard/org/idpass/auth/javacard/auth.cap
build/javacard/org/idpass/tools/javacard/tools.cap
build/javacard/org/idpass/sam/javacard/sam.cap
build/javacard/org/idpass/datastorage/javacard/datastorage.cap'
build/javacard/auth.cap
build/javacard/tools.exp/org/idpass/tools/javacard/tools.cap
build/javacard/sam.cap
build/javacard/datastorage.cap
build/libs/idpass_tools.jar
build/libs/idpass_auth.jar
build/libs/idpass_datastorage.jar
build/libs/idpass_sam.jar'

buildoutputscount=$(echo $buildoutputs | tr ' ' '\n' | wc -l)
./gradlew build
Expand Down
2 changes: 1 addition & 1 deletion datastorage
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Mon Dec 02 10:05:57 SGT 2019
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
Expand Down
Binary file not shown.
39 changes: 39 additions & 0 deletions offcard/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# GlobalPlatform Card Spec 2.3.1

As latest specification contains errata and precision of previous versions of the spec,
therefore will use latest specification url https://globalplatform.org/specs-library/card-specification-v2-3-1/

Older specification, for example, cited a dubious usage advise of `p2` in the `INITIALIZE_UPDATE` command.
The latest specification `v2.3.1` explicitly clarifies the value of `p2` to be always `0x00`. A mis-interpretation
of this tiny detail would lead you to think of `p2` as an option to choose one of the key.

### Applet privileges
- b8=1 indicates that the Application is a Security Domain.
- b7=1 indicates that the Security Domain has DAP Verification capability.
- b6=1 indicates that the Security Domain has Delegated Management privileges.
- b5=1 indicates that the Application has the privilege to lock the card.
- b4=1 indicates that the Application has the privilege to terminate the card.
- b3=1 indicates that the Application has the Default Selected privilege.
- b2=1 indicates that the Application has CVM management privileges.
- b1=1 indicates that the Security Domain has mandated DAP Verification capability.

### 11.1.4 Class Byte Coding (Card Specification v2.3.1)
- 0x00 Command defined in ISO/IEC 7816
- 0x80 Proprietary command
- 0x84 Proprietary command with secure messaging

### Key Type
- 0x00 - 0x7F Reserved
- 0x80 DES - mode (EBC/CBC) implicitely known
- ...

### Miscelaneous (from specs)
- The `ISD` shall be the Default Selected Application
- An initial key shall be available within the `ISD`

### Miscelaneous (from observation)
- Once a key is added, the default factory `kvno` of `0xFF` with default key `40 .. 4F` is forever lost. The offcard must explicitely declare a keyset.
- One a key is added, it cannot be deleted. But only replaced with new key value
- In the JCOP terminal, `/send` != `send`. These are the insecure and secure variations of sending an apdu
- Once a data attempts to go out from an applet **insecurely**, it resets the applet's security level to 0x00. The JCOP terminal still thinks 0x83 though.
- Always first load `tools.cap`
33 changes: 33 additions & 0 deletions offcard/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
group 'org.idpass.offcard'
version '0.0.1'

apply plugin: 'java'
sourceCompatibility = 1.8

dependencies {
compile 'com.klinec:jcardsim:3.0.5.9'
compile 'org.testng:testng:7.0.0'
implementation 'org.bouncycastle:bcprov-jdk15on:1.62'
implementation 'org.web3j:core:2.3.1'
implementation 'org.bitcoinj:bitcoinj-core:0.14.5'

// Establish build order dependency of
// org.idpass.offcard.applet/* to org.idpass.{auth,sam,datastorage}/*
compile project(':auth')
compile project(':sam')
compile project(':datastorage')
compile project(':sign')
}

test {
println "--- offcard test task ---"
filter {
includeTestsMatching "org.idpass.offcard.test.Main.*"
}

testLogging.showStandardStreams = true
outputs.upToDateWhen {false}
useTestNG()
jvmArgs '-noverify'
}

Loading