1.8. 配置 TLS 客户端证书身份验证
客户端证书身份验证可让管理员只允许使用证书进行身份验证的用户访问 web 服务器上的资源。您可以为 /var/www/html/Example/
目录配置客户端证书身份验证。
如果 Apache HTTP 服务器使用 TLS 1.3 协议,某些客户端将需要额外的配置。例如,在 Firefox 中,将about:config
菜单中的security.tls.enable_post_handshake_auth
参数设置为true
。
先决条件
- TLS 加密在服务器上已启用。
流程
编辑
/etc/httpd/conf/httpd.conf
文件,并将以下设置添加到你要为其配置客户端验证的<VirtualHost>
指令中:<Directory "/var/www/html/Example/"> SSLVerifyClient require </Directory>
<Directory "/var/www/html/Example/"> SSLVerifyClient require </Directory>
Copy to Clipboard Copied! SSLVerifyClient require
设置定义了服务器必须成功验证客户端证书,然后客户端才能访问/var/www/html/Example/
目录中的内容。重启
httpd
服务:systemctl restart httpd
# systemctl restart httpd
Copy to Clipboard Copied!
验证
使用
curl
工具在没有客户端身份验证的情况下访问https://example.com/Example/
URL:curl https://example.com/Example/
$ curl https://example.com/Example/ curl: (56) OpenSSL SSL_read: error:1409445C:SSL routines:ssl3_read_bytes:tlsv13 alert certificate required, errno 0
Copy to Clipboard Copied! 这个错误表示 web 服务器需要客户端证书验证。
将客户端私钥和证书以及 CA 证书传递给
curl
以便使用客户端身份验证来访问相同的URL:curl --cacert ca.crt --key client.key --cert client.crt https://example.com/Example/
$ curl --cacert ca.crt --key client.key --cert client.crt https://example.com/Example/
Copy to Clipboard Copied! 如果请求成功,
curl
会显示存储在/var/www/html/Example/
目录中的index.html
文件。