好像比較少中文文章介紹如何使用GPG來驗證File Integrity 還好找到了一篇Apache官網的介紹文章 http://httpd.apache.org/dev/verification.html 一般來說,驗證檔案的方式最常見的還有用hash的方法 像MD5、sha1、sha256、sha384、sha512 但MD5和sha1已經可以很容易的被找到collision,因此比較安全的作法 是使用sha256以上的 hash algorithm 以下使用Mozilla Firefox 10為範例: 下載了 Firefox Setup 10.0.exe Firefox Setup 10.0.exe.asc 這2個檔案後 執行GPG $gpg Firefox\ Setup\ 10.0.exe.asc gpg: Signature made 西元2012年01月30日 (週一) 01時12分47秒 TST using DSA key ID C52175E2 gpg: Can't check signature: public key not found 它的ID是C52175E2,因此我們到pgpkeys.mit.edu 這個keyserver來下載它的public key $gpg --keyserver pgpkeys.mit.edu --recv-key C52175E2 gpg: /home/abc/.gnupg/trustdb.gpg: trustdb created gpg: key 1EBCAB3A: public key "Mozilla Software Releases " imported gpg: Total number processed: 1 gpg: imported: 1 下載完後會存在家目錄的 .gnupg/trustdb.gpg底下,再來就是在本機端驗證檔案完整性 這行指令會去驗證Firefox Setup 10.0.exe這個檔案的完整性 $gpg --verify Firefox\ Setup\ 10.0.exe.asc gpg: Signature made 西元2012年01月30日 (週一) 01時12分47秒 TST using DSA key ID C52175E2 gpg: Good signature from "Mozilla Software Releases " gpg: checking the trustdb gpg: no ultimately trusted keys found 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: 9D03 193D 6BDC 541B D796 C4E4 7F4D 6645 1EBC AB3A Subkey fingerprint: 247C A658 AA95 F617 1EB0 F13E A7D7 5CC7 C521 75E2 Good signature代表這個檔案的確是用這個public key所對應的private key簽名的. 但因為每個人都能上傳自己的public key,所以也不一定能保證這個key一定是由Mozilla那邊產生的,所以會跳出Warning. 如果我們去修改Firefox Setup 10.0.exe這個檔案後 譬如用hexedit去修改其中內容的一個byte後,再去驗證,就會跳出Bad signature $gpg --verify Firefox\ Setup\ 10.0.exe.asc gpg: Signature made 西元2012年01月30日 (週一) 01時12分47秒 TST using DSA key ID C52175E2 gpg: BAD signature from "Mozilla Software Releases " 另外有一種方法比較方便,不過要有sig檔...就是直接import那個含有public key的asc檔,然後再verify那個sig就可以直接驗證了. 不過要注意的就是那個含有public key的asc檔的取得來源要正確,這樣它的sig檔才有意義,因為這個sig檔有點類似md5sum,sha1的checksum file 要有正確的public key來源才能確保無修改過的sig檔.
文章標籤
全站熱搜
創作者介紹
創作者 fvalinux 的頭像
fvalinux

Elegance

fvalinux 發表在 痞客邦 留言(1) 人氣(1,579)