Chinaunix

标题: 本机终端用u盘登陆系统,基于非对称密钥 [打印本页]

作者: archangle    时间: 2005-07-27 14:42
标题: 本机终端用u盘登陆系统,基于非对称密钥
上午发在高级应用版的,转到安全版本比较合适

首先你的对pam有所了解,然后是对linux登陆流程有所了解.
linux登陆流程简单说来可以这样理解.

假如你按下alt+F2, 那么gettty就得到这个信息.(getty的起动是由/etc/inittab控制的).getty随后调用login进程,login进程要求输入用户名和密码.并且把密码和用户名提交给pam系统验证(pam对login程序的验证步骤或者说方法可以由/etc/pam.d/login来设置).
pam系统把验证结果返回给login进程.然后login进程就会起动该用户的shell.比如bash.

关键就是在pam这一步,要怎么验证这都是你自己可以控制的,我的作法是用一个pamusb模块来替换口令模块.当然也可以配合使用.

pamusb的验证机制是用公钥密钥体系来完成的,简单说来就是在机器上放入公钥,u盘里放入密钥,密钥可以被加密.


现在登陆的流程是,假如你没有给密钥设置密码,那么登陆的时候,插入u盘,然后输入用户名就可以直接登陆了.如果密钥有密码的话,就要输入密码.

就这么简单.
有兴趣的朋友可以参考www.pamusb.org上的资料自己去搞.
我自己的系统我只测试了login和xdm,可以正常使用.
作者: authen    时间: 2005-07-27 15:24
标题: 本机终端用u盘登陆系统,基于非对称密钥
提几个问题阿:
1. 如果仅仅是linux认证,CLI login登录和X登录的agent应该是不同的,你这个pamusb是for 哪个的?
2. 有否authentication server? 抑或是单机版?
3. USB中是不是存放着证书? 如果把证书导入其他存储介质应该也是可以的吧。
作者: archangle    时间: 2005-07-27 18:33
标题: 本机终端用u盘登陆系统,基于非对称密钥
1.pamusb是for pam的,login和xdm会去调用这个模块
2.单机版,公钥在用户家目录的.auth目录下
3.是的,u盘存放密钥.把证书放到硬盘或者软盘上也可以,只不过在pam的配置里面指定具体设备就可以了.

如果能作到物理机器的安全,那么这个对登录的安全性有所提高.
作者: 西门飞    时间: 2005-07-28 01:57
标题: 本机终端用u盘登陆系统,基于非对称密钥
密钥存放在u盘

写 密钥 的时候.顺便把U盘的硬件号写上.
只认这一个.
岂不更安全.
作者: authen    时间: 2005-07-28 08:51
标题: 本机终端用u盘登陆系统,基于非对称密钥
如果是USB移动硬盘,程序认哪个分区?
作者: soway    时间: 2005-07-28 09:12
提示: 作者被禁止或删除 内容自动屏蔽
作者: archangle    时间: 2005-07-28 09:15
标题: 本机终端用u盘登陆系统,基于非对称密钥
写 密钥 的时候.顺便把U盘的硬件号写上.
只认这一个.
岂不更安全.

不知道这个参数是不是,我还没仔细研究这个模块.只是实现了最主要的功能.
snfile            string         the serial number file contains the allowed SN. If it doesn't exists, the default behaviour is to grant everything.

如果是USB移动硬盘,程序认哪个分区?

我想你直接指定到分区就可以了,比如/dev/sdc1
这个需要测试.
作者: archangle    时间: 2005-07-28 09:17
标题: 本机终端用u盘登陆系统,基于非对称密钥
另外我在研究Device-mapper.其中一个encryption target (dm-crypt).利用这个东西,我可以把u盘从地层加密,就算u盘丢失,里面的密钥别人也不能得到.
作者: authen    时间: 2005-07-28 09:50
标题: 本机终端用u盘登陆系统,基于非对称密钥
[quote]原帖由 "archangle"]另外我在研究Device-mapper.其中一个encryption target (dm-crypt).利用这个东西,我可以把u盘从地层加密,就算u盘丢失,里面的密钥别人也不能得到.[/quote 发表:

那么U盘可以克隆吧。
作者: archangle    时间: 2005-07-28 09:55
标题: 本机终端用u盘登陆系统,基于非对称密钥
那么U盘可以克隆吧。

这点到是没有考虑到,我要做的就是里面的东西不能被读取.另外不知道u盘的sn是不是唯一的,而且不可更改,如果是那样的话就好办了.
作者: archangle    时间: 2005-07-28 10:08
标题: 本机终端用u盘登陆系统,基于非对称密钥
如果是windows的方式呢?
或者是远程登陆是否也可以这样实现?
比如远程ssh登陆

不好意思,看漏你的贴子了.


windows不适用,因为这个模块只是linux-pam的一个插件而已.
远程登录也可以这么做,只需要修改/etc/pam.d/ssh
不过没有这个必要,因为ssh本身就有自己的一套公钥密钥认证体系
作者: xuanren    时间: 2005-07-28 11:11
标题: 本机终端用u盘登陆系统,基于非对称密钥
格尔有款不成熟的usb_key就类似楼主这种机制
作者: authen    时间: 2005-07-29 09:30
标题: 本机终端用u盘登陆系统,基于非对称密钥
原帖由 "archangle" 发表:

这点到是没有考虑到,我要做的就是里面的东西不能被读取.另外不知道u盘的sn是不是唯一的,而且不可更改,如果是那样的话就好办了.

据我所知,U盘的sn是可以改的。如果你要做到密钥存储介质不能被复制,可能要用到Ukey或智能卡了。
作者: archangle    时间: 2005-07-29 09:43
标题: 本机终端用u盘登陆系统,基于非对称密钥
不过也要有这样的考虑,那就是假如存放密钥的介质丢失了,还能重建.要不然会带来一定的麻烦.
有一个叫做pam_opengpg的模块,支持smartcard验证.由于手头没有设备,所以没机会去测试.
作者: authen    时间: 2005-07-29 12:05
标题: 本机终端用u盘登陆系统,基于非对称密钥
照这样走下去可能要做的是:CA认证的linux agent了。
作者: archangle    时间: 2005-07-29 12:28
标题: 本机终端用u盘登陆系统,基于非对称密钥
我考虑是能不能用指纹认证,这个似乎不难.
作者: authen    时间: 2005-07-29 16:41
标题: 本机终端用u盘登陆系统,基于非对称密钥
其实任何认证方式,最麻烦的就是面对各种各样的应用开发各种各样的agent,不管是CA认证、动态的静态的口令认证或者指纹认证,它们的认证服务器做起来都不难,算法即使白痴点或高深点基本都可以满足一般需求。
如果要做指纹认证的agent的话,你需要考虑是for CCD的呢还是for 压感电容的,不同的指纹认证技术会有不同的agent,做起来可能难度不小,希望做好心理准备。
作者: archangle    时间: 2005-07-29 18:04
标题: 本机终端用u盘登陆系统,基于非对称密钥
哈哈,你太高估我了,我只会用现成的东西.因为我对写驱动没天赋.
我的意思是利用现成的东西来做.因为linux-pam实在是很方便.
作者: authen    时间: 2005-08-02 08:41
标题: 本机终端用u盘登陆系统,基于非对称密钥
如果每个U盘的头信息具有唯一性的话,似乎可以考虑以这个为验证用户的手段。
但是,不晓得同一批次的U盘这些信息是否相同?

Udiskinfo.GIF (9.87 KB, 下载次数: 57)

Udiskinfo.GIF

作者: archangle    时间: 2005-08-02 09:01
标题: 本机终端用u盘登陆系统,基于非对称密钥
这是pam_usb模块的所有参数。其中的那个snfile可能就是指定u盘的序列号。我先测试一下。


  1. snfile    string    the serial number file contains the allowed SN. If it doesn't exists, the default behaviour is to grant everything.    /etc/pam_usb/serials.conf
复制代码


  1. name         type         description         default value
  2. mntpoint         string         Tells pam_usb the form of the temporary directory. XXXXXX (6 times) will be replaced by a temporary value.         /tmp/pam_usbXXXXXX
  3. proc_basename         string         the device's procfile. You usually don't have to change this, it's where pam_usb searches for devices.         /proc/scsi/usb-storage-%d/%d
  4. pwfile         string         The path pam_usb will search for public and private keys (~user/ and mntpoint/)         /.auth/
  5. pubkey         string         The name of the public key located in the user's home         id_pub
  6. snfile         string         the serial number file contains the allowed SN. If it doesn't exists, the default behaviour is to grant everything.         /etc/pam_usb/serials.conf
  7. fs         string         comma-separated list of filesystems used to mount the device         ext2,vfat
  8. utmp         string         location of the utmp file         /var/run/utmp
  9. mount_opts         string         comma-separated list of mount options (including: ro,bind,sync,remount,nosuid,noexec,nodev)        
  10. log_file         string         print debug messages to that file instead of stdout        
  11. local_consoles         string         comma-separated list of consoles which be able to login when allow_remote=-1         /dev/vc/,/dev/tty,:
  12. direct_open         boolean         Attempt to open the private key using O_DIRECT to avoid disk caching: will work only on devices that support this feature.
  13. local_hosts         string         comma-separated list of hosts that will be able to login when allow_remote=-1         :
  14. force_device         string         Using this option, you can force pam_usb to use a specified device. If it fails mounting, it'll switch back to auto guess mode        
  15. allow_remote         boolean         When set to false (!allow_remote) it will allow only local_hosts and local_consoles to login.         false
  16. check_device         boolean         If unset (!check_device), pam_usb will not check neither if the device is attached, nor its serial number.         true
  17. check_if_mounted         boolean         if the usb device is already mounted pam_usb will use its mountpoint (avoid using it)         false
  18. keep_mounted         boolean         When set to true, it'll keep mntpoint mounted. Useful if combined with check_if_mounted.         false
  19. sign_times         integer         Number of times pam_usb will do the sign/check challenge.         3
  20. debug         boolean         enable debug mode         false
复制代码

作者: archangle    时间: 2005-08-02 09:20
标题: 本机终端用u盘登陆系统,基于非对称密钥
看了一下pam_usb的源代码,的确可以检查u盘的sn.
这是代码:

  1. int check_serial (FILE *proc)
  2. {
  3.         FILE *f;
  4.         char *line = NULL;
  5.         char *serial = NULL;
  6.         char type[] = "{S}";

  7.         /* If there's no serial number file, authorize */
  8.         if ((f = fopen (usb_conf.snfile, "r")) == NULL)
  9.                 return 1;

  10.         DEBUGP ("Found serial number ACL file, checking...\n");

  11.         serial = get_param (proc, "Serial Number", ':');

  12.         if (!serial || !(strcmp (serial, "None"))) {
  13.                 free (serial);
  14.                 serial = NULL;
  15.                 /* trying with the GUID */
  16.                 DEBUGP ("Cannot fetch the device's serial number\n"
  17.                         "Checking the GUID...\n");
  18.                 type[1] = 'G';
  19.                 if (!(serial = get_param (proc, "GUID", ':'))) {
  20.                         /* no luck either */
  21.                         free (serial);
  22.                         fclose (f);
  23.                         return 0;
  24.                 }
  25.                 DEBUGP ("GUID found\n");
  26.         }

  27.         while ((line = get_param (f, type, ' '))) {

  28.                 if (!strcmp (serial, line)) {
  29.                         free (serial);
  30.                         free (line);
  31.                         fclose (f);
  32.                         DEBUGP ("Serial number matches\n");
  33.                         return 1;
  34.                 }

  35.                 free (line);
  36.         }

  37.         free (serial);
  38.         fclose (f);
  39.         DEBUGP ("Serial number doesn't match\n");
  40.         return 0;
  41. }

复制代码

作者: authen    时间: 2005-08-02 09:41
标题: 本机终端用u盘登陆系统,基于非对称密钥

如果U盘头信息是唯一的,不易伪造的,那么似乎这个应用面很广哦,不晓得楼主有没试验过与网页登陆结合。
作者: archangle    时间: 2005-08-02 09:58
标题: 本机终端用u盘登陆系统,基于非对称密钥
网页登录?不明白,能详细说一下吗?

这个是u盘在/proc里的信息。不知道那些东西是唯一的,而且不能伪造。如果有必要可以自己增加验证u盘的内容,比如GUID.

  1.    Host scsi1: usb-storage
  2.        Vendor: KINGSTON     
  3.       Product: USB DRIVE   
  4. Serial Number: 0147357464707
  5.      Protocol: Transparent SCSI
  6.     Transport: Bulk
  7.          GUID: 04e801000000147357464707
  8.      Attached: Yes
复制代码

作者: authen    时间: 2005-08-02 12:30
标题: 本机终端用u盘登陆系统,基于非对称密钥
en...比方登录CU,由用户名+口令-->;用户名+Usb盘
作者: archangle    时间: 2005-08-02 13:10
标题: 本机终端用u盘登陆系统,基于非对称密钥
这个和招行的网上银行差不多了。他们用的就是x509证书。也有存放到u盘的证书。
不过这个结构和我的刚好相反了。而且实现起来也相差很远。
他们是ssl连接后再验证证书。
如果普通网站这么搞有点“杀鸡用牛刀的感觉”,不过个人站点倒是可以考虑这么搞。
作者: authen    时间: 2005-08-02 14:12
标题: 本机终端用u盘登陆系统,基于非对称密钥
俺的意思是不用非对称密钥,如果USB盘序列号唯一的话,就以它来验证用户,不是比较简单么。




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2