-
-
Notifications
You must be signed in to change notification settings - Fork 625
fix poolname to include the digest of the cert for mTLS #307
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
pintsized
merged 21 commits into
ledgetech:master
from
catbro666:mtls-auth-pool-name-adds-cert-hash
Feb 29, 2024
Merged
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
dc468f4
fix poolname to include the digest of the cert for mTLS
catbro666 67485a1
check the private key in order to make sure the caller is indeed the …
catbro666 3ff72f4
add test
catbro666 6eced02
fix: ssl_client_cert is a chain of x509 instead of a x509
catbro666 3ff2af2
fix: use the correct chain path and add `ffi.cast`
catbro666 67a6d8a
add the latest openresty versions and skip mtls tests only when nginx
catbro666 aa3c82a
add type check for client cert and key
catbro666 bc289e6
fallback to non-mTLS when any cert/key error and log a warning
catbro666 8832e33
add debug log to print poolname
catbro666 4e85809
apply the comments
catbro666 a20212e
apply comments
catbro666 baf011a
apply the comment
catbro666 273bf56
load resty.openssl.* at the module level and error out if the client …
catbro666 705f57d
error out directly for other cases as well and fix test
catbro666 9d731c8
fix typo
catbro666 b91ddec
fix test
catbro666 62a7e1d
fix error message
catbro666 efa2b65
fix error message
catbro666 863be74
use `..` concat operation to keep the original style
catbro666 75274fd
fixup
catbro666 43f9d21
fix some return value errors
catbro666 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 |
---|---|---|
|
@@ -105,7 +105,6 @@ GET /t | |
|
||
=== TEST 2: Connection fails during handshake with not priv_key | ||
--- http_config eval: $::mtls_http_config | ||
--- SKIP | ||
--- config eval | ||
" | ||
lua_ssl_trusted_certificate $::HtmlDir/test.crt; | ||
|
@@ -149,12 +148,12 @@ location /t { | |
GET /t | ||
--- error_code: 200 | ||
--- error_log | ||
could not set client certificate: bad client pkey type | ||
bad ssl_client_priv_key: cdata expected, got string | ||
--- response_body_unlike: hello, [email protected],O=OpenResty,ST=California,C=US | ||
|
||
--- skip_nginx | ||
4: < 1.21.4 | ||
|
||
=== TEST 3: Connection succeeds with client cert and key. SKIP'd for CI until feature is merged. | ||
--- SKIP | ||
--- http_config eval: $::mtls_http_config | ||
--- config eval | ||
" | ||
|
@@ -208,4 +207,104 @@ GET /t | |
[warn] | ||
--- response_body | ||
hello, [email protected],O=OpenResty,ST=California,C=US | ||
--- skip_nginx | ||
4: < 1.21.4 | ||
|
||
=== TEST 4: users with different client certs should not share the same pool. | ||
--- http_config eval: $::mtls_http_config | ||
--- config eval | ||
" | ||
lua_ssl_trusted_certificate $::HtmlDir/test.crt; | ||
|
||
location /t { | ||
content_by_lua_block { | ||
local f = assert(io.open('$::HtmlDir/mtls_client.crt')) | ||
local cert_data = f:read('*a') | ||
f:close() | ||
|
||
f = assert(io.open('$::HtmlDir/mtls_client.key')) | ||
local key_data = f:read('*a') | ||
f:close() | ||
|
||
local ssl = require('ngx.ssl') | ||
|
||
local cert = assert(ssl.parse_pem_cert(cert_data)) | ||
local key = assert(ssl.parse_pem_priv_key(key_data)) | ||
|
||
f = assert(io.open('$::HtmlDir/test.crt')) | ||
local invalid_cert_data = f:read('*a') | ||
f:close() | ||
|
||
f = assert(io.open('$::HtmlDir/test.key')) | ||
local invalid_key_data = f:read('*a') | ||
f:close() | ||
|
||
local invalid_cert = assert(ssl.parse_pem_cert(invalid_cert_data)) | ||
local invalid_key = assert(ssl.parse_pem_priv_key(invalid_key_data)) | ||
|
||
local httpc = assert(require('resty.http').new()) | ||
|
||
local ok, err = httpc:connect { | ||
scheme = 'https', | ||
host = 'unix:$::HtmlDir/mtls.sock', | ||
ssl_client_cert = cert, | ||
ssl_client_priv_key = key, | ||
} | ||
|
||
if ok and not err then | ||
local res, err = assert(httpc:request { | ||
method = 'GET', | ||
path = '/', | ||
headers = { | ||
['Host'] = 'example.com', | ||
}, | ||
}) | ||
|
||
ngx.say(res:read_body()) | ||
end | ||
|
||
httpc:set_keepalive() | ||
|
||
local httpc = assert(require('resty.http').new()) | ||
|
||
local ok, err = httpc:connect { | ||
scheme = 'https', | ||
host = 'unix:$::HtmlDir/mtls.sock', | ||
ssl_client_cert = invalid_cert, | ||
ssl_client_priv_key = invalid_key, | ||
} | ||
|
||
ngx.say(httpc:get_reused_times()) | ||
ngx.say(ok) | ||
ngx.say(err) | ||
|
||
if ok and not err then | ||
local res, err = assert(httpc:request { | ||
method = 'GET', | ||
path = '/', | ||
headers = { | ||
['Host'] = 'example.com', | ||
}, | ||
}) | ||
|
||
ngx.say(res.status) -- expect 400 | ||
end | ||
|
||
httpc:close() | ||
} | ||
} | ||
" | ||
--- user_files eval: $::mtls_user_files | ||
--- request | ||
GET /t | ||
--- no_error_log | ||
[error] | ||
[warn] | ||
--- response_body | ||
hello, [email protected],O=OpenResty,ST=California,C=US | ||
0 | ||
true | ||
nil | ||
400 | ||
--- skip_nginx | ||
4: < 1.21.4 |
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.
Uh oh!
There was an error while loading. Please reload this page.