@@ -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
@@ -576,19 +577,22 @@ def _get_voice_packet(self, data):
576
577
return encrypt_packet (header , data )
577
578
578
579
def _encrypt_xsalsa20_poly1305 (self , header : bytes , data ) -> bytes :
580
+ # Deprecated, remove in 2.7
579
581
box = nacl .secret .SecretBox (bytes (self .secret_key ))
580
582
nonce = bytearray (24 )
581
583
nonce [:12 ] = header
582
584
583
585
return header + box .encrypt (bytes (data ), bytes (nonce )).ciphertext
584
586
585
587
def _encrypt_xsalsa20_poly1305_suffix (self , header : bytes , data ) -> bytes :
588
+ # Deprecated, remove in 2.7
586
589
box = nacl .secret .SecretBox (bytes (self .secret_key ))
587
590
nonce = nacl .utils .random (nacl .secret .SecretBox .NONCE_SIZE )
588
591
589
592
return header + box .encrypt (bytes (data ), nonce ).ciphertext + nonce
590
593
591
594
def _encrypt_xsalsa20_poly1305_lite (self , header : bytes , data ) -> bytes :
595
+ # Deprecated, remove in 2.7
592
596
box = nacl .secret .SecretBox (bytes (self .secret_key ))
593
597
nonce = bytearray (24 )
594
598
@@ -597,7 +601,22 @@ def _encrypt_xsalsa20_poly1305_lite(self, header: bytes, data) -> bytes:
597
601
598
602
return header + box .encrypt (bytes (data ), bytes (nonce )).ciphertext + nonce [:4 ]
599
603
604
+ def _encrypt_aead_xchacha20_poly1305_rtpsize (self , header : bytes , data ) -> bytes :
605
+ # Required as of Nov 18 2024
606
+ box = nacl .secret .Aead (bytes (self .secret_key ))
607
+ nonce = bytearray (24 )
608
+
609
+ nonce [:4 ] = struct .pack (">I" , self ._lite_nonce )
610
+ self .checked_add ("_lite_nonce" , 1 , 4294967295 )
611
+
612
+ return (
613
+ header
614
+ + box .encrypt (bytes (data ), bytes (header ), bytes (nonce )).ciphertext
615
+ + nonce [:4 ]
616
+ )
617
+
600
618
def _decrypt_xsalsa20_poly1305 (self , header , data ):
619
+ # Deprecated, remove in 2.7
601
620
box = nacl .secret .SecretBox (bytes (self .secret_key ))
602
621
603
622
nonce = bytearray (24 )
@@ -606,6 +625,7 @@ def _decrypt_xsalsa20_poly1305(self, header, data):
606
625
return self .strip_header_ext (box .decrypt (bytes (data ), bytes (nonce )))
607
626
608
627
def _decrypt_xsalsa20_poly1305_suffix (self , header , data ):
628
+ # Deprecated, remove in 2.7
609
629
box = nacl .secret .SecretBox (bytes (self .secret_key ))
610
630
611
631
nonce_size = nacl .secret .SecretBox .NONCE_SIZE
@@ -614,6 +634,7 @@ def _decrypt_xsalsa20_poly1305_suffix(self, header, data):
614
634
return self .strip_header_ext (box .decrypt (bytes (data [:- nonce_size ]), nonce ))
615
635
616
636
def _decrypt_xsalsa20_poly1305_lite (self , header , data ):
637
+ # Deprecated, remove in 2.7
617
638
box = nacl .secret .SecretBox (bytes (self .secret_key ))
618
639
619
640
nonce = bytearray (24 )
@@ -622,6 +643,18 @@ def _decrypt_xsalsa20_poly1305_lite(self, header, data):
622
643
623
644
return self .strip_header_ext (box .decrypt (bytes (data ), bytes (nonce )))
624
645
646
+ def _decrypt_aead_xchacha20_poly1305_rtpsize (self , header , data ):
647
+ # Required as of Nov 18 2024
648
+ box = nacl .secret .Aead (bytes (self .secret_key ))
649
+
650
+ nonce = bytearray (24 )
651
+ nonce [:4 ] = data [- 4 :]
652
+ data = data [:- 4 ]
653
+
654
+ return self .strip_header_ext (
655
+ box .decrypt (bytes (data ), bytes (header ), bytes (nonce ))
656
+ )
657
+
625
658
@staticmethod
626
659
def strip_header_ext (data ):
627
660
if len (data ) > 4 and data [0 ] == 0xBE and data [1 ] == 0xDE :
@@ -740,11 +773,12 @@ def unpack_audio(self, data):
740
773
data: :class:`bytes`
741
774
Bytes received by Discord via the UDP connection used for sending and receiving voice data.
742
775
"""
743
- if 200 <= data [1 ] <= 204 :
744
- # RTCP received.
745
- # RTCP provides information about the connection
746
- # as opposed to actual audio data, so it's not
747
- # important at the moment.
776
+ if data [1 ] != 0x78 :
777
+ # We Should Ignore Any Payload Types We Do Not Understand
778
+ # Ref RFC 3550 5.1 payload type
779
+ # At Some Point We Noted That We Should Ignore Only Types 200 - 204 inclusive.
780
+ # They Were Marked As RTCP: Provides Information About The Connection
781
+ # This Was Too Broad Of A Whitelist, It Is Unclear If This Is Too Narrow Of A Whitelist
748
782
return
749
783
if self .paused :
750
784
return
0 commit comments