質問編集履歴

5

修正

2019/07/01 09:07

投稿

Take_it
Take_it

スコア357

test CHANGED
File without changes
test CHANGED
@@ -196,7 +196,7 @@
196
196
 
197
197
  * About to connect() to vps.******.com port 443 (#0)
198
198
 
199
- * Trying 150.95.184.243...
199
+ * Trying **.**.**.**...
200
200
 
201
201
  * Connected to vps.******.com (**.**.**.**) port 443 (#0)
202
202
 

4

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

2019/07/01 09:07

投稿

Take_it
Take_it

スコア357

test CHANGED
File without changes
test CHANGED
@@ -157,3 +157,63 @@
157
157
  ```
158
158
 
159
159
  これは正常に動いているようなので、sed以下の部分なんですが・・・正規表現?よくわかりません。。
160
+
161
+
162
+
163
+ ####htpasswd生成成功
164
+
165
+
166
+
167
+ 頂いたアドバイスに従い、
168
+
169
+ ```
170
+
171
+ htpasswd -bm /etc/httpd/conf/.htpasswd "/C=JP/ST=*****/L=******/O=********/CN=*********/emailAddress=****@****.com" password
172
+
173
+ ```
174
+
175
+ で.htpasswdの生成に成功しましたが、証明書を読み込むとエラーで接続できません。
176
+
177
+
178
+
179
+ ####クライアント証明書の verify
180
+
181
+ ```
182
+
183
+ [root@****** ~]# openssl verify -CAfile /etc/pki/CA/cacert.pem ./newcert.pem
184
+
185
+ ./newcert.pem: OK
186
+
187
+ ```
188
+
189
+
190
+
191
+ ####curl コマンドでクライアント証明書認証
192
+
193
+ ```
194
+
195
+ [root@****** ~]# curl -v --cacert /etc/pki/CA/cacert.pem --key ./newkey.pem --cert ./newcert.pem https://******.com
196
+
197
+ * About to connect() to vps.******.com port 443 (#0)
198
+
199
+ * Trying 150.95.184.243...
200
+
201
+ * Connected to vps.******.com (**.**.**.**) port 443 (#0)
202
+
203
+ * Initializing NSS with certpath: sql:/etc/pki/nssdb
204
+
205
+ * CAfile: /etc/pki/CA/cacert.pem
206
+
207
+ CApath: none
208
+
209
+ * unable to load client key: -8178 (SEC_ERROR_BAD_KEY)
210
+
211
+ * NSS error -8178 (SEC_ERROR_BAD_KEY)
212
+
213
+ * Peer's public key is invalid.
214
+
215
+ * Closing connection 0
216
+
217
+ curl: (58) unable to load client key: -8178 (SEC_ERROR_BAD_KEY)
218
+
219
+ ```

3

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

2019/07/01 09:06

投稿

Take_it
Take_it

スコア357

test CHANGED
File without changes
test CHANGED
@@ -124,7 +124,7 @@
124
124
 
125
125
  ```
126
126
 
127
- なお、
127
+ ####htpasswdコマンド
128
128
 
129
129
  ```
130
130
 
@@ -142,6 +142,18 @@
142
142
 
143
143
  ```
144
144
 
145
- この部分が原因なんだろううのでが・・・
145
+ この部分が原因と思われま
146
146
 
147
+
148
+
149
+ ####opensslコマンド
150
+
151
+ ```
152
+
153
+ [root@******* ~]# openssl x509 -noout -subject -in /etc/pki/CA/certs/*********.crt
154
+
147
- /etc/pki/CA/certs/********.crt が確かに存在していることは確認済みです。
155
+ subject= /C=JP/ST=*****/L=******/O=********/CN=*********/emailAddress=****@****.com
156
+
157
+ ```
158
+
159
+ これは正常に動いているようなので、sed以下の部分なんですが・・・正規表現?よくわかりません。。

2

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

2019/07/01 01:51

投稿

Take_it
Take_it

スコア357

test CHANGED
File without changes
test CHANGED
@@ -123,3 +123,25 @@
123
123
  The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.
124
124
 
125
125
  ```
126
+
127
+ なお、
128
+
129
+ ```
130
+
131
+ [root@******* ~]# htpasswd -bcm /etc/httpd/conf/.htpasswd hoge hogehoge
132
+
133
+ Adding password for user hoge
134
+
135
+ ```
136
+
137
+ これは普通に通りましたので、
138
+
139
+ ```
140
+
141
+ `openssl x509 -noout -subject -in /etc/pki/CA/certs/********.crt |sed -e 's/subject= ([^ ]*)/\1/p' -e d` password
142
+
143
+ ```
144
+
145
+ この部分が原因なんだろうとは思うのですが・・・
146
+
147
+ /etc/pki/CA/certs/********.crt が確かに存在していることは確認済みです。

1

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

2019/07/01 01:36

投稿

Take_it
Take_it

スコア357

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,101 @@
25
25
  Apache/2.4.6 (CentOS)
26
26
 
27
27
  Let's Encryptを使用してhttpsでのアクセスは確立済。
28
+
29
+
30
+
31
+ ### AllowOverride をしました。
32
+
33
+ etc/httpd/conf/httpd.conf を編集し、
34
+
35
+
36
+
37
+ <Directory "/var/www/html">のAllowOverrideをNoneからAllにしたところ、証明書を要求するとこまではいきました。
38
+
39
+
40
+
41
+ しかし正しい証明書を選択しているはずなのにアクセスできず、
42
+
43
+
44
+
45
+ このサイトは安全に接続できません
46
+
47
+ vps.*****.com でログイン証明書が承認されなかったか、ログイン証明書が提示されていない可能性があります。
48
+
49
+ システム管理者にお問い合わせください。
50
+
51
+
52
+
53
+ となります。
54
+
55
+
56
+
57
+ 原因として、AllowOverrideについてご指摘頂く前に見ていたのですが、
58
+
59
+ ```
60
+
61
+ BASIC認証用ユーザーデータベース(例:/etc/httpd/conf/.htpasswd)がない場合=1件目の場合
62
+
63
+ [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)へ登録
64
+
65
+
66
+
67
+ BASIC認証用ユーザーデータベース(例:/etc/httpd/conf/.htpasswd)がある場合=2件目以降の場合
68
+
69
+ [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)へ登録
70
+
71
+ ```
72
+
73
+ この部分がうまくいっていない気がします。
74
+
75
+ -bcmのほうでやっても.htpasswdは作成されず、一旦空の.htpasswdを作成してから-bmで行っても空のままです。
76
+
77
+ その際に表示されるエラー?メッセージは下記です。
78
+
79
+ ```
80
+
81
+ [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
82
+
83
+ Usage:
84
+
85
+ htpasswd [-cimBdpsDv] [-C cost] passwordfile username
86
+
87
+ htpasswd -b[cmBdpsDv] [-C cost] passwordfile username password
88
+
89
+
90
+
91
+ htpasswd -n[imBdps] [-C cost] username
92
+
93
+ htpasswd -nb[mBdps] [-C cost] username password
94
+
95
+ -c Create a new file.
96
+
97
+ -n Don't update file; display results on stdout.
98
+
99
+ -b Use the password from the command line rather than prompting for it.
100
+
101
+ -i Read password from stdin without verification (for script usage).
102
+
103
+ -m Force MD5 encryption of the password (default).
104
+
105
+ -B Force bcrypt encryption of the password (very secure).
106
+
107
+ -C Set the computing time used for the bcrypt algorithm
108
+
109
+ (higher is more secure but slower, default: 5, valid: 4 to 31).
110
+
111
+ -d Force CRYPT encryption of the password (8 chars max, insecure).
112
+
113
+ -s Force SHA encryption of the password (insecure).
114
+
115
+ -p Do not encrypt the password (plaintext, insecure).
116
+
117
+ -D Delete the specified user.
118
+
119
+ -v Verify password for the specified user.
120
+
121
+ On other systems than Windows and NetWare the '-p' flag will probably not work.
122
+
123
+ The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.
124
+
125
+ ```