@@ -641,14 +641,24 @@ def fake_respond(self, response: bytes) -> None:
641641
642642 @staticmethod
643643 def verify_keygrip_arguments (min_count : int , max_count : int ,
644- untrusted_args : Optional [bytes ]) -> bytes :
644+ untrusted_args : Optional [bytes ],
645+ allow_list : bool ) -> bytes :
645646 if untrusted_args is None :
646647 raise Filtered
647- args_regex = re .compile (rb'\A[0-9A-F]{40}( [0-9A-F]{40}){%d,%d}\Z' %
648- (min_count - 1 , max_count - 1 ))
648+ if allow_list and untrusted_args .startswith (b'--list' ):
649+ if untrusted_args == b'--list' :
650+ pass
651+ elif untrusted_args [6 ] == 61 : # ASCII '='
652+ # 1000 is the default value used by gpg2
653+ sanitize_int (untrusted_args [len (b'--list=' ):], 1 , 1000 )
654+ else :
655+ raise Filtered
656+ else :
657+ args_regex = re .compile (rb'\A[0-9A-F]{40}( [0-9A-F]{40}){%d,%d}\Z' %
658+ (min_count - 1 , max_count - 1 ))
649659
650- if args_regex .match (untrusted_args ) is None :
651- raise Filtered
660+ if args_regex .match (untrusted_args ) is None :
661+ raise Filtered
652662 return untrusted_args
653663
654664 def sanitize_key_desc (self , untrusted_args : bytes ) -> bytes :
@@ -734,21 +744,11 @@ async def command_HAVEKEY(self, untrusted_args: Optional[bytes]) -> None:
734744 if untrusted_args is None :
735745 raise Filtered
736746 # upper keygrip limit is arbitary
737- if untrusted_args .startswith (b'--list' ):
738- if b'=' in untrusted_args :
739- # 1000 is the default value used by gpg2
740- limit = sanitize_int (untrusted_args [len (b'--list=' ):], 1 , 1000 )
741- args = b'--list=%d' % limit
742- else :
743- if untrusted_args != b'--list' :
744- raise Filtered
745- args = b'--list'
746- else :
747- args = self .verify_keygrip_arguments (1 , 200 , untrusted_args )
747+ args = self .verify_keygrip_arguments (1 , 200 , untrusted_args , True )
748748 await self .send_agent_command (b'HAVEKEY' , args )
749749
750750 async def command_KEYINFO (self , untrusted_args : Optional [bytes ]) -> None :
751- args = self .verify_keygrip_arguments (1 , 1 , untrusted_args )
751+ args = self .verify_keygrip_arguments (1 , 1 , untrusted_args , True )
752752 await self .send_agent_command (b'KEYINFO' , args )
753753
754754 async def command_GENKEY (self , untrusted_args : Optional [bytes ]) -> None :
@@ -788,12 +788,12 @@ async def command_GENKEY(self, untrusted_args: Optional[bytes]) -> None:
788788 await self .send_agent_command (b'GENKEY' , b' ' .join (args ))
789789
790790 async def command_SIGKEY (self , untrusted_args : Optional [bytes ]) -> None :
791- args = self .verify_keygrip_arguments (1 , 1 , untrusted_args )
791+ args = self .verify_keygrip_arguments (1 , 1 , untrusted_args , False )
792792 await self .send_agent_command (b'SIGKEY' , args )
793793 await self .setkeydesc (args )
794794
795795 async def command_SETKEY (self , untrusted_args : Optional [bytes ]) -> None :
796- args = self .verify_keygrip_arguments (1 , 1 , untrusted_args )
796+ args = self .verify_keygrip_arguments (1 , 1 , untrusted_args , False )
797797 await self .send_agent_command (b'SETKEY' , args )
798798 await self .setkeydesc (args )
799799
@@ -999,7 +999,7 @@ async def command_READKEY(self, untrusted_args: Optional[bytes]) -> None:
999999 raise Filtered
10001000 if untrusted_args .startswith (b'-- ' ):
10011001 untrusted_args = untrusted_args [3 :]
1002- args = self .verify_keygrip_arguments (1 , 1 , untrusted_args )
1002+ args = self .verify_keygrip_arguments (1 , 1 , untrusted_args , False )
10031003
10041004 await self .send_agent_command (b'READKEY' , b'-- ' + args )
10051005
0 commit comments