Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit 0bae260

Browse files
feat: add signature mode using "Data Cipher" command (#47)
1 parent f228088 commit 0bae260

10 files changed

+398
-244
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Added
99
- `CalypsoCard.getTransactionCounter` method (issue [#42]).
1010
- `SamRevocationServiceSpi` SPI (issue [#29]).
11-
- `SignatureComputationData` API (issue [#28]).
12-
- `SignatureVerificationData` API (issue [#29]).
11+
- `CommonSignatureComputationData`.
12+
- `BasicSignatureComputationData`.
13+
- `TraceableSignatureComputationData` API (issue [#28]).
14+
- `CommonSignatureVerificationData`.
15+
- `BasicSignatureVerificationData`.
16+
- `TraceableSignatureVerificationData` API (issue [#29]).
1317
- `CommonSecuritySetting` API.
1418
- `CommonSecuritySetting.setControlSamResource` method as a replacement for the `setSamResource` method.
1519
- `CommonSecuritySetting.getTransactionAuditData` method (issue [#44]).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* **************************************************************************************
2+
* Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional information
5+
* regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the terms of the
8+
* Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
************************************************************************************** */
12+
package org.calypsonet.terminal.calypso.transaction;
13+
14+
/**
15+
* Contains the input/output data of the {@link
16+
* CommonTransactionManager#prepareComputeSignature(CommonSignatureComputationData)} method for
17+
* basic signature computation using the "Data Cipher" SAM command.
18+
*
19+
* @since 1.2.0
20+
*/
21+
public interface BasicSignatureComputationData
22+
extends CommonSignatureComputationData<BasicSignatureComputationData> {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* **************************************************************************************
2+
* Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional information
5+
* regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the terms of the
8+
* Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
************************************************************************************** */
12+
package org.calypsonet.terminal.calypso.transaction;
13+
14+
/**
15+
* Contains the input/output data of the {@link
16+
* CommonTransactionManager#prepareVerifySignature(CommonSignatureVerificationData)} method for
17+
* basic signature verification using the "Data Cipher" SAM command.
18+
*
19+
* @since 1.2.0
20+
*/
21+
public interface BasicSignatureVerificationData
22+
extends CommonSignatureVerificationData<BasicSignatureVerificationData> {}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* **************************************************************************************
2+
* Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional information
5+
* regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the terms of the
8+
* Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
************************************************************************************** */
12+
package org.calypsonet.terminal.calypso.transaction;
13+
14+
/**
15+
* Contains the input/output data of the {@link
16+
* CommonTransactionManager#prepareComputeSignature(CommonSignatureComputationData)} method for
17+
* common signature computation modes.
18+
*
19+
* @param <T> The type of the lowest level child object.
20+
* @since 1.2.0
21+
*/
22+
public interface CommonSignatureComputationData<T extends CommonSignatureComputationData<T>> {
23+
24+
/**
25+
* Sets the data to be signed and the KIF/KVC of the key to be used for the signature computation.
26+
*
27+
* @param data The data to be signed.
28+
* @param kif The KIF of the key to be used for the signature computation.
29+
* @param kvc The KVC of the key to be used for the signature computation.
30+
* @return The current instance.
31+
* @since 1.2.0
32+
*/
33+
T setData(byte[] data, byte kif, byte kvc);
34+
35+
/**
36+
* Sets the expected size of the signature in bytes, which can be between 1 and 8 bytes
37+
* (optional).
38+
*
39+
* <p>By default, the signature will be generated on 8 bytes.
40+
*
41+
* <p>Note: the longer the signature, the more secure it is.
42+
*
43+
* @param size The expected size [1..8]
44+
* @return The current instance.
45+
* @since 1.2.0
46+
*/
47+
T setSignatureSize(int size);
48+
49+
/**
50+
* Sets a specific key diversifier to use before signing (optional).
51+
*
52+
* <p>By default, the key diversification is performed with the full serial number of the target
53+
* card or SAM depending on the transaction context (Card or SAM transaction).
54+
*
55+
* @param diversifier The diversifier to be used (from 1 to 8 bytes long).
56+
* @return The current instance.
57+
* @since 1.2.0
58+
*/
59+
T setKeyDiversifier(byte[] diversifier);
60+
61+
/**
62+
* Returns the computed signature.
63+
*
64+
* @return A byte array of 1 to 8 bytes.
65+
* @throws IllegalStateException If the command has not yet been processed.
66+
* @since 1.2.0
67+
*/
68+
byte[] getSignature();
69+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/* **************************************************************************************
2+
* Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/
3+
*
4+
* See the NOTICE file(s) distributed with this work for additional information
5+
* regarding copyright ownership.
6+
*
7+
* This program and the accompanying materials are made available under the terms of the
8+
* Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
************************************************************************************** */
12+
package org.calypsonet.terminal.calypso.transaction;
13+
14+
/**
15+
* Contains the input/output data of the {@link
16+
* CommonTransactionManager#prepareVerifySignature(CommonSignatureVerificationData)} method for
17+
* common signature verification modes.
18+
*
19+
* @param <T> The type of the lowest level child object.
20+
* @since 1.2.0
21+
*/
22+
public interface CommonSignatureVerificationData<T extends CommonSignatureVerificationData<T>> {
23+
24+
/**
25+
* Sets the signed data, the associated signature and the KIF/KVC of the key to be used for the
26+
* signature verification.
27+
*
28+
* @param data The signed data.
29+
* @param signature The associated signature.
30+
* @param kif The KIF of the key to be used for the signature verification.
31+
* @param kvc The KVC of the key to be used for the signature verification.
32+
* @return The current instance.
33+
* @since 1.2.0
34+
*/
35+
T setData(byte[] data, byte[] signature, byte kif, byte kvc);
36+
37+
/**
38+
* Sets a specific key diversifier to use before verifying the signature (optional).
39+
*
40+
* <p>By default, the key diversification is performed with the full serial number of the target
41+
* card or SAM depending on the transaction context (Card or SAM transaction).
42+
*
43+
* @param diversifier The diversifier to be used (from 1 to 8 bytes long).
44+
* @return The current instance.
45+
* @since 1.2.0
46+
*/
47+
T setKeyDiversifier(byte[] diversifier);
48+
49+
/**
50+
* Returns the result of the signature verification process by indicating if the signature is
51+
* valid or not.
52+
*
53+
* @return True if the signature is valid.
54+
* @throws IllegalStateException If the command has not yet been processed.
55+
* @since 1.2.0
56+
*/
57+
boolean isSignatureValid();
58+
}

src/main/java/org/calypsonet/terminal/calypso/transaction/CommonTransactionManager.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ public interface CommonTransactionManager<
4242
List<byte[]> getTransactionAuditData();
4343

4444
/**
45-
* Schedules the execution of a "PSO Compute Signature" SAM command.
45+
* Schedules the execution of a "Data Cipher" or "PSO Compute Signature" SAM command.
4646
*
4747
* <p>Once the command is processed, the result will be available in the provided input/output
48-
* {@link SignatureComputationData} object.
48+
* {@link BasicSignatureComputationData} or {@link TraceableSignatureComputationData} objects.
4949
*
5050
* <p>The signature may be used for many purposes, for example:
5151
*
@@ -64,26 +64,31 @@ public interface CommonTransactionManager<
6464
* @param data The input/output data containing the parameters of the command.
6565
* @return The current instance.
6666
* @throws IllegalArgumentException If the input data is inconsistent.
67-
* @see SignatureComputationData
67+
* @see CommonSignatureComputationData
68+
* @see BasicSignatureComputationData
69+
* @see TraceableSignatureComputationData
6870
* @since 1.2.0
6971
*/
70-
T prepareComputeSignature(SignatureComputationData data);
72+
T prepareComputeSignature(CommonSignatureComputationData<?> data);
7173

7274
/**
73-
* Schedules the execution of a "PSO Verify Signature" SAM command.
75+
* Schedules the execution of a "Data Cipher" or "PSO Verify Signature" SAM command.
7476
*
7577
* <p>Once the command is processed, the result will be available in the provided input/output
76-
* {@link SignatureVerificationData} object.
78+
* {@link BasicSignatureVerificationData} or {@link TraceableSignatureVerificationData} objects.
7779
*
7880
* @param data The input/output data containing the parameters of the command.
7981
* @return The current instance.
8082
* @throws IllegalArgumentException If the input data is inconsistent.
8183
* @throws SamRevokedException If the signature has been computed in "SAM traceability" mode and
82-
* the SAM revocation status check has been requested and the SAM is revoked.
83-
* @see SignatureVerificationData
84+
* the SAM revocation status check has been requested and the SAM is revoked (for traceable
85+
* signature only).
86+
* @see CommonSignatureVerificationData
87+
* @see BasicSignatureVerificationData
88+
* @see TraceableSignatureVerificationData
8489
* @since 1.2.0
8590
*/
86-
T prepareVerifySignature(SignatureVerificationData data);
91+
T prepareVerifySignature(CommonSignatureVerificationData<?> data);
8792

8893
/**
8994
* Process all previously prepared commands.

src/main/java/org/calypsonet/terminal/calypso/transaction/SignatureComputationData.java renamed to src/main/java/org/calypsonet/terminal/calypso/transaction/TraceableSignatureComputationData.java

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,13 @@
1313

1414
/**
1515
* Contains the input/output data of the {@link
16-
* CommonTransactionManager#prepareComputeSignature(SignatureComputationData)} method.
16+
* CommonTransactionManager#prepareComputeSignature(CommonSignatureComputationData)} method for
17+
* traceable signature computation using the "PSO Compute Signature" SAM command.
1718
*
1819
* @since 1.2.0
1920
*/
20-
public interface SignatureComputationData {
21-
22-
/**
23-
* Sets the data to be signed and the KIF/KVC of the key to be used for the signature computation.
24-
*
25-
* @param data The data to be signed.
26-
* @param kif The KIF of the key to be used for the signature computation.
27-
* @param kvc The KVC of the key to be used for the signature computation.
28-
* @return The current instance.
29-
* @since 1.2.0
30-
*/
31-
SignatureComputationData setData(byte[] data, byte kif, byte kvc);
32-
33-
/**
34-
* Sets the expected size of the signature in bytes, which can be between 1 and 8 bytes
35-
* (optional).
36-
*
37-
* <p>By default, the signature will be generated on 8 bytes.
38-
*
39-
* <p>Note: the longer the signature, the more secure it is.
40-
*
41-
* @param size The expected size [1..8]
42-
* @return The current instance.
43-
* @since 1.2.0
44-
*/
45-
SignatureComputationData setSignatureSize(int size);
46-
47-
/**
48-
* Sets a specific key diversifier to use before signing (optional).
49-
*
50-
* <p>By default, the key diversification is performed with the full serial number of the target
51-
* card or SAM depending on the transaction context (Card or SAM transaction).
52-
*
53-
* @param diversifier The diversifier to be used (from 1 to 8 bytes long).
54-
* @return The current instance.
55-
* @since 1.2.0
56-
*/
57-
SignatureComputationData setKeyDiversifier(byte[] diversifier);
21+
public interface TraceableSignatureComputationData
22+
extends CommonSignatureComputationData<TraceableSignatureComputationData> {
5823

5924
/**
6025
* Enables the "SAM traceability" mode to securely record in the data to sign the SAM serial
@@ -75,7 +40,8 @@ public interface SignatureComputationData {
7540
* @return The current instance.
7641
* @since 1.2.0
7742
*/
78-
SignatureComputationData withSamTraceabilityMode(int offset, boolean usePartialSamSerialNumber);
43+
TraceableSignatureComputationData withSamTraceabilityMode(
44+
int offset, boolean usePartialSamSerialNumber);
7945

8046
/**
8147
* Disables the "Busy" mode. When enabled, if the "PSO Verify Signature" command used to check the
@@ -88,7 +54,7 @@ public interface SignatureComputationData {
8854
* @return The current instance.
8955
* @since 1.2.0
9056
*/
91-
SignatureComputationData withoutBusyMode();
57+
TraceableSignatureComputationData withoutBusyMode();
9258

9359
/**
9460
* Returns the data that was used to generate the signature. If the "SAM traceability" mode was
@@ -100,13 +66,4 @@ public interface SignatureComputationData {
10066
* @since 1.2.0
10167
*/
10268
byte[] getSignedData();
103-
104-
/**
105-
* Returns the computed signature.
106-
*
107-
* @return A byte array of 1 to 8 bytes.
108-
* @throws IllegalStateException If the command has not yet been processed.
109-
* @since 1.2.0
110-
*/
111-
byte[] getSignature();
11269
}

0 commit comments

Comments
 (0)