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

Project cleanup #1

Merged
merged 12 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 22 additions & 0 deletions .github/scripts/check_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh

tag=$1
echo "Input tag: '$tag'"

version=`grep "^version" gradle.properties | cut -d= -f2 | tr -d "[:space:]"`
echo "Version in 'gradle.properties' file: '$version'"

if [ "$tag" != "" ]; then
echo "Release mode: check version consistency..."
if [ "$tag" != "$version" ]; then
echo "ERROR: the tag '$tag' is different from the version '$version' in the 'gradle.properties' file"
exit 1
fi
else
echo "Snapshot mode: fetch existing tags..."
git fetch --tags
if [ $(git tag -l "$version") ]; then
echo "ERROR: version '$version' has already been released"
exit 1
fi
fi
28 changes: 28 additions & 0 deletions .github/workflows/java-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Compile and Test

on:
pull_request:
branches:
- main
workflow_dispatch: # To authorize manual run

jobs:
java-test:
runs-on: ubuntu-latest
steps:
- name: Check out repository code from ${{ github.repository }}/${{ github.ref }}
uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
- name: Update permissions
working-directory: .
run: chmod +x ./gradlew ./.github/scripts/*.sh
- name: Check version
working-directory: .
run: ./.github/scripts/check_version.sh
- name: Build and Test
working-directory: .
run: ./gradlew build test --info --stacktrace
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
143 changes: 142 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,142 @@
# keyple-java-tool
## Introduction

This Git repository contains a set of tools for facilitating interaction with Calypso cards and analyzing their file
structure. The tools are developed and maintained by the [Calypso Networks Association](https://calypsonet.org).

This document provides a detailed description of the tools, including their features, usage, dependencies, license, and
copyright information. Although there are two separate executables, they offer closely related and interconnected
functionalities for working with Calypso cards.

---

## Calypso Card Analyzer

The Calypso Card Analyzer is a tool for analyzing the file structure of a Calypso smart card. It retrieves the card's
data and generates a JSON report containing the card's structure and application data.

### Features

- Analyze the file structure of a Calypso smart card
- Retrieve card data and application data
- Generate a JSON report containing the card's structure and application data

### Program workflow

1. Initialize the smart card reader and check if a card is present.
2. Retrieve the traceability information of the card.
3. Get the application data for each AID (Application Identifier) in the provided AID list.
4. Create a `CardStructureData` object containing the traceability information, software information, and application
data.
5. Convert the `CardStructureData` object to a JSON string using the Gson library.
6. Write the JSON string to a file with a name based on the current date and the card's serial number.
7. Print the JSON string to the console.

---

## Calypso Card File Structure Checker

The Calypso Card File Structure Checker is a tool for checking the file structure of a Calypso card against a given JSON
file containing the expected file structure.

### Features

- Check the file structure of a Calypso card against a given JSON file
- Compare the expected file structure with the actual file structure of the card
- Print the differences between the expected and actual file structures to the console

### Program workflow

1. Load the expected file structure from a JSON file.
2. Initialize the smart card reader and check if a card is present.
3. Retrieve the actual file structure of the card.
4. Compare the expected file structure with the actual file structure.
5. Print the differences between the expected and actual file structures to the console.

---

## Building and Using the Tools

### Building the JARs

To build the JARs for the Calypso Card Analyzer and Calypso Card File Structure Checker tools, follow these steps:

1. Clone this Git repository to your local machine.
2. Open a terminal and navigate to the root directory of the project.
3. Run the following command to build the JARs:

```bash
./gradlew build
```

After running this command, the JARs will be generated in the `build/libs` directory of the project.

### Using the Calypso Card Analyzer JAR

To use the Calypso Card Analyzer JAR, follow these steps:

1. Download the Calypso Card Analyzer JAR from
the [releases](https://github.com/CalypsoNetworksAssociation/calypso-card-analysis-tools/releases) page of this
repository.
2. Connect a PC/SC card reader to your computer.
3. Insert a Calypso card into the reader.
4. Open a terminal and navigate to the directory containing the downloaded JAR.
5. Run the following command:

```bash
java -jar Tool_AnalyzeCardFileStructure.jar [readerNameRegex]
```

The `readerNameRegex` parameter is optional and can be used to specify a regular expression for selecting the card reader
to use. If this parameter is not provided, the tool will use the following
expression `.*(ASK.*|Identiv.*2|ACS ACR122U|SCR3310).*`.

The Calypso Card Analyzer tool will read the card and generate a JSON report containing the card's structure and
application data.

### Using the Calypso Card File Structure Checker JAR

To use the Calypso Card File Structure Checker JAR, follow these steps:

1. Download the Calypso Card File Structure Checker JAR from
the [releases](https://github.com/CalypsoNetworksAssociation/calypso-card-analysis-tools/releases) page of this
repository.
2. Connect a PC/SC card reader to your computer.
3. Insert a Calypso card into the reader.
4. Open a terminal and navigate to the directory containing the downloaded JAR.
5. Run the following command:

```bash
java -jar Tool_CheckCardFileStructure.jar <json_file_name> [readerNameRegex]
```

Replace `<json_file_name>` with the name of the JSON file containing the reference file structure.

The `readerNameRegex` parameter is optional and can be used to specify a regular expression for selecting the card reader
to use. If this parameter is not provided, the tool will use the following
expression `.*(ASK.*|Identiv.*2|ACS ACR122U|SCR3310).*`.

For example, if you want to use the `TestKit_CalypsoPrimeRegularProfile_v3.json` card profile provided in
the `card_profiles` directory, you can run the following command:

```bash
java -jar Tool_CheckCardFileStructure.jar card_profiles/TestKit_CalypsoPrimeRegularProfile_v3.json
```

The tool will then read the reference file structure from the specified JSON file, check if a card is present in the
reader, and perform the necessary checks. The verification results will be displayed in the console.

### Dependencies

- Eclipse Keyple Core
- Eclipse Keyple Calypso Extension
- Eclipse Keyple PC/SC Plugin
- Google Gson

### License

This program is made available under the terms of the Eclipse Public License 2.0. See the [LICENSE](LICENSE) file for
more information.

### Copyright

Copyright (c) 2024 [Calypso Networks Association](https://calypsonet.org)
39 changes: 30 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ repositories {
maven(url = "https://s01.oss.sonatype.org/content/repositories/snapshots")
}
dependencies {
implementation("org.calypsonet.terminal:calypsonet-terminal-reader-java-api:1.3.+") { isChanging = true }
implementation("org.calypsonet.terminal:calypsonet-terminal-calypso-java-api:1.8.+") { isChanging = true }
implementation("org.eclipse.keyple:keyple-common-java-api:2.0.+") { isChanging = true }
implementation("org.eclipse.keyple:keyple-service-java-lib:2.3.+") { isChanging = true }
implementation("org.eclipse.keyple:keyple-plugin-pcsc-java-lib:2.1.+") { isChanging = true }
implementation("org.eclipse.keyple:keyple-card-calypso-java-lib:2.2.0")
implementation("org.eclipse.keyple:keyple-util-java-lib:2.+") { isChanging = true }
// Begin Keyple configuration (generated by 'https://keyple.org/components/overview/configuration-wizard/')
implementation("org.eclipse.keypop:keypop-reader-java-api:2.0.0")
implementation("org.eclipse.keypop:keypop-calypso-card-java-api:2.0.0")
implementation("org.eclipse.keyple:keyple-common-java-api:2.0.0")
implementation("org.eclipse.keyple:keyple-util-java-lib:2.3.1")
implementation("org.eclipse.keyple:keyple-service-java-lib:3.1.0")
implementation("org.eclipse.keyple:keyple-card-calypso-java-lib:3.0.1")
implementation("org.eclipse.keyple:keyple-plugin-pcsc-java-lib:2.1.2")
// End Keyple configuration
implementation("org.slf4j:slf4j-simple:1.7.32")
implementation("com.google.code.gson:gson:2.8.5")
}
Expand Down Expand Up @@ -64,7 +66,7 @@ tasks {
archiveClassifier.set("Analyze-fat")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes("Main-Class" to "org.cna.keyple.tool.card.Tool_AnalyzeCardFileStructure")
attributes("Main-Class" to "org.calypsonet.tool.calypso.card.Tool_AnalyzeCardFileStructure")
}
from(configurations.runtimeClasspath.get()
.onEach { println("add from dependencies: ${it.name}") }
Expand All @@ -73,4 +75,23 @@ tasks {
sourcesMain.allSource.forEach { println("add from sources: ${it.name}") }
from(sourcesMain.output)
}
}
register("fatJarCheck", Jar::class.java) {
archiveClassifier.set("Check-fat")
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes("Main-Class" to "org.calypsonet.tool.calypso.card.Tool_CheckCardFileStructure")
}
from(configurations.runtimeClasspath.get()
.onEach { println("add from dependencies: ${it.name}") }
.map { if (it.isDirectory) it else zipTree(it) })
val sourcesMain = sourceSets.main.get()
sourcesMain.allSource.forEach { println("add from sources: ${it.name}") }
from(sourcesMain.output)
}
}

afterEvaluate {
tasks.named("build").configure {
dependsOn(tasks.named("fatJarAnalyze"), tasks.named("fatJarCheck"))
}
}
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
group = org.cna.keyple
title = Keyple Card Calypso Java Tools
description = Card Calypso tools using the API of the Keyple solution.
group = org.calypsonet.tool
title = Calypso card analyzer
description = Calypso card tools dedicated to file structures analysis.
version = 2.0.0

javaSourceLevel = 1.7
javaTargetLevel = 1.7
javaSourceLevel = 1.8
javaTargetLevel = 1.8
Loading