当前公司的产品越来越多的使用了密码+时间验证两种结合登陆的模式,浏览器登录虽然可以通过插件进行登录,但个人觉得不是很舒服,因此看到该文章时,感觉非常的nice,故记录一番。
macOS下的Automator可以直接增加鼠标右键的功能,因此我们可以采取该方案,进行处理。
1、编写一段我们的python脚本
cat /Users/coco/util/ga.py
#!/usr/bin/python
import hmac, base64, struct, hashlib, time
secretKey = '私钥'
def cal_google_code(secret_key):
input = int(time.time())//30
key = base64.b32decode(secret_key) # length of the key must be a multiplier of eight
msg = struct.pack(">Q", input)
google_code = hmac.new(key, msg, hashlib.sha1).digest()
try:
o = google_code[19] & 15
except:
o = ord(google_code[19]) & 15
google_code = str((struct.unpack(">I", google_code[o:o+4])[0] & 0x7fffffff) % 1000000)
if len(google_code) == 5:
google_code = '0' + google_code
if len(google_code) == 4:
google_code = '00' + google_code
return google_code
print(cal_google_code(secretKey))
2、打开自动操作
2.1、快捷键 command+空格,输入Automator,
2.2、选择 自动操作(Automator)
2.3、选择 快速操作(Quick Action)
2.4、找到 运行shell脚本(Run Shell Script),拖拽到右边
2.5、工作流程收到(Workflow receives)设置为 没有输入(no input)
2.6、位于(in) 设置为 任何应用程序(any application)
2.7、打勾 用输入内容替换所选文本 (Output replaces selected text)
2.8、加入自己的代码路径
2.9、command+s ,保存名称为 jumpserver(可以保存为自己喜欢的名字)
PS:发现适合使用在chrome,但不适合使用safari。
https://github.com/pyauth/pyotp
https://zhuanlan.zhihu.com/p/391925970