path
stringlengths 9
117
| type
stringclasses 2
values | project
stringclasses 10
values | commit_hash
stringlengths 40
40
| commit_message
stringlengths 1
137
| ground_truth
stringlengths 0
2.74k
| main_code
stringlengths 102
3.37k
| context
stringlengths 0
14.7k
|
---|---|---|---|---|---|---|---|
aioquic.connection/QuicConnection.connection_made
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<7>:<add> self._push_crypto_data()
|
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
<0> if self.is_client:
<1> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
<2> is_client=self.is_client)
<3> self._init_tls()
<4> self.crypto_initialized = True
<5>
<6> self.tls.handle_message(b'', self.send_buffer)
<7>
|
===========unchanged ref 0===========
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.peer_cid = os.urandom(8)
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.crypto_initialized = False
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.crypto_initialized = True
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoPair
setup_initial(cid, is_client)
at: aioquic.tls
Epoch()
===========changed ref 0===========
# module: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SECRETS_LABELS = [
[None, 'QUIC_CLIENT_EARLY_TRAFFIC_SECRET', 'QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET',
'QUIC_CLIENT_TRAFFIC_SECRET_0'],
[None, None, 'QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET', 'QUIC_SERVER_TRAFFIC_SECRET_0']
]
SEND_PN_SIZE = 2
+ STREAM_FLAGS = 0x07
+ STREAM_FLAG_FIN = 1
+ STREAM_FLAG_LEN = 2
+ STREAM_FLAG_OFF = 4
===========changed ref 1===========
# module: aioquic.stream
class QuicStream:
+ @property
+ def stream_id(self):
+ return self.__stream_id
+
===========changed ref 2===========
# module: aioquic.stream
class QuicStream:
+ def has_data_to_send(self):
+ return bool(self._send_buffer)
+
===========changed ref 3===========
# module: aioquic.stream
class QuicStream:
+ def push_data(self, data):
+ """
+ Push data to send.
+ """
+ if data:
+ self._send_buffer += data
+
===========changed ref 4===========
# module: aioquic.stream
class QuicStream:
+ def __init__(self, stream_id=None):
- def __init__(self):
+ self._recv_buffer = bytearray()
- self._buffer = bytearray()
- self._received = RangeSet()
+ self._recv_start = 0
- self._start = 0
+ self._recv_ranges = RangeSet()
===========changed ref 5===========
# module: aioquic.stream
class QuicStream:
+ def get_frame(self, size):
+ """
+ Get a frame of data to send.
+ """
+ size = min(size, len(self._send_buffer))
+ frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start)
+ self._send_buffer = self._send_buffer[size:]
+ self._send_start += size
+ return frame
+
===========changed ref 6===========
# module: aioquic.packet
+ @contextmanager
+ def push_stream_frame(buf, stream_id, offset):
+ push_uint_var(buf, stream_id)
+ push_uint_var(buf, offset)
+ push_uint16(buf, 0)
+ start = buf.tell()
+ yield
+ end = buf.tell()
+ buf.seek(start - 2)
+ push_uint16(buf, (end - start) | 0x4000)
+ buf.seek(end)
+
===========changed ref 7===========
# module: aioquic.stream
class QuicStream:
def pull_data(self):
+ """
+ Pull received data.
+ """
# no data, or gap at start
+ if not self._recv_ranges or self._recv_ranges[0].start != self._recv_start:
- if not self._received or self._received[0].start != self._start:
return b''
+ r = self._recv_ranges.shift()
- r = self._received.shift()
pos = r.stop - r.start
+ data = self._recv_buffer[:pos]
- data = self._buffer[:pos]
+ self._recv_buffer = self._recv_buffer[pos:]
- self._buffer = self._buffer[pos:]
+ self._recv_start = r.stop
- self._start = r.stop
return data
===========changed ref 8===========
# module: aioquic.stream
class QuicStream:
def add_frame(self, frame: QuicStreamFrame):
+ """
+ Add a frame of received data.
+ """
+ pos = frame.offset - self._recv_start
- pos = frame.offset - self._start
count = len(frame.data)
# frame has been entirely consumed
if pos + count <= 0:
return
# frame has been partially consumed
if pos < 0:
count += pos
frame.data = frame.data[-pos:]
frame.offset -= pos
pos = 0
# marked received
+ self._recv_ranges.add(frame.offset, frame.offset + count)
- self._received.add(frame.offset, frame.offset + count)
# add data
+ gap = pos - len(self._recv_buffer)
- gap = pos - len(self._buffer)
if gap > 0:
+ self._recv_buffer += bytearray(gap)
- self._buffer += bytearray(gap)
+ self._recv_buffer[pos:pos + count] = frame.data
- self._buffer[pos:pos + count] = frame.data
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<5>:<add> if frame_type != QuicFrameType.ACK:
<add> is_ack_only = False
<add>
<6>:<add> pass
<del> is_ack_only = False
<10>:<del> is_ack_only = False
<16>:<add> elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
<add> flags = frame_type & STREAM_FLAGS
<add> stream_id = pull_uint_var(buf)
<add> if flags & STREAM_FLAG_OFF:
<add> offset = pull_uint_var(buf)
<add> else:
<add> offset = 0
<add> if flags & STREAM_FLAG_LEN:
<add> length = pull_uint_var(buf)
<add> else:
<add> length = buf.capacity - buf.tell()
<add> stream = self.streams[stream_id]
<add> stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
<add> elif frame_type == QuicFrameType.MAX_DATA:
<add> pull_uint_var(buf)
<add> elif frame
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
<0> buf = Buffer(data=plain)
<1>
<2> is_ack_only = True
<3> while not buf.eof():
<4> frame_type = pull_uint_var(buf)
<5> if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
<6> is_ack_only = False
<7> elif frame_type == QuicFrameType.ACK:
<8> pull_ack_frame(buf)
<9> elif frame_type == QuicFrameType.CRYPTO:
<10> is_ack_only = False
<11> stream = self.streams[epoch]
<12> stream.add_frame(pull_crypto_frame(buf))
<13> data = stream.pull_data()
<14> if data:
<15> self.tls.handle_message(data, self.send_buffer)
<16> elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
<17> is_ack_only = False
<18> pull_new_connection_id_frame(buf)
<19> else:
<20> logger.warning('unhandled frame type %d', frame_type)
<21> break
<22> return is_ack_only
<23>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
_update_traffic_key(direction, epoch, secret)
_update_traffic_key(self, direction, epoch, secret)
_serialize_parameters(self)
_serialize_parameters()
at: aioquic.connection.QuicConnection.__init__
self.certificate = certificate
self.is_client = is_client
self.private_key = private_key
self.server_name = server_name
self.version = PROTOCOL_VERSION_DRAFT_18
self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
at: aioquic.connection.QuicConnection._init_tls
self.tls = tls.Context(is_client=self.is_client)
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
at: aioquic.packet
pull_uint_var(buf)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
===========unchanged ref 1===========
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.tls
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
Context(is_client)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
+ def create_stream(self, is_unidirectional=False):
+ """
+ Create a stream and return it.
+ """
+ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client)
+ while stream_id in self.streams:
+ stream_id += 4
+ self.streams[stream_id] = QuicStream(stream_id=stream_id)
+ return self.streams[stream_id]
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
if self.is_client:
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
is_client=self.is_client)
self._init_tls()
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
+ self._push_crypto_data()
===========changed ref 2===========
# module: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SECRETS_LABELS = [
[None, 'QUIC_CLIENT_EARLY_TRAFFIC_SECRET', 'QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET',
'QUIC_CLIENT_TRAFFIC_SECRET_0'],
[None, None, 'QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET', 'QUIC_SERVER_TRAFFIC_SECRET_0']
]
SEND_PN_SIZE = 2
+ STREAM_FLAGS = 0x07
+ STREAM_FLAG_FIN = 1
+ STREAM_FLAG_LEN = 2
+ STREAM_FLAG_OFF = 4
===========changed ref 3===========
# module: aioquic.stream
class QuicStream:
+ @property
+ def stream_id(self):
+ return self.__stream_id
+
===========changed ref 4===========
# module: aioquic.stream
class QuicStream:
+ def has_data_to_send(self):
+ return bool(self._send_buffer)
+
===========changed ref 5===========
# module: aioquic.stream
class QuicStream:
+ def push_data(self, data):
+ """
+ Push data to send.
+ """
+ if data:
+ self._send_buffer += data
+
===========changed ref 6===========
# module: aioquic.stream
class QuicStream:
+ def __init__(self, stream_id=None):
- def __init__(self):
+ self._recv_buffer = bytearray()
- self._buffer = bytearray()
- self._received = RangeSet()
+ self._recv_start = 0
- self._start = 0
+ self._recv_ranges = RangeSet()
===========changed ref 7===========
# module: aioquic.stream
class QuicStream:
+ def get_frame(self, size):
+ """
+ Get a frame of data to send.
+ """
+ size = min(size, len(self._send_buffer))
+ frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start)
+ self._send_buffer = self._send_buffer[size:]
+ self._send_start += size
+ return frame
+
===========changed ref 8===========
# module: aioquic.packet
+ @contextmanager
+ def push_stream_frame(buf, stream_id, offset):
+ push_uint_var(buf, stream_id)
+ push_uint_var(buf, offset)
+ push_uint16(buf, 0)
+ start = buf.tell()
+ yield
+ end = buf.tell()
+ buf.seek(start - 2)
+ push_uint16(buf, (end - start) | 0x4000)
+ buf.seek(end)
+
===========changed ref 9===========
# module: aioquic.stream
class QuicStream:
def pull_data(self):
+ """
+ Pull received data.
+ """
# no data, or gap at start
+ if not self._recv_ranges or self._recv_ranges[0].start != self._recv_start:
- if not self._received or self._received[0].start != self._start:
return b''
+ r = self._recv_ranges.shift()
- r = self._received.shift()
pos = r.stop - r.start
+ data = self._recv_buffer[:pos]
- data = self._buffer[:pos]
+ self._recv_buffer = self._recv_buffer[pos:]
- self._buffer = self._buffer[pos:]
+ self._recv_start = r.stop
- self._start = r.stop
return data
|
aioquic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<20>:<add> # STREAM
<add> for stream_id, stream in self.streams.items():
<add> if isinstance(stream_id, int) and stream.has_data_to_send():
<add> frame = stream.get_frame(
<add> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
<add> push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
<add> with push_stream_frame(buf, 0, frame.offset):
<add> tls.push_bytes(buf, frame.data)
<add>
|
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
<0> epoch = tls.Epoch.ONE_RTT
<1> space = self.spaces[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> if not space.crypto.send.is_valid() or not send_ack:
<4> return
<5>
<6> buf = Buffer(capacity=PACKET_MAX_SIZE)
<7>
<8> # write header
<9> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<10> tls.push_bytes(buf, self.peer_cid)
<11> tls.push_uint16(buf, self.packet_number)
<12> header_size = buf.tell()
<13>
<14> # ACK
<15> if send_ack:
<16> push_uint_var(buf, QuicFrameType.ACK)
<17> push_ack_frame(buf, send_ack, 0)
<18> self.send_ack[epoch] = False
<19>
<20> # encrypt
<21> packet_size = buf.tell()
<22> data = buf.data
<23> yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<24>
<25> self.packet_number += 1
<26>
|
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.peer_cid = os.urandom(8)
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._payload_received
buf = Buffer(data=plain)
is_ack_only = True
is_ack_only = False
frame_type = pull_uint_var(buf)
stream_id = pull_uint_var(buf)
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.send = CryptoContext()
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
pull_uint_var(buf)
===========unchanged ref 1===========
push_quic_transport_parameters(buf, params, is_client)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
pull_new_connection_id_frame(buf)
at: aioquic.stream.QuicStream
add_frame(frame: QuicStreamFrame)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
push_bytes(buf: Buffer, v: bytes)
push_uint8(buf: Buffer, v: int)
push_uint16(buf: Buffer, v: int)
at: aioquic.tls.Buffer
tell()
at: logging.Logger
warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.stream
class QuicStream:
def add_frame(self, frame: QuicStreamFrame):
+ """
+ Add a frame of received data.
+ """
+ pos = frame.offset - self._recv_start
- pos = frame.offset - self._start
count = len(frame.data)
# frame has been entirely consumed
if pos + count <= 0:
return
# frame has been partially consumed
if pos < 0:
count += pos
frame.data = frame.data[-pos:]
frame.offset -= pos
pos = 0
# marked received
+ self._recv_ranges.add(frame.offset, frame.offset + count)
- self._received.add(frame.offset, frame.offset + count)
# add data
+ gap = pos - len(self._recv_buffer)
- gap = pos - len(self._buffer)
if gap > 0:
+ self._recv_buffer += bytearray(gap)
- self._buffer += bytearray(gap)
+ self._recv_buffer[pos:pos + count] = frame.data
- self._buffer[pos:pos + count] = frame.data
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
+ def create_stream(self, is_unidirectional=False):
+ """
+ Create a stream and return it.
+ """
+ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client)
+ while stream_id in self.streams:
+ stream_id += 4
+ self.streams[stream_id] = QuicStream(stream_id=stream_id)
+ return self.streams[stream_id]
+
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
if self.is_client:
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
is_client=self.is_client)
self._init_tls()
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
+ self._push_crypto_data()
===========changed ref 3===========
# module: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SECRETS_LABELS = [
[None, 'QUIC_CLIENT_EARLY_TRAFFIC_SECRET', 'QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET',
'QUIC_CLIENT_TRAFFIC_SECRET_0'],
[None, None, 'QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET', 'QUIC_SERVER_TRAFFIC_SECRET_0']
]
SEND_PN_SIZE = 2
+ STREAM_FLAGS = 0x07
+ STREAM_FLAG_FIN = 1
+ STREAM_FLAG_LEN = 2
+ STREAM_FLAG_OFF = 4
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<1>:<add> stream = self.streams[epoch]
<3>:<del> send_data = self.send_buffer[epoch].data
<4>:<del> self.send_buffer[epoch].seek(0)
<7>:<del> offset = 0
<9>:<add> while space.crypto.send.is_valid() and (send_ack or stream.has_data_to_send()):
<del> while space.crypto.send.is_valid() and (send_ack or send_data):
<30>:<add> if stream.has_data_to_send():
<del> if send_data:
<32>:<add> frame = stream.get_frame(
<del> chunk_size = min(len(send_data),
<33>:<add> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4)
<del> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4)
<35>:<add> with push_crypto_frame(buf, frame.offset):
<del> with push_crypto_frame(buf, offset):
<36>:<del> chunk = send_data[:chunk_size]
<37>:<add> tls.push_bytes(buf, frame.data)
<del> tls.push_bytes(buf, chunk)
<38>:<del> send_data = send_data[chunk_size:]
<39>:<del> offset += chunk_size
|
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
<0> space = self.spaces[epoch]
<1> send_ack = space.ack_queue if self.send_ack[epoch] else False
<2> self.send_ack[epoch] = False
<3> send_data = self.send_buffer[epoch].data
<4> self.send_buffer[epoch].seek(0)
<5>
<6> buf = Buffer(capacity=PACKET_MAX_SIZE)
<7> offset = 0
<8>
<9> while space.crypto.send.is_valid() and (send_ack or send_data):
<10> if epoch == tls.Epoch.INITIAL:
<11> packet_type = PACKET_TYPE_INITIAL
<12> else:
<13> packet_type = PACKET_TYPE_HANDSHAKE
<14>
<15> # write header
<16> push_quic_header(buf, QuicHeader(
<17> version=self.version,
<18> packet_type=packet_type | (SEND_PN_SIZE - 1),
<19> destination_cid=self.peer_cid,
<20> source_cid=self.host_cid,
<21> ))
<22> header_size = buf.tell()
<23>
<24> # ACK
<25> if send_ack:
<26> push_uint_var(buf, QuicFrameType.ACK)
<27> push_ack_frame(buf, send_ack, 0)
<28> send_ack = False
<29>
<30> if send_data:
<31> # CRYPTO
<32> chunk_size = min(len(send_data),
<33> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4)
<34> push_uint_var(buf, QuicFrameType.CRYPTO)
<35> with push_crypto_frame(buf, offset):
<36> chunk = send_data[:chunk_size]
<37> tls.push_bytes(buf, chunk)
<38> send_data = send_data[chunk_size:]
<39> offset += chunk_size
<40>
<41> # PADDING
<42> if epoch == tls.</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
tls.push_bytes(
buf,
bytes(PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell()))
# finalize length
packet_size = buf.tell()
buf.seek(header_size - SEND_PN_SIZE - 2)
length = packet_size - header_size + 2 + space.crypto.aead_tag_size
tls.push_uint16(buf, length | 0x4000)
tls.push_uint16(buf, self.packet_number)
buf.seek(packet_size)
# encrypt
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
buf.seek(0)
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
at: aioquic.connection.QuicConnection._write_application
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
buf = Buffer(capacity=PACKET_MAX_SIZE)
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
self.send = CryptoContext()
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
push_uint_var(buf, value)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
===========unchanged ref 1===========
push_bytes(buf: Buffer, v: bytes)
at: aioquic.tls.Buffer
tell()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
+ def _push_crypto_data(self):
+ for epoch, buf in self.send_buffer.items():
+ self.streams[epoch].push_data(buf.data)
+ buf.seek(0)
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
+ def create_stream(self, is_unidirectional=False):
+ """
+ Create a stream and return it.
+ """
+ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client)
+ while stream_id in self.streams:
+ stream_id += 4
+ self.streams[stream_id] = QuicStream(stream_id=stream_id)
+ return self.streams[stream_id]
+
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
if self.is_client:
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
is_client=self.is_client)
self._init_tls()
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
+ self._push_crypto_data()
===========changed ref 3===========
# module: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SECRETS_LABELS = [
[None, 'QUIC_CLIENT_EARLY_TRAFFIC_SECRET', 'QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET',
'QUIC_CLIENT_TRAFFIC_SECRET_0'],
[None, None, 'QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET', 'QUIC_SERVER_TRAFFIC_SECRET_0']
]
SEND_PN_SIZE = 2
+ STREAM_FLAGS = 0x07
+ STREAM_FLAG_FIN = 1
+ STREAM_FLAG_LEN = 2
+ STREAM_FLAG_OFF = 4
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
if not space.crypto.send.is_valid() or not send_ack:
return
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
tls.push_bytes(buf, self.peer_cid)
tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
push_ack_frame(buf, send_ack, 0)
self.send_ack[epoch] = False
+ # STREAM
+ for stream_id, stream in self.streams.items():
+ if isinstance(stream_id, int) and stream.has_data_to_send():
+ frame = stream.get_frame(
+ PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
+ push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
+ with push_stream_frame(buf, 0, frame.offset):
+ tls.push_bytes(buf, frame.data)
+
# encrypt
packet_size = buf.tell()
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
|
examples.cli/run
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<11>:<add> stream = protocol._connection.create_stream()
<add> stream.push_data(b'GET /\r\n')
<del> await asyncio.sleep(10)
|
# module: examples.cli
def run(host, port, secrets_log_file):
<0> # if host is not an IP address, pass it to enable SNI
<1> try:
<2> ipaddress.ip_address(host)
<3> server_name = None
<4> except ValueError:
<5> server_name = host
<6>
<7> _, protocol = await loop.create_datagram_endpoint(
<8> lambda: QuicProtocol(secrets_log_file=secrets_log_file, server_name=server_name),
<9> remote_addr=(host, port))
<10>
<11> await asyncio.sleep(10)
<12>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: examples.cli
QuicProtocol(secrets_log_file, server_name)
loop = asyncio.get_event_loop()
at: ipaddress
ip_address(address: object) -> Any
===========changed ref 0===========
# module: aioquic.stream
class QuicStream:
+ @property
+ def stream_id(self):
+ return self.__stream_id
+
===========changed ref 1===========
# module: aioquic.stream
class QuicStream:
+ def has_data_to_send(self):
+ return bool(self._send_buffer)
+
===========changed ref 2===========
# module: aioquic.stream
class QuicStream:
+ def push_data(self, data):
+ """
+ Push data to send.
+ """
+ if data:
+ self._send_buffer += data
+
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def _push_crypto_data(self):
+ for epoch, buf in self.send_buffer.items():
+ self.streams[epoch].push_data(buf.data)
+ buf.seek(0)
+
===========changed ref 4===========
# module: aioquic.stream
class QuicStream:
+ def __init__(self, stream_id=None):
- def __init__(self):
+ self._recv_buffer = bytearray()
- self._buffer = bytearray()
- self._received = RangeSet()
+ self._recv_start = 0
- self._start = 0
+ self._recv_ranges = RangeSet()
===========changed ref 5===========
# module: aioquic.stream
class QuicStream:
+ def get_frame(self, size):
+ """
+ Get a frame of data to send.
+ """
+ size = min(size, len(self._send_buffer))
+ frame = QuicStreamFrame(data=self._send_buffer[:size], offset=self._send_start)
+ self._send_buffer = self._send_buffer[size:]
+ self._send_start += size
+ return frame
+
===========changed ref 6===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
if self.is_client:
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
is_client=self.is_client)
self._init_tls()
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
+ self._push_crypto_data()
===========changed ref 7===========
# module: aioquic.connection
class QuicConnection:
+ def create_stream(self, is_unidirectional=False):
+ """
+ Create a stream and return it.
+ """
+ stream_id = (int(is_unidirectional) << 1) | int(not self.is_client)
+ while stream_id in self.streams:
+ stream_id += 4
+ self.streams[stream_id] = QuicStream(stream_id=stream_id)
+ return self.streams[stream_id]
+
===========changed ref 8===========
# module: aioquic.packet
+ @contextmanager
+ def push_stream_frame(buf, stream_id, offset):
+ push_uint_var(buf, stream_id)
+ push_uint_var(buf, offset)
+ push_uint16(buf, 0)
+ start = buf.tell()
+ yield
+ end = buf.tell()
+ buf.seek(start - 2)
+ push_uint16(buf, (end - start) | 0x4000)
+ buf.seek(end)
+
===========changed ref 9===========
# module: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SECRETS_LABELS = [
[None, 'QUIC_CLIENT_EARLY_TRAFFIC_SECRET', 'QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET',
'QUIC_CLIENT_TRAFFIC_SECRET_0'],
[None, None, 'QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET', 'QUIC_SERVER_TRAFFIC_SECRET_0']
]
SEND_PN_SIZE = 2
+ STREAM_FLAGS = 0x07
+ STREAM_FLAG_FIN = 1
+ STREAM_FLAG_LEN = 2
+ STREAM_FLAG_OFF = 4
===========changed ref 10===========
# module: aioquic.stream
class QuicStream:
def pull_data(self):
+ """
+ Pull received data.
+ """
# no data, or gap at start
+ if not self._recv_ranges or self._recv_ranges[0].start != self._recv_start:
- if not self._received or self._received[0].start != self._start:
return b''
+ r = self._recv_ranges.shift()
- r = self._received.shift()
pos = r.stop - r.start
+ data = self._recv_buffer[:pos]
- data = self._buffer[:pos]
+ self._recv_buffer = self._recv_buffer[pos:]
- self._buffer = self._buffer[pos:]
+ self._recv_start = r.stop
- self._start = r.stop
return data
===========changed ref 11===========
# module: aioquic.stream
class QuicStream:
def add_frame(self, frame: QuicStreamFrame):
+ """
+ Add a frame of received data.
+ """
+ pos = frame.offset - self._recv_start
- pos = frame.offset - self._start
count = len(frame.data)
# frame has been entirely consumed
if pos + count <= 0:
return
# frame has been partially consumed
if pos < 0:
count += pos
frame.data = frame.data[-pos:]
frame.offset -= pos
pos = 0
# marked received
+ self._recv_ranges.add(frame.offset, frame.offset + count)
- self._received.add(frame.offset, frame.offset + count)
# add data
+ gap = pos - len(self._recv_buffer)
- gap = pos - len(self._buffer)
if gap > 0:
+ self._recv_buffer += bytearray(gap)
- self._buffer += bytearray(gap)
+ self._recv_buffer[pos:pos + count] = frame.data
- self._buffer[pos:pos + count] = frame.data
|
aioquic.packet/pull_quic_header
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<14>:<add> if version == QuicProtocolVersion.NEGOTIATION:
<del> if version == PROTOCOL_VERSION_NEGOTIATION:
|
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
<0> first_byte = pull_uint8(buf)
<1>
<2> token = b''
<3> if is_long_header(first_byte):
<4> # long header packet
<5> version = pull_uint32(buf)
<6> cid_lengths = pull_uint8(buf)
<7>
<8> destination_cid_length = decode_cid_length(cid_lengths // 16)
<9> destination_cid = pull_bytes(buf, destination_cid_length)
<10>
<11> source_cid_length = decode_cid_length(cid_lengths % 16)
<12> source_cid = pull_bytes(buf, source_cid_length)
<13>
<14> if version == PROTOCOL_VERSION_NEGOTIATION:
<15> # version negotiation
<16> packet_type = None
<17> rest_length = buf.capacity - buf.tell()
<18> else:
<19> if version and not (first_byte & PACKET_FIXED_BIT):
<20> raise ValueError('Packet fixed bit is zero')
<21>
<22> packet_type = first_byte & PACKET_TYPE_MASK
<23> if packet_type == PACKET_TYPE_INITIAL:
<24> token_length = pull_uint_var(buf)
<25> token = pull_bytes(buf, token_length)
<26> rest_length = pull_uint_var(buf)
<27>
<28> return QuicHeader(
<29> version=version,
<30> packet_type=packet_type,
<31> destination_cid=destination_cid,
<32> source_cid=source_cid,
<33> token=token,
<34> rest_length=rest_length)
<35> else:
<36> # short header packet
<37> if not (first_byte & PACKET_FIXED_BIT):
<38> raise ValueError('Packet fixed bit is zero')
<39>
<40> packet_type = first_byte & PACKET_TYPE_MASK
<41> destination_cid = pull_bytes(buf, host_cid_length)
<42> return QuicHeader(
<43> version=0,
<44> packet</s>
|
===========below chunk 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========unchanged ref 0===========
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_MASK = 0xf0
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, token: bytes=b'', rest_length: int=0)
decode_cid_length(length)
is_long_header(first_byte)
pull_uint_var(buf)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint8(buf: Buffer) -> int
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
tell()
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<14>:<add> self.version = QuicProtocolVersion.DRAFT_18
<add> self.supported_versions = [
<add> QuicProtocolVersion.DRAFT_17,
<add> QuicProtocolVersion.DRAFT_18,
<add> ]
<del> self.version = PROTOCOL_VERSION_DRAFT_18
<15>:<del> self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.private_key = private_key
<10> self.secrets_log_file = secrets_log_file
<11> self.server_name = server_name
<12>
<13> # protocol versions
<14> self.version = PROTOCOL_VERSION_DRAFT_18
<15> self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
<16>
<17> self.quic_transport_parameters = QuicTransportParameters(
<18> idle_timeout=600,
<19> initial_max_data=16777216,
<20> initial_max_stream_data_bidi_local=1048576,
<21> initial_max_stream_data_bidi_remote=1048576,
<22> initial_max_stream_data_uni=1048576,
<23> initial_max_streams_bidi=100,
<24> ack_delay_exponent=10,
<25> )
<26>
<27> self.send_ack = {
<28> tls.Epoch.INITIAL: False,
<29> tls.Epoch.HANDSHAKE: False,
<30> tls.Epoch.ONE_RTT: False,
<31> }
<32> self.send_buffer = {
<33> tls.Epoch.INITIAL: Buffer(capacity=4096),
<34> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<35> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<36> }
<37> </s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
# offset: 1
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
===========unchanged ref 0===========
at: aioquic.connection
PacketSpace()
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.crypto_initialized = True
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.packet
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
===========unchanged ref 1===========
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
===========changed ref 2===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
+ if version == QuicProtocolVersion.NEGOTIATION:
- if version == PROTOCOL_VERSION_NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
</s>
===========changed ref 3===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
|
tests.test_packet/PacketTest.test_pull_initial_client
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<2>:<add> self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
<del> self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
<0> buf = Buffer(data=load('initial_client.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
<3> self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
<4> self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
<5> self.assertEqual(header.source_cid, b'')
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 1263)
<8> self.assertEqual(buf.tell(), 17)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
tell()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
+ if version == QuicProtocolVersion.NEGOTIATION:
- if version == PROTOCOL_VERSION_NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
</s>
===========changed ref 2===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 3===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
+ self.version = QuicProtocolVersion.DRAFT_18
+ self.supported_versions = [
+ QuicProtocolVersion.DRAFT_17,
+ QuicProtocolVersion.DRAFT_18,
+ ]
- self.version = PROTOCOL_VERSION_DRAFT_18
- self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE</s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
# offset: 1
<s>=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
|
tests.test_packet/PacketTest.test_pull_initial_server
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<2>:<add> self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
<del> self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
<0> buf = Buffer(data=load('initial_server.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
<3> self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
<4> self.assertEqual(header.destination_cid, b'')
<5> self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 182)
<8> self.assertEqual(buf.tell(), 17)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
tell()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
+ if version == QuicProtocolVersion.NEGOTIATION:
- if version == PROTOCOL_VERSION_NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
</s>
===========changed ref 2===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 4===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
+ self.version = QuicProtocolVersion.DRAFT_18
+ self.supported_versions = [
+ QuicProtocolVersion.DRAFT_17,
+ QuicProtocolVersion.DRAFT_18,
+ ]
- self.version = PROTOCOL_VERSION_DRAFT_18
- self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE</s>
|
tests.test_packet/PacketTest.test_pull_version_negotiation
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<2>:<add> self.assertEqual(header.version, QuicProtocolVersion.NEGOTIATION)
<del> self.assertEqual(header.version, PROTOCOL_VERSION_NEGOTIATION)
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_version_negotiation(self):
<0> buf = Buffer(data=load('version_negotiation.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, PROTOCOL_VERSION_NEGOTIATION)
<3> self.assertEqual(header.packet_type, None)
<4> self.assertEqual(header.destination_cid, binascii.unhexlify('dae1889b81a91c26'))
<5> self.assertEqual(header.source_cid, binascii.unhexlify('f49243784f9bf3be'))
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 8)
<8> self.assertEqual(buf.tell(), 22)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
tell()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
+ if version == QuicProtocolVersion.NEGOTIATION:
- if version == PROTOCOL_VERSION_NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
</s>
===========changed ref 2===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
buf = Buffer(data=load('initial_server.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, b'')
self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 182)
self.assertEqual(buf.tell(), 17)
===========changed ref 4===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 5===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
|
tests.test_packet/PacketTest.test_push_initial
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<2>:<add> version=QuicProtocolVersion.DRAFT_17,
<del> version=PROTOCOL_VERSION_DRAFT_17,
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_push_initial(self):
<0> buf = Buffer(capacity=32)
<1> header = QuicHeader(
<2> version=PROTOCOL_VERSION_DRAFT_17,
<3> packet_type=PACKET_TYPE_INITIAL,
<4> destination_cid=binascii.unhexlify('90ed1e1c7b04b5d3'),
<5> source_cid=b'')
<6> push_quic_header(buf, header)
<7> self.assertEqual(buf.data, binascii.unhexlify('c0ff0000115090ed1e1c7b04b5d30000000000'))
<8>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, token: bytes=b'', rest_length: int=0)
push_quic_header(buf, header)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_version_negotiation(self):
buf = Buffer(data=load('version_negotiation.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.NEGOTIATION)
- self.assertEqual(header.version, PROTOCOL_VERSION_NEGOTIATION)
self.assertEqual(header.packet_type, None)
self.assertEqual(header.destination_cid, binascii.unhexlify('dae1889b81a91c26'))
self.assertEqual(header.source_cid, binascii.unhexlify('f49243784f9bf3be'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 8)
self.assertEqual(buf.tell(), 22)
===========changed ref 2===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
buf = Buffer(data=load('initial_server.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, b'')
self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 182)
self.assertEqual(buf.tell(), 17)
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 4===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
===========changed ref 5===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
+ if version == QuicProtocolVersion.NEGOTIATION:
- if version == PROTOCOL_VERSION_NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
</s>
===========changed ref 6===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
|
tests.test_packet/ParamsTest.test_client_params
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<5>:<add> initial_version=QuicProtocolVersion.DRAFT_17,
<del> initial_version=PROTOCOL_VERSION_DRAFT_17,
|
# module: tests.test_packet
class ParamsTest(TestCase):
def test_client_params(self):
<0> buf = Buffer(data=binascii.unhexlify(
<1> 'ff0000110031000500048010000000060004801000000007000480100000000'
<2> '4000481000000000100024258000800024064000a00010a'))
<3> params = pull_quic_transport_parameters(buf, is_client=True)
<4> self.assertEqual(params, QuicTransportParameters(
<5> initial_version=PROTOCOL_VERSION_DRAFT_17,
<6> idle_timeout=600,
<7> initial_max_data=16777216,
<8> initial_max_stream_data_bidi_local=1048576,
<9> initial_max_stream_data_bidi_remote=1048576,
<10> initial_max_stream_data_uni=1048576,
<11> initial_max_streams_bidi=100,
<12> ack_delay_exponent=10,
<13> ))
<14>
<15> buf = Buffer(capacity=512)
<16> push_quic_transport_parameters(buf, params, is_client=True)
<17>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
pull_quic_transport_parameters(buf, is_client)
push_quic_transport_parameters(buf, params, is_client)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
===========unchanged ref 1===========
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_push_initial(self):
buf = Buffer(capacity=32)
header = QuicHeader(
+ version=QuicProtocolVersion.DRAFT_17,
- version=PROTOCOL_VERSION_DRAFT_17,
packet_type=PACKET_TYPE_INITIAL,
destination_cid=binascii.unhexlify('90ed1e1c7b04b5d3'),
source_cid=b'')
push_quic_header(buf, header)
self.assertEqual(buf.data, binascii.unhexlify('c0ff0000115090ed1e1c7b04b5d30000000000'))
===========changed ref 2===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_version_negotiation(self):
buf = Buffer(data=load('version_negotiation.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.NEGOTIATION)
- self.assertEqual(header.version, PROTOCOL_VERSION_NEGOTIATION)
self.assertEqual(header.packet_type, None)
self.assertEqual(header.destination_cid, binascii.unhexlify('dae1889b81a91c26'))
self.assertEqual(header.source_cid, binascii.unhexlify('f49243784f9bf3be'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 8)
self.assertEqual(buf.tell(), 22)
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
buf = Buffer(data=load('initial_server.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, b'')
self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 182)
self.assertEqual(buf.tell(), 17)
===========changed ref 4===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 5===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
|
tests.test_packet/ParamsTest.test_server_params
|
Modified
|
aiortc~aioquic
|
1e33dc5a894c3aee03f3e4af110e6e6bb8b73d7b
|
[packet] add enum for protocol versions
|
<6>:<add> negotiated_version=QuicProtocolVersion.DRAFT_17,
<add> supported_versions=[QuicProtocolVersion.DRAFT_17],
<del> negotiated_version=PROTOCOL_VERSION_DRAFT_17,
<7>:<del> supported_versions=[PROTOCOL_VERSION_DRAFT_17],
|
# module: tests.test_packet
class ParamsTest(TestCase):
def test_server_params(self):
<0> buf = Buffer(data=binascii.unhexlify(
<1> 'ff00001104ff000011004500050004801000000006000480100000000700048'
<2> '010000000040004810000000001000242580002001000000000000000000000'
<3> '000000000000000800024064000a00010a'))
<4> params = pull_quic_transport_parameters(buf, is_client=False)
<5> self.assertEqual(params, QuicTransportParameters(
<6> negotiated_version=PROTOCOL_VERSION_DRAFT_17,
<7> supported_versions=[PROTOCOL_VERSION_DRAFT_17],
<8> idle_timeout=600,
<9> stateless_reset_token=bytes(16),
<10> initial_max_data=16777216,
<11> initial_max_stream_data_bidi_local=1048576,
<12> initial_max_stream_data_bidi_remote=1048576,
<13> initial_max_stream_data_uni=1048576,
<14> initial_max_streams_bidi=100,
<15> ack_delay_exponent=10,
<16> ))
<17>
<18> buf = Buffer(capacity=512)
<19> push_quic_transport_parameters(buf, params, is_client=False)
<20>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
pull_quic_transport_parameters(buf, is_client)
push_quic_transport_parameters(buf, params, is_client)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ class QuicProtocolVersion(IntEnum):
+ NEGOTIATION = 0
+ DRAFT_17 = 0xff000011
+ DRAFT_18 = 0xff000012
+ DRAFT_19 = 0xff000013
+
===========changed ref 1===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_push_initial(self):
buf = Buffer(capacity=32)
header = QuicHeader(
+ version=QuicProtocolVersion.DRAFT_17,
- version=PROTOCOL_VERSION_DRAFT_17,
packet_type=PACKET_TYPE_INITIAL,
destination_cid=binascii.unhexlify('90ed1e1c7b04b5d3'),
source_cid=b'')
push_quic_header(buf, header)
self.assertEqual(buf.data, binascii.unhexlify('c0ff0000115090ed1e1c7b04b5d30000000000'))
===========changed ref 2===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_version_negotiation(self):
buf = Buffer(data=load('version_negotiation.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.NEGOTIATION)
- self.assertEqual(header.version, PROTOCOL_VERSION_NEGOTIATION)
self.assertEqual(header.packet_type, None)
self.assertEqual(header.destination_cid, binascii.unhexlify('dae1889b81a91c26'))
self.assertEqual(header.source_cid, binascii.unhexlify('f49243784f9bf3be'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 8)
self.assertEqual(buf.tell(), 22)
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
buf = Buffer(data=load('initial_server.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, b'')
self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 182)
self.assertEqual(buf.tell(), 17)
===========changed ref 4===========
# module: tests.test_packet
class ParamsTest(TestCase):
def test_client_params(self):
buf = Buffer(data=binascii.unhexlify(
'ff0000110031000500048010000000060004801000000007000480100000000'
'4000481000000000100024258000800024064000a00010a'))
params = pull_quic_transport_parameters(buf, is_client=True)
self.assertEqual(params, QuicTransportParameters(
+ initial_version=QuicProtocolVersion.DRAFT_17,
- initial_version=PROTOCOL_VERSION_DRAFT_17,
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
))
buf = Buffer(capacity=512)
push_quic_transport_parameters(buf, params, is_client=True)
===========changed ref 5===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
- self.assertEqual(header.version, PROTOCOL_VERSION_DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 6===========
# module: aioquic.packet
PACKET_LONG_HEADER = 0x80
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_0RTT = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x10
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
- PROTOCOL_VERSION_NEGOTIATION = 0
- PROTOCOL_VERSION_DRAFT_17 = 0xff000011
- PROTOCOL_VERSION_DRAFT_18 = 0xff000012
-
UINT_VAR_FORMATS = [
(pull_uint8, push_uint8, 0x3f),
(pull_uint16, push_uint16, 0x3fff),
(pull_uint32, push_uint32, 0x3fffffff),
(pull_uint64, push_uint64, 0x3fffffffffffffff),
]
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
6315fa2782c2d8a18690313db5195cf2abb597e6
|
[packet] parse NEW_TOKEN frames
|
<11>:<add> packet.pull_ack_frame(buf)
<del> pull_ack_frame(buf)
<14>:<add> stream.add_frame(packet.pull_crypto_frame(buf))
<del> stream.add_frame(pull_crypto_frame(buf))
<18>:<add> elif frame_type == QuicFrameType.NEW_TOKEN:
<add> packet.pull_new_token_frame(buf)
<36>:<add> packet.pull_new_connection_id_frame(buf)
<del> pull_new_connection_
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
<0> buf = Buffer(data=plain)
<1>
<2> is_ack_only = True
<3> while not buf.eof():
<4> frame_type = pull_uint_var(buf)
<5> if frame_type != QuicFrameType.ACK:
<6> is_ack_only = False
<7>
<8> if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
<9> pass
<10> elif frame_type == QuicFrameType.ACK:
<11> pull_ack_frame(buf)
<12> elif frame_type == QuicFrameType.CRYPTO:
<13> stream = self.streams[epoch]
<14> stream.add_frame(pull_crypto_frame(buf))
<15> data = stream.pull_data()
<16> if data:
<17> self.tls.handle_message(data, self.send_buffer)
<18> elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
<19> flags = frame_type & STREAM_FLAGS
<20> stream_id = pull_uint_var(buf)
<21> if flags & STREAM_FLAG_OFF:
<22> offset = pull_uint_var(buf)
<23> else:
<24> offset = 0
<25> if flags & STREAM_FLAG_LEN:
<26> length = pull_uint_var(buf)
<27> else:
<28> length = buf.capacity - buf.tell()
<29> stream = self.streams[stream_id]
<30> stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
<31> elif frame_type == QuicFrameType.MAX_DATA:
<32> pull_uint_var(buf)
<33> elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
<34> pull_uint_var(buf)
<35> elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
<36> pull_new_connection_</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
STREAM_FLAGS = 0x07
STREAM_FLAG_LEN = 2
STREAM_FLAG_OFF = 4
at: aioquic.connection.QuicConnection
_push_crypto_data()
at: aioquic.connection.QuicConnection.__init__
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
at: aioquic.connection.QuicConnection._init_tls
self.tls = tls.Context(is_client=self.is_client)
at: aioquic.packet
pull_uint_var(buf)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
pull_ack_frame(buf)
QuicStreamFrame(data: bytes=b'', offset: int=0)
pull_crypto_frame(buf)
pull_new_token_frame(buf)
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream
add_frame(frame: QuicStreamFrame)
pull_data()
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
at: aioquic.tls.Buffer
eof()
tell()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========unchanged ref 1===========
at: logging.Logger
warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.packet
+ def pull_new_token_frame(buf):
+ length = pull_uint_var(buf)
+ return pull_bytes(buf, length)
+
===========changed ref 1===========
# module: aioquic.packet
+ def push_new_token_frame(buf, token):
+ push_uint_var(buf, len(token))
+ push_bytes(buf, token)
+
|
aioquic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
6315fa2782c2d8a18690313db5195cf2abb597e6
|
[packet] parse NEW_TOKEN frames
|
<17>:<add> packet.push_ack_frame(buf, send_ack, 0)
<del> push_ack_frame(buf, send_ack, 0)
|
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
<0> epoch = tls.Epoch.ONE_RTT
<1> space = self.spaces[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> if not space.crypto.send.is_valid() or not send_ack:
<4> return
<5>
<6> buf = Buffer(capacity=PACKET_MAX_SIZE)
<7>
<8> # write header
<9> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<10> tls.push_bytes(buf, self.peer_cid)
<11> tls.push_uint16(buf, self.packet_number)
<12> header_size = buf.tell()
<13>
<14> # ACK
<15> if send_ack:
<16> push_uint_var(buf, QuicFrameType.ACK)
<17> push_ack_frame(buf, send_ack, 0)
<18> self.send_ack[epoch] = False
<19>
<20> # STREAM
<21> for stream_id, stream in self.streams.items():
<22> if isinstance(stream_id, int) and stream.has_data_to_send():
<23> frame = stream.get_frame(
<24> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
<25> push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
<26> with push_stream_frame(buf, 0, frame.offset):
<27> tls.push_bytes(buf, frame.data)
<28>
<29> # encrypt
<30> packet_size = buf.tell()
<31> data = buf.data
<32> yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<33>
<34> self.packet_number += 1
<35>
|
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.peer_cid = os.urandom(8)
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
self.send = CryptoContext()
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
push_uint_var(buf, value)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
push_stream_frame(buf, stream_id, offset)
===========unchanged ref 1===========
at: aioquic.stream.QuicStream
get_frame(size)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
push_bytes(buf: Buffer, v: bytes)
push_uint8(buf: Buffer, v: int)
push_uint16(buf: Buffer, v: int)
at: aioquic.tls.Buffer
tell()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
+ packet.pull_ack_frame(buf)
- pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
+ stream.add_frame(packet.pull_crypto_frame(buf))
- stream.add_frame(pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
+ elif frame_type == QuicFrameType.NEW_TOKEN:
+ packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
stream = self.streams[stream_id]
stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var</s>
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>FrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
+ packet.pull_new_connection_id_frame(buf)
- pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
===========changed ref 2===========
# module: aioquic.packet
+ def pull_new_token_frame(buf):
+ length = pull_uint_var(buf)
+ return pull_bytes(buf, length)
+
===========changed ref 3===========
# module: aioquic.packet
+ def push_new_token_frame(buf, token):
+ push_uint_var(buf, len(token))
+ push_bytes(buf, token)
+
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
6315fa2782c2d8a18690313db5195cf2abb597e6
|
[packet] parse NEW_TOKEN frames
|
<25>:<add> packet.push_ack_frame(buf, send_ack, 0)
<del> push_ack_frame(buf, send_ack, 0)
<33>:<add> with packet.push_crypto_frame(buf, frame.offset):
<del> with push_crypto_frame(buf, frame.offset):
|
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
<0> space = self.spaces[epoch]
<1> stream = self.streams[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> self.send_ack[epoch] = False
<4>
<5> buf = Buffer(capacity=PACKET_MAX_SIZE)
<6>
<7> while space.crypto.send.is_valid() and (send_ack or stream.has_data_to_send()):
<8> if epoch == tls.Epoch.INITIAL:
<9> packet_type = PACKET_TYPE_INITIAL
<10> else:
<11> packet_type = PACKET_TYPE_HANDSHAKE
<12>
<13> # write header
<14> push_quic_header(buf, QuicHeader(
<15> version=self.version,
<16> packet_type=packet_type | (SEND_PN_SIZE - 1),
<17> destination_cid=self.peer_cid,
<18> source_cid=self.host_cid,
<19> ))
<20> header_size = buf.tell()
<21>
<22> # ACK
<23> if send_ack:
<24> push_uint_var(buf, QuicFrameType.ACK)
<25> push_ack_frame(buf, send_ack, 0)
<26> send_ack = False
<27>
<28> if stream.has_data_to_send():
<29> # CRYPTO
<30> frame = stream.get_frame(
<31> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4)
<32> push_uint_var(buf, QuicFrameType.CRYPTO)
<33> with push_crypto_frame(buf, frame.offset):
<34> tls.push_bytes(buf, frame.data)
<35>
<36> # PADDING
<37> if epoch == tls.Epoch.INITIAL and self.is_client:
<38> tls.push_bytes(
<39> buf,
<40> bytes(PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
# finalize length
packet_size = buf.tell()
buf.seek(header_size - SEND_PN_SIZE - 2)
length = packet_size - header_size + 2 + space.crypto.aead_tag_size
tls.push_uint16(buf, length | 0x4000)
tls.push_uint16(buf, self.packet_number)
buf.seek(packet_size)
# encrypt
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
buf.seek(0)
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.version = QuicProtocolVersion.DRAFT_18
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
self.send = CryptoContext()
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
===========unchanged ref 1===========
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, token: bytes=b'', rest_length: int=0)
push_uint_var(buf, value)
push_quic_header(buf, header)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream
get_frame(size)
has_data_to_send()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
push_bytes(buf: Buffer, v: bytes)
push_uint16(buf: Buffer, v: int)
at: aioquic.tls.Buffer
seek(pos)
tell()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
if not space.crypto.send.is_valid() or not send_ack:
return
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
tls.push_bytes(buf, self.peer_cid)
tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
+ packet.push_ack_frame(buf, send_ack, 0)
- push_ack_frame(buf, send_ack, 0)
self.send_ack[epoch] = False
# STREAM
for stream_id, stream in self.streams.items():
if isinstance(stream_id, int) and stream.has_data_to_send():
frame = stream.get_frame(
PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
with push_stream_frame(buf, 0, frame.offset):
tls.push_bytes(buf, frame.data)
# encrypt
packet_size = buf.tell()
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
+ packet.pull_ack_frame(buf)
- pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
+ stream.add_frame(packet.pull_crypto_frame(buf))
- stream.add_frame(pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
+ elif frame_type == QuicFrameType.NEW_TOKEN:
+ packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
stream = self.streams[stream_id]
stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var</s>
|
tests.test_packet/FrameTest.test_ack_frame
|
Modified
|
aiortc~aioquic
|
6315fa2782c2d8a18690313db5195cf2abb597e6
|
[packet] parse NEW_TOKEN frames
|
<4>:<add> rangeset, delay = packet.pull_ack_frame(buf)
<del> rangeset, delay = pull_ack_frame(buf)
<11>:<add> buf = Buffer(capacity=len(data))
<del> buf = Buffer(capacity=8)
<12>:<add> packet.push_ack_frame(buf, rangeset, delay)
<del> push_ack_frame(buf, rangeset, delay)
|
# module: tests.test_packet
class FrameTest(TestCase):
def test_ack_frame(self):
<0> data = b'\x00\x02\x00\x00'
<1>
<2> # parse
<3> buf = Buffer(data=data)
<4> rangeset, delay = pull_ack_frame(buf)
<5> self.assertEqual(list(rangeset), [
<6> range(0, 1)
<7> ])
<8> self.assertEqual(delay, 2)
<9>
<10> # serialize
<11> buf = Buffer(capacity=8)
<12> push_ack_frame(buf, rangeset, delay)
<13> self.assertEqual(buf.data, data)
<14>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_ack_frame(buf)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ def pull_new_token_frame(buf):
+ length = pull_uint_var(buf)
+ return pull_bytes(buf, length)
+
===========changed ref 1===========
# module: aioquic.packet
+ def push_new_token_frame(buf, token):
+ push_uint_var(buf, len(token))
+ push_bytes(buf, token)
+
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
if not space.crypto.send.is_valid() or not send_ack:
return
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
tls.push_bytes(buf, self.peer_cid)
tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
+ packet.push_ack_frame(buf, send_ack, 0)
- push_ack_frame(buf, send_ack, 0)
self.send_ack[epoch] = False
# STREAM
for stream_id, stream in self.streams.items():
if isinstance(stream_id, int) and stream.has_data_to_send():
frame = stream.get_frame(
PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
with push_stream_frame(buf, 0, frame.offset):
tls.push_bytes(buf, frame.data)
# encrypt
packet_size = buf.tell()
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
+ packet.pull_ack_frame(buf)
- pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
+ stream.add_frame(packet.pull_crypto_frame(buf))
- stream.add_frame(pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
+ elif frame_type == QuicFrameType.NEW_TOKEN:
+ packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
stream = self.streams[stream_id]
stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var</s>
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>FrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
+ packet.pull_new_connection_id_frame(buf)
- pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
space = self.spaces[epoch]
stream = self.streams[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
self.send_ack[epoch] = False
buf = Buffer(capacity=PACKET_MAX_SIZE)
while space.crypto.send.is_valid() and (send_ack or stream.has_data_to_send()):
if epoch == tls.Epoch.INITIAL:
packet_type = PACKET_TYPE_INITIAL
else:
packet_type = PACKET_TYPE_HANDSHAKE
# write header
push_quic_header(buf, QuicHeader(
version=self.version,
packet_type=packet_type | (SEND_PN_SIZE - 1),
destination_cid=self.peer_cid,
source_cid=self.host_cid,
))
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
+ packet.push_ack_frame(buf, send_ack, 0)
- push_ack_frame(buf, send_ack, 0)
send_ack = False
if stream.has_data_to_send():
# CRYPTO
frame = stream.get_frame(
PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4)
push_uint_var(buf, QuicFrameType.CRYPTO)
+ with packet.push_crypto_frame(buf, frame.offset):
- with push_crypto_frame(buf, frame.offset):
tls.push_bytes(buf, frame.data)
# PADDING
if epoch == tls.Epoch.INITIAL and self.is_client:
tls.push_bytes(
buf,
bytes(PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell</s>
|
tests.test_packet/FrameTest.test_ack_frame_with_ranges
|
Modified
|
aiortc~aioquic
|
6315fa2782c2d8a18690313db5195cf2abb597e6
|
[packet] parse NEW_TOKEN frames
|
<4>:<add> rangeset, delay = packet.pull_ack_frame(buf)
<del> rangeset, delay = pull_ack_frame(buf)
<12>:<add> buf = Buffer(capacity=len(data))
<del> buf = Buffer(capacity=8)
<13>:<add> packet.push_ack_frame(buf, rangeset, delay)
<del> push_ack_frame(buf, rangeset, delay)
|
# module: tests.test_packet
class FrameTest(TestCase):
def test_ack_frame_with_ranges(self):
<0> data = b'\x05\x02\x01\x00\x02\x03'
<1>
<2> # parse
<3> buf = Buffer(data=data)
<4> rangeset, delay = pull_ack_frame(buf)
<5> self.assertEqual(list(rangeset), [
<6> range(0, 4),
<7> range(5, 6)
<8> ])
<9> self.assertEqual(delay, 2)
<10>
<11> # serialize
<12> buf = Buffer(capacity=8)
<13> push_ack_frame(buf, rangeset, delay)
<14> self.assertEqual(buf.data, data)
<15>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_ack_frame(buf)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_packet
class FrameTest(TestCase):
def test_ack_frame(self):
data = b'\x00\x02\x00\x00'
# parse
buf = Buffer(data=data)
+ rangeset, delay = packet.pull_ack_frame(buf)
- rangeset, delay = pull_ack_frame(buf)
self.assertEqual(list(rangeset), [
range(0, 1)
])
self.assertEqual(delay, 2)
# serialize
+ buf = Buffer(capacity=len(data))
- buf = Buffer(capacity=8)
+ packet.push_ack_frame(buf, rangeset, delay)
- push_ack_frame(buf, rangeset, delay)
self.assertEqual(buf.data, data)
===========changed ref 1===========
# module: aioquic.packet
+ def pull_new_token_frame(buf):
+ length = pull_uint_var(buf)
+ return pull_bytes(buf, length)
+
===========changed ref 2===========
# module: aioquic.packet
+ def push_new_token_frame(buf, token):
+ push_uint_var(buf, len(token))
+ push_bytes(buf, token)
+
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
if not space.crypto.send.is_valid() or not send_ack:
return
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
tls.push_bytes(buf, self.peer_cid)
tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
+ packet.push_ack_frame(buf, send_ack, 0)
- push_ack_frame(buf, send_ack, 0)
self.send_ack[epoch] = False
# STREAM
for stream_id, stream in self.streams.items():
if isinstance(stream_id, int) and stream.has_data_to_send():
frame = stream.get_frame(
PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
with push_stream_frame(buf, 0, frame.offset):
tls.push_bytes(buf, frame.data)
# encrypt
packet_size = buf.tell()
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
+ packet.pull_ack_frame(buf)
- pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
+ stream.add_frame(packet.pull_crypto_frame(buf))
- stream.add_frame(pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
+ elif frame_type == QuicFrameType.NEW_TOKEN:
+ packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
stream = self.streams[stream_id]
stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var</s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>FrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
+ packet.pull_new_connection_id_frame(buf)
- pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
|
tests.test_packet/FrameTest.test_new_connection_id
|
Modified
|
aiortc~aioquic
|
6315fa2782c2d8a18690313db5195cf2abb597e6
|
[packet] parse NEW_TOKEN frames
|
<5>:<add> frame = packet.pull_new_connection_id_frame(buf)
<del> frame = pull_new_connection_id_frame(buf)
<12>:<add> buf = Buffer(capacity=len(data))
<del> buf = Buffer(capacity=35)
<13>:<add> packet.push_new_connection_id_frame(buf, *frame)
<del> push_new_connection_id_frame(buf, *frame)
<14>:<add> self.assertEqual(buf.data, data)
|
# module: tests.test_packet
class FrameTest(TestCase):
def test_new_connection_id(self):
<0> data = binascii.unhexlify(
<1> '02117813f3d9e45e0cacbb491b4b66b039f20406f68fede38ec4c31aba8ab1245244e8')
<2>
<3> # parse
<4> buf = Buffer(data=data)
<5> frame = pull_new_connection_id_frame(buf)
<6> self.assertEqual(frame, (
<7> 2,
<8> binascii.unhexlify('7813f3d9e45e0cacbb491b4b66b039f204'),
<9> binascii.unhexlify('06f68fede38ec4c31aba8ab1245244e8')))
<10>
<11> # serialize
<12> buf = Buffer(capacity=35)
<13> push_new_connection_id_frame(buf, *frame)
<14>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_new_token_frame(buf)
push_new_token_frame(buf, token)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
+ def pull_new_token_frame(buf):
+ length = pull_uint_var(buf)
+ return pull_bytes(buf, length)
+
===========changed ref 1===========
# module: aioquic.packet
+ def push_new_token_frame(buf, token):
+ push_uint_var(buf, len(token))
+ push_bytes(buf, token)
+
===========changed ref 2===========
# module: tests.test_packet
class FrameTest(TestCase):
+ def test_new_token(self):
+ data = binascii.unhexlify('080102030405060708')
+
+ # parse
+ buf = Buffer(data=data)
+ token = packet.pull_new_token_frame(buf)
+ self.assertEqual(token, binascii.unhexlify('0102030405060708'))
+
+ # serialize
+ buf = Buffer(capacity=len(data))
+ packet.push_new_token_frame(buf, token)
+ self.assertEqual(buf.data, data)
+
===========changed ref 3===========
# module: tests.test_packet
class FrameTest(TestCase):
def test_ack_frame_with_ranges(self):
data = b'\x05\x02\x01\x00\x02\x03'
# parse
buf = Buffer(data=data)
+ rangeset, delay = packet.pull_ack_frame(buf)
- rangeset, delay = pull_ack_frame(buf)
self.assertEqual(list(rangeset), [
range(0, 4),
range(5, 6)
])
self.assertEqual(delay, 2)
# serialize
+ buf = Buffer(capacity=len(data))
- buf = Buffer(capacity=8)
+ packet.push_ack_frame(buf, rangeset, delay)
- push_ack_frame(buf, rangeset, delay)
self.assertEqual(buf.data, data)
===========changed ref 4===========
# module: tests.test_packet
class FrameTest(TestCase):
def test_ack_frame(self):
data = b'\x00\x02\x00\x00'
# parse
buf = Buffer(data=data)
+ rangeset, delay = packet.pull_ack_frame(buf)
- rangeset, delay = pull_ack_frame(buf)
self.assertEqual(list(rangeset), [
range(0, 1)
])
self.assertEqual(delay, 2)
# serialize
+ buf = Buffer(capacity=len(data))
- buf = Buffer(capacity=8)
+ packet.push_ack_frame(buf, rangeset, delay)
- push_ack_frame(buf, rangeset, delay)
self.assertEqual(buf.data, data)
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
if not space.crypto.send.is_valid() or not send_ack:
return
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
tls.push_bytes(buf, self.peer_cid)
tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
+ packet.push_ack_frame(buf, send_ack, 0)
- push_ack_frame(buf, send_ack, 0)
self.send_ack[epoch] = False
# STREAM
for stream_id, stream in self.streams.items():
if isinstance(stream_id, int) and stream.has_data_to_send():
frame = stream.get_frame(
PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
with push_stream_frame(buf, 0, frame.offset):
tls.push_bytes(buf, frame.data)
# encrypt
packet_size = buf.tell()
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
===========changed ref 6===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
+ packet.pull_ack_frame(buf)
- pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
+ stream.add_frame(packet.pull_crypto_frame(buf))
- stream.add_frame(pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
+ elif frame_type == QuicFrameType.NEW_TOKEN:
+ packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
stream = self.streams[stream_id]
stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var</s>
===========changed ref 7===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>FrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
+ packet.pull_new_connection_id_frame(buf)
- pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
|
aioquic.packet/pull_quic_transport_parameters
|
Modified
|
aiortc~aioquic
|
34d603600c4795802e9230bd8884bd7e02cb9b70
|
[packet] adapt transport parameters parsing for draft 19
|
<3>:<add> elif is_client is False:
<del> else:
|
# module: aioquic.packet
def pull_quic_transport_parameters(buf, is_client):
<0> params = QuicTransportParameters()
<1> if is_client:
<2> params.initial_version = pull_uint32(buf)
<3> else:
<4> params.negotiated_version = pull_uint32(buf)
<5> params.supported_versions = pull_list(buf, 1, pull_uint32)
<6> with pull_block(buf, 2) as length:
<7> end = buf.tell() + length
<8> while buf.tell() < end:
<9> param_id = pull_uint16(buf)
<10> param_len = pull_uint16(buf)
<11> param_start = buf.tell()
<12> param_name, param_type = PARAMS[param_id]
<13> if param_type == int:
<14> setattr(params, param_name, pull_uint_var(buf))
<15> elif param_type == bytes:
<16> setattr(params, param_name, pull_bytes(buf, param_len))
<17> else:
<18> setattr(params, param_name, True)
<19> assert buf.tell() == param_start + param_len
<20>
<21> return params
<22>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_uint_var(buf)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
PARAMS = [
('original_connection_id', bytes),
('idle_timeout', int),
('stateless_reset_token', bytes),
('max_packet_size', int),
('initial_max_data', int),
('initial_max_stream_data_bidi_local', int),
('initial_max_stream_data_bidi_remote', int),
('initial_max_stream_data_uni', int),
('initial_max_streams_bidi', int),
('initial_max_streams_uni', int),
('ack_delay_exponent', int),
('max_ack_delay', int),
('disable_migration', bool),
('preferred_address', bytes),
]
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
===========unchanged ref 1===========
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint16(buf: Buffer) -> int
pull_uint32(buf: Buffer) -> int
pull_block(buf: Buffer, capacity: int)
pull_list(buf: Buffer, capacity: int, func)
at: aioquic.tls.Buffer
tell()
|
aioquic.packet/push_quic_transport_parameters
|
Modified
|
aiortc~aioquic
|
34d603600c4795802e9230bd8884bd7e02cb9b70
|
[packet] adapt transport parameters parsing for draft 19
|
<2>:<add> elif is_client is False:
<del> else:
|
# module: aioquic.packet
def push_quic_transport_parameters(buf, params, is_client):
<0> if is_client:
<1> push_uint32(buf, params.initial_version)
<2> else:
<3> push_uint32(buf, params.negotiated_version)
<4> push_list(buf, 1, push_uint32, params.supported_versions)
<5> with push_block(buf, 2):
<6> for param_id, (param_name, param_type) in enumerate(PARAMS):
<7> param_value = getattr(params, param_name)
<8> if param_value not in [None, False]:
<9> push_uint16(buf, param_id)
<10> with push_block(buf, 2):
<11> if param_type == int:
<12> push_uint_var(buf, param_value)
<13> elif param_type == bytes:
<14> push_bytes(buf, param_value)
<15>
|
===========unchanged ref 0===========
at: aioquic.packet
push_uint_var(buf, value)
PARAMS = [
('original_connection_id', bytes),
('idle_timeout', int),
('stateless_reset_token', bytes),
('max_packet_size', int),
('initial_max_data', int),
('initial_max_stream_data_bidi_local', int),
('initial_max_stream_data_bidi_remote', int),
('initial_max_stream_data_uni', int),
('initial_max_streams_bidi', int),
('initial_max_streams_uni', int),
('ack_delay_exponent', int),
('max_ack_delay', int),
('disable_migration', bool),
('preferred_address', bytes),
]
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
at: aioquic.tls
push_bytes(buf: Buffer, v: bytes)
push_uint16(buf: Buffer, v: int)
push_uint32(buf: Buffer, v: int)
push_block(buf: Buffer, capacity: int)
push_list(buf: Buffer, capacity: int, func, values)
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_transport_parameters(buf, is_client):
params = QuicTransportParameters()
if is_client:
params.initial_version = pull_uint32(buf)
+ elif is_client is False:
- else:
params.negotiated_version = pull_uint32(buf)
params.supported_versions = pull_list(buf, 1, pull_uint32)
with pull_block(buf, 2) as length:
end = buf.tell() + length
while buf.tell() < end:
param_id = pull_uint16(buf)
param_len = pull_uint16(buf)
param_start = buf.tell()
param_name, param_type = PARAMS[param_id]
if param_type == int:
setattr(params, param_name, pull_uint_var(buf))
elif param_type == bytes:
setattr(params, param_name, pull_bytes(buf, param_len))
else:
setattr(params, param_name, True)
assert buf.tell() == param_start + param_len
return params
|
aioquic.connection/QuicConnection._init_tls
|
Modified
|
aiortc~aioquic
|
34d603600c4795802e9230bd8884bd7e02cb9b70
|
[packet] adapt transport parameters parsing for draft 19
|
<0>:<add> if self.version >= QuicProtocolVersion.DRAFT_19:
<add> self.quic_transport_parameters.idle_timeout = 600000
<del> if self.is_client:
<1>:<del> self.quic_transport_parameters.initial_version = self.version
<3>:<add> self.quic_transport_parameters.idle_timeout = 600
<add> if self.is_client:
<add> self.quic_transport_parameters.initial_version = self.version
<add> else:
<add> self.quic_transport_parameters.negotiated_version = self.version
<del> self.quic_transport_parameters.negotiated_version = self.version
<4>:<add> self.quic_transport_parameters.supported_versions = self.supported_versions
<del> self.quic_transport_parameters.supported_versions = self.supported_versions
<5>:<add> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<del> self.quic_transport_parameters.stateless_reset_token = bytes(16)
|
# module: aioquic.connection
class QuicConnection:
def _init_tls(self):
<0> if self.is_client:
<1> self.quic_transport_parameters.initial_version = self.version
<2> else:
<3> self.quic_transport_parameters.negotiated_version = self.version
<4> self.quic_transport_parameters.supported_versions = self.supported_versions
<5> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<6>
<7> self.tls = tls.Context(is_client=self.is_client)
<8> self.tls.certificate = self.certificate
<9> self.tls.certificate_private_key = self.private_key
<10> self.tls.handshake_extensions = [
<11> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<12> ]
<13> self.tls.server_name = self.server_name
<14> self.tls.update_traffic_key_cb = self._update_traffic_key
<15>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
_serialize_parameters(self)
_serialize_parameters()
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.__init__
self.certificate = certificate
self.is_client = is_client
self.private_key = private_key
self.server_name = server_name
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
===========unchanged ref 1===========
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.tls
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Context(is_client)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.packet
def push_quic_transport_parameters(buf, params, is_client):
if is_client:
push_uint32(buf, params.initial_version)
+ elif is_client is False:
- else:
push_uint32(buf, params.negotiated_version)
push_list(buf, 1, push_uint32, params.supported_versions)
with push_block(buf, 2):
for param_id, (param_name, param_type) in enumerate(PARAMS):
param_value = getattr(params, param_name)
if param_value not in [None, False]:
push_uint16(buf, param_id)
with push_block(buf, 2):
if param_type == int:
push_uint_var(buf, param_value)
elif param_type == bytes:
push_bytes(buf, param_value)
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_transport_parameters(buf, is_client):
params = QuicTransportParameters()
if is_client:
params.initial_version = pull_uint32(buf)
+ elif is_client is False:
- else:
params.negotiated_version = pull_uint32(buf)
params.supported_versions = pull_list(buf, 1, pull_uint32)
with pull_block(buf, 2) as length:
end = buf.tell() + length
while buf.tell() < end:
param_id = pull_uint16(buf)
param_len = pull_uint16(buf)
param_start = buf.tell()
param_name, param_type = PARAMS[param_id]
if param_type == int:
setattr(params, param_name, pull_uint_var(buf))
elif param_type == bytes:
setattr(params, param_name, pull_bytes(buf, param_len))
else:
setattr(params, param_name, True)
assert buf.tell() == param_start + param_len
return params
|
aioquic.connection/QuicConnection._serialize_parameters
|
Modified
|
aiortc~aioquic
|
34d603600c4795802e9230bd8884bd7e02cb9b70
|
[packet] adapt transport parameters parsing for draft 19
|
<1>:<add> if self.version >= QuicProtocolVersion.DRAFT_19:
<add> is_client = None
<add> else:
<add> is_client = self.is_client
<2>:<add> is_client=is_client)
<del> is_client=self.is_client)
|
# module: aioquic.connection
class QuicConnection:
def _serialize_parameters(self):
<0> buf = Buffer(capacity=512)
<1> push_quic_transport_parameters(buf, self.quic_transport_parameters,
<2> is_client=self.is_client)
<3> return buf.data
<4>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
at: aioquic.packet
push_quic_transport_parameters(buf, params, is_client)
at: aioquic.tls
Buffer(capacity=None, data=None)
===========changed ref 0===========
# module: aioquic.packet
def push_quic_transport_parameters(buf, params, is_client):
if is_client:
push_uint32(buf, params.initial_version)
+ elif is_client is False:
- else:
push_uint32(buf, params.negotiated_version)
push_list(buf, 1, push_uint32, params.supported_versions)
with push_block(buf, 2):
for param_id, (param_name, param_type) in enumerate(PARAMS):
param_value = getattr(params, param_name)
if param_value not in [None, False]:
push_uint16(buf, param_id)
with push_block(buf, 2):
if param_type == int:
push_uint_var(buf, param_value)
elif param_type == bytes:
push_bytes(buf, param_value)
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _init_tls(self):
+ if self.version >= QuicProtocolVersion.DRAFT_19:
+ self.quic_transport_parameters.idle_timeout = 600000
- if self.is_client:
- self.quic_transport_parameters.initial_version = self.version
else:
+ self.quic_transport_parameters.idle_timeout = 600
+ if self.is_client:
+ self.quic_transport_parameters.initial_version = self.version
+ else:
+ self.quic_transport_parameters.negotiated_version = self.version
- self.quic_transport_parameters.negotiated_version = self.version
+ self.quic_transport_parameters.supported_versions = self.supported_versions
- self.quic_transport_parameters.supported_versions = self.supported_versions
+ self.quic_transport_parameters.stateless_reset_token = bytes(16)
- self.quic_transport_parameters.stateless_reset_token = bytes(16)
self.tls = tls.Context(is_client=self.is_client)
self.tls.certificate = self.certificate
self.tls.certificate_private_key = self.private_key
self.tls.handshake_extensions = [
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
]
self.tls.server_name = self.server_name
self.tls.update_traffic_key_cb = self._update_traffic_key
===========changed ref 2===========
# module: aioquic.packet
def pull_quic_transport_parameters(buf, is_client):
params = QuicTransportParameters()
if is_client:
params.initial_version = pull_uint32(buf)
+ elif is_client is False:
- else:
params.negotiated_version = pull_uint32(buf)
params.supported_versions = pull_list(buf, 1, pull_uint32)
with pull_block(buf, 2) as length:
end = buf.tell() + length
while buf.tell() < end:
param_id = pull_uint16(buf)
param_len = pull_uint16(buf)
param_start = buf.tell()
param_name, param_type = PARAMS[param_id]
if param_type == int:
setattr(params, param_name, pull_uint_var(buf))
elif param_type == bytes:
setattr(params, param_name, pull_bytes(buf, param_len))
else:
setattr(params, param_name, True)
assert buf.tell() == param_start + param_len
return params
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
3a6c554acfa8199557652e82e4080244093348f6
|
[connection] create stream if it doesn't exist yet
|
<31>:<del> stream = self.streams[stream_id]
<32>:<add> frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
<del> stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
<33>:<add> stream = self._get_or_create_stream(stream_id)
<add> stream.add_frame(frame)
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
<0> buf = Buffer(data=plain)
<1>
<2> is_ack_only = True
<3> while not buf.eof():
<4> frame_type = pull_uint_var(buf)
<5> if frame_type != QuicFrameType.ACK:
<6> is_ack_only = False
<7>
<8> if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
<9> pass
<10> elif frame_type == QuicFrameType.ACK:
<11> packet.pull_ack_frame(buf)
<12> elif frame_type == QuicFrameType.CRYPTO:
<13> stream = self.streams[epoch]
<14> stream.add_frame(packet.pull_crypto_frame(buf))
<15> data = stream.pull_data()
<16> if data:
<17> self.tls.handle_message(data, self.send_buffer)
<18> elif frame_type == QuicFrameType.NEW_TOKEN:
<19> packet.pull_new_token_frame(buf)
<20> elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
<21> flags = frame_type & STREAM_FLAGS
<22> stream_id = pull_uint_var(buf)
<23> if flags & STREAM_FLAG_OFF:
<24> offset = pull_uint_var(buf)
<25> else:
<26> offset = 0
<27> if flags & STREAM_FLAG_LEN:
<28> length = pull_uint_var(buf)
<29> else:
<30> length = buf.capacity - buf.tell()
<31> stream = self.streams[stream_id]
<32> stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
<33> elif frame_type == QuicFrameType.MAX_DATA:
<34> pull_uint_var(buf)
<35> elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
<36> </s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
===========unchanged ref 0===========
at: aioquic.connection
STREAM_FLAGS = 0x07
STREAM_FLAG_LEN = 2
STREAM_FLAG_OFF = 4
at: aioquic.connection.QuicConnection
_serialize_parameters()
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.__init__
self.server_name = server_name
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
at: aioquic.connection.QuicConnection._init_tls
self.tls = tls.Context(is_client=self.is_client)
at: aioquic.packet
pull_uint_var(buf)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
pull_ack_frame(buf)
QuicStreamFrame(data: bytes=b'', offset: int=0)
pull_crypto_frame(buf)
pull_new_token_frame(buf)
pull_new_connection_id_frame(buf)
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream
add_frame(frame: QuicStreamFrame)
pull_data()
===========unchanged ref 1===========
at: aioquic.tls
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
at: aioquic.tls.Buffer
eof()
tell()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: aioquic.tls.Context.__init__
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
+ def _get_or_create_stream(self, stream_id):
+ if stream_id not in self.streams:
+ self.streams[stream_id] = QuicStream(stream_id=stream_id)
+ return self.streams[stream_id]
+
|
aioquic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
3a6c554acfa8199557652e82e4080244093348f6
|
[connection] create stream if it doesn't exist yet
|
<3>:<add> if not space.crypto.send.is_valid():
<del> if not space.crypto.send.is_valid() or not send_ack:
<31>:<add> if packet_size > header_size:
<add> data = buf.data
<del> data = buf.data
<32>:<add> yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<del> yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<34>:<add> self.packet_number += 1
<del> self.packet_number += 1
|
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
<0> epoch = tls.Epoch.ONE_RTT
<1> space = self.spaces[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> if not space.crypto.send.is_valid() or not send_ack:
<4> return
<5>
<6> buf = Buffer(capacity=PACKET_MAX_SIZE)
<7>
<8> # write header
<9> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<10> tls.push_bytes(buf, self.peer_cid)
<11> tls.push_uint16(buf, self.packet_number)
<12> header_size = buf.tell()
<13>
<14> # ACK
<15> if send_ack:
<16> push_uint_var(buf, QuicFrameType.ACK)
<17> packet.push_ack_frame(buf, send_ack, 0)
<18> self.send_ack[epoch] = False
<19>
<20> # STREAM
<21> for stream_id, stream in self.streams.items():
<22> if isinstance(stream_id, int) and stream.has_data_to_send():
<23> frame = stream.get_frame(
<24> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6)
<25> push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
<26> with push_stream_frame(buf, 0, frame.offset):
<27> tls.push_bytes(buf, frame.data)
<28>
<29> # encrypt
<30> packet_size = buf.tell()
<31> data = buf.data
<32> yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<33>
<34> self.packet_number += 1
<35>
|
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.peer_cid = os.urandom(8)
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
self.send = CryptoContext()
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
push_uint_var(buf, value)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_stream_frame(buf, stream_id, offset)
===========unchanged ref 1===========
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream
get_frame(size)
has_data_to_send()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
push_bytes(buf: Buffer, v: bytes)
push_uint8(buf: Buffer, v: int)
push_uint16(buf: Buffer, v: int)
at: aioquic.tls.Buffer
tell()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
+ def _get_or_create_stream(self, stream_id):
+ if stream_id not in self.streams:
+ self.streams[stream_id] = QuicStream(stream_id=stream_id)
+ return self.streams[stream_id]
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
packet.pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
stream.add_frame(packet.pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_TOKEN:
packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
- stream = self.streams[stream_id]
+ frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
- stream.add_frame(QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length)))
+ stream = self._get_or_create_stream(stream_id)
+ stream.add_frame(frame)
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>Type.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, QuicFrameType.MAX_STREAMS_UNI]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
|
tests.test_packet/ParamsTest.test_client_params
|
Modified
|
aiortc~aioquic
|
df6c78ffe69d85599dbca5df510005e5ecd81fa0
|
[packet] add missing test for disable_migration
|
<0>:<add> data = binascii.unhexlify(
<del> buf = Buffer(data=binascii.unhexlify(
<2>:<add> '4000481000000000100024258000800024064000a00010a')
<del> '4000481000000000100024258000800024064000a00010a'))
<3>:<add>
<add> # parse
<add> buf = Buffer(data=data)
<15>:<add> # serialize
<add> buf = Buffer(capacity=len(data))
<del> buf = Buffer(capacity=512)
<17>:<add> self.assertEqual(len(buf.data), len(data))
|
# module: tests.test_packet
class ParamsTest(TestCase):
def test_client_params(self):
<0> buf = Buffer(data=binascii.unhexlify(
<1> 'ff0000110031000500048010000000060004801000000007000480100000000'
<2> '4000481000000000100024258000800024064000a00010a'))
<3> params = pull_quic_transport_parameters(buf, is_client=True)
<4> self.assertEqual(params, QuicTransportParameters(
<5> initial_version=QuicProtocolVersion.DRAFT_17,
<6> idle_timeout=600,
<7> initial_max_data=16777216,
<8> initial_max_stream_data_bidi_local=1048576,
<9> initial_max_stream_data_bidi_remote=1048576,
<10> initial_max_stream_data_uni=1048576,
<11> initial_max_streams_bidi=100,
<12> ack_delay_exponent=10,
<13> ))
<14>
<15> buf = Buffer(capacity=512)
<16> push_quic_transport_parameters(buf, params, is_client=True)
<17>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
pull_quic_transport_parameters(buf, is_client=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
===========unchanged ref 1===========
preferred_address: bytes = None
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_packet.ParamsTest
maxDiff = None
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
|
tests.test_packet/ParamsTest.test_server_params
|
Modified
|
aiortc~aioquic
|
df6c78ffe69d85599dbca5df510005e5ecd81fa0
|
[packet] add missing test for disable_migration
|
<0>:<add> data = binascii.unhexlify(
<del> buf = Buffer(data=binascii.unhexlify(
<3>:<add> '000000000000000800024064000a00010a')
<del> '000000000000000800024064000a00010a'))
<4>:<add>
<add> # parse
<add> buf = Buffer(data=data)
<18>:<add> # serialize
<add> buf = Buffer(capacity=len(data))
<del> buf = Buffer(capacity=512)
<20>:<add> self.assertEqual(len(buf.data), len(data))
|
# module: tests.test_packet
class ParamsTest(TestCase):
def test_server_params(self):
<0> buf = Buffer(data=binascii.unhexlify(
<1> 'ff00001104ff000011004500050004801000000006000480100000000700048'
<2> '010000000040004810000000001000242580002001000000000000000000000'
<3> '000000000000000800024064000a00010a'))
<4> params = pull_quic_transport_parameters(buf, is_client=False)
<5> self.assertEqual(params, QuicTransportParameters(
<6> negotiated_version=QuicProtocolVersion.DRAFT_17,
<7> supported_versions=[QuicProtocolVersion.DRAFT_17],
<8> idle_timeout=600,
<9> stateless_reset_token=bytes(16),
<10> initial_max_data=16777216,
<11> initial_max_stream_data_bidi_local=1048576,
<12> initial_max_stream_data_bidi_remote=1048576,
<13> initial_max_stream_data_uni=1048576,
<14> initial_max_streams_bidi=100,
<15> ack_delay_exponent=10,
<16> ))
<17>
<18> buf = Buffer(capacity=512)
<19> push_quic_transport_parameters(buf, params, is_client=False)
<20>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
pull_quic_transport_parameters(buf, is_client=None)
push_quic_transport_parameters(buf, params, is_client=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_packet.ParamsTest.test_client_params
data = binascii.unhexlify(
'ff0000110031000500048010000000060004801000000007000480100000000'
'4000481000000000100024258000800024064000a00010a')
params = pull_quic_transport_parameters(buf, is_client=True)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_packet
class ParamsTest(TestCase):
def test_client_params(self):
+ data = binascii.unhexlify(
- buf = Buffer(data=binascii.unhexlify(
'ff0000110031000500048010000000060004801000000007000480100000000'
+ '4000481000000000100024258000800024064000a00010a')
- '4000481000000000100024258000800024064000a00010a'))
+
+ # parse
+ buf = Buffer(data=data)
params = pull_quic_transport_parameters(buf, is_client=True)
self.assertEqual(params, QuicTransportParameters(
initial_version=QuicProtocolVersion.DRAFT_17,
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
))
+ # serialize
+ buf = Buffer(capacity=len(data))
- buf = Buffer(capacity=512)
push_quic_transport_parameters(buf, params, is_client=True)
+ self.assertEqual(len(buf.data), len(data))
|
tests.test_packet/ParamsTest.test_params
|
Modified
|
aiortc~aioquic
|
df6c78ffe69d85599dbca5df510005e5ecd81fa0
|
[packet] add missing test for disable_migration
|
<0>:<add> data = binascii.unhexlify(
<del> buf = Buffer(data=binascii.unhexlify(
<3>:<add> '0b0001190003000247e4')
<del> '0b0001190003000247e4'))
<5>:<add> # parse
<add> buf = Buffer(data=data)
<add> params = pull_quic_transport_parameters(buf)
<del> params = pull_quic_transport_parameters(buf, is_client=None)
|
# module: tests.test_packet
class ParamsTest(TestCase):
def test_params(self):
<0> buf = Buffer(data=binascii.unhexlify(
<1> '004700020010cc2fd6e7d97a53ab5be85b28d75c80080008000106000100026'
<2> '710000600048000ffff000500048000ffff000400048005fffa000a00010300'
<3> '0b0001190003000247e4'))
<4>
<5> params = pull_quic_transport_parameters(buf, is_client=None)
<6> self.assertEqual(params, QuicTransportParameters(
<7> idle_timeout=10000,
<8> stateless_reset_token=b'\xcc/\xd6\xe7\xd9zS\xab[\xe8[(\xd7\\\x80\x08',
<9> max_packet_size=2020,
<10> initial_max_data=393210,
<11> initial_max_stream_data_bidi_local=65535,
<12> initial_max_stream_data_bidi_remote=65535,
<13> initial_max_stream_data_uni=None,
<14> initial_max_streams_bidi=6,
<15> initial_max_streams_uni=None,
<16> ack_delay_exponent=3,
<17> max_ack_delay=25
<18> ))
<19>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
pull_quic_transport_parameters(buf, is_client=None)
push_quic_transport_parameters(buf, params, is_client=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_packet.ParamsTest.test_server_params
data = binascii.unhexlify(
'ff00001104ff000011004500050004801000000006000480100000000700048'
'010000000040004810000000001000242580002001000000000000000000000'
'000000000000000800024064000a00010a')
params = pull_quic_transport_parameters(buf, is_client=False)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_packet
class ParamsTest(TestCase):
def test_client_params(self):
+ data = binascii.unhexlify(
- buf = Buffer(data=binascii.unhexlify(
'ff0000110031000500048010000000060004801000000007000480100000000'
+ '4000481000000000100024258000800024064000a00010a')
- '4000481000000000100024258000800024064000a00010a'))
+
+ # parse
+ buf = Buffer(data=data)
params = pull_quic_transport_parameters(buf, is_client=True)
self.assertEqual(params, QuicTransportParameters(
initial_version=QuicProtocolVersion.DRAFT_17,
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
))
+ # serialize
+ buf = Buffer(capacity=len(data))
- buf = Buffer(capacity=512)
push_quic_transport_parameters(buf, params, is_client=True)
+ self.assertEqual(len(buf.data), len(data))
===========changed ref 1===========
# module: tests.test_packet
class ParamsTest(TestCase):
def test_server_params(self):
+ data = binascii.unhexlify(
- buf = Buffer(data=binascii.unhexlify(
'ff00001104ff000011004500050004801000000006000480100000000700048'
'010000000040004810000000001000242580002001000000000000000000000'
+ '000000000000000800024064000a00010a')
- '000000000000000800024064000a00010a'))
+
+ # parse
+ buf = Buffer(data=data)
params = pull_quic_transport_parameters(buf, is_client=False)
self.assertEqual(params, QuicTransportParameters(
negotiated_version=QuicProtocolVersion.DRAFT_17,
supported_versions=[QuicProtocolVersion.DRAFT_17],
idle_timeout=600,
stateless_reset_token=bytes(16),
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
))
+ # serialize
+ buf = Buffer(capacity=len(data))
- buf = Buffer(capacity=512)
push_quic_transport_parameters(buf, params, is_client=False)
+ self.assertEqual(len(buf.data), len(data))
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
90f6d4c8b556b6639412d4ed5adadef5abfb5c5c
|
[connection] defer initialization
|
<30>:<del> self.send_ack = {
<31>:<del> tls.Epoch.INITIAL: False,
<32>:<del> tls.Epoch.HANDSHAKE: False,
<33>:<del> tls.Epoch.ONE_RTT: False,
<34>:<del> }
<35>:<del> self.send_buffer = {
<36>:<del> tls.Epoch.INITIAL: Buffer(capacity=4096),
<37>:<del> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<38>:<del> tls.Epoch.ONE_RTT: Buffer(capacity=4
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.private_key = private_key
<10> self.secrets_log_file = secrets_log_file
<11> self.server_name = server_name
<12>
<13> # protocol versions
<14> self.version = QuicProtocolVersion.DRAFT_18
<15> self.supported_versions = [
<16> QuicProtocolVersion.DRAFT_17,
<17> QuicProtocolVersion.DRAFT_18,
<18> ]
<19>
<20> self.quic_transport_parameters = QuicTransportParameters(
<21> idle_timeout=600,
<22> initial_max_data=16777216,
<23> initial_max_stream_data_bidi_local=1048576,
<24> initial_max_stream_data_bidi_remote=1048576,
<25> initial_max_stream_data_uni=1048576,
<26> initial_max_streams_bidi=100,
<27> ack_delay_exponent=10,
<28> )
<29>
<30> self.send_ack = {
<31> tls.Epoch.INITIAL: False,
<32> tls.Epoch.HANDSHAKE: False,
<33> tls.Epoch.ONE_RTT: False,
<34> }
<35> self.send_buffer = {
<36> tls.Epoch.INITIAL: Buffer(capacity=4096),
<37> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<38> tls.Epoch.ONE_RTT: Buffer(capacity=4</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
# offset: 1
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
_initialize(self, peer_cid)
_initialize(peer_cid)
_push_crypto_data()
at: aioquic.connection.QuicConnection._initialize
self.tls = tls.Context(is_client=self.is_client)
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.__initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
===========unchanged ref 1===========
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: os
urandom(size: int, /) -> bytes
|
aioquic.connection/QuicConnection.connection_made
|
Modified
|
aiortc~aioquic
|
90f6d4c8b556b6639412d4ed5adadef5abfb5c5c
|
[connection] defer initialization
|
<4>:<del> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
<5>:<del> is_client=self.is_client)
<6>:<del> self._init_tls()
<7>:<del> self.crypto_initialized = True
<8>:<add> self._initialize(self.peer_cid)
|
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
<0> """
<1> At startup the client initiates the crypto handshake.
<2> """
<3> if self.is_client:
<4> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
<5> is_client=self.is_client)
<6> self._init_tls()
<7> self.crypto_initialized = True
<8>
<9> self.tls.handle_message(b'', self.send_buffer)
<10> self._push_crypto_data()
<11>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
at: aioquic.packet
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
eof()
tell()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
- self.send_ack = {
- tls.Epoch.INITIAL: False,
- tls.Epoch.HANDSHAKE: False,
- tls.Epoch.ONE_RTT: False,
- }
- self.send_buffer = {
- tls.Epoch.INITIAL: Buffer(capacity=4096),
- tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
- tls.Epoch.ONE_RTT: Buffer(capacity=4096),
- }
- self.spaces = {
- tls.Epoch.INITIAL: PacketSpace(),
- </s>
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
# offset: 1
<s>096),
- }
- self.spaces = {
- tls.Epoch.INITIAL: PacketSpace(),
- tls.Epoch.HANDSHAKE: PacketSpace(),
- tls.Epoch.ONE_RTT: PacketSpace(),
- }
- self.streams = {
- tls.Epoch.INITIAL: QuicStream(),
- tls.Epoch.HANDSHAKE: QuicStream(),
- tls.Epoch.ONE_RTT: QuicStream(),
- }
+ self.__initialized = False
- self.crypto_initialized = False
- self.packet_number = 0
-
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
90f6d4c8b556b6639412d4ed5adadef5abfb5c5c
|
[connection] defer initialization
|
<23>:<add> if not self.is_client and not self.__initialized:
<del> if not self.is_client and not self.crypto_initialized:
<24>:<del> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<25>:<del> is_client=self.is_client)
<26>:<del> self._init_tls()
<27>:<del> self.crypto_initialized = True
<28>:<add> self._initialize(header.destination_cid)
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> # version negotiation
<10> if self.is_client and header.packet_type is None:
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> self.version = max(common)
<16> self.connection_made()
<17> return
<18>
<19> encrypted_off = buf.tell() - start_off
<20> end_off = buf.tell() + header.rest_length
<21> tls.pull_bytes(buf, header.rest_length)
<22>
<23> if not self.is_client and not self.crypto_initialized:
<24> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<25> is_client=self.is_client)
<26> self._init_tls()
<27> self.crypto_initialized = True
<28>
<29> epoch = get_epoch(header.packet_type)
<30> space = self.spaces[epoch]
<31> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<32> data[start_off:end_off], encrypted_off)
<33>
<34> if not self.peer_cid_set:
<35> self.peer_cid = header.source_cid
<36> self.peer_cid_set = True
<37>
<38> # handle payload
<39> is_ack_only = self._payload_received(epoch, plain_payload)
<40>
<41> # record packet as received
<42> space.ack_queue.add(packet_number)
<43> if not is_ack</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
self.send_ack[epoch] = True
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_payload_received(epoch, plain)
_write_application()
_write_handshake(epoch)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
===========unchanged ref 1===========
at: aioquic.connection.QuicConnection.datagram_received
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
self.version = max(common)
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.packet.QuicHeader
packet_type: int
destination_cid: bytes
source_cid: bytes
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
idle_timeout: int = None
stateless_reset_token: bytes = None
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls
Epoch()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
"""
At startup the client initiates the crypto handshake.
"""
if self.is_client:
- self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
- is_client=self.is_client)
- self._init_tls()
- self.crypto_initialized = True
+ self._initialize(self.peer_cid)
self.tls.handle_message(b'', self.send_buffer)
self._push_crypto_data()
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
- self.send_ack = {
- tls.Epoch.INITIAL: False,
- tls.Epoch.HANDSHAKE: False,
- tls.Epoch.ONE_RTT: False,
- }
- self.send_buffer = {
- tls.Epoch.INITIAL: Buffer(capacity=4096),
- tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
- tls.Epoch.ONE_RTT: Buffer(capacity=4096),
- }
- self.spaces = {
- tls.Epoch.INITIAL: PacketSpace(),
- </s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
# offset: 1
<s>096),
- }
- self.spaces = {
- tls.Epoch.INITIAL: PacketSpace(),
- tls.Epoch.HANDSHAKE: PacketSpace(),
- tls.Epoch.ONE_RTT: PacketSpace(),
- }
- self.streams = {
- tls.Epoch.INITIAL: QuicStream(),
- tls.Epoch.HANDSHAKE: QuicStream(),
- tls.Epoch.ONE_RTT: QuicStream(),
- }
+ self.__initialized = False
- self.crypto_initialized = False
- self.packet_number = 0
-
|
tests.test_connection/QuicConnectionTest.test_create_stream
|
Modified
|
aiortc~aioquic
|
90f6d4c8b556b6639412d4ed5adadef5abfb5c5c
|
[connection] defer initialization
|
<1>:<add> client._initialize(b'')
<add>
<5>:<add> server._initialize(b'')
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_create_stream(self):
<0> client = QuicConnection(is_client=True)
<1> server = QuicConnection(
<2> is_client=False,
<3> certificate=SERVER_CERTIFICATE,
<4> private_key=SERVER_PRIVATE_KEY)
<5>
<6> # client
<7> stream = client.create_stream()
<8> self.assertEqual(stream.stream_id, 0)
<9>
<10> stream = client.create_stream()
<11> self.assertEqual(stream.stream_id, 4)
<12>
<13> stream = client.create_stream(is_unidirectional=True)
<14> self.assertEqual(stream.stream_id, 2)
<15>
<16> stream = client.create_stream(is_unidirectional=True)
<17> self.assertEqual(stream.stream_id, 6)
<18>
<19> # server
<20> stream = server.create_stream()
<21> self.assertEqual(stream.stream_id, 1)
<22>
<23> stream = server.create_stream()
<24> self.assertEqual(stream.stream_id, 5)
<25>
<26> stream = server.create_stream(is_unidirectional=True)
<27> self.assertEqual(stream.stream_id, 3)
<28>
<29> stream = server.create_stream(is_unidirectional=True)
<30> self.assertEqual(stream.stream_id, 7)
<31>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None, server_name=None)
at: aioquic.connection.QuicConnection
create_stream(is_unidirectional=False)
at: tests.test_connection
SERVER_CERTIFICATE = x509.load_pem_x509_certificate(
load('ssl_cert.pem'), backend=default_backend())
SERVER_PRIVATE_KEY = serialization.load_pem_private_key(
load('ssl_key.pem'), password=None, backend=default_backend())
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
"""
At startup the client initiates the crypto handshake.
"""
if self.is_client:
- self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
- is_client=self.is_client)
- self._init_tls()
- self.crypto_initialized = True
+ self._initialize(self.peer_cid)
self.tls.handle_message(b'', self.send_buffer)
self._push_crypto_data()
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
- def _init_tls(self):
- if self.version >= QuicProtocolVersion.DRAFT_19:
- self.quic_transport_parameters.idle_timeout = 600000
- else:
- self.quic_transport_parameters.idle_timeout = 600
- if self.is_client:
- self.quic_transport_parameters.initial_version = self.version
- else:
- self.quic_transport_parameters.negotiated_version = self.version
- self.quic_transport_parameters.supported_versions = self.supported_versions
- self.quic_transport_parameters.stateless_reset_token = bytes(16)
-
- self.tls = tls.Context(is_client=self.is_client)
- self.tls.certificate = self.certificate
- self.tls.certificate_private_key = self.private_key
- self.tls.handshake_extensions = [
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
- ]
- self.tls.server_name = self.server_name
- self.tls.update_traffic_key_cb = self._update_traffic_key
-
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
# version negotiation
if self.is_client and header.packet_type is None:
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
self.version = max(common)
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
+ if not self.is_client and not self.__initialized:
- if not self.is_client and not self.crypto_initialized:
- self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
- is_client=self.is_client)
- self._init_tls()
- self.crypto_initialized = True
+ self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
<s> space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
+ def _initialize(self, peer_cid):
+ # transport parameters
+ if self.version >= QuicProtocolVersion.DRAFT_19:
+ self.quic_transport_parameters.idle_timeout = 600000
+ else:
+ self.quic_transport_parameters.idle_timeout = 600
+ if self.is_client:
+ self.quic_transport_parameters.initial_version = self.version
+ else:
+ self.quic_transport_parameters.negotiated_version = self.version
+ self.quic_transport_parameters.supported_versions = self.supported_versions
+ self.quic_transport_parameters.stateless_reset_token = bytes(16)
+
+ # TLS
+ self.tls = tls.Context(is_client=self.is_client)
+ self.tls.certificate = self.certificate
+ self.tls.certificate_private_key = self.private_key
+ self.tls.handshake_extensions = [
+ (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
+ ]
+ self.tls.server_name = self.server_name
+ self.tls.update_traffic_key_cb = self._update_traffic_key
+
+ # packet spaces
+ self.send_ack = {
+ tls.Epoch.INITIAL: False,
+ tls.Epoch.HANDSHAKE: False,
+ tls.Epoch.ONE_RTT: False,
+ }
+ self.send_buffer = {
+ tls.Epoch.INITIAL: Buffer(capacity=4096),
+ tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
+ tls.Epoch.ONE_RTT: Buffer(capacity=4096),
+ }
+ self.spaces = {
+ tls.Epoch.INITIAL: PacketSpace(),
+ tls.Epoch.HANDSHAKE: PacketSpace(),
+ tls.Epoch.ONE_RTT: PacketSpace(),
+ }
+ </s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
+ def _initialize(self, peer_cid):
# offset: 1
<s>Epoch.HANDSHAKE: PacketSpace(),
+ tls.Epoch.ONE_RTT: PacketSpace(),
+ }
+ self.streams = {
+ tls.Epoch.INITIAL: QuicStream(),
+ tls.Epoch.HANDSHAKE: QuicStream(),
+ tls.Epoch.ONE_RTT: QuicStream(),
+ }
+
+ self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
+ is_client=self.is_client)
+
+ self.__initialized = True
+ self.packet_number = 0
+
|
aioquic.tls/Context.__init__
|
Modified
|
aiortc~aioquic
|
3b6b4ec2f7ff9f4c1f174beb3322dc2e58ebd508
|
[tls] refactor logging
|
<15>:<add> self.__logger = logger
|
# module: aioquic.tls
class Context:
+ def __init__(self, is_client, logger=None):
- def __init__(self, is_client):
<0> self.certificate = None
<1> self.certificate_private_key = None
<2> self.handshake_extensions = []
<3> self.is_client = is_client
<4> self.server_name = None
<5> self.update_traffic_key_cb = lambda d, e, s: None
<6>
<7> self._cipher_suites = [
<8> CipherSuite.AES_256_GCM_SHA384,
<9> CipherSuite.AES_128_GCM_SHA256,
<10> ]
<11> self._peer_certificate = None
<12> self._receive_buffer = b''
<13> self._enc_key = None
<14> self._dec_key = None
<15>
<16> if is_client:
<17> self.client_random = os.urandom(32)
<18> self.session_id = os.urandom(32)
<19> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<20> self.state = State.CLIENT_HANDSHAKE_START
<21> else:
<22> self.client_random = None
<23> self.session_id = None
<24> self.private_key = None
<25> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<26>
|
===========unchanged ref 0===========
at: aioquic.tls
State()
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.tls.Context._client_handle_certificate
self._peer_certificate = x509.load_der_x509_certificate(
certificate.certificates[0][0], backend=default_backend())
at: aioquic.tls.Context._client_handle_finished
self._enc_key = next_enc_key
at: aioquic.tls.Context._server_handle_finished
self._dec_key = self._next_dec_key
at: aioquic.tls.Context._server_handle_hello
self.client_random = peer_hello.random
self.session_id = peer_hello.session_id
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._set_state
self.state = state
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
self._dec_key = key
at: aioquic.tls.Context.handle_message
self._receive_buffer += input_data
self._receive_buffer = self._receive_buffer[message_length:]
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
- logger = logging.getLogger('tls')
-
TLS_VERSION_1_2 = 0x0303
TLS_VERSION_1_3 = 0x0304
TLS_VERSION_1_3_DRAFT_28 = 0x7f1c
TLS_VERSION_1_3_DRAFT_27 = 0x7f1b
TLS_VERSION_1_3_DRAFT_26 = 0x7f1a
|
aioquic.tls/Context._set_state
|
Modified
|
aiortc~aioquic
|
3b6b4ec2f7ff9f4c1f174beb3322dc2e58ebd508
|
[tls] refactor logging
|
<0>:<add> if self.__logger:
<add> self.__logger.info('TLS %s -> %s', self.state, state)
<del> logger.info('%s -> %s', self.state, state)
|
# module: aioquic.tls
class Context:
def _set_state(self, state):
<0> logger.info('%s -> %s', self.state, state)
<1> self.state = state
<2>
|
===========unchanged ref 0===========
at: aioquic.tls.Context.__init__
self.__logger = logger
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 0===========
# module: aioquic.tls
class Context:
+ def __init__(self, is_client, logger=None):
- def __init__(self, is_client):
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
+ self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 1===========
# module: aioquic.tls
- logger = logging.getLogger('tls')
-
TLS_VERSION_1_2 = 0x0303
TLS_VERSION_1_3 = 0x0304
TLS_VERSION_1_3_DRAFT_28 = 0x7f1c
TLS_VERSION_1_3_DRAFT_27 = 0x7f1b
TLS_VERSION_1_3_DRAFT_26 = 0x7f1a
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
3b6b4ec2f7ff9f4c1f174beb3322dc2e58ebd508
|
[tls] refactor logging
|
<31>:<add> self.__logger = logger
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.private_key = private_key
<10> self.secrets_log_file = secrets_log_file
<11> self.server_name = server_name
<12>
<13> # protocol versions
<14> self.version = QuicProtocolVersion.DRAFT_18
<15> self.supported_versions = [
<16> QuicProtocolVersion.DRAFT_17,
<17> QuicProtocolVersion.DRAFT_18,
<18> ]
<19>
<20> self.quic_transport_parameters = QuicTransportParameters(
<21> idle_timeout=600,
<22> initial_max_data=16777216,
<23> initial_max_stream_data_bidi_local=1048576,
<24> initial_max_stream_data_bidi_remote=1048576,
<25> initial_max_stream_data_uni=1048576,
<26> initial_max_streams_bidi=100,
<27> ack_delay_exponent=10,
<28> )
<29>
<30> self.__initialized = False
<31>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
===========unchanged ref 1===========
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
class Context:
def _set_state(self, state):
+ if self.__logger:
+ self.__logger.info('TLS %s -> %s', self.state, state)
- logger.info('%s -> %s', self.state, state)
self.state = state
===========changed ref 1===========
# module: aioquic.tls
- logger = logging.getLogger('tls')
-
TLS_VERSION_1_2 = 0x0303
TLS_VERSION_1_3 = 0x0304
TLS_VERSION_1_3_DRAFT_28 = 0x7f1c
TLS_VERSION_1_3_DRAFT_27 = 0x7f1b
TLS_VERSION_1_3_DRAFT_26 = 0x7f1a
===========changed ref 2===========
# module: aioquic.tls
class Context:
+ def __init__(self, is_client, logger=None):
- def __init__(self, is_client):
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
+ self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
3b6b4ec2f7ff9f4c1f174beb3322dc2e58ebd508
|
[tls] refactor logging
|
<15>:<add> if not common:
<add> self.__logger.error('Could not find a common protocol version')
<add> return
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> # version negotiation
<10> if self.is_client and header.packet_type is None:
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> self.version = max(common)
<16> self.connection_made()
<17> return
<18>
<19> encrypted_off = buf.tell() - start_off
<20> end_off = buf.tell() + header.rest_length
<21> tls.pull_bytes(buf, header.rest_length)
<22>
<23> if not self.is_client and not self.__initialized:
<24> self._initialize(header.destination_cid)
<25>
<26> epoch = get_epoch(header.packet_type)
<27> space = self.spaces[epoch]
<28> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<29> data[start_off:end_off], encrypted_off)
<30>
<31> if not self.peer_cid_set:
<32> self.peer_cid = header.source_cid
<33> self.peer_cid_set = True
<34>
<35> # handle payload
<36> is_ack_only = self._payload_received(epoch, plain_payload)
<37>
<38> # record packet as received
<39> space.ack_queue.add(packet_number)
<40> if not is_ack_only:
<41> self.send_ack[epoch] = True
<42>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
connection_made()
_initialize(self, peer_cid)
_initialize(peer_cid)
_payload_received(epoch, plain)
_payload_received(self, epoch, plain)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.__initialized = False
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.__initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
===========unchanged ref 1===========
at: aioquic.tls
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
+ self.__logger = logger
===========changed ref 1===========
# module: aioquic.tls
class Context:
def _set_state(self, state):
+ if self.__logger:
+ self.__logger.info('TLS %s -> %s', self.state, state)
- logger.info('%s -> %s', self.state, state)
self.state = state
===========changed ref 2===========
# module: aioquic.tls
- logger = logging.getLogger('tls')
-
TLS_VERSION_1_2 = 0x0303
TLS_VERSION_1_3 = 0x0304
TLS_VERSION_1_3_DRAFT_28 = 0x7f1c
TLS_VERSION_1_3_DRAFT_27 = 0x7f1b
TLS_VERSION_1_3_DRAFT_26 = 0x7f1a
===========changed ref 3===========
# module: aioquic.tls
class Context:
+ def __init__(self, is_client, logger=None):
- def __init__(self, is_client):
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
+ self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
|
aioquic.connection/QuicConnection._initialize
|
Modified
|
aiortc~aioquic
|
3b6b4ec2f7ff9f4c1f174beb3322dc2e58ebd508
|
[tls] refactor logging
|
<13>:<add> self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
<del> self.tls = tls.Context(is_client=self.is_client)
|
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
<0> # transport parameters
<1> if self.version >= QuicProtocolVersion.DRAFT_19:
<2> self.quic_transport_parameters.idle_timeout = 600000
<3> else:
<4> self.quic_transport_parameters.idle_timeout = 600
<5> if self.is_client:
<6> self.quic_transport_parameters.initial_version = self.version
<7> else:
<8> self.quic_transport_parameters.negotiated_version = self.version
<9> self.quic_transport_parameters.supported_versions = self.supported_versions
<10> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<11>
<12> # TLS
<13> self.tls = tls.Context(is_client=self.is_client)
<14> self.tls.certificate = self.certificate
<15> self.tls.certificate_private_key = self.private_key
<16> self.tls.handshake_extensions = [
<17> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<18> ]
<19> self.tls.server_name = self.server_name
<20> self.tls.update_traffic_key_cb = self._update_traffic_key
<21>
<22> # packet spaces
<23> self.send_ack = {
<24> tls.Epoch.INITIAL: False,
<25> tls.Epoch.HANDSHAKE: False,
<26> tls.Epoch.ONE_RTT: False,
<27> }
<28> self.send_buffer = {
<29> tls.Epoch.INITIAL: Buffer(capacity=4096),
<30> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<31> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<32> }
<33> self.spaces = {
<34> tls.Epoch.INITIAL: PacketSpace(),
<35> tls.Epoch.HANDSHAKE: PacketSpace(),
<36> tls.Epoch.ONE_RTT: PacketSpace(),
<37> }
<38> </s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# offset: 1
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
is_client=self.is_client)
self.__initialized = True
self.packet_number = 0
===========unchanged ref 0===========
at: aioquic.connection
PacketSpace()
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_serialize_parameters()
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.__init__
self.certificate = certificate
self.is_client = is_client
self.private_key = private_key
self.server_name = server_name
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
at: aioquic.crypto.CryptoPair
setup_initial(cid, is_client)
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
===========unchanged ref 1===========
supported_versions: List[int] = field(default_factory=list)
idle_timeout: int = None
stateless_reset_token: bytes = None
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls
Epoch()
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
Context(is_client, logger=None)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
+ self.__logger = logger
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
# version negotiation
if self.is_client and header.packet_type is None:
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
+ if not common:
+ self.__logger.error('Could not find a common protocol version')
+ return
self.version = max(common)
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========changed ref 2===========
# module: aioquic.tls
class Context:
def _set_state(self, state):
+ if self.__logger:
+ self.__logger.info('TLS %s -> %s', self.state, state)
- logger.info('%s -> %s', self.state, state)
self.state = state
===========changed ref 3===========
# module: aioquic.tls
- logger = logging.getLogger('tls')
-
TLS_VERSION_1_2 = 0x0303
TLS_VERSION_1_3 = 0x0304
TLS_VERSION_1_3_DRAFT_28 = 0x7f1c
TLS_VERSION_1_3_DRAFT_27 = 0x7f1b
TLS_VERSION_1_3_DRAFT_26 = 0x7f1a
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
3b6b4ec2f7ff9f4c1f174beb3322dc2e58ebd508
|
[tls] refactor logging
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
<0> buf = Buffer(data=plain)
<1>
<2> is_ack_only = True
<3> while not buf.eof():
<4> frame_type = pull_uint_var(buf)
<5> if frame_type != QuicFrameType.ACK:
<6> is_ack_only = False
<7>
<8> if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
<9> pass
<10> elif frame_type == QuicFrameType.ACK:
<11> packet.pull_ack_frame(buf)
<12> elif frame_type == QuicFrameType.CRYPTO:
<13> stream = self.streams[epoch]
<14> stream.add_frame(packet.pull_crypto_frame(buf))
<15> data = stream.pull_data()
<16> if data:
<17> self.tls.handle_message(data, self.send_buffer)
<18> elif frame_type == QuicFrameType.NEW_TOKEN:
<19> packet.pull_new_token_frame(buf)
<20> elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
<21> flags = frame_type & STREAM_FLAGS
<22> stream_id = pull_uint_var(buf)
<23> if flags & STREAM_FLAG_OFF:
<24> offset = pull_uint_var(buf)
<25> else:
<26> offset = 0
<27> if flags & STREAM_FLAG_LEN:
<28> length = pull_uint_var(buf)
<29> else:
<30> length = buf.capacity - buf.tell()
<31> frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
<32> stream = self._get_or_create_stream(stream_id)
<33> stream.add_frame(frame)
<34> elif frame_type == QuicFrameType.MAX_DATA:
<35> pull_uint_var(buf)
<36> elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, Quic</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
STREAM_FLAGS = 0x07
STREAM_FLAG_LEN = 2
STREAM_FLAG_OFF = 4
at: aioquic.connection.QuicConnection
_get_or_create_stream(stream_id)
_push_crypto_data()
at: aioquic.connection.QuicConnection._initialize
self.tls = tls.Context(is_client=self.is_client)
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
at: aioquic.packet
pull_uint_var(buf)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
pull_ack_frame(buf)
QuicStreamFrame(data: bytes=b'', offset: int=0)
pull_crypto_frame(buf)
pull_new_token_frame(buf)
pull_new_connection_id_frame(buf)
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream
add_frame(frame: QuicStreamFrame)
pull_data()
at: aioquic.tls
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
at: aioquic.tls.Buffer
eof()
tell()
===========unchanged ref 1===========
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: logging.Logger
warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
+ self.__logger = logger
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
# version negotiation
if self.is_client and header.packet_type is None:
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
+ if not common:
+ self.__logger.error('Could not find a common protocol version')
+ return
self.version = max(common)
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
|
|
tests.test_connection/QuicConnectionTest._test_connect_with_version
|
Modified
|
aiortc~aioquic
|
133b36a4201c57a9fd24e6e711db42ba3e4e65ff
|
[tests] refactor connection tests
|
<2>:<add> client.supported_versions = client_versions
<del> client.supported_versions = [version]
<3>:<add> client.version = max(client_versions)
<del> client.version = version
<9>:<add> server.supported_versions = server_versions
<del> server.supported_versions = [version]
<10>:<add> server.version = max(server_versions)
<del> server.version = version
<14>:<del> for datagram in client.pending_datagrams():
<15>:<del> server.datagram_received(datagram)
<16>:<del>
<17>:<del> for datagram in server.pending_datagrams():
<18>:<del> client.datagram_received(datagram)
<19>:<del>
<20>:<del> for datagram in client.pending_datagrams():
<21>:<del> server.datagram_received(datagram)
<22>:<del>
<23>:<del> for datagram in server.pending_datagrams():
<24>:<del> client.datagram_received(datagram)
<25>:<add> self.assertEqual(exchange_data(client, server), 2)
<29>:<del>
<30>:<del> for datagram in client.pending_datagrams():
<31>:<del> server.datagram_received(datagram)
<32>:<del>
<33>:<del> for datagram in server.pending_datagrams():
<34>:<del> client.datagram_received(datagram)
<35>:<add> self.assertEqual(exchange_data(client, server), 1)
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def _test_connect_with_version(self, client_versions, server_versions):
- def _test_connect_with_version(self, version):
<0> client = QuicConnection(
<1> is_client=True)
<2> client.supported_versions = [version]
<3> client.version = version
<4>
<5> server = QuicConnection(
<6> is_client=False,
<7> certificate=SERVER_CERTIFICATE,
<8> private_key=SERVER_PRIVATE_KEY)
<9> server.supported_versions = [version]
<10> server.version = version
<11>
<12> # perform handshake
<13> client.connection_made()
<14> for datagram in client.pending_datagrams():
<15> server.datagram_received(datagram)
<16>
<17> for datagram in server.pending_datagrams():
<18> client.datagram_received(datagram)
<19>
<20> for datagram in client.pending_datagrams():
<21> server.datagram_received(datagram)
<22>
<23> for datagram in server.pending_datagrams():
<24> client.datagram_received(datagram)
<25>
<26> # send data over stream
<27> client_stream = client.create_stream()
<28> client_stream.push_data(b'ping')
<29>
<30> for datagram in client.pending_datagrams():
<31> server.datagram_received(datagram)
<32>
<33> for datagram in server.pending_datagrams():
<34> client.datagram_received(datagram)
<35>
<36> server_stream = server.streams[0]
<37> self.assertEqual(server_stream.pull_data(), b'ping')
<38>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None, server_name=None)
at: aioquic.connection.QuicConnection
connection_made()
datagram_received(data: bytes)
pending_datagrams()
at: aioquic.connection.QuicConnection.__init__
self.version = QuicProtocolVersion.DRAFT_18
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
]
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
at: tests.test_connection
SERVER_CERTIFICATE = x509.load_pem_x509_certificate(
load('ssl_cert.pem'), backend=default_backend())
SERVER_PRIVATE_KEY = serialization.load_pem_private_key(
load('ssl_key.pem'), password=None, backend=default_backend())
exchange_data(client, server)
at: unittest.case
TestCase(methodName: str=...)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_connection
+ def exchange_data(client, server):
+ rounds = 0
+
+ while True:
+ client_sent = False
+ for datagram in client.pending_datagrams():
+ server.datagram_received(datagram)
+ client_sent = True
+
+ server_sent = False
+ for datagram in server.pending_datagrams():
+ client.datagram_received(datagram)
+ server_sent = True
+
+ if client_sent or server_sent:
+ rounds += 1
+ else:
+ break
+
+ return rounds
+
|
tests.test_connection/QuicConnectionTest.test_connect_draft_17
|
Modified
|
aiortc~aioquic
|
133b36a4201c57a9fd24e6e711db42ba3e4e65ff
|
[tests] refactor connection tests
|
<0>:<add> self._test_connect_with_version(
<add> client_versions=[QuicProtocolVersion.DRAFT_17],
<add> server_versions=[QuicProtocolVersion.DRAFT_17])
<del> self._test_connect_with_version(QuicProtocolVersion.DRAFT_17)
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_17(self):
<0> self._test_connect_with_version(QuicProtocolVersion.DRAFT_17)
<1>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
create_stream(is_unidirectional=False)
at: aioquic.stream.QuicStream
push_data(data)
at: tests.test_connection.QuicConnectionTest._test_connect_with_version
client = QuicConnection(
is_client=True)
===========changed ref 0===========
# module: tests.test_connection
+ def exchange_data(client, server):
+ rounds = 0
+
+ while True:
+ client_sent = False
+ for datagram in client.pending_datagrams():
+ server.datagram_received(datagram)
+ client_sent = True
+
+ server_sent = False
+ for datagram in server.pending_datagrams():
+ client.datagram_received(datagram)
+ server_sent = True
+
+ if client_sent or server_sent:
+ rounds += 1
+ else:
+ break
+
+ return rounds
+
===========changed ref 1===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def _test_connect_with_version(self, client_versions, server_versions):
- def _test_connect_with_version(self, version):
client = QuicConnection(
is_client=True)
+ client.supported_versions = client_versions
- client.supported_versions = [version]
+ client.version = max(client_versions)
- client.version = version
server = QuicConnection(
is_client=False,
certificate=SERVER_CERTIFICATE,
private_key=SERVER_PRIVATE_KEY)
+ server.supported_versions = server_versions
- server.supported_versions = [version]
+ server.version = max(server_versions)
- server.version = version
# perform handshake
client.connection_made()
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 2)
# send data over stream
client_stream = client.create_stream()
client_stream.push_data(b'ping')
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 1)
server_stream = server.streams[0]
self.assertEqual(server_stream.pull_data(), b'ping')
|
tests.test_connection/QuicConnectionTest.test_connect_draft_18
|
Modified
|
aiortc~aioquic
|
133b36a4201c57a9fd24e6e711db42ba3e4e65ff
|
[tests] refactor connection tests
|
<0>:<add> self._test_connect_with_version(
<add> client_versions=[QuicProtocolVersion.DRAFT_18],
<add> server_versions=[QuicProtocolVersion.DRAFT_18])
<del> self._test_connect_with_version(QuicProtocolVersion.DRAFT_18)
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_18(self):
<0> self._test_connect_with_version(QuicProtocolVersion.DRAFT_18)
<1>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
at: tests.test_connection.QuicConnectionTest._test_connect_with_version
server = QuicConnection(
is_client=False,
certificate=SERVER_CERTIFICATE,
private_key=SERVER_PRIVATE_KEY)
===========changed ref 0===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_17(self):
+ self._test_connect_with_version(
+ client_versions=[QuicProtocolVersion.DRAFT_17],
+ server_versions=[QuicProtocolVersion.DRAFT_17])
- self._test_connect_with_version(QuicProtocolVersion.DRAFT_17)
===========changed ref 1===========
# module: tests.test_connection
+ def exchange_data(client, server):
+ rounds = 0
+
+ while True:
+ client_sent = False
+ for datagram in client.pending_datagrams():
+ server.datagram_received(datagram)
+ client_sent = True
+
+ server_sent = False
+ for datagram in server.pending_datagrams():
+ client.datagram_received(datagram)
+ server_sent = True
+
+ if client_sent or server_sent:
+ rounds += 1
+ else:
+ break
+
+ return rounds
+
===========changed ref 2===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def _test_connect_with_version(self, client_versions, server_versions):
- def _test_connect_with_version(self, version):
client = QuicConnection(
is_client=True)
+ client.supported_versions = client_versions
- client.supported_versions = [version]
+ client.version = max(client_versions)
- client.version = version
server = QuicConnection(
is_client=False,
certificate=SERVER_CERTIFICATE,
private_key=SERVER_PRIVATE_KEY)
+ server.supported_versions = server_versions
- server.supported_versions = [version]
+ server.version = max(server_versions)
- server.version = version
# perform handshake
client.connection_made()
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 2)
# send data over stream
client_stream = client.create_stream()
client_stream.push_data(b'ping')
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 1)
server_stream = server.streams[0]
self.assertEqual(server_stream.pull_data(), b'ping')
|
tests.test_connection/QuicConnectionTest.test_connect_draft_19
|
Modified
|
aiortc~aioquic
|
133b36a4201c57a9fd24e6e711db42ba3e4e65ff
|
[tests] refactor connection tests
|
<0>:<add> self._test_connect_with_version(
<add> client_versions=[QuicProtocolVersion.DRAFT_19],
<add> server_versions=[QuicProtocolVersion.DRAFT_19])
<del> self._test_connect_with_version(QuicProtocolVersion.DRAFT_19)
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_19(self):
<0> self._test_connect_with_version(QuicProtocolVersion.DRAFT_19)
<1>
|
===========unchanged ref 0===========
at: tests.test_connection.QuicConnectionTest._test_connect_with_version
client = QuicConnection(
is_client=True)
server = QuicConnection(
is_client=False,
certificate=SERVER_CERTIFICATE,
private_key=SERVER_PRIVATE_KEY)
===========changed ref 0===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_18(self):
+ self._test_connect_with_version(
+ client_versions=[QuicProtocolVersion.DRAFT_18],
+ server_versions=[QuicProtocolVersion.DRAFT_18])
- self._test_connect_with_version(QuicProtocolVersion.DRAFT_18)
===========changed ref 1===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_17(self):
+ self._test_connect_with_version(
+ client_versions=[QuicProtocolVersion.DRAFT_17],
+ server_versions=[QuicProtocolVersion.DRAFT_17])
- self._test_connect_with_version(QuicProtocolVersion.DRAFT_17)
===========changed ref 2===========
# module: tests.test_connection
+ def exchange_data(client, server):
+ rounds = 0
+
+ while True:
+ client_sent = False
+ for datagram in client.pending_datagrams():
+ server.datagram_received(datagram)
+ client_sent = True
+
+ server_sent = False
+ for datagram in server.pending_datagrams():
+ client.datagram_received(datagram)
+ server_sent = True
+
+ if client_sent or server_sent:
+ rounds += 1
+ else:
+ break
+
+ return rounds
+
===========changed ref 3===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def _test_connect_with_version(self, client_versions, server_versions):
- def _test_connect_with_version(self, version):
client = QuicConnection(
is_client=True)
+ client.supported_versions = client_versions
- client.supported_versions = [version]
+ client.version = max(client_versions)
- client.version = version
server = QuicConnection(
is_client=False,
certificate=SERVER_CERTIFICATE,
private_key=SERVER_PRIVATE_KEY)
+ server.supported_versions = server_versions
- server.supported_versions = [version]
+ server.version = max(server_versions)
- server.version = version
# perform handshake
client.connection_made()
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 2)
# send data over stream
client_stream = client.create_stream()
client_stream.push_data(b'ping')
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 1)
server_stream = server.streams[0]
self.assertEqual(server_stream.pull_data(), b'ping')
|
tests.test_connection/QuicConnectionTest.test_connect_with_log
|
Modified
|
aiortc~aioquic
|
133b36a4201c57a9fd24e6e711db42ba3e4e65ff
|
[tests] refactor connection tests
|
<13>:<del> for datagram in client.pending_datagrams():
<14>:<del> server.datagram_received(datagram)
<15>:<del>
<16>:<del> for datagram in server.pending_datagrams():
<17>:<del> client.datagram_received(datagram)
<18>:<del>
<19>:<del> for datagram in client.pending_datagrams():
<20>:<del> server.datagram_received(datagram)
<21>:<del>
<22>:<del> for datagram in server.pending_datagrams():
<23>:<del> client.datagram_received(datagram)
<24>:<add> self.assertEqual(exchange_data(client, server), 2)
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_with_log(self):
<0> client_log_file = io.StringIO()
<1> client = QuicConnection(
<2> is_client=True,
<3> secrets_log_file=client_log_file)
<4> server_log_file = io.StringIO()
<5> server = QuicConnection(
<6> is_client=False,
<7> certificate=SERVER_CERTIFICATE,
<8> private_key=SERVER_PRIVATE_KEY,
<9> secrets_log_file=server_log_file)
<10>
<11> # perform handshake
<12> client.connection_made()
<13> for datagram in client.pending_datagrams():
<14> server.datagram_received(datagram)
<15>
<16> for datagram in server.pending_datagrams():
<17> client.datagram_received(datagram)
<18>
<19> for datagram in client.pending_datagrams():
<20> server.datagram_received(datagram)
<21>
<22> for datagram in server.pending_datagrams():
<23> client.datagram_received(datagram)
<24>
<25> # check secrets were logged
<26> client_log = client_log_file.getvalue()
<27> server_log = server_log_file.getvalue()
<28> self.assertEqual(client_log, server_log)
<29> labels = []
<30> for line in client_log.splitlines():
<31> labels.append(line.split()[0])
<32> self.assertEqual(labels, [
<33> 'QUIC_SERVER_HANDSHAKE_TRAFFIC_SECRET',
<34> 'QUIC_CLIENT_HANDSHAKE_TRAFFIC_SECRET',
<35> 'QUIC_SERVER_TRAFFIC_SECRET_0',
<36> 'QUIC_CLIENT_TRAFFIC_SECRET_0'])
<37>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None, server_name=None)
at: aioquic.connection.QuicConnection
connection_made()
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: io
StringIO(initial_value: Optional[str]=..., newline: Optional[str]=...)
at: io.StringIO
getvalue(self) -> str
at: tests.test_connection
SERVER_CERTIFICATE = x509.load_pem_x509_certificate(
load('ssl_cert.pem'), backend=default_backend())
SERVER_PRIVATE_KEY = serialization.load_pem_private_key(
load('ssl_key.pem'), password=None, backend=default_backend())
exchange_data(client, server)
at: tests.test_connection.QuicConnectionTest
_test_connect_with_version(self, client_versions, server_versions)
_test_connect_with_version(client_versions, server_versions)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_connection
+ def exchange_data(client, server):
+ rounds = 0
+
+ while True:
+ client_sent = False
+ for datagram in client.pending_datagrams():
+ server.datagram_received(datagram)
+ client_sent = True
+
+ server_sent = False
+ for datagram in server.pending_datagrams():
+ client.datagram_received(datagram)
+ server_sent = True
+
+ if client_sent or server_sent:
+ rounds += 1
+ else:
+ break
+
+ return rounds
+
===========changed ref 1===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
+ def _test_connect_with_version(self, client_versions, server_versions):
- def _test_connect_with_version(self, version):
client = QuicConnection(
is_client=True)
+ client.supported_versions = client_versions
- client.supported_versions = [version]
+ client.version = max(client_versions)
- client.version = version
server = QuicConnection(
is_client=False,
certificate=SERVER_CERTIFICATE,
private_key=SERVER_PRIVATE_KEY)
+ server.supported_versions = server_versions
- server.supported_versions = [version]
+ server.version = max(server_versions)
- server.version = version
# perform handshake
client.connection_made()
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 2)
# send data over stream
client_stream = client.create_stream()
client_stream.push_data(b'ping')
-
- for datagram in client.pending_datagrams():
- server.datagram_received(datagram)
-
- for datagram in server.pending_datagrams():
- client.datagram_received(datagram)
+ self.assertEqual(exchange_data(client, server), 1)
server_stream = server.streams[0]
self.assertEqual(server_stream.pull_data(), b'ping')
===========changed ref 2===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_19(self):
+ self._test_connect_with_version(
+ client_versions=[QuicProtocolVersion.DRAFT_19],
+ server_versions=[QuicProtocolVersion.DRAFT_19])
- self._test_connect_with_version(QuicProtocolVersion.DRAFT_19)
===========changed ref 3===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_18(self):
+ self._test_connect_with_version(
+ client_versions=[QuicProtocolVersion.DRAFT_18],
+ server_versions=[QuicProtocolVersion.DRAFT_18])
- self._test_connect_with_version(QuicProtocolVersion.DRAFT_18)
===========changed ref 4===========
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_connect_draft_17(self):
+ self._test_connect_with_version(
+ client_versions=[QuicProtocolVersion.DRAFT_17],
+ server_versions=[QuicProtocolVersion.DRAFT_17])
- self._test_connect_with_version(QuicProtocolVersion.DRAFT_17)
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
44035fee2a148a1a1cf6f17b31a97e31e9488961
|
[connection] use DRAFT-19 by default
|
<14>:<del> self.version = QuicProtocolVersion.DRAFT_18
<18>:<add> QuicProtocolVersion.DRAFT_19,
<19>:<add> self.version = QuicProtocolVersion.DRAFT_19
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.private_key = private_key
<10> self.secrets_log_file = secrets_log_file
<11> self.server_name = server_name
<12>
<13> # protocol versions
<14> self.version = QuicProtocolVersion.DRAFT_18
<15> self.supported_versions = [
<16> QuicProtocolVersion.DRAFT_17,
<17> QuicProtocolVersion.DRAFT_18,
<18> ]
<19>
<20> self.quic_transport_parameters = QuicTransportParameters(
<21> idle_timeout=600,
<22> initial_max_data=16777216,
<23> initial_max_stream_data_bidi_local=1048576,
<24> initial_max_stream_data_bidi_remote=1048576,
<25> initial_max_stream_data_uni=1048576,
<26> initial_max_streams_bidi=100,
<27> ack_delay_exponent=10,
<28> )
<29>
<30> self.__initialized = False
<31> self.__logger = logger
<32>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
===========unchanged ref 1===========
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
|
aioquic.packet/pull_quic_header
|
Modified
|
aiortc~aioquic
|
3d77a32174949e9148640ed449c0c871c6ba5281
|
[packet] use version=None for short headers
|
<43>:<add> version=None,
<del> version=0,
|
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
<0> first_byte = pull_uint8(buf)
<1>
<2> token = b''
<3> if is_long_header(first_byte):
<4> # long header packet
<5> version = pull_uint32(buf)
<6> cid_lengths = pull_uint8(buf)
<7>
<8> destination_cid_length = decode_cid_length(cid_lengths // 16)
<9> destination_cid = pull_bytes(buf, destination_cid_length)
<10>
<11> source_cid_length = decode_cid_length(cid_lengths % 16)
<12> source_cid = pull_bytes(buf, source_cid_length)
<13>
<14> if version == QuicProtocolVersion.NEGOTIATION:
<15> # version negotiation
<16> packet_type = None
<17> rest_length = buf.capacity - buf.tell()
<18> else:
<19> if version and not (first_byte & PACKET_FIXED_BIT):
<20> raise ValueError('Packet fixed bit is zero')
<21>
<22> packet_type = first_byte & PACKET_TYPE_MASK
<23> if packet_type == PACKET_TYPE_INITIAL:
<24> token_length = pull_uint_var(buf)
<25> token = pull_bytes(buf, token_length)
<26> rest_length = pull_uint_var(buf)
<27>
<28> return QuicHeader(
<29> version=version,
<30> packet_type=packet_type,
<31> destination_cid=destination_cid,
<32> source_cid=source_cid,
<33> token=token,
<34> rest_length=rest_length)
<35> else:
<36> # short header packet
<37> if not (first_byte & PACKET_FIXED_BIT):
<38> raise ValueError('Packet fixed bit is zero')
<39>
<40> packet_type = first_byte & PACKET_TYPE_MASK
<41> destination_cid = pull_bytes(buf, host_cid_length)
<42> return QuicHeader(
<43> version=0,
<44> packet</s>
|
===========below chunk 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========unchanged ref 0===========
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_MASK = 0xf0
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, token: bytes=b'', rest_length: int=0)
decode_cid_length(length)
is_long_header(first_byte)
pull_uint_var(buf)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint8(buf: Buffer) -> int
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
tell()
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
3d77a32174949e9148640ed449c0c871c6ba5281
|
[packet] use version=None for short headers
|
<10>:<add> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
<del> if self.is_client and header.packet_type is None:
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> # version negotiation
<10> if self.is_client and header.packet_type is None:
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> if not common:
<16> self.__logger.error('Could not find a common protocol version')
<17> return
<18> self.version = max(common)
<19> self.connection_made()
<20> return
<21>
<22> encrypted_off = buf.tell() - start_off
<23> end_off = buf.tell() + header.rest_length
<24> tls.pull_bytes(buf, header.rest_length)
<25>
<26> if not self.is_client and not self.__initialized:
<27> self._initialize(header.destination_cid)
<28>
<29> epoch = get_epoch(header.packet_type)
<30> space = self.spaces[epoch]
<31> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<32> data[start_off:end_off], encrypted_off)
<33>
<34> if not self.peer_cid_set:
<35> self.peer_cid = header.source_cid
<36> self.peer_cid_set = True
<37>
<38> # handle payload
<39> is_ack_only = self._payload_received(epoch, plain_payload)
<40>
<41> # record packet as received
<42> space.ack_queue.add(packet_number)
<43> if not is_ack_only:
<44> self.send_ack[epoch] = True
<45>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
connection_made()
_initialize(peer_cid)
_payload_received(epoch, plain)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.__initialized = False
self.__logger = logger
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.__initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
===========unchanged ref 1===========
at: aioquic.tls
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
at: logging.Logger
error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
+ version=None,
- version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_</s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s>
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
|
tests.test_packet/PacketTest.test_pull_short_header
|
Modified
|
aiortc~aioquic
|
3d77a32174949e9148640ed449c0c871c6ba5281
|
[packet] use version=None for short headers
|
<2>:<add> self.assertEqual(header.version, None)
<del> self.assertEqual(header.version, 0)
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_short_header(self):
<0> buf = Buffer(data=load('short_header.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, 0)
<3> self.assertEqual(header.packet_type, 0x50)
<4> self.assertEqual(header.destination_cid, binascii.unhexlify('f45aa7b59c0e1ad6'))
<5> self.assertEqual(header.source_cid, b'')
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 12)
<8> self.assertEqual(buf.tell(), 9)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
tell()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
+ version=None,
- version=0,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_</s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s>
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
# version negotiation
+ if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
- if self.is_client and header.packet_type is None:
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error('Could not find a common protocol version')
return
self.version = max(common)
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
|
aioquic.packet/pull_quic_header
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<2>:<add> original_destination_cid = b''
<26>:<add> rest_length = pull_uint_var(buf)
<del> rest_length = pull_uint_var(buf)
<27>:<add> elif packet_type == PACKET_TYPE_RETRY:
<add> original_destination_cid_length = decode_cid_length(first_byte & 0xf)
<add> original_destination_cid = pull_bytes(buf, original_destination_cid_length)
<add> token = pull_bytes(buf, buf.capacity - buf.tell())
<add> rest_length = 0
<add> else:
<add> rest_length = pull_uint_var(buf)
<33>:<add> original_destination_cid=original_destination_cid,
|
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
<0> first_byte = pull_uint8(buf)
<1>
<2> token = b''
<3> if is_long_header(first_byte):
<4> # long header packet
<5> version = pull_uint32(buf)
<6> cid_lengths = pull_uint8(buf)
<7>
<8> destination_cid_length = decode_cid_length(cid_lengths // 16)
<9> destination_cid = pull_bytes(buf, destination_cid_length)
<10>
<11> source_cid_length = decode_cid_length(cid_lengths % 16)
<12> source_cid = pull_bytes(buf, source_cid_length)
<13>
<14> if version == QuicProtocolVersion.NEGOTIATION:
<15> # version negotiation
<16> packet_type = None
<17> rest_length = buf.capacity - buf.tell()
<18> else:
<19> if version and not (first_byte & PACKET_FIXED_BIT):
<20> raise ValueError('Packet fixed bit is zero')
<21>
<22> packet_type = first_byte & PACKET_TYPE_MASK
<23> if packet_type == PACKET_TYPE_INITIAL:
<24> token_length = pull_uint_var(buf)
<25> token = pull_bytes(buf, token_length)
<26> rest_length = pull_uint_var(buf)
<27>
<28> return QuicHeader(
<29> version=version,
<30> packet_type=packet_type,
<31> destination_cid=destination_cid,
<32> source_cid=source_cid,
<33> token=token,
<34> rest_length=rest_length)
<35> else:
<36> # short header packet
<37> if not (first_byte & PACKET_FIXED_BIT):
<38> raise ValueError('Packet fixed bit is zero')
<39>
<40> packet_type = first_byte & PACKET_TYPE_MASK
<41> destination_cid = pull_bytes(buf, host_cid_length)
<42> return QuicHeader(
<43> version=None,
<44> packet</s>
|
===========below chunk 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========unchanged ref 0===========
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
PACKET_TYPE_MASK = 0xf0
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b'', token: bytes=b'', rest_length: int=0)
decode_cid_length(length)
is_long_header(first_byte)
pull_uint_var(buf)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint8(buf: Buffer) -> int
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
tell()
===========changed ref 0===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<9>:<add> self.peer_token = b''
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.private_key = private_key
<10> self.secrets_log_file = secrets_log_file
<11> self.server_name = server_name
<12>
<13> # protocol versions
<14> self.supported_versions = [
<15> QuicProtocolVersion.DRAFT_17,
<16> QuicProtocolVersion.DRAFT_18,
<17> QuicProtocolVersion.DRAFT_19,
<18> ]
<19> self.version = QuicProtocolVersion.DRAFT_19
<20>
<21> self.quic_transport_parameters = QuicTransportParameters(
<22> idle_timeout=600,
<23> initial_max_data=16777216,
<24> initial_max_stream_data_bidi_local=1048576,
<25> initial_max_stream_data_bidi_remote=1048576,
<26> initial_max_stream_data_uni=1048576,
<27> initial_max_streams_bidi=100,
<28> ack_delay_exponent=10,
<29> )
<30>
<31> self.__initialized = False
<32> self.__logger = logger
<33>
|
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
===========unchanged ref 1===========
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
+ original_destination_cid = b''
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
+ rest_length = pull_uint_var(buf)
- rest_length = pull_uint_var(buf)
+ elif packet_type == PACKET_TYPE_RETRY:
+ original_destination_cid_length = decode_cid_length(first_byte & 0xf)
+ original_destination_cid = pull_bytes(buf, original_destination_cid_length)
+ token = pull_bytes(buf, buf.capacity - buf.tell())
+ rest_length = 0
+ else:
+ rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination</s>
===========changed ref 2===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=None,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<9>:<del> # version negotiation
<11>:<add> # version negotiation
<20>:<add> return
<add> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
<add> # stateless retry
<add> if (
<add> header.destination_cid == self.host_cid and
<add> header.original_destination_cid == self.peer_cid
<add> ):
<add> self.__logger.info('Performing stateless retry')
<add> self.peer_cid = header.source_cid
<add> self.peer_token = header.token
<add> self.connection_made()
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> # version negotiation
<10> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> if not common:
<16> self.__logger.error('Could not find a common protocol version')
<17> return
<18> self.version = max(common)
<19> self.connection_made()
<20> return
<21>
<22> encrypted_off = buf.tell() - start_off
<23> end_off = buf.tell() + header.rest_length
<24> tls.pull_bytes(buf, header.rest_length)
<25>
<26> if not self.is_client and not self.__initialized:
<27> self._initialize(header.destination_cid)
<28>
<29> epoch = get_epoch(header.packet_type)
<30> space = self.spaces[epoch]
<31> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<32> data[start_off:end_off], encrypted_off)
<33>
<34> if not self.peer_cid_set:
<35> self.peer_cid = header.source_cid
<36> self.peer_cid_set = True
<37>
<38> # handle payload
<39> is_ack_only = self._payload_received(epoch, plain_payload)
<40>
<41> # record packet as received
<42> space.ack_queue.add(packet_number)
<43> if not is_ack_only:
<44> self.send_ack[epoch] =</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
connection_made()
_initialize(peer_cid)
_payload_received(epoch, plain)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.__initialized = False
self.__logger = logger
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.__initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
===========unchanged ref 1===========
original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
at: logging.Logger
error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
+ original_destination_cid = b''
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
+ rest_length = pull_uint_var(buf)
- rest_length = pull_uint_var(buf)
+ elif packet_type == PACKET_TYPE_RETRY:
+ original_destination_cid_length = decode_cid_length(first_byte & 0xf)
+ original_destination_cid = pull_bytes(buf, original_destination_cid_length)
+ token = pull_bytes(buf, buf.capacity - buf.tell())
+ rest_length = 0
+ else:
+ rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination</s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=None,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
===========changed ref 3===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<19>:<add> token=self.peer_token,
|
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
<0> space = self.spaces[epoch]
<1> stream = self.streams[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> self.send_ack[epoch] = False
<4>
<5> buf = Buffer(capacity=PACKET_MAX_SIZE)
<6>
<7> while space.crypto.send.is_valid() and (send_ack or stream.has_data_to_send()):
<8> if epoch == tls.Epoch.INITIAL:
<9> packet_type = PACKET_TYPE_INITIAL
<10> else:
<11> packet_type = PACKET_TYPE_HANDSHAKE
<12>
<13> # write header
<14> push_quic_header(buf, QuicHeader(
<15> version=self.version,
<16> packet_type=packet_type | (SEND_PN_SIZE - 1),
<17> destination_cid=self.peer_cid,
<18> source_cid=self.host_cid,
<19> ))
<20> header_size = buf.tell()
<21>
<22> # ACK
<23> if send_ack:
<24> push_uint_var(buf, QuicFrameType.ACK)
<25> packet.push_ack_frame(buf, send_ack, 0)
<26> send_ack = False
<27>
<28> if stream.has_data_to_send():
<29> # CRYPTO
<30> frame = stream.get_frame(
<31> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4)
<32> push_uint_var(buf, QuicFrameType.CRYPTO)
<33> with packet.push_crypto_frame(buf, frame.offset):
<34> tls.push_bytes(buf, frame.data)
<35>
<36> # PADDING
<37> if epoch == tls.Epoch.INITIAL and self.is_client:
<38> tls.push_bytes(
<39> buf,
<40> bytes(PACKET_MAX_SIZE - space.crypto.aead_tag_</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
# finalize length
packet_size = buf.tell()
buf.seek(header_size - SEND_PN_SIZE - 2)
length = packet_size - header_size + 2 + space.crypto.aead_tag_size
tls.push_uint16(buf, length | 0x4000)
tls.push_uint16(buf, self.packet_number)
buf.seek(packet_size)
# encrypt
data = buf.data
yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number += 1
buf.seek(0)
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.version = QuicProtocolVersion.DRAFT_19
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
self.send = CryptoContext()
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
===========unchanged ref 1===========
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b'', token: bytes=b'', rest_length: int=0)
push_uint_var(buf, value)
push_quic_header(buf, header)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_crypto_frame(buf, offset=0)
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream
get_frame(size)
has_data_to_send()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
push_bytes(buf: Buffer, v: bytes)
push_uint16(buf: Buffer, v: int)
at: aioquic.tls.Buffer
seek(pos)
tell()
===========changed ref 0===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
|
tests.test_packet/PacketTest.test_pull_initial_client
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<6>:<add> self.assertEqual(header.original_destination_cid, b'')
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
<0> buf = Buffer(data=load('initial_client.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
<3> self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
<4> self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
<5> self.assertEqual(header.source_cid, b'')
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 1263)
<8> self.assertEqual(buf.tell(), 17)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
+ original_destination_cid = b''
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
+ rest_length = pull_uint_var(buf)
- rest_length = pull_uint_var(buf)
+ elif packet_type == PACKET_TYPE_RETRY:
+ original_destination_cid_length = decode_cid_length(first_byte & 0xf)
+ original_destination_cid = pull_bytes(buf, original_destination_cid_length)
+ token = pull_bytes(buf, buf.capacity - buf.tell())
+ rest_length = 0
+ else:
+ rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination</s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=None,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 2===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
|
tests.test_packet/PacketTest.test_pull_initial_server
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<6>:<add> self.assertEqual(header.original_destination_cid, b'')
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
<0> buf = Buffer(data=load('initial_server.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
<3> self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
<4> self.assertEqual(header.destination_cid, b'')
<5> self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 182)
<8> self.assertEqual(buf.tell(), 17)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
+ original_destination_cid = b''
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
+ rest_length = pull_uint_var(buf)
- rest_length = pull_uint_var(buf)
+ elif packet_type == PACKET_TYPE_RETRY:
+ original_destination_cid_length = decode_cid_length(first_byte & 0xf)
+ original_destination_cid = pull_bytes(buf, original_destination_cid_length)
+ token = pull_bytes(buf, buf.capacity - buf.tell())
+ rest_length = 0
+ else:
+ rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination</s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=None,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 2===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
+ self.assertEqual(header.original_destination_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 3===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
|
tests.test_packet/PacketTest.test_pull_version_negotiation
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<6>:<add> self.assertEqual(header.original_destination_cid, b'')
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_version_negotiation(self):
<0> buf = Buffer(data=load('version_negotiation.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, QuicProtocolVersion.NEGOTIATION)
<3> self.assertEqual(header.packet_type, None)
<4> self.assertEqual(header.destination_cid, binascii.unhexlify('dae1889b81a91c26'))
<5> self.assertEqual(header.source_cid, binascii.unhexlify('f49243784f9bf3be'))
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 8)
<8> self.assertEqual(buf.tell(), 22)
<9>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
tell()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_packet.PacketTest.test_pull_initial_server
buf = Buffer(data=load('initial_server.bin'))
at: tests.utils
load(name)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
first_byte = pull_uint8(buf)
+ original_destination_cid = b''
token = b''
if is_long_header(first_byte):
# long header packet
version = pull_uint32(buf)
cid_lengths = pull_uint8(buf)
destination_cid_length = decode_cid_length(cid_lengths // 16)
destination_cid = pull_bytes(buf, destination_cid_length)
source_cid_length = decode_cid_length(cid_lengths % 16)
source_cid = pull_bytes(buf, source_cid_length)
if version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
packet_type = None
rest_length = buf.capacity - buf.tell()
else:
if version and not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
if packet_type == PACKET_TYPE_INITIAL:
token_length = pull_uint_var(buf)
token = pull_bytes(buf, token_length)
+ rest_length = pull_uint_var(buf)
- rest_length = pull_uint_var(buf)
+ elif packet_type == PACKET_TYPE_RETRY:
+ original_destination_cid_length = decode_cid_length(first_byte & 0xf)
+ original_destination_cid = pull_bytes(buf, original_destination_cid_length)
+ token = pull_bytes(buf, buf.capacity - buf.tell())
+ rest_length = 0
+ else:
+ rest_length = pull_uint_var(buf)
return QuicHeader(
version=version,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination</s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s> destination_cid=destination_cid,
source_cid=source_cid,
+ original_destination_cid=original_destination_cid,
token=token,
rest_length=rest_length)
else:
# short header packet
if not (first_byte & PACKET_FIXED_BIT):
raise ValueError('Packet fixed bit is zero')
packet_type = first_byte & PACKET_TYPE_MASK
destination_cid = pull_bytes(buf, host_cid_length)
return QuicHeader(
version=None,
packet_type=packet_type,
destination_cid=destination_cid,
source_cid=b'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========changed ref 2===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
buf = Buffer(data=load('initial_server.bin'))
header = pull_quic_header(buf, host_cid_length=8)
self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, b'')
self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
+ self.assertEqual(header.original_destination_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 182)
self.assertEqual(buf.tell(), 17)
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
+ self.assertEqual(header.original_destination_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 4===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
|
tests.test_packet/PacketTest.test_pull_short_header
|
Modified
|
aiortc~aioquic
|
ae2612040b70b31e7ada4f008f2188cee5af5fb3
|
Add support for stateless retry mechanism
|
<6>:<add> self.assertEqual(header.original_destination_cid, b'')
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_short_header(self):
<0> buf = Buffer(data=load('short_header.bin'))
<1> header = pull_quic_header(buf, host_cid_length=8)
<2> self.assertEqual(header.version, None)
<3> self.assertEqual(header.packet_type, 0x50)
<4> self.assertEqual(header.destination_cid, binascii.unhexlify('f45aa7b59c0e1ad6'))
<5> self.assertEqual(header.source_cid, b'')
<6> self.assertEqual(header.token, b'')
<7> self.assertEqual(header.rest_length, 12)
<8> self.assertEqual(buf.tell(), 9)
<9>
|
===========unchanged ref 0===========
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
tell()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_packet.PacketTest.test_pull_version_negotiation
buf = Buffer(data=load('version_negotiation.bin'))
header = pull_quic_header(buf, host_cid_length=8)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_version_negotiation(self):
buf = Buffer(data=load('version_negotiation.bin'))
header = pull_quic_header(buf, host_cid_length=8)
self.assertEqual(header.version, QuicProtocolVersion.NEGOTIATION)
self.assertEqual(header.packet_type, None)
self.assertEqual(header.destination_cid, binascii.unhexlify('dae1889b81a91c26'))
self.assertEqual(header.source_cid, binascii.unhexlify('f49243784f9bf3be'))
+ self.assertEqual(header.original_destination_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 8)
self.assertEqual(buf.tell(), 22)
===========changed ref 1===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_server(self):
buf = Buffer(data=load('initial_server.bin'))
header = pull_quic_header(buf, host_cid_length=8)
self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, b'')
self.assertEqual(header.source_cid, binascii.unhexlify('0fcee9852fde8780'))
+ self.assertEqual(header.original_destination_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 182)
self.assertEqual(buf.tell(), 17)
===========changed ref 2===========
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_initial_client(self):
buf = Buffer(data=load('initial_client.bin'))
header = pull_quic_header(buf, host_cid_length=8)
self.assertEqual(header.version, QuicProtocolVersion.DRAFT_17)
self.assertEqual(header.packet_type, PACKET_TYPE_INITIAL)
self.assertEqual(header.destination_cid, binascii.unhexlify('90ed1e1c7b04b5d3'))
self.assertEqual(header.source_cid, b'')
+ self.assertEqual(header.original_destination_cid, b'')
self.assertEqual(header.token, b'')
self.assertEqual(header.rest_length, 1263)
self.assertEqual(buf.tell(), 17)
===========changed ref 3===========
# module: tests.test_packet
class PacketTest(TestCase):
+ def test_pull_retry(self):
+ buf = Buffer(data=load('retry.bin'))
+ header = pull_quic_header(buf, host_cid_length=8)
+ self.assertEqual(header.version, QuicProtocolVersion.DRAFT_19)
+ self.assertEqual(header.packet_type, PACKET_TYPE_RETRY)
+ self.assertEqual(header.destination_cid, binascii.unhexlify('c98343fe8f5f0ff4'))
+ self.assertEqual(
+ header.source_cid,
+ binascii.unhexlify('c17f7c0473e635351b85a17e9f3296d7246c'))
+ self.assertEqual(header.original_destination_cid, binascii.unhexlify('85abb547bf28be97'))
+ self.assertEqual(
+ header.token,
+ binascii.unhexlify('01652d68d17c8e9f968d4fb4b70c9e526c4f837dbd85abb547bf28be97'))
+ self.assertEqual(header.rest_length, 0)
+ self.assertEqual(buf.tell(), 69)
+
===========changed ref 4===========
# module: aioquic.packet
@dataclass
class QuicHeader:
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
+ original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
]
self.version = QuicProtocolVersion.DRAFT_19
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
|
aioquic.tls/pull_client_hello
|
Modified
|
aiortc~aioquic
|
c948dd660c52065ce7b5627f657865b7c0c13733
|
[tls] add support for ALPN extension
|
<32>:<add> elif extension_type == ExtensionType.ALPN:
<add> hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
|
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
<0> hello = ClientHello()
<1>
<2> assert pull_uint8(buf) == HandshakeType.CLIENT_HELLO
<3> with pull_block(buf, 3):
<4> assert pull_uint16(buf) == TLS_VERSION_1_2
<5> hello.random = pull_bytes(buf, 32)
<6>
<7> session_id_length = pull_uint8(buf)
<8> hello.session_id = pull_bytes(buf, session_id_length)
<9>
<10> hello.cipher_suites = pull_list(buf, 2, pull_uint16)
<11> hello.compression_methods = pull_list(buf, 1, pull_uint8)
<12>
<13> # extensions
<14> def pull_extension(buf):
<15> extension_type = pull_uint16(buf)
<16> extension_length = pull_uint16(buf)
<17> if extension_type == ExtensionType.KEY_SHARE:
<18> hello.key_share = pull_list(buf, 2, pull_key_share)
<19> elif extension_type == ExtensionType.SUPPORTED_VERSIONS:
<20> hello.supported_versions = pull_list(buf, 1, pull_uint16)
<21> elif extension_type == ExtensionType.SIGNATURE_ALGORITHMS:
<22> hello.signature_algorithms = pull_list(buf, 2, pull_uint16)
<23> elif extension_type == ExtensionType.SUPPORTED_GROUPS:
<24> hello.supported_groups = pull_list(buf, 2, pull_uint16)
<25> elif extension_type == ExtensionType.PSK_KEY_EXCHANGE_MODES:
<26> hello.key_exchange_modes = pull_list(buf, 1, pull_uint8)
<27> elif extension_type == ExtensionType.SERVER_NAME:
<28> with pull_block(buf, 2):
<29> assert pull_uint8(buf) == 0
<30> with pull_block(buf, 2) as length:
<31> hello.server_name = pull_bytes(buf, length).decode('ascii')
<32> else:
<33> hello</s>
|
===========below chunk 0===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
(extension_type, pull_bytes(buf, extension_length)),
)
pull_list(buf, 2, pull_extension)
return hello
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_2 = 0x0303
HandshakeType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HandshakeType(x: Union[str, bytes, bytearray], base: int)
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
push_bytes(buf: Buffer, v: bytes)
pull_uint8(buf: Buffer) -> int
push_uint8(buf: Buffer, v: int)
pull_uint16(buf: Buffer) -> int
pull_block(buf: Buffer, capacity: int)
pull_list(buf: Buffer, capacity: int, func)
at: dataclasses
field(*, default_factory: Callable[[], _T], init: bool=..., repr: bool=..., hash: Optional[bool]=..., compare: bool=..., metadata: Optional[Mapping[str, Any]]=...) -> _T
field(*, init: bool=..., repr: bool=..., hash: Optional[bool]=..., compare: bool=..., metadata: Optional[Mapping[str, Any]]=...) -> Any
field(*, default: _T, init: bool=..., repr: bool=..., hash: Optional[bool]=..., compare: bool=..., metadata: Optional[Mapping[str, Any]]=...) -> _T
dataclass(*, init: bool=..., repr: bool=..., eq: bool=..., order: bool=..., unsafe_hash: bool=..., frozen: bool=...) -> Callable[[Type[_T]], Type[_T]]
dataclass(_cls: None) -> Callable[[Type[_T]], Type[_T]]
dataclass(_cls: Type[_T]) -> Type[_T]
at: typing
Tuple = _TupleType(tuple, -1, inst=False, name='Tuple')
List = _alias(list, 1, inst=False, name='List')
===========changed ref 0===========
# module: aioquic.tls
+ # ALPN
+
+
+ def pull_alpn_protocol(buf: Buffer) -> str:
+ length = pull_uint8(buf)
+ return pull_bytes(buf, length).decode('ascii')
+
===========changed ref 1===========
# module: aioquic.tls
# MESSAGES
@dataclass
class ClientHello:
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
# extensions
+ alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
===========changed ref 2===========
# module: aioquic.tls
class Group(IntEnum):
SECP256R1 = 0x0017
SECP384R1 = 0x0018
SECP521R1 = 0x0019
+ X25519 = 0x001d
===========changed ref 3===========
# module: aioquic.tls
class CipherSuite(IntEnum):
AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
CHACHA20_POLY1305_SHA256 = 0x1303
+ EMPTY_RENEGOTIATION_INFO_SCSV = 0x00ff
===========changed ref 4===========
# module: aioquic.tls
class SignatureAlgorithm(IntEnum):
+ ECDSA_SECP256R1_SHA256 = 0x0403
+ ECDSA_SECP384R1_SHA384 = 0x0503
+ ECDSA_SECP521R1_SHA512 = 0x0603
+ ED25519 = 0x0807
+ ED448 = 0x0808
+ RSA_PKCS1_SHA1 = 0x0201
+ RSA_PKCS1_SHA256 = 0x0401
+ RSA_PKCS1_SHA384 = 0x0501
+ RSA_PKCS1_SHA512 = 0x0601
+ RSA_PSS_PSS_SHA256 = 0x0809
+ RSA_PSS_PSS_SHA384 = 0x080a
+ RSA_PSS_PSS_SHA512 = 0x080b
RSA_PSS_RSAE_SHA256 = 0x0804
- ECDSA_SECP256R1_SHA256 = 0x0403
- RSA_PKCS1_SHA256 = 0x0401
- RSA_PKCS1_SHA1 = 0x0201
+ RSA_PSS_RSAE_SHA384 = 0x0805
+ RSA_PSS_RSAE_SHA512 = 0x0806
|
aioquic.tls/push_client_hello
|
Modified
|
aiortc~aioquic
|
c948dd660c52065ce7b5627f657865b7c0c13733
|
[tls] add support for ALPN extension
|
<33>:<add> if hello.alpn_protocols is not None:
<add> with push_extension(buf, ExtensionType.ALPN):
<add> push_list(buf, 2, push_alpn_protocol, hello.alpn_protocols)
<add>
|
# module: aioquic.tls
def push_client_hello(buf: Buffer, hello: ClientHello):
<0> push_uint8(buf, HandshakeType.CLIENT_HELLO)
<1> with push_block(buf, 3):
<2> push_uint16(buf, TLS_VERSION_1_2)
<3> push_bytes(buf, hello.random)
<4> with push_block(buf, 1):
<5> push_bytes(buf, hello.session_id)
<6> push_list(buf, 2, push_uint16, hello.cipher_suites)
<7> push_list(buf, 1, push_uint8, hello.compression_methods)
<8>
<9> # extensions
<10> with push_block(buf, 2):
<11> with push_extension(buf, ExtensionType.KEY_SHARE):
<12> push_list(buf, 2, push_key_share, hello.key_share)
<13>
<14> with push_extension(buf, ExtensionType.SUPPORTED_VERSIONS):
<15> push_list(buf, 1, push_uint16, hello.supported_versions)
<16>
<17> with push_extension(buf, ExtensionType.SIGNATURE_ALGORITHMS):
<18> push_list(buf, 2, push_uint16, hello.signature_algorithms)
<19>
<20> with push_extension(buf, ExtensionType.SUPPORTED_GROUPS):
<21> push_list(buf, 2, push_uint16, hello.supported_groups)
<22>
<23> with push_extension(buf, ExtensionType.PSK_KEY_EXCHANGE_MODES):
<24> push_list(buf, 1, push_uint8, hello.key_exchange_modes)
<25>
<26> if hello.server_name is not None:
<27> with push_extension(buf, ExtensionType.SERVER_NAME):
<28> with push_block(buf, 2):
<29> push_uint8(buf, 0)
<30> with push_block(buf, 2):
<31> push_bytes(buf, hello.server_name.encode('ascii'))
<32>
<33> for extension_type, extension_value in hello.other_extensions:
<34> with push_extension(buf</s>
|
===========below chunk 0===========
# module: aioquic.tls
def push_client_hello(buf: Buffer, hello: ClientHello):
# offset: 1
push_bytes(buf, extension_value)
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_2 = 0x0303
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HandshakeType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HandshakeType(x: Union[str, bytes, bytearray], base: int)
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
push_bytes(buf: Buffer, v: bytes)
pull_uint8(buf: Buffer) -> int
push_uint8(buf: Buffer, v: int)
pull_uint16(buf: Buffer) -> int
push_uint16(buf: Buffer, v: int)
pull_block(buf: Buffer, capacity: int)
push_block(buf: Buffer, capacity: int)
pull_list(buf: Buffer, capacity: int, func)
pull_key_share(buf: Buffer) -> Tuple[int, bytes]
pull_alpn_protocol(buf: Buffer) -> str
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=None, alpn_protocols: List[str]=None, key_exchange_modes: List[int]=None, key_share: List[Tuple[int, bytes]]=None, server_name: str=None, signature_algorithms: List[int]=None, supported_groups: List[int]=None, supported_versions: List[int]=None, other_extensions: List[Tuple[int, bytes]]=field(default_factory=list))
at: aioquic.tls.ClientHello
random: bytes = None
session_id: bytes = None
alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
===========unchanged ref 1===========
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: aioquic.tls.pull_client_hello
hello = ClientHello()
===========changed ref 0===========
# module: aioquic.tls
+ # ALPN
+
+
+ def pull_alpn_protocol(buf: Buffer) -> str:
+ length = pull_uint8(buf)
+ return pull_bytes(buf, length).decode('ascii')
+
===========changed ref 1===========
# module: aioquic.tls
# MESSAGES
@dataclass
class ClientHello:
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
# extensions
+ alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
===========changed ref 2===========
# module: aioquic.tls
+ def push_alpn_protocol(buf: Buffer, protocol: str):
+ data = protocol.encode('ascii')
+ push_uint8(buf, len(data))
+ push_bytes(buf, data)
+
===========changed ref 3===========
# module: aioquic.tls
class Group(IntEnum):
SECP256R1 = 0x0017
SECP384R1 = 0x0018
SECP521R1 = 0x0019
+ X25519 = 0x001d
===========changed ref 4===========
# module: aioquic.tls
class CipherSuite(IntEnum):
AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
CHACHA20_POLY1305_SHA256 = 0x1303
+ EMPTY_RENEGOTIATION_INFO_SCSV = 0x00ff
===========changed ref 5===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
hello = ClientHello()
assert pull_uint8(buf) == HandshakeType.CLIENT_HELLO
with pull_block(buf, 3):
assert pull_uint16(buf) == TLS_VERSION_1_2
hello.random = pull_bytes(buf, 32)
session_id_length = pull_uint8(buf)
hello.session_id = pull_bytes(buf, session_id_length)
hello.cipher_suites = pull_list(buf, 2, pull_uint16)
hello.compression_methods = pull_list(buf, 1, pull_uint8)
# extensions
def pull_extension(buf):
extension_type = pull_uint16(buf)
extension_length = pull_uint16(buf)
if extension_type == ExtensionType.KEY_SHARE:
hello.key_share = pull_list(buf, 2, pull_key_share)
elif extension_type == ExtensionType.SUPPORTED_VERSIONS:
hello.supported_versions = pull_list(buf, 1, pull_uint16)
elif extension_type == ExtensionType.SIGNATURE_ALGORITHMS:
hello.signature_algorithms = pull_list(buf, 2, pull_uint16)
elif extension_type == ExtensionType.SUPPORTED_GROUPS:
hello.supported_groups = pull_list(buf, 2, pull_uint16)
elif extension_type == ExtensionType.PSK_KEY_EXCHANGE_MODES:
hello.key_exchange_modes = pull_list(buf, 1, pull_uint8)
elif extension_type == ExtensionType.SERVER_NAME:
with pull_block(buf, 2):
assert pull_uint8(buf) == 0
with pull_block(buf, 2) as length:
hello.server_name = pull_bytes(buf, length).decode('ascii')
+ elif extension_type == ExtensionType.ALPN:
+ hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
</s>
===========changed ref 6===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
<s>ALPN:
+ hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
else:
hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
pull_list(buf, 2, pull_extension)
return hello
|
aioquic.tls/Context.__init__
|
Modified
|
aiortc~aioquic
|
c948dd660c52065ce7b5627f657865b7c0c13733
|
[tls] add support for ALPN extension
|
<0>:<add> self.alpn_protocols = None
|
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
<0> self.certificate = None
<1> self.certificate_private_key = None
<2> self.handshake_extensions = []
<3> self.is_client = is_client
<4> self.server_name = None
<5> self.update_traffic_key_cb = lambda d, e, s: None
<6>
<7> self._cipher_suites = [
<8> CipherSuite.AES_256_GCM_SHA384,
<9> CipherSuite.AES_128_GCM_SHA256,
<10> ]
<11> self._peer_certificate = None
<12> self._receive_buffer = b''
<13> self._enc_key = None
<14> self._dec_key = None
<15> self.__logger = logger
<16>
<17> if is_client:
<18> self.client_random = os.urandom(32)
<19> self.session_id = os.urandom(32)
<20> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<21> self.state = State.CLIENT_HANDSHAKE_START
<22> else:
<23> self.client_random = None
<24> self.session_id = None
<25> self.private_key = None
<26> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<27>
|
===========unchanged ref 0===========
at: aioquic.tls
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Group(x: Union[str, bytes, bytearray], base: int)
Group(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CIPHER_SUITES = {
CipherSuite.AES_128_GCM_SHA256: (aead.AESGCM, hashes.SHA256),
CipherSuite.AES_256_GCM_SHA384: (aead.AESGCM, hashes.SHA384),
CipherSuite.CHACHA20_POLY1305_SHA256: (aead.ChaCha20Poly1305, hashes.SHA256),
}
===========changed ref 0===========
# module: aioquic.tls
class Group(IntEnum):
SECP256R1 = 0x0017
SECP384R1 = 0x0018
SECP521R1 = 0x0019
+ X25519 = 0x001d
===========changed ref 1===========
# module: aioquic.tls
class CipherSuite(IntEnum):
AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
CHACHA20_POLY1305_SHA256 = 0x1303
+ EMPTY_RENEGOTIATION_INFO_SCSV = 0x00ff
===========changed ref 2===========
# module: aioquic.tls
+ # ALPN
+
+
+ def pull_alpn_protocol(buf: Buffer) -> str:
+ length = pull_uint8(buf)
+ return pull_bytes(buf, length).decode('ascii')
+
===========changed ref 3===========
# module: aioquic.tls
+ def push_alpn_protocol(buf: Buffer, protocol: str):
+ data = protocol.encode('ascii')
+ push_uint8(buf, len(data))
+ push_bytes(buf, data)
+
===========changed ref 4===========
# module: aioquic.tls
# MESSAGES
@dataclass
class ClientHello:
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
# extensions
+ alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
===========changed ref 5===========
# module: aioquic.tls
def push_client_hello(buf: Buffer, hello: ClientHello):
push_uint8(buf, HandshakeType.CLIENT_HELLO)
with push_block(buf, 3):
push_uint16(buf, TLS_VERSION_1_2)
push_bytes(buf, hello.random)
with push_block(buf, 1):
push_bytes(buf, hello.session_id)
push_list(buf, 2, push_uint16, hello.cipher_suites)
push_list(buf, 1, push_uint8, hello.compression_methods)
# extensions
with push_block(buf, 2):
with push_extension(buf, ExtensionType.KEY_SHARE):
push_list(buf, 2, push_key_share, hello.key_share)
with push_extension(buf, ExtensionType.SUPPORTED_VERSIONS):
push_list(buf, 1, push_uint16, hello.supported_versions)
with push_extension(buf, ExtensionType.SIGNATURE_ALGORITHMS):
push_list(buf, 2, push_uint16, hello.signature_algorithms)
with push_extension(buf, ExtensionType.SUPPORTED_GROUPS):
push_list(buf, 2, push_uint16, hello.supported_groups)
with push_extension(buf, ExtensionType.PSK_KEY_EXCHANGE_MODES):
push_list(buf, 1, push_uint8, hello.key_exchange_modes)
if hello.server_name is not None:
with push_extension(buf, ExtensionType.SERVER_NAME):
with push_block(buf, 2):
push_uint8(buf, 0)
with push_block(buf, 2):
push_bytes(buf, hello.server_name.encode('ascii'))
+ if hello.alpn_protocols is not None:
+ with push_extension(buf, ExtensionType.ALPN):
+ push_list(buf, 2, push_alpn_protocol, hello.alpn_protocols)
+
for</s>
===========changed ref 6===========
# module: aioquic.tls
def push_client_hello(buf: Buffer, hello: ClientHello):
# offset: 1
<s>
+ push_list(buf, 2, push_alpn_protocol, hello.alpn_protocols)
+
for extension_type, extension_value in hello.other_extensions:
with push_extension(buf, extension_type):
push_bytes(buf, extension_value)
===========changed ref 7===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
hello = ClientHello()
assert pull_uint8(buf) == HandshakeType.CLIENT_HELLO
with pull_block(buf, 3):
assert pull_uint16(buf) == TLS_VERSION_1_2
hello.random = pull_bytes(buf, 32)
session_id_length = pull_uint8(buf)
hello.session_id = pull_bytes(buf, session_id_length)
hello.cipher_suites = pull_list(buf, 2, pull_uint16)
hello.compression_methods = pull_list(buf, 1, pull_uint8)
# extensions
def pull_extension(buf):
extension_type = pull_uint16(buf)
extension_length = pull_uint16(buf)
if extension_type == ExtensionType.KEY_SHARE:
hello.key_share = pull_list(buf, 2, pull_key_share)
elif extension_type == ExtensionType.SUPPORTED_VERSIONS:
hello.supported_versions = pull_list(buf, 1, pull_uint16)
elif extension_type == ExtensionType.SIGNATURE_ALGORITHMS:
hello.signature_algorithms = pull_list(buf, 2, pull_uint16)
elif extension_type == ExtensionType.SUPPORTED_GROUPS:
hello.supported_groups = pull_list(buf, 2, pull_uint16)
elif extension_type == ExtensionType.PSK_KEY_EXCHANGE_MODES:
hello.key_exchange_modes = pull_list(buf, 1, pull_uint8)
elif extension_type == ExtensionType.SERVER_NAME:
with pull_block(buf, 2):
assert pull_uint8(buf) == 0
with pull_block(buf, 2) as length:
hello.server_name = pull_bytes(buf, length).decode('ascii')
+ elif extension_type == ExtensionType.ALPN:
+ hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
</s>
===========changed ref 8===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
<s>ALPN:
+ hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
else:
hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
pull_list(buf, 2, pull_extension)
return hello
|
aioquic.tls/Context._client_send_hello
|
Modified
|
aiortc~aioquic
|
c948dd660c52065ce7b5627f657865b7c0c13733
|
[tls] add support for ALPN extension
|
<8>:<add> alpn_protocols=self.alpn_protocols,
|
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
<0> hello = ClientHello(
<1> random=self.client_random,
<2> session_id=self.session_id,
<3> cipher_suites=self._cipher_suites,
<4> compression_methods=[
<5> CompressionMethod.NULL,
<6> ],
<7>
<8> key_exchange_modes=[
<9> KeyExchangeMode.PSK_DHE_KE,
<10> ],
<11> key_share=[
<12> encode_public_key(self.private_key.public_key()),
<13> ],
<14> server_name=self.server_name,
<15> signature_algorithms=[
<16> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<17> ],
<18> supported_groups=[
<19> Group.SECP256R1,
<20> ],
<21> supported_versions=[
<22> TLS_VERSION_1_3,
<23> ],
<24>
<25> other_extensions=self.handshake_extensions
<26> )
<27>
<28> self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
<29> self.key_schedule.extract(None)
<30>
<31> with self._push_message(output_buf):
<32> push_client_hello(output_buf, hello)
<33>
<34> self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
<35>
|
===========unchanged ref 0===========
at: aioquic.tls
AlertUnexpectedMessage(*args: object)
Epoch()
State()
HandshakeType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HandshakeType(x: Union[str, bytes, bytearray], base: int)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.Context
_client_handle_finished(input_buf, output_buf)
_client_handle_new_session_ticket(input_buf)
_server_handle_hello(input_buf, output_buf)
_server_handle_finished(input_buf)
at: aioquic.tls.Context.__init__
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._set_state
self.state = state
at: aioquic.tls.Context.handle_message
message_type = self._receive_buffer[0]
input_buf = Buffer(data=message)
===========changed ref 0===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
+ self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 1===========
# module: aioquic.tls
+ # ALPN
+
+
+ def pull_alpn_protocol(buf: Buffer) -> str:
+ length = pull_uint8(buf)
+ return pull_bytes(buf, length).decode('ascii')
+
===========changed ref 2===========
# module: aioquic.tls
+ def push_alpn_protocol(buf: Buffer, protocol: str):
+ data = protocol.encode('ascii')
+ push_uint8(buf, len(data))
+ push_bytes(buf, data)
+
===========changed ref 3===========
# module: aioquic.tls
# MESSAGES
@dataclass
class ClientHello:
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
# extensions
+ alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
===========changed ref 4===========
# module: aioquic.tls
class Group(IntEnum):
SECP256R1 = 0x0017
SECP384R1 = 0x0018
SECP521R1 = 0x0019
+ X25519 = 0x001d
===========changed ref 5===========
# module: aioquic.tls
class CipherSuite(IntEnum):
AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
CHACHA20_POLY1305_SHA256 = 0x1303
+ EMPTY_RENEGOTIATION_INFO_SCSV = 0x00ff
===========changed ref 6===========
# module: aioquic.tls
def push_client_hello(buf: Buffer, hello: ClientHello):
push_uint8(buf, HandshakeType.CLIENT_HELLO)
with push_block(buf, 3):
push_uint16(buf, TLS_VERSION_1_2)
push_bytes(buf, hello.random)
with push_block(buf, 1):
push_bytes(buf, hello.session_id)
push_list(buf, 2, push_uint16, hello.cipher_suites)
push_list(buf, 1, push_uint8, hello.compression_methods)
# extensions
with push_block(buf, 2):
with push_extension(buf, ExtensionType.KEY_SHARE):
push_list(buf, 2, push_key_share, hello.key_share)
with push_extension(buf, ExtensionType.SUPPORTED_VERSIONS):
push_list(buf, 1, push_uint16, hello.supported_versions)
with push_extension(buf, ExtensionType.SIGNATURE_ALGORITHMS):
push_list(buf, 2, push_uint16, hello.signature_algorithms)
with push_extension(buf, ExtensionType.SUPPORTED_GROUPS):
push_list(buf, 2, push_uint16, hello.supported_groups)
with push_extension(buf, ExtensionType.PSK_KEY_EXCHANGE_MODES):
push_list(buf, 1, push_uint8, hello.key_exchange_modes)
if hello.server_name is not None:
with push_extension(buf, ExtensionType.SERVER_NAME):
with push_block(buf, 2):
push_uint8(buf, 0)
with push_block(buf, 2):
push_bytes(buf, hello.server_name.encode('ascii'))
+ if hello.alpn_protocols is not None:
+ with push_extension(buf, ExtensionType.ALPN):
+ push_list(buf, 2, push_alpn_protocol, hello.alpn_protocols)
+
for</s>
===========changed ref 7===========
# module: aioquic.tls
def push_client_hello(buf: Buffer, hello: ClientHello):
# offset: 1
<s>
+ push_list(buf, 2, push_alpn_protocol, hello.alpn_protocols)
+
for extension_type, extension_value in hello.other_extensions:
with push_extension(buf, extension_type):
push_bytes(buf, extension_value)
|
tests.test_tls/TlsTest.test_pull_client_hello
|
Modified
|
aiortc~aioquic
|
c948dd660c52065ce7b5627f657865b7c0c13733
|
[tls] add support for ALPN extension
|
<22>:<add> self.assertEqual(hello.alpn_protocols, None)
|
# module: tests.test_tls
class TlsTest(TestCase):
def test_pull_client_hello(self):
<0> buf = Buffer(data=load('tls_client_hello.bin'))
<1> hello = pull_client_hello(buf)
<2> self.assertTrue(buf.eof())
<3>
<4> self.assertEqual(
<5> hello.random,
<6> binascii.unhexlify(
<7> '18b2b23bf3e44b5d52ccfe7aecbc5ff14eadc3d349fabf804d71f165ae76e7d5'))
<8> self.assertEqual(
<9> hello.session_id,
<10> binascii.unhexlify(
<11> '9aee82a2d186c1cb32a329d9dcfe004a1a438ad0485a53c6bfcf55c132a23235'))
<12> self.assertEqual(hello.cipher_suites, [
<13> tls.CipherSuite.AES_256_GCM_SHA384,
<14> tls.CipherSuite.AES_128_GCM_SHA256,
<15> tls.CipherSuite.CHACHA20_POLY1305_SHA256,
<16> ])
<17> self.assertEqual(hello.compression_methods, [
<18> tls.CompressionMethod.NULL,
<19> ])
<20>
<21> # extensions
<22> self.assertEqual(hello.key_exchange_modes, [
<23> tls.KeyExchangeMode.PSK_DHE_KE,
<24> ])
<25> self.assertEqual(hello.key_share, [
<26> (
<27> tls.Group.SECP256R1,
<28> binascii.unhexlify(
<29> '047bfea344467535054263b75def60cffa82405a211b68d1eb8d1d944e67aef8'
<30> '93c7665a5473d032cfaf22a73da28eb4aacae0017ed12557b5791f98a1e84f15'</s>
|
===========below chunk 0===========
# module: tests.test_tls
class TlsTest(TestCase):
def test_pull_client_hello(self):
# offset: 1
)
])
self.assertEqual(hello.server_name, None)
self.assertEqual(hello.signature_algorithms, [
tls.SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
tls.SignatureAlgorithm.ECDSA_SECP256R1_SHA256,
tls.SignatureAlgorithm.RSA_PKCS1_SHA256,
tls.SignatureAlgorithm.RSA_PKCS1_SHA1,
])
self.assertEqual(hello.supported_groups, [
tls.Group.SECP256R1,
])
self.assertEqual(hello.supported_versions, [
tls.TLS_VERSION_1_3,
tls.TLS_VERSION_1_3_DRAFT_28,
tls.TLS_VERSION_1_3_DRAFT_27,
tls.TLS_VERSION_1_3_DRAFT_26,
])
self.assertEqual(hello.other_extensions, [
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
])
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_3 = 0x0304
TLS_VERSION_1_3_DRAFT_28 = 0x7f1c
TLS_VERSION_1_3_DRAFT_27 = 0x7f1b
TLS_VERSION_1_3_DRAFT_26 = 0x7f1a
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Group(x: Union[str, bytes, bytearray], base: int)
Group(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
KeyExchangeMode(x: Union[str, bytes, bytearray], base: int)
KeyExchangeMode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
SignatureAlgorithm(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
pull_client_hello(buf: Buffer)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.ClientHello
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
===========unchanged ref 1===========
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_tls
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
at: tests.utils
load(name)
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertTrue(expr: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.tls
class Group(IntEnum):
SECP256R1 = 0x0017
SECP384R1 = 0x0018
SECP521R1 = 0x0019
+ X25519 = 0x001d
===========changed ref 1===========
# module: aioquic.tls
class CipherSuite(IntEnum):
AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
CHACHA20_POLY1305_SHA256 = 0x1303
+ EMPTY_RENEGOTIATION_INFO_SCSV = 0x00ff
===========changed ref 2===========
# module: aioquic.tls
class SignatureAlgorithm(IntEnum):
+ ECDSA_SECP256R1_SHA256 = 0x0403
+ ECDSA_SECP384R1_SHA384 = 0x0503
+ ECDSA_SECP521R1_SHA512 = 0x0603
+ ED25519 = 0x0807
+ ED448 = 0x0808
+ RSA_PKCS1_SHA1 = 0x0201
+ RSA_PKCS1_SHA256 = 0x0401
+ RSA_PKCS1_SHA384 = 0x0501
+ RSA_PKCS1_SHA512 = 0x0601
+ RSA_PSS_PSS_SHA256 = 0x0809
+ RSA_PSS_PSS_SHA384 = 0x080a
+ RSA_PSS_PSS_SHA512 = 0x080b
RSA_PSS_RSAE_SHA256 = 0x0804
- ECDSA_SECP256R1_SHA256 = 0x0403
- RSA_PKCS1_SHA256 = 0x0401
- RSA_PKCS1_SHA1 = 0x0201
+ RSA_PSS_RSAE_SHA384 = 0x0805
+ RSA_PSS_RSAE_SHA512 = 0x0806
|
tests.test_tls/TlsTest.test_pull_client_hello_with_sni
|
Modified
|
aiortc~aioquic
|
c948dd660c52065ce7b5627f657865b7c0c13733
|
[tls] add support for ALPN extension
|
<22>:<add> self.assertEqual(hello.alpn_protocols, None)
|
# module: tests.test_tls
class TlsTest(TestCase):
def test_pull_client_hello_with_sni(self):
<0> buf = Buffer(data=load('tls_client_hello_with_sni.bin'))
<1> hello = pull_client_hello(buf)
<2> self.assertTrue(buf.eof())
<3>
<4> self.assertEqual(
<5> hello.random,
<6> binascii.unhexlify(
<7> '987d8934140b0a42cc5545071f3f9f7f61963d7b6404eb674c8dbe513604346b'))
<8> self.assertEqual(
<9> hello.session_id,
<10> binascii.unhexlify(
<11> '26b19bdd30dbf751015a3a16e13bd59002dfe420b799d2a5cd5e11b8fa7bcb66'))
<12> self.assertEqual(hello.cipher_suites, [
<13> tls.CipherSuite.AES_256_GCM_SHA384,
<14> tls.CipherSuite.AES_128_GCM_SHA256,
<15> tls.CipherSuite.CHACHA20_POLY1305_SHA256,
<16> ])
<17> self.assertEqual(hello.compression_methods, [
<18> tls.CompressionMethod.NULL,
<19> ])
<20>
<21> # extensions
<22> self.assertEqual(hello.key_exchange_modes, [
<23> tls.KeyExchangeMode.PSK_DHE_KE,
<24> ])
<25> self.assertEqual(hello.key_share, [
<26> (
<27> tls.Group.SECP256R1,
<28> binascii.unhexlify(
<29> '04b62d70f907c814cd65d0f73b8b991f06b70c77153f548410a191d2b19764a2'
<30> 'ecc06065a480efa9e1f10c8da6e737d5bfc04be3f773e20a</s>
|
===========below chunk 0===========
# module: tests.test_tls
class TlsTest(TestCase):
def test_pull_client_hello_with_sni(self):
# offset: 1
'40'),
)
])
self.assertEqual(hello.server_name, 'cloudflare-quic.com')
self.assertEqual(hello.signature_algorithms, [
tls.SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
tls.SignatureAlgorithm.ECDSA_SECP256R1_SHA256,
tls.SignatureAlgorithm.RSA_PKCS1_SHA256,
tls.SignatureAlgorithm.RSA_PKCS1_SHA1,
])
self.assertEqual(hello.supported_groups, [
tls.Group.SECP256R1,
])
self.assertEqual(hello.supported_versions, [
tls.TLS_VERSION_1_3,
tls.TLS_VERSION_1_3_DRAFT_28,
tls.TLS_VERSION_1_3_DRAFT_27,
tls.TLS_VERSION_1_3_DRAFT_26,
])
self.assertEqual(hello.other_extensions, [
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
])
# serialize
buf = Buffer(1000)
push_client_hello(buf, hello)
self.assertEqual(buf.data, load('tls_client_hello_with_sni.bin'))
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_3 = 0x0304
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, bytearray], base: int)
Group(x: Union[str, bytes, bytearray], base: int)
Group(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
KeyExchangeMode(x: Union[str, bytes, bytearray], base: int)
KeyExchangeMode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
SignatureAlgorithm(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
pull_client_hello(buf: Buffer)
at: aioquic.tls.Buffer
eof()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.utils
load(name)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertTrue(expr: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.tls
class Group(IntEnum):
SECP256R1 = 0x0017
SECP384R1 = 0x0018
SECP521R1 = 0x0019
+ X25519 = 0x001d
===========changed ref 1===========
# module: aioquic.tls
class CipherSuite(IntEnum):
AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
CHACHA20_POLY1305_SHA256 = 0x1303
+ EMPTY_RENEGOTIATION_INFO_SCSV = 0x00ff
===========changed ref 2===========
# module: aioquic.tls
class SignatureAlgorithm(IntEnum):
+ ECDSA_SECP256R1_SHA256 = 0x0403
+ ECDSA_SECP384R1_SHA384 = 0x0503
+ ECDSA_SECP521R1_SHA512 = 0x0603
+ ED25519 = 0x0807
+ ED448 = 0x0808
+ RSA_PKCS1_SHA1 = 0x0201
+ RSA_PKCS1_SHA256 = 0x0401
+ RSA_PKCS1_SHA384 = 0x0501
+ RSA_PKCS1_SHA512 = 0x0601
+ RSA_PSS_PSS_SHA256 = 0x0809
+ RSA_PSS_PSS_SHA384 = 0x080a
+ RSA_PSS_PSS_SHA512 = 0x080b
RSA_PSS_RSAE_SHA256 = 0x0804
- ECDSA_SECP256R1_SHA256 = 0x0403
- RSA_PKCS1_SHA256 = 0x0401
- RSA_PKCS1_SHA1 = 0x0201
+ RSA_PSS_RSAE_SHA384 = 0x0805
+ RSA_PSS_RSAE_SHA512 = 0x0806
===========changed ref 3===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
hello = ClientHello()
assert pull_uint8(buf) == HandshakeType.CLIENT_HELLO
with pull_block(buf, 3):
assert pull_uint16(buf) == TLS_VERSION_1_2
hello.random = pull_bytes(buf, 32)
session_id_length = pull_uint8(buf)
hello.session_id = pull_bytes(buf, session_id_length)
hello.cipher_suites = pull_list(buf, 2, pull_uint16)
hello.compression_methods = pull_list(buf, 1, pull_uint8)
# extensions
def pull_extension(buf):
extension_type = pull_uint16(buf)
extension_length = pull_uint16(buf)
if extension_type == ExtensionType.KEY_SHARE:
hello.key_share = pull_list(buf, 2, pull_key_share)
elif extension_type == ExtensionType.SUPPORTED_VERSIONS:
hello.supported_versions = pull_list(buf, 1, pull_uint16)
elif extension_type == ExtensionType.SIGNATURE_ALGORITHMS:
hello.signature_algorithms = pull_list(buf, 2, pull_uint16)
elif extension_type == ExtensionType.SUPPORTED_GROUPS:
hello.supported_groups = pull_list(buf, 2, pull_uint16)
elif extension_type == ExtensionType.PSK_KEY_EXCHANGE_MODES:
hello.key_exchange_modes = pull_list(buf, 1, pull_uint8)
elif extension_type == ExtensionType.SERVER_NAME:
with pull_block(buf, 2):
assert pull_uint8(buf) == 0
with pull_block(buf, 2) as length:
hello.server_name = pull_bytes(buf, length).decode('ascii')
+ elif extension_type == ExtensionType.ALPN:
+ hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
</s>
===========changed ref 4===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
<s>ALPN:
+ hello.alpn_protocols = pull_list(buf, 2, pull_alpn_protocol)
else:
hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
pull_list(buf, 2, pull_extension)
return hello
|
aioquic.crypto/derive_key_iv_hp
|
Modified
|
aiortc~aioquic
|
aff7b1956ba956ee44784323a0bcaa9c4b54ad2e
|
[crypto] add support for CHACHA20_POLY1305_SHA256 cipher suite
|
<1>:<add> if cipher_suite in [
<add> CipherSuite.AES_256_GCM_SHA384,
<del> if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
<2>:<add> CipherSuite.CHACHA20_POLY1305_SHA256,
<add> ]:
|
# module: aioquic.crypto
def derive_key_iv_hp(cipher_suite, secret):
<0> algorithm = cipher_suite_hash(cipher_suite)
<1> if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
<2> key_size = 32
<3> else:
<4> key_size = 16
<5> return (
<6> hkdf_expand_label(algorithm, secret, b'quic key', b'', key_size),
<7> hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
<8> hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
<9> )
<10>
|
===========unchanged ref 0===========
at: aioquic.tls
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
cipher_suite_hash(cipher_suite)
===========changed ref 0===========
# module: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
+ SAMPLE_SIZE = 16
|
aioquic.crypto/CryptoContext.decrypt_packet
|
Modified
|
aiortc~aioquic
|
aff7b1956ba956ee44784323a0bcaa9c4b54ad2e
|
[crypto] add support for CHACHA20_POLY1305_SHA256 cipher suite
|
<4>:<add> sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
<del> sample = packet[sample_offset:sample_offset + 16]
<5>:<del> encryptor = self.hp.encryptor()
<6>:<del> buf = bytearray(31)
<7>:<del> encryptor.update_into(sample, buf)
<8>:<del> mask = buf[:5]
<9>:<add> mask = self.header_protection_mask(sample)
|
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
<0> packet = bytearray(packet)
<1>
<2> # header protection
<3> sample_offset = encrypted_offset + MAX_PN_SIZE
<4> sample = packet[sample_offset:sample_offset + 16]
<5> encryptor = self.hp.encryptor()
<6> buf = bytearray(31)
<7> encryptor.update_into(sample, buf)
<8> mask = buf[:5]
<9>
<10> if is_long_header(packet[0]):
<11> # long header
<12> packet[0] ^= (mask[0] & 0x0f)
<13> else:
<14> # short header
<15> packet[0] ^= (mask[0] & 0x1f)
<16>
<17> pn_length = (packet[0] & 0x03) + 1
<18> for i in range(pn_length):
<19> packet[encrypted_offset + i] ^= mask[1 + i]
<20> pn = packet[encrypted_offset:encrypted_offset + pn_length]
<21> plain_header = bytes(packet[:encrypted_offset + pn_length])
<22>
<23> # payload protection
<24> nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
<25> for i in range(len(self.iv)):
<26> nonce[i] ^= self.iv[i]
<27> payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
<28> plain_header)
<29>
<30> # packet number
<31> packet_number = 0
<32> for i in range(pn_length):
<33> packet_number = (packet_number << 8) | pn[i]
<34>
<35> return plain_header, payload, packet_number
<36>
|
===========unchanged ref 0===========
at: aioquic.crypto
MAX_PN_SIZE = 4
SAMPLE_SIZE = 16
at: aioquic.crypto.CryptoContext
header_protection_mask(self, sample)
header_protection_mask(sample)
teardown()
at: aioquic.crypto.CryptoContext.setup
key, self.iv, self.hp = derive_key_iv_hp(cipher_suite, secret)
self.aead = cipher_suite_aead(cipher_suite, key)
at: aioquic.crypto.CryptoContext.teardown
self.aead = None
self.iv = None
at: aioquic.packet
is_long_header(first_byte)
===========changed ref 0===========
# module: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
+ SAMPLE_SIZE = 16
===========changed ref 1===========
# module: aioquic.crypto
def derive_key_iv_hp(cipher_suite, secret):
algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite in [
+ CipherSuite.AES_256_GCM_SHA384,
- if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ CipherSuite.CHACHA20_POLY1305_SHA256,
+ ]:
key_size = 32
else:
key_size = 16
return (
hkdf_expand_label(algorithm, secret, b'quic key', b'', key_size),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
)
|
aioquic.crypto/CryptoContext.encrypt_packet
|
Modified
|
aiortc~aioquic
|
aff7b1956ba956ee44784323a0bcaa9c4b54ad2e
|
[crypto] add support for CHACHA20_POLY1305_SHA256 cipher suite
|
<12>:<add> sample = protected_payload[sample_offset:sample_offset + SAMPLE_SIZE]
<del> sample = protected_payload[sample_offset:sample_offset + 16]
<13>:<del> encryptor = self.hp.encryptor()
<14>:<del> buf = bytearray(31)
<15>:<del> encryptor.update_into(sample, buf)
<16>:<del> mask = buf[:5]
<17>:<add> mask = self.header_protection_mask(sample)
|
# module: aioquic.crypto
class CryptoContext:
def encrypt_packet(self, plain_header, plain_payload):
<0> pn_length = (plain_header[0] & 0x03) + 1
<1> pn_offset = len(plain_header) - pn_length
<2> pn = plain_header[pn_offset:pn_offset + pn_length]
<3>
<4> # payload protection
<5> nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
<6> for i in range(len(self.iv)):
<7> nonce[i] ^= self.iv[i]
<8> protected_payload = self.aead.encrypt(nonce, plain_payload, plain_header)
<9>
<10> # header protection
<11> sample_offset = MAX_PN_SIZE - pn_length
<12> sample = protected_payload[sample_offset:sample_offset + 16]
<13> encryptor = self.hp.encryptor()
<14> buf = bytearray(31)
<15> encryptor.update_into(sample, buf)
<16> mask = buf[:5]
<17>
<18> packet = bytearray(plain_header + protected_payload)
<19> if is_long_header(packet[0]):
<20> # long header
<21> packet[0] ^= (mask[0] & 0x0f)
<22> else:
<23> # short header
<24> packet[0] ^= (mask[0] & 0x1f)
<25>
<26> for i in range(pn_length):
<27> packet[pn_offset + i] ^= mask[1 + i]
<28>
<29> return packet
<30>
|
===========unchanged ref 0===========
at: aioquic.crypto
MAX_PN_SIZE = 4
SAMPLE_SIZE = 16
at: aioquic.crypto.CryptoContext.setup
key, self.iv, self.hp = derive_key_iv_hp(cipher_suite, secret)
self.aead = cipher_suite_aead(cipher_suite, key)
at: aioquic.crypto.CryptoContext.teardown
self.aead = None
self.iv = None
at: aioquic.packet
is_long_header(first_byte)
===========changed ref 0===========
# module: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
+ SAMPLE_SIZE = 16
===========changed ref 1===========
# module: aioquic.crypto
def derive_key_iv_hp(cipher_suite, secret):
algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite in [
+ CipherSuite.AES_256_GCM_SHA384,
- if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ CipherSuite.CHACHA20_POLY1305_SHA256,
+ ]:
key_size = 32
else:
key_size = 16
return (
hkdf_expand_label(algorithm, secret, b'quic key', b'', key_size),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
)
===========changed ref 2===========
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
packet = bytearray(packet)
# header protection
sample_offset = encrypted_offset + MAX_PN_SIZE
+ sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
- sample = packet[sample_offset:sample_offset + 16]
- encryptor = self.hp.encryptor()
- buf = bytearray(31)
- encryptor.update_into(sample, buf)
- mask = buf[:5]
+ mask = self.header_protection_mask(sample)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
pn_length = (packet[0] & 0x03) + 1
for i in range(pn_length):
packet[encrypted_offset + i] ^= mask[1 + i]
pn = packet[encrypted_offset:encrypted_offset + pn_length]
plain_header = bytes(packet[:encrypted_offset + pn_length])
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
plain_header)
# packet number
packet_number = 0
for i in range(pn_length):
packet_number = (packet_number << 8) | pn[i]
return plain_header, payload, packet_number
|
aioquic.crypto/CryptoContext.setup
|
Modified
|
aiortc~aioquic
|
aff7b1956ba956ee44784323a0bcaa9c4b54ad2e
|
[crypto] add support for CHACHA20_POLY1305_SHA256 cipher suite
|
<0>:<add> assert cipher_suite in [
<add> CipherSuite.AES_128_GCM_SHA256,
<add> CipherSuite.AES_256_GCM_SHA384,
<add> CipherSuite.CHACHA20_POLY1305_SHA256,
<add> ], 'unsupported cipher suite'
<add> key, self.iv, self.hp = derive_key_iv_hp(cipher_suite, secret)
<del> key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
<2>:<add> self.cipher_suite = cipher_suite
<del> self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
|
# module: aioquic.crypto
class CryptoContext:
def setup(self, cipher_suite, secret):
<0> key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
<1> self.aead = cipher_suite_aead(cipher_suite, key)
<2> self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
<3>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoContext.header_protection_mask
encryptor = Cipher(
algorithms.ChaCha20(key=self.hp, nonce=sample),
mode=None,
backend=default_backend()).encryptor()
encryptor = Cipher(
algorithms.AES(self.hp),
mode=modes.ECB(),
backend=default_backend()).encryptor()
===========changed ref 0===========
# module: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
+ SAMPLE_SIZE = 16
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
+ def header_protection_mask(self, sample):
+ if self.cipher_suite == CipherSuite.CHACHA20_POLY1305_SHA256:
+ encryptor = Cipher(
+ algorithms.ChaCha20(key=self.hp, nonce=sample),
+ mode=None,
+ backend=default_backend()).encryptor()
+ buf = bytearray(5)
+ encryptor.update_into(bytes(5), buf)
+ return bytes(buf)
+ else:
+ encryptor = Cipher(
+ algorithms.AES(self.hp),
+ mode=modes.ECB(),
+ backend=default_backend()).encryptor()
+ buf = bytearray(31)
+ encryptor.update_into(sample, buf)
+ return buf[:5]
+
===========changed ref 2===========
# module: aioquic.crypto
def derive_key_iv_hp(cipher_suite, secret):
algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite in [
+ CipherSuite.AES_256_GCM_SHA384,
- if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ CipherSuite.CHACHA20_POLY1305_SHA256,
+ ]:
key_size = 32
else:
key_size = 16
return (
hkdf_expand_label(algorithm, secret, b'quic key', b'', key_size),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
)
===========changed ref 3===========
# module: aioquic.crypto
class CryptoContext:
def encrypt_packet(self, plain_header, plain_payload):
pn_length = (plain_header[0] & 0x03) + 1
pn_offset = len(plain_header) - pn_length
pn = plain_header[pn_offset:pn_offset + pn_length]
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
protected_payload = self.aead.encrypt(nonce, plain_payload, plain_header)
# header protection
sample_offset = MAX_PN_SIZE - pn_length
+ sample = protected_payload[sample_offset:sample_offset + SAMPLE_SIZE]
- sample = protected_payload[sample_offset:sample_offset + 16]
- encryptor = self.hp.encryptor()
- buf = bytearray(31)
- encryptor.update_into(sample, buf)
- mask = buf[:5]
+ mask = self.header_protection_mask(sample)
packet = bytearray(plain_header + protected_payload)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
for i in range(pn_length):
packet[pn_offset + i] ^= mask[1 + i]
return packet
===========changed ref 4===========
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
packet = bytearray(packet)
# header protection
sample_offset = encrypted_offset + MAX_PN_SIZE
+ sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
- sample = packet[sample_offset:sample_offset + 16]
- encryptor = self.hp.encryptor()
- buf = bytearray(31)
- encryptor.update_into(sample, buf)
- mask = buf[:5]
+ mask = self.header_protection_mask(sample)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
pn_length = (packet[0] & 0x03) + 1
for i in range(pn_length):
packet[encrypted_offset + i] ^= mask[1 + i]
pn = packet[encrypted_offset:encrypted_offset + pn_length]
plain_header = bytes(packet[:encrypted_offset + pn_length])
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
plain_header)
# packet number
packet_number = 0
for i in range(pn_length):
packet_number = (packet_number << 8) | pn[i]
return plain_header, payload, packet_number
|
aioquic.crypto/CryptoContext.teardown
|
Modified
|
aiortc~aioquic
|
aff7b1956ba956ee44784323a0bcaa9c4b54ad2e
|
[crypto] add support for CHACHA20_POLY1305_SHA256 cipher suite
|
<1>:<add> self.cipher_suite = None
|
# module: aioquic.crypto
class CryptoContext:
def teardown(self):
<0> self.aead = None
<1> self.hp = None
<2> self.iv = None
<3>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoContext.setup
key, self.iv, self.hp = derive_key_iv_hp(cipher_suite, secret)
at: aioquic.crypto.CryptoContext.teardown
self.hp = None
===========changed ref 0===========
# module: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
+ SAMPLE_SIZE = 16
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, cipher_suite, secret):
+ assert cipher_suite in [
+ CipherSuite.AES_128_GCM_SHA256,
+ CipherSuite.AES_256_GCM_SHA384,
+ CipherSuite.CHACHA20_POLY1305_SHA256,
+ ], 'unsupported cipher suite'
+ key, self.iv, self.hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
self.aead = cipher_suite_aead(cipher_suite, key)
+ self.cipher_suite = cipher_suite
- self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 2===========
# module: aioquic.crypto
class CryptoContext:
+ def header_protection_mask(self, sample):
+ if self.cipher_suite == CipherSuite.CHACHA20_POLY1305_SHA256:
+ encryptor = Cipher(
+ algorithms.ChaCha20(key=self.hp, nonce=sample),
+ mode=None,
+ backend=default_backend()).encryptor()
+ buf = bytearray(5)
+ encryptor.update_into(bytes(5), buf)
+ return bytes(buf)
+ else:
+ encryptor = Cipher(
+ algorithms.AES(self.hp),
+ mode=modes.ECB(),
+ backend=default_backend()).encryptor()
+ buf = bytearray(31)
+ encryptor.update_into(sample, buf)
+ return buf[:5]
+
===========changed ref 3===========
# module: aioquic.crypto
def derive_key_iv_hp(cipher_suite, secret):
algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite in [
+ CipherSuite.AES_256_GCM_SHA384,
- if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ CipherSuite.CHACHA20_POLY1305_SHA256,
+ ]:
key_size = 32
else:
key_size = 16
return (
hkdf_expand_label(algorithm, secret, b'quic key', b'', key_size),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
)
===========changed ref 4===========
# module: aioquic.crypto
class CryptoContext:
def encrypt_packet(self, plain_header, plain_payload):
pn_length = (plain_header[0] & 0x03) + 1
pn_offset = len(plain_header) - pn_length
pn = plain_header[pn_offset:pn_offset + pn_length]
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
protected_payload = self.aead.encrypt(nonce, plain_payload, plain_header)
# header protection
sample_offset = MAX_PN_SIZE - pn_length
+ sample = protected_payload[sample_offset:sample_offset + SAMPLE_SIZE]
- sample = protected_payload[sample_offset:sample_offset + 16]
- encryptor = self.hp.encryptor()
- buf = bytearray(31)
- encryptor.update_into(sample, buf)
- mask = buf[:5]
+ mask = self.header_protection_mask(sample)
packet = bytearray(plain_header + protected_payload)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
for i in range(pn_length):
packet[pn_offset + i] ^= mask[1 + i]
return packet
===========changed ref 5===========
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
packet = bytearray(packet)
# header protection
sample_offset = encrypted_offset + MAX_PN_SIZE
+ sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
- sample = packet[sample_offset:sample_offset + 16]
- encryptor = self.hp.encryptor()
- buf = bytearray(31)
- encryptor.update_into(sample, buf)
- mask = buf[:5]
+ mask = self.header_protection_mask(sample)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
pn_length = (packet[0] & 0x03) + 1
for i in range(pn_length):
packet[encrypted_offset + i] ^= mask[1 + i]
pn = packet[encrypted_offset:encrypted_offset + pn_length]
plain_header = bytes(packet[:encrypted_offset + pn_length])
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
plain_header)
# packet number
packet_number = 0
for i in range(pn_length):
packet_number = (packet_number << 8) | pn[i]
return plain_header, payload, packet_number
|
aioquic.tls/Context.__init__
|
Modified
|
aiortc~aioquic
|
1a6acaf4133f57497177995cf682ab023965b407
|
[tls] offer CHACHA20_POLY1305_SHA256 cipher suite
|
<11>:<add> CipherSuite.CHACHA20_POLY1305_SHA256,
|
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
<0> self.alpn_protocols = None
<1> self.certificate = None
<2> self.certificate_private_key = None
<3> self.handshake_extensions = []
<4> self.is_client = is_client
<5> self.server_name = None
<6> self.update_traffic_key_cb = lambda d, e, s: None
<7>
<8> self._cipher_suites = [
<9> CipherSuite.AES_256_GCM_SHA384,
<10> CipherSuite.AES_128_GCM_SHA256,
<11> ]
<12> self._peer_certificate = None
<13> self._receive_buffer = b''
<14> self._enc_key = None
<15> self._dec_key = None
<16> self.__logger = logger
<17>
<18> if is_client:
<19> self.client_random = os.urandom(32)
<20> self.session_id = os.urandom(32)
<21> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<22> self.state = State.CLIENT_HANDSHAKE_START
<23> else:
<24> self.client_random = None
<25> self.session_id = None
<26> self.private_key = None
<27> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<28>
|
===========unchanged ref 0===========
at: aioquic.tls
State()
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.tls.Context._client_handle_certificate
self._peer_certificate = x509.load_der_x509_certificate(
certificate.certificates[0][0], backend=default_backend())
at: aioquic.tls.Context._client_handle_finished
self._enc_key = next_enc_key
at: aioquic.tls.Context._server_handle_finished
self._dec_key = self._next_dec_key
at: aioquic.tls.Context._server_handle_hello
self.client_random = peer_hello.random
self.session_id = peer_hello.session_id
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._set_state
self.state = state
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
self._dec_key = key
at: aioquic.tls.Context.handle_message
self._receive_buffer += input_data
self._receive_buffer = self._receive_buffer[message_length:]
at: os
urandom(size: int, /) -> bytes
|
aioquic.tls/Context._server_handle_hello
|
Modified
|
aiortc~aioquic
|
1a6acaf4133f57497177995cf682ab023965b407
|
[tls] offer CHACHA20_POLY1305_SHA256 cipher suite
|
<13>:<add> assert cipher_suite is not None, 'no supported cipher suites'
<del> assert cipher_suite is not None
|
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
<0> peer_hello = pull_client_hello(input_buf)
<1>
<2> self.client_random = peer_hello.random
<3> self.server_random = os.urandom(32)
<4> self.session_id = peer_hello.session_id
<5> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<6>
<7> # determine cipher suite
<8> cipher_suite = None
<9> for c in self._cipher_suites:
<10> if c in peer_hello.cipher_suites:
<11> cipher_suite = c
<12> break
<13> assert cipher_suite is not None
<14>
<15> self.key_schedule = KeySchedule(cipher_suite)
<16> self.key_schedule.extract(None)
<17> self.key_schedule.update_hash(input_buf.data)
<18>
<19> peer_public_key = decode_public_key(peer_hello.key_share[0])
<20> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<21>
<22> # send hello
<23> hello = ServerHello(
<24> random=self.server_random,
<25> session_id=self.session_id,
<26> cipher_suite=cipher_suite,
<27> compression_method=CompressionMethod.NULL,
<28>
<29> key_share=encode_public_key(self.private_key.public_key()),
<30> supported_version=TLS_VERSION_1_3,
<31> )
<32> with self._push_message(output_buf):
<33> push_server_hello(output_buf, hello)
<34> self.key_schedule.extract(shared_key)
<35>
<36> self._setup_traffic_protection(Direction.ENCRYPT, Epoch.HANDSHAKE, b's hs traffic')
<37> self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b'c hs traffic')
<38> </s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
# offset: 1
with self._push_message(output_buf):
push_encrypted_extensions(output_buf, EncryptedExtensions(
other_extensions=self.handshake_extensions))
# send certificate
with self._push_message(output_buf):
push_certificate(output_buf, Certificate(
request_context=b'',
certificates=[
(self.certificate.public_bytes(Encoding.DER), b'')
]))
# send certificate verify
algorithm = hashes.SHA256()
signature = self.certificate_private_key.sign(
self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
padding.PSS(
mgf=padding.MGF1(algorithm),
salt_length=algorithm.digest_size
),
algorithm)
with self._push_message(output_buf):
push_certificate_verify(output_buf, CertificateVerify(
algorithm=SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
signature=signature))
# send finished
with self._push_message(output_buf):
push_finished(output_buf, Finished(
verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.ENCRYPT, Epoch.ONE_RTT, b's ap traffic')
self._next_dec_key = self.key_schedule.derive_secret(b'c ap traffic')
self._set_state(State.SERVER_EXPECT_FINISHED)
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_3 = 0x0304
Direction()
Epoch()
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_client_hello(buf: Buffer)
ServerHello(random: bytes=None, session_id: bytes=None, cipher_suite: int=None, compression_method: int=None, key_share: Tuple[int, bytes]=None, supported_version: int=None)
push_server_hello(buf: Buffer, hello: ServerHello)
EncryptedExtensions(other_extensions: List[Tuple[int, bytes]]=field(default_factory=list))
push_encrypted_extensions(buf: Buffer, extensions: EncryptedExtensions)
Certificate(request_context: bytes=b'', certificates: List=field(default_factory=list))
push_certificate(buf: Buffer, certificate: Certificate)
CertificateVerify(algorithm: int=None, signature: bytes=None)
push_certificate_verify(buf: Buffer, verify: CertificateVerify)
Finished(verify_data: bytes=b'')
push_finished(buf: Buffer, finished: Finished)
KeySchedule(cipher_suite)
decode_public_key(key_share)
encode_public_key(public_key)
at: aioquic.tls.Certificate
request_context: bytes = b''
certificates: List = field(default_factory=list)
at: aioquic.tls.CertificateVerify
algorithm: int = None
signature: bytes = None
at: aioquic.tls.ClientHello
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
===========unchanged ref 1===========
compression_methods: List[int] = None
alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: aioquic.tls.Context
_push_message(self, buf: Buffer)
_setup_traffic_protection(direction, epoch, label)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self._enc_key = None
self.client_random = None
self.client_random = os.urandom(32)
self.session_id = None
self.session_id = os.urandom(32)
self.private_key = None
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._client_handle_finished
self._enc_key = next_enc_key
at: aioquic.tls.Context._client_handle_hello
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
at: aioquic.tls.Context._client_send_hello
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
===========unchanged ref 2===========
at: aioquic.tls.Context._server_handle_finished
self._next_dec_key = None
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
at: aioquic.tls.EncryptedExtensions
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: aioquic.tls.Finished
verify_data: bytes = b''
at: aioquic.tls.KeySchedule
certificate_verify_data(context_string)
finished_verify_data(secret)
derive_secret(label)
extract(key_material=None)
update_hash(data)
at: aioquic.tls.KeySchedule.__init__
self.generation = 0
at: aioquic.tls.KeySchedule.extract
self.generation += 1
at: aioquic.tls.KeyScheduleProxy
extract(key_material=None)
update_hash(data)
at: aioquic.tls.ServerHello
random: bytes = None
session_id: bytes = None
cipher_suite: int = None
compression_method: int = None
key_share: Tuple[int, bytes] = None
supported_version: int = None
at: os
urandom(size: int, /) -> bytes
|
tests.test_tls/ContextTest.test_handshake
|
Modified
|
aiortc~aioquic
|
1a6acaf4133f57497177995cf682ab023965b407
|
[tls] offer CHACHA20_POLY1305_SHA256 cipher suite
|
<8>:<add> self.assertEqual(len(server_input), 246)
<del> self.assertEqual(len(server_input), 244)
|
# module: tests.test_tls
class ContextTest(TestCase):
def test_handshake(self):
<0> client = self.create_client()
<1> server = self.create_server()
<2>
<3> # send client hello
<4> client_buf = create_buffers()
<5> client.handle_message(b'', client_buf)
<6> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<7> server_input = merge_buffers(client_buf)
<8> self.assertEqual(len(server_input), 244)
<9> reset_buffers(client_buf)
<10>
<11> # handle client hello
<12> # send server hello, encrypted extensions, certificate, certificate verify, finished
<13> server_buf = create_buffers()
<14> server.handle_message(server_input, server_buf)
<15> self.assertEqual(server.state, State.SERVER_EXPECT_FINISHED)
<16> client_input = merge_buffers(server_buf)
<17> self.assertEqual(len(client_input), 2227)
<18> reset_buffers(server_buf)
<19>
<20> # handle server hello, encrypted extensions, certificate, certificate verify, finished
<21> # send finished
<22> client.handle_message(client_input, client_buf)
<23> self.assertEqual(client.state, State.CLIENT_POST_HANDSHAKE)
<24> server_input = merge_buffers(client_buf)
<25> self.assertEqual(len(server_input), 52)
<26> reset_buffers(client_buf)
<27>
<28> # handle finished
<29> server.handle_message(server_input, server_buf)
<30> self.assertEqual(server.state, State.SERVER_POST_HANDSHAKE)
<31> client_input = merge_buffers(server_buf)
<32> self.assertEqual(len(client_input), 0)
<33>
<34> # check keys match
<35> self.assertEqual(client._dec_key, server._enc_key)
<36> self.assertEqual(client._enc_key, server._dec_key)
<37>
|
===========unchanged ref 0===========
at: aioquic.tls
State()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: aioquic.tls.Context.__init__
self._enc_key = None
self._dec_key = None
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._client_handle_finished
self._enc_key = next_enc_key
at: aioquic.tls.Context._server_handle_finished
self._dec_key = self._next_dec_key
at: aioquic.tls.Context._set_state
self.state = state
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
self._dec_key = key
at: tests.test_tls
create_buffers()
merge_buffers(buffers)
reset_buffers(buffers)
at: tests.test_tls.ContextTest
create_client()
create_server()
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
+ CipherSuite.CHACHA20_POLY1305_SHA256,
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 1===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
peer_hello = pull_client_hello(input_buf)
self.client_random = peer_hello.random
self.server_random = os.urandom(32)
self.session_id = peer_hello.session_id
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
# determine cipher suite
cipher_suite = None
for c in self._cipher_suites:
if c in peer_hello.cipher_suites:
cipher_suite = c
break
+ assert cipher_suite is not None, 'no supported cipher suites'
- assert cipher_suite is not None
self.key_schedule = KeySchedule(cipher_suite)
self.key_schedule.extract(None)
self.key_schedule.update_hash(input_buf.data)
peer_public_key = decode_public_key(peer_hello.key_share[0])
shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
# send hello
hello = ServerHello(
random=self.server_random,
session_id=self.session_id,
cipher_suite=cipher_suite,
compression_method=CompressionMethod.NULL,
key_share=encode_public_key(self.private_key.public_key()),
supported_version=TLS_VERSION_1_3,
)
with self._push_message(output_buf):
push_server_hello(output_buf, hello)
self.key_schedule.extract(shared_key)
self._setup_traffic_protection(Direction.ENCRYPT, Epoch.HANDSHAKE, b's hs traffic')
self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b'c hs traffic')
# send encrypted extensions
with self._push_message(output_buf):
</s>
===========changed ref 2===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
# offset: 1
<s>KE, b'c hs traffic')
# send encrypted extensions
with self._push_message(output_buf):
push_encrypted_extensions(output_buf, EncryptedExtensions(
other_extensions=self.handshake_extensions))
# send certificate
with self._push_message(output_buf):
push_certificate(output_buf, Certificate(
request_context=b'',
certificates=[
(self.certificate.public_bytes(Encoding.DER), b'')
]))
# send certificate verify
algorithm = hashes.SHA256()
signature = self.certificate_private_key.sign(
self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
padding.PSS(
mgf=padding.MGF1(algorithm),
salt_length=algorithm.digest_size
),
algorithm)
with self._push_message(output_buf):
push_certificate_verify(output_buf, CertificateVerify(
algorithm=SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
signature=signature))
# send finished
with self._push_message(output_buf):
push_finished(output_buf, Finished(
verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.ENCRYPT, Epoch.ONE_RTT, b's ap traffic')
self._next_dec_key = self.key_schedule.derive_secret(b'c ap traffic')
self._set_state(State.SERVER_EXPECT_FINISHED)
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
fca22bcff75883008022b667abe2b4a217057b22
|
[connection] add test for draft 20 connection
|
<19>:<add> QuicProtocolVersion.DRAFT_20,
<20>:<add> self.version = QuicProtocolVersion.DRAFT_20
<del> self.version = QuicProtocolVersion.DRAFT_19
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.peer_token = b''
<10> self.private_key = private_key
<11> self.secrets_log_file = secrets_log_file
<12> self.server_name = server_name
<13>
<14> # protocol versions
<15> self.supported_versions = [
<16> QuicProtocolVersion.DRAFT_17,
<17> QuicProtocolVersion.DRAFT_18,
<18> QuicProtocolVersion.DRAFT_19,
<19> ]
<20> self.version = QuicProtocolVersion.DRAFT_19
<21>
<22> self.quic_transport_parameters = QuicTransportParameters(
<23> idle_timeout=600,
<24> initial_max_data=16777216,
<25> initial_max_stream_data_bidi_local=1048576,
<26> initial_max_stream_data_bidi_remote=1048576,
<27> initial_max_stream_data_uni=1048576,
<28> initial_max_streams_bidi=100,
<29> ack_delay_exponent=10,
<30> )
<31>
<32> self.__initialized = False
<33> self.__logger = logger
<34>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
self.peer_token = header.token
self.peer_cid_set = True
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
===========unchanged ref 1===========
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.packet
class QuicProtocolVersion(IntEnum):
NEGOTIATION = 0
DRAFT_17 = 0xff000011
DRAFT_18 = 0xff000012
DRAFT_19 = 0xff000013
+ DRAFT_20 = 0xff000014
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
db003c27a457b4fbf733e40af6f53b2b0f97fd6c
|
[examples] allow passing kwargs to QuicConnection
|
<4>:<add> self.alpn_protocols = alpn_protocols
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
+ alpn_protocols=None, server_name=None):
- server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.certificate = certificate
<5> self.is_client = is_client
<6> self.host_cid = os.urandom(8)
<7> self.peer_cid = os.urandom(8)
<8> self.peer_cid_set = False
<9> self.peer_token = b''
<10> self.private_key = private_key
<11> self.secrets_log_file = secrets_log_file
<12> self.server_name = server_name
<13>
<14> # protocol versions
<15> self.supported_versions = [
<16> QuicProtocolVersion.DRAFT_17,
<17> QuicProtocolVersion.DRAFT_18,
<18> QuicProtocolVersion.DRAFT_19,
<19> QuicProtocolVersion.DRAFT_20,
<20> ]
<21> self.version = QuicProtocolVersion.DRAFT_20
<22>
<23> self.quic_transport_parameters = QuicTransportParameters(
<24> idle_timeout=600,
<25> initial_max_data=16777216,
<26> initial_max_stream_data_bidi_local=1048576,
<27> initial_max_stream_data_bidi_remote=1048576,
<28> initial_max_stream_data_uni=1048576,
<29> initial_max_streams_bidi=100,
<30> ack_delay_exponent=10,
<31> )
<32>
<33> self.__initialized = False
<34> self.__logger = logger
<35>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.version = QuicProtocolVersion(max(common))
self.peer_cid = header.source_cid
self.peer_token = header.token
self.peer_cid_set = True
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
===========unchanged ref 1===========
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
db003c27a457b4fbf733e40af6f53b2b0f97fd6c
|
[examples] allow passing kwargs to QuicConnection
|
<18>:<add> self.version = QuicProtocolVersion(max(common))
<del> self.version = max(common)
<19>:<add> self.__logger.info('Retrying with %s' % self.version)
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
<10> # version negotiation
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> if not common:
<16> self.__logger.error('Could not find a common protocol version')
<17> return
<18> self.version = max(common)
<19> self.connection_made()
<20> return
<21> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
<22> # stateless retry
<23> if (
<24> header.destination_cid == self.host_cid and
<25> header.original_destination_cid == self.peer_cid
<26> ):
<27> self.__logger.info('Performing stateless retry')
<28> self.peer_cid = header.source_cid
<29> self.peer_token = header.token
<30> self.connection_made()
<31> return
<32>
<33> encrypted_off = buf.tell() - start_off
<34> end_off = buf.tell() + header.rest_length
<35> tls.pull_bytes(buf, header.rest_length)
<36>
<37> if not self.is_client and not self.__initialized:
<38> self._initialize(header.destination_cid)
<39>
<40> epoch = get_epoch(header.packet_type)
<41> space = self.spaces[epoch]
<42> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<43> data[start_off:</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
connection_made()
_initialize(self, peer_cid)
_initialize(peer_cid)
_payload_received(epoch, plain)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.__initialized = False
self.__logger = logger
at: aioquic.connection.QuicConnection._initialize
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.__initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
===========unchanged ref 1===========
source_cid: bytes
original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
at: logging.Logger
info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
+ alpn_protocols=None, server_name=None):
- server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
+ self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
|
aioquic.connection/QuicConnection._initialize
|
Modified
|
aiortc~aioquic
|
db003c27a457b4fbf733e40af6f53b2b0f97fd6c
|
[examples] allow passing kwargs to QuicConnection
|
<14>:<add> self.tls.alpn_protocols = self.alpn_protocols
|
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
<0> # transport parameters
<1> if self.version >= QuicProtocolVersion.DRAFT_19:
<2> self.quic_transport_parameters.idle_timeout = 600000
<3> else:
<4> self.quic_transport_parameters.idle_timeout = 600
<5> if self.is_client:
<6> self.quic_transport_parameters.initial_version = self.version
<7> else:
<8> self.quic_transport_parameters.negotiated_version = self.version
<9> self.quic_transport_parameters.supported_versions = self.supported_versions
<10> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<11>
<12> # TLS
<13> self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
<14> self.tls.certificate = self.certificate
<15> self.tls.certificate_private_key = self.private_key
<16> self.tls.handshake_extensions = [
<17> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<18> ]
<19> self.tls.server_name = self.server_name
<20> self.tls.update_traffic_key_cb = self._update_traffic_key
<21>
<22> # packet spaces
<23> self.send_ack = {
<24> tls.Epoch.INITIAL: False,
<25> tls.Epoch.HANDSHAKE: False,
<26> tls.Epoch.ONE_RTT: False,
<27> }
<28> self.send_buffer = {
<29> tls.Epoch.INITIAL: Buffer(capacity=4096),
<30> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<31> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<32> }
<33> self.spaces = {
<34> tls.Epoch.INITIAL: PacketSpace(),
<35> tls.Epoch.HANDSHAKE: PacketSpace(),
<36> tls.Epoch.ONE_RTT: PacketSpace(),
</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# offset: 1
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
is_client=self.is_client)
self.__initialized = True
self.packet_number = 0
===========unchanged ref 0===========
at: aioquic.connection
PacketSpace()
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_serialize_parameters()
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.__init__
self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.private_key = private_key
self.server_name = server_name
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__logger = logger
at: aioquic.connection.QuicConnection.datagram_received
self.version = QuicProtocolVersion(max(common))
at: aioquic.crypto.CryptoPair
setup_initial(cid, is_client)
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
===========unchanged ref 1===========
idle_timeout: int = None
stateless_reset_token: bytes = None
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls
Epoch()
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
Context(is_client, logger=None)
at: aioquic.tls.Context.__init__
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
+ alpn_protocols=None, server_name=None):
- server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
+ self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error('Could not find a common protocol version')
return
+ self.version = QuicProtocolVersion(max(common))
- self.version = max(common)
+ self.__logger.info('Retrying with %s' % self.version)
self.connection_made()
return
elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
# stateless retry
if (
header.destination_cid == self.host_cid and
header.original_destination_cid == self.peer_cid
):
self.__logger.info('Performing stateless retry')
self.peer_cid = header.source_cid
self.peer_token = header.token
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
<s>payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
|
examples.cli/QuicProtocol.__init__
|
Modified
|
aiortc~aioquic
|
db003c27a457b4fbf733e40af6f53b2b0f97fd6c
|
[examples] allow passing kwargs to QuicConnection
|
<0>:<del> self._connection = QuicConnection(secrets_log_file=secrets_log_file,
<1>:<del> server_name=server_name)
<2>:<add> self._connection = QuicConnection(**kwargs)
|
# module: examples.cli
class QuicProtocol(asyncio.DatagramProtocol):
+ def __init__(self, **kwargs):
- def __init__(self, secrets_log_file, server_name):
<0> self._connection = QuicConnection(secrets_log_file=secrets_log_file,
<1> server_name=server_name)
<2> self._transport = None
<3>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None, alpn_protocols=None, server_name=None)
at: examples.cli.QuicProtocol.connection_made
self._transport = transport
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
+ alpn_protocols=None, server_name=None):
- server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
+ self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# transport parameters
if self.version >= QuicProtocolVersion.DRAFT_19:
self.quic_transport_parameters.idle_timeout = 600000
else:
self.quic_transport_parameters.idle_timeout = 600
if self.is_client:
self.quic_transport_parameters.initial_version = self.version
else:
self.quic_transport_parameters.negotiated_version = self.version
self.quic_transport_parameters.supported_versions = self.supported_versions
self.quic_transport_parameters.stateless_reset_token = bytes(16)
# TLS
self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
+ self.tls.alpn_protocols = self.alpn_protocols
self.tls.certificate = self.certificate
self.tls.certificate_private_key = self.private_key
self.tls.handshake_extensions = [
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
]
self.tls.server_name = self.server_name
self.tls.update_traffic_key_cb = self._update_traffic_key
# packet spaces
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: Quic</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# offset: 1
<s>Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
is_client=self.is_client)
self.__initialized = True
self.packet_number = 0
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error('Could not find a common protocol version')
return
+ self.version = QuicProtocolVersion(max(common))
- self.version = max(common)
+ self.__logger.info('Retrying with %s' % self.version)
self.connection_made()
return
elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
# stateless retry
if (
header.destination_cid == self.host_cid and
header.original_destination_cid == self.peer_cid
):
self.__logger.info('Performing stateless retry')
self.peer_cid = header.source_cid
self.peer_token = header.token
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)</s>
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
<s>payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
|
examples.cli/run
|
Modified
|
aiortc~aioquic
|
db003c27a457b4fbf733e40af6f53b2b0f97fd6c
|
[examples] allow passing kwargs to QuicConnection
|
<3>:<del> server_name = None
<5>:<add> kwargs['server_name'] = host
<del> server_name = host
<8>:<add> lambda: QuicProtocol(**kwargs),
<del> lambda: QuicProtocol(secrets_log_file=secrets_log_file, server_name=server_name),
|
# module: examples.cli
+ def run(host, port, **kwargs):
- def run(host, port, secrets_log_file):
<0> # if host is not an IP address, pass it to enable SNI
<1> try:
<2> ipaddress.ip_address(host)
<3> server_name = None
<4> except ValueError:
<5> server_name = host
<6>
<7> _, protocol = await loop.create_datagram_endpoint(
<8> lambda: QuicProtocol(secrets_log_file=secrets_log_file, server_name=server_name),
<9> remote_addr=(host, port))
<10>
<11> stream = protocol._connection.create_stream()
<12> stream.push_data(b'GET /\r\n')
<13>
<14> await asyncio.sleep(5)
<15>
<16> print(stream.pull_data())
<17>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: asyncio.tasks
sleep(delay: float, result: _T=..., *, loop: Optional[AbstractEventLoop]=...) -> Future[_T]
at: examples.cli
QuicProtocol(*, is_client=True, certificate=None, private_key=None, alpn_protocols=None, server_name=None)
loop = asyncio.get_event_loop()
at: ipaddress
ip_address(address: object) -> Any
===========changed ref 0===========
# module: examples.cli
class QuicProtocol(asyncio.DatagramProtocol):
+ def __init__(self, **kwargs):
- def __init__(self, secrets_log_file, server_name):
- self._connection = QuicConnection(secrets_log_file=secrets_log_file,
- server_name=server_name)
+ self._connection = QuicConnection(**kwargs)
self._transport = None
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
+ alpn_protocols=None, server_name=None):
- server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
+ self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# transport parameters
if self.version >= QuicProtocolVersion.DRAFT_19:
self.quic_transport_parameters.idle_timeout = 600000
else:
self.quic_transport_parameters.idle_timeout = 600
if self.is_client:
self.quic_transport_parameters.initial_version = self.version
else:
self.quic_transport_parameters.negotiated_version = self.version
self.quic_transport_parameters.supported_versions = self.supported_versions
self.quic_transport_parameters.stateless_reset_token = bytes(16)
# TLS
self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
+ self.tls.alpn_protocols = self.alpn_protocols
self.tls.certificate = self.certificate
self.tls.certificate_private_key = self.private_key
self.tls.handshake_extensions = [
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
]
self.tls.server_name = self.server_name
self.tls.update_traffic_key_cb = self._update_traffic_key
# packet spaces
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: Quic</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# offset: 1
<s>Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
is_client=self.is_client)
self.__initialized = True
self.packet_number = 0
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error('Could not find a common protocol version')
return
+ self.version = QuicProtocolVersion(max(common))
- self.version = max(common)
+ self.__logger.info('Retrying with %s' % self.version)
self.connection_made()
return
elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
# stateless retry
if (
header.destination_cid == self.host_cid and
header.original_destination_cid == self.peer_cid
):
self.__logger.info('Performing stateless retry')
self.peer_cid = header.source_cid
self.peer_token = header.token
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off)</s>
|
aioquic.tls/Context.__init__
|
Modified
|
aiortc~aioquic
|
18a9b6840b240e5e7dd3f971129e47d4dcd9e43b
|
[tls] negotiate signature algorithm
|
<13>:<add> self._signature_algorithms = [
<add> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<add> ]
<add>
|
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
<0> self.alpn_protocols = None
<1> self.certificate = None
<2> self.certificate_private_key = None
<3> self.handshake_extensions = []
<4> self.is_client = is_client
<5> self.server_name = None
<6> self.update_traffic_key_cb = lambda d, e, s: None
<7>
<8> self._cipher_suites = [
<9> CipherSuite.AES_256_GCM_SHA384,
<10> CipherSuite.AES_128_GCM_SHA256,
<11> CipherSuite.CHACHA20_POLY1305_SHA256,
<12> ]
<13> self._peer_certificate = None
<14> self._receive_buffer = b''
<15> self._enc_key = None
<16> self._dec_key = None
<17> self.__logger = logger
<18>
<19> if is_client:
<20> self.client_random = os.urandom(32)
<21> self.session_id = os.urandom(32)
<22> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<23> self.state = State.CLIENT_HANDSHAKE_START
<24> else:
<25> self.client_random = None
<26> self.session_id = None
<27> self.private_key = None
<28> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<29>
|
===========unchanged ref 0===========
at: aioquic.tls
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CURVE_TO_GROUP = dict((v, k) for k, v in GROUP_TO_CURVE.items())
===========changed ref 0===========
# module: aioquic.tls
CIPHER_SUITES = {
CipherSuite.AES_128_GCM_SHA256: (aead.AESGCM, hashes.SHA256),
CipherSuite.AES_256_GCM_SHA384: (aead.AESGCM, hashes.SHA384),
CipherSuite.CHACHA20_POLY1305_SHA256: (aead.ChaCha20Poly1305, hashes.SHA256),
+ }
+
+ SIGNATURE_ALGORITHMS = {
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256: hashes.SHA256,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA384: hashes.SHA384,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA512: hashes.SHA512,
}
GROUP_TO_CURVE = {
Group.SECP256R1: ec.SECP256R1,
Group.SECP384R1: ec.SECP384R1,
Group.SECP521R1: ec.SECP521R1,
}
CURVE_TO_GROUP = dict((v, k) for k, v in GROUP_TO_CURVE.items())
===========changed ref 1===========
# module: aioquic.tls
+ class AlertHandshakeFailure(Exception):
+ pass
+
|
aioquic.tls/Context._client_send_hello
|
Modified
|
aiortc~aioquic
|
18a9b6840b240e5e7dd3f971129e47d4dcd9e43b
|
[tls] negotiate signature algorithm
|
<16>:<del> signature_algorithms=[
<17>:<del> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<18>:<del> ],
<19>:<add> signature_algorithms=self._signature_algorithms,
|
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
<0> hello = ClientHello(
<1> random=self.client_random,
<2> session_id=self.session_id,
<3> cipher_suites=self._cipher_suites,
<4> compression_methods=[
<5> CompressionMethod.NULL,
<6> ],
<7>
<8> alpn_protocols=self.alpn_protocols,
<9> key_exchange_modes=[
<10> KeyExchangeMode.PSK_DHE_KE,
<11> ],
<12> key_share=[
<13> encode_public_key(self.private_key.public_key()),
<14> ],
<15> server_name=self.server_name,
<16> signature_algorithms=[
<17> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<18> ],
<19> supported_groups=[
<20> Group.SECP256R1,
<21> ],
<22> supported_versions=[
<23> TLS_VERSION_1_3,
<24> ],
<25>
<26> other_extensions=self.handshake_extensions
<27> )
<28>
<29> self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
<30> self.key_schedule.extract(None)
<31>
<32> with self._push_message(output_buf):
<33> push_client_hello(output_buf, hello)
<34>
<35> self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
<36>
|
===========unchanged ref 0===========
at: aioquic.tls
AlertUnexpectedMessage(*args: object)
Epoch()
State()
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, bytearray], base: int)
HandshakeType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
HandshakeType(x: Union[str, bytes, bytearray], base: int)
KeyExchangeMode(x: Union[str, bytes, bytearray], base: int)
KeyExchangeMode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=None, alpn_protocols: List[str]=None, key_exchange_modes: List[int]=None, key_share: List[Tuple[int, bytes]]=None, server_name: str=None, signature_algorithms: List[int]=None, supported_groups: List[int]=None, supported_versions: List[int]=None, other_extensions: List[Tuple[int, bytes]]=field(default_factory=list))
encode_public_key(public_key)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.ClientHello
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
===========unchanged ref 1===========
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: aioquic.tls.Context
_server_handle_hello(self, input_buf, output_buf)
_server_handle_hello(input_buf, output_buf)
_server_handle_finished(input_buf)
at: aioquic.tls.Context.__init__
self.alpn_protocols = None
self.server_name = None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self.client_random = None
self.client_random = os.urandom(32)
self.session_id = None
self.session_id = os.urandom(32)
self.private_key = None
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._server_handle_hello
self.client_random = peer_hello.random
self.session_id = peer_hello.session_id
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._set_state
self.state = state
at: aioquic.tls.Context.handle_message
message_type = self._receive_buffer[0]
input_buf = Buffer(data=message)
===========changed ref 0===========
# module: aioquic.tls
+ def negotiate(supported, offered):
+ for c in supported:
+ if c in offered:
+ return c
+
===========changed ref 1===========
# module: aioquic.tls
CIPHER_SUITES = {
CipherSuite.AES_128_GCM_SHA256: (aead.AESGCM, hashes.SHA256),
CipherSuite.AES_256_GCM_SHA384: (aead.AESGCM, hashes.SHA384),
CipherSuite.CHACHA20_POLY1305_SHA256: (aead.ChaCha20Poly1305, hashes.SHA256),
+ }
+
+ SIGNATURE_ALGORITHMS = {
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256: hashes.SHA256,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA384: hashes.SHA384,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA512: hashes.SHA512,
}
GROUP_TO_CURVE = {
Group.SECP256R1: ec.SECP256R1,
Group.SECP384R1: ec.SECP384R1,
Group.SECP521R1: ec.SECP521R1,
}
CURVE_TO_GROUP = dict((v, k) for k, v in GROUP_TO_CURVE.items())
===========changed ref 2===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._signature_algorithms = [
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 3===========
# module: aioquic.tls
+ class AlertHandshakeFailure(Exception):
+ pass
+
|
aioquic.tls/Context._client_handle_certificate_verify
|
Modified
|
aiortc~aioquic
|
18a9b6840b240e5e7dd3f971129e47d4dcd9e43b
|
[tls] negotiate signature algorithm
|
<3>:<del> assert verify.algorithm == SignatureAlgorithm.RSA_PSS_RSAE_SHA256
<4>:<del> algorithm = hashes.SHA256()
<5>:<add> algorithm = SIGNATURE_ALGORITHMS[verify.algorithm]()
|
# module: aioquic.tls
class Context:
def _client_handle_certificate_verify(self, input_buf):
<0> verify = pull_certificate_verify(input_buf)
<1>
<2> # check signature
<3> assert verify.algorithm == SignatureAlgorithm.RSA_PSS_RSAE_SHA256
<4> algorithm = hashes.SHA256()
<5> self._peer_certificate.public_key().verify(
<6> verify.signature,
<7> self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
<8> padding.PSS(
<9> mgf=padding.MGF1(algorithm),
<10> salt_length=algorithm.digest_size
<11> ),
<12> algorithm)
<13>
<14> self.key_schedule.update_hash(input_buf.data)
<15>
<16> self._set_state(State.CLIENT_EXPECT_FINISHED)
<17>
|
===========unchanged ref 0===========
at: aioquic.tls
Direction()
Epoch()
State()
pull_encrypted_extensions(buf: Buffer) -> EncryptedExtensions
pull_certificate(buf: Buffer) -> Certificate
at: aioquic.tls.Certificate
request_context: bytes = b''
certificates: List = field(default_factory=list)
at: aioquic.tls.Context
_setup_traffic_protection(direction, epoch, label)
_set_state(state)
at: aioquic.tls.Context.__init__
self._peer_certificate = None
at: aioquic.tls.Context._client_handle_hello
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
at: aioquic.tls.Context._client_send_hello
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
at: aioquic.tls.Context._server_handle_hello
self.key_schedule = KeySchedule(cipher_suite)
at: aioquic.tls.KeySchedule
update_hash(data)
at: aioquic.tls.KeyScheduleProxy
update_hash(data)
===========changed ref 0===========
# module: aioquic.tls
+ def negotiate(supported, offered):
+ for c in supported:
+ if c in offered:
+ return c
+
===========changed ref 1===========
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=self._cipher_suites,
compression_methods=[
CompressionMethod.NULL,
],
alpn_protocols=self.alpn_protocols,
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
server_name=self.server_name,
- signature_algorithms=[
- SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
- ],
+ signature_algorithms=self._signature_algorithms,
supported_groups=[
Group.SECP256R1,
],
supported_versions=[
TLS_VERSION_1_3,
],
other_extensions=self.handshake_extensions
)
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
self.key_schedule.extract(None)
with self._push_message(output_buf):
push_client_hello(output_buf, hello)
self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
===========changed ref 2===========
# module: aioquic.tls
CIPHER_SUITES = {
CipherSuite.AES_128_GCM_SHA256: (aead.AESGCM, hashes.SHA256),
CipherSuite.AES_256_GCM_SHA384: (aead.AESGCM, hashes.SHA384),
CipherSuite.CHACHA20_POLY1305_SHA256: (aead.ChaCha20Poly1305, hashes.SHA256),
+ }
+
+ SIGNATURE_ALGORITHMS = {
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256: hashes.SHA256,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA384: hashes.SHA384,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA512: hashes.SHA512,
}
GROUP_TO_CURVE = {
Group.SECP256R1: ec.SECP256R1,
Group.SECP384R1: ec.SECP384R1,
Group.SECP521R1: ec.SECP521R1,
}
CURVE_TO_GROUP = dict((v, k) for k, v in GROUP_TO_CURVE.items())
===========changed ref 3===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._signature_algorithms = [
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 4===========
# module: aioquic.tls
+ class AlertHandshakeFailure(Exception):
+ pass
+
|
aioquic.tls/Context._server_handle_hello
|
Modified
|
aiortc~aioquic
|
18a9b6840b240e5e7dd3f971129e47d4dcd9e43b
|
[tls] negotiate signature algorithm
|
<1>:<add>
<add> # negotiate cipher suite
<add> cipher_suite = negotiate(self._cipher_suites, peer_hello.cipher_suites)
<add> if cipher_suite is None:
<add> raise AlertHandshakeFailure('No supported cipher suites')
<add>
<add> # negotiate signature algorithm
<add> signature_algorithm = negotiate(self._signature_algorithms, peer_hello.signature_algorithms)
<add> if signature_algorithm is None:
<add> raise AlertHandshakeFailure('No supported signature algorithms')
<6>:<del>
<7>:<del> # determine cipher suite
<8>:<del> cipher_suite = None
<9>:<del> for c in self._cipher_suites:
<10>:<del> if c in peer_hello.cipher_suites:
<11>:<del> cipher_suite = c
<12>:<del> break
<13>:<del> assert cipher_suite is not None, 'no supported cipher suites'
|
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
<0> peer_hello = pull_client_hello(input_buf)
<1>
<2> self.client_random = peer_hello.random
<3> self.server_random = os.urandom(32)
<4> self.session_id = peer_hello.session_id
<5> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<6>
<7> # determine cipher suite
<8> cipher_suite = None
<9> for c in self._cipher_suites:
<10> if c in peer_hello.cipher_suites:
<11> cipher_suite = c
<12> break
<13> assert cipher_suite is not None, 'no supported cipher suites'
<14>
<15> self.key_schedule = KeySchedule(cipher_suite)
<16> self.key_schedule.extract(None)
<17> self.key_schedule.update_hash(input_buf.data)
<18>
<19> peer_public_key = decode_public_key(peer_hello.key_share[0])
<20> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<21>
<22> # send hello
<23> hello = ServerHello(
<24> random=self.server_random,
<25> session_id=self.session_id,
<26> cipher_suite=cipher_suite,
<27> compression_method=CompressionMethod.NULL,
<28>
<29> key_share=encode_public_key(self.private_key.public_key()),
<30> supported_version=TLS_VERSION_1_3,
<31> )
<32> with self._push_message(output_buf):
<33> push_server_hello(output_buf, hello)
<34> self.key_schedule.extract(shared_key)
<35>
<36> self._setup_traffic_protection(Direction.ENCRYPT, Epoch.HANDSHAKE, b's hs traffic')
<37> self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b</s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
# offset: 1
# send encrypted extensions
with self._push_message(output_buf):
push_encrypted_extensions(output_buf, EncryptedExtensions(
other_extensions=self.handshake_extensions))
# send certificate
with self._push_message(output_buf):
push_certificate(output_buf, Certificate(
request_context=b'',
certificates=[
(self.certificate.public_bytes(Encoding.DER), b'')
]))
# send certificate verify
algorithm = hashes.SHA256()
signature = self.certificate_private_key.sign(
self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
padding.PSS(
mgf=padding.MGF1(algorithm),
salt_length=algorithm.digest_size
),
algorithm)
with self._push_message(output_buf):
push_certificate_verify(output_buf, CertificateVerify(
algorithm=SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
signature=signature))
# send finished
with self._push_message(output_buf):
push_finished(output_buf, Finished(
verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.ENCRYPT, Epoch.ONE_RTT, b's ap traffic')
self._next_dec_key = self.key_schedule.derive_secret(b'c ap traffic')
self._set_state(State.SERVER_EXPECT_FINISHED)
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_3 = 0x0304
AlertHandshakeFailure(*args: object)
Direction()
Epoch()
State()
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, bytearray], base: int)
pull_client_hello(buf: Buffer)
ServerHello(random: bytes=None, session_id: bytes=None, cipher_suite: int=None, compression_method: int=None, key_share: Tuple[int, bytes]=None, supported_version: int=None)
push_server_hello(buf: Buffer, hello: ServerHello)
pull_new_session_ticket(buf: Buffer) -> NewSessionTicket
EncryptedExtensions(other_extensions: List[Tuple[int, bytes]]=field(default_factory=list))
push_encrypted_extensions(buf: Buffer, extensions: EncryptedExtensions)
Certificate(request_context: bytes=b'', certificates: List=field(default_factory=list))
push_certificate(buf: Buffer, certificate: Certificate)
Finished(verify_data: bytes=b'')
push_finished(buf: Buffer, finished: Finished)
KeySchedule(cipher_suite)
SIGNATURE_ALGORITHMS = {
SignatureAlgorithm.RSA_PSS_RSAE_SHA256: hashes.SHA256,
SignatureAlgorithm.RSA_PSS_RSAE_SHA384: hashes.SHA384,
SignatureAlgorithm.RSA_PSS_RSAE_SHA512: hashes.SHA512,
}
decode_public_key(key_share)
encode_public_key(public_key)
negotiate(supported, offered)
at: aioquic.tls.Context
_push_message(buf: Buffer)
_setup_traffic_protection(direction, epoch, label)
_set_state(state)
at: aioquic.tls.Context.__init__
self.certificate = None
===========unchanged ref 1===========
self.certificate_private_key = None
self.handshake_extensions = []
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
]
self._enc_key = None
self.client_random = None
self.client_random = os.urandom(32)
self.session_id = None
self.session_id = os.urandom(32)
self.private_key = None
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._client_handle_hello
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
at: aioquic.tls.Context._client_send_hello
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
at: aioquic.tls.EncryptedExtensions
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: aioquic.tls.Finished
verify_data: bytes = b''
at: aioquic.tls.KeySchedule
certificate_verify_data(context_string)
finished_verify_data(secret)
derive_secret(label)
extract(key_material=None)
update_hash(data)
at: aioquic.tls.KeyScheduleProxy
extract(key_material=None)
update_hash(data)
at: aioquic.tls.ServerHello
random: bytes = None
===========unchanged ref 2===========
session_id: bytes = None
cipher_suite: int = None
compression_method: int = None
key_share: Tuple[int, bytes] = None
supported_version: int = None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
+ def negotiate(supported, offered):
+ for c in supported:
+ if c in offered:
+ return c
+
===========changed ref 1===========
# module: aioquic.tls
+ class AlertHandshakeFailure(Exception):
+ pass
+
===========changed ref 2===========
# module: aioquic.tls
class Context:
def _client_handle_certificate_verify(self, input_buf):
verify = pull_certificate_verify(input_buf)
# check signature
- assert verify.algorithm == SignatureAlgorithm.RSA_PSS_RSAE_SHA256
- algorithm = hashes.SHA256()
+ algorithm = SIGNATURE_ALGORITHMS[verify.algorithm]()
self._peer_certificate.public_key().verify(
verify.signature,
self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
padding.PSS(
mgf=padding.MGF1(algorithm),
salt_length=algorithm.digest_size
),
algorithm)
self.key_schedule.update_hash(input_buf.data)
self._set_state(State.CLIENT_EXPECT_FINISHED)
|
tests.test_tls/ContextTest.test_server_unexpected_message
|
Modified
|
aiortc~aioquic
|
18a9b6840b240e5e7dd3f971129e47d4dcd9e43b
|
[tls] negotiate signature algorithm
|
<0>:<add> server = self.create_server()
<del> server = self.create_client()
|
# module: tests.test_tls
class ContextTest(TestCase):
def test_server_unexpected_message(self):
<0> server = self.create_client()
<1>
<2> server.state = State.SERVER_EXPECT_CLIENT_HELLO
<3> with self.assertRaises(tls.AlertUnexpectedMessage):
<4> server.handle_message(b'\x00\x00\x00\x00', create_buffers())
<5>
<6> server.state = State.SERVER_EXPECT_FINISHED
<7> with self.assertRaises(tls.AlertUnexpectedMessage):
<8> server.handle_message(b'\x00\x00\x00\x00', create_buffers())
<9>
<10> server.state = State.SERVER_POST_HANDSHAKE
<11> with self.assertRaises(tls.AlertUnexpectedMessage):
<12> server.handle_message(b'\x00\x00\x00\x00', create_buffers())
<13>
|
===========unchanged ref 0===========
at: aioquic.tls
AlertUnexpectedMessage(*args: object)
State()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: aioquic.tls.Context.__init__
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._set_state
self.state = state
at: tests.test_tls
create_buffers()
at: tests.test_tls.ContextTest
create_server()
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]
assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.tls
+ class AlertHandshakeFailure(Exception):
+ pass
+
===========changed ref 1===========
# module: aioquic.tls
+ def negotiate(supported, offered):
+ for c in supported:
+ if c in offered:
+ return c
+
===========changed ref 2===========
# module: aioquic.tls
class Context:
def _client_handle_certificate_verify(self, input_buf):
verify = pull_certificate_verify(input_buf)
# check signature
- assert verify.algorithm == SignatureAlgorithm.RSA_PSS_RSAE_SHA256
- algorithm = hashes.SHA256()
+ algorithm = SIGNATURE_ALGORITHMS[verify.algorithm]()
self._peer_certificate.public_key().verify(
verify.signature,
self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
padding.PSS(
mgf=padding.MGF1(algorithm),
salt_length=algorithm.digest_size
),
algorithm)
self.key_schedule.update_hash(input_buf.data)
self._set_state(State.CLIENT_EXPECT_FINISHED)
===========changed ref 3===========
# module: aioquic.tls
CIPHER_SUITES = {
CipherSuite.AES_128_GCM_SHA256: (aead.AESGCM, hashes.SHA256),
CipherSuite.AES_256_GCM_SHA384: (aead.AESGCM, hashes.SHA384),
CipherSuite.CHACHA20_POLY1305_SHA256: (aead.ChaCha20Poly1305, hashes.SHA256),
+ }
+
+ SIGNATURE_ALGORITHMS = {
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256: hashes.SHA256,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA384: hashes.SHA384,
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA512: hashes.SHA512,
}
GROUP_TO_CURVE = {
Group.SECP256R1: ec.SECP256R1,
Group.SECP384R1: ec.SECP384R1,
Group.SECP521R1: ec.SECP521R1,
}
CURVE_TO_GROUP = dict((v, k) for k, v in GROUP_TO_CURVE.items())
===========changed ref 4===========
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=self._cipher_suites,
compression_methods=[
CompressionMethod.NULL,
],
alpn_protocols=self.alpn_protocols,
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
server_name=self.server_name,
- signature_algorithms=[
- SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
- ],
+ signature_algorithms=self._signature_algorithms,
supported_groups=[
Group.SECP256R1,
],
supported_versions=[
TLS_VERSION_1_3,
],
other_extensions=self.handshake_extensions
)
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
self.key_schedule.extract(None)
with self._push_message(output_buf):
push_client_hello(output_buf, hello)
self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
===========changed ref 5===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._signature_algorithms = [
+ SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
|
examples.cli/run
|
Modified
|
aiortc~aioquic
|
30b74f148de8593a048ea6dc0e692036c5c14569
|
[examples] change timings
|
<10>:<add> await asyncio.sleep(2)
<add>
<12>:<add> protocol._send_pending()
<13>:<add> await asyncio.sleep(1)
<del> await asyncio.sleep(5)
|
# module: examples.cli
def run(host, port, **kwargs):
<0> # if host is not an IP address, pass it to enable SNI
<1> try:
<2> ipaddress.ip_address(host)
<3> except ValueError:
<4> kwargs['server_name'] = host
<5>
<6> _, protocol = await loop.create_datagram_endpoint(
<7> lambda: QuicProtocol(**kwargs),
<8> remote_addr=(host, port))
<9>
<10> stream = protocol._connection.create_stream()
<11> stream.push_data(b'GET /\r\n')
<12>
<13> await asyncio.sleep(5)
<14>
<15> print(stream.pull_data())
<16>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: asyncio.tasks
sleep(delay: float, result: _T=..., *, loop: Optional[AbstractEventLoop]=...) -> Future[_T]
at: examples.cli
QuicProtocol(*, is_client=True, certificate=None, private_key=None, alpn_protocols=None, server_name=None)
loop = asyncio.get_event_loop()
at: ipaddress
ip_address(address: object) -> Any
|
aioquic.tls/Context.__init__
|
Modified
|
aiortc~aioquic
|
637e0efb4f53429885cd0ca76a887e90bc6a9223
|
[tls] add more checks on parameters
|
<13>:<add> self._compression_methods = [
<add> CompressionMethod.NULL,
<add> ]
<15>:<add> ]
<add> self._supported_versions = [
<add> TLS_VERSION_1_3
|
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
<0> self.alpn_protocols = None
<1> self.certificate = None
<2> self.certificate_private_key = None
<3> self.handshake_extensions = []
<4> self.is_client = is_client
<5> self.server_name = None
<6> self.update_traffic_key_cb = lambda d, e, s: None
<7>
<8> self._cipher_suites = [
<9> CipherSuite.AES_256_GCM_SHA384,
<10> CipherSuite.AES_128_GCM_SHA256,
<11> CipherSuite.CHACHA20_POLY1305_SHA256,
<12> ]
<13> self._signature_algorithms = [
<14> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<15> ]
<16>
<17> self._peer_certificate = None
<18> self._receive_buffer = b''
<19> self._enc_key = None
<20> self._dec_key = None
<21> self.__logger = logger
<22>
<23> if is_client:
<24> self.client_random = os.urandom(32)
<25> self.session_id = os.urandom(32)
<26> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<27> self.state = State.CLIENT_HANDSHAKE_START
<28> else:
<29> self.client_random = None
<30> self.session_id = None
<31> self.private_key = None
<32> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<33>
|
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_3 = 0x0304
AlertHandshakeFailure(*args: object)
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.tls.Context._client_handle_certificate
self._peer_certificate = x509.load_der_x509_certificate(
certificate.certificates[0][0], backend=default_backend())
at: aioquic.tls.Context._client_handle_finished
self._enc_key = next_enc_key
at: aioquic.tls.Context._server_handle_finished
self._dec_key = self._next_dec_key
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
self._dec_key = key
at: aioquic.tls.Context.handle_message
self._receive_buffer += input_data
self._receive_buffer = self._receive_buffer[message_length:]
===========changed ref 0===========
# module: aioquic.tls
+ class Alert(Exception):
+ pass
+
|
aioquic.tls/Context._client_send_hello
|
Modified
|
aiortc~aioquic
|
637e0efb4f53429885cd0ca76a887e90bc6a9223
|
[tls] add more checks on parameters
|
<4>:<del> compression_methods=[
<5>:<del> CompressionMethod.NULL,
<6>:<del> ],
<7>:<add> compression_methods=self._compression_methods,
<20>:<del> supported_versions=[
<21>:<del> TLS_VERSION_1_3,
<22>:<del> ],
<23>:<add> supported_versions=self._supported_versions,
|
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
<0> hello = ClientHello(
<1> random=self.client_random,
<2> session_id=self.session_id,
<3> cipher_suites=self._cipher_suites,
<4> compression_methods=[
<5> CompressionMethod.NULL,
<6> ],
<7>
<8> alpn_protocols=self.alpn_protocols,
<9> key_exchange_modes=[
<10> KeyExchangeMode.PSK_DHE_KE,
<11> ],
<12> key_share=[
<13> encode_public_key(self.private_key.public_key()),
<14> ],
<15> server_name=self.server_name,
<16> signature_algorithms=self._signature_algorithms,
<17> supported_groups=[
<18> Group.SECP256R1,
<19> ],
<20> supported_versions=[
<21> TLS_VERSION_1_3,
<22> ],
<23>
<24> other_extensions=self.handshake_extensions
<25> )
<26>
<27> self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
<28> self.key_schedule.extract(None)
<29>
<30> with self._push_message(output_buf):
<31> push_client_hello(output_buf, hello)
<32>
<33> self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
<34>
|
===========unchanged ref 0===========
at: aioquic.tls
AlertUnexpectedMessage(*args: object)
State()
Group(x: Union[str, bytes, bytearray], base: int)
Group(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
KeyExchangeMode(x: Union[str, bytes, bytearray], base: int)
KeyExchangeMode(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=None, alpn_protocols: List[str]=None, key_exchange_modes: List[int]=None, key_share: List[Tuple[int, bytes]]=None, server_name: str=None, signature_algorithms: List[int]=None, supported_groups: List[int]=None, supported_versions: List[int]=None, other_extensions: List[Tuple[int, bytes]]=field(default_factory=list))
encode_public_key(public_key)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.ClientHello
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
alpn_protocols: List[str] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
at: aioquic.tls.Context.__init__
self.alpn_protocols = None
self.handshake_extensions = []
self.server_name = None
===========unchanged ref 1===========
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self._compression_methods = [
CompressionMethod.NULL,
]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
]
self._supported_versions = [
TLS_VERSION_1_3
]
self.client_random = None
self.client_random = os.urandom(32)
self.session_id = None
self.session_id = os.urandom(32)
self.private_key = None
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._server_handle_hello
self.client_random = peer_hello.random
self.session_id = peer_hello.session_id
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._set_state
self.state = state
at: aioquic.tls.Context.handle_message
input_buf = Buffer(data=message)
===========changed ref 0===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._compression_methods = [
+ CompressionMethod.NULL,
+ ]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+ self._supported_versions = [
+ TLS_VERSION_1_3
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 1===========
# module: aioquic.tls
+ class Alert(Exception):
+ pass
+
|
aioquic.tls/Context._client_handle_hello
|
Modified
|
aiortc~aioquic
|
637e0efb4f53429885cd0ca76a887e90bc6a9223
|
[tls] add more checks on parameters
|
<1>:<add>
<add> assert peer_hello.cipher_suite in self._cipher_suites
<add> assert peer_hello.compression_method in self._compression_methods
<add> assert peer_hello.supported_version in self._supported_versions
|
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
<0> peer_hello = pull_server_hello(input_buf)
<1>
<2> peer_public_key = decode_public_key(peer_hello.key_share)
<3> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<4>
<5> self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
<6> self.key_schedule.update_hash(input_buf.data)
<7> self.key_schedule.extract(shared_key)
<8>
<9> self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b's hs traffic')
<10>
<11> self._set_state(State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS)
<12>
|
===========unchanged ref 0===========
at: aioquic.tls
State()
push_client_hello(buf: Buffer, hello: ClientHello)
pull_server_hello(buf: Buffer) -> ServerHello
KeyScheduleProxy(cipher_suites)
at: aioquic.tls.ClientHello
cipher_suites: List[int] = None
at: aioquic.tls.Context
_push_message(self, buf: Buffer)
_set_state(state)
at: aioquic.tls.Context.__init__
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self._compression_methods = [
CompressionMethod.NULL,
]
at: aioquic.tls.Context._client_handle_hello
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
at: aioquic.tls.Context._client_send_hello
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=self._cipher_suites,
compression_methods=self._compression_methods,
alpn_protocols=self.alpn_protocols,
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
server_name=self.server_name,
signature_algorithms=self._signature_algorithms,
supported_groups=[
Group.SECP256R1,
],
supported_versions=self._supported_versions,
other_extensions=self.handshake_extensions
)
at: aioquic.tls.Context._server_handle_hello
self.key_schedule = KeySchedule(cipher_suite)
===========unchanged ref 1===========
at: aioquic.tls.KeySchedule
extract(key_material=None)
at: aioquic.tls.KeyScheduleProxy
extract(key_material=None)
at: aioquic.tls.ServerHello
random: bytes = None
session_id: bytes = None
cipher_suite: int = None
compression_method: int = None
key_share: Tuple[int, bytes] = None
supported_version: int = None
===========changed ref 0===========
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=self._cipher_suites,
- compression_methods=[
- CompressionMethod.NULL,
- ],
+ compression_methods=self._compression_methods,
alpn_protocols=self.alpn_protocols,
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
server_name=self.server_name,
signature_algorithms=self._signature_algorithms,
supported_groups=[
Group.SECP256R1,
],
- supported_versions=[
- TLS_VERSION_1_3,
- ],
+ supported_versions=self._supported_versions,
other_extensions=self.handshake_extensions
)
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
self.key_schedule.extract(None)
with self._push_message(output_buf):
push_client_hello(output_buf, hello)
self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
===========changed ref 1===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._compression_methods = [
+ CompressionMethod.NULL,
+ ]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+ self._supported_versions = [
+ TLS_VERSION_1_3
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
===========changed ref 2===========
# module: aioquic.tls
+ class Alert(Exception):
+ pass
+
|
aioquic.tls/Context._server_handle_hello
|
Modified
|
aiortc~aioquic
|
637e0efb4f53429885cd0ca76a887e90bc6a9223
|
[tls] add more checks on parameters
|
<2>:<add> # negotiate parameters
<del> # negotiate cipher suite
<3>:<add> cipher_suite = negotiate(
<add> self._cipher_suites, peer_hello.cipher_suites,
<del> cipher_suite = negotiate(self._cipher_suites, peer_hello.cipher_suites)
<4>:<add> 'No supported cipher suite')
<add> compression_method = negotiate(
<add> self._compression_methods, peer_hello.compression_methods,
<add> 'No supported compression method')
<add> signature_algorithm = negotiate(
<del> if cipher_suite is None:
<5>:<del> raise AlertHandshakeFailure('No supported cipher suites')
<6>:<del>
<7>:<del> # negotiate signature algorithm
<8>:<add> self._signature_algorithms, peer_hello.signature_algorithms,
<del> signature_algorithm = negotiate(self._signature_algorithms, peer_hello.signature_algorithms)
<9>:<del> if signature_algorithm is None:
<10>:<add> 'No supported signature algorithm')
<del> raise AlertHandshakeFailure('No supported signature algorithms')
<11>:<add> supported_version = negotiate(
<add> self._supported_versions, peer_hello.supported_versions,
<add> 'No supported protocol version')
<29>:<add> compression_method=compression_method,
<del> compression_method=CompressionMethod.NULL,
<32>:<add> supported_version=supported_version,
<del> supported_version=TLS_VERSION_1_3,
|
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
<0> peer_hello = pull_client_hello(input_buf)
<1>
<2> # negotiate cipher suite
<3> cipher_suite = negotiate(self._cipher_suites, peer_hello.cipher_suites)
<4> if cipher_suite is None:
<5> raise AlertHandshakeFailure('No supported cipher suites')
<6>
<7> # negotiate signature algorithm
<8> signature_algorithm = negotiate(self._signature_algorithms, peer_hello.signature_algorithms)
<9> if signature_algorithm is None:
<10> raise AlertHandshakeFailure('No supported signature algorithms')
<11>
<12> self.client_random = peer_hello.random
<13> self.server_random = os.urandom(32)
<14> self.session_id = peer_hello.session_id
<15> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<16>
<17> self.key_schedule = KeySchedule(cipher_suite)
<18> self.key_schedule.extract(None)
<19> self.key_schedule.update_hash(input_buf.data)
<20>
<21> peer_public_key = decode_public_key(peer_hello.key_share[0])
<22> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<23>
<24> # send hello
<25> hello = ServerHello(
<26> random=self.server_random,
<27> session_id=self.session_id,
<28> cipher_suite=cipher_suite,
<29> compression_method=CompressionMethod.NULL,
<30>
<31> key_share=encode_public_key(self.private_key.public_key()),
<32> supported_version=TLS_VERSION_1_3,
<33> )
<34> with self._push_message(output_buf):
<35> push_server_hello(output_buf, hello)
<36> self.key_schedule.extract(shared_key)
<37>
<38> self._setup_traffic_pro</s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
# offset: 1
self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b'c hs traffic')
# send encrypted extensions
with self._push_message(output_buf):
push_encrypted_extensions(output_buf, EncryptedExtensions(
other_extensions=self.handshake_extensions))
# send certificate
with self._push_message(output_buf):
push_certificate(output_buf, Certificate(
request_context=b'',
certificates=[
(self.certificate.public_bytes(Encoding.DER), b'')
]))
# send certificate verify
algorithm = SIGNATURE_ALGORITHMS[signature_algorithm]()
signature = self.certificate_private_key.sign(
self.key_schedule.certificate_verify_data(b'TLS 1.3, server CertificateVerify'),
padding.PSS(
mgf=padding.MGF1(algorithm),
salt_length=algorithm.digest_size
),
algorithm)
with self._push_message(output_buf):
push_certificate_verify(output_buf, CertificateVerify(
algorithm=signature_algorithm,
signature=signature))
# send finished
with self._push_message(output_buf):
push_finished(output_buf, Finished(
verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.ENCRYPT, Epoch.ONE_RTT, b's ap traffic')
self._next_dec_key = self.key_schedule.derive_secret(b'c ap traffic')
self._set_state(State.SERVER_EXPECT_FINISHED)
===========unchanged ref 0===========
at: aioquic.tls
Direction()
Epoch()
State()
pull_client_hello(buf: Buffer)
ServerHello(random: bytes=None, session_id: bytes=None, cipher_suite: int=None, compression_method: int=None, key_share: Tuple[int, bytes]=None, supported_version: int=None)
push_server_hello(buf: Buffer, hello: ServerHello)
pull_new_session_ticket(buf: Buffer) -> NewSessionTicket
EncryptedExtensions(other_extensions: List[Tuple[int, bytes]]=field(default_factory=list))
push_encrypted_extensions(buf: Buffer, extensions: EncryptedExtensions)
Certificate(request_context: bytes=b'', certificates: List=field(default_factory=list))
push_certificate(buf: Buffer, certificate: Certificate)
Finished(verify_data: bytes=b'')
push_finished(buf: Buffer, finished: Finished)
KeySchedule(cipher_suite)
SIGNATURE_ALGORITHMS = {
SignatureAlgorithm.RSA_PSS_RSAE_SHA256: hashes.SHA256,
SignatureAlgorithm.RSA_PSS_RSAE_SHA384: hashes.SHA384,
SignatureAlgorithm.RSA_PSS_RSAE_SHA512: hashes.SHA512,
}
decode_public_key(key_share)
encode_public_key(public_key)
negotiate(supported, offered, error_message)
at: aioquic.tls.Certificate
request_context: bytes = b''
certificates: List = field(default_factory=list)
at: aioquic.tls.ClientHello
cipher_suites: List[int] = None
compression_methods: List[int] = None
signature_algorithms: List[int] = None
supported_versions: List[int] = None
at: aioquic.tls.Context
_push_message(self, buf: Buffer)
===========unchanged ref 1===========
_setup_traffic_protection(direction, epoch, label)
_set_state(state)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self._compression_methods = [
CompressionMethod.NULL,
]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
]
self._supported_versions = [
TLS_VERSION_1_3
]
self._enc_key = None
self.client_random = None
self.client_random = os.urandom(32)
self.session_id = None
self.session_id = os.urandom(32)
self.private_key = None
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
at: aioquic.tls.Context._client_handle_finished
next_enc_key = self.key_schedule.derive_secret(b'c ap traffic')
at: aioquic.tls.Context._client_handle_hello
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
at: aioquic.tls.Context._client_send_hello
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
at: aioquic.tls.Context._setup_traffic_protection
self._enc_key = key
at: aioquic.tls.EncryptedExtensions
other_extensions: List[Tuple[int, bytes]] = field(default_factory=list)
===========unchanged ref 2===========
at: aioquic.tls.Finished
verify_data: bytes = b''
at: aioquic.tls.KeySchedule
certificate_verify_data(context_string)
finished_verify_data(secret)
extract(key_material=None)
update_hash(data)
at: aioquic.tls.KeyScheduleProxy
extract(key_material=None)
update_hash(data)
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
+
+ assert peer_hello.cipher_suite in self._cipher_suites
+ assert peer_hello.compression_method in self._compression_methods
+ assert peer_hello.supported_version in self._supported_versions
peer_public_key = decode_public_key(peer_hello.key_share)
shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
self.key_schedule.update_hash(input_buf.data)
self.key_schedule.extract(shared_key)
self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b's hs traffic')
self._set_state(State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS)
|
tests.test_tls/ContextTest.test_server_unsupported_cipher_suite
|
Modified
|
aiortc~aioquic
|
637e0efb4f53429885cd0ca76a887e90bc6a9223
|
[tls] add more checks on parameters
|
<10>:<del> # send client hello
<11>:<del> client_buf = create_buffers()
<12>:<del> client.handle_message(b'', client_buf)
<13>:<del> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<14>:<del> server_input = merge_buffers(client_buf)
<15>:<del> reset_buffers(client_buf)
<16>:<add> with self.assertRaises(tls.AlertHandshakeFailure) as cm:
<add> self._server_fail_hello(client, server)
<add> self.assertEqual(str(cm.exception), 'No supported cipher suite')
<17>:<del> # handle client hello
<18>:<del> server_buf = create_buffers()
<19>:<del> with self.assertRaises(tls.AlertHandshakeFailure) as cm:
<20>:<del> server.handle_message(server_input, server_buf)
<21>:<del> self.assertEqual(str(cm.exception), 'No supported cipher suites')
<22>:<del>
|
# module: tests.test_tls
class ContextTest(TestCase):
def test_server_unsupported_cipher_suite(self):
<0> client = self.create_client()
<1> client._cipher_suites = [
<2> tls.CipherSuite.AES_128_GCM_SHA256,
<3> ]
<4>
<5> server = self.create_server()
<6> server._cipher_suites = [
<7> tls.CipherSuite.AES_256_GCM_SHA384,
<8> ]
<9>
<10> # send client hello
<11> client_buf = create_buffers()
<12> client.handle_message(b'', client_buf)
<13> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<14> server_input = merge_buffers(client_buf)
<15> reset_buffers(client_buf)
<16>
<17> # handle client hello
<18> server_buf = create_buffers()
<19> with self.assertRaises(tls.AlertHandshakeFailure) as cm:
<20> server.handle_message(server_input, server_buf)
<21> self.assertEqual(str(cm.exception), 'No supported cipher suites')
<22>
|
===========unchanged ref 0===========
at: aioquic.tls
State()
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: aioquic.tls.Context.__init__
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._set_state
self.state = state
at: tests.test_tls
create_buffers()
merge_buffers(buffers)
reset_buffers(buffers)
at: tests.test_tls.ContextTest
create_client()
create_server()
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_tls
class ContextTest(TestCase):
+ def _server_fail_hello(self, client, server):
+ # send client hello
+ client_buf = create_buffers()
+ client.handle_message(b'', client_buf)
+ self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
+ server_input = merge_buffers(client_buf)
+ reset_buffers(client_buf)
+
+ # handle client hello
+ server_buf = create_buffers()
+ server.handle_message(server_input, server_buf)
+
===========changed ref 1===========
# module: aioquic.tls
+ class Alert(Exception):
+ pass
+
===========changed ref 2===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
+
+ assert peer_hello.cipher_suite in self._cipher_suites
+ assert peer_hello.compression_method in self._compression_methods
+ assert peer_hello.supported_version in self._supported_versions
peer_public_key = decode_public_key(peer_hello.key_share)
shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
self.key_schedule.update_hash(input_buf.data)
self.key_schedule.extract(shared_key)
self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b's hs traffic')
self._set_state(State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS)
===========changed ref 3===========
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=self._cipher_suites,
- compression_methods=[
- CompressionMethod.NULL,
- ],
+ compression_methods=self._compression_methods,
alpn_protocols=self.alpn_protocols,
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
server_name=self.server_name,
signature_algorithms=self._signature_algorithms,
supported_groups=[
Group.SECP256R1,
],
- supported_versions=[
- TLS_VERSION_1_3,
- ],
+ supported_versions=self._supported_versions,
other_extensions=self.handshake_extensions
)
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
self.key_schedule.extract(None)
with self._push_message(output_buf):
push_client_hello(output_buf, hello)
self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
===========changed ref 4===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._compression_methods = [
+ CompressionMethod.NULL,
+ ]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+ self._supported_versions = [
+ TLS_VERSION_1_3
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
|
tests.test_tls/ContextTest.test_server_unsupported_signature_algorithm
|
Modified
|
aiortc~aioquic
|
637e0efb4f53429885cd0ca76a887e90bc6a9223
|
[tls] add more checks on parameters
|
<6>:<add> server._signature_algorithms = [
<del> client._signature_algorithms = [
<10>:<del> # send client hello
<11>:<del> client_buf = create_buffers()
<12>:<del> client.handle_message(b'', client_buf)
<13>:<del> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<14>:<del> server_input = merge_buffers(client_buf)
<15>:<del> reset_buffers(client_buf)
<16>:<add> with self.assertRaises(tls.AlertHandshakeFailure) as cm:
<add> self._server_fail_hello(client, server)
<add> self.assertEqual(str(cm.exception), 'No supported signature algorithm')
<17>:<del> # handle client hello
<18>:<del> server_buf = create_buffers()
<19>:<del> with self.assertRaises(tls.AlertHandshakeFailure) as cm:
<20>:<del> server.handle_message(server_input, server_buf)
<21>:<del> self.assertEqual(str(cm.exception), 'No supported signature algorithms')
<22>:<del>
|
# module: tests.test_tls
class ContextTest(TestCase):
def test_server_unsupported_signature_algorithm(self):
<0> client = self.create_client()
<1> client._signature_algorithms = [
<2> tls.SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<3> ]
<4>
<5> server = self.create_server()
<6> client._signature_algorithms = [
<7> tls.SignatureAlgorithm.RSA_PSS_RSAE_SHA512,
<8> ]
<9>
<10> # send client hello
<11> client_buf = create_buffers()
<12> client.handle_message(b'', client_buf)
<13> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<14> server_input = merge_buffers(client_buf)
<15> reset_buffers(client_buf)
<16>
<17> # handle client hello
<18> server_buf = create_buffers()
<19> with self.assertRaises(tls.AlertHandshakeFailure) as cm:
<20> server.handle_message(server_input, server_buf)
<21> self.assertEqual(str(cm.exception), 'No supported signature algorithms')
<22>
|
===========unchanged ref 0===========
at: aioquic.tls
TLS_VERSION_1_2 = 0x0303
AlertHandshakeFailure(*args: object)
SignatureAlgorithm(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.tls.Context.__init__
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
]
self._supported_versions = [
TLS_VERSION_1_3
]
at: tests.test_tls.ContextTest
create_client()
create_server()
_server_fail_hello(client, server)
_server_fail_hello(self, client, server)
at: tests.test_tls.ContextTest.test_server_unsupported_cipher_suite
client = self.create_client()
server = self.create_server()
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertRaises(expected_exception: Union[Type[_E], Tuple[Type[_E], ...]], msg: Any=...) -> _AssertRaisesContext[_E]
assertRaises(expected_exception: Union[Type[BaseException], Tuple[Type[BaseException], ...]], callable: Callable[..., Any], *args: Any, **kwargs: Any) -> None
at: unittest.case._AssertRaisesContext.__exit__
self.exception = exc_value.with_traceback(None)
===========changed ref 0===========
# module: tests.test_tls
class ContextTest(TestCase):
+ def _server_fail_hello(self, client, server):
+ # send client hello
+ client_buf = create_buffers()
+ client.handle_message(b'', client_buf)
+ self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
+ server_input = merge_buffers(client_buf)
+ reset_buffers(client_buf)
+
+ # handle client hello
+ server_buf = create_buffers()
+ server.handle_message(server_input, server_buf)
+
===========changed ref 1===========
# module: tests.test_tls
class ContextTest(TestCase):
def test_server_unsupported_cipher_suite(self):
client = self.create_client()
client._cipher_suites = [
tls.CipherSuite.AES_128_GCM_SHA256,
]
server = self.create_server()
server._cipher_suites = [
tls.CipherSuite.AES_256_GCM_SHA384,
]
- # send client hello
- client_buf = create_buffers()
- client.handle_message(b'', client_buf)
- self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
- server_input = merge_buffers(client_buf)
- reset_buffers(client_buf)
+ with self.assertRaises(tls.AlertHandshakeFailure) as cm:
+ self._server_fail_hello(client, server)
+ self.assertEqual(str(cm.exception), 'No supported cipher suite')
- # handle client hello
- server_buf = create_buffers()
- with self.assertRaises(tls.AlertHandshakeFailure) as cm:
- server.handle_message(server_input, server_buf)
- self.assertEqual(str(cm.exception), 'No supported cipher suites')
-
===========changed ref 2===========
# module: aioquic.tls
+ class Alert(Exception):
+ pass
+
===========changed ref 3===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
+
+ assert peer_hello.cipher_suite in self._cipher_suites
+ assert peer_hello.compression_method in self._compression_methods
+ assert peer_hello.supported_version in self._supported_versions
peer_public_key = decode_public_key(peer_hello.key_share)
shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
self.key_schedule.update_hash(input_buf.data)
self.key_schedule.extract(shared_key)
self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b's hs traffic')
self._set_state(State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS)
===========changed ref 4===========
# module: aioquic.tls
class Context:
def _client_send_hello(self, output_buf):
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=self._cipher_suites,
- compression_methods=[
- CompressionMethod.NULL,
- ],
+ compression_methods=self._compression_methods,
alpn_protocols=self.alpn_protocols,
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
server_name=self.server_name,
signature_algorithms=self._signature_algorithms,
supported_groups=[
Group.SECP256R1,
],
- supported_versions=[
- TLS_VERSION_1_3,
- ],
+ supported_versions=self._supported_versions,
other_extensions=self.handshake_extensions
)
self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
self.key_schedule.extract(None)
with self._push_message(output_buf):
push_client_hello(output_buf, hello)
self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
===========changed ref 5===========
# module: aioquic.tls
class Context:
def __init__(self, is_client, logger=None):
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.is_client = is_client
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
CipherSuite.CHACHA20_POLY1305_SHA256,
]
+ self._compression_methods = [
+ CompressionMethod.NULL,
+ ]
self._signature_algorithms = [
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
+ ]
+ self._supported_versions = [
+ TLS_VERSION_1_3
]
self._peer_certificate = None
self._receive_buffer = b''
self._enc_key = None
self._dec_key = None
self.__logger = logger
if is_client:
self.client_random = os.urandom(32)
self.session_id = os.urandom(32)
self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
self.state = State.CLIENT_HANDSHAKE_START
else:
self.client_random = None
self.session_id = None
self.private_key = None
self.state = State.SERVER_EXPECT_CLIENT_HELLO
|
aioquic.crypto/CryptoContext.decrypt_packet
|
Modified
|
aiortc~aioquic
|
e42765d199e04b86c2866ebf12866bc83d7d1b66
|
[connection] log transport close and decryption errors
|
<24>:<add> try:
<add> payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
<del> payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
<25>:<add> plain_header)
<del> plain_header)
<26>:<add> except InvalidTag:
<add> raise CryptoError('Payload decryption failed')
|
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
<0> packet = bytearray(packet)
<1>
<2> # header protection
<3> sample_offset = encrypted_offset + MAX_PN_SIZE
<4> sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
<5> mask = self.header_protection_mask(sample)
<6>
<7> if is_long_header(packet[0]):
<8> # long header
<9> packet[0] ^= (mask[0] & 0x0f)
<10> else:
<11> # short header
<12> packet[0] ^= (mask[0] & 0x1f)
<13>
<14> pn_length = (packet[0] & 0x03) + 1
<15> for i in range(pn_length):
<16> packet[encrypted_offset + i] ^= mask[1 + i]
<17> pn = packet[encrypted_offset:encrypted_offset + pn_length]
<18> plain_header = bytes(packet[:encrypted_offset + pn_length])
<19>
<20> # payload protection
<21> nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
<22> for i in range(len(self.iv)):
<23> nonce[i] ^= self.iv[i]
<24> payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
<25> plain_header)
<26>
<27> # packet number
<28> packet_number = 0
<29> for i in range(pn_length):
<30> packet_number = (packet_number << 8) | pn[i]
<31>
<32> return plain_header, payload, packet_number
<33>
|
===========unchanged ref 0===========
at: aioquic.crypto
MAX_PN_SIZE = 4
SAMPLE_SIZE = 16
CryptoError(*args: object)
at: aioquic.crypto.CryptoContext
header_protection_mask(sample)
at: aioquic.crypto.CryptoContext.setup
key, self.iv, self.hp = derive_key_iv_hp(cipher_suite, secret)
self.aead = cipher_suite_aead(cipher_suite, key)
at: aioquic.crypto.CryptoContext.teardown
self.aead = None
self.iv = None
at: aioquic.packet
is_long_header(first_byte)
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
e42765d199e04b86c2866ebf12866bc83d7d1b66
|
[connection] log transport close and decryption errors
|
<34>:<add> self.__close = None
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
alpn_protocols=None, server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.alpn_protocols = alpn_protocols
<5> self.certificate = certificate
<6> self.is_client = is_client
<7> self.host_cid = os.urandom(8)
<8> self.peer_cid = os.urandom(8)
<9> self.peer_cid_set = False
<10> self.peer_token = b''
<11> self.private_key = private_key
<12> self.secrets_log_file = secrets_log_file
<13> self.server_name = server_name
<14>
<15> # protocol versions
<16> self.supported_versions = [
<17> QuicProtocolVersion.DRAFT_17,
<18> QuicProtocolVersion.DRAFT_18,
<19> QuicProtocolVersion.DRAFT_19,
<20> QuicProtocolVersion.DRAFT_20,
<21> ]
<22> self.version = QuicProtocolVersion.DRAFT_20
<23>
<24> self.quic_transport_parameters = QuicTransportParameters(
<25> idle_timeout=600,
<26> initial_max_data=16777216,
<27> initial_max_stream_data_bidi_local=1048576,
<28> initial_max_stream_data_bidi_remote=1048576,
<29> initial_max_stream_data_uni=1048576,
<30> initial_max_streams_bidi=100,
<31> ack_delay_exponent=10,
<32> )
<33>
<34> self.__initialized = False
<35> self.__logger = logger
<36>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.close
self.__close = {
'error_code': error_code,
'frame_type': frame_type,
'reason_phrase': reason_phrase
}
at: aioquic.connection.QuicConnection.datagram_received
self.version = QuicProtocolVersion(max(common))
self.peer_cid = header.source_cid
self.peer_token = header.token
self.peer_cid_set = True
at: aioquic.connection.QuicConnection.pending_datagrams
self.__close = None
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
===========unchanged ref 1===========
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.crypto
+ class CryptoError(Exception):
+ pass
+
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
packet = bytearray(packet)
# header protection
sample_offset = encrypted_offset + MAX_PN_SIZE
sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
mask = self.header_protection_mask(sample)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
pn_length = (packet[0] & 0x03) + 1
for i in range(pn_length):
packet[encrypted_offset + i] ^= mask[1 + i]
pn = packet[encrypted_offset:encrypted_offset + pn_length]
plain_header = bytes(packet[:encrypted_offset + pn_length])
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
+ try:
+ payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
- payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
+ plain_header)
- plain_header)
+ except InvalidTag:
+ raise CryptoError('Payload decryption failed')
# packet number
packet_number = 0
for i in range(pn_length):
packet_number = (packet_number << 8) | pn[i]
return plain_header, payload, packet_number
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
e42765d199e04b86c2866ebf12866bc83d7d1b66
|
[connection] log transport close and decryption errors
|
<43>:<add> try:
<add> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<del> plain_header, plain
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
<10> # version negotiation
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> if not common:
<16> self.__logger.error('Could not find a common protocol version')
<17> return
<18> self.version = QuicProtocolVersion(max(common))
<19> self.__logger.info('Retrying with %s' % self.version)
<20> self.connection_made()
<21> return
<22> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
<23> # stateless retry
<24> if (
<25> header.destination_cid == self.host_cid and
<26> header.original_destination_cid == self.peer_cid
<27> ):
<28> self.__logger.info('Performing stateless retry')
<29> self.peer_cid = header.source_cid
<30> self.peer_token = header.token
<31> self.connection_made()
<32> return
<33>
<34> encrypted_off = buf.tell() - start_off
<35> end_off = buf.tell() + header.rest_length
<36> tls.pull_bytes(buf, header.rest_length)
<37>
<38> if not self.is_client and not self.__initialized:
<39> self._initialize(header.destination_cid)
<40>
<41> epoch = get_epoch(header.packet_type)
<42> space = self.spaces[epoch]
<43> plain_header, plain</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
data[start_off:end_off], encrypted_off)
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
connection_made()
_initialize(peer_cid)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_token = b''
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.__initialized = False
self.__logger = logger
at: aioquic.connection.QuicConnection._initialize
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.__initialized = True
at: aioquic.crypto
CryptoError(*args: object)
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
===========unchanged ref 1===========
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
original_destination_cid: bytes = b''
token: bytes = b''
rest_length: int = 0
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
at: logging.Logger
info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
# module: aioquic.crypto
+ class CryptoError(Exception):
+ pass
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
+ def close(self, error_code, frame_type=None, reason_phrase=b''):
+ self.__close = {
+ 'error_code': error_code,
+ 'frame_type': frame_type,
+ 'reason_phrase': reason_phrase
+ }
+
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
alpn_protocols=None, server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
+ self.__close = None
self.__initialized = False
self.__logger = logger
===========changed ref 3===========
# module: aioquic.crypto
class CryptoContext:
def decrypt_packet(self, packet, encrypted_offset):
packet = bytearray(packet)
# header protection
sample_offset = encrypted_offset + MAX_PN_SIZE
sample = packet[sample_offset:sample_offset + SAMPLE_SIZE]
mask = self.header_protection_mask(sample)
if is_long_header(packet[0]):
# long header
packet[0] ^= (mask[0] & 0x0f)
else:
# short header
packet[0] ^= (mask[0] & 0x1f)
pn_length = (packet[0] & 0x03) + 1
for i in range(pn_length):
packet[encrypted_offset + i] ^= mask[1 + i]
pn = packet[encrypted_offset:encrypted_offset + pn_length]
plain_header = bytes(packet[:encrypted_offset + pn_length])
# payload protection
nonce = bytearray(len(self.iv) - pn_length) + bytearray(pn)
for i in range(len(self.iv)):
nonce[i] ^= self.iv[i]
+ try:
+ payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
- payload = self.aead.decrypt(nonce, bytes(packet[encrypted_offset + pn_length:]),
+ plain_header)
- plain_header)
+ except InvalidTag:
+ raise CryptoError('Payload decryption failed')
# packet number
packet_number = 0
for i in range(pn_length):
packet_number = (packet_number << 8) | pn[i]
return plain_header, payload, packet_number
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
e42765d199e04b86c2866ebf12866bc83d7d1b66
|
[connection] log transport close and decryption errors
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
<0> buf = Buffer(data=plain)
<1>
<2> is_ack_only = True
<3> while not buf.eof():
<4> frame_type = pull_uint_var(buf)
<5> if frame_type != QuicFrameType.ACK:
<6> is_ack_only = False
<7>
<8> if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
<9> pass
<10> elif frame_type == QuicFrameType.ACK:
<11> packet.pull_ack_frame(buf)
<12> elif frame_type == QuicFrameType.CRYPTO:
<13> stream = self.streams[epoch]
<14> stream.add_frame(packet.pull_crypto_frame(buf))
<15> data = stream.pull_data()
<16> if data:
<17> self.tls.handle_message(data, self.send_buffer)
<18> elif frame_type == QuicFrameType.NEW_TOKEN:
<19> packet.pull_new_token_frame(buf)
<20> elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
<21> flags = frame_type & STREAM_FLAGS
<22> stream_id = pull_uint_var(buf)
<23> if flags & STREAM_FLAG_OFF:
<24> offset = pull_uint_var(buf)
<25> else:
<26> offset = 0
<27> if flags & STREAM_FLAG_LEN:
<28> length = pull_uint_var(buf)
<29> else:
<30> length = buf.capacity - buf.tell()
<31> frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
<32> stream = self._get_or_create_stream(stream_id)
<33> stream.add_frame(frame)
<34> elif frame_type == QuicFrameType.MAX_DATA:
<35> pull_uint_var(buf)
<36> elif frame_type in [QuicFrameType.MAX_STREAMS_BIDI, Quic</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
else:
self.__logger.warning('unhandled frame type %d', frame_type)
break
self._push_crypto_data()
return is_ack_only
===========unchanged ref 0===========
at: aioquic.connection
STREAM_FLAGS = 0x07
STREAM_FLAG_LEN = 2
STREAM_FLAG_OFF = 4
PacketSpace()
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.__initialized = False
at: aioquic.connection.QuicConnection._initialize
self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_close
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.crypto.CryptoPair
setup_initial(cid, is_client)
at: aioquic.packet
pull_uint_var(buf)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
pull_ack_frame(buf)
pull_crypto_frame(buf)
pull_new_token_frame(buf)
at: aioquic.stream
QuicStream(stream_id=None)
===========unchanged ref 1===========
at: aioquic.stream.QuicStream
add_frame(frame: QuicStreamFrame)
pull_data()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
eof()
tell()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
+ def close(self, error_code, frame_type=None, reason_phrase=b''):
+ self.__close = {
+ 'error_code': error_code,
+ 'frame_type': frame_type,
+ 'reason_phrase': reason_phrase
+ }
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
alpn_protocols=None, server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
+ self.__close = None
self.__initialized = False
self.__logger = logger
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
versions = []
while not buf.eof():
versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error('Could not find a common protocol version')
return
self.version = QuicProtocolVersion(max(common))
self.__logger.info('Retrying with %s' % self.version)
self.connection_made()
return
elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
# stateless retry
if (
header.destination_cid == self.host_cid and
header.original_destination_cid == self.peer_cid
):
self.__logger.info('Performing stateless retry')
self.peer_cid = header.source_cid
self.peer_token = header.token
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
+ try:
+ plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
- plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
<s>.crypto.decrypt_packet(
- plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
+ data[start_off:end_off], encrypted_off)
- data[start_off:end_off], encrypted_off)
+ except CryptoError as exc:
+ self.__logger.warning(exc)
+ return
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
|
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
8d6e40ae7aa924be974dc4acc9f7e1e324bff3ea
|
[examples] negotiate http/0.9
|
<14>:<add> self.streams = {}
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
alpn_protocols=None, server_name=None):
<0> if not is_client:
<1> assert certificate is not None, 'SSL certificate is required'
<2> assert private_key is not None, 'SSL private key is required'
<3>
<4> self.alpn_protocols = alpn_protocols
<5> self.certificate = certificate
<6> self.is_client = is_client
<7> self.host_cid = os.urandom(8)
<8> self.peer_cid = os.urandom(8)
<9> self.peer_cid_set = False
<10> self.peer_token = b''
<11> self.private_key = private_key
<12> self.secrets_log_file = secrets_log_file
<13> self.server_name = server_name
<14>
<15> # protocol versions
<16> self.supported_versions = [
<17> QuicProtocolVersion.DRAFT_17,
<18> QuicProtocolVersion.DRAFT_18,
<19> QuicProtocolVersion.DRAFT_19,
<20> QuicProtocolVersion.DRAFT_20,
<21> ]
<22> self.version = QuicProtocolVersion.DRAFT_20
<23>
<24> self.quic_transport_parameters = QuicTransportParameters(
<25> idle_timeout=600,
<26> initial_max_data=16777216,
<27> initial_max_stream_data_bidi_local=1048576,
<28> initial_max_stream_data_bidi_remote=1048576,
<29> initial_max_stream_data_uni=1048576,
<30> initial_max_streams_bidi=100,
<31> ack_delay_exponent=10,
<32> )
<33>
<34> self.__close = None
<35> self.__initialized = False
<36> self.__logger = logger
<37>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection._initialize
self.__initialized = True
at: aioquic.connection.QuicConnection.close
self.__close = {
'error_code': error_code,
'frame_type': frame_type,
'reason_phrase': reason_phrase
}
at: aioquic.connection.QuicConnection.datagram_received
self.version = QuicProtocolVersion(max(common))
self.peer_cid = header.source_cid
self.peer_token = header.token
self.peer_cid_set = True
at: aioquic.connection.QuicConnection.pending_datagrams
self.__close = None
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicTransportParameters(initial_version: int=None, negotiated_version: int=None, supported_versions: List[int]=field(default_factory=list), original_connection_id: bytes=None, idle_timeout: int=None, stateless_reset_token: bytes=None, max_packet_size: int=None, initial_max_data: int=None, initial_max_stream_data_bidi_local: int=None, initial_max_stream_data_bidi_remote: int=None, initial_max_stream_data_uni: int=None, initial_max_streams_bidi: int=None, initial_max_streams_uni: int=None, ack_delay_exponent: int=None, max_ack_delay: int=None, disable_migration: bool=False, preferred_address: bytes=None)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
original_connection_id: bytes = None
idle_timeout: int = None
===========unchanged ref 1===========
stateless_reset_token: bytes = None
max_packet_size: int = None
initial_max_data: int = None
initial_max_stream_data_bidi_local: int = None
initial_max_stream_data_bidi_remote: int = None
initial_max_stream_data_uni: int = None
initial_max_streams_bidi: int = None
initial_max_streams_uni: int = None
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: os
urandom(size: int, /) -> bytes
|
aioquic.connection/QuicConnection._initialize
|
Modified
|
aiortc~aioquic
|
8d6e40ae7aa924be974dc4acc9f7e1e324bff3ea
|
[examples] negotiate http/0.9
|
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
<0> # transport parameters
<1> if self.version >= QuicProtocolVersion.DRAFT_19:
<2> self.quic_transport_parameters.idle_timeout = 600000
<3> else:
<4> self.quic_transport_parameters.idle_timeout = 600
<5> if self.is_client:
<6> self.quic_transport_parameters.initial_version = self.version
<7> else:
<8> self.quic_transport_parameters.negotiated_version = self.version
<9> self.quic_transport_parameters.supported_versions = self.supported_versions
<10> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<11>
<12> # TLS
<13> self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
<14> self.tls.alpn_protocols = self.alpn_protocols
<15> self.tls.certificate = self.certificate
<16> self.tls.certificate_private_key = self.private_key
<17> self.tls.handshake_extensions = [
<18> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<19> ]
<20> self.tls.server_name = self.server_name
<21> self.tls.update_traffic_key_cb = self._update_traffic_key
<22>
<23> # packet spaces
<24> self.send_ack = {
<25> tls.Epoch.INITIAL: False,
<26> tls.Epoch.HANDSHAKE: False,
<27> tls.Epoch.ONE_RTT: False,
<28> }
<29> self.send_buffer = {
<30> tls.Epoch.INITIAL: Buffer(capacity=4096),
<31> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<32> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<33> }
<34> self.spaces = {
<35> tls.Epoch.INITIAL: PacketSpace(),
<36> tls.Epoch.HANDSHAKE: Packet</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# offset: 1
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.streams = {
tls.Epoch.INITIAL: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
is_client=self.is_client)
self.__initialized = True
self.packet_number = 0
===========unchanged ref 0===========
at: aioquic.connection
PacketSpace()
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_serialize_parameters()
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.__init__
self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.private_key = private_key
self.server_name = server_name
self.streams = {}
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__initialized = False
self.__logger = logger
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_close
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.version = QuicProtocolVersion(max(common))
at: aioquic.crypto.CryptoPair
setup_initial(cid, is_client)
===========unchanged ref 1===========
at: aioquic.packet
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
at: aioquic.packet.QuicTransportParameters
initial_version: int = None
negotiated_version: int = None
supported_versions: List[int] = field(default_factory=list)
idle_timeout: int = None
stateless_reset_token: bytes = None
at: aioquic.stream
QuicStream(stream_id=None)
at: aioquic.tls
Epoch()
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
Context(is_client, logger=None)
at: aioquic.tls.Context.__init__
self.alpn_protocols = None
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
self.server_name = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
alpn_protocols=None, server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
+ self.streams = {}
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__close = None
self.__initialized = False
self.__logger = logger
|
|
examples.cli/run
|
Modified
|
aiortc~aioquic
|
8d6e40ae7aa924be974dc4acc9f7e1e324bff3ea
|
[examples] negotiate http/0.9
|
<10>:<del> await asyncio.sleep(2)
<11>:<del>
|
# module: examples.cli
def run(host, port, **kwargs):
<0> # if host is not an IP address, pass it to enable SNI
<1> try:
<2> ipaddress.ip_address(host)
<3> except ValueError:
<4> kwargs['server_name'] = host
<5>
<6> _, protocol = await loop.create_datagram_endpoint(
<7> lambda: QuicProtocol(**kwargs),
<8> remote_addr=(host, port))
<9>
<10> await asyncio.sleep(2)
<11>
<12> stream = protocol._connection.create_stream()
<13> stream.push_data(b'GET /\r\n')
<14> protocol._send_pending()
<15>
<16> await asyncio.sleep(1)
<17>
<18> print(stream.pull_data())
<19>
|
===========unchanged ref 0===========
at: asyncio.events.AbstractEventLoop
create_datagram_endpoint(protocol_factory: _ProtocolFactory, local_addr: Optional[Tuple[str, int]]=..., remote_addr: Optional[Tuple[str, int]]=..., *, family: int=..., proto: int=..., flags: int=..., reuse_address: Optional[bool]=..., reuse_port: Optional[bool]=..., allow_broadcast: Optional[bool]=..., sock: Optional[socket]=...) -> _TransProtPair
at: asyncio.tasks
sleep(delay: float, result: _T=..., *, loop: Optional[AbstractEventLoop]=...) -> Future[_T]
at: examples.cli
QuicProtocol(*, is_client=True, certificate=None, private_key=None, server_name=None)
loop = asyncio.get_event_loop()
at: ipaddress
ip_address(address: object) -> Any
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
alpn_protocols=None, server_name=None):
if not is_client:
assert certificate is not None, 'SSL certificate is required'
assert private_key is not None, 'SSL private key is required'
self.alpn_protocols = alpn_protocols
self.certificate = certificate
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b''
self.private_key = private_key
self.secrets_log_file = secrets_log_file
self.server_name = server_name
+ self.streams = {}
# protocol versions
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.quic_transport_parameters = QuicTransportParameters(
idle_timeout=600,
initial_max_data=16777216,
initial_max_stream_data_bidi_local=1048576,
initial_max_stream_data_bidi_remote=1048576,
initial_max_stream_data_uni=1048576,
initial_max_streams_bidi=100,
ack_delay_exponent=10,
)
self.__close = None
self.__initialized = False
self.__logger = logger
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# transport parameters
if self.version >= QuicProtocolVersion.DRAFT_19:
self.quic_transport_parameters.idle_timeout = 600000
else:
self.quic_transport_parameters.idle_timeout = 600
if self.is_client:
self.quic_transport_parameters.initial_version = self.version
else:
self.quic_transport_parameters.negotiated_version = self.version
self.quic_transport_parameters.supported_versions = self.supported_versions
self.quic_transport_parameters.stateless_reset_token = bytes(16)
# TLS
self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
self.tls.alpn_protocols = self.alpn_protocols
self.tls.certificate = self.certificate
self.tls.certificate_private_key = self.private_key
self.tls.handshake_extensions = [
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
]
self.tls.server_name = self.server_name
self.tls.update_traffic_key_cb = self._update_traffic_key
# packet spaces
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
- self.streams = {
+ self.streams[tls.Epoch</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _initialize(self, peer_cid):
# offset: 1
<s>.ONE_RTT: PacketSpace(),
}
- self.streams = {
+ self.streams[tls.Epoch.INITIAL] = QuicStream()
- tls.Epoch.INITIAL: QuicStream(),
+ self.streams[tls.Epoch.HANDSHAKE] = QuicStream()
- tls.Epoch.HANDSHAKE: QuicStream(),
+ self.streams[tls.Epoch.ONE_RTT] = QuicStream()
- tls.Epoch.ONE_RTT: QuicStream(),
- }
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=peer_cid,
is_client=self.is_client)
self.__initialized = True
self.packet_number = 0
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
5cba6a6fbd0120433619469286647a71df408fa0
|
[buffer] move basic buffer methods to aioquic.buffer
|
<13>:<add> versions.append(pull_uint32(buf))
<del> versions.append(tls.pull_uint32(buf))
<36>:<add> pull_bytes(buf, header.rest_length)
<del> tls.pull_bytes(buf, header.rest_length)
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
<0> """
<1> Handle an incoming datagram.
<2> """
<3> buf = Buffer(data=data)
<4>
<5> while not buf.eof():
<6> start_off = buf.tell()
<7> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<8>
<9> if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
<10> # version negotiation
<11> versions = []
<12> while not buf.eof():
<13> versions.append(tls.pull_uint32(buf))
<14> common = set(self.supported_versions).intersection(versions)
<15> if not common:
<16> self.__logger.error("Could not find a common protocol version")
<17> return
<18> self.version = QuicProtocolVersion(max(common))
<19> self.__logger.info("Retrying with %s" % self.version)
<20> self.connection_made()
<21> return
<22> elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
<23> # stateless retry
<24> if (
<25> header.destination_cid == self.host_cid
<26> and header.original_destination_cid == self.peer_cid
<27> ):
<28> self.__logger.info("Performing stateless retry")
<29> self.peer_cid = header.source_cid
<30> self.peer_token = header.token
<31> self.connection_made()
<32> return
<33>
<34> encrypted_off = buf.tell() - start_off
<35> end_off = buf.tell() + header.rest_length
<36> tls.pull_bytes(buf, header.rest_length)
<37>
<38> if not self.is_client and not self.__initialized:
<39> self._initialize(header.destination_cid)
<40>
<41> epoch = get_epoch(header.packet_type)
<42> space = self.spaces[epoch]
<43> try:
<44> </s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
data[start_off:end_off], encrypted_off
)
except CryptoError as exc:
self.__logger.warning(exc)
return
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========unchanged ref 0===========
at: aioquic.buffer
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.buffer.Buffer
eof()
tell()
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
connection_made()
_initialize(peer_cid)
_payload_received(epoch, plain)
_payload_received(self, epoch, plain)
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.peer_token = b""
self.supported_versions = [
QuicProtocolVersion.DRAFT_17,
QuicProtocolVersion.DRAFT_18,
QuicProtocolVersion.DRAFT_19,
QuicProtocolVersion.DRAFT_20,
]
self.version = QuicProtocolVersion.DRAFT_20
self.__initialized = False
self.__logger = logger
at: aioquic.connection.QuicConnection._initialize
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.__initialized = True
at: aioquic.crypto
CryptoError(*args: object)
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.packet
PACKET_TYPE_RETRY = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x30
===========unchanged ref 1===========
QuicProtocolVersion(x: Union[str, bytes, bytearray], base: int)
QuicProtocolVersion(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
pull_quic_header(buf, host_cid_length=None)
at: aioquic.packet.QuicHeader
version: int
packet_type: int
destination_cid: bytes
source_cid: bytes
original_destination_cid: bytes = b""
token: bytes = b""
rest_length: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
at: logging.Logger
info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
error(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
+ # module: aioquic.buffer
+ class Buffer:
+ def tell(self):
+ return self._pos
+
===========changed ref 1===========
+ # module: aioquic.buffer
+ class Buffer:
+ def eof(self):
+ return self._pos == self._length
+
===========changed ref 2===========
+ # module: aioquic.buffer
+ # BYTES
+
+
+ def pull_bytes(buf: Buffer, length: int) -> bytes:
+ """
+ Pull bytes.
+ """
+ if buf._pos + length > buf._length:
+ raise BufferReadError
+ v = buf._data[buf._pos : buf._pos + length]
+ buf._pos += length
+ return v
+
===========changed ref 3===========
+ # module: aioquic.buffer
+ def pull_uint32(buf: Buffer) -> int:
+ """
+ Pull a 32-bit unsigned integer.
+ """
+ try:
+ v, = struct.unpack_from("!L", buf._data, buf._pos)
+ buf._pos += 4
+ return v
+ except struct.error:
+ raise BufferReadError
+
===========changed ref 4===========
+ # module: aioquic.buffer
+
+
===========changed ref 5===========
+ # module: aioquic.buffer
+ class BufferReadError(ValueError):
+ pass
+
===========changed ref 6===========
# module: aioquic.tls
- class BufferReadError(ValueError):
- pass
-
===========changed ref 7===========
+ # module: aioquic.buffer
+ class Buffer:
+ @property
+ def capacity(self):
+ return self._length
+
===========changed ref 8===========
# module: aioquic.tls
- class Buffer:
- def tell(self):
- return self._pos
-
===========changed ref 9===========
# module: aioquic.tls
- class Buffer:
- @property
- def capacity(self):
- return self._length
-
===========changed ref 10===========
# module: aioquic.tls
- class Buffer:
- def eof(self):
- return self._pos == self._length
-
===========changed ref 11===========
+ # module: aioquic.buffer
+ class Buffer:
+ def data_slice(self, start, end):
+ return bytes(self._data[start:end])
+
===========changed ref 12===========
+ # module: aioquic.buffer
+ class Buffer:
+ @property
+ def data(self):
+ return bytes(self._data[: self._pos])
+
===========changed ref 13===========
# module: aioquic.tls
- class Buffer:
- def data_slice(self, start, end):
- return bytes(self._data[start:end])
-
===========changed ref 14===========
# module: aioquic.tls
- class Buffer:
- @property
- def data(self):
- return bytes(self._data[: self._pos])
-
===========changed ref 15===========
+ # module: aioquic.buffer
+ class Buffer:
+ def seek(self, pos):
+ assert pos <= self._length
+ self._pos = pos
+
===========changed ref 16===========
# module: aioquic.tls
- class Buffer:
- def seek(self, pos):
- assert pos <= self._length
- self._pos = pos
-
===========changed ref 17===========
+ # module: aioquic.buffer
+ def push_uint8(buf: Buffer, v: int):
+ """
+ Push an 8-bit unsigned integer.
+ """
+ buf._data[buf._pos] = v
+ buf._pos += 1
+
===========changed ref 18===========
# module: aioquic.tls
- def push_uint8(buf: Buffer, v: int):
- """
- Push an 8-bit unsigned integer.
- """
- buf._data[buf._pos] = v
- buf._pos += 1
-
===========changed ref 19===========
+ # module: aioquic.buffer
+ def push_uint64(buf: Buffer, v: int):
+ """
+ Push a 64-bit unsigned integer.
+ """
+ pack_into("!Q", buf._data, buf._pos, v)
+ buf._pos += 8
+
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
5cba6a6fbd0120433619469286647a71df408fa0
|
[buffer] move basic buffer methods to aioquic.buffer
|
<31>:<add> frame = QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
<del> frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
<0> buf = Buffer(data=plain)
<1>
<2> is_ack_only = True
<3> while not buf.eof():
<4> frame_type = pull_uint_var(buf)
<5> if frame_type != QuicFrameType.ACK:
<6> is_ack_only = False
<7>
<8> if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
<9> pass
<10> elif frame_type == QuicFrameType.ACK:
<11> packet.pull_ack_frame(buf)
<12> elif frame_type == QuicFrameType.CRYPTO:
<13> stream = self.streams[epoch]
<14> stream.add_frame(packet.pull_crypto_frame(buf))
<15> data = stream.pull_data()
<16> if data:
<17> self.tls.handle_message(data, self.send_buffer)
<18> elif frame_type == QuicFrameType.NEW_TOKEN:
<19> packet.pull_new_token_frame(buf)
<20> elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
<21> flags = frame_type & STREAM_FLAGS
<22> stream_id = pull_uint_var(buf)
<23> if flags & STREAM_FLAG_OFF:
<24> offset = pull_uint_var(buf)
<25> else:
<26> offset = 0
<27> if flags & STREAM_FLAG_LEN:
<28> length = pull_uint_var(buf)
<29> else:
<30> length = buf.capacity - buf.tell()
<31> frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
<32> stream = self._get_or_create_stream(stream_id)
<33> stream.add_frame(frame)
<34> elif frame_type == QuicFrameType.MAX_DATA:
<35> pull_uint_var(buf)
<36> elif frame_type in [
<37> QuicFrameType.MAX_STREAMS_BIDI</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
QuicFrameType.MAX_STREAMS_UNI,
]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
elif frame_type == QuicFrameType.TRANSPORT_CLOSE:
error_code, frame_type, reason_phrase = packet.pull_transport_close_frame(
buf
)
self.__logger.info(
"Transport close code 0x%X, reason %s" % (error_code, reason_phrase)
)
elif frame_type == QuicFrameType.APPLICATION_CLOSE:
error_code, reason_phrase = packet.pull_application_close_frame(buf)
self.__logger.info(
"Application close code 0x%X, reason %s"
% (error_code, reason_phrase)
)
else:
self.__logger.warning("unhandled frame type %d", frame_type)
break
self._push_crypto_data()
return is_ack_only
===========unchanged ref 0===========
at: aioquic.buffer
Buffer(capacity=None, data=None)
at: aioquic.buffer.Buffer
eof()
tell()
at: aioquic.connection
STREAM_FLAGS = 0x07
STREAM_FLAG_LEN = 2
STREAM_FLAG_OFF = 4
at: aioquic.connection.QuicConnection
_get_or_create_stream(stream_id)
_push_crypto_data()
at: aioquic.connection.QuicConnection.__init__
self.streams = {}
self.__logger = logger
at: aioquic.connection.QuicConnection._initialize
self.tls = tls.Context(is_client=self.is_client, logger=self.__logger)
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
at: aioquic.packet
pull_uint_var(buf)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
pull_ack_frame(buf)
QuicStreamFrame(data: bytes=b"", offset: int=0)
pull_crypto_frame(buf)
pull_new_token_frame(buf)
pull_new_connection_id_frame(buf)
pull_transport_close_frame(buf)
pull_application_close_frame(buf)
at: aioquic.packet.QuicStreamFrame
data: bytes = b""
offset: int = 0
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========unchanged ref 1===========
at: logging.Logger
info(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
warning(msg: Any, *args: Any, exc_info: _ExcInfoType=..., stack_info: bool=..., extra: Optional[Dict[str, Any]]=..., **kwargs: Any) -> None
===========changed ref 0===========
+ # module: aioquic.buffer
+ class Buffer:
+ def tell(self):
+ return self._pos
+
===========changed ref 1===========
+ # module: aioquic.buffer
+ class Buffer:
+ @property
+ def capacity(self):
+ return self._length
+
===========changed ref 2===========
+ # module: aioquic.buffer
+ class Buffer:
+ def eof(self):
+ return self._pos == self._length
+
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
versions = []
while not buf.eof():
+ versions.append(pull_uint32(buf))
- versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error("Could not find a common protocol version")
return
self.version = QuicProtocolVersion(max(common))
self.__logger.info("Retrying with %s" % self.version)
self.connection_made()
return
elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
# stateless retry
if (
header.destination_cid == self.host_cid
and header.original_destination_cid == self.peer_cid
):
self.__logger.info("Performing stateless retry")
self.peer_cid = header.source_cid
self.peer_token = header.token
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
+ pull_bytes(buf, header.rest_length)
- tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
try:
plain_header, plain_payload, packet_number = space.</s>
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
<s>
space = self.spaces[epoch]
try:
plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
data[start_off:end_off], encrypted_off
)
except CryptoError as exc:
self.__logger.warning(exc)
return
if not self.peer_cid_set:
self.peer_cid = header.source_cid
self.peer_cid_set = True
# handle payload
is_ack_only = self._payload_received(epoch, plain_payload)
# record packet as received
space.ack_queue.add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========changed ref 5===========
+ # module: aioquic.buffer
+
+
===========changed ref 6===========
+ # module: aioquic.buffer
+ class BufferReadError(ValueError):
+ pass
+
===========changed ref 7===========
# module: aioquic.tls
- class BufferReadError(ValueError):
- pass
-
===========changed ref 8===========
# module: aioquic.tls
- class Buffer:
- def tell(self):
- return self._pos
-
===========changed ref 9===========
# module: aioquic.tls
- class Buffer:
- @property
- def capacity(self):
- return self._length
-
===========changed ref 10===========
# module: aioquic.tls
- class Buffer:
- def eof(self):
- return self._pos == self._length
-
===========changed ref 11===========
+ # module: aioquic.buffer
+ class Buffer:
+ def data_slice(self, start, end):
+ return bytes(self._data[start:end])
+
===========changed ref 12===========
+ # module: aioquic.buffer
+ class Buffer:
+ @property
+ def data(self):
+ return bytes(self._data[: self._pos])
+
|
aioquic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
5cba6a6fbd0120433619469286647a71df408fa0
|
[buffer] move basic buffer methods to aioquic.buffer
|
<9>:<add> push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<del> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<10>:<add> push_bytes(buf, self.peer_cid)
<del> tls.push_bytes(buf, self.peer_cid)
<11>:<add> push_uint16(buf, self.packet_number)
<del> tls.push_uint16(buf, self.packet_number)
<28>:<add> push_bytes(buf, frame.data)
<del> tls.push_bytes(buf, frame.data)
|
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
<0> epoch = tls.Epoch.ONE_RTT
<1> space = self.spaces[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> if not space.crypto.send.is_valid():
<4> return
<5>
<6> buf = Buffer(capacity=PACKET_MAX_SIZE)
<7>
<8> # write header
<9> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<10> tls.push_bytes(buf, self.peer_cid)
<11> tls.push_uint16(buf, self.packet_number)
<12> header_size = buf.tell()
<13>
<14> # ACK
<15> if send_ack:
<16> push_uint_var(buf, QuicFrameType.ACK)
<17> packet.push_ack_frame(buf, send_ack, 0)
<18> self.send_ack[epoch] = False
<19>
<20> # STREAM
<21> for stream_id, stream in self.streams.items():
<22> if isinstance(stream_id, int) and stream.has_data_to_send():
<23> frame = stream.get_frame(
<24> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6
<25> )
<26> push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
<27> with push_stream_frame(buf, 0, frame.offset):
<28> tls.push_bytes(buf, frame.data)
<29>
<30> # encrypt
<31> packet_size = buf.tell()
<32> if packet_size > header_size:
<33> data = buf.data
<34> yield space.crypto.encrypt_packet(
<35> data[0:header_size], data[header_size:packet_size]
<36> )
<37>
<38> self.packet_number += 1
<39>
|
===========unchanged ref 0===========
at: aioquic.buffer
Buffer(capacity=None, data=None)
at: aioquic.buffer.Buffer
tell()
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.peer_cid = os.urandom(8)
self.streams = {}
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_close
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_handshake
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
self.send = CryptoContext()
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
push_uint_var(buf, value)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
===========unchanged ref 1===========
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_stream_frame(buf, stream_id, offset)
at: aioquic.tls
Epoch()
===========changed ref 0===========
+ # module: aioquic.buffer
+ class Buffer:
+ def tell(self):
+ return self._pos
+
===========changed ref 1===========
+ # module: aioquic.buffer
+ class Buffer:
+ @property
+ def data(self):
+ return bytes(self._data[: self._pos])
+
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
packet.pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
stream.add_frame(packet.pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_TOKEN:
packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
+ frame = QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
- frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
stream = self._get_or_create_stream(stream_id)
stream.add_frame(frame)
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [
QuicFrameType.MAX_STREAMS_BIDI,
QuicFrameType.MAX_STREAMS_</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>type in [
QuicFrameType.MAX_STREAMS_BIDI,
QuicFrameType.MAX_STREAMS_UNI,
]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
elif frame_type == QuicFrameType.TRANSPORT_CLOSE:
error_code, frame_type, reason_phrase = packet.pull_transport_close_frame(
buf
)
self.__logger.info(
"Transport close code 0x%X, reason %s" % (error_code, reason_phrase)
)
elif frame_type == QuicFrameType.APPLICATION_CLOSE:
error_code, reason_phrase = packet.pull_application_close_frame(buf)
self.__logger.info(
"Application close code 0x%X, reason %s"
% (error_code, reason_phrase)
)
else:
self.__logger.warning("unhandled frame type %d", frame_type)
break
self._push_crypto_data()
return is_ack_only
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
"""
Handle an incoming datagram.
"""
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
if self.is_client and header.version == QuicProtocolVersion.NEGOTIATION:
# version negotiation
versions = []
while not buf.eof():
+ versions.append(pull_uint32(buf))
- versions.append(tls.pull_uint32(buf))
common = set(self.supported_versions).intersection(versions)
if not common:
self.__logger.error("Could not find a common protocol version")
return
self.version = QuicProtocolVersion(max(common))
self.__logger.info("Retrying with %s" % self.version)
self.connection_made()
return
elif self.is_client and header.packet_type == PACKET_TYPE_RETRY:
# stateless retry
if (
header.destination_cid == self.host_cid
and header.original_destination_cid == self.peer_cid
):
self.__logger.info("Performing stateless retry")
self.peer_cid = header.source_cid
self.peer_token = header.token
self.connection_made()
return
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
+ pull_bytes(buf, header.rest_length)
- tls.pull_bytes(buf, header.rest_length)
if not self.is_client and not self.__initialized:
self._initialize(header.destination_cid)
epoch = get_epoch(header.packet_type)
space = self.spaces[epoch]
try:
plain_header, plain_payload, packet_number = space.</s>
|
aioquic.connection/QuicConnection._write_close
|
Modified
|
aiortc~aioquic
|
5cba6a6fbd0120433619469286647a71df408fa0
|
[buffer] move basic buffer methods to aioquic.buffer
|
<6>:<add> push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<del> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<7>:<add> push_bytes(buf, self.peer_cid)
<del> tls.push_bytes(buf, self.peer_cid)
<8>:<add> push_uint16(buf, self.packet_number)
<del> tls.push_uint16(buf, self.packet_number)
<25>:<add> push_uint16(buf, length | 0x4000)
<del> tls.push_uint16(buf, length | 0x4000)
<26>:<add> push_uint16(buf, self.packet_number)
<del> tls.push_uint16(buf, self.packet_number)
|
# module: aioquic.connection
class QuicConnection:
def _write_close(self, epoch, error_code, frame_type, reason_phrase):
<0> assert epoch == tls.Epoch.ONE_RTT
<1> space = self.spaces[epoch]
<2>
<3> buf = Buffer(capacity=PACKET_MAX_SIZE)
<4>
<5> # write header
<6> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<7> tls.push_bytes(buf, self.peer_cid)
<8> tls.push_uint16(buf, self.packet_number)
<9> header_size = buf.tell()
<10>
<11> # write frame
<12> if frame_type is None:
<13> push_uint_var(buf, QuicFrameType.APPLICATION_CLOSE)
<14> packet.push_application_close_frame(buf, error_code, reason_phrase)
<15> else:
<16> push_uint_var(buf, QuicFrameType.TRANSPORT_CLOSE)
<17> packet.push_transport_close_frame(
<18> buf, error_code, frame_type, reason_phrase
<19> )
<20>
<21> # finalize length
<22> packet_size = buf.tell()
<23> buf.seek(header_size - SEND_PN_SIZE - 2)
<24> length = packet_size - header_size + 2 + space.crypto.aead_tag_size
<25> tls.push_uint16(buf, length | 0x4000)
<26> tls.push_uint16(buf, self.packet_number)
<27> buf.seek(packet_size)
<28>
<29> # encrypt
<30> data = buf.data
<31> yield space.crypto.encrypt_packet(
<32> data[0:header_size], data[header_size:packet_size]
<33> )
<34> self.packet_number += 1
<35>
|
===========unchanged ref 0===========
at: aioquic.buffer
Buffer(capacity=None, data=None)
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
push_uint_var(buf, value)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
push_transport_close_frame(buf, error_code, frame_type, reason_phrase)
push_application_close_frame(buf, error_code, reason_phrase)
at: aioquic.tls
Epoch()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
space = self.spaces[epoch]
send_ack = space.ack_queue if self.send_ack[epoch] else False
if not space.crypto.send.is_valid():
return
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
+ push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
- tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
+ push_bytes(buf, self.peer_cid)
- tls.push_bytes(buf, self.peer_cid)
+ push_uint16(buf, self.packet_number)
- tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# ACK
if send_ack:
push_uint_var(buf, QuicFrameType.ACK)
packet.push_ack_frame(buf, send_ack, 0)
self.send_ack[epoch] = False
# STREAM
for stream_id, stream in self.streams.items():
if isinstance(stream_id, int) and stream.has_data_to_send():
frame = stream.get_frame(
PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 6
)
push_uint_var(buf, QuicFrameType.STREAM_BASE + 0x07)
with push_stream_frame(buf, 0, frame.offset):
+ push_bytes(buf, frame.data)
- tls.push_bytes(buf, frame.data)
# encrypt
packet_size = buf.tell()
if packet_size > header_size:
data = buf.data
yield space.crypto.encrypt_packet(
data[0:header_size], data[header_size:packet_size</s>
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
# offset: 1
<s>
yield space.crypto.encrypt_packet(
data[0:header_size], data[header_size:packet_size]
)
self.packet_number += 1
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type != QuicFrameType.ACK:
is_ack_only = False
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
pass
elif frame_type == QuicFrameType.ACK:
packet.pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
stream = self.streams[epoch]
stream.add_frame(packet.pull_crypto_frame(buf))
data = stream.pull_data()
if data:
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_TOKEN:
packet.pull_new_token_frame(buf)
elif (frame_type & ~STREAM_FLAGS) == QuicFrameType.STREAM_BASE:
flags = frame_type & STREAM_FLAGS
stream_id = pull_uint_var(buf)
if flags & STREAM_FLAG_OFF:
offset = pull_uint_var(buf)
else:
offset = 0
if flags & STREAM_FLAG_LEN:
length = pull_uint_var(buf)
else:
length = buf.capacity - buf.tell()
+ frame = QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
- frame = QuicStreamFrame(offset=offset, data=tls.pull_bytes(buf, length))
stream = self._get_or_create_stream(stream_id)
stream.add_frame(frame)
elif frame_type == QuicFrameType.MAX_DATA:
pull_uint_var(buf)
elif frame_type in [
QuicFrameType.MAX_STREAMS_BIDI,
QuicFrameType.MAX_STREAMS_</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, epoch, plain):
# offset: 1
<s>type in [
QuicFrameType.MAX_STREAMS_BIDI,
QuicFrameType.MAX_STREAMS_UNI,
]:
pull_uint_var(buf)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
packet.pull_new_connection_id_frame(buf)
elif frame_type == QuicFrameType.TRANSPORT_CLOSE:
error_code, frame_type, reason_phrase = packet.pull_transport_close_frame(
buf
)
self.__logger.info(
"Transport close code 0x%X, reason %s" % (error_code, reason_phrase)
)
elif frame_type == QuicFrameType.APPLICATION_CLOSE:
error_code, reason_phrase = packet.pull_application_close_frame(buf)
self.__logger.info(
"Application close code 0x%X, reason %s"
% (error_code, reason_phrase)
)
else:
self.__logger.warning("unhandled frame type %d", frame_type)
break
self._push_crypto_data()
return is_ack_only
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
5cba6a6fbd0120433619469286647a71df408fa0
|
[buffer] move basic buffer methods to aioquic.buffer
|
<39>:<add> push_bytes(buf, frame.data)
<del> tls.push_bytes(buf, frame.data)
<43>:<add> push_bytes(
<del> tls.push_bytes(
|
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
<0> space = self.spaces[epoch]
<1> stream = self.streams[epoch]
<2> send_ack = space.ack_queue if self.send_ack[epoch] else False
<3> self.send_ack[epoch] = False
<4>
<5> buf = Buffer(capacity=PACKET_MAX_SIZE)
<6>
<7> while space.crypto.send.is_valid() and (send_ack or stream.has_data_to_send()):
<8> if epoch == tls.Epoch.INITIAL:
<9> packet_type = PACKET_TYPE_INITIAL
<10> else:
<11> packet_type = PACKET_TYPE_HANDSHAKE
<12>
<13> # write header
<14> push_quic_header(
<15> buf,
<16> QuicHeader(
<17> version=self.version,
<18> packet_type=packet_type | (SEND_PN_SIZE - 1),
<19> destination_cid=self.peer_cid,
<20> source_cid=self.host_cid,
<21> token=self.peer_token,
<22> ),
<23> )
<24> header_size = buf.tell()
<25>
<26> # ACK
<27> if send_ack:
<28> push_uint_var(buf, QuicFrameType.ACK)
<29> packet.push_ack_frame(buf, send_ack, 0)
<30> send_ack = False
<31>
<32> if stream.has_data_to_send():
<33> # CRYPTO
<34> frame = stream.get_frame(
<35> PACKET_MAX_SIZE - buf.tell() - space.crypto.aead_tag_size - 4
<36> )
<37> push_uint_var(buf, QuicFrameType.CRYPTO)
<38> with packet.push_crypto_frame(buf, frame.offset):
<39> tls.push_bytes(buf, frame.data)
<40>
<41> # PADDING
<42> if epoch == tls.Epoch.INITIAL and self.is_client:
<43> tls.push_bytes(
</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
bytes(
PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell()
),
)
# finalize length
packet_size = buf.tell()
buf.seek(header_size - SEND_PN_SIZE - 2)
length = packet_size - header_size + 2 + space.crypto.aead_tag_size
tls.push_uint16(buf, length | 0x4000)
tls.push_uint16(buf, self.packet_number)
buf.seek(packet_size)
# encrypt
data = buf.data
yield space.crypto.encrypt_packet(
data[0:header_size], data[header_size:packet_size]
)
self.packet_number += 1
buf.seek(0)
===========unchanged ref 0===========
at: aioquic.buffer
Buffer(capacity=None, data=None)
at: aioquic.buffer.Buffer
seek(pos)
tell()
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_token = b""
self.streams = {}
self.version = QuicProtocolVersion.DRAFT_20
at: aioquic.connection.QuicConnection._initialize
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.packet_number = 0
at: aioquic.connection.QuicConnection._write_application
self.packet_number += 1
at: aioquic.connection.QuicConnection._write_close
self.packet_number += 1
at: aioquic.connection.QuicConnection.datagram_received
self.version = QuicProtocolVersion(max(common))
self.peer_cid = header.source_cid
self.peer_token = header.token
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.aead_tag_size = 16
===========unchanged ref 1===========
self.send = CryptoContext()
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, original_destination_cid: bytes=b"", token: bytes=b"", rest_length: int=0)
push_uint_var(buf, value)
push_quic_header(buf, header)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_crypto_frame(buf, offset=0)
at: aioquic.tls
Epoch()
===========changed ref 0===========
+ # module: aioquic.buffer
+ class Buffer:
+ def tell(self):
+ return self._pos
+
===========changed ref 1===========
+ # module: aioquic.buffer
+ class Buffer:
+ @property
+ def data(self):
+ return bytes(self._data[: self._pos])
+
===========changed ref 2===========
+ # module: aioquic.buffer
+ class Buffer:
+ def seek(self, pos):
+ assert pos <= self._length
+ self._pos = pos
+
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _write_close(self, epoch, error_code, frame_type, reason_phrase):
assert epoch == tls.Epoch.ONE_RTT
space = self.spaces[epoch]
buf = Buffer(capacity=PACKET_MAX_SIZE)
# write header
+ push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
- tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
+ push_bytes(buf, self.peer_cid)
- tls.push_bytes(buf, self.peer_cid)
+ push_uint16(buf, self.packet_number)
- tls.push_uint16(buf, self.packet_number)
header_size = buf.tell()
# write frame
if frame_type is None:
push_uint_var(buf, QuicFrameType.APPLICATION_CLOSE)
packet.push_application_close_frame(buf, error_code, reason_phrase)
else:
push_uint_var(buf, QuicFrameType.TRANSPORT_CLOSE)
packet.push_transport_close_frame(
buf, error_code, frame_type, reason_phrase
)
# finalize length
packet_size = buf.tell()
buf.seek(header_size - SEND_PN_SIZE - 2)
length = packet_size - header_size + 2 + space.crypto.aead_tag_size
+ push_uint16(buf, length | 0x4000)
- tls.push_uint16(buf, length | 0x4000)
+ push_uint16(buf, self.packet_number)
- tls.push_uint16(buf, self.packet_number)
buf.seek(packet_size)
# encrypt
data = buf.data
yield space.crypto.encrypt_packet(
data[0:header_size], data[header_size:packet_size]
)
</s>
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def _write_close(self, epoch, error_code, frame_type, reason_phrase):
# offset: 1
<s>.encrypt_packet(
data[0:header_size], data[header_size:packet_size]
)
self.packet_number += 1
|
aioquic.stream/QuicStream.__init__
|
Modified
|
aiortc~aioquic
|
1e067acdbcfb6ae91769aad7c6ae8ad067ec86e3
|
[connection] Add connect() coroutine, rework transmission
|
<0>:<add> self._connection = connection
<add>
|
# module: aioquic.stream
class QuicStream:
+ def __init__(self, stream_id=None, connection=None):
- def __init__(self, stream_id=None):
<0> self._recv_buffer = bytearray()
<1> self._recv_start = 0
<2> self._recv_ranges = RangeSet()
<3>
<4> self._send_buffer = bytearray()
<5> self._send_start = 0
<6>
<7> self.__stream_id = stream_id
<8>
|
===========unchanged ref 0===========
at: aioquic.stream.QuicStream.add_frame
self._recv_buffer += bytearray(gap)
at: aioquic.stream.QuicStream.pull_data
self._recv_buffer = self._recv_buffer[pos:]
self._recv_start = r.stop
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.