View Javadoc
1   /*
2    * Copyright 2019-2021 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package nl.altindag.ssl.util;
18  
19  import nl.altindag.ssl.exception.GenericSecurityException;
20  import nl.altindag.ssl.exception.GenericTrustManagerException;
21  import nl.altindag.ssl.model.KeyStoreHolder;
22  import nl.altindag.ssl.trustmanager.CompositeX509ExtendedTrustManager;
23  import nl.altindag.ssl.trustmanager.UnsafeX509ExtendedTrustManager;
24  import nl.altindag.ssl.trustmanager.X509TrustManagerWrapper;
25  import org.junit.jupiter.api.Test;
26  import org.junit.jupiter.api.extension.ExtendWith;
27  import org.mockito.junit.jupiter.MockitoExtension;
28  
29  import javax.net.ssl.TrustManagerFactory;
30  import javax.net.ssl.X509ExtendedTrustManager;
31  import javax.net.ssl.X509TrustManager;
32  import java.security.KeyStore;
33  import java.security.KeyStoreException;
34  import java.security.Provider;
35  import java.security.Security;
36  import java.util.Arrays;
37  import java.util.Collections;
38  import java.util.List;
39  import java.util.Optional;
40  
41  import static org.assertj.core.api.Assertions.assertThat;
42  import static org.assertj.core.api.Assertions.assertThatThrownBy;
43  import static org.mockito.ArgumentMatchers.any;
44  import static org.mockito.Mockito.doThrow;
45  import static org.mockito.Mockito.mock;
46  
47  /**
48   * @author Hakan Altindag
49   */
50  @ExtendWith(MockitoExtension.class)
51  class TrustManagerUtilsShould {
52  
53      private static final String TRUSTSTORE_FILE_NAME = "truststore.jks";
54      private static final char[] TRUSTSTORE_PASSWORD = new char[] {'s', 'e', 'c', 'r', 'e', 't'};
55      private static final String KEYSTORE_LOCATION = "keystores-for-unit-tests/";
56      private static final String ORIGINAL_OS_NAME = System.getProperty("os.name");
57  
58      @Test
59      void combineTrustManagers() throws KeyStoreException {
60          KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
61          KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
62          X509ExtendedTrustManager trustManager = TrustManagerUtils
63                  .combine(TrustManagerUtils.createTrustManager(trustStoreOne), TrustManagerUtils.createTrustManager(trustStoreTwo));
64  
65          assertThat(trustStoreOne.size()).isEqualTo(1);
66          assertThat(trustStoreTwo.size()).isEqualTo(1);
67          assertThat(trustManager.getAcceptedIssuers()).hasSize(2);
68      }
69  
70      @Test
71      void unwrapCombinedTrustManagersAndRecombineIntoSingleBaseTrustManager() throws KeyStoreException {
72          KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
73          KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
74  
75          X509ExtendedTrustManager trustManagerOne = TrustManagerUtils.createTrustManager(trustStoreOne);
76          X509ExtendedTrustManager trustManagerTwo = TrustManagerUtils.createTrustManager(trustStoreTwo);
77  
78          X509ExtendedTrustManager combinedTrustManager = TrustManagerUtils.combine(trustManagerOne, trustManagerTwo);
79          X509ExtendedTrustManager combinedCombinedTrustManager = TrustManagerUtils.combine(combinedTrustManager, trustManagerOne, trustManagerTwo);
80  
81          assertThat(trustStoreOne.size()).isEqualTo(1);
82          assertThat(trustStoreTwo.size()).isEqualTo(1);
83          assertThat(combinedTrustManager.getAcceptedIssuers()).hasSize(2);
84          assertThat(combinedCombinedTrustManager.getAcceptedIssuers()).hasSize(2);
85  
86          assertThat(combinedTrustManager).isInstanceOf(CompositeX509ExtendedTrustManager.class);
87          assertThat(combinedCombinedTrustManager).isInstanceOf(CompositeX509ExtendedTrustManager.class);
88          assertThat(((CompositeX509ExtendedTrustManager) combinedTrustManager).size()).isEqualTo(2);
89          assertThat(((CompositeX509ExtendedTrustManager) combinedCombinedTrustManager).size()).isEqualTo(4);
90      }
91  
92      @Test
93      void combineTrustManagersWithTrustStoreHolders() throws KeyStoreException {
94          KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
95          KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
96  
97          KeyStoreHolder trustStoreHolderOne = new KeyStoreHolder(trustStoreOne, TRUSTSTORE_PASSWORD);
98          KeyStoreHolder trustStoreHolderTwo = new KeyStoreHolder(trustStoreTwo, TRUSTSTORE_PASSWORD);
99  
100         X509ExtendedTrustManager trustManager = TrustManagerUtils
101                 .combine(TrustManagerUtils.createTrustManager(trustStoreHolderOne, trustStoreHolderTwo));
102 
103         assertThat(trustStoreOne.size()).isEqualTo(1);
104         assertThat(trustStoreTwo.size()).isEqualTo(1);
105         assertThat(trustManager.getAcceptedIssuers()).hasSize(2);
106     }
107 
108     @Test
109     void combineTrustManagersWithKeyStores() throws KeyStoreException {
110         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
111         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
112 
113         X509ExtendedTrustManager trustManager = TrustManagerUtils
114                 .combine(TrustManagerUtils.createTrustManager(trustStoreOne, trustStoreTwo));
115 
116         assertThat(trustStoreOne.size()).isEqualTo(1);
117         assertThat(trustStoreTwo.size()).isEqualTo(1);
118         assertThat(trustManager.getAcceptedIssuers()).hasSize(2);
119     }
120 
121     @Test
122     void combineTrustManagersWhileFilteringDuplicateCertificates() throws KeyStoreException {
123         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
124         X509ExtendedTrustManager trustManager = TrustManagerUtils
125                 .combine(TrustManagerUtils.createTrustManager(trustStore), TrustManagerUtils.createTrustManager(trustStore));
126 
127         assertThat(trustStore.size()).isEqualTo(1);
128         assertThat(trustManager.getAcceptedIssuers()).hasSize(1);
129     }
130 
131     @Test
132     void wrapIfNeeded() {
133         X509TrustManager trustManager = mock(X509TrustManager.class);
134         X509ExtendedTrustManager extendedTrustManager = TrustManagerUtils.wrapIfNeeded(trustManager);
135 
136         assertThat(extendedTrustManager).isInstanceOf(X509TrustManagerWrapper.class);
137     }
138 
139     @Test
140     void doNotWrapWhenInstanceIsX509ExtendedTrustManager() {
141         X509ExtendedTrustManager trustManager = mock(X509ExtendedTrustManager.class);
142         X509ExtendedTrustManager extendedTrustManager = TrustManagerUtils.wrapIfNeeded(trustManager);
143 
144         assertThat(extendedTrustManager)
145                 .isEqualTo(trustManager)
146                 .isNotInstanceOf(X509TrustManagerWrapper.class);
147     }
148 
149     @Test
150     void createTrustManagerWithCustomSecurityProviderBasedOnTheName() {
151         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
152 
153         X509ExtendedTrustManager trustManager = TrustManagerUtils.createTrustManager(trustStore, TrustManagerFactory.getDefaultAlgorithm(), "SunJSSE");
154 
155         assertThat(trustManager).isNotNull();
156     }
157 
158     @Test
159     void createTrustManagerWithCustomSecurityProvider() {
160         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
161         Provider sunJSSE = Security.getProvider("SunJSSE");
162 
163         X509ExtendedTrustManager trustManager = TrustManagerUtils.createTrustManager(trustStore, TrustManagerFactory.getDefaultAlgorithm(), sunJSSE);
164 
165         assertThat(trustManager).isNotNull();
166     }
167 
168     @Test
169     void createTrustManagerWithJdkTrustedCertificatesWhenProvidingNullAsTrustStore() {
170         X509ExtendedTrustManager trustManager = TrustManagerUtils.createTrustManager((KeyStore) null);
171 
172         assertThat(trustManager).isNotNull();
173         assertThat(trustManager.getAcceptedIssuers()).hasSizeGreaterThan(10);
174     }
175 
176     @Test
177     void createTrustManagerWithJdkTrustedCertificatesWhenCallingCreateTrustManagerWithJdkTrustedCertificates() {
178         X509ExtendedTrustManager trustManager = TrustManagerUtils.createTrustManagerWithJdkTrustedCertificates();
179 
180         assertThat(trustManager).isNotNull();
181         assertThat((trustManager).getAcceptedIssuers()).hasSizeGreaterThan(10);
182     }
183 
184     @Test
185     void createTrustManagerWithSystemTrustedCertificate() {
186         String operatingSystem = System.getProperty("os.name").toLowerCase();
187         Optional<X509ExtendedTrustManager> trustManager = TrustManagerUtils.createTrustManagerWithSystemTrustedCertificates();
188         if (operatingSystem.contains("mac") || operatingSystem.contains("windows")) {
189             assertThat(trustManager).isPresent();
190             assertThat((trustManager).get().getAcceptedIssuers()).hasSizeGreaterThan(0);
191         }
192 
193         if (operatingSystem.contains("linux")) {
194             assertThat(trustManager).isNotPresent();
195         }
196     }
197 
198     @Test
199     void createTrustManagerWhenProvidingACustomTrustStore() {
200         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
201         X509ExtendedTrustManager trustManager = TrustManagerUtils.createTrustManager(trustStore);
202 
203         assertThat(trustManager).isNotNull();
204         assertThat((trustManager).getAcceptedIssuers()).hasSize(1);
205     }
206 
207     @Test
208     void createUnsafeTrustManager() {
209         X509ExtendedTrustManager trustManager = TrustManagerUtils.createUnsafeTrustManager();
210 
211         assertThat(trustManager)
212                 .isNotNull()
213                 .isInstanceOf(UnsafeX509ExtendedTrustManager.class)
214                 .isEqualTo(TrustManagerUtils.createUnsafeTrustManager());
215     }
216 
217     @Test
218     void createTrustManagerFromMultipleTrustManagers() {
219         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
220         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
221 
222         X509ExtendedTrustManager trustManagerOne = TrustManagerUtils.createTrustManager(trustStoreOne);
223         X509ExtendedTrustManager trustManagerTwo = TrustManagerUtils.createTrustManager(trustStoreTwo);
224 
225         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
226                 .withTrustManager(trustManagerOne)
227                 .withTrustManager(trustManagerTwo)
228                 .build();
229 
230         assertThat(trustManager).isNotNull();
231     }
232 
233     @Test
234     void createTrustManagerFromMultipleTrustManagersUsingVarArgs() {
235         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
236         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
237 
238         X509ExtendedTrustManager trustManagerOne = TrustManagerUtils.createTrustManager(trustStoreOne);
239         X509ExtendedTrustManager trustManagerTwo = TrustManagerUtils.createTrustManager(trustStoreTwo);
240 
241         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
242                 .withTrustManagers(trustManagerOne, trustManagerTwo)
243                 .build();
244 
245         assertThat(trustManager).isNotNull();
246     }
247 
248     @Test
249     void createTrustManagerFromMultipleTrustManagersUsingList() {
250         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
251         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
252 
253         X509ExtendedTrustManager trustManagerOne = TrustManagerUtils.createTrustManager(trustStoreOne);
254         X509ExtendedTrustManager trustManagerTwo = TrustManagerUtils.createTrustManager(trustStoreTwo);
255 
256         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
257                 .withTrustManagers(Arrays.asList(trustManagerOne, trustManagerTwo))
258                 .build();
259 
260         assertThat(trustManager).isNotNull();
261     }
262 
263     @Test
264     void createTrustManagerFromMultipleTrustStoresUsingVarArgs() {
265         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
266         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
267 
268         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
269                 .withTrustStores(trustStoreOne, trustStoreTwo)
270                 .build();
271 
272         assertThat(trustManager).isNotNull();
273     }
274 
275     @Test
276     void createTrustManagerFromMultipleTrustStoresUsingList() {
277         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
278         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
279 
280         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
281                 .withTrustStores(Arrays.asList(trustStoreOne, trustStoreTwo))
282                 .build();
283 
284         assertThat(trustManager).isNotNull();
285     }
286 
287     @Test
288     void createTrustManagerFromMultipleTrustStores() {
289         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
290         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
291 
292         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
293                 .withTrustStore(trustStoreOne)
294                 .withTrustStore(trustStoreTwo)
295                 .build();
296 
297         assertThat(trustManager).isNotNull();
298     }
299 
300     @Test
301     void loadLinuxSystemKeyStoreReturnsOptionalOfEmpty() {
302         System.setProperty("os.name", "linux");
303 
304         Optional<X509ExtendedTrustManager> trustManager = TrustManagerUtils.createTrustManagerWithSystemTrustedCertificates();
305         assertThat(trustManager).isNotPresent();
306 
307         resetOsName();
308     }
309 
310     @Test
311     void createTrustManagerFromMultipleTrustStoresWithTrustManagerFactoryAlgorithm() {
312         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
313         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
314 
315         X509ExtendedTrustManager trustManager = TrustManagerUtils.trustManagerBuilder()
316                 .withTrustStore(trustStoreOne, TrustManagerFactory.getDefaultAlgorithm())
317                 .withTrustStore(trustStoreTwo, TrustManagerFactory.getDefaultAlgorithm())
318                 .build();
319 
320         assertThat(trustManager).isNotNull();
321     }
322 
323     @Test
324     void throwExceptionWhenInvalidTrustManagerAlgorithmIsProvided() {
325         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
326 
327         assertThatThrownBy(() -> TrustManagerUtils.createTrustManager(trustStore, "ABCD"))
328                 .isInstanceOf(GenericSecurityException.class)
329                 .hasMessage("java.security.NoSuchAlgorithmException: ABCD TrustManagerFactory not available");
330     }
331 
332     @Test
333     void throwExceptionWhenInvalidSecurityProviderNameIsProvided() {
334         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
335         String trustManagerFactoryAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
336 
337         assertThatThrownBy(() -> TrustManagerUtils.createTrustManager(trustStore, trustManagerFactoryAlgorithm, "test"))
338                 .isInstanceOf(GenericSecurityException.class)
339                 .hasMessage("java.security.NoSuchProviderException: no such provider: test");
340     }
341 
342     @Test
343     void throwExceptionWhenInvalidSecurityProviderNameIsProvidedForTheTrustManagerFactoryAlgorithm() {
344         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
345         String trustManagerFactoryAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
346 
347         assertThatThrownBy(() -> TrustManagerUtils.createTrustManager(trustStore, trustManagerFactoryAlgorithm, "SUN"))
348                 .isInstanceOf(GenericSecurityException.class)
349                 .hasMessage("java.security.NoSuchAlgorithmException: no such algorithm: PKIX for provider SUN");
350     }
351 
352     @Test
353     void throwExceptionWhenInvalidSecurityProviderIsProvidedForTheTrustManagerFactoryAlgorithm() {
354         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
355         String trustManagerFactoryAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
356         Provider sunSecurityProvider = Security.getProvider("SUN");
357 
358         assertThatThrownBy(() -> TrustManagerUtils.createTrustManager(trustStore, trustManagerFactoryAlgorithm, sunSecurityProvider))
359                 .isInstanceOf(GenericSecurityException.class)
360                 .hasMessage("java.security.NoSuchAlgorithmException: no such algorithm: PKIX for provider SUN");
361     }
362 
363     @Test
364     void throwGenericSecurityExceptionWhenTrustManagerFactoryCanNotInitializeWithTheProvidedTrustStore() throws KeyStoreException {
365         KeyStore trustStore = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
366         TrustManagerFactory trustManagerFactory = mock(TrustManagerFactory.class);
367 
368         doThrow(new KeyStoreException("KABOOOM!")).when(trustManagerFactory).init(any(KeyStore.class));
369 
370         assertThatThrownBy(() -> TrustManagerUtils.createTrustManager(trustStore, trustManagerFactory))
371                 .isInstanceOf(GenericSecurityException.class)
372                 .hasMessage("java.security.KeyStoreException: KABOOOM!");
373     }
374 
375     @Test
376     void throwGenericTrustManagerExceptionWhenProvidingEmptyListOfTrustManagersWhenCombining() {
377         List<X509TrustManager> trustManagers = Collections.emptyList();
378         assertThatThrownBy(() -> TrustManagerUtils.combine(trustManagers))
379                 .isInstanceOf(GenericTrustManagerException.class)
380                 .hasMessage("Input does not contain TrustManager");
381     }
382 
383     @Test
384     void throwExceptionWhenUnsupportedTrustManagerIsProvidedWhenSwappingTrustManager() {
385         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
386         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
387 
388         X509ExtendedTrustManager trustManagerOne = TrustManagerUtils.createTrustManager(trustStoreOne);
389         X509ExtendedTrustManager trustManagerTwo = TrustManagerUtils.createTrustManager(trustStoreTwo);
390 
391         assertThatThrownBy(() -> TrustManagerUtils.swapTrustManager(trustManagerOne, trustManagerTwo))
392                 .isInstanceOf(GenericTrustManagerException.class)
393                 .hasMessage("The baseTrustManager is from the instance of [sun.security.ssl.X509TrustManagerImpl] " +
394                         "and should be an instance of [nl.altindag.ssl.trustmanager.HotSwappableX509ExtendedTrustManager].");
395     }
396 
397     @Test
398     void throwExceptionWhenUnsupportedTrustManagerIsProvidedWhenSwappingTrustManagerWithANewTrustManager() {
399         KeyStore trustStoreOne = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + TRUSTSTORE_FILE_NAME, TRUSTSTORE_PASSWORD);
400         KeyStore trustStoreTwo = KeyStoreUtils.loadKeyStore(KEYSTORE_LOCATION + "truststore-containing-github.jks", TRUSTSTORE_PASSWORD);
401 
402         X509ExtendedTrustManager baseTrustManager = TrustManagerUtils.createSwappableTrustManager(TrustManagerUtils.createTrustManager(trustStoreOne));
403         X509ExtendedTrustManager newTrustManager = TrustManagerUtils.createSwappableTrustManager(TrustManagerUtils.createTrustManager(trustStoreTwo));
404 
405         assertThatThrownBy(() -> TrustManagerUtils.swapTrustManager(baseTrustManager, newTrustManager))
406                 .isInstanceOf(GenericTrustManagerException.class)
407                 .hasMessage("The newTrustManager should not be an instance of [nl.altindag.ssl.trustmanager.HotSwappableX509ExtendedTrustManager]");
408     }
409 
410     private void resetOsName() {
411         System.setProperty("os.name", ORIGINAL_OS_NAME);
412     }
413 
414 }