0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Root CAとサーバ証明書、クライアント証明書を作る

Last updated at Posted at 2022-02-23

オレオレ証明書を作るときのメモ書き。
途中の入力項目は省略。(あちこちのサイトに書いてあるので、気になる方はそちらでお探しください)

準備

各種作業ディレクトリを作る。

mkdir ca server client

Root CA

$ cd ca
$ mkdir -p demoCA/{certs,newcerts}
$ touch demoCA/index.txt
$ echo '00' > demoCA/serial
$ find .
ca/
ca/demoCA
ca/demoCA/newcerts
ca/demoCA/serial
ca/demoCA/index.txt
ca/demoCA/certs
$ openssl genrsa 2048 > ca.key
$ openssl req -new -key ./ca.key -sha256 -out ca.csr
$ openssl x509 -days 3650 -in ca.csr -req -signkey ca.key -out ca.crt

ca/ca.key がCAの秘密鍵、 ca/ca.crt がオレオレRoot証明書になる。

サーバ証明書

$ cd server
$ openssl genrsa 2048 > server.key
$ openssl req -new -key server.key -sha256 -out server.csr
$ cd ../ca
$ openssl x509 -req -in ../server/server.csr -out ../server/server.crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 3650 -sha256

server/server.key がサーバの秘密鍵、server/server.crt がサーバ証明書になる。
Common Name(CN)に対象のDNSドメインを記載すること。

クライアント証明書

$ cd client
$ openssl genrsa 2048 > client.key
$ openssl req -new -key client.key -out client.csr
$ cd ../ca
$ openssl x509 -req -in ../client/client.csr -out ../client/client.crt -CA ca.crt -CAkey ca.key -CAcreateserial -days 3650 -sha256

client/client.key がクライアントの秘密鍵、client/client.crt がクライアント証明書になる。
サーバ証明書の作成手順と同じ。

その他

PKCS #12にまとめる

クライアントの証明書 + 秘密鍵をローカル環境に導入するときに使ったりする。

$ openssl pkcs12 -export -in client.crt -inkey client.key -out client.p12

つぶやき

本当は openssl.cnf をちゃんと書くべき。証明書作成は難しい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?