目的:使用nginx的吊销列表
环境:
Linux ubuntu 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
nginx-1.12.2
//编译
cd nginx-1.12.2/
./configure --prefix=/opt/nginx-server-ocsp --with-debug --with-openssl=/home/ubu/nginx-ocsp/lib/openssl-1.0.1g --with-http_ssl_module
make
//nginx 配置文件
ubu@ubuntu:/opt/nginx-server-ocsp$ cat conf/nginx-server-ocsp.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
error_log logs/error.log debug;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /opt/nginx-ocsp-test {
root html;
index index.html index.htm index.txt;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
server {
listen 443 ssl;
server_name server_test_01;
charset utf-8;
ssl_crl /home/ubu/openssl_ocsp_test/root-ca/all-revoked.crl;
ssl_verify_client on;
ssl_client_certificate /home/ubu/target/openssl_ocsp_test/root-ca/combine.crt;
ssl_certificate /home/ubu/target/openssl_ocsp_test/server/server.crt;
ssl_certificate_key /home/ubu/target/openssl_ocsp_test/server/server.key;
#ssl_password_file /home/ubu/target/certificate/ca/intermediate/private/server.key;
ssl_protocols TLSv1.2;
ssl_verify_depth 2;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /opt/nginx-server-ocsp {
root html;
index index.html index.htm index.txt;
}
}
}
// nginx启动
/opt/nginx-server-ocsp/nginx-server-ocsp -c /opt/nginx-server-ocsp/conf/nginx-server-ocsp.conf
//curl 测试:
curl https://server_test_01:443/index.txt --cacert root-ca/combine.crt --cert client/client.crt --key client/client.key
//正确结果:客户端证书被验证且没有被吊销
123
//错误结果:客户端证书被验证且客户端证书被吊销
<html>
<head><title>400 The SSL certificate error</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The SSL certificate error</center>
<hr><center>nginx/1.12.2</center>
</body>
</html>
注意:
1,ssl_client_certificate /home/ubu/target/openssl_ocsp_test/root-ca/combine.crt;
如果客户端证书不是根CA(root-ca.crt)直接签发的,而是二级CA(sub-ca.crt)签发的。ssl_client_certificate 应指向一个证书链,即包含根CA和所有二级CA, 且按顺序二级CA在上,根CA在下的顺序:
cat sub-ca.crt root-ca.crt > combine.crt
2,ssl_crl /home/ubu/openssl_ocsp_test/root-ca/all-revoked.crl;
参考:https://trac.nginx.org/nginx/ticket/344#no1
即:When using intermediate CAs, a file with CRLs is expected to contain CRLs for all CAs. The error in question will appear if there is no CRL for some CA in the certificate chain.
ubu@ubuntu:~/target/openssl_ocsp_test/root-ca$ openssl ca -gencrl -config root-ca.conf -out root-ca-revoked.crl
Using configuration from root-ca.conf
Enter pass phrase for ./private/root-ca.key:
ubu@ubuntu:~/target/openssl_ocsp_test/root-ca$ openssl ca -gencrl -config sub-ca.conf -out sub-ca-revoked.crl
Using configuration from sub-ca.conf
Enter pass phrase for ./private/sub-ca.key:
ubu@ubuntu:~/target/openssl_ocsp_test/root-ca$ cat root-ca-revoked.crl sub-ca-revoked.crl > all-revoked.crl