Skip to content

Commit

Permalink
Adjusted the SignServer error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ebourg committed Nov 13, 2024
1 parent 863e958 commit bc1bedd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 4 additions & 1 deletion jsign-crypto/src/main/java/net/jsign/KeyStoreType.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,11 @@ Provider getProvider(KeyStoreBuilder params) {
SIGNSERVER(false, false, false) {
@Override
void validate(KeyStoreBuilder params) {
if (params.keystore() == null) {
throw new IllegalArgumentException("keystore " + params.parameterName() + " must specify the SignServer API endpoint (e.g. https://example.com/signserver/)");
}
if (params.storepass() != null && params.storepass().split("\\|").length > 2) {
throw new IllegalArgumentException("storepass " + params.parameterName() + " must specify the SignServer username/password or the path to the keystore containing the TLS client certificate: <username>|<password>, <certificate>");
throw new IllegalArgumentException("storepass " + params.parameterName() + " must specify the SignServer username/password or the path to the keystore containing the TLS client certificate: <username>|<password> or <certificate>");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import net.jsign.DigestAlgorithm;

import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.Objects.requireNonNull;

/**
* Signing service using the Keyfactor SignServer REST API.
Expand All @@ -58,9 +57,7 @@ public class SignServerSigningService implements SigningService {
* @param credentials the SignServer credentials
*/
public SignServerSigningService(String endpoint, SignServerCredentials credentials) {
this.client = new RESTClient(
requireNonNull(endpoint, "You need to provide the SignServer endpoint URL as keystore parameter")
+ (endpoint.endsWith("/") ? "" : "/"))
this.client = new RESTClient(endpoint)
.authentication(conn -> {
if (conn instanceof HttpsURLConnection && credentials.keystore != null) {
try {
Expand Down
6 changes: 3 additions & 3 deletions jsign-crypto/src/test/java/net/jsign/KeyStoreBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,15 @@ public void testBuildGaraSign() throws Exception {
public void testBuildSignServer() throws Exception {
KeyStoreBuilder builder = new KeyStoreBuilder().storetype(SIGNSERVER);

Exception e = assertThrows(NullPointerException.class, builder::build);
assertEquals("message", "You need to provide the SignServer endpoint URL as keystore parameter", e.getMessage());
Exception e = assertThrows(IllegalArgumentException.class, builder::build);
assertEquals("message", "keystore parameter must specify the SignServer API endpoint (e.g. https://example.com/signserver/)", e.getMessage());

builder.keystore("https://example.com/signserver");

builder.storepass("username|password|certificate.p12");

e = assertThrows(IllegalArgumentException.class, builder::build);
assertEquals("message", "storepass parameter must specify the SignServer username/password or the path to the keystore containing the TLS client certificate: <username>|<password>, <certificate>", e.getMessage());
assertEquals("message", "storepass parameter must specify the SignServer username/password or the path to the keystore containing the TLS client certificate: <username>|<password> or <certificate>", e.getMessage());

builder.storepass("username|password");

Expand Down

0 comments on commit bc1bedd

Please sign in to comment.