-
Notifications
You must be signed in to change notification settings - Fork 275
feature: implement ssl.verify_client()
#289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
978e012
8d975a8
029bcf0
39d2ded
2a2c419
1218b5e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2330,3 +2330,174 @@ got TLS1 version: TLSv1.3, | |
[error] | ||
[alert] | ||
[emerg] | ||
|
||
|
||
|
||
=== TEST 23: verify client with CA certificates | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test case fails with the following leak error in the valgrind test mode on my side using OpenSSL 1.1.1g:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by adding |
||
--- http_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
server { | ||
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; | ||
server_name test.com; | ||
ssl_certificate_by_lua_block { | ||
local ssl = require "ngx.ssl" | ||
|
||
local f = assert(io.open("t/cert/test.crt")) | ||
local cert_data = f:read("*a") | ||
f:close() | ||
|
||
local cert, err = ssl.parse_pem_cert(cert_data) | ||
if not cert then | ||
ngx.log(ngx.ERR, "failed to parse pem cert: ", err) | ||
return | ||
end | ||
|
||
local ok, err = ssl.verify_client(cert, 1) | ||
if not ok then | ||
ngx.log(ngx.ERR, "failed to verify client: ", err) | ||
return | ||
end | ||
} | ||
|
||
ssl_certificate ../../cert/test2.crt; | ||
ssl_certificate_key ../../cert/test2.key; | ||
|
||
location / { | ||
default_type 'text/plain'; | ||
content_by_lua_block { | ||
print('client certificate subject: ', ngx.var.ssl_client_s_dn) | ||
ngx.say(ngx.var.ssl_client_verify) | ||
} | ||
more_clear_headers Date; | ||
} | ||
} | ||
--- config | ||
location /t { | ||
proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock; | ||
proxy_ssl_certificate ../../cert/test.crt; | ||
proxy_ssl_certificate_key ../../cert/test.key; | ||
} | ||
|
||
--- request | ||
GET /t | ||
--- response_body | ||
SUCCESS | ||
|
||
--- error_log | ||
client certificate subject: [email protected],CN=test.com | ||
|
||
--- no_error_log | ||
[error] | ||
[alert] | ||
[emerg] | ||
|
||
|
||
|
||
=== TEST 24: verify client without CA certificates | ||
ArchangelSDY marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--- http_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
server { | ||
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; | ||
server_name test.com; | ||
ssl_certificate_by_lua_block { | ||
local ssl = require "ngx.ssl" | ||
|
||
local ok, err = ssl.verify_client() | ||
if not ok then | ||
ngx.log(ngx.ERR, "failed to verify client: ", err) | ||
return | ||
end | ||
} | ||
|
||
ssl_certificate ../../cert/test2.crt; | ||
ssl_certificate_key ../../cert/test2.key; | ||
|
||
location / { | ||
default_type 'text/plain'; | ||
content_by_lua_block { | ||
print('client certificate subject: ', ngx.var.ssl_client_s_dn) | ||
ngx.say(ngx.var.ssl_client_verify) | ||
} | ||
more_clear_headers Date; | ||
} | ||
} | ||
--- config | ||
location /t { | ||
proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock; | ||
proxy_ssl_certificate ../../cert/test.crt; | ||
proxy_ssl_certificate_key ../../cert/test.key; | ||
} | ||
|
||
--- request | ||
GET /t | ||
--- response_body | ||
FAILED:self signed certificate | ||
|
||
--- error_log | ||
client certificate subject: [email protected],CN=test.com | ||
|
||
--- no_error_log | ||
[error] | ||
[alert] | ||
[emerg] | ||
|
||
|
||
|
||
=== TEST 25: verify client but client provides no certificate | ||
--- http_config | ||
lua_package_path "$TEST_NGINX_LUA_PACKAGE_PATH"; | ||
|
||
server { | ||
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl; | ||
server_name test.com; | ||
ssl_certificate_by_lua_block { | ||
local ssl = require "ngx.ssl" | ||
|
||
local f = assert(io.open("t/cert/test.crt")) | ||
local cert_data = f:read("*a") | ||
f:close() | ||
|
||
local cert, err = ssl.parse_pem_cert(cert_data) | ||
if not cert then | ||
ngx.log(ngx.ERR, "failed to parse pem cert: ", err) | ||
return | ||
end | ||
|
||
local ok, err = ssl.verify_client(cert, 1) | ||
if not ok then | ||
ngx.log(ngx.ERR, "failed to verify client: ", err) | ||
return | ||
end | ||
} | ||
|
||
ssl_certificate ../../cert/test2.crt; | ||
ssl_certificate_key ../../cert/test2.key; | ||
|
||
location / { | ||
default_type 'text/plain'; | ||
content_by_lua_block { | ||
print('client certificate subject: ', ngx.var.ssl_client_s_dn) | ||
ngx.say(ngx.var.ssl_client_verify) | ||
} | ||
more_clear_headers Date; | ||
} | ||
} | ||
--- config | ||
location /t { | ||
proxy_pass https://unix:$TEST_NGINX_HTML_DIR/nginx.sock; | ||
} | ||
|
||
--- request | ||
GET /t | ||
--- response_body | ||
NONE | ||
|
||
--- error_log | ||
client certificate subject: nil | ||
|
||
--- no_error_log | ||
[error] | ||
[alert] | ||
[emerg] |
Uh oh!
There was an error while loading. Please reload this page.