Skip to content

Commit 80fc81e

Browse files
committed
Allow --list argument to KEYINFO
Sequoia Chameleon sends "KEYINFO --list", so do not filter this out.
1 parent 82fc505 commit 80fc81e

1 file changed

Lines changed: 20 additions & 20 deletions

File tree

splitgpg2/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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:
@@ -731,21 +741,11 @@ async def command_HAVEKEY(self, untrusted_args: Optional[bytes]) -> None:
731741
if untrusted_args is None:
732742
raise Filtered
733743
# upper keygrip limit is arbitary
734-
if untrusted_args.startswith(b'--list'):
735-
if b'=' in untrusted_args:
736-
# 1000 is the default value used by gpg2
737-
limit = sanitize_int(untrusted_args[len(b'--list='):], 1, 1000)
738-
args = b'--list=%d' % limit
739-
else:
740-
if untrusted_args != b'--list':
741-
raise Filtered
742-
args = b'--list'
743-
else:
744-
args = self.verify_keygrip_arguments(1, 200, untrusted_args)
744+
args = self.verify_keygrip_arguments(1, 200, untrusted_args, True)
745745
await self.send_agent_command(b'HAVEKEY', args)
746746

747747
async def command_KEYINFO(self, untrusted_args: Optional[bytes]) -> None:
748-
args = self.verify_keygrip_arguments(1, 1, untrusted_args)
748+
args = self.verify_keygrip_arguments(1, 1, untrusted_args, True)
749749
await self.send_agent_command(b'KEYINFO', args)
750750

751751
async def command_GENKEY(self, untrusted_args: Optional[bytes]) -> None:
@@ -785,12 +785,12 @@ async def command_GENKEY(self, untrusted_args: Optional[bytes]) -> None:
785785
await self.send_agent_command(b'GENKEY', b' '.join(args))
786786

787787
async def command_SIGKEY(self, untrusted_args: Optional[bytes]) -> None:
788-
args = self.verify_keygrip_arguments(1, 1, untrusted_args)
788+
args = self.verify_keygrip_arguments(1, 1, untrusted_args, False)
789789
await self.send_agent_command(b'SIGKEY', args)
790790
await self.setkeydesc(args)
791791

792792
async def command_SETKEY(self, untrusted_args: Optional[bytes]) -> None:
793-
args = self.verify_keygrip_arguments(1, 1, untrusted_args)
793+
args = self.verify_keygrip_arguments(1, 1, untrusted_args, False)
794794
await self.send_agent_command(b'SETKEY', args)
795795
await self.setkeydesc(args)
796796

@@ -996,7 +996,7 @@ async def command_READKEY(self, untrusted_args: Optional[bytes]) -> None:
996996
raise Filtered
997997
if untrusted_args.startswith(b'-- '):
998998
untrusted_args = untrusted_args[3:]
999-
args = self.verify_keygrip_arguments(1, 1, untrusted_args)
999+
args = self.verify_keygrip_arguments(1, 1, untrusted_args, False)
10001000

10011001
await self.send_agent_command(b'READKEY', b'-- ' + args)
10021002

0 commit comments

Comments
 (0)