/*********************************************************************
* Author : Samson
* Date : 04/04/2014
* Test platform:
* Linux ubuntu 3.2.0-58-generic-pae
* GNU bash, version 4.2.39
* *******************************************************************/
数字签名是什么?
下面将用一个例子来说明如何来进行签名的验证,以确保下载的文件是没有经过修改的,防止被非作者进行修改后重新打的包(这里面的文章可大了,你懂的:_()
如何使用gpg进行安全签名来验证下载的文件是否完整,以mediawiki为例:
首先,到mediawiki official web download:
mediawiki-1.22.5.tar.gz
再得到上版本的签名文件,再得到pubkey,网页上的获取点如下图:
得到MediaWiki 1.22.5 GPG安全签名文件:mediawiki-1.22.5.tar.gz.sig
能过上图的 MediaWiki的GPG的公钥 得到pubkey文件,并保存到文件mediawiki_pubkey.txt中;
导入公钥到当前系统中:
fuckids@debian-IDS:~/wiki$ gpg --import mediawiki_pubkey.txt
gpg: /home/fuckids/.gnupg/trustdb.gpg: trustdb created
gpg: key 7F901A30: public key "Mark A. Hershberger <[email protected]>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
gpg: no ultimately trusted keys found
//列出当前的公钥,检查 是否导入 成功
fuckids@debian-IDS:~/wiki$ gpg -k
/home/fuckids/.gnupg/pubring.gpg
--------------------------------
pub 2048R/7F901A30 2009-07-01 [expires: 2019-06-29]
uid Mark A. Hershberger <[email protected]>
sub 2048R/84896BEA 2009-07-01 [expires: 2019-06-29]
//使用签名文件对下载的文件进行验证:
fuckids@debian-IDS:~/wiki$ gpg --verify mediawiki-1.22.5.tar.gz.sig mediawiki-1.22.5.tar.gz
gpg: Signature made Fri 28 Mar 2014 08:21:11 AM CST using RSA key ID 7F901A30
gpg: Good signature from "Mark A. Hershberger <[email protected]>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 3CEF 8262 806D 3F0B 6BA1 DBDD 7956 EE47 7F90 1A30
其中 gpg: Good signature from "Mark A. Hershberger <[email protected]>" 这一行表示签名文件是正确的,表示下载的包并没有被中间修改过;
关于gpg相关的请参考:
http://www.gnupg.org
http://www.ruanyifeng.com/blog/2013/07/gpg.html
http://hi.baidu.com/hs_fish/item/8eb09d0b1bab79006c9048c9