リモートアクセスVPNゲートウェイ:OpenSSLを使った自己署名証明書作成手順(Widnows)
WindowsOSにおいて、OpenSSLを使って自己署名証明書を作成する手順です。
構成
リモートアクセスVPNゲートウェイに設定する各種証明書をOpenSSLで作成します。
本ドキュメントはWindows 11 を利用した手順になります。
手順環境
バージョン | |
---|---|
Windows | 11 |
OpenSSL | 3.5.2 |
PowerShell | 5.1.26100.6584 |
注意事項
- 本手順ではサーバー証明書およびクライアント証明書を同一のCA証明書で署名します。
サーバー証明書とクライアント証明書でCA証明書を分けるには、作業用ディレクトリを分けて作業を実施してください。
事前準備
OpenSSL インストール
以下のいずれかの方法でインストールします。
wingetを利用:
> winget install --id ShiningLight.OpenSSL.Light -e --accept-package-agreements --accept-source-agreements
Chocolateyを利用:
> Set-ExecutionPolicy Bypass -Scope Process -Force > [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 > Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) > choco install openssl.light -y
公式インストーラを利用:
- 公式のダウンロードページ より、
Win64 OpenSSL v3.X.X Light
のMISをダウンロードする。 - ダウンロードしたファイルを実行し、指示に従ってインストールする。
- 公式のダウンロードページ より、
opensslコマンドを実行できるように、PATHへ実行ファイルのパスを追加
> $env:Path = 'C:\Program Files\OpenSSL-Win64\bin;' + $env:Path
バージョン確認
> openssl version -a
ディレクトリ初期化
> $PKI_ROOT = 'C:\PKI' > $dirs = @( $PKI_ROOT (Join-Path $PKI_ROOT 'private') (Join-Path $PKI_ROOT 'certs') (Join-Path $PKI_ROOT 'csr') (Join-Path $PKI_ROOT 'newcerts') (Join-Path $PKI_ROOT 'crl') ) > $dirs | ForEach-Object { New-Item -ItemType Directory -Force -Path $_ | Out-Null } > New-Item -ItemType File -Force -Path (Join-Path $PKI_ROOT 'index.txt') | Out-Null '1000' | Out-File (Join-Path $PKI_ROOT 'serial') -Encoding ascii -NoNewline '1000' | Out-File (Join-Path $PKI_ROOT 'crlnumber') -Encoding ascii -NoNewline > Set-Location $PKI_ROOT
CA証明書の作成方法
作成手順
設定ファイル
openssl_ca.cnf
を作成
以下は作成例となります。[ ca ] default_ca = my_ca [ my_ca ] dir = C:/PKI certs = $dir/certs crl_dir = $dir/crl new_certs_dir = $dir/newcerts database = $dir/index.txt serial = $dir/serial crlnumber = $dir/crlnumber private_key = $dir/private/ca.key certificate = $dir/ca.crt crl = $dir/crl/crl.pem default_md = sha256 default_days = 3650 default_crl_days = 30 policy = policy_loose unique_subject = no x509_extensions = server_ext crl_extensions = crl_ext copy_extensions = copy [ policy_loose ] countryName = optional stateOrProvinceName = optional localityName = optional organizationName = optional organizationalUnitName = optional commonName = supplied emailAddress = optional [ req ] default_bits = 2048 default_md = sha256 prompt = yes distinguished_name = req_distinguished_name string_mask = utf8only [ req_distinguished_name ] C = JP ST = Tokyo L = Chiyoda O = ExampleCorp OU = IT CN = <== コモンネームを入力 [ v3_ca ] subjectKeyIdentifier=hash authorityKeyIdentifier=keyid:always,issuer basicConstraints = critical, CA:true keyUsage = critical, cRLSign, keyCertSign [ server_ext ] subjectKeyIdentifier=hash authorityKeyIdentifier=keyid,issuer basicConstraints = CA:false keyUsage = critical, digitalSignature, keyEncipherment extendedKeyUsage = serverAuth, clientAuth subjectAltName = @alt_names [ client_ext ] subjectKeyIdentifier=hash authorityKeyIdentifier=keyid,issuer basicConstraints = CA:false keyUsage = critical, digitalSignature, keyEncipherment extendedKeyUsage = clientAuth [ alt_names ] DNS.1 = server.local DNS.2 = server.example.internal [ crl_ext ] authorityKeyIdentifier=keyid:always
CA証明書の作成
PS C:\PKI> openssl genrsa -aes256 -out .\private\ca.key 2048 Generating RSA private key, 2048 bit long modulus ........................................+++++ ............+++++ Enter pass phrase for .\private\ca.key: ******** Verifying - Enter pass phrase for .\private\ca.key: ******** PS C:\PKI> openssl req -config .\openssl_ca.cnf -new -x509 -days 3650 -extensions v3_ca -key .\private\ca.key -out .\ca.crt Country Name (2 letter code) [JP]: JP <== 国を指定(Enterキー入力) State or Province Name (full name) [Tokyo]: Tokyo <== 都道府県を指定(Enterキー入力) Locality Name (eg, city) [Chiyoda]: Chiyoda <== 市区町村を入力(Enterキー入力) Organization Name (eg, company) [ExampleCorp]: ExampleCorp <== 組織を入力(Enterキー入力) Organizational Unit Name (eg, section) [IT]: IT <== 部門を入力(Enterキー入力) Common Name (eg, fully qualified host name) []: Example Root CA <== コモンネームを入力 Email Address []: <== E-Mail アドレスを入力(Enterキー入力) PS C:\PKI> openssl x509 -in .\ca.crt -noout -subject -dates subject= /C=JP/ST=Tokyo/L=Chiyoda/O=ExampleCorp/OU=IT/CN=Example Root CA notBefore=YYYYMMDDHHMMSSZ notAfter=YYYYMMDDHHMMSSZ
以下のファイルが存在するか確認する
CA証明書 C:\PKI\ca.crt CA秘密鍵 C:\PKI\private\ca.key
サーバー証明書の作成方法
作成手順
サーバー証明書署名要求の作成
PS C:\PKI> openssl genrsa -out .\private\server.key 2048 Generating RSA private key, 2048 bit long modulus ............................+++++ ............+++++ PS C:\PKI> openssl req -new -key .\private\server.key -out .\csr\server.sample.csr -config .\openssl_ca.cnf Country Name (2 letter code) [JP]: JP <== 国を指定(Enterキー入力) State or Province Name (full name) [Tokyo]: Tokyo <== 都道府県を指定(Enterキー入力) Locality Name (eg, city) [Chiyoda]: Chiyoda <== 市区町村を入力(Enterキー入力) Organization Name (eg, company) [ExampleCorp]: ExampleCorp <== 組織を入力(Enterキー入力) Organizational Unit Name (eg, section) [IT]: IT <== 部門を入力(Enterキー入力) Common Name (eg, fully qualified host name) []: server.sample.local <== コモンネームを入力 Email Address []: <== E-Mail アドレスを入力(Enterキー入力)
署名
> openssl ca -config .\openssl_ca.cnf -in .\csr\server.sample.csr -out .\certs\server.sample.crt -extensions server_ext -batch -days 825 > openssl verify -CAfile .\ca.crt .\certs\server.sample.crt
以下のファイルが存在するか確認する
サーバー証明書 C:\PKI\certs\server.sample.crt サーバー秘密鍵 C:\PKI\private\server.key
クライアント証明書の作成方法
作成手順
クライアント証明書署名要求の作成
PS C:\PKI> openssl genrsa -out .\private\client.key 2048 Generating RSA private key, 2048 bit long modulus ............................+++++ ............+++++ PS C:\PKI> openssl req -new -key .\private\client.key -out .\csr\client.sample.csr -config .\openssl_ca.cnf Country Name (2 letter code) [JP]: JP <== 国を指定(Enterキー入力) State or Province Name (full name) [Tokyo]: Tokyo <== 都道府県を指定(Enterキー入力) Locality Name (eg, city) [Chiyoda]: Chiyoda <== 市区町村を入力(Enterキー入力) Organization Name (eg, company) [ExampleCorp]: ExampleCorp <== 組織を入力(Enterキー入力) Organizational Unit Name (eg, section) [IT]: Users <== 部門を入力(Enterキー入力) Common Name (eg, fully qualified host name) []: client.sample.local <== コモンネームを入力 Email Address []: <== E-Mail アドレスを入力(Enterキー入力)
署名および PKCS#12 作成
> openssl ca -config .\openssl_ca.cnf -in .\csr\client.sample.csr -out .\certs\client.sample.crt -extensions client_ext -batch -days 825 > openssl pkcs12 -export -inkey .\private\client.key -in .\certs\client.sample.crt -certfile .\ca.crt -out .\certs\client.sample.p12
以下のファイルが存在するか確認する
クライアント証明書 C:\PKI\certs\client.sample.crt クライアント秘密鍵 C:\PKI\private\client.key PKCS#12 (配布用) C:\PKI\certs\client.sample.p12
確認手順
証明書の確認手順
証明書 (crt ファイル) は以下のコマンドで内容を表示して確認します。
PS >openssl x509 -in <crtファイル>
例: クライアント証明書を表示する場合
PS C:\PKI> openssl x509 -in .\certs\client.sample.crt
-----BEGIN CERTIFICATE-----
xxxxx...
...........................
...xxxxxx
-----END CERTIFICATE-----
秘密鍵の確認手順
PS > type <keyファイル>
※ PowerShellではGet-Content
/cat
でも可能です。
例: サーバー秘密鍵を表示する場合
PS C:\PKI> type .\private\server.key
-----BEGIN PRIVATE KEY-----
xxxxx...
...........................
...xxxxxx
-----END PRIVATE KEY-----
証明書アップロード
下記手順を参考に、表示された証明書や秘密鍵をコントロールパネルからアップロードします。
client.sample.crtをアップロードしエラーになったら、確認手順で表示された-----BEGIN xxx-----
から-----END xxx-----
までをコピーしてテキストボックスへ張り付けてください。
アップロード時に、以下を確認してください。
-----BEGIN xxx-----
と-----END xxx-----
の組み合わせが1つだけであること- 証明書や証明書署名要求、秘密鍵など異なる種類の
BEGIN
やEND
が連結されていないこと
フィードバック
サービス利用中のトラブルは、ニフクラサポート窓口にお願いします。
お役に立ちましたか?