Skip to content

Commit 6554459

Browse files
committed
Merge branch 'RM-4105-2' into 'master'
RM-4105: use slot parameter also with keyserver properties See merge request cdoc2/cdoc2-java-ref-impl!108
2 parents ebb4be1 + 8059958 commit 6554459

File tree

5 files changed

+11
-8
lines changed

5 files changed

+11
-8
lines changed

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocDecryptCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Void call() throws Exception {
7676

7777
KeyCapsuleClientFactory keyCapsulesClientFactory = null;
7878
if (this.keyServerPropertiesFile != null) {
79-
keyCapsulesClientFactory = getKeyCapsulesClientFactory(this.keyServerPropertiesFile);
79+
keyCapsulesClientFactory = getKeyCapsulesClientFactory(this.keyServerPropertiesFile, slot);
8080
}
8181

8282
DecryptionKeyMaterial decryptionKeyMaterial = (null == this.exclusive)

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocListCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public Void call() throws Exception {
6666

6767
KeyCapsuleClientFactory keyCapsulesClientFactory = null;
6868
if (keyServerPropertiesFile != null) {
69-
keyCapsulesClientFactory = getKeyCapsulesClientFactory(this.keyServerPropertiesFile);
69+
keyCapsulesClientFactory = getKeyCapsulesClientFactory(this.keyServerPropertiesFile, slot);
7070
}
7171

7272
DecryptionKeyMaterial decryptionKeyMaterial = (null == this.exclusive)

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/commands/CDocReEncryptCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public Void call() throws Exception {
104104
KeyCapsuleClientFactory keyCapsulesClientFactory = null;
105105

106106
if (this.keyServerPropertiesFile != null) {
107-
keyCapsulesClientFactory = getKeyCapsulesClientFactory(this.keyServerPropertiesFile);
107+
keyCapsulesClientFactory = getKeyCapsulesClientFactory(this.keyServerPropertiesFile, slot);
108108
}
109109

110110
File destCdocFile = getDestinationFile();

cdoc2-cli/src/main/java/ee/cyber/cdoc2/cli/util/CDocDecryptionHelper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ public static CDocDecrypter getDecrypterWithFilesExtraction(
155155
}
156156

157157
public static KeyCapsuleClientFactory getKeyCapsulesClientFactory(
158-
String keyServerPropertiesFile
159-
) throws GeneralSecurityException, IOException {
158+
String keyServerPropertiesFile,
159+
Integer slot) throws GeneralSecurityException, IOException {
160160
Properties p = CDocCommonHelper.getServerProperties(keyServerPropertiesFile);
161-
161+
p.setProperty("pkcs11.slot", slot.toString());
162162
return KeyCapsuleClientImpl.createFactory(p);
163163
}
164164

cdoc2-lib/src/main/java/ee/cyber/cdoc2/client/KeyCapsuleClientImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Optional;
2121
import java.util.Properties;
2222
import javax.annotation.Nullable;
23+
24+
import org.apache.commons.lang3.math.NumberUtils;
2325
import org.slf4j.Logger;
2426
import org.slf4j.LoggerFactory;
2527

@@ -173,8 +175,9 @@ private static KeyStore loadClientKeyStore(Properties p) throws KeyStoreExceptio
173175
String openScLibPath = loadPkcs11LibPath(p);
174176
KeyStore.ProtectionParameter protectionParameter = loadClientKeyStoreProtectionParameter(p);
175177

176-
// default slot 0 - Isikutuvastus
177-
clientKeyStore = Pkcs11Tools.initPKCS11KeysStore(openScLibPath, null, protectionParameter);
178+
String slotProperty = p.getProperty("pkcs11.slot");
179+
Integer slot = NumberUtils.isCreatable(slotProperty) ? Integer.parseInt(slotProperty) : 0;
180+
clientKeyStore = Pkcs11Tools.initPKCS11KeysStore(openScLibPath, slot, protectionParameter);
178181
} else {
179182
throw new IllegalArgumentException("cdoc2.client.ssl.client-store.type " + type + " not supported");
180183
}

0 commit comments

Comments
 (0)