From 38e30f71cec282346de0494490382441ede57c9e Mon Sep 17 00:00:00 2001 From: Joe Cooter Date: Thu, 22 Jun 2017 00:26:53 -0400 Subject: [PATCH 1/2] Add support for setting an explicit TOTP secret This is a total shot in the dark, I basically guessed how errbot uses the args variable. --- otp.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/otp.py b/otp.py index d817ae0..35e96ea 100644 --- a/otp.py +++ b/otp.py @@ -92,15 +92,21 @@ def otp_cmds(self, msg, args): @botcmd(admin_only=True) def otp_secret(self, msg, args): """Send a new secret to somebody""" - new_secret = pyotp.random_base32() + if len(args) > 1: + new_secret = args[1] + target_user = args[0] + else: + new_secret = pyotp.random_base32() + target_user = args + with self.lock: with self.stored('secrets') as secrets: - secrets[args] = (new_secret, 0, BEGINNING_OF_TIMES) + secrets[target_user] = (new_secret, 0, BEGINNING_OF_TIMES) totp = pyotp.TOTP(new_secret) - url = totp.provisioning_uri(args) - self.send(self.build_identifier(args), makeQRCodeMessage(url, self._bot.mode), None, 'chat') + url = totp.provisioning_uri(target_user) + self.send(self.build_identifier(target_user), makeQRCodeMessage(url, self._bot.mode), None, 'chat') - return "New secret set for %s and message sent." % args + return "New secret set for %s and message sent." % target_user @botcmd(admin_only=True) def otp_reset(self, msg, args): From 28fe8f496014cc88623d373c87eaa9cab3c7fc0e Mon Sep 17 00:00:00 2001 From: Joe Cooter Date: Thu, 22 Jun 2017 00:35:49 -0400 Subject: [PATCH 2/2] Adding decorator to split args My wild shot in the dark was a bit off --- otp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/otp.py b/otp.py index 35e96ea..2a235d2 100644 --- a/otp.py +++ b/otp.py @@ -89,7 +89,7 @@ def otp_cmds(self, msg, args): """List the current commands requiring OTPs.""" return "Commands with mandatory OTP:\n" + '\n'.join(self['cmds']) - @botcmd(admin_only=True) + @botcmd(admin_only=True, split_args_with=None) def otp_secret(self, msg, args): """Send a new secret to somebody""" if len(args) > 1: