feature: ssl: add FFI function to set SSL ciphers#961
feature: ssl: add FFI function to set SSL ciphers#961ghedo wants to merge 1 commit intoopenresty:masterfrom ghedo:ssl_set_ciphers
Conversation
|
@agentzh @doujiang24 ping? This seems pretty straightforward. |
|
@ghedo Sorry for the delay on our side. This PR looks good to me :) @doujiang24 ? |
|
@ghedo Have you created a PR for lua-resty-core yet? |
|
Made openresty/lua-resty-core#86 now. |
src/ngx_http_lua_ssl_certby.c
Outdated
|
|
||
| if (!SSL_set_cipher_list(ssl_conn, ciphers)) { | ||
| *err = "SSL_set_cipher_list() failed"; | ||
| goto failed; |
There was a problem hiding this comment.
Seems we can omit the goto here?Just move the failed code here?
|
@agentzh @doujiang24 ping? Is there anything else needed here? |
|
@agentzh @doujiang24 it's now been almost 6 months since this and openresty/lua-resty-core#86 were opened, any news? |
|
@ghedo Sorry for the long delay on our side. We'll look into this as soon as we can manage. Thanks for your understanding! |
| return NGX_ERROR; | ||
| } | ||
|
|
||
| if (!SSL_set_cipher_list(ssl_conn, ciphers)) { |
There was a problem hiding this comment.
@ghedo I wonder if you really need per-connection ciphers. Maybe you just need a per-domain cipher suite? If it's the latter, then we can just reuse a domain-level SSL ctx to avoid per-request cipher name parsing and setting.
There was a problem hiding this comment.
Or maybe we can simply set a parsed SSL cipher suite C data structure to avoid the string parsing here on a hot code path?
There was a problem hiding this comment.
Yes I agree that calling SSL_set_cipher_list on a per request basis is a terrible idea as it both has lots of malloc along the way and the cipher search algorithm is linear.
Better way of doing this is to store the cipher stack created by OpenSSL once and reuse them later in new connections with some kind of Lua handle (e.g. cdata).
There may be other way that's better but I haven't looked too much into other OpenSSL cipher related APIs.
There was a problem hiding this comment.
Ooops, missed these comments...
Anyway, the function is intended to be used in ssl_cert_by_lua, so per-connection, not per-request, and even then not all connections (otherwise you might as well use ssl_protocols in the config).
AFAICT there's no OpenSSL API that would allow you to parse a cipher string into an array or stack of SSL_CIPHER, without actually changing the cipher list on an SSL or SSL_CTX struct. And even then, there's no OpenSSL API to set a cipher list from an array or stack of SSL_CIPHER. Did you have anything specific in mind?
In any case the overhead of SSL_set_cipher_list() is really not that bad, and even if it was too slow/heavy for whatever use case (which would likely prevent other OpenResty APIs from being used as well), nobody would be forced to use this.
There was a problem hiding this comment.
@ghedo Well, I think we are just trying to do it right :) BTW, have you actually measured the overhead of parsing and loading long cipher strings in this context?
| return NGX_ERROR; | ||
| } | ||
|
|
||
| if (!SSL_set_cipher_list(ssl_conn, ciphers)) { |
There was a problem hiding this comment.
Yes I agree that calling SSL_set_cipher_list on a per request basis is a terrible idea as it both has lots of malloc along the way and the cipher search algorithm is linear.
Better way of doing this is to store the cipher stack created by OpenSSL once and reuse them later in new connections with some kind of Lua handle (e.g. cdata).
There may be other way that's better but I haven't looked too much into other OpenSSL cipher related APIs.
|
This pull request is now in conflict :( |
|
This pull request is now in conflict :( |
|
This pull request is now in conflict :( |
|
This pull request is now in conflict :( |
|
This pull request is now in conflict :( |
|
This pull request is now in conflict :( |
|
How to set ciphersuites dynamically? |
|
Why is this PR's changes not merged into master? |
|
I need to dynamically set ciphersuites on openresty/1.27.1.2 |
|
I'm looking forward to this feature, too. |
I hereby granted the copyright of the changes in this pull request
to the authors of this lua-nginx-module project.