257 lines
10 KiB
Java
257 lines
10 KiB
Java
package org.bouncycastle.crypto.tls;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.util.Enumeration;
|
|
import java.util.Hashtable;
|
|
import java.util.Vector;
|
|
import org.bouncycastle.util.Integers;
|
|
|
|
/* loaded from: classes6.dex */
|
|
class DTLSReliableHandshake {
|
|
private static final int MAX_RECEIVE_AHEAD = 10;
|
|
private TlsHandshakeHash handshakeHash;
|
|
private DTLSRecordLayer recordLayer;
|
|
private Hashtable currentInboundFlight = new Hashtable();
|
|
private Hashtable previousInboundFlight = null;
|
|
private Vector outboundFlight = new Vector();
|
|
private boolean sending = true;
|
|
private int message_seq = 0;
|
|
private int next_receive_seq = 0;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void sendMessage(short s, byte[] bArr) throws IOException {
|
|
TlsUtils.checkUint24(bArr.length);
|
|
if (!this.sending) {
|
|
checkInboundFlight();
|
|
this.sending = true;
|
|
this.outboundFlight.removeAllElements();
|
|
}
|
|
int i = this.message_seq;
|
|
this.message_seq = i + 1;
|
|
Message message = new Message(i, s, bArr);
|
|
this.outboundFlight.addElement(message);
|
|
writeMessage(message);
|
|
updateHandshakeMessagesDigest(message);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void resetHandshakeMessagesDigest() {
|
|
this.handshakeHash.reset();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public byte[] receiveMessageBody(short s) throws IOException {
|
|
Message receiveMessage = receiveMessage();
|
|
if (receiveMessage.getType() == s) {
|
|
return receiveMessage.getBody();
|
|
}
|
|
throw new TlsFatalAlert((short) 10);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* JADX WARN: Code restructure failed: missing block: B:73:0x00f7, code lost:
|
|
|
|
continue;
|
|
*/
|
|
/*
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
To view partially-correct add '--show-bad-code' argument
|
|
*/
|
|
public org.bouncycastle.crypto.tls.DTLSReliableHandshake.Message receiveMessage() throws java.io.IOException {
|
|
/*
|
|
Method dump skipped, instructions count: 257
|
|
To view this dump add '--comments-level debug' option
|
|
*/
|
|
throw new UnsupportedOperationException("Method not decompiled: org.bouncycastle.crypto.tls.DTLSReliableHandshake.receiveMessage():org.bouncycastle.crypto.tls.DTLSReliableHandshake$Message");
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public TlsHandshakeHash prepareToFinish() {
|
|
TlsHandshakeHash tlsHandshakeHash = this.handshakeHash;
|
|
this.handshakeHash = tlsHandshakeHash.stopTracking();
|
|
return tlsHandshakeHash;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void notifyHelloComplete() {
|
|
this.handshakeHash = this.handshakeHash.notifyPRFDetermined();
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public TlsHandshakeHash getHandshakeHash() {
|
|
return this.handshakeHash;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void finish() {
|
|
DTLSHandshakeRetransmit dTLSHandshakeRetransmit;
|
|
if (!this.sending) {
|
|
checkInboundFlight();
|
|
} else if (this.currentInboundFlight != null) {
|
|
dTLSHandshakeRetransmit = new DTLSHandshakeRetransmit(this) { // from class: org.bouncycastle.crypto.tls.DTLSReliableHandshake.1
|
|
final DTLSReliableHandshake this$0;
|
|
|
|
@Override // org.bouncycastle.crypto.tls.DTLSHandshakeRetransmit
|
|
public void receivedHandshakeRecord(int i, byte[] bArr, int i2, int i3) throws IOException {
|
|
int readUint16;
|
|
DTLSReassembler dTLSReassembler;
|
|
if (i3 < 12) {
|
|
return;
|
|
}
|
|
int readUint24 = TlsUtils.readUint24(bArr, i2 + 9);
|
|
if (i3 == readUint24 + 12 && (readUint16 = TlsUtils.readUint16(bArr, i2 + 4)) < this.this$0.next_receive_seq) {
|
|
short readUint8 = TlsUtils.readUint8(bArr, i2);
|
|
if (i != (readUint8 == 20 ? 1 : 0)) {
|
|
return;
|
|
}
|
|
int readUint242 = TlsUtils.readUint24(bArr, i2 + 1);
|
|
int readUint243 = TlsUtils.readUint24(bArr, i2 + 6);
|
|
if (readUint243 + readUint24 <= readUint242 && (dTLSReassembler = (DTLSReassembler) this.this$0.currentInboundFlight.get(Integers.valueOf(readUint16))) != null) {
|
|
dTLSReassembler.contributeFragment(readUint8, readUint242, bArr, i2 + 12, readUint243, readUint24);
|
|
if (DTLSReliableHandshake.checkAll(this.this$0.currentInboundFlight)) {
|
|
this.this$0.resendOutboundFlight();
|
|
DTLSReliableHandshake.resetAll(this.this$0.currentInboundFlight);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
{
|
|
this.this$0 = this;
|
|
}
|
|
};
|
|
this.recordLayer.handshakeSuccessful(dTLSHandshakeRetransmit);
|
|
}
|
|
dTLSHandshakeRetransmit = null;
|
|
this.recordLayer.handshakeSuccessful(dTLSHandshakeRetransmit);
|
|
}
|
|
|
|
private void writeMessage(Message message) throws IOException {
|
|
int sendLimit = this.recordLayer.getSendLimit() - 12;
|
|
if (sendLimit <= 0) {
|
|
throw new TlsFatalAlert((short) 80);
|
|
}
|
|
int length = message.getBody().length;
|
|
int i = 0;
|
|
do {
|
|
int min = Math.min(length - i, sendLimit);
|
|
writeHandshakeFragment(message, i, min);
|
|
i += min;
|
|
} while (i < length);
|
|
}
|
|
|
|
private void writeHandshakeFragment(Message message, int i, int i2) throws IOException {
|
|
RecordLayerBuffer recordLayerBuffer = new RecordLayerBuffer(i2 + 12);
|
|
TlsUtils.writeUint8(message.getType(), (OutputStream) recordLayerBuffer);
|
|
TlsUtils.writeUint24(message.getBody().length, recordLayerBuffer);
|
|
TlsUtils.writeUint16(message.getSeq(), recordLayerBuffer);
|
|
TlsUtils.writeUint24(i, recordLayerBuffer);
|
|
TlsUtils.writeUint24(i2, recordLayerBuffer);
|
|
recordLayerBuffer.write(message.getBody(), i, i2);
|
|
recordLayerBuffer.sendToRecordLayer(this.recordLayer);
|
|
}
|
|
|
|
private Message updateHandshakeMessagesDigest(Message message) throws IOException {
|
|
if (message.getType() != 0) {
|
|
byte[] body = message.getBody();
|
|
byte[] bArr = new byte[12];
|
|
TlsUtils.writeUint8(message.getType(), bArr, 0);
|
|
TlsUtils.writeUint24(body.length, bArr, 1);
|
|
TlsUtils.writeUint16(message.getSeq(), bArr, 4);
|
|
TlsUtils.writeUint24(0, bArr, 6);
|
|
TlsUtils.writeUint24(body.length, bArr, 9);
|
|
this.handshakeHash.update(bArr, 0, 12);
|
|
this.handshakeHash.update(body, 0, body.length);
|
|
}
|
|
return message;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static void resetAll(Hashtable hashtable) {
|
|
Enumeration elements = hashtable.elements();
|
|
while (elements.hasMoreElements()) {
|
|
((DTLSReassembler) elements.nextElement()).reset();
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public void resendOutboundFlight() throws IOException {
|
|
this.recordLayer.resetWriteEpoch();
|
|
for (int i = 0; i < this.outboundFlight.size(); i++) {
|
|
writeMessage((Message) this.outboundFlight.elementAt(i));
|
|
}
|
|
}
|
|
|
|
private void prepareInboundFlight() {
|
|
resetAll(this.currentInboundFlight);
|
|
this.previousInboundFlight = this.currentInboundFlight;
|
|
this.currentInboundFlight = new Hashtable();
|
|
}
|
|
|
|
private void checkInboundFlight() {
|
|
Enumeration keys = this.currentInboundFlight.keys();
|
|
while (keys.hasMoreElements()) {
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static boolean checkAll(Hashtable hashtable) {
|
|
Enumeration elements = hashtable.elements();
|
|
while (elements.hasMoreElements()) {
|
|
if (((DTLSReassembler) elements.nextElement()).getBodyIfComplete() == null) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes6.dex */
|
|
public static class Message {
|
|
private final byte[] body;
|
|
private final int message_seq;
|
|
private final short msg_type;
|
|
|
|
public short getType() {
|
|
return this.msg_type;
|
|
}
|
|
|
|
public int getSeq() {
|
|
return this.message_seq;
|
|
}
|
|
|
|
public byte[] getBody() {
|
|
return this.body;
|
|
}
|
|
|
|
private Message(int i, short s, byte[] bArr) {
|
|
this.message_seq = i;
|
|
this.msg_type = s;
|
|
this.body = bArr;
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes6.dex */
|
|
public static class RecordLayerBuffer extends ByteArrayOutputStream {
|
|
void sendToRecordLayer(DTLSRecordLayer dTLSRecordLayer) throws IOException {
|
|
dTLSRecordLayer.send(((ByteArrayOutputStream) this).buf, 0, ((ByteArrayOutputStream) this).count);
|
|
((ByteArrayOutputStream) this).buf = null;
|
|
}
|
|
|
|
RecordLayerBuffer(int i) {
|
|
super(i);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public DTLSReliableHandshake(TlsContext tlsContext, DTLSRecordLayer dTLSRecordLayer) {
|
|
this.recordLayer = dTLSRecordLayer;
|
|
DeferredHash deferredHash = new DeferredHash();
|
|
this.handshakeHash = deferredHash;
|
|
deferredHash.init(tlsContext);
|
|
}
|
|
}
|