0
1

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 3 years have passed since last update.

OpenSSL 証明書作成 with 中間CA

Last updated at Posted at 2021-02-06

ルートCA・中間CAまで含めたオレオレ証明書を作りたくなった時の備忘。多分動くと思う。

ルートCAの建造

mkdir -p /etc/pki/CA/newcerts
touch /etc/pki/CA/index.txt
echo 01 > /etc/pki/CA/serial

opensslがどうしても作業環境に依存してしまうため、最低限作業場所を整える。
Centos8の場合はこれだけやっとけば諸々生成できるようになった。SHAとかの細かい設定はしらんです。

署名時にindex.txtとの突合して同名の証明書定義あるとエラー出るっぽいので

:> /etc/pki/CA/index.txt

を思い立ったタイミングで実行してきれいにしておく。

ルートCA証明書・鍵の作成

openssl req -new -keyout rootCA.key -out rootCA.csr
openssl x509 -req -days 9999 -signkey rootCA.key -in rootCA.csr -out rootCA.crt

以下を生成。-days XXXXで有効な日数を指定。ルートなので長いほうがよさそう。

  • ルートCA鍵:rootCA.key
  • ルートCA証明書要求:rootCA.csr
  • ルートCA証明書:rootCA.crt

実行時の以下入力欄は証明書に署名する時必須っぽいので、さぼらずに記入すること。

  • Country (国名)
  • State (都道府県名)
  • Locality (市区町村名)
  • Organizational Name (組織名)
  • Organizational Unit (部門名)
  • Common Name (コモンネーム)

-subj "/C=JP/ST=Tokyo/L=hoge/O=fuga/OU=piyo/CN=moge"みたいな形で実行時オプションとしても定義可能。

中間CA証明書の作成

openssl req -new -keyout midCA.key -out midCA.csr
openssl ca -days 9999 -keyfile rootCA.key -cert rootCA.crt -in midCA.csr -out midCA.crt

中間CAはさみたくない場合はこれをそのまま証明書として利用しちゃえばよさそう。

証明書の作成

openssl req -new -keyout myCert.key -out myCert.csr
openssl ca -days 9999 -keyfile midCA.key -cert midCA.crt -in myCert.csr -out myCert.crt

中間CAで署名して証明書を作成。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?