Skip to content
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

feat: support OCSP validation of the client certificate #11351

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

yuweizzz
Copy link
Contributor

@yuweizzz yuweizzz commented Jun 14, 2024

Description

Fixes #11385
Releated: #10309

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@yuweizzz
Copy link
Contributor Author

It seem the ocsp responder didn't exit normally, I will check it.

@yuweizzz yuweizzz marked this pull request as draft June 16, 2024 09:31
@yuweizzz yuweizzz marked this pull request as ready for review June 17, 2024 02:15
@yuweizzz
Copy link
Contributor Author

yuweizzz commented Jul 1, 2024

any reviewer?

end

local matched_ssl = ctx.matched_ssl
local required_verify_client = matched_ssl.value.client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you name it required_verify_client just name it client

return
end

local required_ssl_ocsp = matched_ssl.value.ocsp_stapling.ssl_ocsp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto, you can choose a simpler name like ssl_ocsp


local matched_ssl = ctx.matched_ssl
local required_verify_client = matched_ssl.value.client
if not required_verify_client then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about

Suggested change
if not required_verify_client then
if not matched_ssl.value.client then

local full_chain_pem_cert = ctx.var.ssl_client_raw_cert .. matched_ssl.value.client.ca
local der_cert_chain, err = ngx_ssl.cert_pem_to_der(full_chain_pem_cert)
if not der_cert_chain then
core.log.error("failed to convert clinet certificate from PEM to DER: ", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
core.log.error("failed to convert clinet certificate from PEM to DER: ", err)
core.log.error("failed to convert client certificate from PEM to DER: ", err)

default = "off",
enum = {"off", "leaf"},
},
ssl_ocsp_responder = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these fields are just for customising the values of default nginx directives right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, but no all same as nginx directives, just part of it, nginx directives allows "off", "leaf" and "on". the openresty api can not get full chain cert, so we don't support "on" here.

@@ -166,6 +179,7 @@ local function set_cert_and_key(sni, value)
end

local ok, err = set_ocsp_resp(fin_pem_cert,
value.ocsp_stapling.ssl_stapling_responder,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this value is being passed around through many functions, I would recommend checking if this value is nil. If it is nil, use get_ocsp_responder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this value will always be the params of function get_ocsp_responder on line 49, the function will do a check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but instead of passing this values through mulitple functions, I think a simple check before hand can avoid this and make code simpler.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@shreemaan-abhishek
Copy link
Contributor

The issue you have linked with this PR is not focused, please create a new issue describing your proposal.

@bzp2010
Copy link
Contributor

bzp2010 commented Jul 16, 2024

Hi, @yuweizzz. The centos7 related image that was causing the CI error has been removed, please merge the changes on the master branch to resolve the CI error.

@bzp2010 bzp2010 self-requested a review July 16, 2024 04:03
@yuweizzz
Copy link
Contributor Author

Merged.

@yuweizzz
Copy link
Contributor Author

ping @shreemaan-abhishek @bzp2010

local ocsp_url, err = ngx_ocsp.get_ocsp_responder_from_der_chain(der_cert_chain)

if not ocsp_url then
local function get_ocsp_responder(der_cert_chain)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we skip this unnecessary function name modification/breaking down of one function into two?

I am not a OCSP expert and it makes difficult to review.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break down this function because we could reuse it in client verify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: As a user, I want to support OCSP validation of the client certificate
3 participants