Skip to content

Commit c456e9e

Browse files
mrtssvenzik
authored andcommitted
feat: validate signature algorithm values
WE2-817 Signed-off-by: Mart Somermaa <mrts@users.noreply.github.com>
1 parent 3814edf commit c456e9e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

example/src/main/java/eu/webeid/example/service/dto/SignatureAlgorithmDTO.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,25 @@
2222

2323
package eu.webeid.example.service.dto;
2424

25+
import java.util.Arrays;
26+
import java.util.HashSet;
27+
import java.util.Set;
28+
2529
public class SignatureAlgorithmDTO {
2630

31+
// See https://github.com/web-eid/web-eid-app/blob/main/src/controller/command-handlers/signauthutils.cpp#L121-L127
32+
private static final Set<String> SUPPORTED_CRYPTO_ALGOS = new HashSet<>(Arrays.asList(
33+
"ECC", "RSA"
34+
));
35+
private static final Set<String> SUPPORTED_PADDING_SCHEMES = new HashSet<>(Arrays.asList(
36+
"NONE", "PKCS1.5", "PSS"
37+
));
38+
// See https://github.com/web-eid/libelectronic-id/tree/main/src/electronic-id.cpp#L131
39+
private static final Set<String> SUPPORTED_HASH_FUNCTIONS = new HashSet<>(Arrays.asList(
40+
"SHA-224", "SHA-256", "SHA-384", "SHA-512",
41+
"SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512"
42+
));
43+
2744
private String cryptoAlgorithm;
2845

2946
private String hashFunction;
@@ -35,6 +52,9 @@ public String getCryptoAlgorithm() {
3552
}
3653

3754
public void setCryptoAlgorithm(String cryptoAlgorithm) {
55+
if (!SUPPORTED_CRYPTO_ALGOS.contains(cryptoAlgorithm)) {
56+
throw new IllegalArgumentException("The provided crypto algorithm is not supported");
57+
}
3858
this.cryptoAlgorithm = cryptoAlgorithm;
3959
}
4060

@@ -43,6 +63,9 @@ public String getHashFunction() {
4363
}
4464

4565
public void setHashFunction(String hashFunction) {
66+
if (!SUPPORTED_HASH_FUNCTIONS.contains(hashFunction)) {
67+
throw new IllegalArgumentException("The provided hash function is not supported");
68+
}
4669
this.hashFunction = hashFunction;
4770
}
4871

@@ -51,6 +74,9 @@ public String getPaddingScheme() {
5174
}
5275

5376
public void setPaddingScheme(String paddingScheme) {
77+
if (!SUPPORTED_PADDING_SCHEMES.contains(paddingScheme)) {
78+
throw new IllegalArgumentException("The provided padding scheme is not supported");
79+
}
5480
this.paddingScheme = paddingScheme;
5581
}
5682
}

example/src/test/java/eu/webeid/example/testutil/ObjectMother.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ public static CertificateDTO mockPrepareRequest() {
9797
CertificateDTO certificateDTO = new CertificateDTO();
9898
certificateDTO.setCertificate(mockCertificateInBase64());
9999
final SignatureAlgorithmDTO signatureAlgorithmDTO = new SignatureAlgorithmDTO();
100+
signatureAlgorithmDTO.setCryptoAlgorithm("RSA");
100101
signatureAlgorithmDTO.setHashFunction("SHA-256");
102+
signatureAlgorithmDTO.setPaddingScheme("PKCS1.5");
101103
certificateDTO.setSupportedSignatureAlgorithms(List.of(signatureAlgorithmDTO));
102104
return certificateDTO;
103105
}

0 commit comments

Comments
 (0)