温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

基于Pam的Google双重验证实现

发布时间:2020-06-27 12:55:49 来源:网络 阅读:460 作者:My_good_science 栏目:开发技术

1、下载Google Authenticator源码

wget https://github.com/google/google-authenticator/tree/master/libpam

打开https://github.com/google/google-authenticator/blob/master/libpam/pam_google_authenticator.c,查找到pam_get_item(pamh, PAM_AUTHTOK, &password),修改PAM_AUTHTOK为PAM_AUTHTOK_TYPE

Build & install

./bootstrap.sh
./configure
make
sudo make install

拷贝pam_google_authenticator.so到/lib64/security下

Running

执行./google-authenticator

Your new secret key is: A3FY5V6TCAEUN4FX

Your verification code is 680297

Your emergency scratch codes are:

  75304045

  77554864

  18069864

  99313356

  32694105


2、下载Google身份验证器

通过手机,ipad等下载,打开身份验证器,在google身份验证器中输入用户名(一般使用邮件),秘钥则输入./google-authenticator结果中的secret key,选择基于时间候保存,就可以看到每30s生成一个6位数的随机数。


3、下载JPam

官网:http://jpam.sourceforge.net/

wget http://sourceforge.net/projects/jpam/files/jpam/jpam-1.1/JPam-Linux_amd64-1.1.tgz/download


按照JPam安装说明,

a> 首先在/etc/pam.d下,创建一个google-auth文件,在文件中添加如下内容:

   auth   required   /lib64/security/pam_google_authenticator.so use_first_pass

   account  required  /lib64/security/pam_unix_acct.so

b> 写一个JPamTest.java程序

    String user1Name = "root";
    String user1Credentials = "password";
    Pam pam = new Pam("google-auth");    //如果不输入名称,则默认使用net-sf-jpam
    boolean authenticated = pam.authenticateSuccessful(user1Name, user1Credentials));
   
JPamTest.java依赖JPam1.1.jar,libjpam.so(此动态库有问题,需要按照下面的步骤重新编译)


下载源码,并重新编译libpam.so

wget https://github.com/gregrluck/jpam

打开jpam/src/main/c/Pam.c,查找到pam_set_item(pamh, PAM_AUTHTOK, password),修改PAM_AUTHTOK为PAM_AUTHTOK_TYPE

修改后,执行make,重新编译libpam.so


在linux下编译并执行JPamTest.java,其中username为linux root用户名,密码为google身份验证器中的动态密码,如果验证成功,则authenticated的状态值为True.


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI