質問するログイン新規登録

質問編集履歴

5

修正

2019/07/01 09:07

投稿

Take_it
Take_it

スコア357

title CHANGED
File without changes
body CHANGED
@@ -97,7 +97,7 @@
97
97
  ```
98
98
  [root@****** ~]# curl -v --cacert /etc/pki/CA/cacert.pem --key ./newkey.pem --cert ./newcert.pem https://******.com
99
99
  * About to connect() to vps.******.com port 443 (#0)
100
- * Trying 150.95.184.243...
100
+ * Trying **.**.**.**...
101
101
  * Connected to vps.******.com (**.**.**.**) port 443 (#0)
102
102
  * Initializing NSS with certpath: sql:/etc/pki/nssdb
103
103
  * CAfile: /etc/pki/CA/cacert.pem

4

頂いたアドバイスを試行しその結果を追記しました。

2019/07/01 09:07

投稿

Take_it
Take_it

スコア357

title CHANGED
File without changes
body CHANGED
@@ -77,4 +77,34 @@
77
77
  [root@******* ~]# openssl x509 -noout -subject -in /etc/pki/CA/certs/*********.crt
78
78
  subject= /C=JP/ST=*****/L=******/O=********/CN=*********/emailAddress=****@****.com
79
79
  ```
80
- これは正常に動いているようなので、sed以下の部分なんですが・・・正規表現?よくわかりません。。
80
+ これは正常に動いているようなので、sed以下の部分なんですが・・・正規表現?よくわかりません。。
81
+
82
+ ####htpasswd生成成功
83
+
84
+ 頂いたアドバイスに従い、
85
+ ```
86
+ htpasswd -bm /etc/httpd/conf/.htpasswd "/C=JP/ST=*****/L=******/O=********/CN=*********/emailAddress=****@****.com" password
87
+ ```
88
+ で.htpasswdの生成に成功しましたが、証明書を読み込むとエラーで接続できません。
89
+
90
+ ####クライアント証明書の verify
91
+ ```
92
+ [root@****** ~]# openssl verify -CAfile /etc/pki/CA/cacert.pem ./newcert.pem
93
+ ./newcert.pem: OK
94
+ ```
95
+
96
+ ####curl コマンドでクライアント証明書認証
97
+ ```
98
+ [root@****** ~]# curl -v --cacert /etc/pki/CA/cacert.pem --key ./newkey.pem --cert ./newcert.pem https://******.com
99
+ * About to connect() to vps.******.com port 443 (#0)
100
+ * Trying 150.95.184.243...
101
+ * Connected to vps.******.com (**.**.**.**) port 443 (#0)
102
+ * Initializing NSS with certpath: sql:/etc/pki/nssdb
103
+ * CAfile: /etc/pki/CA/cacert.pem
104
+ CApath: none
105
+ * unable to load client key: -8178 (SEC_ERROR_BAD_KEY)
106
+ * NSS error -8178 (SEC_ERROR_BAD_KEY)
107
+ * Peer's public key is invalid.
108
+ * Closing connection 0
109
+ curl: (58) unable to load client key: -8178 (SEC_ERROR_BAD_KEY)
110
+ ```

3

追加検証結果をさらに追記

2019/07/01 09:06

投稿

Take_it
Take_it

スコア357

title CHANGED
File without changes
body CHANGED
@@ -61,7 +61,7 @@
61
61
  On other systems than Windows and NetWare the '-p' flag will probably not work.
62
62
  The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.
63
63
  ```
64
- なお、
64
+ ####htpasswdコマンド
65
65
  ```
66
66
  [root@******* ~]# htpasswd -bcm /etc/httpd/conf/.htpasswd hoge hogehoge
67
67
  Adding password for user hoge
@@ -70,5 +70,11 @@
70
70
  ```
71
71
  `openssl x509 -noout -subject -in /etc/pki/CA/certs/********.crt |sed -e 's/subject= ([^ ]*)/\1/p' -e d` password
72
72
  ```
73
- この部分が原因なんだろううのでが・・・
73
+ この部分が原因と思われま
74
+
75
+ ####opensslコマンド
76
+ ```
77
+ [root@******* ~]# openssl x509 -noout -subject -in /etc/pki/CA/certs/*********.crt
74
- /etc/pki/CA/certs/********.crt が確かに存在していることは確認済みです。
78
+ subject= /C=JP/ST=*****/L=******/O=********/CN=*********/emailAddress=****@****.com
79
+ ```
80
+ これは正常に動いているようなので、sed以下の部分なんですが・・・正規表現?よくわかりません。。

2

追加で確認した事項を追記

2019/07/01 01:51

投稿

Take_it
Take_it

スコア357

title CHANGED
File without changes
body CHANGED
@@ -60,4 +60,15 @@
60
60
  -v Verify password for the specified user.
61
61
  On other systems than Windows and NetWare the '-p' flag will probably not work.
62
62
  The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.
63
- ```
63
+ ```
64
+ なお、
65
+ ```
66
+ [root@******* ~]# htpasswd -bcm /etc/httpd/conf/.htpasswd hoge hogehoge
67
+ Adding password for user hoge
68
+ ```
69
+ これは普通に通りましたので、
70
+ ```
71
+ `openssl x509 -noout -subject -in /etc/pki/CA/certs/********.crt |sed -e 's/subject= ([^ ]*)/\1/p' -e d` password
72
+ ```
73
+ この部分が原因なんだろうとは思うのですが・・・
74
+ /etc/pki/CA/certs/********.crt が確かに存在していることは確認済みです。

1

AllowOverrideにより制限は有効になりましたが証明書を用いたアクセスができません。

2019/07/01 01:36

投稿

Take_it
Take_it

スコア357

title CHANGED
File without changes
body CHANGED
@@ -11,4 +11,53 @@
11
11
  ConoHa VPS
12
12
  CentOS Linux 7.6.1810
13
13
  Apache/2.4.6 (CentOS)
14
- Let's Encryptを使用してhttpsでのアクセスは確立済。
14
+ Let's Encryptを使用してhttpsでのアクセスは確立済。
15
+
16
+ ### AllowOverride をしました。
17
+ etc/httpd/conf/httpd.conf を編集し、
18
+
19
+ <Directory "/var/www/html">のAllowOverrideをNoneからAllにしたところ、証明書を要求するとこまではいきました。
20
+
21
+ しかし正しい証明書を選択しているはずなのにアクセスできず、
22
+
23
+ このサイトは安全に接続できません
24
+ vps.*****.com でログイン証明書が承認されなかったか、ログイン証明書が提示されていない可能性があります。
25
+ システム管理者にお問い合わせください。
26
+
27
+ となります。
28
+
29
+ 原因として、AllowOverrideについてご指摘頂く前に見ていたのですが、
30
+ ```
31
+ BASIC認証用ユーザーデータベース(例:/etc/httpd/conf/.htpasswd)がない場合=1件目の場合
32
+ [root@centos ~]# htpasswd -bcm /etc/httpd/conf/.htpasswd `openssl x509 -noout -subject -in /etc/pki/CA/certs/ユーザー名.crt |sed -e 's/subject= ([^ ]*)/\1/p' -e d` password ← クライアント証明書をBASIC認証用ユーザーデータベース(例:/etc/httpd/conf/.htpasswd)へ登録
33
+
34
+ BASIC認証用ユーザーデータベース(例:/etc/httpd/conf/.htpasswd)がある場合=2件目以降の場合
35
+ [root@centos ~]# htpasswd -bm /etc/httpd/conf/.htpasswd `openssl x509 -noout -subject -in /etc/pki/CA/certs/ユーザー名.crt |sed -e 's/subject= ([^ ]*)/\1/p' -e d` password ← クライアント証明書をBASIC認証用ユーザーデータベース(例:/etc/httpd/conf/.htpasswd)へ登録
36
+ ```
37
+ この部分がうまくいっていない気がします。
38
+ -bcmのほうでやっても.htpasswdは作成されず、一旦空の.htpasswdを作成してから-bmで行っても空のままです。
39
+ その際に表示されるエラー?メッセージは下記です。
40
+ ```
41
+ [root@******* ~]# htpasswd -bcm /etc/httpd/conf/.htpasswd `openssl x509 -noout -subject -in /etc/pki/CA/certs/********.crt |sed -e 's/subject= ([^ ]*)/\1/p' -e d` password
42
+ Usage:
43
+ htpasswd [-cimBdpsDv] [-C cost] passwordfile username
44
+ htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password
45
+
46
+ htpasswd -n[imBdps] [-C cost] username
47
+ htpasswd -nb[mBdps] [-C cost] username password
48
+ -c Create a new file.
49
+ -n Don't update file; display results on stdout.
50
+ -b Use the password from the command line rather than prompting for it.
51
+ -i Read password from stdin without verification (for script usage).
52
+ -m Force MD5 encryption of the password (default).
53
+ -B Force bcrypt encryption of the password (very secure).
54
+ -C Set the computing time used for the bcrypt algorithm
55
+ (higher is more secure but slower, default: 5, valid: 4 to 31).
56
+ -d Force CRYPT encryption of the password (8 chars max, insecure).
57
+ -s Force SHA encryption of the password (insecure).
58
+ -p Do not encrypt the password (plaintext, insecure).
59
+ -D Delete the specified user.
60
+ -v Verify password for the specified user.
61
+ On other systems than Windows and NetWare the '-p' flag will probably not work.
62
+ The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.
63
+ ```