顯示具有 Mac OS X 標籤的文章。 顯示所有文章
顯示具有 Mac OS X 標籤的文章。 顯示所有文章

2009年1月3日

How to verify the integrity of downloaded files on a Mac

I classify files available for download on the internet as the following:

  • Respectable providers ship download files with signatures;
  • Less respectable providers ship with checksums;
  • Unrespectable providers ship only the download file.
The difference is mainly the following: a checksum allows you to verify that the download file hasn't been altered unexpectedly by someone you may not know. A signature allows you to verify the above plus that the file was signed by a certain someone, usually the creator of the file you downloaded. It may be advisable that you use the signature whenever there is one associated with a download file

The most popular way of digitally signing a file is using a private key in the realm of the web of trust. To get started, you can use the GNU Privacy Guard free software. If you don't have it on your Mac, you can install the Mac version. I've downloaded the dmg of version 1.4.8 and it worked like a charm.

After installing the GNU Privacy Guard, a command "gpg" is available to you in /usr/local/bin as well as some other utility programs. You can open a terminal and use
 $ gpg --verify foo.tar.gz.sig
to verify that the file foo.tar.gz matches with the signature file foo.tar.gz.sig. You can verify multiple files at once by
 $ gpg --verify-files *.sig
to verify the integrity of files. Read the manual ("man gpg") for more details.

Oops, an error!

If you see a message like
 gpg: Signature made Wed Dec 13 05:02:10 2006 CST using DSA key ID 64EA74AB
gpg: Can't check signature: public key not found
from "gpg --verify", it means that the public key of the signer is not in your GPG keyring. Just load the public key of the signer to your keyring and off you go. The following is how I do it, your mileage may vary.

The longer route:
  1. Go to http://pgp.mit.edu/, a popular public key server.
  2. Type the key ID in the search box. Remember to add "0x" in front of the 8-character hex key ID. For the example above, I typed "0x64EA74AB".
  3. If all goes well, you'll see a search result page listing one or more keys. Click on the key ID that matches to your input. Other keys belong to people that "vouch" for the key you searched.
  4. The key server should then show you the public key of the key ID. Copy and paste the plain texts between "-----BEGIN PGP PUBLIC KEY BLOCK-----" and "-----END PGP PUBLIC KEY BLOCK-----" to a file on your computer, with these 2 lines included. Let's call the file "foo.txt".
  5. Now import this key into your GPG keyring:
     $ gpg --import foo.txt
The shorter route: The 5 steps outlined above can be done in one command:
 $ gpg --recv-keys 0x64EA74AB
Now you have the public key of the signer in your keyring, you can verify the files signed by him/her using "gpg --verify".

在 Mac OS X 10.5 上安裝 Python 3.0

Python 3.0 在 2008/12/3 發佈,雖然 MacPorts 已經收錄,但 MacPython/Leopard 還在 2.5,要等到 Apple 收進 Mac OS X 裡恐怕還要等好一陣子,所以想嘗鮮又不熟 MacPorts 的人(是說我自己),就要自己裝了。

在 Mac OS X 上安裝 Python 3.0 沒什麼難的,只要依 ijliao 所說:「真男人用 tarball 手動安裝程式」就一切搞定。不過 Python 3.0 在語法、物件、函式庫上都有新東西,想要熟悉它,用互動環境邊打邊學是一定要的,那就絕對要裝讓你可以用上下左右鍵叫回程式敍述東改西改的 readline 函式庫,不然你會 copy & paste 到瘋掉。

安裝 readline 函式庫

Readline 函式庫可以在 ftp://ftp.cwru.edu/pub/bash/ 找到,我用的是 5.2 版,可以下載 readline-5.2.tar.gz 和 readline-5.2-patches 目錄中所有的補丁。在著手安裝之前,你也許應該確認一下這些檔案的完整性。

安裝方式很簡單。假設你已經把檔案下載放在你的桌面,先開啟終端機(Terminal),再依以下指令操作即可。
$ cd ~/3party  # 或任何你喜歡的目錄
$ tar zxvf ~/Desktop/readline-5.2.tar.gz
$ cd readline-5.2
$ cat ~/Desktop/readline52-0?? | patch -p 0
$ ./configure
$ make
$ sudo make install
這就完成了,會把兩個函式庫 libreadline 和 libhistory 裝到 /usr/local/lib 目錄去,每個函式庫都有四個不同副檔名的檔: .a、.dylib、.5.dylib、.5.2.dylib,其中 .dylib 和 .5.dylib 是指到 .5.2.dylib 的 symlink。

安裝 Python 3.0

Readline 裝好後,下載 Python 3.0 的原始碼 tarball 安裝就 OK 啦!
$ tar zxvf ~/Desktop/Python-3.0.tgz
$ cd Python-3.0
$ ./configure --enable-framework
$ make
$ sudo make frameworkinstall
$ cd /Library/Frameworks/Python.framework/Versions/
$ sudo rm Current
$ sudo ln -s 2.4 Current
最後這幾步是因為用 frameworkinstall 才會把 Python 3.0 裝進系統的 Python.framework 目錄,但會把預設 python 改成 3.0,為了不干擾系統其他 python scripts 的運作,要再把預設改回成 2.4。

請享用你的 Python 3.0 吧!