@Override public int getReceiveLimit() throws IOException { return transport.getReceiveLimit(); }
@Override public int getSendLimit() throws IOException { return transport.getSendLimit(); }
@Override public int receive(byte[] buf, int off, int len, int waitMillis) throws IOException { int length = transport.receive(buf, off, len, waitMillis); if (length >= 0) { dumpDatagram("Received", buf, off, length); } return length; }
@Override public void send(byte[] buf, int off, int len) throws IOException { dumpDatagram("Sending", buf, off, len); transport.send(buf, off, len); }
private void closeTransport() { if (!closed) { /* * RFC 5246 7.2.1. Unless some other fatal alert has been transmitted, each party is * required to send a close_notify alert before closing the write side of the * connection. The other party MUST respond with a close_notify alert of its own and * close down the connection immediately, discarding any pending writes. */ try { if (!failed) { warn(AlertDescription.close_notify, null); } transport.close(); } catch (Exception e) { // Ignore } closed = true; } }
@Override public void send(byte[] buf, int off, int len) throws IOException { dumpDatagram("Sending", buf, off, len); transport.send(buf, off, len); }
private void closeTransport() { if (!closed) { /* * RFC 5246 7.2.1. Unless some other fatal alert has been transmitted, each party is * required to send a close_notify alert before closing the write side of the * connection. The other party MUST respond with a close_notify alert of its own and * close down the connection immediately, discarding any pending writes. */ try { if (!failed) { warn(AlertDescription.close_notify, null); } transport.close(); } catch (Exception e) { // Ignore } closed = true; } }
System.arraycopy(ciphertext, 0, record, RECORD_HEADER_LENGTH, ciphertext.length); transport.send(record, 0, record.length);
@Override public int receive(byte[] buf, int off, int len, int waitMillis) throws IOException { int length = transport.receive(buf, off, len, waitMillis); if (length >= 0) { dumpDatagram("Received", buf, off, length); } return length; }
@Override public int getSendLimit() throws IOException { return transport.getSendLimit(); }
@Override public int getReceiveLimit() throws IOException { return transport.getReceiveLimit(); }
private void sendRecord(short contentType, byte[] buf, int off, int len) throws IOException { if (len > this.plaintextLimit) { throw new TlsFatalAlert(AlertDescription.internal_error); } /* * RFC 5264 6.2.1 Implementations MUST NOT send zero-length fragments of Handshake, Alert, * or ChangeCipherSpec content types. */ if (len < 1 && contentType != ContentType.application_data) { throw new TlsFatalAlert(AlertDescription.internal_error); } int recordEpoch = writeEpoch.getEpoch(); long recordSequenceNumber = writeEpoch.allocateSequenceNumber(); byte[] ciphertext = writeEpoch.getCipher().encodePlaintext( getMacSequenceNumber(recordEpoch, recordSequenceNumber), contentType, buf, off, len); // TODO Check the ciphertext length? byte[] record = new byte[ciphertext.length + RECORD_HEADER_LENGTH]; TlsUtils.writeUint8(contentType, record, 0); ProtocolVersion version = discoveredPeerVersion != null ? discoveredPeerVersion : context.getClientVersion(); TlsUtils.writeVersion(version, record, 1); TlsUtils.writeUint16(recordEpoch, record, 3); TlsUtils.writeUint48(recordSequenceNumber, record, 5); TlsUtils.writeUint16(ciphertext.length, record, 11); System.arraycopy(ciphertext, 0, record, RECORD_HEADER_LENGTH, ciphertext.length); transport.send(record, 0, record.length); }
private int receiveRecord(byte[] buf, int off, int len, int waitMillis) throws IOException { if (recordQueue.available() > 0) { int length = 0; if (recordQueue.available() >= RECORD_HEADER_LENGTH) { byte[] lengthBytes = new byte[2]; recordQueue.read(lengthBytes, 0, 2, 11); length = TlsUtils.readUint16(lengthBytes, 0); } int received = Math.min(recordQueue.available(), RECORD_HEADER_LENGTH + length); recordQueue.removeData(buf, off, received, 0); return received; } int received = transport.receive(buf, off, len, waitMillis); if (received >= RECORD_HEADER_LENGTH) { int fragmentLength = TlsUtils.readUint16(buf, off + 11); int recordLength = RECORD_HEADER_LENGTH + fragmentLength; if (received > recordLength) { recordQueue.addData(buf, off + recordLength, received - recordLength); received = recordLength; } } return received; }
public int getSendLimit() throws IOException { return Math.min(this.plaintextLimit, writeEpoch.getCipher().getPlaintextLimit(transport.getSendLimit() - RECORD_HEADER_LENGTH)); }
public int getReceiveLimit() throws IOException { return Math.min(this.plaintextLimit, readEpoch.getCipher().getPlaintextLimit(transport.getReceiveLimit() - RECORD_HEADER_LENGTH)); }
private int receiveRecord(byte[] buf, int off, int len, int waitMillis) throws IOException { if (recordQueue.available() > 0) { int length = 0; if (recordQueue.available() >= RECORD_HEADER_LENGTH) { byte[] lengthBytes = new byte[2]; recordQueue.read(lengthBytes, 0, 2, 11); length = TlsUtils.readUint16(lengthBytes, 0); } int received = Math.min(recordQueue.available(), RECORD_HEADER_LENGTH + length); recordQueue.removeData(buf, off, received, 0); return received; } int received = transport.receive(buf, off, len, waitMillis); if (received >= RECORD_HEADER_LENGTH) { int fragmentLength = TlsUtils.readUint16(buf, off + 11); int recordLength = RECORD_HEADER_LENGTH + fragmentLength; if (received > recordLength) { recordQueue.addData(buf, off + recordLength, received - recordLength); received = recordLength; } } return received; }
public int getSendLimit() throws IOException { return Math.min(this.plaintextLimit, writeEpoch.getCipher().getPlaintextLimit(transport.getSendLimit() - RECORD_HEADER_LENGTH)); }
public int getReceiveLimit() throws IOException { return Math.min(this.plaintextLimit, readEpoch.getCipher().getPlaintextLimit(transport.getReceiveLimit() - RECORD_HEADER_LENGTH)); }