|
8 | 8 | import org.apache.hc.client5.http.impl.classic.HttpClients;
|
9 | 9 | import org.apache.hc.client5.http.impl.io.BasicHttpClientConnectionManager;
|
10 | 10 | import org.apache.hc.client5.http.socket.ConnectionSocketFactory;
|
| 11 | +import org.apache.hc.client5.http.ssl.DefaultHostnameVerifier; |
| 12 | +import org.apache.hc.client5.http.ssl.HttpClientHostnameVerifier; |
11 | 13 | import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
|
12 | 14 | import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
|
13 | 15 | import org.apache.hc.core5.http.config.Registry;
|
@@ -93,47 +95,11 @@ private KeyManagerFactory prepareParsecTest() {
|
93 | 95 | client.psaImportKey(
|
94 | 96 | "client",
|
95 | 97 | Files.readAllBytes(clientKeyDer),
|
96 |
| - PsaKeyAttributes.KeyAttributes.newBuilder() |
97 |
| - .setKeyPolicy( |
98 |
| - PsaKeyAttributes.KeyPolicy.newBuilder() |
99 |
| - |
100 |
| - .setKeyAlgorithm( |
101 |
| - |
102 |
| - PsaAlgorithm.Algorithm.newBuilder() |
103 |
| - |
104 |
| - .setAsymmetricSignature( |
105 |
| - PsaAlgorithm.Algorithm |
106 |
| - .AsymmetricSignature |
107 |
| - .newBuilder() |
108 |
| - .setRsaPkcs1V15Sign( |
109 |
| - PsaAlgorithm.Algorithm.AsymmetricSignature.RsaPkcs1v15Sign.newBuilder() |
110 |
| - .setHashAlg(PsaAlgorithm.Algorithm.AsymmetricSignature.SignHash.newBuilder() |
111 |
| - .setAny(PsaAlgorithm.Algorithm.AsymmetricSignature.SignHash.Any.newBuilder().build()) |
112 |
| - .build()) |
113 |
| - .build() |
114 |
| - ) |
115 |
| - .build()) |
116 |
| - .build()) |
117 |
| - .setKeyUsageFlags( |
118 |
| - PsaKeyAttributes.UsageFlags.newBuilder() |
119 |
| - .setDecrypt(true) |
120 |
| - .setEncrypt(true) |
121 |
| - .setSignMessage(true) |
122 |
| - .setVerifyMessage(true) |
123 |
| - .setVerifyHash(true) |
124 |
| - .setSignHash(true) |
125 |
| - .build()) |
126 |
| - .build()) |
127 |
| - .setKeyType( |
128 |
| - PsaKeyAttributes.KeyType.newBuilder() |
129 |
| - .setRsaKeyPair( |
130 |
| - PsaKeyAttributes.KeyType.RsaKeyPair.newBuilder() |
131 |
| - .build()) |
132 |
| - .build()) |
133 |
| - .build()); |
| 98 | + ParsecCipherSuites.RSA_WITH_PKCS1.getKeyAttributes()); |
| 99 | + |
134 | 100 | URI socketUri = parsecContainer.getSocketUri();
|
135 | 101 | Provider parsec = ParsecProvider.builder().socketUri(socketUri).build();
|
136 |
| - Security.insertProviderAt(parsec, 1); |
| 102 | + Security.insertProviderAt(parsec, 0); |
137 | 103 |
|
138 | 104 | Path clientCertStoreFile = copyFromNginx("/keys/client_cert.jks");
|
139 | 105 | KeyStore clientCertStore = defaultKeystoreFromFile(clientCertStoreFile);
|
@@ -165,12 +131,11 @@ private String absFile(String f) {
|
165 | 131 | @SneakyThrows
|
166 | 132 | void setup() {
|
167 | 133 | Awaitility.await().until(nginxContainer::isRunning);
|
168 |
| - hostPort = format("%s:%s", nginxContainer.getHost(), nginxContainer.getMappedPort(443)); |
169 | 134 | ExecResult r =
|
170 | 135 | nginxContainer.execInContainer(
|
171 | 136 | "sh",
|
172 | 137 | "-c",
|
173 |
| - format("/init.sh %s %s /", hostPort, new String(keystorePassword))); |
| 138 | + format("/init.sh %s %s /", nginxContainer.getHost(), new String(keystorePassword))); |
174 | 139 | assertEquals(0, r.getExitCode(), r.getStderr() + r.getStdout());
|
175 | 140 |
|
176 | 141 | Path serverTrustStore = copyFromNginx("/keys/server_chain.jks");
|
@@ -215,15 +180,16 @@ void testHttpClient(String description, int expectedResponseCode, KmfTestFactory
|
215 | 180 | assertNotNull(sslContext.getProvider());
|
216 | 181 |
|
217 | 182 | SSLConnectionSocketFactory sslsf =
|
218 |
| - new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE); |
| 183 | + new SSLConnectionSocketFactory(sslContext, new DefaultHostnameVerifier()); |
219 | 184 |
|
220 | 185 | Registry<ConnectionSocketFactory> socketFactoryRegistry =
|
221 | 186 | RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslsf).build();
|
222 | 187 | BasicHttpClientConnectionManager connectionManager =
|
223 | 188 | new BasicHttpClientConnectionManager(socketFactoryRegistry);
|
224 | 189 | CloseableHttpClient httpClient =
|
225 | 190 | HttpClients.custom().setConnectionManager(connectionManager).build();
|
226 |
| - CloseableHttpResponse r = httpClient.execute(new HttpGet("https://" + hostPort)); |
| 191 | + CloseableHttpResponse r = httpClient.execute( |
| 192 | + new HttpGet(format("https://%s:%s", nginxContainer.getHost(), nginxContainer.getMappedPort(443)))); |
227 | 193 | assertEquals(expectedResponseCode, r.getCode());
|
228 | 194 | }
|
229 | 195 |
|
|
0 commit comments