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

feature: Added ngx_http_lua_ffi_ssl_ocsp_get_nextupdate #1041

Closed
wants to merge 2 commits into from

Conversation

alubbe
Copy link
Contributor

@alubbe alubbe commented Apr 14, 2017

This PR is a possible solution to openresty/lua-resty-core#75 and is complemented by openresty/lua-resty-core#99.
Looking forward to your feedback.

I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.

@alubbe
Copy link
Contributor Author

alubbe commented Apr 14, 2017

Also, two newbie questions:

  1. I copied ngx_ssl_stapling_time over from the nginx source code because I couldn't figure out how to reference/reuse/import it. Is there a way to do this without patching nginx?
  2. Should ngx_http_lua_ffi_ssl_ocsp_get_nextupdate be in a header file somewhere?

@agentzh
Copy link
Member

agentzh commented Apr 14, 2017

@alubbe To answer your questions:

  1. Static C functions cannot be reused outside that compilation unit.
  2. No. Those C functions are not meant to be used by other C code.

@agentzh
Copy link
Member

agentzh commented Apr 14, 2017

@ghedo @lziest Do you mind reviewing this PR for me? Many thanks!

@@ -433,6 +433,182 @@ ngx_http_lua_ffi_ssl_validate_ocsp_response(const u_char *resp,
}


static time_t
ngx_ssl_stapling_time(ASN1_GENERALIZEDTIME *asn1time)
Copy link
Member

Choose a reason for hiding this comment

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

You should use the ngx_http_lua_ prefix, no matter what.

@alubbe
Copy link
Contributor Author

alubbe commented Apr 16, 2017

Static C functions cannot be reused outside that compilation unit.

Fair enough. I will copy the contents and rename it to ngx_http_lua_ssl_stapling_time.

No. Those C functions are not meant to be used by other C code.

Can we also remove /~https://github.com/openresty/lua-nginx-module/pull/782/files#diff-c4f8697714ffd4ae8e3d403bc9a55715R17 ?

goto error;
}

id = OCSP_cert_to_id(NULL, cert, issuer);
Copy link

Choose a reason for hiding this comment

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

hmm, I am not sure what this cert_to_id do though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It extracts the id that I believe is mandatory to call OCSP_resp_find_status, which in turn extracts the nextUpdate value.
https://www.openssl.org/docs/man1.1.0/crypto/OCSP_cert_to_id.html
https://www.openssl.org/docs/man1.1.0/crypto/OCSP_resp_find_status.html

Copy link
Contributor

Choose a reason for hiding this comment

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

Is issuer supposed to be the issuer of the leaf certificate, or the issuer of the OCSP response? (they don't always match).

If I understand the documentation and the OpenSSL code correctly it is the former (issuer of certificate) so this implementation is correct, but I'm not 100% sure.

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 function body borrows heavily from the function right above it. This particular line is the same as /~https://github.com/openresty/lua-nginx-module/pull/1041/files#diff-50267b7dd63c740bc5c1d29c7387e789R357

goto error;
}

cert = d2i_X509_bio(bio, NULL);
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have FFI functions to parse certificates into STACK_OF(X509) (from PEM, but still), so IMO this function should just take an already parsed certificate chain instead of a DER blob.

}

if (nupdate_ans1 == NULL)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not be on its own line.


if (OCSP_resp_find_status(basic, id, NULL, NULL, NULL, NULL, &nupdate_ans1)
!= 1)
{
Copy link
Contributor

@ghedo ghedo Apr 22, 2017

Choose a reason for hiding this comment

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

Same (as below).


int
ngx_http_lua_ffi_ssl_ocsp_get_nextupdate(const u_char *resp, size_t resp_len,
const char *chain_data, size_t chain_len, time_t* nextupdate,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be time_t *nextupdate not time_t* nextupdate.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, next_update might be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that next_update is better, since the official field name is nextUpdate. However, that naming decision was already made in existing code: /~https://github.com/openresty/lua-nginx-module/pull/1041/files#diff-50267b7dd63c740bc5c1d29c7387e789L284
If @agentzh would allow me, I could open a PR renaming all existing instances to next_update, but until then I'd stick to the existing convention of nextupdate.

@zhuizhuhaomeng
Copy link
Contributor

This feature has been implemented in another PR.
See lua-resty-core git commit 7a6521deb7a354fac9cb24cb477c144559ec3c06 for more detail.

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

Successfully merging this pull request may close these issues.

5 participants