|
38 | 38 | import java.nio.file.Files; |
39 | 39 | import java.nio.file.StandardCopyOption; |
40 | 40 | import org.glassfish.jersey.logging.LoggingFeature; |
| 41 | + |
| 42 | +import java.security.KeyStore; |
| 43 | +import java.security.KeyStoreException; |
| 44 | +import java.security.NoSuchAlgorithmException; |
41 | 45 | import java.security.SecureRandom; |
42 | 46 | import java.security.cert.CertificateException; |
43 | 47 | import java.security.cert.X509Certificate; |
@@ -84,7 +88,7 @@ public ApiClient() { |
84 | 88 | this.dateFormat = new RFC3339DateFormat(); |
85 | 89 |
|
86 | 90 | // Set default User-Agent. |
87 | | - setUserAgent("Swagger-Codegen/3.15.0-RC1/java"); |
| 91 | + setUserAgent("Swagger-Codegen/3.15.0/java"); |
88 | 92 |
|
89 | 93 | // Setup authentications (key: authentication name, value: authentication). |
90 | 94 | authentications = new HashMap<String, Authentication>(); |
@@ -1699,28 +1703,47 @@ public boolean verify(String hostname, SSLSession session) { |
1699 | 1703 | } |
1700 | 1704 |
|
1701 | 1705 | class SecureTrustManager implements X509TrustManager { |
| 1706 | + private X509TrustManager x509TrustManager = null; |
| 1707 | + |
| 1708 | + SecureTrustManager() { |
| 1709 | + try { |
| 1710 | + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
| 1711 | + KeyStore ks = null; |
| 1712 | + trustManagerFactory.init(ks); |
| 1713 | + for (TrustManager trustManager: trustManagerFactory.getTrustManagers()) { |
| 1714 | + if (trustManager instanceof X509TrustManager) { |
| 1715 | + x509TrustManager = (X509TrustManager) trustManager; |
| 1716 | + break; |
| 1717 | + } |
| 1718 | + } |
| 1719 | + } catch (final Exception ex) { |
| 1720 | + System.err.println("failed to initialize SecureTrustManager: " + ex); |
| 1721 | + } |
| 1722 | + } |
1702 | 1723 |
|
1703 | 1724 | @Override |
1704 | 1725 | public void checkClientTrusted(X509Certificate[] arg0, String arg1) |
1705 | 1726 | throws CertificateException { |
| 1727 | + if (x509TrustManager == null) { |
| 1728 | + throw new CertificateException("x509TrustManager is null. certs could not be loaded."); |
| 1729 | + } |
| 1730 | + |
| 1731 | + x509TrustManager.checkClientTrusted(arg0, arg1); |
1706 | 1732 | } |
1707 | 1733 |
|
1708 | 1734 | @Override |
1709 | 1735 | public void checkServerTrusted(X509Certificate[] arg0, String arg1) |
1710 | 1736 | throws CertificateException { |
| 1737 | + if (x509TrustManager == null) { |
| 1738 | + throw new CertificateException("x509TrustManager is null. certs could not be loaded."); |
| 1739 | + } |
| 1740 | + |
| 1741 | + x509TrustManager.checkServerTrusted(arg0, arg1); |
1711 | 1742 | } |
1712 | 1743 |
|
1713 | 1744 | @Override |
1714 | 1745 | public X509Certificate[] getAcceptedIssuers() { |
1715 | | - return new X509Certificate[0]; |
1716 | | - } |
1717 | | - |
1718 | | - public boolean isClientTrusted(X509Certificate[] arg0) { |
1719 | | - return true; |
1720 | | - } |
1721 | | - |
1722 | | - public boolean isServerTrusted(X509Certificate[] arg0) { |
1723 | | - return true; |
| 1746 | + return x509TrustManager.getAcceptedIssuers(); |
1724 | 1747 | } |
1725 | 1748 |
|
1726 | 1749 | } |
|
0 commit comments