Skip to content

feature: ssl: add FFI function to set SSL ciphers#961

Open
ghedo wants to merge 1 commit into
openresty:masterfrom
ghedo:ssl_set_ciphers
Open

feature: ssl: add FFI function to set SSL ciphers#961
ghedo wants to merge 1 commit into
openresty:masterfrom
ghedo:ssl_set_ciphers

Conversation

@ghedo

@ghedo ghedo commented Jan 19, 2017

Copy link
Copy Markdown
Contributor

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

@ghedo

ghedo commented Feb 2, 2017

Copy link
Copy Markdown
Contributor Author

@agentzh @doujiang24 ping? This seems pretty straightforward.

@agentzh

agentzh commented Feb 2, 2017

Copy link
Copy Markdown
Member

@ghedo Sorry for the delay on our side. This PR looks good to me :) @doujiang24 ?

@agentzh

agentzh commented Feb 2, 2017

Copy link
Copy Markdown
Member

@ghedo Have you created a PR for lua-resty-core yet?

@ghedo

ghedo commented Feb 2, 2017

Copy link
Copy Markdown
Contributor Author

Made openresty/lua-resty-core#86 now.

Comment thread src/ngx_http_lua_ssl_certby.c Outdated

if (!SSL_set_cipher_list(ssl_conn, ciphers)) {
*err = "SSL_set_cipher_list() failed";
goto failed;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems we can omit the goto here?Just move the failed code here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ghedo

ghedo commented Mar 18, 2017

Copy link
Copy Markdown
Contributor Author

@agentzh @doujiang24 ping? Is there anything else needed here?

@ghedo

ghedo commented Jul 13, 2017

Copy link
Copy Markdown
Contributor Author

@agentzh @doujiang24 it's now been almost 6 months since this and openresty/lua-resty-core#86 were opened, any news?

@agentzh

agentzh commented Jul 13, 2017

Copy link
Copy Markdown
Member

@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)) {

@agentzh agentzh Nov 18, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@mergify

mergify Bot commented Jun 26, 2020

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Jun 26, 2020
@mergify mergify Bot removed the conflict label Mar 20, 2023
@mergify

mergify Bot commented Mar 20, 2023

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Mar 20, 2023
@mergify mergify Bot removed the conflict label May 10, 2023
@mergify

mergify Bot commented May 10, 2023

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label May 10, 2023
@mergify mergify Bot removed the conflict label Sep 23, 2023
@mergify

mergify Bot commented Sep 23, 2023

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Sep 23, 2023
@mergify mergify Bot removed the conflict label Mar 6, 2024
@mergify

mergify Bot commented Mar 6, 2024

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label Mar 6, 2024
@mergify mergify Bot removed the conflict label May 27, 2024
@mergify

mergify Bot commented May 27, 2024

Copy link
Copy Markdown

This pull request is now in conflict :(

@mergify mergify Bot added the conflict label May 27, 2024
@mergify mergify Bot removed the conflict label Feb 13, 2025
@Webster-Yang

Copy link
Copy Markdown

How to set ciphersuites dynamically?
Can the changes in this PR be used directly on openresty/1.27.1.2?

@Webster-Yang

Copy link
Copy Markdown

Why is this PR's changes not merged into master?
@agentzh

@Webster-Yang

Copy link
Copy Markdown

I need to dynamically set ciphersuites on openresty/1.27.1.2
@agentzh

@linsite

linsite commented Aug 25, 2025

Copy link
Copy Markdown

I'm looking forward to this feature, too.
Many thanks to this work and OpenResty project.

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.

6 participants