what-the-bank/sources/org/bouncycastle/crypto/tls/AbstractTlsClient.java

158 lines
5.9 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package org.bouncycastle.crypto.tls;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Vector;
/* loaded from: classes6.dex */
public abstract class AbstractTlsClient extends AbstractTlsPeer implements TlsClient {
protected TlsCipherFactory cipherFactory;
protected short[] clientECPointFormats;
protected TlsClientContext context;
protected int[] namedCurves;
protected int selectedCipherSuite;
protected short selectedCompressionMethod;
protected short[] serverECPointFormats;
protected Vector supportedSignatureAlgorithms;
@Override // org.bouncycastle.crypto.tls.TlsClient
public Vector getClientSupplementalData() throws IOException {
return null;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public TlsSession getSessionToResume() {
return null;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public boolean isFallback() {
return false;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void notifyNewSessionTicket(NewSessionTicket newSessionTicket) throws IOException {
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void notifySessionID(byte[] bArr) {
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void processServerSupplementalData(Vector vector) throws IOException {
if (vector != null) {
throw new TlsFatalAlert((short) 10);
}
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void processServerExtensions(Hashtable hashtable) throws IOException {
if (hashtable != null) {
checkForUnexpectedServerExtension(hashtable, TlsUtils.EXT_signature_algorithms);
checkForUnexpectedServerExtension(hashtable, TlsECCUtils.EXT_elliptic_curves);
if (TlsECCUtils.isECCCipherSuite(this.selectedCipherSuite)) {
this.serverECPointFormats = TlsECCUtils.getSupportedPointFormatsExtension(hashtable);
} else {
checkForUnexpectedServerExtension(hashtable, TlsECCUtils.EXT_ec_point_formats);
}
checkForUnexpectedServerExtension(hashtable, TlsExtensionsUtils.EXT_padding);
}
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void notifyServerVersion(ProtocolVersion protocolVersion) throws IOException {
if (!getMinimumVersion().isEqualOrEarlierVersionOf(protocolVersion)) {
throw new TlsFatalAlert((short) 70);
}
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void notifySelectedCompressionMethod(short s) {
this.selectedCompressionMethod = s;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void notifySelectedCipherSuite(int i) {
this.selectedCipherSuite = i;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public void init(TlsClientContext tlsClientContext) {
this.context = tlsClientContext;
}
public ProtocolVersion getMinimumVersion() {
return ProtocolVersion.TLSv10;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public short[] getCompressionMethods() {
return new short[]{0};
}
@Override // org.bouncycastle.crypto.tls.TlsPeer
public TlsCompression getCompression() throws IOException {
if (this.selectedCompressionMethod == 0) {
return new TlsNullCompression();
}
throw new TlsFatalAlert((short) 80);
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public ProtocolVersion getClientVersion() {
return ProtocolVersion.TLSv12;
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public ProtocolVersion getClientHelloRecordLayerVersion() {
return getClientVersion();
}
@Override // org.bouncycastle.crypto.tls.TlsClient
public Hashtable getClientExtensions() throws IOException {
Hashtable hashtable = null;
if (TlsUtils.isSignatureAlgorithmsExtensionAllowed(this.context.getClientVersion())) {
this.supportedSignatureAlgorithms = TlsUtils.getDefaultSupportedSignatureAlgorithms();
hashtable = TlsExtensionsUtils.ensureExtensionsInitialised(null);
TlsUtils.addSignatureAlgorithmsExtension(hashtable, this.supportedSignatureAlgorithms);
}
if (!TlsECCUtils.containsECCCipherSuites(getCipherSuites())) {
return hashtable;
}
this.namedCurves = new int[]{23, 24};
this.clientECPointFormats = new short[]{0, 1, 2};
Hashtable ensureExtensionsInitialised = TlsExtensionsUtils.ensureExtensionsInitialised(hashtable);
TlsECCUtils.addSupportedEllipticCurvesExtension(ensureExtensionsInitialised, this.namedCurves);
TlsECCUtils.addSupportedPointFormatsExtension(ensureExtensionsInitialised, this.clientECPointFormats);
return ensureExtensionsInitialised;
}
@Override // org.bouncycastle.crypto.tls.TlsPeer
public TlsCipher getCipher() throws IOException {
return this.cipherFactory.createCipher(this.context, TlsUtils.getEncryptionAlgorithm(this.selectedCipherSuite), TlsUtils.getMACAlgorithm(this.selectedCipherSuite));
}
protected void checkForUnexpectedServerExtension(Hashtable hashtable, Integer num) throws IOException {
byte[] extensionData = TlsUtils.getExtensionData(hashtable, num);
if (extensionData != null && !allowUnexpectedServerExtension(num, extensionData)) {
throw new TlsFatalAlert((short) 47);
}
}
protected boolean allowUnexpectedServerExtension(Integer num, byte[] bArr) throws IOException {
if (num.intValue() != 10) {
return false;
}
TlsECCUtils.readSupportedEllipticCurvesExtension(bArr);
return true;
}
public AbstractTlsClient(TlsCipherFactory tlsCipherFactory) {
this.cipherFactory = tlsCipherFactory;
}
public AbstractTlsClient() {
this(new DefaultTlsCipherFactory());
}
}