You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add TLS-PSK authentication support via callback mechanism
This adds support for TLS Pre-Shared Key (PSK) authentication, allowing
secure connections without certificates using a shared secret key.
Changes:
- Add psk_cred_handler() builder method to create_webserver
- Add psk_cred_handler_callback typedef for PSK credential lookup
- Implement psk_cred_handler_func() static callback using GnuTLS
- Add MHD_OPTION_GNUTLS_PSK_CRED_HANDLER option when PSK is configured
- Add AM_CONDITIONAL for HAVE_GNUTLS in configure.ac
- Remove deprecated AC_HEADER_STDC macro
- Add minimal_https_psk example demonstrating PSK usage
- Add conditional GnuTLS linking in test/Makefile.am
- Update README.md with PSK documentation and example
The callback receives a username and returns the hex-encoded PSK,
or an empty string for unknown users.
Copy file name to clipboardExpand all lines: README.md
+54Lines changed: 54 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -313,6 +313,7 @@ You can also check this example on [github](https://github.com/etr/libhttpserver
313
313
*_.https_mem_cert(**const std::string&** filename):_ String representing the path to a file containing the certificate to be used by the HTTPS daemon. This must be used in conjunction with `https_mem_key`.
314
314
*_.https_mem_trust(**const std::string&** filename):_ String representing the path to a file containing the CA certificate to be used by the HTTPS daemon to authenticate and trust clients certificates. The presence of this option activates the request of certificate to the client. The request to the client is marked optional, and it is the responsibility of the server to check the presence of the certificate if needed. Note that most browsers will only present a client certificate only if they have one matching the specified CA, not sending any certificate otherwise.
315
315
*_.https_priorities(**const std::string&** priority_string):_ SSL/TLS protocol version and ciphers. Must be followed by a string specifying the SSL/TLS protocol versions and ciphers that are acceptable for the application. The string is passed unchanged to gnutls_priority_init. If this option is not specified, `"NORMAL"` is used.
316
+
*_.psk_cred_handler(**psk_cred_handler_callback** handler):_ Sets a callback function for TLS-PSK (Pre-Shared Key) authentication. The callback receives a username and should return the corresponding hex-encoded PSK, or an empty string if the user is unknown. This option requires `use_ssl()`, `cred_type(http::http_utils::PSK)`, and an appropriate `https_priorities()` string that enables PSK cipher suites. PSK authentication allows TLS without certificates by using a shared secret key.
316
317
317
318
#### Minimal example using HTTPS
318
319
```cpp
@@ -346,6 +347,59 @@ To test the above example, you can run the following command from a terminal:
346
347
347
348
You can also check this example on [github](https://github.com/etr/libhttpserver/blob/master/examples/minimal_https.cpp).
348
349
350
+
#### Minimal example using TLS-PSK
351
+
```cpp
352
+
#include<httpserver.hpp>
353
+
#include<map>
354
+
#include<string>
355
+
356
+
usingnamespacehttpserver;
357
+
358
+
// Simple PSK database - in production, use secure storage
Then type `GET /hello HTTP/1.1` followed by `Host: localhost` and two newlines.
400
+
401
+
You can also check this example on [github](https://github.com/etr/libhttpserver/blob/master/examples/minimal_https_psk.cpp).
402
+
349
403
### IP Blacklisting/Whitelisting
350
404
libhttpserver supports IP blacklisting and whitelisting as an internal feature. This section explains the startup options related with IP blacklisting/whitelisting. See the [specific section](#ip-blacklisting-and-whitelisting) to read more about the topic.
351
405
* _.ban_system() and .no_ban_system:_ Can be used to enable/disable the ban system. `on` by default.
0 commit comments