package io.grpc; import com.google.common.base.Preconditions; import com.google.common.io.ByteStreams; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.Set; import javax.net.ssl.KeyManager; import javax.net.ssl.TrustManager; /* loaded from: classes6.dex */ public final class TlsServerCredentials extends ServerCredentials { private final byte[] certificateChain; private final ClientAuth clientAuth; private final boolean fakeFeature; private final List keyManagers; private final byte[] privateKey; private final String privateKeyPassword; private final byte[] rootCertificates; private final List trustManagers; /* loaded from: classes6.dex */ public enum ClientAuth { NONE, OPTIONAL, REQUIRE } /* loaded from: classes6.dex */ public enum Feature { FAKE, MTLS, CUSTOM_MANAGERS } public static ServerCredentials create(File file, File file2) throws IOException { return newBuilder().keyManager(file, file2).build(); } public static ServerCredentials create(InputStream inputStream, InputStream inputStream2) throws IOException { return newBuilder().keyManager(inputStream, inputStream2).build(); } TlsServerCredentials(Builder builder) { this.fakeFeature = builder.fakeFeature; this.certificateChain = builder.certificateChain; this.privateKey = builder.privateKey; this.privateKeyPassword = builder.privateKeyPassword; this.keyManagers = builder.keyManagers; this.clientAuth = builder.clientAuth; this.rootCertificates = builder.rootCertificates; this.trustManagers = builder.trustManagers; } public final byte[] getCertificateChain() { byte[] bArr = this.certificateChain; if (bArr == null) { return null; } return Arrays.copyOf(bArr, bArr.length); } public final byte[] getPrivateKey() { byte[] bArr = this.privateKey; if (bArr == null) { return null; } return Arrays.copyOf(bArr, bArr.length); } public final byte[] getRootCertificates() { byte[] bArr = this.rootCertificates; if (bArr == null) { return null; } return Arrays.copyOf(bArr, bArr.length); } public final Set incomprehensible(Set set) { EnumSet noneOf = EnumSet.noneOf(Feature.class); if (this.fakeFeature) { requiredFeature(set, noneOf, Feature.FAKE); } if (this.clientAuth != ClientAuth.NONE) { requiredFeature(set, noneOf, Feature.MTLS); } if (this.keyManagers != null || this.trustManagers != null) { requiredFeature(set, noneOf, Feature.CUSTOM_MANAGERS); } return Collections.unmodifiableSet(noneOf); } private static void requiredFeature(Set set, Set set2, Feature feature) { if (set.contains(feature)) { return; } set2.add(feature); } public static Builder newBuilder() { return new Builder(); } /* loaded from: classes6.dex */ public static final class Builder { private byte[] certificateChain; private ClientAuth clientAuth; private boolean fakeFeature; private List keyManagers; private byte[] privateKey; private String privateKeyPassword; private byte[] rootCertificates; private List trustManagers; private Builder() { this.clientAuth = ClientAuth.NONE; } public final Builder keyManager(File file, File file2) throws IOException { return keyManager(file, file2, (String) null); } /* JADX WARN: Code restructure failed: missing block: B:14:0x001a, code lost: r2 = move-exception; */ /* JADX WARN: Code restructure failed: missing block: B:16:0x001e, code lost: throw r2; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public final io.grpc.TlsServerCredentials.Builder keyManager(java.io.File r2, java.io.File r3, java.lang.String r4) throws java.io.IOException { /* r1 = this; java.io.FileInputStream r0 = new java.io.FileInputStream r0.(r2) java.io.FileInputStream r2 = new java.io.FileInputStream // Catch: java.lang.Throwable -> L1a r2.(r3) // Catch: java.lang.Throwable -> L1a io.grpc.TlsServerCredentials$Builder r3 = r1.keyManager(r0, r2, r4) // Catch: java.lang.Throwable -> L15 r2.close() // Catch: java.lang.Throwable -> L1a r0.close() return r3 L15: r3 = move-exception r2.close() // Catch: java.lang.Throwable -> L1a throw r3 // Catch: java.lang.Throwable -> L1a L1a: r2 = move-exception r0.close() throw r2 */ throw new UnsupportedOperationException("Method not decompiled: io.grpc.TlsServerCredentials.Builder.keyManager(java.io.File, java.io.File, java.lang.String):io.grpc.TlsServerCredentials$Builder"); } public final Builder keyManager(InputStream inputStream, InputStream inputStream2) throws IOException { return keyManager(inputStream, inputStream2, (String) null); } public final Builder keyManager(InputStream inputStream, InputStream inputStream2, String str) throws IOException { byte[] byteArray = ByteStreams.toByteArray(inputStream); byte[] byteArray2 = ByteStreams.toByteArray(inputStream2); clearKeyManagers(); this.certificateChain = byteArray; this.privateKey = byteArray2; this.privateKeyPassword = str; return this; } public final Builder keyManager(KeyManager... keyManagerArr) { List unmodifiableList = Collections.unmodifiableList(new ArrayList(Arrays.asList(keyManagerArr))); clearKeyManagers(); this.keyManagers = unmodifiableList; return this; } public final Builder clientAuth(ClientAuth clientAuth) { Preconditions.checkNotNull(clientAuth, "clientAuth"); this.clientAuth = clientAuth; return this; } public final Builder trustManager(File file) throws IOException { FileInputStream fileInputStream = new FileInputStream(file); try { return trustManager(fileInputStream); } finally { fileInputStream.close(); } } public final Builder trustManager(InputStream inputStream) throws IOException { byte[] byteArray = ByteStreams.toByteArray(inputStream); clearTrustManagers(); this.rootCertificates = byteArray; return this; } public final Builder trustManager(TrustManager... trustManagerArr) { List unmodifiableList = Collections.unmodifiableList(new ArrayList(Arrays.asList(trustManagerArr))); clearTrustManagers(); this.trustManagers = unmodifiableList; return this; } public final ServerCredentials build() { if (this.certificateChain == null && this.keyManagers == null) { throw new IllegalStateException("A key manager is required"); } return new TlsServerCredentials(this); } public final Builder requireFakeFeature() { this.fakeFeature = true; return this; } private void clearTrustManagers() { this.rootCertificates = null; this.trustManagers = null; } private void clearKeyManagers() { this.certificateChain = null; this.privateKey = null; this.privateKeyPassword = null; this.keyManagers = null; } } public final List getTrustManagers() { return this.trustManagers; } public final String getPrivateKeyPassword() { return this.privateKeyPassword; } public final List getKeyManagers() { return this.keyManagers; } public final ClientAuth getClientAuth() { return this.clientAuth; } }