-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
server: SSL Support #5926
server: SSL Support #5926
Conversation
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
All SSL setup is hidden behind CPPHTTPLIB_OPENSSL_SUPPORT in the same way that the base httlib hides the SSL support Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
@@ -2173,7 +2183,24 @@ static void server_params_parse(int argc, char ** argv, server_params & sparams, | |||
} | |||
} | |||
key_file.close(); | |||
} else if (arg == "--timeout" || arg == "-to") { | |||
|
|||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of hate that this breaks the brace formatting of the rest of the if/else if
chain, but I figured it was better than duplicating the else if (arg == "--timeout"...
.
Note that the tests are written in Python, but there is no binding, just plain old http calls to the server. Anyway, these are mainly functional tests, and I don't expect to add an ssl handcheck against the server as it will require a trusted root certificate. If it compiles with the good libopenssl version, it will work. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document the README.md with the proposed changes
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Thanks for the review! The README changes are pushed as well as a first pass at top-level |
For a few libraries we are using pkg-config. It's probably not necessary here though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really useful, thanks
* add cmake build toggle to enable ssl support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * add flags for ssl key/cert files and use SSLServer if set All SSL setup is hidden behind CPPHTTPLIB_OPENSSL_SUPPORT in the same way that the base httlib hides the SSL support Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Update readme for SSL support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Add LLAMA_SERVER_SSL variable setup to top-level Makefile Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> --------- Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* add cmake build toggle to enable ssl support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * add flags for ssl key/cert files and use SSLServer if set All SSL setup is hidden behind CPPHTTPLIB_OPENSSL_SUPPORT in the same way that the base httlib hides the SSL support Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Update readme for SSL support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Add LLAMA_SERVER_SSL variable setup to top-level Makefile Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> --------- Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* add cmake build toggle to enable ssl support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * add flags for ssl key/cert files and use SSLServer if set All SSL setup is hidden behind CPPHTTPLIB_OPENSSL_SUPPORT in the same way that the base httlib hides the SSL support Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Update readme for SSL support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Add LLAMA_SERVER_SSL variable setup to top-level Makefile Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> --------- Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
* add cmake build toggle to enable ssl support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * add flags for ssl key/cert files and use SSLServer if set All SSL setup is hidden behind CPPHTTPLIB_OPENSSL_SUPPORT in the same way that the base httlib hides the SSL support Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Update readme for SSL support in server Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> * Add LLAMA_SERVER_SSL variable setup to top-level Makefile Signed-off-by: Gabe Goodhart <ghart@us.ibm.com> --------- Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
Description
This PR adds SSL support to the
examples/server
using the built-in SSL support in the vendoredhttlib.h
header library.Changes
CMake
build optionLLAMA_SERVER_SSL
(defaultOFF
) to toggle building with/without SSL supportlibssl
/libcrypto
, so this adds a dependency onopenssl
and requires version >= 3 (see note here on thecpp-httplib
repo)#define CPPHTTPLIB_OPENSSL_SUPPORT
following the pattern inhttplib
ssl_key_file
andssl_cert_file
to theserver_params
struct--ssl-key-file
and--ssl-cert-file
httplib
does not support inline PEM strings, so these must point to filessvr
instance variable to be aunique_ptr<httplib::Server>
and instantiate it as either ahttplib::Server
orhttplib::SslServer
depending on the values ofserver_params.ssl_key_file
andserver_params.ssl_cert_file
.svr
to move from.
to->
, so touched a lot of lines!Testing
I noticed the tests in examples/server/tests, but these all appear to be testing against the python bindings. Since building with SSL support requires additional dependencies, I did not want to add these as dependencies in the python bindings and did not attempt to make the default build for python include SSL support, therefore I did not update these tests.
I performed manual testing using locally-generated SSL files (see my utility script for generating them below). With the generated
server.key.pem
andserver.cert.pem
, I ran the following:gen_mtls_test_files.sh
Open Questions
nginx
proxy is a more robust way to go. That said, having basic SSL support in the native server is a much simpler deployment topology, so may be worth the maintenance effort.--ssl-key-file
and--ssl-cert-file
arguments only work if both are specified. Currently, if either is not specified, they are both ignored. Should they instead cause an error if one is specified without the other?cpp-httlib
does not support mutual TLS, this change also does not support it. Is it worth having non-mutual support without going all the way to mTLS?