@@ -710,10 +710,14 @@ def RequestPacket(self):
710
710
return header + attr
711
711
712
712
def PwDecrypt (self , password ):
713
- """Obfuscate a RADIUS password. RADIUS hides passwords in packets by
713
+ """De- Obfuscate a RADIUS password. RADIUS hides passwords in packets by
714
714
using an algorithm based on the MD5 hash of the packet authenticator
715
715
and RADIUS secret. This function reverses the obfuscation process.
716
716
717
+ Although RFC2865 does not explicitly state UTF-8 for the password field,
718
+ the rest of RFC2865 defines UTF-8 as the encoding expected for the decrypted password.
719
+
720
+
717
721
:param password: obfuscated form of password
718
722
:type password: binary string
719
723
:return: plaintext password
@@ -729,10 +733,16 @@ def PwDecrypt(self, password):
729
733
pw += bytes ((hash [i ] ^ buf [i ],))
730
734
(last , buf ) = (buf [:16 ], buf [16 :])
731
735
736
+ # This is safe even with UTF-8 encoding since no valid encoding of UTF-8
737
+ # (other than encoding U+0000 NULL) will produce a bytestream containing 0x00 byte.
732
738
while pw .endswith (b'\x00 ' ):
733
739
pw = pw [:- 1 ]
734
740
735
- return pw .decode ('utf-8' )
741
+ # If the shared secret with the client is not the same, then de-obfuscating the password
742
+ # field may yield illegal UTF-8 bytes. Therefore, in order not to provoke an Exception here
743
+ # (which would be not consistently generated since this will depend on the random data chosen
744
+ # by the client) we simply ignore un-parsable UTF-8 sequences.
745
+ return pw .decode ('utf-8' , errors = "ignore" )
736
746
737
747
def PwCrypt (self , password ):
738
748
"""Obfuscate password.
0 commit comments