GnuPG で遊ぶ
%%Title: GnuPG で遊ぶ
%%Created: Thu Aug 8 17:15:24 JST 2002
%%Updated: Wed Mar 24 10:57:52 JST 2004
GnuPGを使ってみる。
設定
自分の公開鍵・秘密鍵を作る
サイン会
keyserver
gpg-agent
その他
PGP2からの移行
"gpg: Warning: using insecure memory!" と怒られます
o 設定
GNUPGHOME
キーリングや設定ファイルが置いてあるディレクトリを示す。
デフォルトは ${HOME}/.gnupg
o 自分の公開鍵・秘密鍵を作る。
% gpg --gen-key
gpg (GnuPG) 1.0.7; Copyright (C) 2002 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.
Please select what kind of key you want:
(1) DSA and ElGamal (default)
(2) DSA (sign only)
(4) ElGamal (sign and encrypt)
(5) RSA (sign only)
Your selection? 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
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
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: Shoichi Sakane
Email address: sakane@tanu.org
Comment:
You selected this USER-ID:
"Shoichi Sakane "
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
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.
key marked as ultimately trusted.
pub 1024D/5752D650 2002-08-08 Shoichi Sakane
Key fingerprint = 170D EBFD FB14 9312 A49A D817 2969 C50B 5752 D650
sub 2048g/81CC255A 2002-08-08
84.869u 0.101s 4:33.61 31.0% 713+261k 0+43io 0pf+0w
o サイン会
- 自分の公開鍵にサインしてもらうために鍵をASCIIで出力する
% gpg --armor --export sakane@tanu.org > public.txt
※ --armor は --export よりも前に指定しないと悲しい事になる
- サインしてもらった鍵をキーリングに戻す。単にインポートするだけ。
% gpg --import signed-public.txt
- サインした人も含めてリストする
% gpg --list-sigs
o keyserver
世の中には公開鍵を貯めておく公開サーバがある。
http://www.keyserver.net/en/
http://www.keyserver.net/en/other.html
http://www.hal-pc.org/~bunbytes/karlsson/pgp/keyservers.html
http://pgp.nic.ad.jp/pgp/
鍵サーバに公開鍵を登録する
% gpg --keyserver search.keyserver.net --send-key you@yourisp.net
鍵サーバを使って公開鍵を検索し keyringに登録する。
% gpg --keyserver pgp.nic.ad.jp --search-key sakane
gpg-agent
o gpg-agent
少なくとも GnuPG 1.9.15には gpg-agentなるプログラムがある。
2005/04/20の時点でNetBSDの場合は、gnupg-develに入っている。
-enable-agent-only
o その他
- リストする
% gpg --list-keys
- 公開鍵を削除する
% gpg --delete-key xxx@hoge.hage
o PGP2からGnuPGへの移行
ここではPGP2で使っていたkeyringをGnuPGに移行する手続きについて書く。
1つの公開鍵毎に pgpでエクスポートして gpgでインポートしなければいけない(ようだ…)。
PGP2とGnuPG間のinteroperabilityは今の所は興味ないので触れない。
詳細は http://www.gnupg.org/gph/en/pgp2x.html
- PGP2のキーリングから公開鍵を取り出し GnuPGのキーリングへ登録する。
% pgp263i/src/pgp -fkx sakane@ydc.co.jp | gpg --import
- PGP2のキーリングから秘密鍵を取り出し GnuPGのキーリングへ登録する。
% pgp263i/src/pgp -fkx sakane private.pgp ./secring.pgp
Pretty Good Privacy(tm) 2.6.3i - Public-key encryption for the masses.
(c) 1990-96 Philip Zimmermann, Phil's Pretty Good Software. 1996-01-18
International version - not for use in the USA. Does not use RSAREF.
Current time: 2002/08/08 08:16 GMT
Extracting from key ring: './secring.pgp', userid "sakane".
Key for user ID: Shoichi Sakane
1024-bit key, key ID 6BC2D949, created 1998/03/05
Key ID 6BC2D949 is already included in key ring 'private.pgp'.
Keyring extract error.
For a usage summary, type: pgp -h
For more detailed help, consult the PGP User's Guide.
% gpg --import ~/.pgp/private.pgp
gpg: key 6BC2D949: secret key imported
gpg: Total number processed: 1
gpg: secret keys read: 1
gpg: secret keys imported: 1
o "gpg: Warning: using insecure memory!" と怒られます
http://www.gnupg.org/faq.html#q6.1 参照
mlock()できないと怒っている。回避方法は3つ。
1. gpgのsetuidビットを立てる。
2. --no-secmem-warning オプションを使う。
3. 設定ファイルに no-secmem-warning と書く。