-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44549 from cescoffier/encrypted-pem-support
Add support for encrypted PKCS#8
- Loading branch information
Showing
10 changed files
with
247 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...tls-registry/deployment/src/test/java/io/quarkus/tls/DefaultEncryptedPemKeyStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkus.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.security.KeyStoreException; | ||
import java.security.cert.CertificateParsingException; | ||
import java.security.cert.X509Certificate; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = { | ||
@Certificate(name = "test-formats-encrypted-pem", password = "password", formats = { Format.JKS, Format.ENCRYPTED_PEM, | ||
Format.PKCS12 }) | ||
}) | ||
public class DefaultEncryptedPemKeyStoreTest { | ||
|
||
private static final String configuration = """ | ||
quarkus.tls.key-store.pem.foo.cert=target/certs/test-formats-encrypted-pem.crt | ||
quarkus.tls.key-store.pem.foo.key=target/certs/test-formats-encrypted-pem.key | ||
quarkus.tls.key-store.pem.foo.password=password | ||
"""; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.add(new StringAsset(configuration), "application.properties")); | ||
|
||
@Inject | ||
TlsConfigurationRegistry certificates; | ||
|
||
@Test | ||
void test() throws KeyStoreException, CertificateParsingException { | ||
TlsConfiguration def = certificates.getDefault().orElseThrow(); | ||
|
||
assertThat(def.getKeyStoreOptions()).isNotNull(); | ||
assertThat(def.getKeyStore()).isNotNull(); | ||
|
||
// dummy-entry-x is the alias of the certificate in the keystore generated by Vert.x. | ||
|
||
X509Certificate certificate = (X509Certificate) def.getKeyStore().getCertificate("dummy-entry-0"); | ||
assertThat(certificate).isNotNull(); | ||
assertThat(certificate.getSubjectAlternativeNames()).anySatisfy(l -> { | ||
assertThat(l.get(0)).isEqualTo(2); | ||
assertThat(l.get(1)).isEqualTo("localhost"); | ||
}); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
.../tls-registry/deployment/src/test/java/io/quarkus/tls/EncryptedPemWithNoPasswordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.quarkus.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import java.security.KeyStoreException; | ||
import java.security.cert.CertificateParsingException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = { | ||
@Certificate(name = "test-formats-encrypted-pem", password = "password", formats = { Format.JKS, Format.ENCRYPTED_PEM, | ||
Format.PKCS12 }) | ||
}) | ||
public class EncryptedPemWithNoPasswordTest { | ||
|
||
private static final String configuration = """ | ||
quarkus.tls.key-store.pem.foo.cert=target/certs/test-formats-encrypted-pem.crt | ||
quarkus.tls.key-store.pem.foo.key=target/certs/test-formats-encrypted-pem.key | ||
"""; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.add(new StringAsset(configuration), "application.properties")) | ||
.assertException(t -> assertThat(t.getMessage()).contains("key/certificate pair", "default")); | ||
|
||
@Test | ||
void test() throws KeyStoreException, CertificateParsingException { | ||
fail("Should not be called as the extension should fail before."); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...s-registry/deployment/src/test/java/io/quarkus/tls/EncryptedPemWithWrongPasswordTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.quarkus.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.fail; | ||
|
||
import java.security.KeyStoreException; | ||
import java.security.cert.CertificateParsingException; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = { | ||
@Certificate(name = "test-formats-encrypted-pem", password = "password", formats = { Format.JKS, Format.ENCRYPTED_PEM, | ||
Format.PKCS12 }) | ||
}) | ||
public class EncryptedPemWithWrongPasswordTest { | ||
|
||
private static final String configuration = """ | ||
quarkus.tls.key-store.pem.foo.cert=target/certs/test-formats-encrypted-pem.crt | ||
quarkus.tls.key-store.pem.foo.key=target/certs/test-formats-encrypted-pem.key | ||
quarkus.tls.key-store.pem.foo.password=wrong | ||
"""; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.add(new StringAsset(configuration), "application.properties")) | ||
.assertException(t -> assertThat(t.getMessage()).contains("key/certificate pair", "default")); | ||
|
||
@Test | ||
void test() throws KeyStoreException, CertificateParsingException { | ||
fail("Should not be called as the extension should fail before."); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...s/tls-registry/deployment/src/test/java/io/quarkus/tls/NamedEncryptedPemKeyStoreTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.quarkus.tls; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.security.KeyStoreException; | ||
import java.security.cert.CertificateParsingException; | ||
import java.security.cert.X509Certificate; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.smallrye.certs.Format; | ||
import io.smallrye.certs.junit5.Certificate; | ||
import io.smallrye.certs.junit5.Certificates; | ||
|
||
@Certificates(baseDir = "target/certs", certificates = { | ||
@Certificate(name = "test-formats-encrypted-pem", password = "password", formats = { Format.JKS, Format.ENCRYPTED_PEM, | ||
Format.PKCS12 }) | ||
}) | ||
public class NamedEncryptedPemKeyStoreTest { | ||
|
||
private static final String configuration = """ | ||
quarkus.tls.http.key-store.pem.foo.cert=target/certs/test-formats-encrypted-pem.crt | ||
quarkus.tls.http.key-store.pem.foo.key=target/certs/test-formats-encrypted-pem.key | ||
quarkus.tls.http.key-store.pem.foo.password=password | ||
"""; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest().setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class) | ||
.add(new StringAsset(configuration), "application.properties")); | ||
|
||
@Inject | ||
TlsConfigurationRegistry certificates; | ||
|
||
@Test | ||
void test() throws KeyStoreException, CertificateParsingException { | ||
TlsConfiguration def = certificates.getDefault().orElseThrow(); | ||
TlsConfiguration named = certificates.get("http").orElseThrow(); | ||
|
||
assertThat(def.getKeyStoreOptions()).isNull(); | ||
assertThat(def.getKeyStore()).isNull(); | ||
|
||
assertThat(named.getKeyStoreOptions()).isNotNull(); | ||
assertThat(named.getKeyStore()).isNotNull(); | ||
|
||
X509Certificate certificate = (X509Certificate) named.getKeyStore().getCertificate("dummy-entry-0"); | ||
assertThat(certificate).isNotNull(); | ||
assertThat(certificate.getSubjectAlternativeNames()).anySatisfy(l -> { | ||
assertThat(l.get(0)).isEqualTo(2); | ||
assertThat(l.get(1)).isEqualTo("localhost"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters