Skip to content

Commit 3850930

Browse files
committed
Merge branch 'RM-3257' into 'master'
RM-3257: Fix Junit id-card tests See merge request cdoc2/cdoc2-java-ref-impl!42
2 parents 19869f1 + 4d8b514 commit 3850930

File tree

7 files changed

+57
-10
lines changed

7 files changed

+57
-10
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,16 @@ To run the tests using a physical PKCS11 device (smart card or usb token), execu
231231
mvn test -Dtests=pkcs11
232232
```
233233

234-
The pkcs11 device configuration (PKCS11 library, slot, pin, etc) can be specified using `cdoc2.pkcs11.conf-file` system property, for example:
234+
The pkcs11 device configuration (PKCS11 library, slot, pin, etc) can be specified using
235+
`cdoc2.pkcs11.conf-file` system property, for example run with configuration file from filesystem
236+
from the root of the project:
235237

236238
```
237-
mvn test -Dtests=pkcs11 -Dcdoc2.pkcs11.conf-file=pkcs11-test-safenet.properties
239+
mvn test -Dtests=pkcs11 -Dcdoc2.pkcs11.conf-file=src/test/resources/pkcs11-test-safenet.properties
240+
```
241+
or
242+
```
243+
mvn test -Dtests=pkcs11 -Dcdoc2.pkcs11.conf-file=src/test/resources/pkcs11-test-idcard.properties
238244
```
239245

240246
By default, the pkcs11 configuration is read from the file `pkcs11-test-idcard.properties`.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEDjCCA2+gAwIBAgIQaLfRQQSV3nMFgzOBgc5eKjAKBggqhkjOPQQDBDBgMQsw
3+
CQYDVQQGEwJFRTEbMBkGA1UECgwSU0sgSUQgU29sdXRpb25zIEFTMRcwFQYDVQRh
4+
DA5OVFJFRS0xMDc0NzAxMzEbMBkGA1UEAwwSVEVTVCBvZiBFU1RFSUQyMDE4MB4X
5+
DTIzMTEyOTA3MTYwOVoXDTI4MTEyODIxNTk1OVowfzELMAkGA1UEBhMCRUUxKjAo
6+
BgNVBAMMIUrDlUVPUkcsSkFBSy1L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JX
22+
jxjGyHAwiMVBnD4UBWUCQgFU4YC4yybxs6lsWp9h8pvLb72eqibkq50Jjb19bwhk
23+
mPaHamWsjrX1071PHqk7W4szaKrxy49qBuoiouLtjug9hQ==
24+
-----END CERTIFICATE-----

cdoc2-lib/src/main/java/ee/cyber/cdoc2/util/Resources.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.file.Path;
1010
import java.util.Objects;
1111

12+
1213
/**
1314
* Utility class for loading resources (ex. properties files) from classpath
1415
*/
@@ -46,4 +47,5 @@ public static InputStream getResourceAsStream(String name, @Nullable ClassLoader
4647
return Files.newInputStream(Path.of(name));
4748
}
4849
}
50+
4951
}

cdoc2-lib/src/test/java/ee/cyber/cdoc2/crypto/Pkcs11DeviceConfiguration.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package ee.cyber.cdoc2.crypto;
22

3+
import java.io.File;
34
import java.io.InputStream;
45
import java.util.Optional;
56
import java.util.Properties;
67
import javax.annotation.Nullable;
78
import org.slf4j.Logger;
89
import org.slf4j.LoggerFactory;
910

11+
import ee.cyber.cdoc2.util.Resources;
12+
13+
1014
/**
1115
* Test configuration for running PKCS11 tests using a hardware device.
1216
*/
@@ -36,14 +40,25 @@ public record Pkcs11DeviceConfiguration(
3640
*
3741
*/
3842
public static Pkcs11DeviceConfiguration load() {
39-
String filename = System.getProperty("cdoc2.pkcs11.conf-file", "pkcs11-test-idcard.properties");
40-
return loadFromPropertiesFile(filename);
43+
final String classpath = "classpath:";
44+
String filename = System.getProperty(
45+
"cdoc2.pkcs11.conf-file",
46+
classpath + "pkcs11-test-idcard.properties"
47+
);
48+
String propertyFileName;
49+
if (filename.contains(classpath)) {
50+
propertyFileName = filename;
51+
} else {
52+
propertyFileName = new File(filename).getAbsolutePath();
53+
}
54+
return loadFromPropertiesFile(propertyFileName);
4155
}
4256

4357
private static Pkcs11DeviceConfiguration loadFromPropertiesFile(String filename) {
4458
log.info("Loading PKCS11 device configuration from {}", filename);
4559

46-
try (InputStream is = Pkcs11Test.class.getClassLoader().getResourceAsStream(filename)) {
60+
try (InputStream is
61+
= Resources.getResourceAsStream(filename, Pkcs11Test.class.getClassLoader())) {
4762
var properties = new Properties();
4863
properties.load(is);
4964

@@ -64,4 +79,5 @@ private static String getRequiredProperty(Properties properties, String property
6479
return Optional.ofNullable(properties.getProperty(property))
6580
.orElseThrow(() -> new IllegalArgumentException("Required property '" + property + "' not found"));
6681
}
82+
6783
}

cdoc2-lib/src/test/java/ee/cyber/cdoc2/crypto/Pkcs11Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
class Pkcs11Test {
3131
private static final Logger log = LoggerFactory.getLogger(Pkcs11Test.class);
3232

33-
// load pkcs11 devive properties
33+
// load pkcs11 device properties
3434
private static final Pkcs11DeviceConfiguration CONF = Pkcs11DeviceConfiguration.load();
3535

3636
@Test

cdoc2-lib/src/test/resources/pkcs11-test-idcard.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
pkcs11.library=/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so
44
pkcs11.slot=0
5-
# pin
6-
pkcs11.pin=3471
5+
# ID card pin 1
6+
pkcs11.pin=1357
77
# key alias in the key store
88
pkcs11.key-alias=Isikutuvastus
99
# part of the CN in the certificate to match
10-
pkcs11.cert.cn=37101010021
10+
pkcs11.cert.cn=38001085718

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@
220220
</dependencies>
221221
</dependencyManagement>
222222

223-
224223
<dependencies>
225224
<dependency>
226225
<groupId>org.junit.jupiter</groupId>

0 commit comments

Comments
 (0)