谷歌验证 (Google Authenticator) 的实现原理是什么?

著作权归作者所有。
商业转载请联系作者获得授权,非商业转载请注明出处。
作者:徐小花
链接:http://www.zhihu.com/question/20462696/answer/18731073
来源:知乎

开启Google的登陆二步验证(即Google Authenticator服务)后用户登陆时需要输入额外由手机客户端生成的一次性密码。

实现Google Authenticator功能需要服务器端和客户端的支持。服务器端负责密钥的生成、验证一次性密码是否正确。客户端记录密钥后生成一次性密码。

目前客户端有:
android版: Google 身份验证器
iOS版:https://itunes.apple.com/cn/app/google-authenticator/id388497605

实现原理:

一、用户需要开启Google Authenticator服务时,
1.服务器随机生成一个类似于『DPI45HKISEXU6HG7』的密钥,并且把这个密钥保存在数据库中。
2.在页面上显示一个二维码,内容是一个URI地址(otpauth://totp/账号?secret=密钥),如『otpauth://totp/[email protected]?secret=DPI45HCEBCJK6HG7』,下图:
<img src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHBzL3BpYzEuemhpbWcuY29tL2QzN2QzMTFkOTQ2NGQ0YzI0YTM3ZTcwZDU0MTM2NGJjX2IuanBn.jpg" data-rawwidth="200" data-rawheight="200" class="content_image" width="200">
3.客户端扫描二维码,把密钥『DPI45HKISEXU6HG7』保存在客户端。

二、用户需要登陆时
1.客户端每30秒使用密钥『DPI45HKISEXU6HG7』和时间戳通过一种『算法』生成一个6位数字的一次性密码,如『684060』。如下图android版界面:
<img src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHBzL3BpYzEuemhpbWcuY29tL2MyMDU2MjYxYTBiMTA2YWYxOTUxNzY5Nzg4N2MwYjM4X2IuanBn.jpg" data-rawwidth="281" data-rawheight="398" class="content_image" width="281">
2.用户登陆时输入一次性密码『684060』。
3.服务器端使用保存在数据库中的密钥『DPI45HKISEXU6HG7』和时间戳通过同一种『算法』生成一个6位数字的一次性密码。大家都懂控制变量法,如果算法相同、密钥相同,又是同一个时间(时间戳相同),那么客户端和服务器计算出的一次性密码是一样的。服务器验证时如果一样,就登录成功了。

Tips:
1.这种『算法』是公开的,所以服务器端也有很多开源的实现,比如php版的:https://github.com/PHPGangsta/GoogleAuthenticator 。上github搜索『Google Authenticator』可以找到更多语言版的Google Authenticator。
2.所以,你在自己的项目可以轻松加入对Google Authenticator的支持,在一个客户端上显示多个账户的效果可以看上面android版界面的截图。目前dropbox、lastpass、wordpress,甚至vps等第三方应用都支持Google Authenticator登陆,请自行搜索。
3.现实生活中,网银、网络游戏的实体动态口令牌其实原理也差不多,大家可以自行脑补下,谢谢。
<img src="//pic.ikafan.com/imgp/L3Byb3h5L2h0dHBzL3BpYzIuemhpbWcuY29tL2ZjMDYxN2JhNmIyMDYyYmVjNjhjODdlYjQ4MWQyNWMxX2IuanBn.jpg" data-rawwidth="302" data-rawheight="144" class="content_image" width="302">

时间: 2024-08-04 09:50:55

谷歌验证 (Google Authenticator) 的实现原理是什么?的相关文章

java实现谷歌二步验证 (Google Authenticator)

准备: 一个谷歌二步验证APP,  我用的是ios 身份宝 资料: 1.Google Authenticator 原理及Java实现   //主要参考 https://blog.csdn.net/lizhengjava/article/details/76947962# 2.谷歌验证 (Google Authenticator) 的实现原理是什么? https://www.zhihu.com/question/20462696 3.谷歌验证,又称两步验证, https://www.360shou

谷歌上google authenticator二次验证

参考: GA安装: https://www.cnblogs.com/hanyifeng/p/kevin4real.html https://shenyu.me/2016/09/05/centos-google-authenticator.html https://www.howtoing.com/secure-ssh-with-google-authenticator-on-centos-7 原理: https://en.wikipedia.org/wiki/Google_Authenticat

Google authenticator 登陆 Wordpress和 Gmail账号

这段时间在学习aws,发现可以通过配置google authenticator来强化登陆的安全性.心想能不能把Google authenticator用在其他地方呢?意外的发现wordpess和Gmail Account也是支持的. WordPress配置很简单,首先安装Plugin,激活 然后在管理员的Profile下面,生成二维码 iPhone上安装对应的软件,(左下角白***标),扫描二维码,即可绑定 保存Wordpress的设置,重新进入登录界面,发现多了个验证码的选项 下面我的截图里面

Google authenticator 谷歌身份验证,实现动态口令

google authenticator php 服务端 使用PHP类 require_once '../PHPGangsta/GoogleAuthenticator.php'; $ga = new PHPGangsta_GoogleAuthenticator(); //创建一个新的"安全密匙SecretKey" //把本次的"安全密匙SecretKey" 入库,和账户关系绑定,客户端也是绑定这同一个"安全密匙SecretKey" $secret

google authenticator 谷歌身份验证器

How to add extra security to your MVC web application, using two factor authentication. Download source code - 2.8 MB What is Two Factor Authentication? Two Factor Authentication is a way to authenticate users using two of the three valid authenticat

Google Authenticator TOTP原理详解(以Python为例)

小生博客:http://xsboke.blog.51cto.com 如果有疑问,请点击此处,然后发表评论交流,作者会及时回复(也可以直接在当前文章评论). -------谢谢您的参考,如有疑问,欢迎交流 一. 原理详解(图片可以点击然后放大查看) 二. 验证1.下载Google谷歌身份验证器.2.通过Python 的qrcode和pyotp模块生成二维码. 3.然后使用下载的谷歌身份验证器扫描生成的二维码 如果没有谷歌服务,则选择输入秘钥,在账户明处填入name参数,在秘钥处填入Secret即可

Google Authenticator SSH双重验证技术

    Technology - Site OPS Google Authenticator SSH双重验证技术 管理手册 目  录 第1章引言... 1 1.1 目的... 1 1.2 说明... 1 第2章 SSH 双重验证实现... 2 2.1 基础工作... 2 2.2 配置工作... 2 第3章手机客户端配置... 4 第4章 SSH 登录验证... 6 4.1XSHELL 登录验证... 6 4.2 跳板机登录... 7 4.3 总结... 8 第1章 引言 1.1 目的 SSH 安

SSH使用Google Authenticator二次验证

基本的原理如上图: 客户端在输入code码之后,才可以输入服务器的密码,进行账户验证,方可进入服务器. 实现方式如下: 1. 安装所需组件 # yum -y install mercurial pam-devel 2.  安装qrencode,在Linux上,有一个名为 QrenCode 的命令行工具可以很容易帮我们生成二维码,google authenticator命令行生成二维码就是调用它. # wgethttp://fukuchi.org/works/qrencode/qrencode-3

使用Google Authenticator给ssh进行登录验证

普通情况下的服务器登录,是"服务器+密码"这种直白的验证方式,但是这种方式太过简单,一旦密码泄露,服务器就有危险,于是为了安全我们就要在登录上再加一把锁,那就是使用Google Authenticator(谷歌身份验证器)这个工具,在登录的时候进行一次验证,只有"验证通过了"+"密码正确"才能登陆服务器. 安装前准备: 1)关闭Selinux :#setenforce 0 2)安装依赖:#yum -y install gcc make pam-d