Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6968757
  • 博文数量: 637
  • 博客积分: 10265
  • 博客等级: 上将
  • 技术积分: 6165
  • 用 户 组: 普通用户
  • 注册时间: 2004-12-12 22:00
文章分类

全部博文(637)

文章存档

2011年(1)

2010年(1)

2009年(3)

2008年(12)

2007年(44)

2006年(156)

2005年(419)

2004年(1)

分类: LINUX

2006-02-19 11:25:43

 数字签名(Digital Signature),是一种身份认证技术。软件包增加数字签名后,其它用户可以通过校验其签名,辨其真伪,看其是否原装,是否被修改过。RPM采用的数字签名为PGP数字签名,PGP即Pretty Good Privacy,它是采用RSA密码技术实现的,应用时要产生一个密钥对(两个密钥),一个为公开密钥(可告诉他人),一个为秘密密钥(自己保留)。秘密密钥加密的文件任何有相应公开密钥的人均可解密,而用公开密钥加密的文件只有持有秘密密钥的人才可以解密。
PGP的下载与安装
PGP应用程序我是从网址处下载的。LINUX版的下载文件为PGPcmdln_6.5.8.Lnx_FW.rpm.tar,可用下面的命令解压此软件包,并安装PGP:
# tar xvzf PGPcmdln_6.5.8.Lnx_FW.rpm.tar
-rwxr-xr-x root/other 2955703 2000-08-31 05:29 PGPcmdln_6.5.8_Lnx_FW.rpm
-rwxr-xr-x root/other 66 2000-08-31 10:09 PGPcmdln_6.5.8_Lnx_FW.rpm.sig
-rwxr-xr-x root/other10981 2000-08-30 21:58 WhatsNew.htm
-rwxr-xr-x root/other 8758 2000-08-30 21:58 WhatsNew.txt
#
# rpm -iv PGPcmdln_6.5.8_Lnx_FW.rpm
pgp-6.5.8-rsaref658
#
# rpm -ql pgp
/usr/bin/pgp
/usr/doc/pgp-6.5.8
/usr/doc/pgp-6.5.8/CREDITS
/usr/doc/pgp-6.5.8/IntrotoCrypto.pdf
/usr/doc/pgp-6.5.8/IntrotoCrypto.ps
/usr/doc/pgp-6.5.8/LICENSE
/usr/doc/pgp-6.5.8/PGPCmdLineGuide.pdf
/usr/doc/pgp-6.5.8/PGPCmdLineGuide.ps
/usr/doc/pgp-6.5.8/PGPCmdLineInstallGuide.pdf
/usr/doc/pgp-6.5.8/PGPCmdLineInstallGuide.ps
/usr/doc/pgp-6.5.8/RSALICENSE
/usr/doc/pgp-6.5.8/SampleKeys.asc
/usr/doc/pgp-6.5.8/WHATSNEW
/usr/doc/pgp-6.5.8/WhatsNew.htm
/usr/man/man1/pgp.1
#

注:第1条命令解压软件包,第2条命令安装RPM格式的PGP包,第3条命令则是查询一下PGP包里的文件,其执行文件是/usr/bin/pgp,说明文档在/usr/doc/pgp-6.5.8目录下,有man手册(/usr/man/man1/pgp.1),可以用man pgp来获得pgp的帮助信息。
另外,还可以到网站查找或下载PGP程序,前面介绍的网站速度快,这个网站速度慢。
RPM应用PGP所需的配置
1. 生成PGP密钥对
这需要使用pgp -kg命令来产生新的密钥对,以用于签名:
# pgp -kg
Pretty Good Privacy(tm) Version 6.5.8
(c) 1999 Network Associates Inc.
Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc.
Export of this software may be restricted by the U.S. government.
Choose the public-key algorithm to use with your new key
1) DSS/DH (a.k.a. DSA/ElGamal) (default)
2) RSA
Choose 1 or 2: 1
Choose the type of key you want to generate
1) Generate a new signing key (default)
2) Generate an encryption key for an existing signing key
Choose 1 or 2: 1
Pick your DSS ``master key'' size:
1) 1024 bits- Maximum size (Recommended)
Choose 1 or enter desired number of bits: 1
Generating a 1024-bit DSS key.
You need a user ID for your public key. The desired form for this
user ID is your name, followed by your E-mail address enclosed in
, if you have an E-mail address.
For example: John Q. Smith
Enter a user ID for your public key: zhsoft
Enter the validity period of your signing key in days from 0 - 10950
0 is forever (the default is 0):
You need a pass phrase to protect your DSS secret key.
Your pass phrase can be any sentence or phrase and may have many
words, spaces, punctuation, or any other printable characters.
Enter pass phrase: MYPASS
Enter same pass phrase again: MYPASS
PGP will generate a signing key. Do you also require an
encryption key? (Y/n) Y
Pick your DH key size:
1) 1024 bits- High commercial grade, secure for many years
2) 2048 bits- "Military" grade, secure for forseeable future
3) 3072 bits- Archival grade, slow, highest security
Choose 1, 2, 3, or enter desired number of bits: 1
Enter the validity period of your encryption key in days from 0 - 10950
0 is forever (the default is 0): 0
Note that key generation is a lengthy process.
PGP needs to generate some random data. This is done by measuring
the time intervals between your keystrokes. Please enter some
random text on your keyboard until the indicator reaches 100%.
Press ^D to cancel
100% of required data
Enough, thank you.
.******* .......................******* .
Make this the default signing key? (Y/n) Y
........******* ..........................*******
Key generation completed.
#

注:例子中,在生成PGP密钥前有若干工作要做:
1) 选择哪种公开加密算法:第1个是DSS/DH算法(默认),第2个是RSA算法,本例用第1个。
2) 选择生成哪种类型的密钥:第1个是新的签名密钥(默认),第2个是为已存在的签名密
钥产生一个加密密钥,本例选第1个。
3) 选择DSS主密钥大小:最大为1024位(系统建议使用),本例选择用它,当然,也可以输
入其它位数。
4) 为公开密钥设置一个用户标识(user ID,格式为:用户名 <电子邮箱>),本例使用:
纵横软件制作中心
5) 设定密钥适用天数(0-10950),本例选择0,表示永远适用。
6) 为DSS秘密密钥设置一个密码,本例密码为MYPASS,按要求输入了两次。
7) PGP提示是否还需要为签名密钥加密,本例选择Y(Yes)。
8) 选择DH密钥大小:第1是1024位,第2是2048位,第3是3072位,还可输入其它数值,本例
选择1,确下DH密钥大小为1024位。
9) 输入加密密钥适用天数(0-10950),本例选择0,表示永远适用。
10) PGP提示需要产生一些随机数据,用户需要随机输入一些,直到所需数据百分之百(100%)
完成才可。
11) PGP生成签名密钥后,提示是否将此密钥设置为默认的密钥,本例选择Y,将此密钥设
为默认使用的密钥。
12) PGP密钥产生完成。
密钥生成后,PGP会在用户主目录下建立一个.pgp的子目录,用于存放密钥相关的文件。
下例列出了root用户.pgp子目录下的文件:
# ls ~/.pgp
total 32
-rw------- 1 root root 2117 Nov 8 17:10 PGPMacBinaryMappings.txt
-rw------- 1 root root 146 Nov 8 17:10 PGPgroup.pgr
-rw------- 1 root root 151 Nov 8 17:12 PGPsdkPreferences
-rw------- 1 root root0 Nov 8 17:10 pgp.cfg
-rw------- 1 root root0 Nov 8 17:10 pubring-bak-1.pkr
-rw------- 1 root root 897 Nov 8 17:12 pubring-bak-2.pkr
-rw------- 1 root root 897 Nov 8 17:12 pubring.pkr
-rw------- 1 root root 512 Nov 8 19:34 randseed.rnd
-rw------- 1 root root0 Nov 8 17:10 secring-bak-1.skr
-rw------- 1 root root 984 Nov 8 17:12 secring-bak-2.skr
-rw------- 1 root root 984 Nov 8 17:12 secring.skr
#

文件之中:pubring.pkr为公开密钥文件,secring.skr为秘密密钥文件。
2. 配置RPM宏
RPM要想使用PGP数字签名的功能,必须在/usr/lib/rpm/macros宏文件或者在用户主目
录下的~/.rpmmacros文件中,设置以下几个宏:(最好编辑自己的宏文件--~/.rpmmacros文件,
不要随意改变含RPM默认设置的宏文件/usr/lib/rpm/macros)
1) _signature :
此宏定义数字签名的类型,此类型只有一个,为pgp(RPM仅支持这一种)。其定义为:
%_signature pgp
2) _pgpbin :
此宏定义PGP执行程序名。其定义为:
%_pgpbin /usr/bin/pgp
3) _pgp_name :
此宏定义使用哪个PGP用户的公开密钥进行签名处理(PGP可建立属于多个用户的密钥对)。
其定义格式为:
%_pgp_name 名字 <电子邮箱>
如:
%_pgp_name 纵横软件制作中心
4) _pgp_path :
此宏定义RPM使用的签名所在的目录,如:
%_pgp_path /root/.pgp
该宏定义RPM使用/root/.pgp目录下的签名。
RPM的PGP签名选项
1. --resign :
本选项用于为RPM软件包重新签名。如果原包没有数字签名,则为其添加签名;如果已有签名,则旧的签名将统统删除,之后再添加新的签名。其用法为:
rpm --resign 包裹文件1 [包裹文件2]...
2. --addsign :
本选项用于为RPM软件包添加数字签名(一个软件包可以有多个数字签名)。用法为:
rpm --addsign 包裹文件1 [包裹文件2]...
如:
# rpm --addsign lze-6.0-2.i386.rpm
Enter pass phrase: MYPASS
Pass phrase is good.
lze-6.0-2.i386.rpm:
Pretty Good Privacy(tm) Version 6.5.8
(c) 1999 Network Associates Inc.
Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc.
Export of this software may be restricted by the U.S. government.
#

本例为lze软件包添加数字签名,输入密码为MYPASS。数字签名也可以在建包时添加,这时需使用--sign选项。
3. --checksig :
本选项用于校验RPM包的数字签名等内容,看其是否正常。用法为:
rpm --checksig [--nopgp] [--nogpg] [--nomd5] [--rcfile 资源文件] 包裹文件1 [包裹文件2]...
注:[]所括为可选项。--checksig也可用-K替换,效果相同。可选项中,--nopgp选项指示RPM不校验PGP签名,--nogpg选项指示RPM不校验GPG签名,--nomd5选项指示RPM不校验MD5检查和,--rcfile选项则用于指定RPM所利用的资源配置文件。
如:
# rpm --checksig lze-6.0-2.i386.rpm
Pretty Good Privacy(tm) Version 6.5.8
(c) 1999 Network Associates Inc.
Uses the RSAREF(tm) Toolkit, which is copyright RSA Data Security, Inc.
Export of this software may be restricted by the U.S. government.
lze-6.0-2.i386.rpm: pgp md5 OK
#

注:本例校验lze包的签名时,RPM显示pgp校验OK,md5校验OK,这表明lze包一切正常。
阅读(4904) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~