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.datagram_received
|
Modified
|
aiortc~aioquic
|
2993d0a32ceacba976ba1c82ec7a32bab3829e29
|
[rangeset] add RangeSet class to track ACKs
|
<9>:<add> epoch = get_epoch(header.packet_type)
<del> crypto = self.crypto[get_epoch(header.packet_type)]
<10>:<add> crypto = self.crypto[epoch]
<add> plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
<del> plain_header, plain_payload = crypto.recv.decrypt_packet(
<12>:<add>
<13>:<add> is_ack_only = self.payload_received(plain_payload)
<add> self.ack[epoch].add(packet_number)
<add> if not is_ack_only:
<add> self.send_ack = True
<del> self.send_ack = True
<14>:<add> self.write_crypto()
<del> self.payload_received(plain_payload)
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
<0> buf = Buffer(data=data)
<1>
<2> while not buf.eof():
<3> start_off = buf.tell()
<4> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<5> encrypted_off = buf.tell() - start_off
<6> end_off = buf.tell() + header.rest_length
<7> tls.pull_bytes(buf, header.rest_length)
<8>
<9> crypto = self.crypto[get_epoch(header.packet_type)]
<10> plain_header, plain_payload = crypto.recv.decrypt_packet(
<11> data[start_off:end_off], encrypted_off)
<12> self.peer_cid = header.source_cid
<13> self.send_ack = True
<14> self.payload_received(plain_payload)
<15>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
write_crypto(self)
write_crypto()
at: aioquic.connection.QuicConnection.__init__
self.tls = tls.Context(is_client=True)
self.send_buffer = Buffer(capacity=4096)
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 __init__(self):
self.host_cid = b''
self.peer_cid = os.urandom(8)
- self.packet_number = 0
self.tls = tls.Context(is_client=True)
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.update_traffic_key_cb = self.update_traffic_key
self.send_buffer = Buffer(capacity=4096)
self.send_ack = False
self.send_datagrams = []
self.send_padding = True
+
+ self.ack = {
+ tls.Epoch.INITIAL: RangeSet(),
+ tls.Epoch.HANDSHAKE: RangeSet(),
+ tls.Epoch.ONE_RTT: RangeSet(),
+ }
self.crypto = {
tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
+ self.packet_number = {
+ tls.Epoch.INITIAL: 0,
+ tls.Epoch.HANDSHAKE: 0,
+ tls.Epoch.ONE_RTT: 0,
+ }
===========changed ref 1===========
+ # module: aioquic.rangeset
+
+
===========changed ref 2===========
+ # module: aioquic.rangeset
+ class RangeSet:
+ def __init__(self):
+ self.ranges = []
+
===========changed ref 3===========
+ # module: aioquic.rangeset
+ class RangeSet:
+ def __bool__(self):
+ return bool(self.ranges)
+
===========changed ref 4===========
# module: aioquic.packet
- @dataclass
- class QuickAckFrame:
- largest_acknowledged: int
- ack_delay: int
- first_ack_range: int
- ack_ranges: List[Tuple[int, int]]
-
===========changed ref 5===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_server(self):
pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
+ plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
+ SERVER_ENCRYPTED_PACKET, 17)
- plain_header, plain_payload = pair.recv.decrypt_packet(SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SERVER_PLAIN_PAYLOAD)
+ self.assertEqual(packet_number, 1)
===========changed ref 6===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_client(self):
pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
+ plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
+ CLIENT_ENCRYPTED_PACKET, 17)
- plain_header, plain_payload = pair.recv.decrypt_packet(CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, CLIENT_PLAIN_PAYLOAD)
+ self.assertEqual(packet_number, 2)
===========changed ref 7===========
+ # module: aioquic.rangeset
+ class RangeSet:
+ def add(self, pn):
+ for i, r in enumerate(self.ranges):
+ if pn in r:
+ return
+ if r.stop == pn:
+ if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
+ self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
+ self.ranges.pop(i + 1)
+ else:
+ self.ranges[i] = range(r.start, r.stop + 1)
+ return
+ if r.start == pn + 1:
+ self.ranges[i] = range(pn, r.stop)
+ return
+
+ self.ranges.append(range(pn, pn + 1))
+
===========changed ref 8===========
# 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 = pull_ack_frame(buf)
- ack = pull_ack_frame(buf)
+ self.assertEqual(rangeset.ranges, [
- self.assertEqual(ack.largest_acknowledged, 0)
+ range(0, 1)
+ ])
+ self.assertEqual(delay, 2)
- self.assertEqual(ack.ack_delay, 2)
- self.assertEqual(ack.first_ack_range, 0)
- self.assertEqual(ack.ack_ranges, [])
# serialize
buf = Buffer(capacity=8)
+ push_ack_frame(buf, rangeset, delay)
- push_ack_frame(buf, ack)
self.assertEqual(buf.data, data)
===========changed ref 9===========
# module: tests.test_packet
class FrameTest(TestCase):
def test_ack_frame_with_ranges(self):
+ data = b'\x05\x02\x01\x00\x02\x03'
- data = b'\x00\x02\x01\x00\x02\x03'
buf = Buffer(data=data)
+ rangeset, delay = pull_ack_frame(buf)
- ack = pull_ack_frame(buf)
+ self.assertEqual(rangeset.ranges, [
- self.assertEqual(ack.largest_acknowledged, 0)
+ range(0, 4),
+ range(5, 6)
+ ])
+ self.assertEqual(delay, 2)
- self.assertEqual(ack.ack_delay, 2)
- self.assertEqual(ack.first_ack_range, 0)
- self.assertEqual(ack.ack_ranges, [(2, 3)])
buf = Buffer(capacity=8)
+ push_ack_frame(buf, rangeset, delay)
- push_ack_frame(buf, ack)
self.assertEqual(buf.data, data)
|
aioquic.connection/QuicConnection.payload_received
|
Modified
|
aiortc~aioquic
|
2993d0a32ceacba976ba1c82ec7a32bab3829e29
|
[rangeset] add RangeSet class to track ACKs
|
<2>:<add> is_ack_only = True
<4>:<add> if frame_type == QuicFrameType.PADDING:
<add> pass
<add> elif frame_type == QuicFrameType.ACK:
<del> if frame_type == QuicFrameType.ACK:
<7>:<add> is_ack_only = False
<10>:<del> self.write_crypto()
<14>:<add> return is_ack_only
|
# module: aioquic.connection
class QuicConnection:
def payload_received(self, plain):
<0> buf = Buffer(data=plain)
<1>
<2> while not buf.eof():
<3> frame_type = pull_uint_var(buf)
<4> if frame_type == QuicFrameType.ACK:
<5> pull_ack_frame(buf)
<6> elif frame_type == QuicFrameType.CRYPTO:
<7> data = pull_crypto_frame(buf)
<8> assert len(data)
<9> self.tls.handle_message(data, self.send_buffer)
<10> self.write_crypto()
<11> else:
<12> logger.warning('unhandled frame type %d', frame_type)
<13> break
<14>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.QuicConnection
payload_received(plain)
payload_received(self, plain)
write_crypto(self)
write_crypto()
at: aioquic.connection.QuicConnection.__init__
self.peer_cid = os.urandom(8)
self.send_ack = False
self.crypto = {
tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.ack = {
tls.Epoch.INITIAL: RangeSet(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
}
at: aioquic.connection.QuicConnection.datagram_received
buf = Buffer(data=data)
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
at: aioquic.connection.QuicConnection.write_crypto
self.send_ack = False
at: aioquic.crypto.CryptoContext
decrypt_packet(packet, encrypted_offset)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
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(pn)
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
at: aioquic.tls.Buffer
tell()
===========changed ref 0===========
+ # module: aioquic.rangeset
+ class RangeSet:
+ def add(self, pn):
+ for i, r in enumerate(self.ranges):
+ if pn in r:
+ return
+ if r.stop == pn:
+ if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
+ self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
+ self.ranges.pop(i + 1)
+ else:
+ self.ranges[i] = range(r.start, r.stop + 1)
+ return
+ if r.start == pn + 1:
+ self.ranges[i] = range(pn, r.stop)
+ return
+
+ self.ranges.append(range(pn, pn + 1))
+
===========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 + 16]
encryptor = self.hp.encryptor()
buf = bytearray(31)
encryptor.update_into(sample, buf)
mask = buf[:5]
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
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
+ epoch = get_epoch(header.packet_type)
- crypto = self.crypto[get_epoch(header.packet_type)]
+ crypto = self.crypto[epoch]
+ plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
- plain_header, plain_payload = crypto.recv.decrypt_packet(
data[start_off:end_off], encrypted_off)
+
self.peer_cid = header.source_cid
+ is_ack_only = self.payload_received(plain_payload)
+ self.ack[epoch].add(packet_number)
+ if not is_ack_only:
+ self.send_ack = True
- self.send_ack = True
+ self.write_crypto()
- self.payload_received(plain_payload)
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def __init__(self):
self.host_cid = b''
self.peer_cid = os.urandom(8)
- self.packet_number = 0
self.tls = tls.Context(is_client=True)
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.update_traffic_key_cb = self.update_traffic_key
self.send_buffer = Buffer(capacity=4096)
self.send_ack = False
self.send_datagrams = []
self.send_padding = True
+
+ self.ack = {
+ tls.Epoch.INITIAL: RangeSet(),
+ tls.Epoch.HANDSHAKE: RangeSet(),
+ tls.Epoch.ONE_RTT: RangeSet(),
+ }
self.crypto = {
tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
+ self.packet_number = {
+ tls.Epoch.INITIAL: 0,
+ tls.Epoch.HANDSHAKE: 0,
+ tls.Epoch.ONE_RTT: 0,
+ }
===========changed ref 4===========
+ # module: aioquic.rangeset
+
+
===========changed ref 5===========
+ # module: aioquic.rangeset
+ class RangeSet:
+ def __init__(self):
+ self.ranges = []
+
===========changed ref 6===========
+ # module: aioquic.rangeset
+ class RangeSet:
+ def __bool__(self):
+ return bool(self.ranges)
+
===========changed ref 7===========
# module: aioquic.packet
- @dataclass
- class QuickAckFrame:
- largest_acknowledged: int
- ack_delay: int
- first_ack_range: int
- ack_ranges: List[Tuple[int, int]]
-
|
aioquic.connection/QuicConnection.write_crypto
|
Modified
|
aiortc~aioquic
|
2993d0a32ceacba976ba1c82ec7a32bab3829e29
|
[rangeset] add RangeSet class to track ACKs
|
<9>:<add> epoch = get_epoch(packet_type)
<add> crypto = self.crypto[epoch]
<del> crypto = self.crypto[get_epoch(packet_type)]
<36>:<add> push_ack_frame(buf, self.ack[epoch], 0)
<del> tls.push_bytes(buf, binascii.unhexlify('01000001'))
|
# module: aioquic.connection
class QuicConnection:
def write_crypto(self):
<0> if not self.send_buffer.tell():
<1> return
<2>
<3> buf = Buffer(capacity=PACKET_MAX_SIZE)
<4>
<5> if self.send_padding:
<6> packet_type = PACKET_TYPE_INITIAL
<7> else:
<8> packet_type = PACKET_TYPE_HANDSHAKE
<9> crypto = self.crypto[get_epoch(packet_type)]
<10>
<11> # write header
<12> push_quic_header(buf, QuicHeader(
<13> version=PROTOCOL_VERSION_DRAFT_17,
<14> packet_type=packet_type | (SEND_PN_SIZE - 1),
<15> destination_cid=self.peer_cid,
<16> source_cid=self.host_cid,
<17> ))
<18> header_size = buf.tell()
<19>
<20> # CRYPTO
<21> push_uint_var(buf, QuicFrameType.CRYPTO)
<22> with push_crypto_frame(buf):
<23> tls.push_bytes(buf, self.send_buffer.data)
<24> self.send_buffer.seek(0)
<25>
<26> # PADDING
<27> if self.send_padding:
<28> tls.push_bytes(
<29> buf,
<30> bytes(PACKET_MAX_SIZE - crypto.send.aead_tag_size - buf.tell()))
<31> self.send_padding = False
<32>
<33> # ACK
<34> if self.send_ack:
<35> push_uint_var(buf, QuicFrameType.ACK)
<36> tls.push_bytes(buf, binascii.unhexlify('01000001'))
<37> self.send_ack = False
<38>
<39> # finalize length
<40> packet_size = buf.tell()
<41> buf.seek(header_size - SEND_PN_SIZE - 2)
<42> length = packet_size - header_size + 2 + crypto.send.aead_tag_size
<43> tls.push_uint16(buf, length | 0x4000</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def write_crypto(self):
# offset: 1
tls.push_uint16(buf, self.packet_number)
buf.seek(packet_size)
# encrypt
data = buf.data
self.send_datagrams.append(
crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size]))
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
get_epoch(packet_type)
QuicFrameType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
QuicFrameType(x: Union[str, bytes, bytearray], base: int)
at: aioquic.connection.QuicConnection.__init__
self.host_cid = b''
self.peer_cid = os.urandom(8)
self.tls = tls.Context(is_client=True)
self.send_buffer = Buffer(capacity=4096)
self.send_padding = True
self.crypto = {
tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PROTOCOL_VERSION_DRAFT_17 = 0xff000011 # draft 17
QuicHeader(version: int, packet_type: int, destination_cid: bytes, source_cid: bytes, token: bytes=b'', rest_length: int=0)
pull_uint_var(buf)
push_uint_var(buf, value)
push_quic_header(buf, header)
pull_ack_frame(buf)
pull_crypto_frame(buf)
push_crypto_frame(buf, offset=0)
at: aioquic.tls
Buffer(capacity=None, data=None)
===========unchanged ref 1===========
push_bytes(buf: Buffer, v: bytes)
at: aioquic.tls.Buffer
eof()
seek(pos)
tell()
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.packet
def pull_ack_frame(buf):
+ rangeset = RangeSet()
+ end = pull_uint_var(buf) # largest acknowledged
- largest_acknowledged = pull_uint_var(buf)
+ delay = pull_uint_var(buf)
- ack_delay = pull_uint_var(buf)
ack_range_count = pull_uint_var(buf)
- first_ack_range = pull_uint_var(buf)
- ack = QuickAckFrame(
- largest_acknowledged=largest_acknowledged,
- ack_delay=ack_delay,
- first_ack_range=first_ack_range,
- ack_ranges=[])
+ ack_count = pull_uint_var(buf) # first ack range
+ rangeset.ranges.insert(0, range(end - ack_count, end + 1))
+ end -= ack_count
for _ in range(ack_range_count):
- ack.ack_ranges.append((
+ end -= pull_uint_var(buf)
- pull_uint_var(buf),
+ ack_count = pull_uint_var(buf)
- pull_uint_var(buf)))
+ rangeset.ranges.insert(0, range(end - ack_count, end + 1))
+ end -= ack_count
+ return rangeset, delay
- return ack
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def payload_received(self, plain):
buf = Buffer(data=plain)
+ is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
+ if frame_type == QuicFrameType.PADDING:
+ pass
+ elif frame_type == QuicFrameType.ACK:
- if frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
+ is_ack_only = False
data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
- self.write_crypto()
else:
logger.warning('unhandled frame type %d', frame_type)
break
+ return is_ack_only
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
encrypted_off = buf.tell() - start_off
end_off = buf.tell() + header.rest_length
tls.pull_bytes(buf, header.rest_length)
+ epoch = get_epoch(header.packet_type)
- crypto = self.crypto[get_epoch(header.packet_type)]
+ crypto = self.crypto[epoch]
+ plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
- plain_header, plain_payload = crypto.recv.decrypt_packet(
data[start_off:end_off], encrypted_off)
+
self.peer_cid = header.source_cid
+ is_ack_only = self.payload_received(plain_payload)
+ self.ack[epoch].add(packet_number)
+ if not is_ack_only:
+ self.send_ack = True
- self.send_ack = True
+ self.write_crypto()
- self.payload_received(plain_payload)
|
aioquic.crypto/CryptoPair.initial
|
Modified
|
aiortc~aioquic
|
bb92d0fbc0abed62e1de9302e35c6dbddfffae77
|
[connection] send data for different epochs
|
<1>:<del> pair.recv.setup_initial(cid, not is_client)
<2>:<add> pair.setup_initial(cid, is_client)
<del> pair.send.setup_initial(cid, is_client)
|
# module: aioquic.crypto
class CryptoPair:
@classmethod
def initial(cls, cid, is_client):
<0> pair = cls()
<1> pair.recv.setup_initial(cid, not is_client)
<2> pair.send.setup_initial(cid, is_client)
<3> return pair
<4>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoContext.setup
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 0===========
# module: aioquic.crypto
class CryptoContext:
+ def is_valid(self):
+ return self.aead is not None
+
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
+ def teardown(self):
+ self.aead = None
+ self.hp = None
+ self.iv = None
+
===========changed ref 2===========
# module: aioquic.crypto
class CryptoContext:
+ def __init__(self):
+ self.teardown()
+
===========changed ref 3===========
# module: aioquic.packet
- @dataclass
- class QuicShortHeader:
- packet_type: int
- destination_cid: bytes
-
===========changed ref 4===========
# module: aioquic.packet
+ # FRAMES
+
+
+ class QuicFrameType(IntEnum):
+ PADDING = 0
+ PING = 1
+ ACK = 2
+ ACK_WITH_ECN = 3
+ RESET_STREAM = 4
+ STOP_SENDING = 5
+ CRYPTO = 6
+ NEW_CONNECTION_ID = 0x18
+
===========changed ref 5===========
# module: aioquic.packet
+ def push_new_connection_id_frame(buf, sequence_number, connection_id, stateless_reset_token):
+ assert len(stateless_reset_token) == 16
+ push_uint_var(buf, sequence_number)
+ push_uint8(buf, len(connection_id))
+ push_bytes(buf, connection_id)
+ push_bytes(buf, stateless_reset_token)
+
===========changed ref 6===========
# module: aioquic.packet
+ def pull_new_connection_id_frame(buf):
+ sequence_number = pull_uint_var(buf)
+ length = pull_uint8(buf)
+ connection_id = pull_bytes(buf, length)
+ stateless_reset_token = pull_bytes(buf, 16)
+ return (sequence_number, connection_id, stateless_reset_token)
+
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
bb92d0fbc0abed62e1de9302e35c6dbddfffae77
|
[connection] send data for different epochs
|
<0>:<add> if not is_client:
<add> assert certificate is not None, 'SSL certificate is required'
<add> assert private_key is not None, 'SSL private key is required'
<add>
<add> self.is_client = is_client
<add> self.host_cid = os.urandom(8)
<del> self.host_cid = b''
<2>:<add> self.peer_cid_set = False
<add> self.tls = tls.Context(is_client=is_client)
<del> self.tls = tls.Context(is_client=True)
<3>:<add> if is_client:
<add> self.tls.handshake_extensions.append(
<del> self.tls.handshake_extensions.append(
<4>:<add> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<5>:<add> )
<del> )
<6>:<add> else:
<add> self.tls.handshake_extensions.append(
<add> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<add> )
<add> self.tls.certificate = certificate
<add> self.tls.certificate_private_key = private_key
<add>
<add> self.tls.update_traffic_
|
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None):
- def __init__(self):
<0> self.host_cid = b''
<1> self.peer_cid = os.urandom(8)
<2> self.tls = tls.Context(is_client=True)
<3> self.tls.handshake_extensions.append(
<4> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<5> )
<6> self.tls.update_traffic_key_cb = self.update_traffic_key
<7>
<8> self.send_buffer = Buffer(capacity=4096)
<9> self.send_ack = False
<10> self.send_datagrams = []
<11> self.send_padding = True
<12>
<13> self.ack = {
<14> tls.Epoch.INITIAL: RangeSet(),
<15> tls.Epoch.HANDSHAKE: RangeSet(),
<16> tls.Epoch.ONE_RTT: RangeSet(),
<17> }
<18> self.crypto = {
<19> tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
<20> tls.Epoch.HANDSHAKE: CryptoPair(),
<21> tls.Epoch.ONE_RTT: CryptoPair(),
<22> }
<23> self.packet_number = {
<24> tls.Epoch.INITIAL: 0,
<25> tls.Epoch.HANDSHAKE: 0,
<26> tls.Epoch.ONE_RTT: 0,
<27> }
<28>
|
===========unchanged ref 0===========
at: aioquic.connection
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
at: aioquic.connection.QuicConnection
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection._write_application
self.send_ack = False
at: aioquic.connection.QuicConnection._write_handshake
self.send_ack = False
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
self.peer_cid_set = True
self.send_ack = True
at: aioquic.crypto
CryptoPair()
at: aioquic.rangeset
RangeSet()
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)
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
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.connection
- class QuicFrameType(IntEnum):
- PADDING = 0
- PING = 1
- ACK = 2
- ACK_WITH_ECN = 3
- RESET_STREAM = 4
- STOP_SENDING = 5
- CRYPTO = 6
-
===========changed ref 1===========
# module: aioquic.connection
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
+ SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
+ b'ff00001104ff000011004500050004801000000006000480100000000700048'
+ b'010000000040004810000000001000242580002001000000000000000000000'
+ b'000000000000000800024064000a00010a')
+
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
===========changed ref 2===========
# module: aioquic.crypto
class CryptoContext:
+ def __init__(self):
+ self.teardown()
+
===========changed ref 3===========
# module: aioquic.crypto
class CryptoContext:
+ def is_valid(self):
+ return self.aead is not None
+
===========changed ref 4===========
# module: aioquic.packet
- @dataclass
- class QuicShortHeader:
- packet_type: int
- destination_cid: bytes
-
===========changed ref 5===========
# module: aioquic.crypto
class CryptoContext:
+ def teardown(self):
+ self.aead = None
+ self.hp = None
+ self.iv = None
+
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
+ def setup_initial(self, cid, is_client):
+ self.recv.setup_initial(cid, not is_client)
+ self.send.setup_initial(cid, is_client)
+
===========changed ref 7===========
# module: aioquic.crypto
class CryptoPair:
@classmethod
def initial(cls, cid, is_client):
pair = cls()
- pair.recv.setup_initial(cid, not is_client)
+ pair.setup_initial(cid, is_client)
- pair.send.setup_initial(cid, is_client)
return pair
===========changed ref 8===========
# module: aioquic.packet
+ # FRAMES
+
+
+ class QuicFrameType(IntEnum):
+ PADDING = 0
+ PING = 1
+ ACK = 2
+ ACK_WITH_ECN = 3
+ RESET_STREAM = 4
+ STOP_SENDING = 5
+ CRYPTO = 6
+ NEW_CONNECTION_ID = 0x18
+
===========changed ref 9===========
# module: aioquic.packet
+ def push_new_connection_id_frame(buf, sequence_number, connection_id, stateless_reset_token):
+ assert len(stateless_reset_token) == 16
+ push_uint_var(buf, sequence_number)
+ push_uint8(buf, len(connection_id))
+ push_bytes(buf, connection_id)
+ push_bytes(buf, stateless_reset_token)
+
===========changed ref 10===========
# module: aioquic.packet
+ def pull_new_connection_id_frame(buf):
+ sequence_number = pull_uint_var(buf)
+ length = pull_uint8(buf)
+ connection_id = pull_bytes(buf, length)
+ stateless_reset_token = pull_bytes(buf, 16)
+ return (sequence_number, connection_id, stateless_reset_token)
+
|
aioquic.connection/QuicConnection.connection_made
|
Modified
|
aiortc~aioquic
|
bb92d0fbc0abed62e1de9302e35c6dbddfffae77
|
[connection] send data for different epochs
|
<0>:<add> if self.is_client:
<add> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
<add> is_client=self.is_client)
<add> self.crypto_initialized = True
<del> self.tls.handle_message(b'', self.send_buffer)
<1>:<del> self.write_crypto()
|
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
<0> self.tls.handle_message(b'', self.send_buffer)
<1> self.write_crypto()
<2>
|
===========unchanged ref 0===========
at: aioquic.tls
Epoch()
===========changed ref 0===========
# module: aioquic.connection
- class QuicFrameType(IntEnum):
- PADDING = 0
- PING = 1
- ACK = 2
- ACK_WITH_ECN = 3
- RESET_STREAM = 4
- STOP_SENDING = 5
- CRYPTO = 6
-
===========changed ref 1===========
# module: aioquic.connection
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
+ SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
+ b'ff00001104ff000011004500050004801000000006000480100000000700048'
+ b'010000000040004810000000001000242580002001000000000000000000000'
+ b'000000000000000800024064000a00010a')
+
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None):
- def __init__(self):
+ 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.is_client = is_client
+ self.host_cid = os.urandom(8)
- self.host_cid = b''
self.peer_cid = os.urandom(8)
+ self.peer_cid_set = False
+ self.tls = tls.Context(is_client=is_client)
- self.tls = tls.Context(is_client=True)
+ if is_client:
+ self.tls.handshake_extensions.append(
- self.tls.handshake_extensions.append(
+ (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
+ )
- )
+ else:
+ self.tls.handshake_extensions.append(
+ (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
+ )
+ self.tls.certificate = certificate
+ self.tls.certificate_private_key = private_key
+
+ self.tls.update_traffic_key_cb = self._update_traffic_key
- self.tls.update_traffic_key_cb = self.update_traffic_key
self.send_buffer = Buffer(capacity=4096)
self.send_ack = False
- self.send_datagrams = []
- self.send_padding = True
self.ack = {
tls.Epoch.INITIAL: RangeSet(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None):
- def __init__(self):
# offset: 1
<s>Set(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
}
self.crypto = {
+ tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
===========changed ref 4===========
# module: aioquic.crypto
class CryptoContext:
+ def __init__(self):
+ self.teardown()
+
===========changed ref 5===========
# module: aioquic.crypto
class CryptoContext:
+ def is_valid(self):
+ return self.aead is not None
+
===========changed ref 6===========
# module: aioquic.packet
- @dataclass
- class QuicShortHeader:
- packet_type: int
- destination_cid: bytes
-
===========changed ref 7===========
# module: aioquic.crypto
class CryptoContext:
+ def teardown(self):
+ self.aead = None
+ self.hp = None
+ self.iv = None
+
===========changed ref 8===========
# module: aioquic.crypto
class CryptoPair:
+ def setup_initial(self, cid, is_client):
+ self.recv.setup_initial(cid, not is_client)
+ self.send.setup_initial(cid, is_client)
+
===========changed ref 9===========
# module: aioquic.crypto
class CryptoPair:
@classmethod
def initial(cls, cid, is_client):
pair = cls()
- pair.recv.setup_initial(cid, not is_client)
+ pair.setup_initial(cid, is_client)
- pair.send.setup_initial(cid, is_client)
return pair
===========changed ref 10===========
# module: aioquic.packet
+ # FRAMES
+
+
+ class QuicFrameType(IntEnum):
+ PADDING = 0
+ PING = 1
+ ACK = 2
+ ACK_WITH_ECN = 3
+ RESET_STREAM = 4
+ STOP_SENDING = 5
+ CRYPTO = 6
+ NEW_CONNECTION_ID = 0x18
+
===========changed ref 11===========
# module: aioquic.packet
+ def push_new_connection_id_frame(buf, sequence_number, connection_id, stateless_reset_token):
+ assert len(stateless_reset_token) == 16
+ push_uint_var(buf, sequence_number)
+ push_uint8(buf, len(connection_id))
+ push_bytes(buf, connection_id)
+ push_bytes(buf, stateless_reset_token)
+
===========changed ref 12===========
# module: aioquic.packet
+ def pull_new_connection_id_frame(buf):
+ sequence_number = pull_uint_var(buf)
+ length = pull_uint8(buf)
+ connection_id = pull_bytes(buf, length)
+ stateless_reset_token = pull_bytes(buf, 16)
+ return (sequence_number, connection_id, stateless_reset_token)
+
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
bb92d0fbc0abed62e1de9302e35c6dbddfffae77
|
[connection] send data for different epochs
|
<9>:<add> if not self.is_client and not self.crypto_initialized:
<add> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
<add> is_client=self.is_client)
<add> self.crypto_initialized = True
<add>
<14>:<add> if not self.peer_cid_set:
<add> self.peer_cid = header.source_cid
<del> self.peer_cid = header.source_cid
<15>:<add> self.peer_cid_set = True
<add>
<add> is_ack_only = self._payload_received(plain_payload)
<del> is_ack_only = self.payload_received(plain_payload)
<19>:<del> self.write_crypto()
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
<0> buf = Buffer(data=data)
<1>
<2> while not buf.eof():
<3> start_off = buf.tell()
<4> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<5> encrypted_off = buf.tell() - start_off
<6> end_off = buf.tell() + header.rest_length
<7> tls.pull_bytes(buf, header.rest_length)
<8>
<9> epoch = get_epoch(header.packet_type)
<10> crypto = self.crypto[epoch]
<11> plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
<12> data[start_off:end_off], encrypted_off)
<13>
<14> self.peer_cid = header.source_cid
<15> is_ack_only = self.payload_received(plain_payload)
<16> self.ack[epoch].add(packet_number)
<17> if not is_ack_only:
<18> self.send_ack = True
<19> self.write_crypto()
<20>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.tls = tls.Context(is_client=is_client)
self.send_buffer = Buffer(capacity=4096)
self.crypto = {
tls.Epoch.INITIAL: CryptoPair(),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
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.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
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.crypto
class CryptoPair:
+ def setup_initial(self, cid, is_client):
+ self.recv.setup_initial(cid, not is_client)
+ self.send.setup_initial(cid, is_client)
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
+ if self.is_client:
+ self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
+ self.crypto_initialized = True
- self.tls.handle_message(b'', self.send_buffer)
- self.write_crypto()
===========changed ref 2===========
# module: aioquic.connection
- class QuicFrameType(IntEnum):
- PADDING = 0
- PING = 1
- ACK = 2
- ACK_WITH_ECN = 3
- RESET_STREAM = 4
- STOP_SENDING = 5
- CRYPTO = 6
-
===========changed ref 3===========
# module: aioquic.connection
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
+ SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
+ b'ff00001104ff000011004500050004801000000006000480100000000700048'
+ b'010000000040004810000000001000242580002001000000000000000000000'
+ b'000000000000000800024064000a00010a')
+
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None):
- def __init__(self):
+ 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.is_client = is_client
+ self.host_cid = os.urandom(8)
- self.host_cid = b''
self.peer_cid = os.urandom(8)
+ self.peer_cid_set = False
+ self.tls = tls.Context(is_client=is_client)
- self.tls = tls.Context(is_client=True)
+ if is_client:
+ self.tls.handshake_extensions.append(
- self.tls.handshake_extensions.append(
+ (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
+ )
- )
+ else:
+ self.tls.handshake_extensions.append(
+ (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
+ )
+ self.tls.certificate = certificate
+ self.tls.certificate_private_key = private_key
+
+ self.tls.update_traffic_key_cb = self._update_traffic_key
- self.tls.update_traffic_key_cb = self.update_traffic_key
self.send_buffer = Buffer(capacity=4096)
self.send_ack = False
- self.send_datagrams = []
- self.send_padding = True
self.ack = {
tls.Epoch.INITIAL: RangeSet(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
</s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None):
- def __init__(self):
# offset: 1
<s>Set(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
}
self.crypto = {
+ tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.INITIAL: CryptoPair.initial(cid=self.peer_cid, is_client=True),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
===========changed ref 6===========
# module: aioquic.crypto
class CryptoContext:
+ def __init__(self):
+ self.teardown()
+
===========changed ref 7===========
# module: aioquic.crypto
class CryptoContext:
+ def is_valid(self):
+ return self.aead is not None
+
===========changed ref 8===========
# module: aioquic.packet
- @dataclass
- class QuicShortHeader:
- packet_type: int
- destination_cid: bytes
-
===========changed ref 9===========
# module: aioquic.crypto
class CryptoContext:
+ def teardown(self):
+ self.aead = None
+ self.hp = None
+ self.iv = None
+
===========changed ref 10===========
# module: aioquic.crypto
class CryptoPair:
@classmethod
def initial(cls, cid, is_client):
pair = cls()
- pair.recv.setup_initial(cid, not is_client)
+ pair.setup_initial(cid, is_client)
- pair.send.setup_initial(cid, is_client)
return pair
===========changed ref 11===========
# module: aioquic.packet
+ # FRAMES
+
+
+ class QuicFrameType(IntEnum):
+ PADDING = 0
+ PING = 1
+ ACK = 2
+ ACK_WITH_ECN = 3
+ RESET_STREAM = 4
+ STOP_SENDING = 5
+ CRYPTO = 6
+ NEW_CONNECTION_ID = 0x18
+
|
aioquic.tls/Context.handle_message
|
Modified
|
aiortc~aioquic
|
435015718f55909188a3b0e1f4d2291216de76ec
|
[tls] consume NewSessionTicket message
|
<7>:<add> message_type = self._receive_buffer[0]
<29>:<add> elif self.state == State.CLIENT_POST_HANDSHAKE:
<add> if message_type == HandshakeType.NEW_SESSION_TICKET:
<add> self._client_handle_new_session_ticket(input_buf, output_buf)
<add> else:
<add> raise AlertUnexpectedMessage
<add>
|
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
<0> if not input_data:
<1> self._client_send_hello(output_buf)
<2> return
<3>
<4> self._receive_buffer += input_data
<5> while len(self._receive_buffer) >= 4:
<6> # determine message length
<7> message_length = 0
<8> for b in self._receive_buffer[1:4]:
<9> message_length = (message_length << 8) | b
<10> message_length += 4
<11>
<12> # check message is complete
<13> if len(self._receive_buffer) < message_length:
<14> break
<15> message = self._receive_buffer[:message_length]
<16> self._receive_buffer = self._receive_buffer[message_length:]
<17>
<18> input_buf = Buffer(data=message)
<19> if self.state == State.CLIENT_EXPECT_SERVER_HELLO:
<20> self._client_handle_hello(input_buf, output_buf)
<21> elif self.state == State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS:
<22> self._client_handle_encrypted_extensions(input_buf, output_buf)
<23> elif self.state == State.CLIENT_EXPECT_CERTIFICATE_REQUEST_OR_CERTIFICATE:
<24> self._client_handle_certificate(input_buf, output_buf)
<25> elif self.state == State.CLIENT_EXPECT_CERTIFICATE_VERIFY:
<26> self._client_handle_certificate_verify(input_buf, output_buf)
<27> elif self.state == State.CLIENT_EXPECT_FINISHED:
<28> self._client_handle_finished(input_buf, output_buf)
<29> elif self.state == State.SERVER_EXPECT_CLIENT_HELLO:
<30> self._server_handle_hello(input_buf, output_buf)
<31> elif self.state == State.SERVER_EXPECT_FINISHED:
<32> self._server_handle_finished(input_buf, output_buf)
<33> </s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 1
raise Exception('unhandled state')
assert input_buf.eof()
===========unchanged ref 0===========
at: aioquic.tls
State()
at: aioquic.tls.Context
_client_send_hello(output_buf)
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: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
+ @dataclass
+ class NewSessionTicket:
+ lifetime_hint: int = 0
+ ticket: bytes = b''
+
===========changed ref 1===========
# module: aioquic.tls
+ def pull_new_session_ticket(buf: Buffer) -> NewSessionTicket:
+ new_session_ticket = NewSessionTicket()
+
+ assert pull_uint8(buf) == HandshakeType.NEW_SESSION_TICKET
+ with pull_block(buf, 3) as length:
+ new_session_ticket.lifetime_hint = pull_uint32(buf)
+ new_session_ticket.ticket = pull_bytes(buf, length - 4)
+
+ return new_session_ticket
+
===========changed ref 2===========
# module: aioquic.tls
+ class AlertUnexpectedMessage(Exception):
+ pass
+
|
aioquic.tls/Context.handle_message
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<0>:<add> if self.state == State.CLIENT_HANDSHAKE_START:
<del> if not input_data:
<1>:<add> self._client_send_hello(output_buf[Epoch.INITIAL])
<del> self._client_send_hello(output_buf)
<20>:<add>
<add> # client states
<add>
<21>:<add> if message_type == HandshakeType.SERVER_HELLO:
<add> self._client_handle_hello(input_buf, output_buf[Epoch.INITIAL])
<del> self._client_handle_hello(input_buf, output_buf)
<22>:<add> else:
<add> raise AlertUnexpectedMessage
<23>:<add> if message_type == HandshakeType.ENCRYPTED_EXTENSIONS:
<add> self._client_handle_encrypted_extensions(input_buf)
<del> self._client_handle_encrypted_extensions(input_buf, output_buf)
<24>:<add> else:
<add> raise AlertUnexpectedMessage
<25>:<add> if message_type == HandshakeType.CERTIFICATE:
<add> self._client_handle_certificate(input_buf)
<del> self._client_handle_certificate(input_buf, output_buf)
<26>:<add> else:
<add> # FIXME: handle certificate request
<add> raise AlertUnexpectedMessage
<27>:<add> if message_type == HandshakeType.CERTIFICATE_VERIFY:
<add> self._client_handle_certificate_verify(
|
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
<0> if not input_data:
<1> self._client_send_hello(output_buf)
<2> return
<3>
<4> self._receive_buffer += input_data
<5> while len(self._receive_buffer) >= 4:
<6> # determine message length
<7> message_type = self._receive_buffer[0]
<8> message_length = 0
<9> for b in self._receive_buffer[1:4]:
<10> message_length = (message_length << 8) | b
<11> message_length += 4
<12>
<13> # check message is complete
<14> if len(self._receive_buffer) < message_length:
<15> break
<16> message = self._receive_buffer[:message_length]
<17> self._receive_buffer = self._receive_buffer[message_length:]
<18>
<19> input_buf = Buffer(data=message)
<20> if self.state == State.CLIENT_EXPECT_SERVER_HELLO:
<21> self._client_handle_hello(input_buf, output_buf)
<22> elif self.state == State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS:
<23> self._client_handle_encrypted_extensions(input_buf, output_buf)
<24> elif self.state == State.CLIENT_EXPECT_CERTIFICATE_REQUEST_OR_CERTIFICATE:
<25> self._client_handle_certificate(input_buf, output_buf)
<26> elif self.state == State.CLIENT_EXPECT_CERTIFICATE_VERIFY:
<27> self._client_handle_certificate_verify(input_buf, output_buf)
<28> elif self.state == State.CLIENT_EXPECT_FINISHED:
<29> self._client_handle_finished(input_buf, output_buf)
<30> elif self.state == State.CLIENT_POST_HANDSHAKE:
<31> if message_type == HandshakeType.NEW_SESSION_TICKET:
<32> self._client_handle_new_session_ticket(input_buf, output_buf)
<33> else:
</s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 1
elif self.state == State.SERVER_EXPECT_CLIENT_HELLO:
self._server_handle_hello(input_buf, output_buf)
elif self.state == State.SERVER_EXPECT_FINISHED:
self._server_handle_finished(input_buf, output_buf)
else:
raise Exception('unhandled state')
assert input_buf.eof()
===========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)
Buffer(capacity=None, data=None)
at: aioquic.tls.Context
_client_send_hello(output_buf)
_client_handle_hello(input_buf, output_buf)
_client_handle_encrypted_extensions(input_buf)
_client_handle_certificate(input_buf)
_client_handle_certificate_verify(input_buf)
at: aioquic.tls.Context.__init__
self._receive_buffer = b''
self.state = State.CLIENT_HANDSHAKE_START
self.state = State.SERVER_EXPECT_CLIENT_HELLO
at: aioquic.tls.Context._set_state
self.state = state
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<22>:<del> self.send_buffer = Buffer(capacity=4096)
<23>:<del> self.send_ack = False
<24>:<del>
<40>:<add> self.send_ack = {
<add> tls.Epoch.INITIAL: False,
<add> tls.Epoch.HANDSHAKE: False,
<add> tls.Epoch.ONE_RTT: False,
<add> }
<add> self.send_buffer = {
<add> tls.Epoch.INITIAL: Buffer(capacity=4096),
<add> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<add> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<add> }
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
<5> self.host_cid = os.urandom(8)
<6> self.peer_cid = os.urandom(8)
<7> self.peer_cid_set = False
<8> self.tls = tls.Context(is_client=is_client)
<9> if is_client:
<10> self.tls.handshake_extensions.append(
<11> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<12> )
<13> else:
<14> self.tls.handshake_extensions.append(
<15> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<16> )
<17> self.tls.certificate = certificate
<18> self.tls.certificate_private_key = private_key
<19>
<20> self.tls.update_traffic_key_cb = self._update_traffic_key
<21>
<22> self.send_buffer = Buffer(capacity=4096)
<23> self.send_ack = False
<24>
<25> self.ack = {
<26> tls.Epoch.INITIAL: RangeSet(),
<27> tls.Epoch.HANDSHAKE: RangeSet(),
<28> tls.Epoch.ONE_RTT: RangeSet(),
<29> }
<30> self.crypto = {
<31> tls.Epoch.INITIAL: CryptoPair(),
<32> tls.Epoch.HANDSHAKE: CryptoPair(),
<33> tls.Epoch.ONE_RTT: CryptoPair(),
<34> }
<35> self.packet_number = {
<36> tls.Epoch.INITIAL: 0,
<37> tls.Epoch.HANDSHAKE: 0,
<38> tls.Epoch.ONE_RTT: 0,
<39> }
<40>
<41> self.crypto_initialized =</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
===========unchanged ref 0===========
at: aioquic.connection
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
at: aioquic.connection.QuicConnection
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.crypto
CryptoPair()
at: aioquic.rangeset
RangeSet()
at: aioquic.tls
Epoch()
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.update_traffic_key_cb = lambda d, e, s: None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
+ if self.state == State.CLIENT_HANDSHAKE_START:
- if not input_data:
+ self._client_send_hello(output_buf[Epoch.INITIAL])
- self._client_send_hello(output_buf)
return
self._receive_buffer += input_data
while len(self._receive_buffer) >= 4:
# determine message length
message_type = self._receive_buffer[0]
message_length = 0
for b in self._receive_buffer[1:4]:
message_length = (message_length << 8) | b
message_length += 4
# check message is complete
if len(self._receive_buffer) < message_length:
break
message = self._receive_buffer[:message_length]
self._receive_buffer = self._receive_buffer[message_length:]
input_buf = Buffer(data=message)
+
+ # client states
+
if self.state == State.CLIENT_EXPECT_SERVER_HELLO:
+ if message_type == HandshakeType.SERVER_HELLO:
+ self._client_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._client_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS:
+ if message_type == HandshakeType.ENCRYPTED_EXTENSIONS:
+ self._client_handle_encrypted_extensions(input_buf)
- self._client_handle_encrypted_extensions(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_REQUEST_OR_CERTIFICATE:
+ if message_type == HandshakeType.CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input</s>
===========changed ref 1===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 1
<s>CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input_buf, output_buf)
+ else:
+ # FIXME: handle certificate request
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_VERIFY:
+ if message_type == HandshakeType.CERTIFICATE_VERIFY:
+ self._client_handle_certificate_verify(input_buf)
- self._client_handle_certificate_verify(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_FINISHED:
+ if message_type == HandshakeType.FINISHED:
+ self._client_handle_finished(input_buf, output_buf[Epoch.HANDSHAKE])
- self._client_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_POST_HANDSHAKE:
if message_type == HandshakeType.NEW_SESSION_TICKET:
+ self._client_handle_new_session_ticket(input_buf)
- self._client_handle_new_session_ticket(input_buf, output_buf)
else:
raise AlertUnexpectedMessage
+ # server states
+
elif self.state == State.SERVER_EXPECT_CLIENT_HELLO:
+ if message_type == HandshakeType.CLIENT_HELLO:
+ self._server_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._server_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.SERVER_EXPECT_FINISHED:
+ if message_type</s>
===========changed ref 2===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 2
<s>Type.FINISHED:
+ self._server_handle_finished(input_buf)
- self._server_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
+ elif self.state == State.SERVER_POST_HANDSHAKE:
+ raise AlertUnexpectedMessage
+
+ # should not happen
+
else:
raise Exception('unhandled state')
assert input_buf.eof()
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<26>:<add> self.send_ack[epoch] = True
<del> self.send_ack = True
<28>:<del> if epoch == tls.Epoch.INITIAL:
<29>:<del> self.crypto[epoch].recv.teardown()
<30>:<del> self.crypto[epoch].send.teardown()
<31>:<del>
|
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
<0> buf = Buffer(data=data)
<1>
<2> while not buf.eof():
<3> start_off = buf.tell()
<4> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<5> encrypted_off = buf.tell() - start_off
<6> end_off = buf.tell() + header.rest_length
<7> tls.pull_bytes(buf, header.rest_length)
<8>
<9> if not self.is_client and not self.crypto_initialized:
<10> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
<11> is_client=self.is_client)
<12> self.crypto_initialized = True
<13>
<14> epoch = get_epoch(header.packet_type)
<15> crypto = self.crypto[epoch]
<16> plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
<17> data[start_off:end_off], encrypted_off)
<18>
<19> if not self.peer_cid_set:
<20> self.peer_cid = header.source_cid
<21> self.peer_cid_set = True
<22>
<23> is_ack_only = self._payload_received(plain_payload)
<24> self.ack[epoch].add(packet_number)
<25> if not is_ack_only:
<26> self.send_ack = True
<27>
<28> if epoch == tls.Epoch.INITIAL:
<29> self.crypto[epoch].recv.teardown()
<30> self.crypto[epoch].send.teardown()
<31>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.QuicConnection
_payload_received(plain)
_payload_received(self, 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.tls = tls.Context(is_client=is_client)
self.send_buffer = Buffer(capacity=4096)
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.crypto = {
tls.Epoch.INITIAL: CryptoPair(),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.crypto_initialized = False
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.crypto.CryptoContext
decrypt_packet(packet, encrypted_offset)
at: aioquic.crypto.CryptoPair
setup_initial(cid, is_client)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
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
Epoch()
Buffer(capacity=None, data=None)
===========unchanged ref 1===========
pull_bytes(buf: Buffer, length: int) -> bytes
at: aioquic.tls.Buffer
eof()
tell()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========changed ref 0===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
+ if self.state == State.CLIENT_HANDSHAKE_START:
- if not input_data:
+ self._client_send_hello(output_buf[Epoch.INITIAL])
- self._client_send_hello(output_buf)
return
self._receive_buffer += input_data
while len(self._receive_buffer) >= 4:
# determine message length
message_type = self._receive_buffer[0]
message_length = 0
for b in self._receive_buffer[1:4]:
message_length = (message_length << 8) | b
message_length += 4
# check message is complete
if len(self._receive_buffer) < message_length:
break
message = self._receive_buffer[:message_length]
self._receive_buffer = self._receive_buffer[message_length:]
input_buf = Buffer(data=message)
+
+ # client states
+
if self.state == State.CLIENT_EXPECT_SERVER_HELLO:
+ if message_type == HandshakeType.SERVER_HELLO:
+ self._client_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._client_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS:
+ if message_type == HandshakeType.ENCRYPTED_EXTENSIONS:
+ self._client_handle_encrypted_extensions(input_buf)
- self._client_handle_encrypted_extensions(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_REQUEST_OR_CERTIFICATE:
+ if message_type == HandshakeType.CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input</s>
===========changed ref 1===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 1
<s>CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input_buf, output_buf)
+ else:
+ # FIXME: handle certificate request
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_VERIFY:
+ if message_type == HandshakeType.CERTIFICATE_VERIFY:
+ self._client_handle_certificate_verify(input_buf)
- self._client_handle_certificate_verify(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_FINISHED:
+ if message_type == HandshakeType.FINISHED:
+ self._client_handle_finished(input_buf, output_buf[Epoch.HANDSHAKE])
- self._client_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_POST_HANDSHAKE:
if message_type == HandshakeType.NEW_SESSION_TICKET:
+ self._client_handle_new_session_ticket(input_buf)
- self._client_handle_new_session_ticket(input_buf, output_buf)
else:
raise AlertUnexpectedMessage
+ # server states
+
elif self.state == State.SERVER_EXPECT_CLIENT_HELLO:
+ if message_type == HandshakeType.CLIENT_HELLO:
+ self._server_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._server_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.SERVER_EXPECT_FINISHED:
+ if message_type</s>
===========changed ref 2===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 2
<s>Type.FINISHED:
+ self._server_handle_finished(input_buf)
- self._server_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
+ elif self.state == State.SERVER_POST_HANDSHAKE:
+ raise AlertUnexpectedMessage
+
+ # should not happen
+
else:
raise Exception('unhandled state')
assert input_buf.eof()
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<6>:<add> is_ack_only = False
<del> pass
<15>:<add> is_ack_only = False
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, 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> pass
<7> elif frame_type == QuicFrameType.ACK:
<8> pull_ack_frame(buf)
<9> elif frame_type == QuicFrameType.CRYPTO:
<10> is_ack_only = False
<11> data = pull_crypto_frame(buf)
<12> assert len(data)
<13> self.tls.handle_message(data, self.send_buffer)
<14> elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
<15> pull_new_connection_id_frame(buf)
<16> else:
<17> logger.warning('unhandled frame type %d', frame_type)
<18> break
<19> return is_ack_only
<20>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection.__init__
self.tls = tls.Context(is_client=is_client)
self.send_buffer = Buffer(capacity=4096)
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)
pull_crypto_frame(buf)
pull_new_connection_id_frame(buf)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========changed ref 0===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
+ if self.state == State.CLIENT_HANDSHAKE_START:
- if not input_data:
+ self._client_send_hello(output_buf[Epoch.INITIAL])
- self._client_send_hello(output_buf)
return
self._receive_buffer += input_data
while len(self._receive_buffer) >= 4:
# determine message length
message_type = self._receive_buffer[0]
message_length = 0
for b in self._receive_buffer[1:4]:
message_length = (message_length << 8) | b
message_length += 4
# check message is complete
if len(self._receive_buffer) < message_length:
break
message = self._receive_buffer[:message_length]
self._receive_buffer = self._receive_buffer[message_length:]
input_buf = Buffer(data=message)
+
+ # client states
+
if self.state == State.CLIENT_EXPECT_SERVER_HELLO:
+ if message_type == HandshakeType.SERVER_HELLO:
+ self._client_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._client_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS:
+ if message_type == HandshakeType.ENCRYPTED_EXTENSIONS:
+ self._client_handle_encrypted_extensions(input_buf)
- self._client_handle_encrypted_extensions(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_REQUEST_OR_CERTIFICATE:
+ if message_type == HandshakeType.CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input</s>
===========changed ref 1===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 1
<s>CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input_buf, output_buf)
+ else:
+ # FIXME: handle certificate request
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_VERIFY:
+ if message_type == HandshakeType.CERTIFICATE_VERIFY:
+ self._client_handle_certificate_verify(input_buf)
- self._client_handle_certificate_verify(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_FINISHED:
+ if message_type == HandshakeType.FINISHED:
+ self._client_handle_finished(input_buf, output_buf[Epoch.HANDSHAKE])
- self._client_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_POST_HANDSHAKE:
if message_type == HandshakeType.NEW_SESSION_TICKET:
+ self._client_handle_new_session_ticket(input_buf)
- self._client_handle_new_session_ticket(input_buf, output_buf)
else:
raise AlertUnexpectedMessage
+ # server states
+
elif self.state == State.SERVER_EXPECT_CLIENT_HELLO:
+ if message_type == HandshakeType.CLIENT_HELLO:
+ self._server_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._server_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.SERVER_EXPECT_FINISHED:
+ if message_type</s>
===========changed ref 2===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 2
<s>Type.FINISHED:
+ self._server_handle_finished(input_buf)
- self._server_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
+ elif self.state == State.SERVER_POST_HANDSHAKE:
+ raise AlertUnexpectedMessage
+
+ # should not happen
+
else:
raise Exception('unhandled state')
assert input_buf.eof()
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
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.crypto_initialized:
self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
is_client=self.is_client)
self.crypto_initialized = True
epoch = get_epoch(header.packet_type)
crypto = self.crypto[epoch]
plain_header, plain_payload, packet_number = crypto.recv.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
is_ack_only = self._payload_received(plain_payload)
self.ack[epoch].add(packet_number)
if not is_ack_only:
+ self.send_ack[epoch] = True
- self.send_ack = True
- if epoch == tls.Epoch.INITIAL:
- self.crypto[epoch].recv.teardown()
- self.crypto[epoch].send.teardown()
-
|
aioquic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<2>:<add> send_ack = self.ack[epoch] if self.send_ack[epoch] else False
<add> if not crypto.send.is_valid() or not send_ack:
<del> if not crypto.send.is_valid() or not self.ack[epoch]:
<14>:<add> if send_ack:
<del> if self.send_ack and self.ack[epoch]:
<16>:<add> push_ack_frame(buf, send_ack, 0)
<del> push_ack_frame(buf, self.ack[epoch], 0)
<17>:<add> self.send_ack[epoch] = False
<del> self.send_ack = False
|
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
<0> epoch = tls.Epoch.ONE_RTT
<1> crypto = self.crypto[epoch]
<2> if not crypto.send.is_valid() or not self.ack[epoch]:
<3> return
<4>
<5> buf = Buffer(capacity=PACKET_MAX_SIZE)
<6>
<7> # write header
<8> tls.push_uint8(buf, PACKET_FIXED_BIT | (SEND_PN_SIZE - 1))
<9> tls.push_bytes(buf, self.peer_cid)
<10> tls.push_uint16(buf, self.packet_number[epoch])
<11> header_size = buf.tell()
<12>
<13> # ACK
<14> if self.send_ack and self.ack[epoch]:
<15> push_uint_var(buf, QuicFrameType.ACK)
<16> push_ack_frame(buf, self.ack[epoch], 0)
<17> self.send_ack = False
<18>
<19> # encrypt
<20> packet_size = buf.tell()
<21> data = buf.data
<22> yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<23>
<24> self.packet_number[epoch] += 1
<25>
|
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.QuicConnection.__init__
self.peer_cid = os.urandom(8)
self.ack = {
tls.Epoch.INITIAL: RangeSet(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
}
self.send_ack = False
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.crypto = {
tls.Epoch.INITIAL: CryptoPair(),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
at: aioquic.connection.QuicConnection._write_handshake
send_ack = self.ack[epoch] if self.send_ack[epoch] else False
self.send_ack = False
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
self.send_ack = True
at: aioquic.crypto.CryptoContext
encrypt_packet(plain_header, plain_payload)
is_valid()
at: aioquic.crypto.CryptoPair.__init__
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)
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, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
+ is_ack_only = False
- pass
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
+ is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data):
buf = Buffer(data=data)
while not buf.eof():
start_off = buf.tell()
header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
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.crypto_initialized:
self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
is_client=self.is_client)
self.crypto_initialized = True
epoch = get_epoch(header.packet_type)
crypto = self.crypto[epoch]
plain_header, plain_payload, packet_number = crypto.recv.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
is_ack_only = self._payload_received(plain_payload)
self.ack[epoch].add(packet_number)
if not is_ack_only:
+ self.send_ack[epoch] = True
- self.send_ack = True
- if epoch == tls.Epoch.INITIAL:
- self.crypto[epoch].recv.teardown()
- self.crypto[epoch].send.teardown()
-
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
- self.send_buffer = Buffer(capacity=4096)
- self.send_ack = False
-
self.ack = {
tls.Epoch.INITIAL: RangeSet(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
}
self.crypto = {
tls.Epoch.INITIAL: CryptoPair(),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
+ self.send_ack = {
+ tls.Epoch.INITIAL: False,
+ tls.Epoch.HANDSHAKE: False,
+ tls.Epoch.ONE_RTT: False,</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s>: 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.crypto_initialized = False
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<1>:<add> send_ack = self.ack[epoch] if self.send_ack[epoch] else False
<add> send_data = self.send_buffer[epoch].data
<add> self.send_buffer[epoch].seek(0)
<add> if not crypto.send.is_valid() or (not send_ack and not send_data):
<del> if not crypto.send.is_valid() or not self.send_buffer.tell():
<20>:<add> if send_data:
<del> if self.send_buffer.tell():
<24>:<add> tls.push_bytes(buf, send_data)
<del> tls.push_bytes(buf, self.send_buffer.data)
<25>:<del> self.send_buffer.seek(0)
<34>:<add> if send_ack:
<del> if self.send_ack and self.ack[epoch]:
<36>:<add> push_ack_frame(buf, send_ack, 0)
<del> push_ack_frame(buf, self.ack[epoch], 0)
<37>:<add> self.send_ack[epoch] = False
<del> self.send_ack = False
|
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
<0> crypto = self.crypto[epoch]
<1> if not crypto.send.is_valid() or not self.send_buffer.tell():
<2> return
<3>
<4> buf = Buffer(capacity=PACKET_MAX_SIZE)
<5>
<6> if epoch == tls.Epoch.INITIAL:
<7> packet_type = PACKET_TYPE_INITIAL
<8> else:
<9> packet_type = PACKET_TYPE_HANDSHAKE
<10>
<11> # write header
<12> push_quic_header(buf, QuicHeader(
<13> version=PROTOCOL_VERSION_DRAFT_17,
<14> packet_type=packet_type | (SEND_PN_SIZE - 1),
<15> destination_cid=self.peer_cid,
<16> source_cid=self.host_cid,
<17> ))
<18> header_size = buf.tell()
<19>
<20> if self.send_buffer.tell():
<21> # CRYPTO
<22> push_uint_var(buf, QuicFrameType.CRYPTO)
<23> with push_crypto_frame(buf):
<24> tls.push_bytes(buf, self.send_buffer.data)
<25> self.send_buffer.seek(0)
<26>
<27> # PADDING
<28> if epoch == tls.Epoch.INITIAL:
<29> tls.push_bytes(
<30> buf,
<31> bytes(PACKET_MAX_SIZE - crypto.send.aead_tag_size - buf.tell()))
<32>
<33> # ACK
<34> if self.send_ack and self.ack[epoch]:
<35> push_uint_var(buf, QuicFrameType.ACK)
<36> push_ack_frame(buf, self.ack[epoch], 0)
<37> self.send_ack = False
<38>
<39> # finalize length
<40> packet_size = buf.tell()
<41> buf.seek(header_size - SEND_PN_SIZE - 2)
<42> length = packet_size - header_size + 2 + crypto.send.aead_tag_</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
tls.push_uint16(buf, length | 0x4000)
tls.push_uint16(buf, self.packet_number[epoch])
buf.seek(packet_size)
# encrypt
data = buf.data
yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number[epoch] += 1
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.QuicConnection.__init__
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.ack = {
tls.Epoch.INITIAL: RangeSet(),
tls.Epoch.HANDSHAKE: RangeSet(),
tls.Epoch.ONE_RTT: RangeSet(),
}
self.send_buffer = Buffer(capacity=4096)
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.send_ack = False
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.crypto = {
tls.Epoch.INITIAL: CryptoPair(),
tls.Epoch.HANDSHAKE: CryptoPair(),
tls.Epoch.ONE_RTT: CryptoPair(),
}
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
at: aioquic.connection.QuicConnection._write_application
send_ack = self.ack[epoch] if self.send_ack[epoch] else False
self.send_ack = False
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
self.send_ack = True
at: aioquic.crypto.CryptoContext
is_valid()
at: aioquic.crypto.CryptoContext.setup
self.aead_tag_size = 16
===========unchanged ref 1===========
at: aioquic.crypto.CryptoPair.__init__
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
PROTOCOL_VERSION_DRAFT_17 = 0xff000011 # draft 17
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)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_crypto_frame(buf, offset=0)
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 _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
+ is_ack_only = False
- pass
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
+ is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
crypto = self.crypto[epoch]
+ send_ack = self.ack[epoch] if self.send_ack[epoch] else False
+ if not crypto.send.is_valid() or not send_ack:
- if not crypto.send.is_valid() or not self.ack[epoch]:
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[epoch])
header_size = buf.tell()
# ACK
+ if send_ack:
- if self.send_ack and self.ack[epoch]:
push_uint_var(buf, QuicFrameType.ACK)
+ push_ack_frame(buf, send_ack, 0)
- push_ack_frame(buf, self.ack[epoch], 0)
+ self.send_ack[epoch] = False
- self.send_ack = False
# encrypt
packet_size = buf.tell()
data = buf.data
yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number[epoch] += 1
|
tests.test_tls/ContextTest.test_handshake
|
Modified
|
aiortc~aioquic
|
2ed04f4c360969c8849304489ffe3fe03e05bc8c
|
[tls] split send buffers by epoch
|
<0>:<del> client = Context(is_client=True)
<1>:<del> client.handshake_extensions = [
<2>:<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<3>:<del> ]
<4>:<del> self.assertEqual(client.state, State.CLIENT_HANDSHAKE_START)
<5>:<del>
<6>:<del> server = Context(is_client=False)
<7>:<del> server.certificate = SERVER_CERTIFICATE
<8>:<del> server.certificate_private_key = SERVER_PRIVATE_KEY
<9>:<del>
<10>:<del> server.handshake_extensions = [
<11>:<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<12>:<del> ]
<13>:<del> self.assertEqual(server.state, State.SERVER_EXPECT_CLIENT_HELLO)
<14>:<add> client = self.create_client()
<add> server = self.create_server()
<16>:<add> client_buf = create_buffers()
<del> client_buf = Buffer(capacity=512)
<19>:<del> self.assertEqual(client_buf.tell(), 248)
<20>:<add> server_input = merge_buffers(client_buf)
<del> server_input = client_buf.data
<21>:<add> self.assertEqual(len(server_input), 248)
<add> reset_buffers(client_buf)
<del> client_buf.seek(0)
<25>:<add> server_buf = create_buffers()
<del> server_buf = Buffer(capacity=4096)
<28>:<add> client_input = merge_buffers(server_buf)
<add> self.assertEqual(len(client_input), 155 + 90 + 1538 + 392 + 36)
<del> self.assertEqual(server_buf.tell(), 155 + 90 + 1538 + 392 + 36)
<29>:<del> client_input = server_buf.data
<30>:<del> server_buf.seek(0)
<31>:<add> reset_buffers(server_buf)
|
# module: tests.test_tls
class ContextTest(TestCase):
def test_handshake(self):
<0> client = Context(is_client=True)
<1> client.handshake_extensions = [
<2> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<3> ]
<4> self.assertEqual(client.state, State.CLIENT_HANDSHAKE_START)
<5>
<6> server = Context(is_client=False)
<7> server.certificate = SERVER_CERTIFICATE
<8> server.certificate_private_key = SERVER_PRIVATE_KEY
<9>
<10> server.handshake_extensions = [
<11> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<12> ]
<13> self.assertEqual(server.state, State.SERVER_EXPECT_CLIENT_HELLO)
<14>
<15> # send client hello
<16> client_buf = Buffer(capacity=512)
<17> client.handle_message(b'', client_buf)
<18> self.assertEqual(client.state, State.CLIENT_EXPECT_SERVER_HELLO)
<19> self.assertEqual(client_buf.tell(), 248)
<20> server_input = client_buf.data
<21> client_buf.seek(0)
<22>
<23> # handle client hello
<24> # send server hello, encrypted extensions, certificate, certificate verify, finished
<25> server_buf = Buffer(capacity=4096)
<26> server.handle_message(server_input, server_buf)
<27> self.assertEqual(server.state, State.SERVER_EXPECT_FINISHED)
<28> self.assertEqual(server_buf.tell(), 155 + 90 + 1538 + 392 + 36)
<29> client_input = server_buf.data
<30> server_buf.seek(0)
<31>
<32> # handle server hello, encrypted extensions, certificate, certificate verify, finished
<33> # send finished
<34> client.handle_message(client_input, client_buf)
<35> self.assertEqual(client.state, State.CLIENT_POST_HAND</s>
|
===========below chunk 0===========
# module: tests.test_tls
class ContextTest(TestCase):
def test_handshake(self):
# offset: 1
self.assertEqual(client_buf.tell(), 36)
server_input = client_buf.data
client_buf.seek(0)
# handle finished
server.handle_message(server_input, server_buf)
self.assertEqual(server.state, State.SERVER_POST_HANDSHAKE)
self.assertEqual(server_buf.tell(), 0)
# check keys match
self.assertEqual(client.dec_key, server.enc_key)
self.assertEqual(client.enc_key, server.dec_key)
===========unchanged ref 0===========
at: aioquic.tls
AlertUnexpectedMessage(*args: object)
Epoch()
State()
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
seek(pos)
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.handshake_extensions = []
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
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())
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
create_buffers()
at: unittest.case
TestCase(methodName: str=...)
===========unchanged ref 1===========
at: unittest.case.TestCase
failureException: Type[BaseException]
longMessage: bool
maxDiff: Optional[int]
_testMethodName: str
_testMethodDoc: str
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
===========changed ref 0===========
# module: tests.test_tls
+ def create_buffers():
+ return {
+ tls.Epoch.INITIAL: Buffer(capacity=4096),
+ tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
+ tls.Epoch.ONE_RTT: Buffer(capacity=4096),
+ }
+
===========changed ref 1===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
+ if self.state == State.CLIENT_HANDSHAKE_START:
- if not input_data:
+ self._client_send_hello(output_buf[Epoch.INITIAL])
- self._client_send_hello(output_buf)
return
self._receive_buffer += input_data
while len(self._receive_buffer) >= 4:
# determine message length
message_type = self._receive_buffer[0]
message_length = 0
for b in self._receive_buffer[1:4]:
message_length = (message_length << 8) | b
message_length += 4
# check message is complete
if len(self._receive_buffer) < message_length:
break
message = self._receive_buffer[:message_length]
self._receive_buffer = self._receive_buffer[message_length:]
input_buf = Buffer(data=message)
+
+ # client states
+
if self.state == State.CLIENT_EXPECT_SERVER_HELLO:
+ if message_type == HandshakeType.SERVER_HELLO:
+ self._client_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._client_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS:
+ if message_type == HandshakeType.ENCRYPTED_EXTENSIONS:
+ self._client_handle_encrypted_extensions(input_buf)
- self._client_handle_encrypted_extensions(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_REQUEST_OR_CERTIFICATE:
+ if message_type == HandshakeType.CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input</s>
===========changed ref 2===========
# module: aioquic.tls
class Context:
def handle_message(self, input_data, output_buf):
# offset: 1
<s>CERTIFICATE:
+ self._client_handle_certificate(input_buf)
- self._client_handle_certificate(input_buf, output_buf)
+ else:
+ # FIXME: handle certificate request
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_CERTIFICATE_VERIFY:
+ if message_type == HandshakeType.CERTIFICATE_VERIFY:
+ self._client_handle_certificate_verify(input_buf)
- self._client_handle_certificate_verify(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_EXPECT_FINISHED:
+ if message_type == HandshakeType.FINISHED:
+ self._client_handle_finished(input_buf, output_buf[Epoch.HANDSHAKE])
- self._client_handle_finished(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.CLIENT_POST_HANDSHAKE:
if message_type == HandshakeType.NEW_SESSION_TICKET:
+ self._client_handle_new_session_ticket(input_buf)
- self._client_handle_new_session_ticket(input_buf, output_buf)
else:
raise AlertUnexpectedMessage
+ # server states
+
elif self.state == State.SERVER_EXPECT_CLIENT_HELLO:
+ if message_type == HandshakeType.CLIENT_HELLO:
+ self._server_handle_hello(input_buf, output_buf[Epoch.INITIAL])
- self._server_handle_hello(input_buf, output_buf)
+ else:
+ raise AlertUnexpectedMessage
elif self.state == State.SERVER_EXPECT_FINISHED:
+ if message_type</s>
|
aioquic.crypto/CryptoPair.setup_initial
|
Modified
|
aiortc~aioquic
|
d501c5a8fddbecf6795d6ebb0cd90533eb73d493
|
[crypto] remove CryptoPair.initial and CryptoContext.setup_initial
|
<0>:<add> if is_client:
<add> recv_label, send_label = b'server in', b'client in'
<add> else:
<add> recv_label, send_label = b'client in', b'server in'
<del> self.recv.setup_initial(cid, not is_client)
<1>:<del> self.send.setup_initial(cid, is_client)
|
# module: aioquic.crypto
class CryptoPair:
def setup_initial(self, cid, is_client):
<0> self.recv.setup_initial(cid, not is_client)
<1> self.send.setup_initial(cid, is_client)
<2>
|
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
- @classmethod
- def initial(cls, cid, is_client):
- pair = cls()
- pair.setup_initial(cid, is_client)
- return pair
-
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
- def setup_initial(self, cid, is_client):
- algorithm, secret = derive_initial_secret(cid, is_client)
- self.setup(algorithm, secret)
-
===========changed ref 2===========
# module: aioquic.crypto
+ INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 3===========
# module: aioquic.crypto
- def derive_initial_secret(cid, is_client):
- if is_client:
- label = b'client in'
- else:
- label = b'server in'
-
- algorithm = hashes.SHA256()
- initial_secret = hkdf_extract(algorithm, INITIAL_SALT, cid)
- secret = hkdf_expand_label(algorithm, initial_secret, label, b'', algorithm.digest_size)
- return algorithm, secret
-
|
tests.test_crypto/CryptoTest.test_decrypt_packet_client
|
Modified
|
aiortc~aioquic
|
d501c5a8fddbecf6795d6ebb0cd90533eb73d493
|
[crypto] remove CryptoPair.initial and CryptoContext.setup_initial
|
<0>:<add> pair = self.create_crypto(is_client=False)
<del> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_client(self):
<0> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
<1>
<2> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
<3> CLIENT_ENCRYPTED_PACKET, 17)
<4> self.assertEqual(plain_header, CLIENT_PLAIN_HEADER)
<5> self.assertEqual(plain_payload, CLIENT_PLAIN_PAYLOAD)
<6> self.assertEqual(packet_number, 2)
<7>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_ALGORITHM = hashes.SHA256()
derive_key_iv_hp(algorithm, secret)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
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_crypto
class CryptoTest(TestCase):
- def test_server_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=False)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
- self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
- self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
-
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_client_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=True)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
- self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
- self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
-
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def create_crypto(self, is_client):
+ pair = CryptoPair()
+ pair.setup_initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=is_client)
+ if is_client:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ else:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ return pair
+
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def test_derive_key_iv_hp(self):
+ # client
+ secret = binascii.unhexlify(
+ '8a3515a14ae3c31b9c2d6d5bc58538ca5cd2baa119087143e60887428dcb52f6')
+ key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
+ self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
+ self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
+
+ # server
+ secret = binascii.unhexlify(
+ '47b2eaea6c266e32c0697a9e2a898bdf5c4fb3e5ac34f0e549bf2c58581a3811')
+ key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
+ self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
+ self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
+
===========changed ref 4===========
# module: aioquic.crypto
class CryptoPair:
- @classmethod
- def initial(cls, cid, is_client):
- pair = cls()
- pair.setup_initial(cid, is_client)
- return pair
-
===========changed ref 5===========
# module: aioquic.crypto
class CryptoContext:
- def setup_initial(self, cid, is_client):
- algorithm, secret = derive_initial_secret(cid, is_client)
- self.setup(algorithm, secret)
-
===========changed ref 6===========
# module: aioquic.crypto
+ INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 7===========
# module: aioquic.crypto
class CryptoPair:
def setup_initial(self, cid, is_client):
+ if is_client:
+ recv_label, send_label = b'server in', b'client in'
+ else:
+ recv_label, send_label = b'client in', b'server in'
- self.recv.setup_initial(cid, not is_client)
- self.send.setup_initial(cid, is_client)
===========changed ref 8===========
# module: aioquic.crypto
- def derive_initial_secret(cid, is_client):
- if is_client:
- label = b'client in'
- else:
- label = b'server in'
-
- algorithm = hashes.SHA256()
- initial_secret = hkdf_extract(algorithm, INITIAL_SALT, cid)
- secret = hkdf_expand_label(algorithm, initial_secret, label, b'', algorithm.digest_size)
- return algorithm, secret
-
|
tests.test_crypto/CryptoTest.test_decrypt_packet_server
|
Modified
|
aiortc~aioquic
|
d501c5a8fddbecf6795d6ebb0cd90533eb73d493
|
[crypto] remove CryptoPair.initial and CryptoContext.setup_initial
|
<0>:<add> pair = self.create_crypto(is_client=True)
<del> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_server(self):
<0> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
<1>
<2> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
<3> SERVER_ENCRYPTED_PACKET, 17)
<4> self.assertEqual(plain_header, SERVER_PLAIN_HEADER)
<5> self.assertEqual(plain_payload, SERVER_PLAIN_PAYLOAD)
<6> self.assertEqual(packet_number, 1)
<7>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoContext
decrypt_packet(packet, encrypted_offset)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
===========unchanged ref 1===========
at: tests.test_crypto
CLIENT_ENCRYPTED_PACKET = binascii.unhexlify(
'c1ff000012508394c8f03e51570800449f0dbc195a0000f3a694c75775b4e546'
'172ce9e047cd0b5bee5181648c727adc87f7eae54473ec6cba6bdad4f5982317'
'4b769f12358abd292d4f3286934484fb8b239c38732e1f3bbbc6a003056487eb'
'8b5c88b9fd9279ffff3b0f4ecf95c4624db6d65d4113329ee9b0bf8cdd7c8a8d'
'72806d55df25ecb66488bc119d7c9a29abaf99bb33c56b08ad8c26995f838bb3'
'b7a3d5c1858b8ec06b839db2dcf918d5ea9317f1acd6b663cc8925868e2f6a1b'
'da546695f3c3f33175944db4a11a346afb07e78489e509b02add51b7b203eda5'
'c330b03641179a31fbba9b56ce00f3d5b5e3d7d9c5429aebb9576f2f7eacbe27'
'bc1b8082aaf68fb69c921aa5d33ec0c8510410865a178d86d7e54122d55ef2c2'
'bbc040be46d7fece73fe8a1b24495ec160df2da9b20a7ba2f26dfa2a44366dbc'
'63de5cd7d7c94c57172fe6d79c9</s>
===========unchanged ref 2===========
at: tests.test_crypto.CryptoTest
create_crypto(is_client)
at: tests.test_crypto.CryptoTest.test_derive_key_iv_hp
key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def create_crypto(self, is_client):
+ pair = CryptoPair()
+ pair.setup_initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=is_client)
+ if is_client:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ else:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ return pair
+
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_client(self):
+ pair = self.create_crypto(is_client=False)
- pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_server_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=False)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
- self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
- self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
-
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_client_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=True)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
- self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
- self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
-
===========changed ref 4===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def test_derive_key_iv_hp(self):
+ # client
+ secret = binascii.unhexlify(
+ '8a3515a14ae3c31b9c2d6d5bc58538ca5cd2baa119087143e60887428dcb52f6')
+ key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
+ self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
+ self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
+
+ # server
+ secret = binascii.unhexlify(
+ '47b2eaea6c266e32c0697a9e2a898bdf5c4fb3e5ac34f0e549bf2c58581a3811')
+ key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
+ self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
+ self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
+
|
tests.test_crypto/CryptoTest.test_encrypt_packet_client
|
Modified
|
aiortc~aioquic
|
d501c5a8fddbecf6795d6ebb0cd90533eb73d493
|
[crypto] remove CryptoPair.initial and CryptoContext.setup_initial
|
<0>:<add> pair = self.create_crypto(is_client=True)
<del> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_packet_client(self):
<0> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
<1>
<2> packet = pair.send.encrypt_packet(CLIENT_PLAIN_HEADER, CLIENT_PLAIN_PAYLOAD)
<3> self.assertEqual(packet, CLIENT_ENCRYPTED_PACKET)
<4>
|
===========unchanged ref 0===========
at: tests.test_crypto
CLIENT_PLAIN_PAYLOAD = binascii.unhexlify(
'060040c4010000c003036660261ff947cea49cce6cfad687f457cf1b14531ba1'
'4131a0e8f309a1d0b9c4000006130113031302010000910000000b0009000006'
'736572766572ff01000100000a00140012001d00170018001901000101010201'
'03010400230000003300260024001d00204cfdfcd178b784bf328cae793b136f'
'2aedce005ff183d7bb1495207236647037002b0003020304000d0020001e0403'
'05030603020308040805080604010501060102010402050206020202002d0002'
'0101001c00024001') + bytes(963)
at: tests.test_crypto.CryptoTest
create_crypto(is_client)
at: tests.test_crypto.CryptoTest.test_decrypt_packet_client
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
CLIENT_ENCRYPTED_PACKET, 17)
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
CLIENT_ENCRYPTED_PACKET, 17)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def create_crypto(self, is_client):
+ pair = CryptoPair()
+ pair.setup_initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=is_client)
+ if is_client:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ else:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ return pair
+
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_server(self):
+ pair = self.create_crypto(is_client=True)
- pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 1)
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_client(self):
+ pair = self.create_crypto(is_client=False)
- pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_server_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=False)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
- self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
- self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
-
===========changed ref 4===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_client_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=True)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
- self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
- self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
-
===========changed ref 5===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def test_derive_key_iv_hp(self):
+ # client
+ secret = binascii.unhexlify(
+ '8a3515a14ae3c31b9c2d6d5bc58538ca5cd2baa119087143e60887428dcb52f6')
+ key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
+ self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
+ self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
+
+ # server
+ secret = binascii.unhexlify(
+ '47b2eaea6c266e32c0697a9e2a898bdf5c4fb3e5ac34f0e549bf2c58581a3811')
+ key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
+ self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
+ self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
+
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
- @classmethod
- def initial(cls, cid, is_client):
- pair = cls()
- pair.setup_initial(cid, is_client)
- return pair
-
===========changed ref 7===========
# module: aioquic.crypto
class CryptoContext:
- def setup_initial(self, cid, is_client):
- algorithm, secret = derive_initial_secret(cid, is_client)
- self.setup(algorithm, secret)
-
|
tests.test_crypto/CryptoTest.test_encrypt_packet_server
|
Modified
|
aiortc~aioquic
|
d501c5a8fddbecf6795d6ebb0cd90533eb73d493
|
[crypto] remove CryptoPair.initial and CryptoContext.setup_initial
|
<0>:<add> pair = self.create_crypto(is_client=False)
<del> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_packet_server(self):
<0> pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
<1>
<2> packet = pair.send.encrypt_packet(SERVER_PLAIN_HEADER, SERVER_PLAIN_PAYLOAD)
<3> self.assertEqual(packet, SERVER_ENCRYPTED_PACKET)
<4>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoContext
decrypt_packet(packet, encrypted_offset)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
at: tests.test_crypto
SERVER_PLAIN_HEADER = binascii.unhexlify('c1ff00001205f067a5502a4262b50040740001')
SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'0d0000000018410a020000560303eefce7f7b37ba1d1632e96677825ddf73988'
'cfc79825df566dc5430b9a045a1200130100002e00330024001d00209d3c940d'
'89690b84d08a60993c144eca684d1081287c834d5311bcf32bb9da1a002b0002'
'0304')
SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'c4ff00001205f067a5502a4262b5004074f7ed5f01c4c2a2303d297e3c519bf6'
'b22386e3d0bd6dfc66121677298031041bb9a79c9f0f9d4c5877270a660f5da3'
'6207d98b73839b2fdf2ef8e7df5a51b17b8c68d864fd3e708c6c1b71a98a3318'
'15599ef5014ea38c44bdfd387c03b5275c35e009b6238f831420047c7271281c'
'cb54df7884')
at: tests.test_crypto.CryptoTest.test_decrypt_packet_server
pair = self.create_crypto(is_client=True)
===========unchanged ref 1===========
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_packet_client(self):
+ pair = self.create_crypto(is_client=True)
- pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
packet = pair.send.encrypt_packet(CLIENT_PLAIN_HEADER, CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet, CLIENT_ENCRYPTED_PACKET)
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_server(self):
+ pair = self.create_crypto(is_client=True)
- pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=True)
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 1)
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_packet_client(self):
+ pair = self.create_crypto(is_client=False)
- pair = CryptoPair.initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=False)
plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_server_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=False)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
- self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
- self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
-
===========changed ref 4===========
# module: tests.test_crypto
class CryptoTest(TestCase):
- def test_client_initial(self):
- cid = binascii.unhexlify('8394c8f03e515708')
- algorithm, secret = derive_initial_secret(cid, is_client=True)
- key, iv, hp = derive_key_iv_hp(algorithm, secret)
- self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
- self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
- self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
-
===========changed ref 5===========
# module: tests.test_crypto
class CryptoTest(TestCase):
+ def create_crypto(self, is_client):
+ pair = CryptoPair()
+ pair.setup_initial(cid=binascii.unhexlify('8394c8f03e515708'), is_client=is_client)
+ if is_client:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ else:
+ self.assertEqual(pair.send.iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
+ self.assertEqual(pair.recv.iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
+ return pair
+
|
aioquic.packet/pull_crypto_frame
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<0>:<add> offset = pull_uint_var(buf)
<del> pull_uint_var(buf)
<2>:<add> return offset, pull_bytes(buf, length)
<del> return pull_bytes(buf, length)
|
# module: aioquic.packet
def pull_crypto_frame(buf):
<0> pull_uint_var(buf)
<1> length = pull_uint_var(buf)
<2> return pull_bytes(buf, length)
<3>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_uint_var(buf)
at: aioquic.tls
pull_bytes(buf: Buffer, length: int) -> bytes
|
aioquic.crypto/CryptoContext.setup
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<2>:<del> self.aead_tag_size = 16
|
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
<0> key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
<1> self.aead = aead.AESGCM(key)
<2> self.aead_tag_size = 16
<3> self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
<4>
|
===========unchanged ref 0===========
at: aioquic.crypto
derive_key_iv_hp(algorithm, secret)
at: aioquic.crypto.CryptoContext.teardown
self.aead = None
self.hp = None
self.iv = None
===========changed ref 0===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
|
aioquic.crypto/CryptoPair.__init__
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<0>:<add> self.aead_tag_size = 16
|
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
<0> self.recv = CryptoContext()
<1> self.send = CryptoContext()
<2>
|
===========unchanged ref 0===========
at: aioquic.crypto
CryptoContext()
===========changed ref 0===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 1===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<22>:<del> self.ack = {
<23>:<del> tls.Epoch.INITIAL: RangeSet(),
<24>:<del> tls.Epoch.HANDSHAKE: RangeSet(),
<25>:<del> tls.Epoch.ONE_RTT: RangeSet(),
<26>:<del> }
<27>:<del> self.crypto = {
<28>:<del> tls.Epoch.INITIAL: CryptoPair(),
<29>:<del> tls.Epoch.HANDSHAKE: CryptoPair(),
<30>:<del> tls.Epoch.ONE_RTT: CryptoPair(),
<31>:<del> }
<32>:<del> self.packet_number = {
<33>:<del> tls.Epoch.INITIAL: 0,
<34>:<del> tls.Epoch.HANDSHAKE: 0,
<35>:<del> tls.Epoch.ONE_RTT: 0,
<36>:<del> }
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
<5> self.host_cid = os.urandom(8)
<6> self.peer_cid = os.urandom(8)
<7> self.peer_cid_set = False
<8> self.tls = tls.Context(is_client=is_client)
<9> if is_client:
<10> self.tls.handshake_extensions.append(
<11> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<12> )
<13> else:
<14> self.tls.handshake_extensions.append(
<15> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<16> )
<17> self.tls.certificate = certificate
<18> self.tls.certificate_private_key = private_key
<19>
<20> self.tls.update_traffic_key_cb = self._update_traffic_key
<21>
<22> self.ack = {
<23> tls.Epoch.INITIAL: RangeSet(),
<24> tls.Epoch.HANDSHAKE: RangeSet(),
<25> tls.Epoch.ONE_RTT: RangeSet(),
<26> }
<27> self.crypto = {
<28> tls.Epoch.INITIAL: CryptoPair(),
<29> tls.Epoch.HANDSHAKE: CryptoPair(),
<30> tls.Epoch.ONE_RTT: CryptoPair(),
<31> }
<32> self.packet_number = {
<33> tls.Epoch.INITIAL: 0,
<34> tls.Epoch.HANDSHAKE: 0,
<35> tls.Epoch.ONE_RTT: 0,
<36> }
<37> self.send_ack = {
<38> tls.Epoch.INITIAL: False,
<39> tls.Epoch.HANDSHAKE: False,
<40> tls.Epoch</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
}
self.send_buffer = {
tls.Epoch.INITIAL: Buffer(capacity=4096),
tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
tls.Epoch.ONE_RTT: Buffer(capacity=4096),
}
self.crypto_initialized = False
===========unchanged ref 0===========
at: aioquic.connection
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
PacketSpace()
QuicConnection(is_client=True, certificate=None, private_key=None)
at: aioquic.connection.QuicConnection
_update_traffic_key(direction, epoch, secret)
_update_traffic_key(self, direction, epoch, secret)
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
self.peer_cid_set = True
at: aioquic.crypto
CryptoPair()
at: aioquic.rangeset
RangeSet()
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)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
===========unchanged ref 1===========
self.handshake_extensions = []
self.update_traffic_key_cb = lambda d, e, s: None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 1===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 2===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 3===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 4===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 5===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
|
aioquic.connection/QuicConnection.connection_made
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<1>:<add> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=self.peer_cid,
<del> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
<2>:<add> is_client=self.is_client)
<del> is_client=self.is_client)
|
# module: aioquic.connection
class QuicConnection:
def connection_made(self):
<0> if self.is_client:
<1> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
<2> is_client=self.is_client)
<3> self.crypto_initialized = True
<4>
<5> self.tls.handle_message(b'', self.send_buffer)
<6>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.tls = tls.Context(is_client=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.crypto_initialized = False
at: aioquic.connection.QuicConnection.datagram_received
self.crypto_initialized = True
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========changed ref 0===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
- self.ack = {
- tls.Epoch.INITIAL: RangeSet(),
- tls.Epoch.HANDSHAKE: RangeSet(),
- tls.Epoch.ONE_RTT: RangeSet(),
- }
- self.crypto = {
- tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.HANDSHAKE: CryptoPair(),
- tls.Epoch.ONE_RTT: CryptoPair(),
- }
- self.packet_number = {
- tls.Epoch.INITIAL: 0,
- tls.Epoch.HANDSHAKE: 0,
- tls.Epoch.ONE_RTT: 0,
- }
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s> 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.crypto_initialized = False
+ self.packet_number = 0
===========changed ref 3===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 4===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 5===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 6===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 7===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<0>:<add> """
<add> Handle an incoming datagram.
<add> """
<10>:<add> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<del> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
<11>:<add> is_client=self.is_client)
<del> is_client=self.is_client)
<15>:<add> space = self.spaces[epoch]
<del> crypto = self.crypto[epoch]
<16>:<add> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<del> plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
<23>:<add> # record packet as received
<24>:<add> space.ack_queue.add(packet_number)
<del> self.ack[epoch].add(packet_number)
|
# module: aioquic.connection
class QuicConnection:
+ def datagram_received(self, data: bytes):
- def datagram_received(self, data):
<0> buf = Buffer(data=data)
<1>
<2> while not buf.eof():
<3> start_off = buf.tell()
<4> header = pull_quic_header(buf, host_cid_length=len(self.host_cid))
<5> encrypted_off = buf.tell() - start_off
<6> end_off = buf.tell() + header.rest_length
<7> tls.pull_bytes(buf, header.rest_length)
<8>
<9> if not self.is_client and not self.crypto_initialized:
<10> self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
<11> is_client=self.is_client)
<12> self.crypto_initialized = True
<13>
<14> epoch = get_epoch(header.packet_type)
<15> crypto = self.crypto[epoch]
<16> plain_header, plain_payload, packet_number = crypto.recv.decrypt_packet(
<17> data[start_off:end_off], encrypted_off)
<18>
<19> if not self.peer_cid_set:
<20> self.peer_cid = header.source_cid
<21> self.peer_cid_set = True
<22>
<23> is_ack_only = self._payload_received(plain_payload)
<24> self.ack[epoch].add(packet_number)
<25> if not is_ack_only:
<26> self.send_ack[epoch] = True
<27>
|
===========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(plain)
_payload_received(self, 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.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.crypto_initialized = False
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
setup_initial(cid, is_client)
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(pn)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
at: aioquic.tls.Buffer
eof()
tell()
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 1===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
- self.ack = {
- tls.Epoch.INITIAL: RangeSet(),
- tls.Epoch.HANDSHAKE: RangeSet(),
- tls.Epoch.ONE_RTT: RangeSet(),
- }
- self.crypto = {
- tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.HANDSHAKE: CryptoPair(),
- tls.Epoch.ONE_RTT: CryptoPair(),
- }
- self.packet_number = {
- tls.Epoch.INITIAL: 0,
- tls.Epoch.HANDSHAKE: 0,
- tls.Epoch.ONE_RTT: 0,
- }
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.</s>
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s> 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.crypto_initialized = False
+ self.packet_number = 0
===========changed ref 5===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 7===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 8===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<11>:<add> offset, data = pull_crypto_frame(buf)
<del> data = pull_crypto_frame(buf)
|
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, 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> data = pull_crypto_frame(buf)
<12> assert len(data)
<13> self.tls.handle_message(data, self.send_buffer)
<14> elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
<15> is_ack_only = False
<16> pull_new_connection_id_frame(buf)
<17> else:
<18> logger.warning('unhandled frame type %d', frame_type)
<19> break
<20> return is_ack_only
<21>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
_write_application()
_write_application(self)
_write_handshake(self, epoch)
_write_handshake(epoch)
at: aioquic.connection.QuicConnection.__init__
self.tls = tls.Context(is_client=is_client)
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)
pull_crypto_frame(buf)
pull_new_connection_id_frame(buf)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========changed ref 0===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 1===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def datagram_received(self, data: bytes):
- def datagram_received(self, data):
+ """
+ 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))
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.crypto_initialized:
+ self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
epoch = get_epoch(header.packet_type)
+ space = self.spaces[epoch]
- crypto = self.crypto[epoch]
+ plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
- plain_header, plain_payload, packet_number = crypto.recv.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
+ # record packet as received
is_ack_only = self._payload_received(plain_payload)
+ space.ack_queue.add(packet_number)
- self.ack[epoch].add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
- self.ack = {
- tls.Epoch.INITIAL: RangeSet(),
- tls.Epoch.HANDSHAKE: RangeSet(),
- tls.Epoch.ONE_RTT: RangeSet(),
- }
- self.crypto = {
- tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.HANDSHAKE: CryptoPair(),
- tls.Epoch.ONE_RTT: CryptoPair(),
- }
- self.packet_number = {
- tls.Epoch.INITIAL: 0,
- tls.Epoch.HANDSHAKE: 0,
- tls.Epoch.ONE_RTT: 0,
- }
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.</s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s> 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.crypto_initialized = False
+ self.packet_number = 0
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 7===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 8===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
|
aioquic.connection/QuicConnection._update_traffic_key
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<0>:<add> crypto = self.spaces[epoch].crypto
<del> crypto = self.crypto[epoch]
|
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
<0> crypto = self.crypto[epoch]
<1> if direction == tls.Direction.ENCRYPT:
<2> crypto.send.setup(self.tls.key_schedule.algorithm, secret)
<3> else:
<4> crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
<5>
|
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
at: aioquic.connection.QuicConnection._payload_received
is_ack_only = True
is_ack_only = False
frame_type = pull_uint_var(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 PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
is_ack_only = False
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
+ offset, data = pull_crypto_frame(buf)
- data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def datagram_received(self, data: bytes):
- def datagram_received(self, data):
+ """
+ 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))
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.crypto_initialized:
+ self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
epoch = get_epoch(header.packet_type)
+ space = self.spaces[epoch]
- crypto = self.crypto[epoch]
+ plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
- plain_header, plain_payload, packet_number = crypto.recv.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
+ # record packet as received
is_ack_only = self._payload_received(plain_payload)
+ space.ack_queue.add(packet_number)
- self.ack[epoch].add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
- self.ack = {
- tls.Epoch.INITIAL: RangeSet(),
- tls.Epoch.HANDSHAKE: RangeSet(),
- tls.Epoch.ONE_RTT: RangeSet(),
- }
- self.crypto = {
- tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.HANDSHAKE: CryptoPair(),
- tls.Epoch.ONE_RTT: CryptoPair(),
- }
- self.packet_number = {
- tls.Epoch.INITIAL: 0,
- tls.Epoch.HANDSHAKE: 0,
- tls.Epoch.ONE_RTT: 0,
- }
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.</s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s> 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.crypto_initialized = False
+ self.packet_number = 0
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 7===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 8===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
|
aioquic.connection/QuicConnection._write_application
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<1>:<add> space = self.spaces[epoch]
<del> crypto = self.crypto[epoch]
<2>:<add> send_ack = space.ack_queue if self.send_ack[epoch] else False
<del> send_ack = self.ack[epoch] if self.send_ack[epoch] else False
<3>:<add> if not space.crypto.send.is_valid() or not send_ack:
<del> if not crypto.send.is_valid() or not send_ack:
<11>:<add> tls.push_uint16(buf, self.packet_number)
<del> tls.push_uint16(buf, self.packet_number[epoch])
<23>:<add> yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<del> yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<25>:<add> self.packet_number += 1
<del> self.packet_number[epoch] += 1
|
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
<0> epoch = tls.Epoch.ONE_RTT
<1> crypto = self.crypto[epoch]
<2> send_ack = self.ack[epoch] if self.send_ack[epoch] else False
<3> if not 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[epoch])
<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 crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
<24>
<25> self.packet_number[epoch] += 1
<26>
|
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
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.packet_number = 0
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
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)
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 _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 1===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
is_ack_only = False
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
+ offset, data = pull_crypto_frame(buf)
- data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
+ def datagram_received(self, data: bytes):
- def datagram_received(self, data):
+ """
+ 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))
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.crypto_initialized:
+ self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=header.destination_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
epoch = get_epoch(header.packet_type)
+ space = self.spaces[epoch]
- crypto = self.crypto[epoch]
+ plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
- plain_header, plain_payload, packet_number = crypto.recv.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
+ # record packet as received
is_ack_only = self._payload_received(plain_payload)
+ space.ack_queue.add(packet_number)
- self.ack[epoch].add(packet_number)
if not is_ack_only:
self.send_ack[epoch] = True
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
- self.ack = {
- tls.Epoch.INITIAL: RangeSet(),
- tls.Epoch.HANDSHAKE: RangeSet(),
- tls.Epoch.ONE_RTT: RangeSet(),
- }
- self.crypto = {
- tls.Epoch.INITIAL: CryptoPair(),
- tls.Epoch.HANDSHAKE: CryptoPair(),
- tls.Epoch.ONE_RTT: CryptoPair(),
- }
- self.packet_number = {
- tls.Epoch.INITIAL: 0,
- tls.Epoch.HANDSHAKE: 0,
- tls.Epoch.ONE_RTT: 0,
- }
self.send_ack = {
tls.Epoch.INITIAL: False,
tls.Epoch.HANDSHAKE: False,
tls.Epoch.ONE_RTT: False,
}
self.send_buffer = {
tls.Epoch.</s>
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<0>:<add> space = self.spaces[epoch]
<del> crypto = self.crypto[epoch]
<1>:<add> send_ack = space.ack_queue if self.send_ack[epoch] else False
<del> send_ack = self.ack[epoch] if self.send_ack[epoch] else False
<4>:<add> if not space.crypto.send.is_valid() or (not send_ack and not send_data):
<del> if not crypto.send.is_valid() or (not send_ack and not send_data):
<33>:<add> bytes(PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell()))
<del> bytes(PACKET_MAX_SIZE - crypto.send.aead_tag_size - buf.tell()))
|
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
<0> crypto = self.crypto[epoch]
<1> send_ack = self.ack[epoch] if self.send_ack[epoch] else False
<2> send_data = self.send_buffer[epoch].data
<3> self.send_buffer[epoch].seek(0)
<4> if not crypto.send.is_valid() or (not send_ack and not send_data):
<5> return
<6>
<7> buf = Buffer(capacity=PACKET_MAX_SIZE)
<8>
<9> if epoch == tls.Epoch.INITIAL:
<10> packet_type = PACKET_TYPE_INITIAL
<11> else:
<12> packet_type = PACKET_TYPE_HANDSHAKE
<13>
<14> # write header
<15> push_quic_header(buf, QuicHeader(
<16> version=PROTOCOL_VERSION_DRAFT_17,
<17> packet_type=packet_type | (SEND_PN_SIZE - 1),
<18> destination_cid=self.peer_cid,
<19> source_cid=self.host_cid,
<20> ))
<21> header_size = buf.tell()
<22>
<23> if send_data:
<24> # CRYPTO
<25> push_uint_var(buf, QuicFrameType.CRYPTO)
<26> with push_crypto_frame(buf):
<27> tls.push_bytes(buf, send_data)
<28>
<29> # PADDING
<30> if epoch == tls.Epoch.INITIAL:
<31> tls.push_bytes(
<32> buf,
<33> bytes(PACKET_MAX_SIZE - crypto.send.aead_tag_size - buf.tell()))
<34>
<35> # ACK
<36> if send_ack:
<37> push_uint_var(buf, QuicFrameType.ACK)
<38> push_ack_frame(buf, send_ack, 0)
<39> self.send_ack[epoch] = False
<40>
<41> # finalize length
<42> packet_size = buf.tell()
<43> buf.seek(header_size - SEND_PN_SIZE</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
length = packet_size - header_size + 2 + crypto.send.aead_tag_size
tls.push_uint16(buf, length | 0x4000)
tls.push_uint16(buf, self.packet_number[epoch])
buf.seek(packet_size)
# encrypt
data = buf.data
yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
self.packet_number[epoch] += 1
===========unchanged ref 0===========
at: aioquic.connection
PACKET_MAX_SIZE = 1280
SEND_PN_SIZE = 2
at: aioquic.connection.QuicConnection.__init__
self.packet_number = 0
self.packet_number = {
tls.Epoch.INITIAL: 0,
tls.Epoch.HANDSHAKE: 0,
tls.Epoch.ONE_RTT: 0,
}
at: aioquic.connection.QuicConnection._write_application
header_size = buf.tell()
packet_size = buf.tell()
data = buf.data
at: aioquic.packet
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PROTOCOL_VERSION_DRAFT_17 = 0xff000011 # draft 17
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)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_crypto_frame(buf, offset=0)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
push_bytes(buf: Buffer, v: bytes)
push_uint16(buf: Buffer, v: int)
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 1===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
is_ack_only = False
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
+ offset, data = pull_crypto_frame(buf)
- data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
+ space = self.spaces[epoch]
- crypto = self.crypto[epoch]
+ send_ack = space.ack_queue if self.send_ack[epoch] else False
- send_ack = self.ack[epoch] if self.send_ack[epoch] else False
+ if not space.crypto.send.is_valid() or not send_ack:
- if not 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)
- tls.push_uint16(buf, self.packet_number[epoch])
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
# encrypt
packet_size = buf.tell()
data = buf.data
+ yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
- yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
+ self.packet_number += 1
- self.packet_number[epoch] += 1
|
tests.test_crypto/CryptoTest.test_decrypt_long_client
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<2>:<add> plain_header, plain_payload, packet_number = pair.decrypt_packet(
<del> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_client(self):
<0> pair = self.create_crypto(is_client=False)
<1>
<2> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
<3> LONG_CLIENT_ENCRYPTED_PACKET, 17)
<4> self.assertEqual(plain_header, LONG_CLIENT_PLAIN_HEADER)
<5> self.assertEqual(plain_payload, LONG_CLIENT_PLAIN_PAYLOAD)
<6> self.assertEqual(packet_number, 2)
<7>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: tests.test_crypto
LONG_CLIENT_PLAIN_HEADER = binascii.unhexlify('c3ff000012508394c8f03e51570800449f00000002')
LONG_CLIENT_PLAIN_PAYLOAD = binascii.unhexlify(
'060040c4010000c003036660261ff947cea49cce6cfad687f457cf1b14531ba1'
'4131a0e8f309a1d0b9c4000006130113031302010000910000000b0009000006'
'736572766572ff01000100000a00140012001d00170018001901000101010201'
'03010400230000003300260024001d00204cfdfcd178b784bf328cae793b136f'
'2aedce005ff183d7bb1495207236647037002b0003020304000d0020001e0403'
'05030603020308040805080604010501060102010402050206020202002d0002'
'0101001c00024001') + bytes(963)
===========unchanged ref 1===========
LONG_CLIENT_ENCRYPTED_PACKET = binascii.unhexlify(
'c1ff000012508394c8f03e51570800449f0dbc195a0000f3a694c75775b4e546'
'172ce9e047cd0b5bee5181648c727adc87f7eae54473ec6cba6bdad4f5982317'
'4b769f12358abd292d4f3286934484fb8b239c38732e1f3bbbc6a003056487eb'
'8b5c88b9fd9279ffff3b0f4ecf95c4624db6d65d4113329ee9b0bf8cdd7c8a8d'
'72806d55df25ecb66488bc119d7c9a29abaf99bb33c56b08ad8c26995f838bb3'
'b7a3d5c1858b8ec06b839db2dcf918d5ea9317f1acd6b663cc8925868e2f6a1b'
'da546695f3c3f33175944db4a11a346afb07e78489e509b02add51b7b203eda5'
'c330b03641179a31fbba9b56ce00f3d5b5e3d7d9c5429aebb9576f2f7eacbe27'
'bc1b8082aaf68fb69c921aa5d33ec0c8510410865a178d86d7e54122d55ef2c2'
'bbc040be46d7fece73fe8a1b24495ec160df2da9b20a7ba2f26dfa2a44366dbc'
'63de5cd7d7c94c57172fe6d79c901f025c00</s>
===========unchanged ref 2===========
at: tests.test_crypto.CryptoTest
create_crypto(is_client)
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.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 1===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 2===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 3===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 4===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 5===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 6===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 7===========
# 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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 8===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
is_ack_only = False
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
+ offset, data = pull_crypto_frame(buf)
- data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
|
tests.test_crypto/CryptoTest.test_decrypt_long_server
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<2>:<add> plain_header, plain_payload, packet_number = pair.decrypt_packet(
<del> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_server(self):
<0> pair = self.create_crypto(is_client=True)
<1>
<2> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
<3> LONG_SERVER_ENCRYPTED_PACKET, 17)
<4> self.assertEqual(plain_header, LONG_SERVER_PLAIN_HEADER)
<5> self.assertEqual(plain_payload, LONG_SERVER_PLAIN_PAYLOAD)
<6> self.assertEqual(packet_number, 1)
<7>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: tests.test_crypto
LONG_SERVER_PLAIN_HEADER = binascii.unhexlify('c1ff00001205f067a5502a4262b50040740001')
LONG_SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'0d0000000018410a020000560303eefce7f7b37ba1d1632e96677825ddf73988'
'cfc79825df566dc5430b9a045a1200130100002e00330024001d00209d3c940d'
'89690b84d08a60993c144eca684d1081287c834d5311bcf32bb9da1a002b0002'
'0304')
LONG_SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'c4ff00001205f067a5502a4262b5004074f7ed5f01c4c2a2303d297e3c519bf6'
'b22386e3d0bd6dfc66121677298031041bb9a79c9f0f9d4c5877270a660f5da3'
'6207d98b73839b2fdf2ef8e7df5a51b17b8c68d864fd3e708c6c1b71a98a3318'
'15599ef5014ea38c44bdfd387c03b5275c35e009b6238f831420047c7271281c'
'cb54df7884')
at: tests.test_crypto.CryptoTest
create_crypto(is_client)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_client(self):
pair = self.create_crypto(is_client=False)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 2===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 3===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 4===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 5===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 6===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 7===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 8===========
# 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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 9===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
is_ack_only = False
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
+ offset, data = pull_crypto_frame(buf)
- data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
===========changed ref 10===========
# module: aioquic.connection
class QuicConnection:
def _write_application(self):
epoch = tls.Epoch.ONE_RTT
+ space = self.spaces[epoch]
- crypto = self.crypto[epoch]
+ send_ack = space.ack_queue if self.send_ack[epoch] else False
- send_ack = self.ack[epoch] if self.send_ack[epoch] else False
+ if not space.crypto.send.is_valid() or not send_ack:
- if not 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)
- tls.push_uint16(buf, self.packet_number[epoch])
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
# encrypt
packet_size = buf.tell()
data = buf.data
+ yield space.crypto.encrypt_packet(data[0:header_size], data[header_size:packet_size])
- yield crypto.send.encrypt_packet(data[0:header_size], data[header_size:packet_size])
+ self.packet_number += 1
- self.packet_number[epoch] += 1
|
tests.test_crypto/CryptoTest.test_decrypt_short_server
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<5>:<add> plain_header, plain_payload, packet_number = pair.decrypt_packet(
<del> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_short_server(self):
<0> pair = CryptoPair()
<1> pair.recv.setup(
<2> INITIAL_ALGORITHM,
<3> binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
<4>
<5> plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
<6> SHORT_SERVER_ENCRYPTED_PACKET, 9)
<7> self.assertEqual(plain_header, SHORT_SERVER_PLAIN_HEADER)
<8> self.assertEqual(plain_payload, SHORT_SERVER_PLAIN_PAYLOAD)
<9> self.assertEqual(packet_number, 3)
<10>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_ALGORITHM = hashes.SHA256()
CryptoPair()
at: aioquic.crypto.CryptoContext
setup(algorithm, secret)
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_crypto
SHORT_SERVER_PLAIN_HEADER = binascii.unhexlify('41b01fd24a586a9cf30003')
SHORT_SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'06003904000035000151805a4bebf5000020b098c8dc4183e4c182572e10ac3e'
'2b88897e0524c8461847548bd2dffa2c0ae60008002a0004ffffffff')
SHORT_SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'5db01fd24a586a9cf33dec094aaec6d6b4b7a5e15f5a3f05d06cf1ad0355c19d'
'cce0807eecf7bf1c844a66e1ecd1f74b2a2d69bfd25d217833edd973246597bd'
'5107ea15cb1e210045396afa602fe23432f4ab24ce251b')
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_server(self):
pair = self.create_crypto(is_client=True)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 1)
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_client(self):
pair = self.create_crypto(is_client=False)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 4===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 5===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 7===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 8===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 9===========
# 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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 10===========
# module: aioquic.connection
class QuicConnection:
def _payload_received(self, plain):
buf = Buffer(data=plain)
is_ack_only = True
while not buf.eof():
frame_type = pull_uint_var(buf)
if frame_type in [QuicFrameType.PADDING, QuicFrameType.PING]:
is_ack_only = False
elif frame_type == QuicFrameType.ACK:
pull_ack_frame(buf)
elif frame_type == QuicFrameType.CRYPTO:
is_ack_only = False
+ offset, data = pull_crypto_frame(buf)
- data = pull_crypto_frame(buf)
assert len(data)
self.tls.handle_message(data, self.send_buffer)
elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
is_ack_only = False
pull_new_connection_id_frame(buf)
else:
logger.warning('unhandled frame type %d', frame_type)
break
return is_ack_only
|
tests.test_crypto/CryptoTest.test_encrypt_long_client
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<2>:<add> packet = pair.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
<del> packet = pair.send.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_long_client(self):
<0> pair = self.create_crypto(is_client=True)
<1>
<2> packet = pair.send.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
<3> self.assertEqual(packet, LONG_CLIENT_ENCRYPTED_PACKET)
<4>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: tests.test_crypto
LONG_CLIENT_PLAIN_HEADER = binascii.unhexlify('c3ff000012508394c8f03e51570800449f00000002')
LONG_CLIENT_PLAIN_PAYLOAD = binascii.unhexlify(
'060040c4010000c003036660261ff947cea49cce6cfad687f457cf1b14531ba1'
'4131a0e8f309a1d0b9c4000006130113031302010000910000000b0009000006'
'736572766572ff01000100000a00140012001d00170018001901000101010201'
'03010400230000003300260024001d00204cfdfcd178b784bf328cae793b136f'
'2aedce005ff183d7bb1495207236647037002b0003020304000d0020001e0403'
'05030603020308040805080604010501060102010402050206020202002d0002'
'0101001c00024001') + bytes(963)
===========unchanged ref 1===========
LONG_CLIENT_ENCRYPTED_PACKET = binascii.unhexlify(
'c1ff000012508394c8f03e51570800449f0dbc195a0000f3a694c75775b4e546'
'172ce9e047cd0b5bee5181648c727adc87f7eae54473ec6cba6bdad4f5982317'
'4b769f12358abd292d4f3286934484fb8b239c38732e1f3bbbc6a003056487eb'
'8b5c88b9fd9279ffff3b0f4ecf95c4624db6d65d4113329ee9b0bf8cdd7c8a8d'
'72806d55df25ecb66488bc119d7c9a29abaf99bb33c56b08ad8c26995f838bb3'
'b7a3d5c1858b8ec06b839db2dcf918d5ea9317f1acd6b663cc8925868e2f6a1b'
'da546695f3c3f33175944db4a11a346afb07e78489e509b02add51b7b203eda5'
'c330b03641179a31fbba9b56ce00f3d5b5e3d7d9c5429aebb9576f2f7eacbe27'
'bc1b8082aaf68fb69c921aa5d33ec0c8510410865a178d86d7e54122d55ef2c2'
'bbc040be46d7fece73fe8a1b24495ec160df2da9b20a7ba2f26dfa2a44366dbc'
'63de5cd7d7c94c57172fe6d79c901f025c00</s>
===========unchanged ref 2===========
at: tests.test_crypto.CryptoTest
create_crypto(is_client)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_server(self):
pair = self.create_crypto(is_client=True)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 1)
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_client(self):
pair = self.create_crypto(is_client=False)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_short_server(self):
pair = CryptoPair()
pair.recv.setup(
INITIAL_ALGORITHM,
binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
SHORT_SERVER_ENCRYPTED_PACKET, 9)
self.assertEqual(plain_header, SHORT_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SHORT_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 3)
===========changed ref 4===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 5===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 6===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 7===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 8===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 9===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
|
tests.test_crypto/CryptoTest.test_encrypt_long_server
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<2>:<add> packet = pair.encrypt_packet(LONG_SERVER_PLAIN_HEADER, LONG_SERVER_PLAIN_PAYLOAD)
<del> packet = pair.send.encrypt_packet(LONG_SERVER_PLAIN_HEADER, LONG_SERVER_PLAIN_PAYLOAD)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_long_server(self):
<0> pair = self.create_crypto(is_client=False)
<1>
<2> packet = pair.send.encrypt_packet(LONG_SERVER_PLAIN_HEADER, LONG_SERVER_PLAIN_PAYLOAD)
<3> self.assertEqual(packet, LONG_SERVER_ENCRYPTED_PACKET)
<4>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: tests.test_crypto
LONG_SERVER_PLAIN_HEADER = binascii.unhexlify('c1ff00001205f067a5502a4262b50040740001')
LONG_SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'0d0000000018410a020000560303eefce7f7b37ba1d1632e96677825ddf73988'
'cfc79825df566dc5430b9a045a1200130100002e00330024001d00209d3c940d'
'89690b84d08a60993c144eca684d1081287c834d5311bcf32bb9da1a002b0002'
'0304')
LONG_SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'c4ff00001205f067a5502a4262b5004074f7ed5f01c4c2a2303d297e3c519bf6'
'b22386e3d0bd6dfc66121677298031041bb9a79c9f0f9d4c5877270a660f5da3'
'6207d98b73839b2fdf2ef8e7df5a51b17b8c68d864fd3e708c6c1b71a98a3318'
'15599ef5014ea38c44bdfd387c03b5275c35e009b6238f831420047c7271281c'
'cb54df7884')
at: tests.test_crypto.CryptoTest
create_crypto(is_client)
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_long_client(self):
pair = self.create_crypto(is_client=True)
+ packet = pair.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
- packet = pair.send.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet, LONG_CLIENT_ENCRYPTED_PACKET)
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_server(self):
pair = self.create_crypto(is_client=True)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 1)
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_client(self):
pair = self.create_crypto(is_client=False)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 4===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_short_server(self):
pair = CryptoPair()
pair.recv.setup(
INITIAL_ALGORITHM,
binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
SHORT_SERVER_ENCRYPTED_PACKET, 9)
self.assertEqual(plain_header, SHORT_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SHORT_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 3)
===========changed ref 5===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 6===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 7===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 8===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 9===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 10===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 11===========
# 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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
|
tests.test_crypto/CryptoTest.test_encrypt_short_server
|
Modified
|
aiortc~aioquic
|
ac4dcbd7b7d60cf34c74fe6aa7b0bd60935c7ba8
|
[connection] add PacketSpace class
|
<5>:<add> packet = pair.encrypt_packet(SHORT_SERVER_PLAIN_HEADER, SHORT_SERVER_PLAIN_PAYLOAD)
<del> packet = pair.send.encrypt_packet(SHORT_SERVER_PLAIN_HEADER, SHORT_SERVER_PLAIN_PAYLOAD)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_short_server(self):
<0> pair = CryptoPair()
<1> pair.send.setup(
<2> INITIAL_ALGORITHM,
<3> binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
<4>
<5> packet = pair.send.encrypt_packet(SHORT_SERVER_PLAIN_HEADER, SHORT_SERVER_PLAIN_PAYLOAD)
<6> self.assertEqual(packet, SHORT_SERVER_ENCRYPTED_PACKET)
<7>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_ALGORITHM = hashes.SHA256()
CryptoPair()
at: aioquic.crypto.CryptoContext
setup(algorithm, secret)
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.send = CryptoContext()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_crypto
SHORT_SERVER_PLAIN_HEADER = binascii.unhexlify('41b01fd24a586a9cf30003')
SHORT_SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'06003904000035000151805a4bebf5000020b098c8dc4183e4c182572e10ac3e'
'2b88897e0524c8461847548bd2dffa2c0ae60008002a0004ffffffff')
SHORT_SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'5db01fd24a586a9cf33dec094aaec6d6b4b7a5e15f5a3f05d06cf1ad0355c19d'
'cce0807eecf7bf1c844a66e1ecd1f74b2a2d69bfd25d217833edd973246597bd'
'5107ea15cb1e210045396afa602fe23432f4ab24ce251b')
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoPair:
+ def encrypt_packet(self, plain_header, plain_payload):
+ return self.send.encrypt_packet(plain_header, plain_payload)
+
===========changed ref 1===========
# module: aioquic.crypto
class CryptoContext:
def setup(self, algorithm, secret):
key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
self.aead = aead.AESGCM(key)
- self.aead_tag_size = 16
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_long_server(self):
pair = self.create_crypto(is_client=False)
+ packet = pair.encrypt_packet(LONG_SERVER_PLAIN_HEADER, LONG_SERVER_PLAIN_PAYLOAD)
- packet = pair.send.encrypt_packet(LONG_SERVER_PLAIN_HEADER, LONG_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet, LONG_SERVER_ENCRYPTED_PACKET)
===========changed ref 3===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_long_client(self):
pair = self.create_crypto(is_client=True)
+ packet = pair.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
- packet = pair.send.encrypt_packet(LONG_CLIENT_PLAIN_HEADER, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet, LONG_CLIENT_ENCRYPTED_PACKET)
===========changed ref 4===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_server(self):
pair = self.create_crypto(is_client=True)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_SERVER_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 1)
===========changed ref 5===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_long_client(self):
pair = self.create_crypto(is_client=False)
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
LONG_CLIENT_ENCRYPTED_PACKET, 17)
self.assertEqual(plain_header, LONG_CLIENT_PLAIN_HEADER)
self.assertEqual(plain_payload, LONG_CLIENT_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 2)
===========changed ref 6===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_short_server(self):
pair = CryptoPair()
pair.recv.setup(
INITIAL_ALGORITHM,
binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
+ plain_header, plain_payload, packet_number = pair.decrypt_packet(
- plain_header, plain_payload, packet_number = pair.recv.decrypt_packet(
SHORT_SERVER_ENCRYPTED_PACKET, 9)
self.assertEqual(plain_header, SHORT_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SHORT_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 3)
===========changed ref 7===========
# module: aioquic.crypto
class CryptoPair:
+ def decrypt_packet(self, packet, encrypted_offset):
+ return self.recv.decrypt_packet(packet, encrypted_offset)
+
===========changed ref 8===========
# module: aioquic.connection
+ class PacketSpace:
+ def __init__(self):
+ self.ack_queue = RangeSet()
+ self.crypto = CryptoPair()
+
===========changed ref 9===========
# module: aioquic.crypto
class CryptoPair:
def __init__(self):
+ self.aead_tag_size = 16
self.recv = CryptoContext()
self.send = CryptoContext()
===========changed ref 10===========
# module: aioquic.packet
def pull_crypto_frame(buf):
+ offset = pull_uint_var(buf)
- pull_uint_var(buf)
length = pull_uint_var(buf)
+ return offset, pull_bytes(buf, length)
- return pull_bytes(buf, length)
===========changed ref 11===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ crypto = self.spaces[epoch].crypto
- crypto = self.crypto[epoch]
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 12===========
# 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,
- self.crypto[tls.Epoch.INITIAL].setup_initial(cid=self.peer_cid,
+ is_client=self.is_client)
- is_client=self.is_client)
self.crypto_initialized = True
self.tls.handle_message(b'', self.send_buffer)
|
aioquic.rangeset/RangeSet.__init__
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<0>:<add> self.__ranges: List[range] = []
<del> self.ranges = []
<1>:<add> for r in ranges:
<add> assert r.step == 1
<add> self.add(r.start, r.stop)
|
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
<0> self.ranges = []
<1>
|
===========unchanged ref 0===========
at: typing
Sequence = _alias(collections.abc.Sequence, 1)
|
aioquic.rangeset/RangeSet.add
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<0>:<add> if stop is None:
<add> stop = start + 1
<add> assert stop > start
<add>
<add> for i, r in enumerate(self.__ranges):
<del> for i, r in enumerate(self.ranges):
<1>:<del> if pn in r:
<2>:<del> return
<3>:<add> # the added range is entirely before current item, insert here
<add> if stop < r.start:
<del> if r.stop == pn:
<4>:<del> if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
<5>:<del> self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
<6>:<del> self.ranges.pop(i + 1)
<7>:<del> else:
<8>:<del> self.ranges[i] = range(r.start, r.stop + 1)
<9>:<del> return
<10>:<del> if r.start == pn + 1:
<11>:<add> self.__ranges.insert(i, range(start, stop))
<del> self.ranges[i] = range(pn, r.stop)
<14>:<add> # the added range is entirely after current item, keep looking
<add> if start > r.stop:
<add> continue
<del> self.ranges.append(range(pn, pn + 1))
|
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
<0> for i, r in enumerate(self.ranges):
<1> if pn in r:
<2> return
<3> if r.stop == pn:
<4> if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
<5> self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
<6> self.ranges.pop(i + 1)
<7> else:
<8> self.ranges[i] = range(r.start, r.stop + 1)
<9> return
<10> if r.start == pn + 1:
<11> self.ranges[i] = range(pn, r.stop)
<12> return
<13>
<14> self.ranges.append(range(pn, pn + 1))
<15>
|
===========unchanged ref 0===========
at: typing
Iterable = _alias(collections.abc.Iterable, 1)
Sequence = _alias(collections.abc.Sequence, 1)
List = _alias(list, 1, inst=False, name='List')
===========changed ref 0===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
+ self.__ranges: List[range] = []
- self.ranges = []
+ for r in ranges:
+ assert r.step == 1
+ self.add(r.start, r.stop)
|
aioquic.rangeset/RangeSet.__bool__
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<0>:<add> return bool(self.__ranges)
<del> return bool(self.ranges)
|
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
def __bool__(self):
<0> return bool(self.ranges)
<1>
|
===========unchanged ref 0===========
at: aioquic.rangeset.RangeSet.__init__
self.__ranges: List[range] = []
at: aioquic.rangeset.RangeSet.add
stop = start + 1
===========changed ref 0===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
+ self.__ranges: List[range] = []
- self.ranges = []
+ for r in ranges:
+ assert r.step == 1
+ self.add(r.start, r.stop)
===========changed ref 1===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
+ if stop is None:
+ stop = start + 1
+ assert stop > start
+
+ for i, r in enumerate(self.__ranges):
- for i, r in enumerate(self.ranges):
- if pn in r:
- return
+ # the added range is entirely before current item, insert here
+ if stop < r.start:
- if r.stop == pn:
- if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
- self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
- self.ranges.pop(i + 1)
- else:
- self.ranges[i] = range(r.start, r.stop + 1)
- return
- if r.start == pn + 1:
+ self.__ranges.insert(i, range(start, stop))
- self.ranges[i] = range(pn, r.stop)
return
+ # the added range is entirely after current item, keep looking
+ if start > r.stop:
+ continue
- self.ranges.append(range(pn, pn + 1))
|
aioquic.packet/pull_ack_frame
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<5>:<add> rangeset.add(end - ack_count, end + 1)
<del> rangeset.ranges.insert(0, range(end - ack_count, end + 1))
<10>:<add> rangeset.add(end - ack_count, end + 1)
<del> rangeset.ranges.insert(0, range(end - ack_count, end + 1))
|
# module: aioquic.packet
def pull_ack_frame(buf):
<0> rangeset = RangeSet()
<1> end = pull_uint_var(buf) # largest acknowledged
<2> delay = pull_uint_var(buf)
<3> ack_range_count = pull_uint_var(buf)
<4> ack_count = pull_uint_var(buf) # first ack range
<5> rangeset.ranges.insert(0, range(end - ack_count, end + 1))
<6> end -= ack_count
<7> for _ in range(ack_range_count):
<8> end -= pull_uint_var(buf)
<9> ack_count = pull_uint_var(buf)
<10> rangeset.ranges.insert(0, range(end - ack_count, end + 1))
<11> end -= ack_count
<12> return rangeset, delay
<13>
|
===========unchanged ref 0===========
at: aioquic.packet
pull_uint_var(buf)
at: aioquic.rangeset
RangeSet(ranges: Iterable[range]=[])
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
===========changed ref 0===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
+ if stop is None:
+ stop = start + 1
+ assert stop > start
+
+ for i, r in enumerate(self.__ranges):
- for i, r in enumerate(self.ranges):
- if pn in r:
- return
+ # the added range is entirely before current item, insert here
+ if stop < r.start:
- if r.stop == pn:
- if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
- self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
- self.ranges.pop(i + 1)
- else:
- self.ranges[i] = range(r.start, r.stop + 1)
- return
- if r.start == pn + 1:
+ self.__ranges.insert(i, range(start, stop))
- self.ranges[i] = range(pn, r.stop)
return
+ # the added range is entirely after current item, keep looking
+ if start > r.stop:
+ continue
- self.ranges.append(range(pn, pn + 1))
===========changed ref 1===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __len__(self):
+ return len(self.__ranges)
+
===========changed ref 2===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __getitem__(self, key) -> range:
+ return self.__ranges[key]
+
===========changed ref 3===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __repr__(self):
+ return 'RangeSet({})'.format(repr(self.__ranges))
+
===========changed ref 4===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
def __bool__(self):
+ return bool(self.__ranges)
- return bool(self.ranges)
===========changed ref 5===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __eq__(self, other: object):
+ if not isinstance(other, RangeSet):
+ return NotImplemented
+
+ return self.__ranges == other.__ranges
+
===========changed ref 6===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
+ self.__ranges: List[range] = []
- self.ranges = []
+ for r in ranges:
+ assert r.step == 1
+ self.add(r.start, r.stop)
|
aioquic.packet/push_ack_frame
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<0>:<add> index = len(rangeset) - 1
<del> index = len(rangeset.ranges) - 1
<1>:<add> r = rangeset[index]
<del> r = rangeset.ranges[index]
<9>:<add> r = rangeset[index]
<del> r = rangeset.ranges[index]
|
# module: aioquic.packet
def push_ack_frame(buf, rangeset: RangeSet, delay: int):
<0> index = len(rangeset.ranges) - 1
<1> r = rangeset.ranges[index]
<2> push_uint_var(buf, r.stop - 1)
<3> push_uint_var(buf, delay)
<4> push_uint_var(buf, index)
<5> push_uint_var(buf, r.stop - 1 - r.start)
<6> start = r.start
<7> while index > 0:
<8> index -= 1
<9> r = rangeset.ranges[index]
<10> push_uint_var(buf, start - r.stop + 1)
<11> push_uint_var(buf, r.stop - r.start - 1)
<12> start = r.start
<13>
|
===========unchanged ref 0===========
at: aioquic.packet
push_uint_var(buf, value)
at: aioquic.rangeset
RangeSet(ranges: Iterable[range]=[])
===========changed ref 0===========
# module: aioquic.packet
def pull_ack_frame(buf):
rangeset = RangeSet()
end = pull_uint_var(buf) # largest acknowledged
delay = pull_uint_var(buf)
ack_range_count = pull_uint_var(buf)
ack_count = pull_uint_var(buf) # first ack range
+ rangeset.add(end - ack_count, end + 1)
- rangeset.ranges.insert(0, range(end - ack_count, end + 1))
end -= ack_count
for _ in range(ack_range_count):
end -= pull_uint_var(buf)
ack_count = pull_uint_var(buf)
+ rangeset.add(end - ack_count, end + 1)
- rangeset.ranges.insert(0, range(end - ack_count, end + 1))
end -= ack_count
return rangeset, delay
===========changed ref 1===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __len__(self):
+ return len(self.__ranges)
+
===========changed ref 2===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __getitem__(self, key) -> range:
+ return self.__ranges[key]
+
===========changed ref 3===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __repr__(self):
+ return 'RangeSet({})'.format(repr(self.__ranges))
+
===========changed ref 4===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
def __bool__(self):
+ return bool(self.__ranges)
- return bool(self.ranges)
===========changed ref 5===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __eq__(self, other: object):
+ if not isinstance(other, RangeSet):
+ return NotImplemented
+
+ return self.__ranges == other.__ranges
+
===========changed ref 6===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
+ self.__ranges: List[range] = []
- self.ranges = []
+ for r in ranges:
+ assert r.step == 1
+ self.add(r.start, r.stop)
===========changed ref 7===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
+ if stop is None:
+ stop = start + 1
+ assert stop > start
+
+ for i, r in enumerate(self.__ranges):
- for i, r in enumerate(self.ranges):
- if pn in r:
- return
+ # the added range is entirely before current item, insert here
+ if stop < r.start:
- if r.stop == pn:
- if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
- self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
- self.ranges.pop(i + 1)
- else:
- self.ranges[i] = range(r.start, r.stop + 1)
- return
- if r.start == pn + 1:
+ self.__ranges.insert(i, range(start, stop))
- self.ranges[i] = range(pn, r.stop)
return
+ # the added range is entirely after current item, keep looking
+ if start > r.stop:
+ continue
- self.ranges.append(range(pn, pn + 1))
|
tests.test_packet/FrameTest.test_ack_frame
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<5>:<add> self.assertEqual(list(rangeset), [
<del> self.assertEqual(rangeset.ranges, [
|
# 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(rangeset.ranges, [
<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 push_ack_frame(buf, rangeset: RangeSet, delay: int):
+ index = len(rangeset) - 1
- index = len(rangeset.ranges) - 1
+ r = rangeset[index]
- r = rangeset.ranges[index]
push_uint_var(buf, r.stop - 1)
push_uint_var(buf, delay)
push_uint_var(buf, index)
push_uint_var(buf, r.stop - 1 - r.start)
start = r.start
while index > 0:
index -= 1
+ r = rangeset[index]
- r = rangeset.ranges[index]
push_uint_var(buf, start - r.stop + 1)
push_uint_var(buf, r.stop - r.start - 1)
start = r.start
===========changed ref 1===========
# module: aioquic.packet
def pull_ack_frame(buf):
rangeset = RangeSet()
end = pull_uint_var(buf) # largest acknowledged
delay = pull_uint_var(buf)
ack_range_count = pull_uint_var(buf)
ack_count = pull_uint_var(buf) # first ack range
+ rangeset.add(end - ack_count, end + 1)
- rangeset.ranges.insert(0, range(end - ack_count, end + 1))
end -= ack_count
for _ in range(ack_range_count):
end -= pull_uint_var(buf)
ack_count = pull_uint_var(buf)
+ rangeset.add(end - ack_count, end + 1)
- rangeset.ranges.insert(0, range(end - ack_count, end + 1))
end -= ack_count
return rangeset, delay
===========changed ref 2===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __len__(self):
+ return len(self.__ranges)
+
===========changed ref 3===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __getitem__(self, key) -> range:
+ return self.__ranges[key]
+
===========changed ref 4===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __repr__(self):
+ return 'RangeSet({})'.format(repr(self.__ranges))
+
===========changed ref 5===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
def __bool__(self):
+ return bool(self.__ranges)
- return bool(self.ranges)
===========changed ref 6===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __eq__(self, other: object):
+ if not isinstance(other, RangeSet):
+ return NotImplemented
+
+ return self.__ranges == other.__ranges
+
===========changed ref 7===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
+ self.__ranges: List[range] = []
- self.ranges = []
+ for r in ranges:
+ assert r.step == 1
+ self.add(r.start, r.stop)
===========changed ref 8===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
+ if stop is None:
+ stop = start + 1
+ assert stop > start
+
+ for i, r in enumerate(self.__ranges):
- for i, r in enumerate(self.ranges):
- if pn in r:
- return
+ # the added range is entirely before current item, insert here
+ if stop < r.start:
- if r.stop == pn:
- if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
- self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
- self.ranges.pop(i + 1)
- else:
- self.ranges[i] = range(r.start, r.stop + 1)
- return
- if r.start == pn + 1:
+ self.__ranges.insert(i, range(start, stop))
- self.ranges[i] = range(pn, r.stop)
return
+ # the added range is entirely after current item, keep looking
+ if start > r.stop:
+ continue
- self.ranges.append(range(pn, pn + 1))
|
tests.test_packet/FrameTest.test_ack_frame_with_ranges
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<5>:<add> self.assertEqual(list(rangeset), [
<del> self.assertEqual(rangeset.ranges, [
|
# 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(rangeset.ranges, [
<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: aioquic.packet
def push_ack_frame(buf, rangeset: RangeSet, delay: int):
+ index = len(rangeset) - 1
- index = len(rangeset.ranges) - 1
+ r = rangeset[index]
- r = rangeset.ranges[index]
push_uint_var(buf, r.stop - 1)
push_uint_var(buf, delay)
push_uint_var(buf, index)
push_uint_var(buf, r.stop - 1 - r.start)
start = r.start
while index > 0:
index -= 1
+ r = rangeset[index]
- r = rangeset.ranges[index]
push_uint_var(buf, start - r.stop + 1)
push_uint_var(buf, r.stop - r.start - 1)
start = r.start
===========changed ref 1===========
# module: aioquic.packet
def pull_ack_frame(buf):
rangeset = RangeSet()
end = pull_uint_var(buf) # largest acknowledged
delay = pull_uint_var(buf)
ack_range_count = pull_uint_var(buf)
ack_count = pull_uint_var(buf) # first ack range
+ rangeset.add(end - ack_count, end + 1)
- rangeset.ranges.insert(0, range(end - ack_count, end + 1))
end -= ack_count
for _ in range(ack_range_count):
end -= pull_uint_var(buf)
ack_count = pull_uint_var(buf)
+ rangeset.add(end - ack_count, end + 1)
- rangeset.ranges.insert(0, range(end - ack_count, end + 1))
end -= ack_count
return rangeset, delay
===========changed ref 2===========
# 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 = pull_ack_frame(buf)
+ self.assertEqual(list(rangeset), [
- self.assertEqual(rangeset.ranges, [
range(0, 1)
])
self.assertEqual(delay, 2)
# serialize
buf = Buffer(capacity=8)
push_ack_frame(buf, rangeset, delay)
self.assertEqual(buf.data, data)
===========changed ref 3===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __len__(self):
+ return len(self.__ranges)
+
===========changed ref 4===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __getitem__(self, key) -> range:
+ return self.__ranges[key]
+
===========changed ref 5===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __repr__(self):
+ return 'RangeSet({})'.format(repr(self.__ranges))
+
===========changed ref 6===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
def __bool__(self):
+ return bool(self.__ranges)
- return bool(self.ranges)
===========changed ref 7===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __eq__(self, other: object):
+ if not isinstance(other, RangeSet):
+ return NotImplemented
+
+ return self.__ranges == other.__ranges
+
===========changed ref 8===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __init__(self, ranges: Iterable[range] = []):
- def __init__(self):
+ self.__ranges: List[range] = []
- self.ranges = []
+ for r in ranges:
+ assert r.step == 1
+ self.add(r.start, r.stop)
===========changed ref 9===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
+ if stop is None:
+ stop = start + 1
+ assert stop > start
+
+ for i, r in enumerate(self.__ranges):
- for i, r in enumerate(self.ranges):
- if pn in r:
- return
+ # the added range is entirely before current item, insert here
+ if stop < r.start:
- if r.stop == pn:
- if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
- self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
- self.ranges.pop(i + 1)
- else:
- self.ranges[i] = range(r.start, r.stop + 1)
- return
- if r.start == pn + 1:
+ self.__ranges.insert(i, range(start, stop))
- self.ranges[i] = range(pn, r.stop)
return
+ # the added range is entirely after current item, keep looking
+ if start > r.stop:
+ continue
- self.ranges.append(range(pn, pn + 1))
|
tests.test_rangeset/RangeSetTest.test_bool
|
Modified
|
aiortc~aioquic
|
a559cb0d8f7e63fd867f26f6a0f5208aacfd346b
|
[rangeset] add support for adding a range, inherit Sequence
|
<3>:<add> rangeset = RangeSet([range(0, 1)])
<del> rangeset.add(0)
|
# module: tests.test_rangeset
class RangeSetTest(TestCase):
def test_bool(self):
<0> rangeset = RangeSet()
<1> self.assertFalse(bool(rangeset))
<2>
<3> rangeset.add(0)
<4> self.assertTrue(bool(rangeset))
<5>
|
===========unchanged ref 0===========
at: aioquic.rangeset
RangeSet(ranges: Iterable[range]=[])
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=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.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def add(self, start: int, stop: Optional[int] = None):
- def add(self, pn):
+ if stop is None:
+ stop = start + 1
+ assert stop > start
+
+ for i, r in enumerate(self.__ranges):
- for i, r in enumerate(self.ranges):
- if pn in r:
- return
+ # the added range is entirely before current item, insert here
+ if stop < r.start:
- if r.stop == pn:
- if i < len(self.ranges) - 1 and self.ranges[i + 1].start == pn + 1:
- self.ranges[i] = range(r.start, self.ranges[i + 1].stop)
- self.ranges.pop(i + 1)
- else:
- self.ranges[i] = range(r.start, r.stop + 1)
- return
- if r.start == pn + 1:
+ self.__ranges.insert(i, range(start, stop))
- self.ranges[i] = range(pn, r.stop)
return
+ # the added range is entirely after current item, keep looking
+ if start > r.stop:
+ continue
- self.ranges.append(range(pn, pn + 1))
===========changed ref 1===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
+ def test_add_range_ordered(self):
+ rangeset = RangeSet()
+
+ rangeset.add(0, 2)
+ self.assertEqual(list(rangeset), [
+ range(0, 2),
+ ])
+
+ rangeset.add(2, 4)
+ self.assertEqual(list(rangeset), [
+ range(0, 4),
+ ])
+
+ rangeset.add(4, 6)
+ self.assertEqual(list(rangeset), [
+ range(0, 6),
+ ])
+
===========changed ref 2===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_reverse(self):
- rangeset = RangeSet()
-
- rangeset.add(2)
- self.assertEqual(rangeset.ranges, [
- range(2, 3),
- ])
-
- rangeset.add(1)
- self.assertEqual(rangeset.ranges, [
- range(1, 3),
- ])
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 3),
- ])
-
===========changed ref 3===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_reverse(self):
- rangeset = RangeSet()
-
- rangeset.add(2)
- self.assertEqual(rangeset.ranges, [
- range(2, 3),
- ])
-
- rangeset.add(1)
- self.assertEqual(rangeset.ranges, [
- range(1, 3),
- ])
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 3),
- ])
-
===========changed ref 4===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_duplicate(self):
- rangeset = RangeSet()
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
===========changed ref 5===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_duplicate(self):
- rangeset = RangeSet()
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
===========changed ref 6===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_merge(self):
- rangeset = RangeSet()
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
- rangeset.add(2)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- range(2, 3),
- ])
-
- rangeset.add(1)
- self.assertEqual(rangeset.ranges, [
- range(0, 3),
- ])
-
===========changed ref 7===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_merge(self):
- rangeset = RangeSet()
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
- rangeset.add(2)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- range(2, 3),
- ])
-
- rangeset.add(1)
- self.assertEqual(rangeset.ranges, [
- range(0, 3),
- ])
-
===========changed ref 8===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_ordered(self):
- rangeset = RangeSet()
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
- rangeset.add(1)
- self.assertEqual(rangeset.ranges, [
- range(0, 2),
- ])
-
- rangeset.add(2)
- self.assertEqual(rangeset.ranges, [
- range(0, 3),
- ])
-
===========changed ref 9===========
# module: tests.test_rangeset
class RangeSetTest(TestCase):
- def test_add_ordered(self):
- rangeset = RangeSet()
-
- rangeset.add(0)
- self.assertEqual(rangeset.ranges, [
- range(0, 1),
- ])
-
- rangeset.add(1)
- self.assertEqual(rangeset.ranges, [
- range(0, 2),
- ])
-
- rangeset.add(2)
- self.assertEqual(rangeset.ranges, [
- range(0, 3),
- ])
-
===========changed ref 10===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __len__(self):
+ return len(self.__ranges)
+
===========changed ref 11===========
# module: aioquic.rangeset
+ class RangeSet(Sequence):
- class RangeSet:
+ def __getitem__(self, key) -> range:
+ return self.__ranges[key]
+
|
aioquic.packet/pull_crypto_frame
|
Modified
|
aiortc~aioquic
|
8dd39b275c0dca57fc38e5da13eeb699d525451c
|
[connection] add re-assembly buffer for received data
|
<2>:<add> return QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
<del> return offset, pull_bytes(buf, length)
|
# module: aioquic.packet
def pull_crypto_frame(buf):
<0> offset = pull_uint_var(buf)
<1> length = pull_uint_var(buf)
<2> return offset, pull_bytes(buf, length)
<3>
|
===========unchanged ref 0===========
at: dataclasses
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]
===========changed ref 0===========
# module: aioquic.rangeset
class RangeSet(Sequence):
+ def shift(self):
+ return self.__ranges.pop(0)
+
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
8dd39b275c0dca57fc38e5da13eeb699d525451c
|
[connection] add re-assembly buffer for received data
|
<37>:<add> self.streams = {
<add> tls.Epoch.INITIAL: QuicStream(),
<add> tls.Epoch.HANDSHAKE: QuicStream(),
<add> tls.Epoch.ONE_RTT: QuicStream(),
<add> }
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
<5> self.host_cid = os.urandom(8)
<6> self.peer_cid = os.urandom(8)
<7> self.peer_cid_set = False
<8> self.tls = tls.Context(is_client=is_client)
<9> if is_client:
<10> self.tls.handshake_extensions.append(
<11> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<12> )
<13> else:
<14> self.tls.handshake_extensions.append(
<15> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<16> )
<17> self.tls.certificate = certificate
<18> self.tls.certificate_private_key = private_key
<19>
<20> self.tls.update_traffic_key_cb = self._update_traffic_key
<21>
<22> self.send_ack = {
<23> tls.Epoch.INITIAL: False,
<24> tls.Epoch.HANDSHAKE: False,
<25> tls.Epoch.ONE_RTT: False,
<26> }
<27> self.send_buffer = {
<28> tls.Epoch.INITIAL: Buffer(capacity=4096),
<29> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<30> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<31> }
<32> self.spaces = {
<33> tls.Epoch.INITIAL: PacketSpace(),
<34> tls.Epoch.HANDSHAKE: PacketSpace(),
<35> tls.Epoch.ONE_RTT: PacketSpace(),
<36> }
<37>
<38> self.crypto_initialized = False
<39> self.packet_number = 0
</s>
|
===========unchanged ref 0===========
at: aioquic.connection
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
PacketSpace()
at: aioquic.connection.QuicConnection
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.stream
QuicStream()
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)
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
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
+ # module: aioquic.stream
+
+
===========changed ref 1===========
# module: aioquic.rangeset
class RangeSet(Sequence):
+ def shift(self):
+ return self.__ranges.pop(0)
+
===========changed ref 2===========
# module: aioquic.packet
+ @dataclass
+ class QuicStreamFrame:
+ data: bytes = b''
+ offset: int = 0
+
===========changed ref 3===========
+ # module: aioquic.stream
+ class QuicStream:
+ def __init__(self):
+ self._buffer = bytearray()
+ self._received = RangeSet()
+ self._start = 0
+
===========changed ref 4===========
# module: aioquic.packet
def pull_crypto_frame(buf):
offset = pull_uint_var(buf)
length = pull_uint_var(buf)
+ return QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
- return offset, pull_bytes(buf, length)
===========changed ref 5===========
+ # module: aioquic.stream
+ class QuicStream:
+ def pull_data(self):
+ # no data, or gap at start
+ if not self._received or self._received[0].start != self._start:
+ return b''
+
+ r = self._received.shift()
+ pos = r.stop - r.start
+ data = self._buffer[:pos]
+ self._buffer = self._buffer[pos:]
+ self._start = r.stop
+ return data
+
===========changed ref 6===========
+ # module: aioquic.stream
+ class QuicStream:
+ def add_frame(self, frame: QuicStreamFrame):
+ assert frame.offset >= self._start
+
+ # marked received
+ count = len(frame.data)
+ self._received.add(frame.offset, frame.offset + count)
+
+ # add data
+ pos = frame.offset - self._start
+ gap = pos - len(self._buffer)
+ if gap > 0:
+ self._buffer += bytearray(gap)
+ self._buffer[pos:pos + count] = frame.data
+
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
8dd39b275c0dca57fc38e5da13eeb699d525451c
|
[connection] add re-assembly buffer for received data
|
<27>:<add> is_ack_only = self._payload_received(epoch, plain_payload)
<del> is_ack_only = self._payload_received(plain_payload)
|
# 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> encrypted_off = buf.tell() - start_off
<9> end_off = buf.tell() + header.rest_length
<10> tls.pull_bytes(buf, header.rest_length)
<11>
<12> if not self.is_client and not self.crypto_initialized:
<13> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<14> is_client=self.is_client)
<15> self.crypto_initialized = True
<16>
<17> epoch = get_epoch(header.packet_type)
<18> space = self.spaces[epoch]
<19> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<20> data[start_off:end_off], encrypted_off)
<21>
<22> if not self.peer_cid_set:
<23> self.peer_cid = header.source_cid
<24> self.peer_cid_set = True
<25>
<26> # record packet as received
<27> is_ack_only = self._payload_received(plain_payload)
<28> space.ack_queue.add(packet_number)
<29> if not is_ack_only:
<30> self.send_ack[epoch] = True
<31>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
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_cid_set = False
self.tls = tls.Context(is_client=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.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.crypto_initialized = False
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
setup_initial(cid, is_client)
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
Epoch()
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)
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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: QuicStream(),
+ tls.Epoch.HANDSHAKE: QuicStream(),
+ tls.Epoch.ONE_RTT: QuicStream(),
+ }
self</s>
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s>KE: QuicStream(),
+ tls.Epoch.ONE_RTT: QuicStream(),
+ }
self.crypto_initialized = False
self.packet_number = 0
===========changed ref 2===========
+ # module: aioquic.stream
+
+
===========changed ref 3===========
# module: aioquic.rangeset
class RangeSet(Sequence):
+ def shift(self):
+ return self.__ranges.pop(0)
+
===========changed ref 4===========
# module: aioquic.packet
+ @dataclass
+ class QuicStreamFrame:
+ data: bytes = b''
+ offset: int = 0
+
===========changed ref 5===========
+ # module: aioquic.stream
+ class QuicStream:
+ def __init__(self):
+ self._buffer = bytearray()
+ self._received = RangeSet()
+ self._start = 0
+
===========changed ref 6===========
# module: aioquic.packet
def pull_crypto_frame(buf):
offset = pull_uint_var(buf)
length = pull_uint_var(buf)
+ return QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
- return offset, pull_bytes(buf, length)
===========changed ref 7===========
+ # module: aioquic.stream
+ class QuicStream:
+ def pull_data(self):
+ # no data, or gap at start
+ if not self._received or self._received[0].start != self._start:
+ return b''
+
+ r = self._received.shift()
+ pos = r.stop - r.start
+ data = self._buffer[:pos]
+ self._buffer = self._buffer[pos:]
+ self._start = r.stop
+ return data
+
===========changed ref 8===========
+ # module: aioquic.stream
+ class QuicStream:
+ def add_frame(self, frame: QuicStreamFrame):
+ assert frame.offset >= self._start
+
+ # marked received
+ count = len(frame.data)
+ self._received.add(frame.offset, frame.offset + count)
+
+ # add data
+ pos = frame.offset - self._start
+ gap = pos - len(self._buffer)
+ if gap > 0:
+ self._buffer += bytearray(gap)
+ self._buffer[pos:pos + count] = frame.data
+
|
aioquic.connection/QuicConnection._payload_received
|
Modified
|
aiortc~aioquic
|
8dd39b275c0dca57fc38e5da13eeb699d525451c
|
[connection] add re-assembly buffer for received data
|
<11>:<add> stream = self.streams[epoch]
<add> stream.add_frame(pull_crypto_frame(buf))
<add> data = stream.pull_data()
<del> offset, data = pull_crypto_frame(buf)
<12>:<add> if data:
<del> assert len(data)
<13>:<add> self.tls.handle_message(data, self.send_buffer)
<del> self.tls.handle_message(data, self.send_buffer)
|
# module: aioquic.connection
class QuicConnection:
+ def _payload_received(self, epoch, plain):
- def _payload_received(self, 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> offset, data = pull_crypto_frame(buf)
<12> assert len(data)
<13> self.tls.handle_message(data, self.send_buffer)
<14> elif frame_type == QuicFrameType.NEW_CONNECTION_ID:
<15> is_ack_only = False
<16> pull_new_connection_id_frame(buf)
<17> else:
<18> logger.warning('unhandled frame type %d', frame_type)
<19> break
<20> return is_ack_only
<21>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
_write_application()
_write_handshake(epoch)
at: aioquic.connection.QuicConnection.__init__
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)
pull_crypto_frame(buf)
at: aioquic.stream.QuicStream
add_frame(frame: QuicStreamFrame)
pull_data()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
eof()
===========changed ref 0===========
# module: aioquic.packet
def pull_crypto_frame(buf):
offset = pull_uint_var(buf)
length = pull_uint_var(buf)
+ return QuicStreamFrame(offset=offset, data=pull_bytes(buf, length))
- return offset, pull_bytes(buf, length)
===========changed ref 1===========
+ # module: aioquic.stream
+ class QuicStream:
+ def pull_data(self):
+ # no data, or gap at start
+ if not self._received or self._received[0].start != self._start:
+ return b''
+
+ r = self._received.shift()
+ pos = r.stop - r.start
+ data = self._buffer[:pos]
+ self._buffer = self._buffer[pos:]
+ self._start = r.stop
+ return data
+
===========changed ref 2===========
+ # module: aioquic.stream
+ class QuicStream:
+ def add_frame(self, frame: QuicStreamFrame):
+ assert frame.offset >= self._start
+
+ # marked received
+ count = len(frame.data)
+ self._received.add(frame.offset, frame.offset + count)
+
+ # add data
+ pos = frame.offset - self._start
+ gap = pos - len(self._buffer)
+ if gap > 0:
+ self._buffer += bytearray(gap)
+ self._buffer[pos:pos + count] = frame.data
+
===========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))
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.crypto_initialized:
self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
is_client=self.is_client)
self.crypto_initialized = True
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
# record packet as received
+ is_ack_only = self._payload_received(epoch, plain_payload)
- is_ack_only = self._payload_received(plain_payload)
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 __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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: QuicStream(),
+ tls.Epoch.HANDSHAKE: QuicStream(),
+ tls.Epoch.ONE_RTT: QuicStream(),
+ }
self</s>
===========changed ref 5===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s>KE: QuicStream(),
+ tls.Epoch.ONE_RTT: QuicStream(),
+ }
self.crypto_initialized = False
self.packet_number = 0
===========changed ref 6===========
+ # module: aioquic.stream
+
+
===========changed ref 7===========
# module: aioquic.rangeset
class RangeSet(Sequence):
+ def shift(self):
+ return self.__ranges.pop(0)
+
===========changed ref 8===========
# module: aioquic.packet
+ @dataclass
+ class QuicStreamFrame:
+ data: bytes = b''
+ offset: int = 0
+
===========changed ref 9===========
+ # module: aioquic.stream
+ class QuicStream:
+ def __init__(self):
+ self._buffer = bytearray()
+ self._received = RangeSet()
+ self._start = 0
+
|
aioquic.connection/QuicConnection._write_handshake
|
Modified
|
aiortc~aioquic
|
057adcf5497752f26d4a682da2fbdd6cd826a77b
|
[connection] split data in chunks to respect MAX_PACKET_SIZE
|
<2>:<add> self.send_ack[epoch] = False
<4>:<del> if not space.crypto.send.is_valid() or (not send_ack and not send_data):
<5>:<del> return
<8>:<add> offset = 0
<9>:<add> while space.crypto.send.is_valid() and (send_ack or send_data):
<add> if epoch == tls.Epoch.INITIAL:
<del> if epoch == tls.Epoch.INITIAL:
<10>:<add> packet_type = PACKET_TYPE_INITIAL
<del> packet_type = PACKET_TYPE_INITIAL
<11>:<add> else:
<del> else:
<12>:<add> packet_type = PACKET_TYPE_HANDSHAKE
<del> packet_type = PACKET_TYPE_HANDSHAKE
<14>:<add> # write header
<del> # write header
<15>:<add> push_quic_header(buf, QuicHeader(
<del> push_quic_header(buf, QuicHeader(
<16>:<add> version=PROTOCOL_VERSION_DRAFT_17,
<del> version=PROTOCOL_VERSION_DRAFT_17,
<17>:<add> packet_type=packet_type | (SEND_PN_SIZE - 1),
<del> packet_type=packet_type | (SEND_PN_SIZE - 1),
<18>:<add> destination_cid=self.peer_cid,
<del> destination_cid=self.peer_cid,
<19>:<add> source_cid=self.host_cid,
<del> source_cid=self.host_cid,
<20>:<add> ))
<del> ))
<21>:<add> header_size = buf.tell()
<del> header_size = buf.tell()
<23>:<del> if send_data:
<24>:<add> # ACK
<del> # CRYPTO
<25>:<add> if send_ack:
<add> push_uint_var(buf, QuicFrameType.
|
# 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> send_data = self.send_buffer[epoch].data
<3> self.send_buffer[epoch].seek(0)
<4> if not space.crypto.send.is_valid() or (not send_ack and not send_data):
<5> return
<6>
<7> buf = Buffer(capacity=PACKET_MAX_SIZE)
<8>
<9> if epoch == tls.Epoch.INITIAL:
<10> packet_type = PACKET_TYPE_INITIAL
<11> else:
<12> packet_type = PACKET_TYPE_HANDSHAKE
<13>
<14> # write header
<15> push_quic_header(buf, QuicHeader(
<16> version=PROTOCOL_VERSION_DRAFT_17,
<17> packet_type=packet_type | (SEND_PN_SIZE - 1),
<18> destination_cid=self.peer_cid,
<19> source_cid=self.host_cid,
<20> ))
<21> header_size = buf.tell()
<22>
<23> if send_data:
<24> # CRYPTO
<25> push_uint_var(buf, QuicFrameType.CRYPTO)
<26> with push_crypto_frame(buf):
<27> tls.push_bytes(buf, send_data)
<28>
<29> # PADDING
<30> if epoch == tls.Epoch.INITIAL:
<31> tls.push_bytes(
<32> buf,
<33> bytes(PACKET_MAX_SIZE - space.crypto.aead_tag_size - buf.tell()))
<34>
<35> # ACK
<36> if send_ack:
<37> push_uint_var(buf, QuicFrameType.ACK)
<38> push_ack_frame(buf, send_ack, 0)
<39> self.send_ack[epoch] = False
<40>
<41> # finalize length
<42> packet_size = buf.tell()
<43> buf.seek(header_size - SEND_PN_</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def _write_handshake(self, epoch):
# offset: 1
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
===========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.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.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_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
PROTOCOL_VERSION_DRAFT_17 = 0xff000011 # draft 17
===========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)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_crypto_frame(buf, offset=0)
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
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()
|
aioquic.tls/push_client_hello
|
Modified
|
aiortc~aioquic
|
140fca2d624edc683f96cfadbf82796595db6c81
|
[tls] serialize known extensions before others
|
<23>:<add> with push_extension(buf, ExtensionType.PSK_KEY_EXCHANGE_MODES):
<add> push_list(buf, 1, push_uint8, hello.key_exchange_modes)
<add>
<27>:<del> with push_extension(buf, ExtensionType.PSK_KEY_EXCHANGE_MODES):
<28>:<del> push_list(buf, 1, push_uint8, hello.key_exchange_modes)
<29>:<del>
|
# 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> for extension_type, extension_value in hello.other_extensions:
<24> with push_extension(buf, extension_type):
<25> push_bytes(buf, extension_value)
<26>
<27> with push_extension(buf, ExtensionType.PSK_KEY_EXCHANGE_MODES):
<28> push_list(buf, 1, push_uint8, hello.key_exchange_modes)
<29>
|
===========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)
push_bytes(buf: Buffer, v: bytes)
push_uint8(buf: Buffer, v: int)
push_uint16(buf: Buffer, v: int)
push_block(buf: Buffer, capacity: int)
push_list(buf: Buffer, capacity: int, func, values)
push_key_share(buf: Buffer, value: Tuple[int, bytes])
push_extension(buf: Buffer, extension_type: int)
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=None, key_exchange_modes: List[int]=None, key_share: List[Tuple[int, bytes]]=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
cipher_suites: List[int] = None
compression_methods: List[int] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = 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)
|
aioquic.tls/Context._client_send_hello
|
Modified
|
aiortc~aioquic
|
dcb946b4f40bff514a170f6d20554f8ee3f2b8f0
|
[tls] remove some signing algorithms, refactor public key handling
|
<14>:<del> (
<15>:<del> Group.SECP256R1,
<16>:<del> self.private_key.public_key().public_bytes(
<17>:<del> Encoding.X962, PublicFormat.UncompressedPoint),
<18>:<del> )
<19>:<add> encode_public_key(self.private_key.public_key()),
<22>:<del> SignatureAlgorithm.ECDSA_SECP256R1_SHA256,
<23>:<del> SignatureAlgorithm.RSA_PKCS1_SHA256,
<24>:<del> SignatureAlgorithm.RSA_PKCS1_SHA1,
|
# 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=[
<4> CipherSuite.AES_128_GCM_SHA256,
<5> ],
<6> compression_methods=[
<7> CompressionMethod.NULL,
<8> ],
<9>
<10> key_exchange_modes=[
<11> KeyExchangeMode.PSK_DHE_KE,
<12> ],
<13> key_share=[
<14> (
<15> Group.SECP256R1,
<16> self.private_key.public_key().public_bytes(
<17> Encoding.X962, PublicFormat.UncompressedPoint),
<18> )
<19> ],
<20> signature_algorithms=[
<21> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<22> SignatureAlgorithm.ECDSA_SECP256R1_SHA256,
<23> SignatureAlgorithm.RSA_PKCS1_SHA256,
<24> SignatureAlgorithm.RSA_PKCS1_SHA1,
<25> ],
<26> supported_groups=[
<27> Group.SECP256R1,
<28> ],
<29> supported_versions=[
<30> TLS_VERSION_1_3,
<31> ],
<32>
<33> other_extensions=self.handshake_extensions
<34> )
<35>
<36> self.key_schedule = KeySchedule()
<37> self.key_schedule.extract(None)
<38>
<39> with self._push_message(output_buf):
<40> push_client_hello(output_buf, hello)
<41>
<42> self._set_state(State.CLIENT_EXPECT_SERVER_HELLO)
<43>
|
===========unchanged ref 0===========
at: aioquic.tls
AlertUnexpectedMessage(*args: object)
Epoch()
State()
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)
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]=...)
SignatureAlgorithm(x: Union[str, bytes, bytearray], base: int)
SignatureAlgorithm(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, key_exchange_modes: List[int]=None, key_share: List[Tuple[int, bytes]]=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
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
===========unchanged ref 1===========
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
_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.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 encode_public_key(public_key):
+ return (
+ CURVE_TO_GROUP[public_key.curve.__class__],
+ public_key.public_bytes(
+ Encoding.X962, PublicFormat.UncompressedPoint),
+ )
+
===========changed ref 1===========
# module: aioquic.tls
class CipherSuite(IntEnum):
+ AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
- AES_128_GCM_SHA256 = 0x1301
CHACHA20_POLY1305_SHA256 = 0x1303
===========changed ref 2===========
# module: aioquic.tls
+ def decode_public_key(key_share):
+ return ec.EllipticCurvePublicKey.from_encoded_point(
+ GROUP_TO_CURVE[key_share[0]](), key_share[1])
+
===========changed ref 3===========
# module: aioquic.tls
class Group(IntEnum):
+ SECP256R1 = 0x0017
- SECP256R1 = 23
+ SECP384R1 = 0x0018
+ SECP521R1 = 0x0019
|
aioquic.tls/Context._client_handle_hello
|
Modified
|
aiortc~aioquic
|
dcb946b4f40bff514a170f6d20554f8ee3f2b8f0
|
[tls] remove some signing algorithms, refactor public key handling
|
<2>:<del> peer_public_key = ec.EllipticCurvePublicKey.from_encoded_point(
<3>:<del> ec.SECP256R1(), peer_hello.key_share[1])
<4>:<add> peer_public_key = decode_public_key(peer_hello.key_share)
|
# 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 = ec.EllipticCurvePublicKey.from_encoded_point(
<3> ec.SECP256R1(), peer_hello.key_share[1])
<4> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<5>
<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
TLS_VERSION_1_3 = 0x0304
push_client_hello(buf: Buffer, hello: ClientHello)
KeySchedule()
at: aioquic.tls.Context
_push_message(self, buf: Buffer)
at: aioquic.tls.Context.__init__
self.handshake_extensions = []
at: aioquic.tls.Context._client_send_hello
hello = ClientHello(
random=self.client_random,
session_id=self.session_id,
cipher_suites=[
CipherSuite.AES_128_GCM_SHA256,
],
compression_methods=[
CompressionMethod.NULL,
],
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
signature_algorithms=[
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
],
supported_groups=[
Group.SECP256R1,
],
supported_versions=[
TLS_VERSION_1_3,
],
other_extensions=self.handshake_extensions
)
at: aioquic.tls.Context._server_handle_hello
self.key_schedule = KeySchedule()
at: aioquic.tls.KeySchedule
extract(key_material=None)
===========changed ref 0===========
# module: aioquic.tls
+ def decode_public_key(key_share):
+ return ec.EllipticCurvePublicKey.from_encoded_point(
+ GROUP_TO_CURVE[key_share[0]](), key_share[1])
+
===========changed ref 1===========
# module: aioquic.tls
+ def encode_public_key(public_key):
+ return (
+ CURVE_TO_GROUP[public_key.curve.__class__],
+ public_key.public_bytes(
+ Encoding.X962, PublicFormat.UncompressedPoint),
+ )
+
===========changed ref 2===========
# 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=[
CipherSuite.AES_128_GCM_SHA256,
],
compression_methods=[
CompressionMethod.NULL,
],
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
- (
- Group.SECP256R1,
- self.private_key.public_key().public_bytes(
- Encoding.X962, PublicFormat.UncompressedPoint),
- )
+ encode_public_key(self.private_key.public_key()),
],
signature_algorithms=[
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
- SignatureAlgorithm.ECDSA_SECP256R1_SHA256,
- SignatureAlgorithm.RSA_PKCS1_SHA256,
- SignatureAlgorithm.RSA_PKCS1_SHA1,
],
supported_groups=[
Group.SECP256R1,
],
supported_versions=[
TLS_VERSION_1_3,
],
other_extensions=self.handshake_extensions
)
self.key_schedule = KeySchedule()
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 3===========
# module: aioquic.tls
class Group(IntEnum):
+ SECP256R1 = 0x0017
- SECP256R1 = 23
+ SECP384R1 = 0x0018
+ SECP521R1 = 0x0019
===========changed ref 4===========
# module: aioquic.tls
class CipherSuite(IntEnum):
+ AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
- AES_128_GCM_SHA256 = 0x1301
CHACHA20_POLY1305_SHA256 = 0x1303
|
aioquic.tls/Context._server_handle_hello
|
Modified
|
aiortc~aioquic
|
dcb946b4f40bff514a170f6d20554f8ee3f2b8f0
|
[tls] remove some signing algorithms, refactor public key handling
|
<11>:<del> peer_public_key = ec.EllipticCurvePublicKey.from_encoded_point(
<12>:<del> ec.SECP256R1(), peer_hello.key_share[0][1])
<13>:<add> peer_public_key = decode_public_key(peer_hello.key_share[0])
<22>:<del> key_share=(
<23>:<del> Group.SECP256R1,
<24>:<del> self.private_key.public_key().public_bytes(
<25>:<del> Encoding.X962, PublicFormat.UncompressedPoint),
<26>:<del> ),
<27>:<add> key_share=encode_public_key(self.private_key.public_key()),
|
# 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> self.key_schedule = KeySchedule()
<8> self.key_schedule.extract(None)
<9> self.key_schedule.update_hash(input_buf.data)
<10>
<11> peer_public_key = ec.EllipticCurvePublicKey.from_encoded_point(
<12> ec.SECP256R1(), peer_hello.key_share[0][1])
<13> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<14>
<15> # send hello
<16> hello = ServerHello(
<17> random=self.server_random,
<18> session_id=self.session_id,
<19> cipher_suite=CipherSuite.AES_128_GCM_SHA256,
<20> compression_method=CompressionMethod.NULL,
<21>
<22> key_share=(
<23> Group.SECP256R1,
<24> self.private_key.public_key().public_bytes(
<25> Encoding.X962, PublicFormat.UncompressedPoint),
<26> ),
<27> supported_version=TLS_VERSION_1_3,
<28> )
<29> with self._push_message(output_buf):
<30> push_server_hello(output_buf, hello)
<31> self.key_schedule.extract(shared_key)
<32>
<33> self._setup_traffic_protection(Direction.ENCRYPT, Epoch.HANDSHAKE, b's hs traffic')
<34> self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b'c hs traffic')
<35>
<36> # send encrypted extensions
<37> </s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
# offset: 1
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()
State()
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]=...)
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)
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()
decode_public_key(key_share)
encode_public_key(public_key)
at: aioquic.tls.Certificate
request_context: bytes = b''
certificates: List = field(default_factory=list)
===========unchanged ref 1===========
at: aioquic.tls.CertificateVerify
algorithm: int = None
signature: bytes = None
at: aioquic.tls.ClientHello
random: bytes = None
session_id: bytes = None
key_share: List[Tuple[int, bytes]] = None
at: aioquic.tls.Context
_push_message(self, buf: Buffer)
_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.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_send_hello
self.key_schedule = KeySchedule()
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.ServerHello
random: bytes = None
session_id: bytes = None
cipher_suite: int = None
compression_method: int = None
===========unchanged ref 2===========
key_share: Tuple[int, bytes] = None
supported_version: int = None
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.tls
+ def decode_public_key(key_share):
+ return ec.EllipticCurvePublicKey.from_encoded_point(
+ GROUP_TO_CURVE[key_share[0]](), key_share[1])
+
===========changed ref 1===========
# module: aioquic.tls
+ def encode_public_key(public_key):
+ return (
+ CURVE_TO_GROUP[public_key.curve.__class__],
+ public_key.public_bytes(
+ Encoding.X962, PublicFormat.UncompressedPoint),
+ )
+
===========changed ref 2===========
# module: aioquic.tls
class CipherSuite(IntEnum):
+ AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
- AES_128_GCM_SHA256 = 0x1301
CHACHA20_POLY1305_SHA256 = 0x1303
===========changed ref 3===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
- peer_public_key = ec.EllipticCurvePublicKey.from_encoded_point(
- ec.SECP256R1(), peer_hello.key_share[1])
+ peer_public_key = decode_public_key(peer_hello.key_share)
shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
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_handshake
|
Modified
|
aiortc~aioquic
|
dcb946b4f40bff514a170f6d20554f8ee3f2b8f0
|
[tls] remove some signing algorithms, refactor public key handling
|
<8>:<add> self.assertEqual(len(server_input), 242)
<del> self.assertEqual(len(server_input), 248)
|
# 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), 248)
<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), 155 + 90 + 1538 + 392 + 36)
<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), 36)
<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.</s>
|
===========below chunk 0===========
# module: tests.test_tls
class ContextTest(TestCase):
def test_handshake(self):
# offset: 1
===========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
+ def decode_public_key(key_share):
+ return ec.EllipticCurvePublicKey.from_encoded_point(
+ GROUP_TO_CURVE[key_share[0]](), key_share[1])
+
===========changed ref 1===========
# module: aioquic.tls
class Group(IntEnum):
+ SECP256R1 = 0x0017
- SECP256R1 = 23
+ SECP384R1 = 0x0018
+ SECP521R1 = 0x0019
===========changed ref 2===========
# module: aioquic.tls
+ def encode_public_key(public_key):
+ return (
+ CURVE_TO_GROUP[public_key.curve.__class__],
+ public_key.public_bytes(
+ Encoding.X962, PublicFormat.UncompressedPoint),
+ )
+
===========changed ref 3===========
# module: aioquic.tls
class CipherSuite(IntEnum):
+ AES_128_GCM_SHA256 = 0x1301
AES_256_GCM_SHA384 = 0x1302
- AES_128_GCM_SHA256 = 0x1301
CHACHA20_POLY1305_SHA256 = 0x1303
===========changed ref 4===========
# module: aioquic.tls
+ 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 5===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
- peer_public_key = ec.EllipticCurvePublicKey.from_encoded_point(
- ec.SECP256R1(), peer_hello.key_share[1])
+ peer_public_key = decode_public_key(peer_hello.key_share)
shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
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 6===========
# 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=[
CipherSuite.AES_128_GCM_SHA256,
],
compression_methods=[
CompressionMethod.NULL,
],
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
- (
- Group.SECP256R1,
- self.private_key.public_key().public_bytes(
- Encoding.X962, PublicFormat.UncompressedPoint),
- )
+ encode_public_key(self.private_key.public_key()),
],
signature_algorithms=[
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
- SignatureAlgorithm.ECDSA_SECP256R1_SHA256,
- SignatureAlgorithm.RSA_PKCS1_SHA256,
- SignatureAlgorithm.RSA_PKCS1_SHA1,
],
supported_groups=[
Group.SECP256R1,
],
supported_versions=[
TLS_VERSION_1_3,
],
other_extensions=self.handshake_extensions
)
self.key_schedule = KeySchedule()
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 7===========
# 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())
self.key_schedule = KeySchedule()
self.key_schedule.extract(None)
self.key_schedule.update_hash(input_buf.data)
- peer_public_key = ec.EllipticCurvePublicKey.from_encoded_point(
- ec.SECP256R1(), peer_hello.key_share[0][1])
+ 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=CipherSuite.AES_128_GCM_SHA256,
compression_method=CompressionMethod.NULL,
- key_share=(
- Group.SECP256R1,
- self.private_key.public_key().public_bytes(
- Encoding.X962, PublicFormat.UncompressedPoint),
- ),
+ 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.</s>
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
b9257b84c215bfe935faed202244f4e0f4cefc10
|
[connection] make it possible to log traffic secrets
|
<8>:<add> self.secrets_log_file = secrets_log_file
|
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
<5> self.host_cid = os.urandom(8)
<6> self.peer_cid = os.urandom(8)
<7> self.peer_cid_set = False
<8> self.tls = tls.Context(is_client=is_client)
<9> if is_client:
<10> self.tls.handshake_extensions.append(
<11> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<12> )
<13> else:
<14> self.tls.handshake_extensions.append(
<15> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<16> )
<17> self.tls.certificate = certificate
<18> self.tls.certificate_private_key = private_key
<19>
<20> self.tls.update_traffic_key_cb = self._update_traffic_key
<21>
<22> self.send_ack = {
<23> tls.Epoch.INITIAL: False,
<24> tls.Epoch.HANDSHAKE: False,
<25> tls.Epoch.ONE_RTT: False,
<26> }
<27> self.send_buffer = {
<28> tls.Epoch.INITIAL: Buffer(capacity=4096),
<29> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<30> tls.Epoch.ONE_RTT: Buffer(capacity=4096),
<31> }
<32> self.spaces = {
<33> tls.Epoch.INITIAL: PacketSpace(),
<34> tls.Epoch.HANDSHAKE: PacketSpace(),
<35> tls.Epoch.</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
}
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
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
PacketSpace()
at: aioquic.connection.PacketSpace.__init__
self.ack_queue = RangeSet()
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.datagram_received
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.crypto
CryptoPair()
at: aioquic.rangeset
RangeSet(ranges: Iterable[range]=[])
at: aioquic.stream
QuicStream()
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)
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
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# module: aioquic.connection
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
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
|
aioquic.connection/QuicConnection._update_traffic_key
|
Modified
|
aiortc~aioquic
|
b9257b84c215bfe935faed202244f4e0f4cefc10
|
[connection] make it possible to log traffic secrets
|
<0>:<add> if self.secrets_log_file is not None:
<add> label_row = self.is_client == (direction == tls.Direction.DECRYPT)
<add> label = SECRETS_LABELS[label_row][epoch.value]
<add> self.secrets_log_file.write('%s %s %s\n' % (
<add> label, self.tls.client_random.hex(), secret.hex()))
<add> self.secrets_log_file.flush()
<add>
|
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
<0> crypto = self.spaces[epoch].crypto
<1> if direction == tls.Direction.ENCRYPT:
<2> crypto.send.setup(self.tls.key_schedule.algorithm, secret)
<3> else:
<4> crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
<5>
|
===========unchanged ref 0===========
at: aioquic.connection
logger = logging.getLogger('quic')
at: aioquic.connection.QuicConnection._payload_received
buf = Buffer(data=plain)
is_ack_only = True
is_ack_only = False
frame_type = pull_uint_var(buf)
at: aioquic.packet
pull_new_connection_id_frame(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
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
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
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.secrets_log_file = secrets_log_file
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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 = {
</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s>KE: 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
|
examples.cli/QuicProtocol.__init__
|
Modified
|
aiortc~aioquic
|
b9257b84c215bfe935faed202244f4e0f4cefc10
|
[connection] make it possible to log traffic secrets
|
<0>:<add> self._connection = QuicConnection(secrets_log_file=secrets_log_file)
<del> self._connection = QuicConnection()
|
# module: examples.cli
class QuicProtocol(asyncio.DatagramProtocol):
+ def __init__(self, secrets_log_file):
- def __init__(self):
<0> self._connection = QuicConnection()
<1> self._transport = None
<2>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None)
at: examples.cli.QuicProtocol.connection_made
self._transport = transport
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ if self.secrets_log_file is not None:
+ label_row = self.is_client == (direction == tls.Direction.DECRYPT)
+ label = SECRETS_LABELS[label_row][epoch.value]
+ self.secrets_log_file.write('%s %s %s\n' % (
+ label, self.tls.client_random.hex(), secret.hex()))
+ self.secrets_log_file.flush()
+
crypto = self.spaces[epoch].crypto
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 1===========
# module: aioquic.connection
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
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
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.secrets_log_file = secrets_log_file
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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 = {
</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s>KE: 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
|
examples.cli/run
|
Modified
|
aiortc~aioquic
|
b9257b84c215bfe935faed202244f4e0f4cefc10
|
[connection] make it possible to log traffic secrets
|
<1>:<add> lambda: QuicProtocol(secrets_log_file=secrets_log_file),
<del> QuicProtocol,
|
# module: examples.cli
+ def run(address, port, secrets_log_file):
- def run(address, port):
<0> _, protocol = await loop.create_datagram_endpoint(
<1> QuicProtocol,
<2> remote_addr=(address, port))
<3>
<4> await asyncio.sleep(10)
<5>
|
===========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(secrets_log_file)
loop = asyncio.get_event_loop()
===========changed ref 0===========
# module: examples.cli
class QuicProtocol(asyncio.DatagramProtocol):
+ def __init__(self, secrets_log_file):
- def __init__(self):
+ self._connection = QuicConnection(secrets_log_file=secrets_log_file)
- self._connection = QuicConnection()
self._transport = None
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
+ if self.secrets_log_file is not None:
+ label_row = self.is_client == (direction == tls.Direction.DECRYPT)
+ label = SECRETS_LABELS[label_row][epoch.value]
+ self.secrets_log_file.write('%s %s %s\n' % (
+ label, self.tls.client_random.hex(), secret.hex()))
+ self.secrets_log_file.flush()
+
crypto = self.spaces[epoch].crypto
if direction == tls.Direction.ENCRYPT:
crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
===========changed ref 2===========
# module: aioquic.connection
logger = logging.getLogger('quic')
CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff0000110031000500048010000000060004801000000007000480100000000'
b'4000481000000000100024258000800024064000a00010a')
SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
b'ff00001104ff000011004500050004801000000006000480100000000700048'
b'010000000040004810000000001000242580002001000000000000000000000'
b'000000000000000800024064000a00010a')
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
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
+ self.secrets_log_file = secrets_log_file
self.tls = tls.Context(is_client=is_client)
if is_client:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
)
else:
self.tls.handshake_extensions.append(
(tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
)
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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 = {
</s>
===========changed ref 4===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
- def __init__(self, is_client=True, certificate=None, private_key=None):
# offset: 1
<s>KE: 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
|
aioquic.packet/pull_quic_header
|
Modified
|
aiortc~aioquic
|
d1437bdf10dd07a094992cef013601b4bb5f1404
|
[packet] don't bomb on version negotiation packet
|
<1>:<del> if not (first_byte & PACKET_FIXED_BIT):
<2>:<del> raise ValueError('Packet fixed bit is zero')
<6>:<add> # long header packet
<15>:<add> if version == PROTOCOL_VERSION_NEGOTIATION:
<add> # version negotiation
<add> packet_type = None
<add> rest_length = buf.capacity - buf.tell()
<add> else:
<add> if version and not (first_byte & PACKET_FIXED_BIT):
<add> raise ValueError('Packet fixed bit is zero')
<add>
<add> packet_type = first_byte & PACKET_TYPE_MASK
<del> packet_type = first_byte & PACKET_TYPE_MASK
<16>:<add> if packet_type == PACKET_TYPE_INITIAL:
<del> if packet_type == PACKET_TYPE_INITIAL:
<17>:<add> token_length = pull_uint_var(buf)
<del> token_length = pull_uint_var(buf)
<18>:<add> token = pull_bytes(buf, token_length)
<del> token = pull_bytes(buf, token_length)
<19>:<add> rest_length = pull_uint_var(buf)
<del> rest_length = pull_uint_var(buf)
<30>:<add> if not (first_byte & PACKET_FIXED_BIT):
<add> raise ValueError('Packet fixed bit is zero')
<add>
|
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
<0> first_byte = pull_uint8(buf)
<1> if not (first_byte & PACKET_FIXED_BIT):
<2> raise ValueError('Packet fixed bit is zero')
<3>
<4> token = b''
<5> if is_long_header(first_byte):
<6> version = pull_uint32(buf)
<7> cid_lengths = pull_uint8(buf)
<8>
<9> destination_cid_length = decode_cid_length(cid_lengths // 16)
<10> destination_cid = pull_bytes(buf, destination_cid_length)
<11>
<12> source_cid_length = decode_cid_length(cid_lengths % 16)
<13> source_cid = pull_bytes(buf, source_cid_length)
<14>
<15> packet_type = first_byte & PACKET_TYPE_MASK
<16> if packet_type == PACKET_TYPE_INITIAL:
<17> token_length = pull_uint_var(buf)
<18> token = pull_bytes(buf, token_length)
<19> rest_length = pull_uint_var(buf)
<20>
<21> return QuicHeader(
<22> version=version,
<23> packet_type=packet_type,
<24> destination_cid=destination_cid,
<25> source_cid=source_cid,
<26> token=token,
<27> rest_length=rest_length)
<28> else:
<29> # short header packet
<30> packet_type = first_byte & PACKET_TYPE_MASK
<31> destination_cid = pull_bytes(buf, host_cid_length)
<32> return QuicHeader(
<33> version=0,
<34> packet_type=packet_type,
<35> destination_cid=destination_cid,
<36> source_cid=b'',
<37> token=b'',
<38> rest_length=buf.capacity - buf.tell())
<39>
|
===========unchanged ref 0===========
at: aioquic.packet
PACKET_FIXED_BIT = 0x40
PACKET_TYPE_INITIAL = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x00
PACKET_TYPE_MASK = 0xf0
PROTOCOL_VERSION_NEGOTIATION = 0
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
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 # draft 17
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_pull_long_header_no_fixed_bit
|
Modified
|
aiortc~aioquic
|
d1437bdf10dd07a094992cef013601b4bb5f1404
|
[packet] don't bomb on version negotiation packet
|
<0>:<add> buf = Buffer(data=b'\x80\xff\x00\x00\x11\x00')
<del> buf = Buffer(data=b'\x80\x00\x00\x00\x00\x00')
|
# module: tests.test_packet
class PacketTest(TestCase):
def test_pull_long_header_no_fixed_bit(self):
<0> buf = Buffer(data=b'\x80\x00\x00\x00\x00\x00')
<1> with self.assertRaises(ValueError) as cm:
<2> pull_quic_header(buf, host_cid_length=8)
<3> self.assertEqual(str(cm.exception), 'Packet fixed bit is zero')
<4>
|
===========unchanged ref 0===========
at: aioquic.packet
PROTOCOL_VERSION_NEGOTIATION = 0
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: 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)
- if not (first_byte & PACKET_FIXED_BIT):
- raise ValueError('Packet fixed bit is zero')
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 == 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
- packet_type = first_byte & PACKET_TYPE_MASK
+ if packet_type == PACKET_TYPE_INITIAL:
- if packet_type == PACKET_TYPE_INITIAL:
+ token_length = pull_uint_var(buf)
- token_length = pull_uint_var(buf)
+ token = pull_bytes(buf, token_length)
- token = pull_bytes(buf, token_length)
+ rest_length = pull_uint_var(buf)
- 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
+ </s>
===========changed ref 1===========
# module: aioquic.packet
def pull_quic_header(buf, host_cid_length=None):
# offset: 1
<s>,
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'',
token=b'',
rest_length=buf.capacity - buf.tell())
===========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, 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: 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 # draft 17
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.datagram_received
|
Modified
|
aiortc~aioquic
|
f3f03b09dd9bbe8cdb8878a5c8b01bd5c80d1441
|
[connection] raise an exception on version negotiation
|
<8>:<add> if header.packet_type is None:
<add> versions = []
<add> while not buf.eof():
<add> versions.append('0x%x' % tls.pull_uint32(buf))
<add> raise Exception('Version negotiation needed: %s' % versions)
<add>
|
# 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> encrypted_off = buf.tell() - start_off
<9> end_off = buf.tell() + header.rest_length
<10> tls.pull_bytes(buf, header.rest_length)
<11>
<12> if not self.is_client and not self.crypto_initialized:
<13> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<14> is_client=self.is_client)
<15> self.crypto_initialized = True
<16>
<17> epoch = get_epoch(header.packet_type)
<18> space = self.spaces[epoch]
<19> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<20> data[start_off:end_off], encrypted_off)
<21>
<22> if not self.peer_cid_set:
<23> self.peer_cid = header.source_cid
<24> self.peer_cid_set = True
<25>
<26> # handle payload
<27> is_ack_only = self._payload_received(epoch, plain_payload)
<28>
<29> # record packet as received
<30> space.ack_queue.add(packet_number)
<31> if not is_ack_only:
<32> self.send_ack[epoch] = True
<33>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
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_cid_set = False
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.crypto_initialized = False
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
setup_initial(cid, is_client)
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
Epoch()
Buffer(capacity=None, data=None)
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
b3db6c485ccf8e11c74087468d7f62616abee87a
|
[packet] parse / serialize Quic Transport Parameters
|
<10>:<add>
<add> self.quic_transport_parameters = QuicTransportParameters(
<add> idle_timeout=600,
<add> initial_max_data=16777216,
<add> initial_max_stream_data_bidi_local=1048576,
<add> initial_max_stream_data_bidi_remote=1048576,
<add> initial_max_stream_data_uni=1048576,
<add> initial_max_streams_bidi=100,
<add> ack_delay_exponent=10,
<add> )
<add>
<11>:<del> self.tls.handshake_extensions.append(
<12>:<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<13>:<del> )
<14>:<add> self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
<15>:<add> self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
<add> self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
<add> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<del> self.tls.handshake_extensions.append(
<16>:<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<17>:<del> )
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=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.is_client = is_client
<5> self.host_cid = os.urandom(8)
<6> self.peer_cid = os.urandom(8)
<7> self.peer_cid_set = False
<8> self.secrets_log_file = secrets_log_file
<9> self.tls = tls.Context(is_client=is_client)
<10> if is_client:
<11> self.tls.handshake_extensions.append(
<12> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
<13> )
<14> else:
<15> self.tls.handshake_extensions.append(
<16> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
<17> )
<18> self.tls.certificate = certificate
<19> self.tls.certificate_private_key = private_key
<20>
<21> self.tls.update_traffic_key_cb = self._update_traffic_key
<22>
<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> </s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
# offset: 1
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
_update_traffic_key(direction, epoch, secret)
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.connection.QuicConnection.datagram_received
self.crypto_initialized = True
self.peer_cid_set = True
at: aioquic.packet
PROTOCOL_VERSION_DRAFT_17 = 0xff000011 # draft 17
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: aioquic.stream
QuicStream()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
Context(is_client)
at: aioquic.tls.Context.__init__
self.certificate = None
self.certificate_private_key = None
self.update_traffic_key_cb = lambda d, e, s: None
===========changed ref 0===========
# module: aioquic.packet
+ # TLS EXTENSION
+
+
+ @dataclass
+ class 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
+
===========changed ref 1===========
# module: aioquic.connection
logger = logging.getLogger('quic')
-
-
- CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
- b'ff0000110031000500048010000000060004801000000007000480100000000'
- b'4000481000000000100024258000800024064000a00010a')
- SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
- b'ff00001104ff000011004500050004801000000006000480100000000700048'
- b'010000000040004810000000001000242580002001000000000000000000000'
- b'000000000000000800024064000a00010a')
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
===========changed ref 2===========
# module: aioquic.packet
+ 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),
+ ]
===========changed ref 3===========
# module: aioquic.packet
+ def push_quic_transport_parameters(buf, params, is_client):
+ if is_client:
+ push_uint32(buf, params.initial_version)
+ 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)
+
|
aioquic.connection/QuicConnection.connection_made
|
Modified
|
aiortc~aioquic
|
b3db6c485ccf8e11c74087468d7f62616abee87a
|
[packet] parse / serialize Quic Transport Parameters
|
<5>:<add> self.tls.handshake_extensions.append(
<add> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<add> )
|
# 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.crypto_initialized = True
<4>
<5> self.tls.handle_message(b'', self.send_buffer)
<6>
|
===========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
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')
-
-
- CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
- b'ff0000110031000500048010000000060004801000000007000480100000000'
- b'4000481000000000100024258000800024064000a00010a')
- SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
- b'ff00001104ff000011004500050004801000000006000480100000000700048'
- b'010000000040004810000000001000242580002001000000000000000000000'
- b'000000000000000800024064000a00010a')
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
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.secrets_log_file = secrets_log_file
self.tls = tls.Context(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,
+ )
+
if is_client:
- self.tls.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
- )
+ self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
else:
+ self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
+ self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
+ self.quic_transport_parameters.stateless_reset_token = bytes(16)
- self.tls.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
- )
self.tls.certificate</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
# offset: 1
<s>.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
- )
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
===========changed ref 3===========
# module: aioquic.packet
+ 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),
+ ]
===========changed ref 4===========
# module: aioquic.packet
+ def push_quic_transport_parameters(buf, params, is_client):
+ if is_client:
+ push_uint32(buf, params.initial_version)
+ 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)
+
|
aioquic.connection/QuicConnection.datagram_received
|
Modified
|
aiortc~aioquic
|
b3db6c485ccf8e11c74087468d7f62616abee87a
|
[packet] parse / serialize Quic Transport Parameters
|
<23>:<add> self.tls.handshake_extensions.append(
<add> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<add> )
<add>
|
# 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> if header.packet_type is None:
<9> versions = []
<10> while not buf.eof():
<11> versions.append('0x%x' % tls.pull_uint32(buf))
<12> raise Exception('Version negotiation needed: %s' % versions)
<13>
<14> encrypted_off = buf.tell() - start_off
<15> end_off = buf.tell() + header.rest_length
<16> tls.pull_bytes(buf, header.rest_length)
<17>
<18> if not self.is_client and not self.crypto_initialized:
<19> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<20> is_client=self.is_client)
<21> self.crypto_initialized = True
<22>
<23> epoch = get_epoch(header.packet_type)
<24> space = self.spaces[epoch]
<25> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<26> data[start_off:end_off], encrypted_off)
<27>
<28> if not self.peer_cid_set:
<29> self.peer_cid = header.source_cid
<30> self.peer_cid_set = True
<31>
<32> # handle payload
<33> is_ack_only = self._payload_received(epoch, plain_payload)
<34>
<35> # record packet as received
<36> space.ack_queue.add(packet_number)
<37> if not is_ack_only:
<38> self.send_ack[epoch] = True
<39>
|
===========unchanged ref 0===========
at: aioquic.connection
get_epoch(packet_type)
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_serialize_parameters()
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.tls = tls.Context(is_client=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.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
self.crypto_initialized = False
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
setup_initial(cid, is_client)
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
Epoch()
ExtensionType(x: Union[str, bytes, bytearray], base: int)
ExtensionType(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
Buffer(capacity=None, data=None)
===========unchanged ref 1===========
pull_bytes(buf: Buffer, length: int) -> bytes
pull_uint32(buf: Buffer) -> int
at: aioquic.tls.Buffer
eof()
tell()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
at: aioquic.tls.Context.__init__
self.handshake_extensions = []
===========changed ref 0===========
# 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.crypto_initialized = True
+ self.tls.handshake_extensions.append(
+ (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
+ )
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 1===========
# module: aioquic.connection
logger = logging.getLogger('quic')
-
-
- CLIENT_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
- b'ff0000110031000500048010000000060004801000000007000480100000000'
- b'4000481000000000100024258000800024064000a00010a')
- SERVER_QUIC_TRANSPORT_PARAMETERS = binascii.unhexlify(
- b'ff00001104ff000011004500050004801000000006000480100000000700048'
- b'010000000040004810000000001000242580002001000000000000000000000'
- b'000000000000000800024064000a00010a')
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
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=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.is_client = is_client
self.host_cid = os.urandom(8)
self.peer_cid = os.urandom(8)
self.peer_cid_set = False
self.secrets_log_file = secrets_log_file
self.tls = tls.Context(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,
+ )
+
if is_client:
- self.tls.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, CLIENT_QUIC_TRANSPORT_PARAMETERS),
- )
+ self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
else:
+ self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
+ self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
+ self.quic_transport_parameters.stateless_reset_token = bytes(16)
- self.tls.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
- )
self.tls.certificate</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
# offset: 1
<s>.QUIC_TRANSPORT_PARAMETERS, SERVER_QUIC_TRANSPORT_PARAMETERS),
- )
self.tls.certificate = certificate
self.tls.certificate_private_key = private_key
self.tls.update_traffic_key_cb = self._update_traffic_key
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: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
bdc1c9c57ebf754d9f71004107091e1f2d40cc63
|
[client] add support for version negotiation
|
<4>:<add> self.certificate = certificate
<8>:<add> self.private_key = private_key
<9>:<add>
<add> # protocol versions
<add> self.version = PROTOCOL_VERSION_DRAFT_18
<add> self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
<del> self.tls = tls.Context(is_client=is_client)
<20>:<del>
<21>:<del> if is_client:
<22>:<del> self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
<23>:<del> else:
<24>:<del> self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
<25>:<del> self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
<26>:<del> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<27>:<del> self.tls.certificate = certificate
<28>:<del> self.tls.certificate_private_key = private_key
<29>:<del>
<30>:<del> self.tls.update_traffic_key_cb = self._update_traffic_key
|
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=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.is_client = is_client
<5> self.host_cid = os.urandom(8)
<6> self.peer_cid = os.urandom(8)
<7> self.peer_cid_set = False
<8> self.secrets_log_file = secrets_log_file
<9> self.tls = tls.Context(is_client=is_client)
<10>
<11> self.quic_transport_parameters = QuicTransportParameters(
<12> idle_timeout=600,
<13> initial_max_data=16777216,
<14> initial_max_stream_data_bidi_local=1048576,
<15> initial_max_stream_data_bidi_remote=1048576,
<16> initial_max_stream_data_uni=1048576,
<17> initial_max_streams_bidi=100,
<18> ack_delay_exponent=10,
<19> )
<20>
<21> if is_client:
<22> self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
<23> else:
<24> self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
<25> self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
<26> self.quic_transport_parameters.stateless_reset_token = bytes(16)
<27> self.tls.certificate = certificate
<28> self.tls.certificate_private_key = private_key
<29>
<30> self.tls.update_traffic_key_cb = self._update_traffic_key
<31>
<32> self.send_ack = {
<33> tls.Epoch.INITIAL: False,
<34> tls.Epoch.HANDSHAKE: False</s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
# offset: 1
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: 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.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection
_init_tls()
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.crypto.CryptoPair
setup_initial(cid, is_client)
at: aioquic.packet
PROTOCOL_VERSION_DRAFT_17 = 0xff000011
PROTOCOL_VERSION_DRAFT_18 = 0xff000012
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
===========unchanged ref 1===========
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()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
at: os
urandom(size: int, /) -> bytes
===========changed ref 0===========
# 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_17 = 0xff000011 # draft 17
+ 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.connection_made
|
Modified
|
aiortc~aioquic
|
bdc1c9c57ebf754d9f71004107091e1f2d40cc63
|
[client] add support for version negotiation
|
<3>:<add> self._init_tls()
<5>:<del> self.tls.handshake_extensions.append(
<6>:<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<7>:<del> )
|
# 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.crypto_initialized = True
<4>
<5> self.tls.handshake_extensions.append(
<6> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<7> )
<8> self.tls.handle_message(b'', self.send_buffer)
<9>
|
===========unchanged ref 0===========
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),
}
at: aioquic.connection.QuicConnection._init_tls
self.tls = tls.Context(is_client=self.is_client)
at: aioquic.tls
Buffer(capacity=None, data=None)
at: aioquic.tls.Buffer
eof()
at: aioquic.tls.Context
handle_message(input_data, output_buf)
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=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
+
+ # protocol versions
+ self.version = PROTOCOL_VERSION_DRAFT_18
+ self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
- self.tls = tls.Context(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,
)
-
- if is_client:
- self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
- else:
- self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
- self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
- self.quic_transport_parameters.stateless_reset_token = bytes(16)
- self.tls.certificate = certificate
- self.tls.certificate_private_key = private_key
-
- self.</s>
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
# offset: 1
<s> self.tls.certificate = certificate
- self.tls.certificate_private_key = private_key
-
- self.tls.update_traffic_key_cb = self._update_traffic_key
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: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
===========changed ref 2===========
# 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_17 = 0xff000011 # draft 17
+ 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.datagram_received
|
Modified
|
aiortc~aioquic
|
bdc1c9c57ebf754d9f71004107091e1f2d40cc63
|
[client] add support for version negotiation
|
<8>:<add>
<add> # version negotiation
<add> if self.is_client and header.packet_type is None:
<del> if header.packet_type is None:
<11>:<add> versions.append(tls.pull_uint32(buf))
<del> versions.append('0x%x' % tls.pull_uint32(buf))
<12>:<add> common = set(self.supported_versions).intersection(versions)
<add> self.version = max(common)
<add> self.connection_made()
<add> return
<del> raise Exception('Version negotiation needed: %s' % versions)
<21>:<add> self._init_tls()
<22>:<del>
<23>:<del> self.tls.handshake_extensions.append(
<24>:<del> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<25>:<del> )
|
# 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> if header.packet_type is None:
<9> versions = []
<10> while not buf.eof():
<11> versions.append('0x%x' % tls.pull_uint32(buf))
<12> raise Exception('Version negotiation needed: %s' % versions)
<13>
<14> encrypted_off = buf.tell() - start_off
<15> end_off = buf.tell() + header.rest_length
<16> tls.pull_bytes(buf, header.rest_length)
<17>
<18> if not self.is_client and not self.crypto_initialized:
<19> self.spaces[tls.Epoch.INITIAL].crypto.setup_initial(cid=header.destination_cid,
<20> is_client=self.is_client)
<21> self.crypto_initialized = True
<22>
<23> self.tls.handshake_extensions.append(
<24> (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
<25> )
<26>
<27> epoch = get_epoch(header.packet_type)
<28> space = self.spaces[epoch]
<29> plain_header, plain_payload, packet_number = space.crypto.decrypt_packet(
<30> data[start_off:end_off], encrypted_off)
<31>
<32> if not self.peer_cid_set:
<33> self.peer_cid = header.source_cid
<34> self.peer_cid_set = True
<35>
<36> # handle payload
<37> is_ack_only = self._payload_received(epoch, plain_payload)
<38>
<39> # record packet as received
<40> space.ack_queue.add(packet_number)
<41> if not is_</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
connection_made(self)
connection_made()
_init_tls()
_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.version = PROTOCOL_VERSION_DRAFT_18
self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_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.crypto_initialized = False
at: aioquic.connection.QuicConnection.connection_made
self.crypto_initialized = True
at: aioquic.connection.QuicConnection.datagram_received
buf = Buffer(data=data)
start_off = buf.tell()
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
setup_initial(cid, is_client)
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''
===========unchanged ref 1===========
rest_length: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
at: aioquic.tls
Epoch()
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 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.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
- )
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=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
+
+ # protocol versions
+ self.version = PROTOCOL_VERSION_DRAFT_18
+ self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
- self.tls = tls.Context(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,
)
-
- if is_client:
- self.quic_transport_parameters.initial_version = PROTOCOL_VERSION_DRAFT_17
- else:
- self.quic_transport_parameters.negotiated_version = PROTOCOL_VERSION_DRAFT_17
- self.quic_transport_parameters.supported_versions = [PROTOCOL_VERSION_DRAFT_17]
- self.quic_transport_parameters.stateless_reset_token = bytes(16)
- self.tls.certificate = certificate
- self.tls.certificate_private_key = private_key
-
- self.</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
# offset: 1
<s> self.tls.certificate = certificate
- self.tls.certificate_private_key = private_key
-
- self.tls.update_traffic_key_cb = self._update_traffic_key
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: QuicStream(),
tls.Epoch.HANDSHAKE: QuicStream(),
tls.Epoch.ONE_RTT: QuicStream(),
}
self.crypto_initialized = False
self.packet_number = 0
===========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_17 = 0xff000011 # draft 17
+ 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._write_handshake
|
Modified
|
aiortc~aioquic
|
bdc1c9c57ebf754d9f71004107091e1f2d40cc63
|
[client] add support for version negotiation
|
<17>:<add> version=self.version,
<del> version=PROTOCOL_VERSION_DRAFT_17,
|
# 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=PROTOCOL_VERSION_DRAFT_17,
<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> </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
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 = PROTOCOL_VERSION_DRAFT_18
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.packet_number = 0
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)
header_size = buf.tell()
at: aioquic.connection.QuicConnection._write_handshake
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()
===========unchanged ref 1===========
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
PACKET_TYPE_HANDSHAKE = PACKET_LONG_HEADER | PACKET_FIXED_BIT | 0x20
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)
push_ack_frame(buf, rangeset: RangeSet, delay: int)
push_crypto_frame(buf, offset=0)
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
push_bytes(buf: Buffer, v: bytes)
at: aioquic.tls.Buffer
seek(pos)
tell()
===========changed ref 0===========
# 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.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
- )
self.tls.handle_message(b'', self.send_buffer)
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
+ def _init_tls(self):
+ 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.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:
- if header.packet_type is None:
versions = []
while not buf.eof():
+ versions.append(tls.pull_uint32(buf))
- versions.append('0x%x' % tls.pull_uint32(buf))
+ common = set(self.supported_versions).intersection(versions)
+ self.version = max(common)
+ self.connection_made()
+ return
- raise Exception('Version negotiation needed: %s' % versions)
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.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.tls.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
- )
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_</s>
|
tests.test_connection/QuicConnectionTest.test_version_negotiation_needed
|
Modified
|
aiortc~aioquic
|
bdc1c9c57ebf754d9f71004107091e1f2d40cc63
|
[client] add support for version negotiation
|
<3>:<add> datagrams = 0
<5>:<add> datagrams += 1
<add> self.assertEqual(datagrams, 1)
<del> pass
<7>:<del> with self.assertRaises(Exception) as cm:
<8>:<add> client.datagram_received(load('version_negotiation.bin'))
<del> client.datagram_received(load('version_negotiation.bin'))
<9>:<add> for datagram in client.pending_datagrams():
<add> datagrams += 1
<add> self.assertEqual(datagrams, 2)
<del> self.assertEqual(str(cm.exception),
<10>:<del> "Version negotiation needed: ['0xff000012', '0x1a2a3a4a']")
|
# module: tests.test_connection
class QuicConnectionTest(TestCase):
def test_version_negotiation_needed(self):
<0> client = QuicConnection(
<1> is_client=True)
<2>
<3> client.connection_made()
<4> for datagram in client.pending_datagrams():
<5> pass
<6>
<7> with self.assertRaises(Exception) as cm:
<8> client.datagram_received(load('version_negotiation.bin'))
<9> self.assertEqual(str(cm.exception),
<10> "Version negotiation needed: ['0xff000012', '0x1a2a3a4a']")
<11>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None)
at: aioquic.connection.QuicConnection
connection_made()
datagram_received(data: bytes)
pending_datagrams()
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
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: 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.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
- )
self.tls.handle_message(b'', self.send_buffer)
===========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:
- if header.packet_type is None:
versions = []
while not buf.eof():
+ versions.append(tls.pull_uint32(buf))
- versions.append('0x%x' % tls.pull_uint32(buf))
+ common = set(self.supported_versions).intersection(versions)
+ self.version = max(common)
+ self.connection_made()
+ return
- raise Exception('Version negotiation needed: %s' % versions)
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.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.tls.handshake_extensions.append(
- (tls.ExtensionType.QUIC_TRANSPORT_PARAMETERS, self._serialize_parameters()),
- )
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_</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
def datagram_received(self, data: bytes):
# offset: 1
<s> 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 3===========
# module: aioquic.connection
class QuicConnection:
+ def _init_tls(self):
+ 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.update_traffic_key_cb = self._update_traffic_key
+
===========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_17 = 0xff000011 # draft 17
+ 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.tls/KeySchedule.__init__
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<0>:<add> self.algorithm = cipher_suite_hash(cipher_suite)
<add> self.cipher_suite = cipher_suite
<del> self.algorithm = hashes.SHA256()
|
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
<0> self.algorithm = hashes.SHA256()
<1> self.generation = 0
<2> self.hash = hashes.Hash(self.algorithm, default_backend())
<3> self.hash_empty_value = self.hash.copy().finalize()
<4> self.secret = bytes(self.algorithm.digest_size)
<5>
|
===========unchanged ref 0===========
at: aioquic.tls
cipher_suite_hash(cipher_suite)
at: aioquic.tls.KeySchedule.extract
self.generation += 1
===========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
+ 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),
+ }
+
|
aioquic.tls/Context.__init__
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<5>:<add> self._cipher_suites = [
<add> CipherSuite.AES_256_GCM_SHA384,
<add> CipherSuite.AES_128_GCM_SHA256,
<add> ]
|
# module: aioquic.tls
class Context:
def __init__(self, is_client):
<0> self.certificate = None
<1> self.certificate_private_key = None
<2> self.handshake_extensions = []
<3> self.update_traffic_key_cb = lambda d, e, s: None
<4>
<5> self._peer_certificate = None
<6> self._receive_buffer = b''
<7> self.enc_key = None
<8> self.dec_key = None
<9>
<10> if is_client:
<11> self.client_random = os.urandom(32)
<12> self.session_id = os.urandom(32)
<13> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<14> self.state = State.CLIENT_HANDSHAKE_START
<15> else:
<16> self.client_random = None
<17> self.session_id = None
<18> self.private_key = None
<19> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<20>
<21> self.is_client = is_client
<22>
|
===========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 KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 1===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 2===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 3===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 4===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 5===========
# 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
+ 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),
+ }
+
|
aioquic.tls/Context._client_send_hello
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<3>:<del> cipher_suites=[
<4>:<del> CipherSuite.AES_128_GCM_SHA256,
<5>:<del> ],
<6>:<add> cipher_suites=self._cipher_suites,
<29>:<add> self.key_schedule = KeyScheduleProxy(hello.cipher_suites)
<del> self.key_schedule = KeySchedule()
|
# 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=[
<4> CipherSuite.AES_128_GCM_SHA256,
<5> ],
<6> compression_methods=[
<7> CompressionMethod.NULL,
<8> ],
<9>
<10> key_exchange_modes=[
<11> KeyExchangeMode.PSK_DHE_KE,
<12> ],
<13> key_share=[
<14> encode_public_key(self.private_key.public_key()),
<15> ],
<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 = KeySchedule()
<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()
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_certificate_verify(input_buf)
_client_handle_finished(self, input_buf, output_buf)
_client_handle_finished(input_buf, output_buf)
_client_handle_new_session_ticket(input_buf)
_client_handle_new_session_ticket(self, input_buf)
_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.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
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 1===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 2===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 3===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 6===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 7===========
# module: aioquic.tls
class Context:
def __init__(self, is_client):
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,
+ ]
self._peer_certificate = None
self._receive_buffer = b''
self.enc_key = None
self.dec_key = None
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
self.is_client = is_client
===========changed ref 8===========
# 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
+ 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),
+ }
+
|
aioquic.tls/Context._client_handle_hello
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<5>:<add> self.key_schedule = self.key_schedule.select(peer_hello.cipher_suite)
|
# 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.update_hash(input_buf.data)
<6> self.key_schedule.extract(shared_key)
<7>
<8> self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b's hs traffic')
<9>
<10> self._set_state(State.CLIENT_EXPECT_ENCRYPTED_EXTENSIONS)
<11>
|
===========unchanged ref 0===========
at: aioquic.tls
CompressionMethod(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
CompressionMethod(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, key_exchange_modes: List[int]=None, key_share: List[Tuple[int, bytes]]=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
cipher_suites: List[int] = None
compression_methods: List[int] = None
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = 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._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self.client_random = None
self.client_random = os.urandom(32)
self.session_id = None
self.session_id = os.urandom(32)
===========unchanged ref 1===========
at: aioquic.tls.Context._server_handle_hello
self.client_random = peer_hello.random
self.session_id = peer_hello.session_id
===========changed ref 0===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 1===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 2===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 3===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 6===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 7===========
# 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=[
- CipherSuite.AES_128_GCM_SHA256,
- ],
+ cipher_suites=self._cipher_suites,
compression_methods=[
CompressionMethod.NULL,
],
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
signature_algorithms=[
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
],
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 = KeySchedule()
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 8===========
# module: aioquic.tls
class Context:
def __init__(self, is_client):
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,
+ ]
self._peer_certificate = None
self._receive_buffer = b''
self.enc_key = None
self.dec_key = None
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
self.is_client = is_client
===========changed ref 9===========
# 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
+ 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),
+ }
+
|
aioquic.tls/Context._server_handle_hello
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<7>:<add> # determine cipher suite
<add> cipher_suite = None
<add> for c in self._cipher_suites:
<add> if c in peer_hello.cipher_suites:
<add> cipher_suite = c
<add> break
<add> assert cipher_suite is not None
<add>
<add> self.key_schedule = KeySchedule(cipher_suite)
<del> self.key_schedule = KeySchedule()
<18>:<add> cipher_suite=cipher_suite,
<del> cipher_suite=CipherSuite.AES_128_GCM_SHA256,
|
# 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> self.key_schedule = KeySchedule()
<8> self.key_schedule.extract(None)
<9> self.key_schedule.update_hash(input_buf.data)
<10>
<11> peer_public_key = decode_public_key(peer_hello.key_share[0])
<12> shared_key = self.private_key.exchange(ec.ECDH(), peer_public_key)
<13>
<14> # send hello
<15> hello = ServerHello(
<16> random=self.server_random,
<17> session_id=self.session_id,
<18> cipher_suite=CipherSuite.AES_128_GCM_SHA256,
<19> compression_method=CompressionMethod.NULL,
<20>
<21> key_share=encode_public_key(self.private_key.public_key()),
<22> supported_version=TLS_VERSION_1_3,
<23> )
<24> with self._push_message(output_buf):
<25> push_server_hello(output_buf, hello)
<26> self.key_schedule.extract(shared_key)
<27>
<28> self._setup_traffic_protection(Direction.ENCRYPT, Epoch.HANDSHAKE, b's hs traffic')
<29> self._setup_traffic_protection(Direction.DECRYPT, Epoch.HANDSHAKE, b'c hs traffic')
<30>
<31> # send encrypted extensions
<32> with self._push_message(output_buf):
<33> push_encrypted_extensions(output_buf, EncryptedExtensions(
<34> other_extensions=self.handshake_extensions))
<35>
<36> # send certificate
<37> </s>
|
===========below chunk 0===========
# module: aioquic.tls
class Context:
def _server_handle_hello(self, input_buf, output_buf):
# offset: 1
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()
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)
pull_new_session_ticket(buf: Buffer) -> NewSessionTicket
Finished(verify_data: bytes=b'')
pull_finished(buf: Buffer) -> Finished
push_finished(buf: Buffer, finished: Finished)
KeySchedule(cipher_suite)
decode_public_key(key_share)
encode_public_key(public_key)
at: aioquic.tls.Context
_push_message(buf: Buffer)
_setup_traffic_protection(direction, epoch, label)
_set_state(state)
at: aioquic.tls.Context.__init__
self.update_traffic_key_cb = lambda d, e, s: None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self.enc_key = None
self.dec_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())
===========unchanged ref 1===========
at: aioquic.tls.Context._client_handle_certificate_verify
algorithm = hashes.SHA256()
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_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.Finished
verify_data: bytes = b''
at: aioquic.tls.KeySchedule
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
===========changed ref 0===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 1===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 2===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 3===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 4===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 7===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
|
aioquic.crypto/derive_key_iv_hp
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<0>:<add> algorithm = cipher_suite_hash(cipher_suite)
<add> if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
<add> key_size = 32
<add> else:
<add> key_size = 16
<1>:<add> hkdf_expand_label(algorithm, secret, b'quic key', b'', key_size),
<del> hkdf_expand_label(algorithm, secret, b'quic key', b'', 16),
<3>:<add> hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
<del> hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
|
# module: aioquic.crypto
+ def derive_key_iv_hp(cipher_suite, secret):
- def derive_key_iv_hp(algorithm, secret):
<0> return (
<1> hkdf_expand_label(algorithm, secret, b'quic key', b'', 16),
<2> hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
<3> hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
<4> )
<5>
|
===========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.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 1===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 2===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 3===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 7===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 8===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 9===========
# 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
+ 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 10===========
# module: aioquic.tls
class Context:
def __init__(self, is_client):
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,
+ ]
self._peer_certificate = None
self._receive_buffer = b''
self.enc_key = None
self.dec_key = None
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
self.is_client = is_client
===========changed ref 11===========
# 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=[
- CipherSuite.AES_128_GCM_SHA256,
- ],
+ cipher_suites=self._cipher_suites,
compression_methods=[
CompressionMethod.NULL,
],
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
signature_algorithms=[
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
],
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 = KeySchedule()
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)
|
aioquic.crypto/CryptoContext.setup
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<0>:<add> key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
<del> key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
<1>:<add> self.aead = cipher_suite_aead(cipher_suite, key)
<del> self.aead = aead.AESGCM(key)
|
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
<0> key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
<1> self.aead = aead.AESGCM(key)
<2> self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
<3>
|
===========unchanged ref 0===========
at: aioquic.crypto.CryptoContext.setup
self.aead = cipher_suite_aead(cipher_suite, key)
at: aioquic.crypto.CryptoContext.teardown
self.aead = None
===========changed ref 0===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 1===========
# module: aioquic.crypto
+ def derive_key_iv_hp(cipher_suite, secret):
- def derive_key_iv_hp(algorithm, secret):
+ algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ 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 key', b'', 16),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
+ hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
- hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
)
===========changed ref 2===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 3===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 4===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 7===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 8===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 9===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 10===========
# 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
+ 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 11===========
# module: aioquic.tls
class Context:
def __init__(self, is_client):
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,
+ ]
self._peer_certificate = None
self._receive_buffer = b''
self.enc_key = None
self.dec_key = None
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
self.is_client = is_client
===========changed ref 12===========
# 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=[
- CipherSuite.AES_128_GCM_SHA256,
- ],
+ cipher_suites=self._cipher_suites,
compression_methods=[
CompressionMethod.NULL,
],
key_exchange_modes=[
KeyExchangeMode.PSK_DHE_KE,
],
key_share=[
encode_public_key(self.private_key.public_key()),
],
signature_algorithms=[
SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
],
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 = KeySchedule()
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)
|
aioquic.crypto/CryptoPair.setup_initial
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<5>:<add> algorithm = cipher_suite_hash(INITIAL_CIPHER_SUITE)
<del> algorithm = INITIAL_ALGORITHM
<8>:<add> INITIAL_CIPHER_SUITE,
<del> algorithm,
<11>:<add> INITIAL_CIPHER_SUITE,
<del> algorithm,
|
# module: aioquic.crypto
class CryptoPair:
def setup_initial(self, cid, is_client):
<0> if is_client:
<1> recv_label, send_label = b'server in', b'client in'
<2> else:
<3> recv_label, send_label = b'client in', b'server in'
<4>
<5> algorithm = INITIAL_ALGORITHM
<6> initial_secret = hkdf_extract(algorithm, INITIAL_SALT, cid)
<7> self.recv.setup(
<8> algorithm,
<9> hkdf_expand_label(algorithm, initial_secret, recv_label, b'', algorithm.digest_size))
<10> self.send.setup(
<11> algorithm,
<12> hkdf_expand_label(algorithm, initial_secret, send_label, b'', algorithm.digest_size))
<13>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
at: aioquic.crypto.CryptoContext
encrypt_packet(plain_header, plain_payload)
setup(cipher_suite, secret)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
self.send = CryptoContext()
at: aioquic.tls
hkdf_extract(algorithm, salt, key_material)
cipher_suite_hash(cipher_suite)
===========changed ref 0===========
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
+ key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
+ self.aead = cipher_suite_aead(cipher_suite, key)
- self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 1===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 2===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 3===========
# module: aioquic.crypto
+ def derive_key_iv_hp(cipher_suite, secret):
- def derive_key_iv_hp(algorithm, secret):
+ algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ 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 key', b'', 16),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
+ hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
- hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
)
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 5===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 7===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 8===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 9===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 10===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 11===========
# 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
+ 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 12===========
# module: aioquic.tls
class Context:
def __init__(self, is_client):
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,
+ ]
self._peer_certificate = None
self._receive_buffer = b''
self.enc_key = None
self.dec_key = None
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
self.is_client = is_client
|
aioquic.connection/QuicConnection._update_traffic_key
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<9>:<add> crypto.send.setup(self.tls.key_schedule.cipher_suite, secret)
<del> crypto.send.setup(self.tls.key_schedule.algorithm, secret)
<11>:<add> crypto.recv.setup(self.tls.key_schedule.cipher_suite, secret)
<del> crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
|
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
<0> if self.secrets_log_file is not None:
<1> label_row = self.is_client == (direction == tls.Direction.DECRYPT)
<2> label = SECRETS_LABELS[label_row][epoch.value]
<3> self.secrets_log_file.write('%s %s %s\n' % (
<4> label, self.tls.client_random.hex(), secret.hex()))
<5> self.secrets_log_file.flush()
<6>
<7> crypto = self.spaces[epoch].crypto
<8> if direction == tls.Direction.ENCRYPT:
<9> crypto.send.setup(self.tls.key_schedule.algorithm, secret)
<10> else:
<11> crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
<12>
|
===========unchanged ref 0===========
at: aioquic.connection
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']
]
at: aioquic.connection.PacketSpace.__init__
self.crypto = CryptoPair()
at: aioquic.connection.QuicConnection.__init__
self.is_client = is_client
self.secrets_log_file = secrets_log_file
self.spaces = {
tls.Epoch.INITIAL: PacketSpace(),
tls.Epoch.HANDSHAKE: PacketSpace(),
tls.Epoch.ONE_RTT: PacketSpace(),
}
at: aioquic.connection.QuicConnection._init_tls
self.tls = tls.Context(is_client=self.is_client)
at: aioquic.crypto.CryptoContext
setup(cipher_suite, secret)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
self.send = CryptoContext()
at: aioquic.tls
Direction()
at: aioquic.tls.Context.__init__
self.client_random = None
self.client_random = os.urandom(32)
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.client_random = peer_hello.random
self.key_schedule = KeySchedule(cipher_suite)
===========unchanged ref 1===========
at: aioquic.tls.KeySchedule.__init__
self.algorithm = cipher_suite_hash(cipher_suite)
at: io.StringIO
flush(self) -> None
write(self, s: str, /) -> int
===========changed ref 0===========
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
+ key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
+ self.aead = cipher_suite_aead(cipher_suite, key)
- self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 1===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 2===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 3===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 7===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 8===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 9===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 10===========
# module: aioquic.crypto
+ def derive_key_iv_hp(cipher_suite, secret):
- def derive_key_iv_hp(algorithm, secret):
+ algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ 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 key', b'', 16),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
+ hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
- hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
)
===========changed ref 11===========
# 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
+ 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),
+ }
+
|
tests.test_tls/ContextTest.test_handshake
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<8>:<add> self.assertEqual(len(server_input), 244)
<del> self.assertEqual(len(server_input), 242)
<17>:<add> self.assertEqual(len(client_input), 2227)
<del> self.assertEqual(len(client_input), 155 + 90 + 1538 + 392 + 36)
<25>:<add> self.assertEqual(len(server_input), 52)
<del> self.assertEqual(len(server_input), 36)
|
# 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), 242)
<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), 155 + 90 + 1538 + 392 + 36)
<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), 36)
<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.</s>
|
===========below chunk 0===========
# module: tests.test_tls
class ContextTest(TestCase):
def test_handshake(self):
# offset: 1
===========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
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 1===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 2===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 3===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 6===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 7===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 8===========
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
+ key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
+ self.aead = cipher_suite_aead(cipher_suite, key)
- self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 9===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 10===========
# module: aioquic.crypto
+ def derive_key_iv_hp(cipher_suite, secret):
- def derive_key_iv_hp(algorithm, secret):
+ algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ 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 key', b'', 16),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
+ hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
- hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
)
===========changed ref 11===========
# 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
+ 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 12===========
# module: aioquic.crypto
class CryptoPair:
def setup_initial(self, cid, is_client):
if is_client:
recv_label, send_label = b'server in', b'client in'
else:
recv_label, send_label = b'client in', b'server in'
+ algorithm = cipher_suite_hash(INITIAL_CIPHER_SUITE)
- algorithm = INITIAL_ALGORITHM
initial_secret = hkdf_extract(algorithm, INITIAL_SALT, cid)
self.recv.setup(
+ INITIAL_CIPHER_SUITE,
- algorithm,
hkdf_expand_label(algorithm, initial_secret, recv_label, b'', algorithm.digest_size))
self.send.setup(
+ INITIAL_CIPHER_SUITE,
- algorithm,
hkdf_expand_label(algorithm, initial_secret, send_label, b'', algorithm.digest_size))
|
tests.test_crypto/CryptoTest.test_derive_key_iv_hp
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<3>:<add> key, iv, hp = derive_key_iv_hp(INITIAL_CIPHER_SUITE, secret)
<del> key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
<11>:<add> key, iv, hp = derive_key_iv_hp(INITIAL_CIPHER_SUITE, secret)
<del> key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_derive_key_iv_hp(self):
<0> # client
<1> secret = binascii.unhexlify(
<2> '8a3515a14ae3c31b9c2d6d5bc58538ca5cd2baa119087143e60887428dcb52f6')
<3> key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
<4> self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
<5> self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
<6> self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
<7>
<8> # server
<9> secret = binascii.unhexlify(
<10> '47b2eaea6c266e32c0697a9e2a898bdf5c4fb3e5ac34f0e549bf2c58581a3811')
<11> key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
<12> self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
<13> self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
<14> self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
<15>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
derive_key_iv_hp(cipher_suite, secret)
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
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.crypto
+ def derive_key_iv_hp(cipher_suite, secret):
- def derive_key_iv_hp(algorithm, secret):
+ algorithm = cipher_suite_hash(cipher_suite)
+ if cipher_suite == CipherSuite.AES_256_GCM_SHA384:
+ 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 key', b'', 16),
hkdf_expand_label(algorithm, secret, b'quic iv', b'', 12),
+ hkdf_expand_label(algorithm, secret, b'quic hp', b'', key_size)
- hkdf_expand_label(algorithm, secret, b'quic hp', b'', 16)
)
===========changed ref 1===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 2===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 3===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 7===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 8===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 9===========
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
+ key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
+ self.aead = cipher_suite_aead(cipher_suite, key)
- self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 10===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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 11===========
# 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
+ 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 12===========
# module: aioquic.crypto
class CryptoPair:
def setup_initial(self, cid, is_client):
if is_client:
recv_label, send_label = b'server in', b'client in'
else:
recv_label, send_label = b'client in', b'server in'
+ algorithm = cipher_suite_hash(INITIAL_CIPHER_SUITE)
- algorithm = INITIAL_ALGORITHM
initial_secret = hkdf_extract(algorithm, INITIAL_SALT, cid)
self.recv.setup(
+ INITIAL_CIPHER_SUITE,
- algorithm,
hkdf_expand_label(algorithm, initial_secret, recv_label, b'', algorithm.digest_size))
self.send.setup(
+ INITIAL_CIPHER_SUITE,
- algorithm,
hkdf_expand_label(algorithm, initial_secret, send_label, b'', algorithm.digest_size))
===========changed ref 13===========
# module: aioquic.connection
class QuicConnection:
def _update_traffic_key(self, direction, epoch, secret):
if self.secrets_log_file is not None:
label_row = self.is_client == (direction == tls.Direction.DECRYPT)
label = SECRETS_LABELS[label_row][epoch.value]
self.secrets_log_file.write('%s %s %s\n' % (
label, self.tls.client_random.hex(), secret.hex()))
self.secrets_log_file.flush()
crypto = self.spaces[epoch].crypto
if direction == tls.Direction.ENCRYPT:
+ crypto.send.setup(self.tls.key_schedule.cipher_suite, secret)
- crypto.send.setup(self.tls.key_schedule.algorithm, secret)
else:
+ crypto.recv.setup(self.tls.key_schedule.cipher_suite, secret)
- crypto.recv.setup(self.tls.key_schedule.algorithm, secret)
|
tests.test_crypto/CryptoTest.test_decrypt_short_server
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<2>:<add> INITIAL_CIPHER_SUITE,
<del> INITIAL_ALGORITHM,
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_short_server(self):
<0> pair = CryptoPair()
<1> pair.recv.setup(
<2> INITIAL_ALGORITHM,
<3> binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
<4>
<5> plain_header, plain_payload, packet_number = pair.decrypt_packet(
<6> SHORT_SERVER_ENCRYPTED_PACKET, 9)
<7> self.assertEqual(plain_header, SHORT_SERVER_PLAIN_HEADER)
<8> self.assertEqual(plain_payload, SHORT_SERVER_PLAIN_PAYLOAD)
<9> self.assertEqual(packet_number, 3)
<10>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
CryptoPair()
at: aioquic.crypto.CryptoContext
setup(cipher_suite, secret)
at: aioquic.crypto.CryptoPair
decrypt_packet(packet, encrypted_offset)
at: aioquic.crypto.CryptoPair.__init__
self.recv = CryptoContext()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_crypto
SHORT_SERVER_PLAIN_HEADER = binascii.unhexlify('41b01fd24a586a9cf30003')
SHORT_SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'06003904000035000151805a4bebf5000020b098c8dc4183e4c182572e10ac3e'
'2b88897e0524c8461847548bd2dffa2c0ae60008002a0004ffffffff')
SHORT_SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'5db01fd24a586a9cf33dec094aaec6d6b4b7a5e15f5a3f05d06cf1ad0355c19d'
'cce0807eecf7bf1c844a66e1ecd1f74b2a2d69bfd25d217833edd973246597bd'
'5107ea15cb1e210045396afa602fe23432f4ab24ce251b')
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
+ key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
+ self.aead = cipher_suite_aead(cipher_suite, key)
- self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_derive_key_iv_hp(self):
# client
secret = binascii.unhexlify(
'8a3515a14ae3c31b9c2d6d5bc58538ca5cd2baa119087143e60887428dcb52f6')
+ key, iv, hp = derive_key_iv_hp(INITIAL_CIPHER_SUITE, secret)
- key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
# server
secret = binascii.unhexlify(
'47b2eaea6c266e32c0697a9e2a898bdf5c4fb3e5ac34f0e549bf2c58581a3811')
+ key, iv, hp = derive_key_iv_hp(INITIAL_CIPHER_SUITE, secret)
- key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
===========changed ref 2===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 3===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 4===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 5===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 7===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 8===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 9===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
===========changed ref 10===========
# module: aioquic.tls
class Context:
def _client_handle_hello(self, input_buf, output_buf):
peer_hello = pull_server_hello(input_buf)
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_crypto/CryptoTest.test_encrypt_short_server
|
Modified
|
aiortc~aioquic
|
3b436074ac22044aa678d726d582ec99debd5193
|
[tls] negotiate cipher suite, add AES_256_GCM_SHA384
|
<2>:<add> INITIAL_CIPHER_SUITE,
<del> INITIAL_ALGORITHM,
|
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_encrypt_short_server(self):
<0> pair = CryptoPair()
<1> pair.send.setup(
<2> INITIAL_ALGORITHM,
<3> binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
<4>
<5> packet = pair.encrypt_packet(SHORT_SERVER_PLAIN_HEADER, SHORT_SERVER_PLAIN_PAYLOAD)
<6> self.assertEqual(packet, SHORT_SERVER_ENCRYPTED_PACKET)
<7>
|
===========unchanged ref 0===========
at: aioquic.crypto
INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
CryptoPair()
at: aioquic.crypto.CryptoContext
setup(cipher_suite, secret)
at: aioquic.crypto.CryptoPair
encrypt_packet(plain_header, plain_payload)
at: aioquic.crypto.CryptoPair.__init__
self.send = CryptoContext()
at: binascii
unhexlify(hexstr: _Ascii, /) -> bytes
at: tests.test_crypto
SHORT_SERVER_PLAIN_HEADER = binascii.unhexlify('41b01fd24a586a9cf30003')
SHORT_SERVER_PLAIN_PAYLOAD = binascii.unhexlify(
'06003904000035000151805a4bebf5000020b098c8dc4183e4c182572e10ac3e'
'2b88897e0524c8461847548bd2dffa2c0ae60008002a0004ffffffff')
SHORT_SERVER_ENCRYPTED_PACKET = binascii.unhexlify(
'5db01fd24a586a9cf33dec094aaec6d6b4b7a5e15f5a3f05d06cf1ad0355c19d'
'cce0807eecf7bf1c844a66e1ecd1f74b2a2d69bfd25d217833edd973246597bd'
'5107ea15cb1e210045396afa602fe23432f4ab24ce251b')
at: unittest.case.TestCase
assertEqual(first: Any, second: Any, msg: Any=...) -> None
===========changed ref 0===========
# module: aioquic.crypto
class CryptoContext:
+ def setup(self, cipher_suite, secret):
- def setup(self, algorithm, secret):
+ key, self.iv, hp = derive_key_iv_hp(cipher_suite, secret)
- key, self.iv, hp = derive_key_iv_hp(algorithm, secret)
+ self.aead = cipher_suite_aead(cipher_suite, key)
- self.aead = aead.AESGCM(key)
self.hp = Cipher(algorithms.AES(hp), modes.ECB(), backend=default_backend())
===========changed ref 1===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_decrypt_short_server(self):
pair = CryptoPair()
pair.recv.setup(
+ INITIAL_CIPHER_SUITE,
- INITIAL_ALGORITHM,
binascii.unhexlify('310281977cb8c1c1c1212d784b2d29e5a6489e23de848d370a5a2f9537f3a100'))
plain_header, plain_payload, packet_number = pair.decrypt_packet(
SHORT_SERVER_ENCRYPTED_PACKET, 9)
self.assertEqual(plain_header, SHORT_SERVER_PLAIN_HEADER)
self.assertEqual(plain_payload, SHORT_SERVER_PLAIN_PAYLOAD)
self.assertEqual(packet_number, 3)
===========changed ref 2===========
# module: tests.test_crypto
class CryptoTest(TestCase):
def test_derive_key_iv_hp(self):
# client
secret = binascii.unhexlify(
'8a3515a14ae3c31b9c2d6d5bc58538ca5cd2baa119087143e60887428dcb52f6')
+ key, iv, hp = derive_key_iv_hp(INITIAL_CIPHER_SUITE, secret)
- key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
self.assertEqual(key, binascii.unhexlify('98b0d7e5e7a402c67c33f350fa65ea54'))
self.assertEqual(iv, binascii.unhexlify('19e94387805eb0b46c03a788'))
self.assertEqual(hp, binascii.unhexlify('0edd982a6ac527f2eddcbb7348dea5d7'))
# server
secret = binascii.unhexlify(
'47b2eaea6c266e32c0697a9e2a898bdf5c4fb3e5ac34f0e549bf2c58581a3811')
+ key, iv, hp = derive_key_iv_hp(INITIAL_CIPHER_SUITE, secret)
- key, iv, hp = derive_key_iv_hp(INITIAL_ALGORITHM, secret)
self.assertEqual(key, binascii.unhexlify('9a8be902a9bdd91d16064ca118045fb4'))
self.assertEqual(iv, binascii.unhexlify('0a82086d32205ba22241d8dc'))
self.assertEqual(hp, binascii.unhexlify('94b9452d2b3c7c7f6da7fdd8593537fd'))
===========changed ref 3===========
# module: aioquic.tls
+ def cipher_suite_hash(cipher_suite):
+ return CIPHER_SUITES[cipher_suite][1]()
+
===========changed ref 4===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def __init__(self, cipher_suites):
+ self.__items = list(map(KeySchedule, cipher_suites))
+
===========changed ref 5===========
# module: aioquic.tls
+ def cipher_suite_aead(cipher_suite, key):
+ return CIPHER_SUITES[cipher_suite][0](key)
+
===========changed ref 6===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def update_hash(self, data):
+ for k in self.__items:
+ k.update_hash(data)
+
===========changed ref 7===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def extract(self, key_material=None):
+ for k in self.__items:
+ k.extract(key_material)
+
===========changed ref 8===========
# module: aioquic.tls
+ class KeyScheduleProxy:
+ def select(self, cipher_suite):
+ for k in self.__items:
+ if k.cipher_suite == cipher_suite:
+ return k
+
===========changed ref 9===========
# module: aioquic.crypto
+ INITIAL_CIPHER_SUITE = CipherSuite.AES_128_GCM_SHA256
- INITIAL_ALGORITHM = hashes.SHA256()
INITIAL_SALT = binascii.unhexlify('ef4fb0abb47470c41befcf8031334fae485e09a0')
MAX_PN_SIZE = 4
===========changed ref 10===========
# module: aioquic.tls
# CONTEXT
class KeySchedule:
+ def __init__(self, cipher_suite):
- def __init__(self):
+ self.algorithm = cipher_suite_hash(cipher_suite)
+ self.cipher_suite = cipher_suite
- self.algorithm = hashes.SHA256()
self.generation = 0
self.hash = hashes.Hash(self.algorithm, default_backend())
self.hash_empty_value = self.hash.copy().finalize()
self.secret = bytes(self.algorithm.digest_size)
|
aioquic.tls/pull_client_hello
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<27>:<add> elif extension_type == ExtensionType.SERVER_NAME:
<add> with pull_block(buf, 2):
<add> assert pull_uint8(buf) == 0
<add> with pull_block(buf, 2) as length:
<add> hello.server_name = pull_bytes(buf, length).decode('ascii')
|
# 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> else:
<28> hello.other_extensions.append(
<29> (extension_type, pull_bytes(buf, extension_length)),
<30> )
<31>
<32> pull_list(buf, 2, pull_extension)
<33>
<34> return hello
<35>
|
===========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
pull_uint8(buf: Buffer) -> int
pull_uint16(buf: Buffer) -> int
pull_block(buf: Buffer, capacity: int)
pull_list(buf: Buffer, capacity: int, func)
pull_key_share(buf: Buffer) -> Tuple[int, bytes]
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=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
cipher_suites: List[int] = None
compression_methods: List[int] = 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)
===========changed ref 0===========
# 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
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)
|
aioquic.tls/push_client_hello
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<26>:<add> if hello.server_name is not None:
<add> with push_extension(buf, ExtensionType.SERVER_NAME):
<add> with push_block(buf, 2):
<add> push_uint8(buf, 0)
<add> with push_block(buf, 2):
<add> push_bytes(buf, hello.server_name.encode('ascii'))
<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> for extension_type, extension_value in hello.other_extensions:
<27> with push_extension(buf, extension_type):
<28> push_bytes(buf, extension_value)
<29>
|
===========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)
push_bytes(buf: Buffer, v: bytes)
push_uint8(buf: Buffer, v: int)
push_uint16(buf: Buffer, v: int)
push_block(buf: Buffer, capacity: int)
pull_list(buf: Buffer, capacity: int, func)
push_list(buf: Buffer, capacity: int, func, values)
push_key_share(buf: Buffer, value: Tuple[int, bytes])
push_extension(buf: Buffer, extension_type: int)
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=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
cipher_suites: List[int] = None
compression_methods: List[int] = None
key_share: List[Tuple[int, bytes]] = None
signature_algorithms: List[int] = None
supported_groups: List[int] = None
supported_versions: List[int] = None
===========unchanged ref 1===========
at: aioquic.tls.pull_client_hello
hello = ClientHello()
pull_extension(buf)
===========changed ref 0===========
# 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
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 1===========
# 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')
else:
hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
</s>
===========changed ref 2===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
<s> 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
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<3>:<add> self.is_client = is_client
<add> self.server_name = None
<11>:<add> self._enc_key = None
<del> self.enc_key = None
<12>:<add> self._dec_key = None
<del> self.dec_key = None
<25>:<del> self.is_client = is_client
<26>:<del>
|
# module: aioquic.tls
class Context:
def __init__(self, is_client):
<0> self.certificate = None
<1> self.certificate_private_key = None
<2> self.handshake_extensions = []
<3> self.update_traffic_key_cb = lambda d, e, s: None
<4>
<5> self._cipher_suites = [
<6> CipherSuite.AES_256_GCM_SHA384,
<7> CipherSuite.AES_128_GCM_SHA256,
<8> ]
<9> self._peer_certificate = None
<10> self._receive_buffer = b''
<11> self.enc_key = None
<12> self.dec_key = None
<13>
<14> if is_client:
<15> self.client_random = os.urandom(32)
<16> self.session_id = os.urandom(32)
<17> self.private_key = ec.generate_private_key(ec.SECP256R1(), default_backend())
<18> self.state = State.CLIENT_HANDSHAKE_START
<19> else:
<20> self.client_random = None
<21> self.session_id = None
<22> self.private_key = None
<23> self.state = State.SERVER_EXPECT_CLIENT_HELLO
<24>
<25> self.is_client = is_client
<26>
|
===========unchanged ref 0===========
at: aioquic.tls
CipherSuite(x: Union[str, bytes, bytearray], base: int)
CipherSuite(x: Union[str, bytes, SupportsInt, _SupportsIndex, _SupportsTrunc]=...)
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())
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.handle_message
self._receive_buffer += input_data
self._receive_buffer = self._receive_buffer[message_length:]
===========changed ref 0===========
# 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
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 1===========
# 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'))
+
for extension_type, extension_value in hello.other_extensions:
with push_extension(buf, extension_type):
push_bytes(buf, extension_value)
===========changed ref 2===========
# 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')
else:
hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
</s>
===========changed ref 3===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
<s> 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
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<14>:<add> server_name=self.server_name,
|
# 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> signature_algorithms=[
<15> SignatureAlgorithm.RSA_PSS_RSAE_SHA256,
<16> ],
<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()
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]=...)
ClientHello(random: bytes=None, session_id: bytes=None, cipher_suites: List[int]=None, compression_methods: List[int]=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.Context
_server_handle_finished(self, input_buf)
_server_handle_finished(input_buf)
at: aioquic.tls.Context.__init__
self.server_name = None
self._cipher_suites = [
CipherSuite.AES_256_GCM_SHA384,
CipherSuite.AES_128_GCM_SHA256,
]
self.client_random = None
self.client_random = os.urandom(32)
===========unchanged ref 1===========
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
# MESSAGES
@dataclass
class ClientHello:
random: bytes = None
session_id: bytes = None
cipher_suites: List[int] = None
compression_methods: List[int] = None
# extensions
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 1===========
# module: aioquic.tls
class Context:
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.enc_key = None
+ self._dec_key = None
- self.dec_key = None
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
- self.is_client = is_client
-
===========changed ref 2===========
# 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'))
+
for extension_type, extension_value in hello.other_extensions:
with push_extension(buf, extension_type):
push_bytes(buf, extension_value)
|
aioquic.tls/Context._client_handle_finished
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<3>:<add> expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
<del> expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
<15>:<add> verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
<del> verify_data=self.key_schedule.finished_verify_data(self.enc_key)))
<18>:<add> self._enc_key = next_enc_key
<del> self.enc_key = next_enc_key
<19>:<add> self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self._enc_key)
<del> self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self.enc_key)
|
# module: aioquic.tls
class Context:
def _client_handle_finished(self, input_buf, output_buf):
<0> finished = pull_finished(input_buf)
<1>
<2> # check verify data
<3> expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
<4> assert finished.verify_data == expected_verify_data
<5> self.key_schedule.update_hash(input_buf.data)
<6>
<7> # prepare traffic keys
<8> assert self.key_schedule.generation == 2
<9> self.key_schedule.extract(None)
<10> self._setup_traffic_protection(Direction.DECRYPT, Epoch.ONE_RTT, b's ap traffic')
<11> next_enc_key = self.key_schedule.derive_secret(b'c ap traffic')
<12>
<13> # send finished
<14> push_finished(output_buf, Finished(
<15> verify_data=self.key_schedule.finished_verify_data(self.enc_key)))
<16>
<17> # commit traffic key
<18> self.enc_key = next_enc_key
<19> self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self.enc_key)
<20>
<21> self._set_state(State.CLIENT_POST_HANDSHAKE)
<22>
|
===========unchanged ref 0===========
at: aioquic.tls
State()
pull_finished(buf: Buffer) -> Finished
at: aioquic.tls.CertificateVerify
algorithm: int = None
signature: bytes = None
at: aioquic.tls.Context
_set_state(state)
at: aioquic.tls.Context.__init__
self._peer_certificate = None
self._dec_key = None
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_certificate_verify
verify = pull_certificate_verify(input_buf)
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_finished
self._dec_key = self._next_dec_key
at: aioquic.tls.Context._server_handle_hello
self.key_schedule = KeySchedule(cipher_suite)
at: aioquic.tls.Context._setup_traffic_protection
self._dec_key = key
at: aioquic.tls.Finished
verify_data: bytes = b''
at: aioquic.tls.KeySchedule
certificate_verify_data(context_string)
finished_verify_data(secret)
update_hash(data)
at: aioquic.tls.KeyScheduleProxy
update_hash(data)
===========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,
],
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,
],
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 1===========
# module: aioquic.tls
class Context:
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.enc_key = None
+ self._dec_key = None
- self.dec_key = None
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
- self.is_client = is_client
-
===========changed ref 2===========
# 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
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 3===========
# 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'))
+
for extension_type, extension_value in hello.other_extensions:
with push_extension(buf, extension_type):
push_bytes(buf, extension_value)
|
aioquic.tls/Context._server_handle_hello
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
# 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()
State()
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)
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)
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.Context
_push_message(buf: Buffer)
_setup_traffic_protection(direction, epoch, label)
_set_state(state)
===========unchanged ref 1===========
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,
]
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)
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: aioquic.tls.ServerHello
random: bytes = None
session_id: bytes = None
===========unchanged ref 2===========
cipher_suite: int = None
compression_method: int = None
key_share: Tuple[int, bytes] = None
supported_version: int = None
at: os
urandom(size: int, /) -> bytes
|
|
aioquic.tls/Context._server_handle_finished
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<3>:<add> expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
<del> expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
<7>:<add> self._dec_key = self._next_dec_key
<del> self.dec_key = self._next_dec_key
<9>:<add> self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self._dec_key)
<del> self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self.dec_key)
|
# module: aioquic.tls
class Context:
def _server_handle_finished(self, input_buf):
<0> finished = pull_finished(input_buf)
<1>
<2> # check verify data
<3> expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
<4> assert finished.verify_data == expected_verify_data
<5>
<6> # commit traffic key
<7> self.dec_key = self._next_dec_key
<8> self._next_dec_key = None
<9> self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self.dec_key)
<10>
<11> self.key_schedule.update_hash(input_buf.data)
<12>
<13> self._set_state(State.SERVER_POST_HANDSHAKE)
<14>
|
===========unchanged ref 0===========
at: aioquic.tls
Direction()
Epoch()
State()
Finished(verify_data: bytes=b'')
push_finished(buf: Buffer, finished: Finished)
at: aioquic.tls.Context
_push_message(buf: Buffer)
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)
===========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,
],
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,
],
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 1===========
# module: aioquic.tls
class Context:
def _client_handle_finished(self, input_buf, output_buf):
finished = pull_finished(input_buf)
# check verify data
+ expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
- expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
assert finished.verify_data == expected_verify_data
self.key_schedule.update_hash(input_buf.data)
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.DECRYPT, Epoch.ONE_RTT, b's ap traffic')
next_enc_key = self.key_schedule.derive_secret(b'c ap traffic')
# send finished
push_finished(output_buf, Finished(
+ verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
- verify_data=self.key_schedule.finished_verify_data(self.enc_key)))
# commit traffic key
+ self._enc_key = next_enc_key
- self.enc_key = next_enc_key
+ self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self._enc_key)
- self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self.enc_key)
self._set_state(State.CLIENT_POST_HANDSHAKE)
===========changed ref 2===========
# module: aioquic.tls
class Context:
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.enc_key = None
+ self._dec_key = None
- self.dec_key = None
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
- self.is_client = is_client
-
===========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
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 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
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):
push_encrypted_extensions(output_buf, EncryptedExtensions(
other_extensions</s>
|
aioquic.tls/Context._setup_traffic_protection
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<3>:<add> self._enc_key = key
<del> self.enc_key = key
<5>:<add> self._dec_key = key
<del> self.dec_key = key
|
# module: aioquic.tls
class Context:
def _setup_traffic_protection(self, direction, epoch, label):
<0> key = self.key_schedule.derive_secret(label)
<1>
<2> if direction == Direction.ENCRYPT:
<3> self.enc_key = key
<4> else:
<5> self.dec_key = key
<6>
<7> self.update_traffic_key_cb(direction, epoch, key)
<8>
|
===========unchanged ref 0===========
at: aioquic.tls
Direction()
Epoch()
State()
at: aioquic.tls.Context
_set_state(state)
at: aioquic.tls.Context.__init__
self.update_traffic_key_cb = lambda d, e, s: None
self._dec_key = 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)
self._next_dec_key = self.key_schedule.derive_secret(b'c ap traffic')
at: aioquic.tls.Context._setup_traffic_protection
self._dec_key = key
at: aioquic.tls.KeyScheduleProxy
update_hash(data)
at: contextlib
contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]
===========changed ref 0===========
# module: aioquic.tls
class Context:
def _server_handle_finished(self, input_buf):
finished = pull_finished(input_buf)
# check verify data
+ expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
- expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
assert finished.verify_data == expected_verify_data
# commit traffic key
+ self._dec_key = self._next_dec_key
- self.dec_key = self._next_dec_key
self._next_dec_key = None
+ self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self._dec_key)
- self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self.dec_key)
self.key_schedule.update_hash(input_buf.data)
self._set_state(State.SERVER_POST_HANDSHAKE)
===========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,
],
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,
],
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
class Context:
def _client_handle_finished(self, input_buf, output_buf):
finished = pull_finished(input_buf)
# check verify data
+ expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
- expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
assert finished.verify_data == expected_verify_data
self.key_schedule.update_hash(input_buf.data)
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.DECRYPT, Epoch.ONE_RTT, b's ap traffic')
next_enc_key = self.key_schedule.derive_secret(b'c ap traffic')
# send finished
push_finished(output_buf, Finished(
+ verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
- verify_data=self.key_schedule.finished_verify_data(self.enc_key)))
# commit traffic key
+ self._enc_key = next_enc_key
- self.enc_key = next_enc_key
+ self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self._enc_key)
- self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self.enc_key)
self._set_state(State.CLIENT_POST_HANDSHAKE)
===========changed ref 3===========
# module: aioquic.tls
class Context:
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.enc_key = None
+ self._dec_key = None
- self.dec_key = None
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
- self.is_client = is_client
-
===========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
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)
|
tests.test_tls/ContextTest.test_handshake
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
<35>:<add> self.assertEqual(client._dec_key, server._enc_key)
<del> self.assertEqual(client.dec_key, server.enc_key)
<36>:<add> self.assertEqual(client._enc_key, server._dec_key)
<del> self.assertEqual(client.enc_key, server.dec_key)
|
# 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 _setup_traffic_protection(self, direction, epoch, label):
key = self.key_schedule.derive_secret(label)
if direction == Direction.ENCRYPT:
+ self._enc_key = key
- self.enc_key = key
else:
+ self._dec_key = key
- self.dec_key = key
self.update_traffic_key_cb(direction, epoch, key)
===========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
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 Context:
def _server_handle_finished(self, input_buf):
finished = pull_finished(input_buf)
# check verify data
+ expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
- expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
assert finished.verify_data == expected_verify_data
# commit traffic key
+ self._dec_key = self._next_dec_key
- self.dec_key = self._next_dec_key
self._next_dec_key = None
+ self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self._dec_key)
- self.update_traffic_key_cb(Direction.DECRYPT, Epoch.ONE_RTT, self.dec_key)
self.key_schedule.update_hash(input_buf.data)
self._set_state(State.SERVER_POST_HANDSHAKE)
===========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,
],
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,
],
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 4===========
# module: aioquic.tls
class Context:
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.enc_key = None
+ self._dec_key = None
- self.dec_key = None
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
- self.is_client = is_client
-
===========changed ref 5===========
# module: aioquic.tls
class Context:
def _client_handle_finished(self, input_buf, output_buf):
finished = pull_finished(input_buf)
# check verify data
+ expected_verify_data = self.key_schedule.finished_verify_data(self._dec_key)
- expected_verify_data = self.key_schedule.finished_verify_data(self.dec_key)
assert finished.verify_data == expected_verify_data
self.key_schedule.update_hash(input_buf.data)
# prepare traffic keys
assert self.key_schedule.generation == 2
self.key_schedule.extract(None)
self._setup_traffic_protection(Direction.DECRYPT, Epoch.ONE_RTT, b's ap traffic')
next_enc_key = self.key_schedule.derive_secret(b'c ap traffic')
# send finished
push_finished(output_buf, Finished(
+ verify_data=self.key_schedule.finished_verify_data(self._enc_key)))
- verify_data=self.key_schedule.finished_verify_data(self.enc_key)))
# commit traffic key
+ self._enc_key = next_enc_key
- self.enc_key = next_enc_key
+ self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self._enc_key)
- self.update_traffic_key_cb(Direction.ENCRYPT, Epoch.ONE_RTT, self.enc_key)
self._set_state(State.CLIENT_POST_HANDSHAKE)
|
tests.test_tls/TlsTest.test_pull_client_hello
|
Modified
|
aiortc~aioquic
|
186d97a5d603f794b10794e66f5103bfa9961c44
|
[tls] add support for Server Name Indication extension
|
# 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.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
key_exchange_modes: List[int] = None
key_share: List[Tuple[int, bytes]] = None
server_name: str = None
===========unchanged ref 1===========
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
assertEqual(first: Any, second: Any, msg: Any=...) -> None
assertTrue(expr: Any, msg: Any=...) -> None
===========changed ref 0===========
# 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')
else:
hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
</s>
===========changed ref 1===========
# module: aioquic.tls
def pull_client_hello(buf: Buffer):
# offset: 1
<s> hello.other_extensions.append(
(extension_type, pull_bytes(buf, extension_length)),
)
pull_list(buf, 2, pull_extension)
return hello
|
|
aioquic.connection/QuicConnection.__init__
|
Modified
|
aiortc~aioquic
|
0eac19b31d9a074881d0fc18d0239c4174c27b25
|
[examples] pass server name to enable SNI extension
|
<11>:<add> self.server_name = server_name
|
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- 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>
<12> # protocol versions
<13> self.version = PROTOCOL_VERSION_DRAFT_18
<14> self.supported_versions = [PROTOCOL_VERSION_DRAFT_17, PROTOCOL_VERSION_DRAFT_18]
<15>
<16> self.quic_transport_parameters = QuicTransportParameters(
<17> idle_timeout=600,
<18> initial_max_data=16777216,
<19> initial_max_stream_data_bidi_local=1048576,
<20> initial_max_stream_data_bidi_remote=1048576,
<21> initial_max_stream_data_uni=1048576,
<22> initial_max_streams_bidi=100,
<23> ack_delay_exponent=10,
<24> )
<25>
<26> self.send_ack = {
<27> tls.Epoch.INITIAL: False,
<28> tls.Epoch.HANDSHAKE: False,
<29> tls.Epoch.ONE_RTT: False,
<30> }
<31> self.send_buffer = {
<32> tls.Epoch.INITIAL: Buffer(capacity=4096),
<33> tls.Epoch.HANDSHAKE: Buffer(capacity=4096),
<34> </s>
|
===========below chunk 0===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- 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
PacketSpace()
at: aioquic.connection.QuicConnection.datagram_received
self.version = max(common)
self.peer_cid = header.source_cid
self.peer_cid_set = True
at: aioquic.packet
PROTOCOL_VERSION_DRAFT_17 = 0xff000011
PROTOCOL_VERSION_DRAFT_18 = 0xff000012
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
===========unchanged ref 1===========
ack_delay_exponent: int = None
max_ack_delay: int = None
disable_migration: bool = False
preferred_address: bytes = None
at: aioquic.stream
QuicStream()
at: aioquic.tls
Epoch()
Buffer(capacity=None, data=None)
at: os
urandom(size: int, /) -> bytes
|
aioquic.connection/QuicConnection._init_tls
|
Modified
|
aiortc~aioquic
|
0eac19b31d9a074881d0fc18d0239c4174c27b25
|
[examples] pass server name to enable SNI extension
|
<13>:<add> self.tls.server_name = self.server_name
|
# 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.update_traffic_key_cb = self._update_traffic_key
<14>
|
===========unchanged ref 0===========
at: aioquic.connection.QuicConnection
_serialize_parameters()
_write_application()
at: aioquic.connection.QuicConnection.__init__
self.certificate = certificate
self.is_client = is_client
self.private_key = private_key
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.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)
stateless_reset_token: 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 = []
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- 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 = 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_RTT: Buffer(capacity=4096),
}
self</s>
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
+ server_name=None):
# offset: 1
<s>=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
|
examples.cli/QuicProtocol.__init__
|
Modified
|
aiortc~aioquic
|
0eac19b31d9a074881d0fc18d0239c4174c27b25
|
[examples] pass server name to enable SNI extension
|
<0>:<add> self._connection = QuicConnection(secrets_log_file=secrets_log_file,
<del> self._connection = QuicConnection(secrets_log_file=secrets_log_file)
<1>:<add> server_name=server_name)
|
# module: examples.cli
class QuicProtocol(asyncio.DatagramProtocol):
+ def __init__(self, secrets_log_file, server_name):
- def __init__(self, secrets_log_file):
<0> self._connection = QuicConnection(secrets_log_file=secrets_log_file)
<1> self._transport = None
<2>
|
===========unchanged ref 0===========
at: aioquic.connection
QuicConnection(is_client=True, certificate=None, private_key=None, secrets_log_file=None, server_name=None)
at: asyncio.protocols
DatagramProtocol()
===========changed ref 0===========
# module: aioquic.connection
class QuicConnection:
def _init_tls(self):
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 1===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- 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 = 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_RTT: Buffer(capacity=4096),
}
self</s>
===========changed ref 2===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
+ server_name=None):
# offset: 1
<s>=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
|
examples.cli/run
|
Modified
|
aiortc~aioquic
|
0eac19b31d9a074881d0fc18d0239c4174c27b25
|
[examples] pass server name to enable SNI extension
|
<0>:<add> # if host is not an IP address, pass it to enable SNI
<add> try:
<add> ipaddress.ip_address(host)
<add> server_name = None
<add> except ValueError:
<add> server_name = host
<add>
<1>:<add> lambda: QuicProtocol(secrets_log_file=secrets_log_file, server_name=server_name),
<del> lambda: QuicProtocol(secrets_log_file=secrets_log_file),
<2>:<add> remote_addr=(host, port))
<del> remote_addr=(address, port))
|
# module: examples.cli
+ def run(host, port, secrets_log_file):
- def run(address, port, secrets_log_file):
<0> _, protocol = await loop.create_datagram_endpoint(
<1> lambda: QuicProtocol(secrets_log_file=secrets_log_file),
<2> remote_addr=(address, port))
<3>
<4> await asyncio.sleep(10)
<5>
|
===========unchanged ref 0===========
at: ipaddress
ip_address(address: object) -> Any
===========changed ref 0===========
# module: examples.cli
class QuicProtocol(asyncio.DatagramProtocol):
+ def __init__(self, secrets_log_file, server_name):
- def __init__(self, secrets_log_file):
+ self._connection = QuicConnection(secrets_log_file=secrets_log_file,
- self._connection = QuicConnection(secrets_log_file=secrets_log_file)
+ server_name=server_name)
self._transport = None
===========changed ref 1===========
# module: aioquic.connection
class QuicConnection:
def _init_tls(self):
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 __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- 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 = 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_RTT: Buffer(capacity=4096),
}
self</s>
===========changed ref 3===========
# module: aioquic.connection
class QuicConnection:
+ def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None,
- def __init__(self, is_client=True, certificate=None, private_key=None, secrets_log_file=None):
+ server_name=None):
# offset: 1
<s>=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
|
aioquic.stream/QuicStream.add_frame
|
Modified
|
aiortc~aioquic
|
6c9390c2759cf7dd81ce5252f4aa8f40265490df
|
[stream] deal with duplicate data
|
<0>:<add> pos = frame.offset - self._start
<del> assert frame.offset >= self._start
<1>:<add> count = len(frame.data)
<add>
<add> # frame has been entirely consumed
<add> if pos + count <= 0:
<add> return
<add>
<add> # frame has been partially consumed
<add> if pos < 0:
<add> count += pos
<add> frame.data = frame.data[-pos:]
<add> frame.offset -= pos
<add> pos = 0
<3>:<del> count = len(frame.data)
<7>:<del> pos = frame.offset - self._start
|
# module: aioquic.stream
class QuicStream:
def add_frame(self, frame: QuicStreamFrame):
<0> assert frame.offset >= self._start
<1>
<2> # marked received
<3> count = len(frame.data)
<4> self._received.add(frame.offset, frame.offset + count)
<5>
<6> # add data
<7> pos = frame.offset - self._start
<8> gap = pos - len(self._buffer)
<9> if gap > 0:
<10> self._buffer += bytearray(gap)
<11> self._buffer[pos:pos + count] = frame.data
<12>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicStreamFrame(data: bytes=b'', offset: int=0)
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream.__init__
self._start = 0
at: aioquic.stream.QuicStream.pull_data
self._start = r.stop
|
aioquic.stream/QuicStream.__init__
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<0>:<add> self._recv_buffer = bytearray()
<del> self._buffer = bytearray()
<1>:<del> self._received = RangeSet()
<2>:<add> self._recv_start = 0
<del> self._start = 0
<3>:<add> self._recv_ranges = RangeSet()
|
# module: aioquic.stream
class QuicStream:
+ def __init__(self, stream_id=None):
- def __init__(self):
<0> self._buffer = bytearray()
<1> self._received = RangeSet()
<2> self._start = 0
<3>
|
===========unchanged ref 0===========
at: aioquic.rangeset
RangeSet(ranges: Iterable[range]=[])
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
===========changed ref 0===========
# 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)
+
|
aioquic.stream/QuicStream.add_frame
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<0>:<add> """
<add> Add a frame of received data.
<add> """
<add> pos = frame.offset - self._recv_start
<del> pos = frame.offset - self._start
<15>:<add> self._recv_ranges.add(frame.offset, frame.offset + count)
<del> self._received.add(frame.offset, frame.offset + count)
<18>:<add> gap = pos - len(self._recv_buffer)
<del> gap = pos - len(self._buffer)
<20>:<add> self._recv_buffer += bytearray(gap)
<del> self._buffer += bytearray(gap)
<21>:<add> self._recv_buffer[pos:pos + count] = frame.data
<del> self._buffer[pos:pos + count] = frame.data
|
# module: aioquic.stream
class QuicStream:
def add_frame(self, frame: QuicStreamFrame):
<0> pos = frame.offset - self._start
<1> count = len(frame.data)
<2>
<3> # frame has been entirely consumed
<4> if pos + count <= 0:
<5> return
<6>
<7> # frame has been partially consumed
<8> if pos < 0:
<9> count += pos
<10> frame.data = frame.data[-pos:]
<11> frame.offset -= pos
<12> pos = 0
<13>
<14> # marked received
<15> self._received.add(frame.offset, frame.offset + count)
<16>
<17> # add data
<18> gap = pos - len(self._buffer)
<19> if gap > 0:
<20> self._buffer += bytearray(gap)
<21> self._buffer[pos:pos + count] = frame.data
<22>
|
===========unchanged ref 0===========
at: aioquic.packet
QuicStreamFrame(data: bytes=b'', offset: int=0)
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.stream.QuicStream.__init__
self._recv_start = 0
at: aioquic.stream.QuicStream.get_frame
self._send_buffer = self._send_buffer[size:]
self._send_start += size
at: aioquic.stream.QuicStream.pull_data
self._recv_start = r.stop
at: aioquic.stream.QuicStream.push_data
self._send_buffer += data
===========changed ref 0===========
# 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 1===========
# 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)
+
|
aioquic.stream/QuicStream.pull_data
|
Modified
|
aiortc~aioquic
|
e46ddb4ba3056a36e019f5d54d9d6b4325e7f20c
|
[stream] start adding send API
|
<0>:<add> """
<add> Pull received data.
<add> """
<1>:<add> if not self._recv_ranges or self._recv_ranges[0].start != self._recv_start:
<del> if not self._received or self._received[0].start != self._start:
<4>:<add> r = self._recv_ranges.shift()
<del> r = self._received.shift()
<6>:<add> data = self._recv_buffer[:pos]
<del> data = self._buffer[:pos]
<7>:<add> self._recv_buffer = self._recv_buffer[pos:]
<del> self._buffer = self._buffer[pos:]
<8>:<add> self._recv_start = r.stop
<del> self._start = r.stop
|
# module: aioquic.stream
class QuicStream:
def pull_data(self):
<0> # no data, or gap at start
<1> if not self._received or self._received[0].start != self._start:
<2> return b''
<3>
<4> r = self._received.shift()
<5> pos = r.stop - r.start
<6> data = self._buffer[:pos]
<7> self._buffer = self._buffer[pos:]
<8> self._start = r.stop
<9> return data
<10>
|
===========unchanged ref 0===========
at: aioquic.packet.QuicStreamFrame
data: bytes = b''
offset: int = 0
at: aioquic.rangeset.RangeSet
add(start: int, stop: Optional[int]=None)
at: aioquic.stream.QuicStream.__init__
self._recv_buffer = bytearray()
self._recv_ranges = RangeSet()
at: aioquic.stream.QuicStream.add_frame
count += pos
count = len(frame.data)
at: aioquic.stream.QuicStream.pull_data
self._recv_buffer = self._recv_buffer[pos:]
===========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 __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 2===========
# 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 3===========
# 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)
+
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.