Skip to content

Commit

Permalink
Last changes in docs and minor refactor/fixes in typing in Server method
Browse files Browse the repository at this point in the history
  • Loading branch information
michalpokusa committed Dec 21, 2024
1 parent 1bb84f9 commit 17364ed
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ HTTP Server for CircuitPython.
- Supports URL parameters and wildcard URLs.
- Supports HTTP Basic and Bearer Authentication on both server and route per level.
- Supports Websockets and Server-Sent Events.
- Limited support for HTTPS (only on selected microcontrollers e.g. ESP32-S3).
- Limited support for HTTPS (only on selected microcontrollers with enough memory e.g. ESP32-S3).


Dependencies
Expand Down
14 changes: 8 additions & 6 deletions adafruit_httpserver/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ class Server: # pylint: disable=too-many-instance-attributes
"""Root directory to serve files from. ``None`` if serving files is disabled."""

@staticmethod
def _validate_https_cert_provided(certfile: str, keyfile: str) -> None:
if not certfile or not keyfile:
def _validate_https_cert_provided(
certfile: Union[str, None], keyfile: Union[str, None]
) -> None:
if certfile is None or keyfile is None:
raise ValueError("Both certfile and keyfile must be specified for HTTPS")

@staticmethod
def __create_circuitpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
def _create_circuitpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
ssl_context = create_default_context()

ssl_context.load_verify_locations(cadata="")
Expand All @@ -74,7 +76,7 @@ def __create_circuitpython_ssl_context(certfile: str, keyfile: str) -> SSLContex
return ssl_context

@staticmethod
def __create_cpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
def _create_cpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
ssl_context = create_default_context(purpose=Purpose.CLIENT_AUTH)

ssl_context.load_cert_chain(certfile, keyfile)
Expand All @@ -87,9 +89,9 @@ def __create_cpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
@classmethod
def _create_ssl_context(cls, certfile: str, keyfile: str) -> SSLContext:
return (
cls.__create_circuitpython_ssl_context(certfile, keyfile)
cls._create_circuitpython_ssl_context(certfile, keyfile)
if implementation.name == "circuitpython"
else cls.__create_cpython_ssl_context(certfile, keyfile)
else cls._create_cpython_ssl_context(certfile, keyfile)
)

def __init__(
Expand Down
8 changes: 4 additions & 4 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -372,14 +372,14 @@ video to multiple clients while simultaneously handling other requests.
:emphasize-lines: 31-77,92
:linenos:

SSL/TLS (HTTPS)
---------------
HTTPS
-----

.. warning::
For now HTTPS on CircuitPython is **only supported on ESP32-S3 boards**.
HTTPS on CircuitPython **works only on boards with enough memory e.g. ESP32-S3**.

When you want to expose your server to the internet or an untrusted network, it is recommended to use HTTPS.
Together with authentication, it provides a secure way to communicate with the server, without the risk of eavesdropping.
Together with authentication, it provides a relatively secure way to communicate with the server.

.. note::
Using HTTPS slows down the server, because of additional work with encryption and decryption.
Expand Down

0 comments on commit 17364ed

Please sign in to comment.