@@ -271,6 +271,7 @@ def __init__(self, client: Client, channel: abc.Connectable):
271
271
"xsalsa20_poly1305_lite" ,
272
272
"xsalsa20_poly1305_suffix" ,
273
273
"xsalsa20_poly1305" ,
274
+ "aead_xchacha20_poly1305_rtpsize" ,
274
275
)
275
276
276
277
@property
@@ -564,19 +565,22 @@ def _get_voice_packet(self, data):
564
565
return encrypt_packet (header , data )
565
566
566
567
def _encrypt_xsalsa20_poly1305 (self , header : bytes , data ) -> bytes :
568
+ # Deprecated, remove in 2.7
567
569
box = nacl .secret .SecretBox (bytes (self .secret_key ))
568
570
nonce = bytearray (24 )
569
571
nonce [:12 ] = header
570
572
571
573
return header + box .encrypt (bytes (data ), bytes (nonce )).ciphertext
572
574
573
575
def _encrypt_xsalsa20_poly1305_suffix (self , header : bytes , data ) -> bytes :
576
+ # Deprecated, remove in 2.7
574
577
box = nacl .secret .SecretBox (bytes (self .secret_key ))
575
578
nonce = nacl .utils .random (nacl .secret .SecretBox .NONCE_SIZE )
576
579
577
580
return header + box .encrypt (bytes (data ), nonce ).ciphertext + nonce
578
581
579
582
def _encrypt_xsalsa20_poly1305_lite (self , header : bytes , data ) -> bytes :
583
+ # Deprecated, remove in 2.7
580
584
box = nacl .secret .SecretBox (bytes (self .secret_key ))
581
585
nonce = bytearray (24 )
582
586
@@ -585,7 +589,22 @@ def _encrypt_xsalsa20_poly1305_lite(self, header: bytes, data) -> bytes:
585
589
586
590
return header + box .encrypt (bytes (data ), bytes (nonce )).ciphertext + nonce [:4 ]
587
591
592
+ def _encrypt_aead_xchacha20_poly1305_rtpsize (self , header : bytes , data ) -> bytes :
593
+ # Required as of Nov 18 2024
594
+ box = nacl .secret .Aead (bytes (self .secret_key ))
595
+ nonce = bytearray (24 )
596
+
597
+ nonce [:4 ] = struct .pack (">I" , self ._lite_nonce )
598
+ self .checked_add ("_lite_nonce" , 1 , 4294967295 )
599
+
600
+ return (
601
+ header
602
+ + box .encrypt (bytes (data ), bytes (header ), bytes (nonce )).ciphertext
603
+ + nonce [:4 ]
604
+ )
605
+
588
606
def _decrypt_xsalsa20_poly1305 (self , header , data ):
607
+ # Deprecated, remove in 2.7
589
608
box = nacl .secret .SecretBox (bytes (self .secret_key ))
590
609
591
610
nonce = bytearray (24 )
@@ -594,6 +613,7 @@ def _decrypt_xsalsa20_poly1305(self, header, data):
594
613
return self .strip_header_ext (box .decrypt (bytes (data ), bytes (nonce )))
595
614
596
615
def _decrypt_xsalsa20_poly1305_suffix (self , header , data ):
616
+ # Deprecated, remove in 2.7
597
617
box = nacl .secret .SecretBox (bytes (self .secret_key ))
598
618
599
619
nonce_size = nacl .secret .SecretBox .NONCE_SIZE
@@ -602,6 +622,7 @@ def _decrypt_xsalsa20_poly1305_suffix(self, header, data):
602
622
return self .strip_header_ext (box .decrypt (bytes (data [:- nonce_size ]), nonce ))
603
623
604
624
def _decrypt_xsalsa20_poly1305_lite (self , header , data ):
625
+ # Deprecated, remove in 2.7
605
626
box = nacl .secret .SecretBox (bytes (self .secret_key ))
606
627
607
628
nonce = bytearray (24 )
@@ -610,6 +631,18 @@ def _decrypt_xsalsa20_poly1305_lite(self, header, data):
610
631
611
632
return self .strip_header_ext (box .decrypt (bytes (data ), bytes (nonce )))
612
633
634
+ def _decrypt_aead_xchacha20_poly1305_rtpsize (self , header , data ):
635
+ # Required as of Nov 18 2024
636
+ box = nacl .secret .Aead (bytes (self .secret_key ))
637
+
638
+ nonce = bytearray (24 )
639
+ nonce [:4 ] = data [- 4 :]
640
+ data = data [:- 4 ]
641
+
642
+ return self .strip_header_ext (
643
+ box .decrypt (bytes (data ), bytes (header ), bytes (nonce ))
644
+ )
645
+
613
646
@staticmethod
614
647
def strip_header_ext (data ):
615
648
if len (data ) > 4 and data [0 ] == 0xBE and data [1 ] == 0xDE :
@@ -724,11 +757,12 @@ def unpack_audio(self, data):
724
757
data: :class:`bytes`
725
758
Bytes received by Discord via the UDP connection used for sending and receiving voice data.
726
759
"""
727
- if 200 <= data [1 ] <= 204 :
728
- # RTCP received.
729
- # RTCP provides information about the connection
730
- # as opposed to actual audio data, so it's not
731
- # important at the moment.
760
+ if data [1 ] != 0x78 :
761
+ # We Should Ignore Any Payload Types We Do Not Understand
762
+ # Ref RFC 3550 5.1 payload type
763
+ # At Some Point We Noted That We Should Ignore Only Types 200 - 204 inclusive.
764
+ # They Were Marked As RTCP: Provides Information About The Connection
765
+ # This Was Too Broad Of A Whitelist, It Is Unclear If This Is Too Narrow Of A Whitelist
732
766
return
733
767
if self .paused :
734
768
return
0 commit comments