|
26 | 26 | import java.util.function.Consumer;
|
27 | 27 | import java.util.function.LongConsumer;
|
28 | 28 | import java.util.function.Predicate;
|
| 29 | +import java.util.stream.Collectors; |
| 30 | +import javax.net.ssl.SSLParameters; |
29 | 31 | import javax.net.ssl.X509TrustManager;
|
30 | 32 | import org.slf4j.Logger;
|
31 | 33 | import org.slf4j.LoggerFactory;
|
@@ -213,4 +215,92 @@ public X509Certificate[] getAcceptedIssuers() {
|
213 | 215 | return new X509Certificate[0];
|
214 | 216 | }
|
215 | 217 | }
|
| 218 | + |
| 219 | + static void mergeSslParameters(SSLParameters original, SSLParameters provided) { |
| 220 | + if (notEmptyArray(provided.getCipherSuites())) { |
| 221 | + LOGGER.debug( |
| 222 | + "Setting SSLParameters cipherSuites from {} to {}", |
| 223 | + arrayToString(original.getCipherSuites()), |
| 224 | + arrayToString(provided.getCipherSuites())); |
| 225 | + original.setCipherSuites(provided.getCipherSuites()); |
| 226 | + } |
| 227 | + if (notEmptyArray(provided.getProtocols())) { |
| 228 | + LOGGER.debug( |
| 229 | + "Setting SSLParameters protocols from {} to {}", |
| 230 | + arrayToString(original.getProtocols()), |
| 231 | + arrayToString(provided.getProtocols())); |
| 232 | + original.setProtocols(provided.getProtocols()); |
| 233 | + } |
| 234 | + if (original.getWantClientAuth() != provided.getWantClientAuth()) { |
| 235 | + LOGGER.debug( |
| 236 | + "Setting SSLParameters wantClientAuth from {} to {}", |
| 237 | + original.getWantClientAuth(), |
| 238 | + provided.getWantClientAuth()); |
| 239 | + original.setWantClientAuth(provided.getWantClientAuth()); |
| 240 | + } |
| 241 | + if (original.getNeedClientAuth() != provided.getNeedClientAuth()) { |
| 242 | + LOGGER.debug( |
| 243 | + "Setting SSLParameters needClientAuth from {} to {}", |
| 244 | + original.getNeedClientAuth(), |
| 245 | + provided.getNeedClientAuth()); |
| 246 | + original.setNeedClientAuth(provided.getNeedClientAuth()); |
| 247 | + } |
| 248 | + if (notNullOrBlank(provided.getEndpointIdentificationAlgorithm())) { |
| 249 | + LOGGER.debug( |
| 250 | + "Setting SSLParameters endpointIdentificationAlgorithm from {} to {}", |
| 251 | + original.getEndpointIdentificationAlgorithm(), |
| 252 | + provided.getEndpointIdentificationAlgorithm()); |
| 253 | + original.setEndpointIdentificationAlgorithm(provided.getEndpointIdentificationAlgorithm()); |
| 254 | + } |
| 255 | + if (provided.getAlgorithmConstraints() != null) { |
| 256 | + LOGGER.debug( |
| 257 | + "Setting SSLParameters algorithmConstraints from {} to {}", |
| 258 | + original.getAlgorithmConstraints(), |
| 259 | + provided.getAlgorithmConstraints()); |
| 260 | + original.setAlgorithmConstraints(provided.getAlgorithmConstraints()); |
| 261 | + } |
| 262 | + if (provided.getServerNames() != null) { |
| 263 | + LOGGER.debug( |
| 264 | + "Setting SSLParameters serverNames from {} to {}", |
| 265 | + original.getServerNames(), |
| 266 | + provided.getServerNames()); |
| 267 | + original.setServerNames(provided.getServerNames()); |
| 268 | + } |
| 269 | + if (provided.getSNIMatchers() != null) { |
| 270 | + LOGGER.debug( |
| 271 | + "Setting SSLParameters SNIMatchers from {} to {}", |
| 272 | + original.getSNIMatchers(), |
| 273 | + provided.getSNIMatchers()); |
| 274 | + original.setSNIMatchers(provided.getSNIMatchers()); |
| 275 | + } |
| 276 | + if (original.getUseCipherSuitesOrder() != provided.getUseCipherSuitesOrder()) { |
| 277 | + LOGGER.debug( |
| 278 | + "Setting SSLParameters useCipherSuitesOrder from {} to {}", |
| 279 | + original.getUseCipherSuitesOrder(), |
| 280 | + provided.getUseCipherSuitesOrder()); |
| 281 | + original.setUseCipherSuitesOrder(provided.getUseCipherSuitesOrder()); |
| 282 | + } |
| 283 | + } |
| 284 | + |
| 285 | + private static boolean notNullOrBlank(String str) { |
| 286 | + return str != null && !str.trim().isEmpty(); |
| 287 | + } |
| 288 | + |
| 289 | + private static String arrayToString(Object[] array) { |
| 290 | + if (emptyArray(array)) { |
| 291 | + return ""; |
| 292 | + } else { |
| 293 | + return Arrays.stream(array) |
| 294 | + .map(o -> o == null ? "null" : o.toString()) |
| 295 | + .collect(Collectors.joining()); |
| 296 | + } |
| 297 | + } |
| 298 | + |
| 299 | + private static boolean emptyArray(Object[] array) { |
| 300 | + return array == null || array.length == 0; |
| 301 | + } |
| 302 | + |
| 303 | + private static boolean notEmptyArray(Object[] array) { |
| 304 | + return !emptyArray(array); |
| 305 | + } |
216 | 306 | }
|
0 commit comments