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?

【超簡単】検証用に有効期限切れのクライアント証明書をつくりたい

Last updated at Posted at 2025-04-24

前提

Linux環境(Ubuntu22.04)を想定しています(が、WindowsやMacでもほぼ同様の手順です)

手順

1.OpenSSLのダウンロード

まずはOpenSSLをダウンロードします。ソースコードはOpenSSLサイトからダウンロード可能です。
以下のコマンドを上から順番に実行していきます。

wget https://www.openssl.org/source/openssl-3.0.9.tar.gz

tar -xzf openssl-3.0.9.tar.gz

cd openssl-3.0.9

2.OpenSSLのインストール

続いてOpenSSLをインストールしていきます。
以下のコマンドを上から順番に実行していきます。

./Configure '-Wl,-rpath,$(LIBRPATH)'

make

make install

正しくインストールが完了している場合、以下のコマンドを実行すると正しくバージョン情報を取得することができます。

openssl version -a

image.png

3.認証局用の秘密鍵と証明書の作成

以降の処理はこちらの記事を参考にしています。オプションの説明などの詳細に関してはそちらをご参照ください。

以下のコマンドを実行して認証局用の秘密鍵と証明書を作成します。

$ openssl req -x509 -new \
              -newkey rsa:2048 -keyout rootCA.key -nodes \
              -sha256 \
              -days 3650 \
              -out rootCA.crt \
              -subj "/C=JP/O=example.com/CN=EXAMPLE PKI ROOT"

4.クライアント証明書用の秘密鍵と署名要求を作成

以下のコマンドを実行してクライアント証明書用の秘密鍵と署名要求を作成します。

openssl req -newkey rsa:2048 -keyout expired-client.key -nodes -out expired-client.csr \
              -subj "/C=JP/O=example.com/CN=CLIENT"

5.認証局用の秘密鍵と証明書でクライアント証明書の署名要求に署名

以下のコマンドを実行してクライアント証明書用の秘密鍵と署名要求に署名します。
その際、有効期限を1日前に指定します。

 openssl x509 -req \
               -in expired-client.csr \
               -CA rootCA.crt -CAkey rootCA.key -CAcreateserial \
               -sha256 \
               -days -1 \ // 有効期限を一日前に指定
               -out expired-client.crt 

6.確認

以下のコマンドで作成したクライアント証明書の有効期限を確認することができます。

openssl x509 -in expired-client.crt -noout -dates

有効期限切れのクライアント証明書が作成できました!

image.png

参考

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?