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.

自宅サーバの設定ー自己証明書サーバ

Posted at

自宅サーバのCentOS 8Stream で自己証明書サーバを起動させる
自宅にあるので、DNSはなし。
/etc/hostsでサーバ名解決。

利用しているWindowsからは、C:\Windows\System32\drivers\etc\hostsに
192.168.1.33 yyuu.local
の1行を記載

・秘密鍵作成

# openssl genrsa 2048 > localserver.key
Generating RSA private key, 2048 bit long modulus (2 primes)
..............................................................
..............................................................
...............................................+++++
....+++++
e is 65537 (0x010001)

・CSRの作成

# openssl req -new -key localserver.key > localserver.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:****
Locality Name (eg, city) [Default City]:***
Organization Name (eg, company) [Default Company Ltd]:yyuu
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:yyuu.local
Email Address []:

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:

・サーバ証明書作成

# openssl x509 -req -days 3650 -signkey localserver.key < localserver.csr >localserver.crt
Signature ok
subject=C = JP, ST = ****, L = ***, O = yyuu, CN = yyuu.local
Getting Private key

証明書の有効期限は10年(3650日)

# ls
localserver.crt  localserver.csr  localserver.key
# mv ssl.conf ssl.conforg
# cp vhost.conf vhost-ssl.conf

vhost-ssl.confを編集

# apachectl configtest
Syntax OK

ブラウザ越しでエラーになる

# telnet 192.168.1.33 443
Trying 192.168.1.33...
telnet: connect to address 192.168.1.33: Connection refused

443ポートで起動していないので、ログ確認

[Fri Jan 20 12:14:53.684895 2023] [ssl:warn] [pid 147249:tid 140078683593024] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]

443がないってことで、ssl.confにあった
Listen 443 https
がないのに気づき、ファイルを戻すして再起動。起動確認。

# mv ssl.conforg ssl.conf
# apachectl restart
# telnet 192.168.1.33 443
Trying 192.168.1.33...
Connected to 192.168.1.33.
Escape character is '^]'.
^CConnection closed by foreign host.

ブラウザ越しで確認
image.png

詳細設定からyyuu.localにアクセスする
image.png

image.png

localhost.localdomainなので、なんか違う?
ssl.confのほうにカギをいれてみる

# vi ssl.conf
SLCertificateFile /etc/ssl/localhost/localserver.crt
SSLCertificateKeyFile /etc/ssl/localhost/localserver.key

# apachectl restart

とりあえず、成功
image.png

ローカルで使うのにアラートがでるので、それを消すため証明書をエクスポート
image.png

エクスポートしたファイルをダブルクリックして「詳細」タブから「ファイルにコピー」
image.png
image.png
cerでエクスポート
image.png

エクスポート完了のダイアログがでれば完了。

Chromeの設定-詳細設定を開いて「プライバシーとセキュリティ」を」クリック。
「セキュリティ」をクリック
「デバイス証明書の管理」をクリック
image.png

インポートをクリック。
image.png

image.png

image.png

]# openssl pkcs12 -export -inkey localserver.key -in localserver.crt -out localserver.pfx
Enter Export Password:
Verifying - Enter Export Password:
image.png
image.png
image.png
image.png
image.png

いろいろ証明書をインポートしてみたがwindows11ではうまくいかなかったので、一旦終了。
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?