ここでは、私が常用しているpgp2.6.3i、GPG(GNU Privacy Guard)のインストール方法と使用方法、及びノウハウについて示します。
PGP2.6.3のインストールと設定
GPG1.0のインストールと設定
GPGでPGP2の暗号/復号を行う方法
PGPの詳細が知りたければ、以下のペイジを参照することをお奨めします。
MIT PGP2.6.2のソースコードを、アメリカ合衆国外で使うように修正されたのがPGP2.6.3iです。UNIX系OSでは、現在最も普及しているバージョンでしょう。不具合が修正されたPGP2.6.3iaを使うのがいいでしょう。これから、PGPを始める方は、PGP2.6.3iではなく、PGP国際化バージョンのPGP5やPGP6、及びGPGの使用をお奨めします。
PGPのインストールは、以下の通りです。
# mkdir pgp
# cd pgp
# tar zxvf ../pgp263is.tar.gz
# tar xvf pgp263ii.tar
# cd src
# make linux
# cp pgp /usr/local/bin/pgp
# mkdir -p /usr/local/share/pgp
# cp -r doc *.hlp *.txt /usr/local/share/pgp/.
PGPを使用するためには、環境の設定する必要があります。環境設定は以下の通りです。
$ mkdir ~/.pgp
$ chmod 700 ~/.pgp $ cd /usr/local/share/pgp
$ cp -r doc *.hlp *.txt ~/.pgp/.
(重要:~/.pgpは、他人がアクセスできないようにします。)
PGPを使用するためには、自分の鍵ペア(秘密キーと公開キー)を作成する必要があります。環境設定は以下の通りです。自分の鍵ペアを作成する方法は、以下の通りです。これは、最初の1回だけ必要です。
$ pgp -kg
Pretty Good Privacy(tm) 2.6.3ia - Public-key encryption for the masses.
(c) 1990-96 Philip Zimmermann, Phil's Pretty Good Software. 1996-03-04
International version - not for use in the USA. Does not use RSAREF.
Current time: 1998/03/20 12:01 GMT
Pick your RSA key size:
1) 512 bits- Low commercial grade, fast but less secure
2) 768 bits- High commercial grade, medium speed, good security
3) 1024 bits- "Military" grade, slow, highest security
Choose 1, 2, or 3, or enter desired number of bits:3
(キーサイズは、1024bitが良いでしょう。3を選択します。)
Generating an RSA key with a 1024-bit modulus.
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 <12345.6789@compuserve.com>
Enter a user ID for your public key:
Takahashi Shin-ichi <tks@love.email.ne.jp>
(PGPをメイルで使用する方は、IDをメイルアドレスにします。
メイルのFromアドレスと同じものにしましょう。)
You need a pass phrase to protect your RSA 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: xxxxxxxxxx
Enter same pass phrase again: xxxxxxxxxx
(暗号/復号時に入力するパスフレーズを入力します。)
Note that key generation is a lengthy process.
We need to generate 1015 random bits. This is done by measuring the
time intervals between your keystrokes. Please enter some random text
on your keyboard until you hear the beep:
1015
(キー作成のために乱数を使用しますが、キーボードのキー入力を
利用して乱数作成に利用します。適当にキー入力します。)
0 * -Enough, thank you.
.........................................................................
Pass phrase is good. Just a moment....
Key signature certificate added.
Key generation completed.
(キー作成が終りました。)
これで、~/.pgpに公開キーリング(pubring.pgp)と秘密キー(secring.pgp)が作成されます。秘密キーは、パスフレーズと共に他人に盗まれないよう注意しましょう。
GUNPGは、IDEA、RSAといったPatentedなアルゴリズムを使用しません。そのためPGP2ユーザと暗号データのやりとり、電子署名検証ができません(後述する方法を使えば可能にすることができます)。Patentedなアルゴリズムを使用しないことから、今後ソフトウェア配付の電子署名等広く使われて行くことになると思います。
GPGのインストールは、以下の通りです。
# tar zxvf gnupg-1.0.0.tar.gz
# cd gnupg-1.0.0
# ./configure
# make
# make install
鍵作成時に利用される乱数作成にRandom Deviceを利用することができます。Random Deviceがあるか調べます。なければ作ります。
# ls -l /dev/random
# mknod /dev/random c 1 8
# mknod /dev/urandom c 1 9
GPGを使用するためには、まず始めに1回だけ秘密鍵と公開鍵を作成する必要があります。鍵ペアの作成方法は、以下の通りです。
$ gpg --gen-key gpg (GnuPG) 1.0.0; Copyright (C) 1999 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. gpg: Warning: using insecure memory! gpg: /home/tks/.gnupg: directory created gpg: /home/tks/.gnupg/options: new options file created gpg: /home/tks/.gnupg/secring.gpg: keyring created gpg: /home/tks/.gnupg/pubring.gpg: keyring created Please select what kind of key you want: (1) DSA and ElGamal (default) (2) DSA (sign only) (4) ElGamal (sign and encrypt) Your selection? 1 (1を選択しましょう。) DSA keypair will have 1024 bits. About to generate a new ELG-E keypair. minimum keysize is 768 bits default keysize is 1024 bits highest suggested keysize is 2048 bits What keysize do you want? (1024) 2048 (鍵サイズを指定します。1024でいいでしょう。私は、2048にしましたが...) Requested keysize is 2048 bits Please specify how long the key should be valid. 0 = key does not expire= key expires in n days w = key expires in n weeks m = key expires in n months y = key expires in n years Key is valid for? (0) (鍵の有効期限を指定します。無期限(0)を指定します。) Key does not expire at all Is this correct (y/n)?y (上記入力に間違いがなければ、yを指定します。) You need a User-ID to identify your key; the software constructs the user id from Real Name, Comment and Email Address in this form: "Heinrich Heine (Der Dichter) " Real name: Takahashi Shin-ichi Email address: tks@love.email.ne.jp Comment: You selected this USER-ID: "Takahashi Shin-ichi " Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? o (名前、メイルアドレスを指定します。メイルのFromアドレスと同じに なるようにしましょう。) You need a Passphrase to protect your secret key. Enter passphrase: xxxxxxxxxxxx Repeat passphrase: xxxxxxxxxxxx (暗号/復号時に入力するパスフレーズを入力しましょう。) We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. +++++++++++++++.++++++++++++++++++++.++++++++++.++++++++++.++++++++++.. We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy. ++++++++++.+++++++++++++++++++++++++..+++++++++++++++++++++++++....++++ public and secret key created and signed. 上記により、~/.gnupgディレクトリが作成され、ここに公開鍵(pubring.gpg)、秘密鍵(secring.gpg)が作成されました。秘密キーは、パスフレーズと共に他人に盗まれないよう注意しましょう。作成された鍵の情報は、以下のようにすれば見ることができます。
$ gpg --list-key gpg: Warning: using insecure memory! /home/tks/.gnupg/pubring.gpg ---------------------------- pub 1024D/0834E1C7 1999-09-11 Takahashi Shin-ichi <tks@love.email.ne.jp> uid Takahashi Shin-ichi <takashin@yh.msy.co.jp> sub 2048g/D67BF739 1999-09-11 $ gpg --fingerprint gpg: Warning: using insecure memory! /home/tks/.gnupg/pubring.gpg ---------------------------- pub 1024D/0834E1C7 1999-09-11 Takahashi Shin-ichi <tks@love.email.ne.jp> Key fingerprint = 5EF6 547F A8AA E56C DDDE 7F6B 9D6D FC4C 0834 E1C7 uid Takahashi Shin-ichi <takashin@yh.msy.co.jp> sub 2048g/D67BF739 1999-09-11
GPGは、contribのソフトウェアを使用することでPGP2の鍵の取り込み、暗号/復号、電子署名検証を行うことができるようになります。
contribのidea.cとrsa.cをインストールして設定を行えばpgp2.6.3で使用していた公開鍵をgpgで使うことができます。idea.cとrsa.cのインストールと設定は以下の通りです。
(idea, rsaのインストール) # gcc -Wall -O2 -shared -fPIC -o idea idea.c # cp idea /usr/local/lib/gnupg/. # gcc -Wall -O2 -shared -fPIC -o rsa rsa.c # cp rsa /usr/local/lib/gnupg/. (設定 ~/.gnupg/optionsに以下を追加する) $ vi ~/.gnupg/options load-extension rsa load-extension ideapgpの鍵をgpgに取り込みます。これで、pgpで暗号化されたものをgpgで復号できます。
$ gpg --import ~/.pgp/secring.pgp $ gpg --import ~/.pgp/pubring.pgpgpgでpgpの公開鍵を使って暗号化を行うには、以下の方法で行います。(未確認)。まず、始めに公開鍵の有効性(公開鍵がその本人の物であるということを信用する度合)を設定します。その鍵が信用できるものならば、公開鍵に対して署名もしておくといいでしょう。
$ gpg --edit "<公開鍵のUserID>" gpg (GnuPG) 1.0.1; Copyright (C) 1999 Free Software Foundation, Inc. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the file COPYING for details. gpg: Warning: using insecure memory! Secret key is available. pub 768R/0C9857A5 created: 1995-09-30 expires: never trust: -/f (1) Werner Koch <werner.koch@guug.de> (2) Werner Koch (mein alter key) <wk@computer.org> Command> trust pub 768R/0C9857A5 created: 1995-09-30 expires: never trust: -/f (1) Werner Koch <werner.koch@guug.de> (2) Werner Koch (mein alter key) <wk@computer.org> Please decide how far you trust this user to correctly verify other users' keys (by looking at passports, checking fingerprints from different sources...)? 1 = Don't know 2 = I do NOT trust 3 = I trust marginally 4 = I trust fully s = please show me more information m = back to the main menu Your decision? f pub 1024D/0834E1C7 created: 1999-09-11 expires: never trust: f/u sub 2048g/D67BF739 created: 1999-09-11 expires: never (1) Takahashi Shin-ichi <tks@love.email.ne.jp> Command> sign Really sign all user IDs? yes pub 768R/0C9857A5 created: 1995-09-30 expires: never trust: f/q Fingerprint: 62 9E 97 C0 D5 55 76 3B 90 5A FA E9 81 1C 64 09 Werner Koch <werner.koch@guug.de> Werner Koch (mein alter key) <wk@computer.org> Are you really sure that you want to sign this key with your key: "Takahashi Shin-ichi <tks@love.email.ne.jp>" Really sign? yes You need a passphrase to unlock the secret key for user: "Takahashi Shin-ichi <tks@love.email.ne.jp>" 1024-bit DSA key, ID 0834E1C7, created 1999-09-11 Enter passphrase: xxxxxxxx Command> q Save change? yPGP公開鍵で暗号化をするには、以下の方法で行います。
cat <暗号化するファイル> | gpg -ea --rfc1991 --cipher-algo=IDEA -r <公開鍵のUsrID>