|
18 | 18 |
|
19 | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | 20 | import static com.google.common.base.Preconditions.checkState; |
21 | | -import static io.grpc.internal.CertificateUtils.getX509ExtendedTrustManager; |
22 | 21 |
|
23 | 22 | import com.google.common.annotations.VisibleForTesting; |
24 | 23 | import com.google.common.base.Preconditions; |
|
42 | 41 | import io.grpc.Status; |
43 | 42 | import io.grpc.TlsChannelCredentials; |
44 | 43 | import io.grpc.TlsServerCredentials; |
| 44 | +import io.grpc.internal.CertificateUtils; |
45 | 45 | import io.grpc.internal.GrpcAttributes; |
46 | 46 | import io.grpc.internal.GrpcUtil; |
47 | 47 | import io.grpc.internal.ObjectPool; |
|
79 | 79 | import java.util.Arrays; |
80 | 80 | import java.util.EnumSet; |
81 | 81 | import java.util.LinkedHashMap; |
| 82 | +import java.util.List; |
82 | 83 | import java.util.Map; |
83 | 84 | import java.util.Optional; |
84 | 85 | import java.util.Set; |
@@ -130,27 +131,24 @@ public static FromChannelCredentialsResult from(ChannelCredentials creds) { |
130 | 131 | new ByteArrayInputStream(tlsCreds.getPrivateKey()), |
131 | 132 | tlsCreds.getPrivateKeyPassword()); |
132 | 133 | } |
133 | | - Optional<TrustManager> x509ExtendedTrustManager; |
134 | 134 | try { |
| 135 | + List<TrustManager> trustManagers; |
135 | 136 | if (tlsCreds.getTrustManagers() != null) { |
136 | | - builder.trustManager(new FixedTrustManagerFactory(tlsCreds.getTrustManagers())); |
137 | | - x509ExtendedTrustManager = tlsCreds.getTrustManagers().stream().filter( |
138 | | - trustManager -> trustManager instanceof X509ExtendedTrustManager).findFirst(); |
| 137 | + trustManagers = tlsCreds.getTrustManagers(); |
139 | 138 | } else if (tlsCreds.getRootCertificates() != null) { |
140 | | - builder.trustManager(new ByteArrayInputStream(tlsCreds.getRootCertificates())); |
141 | | - x509ExtendedTrustManager = getX509ExtendedTrustManager(new ByteArrayInputStream( |
142 | | - tlsCreds.getRootCertificates())); |
| 139 | + trustManagers = CertificateUtils.getTrustManagers( |
| 140 | + new ByteArrayInputStream(tlsCreds.getRootCertificates())); |
143 | 141 | } else { // else use system default |
144 | 142 | TrustManagerFactory tmf = TrustManagerFactory.getInstance( |
145 | 143 | TrustManagerFactory.getDefaultAlgorithm()); |
146 | 144 | tmf.init((KeyStore) null); |
147 | | - x509ExtendedTrustManager = Arrays.stream(tmf.getTrustManagers()) |
148 | | - .filter(trustManager -> trustManager instanceof X509ExtendedTrustManager).findFirst(); |
| 145 | + trustManagers = Arrays.asList(tmf.getTrustManagers()); |
149 | 146 | } |
| 147 | + builder.trustManager(new FixedTrustManagerFactory(trustManagers)); |
| 148 | + Optional<TrustManager> x509ExtendedTrustManager = trustManagers.stream().filter( |
| 149 | + trustManager -> trustManager instanceof X509ExtendedTrustManager).findFirst(); |
150 | 150 | return FromChannelCredentialsResult.negotiator(tlsClientFactory(builder.build(), |
151 | | - x509ExtendedTrustManager.isPresent() |
152 | | - ? (X509ExtendedTrustManager) x509ExtendedTrustManager.get() |
153 | | - : null)); |
| 151 | + (X509ExtendedTrustManager) x509ExtendedTrustManager.orElse(null))); |
154 | 152 | } catch (SSLException | GeneralSecurityException ex) { |
155 | 153 | log.log(Level.FINE, "Exception building SslContext", ex); |
156 | 154 | return FromChannelCredentialsResult.error( |
@@ -1233,7 +1231,7 @@ public SSLParameters getSSLParameters() { |
1233 | 1231 | } |
1234 | 1232 | } |
1235 | 1233 |
|
1236 | | - static class FakeSslSession extends NoopSslSession { |
| 1234 | + static final class FakeSslSession extends NoopSslSession { |
1237 | 1235 | private final String peerHost; |
1238 | 1236 |
|
1239 | 1237 | FakeSslSession(String peerHost) { |
|
0 commit comments