certutilによる証明書管理 [Fedora14]
作成 : 2011/05/14
certutil
certutilはmozillaが提供しているNSSセキュリティツールのひとつで、証明書と鍵データベースを管理できる。 opensslの代替になるもの? 本家サイトはNSS Security Toolsで、ドキュメントも置いてある。 openswanでX.509証明書による認証を利用するときに操作が必要になる。
インストール
certutilはnss-toolsパッケージに含まれる。
[root@router1 ~]# yum install nss-tools インストール処理の設定をしています 依存性の解決をしています --> トランザクションの確認を実行しています ---> パッケージ nss-tools.i686 0:3.12.9-10.fc14 をインストールに設定しました --> 依存性解決を終了しました 依存性を解決しました ========================================================================================== パッケージ アーキテクチャ バージョン リポジトリー 容量 ========================================================================================== インストールしています: nss-tools i686 3.12.9-10.fc14 updates 777 k トランザクションの要約 ========================================================================================== Install 1 Package(s) 総ダウンロード容量: 777 k インストール済み容量: 3.1 M これでいいですか? [y/N]y パッケージをダウンロードしています: nss-tools-3.12.9-10.fc14.i686.rpm | 777 kB 00:00 rpm_check_debug を実行しています トランザクションのテストを実行しています トランザクションのテストを成功しました トランザクションを実行しています インストールし : nss-tools-3.12.9-10.fc14.i686 1/1 インストールしました: nss-tools.i686 0:3.12.9-10.fc14 完了しました!
インストールされたファイルを見てみる。
[root@router1 ~]# rpm -qlv nss-tools
-rwxr-xr-x 1 root root 162948 4月 13 05:39 /usr/bin/certutil
-rwxr-xr-x 1 root root 114240 4月 13 05:39 /usr/bin/cmsutil
-rwxr-xr-x 1 root root 127696 4月 13 05:39 /usr/bin/crlutil
-rwxr-xr-x 1 root root 171772 4月 13 05:39 /usr/bin/modutil
-rwxr-xr-x 1 root root 104540 4月 13 05:39 /usr/bin/pk12util
-rwxr-xr-x 1 root root 186492 4月 13 05:39 /usr/bin/signtool
-rwxr-xr-x 1 root root 105588 4月 13 05:39 /usr/bin/signver
-rwxr-xr-x 1 root root 60104 4月 13 05:39 /usr/bin/ssltap
-rwxr-xr-x 1 root root 6140 4月 13 05:39 /usr/lib/nss/unsupported-tools/atob
-rwxr-xr-x 1 root root 6392 4月 13 05:39 /usr/lib/nss/unsupported-tools/btoa
-rwxr-xr-x 1 root root 95880 4月 13 05:39 /usr/lib/nss/unsupported-tools/derdump
-rwxr-xr-x 1 root root 1313012 4月 13 05:39 /usr/lib/nss/unsupported-tools/ocspclnt
-rwxr-xr-x 1 root root 93856 4月 13 05:39 /usr/lib/nss/unsupported-tools/pp
-rwxr-xr-x 1 root root 122168 4月 13 05:39 /usr/lib/nss/unsupported-tools/selfserv
-rwxr-xr-x 1 root root 112644 4月 13 05:39 /usr/lib/nss/unsupported-tools/strsclnt
-rwxr-xr-x 1 root root 107680 4月 13 05:39 /usr/lib/nss/unsupported-tools/symkeyutil
-rwxr-xr-x 1 root root 108468 4月 13 05:39 /usr/lib/nss/unsupported-tools/tstclnt
-rwxr-xr-x 1 root root 101672 4月 13 05:39 /usr/lib/nss/unsupported-tools/vfychain
-rwxr-xr-x 1 root root 106740 4月 13 05:39 /usr/lib/nss/unsupported-tools/vfyserv
ヘルプ
-Hオプションをつけると、ヘルプが表示される。 NSS Security Toolsのページにもオプションについて記載があるが、追加されているオプションがあるのでヘルプを見た方がよいと思う。
[root@router2 ~]# certutil -H
-A Add a certificate to the database (create if needed)
All options under -E apply
-B Run a series of certutil commands from a batch file
-i batch-file Specify the batch file
-E Add an Email certificate to the database (create if needed)
-n cert-name Specify the nickname of the certificate to add
-t trustargs Set the certificate trust attributes:
trustargs is of the form x,y,z where x is for SSL, y is for S/MIME,
and z is for code signing
p valid peer
P trusted peer (implies p)
c valid CA
T trusted CA to issue client certs (implies c)
C trusted CA to issue server certs (implies c)
u user cert
w send warning
g make step-up cert
-f pwfile Specify the password file
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-a The input certificate is encoded in ASCII (RFC1113)
-i input Specify the certificate file (default is stdin)
-C Create a new binary certificate from a BINARY cert request
-c issuer-name The nickname of the issuer cert
-i cert-request The BINARY certificate request file
-o output-cert Output binary cert to this file (default is stdout)
-x Self sign
-m serial-number Cert serial number
-w warp-months Time Warp
-v months-valid Months valid (default is 3)
-f pwfile Specify the password file
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-1 | --keyUsage keyword,keyword,...
Create key usage extension. Possible keywords:
"digitalSignature", "nonRepudiation", "keyEncipherment",
"dataEncipherment", "keyAgreement", "certSigning",
"crlSigning", "critical"
-2 Create basic constraint extension
-3 Create authority key ID extension
-4 Create crl distribution point extension
-5 | -nsCertType keyword,keyword,...
Create netscape cert type extension. Possible keywords:
"sslClient", "sslServer", "smime", "objectSigning",
"sslCA", "smimeCA", "objectSigningCA", "critical".
-6 | --extKeyUsage keyword,keyword,...
Create extended key usage extension. Possible keywords:
"serverAuth", "clientAuth","codeSigning",
"emailProtection", "timeStamp","ocspResponder",
"stepUp", "critical"
-7 emailAddrs Create an email subject alt name extension
-8 dnsNames Create an dns subject alt name extension
-a The input certificate request is encoded in ASCII (RFC1113)
-G Generate a new key pair
-h token-name Name of token in which to generate key (default is internal)
-k key-type Type of key pair to generate ("dsa", "rsa" (default))
-g key-size Key size in bits, (min 512, max 8192, default 1024)
-y exp Set the public exponent value (3, 17, 65537) (rsa only)
-f password-file Specify the password file
-z noisefile Specify the noise file to be used
-q pqgfile read PQG value from pqgfile (dsa only)
-d keydir Key database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-D Delete a certificate from the database
-n cert-name The nickname of the cert to delete
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-U List all modules
-d moddir Module database directory (default is '~/.netscape')
-P dbprefix Cert & Key database prefix
-X force the database to open R/W
-K List all private keys
-h token-name Name of token to search ("all" for all tokens)
-k key-type Key type ("all" (default), "dsa", "rsa")
-n name The nickname of the key or associated certificate
-f password-file Specify the password file
-d keydir Key database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-X force the database to open R/W
-L List all certs, or print out a single named cert
-n cert-name Pretty print named cert (list all if unspecified)
--email email-address
Pretty print cert with email address (list all if unspecified)
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-X force the database to open R/W
-r For single cert, print binary DER encoding
-a For single cert, print ASCII encoding (RFC1113)
-M Modify trust attributes of certificate
-n cert-name The nickname of the cert to modify
-t trustargs Set the certificate trust attributes (see -A above)
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-N Create a new certificate database
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-T Reset the Key database or token
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-h token-name Token to reset (default is internal)
-0 SSO-password Set token's Site Security Officer password
-O Print the chain of a certificate
-n cert-name The nickname of the cert to modify
-d certdir Cert database directory (default is ~/.netscape)
-a Input the certificate in ASCII (RFC1113); default is binary
-P dbprefix Cert & Key database prefix
-X force the database to open R/W
-R Generate a certificate request (stdout)
-s subject Specify the subject name (using RFC1485)
-o output-req Output the cert request to this file
-k key-type-or-id Type of key pair to generate ("dsa", "rsa" (default))
or nickname of the cert key to use
-h token-name Name of token in which to generate key (default is internal)
-g key-size Key size in bits, RSA keys only (min 512, max 8192, default 1024)
-q pqgfile Name of file containing PQG parameters (dsa only)
-f pwfile Specify the password file
-d keydir Key database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-p phone Specify the contact phone number ("123-456-7890")
-a Output the cert request in ASCII (RFC1113); default is binary
See -S for available extension options
-V Validate a certificate
-n cert-name The nickname of the cert to Validate
-b time validity time ("YYMMDDHHMMSS[+HHMM|-HHMM|Z]")
-e Check certificate signature
-u certusage Specify certificate usage:
C SSL Client
V SSL Server
S Email signer
R Email Recipient
O OCSP status responder
J Object signer
-d certdir Cert database directory (default is ~/.netscape)
-a Input the certificate in ASCII (RFC1113); default is binary
-P dbprefix Cert & Key database prefix
-X force the database to open R/W
-W Change the key database password
-d certdir cert and key database directory
-f pwfile Specify a file with the current password
-@ newpwfile Specify a file with the new password in two lines
--upgrade-merge Upgrade an old database and merge it into a new one
-d certdir Cert database directory to merge into (default is ~/.netscape)
-P dbprefix Cert & Key database prefix of the target database
-f pwfile Specify the password file for the target database
--source-dir certdir
Cert database directory to upgrade from
--soruce-prefix dbprefix
Cert & Key database prefix of the upgrade database
--upgrade-id uniqueID
Unique identifier for the upgrade database
--upgrade-token-name name
Name of the token while it is in upgrade state
-@ pwfile Specify the password file for the upgrade database
--merge Merge source database into the target database
-d certdir Cert database directory of target (default is ~/.netscape)
-P dbprefix Cert & Key database prefix of the target database
-f pwfile Specify the password file for the target database
--source-dir certdir
Cert database directory of the source database
--source-prefix dbprefix
Cert & Key database prefix of the source database
-@ pwfile Specify the password file for the source database
-S Make a certificate and add to database
-n key-name Specify the nickname of the cert
-s subject Specify the subject name (using RFC1485)
-c issuer-name The nickname of the issuer cert
-t trustargs Set the certificate trust attributes (see -A above)
-k key-type-or-id Type of key pair to generate ("dsa", "rsa" (default))
-h token-name Name of token in which to generate key (default is internal)
-g key-size Key size in bits, RSA keys only (min 512, max 8192, default 1024)
-q pqgfile Name of file containing PQG parameters (dsa only)
-x Self sign
-m serial-number Cert serial number
-w warp-months Time Warp
-v months-valid Months valid (default is 3)
-f pwfile Specify the password file
-d certdir Cert database directory (default is ~/.netscape)
-P dbprefix Cert & Key database prefix
-p phone Specify the contact phone number ("123-456-7890")
-1 Create key usage extension
-2 Create basic constraint extension
-3 Create authority key ID extension
-4 Create crl distribution point extension
-5 Create netscape cert type extension
-6 Create extended key usage extension
-7 emailAddrs Create an email subject alt name extension
-8 DNS-names Create a DNS subject alt name extension
--extAIA Create an Authority Information Access extension
--extSIA Create a Subject Information Access extension
--extCP Create a Certificate Policies extension
--extPM Create a Policy Mappings extension
--extPC Create a Policy Constraints extension
--extIA Create an Inhibit Any Policy extension
--extSKID Create a subject key ID extension
証明書DBと鍵DBの作成
はじめに、証明書を格納するデータベースと鍵を格納するデータベースを作成する。 鍵DBのパスワードを入力しないと、鍵DBにアクセスするときパスワード入力を求められなくなる。
certutil -N -d /tmp/ -d : データベースを作成するディレクトリを指定。
[root@router2 ~]# certutil -N -d /tmp/ Enter a password which will be used to encrypt your keys. The password should be at least 8 characters long, and should contain at least one non-alphabetic character. Enter new password: 鍵DBにアクセスするためのパスワード Re-enter password: 鍵DBにアクセスするためのパスワード(再入力)
証明書DBと鍵DBが作成される。
[root@router2 ~]# ls -l /tmp/
-rw-------. 1 root root 65536 2011-05-11 22:41 cert8.db
-rw-------. 1 root root 16384 2011-05-11 22:41 key3.db
-rw-------. 1 root root 16384 2011-05-11 22:41 secmod.db
CA証明書と秘密鍵の作成(CAを開設)
CAの秘密鍵と証明書を作成する。
certutil -S -n ca -s "CN=ca" -1 -2 -5 -v 12 -t "C,C,C" -x -d /tmp
-n : ニックネームを指定。
-s : 証明書の所有者を特定する情報を指定(CN=..., OU=...)。
-1 : X.509v3拡張 Key Usageを付加する。(対話形式)
-2 : X.509v3拡張 Basic Constraintsを付加する。(対話形式)
-v : 証明書の有効期間を月単位で指定。
-t : 証明書の信頼性を指定(後から変更可能)。
"C"は、サーバ証明書の発行元として信頼しているCAの証明書であることを示す。
詳細はファイルから証明書をインポートを参照。
-x : 自己署名証明書。
-d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -S -n ca -s "CN=ca" -1 -2 -v 12 -t "C,C,C" -x -d /tmp Enter Password or Pin for "NSS Certificate DB": A random seed must be generated that will be used in the creation of your key. One of the easiest ways to create a random seed is to use the timing of keystrokes on a keyboard. To begin, type keys on the keyboard until this progress meter is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD! Continue typing until the progress meter is full: |鍵を生成するためランダムにキー入力(*で表示される)| Finished. Press enter to continue:(Enter) Generating key. This may take a few moments... 0 - Digital Signature 1 - Non-repudiation 2 - Key encipherment 3 - Data encipherment 4 - Key agreement 5 - Cert signing key 6 - CRL signing key Other to finish > 5 0 - Digital Signature 1 - Non-repudiation 2 - Key encipherment 3 - Data encipherment 4 - Key agreement 5 - Cert signing key 6 - CRL signing key Other to finish > 6 0 - Digital Signature 1 - Non-repudiation 2 - Key encipherment 3 - Data encipherment 4 - Key agreement 5 - Cert signing key 6 - CRL signing key Other to finish > 9 Is this a critical extension [y/N]? n Is this a CA certificate [y/N]? y Enter the path length constraint, enter to skip [<0 for unlimited path]: > 0 Is this a critical extension [y/N]? n
X.509v3拡張を付加しないと、システムによってはCA証明書として認識しない(Androidとか)。 その他のX.509v3拡張も付加可能だが、値の指定方法がわからない。 Authority Key IDとかSubject Key IDとか、自動生成してくれない?
秘密鍵の表示
鍵DBに格納された秘密鍵を表示する。
certutil -K -d /tmp/ -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -K -d /tmp/ certutil: Checking token "NSS Certificate DB" in slot "NSS User Private Key and Certificate Services" Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード < 0> rsa 9135b061216f24c2ee10c28b565dbc4c691df760 NSS Certificate DB:ca
証明書の表示
証明書DBに格納された証明書を表示する。
一覧表示。
certutil -L -d /tmp/ -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -L -d /tmp/
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
ca Cu,Cu,Cu
ニックネームを指定して詳細表示。
certutil -L -n ca -d /tmp/ -n : ニックネームを指定。 -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -L -n ca -d /tmp/
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
00:94:60:08:f4
Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption
Issuer: "CN=ca"
Validity:
Not Before: Wed May 11 13:45:19 2011
Not After : Fri May 11 13:45:19 2012
Subject: "CN=ca"
Subject Public Key Info:
Public Key Algorithm: PKCS #1 RSA Encryption
RSA Public Key:
Modulus:
bd:89:15:71:ec:a2:91:93:60:a9:a0:8f:68:c4:03:b6:
14:8e:63:86:5c:49:54:f1:b8:78:e8:62:4e:9d:26:78:
d7:ce:1f:d8:82:a3:51:85:af:19:bb:90:bd:15:d5:57:
a2:54:f7:ad:9b:b3:ca:63:29:e3:be:e5:7f:6c:c3:d2:
14:7a:be:e2:da:cf:f6:23:93:4d:49:db:25:df:4b:da:
f5:fc:a3:fb:f9:45:4f:f2:72:4b:e1:7e:72:ef:65:c3:
2f:47:fb:5e:68:90:d1:ee:db:56:a2:2d:da:0f:a1:a2:
62:b4:f6:89:d9:e7:e7:a0:e3:92:b2:21:84:67:d0:0f
Exponent: 65537 (0x10001)
Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption
Signature:
01:a3:b8:77:f4:fa:39:4b:ef:79:9b:06:20:4c:d9:37:
c9:94:ed:5f:97:51:6f:85:47:7c:67:6d:67:6e:d8:aa:
46:91:18:ad:43:f9:77:bc:f7:53:77:c8:bb:9c:07:18:
06:53:d4:0a:25:e6:34:bb:74:c0:ed:76:87:7b:7e:42:
9f:4c:9d:db:64:b1:8a:af:a8:17:81:8b:85:e2:b5:d1:
2d:da:f2:bb:34:dd:91:55:74:b2:cd:26:38:2c:9c:b6:
35:d8:ed:9f:85:0a:43:9e:7b:11:65:d8:5f:27:c5:8d:
c1:6d:a8:39:a5:05:f1:ce:8f:2b:2f:2f:76:d3:1d:d8
Fingerprint (MD5):
D4:8D:AC:BA:C0:E0:BF:79:32:33:C3:CC:FF:D0:79:92
Fingerprint (SHA1):
65:FA:A4:F6:E5:31:C0:EA:59:6B:54:69:43:ED:77:96:22:F0:9E:99
Certificate Trust Flags:
SSL Flags:
Valid CA
Trusted CA
User
Email Flags:
Valid CA
Trusted CA
User
Object Signing Flags:
Valid CA
Trusted CA
User
ニックネームを指定してテキスト(PEM)形式で表示。
certutil -L -n ca -a -d /tmp/ -n : ニックネームを指定。 -a : テキスト(PEM)形式で出力。 -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -L -n ca -a -d /tmp/
-----BEGIN CERTIFICATE-----
MIIBkTCB+6ADAgECAgUAlGAI9DANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDEwJj
YTAeFw0xMTA1MTExMzQ1MTlaFw0xMjA1MTExMzQ1MTlaMA0xCzAJBgNVBAMTAmNh
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9iRVx7KKRk2CpoI9oxAO2FI5j
hlxJVPG4eOhiTp0meNfOH9iCo1GFrxm7kL0V1VeiVPetm7PKYynjvuV/bMPSFHq+
4trP9iOTTUnbJd9L2vX8o/v5RU/yckvhfnLvZcMvR/teaJDR7ttWoi3aD6GiYrT2
idnn56DjkrIhhGfQDwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAAGjuHf0+jlL73mb
BiBM2TfJlO1fl1FvhUd8Z21nbtiqRpEYrUP5d7z3U3fIu5wHGAZT1Aol5jS7dMDt
dod7fkKfTJ3bZLGKr6gXgYuF4rXRLdryuzTdkVV0ss0mOCyctjXY7Z+FCkOeexFl
2F8nxY3Bbag5pQXxzo8rLy920x3Y
-----END CERTIFICATE-----
ユーザ証明書と秘密鍵の作成
ユーザの証明書と秘密鍵をまとめて作成する。 実際は、生成した秘密鍵を元にCSRを作成し、それにCAが署名をして証明書を作成して証明書DBにインポートするという一連の作業をまとめて実行している。
certutil -S -c ca -n userA -s "CN=userA" -v 12 -t "u,u,u" -d /tmp/
-c : 証明書を発行するCAのニックネームを指定。
-n : ニックネームを指定。
-s : 証明書の所有者を特定する情報を指定(CN=..., OU=...)。
-v : 証明書の有効期間を月単位で指定。
-t : 証明書の信頼性を指定(後から変更可能)。
"u"は、ユーザ証明書を示す。
詳細はファイルから証明書をインポートを参照。
-d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -S -c ca -n userA -s "CN=userA" -v 12 -t "u,u,u" -d /tmp/ Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード A random seed must be generated that will be used in the creation of your key. One of the easiest ways to create a random seed is to use the timing of keystrokes on a keyboard. To begin, type keys on the keyboard until this progress meter is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD! Continue typing until the progress meter is full: |鍵を生成するためランダムにキー入力(*で表示される)| Finished. Press enter to continue: (Enter) Generating key. This may take a few moments...
証明書と秘密鍵を見てみる。
[root@router2 ~]# certutil -L -d /tmp/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI userA u,u,u ca Cu,Cu,Cu [root@router2 ~]# certutil -L -n userA -d /tmp/ Certificate: Data: Version: 3 (0x2) Serial Number: 00:94:60:10:99 Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption Issuer: "CN=ca" Validity: Not Before: Wed May 11 14:02:21 2011 Not After : Fri May 11 14:02:21 2012 Subject: "CN=userA" Subject Public Key Info: Public Key Algorithm: PKCS #1 RSA Encryption RSA Public Key: Modulus: c0:65:3c:84:56:f5:d4:d3:b2:33:01:d8:a8:68:81:10: 57:80:68:70:44:01:6c:07:ab:22:f8:e9:39:01:8b:36: 96:1c:05:59:0f:fa:65:1d:0a:2d:b1:20:3e:8b:e2:66: 71:9b:8a:c8:c0:8e:4d:b5:28:4d:60:1a:0e:cf:8b:29: af:00:de:f4:b8:74:d3:db:77:cd:e5:58:73:a5:ec:40: ee:9a:a6:87:90:dc:1c:10:4d:67:2b:5c:f6:6c:f7:8f: 6e:03:66:96:96:0f:c3:89:b5:30:53:fb:70:0e:b9:35: ad:11:f3:fa:bc:3c:81:d4:5e:38:80:fb:87:65:14:8b Exponent: 65537 (0x10001) Signature Algorithm: PKCS #1 SHA-1 With RSA Encryption Signature: 96:fe:44:b5:59:c8:ec:fe:5d:86:40:49:e0:d0:02:00: 8e:9f:45:fc:26:d3:5f:d7:ee:2d:0c:7a:74:3f:d6:4c: c4:c9:ae:85:55:4e:4c:ec:dc:5e:19:82:3b:db:aa:46: ef:72:43:ad:bf:cc:0e:51:a1:3d:10:3e:0b:a7:c7:3c: a1:c7:3f:9d:b5:42:f6:ab:aa:4e:eb:1c:2f:1e:a8:51: 38:d5:6f:ee:4c:fa:f7:be:40:59:2a:b4:81:30:5a:f3: b8:84:80:3d:ae:9c:c9:2f:33:78:13:fc:77:28:c6:1f: 68:33:93:85:cb:eb:1c:33:72:d7:5c:97:e4:7a:18:13 Fingerprint (MD5): BD:3A:88:71:E7:C8:E4:B1:36:7B:DA:85:2E:4C:76:32 Fingerprint (SHA1): 5F:8F:CA:63:36:3D:67:25:86:7D:A2:28:FE:CF:4C:CA:E6:6E:18:79 Certificate Trust Flags: SSL Flags: User Email Flags: User Object Signing Flags: User [root@router2 ~]# certutil -K -d /tmp/ certutil: Checking token "NSS Certificate DB" in slot "NSS User Private Key and Certificate Services" Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード < 0> rsa 9135b061216f24c2ee10c28b565dbc4c691df760 NSS Certificate DB:ca < 1> rsa 6b9cf32f445b5cc2b08cf6712311f62acc105e38 NSS Certificate DB:userA
CSRと秘密鍵の作成
秘密鍵を生成して、それを元にCSRファイルを作成する。 CSRファイルは、CAに渡して証明書を発行してもらう。
certutil -R -s "CN=userB" -o /tmp/userB.csr -a -d /tmp/ -s : 証明書の所有者を特定する情報を指定(CN=..., OU=...)。 -o : 作成するCSRファイルを指定。 -a : テキスト(PEM)形式で作成。 指定しないとバイナリ(DER)形式で作成。 -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -R -s "CN=userB" -o /tmp/userB.csr -a -d /tmp/ Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード A random seed must be generated that will be used in the creation of your key. One of the easiest ways to create a random seed is to use the timing of keystrokes on a keyboard. To begin, type keys on the keyboard until this progress meter is full. DO NOT USE THE AUTOREPEAT FUNCTION ON YOUR KEYBOARD! Continue typing until the progress meter is full: |鍵を生成するためランダムにキー入力(*で表示される)| Finished. Press enter to continue: (Enter) Generating key. This may take a few moments...
CSRファイルを見てみる。
[root@router2 ~]# more /tmp/userB.csr
Certificate request generated by Netscape certutil
Phone: (not specified)
Common Name: userB
Email: (not specified)
Organization: (not specified)
State: (not specified)
Country: (not specified)
-----BEGIN NEW CERTIFICATE REQUEST-----
MIIBTzCBuQIBADAQMQ4wDAYDVQQDEwV1c2VyQjCBnzANBgkqhkiG9w0BAQEFAAOB
jQAwgYkCgYEAxwhAttOBFA9PgqiqcM6H888oVeoNqWb2cAENcVh9EZ8rZP+Cekri
/X0vjw03BDTRUtzoadOu1nprH5TrYKjss/oFKSCSl0+ItpTqGRW/yZMhsMWyFrSV
z5kwExrE37Mp2OUXD0k2dweIBgGFGD8sBG/kDCj8dmiZU/4YNC1UoBcCAwEAAaAA
MA0GCSqGSIb3DQEBBQUAA4GBALy0Al27hMSH+Y4F186W2TT1lWwrX4UavMno99vF
/X3wIzuPDX+ZIXId9WUKaPipLtew8uhqD7oelPiDvRztrFjdK9THN8TWmOaaC1Go
HZcJ9RCncyLaSIiqL3aI+jY9IDgNzVub5wvPXd0HfEwMInnPUfMLONsQKqDFoGfK
cQ9L
-----END NEW CERTIFICATE REQUEST-----
秘密鍵を見ると、鍵に対応する証明書が存在しないため「(orphan)」という表示になっている。 CAが発行した証明書を証明書DBにインポートすると、ニックネームが表示される。
[root@router2 ~]# certutil -K -d /tmp/ certutil: Checking token "NSS Certificate DB" in slot "NSS User Private Key and Certificate Services" Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード < 0> rsa f5a9d4e385aa36bd6018f4ec16bc6316d4472ca1 (orphan) < 1> rsa 9135b061216f24c2ee10c28b565dbc4c691df760 NSS Certificate DB:ca < 2> rsa 6b9cf32f445b5cc2b08cf6712311f62acc105e38 NSS Certificate DB:userA
CSRにサインして証明書ファイルを作成
CSRにサインして、証明書ファイルを作成する。 CAの秘密鍵でサインして証明書を発行するため、鍵DBのパスワード入力を求められる。 発行した証明書は、証明書DBに格納されない。
certutil -C -c ca -i /tmp/userB.csr -a -o /tmp/userB.pem -v 12 -d /tmp/ -c : 証明書を発行するCAのニックネームを指定。 -i : 読み込むCSRファイルを指定。 -a : CSRファイルがテキスト(PEM)形式の場合、指定。 指定しないとバイナリ(DER)形式。 -o : 作成する証明書ファイルを指定。 -v : 証明書の有効期間を月単位で指定。 -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -C -c ca -a -i /tmp/userB.csr -o /tmp/userB.pem -v 12 -d /tmp/ Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード
作成した証明書ファイルを見てみる。
[root@router2 ~]# more /tmp/userB.pem
-----BEGIN CERTIFICATE-----
MIIBlDCB/qADAgECAgUAlGAU8zANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDEwJj
YTAeFw0xMTA1MTExNDExNTRaFw0xMjA1MTExNDExNTRaMBAxDjAMBgNVBAMTBXVz
ZXJCMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDHCEC204EUD0+CqKpwzofz
zyhV6g2pZvZwAQ1xWH0Rnytk/4J6SuL9fS+PDTcENNFS3Ohp067WemsflOtgqOyz
+gUpIJKXT4i2lOoZFb/JkyGwxbIWtJXPmTATGsTfsynY5RcPSTZ3B4gGAYUYPywE
b+QMKPx2aJlT/hg0LVSgFwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAAzrTYXELllS
YukFlyBKs1Frq3DLVzWZqD4p+pLzEXidyBXUqgAJGCJAEAWLnzimxUpjlphf6oWl
iSoEn+P8zCVt1iuhH+FWHGPn78ykzqx9N4hFf0h5mMHRuqk8aP2s5Vbk9fl6Q9qr
586dTOMvYmENwkv9zydQcWqLGEl8IwLs
-----END CERTIFICATE-----
ファイルから証明書をインポート
ファイルから証明書をDBにインポートする。
certutil -A -n userB -i userB.pem -a -t "u,u,u" -d /tmp/
-n : ニックネームを指定。
-i : 読み込む証明書ファイルを指定。
-a : 証明書ファイルがテキスト(PEM)形式の場合、指定。 指定しないとバイナリ(DER)形式。
-t : 証明書の信頼性を指定(後から変更可能)。
カンマ区切りのひとつめがSSL、ふたつめがS/MIME、みっつめがコードサイニングにについての設定。
"CTu"のように複数指定することも可能。
p : 有効な証明書。
P : 信頼している証明書。
c : 有効なCA証明書。
T : クライアント証明書発行元として信頼しているCAの証明書(SSLのみ?)。
C : サーバ証明書発行元として信頼しているCAの証明書。
u : ペアとなる秘密鍵が存在する証明書。
証明書による認証と秘密鍵による署名が可能。
ペアとなる秘密鍵が存在しない証明書をインポートするときに指定しても無視される。
w : send warning
g : make step-up cert
-d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -A -n userB -i userB.pem -a -t "u,u,u" -d /tmp/
証明書をファイルにエクスポート
DBからファイルに証明書をエクスポートする。 テキスト(PEM)形式での証明書の表示とオプションは同じで、出力をファイルにリダイレクトする。
[root@router2 ~]# certutil -L -n ca -a -d /tmp/ > ca.pem
エクスポートした証明書ファイルを見てみる。
[root@router2 ~]# more /tmp/ca.pem
-----BEGIN CERTIFICATE-----
MIIBkTCB+6ADAgECAgUAlGAI9DANBgkqhkiG9w0BAQUFADANMQswCQYDVQQDEwJj
YTAeFw0xMTA1MTExMzQ1MTlaFw0xMjA1MTExMzQ1MTlaMA0xCzAJBgNVBAMTAmNh
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9iRVx7KKRk2CpoI9oxAO2FI5j
hlxJVPG4eOhiTp0meNfOH9iCo1GFrxm7kL0V1VeiVPetm7PKYynjvuV/bMPSFHq+
4trP9iOTTUnbJd9L2vX8o/v5RU/yckvhfnLvZcMvR/teaJDR7ttWoi3aD6GiYrT2
idnn56DjkrIhhGfQDwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAAGjuHf0+jlL73mb
BiBM2TfJlO1fl1FvhUd8Z21nbtiqRpEYrUP5d7z3U3fIu5wHGAZT1Aol5jS7dMDt
dod7fkKfTJ3bZLGKr6gXgYuF4rXRLdryuzTdkVV0ss0mOCyctjXY7Z+FCkOeexFl
2F8nxY3Bbag5pQXxzo8rLy920x3Y
-----END CERTIFICATE-----
証明書と秘密鍵をPKCS12形式でエクスポート
証明書と秘密鍵をまとめてPKCS12形式でエクスポートするときは、nss-toolsパッケージに含まれるpk12utilを使う。
pk12util -n ca -o /tmp/ca.p12 -d /tmp/ -n : ニックネームを指定。 -o : 出力するPKCS12形式ファイル -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# pk12util -n ca -o /tmp/ca.p12 -d /tmp/ Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード Enter password for PKCS12 file: 出力するPKCS12形式ファイルに設定するパスワード Re-enter password: 出力するPKCS12形式ファイルに設定するパスワード(再入力) pk12util: PKCS12 EXPORT SUCCESSFUL
PKCS12形式ファイルをインポート
PKCS12形式を証明書DBと鍵DBにインポートするときは、nss-toolsパッケージに含まれるpk12utilを使う。
pk12util -i /tmp/userZ.p12 -d /tmp/ -n : ニックネームを指定。 -i : 読み込むPKCS12形式ファイル -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# pk12util -i /tmp/userZ.p12 -d /tmp/ Enter Password or Pin for "NSS Certificate DB": 鍵DBのパスワード Enter password for PKCS12 file: PKCS12形式ファイルのパスワード
証明書の削除
証明書を削除する。
certutil -D -n userZ -d /tmp/ -n : ニックネームを指定。 -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -D -n userZ -d /tmp/
秘密鍵の削除
秘密鍵を削除する。 ペアの証明書も削除される?
certutil -F -n userZ -d /tmp/ -n : ニックネームを指定。 -d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -F -n userZ -d /tmp/
証明書の信頼性を変更
証明書の信頼性を変更する。
certutil -F -n userZ -d /tmp/
-n : ニックネームを指定。
-t : 証明書の信頼性を指定。
詳細はファイルから証明書をインポートを参照。
-d : データベースが存在するディレクトリを指定。
[root@router2 ~]# certutil -M -n userA -t "p,p,p" -d /tmp/
証明書の検証
証明書を検証する。 認証時に対向から提示される証明書が有効か検証するには、対向の証明書をDBにインポートすればよいのだと思う。
certutil -V -n userZ -d /tmp/ -u C
-n : ニックネームを指定。
詳細はファイルから証明書をインポートを参照。
-d : データベースが存在するディレクトリを指定。
-u : 証明書の使途を指定。
C : SSLクライアント証明書
V : SSLサーバ証明書
S : Email signer
R : Email Recipient
O : OCSP status responder
J : Object signer
証明書を発行したCAの証明書がDBにない場合。
[root@router2 ~]# certutil -L -d /tmp/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI ca Cu,Cu,Cu userZ ,, [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u C certutil: certificate is invalid: Peer's Certificate issuer is not recognized. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u V certutil: certificate is invalid: Peer's Certificate issuer is not recognized. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u S certutil: certificate is invalid: Peer's Certificate issuer is not recognized. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u R certutil: certificate is invalid: Peer's Certificate issuer is not recognized. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u O certutil: certificate is invalid: Certificate type not approved for application. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u J certutil: certificate is invalid: Certificate type not approved for application.
証明書を発行したCAの証明書が信頼されていない場合。
[root@router2 ~]# certutil -L -d /tmp/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI ca Cu,Cu,Cu otherCA c,c,c userZ ,, [root@router2 ~]# certutil -O -n userZ -d /tmp/ "otherCA" [CN=otherCA] "userZ" [CN=userZ] [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u C certutil: certificate is invalid: Peer's certificate issuer has been marked as not trusted by the user. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u V certutil: certificate is invalid: Peer's certificate issuer has been marked as not trusted by the user. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u S certutil: certificate is invalid: Peer's certificate issuer has been marked as not trusted by the user. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u R certutil: certificate is invalid: Peer's certificate issuer has been marked as not trusted by the user. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u O certutil: certificate is invalid: Certificate type not approved for application. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u J certutil: certificate is invalid: Certificate type not approved for application.
証明書を発行したCAの証明書が、サーバ証明書発行元として信頼されている場合。
[root@router2 ~]# certutil -L -d /tmp/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI ca Cu,Cu,Cu otherCA C,C,C userZ ,, [root@router2 ~]# certutil -O -n userZ -d /tmp/ "otherCA" [CN=otherCA] "userZ" [CN=userZ] [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u C certutil: certificate is invalid: Peer's certificate issuer has been marked as not trusted by the user. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u V certutil: certificate is valid [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u S certutil: certificate is valid [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u R certutil: certificate is valid [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u O certutil: certificate is invalid: Certificate type not approved for application. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u J certutil: certificate is invalid: Certificate type not approved for application.
証明書を発行したCAの証明書が、クライアント証明書発行元として信頼されている場合。
[root@router2 ~]# certutil -L -d /tmp/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI ca Cu,Cu,Cu userZ ,, otherCA T,C,C [root@router2 ~]# certutil -O -n userZ -d /tmp/ "otherCA" [CN=otherCA] "userZ" [CN=userZ] [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u C certutil: certificate is valid [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u V certutil: certificate is invalid: Peer's certificate issuer has been marked as not trusted by the user. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u S certutil: certificate is valid [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u R certutil: certificate is valid [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u O certutil: certificate is invalid: Certificate type not approved for application. [root@router2 ~]# certutil -V -n userZ -d /tmp/ -u J certutil: certificate is invalid: Certificate type not approved for application.