-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
978e012
feature: implement `ssl.verify_client()`
ArchangelSDY 8d975a8
tests: add unit tests for client certificate verification API
ArchangelSDY 029bcf0
feature: update arguments order of `ssl.verify_client` and update doc
ArchangelSDY 39d2ded
tests: use a different cert at server side
ArchangelSDY 2a2c419
tests: refine and clean up
ArchangelSDY 1218b5e
bugfix: fix memory leak in test cases
ArchangelSDY File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2330,3 +2330,177 @@ got TLS1 version: TLSv1.3, | |
[error] | ||
[alert] | ||
[emerg] | ||
|
||
|
||
|
||
=== TEST 23: verify client with CA certificates | ||
--- 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; | ||
proxy_ssl_session_reuse off; | ||
} | ||
|
||
--- 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; | ||
proxy_ssl_session_reuse off; | ||
} | ||
|
||
--- 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; | ||
proxy_ssl_session_reuse off; | ||
} | ||
|
||
--- request | ||
GET /t | ||
--- response_body | ||
NONE | ||
|
||
--- error_log | ||
client certificate subject: nil | ||
|
||
--- no_error_log | ||
[error] | ||
[alert] | ||
[emerg] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed by adding
proxy_ssl_session_reuse: off
.