We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Certificates not created with `mkcert` or `trustme` raise a RuntimeError
The `CertLoader` class in `sanic-org/sanic/sanic/worker/loader.py` checks the creator of the certificate. If the creator is not `mkcert` or `trustme` then it raises a `RuntimeError`. This will prevent Sanic from running with certificates from any other sources.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `sanic/worker/loader.py`
Content:
```
1 from __future__ import annotations
2 
3 import os
4 import sys
5 
6 from importlib import import_module
7 from pathlib import Path
8 from typing import (
9     TYPE_CHECKING,
10     Any,
11     Callable,
12     Dict,
13     Optional,
14     Type,
15     Union,
16     cast,
17 )
18 
19 from sanic.http.tls.creators import CertCreator, MkcertCreator, TrustmeCreator
20 
21 
22 if TYPE_CHECKING:
23     from sanic import Sanic as SanicApp
24 
25 
26 class AppLoader:
27     def __init__(
28         self,
29         module_input: str = "",
30         as_factory: bool = False,
31         as_simple: bool = False,
32         args: Any = None,
33         factory: Optional[Callable[[], SanicApp]] = None,
34     ) -> None:
35         self.module_input = module_input
36         self.module_name = ""
37         self.app_name = ""
38         self.as_factory = as_factory
39         self.as_simple = as_simple
40         self.args = args
41         self.factory = factory
42         self.cwd = os.getcwd()
43 
44         if module_input:
45             delimiter = ":" if ":" in module_input else "."
46             if module_input.count(delimiter):
47                 module_name, app_name = module_input.rsplit(delimiter, 1)
48                 self.module_name = module_name
49                 self.app_name = app_name
50                 if self.app_name.endswith("()"):
51                     self.as_factory = True
52                     self.app_name = self.app_name[:-2]
53 
54     def load(self) -> SanicApp:
55         module_path = os.path.abspath(self.cwd)
56         if module_path not in sys.path:
57             sys.path.append(module_path)
58 
59         if self.factory:
60             return self.factory()
61         else:
62             from sanic.app import Sanic
63             from sanic.simple import create_simple_server
64 
65             if self.as_simple:
66                 path = Path(self.module_input)
67                 app = create_simple_server(path)
68             else:
69                 if self.module_name == "" and os.path.isdir(self.module_input):
70                     raise ValueError(
71                         "App not found.\n"
72                         "   Please use --simple if you are passing a "
73                         "directory to sanic.\n"
74                         f"   eg. sanic {self.module_input} --simple"
75                     )
76 
77                 module = import_module(self.module_name)
78                 app = getattr(module, self.app_name, None)
79                 if self.as_factory:
80                     try:
81                         app = app(self.args)
82                     except TypeError:
83                         app = app()
84 
85                 app_type_name = type(app).__name__
86 
87                 if (
88                     not isinstance(app, Sanic)
89                     and self.args
90                     and hasattr(self.args, "module")
91                 ):
92                     if callable(app):
93                         solution = f"sanic {self.args.module} --factory"
94                         raise ValueError(
95                             "Module is not a Sanic app, it is a "
96                             f"{app_type_name}\n"
97                             "  If this callable returns a "
98                             f"Sanic instance try: \n{solution}"
99                         )
100 
101                     raise ValueError(
102                         f"Module is not a Sanic app, it is a {app_type_name}\n"
103                         f"  Perhaps you meant {self.args.module}:app?"
104                     )
105         return app
106 
107 
108 class CertLoader:
109     _creator_class: Type[CertCreator]
110 
111     def __init__(self, ssl_data: Dict[str, Union[str, os.PathLike]]):
112         creator_name = ssl_data.get("creator")
113         if creator_name not in ("mkcert", "trustme"):
114             raise RuntimeError(f"Unknown certificate creator: {creator_name}")
115         elif creator_name == "mkcert":
116             self._creator_class = MkcertCreator
117         elif creator_name == "trustme":
118             self._creator_class = TrustmeCreator
119 
120         self._key = ssl_data["key"]
121         self._cert = ssl_data["cert"]
122         self._localhost = cast(str, ssl_data["localhost"])
123 
124     def load(self, app: SanicApp):
125         creator = self._creator_class(app, self._key, self._cert)
126         return creator.generate_cert(self._localhost)
127
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/sanic/worker/loader.py b/sanic/worker/loader.py
--- a/sanic/worker/loader.py
+++ b/sanic/worker/loader.py
@@ -5,18 +5,10 @@
 
 from importlib import import_module
 from pathlib import Path
-from typing import (
-    TYPE_CHECKING,
-    Any,
-    Callable,
-    Dict,
-    Optional,
-    Type,
-    Union,
-    cast,
-)
+from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union, cast
 
-from sanic.http.tls.creators import CertCreator, MkcertCreator, TrustmeCreator
+from sanic.http.tls.context import process_to_context
+from sanic.http.tls.creators import MkcertCreator, TrustmeCreator
 
 
 if TYPE_CHECKING:
@@ -106,21 +98,30 @@
 
 
 class CertLoader:
-    _creator_class: Type[CertCreator]
+    _creators = {
+        "mkcert": MkcertCreator,
+        "trustme": TrustmeCreator,
+    }
 
     def __init__(self, ssl_data: Dict[str, Union[str, os.PathLike]]):
-        creator_name = ssl_data.get("creator")
-        if creator_name not in ("mkcert", "trustme"):
+        self._ssl_data = ssl_data
+
+        creator_name = cast(str, ssl_data.get("creator"))
+
+        self._creator_class = self._creators.get(creator_name)
+        if not creator_name:
+            return
+
+        if not self._creator_class:
             raise RuntimeError(f"Unknown certificate creator: {creator_name}")
-        elif creator_name == "mkcert":
-            self._creator_class = MkcertCreator
-        elif creator_name == "trustme":
-            self._creator_class = TrustmeCreator
 
         self._key = ssl_data["key"]
         self._cert = ssl_data["cert"]
         self._localhost = cast(str, ssl_data["localhost"])
 
     def load(self, app: SanicApp):
+        if not self._creator_class:
+            return process_to_context(self._ssl_data)
+
         creator = self._creator_class(app, self._key, self._cert)
         return creator.generate_cert(self._localhost)

{"golden_diff": "diff --git a/sanic/worker/loader.py b/sanic/worker/loader.py\n--- a/sanic/worker/loader.py\n+++ b/sanic/worker/loader.py\n@@ -5,18 +5,10 @@\n \n from importlib import import_module\n from pathlib import Path\n-from typing import (\n-    TYPE_CHECKING,\n-    Any,\n-    Callable,\n-    Dict,\n-    Optional,\n-    Type,\n-    Union,\n-    cast,\n-)\n+from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union, cast\n \n-from sanic.http.tls.creators import CertCreator, MkcertCreator, TrustmeCreator\n+from sanic.http.tls.context import process_to_context\n+from sanic.http.tls.creators import MkcertCreator, TrustmeCreator\n \n \n if TYPE_CHECKING:\n@@ -106,21 +98,30 @@\n \n \n class CertLoader:\n-    _creator_class: Type[CertCreator]\n+    _creators = {\n+        \"mkcert\": MkcertCreator,\n+        \"trustme\": TrustmeCreator,\n+    }\n \n     def __init__(self, ssl_data: Dict[str, Union[str, os.PathLike]]):\n-        creator_name = ssl_data.get(\"creator\")\n-        if creator_name not in (\"mkcert\", \"trustme\"):\n+        self._ssl_data = ssl_data\n+\n+        creator_name = cast(str, ssl_data.get(\"creator\"))\n+\n+        self._creator_class = self._creators.get(creator_name)\n+        if not creator_name:\n+            return\n+\n+        if not self._creator_class:\n             raise RuntimeError(f\"Unknown certificate creator: {creator_name}\")\n-        elif creator_name == \"mkcert\":\n-            self._creator_class = MkcertCreator\n-        elif creator_name == \"trustme\":\n-            self._creator_class = TrustmeCreator\n \n         self._key = ssl_data[\"key\"]\n         self._cert = ssl_data[\"cert\"]\n         self._localhost = cast(str, ssl_data[\"localhost\"])\n \n     def load(self, app: SanicApp):\n+        if not self._creator_class:\n+            return process_to_context(self._ssl_data)\n+\n         creator = self._creator_class(app, self._key, self._cert)\n         return creator.generate_cert(self._localhost)\n", "issue": "Certificates not created with `mkcert` or `trustme` raise a RuntimeError\nThe `CertLoader` class in `sanic-org/sanic/sanic/worker/loader.py` checks the creator of the certificate. If the creator is not `mkcert` or `trustme` then it raises a `RuntimeError`. This will prevent Sanic from running with certificates from any other sources.\r\n\n", "before_files": [{"content": "from __future__ import annotations\n\nimport os\nimport sys\n\nfrom importlib import import_module\nfrom pathlib import Path\nfrom typing import (\n    TYPE_CHECKING,\n    Any,\n    Callable,\n    Dict,\n    Optional,\n    Type,\n    Union,\n    cast,\n)\n\nfrom sanic.http.tls.creators import CertCreator, MkcertCreator, TrustmeCreator\n\n\nif TYPE_CHECKING:\n    from sanic import Sanic as SanicApp\n\n\nclass AppLoader:\n    def __init__(\n        self,\n        module_input: str = \"\",\n        as_factory: bool = False,\n        as_simple: bool = False,\n        args: Any = None,\n        factory: Optional[Callable[[], SanicApp]] = None,\n    ) -> None:\n        self.module_input = module_input\n        self.module_name = \"\"\n        self.app_name = \"\"\n        self.as_factory = as_factory\n        self.as_simple = as_simple\n        self.args = args\n        self.factory = factory\n        self.cwd = os.getcwd()\n\n        if module_input:\n            delimiter = \":\" if \":\" in module_input else \".\"\n            if module_input.count(delimiter):\n                module_name, app_name = module_input.rsplit(delimiter, 1)\n                self.module_name = module_name\n                self.app_name = app_name\n                if self.app_name.endswith(\"()\"):\n                    self.as_factory = True\n                    self.app_name = self.app_name[:-2]\n\n    def load(self) -> SanicApp:\n        module_path = os.path.abspath(self.cwd)\n        if module_path not in sys.path:\n            sys.path.append(module_path)\n\n        if self.factory:\n            return self.factory()\n        else:\n            from sanic.app import Sanic\n            from sanic.simple import create_simple_server\n\n            if self.as_simple:\n                path = Path(self.module_input)\n                app = create_simple_server(path)\n            else:\n                if self.module_name == \"\" and os.path.isdir(self.module_input):\n                    raise ValueError(\n                        \"App not found.\\n\"\n                        \"   Please use --simple if you are passing a \"\n                        \"directory to sanic.\\n\"\n                        f\"   eg. sanic {self.module_input} --simple\"\n                    )\n\n                module = import_module(self.module_name)\n                app = getattr(module, self.app_name, None)\n                if self.as_factory:\n                    try:\n                        app = app(self.args)\n                    except TypeError:\n                        app = app()\n\n                app_type_name = type(app).__name__\n\n                if (\n                    not isinstance(app, Sanic)\n                    and self.args\n                    and hasattr(self.args, \"module\")\n                ):\n                    if callable(app):\n                        solution = f\"sanic {self.args.module} --factory\"\n                        raise ValueError(\n                            \"Module is not a Sanic app, it is a \"\n                            f\"{app_type_name}\\n\"\n                            \"  If this callable returns a \"\n                            f\"Sanic instance try: \\n{solution}\"\n                        )\n\n                    raise ValueError(\n                        f\"Module is not a Sanic app, it is a {app_type_name}\\n\"\n                        f\"  Perhaps you meant {self.args.module}:app?\"\n                    )\n        return app\n\n\nclass CertLoader:\n    _creator_class: Type[CertCreator]\n\n    def __init__(self, ssl_data: Dict[str, Union[str, os.PathLike]]):\n        creator_name = ssl_data.get(\"creator\")\n        if creator_name not in (\"mkcert\", \"trustme\"):\n            raise RuntimeError(f\"Unknown certificate creator: {creator_name}\")\n        elif creator_name == \"mkcert\":\n            self._creator_class = MkcertCreator\n        elif creator_name == \"trustme\":\n            self._creator_class = TrustmeCreator\n\n        self._key = ssl_data[\"key\"]\n        self._cert = ssl_data[\"cert\"]\n        self._localhost = cast(str, ssl_data[\"localhost\"])\n\n    def load(self, app: SanicApp):\n        creator = self._creator_class(app, self._key, self._cert)\n        return creator.generate_cert(self._localhost)\n", "path": "sanic/worker/loader.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport os\nimport sys\n\nfrom importlib import import_module\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Union, cast\n\nfrom sanic.http.tls.context import process_to_context\nfrom sanic.http.tls.creators import MkcertCreator, TrustmeCreator\n\n\nif TYPE_CHECKING:\n    from sanic import Sanic as SanicApp\n\n\nclass AppLoader:\n    def __init__(\n        self,\n        module_input: str = \"\",\n        as_factory: bool = False,\n        as_simple: bool = False,\n        args: Any = None,\n        factory: Optional[Callable[[], SanicApp]] = None,\n    ) -> None:\n        self.module_input = module_input\n        self.module_name = \"\"\n        self.app_name = \"\"\n        self.as_factory = as_factory\n        self.as_simple = as_simple\n        self.args = args\n        self.factory = factory\n        self.cwd = os.getcwd()\n\n        if module_input:\n            delimiter = \":\" if \":\" in module_input else \".\"\n            if module_input.count(delimiter):\n                module_name, app_name = module_input.rsplit(delimiter, 1)\n                self.module_name = module_name\n                self.app_name = app_name\n                if self.app_name.endswith(\"()\"):\n                    self.as_factory = True\n                    self.app_name = self.app_name[:-2]\n\n    def load(self) -> SanicApp:\n        module_path = os.path.abspath(self.cwd)\n        if module_path not in sys.path:\n            sys.path.append(module_path)\n\n        if self.factory:\n            return self.factory()\n        else:\n            from sanic.app import Sanic\n            from sanic.simple import create_simple_server\n\n            if self.as_simple:\n                path = Path(self.module_input)\n                app = create_simple_server(path)\n            else:\n                if self.module_name == \"\" and os.path.isdir(self.module_input):\n                    raise ValueError(\n                        \"App not found.\\n\"\n                        \"   Please use --simple if you are passing a \"\n                        \"directory to sanic.\\n\"\n                        f\"   eg. sanic {self.module_input} --simple\"\n                    )\n\n                module = import_module(self.module_name)\n                app = getattr(module, self.app_name, None)\n                if self.as_factory:\n                    try:\n                        app = app(self.args)\n                    except TypeError:\n                        app = app()\n\n                app_type_name = type(app).__name__\n\n                if (\n                    not isinstance(app, Sanic)\n                    and self.args\n                    and hasattr(self.args, \"module\")\n                ):\n                    if callable(app):\n                        solution = f\"sanic {self.args.module} --factory\"\n                        raise ValueError(\n                            \"Module is not a Sanic app, it is a \"\n                            f\"{app_type_name}\\n\"\n                            \"  If this callable returns a \"\n                            f\"Sanic instance try: \\n{solution}\"\n                        )\n\n                    raise ValueError(\n                        f\"Module is not a Sanic app, it is a {app_type_name}\\n\"\n                        f\"  Perhaps you meant {self.args.module}:app?\"\n                    )\n        return app\n\n\nclass CertLoader:\n    _creators = {\n        \"mkcert\": MkcertCreator,\n        \"trustme\": TrustmeCreator,\n    }\n\n    def __init__(self, ssl_data: Dict[str, Union[str, os.PathLike]]):\n        self._ssl_data = ssl_data\n\n        creator_name = cast(str, ssl_data.get(\"creator\"))\n\n        self._creator_class = self._creators.get(creator_name)\n        if not creator_name:\n            return\n\n        if not self._creator_class:\n            raise RuntimeError(f\"Unknown certificate creator: {creator_name}\")\n\n        self._key = ssl_data[\"key\"]\n        self._cert = ssl_data[\"cert\"]\n        self._localhost = cast(str, ssl_data[\"localhost\"])\n\n    def load(self, app: SanicApp):\n        if not self._creator_class:\n            return process_to_context(self._ssl_data)\n\n        creator = self._creator_class(app, self._key, self._cert)\n        return creator.generate_cert(self._localhost)\n", "path": "sanic/worker/loader.py"}]}