Polish SSL
This commit is contained in:
@@ -26,6 +26,8 @@ import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Helper used to match certificates against a {@link PrivateKey}.
|
||||
*
|
||||
@@ -48,14 +50,16 @@ class CertificateMatcher {
|
||||
private final byte[] generatedSignature;
|
||||
|
||||
CertificateMatcher(PrivateKey privateKey) {
|
||||
Assert.notNull(privateKey, "Private key must not be null");
|
||||
this.privateKey = privateKey;
|
||||
this.signature = createSignature(privateKey);
|
||||
Assert.notNull(this.signature, "Failed to create signature");
|
||||
this.generatedSignature = sign(this.signature, privateKey);
|
||||
}
|
||||
|
||||
private Signature createSignature(PrivateKey privateKey) {
|
||||
try {
|
||||
String algorithm = getSignatureAlgorithm(this.privateKey);
|
||||
String algorithm = getSignatureAlgorithm(privateKey);
|
||||
return (algorithm != null) ? Signature.getInstance(algorithm) : null;
|
||||
}
|
||||
catch (NoSuchAlgorithmException ex) {
|
||||
|
||||
@@ -120,7 +120,7 @@ public final class PropertiesSslBundle implements SslBundle {
|
||||
if (properties.isVerifyKeys()) {
|
||||
CertificateMatcher certificateMatcher = new CertificateMatcher(pemSslStore.privateKey());
|
||||
Assert.state(certificateMatcher.matchesAny(pemSslStore.certificates()),
|
||||
"Private key matches none of the certificates in the chain");
|
||||
"Private key in %s matches none of the certificates in the chain".formatted(propertyName));
|
||||
}
|
||||
return pemSslStore;
|
||||
}
|
||||
|
||||
@@ -134,7 +134,7 @@ class PropertiesSslBundleTests {
|
||||
properties.getKeystore().setVerifyKeys(true);
|
||||
properties.getKey().setAlias("test-alias");
|
||||
assertThatIllegalStateException().isThrownBy(() -> PropertiesSslBundle.get(properties))
|
||||
.withMessageContaining("Private key matches none of the certificates");
|
||||
.withMessageContaining("Private key in keystore matches none of the certificates");
|
||||
}
|
||||
|
||||
private Consumer<KeyStore> storeContainingCertAndKey(String keyAlias) {
|
||||
|
||||
Reference in New Issue
Block a user