Cert endpoints.
This commit is contained in:
@@ -15,3 +15,21 @@ BASE_CONFIG_SCHEMA = {
|
||||
},
|
||||
"required": ["server_name", "report_stats"],
|
||||
}
|
||||
|
||||
CERT_PATHS_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"cert_path": {"type": "string", "minlength": 1},
|
||||
"cert_key_path": {"type": "string", "minlength": 1},
|
||||
},
|
||||
"required": ["cert_path", "cert_key_path"],
|
||||
}
|
||||
|
||||
CERTS_SCHEMA = {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"cert": {"type": "string", "minlength": 1},
|
||||
"cert_key": {"type": "string", "minlength": 1},
|
||||
},
|
||||
"required": ["cert", "cert_key"],
|
||||
}
|
||||
|
||||
@@ -6,7 +6,12 @@ from synapse_topology import model
|
||||
from twisted.web.static import File
|
||||
|
||||
from . import error_handlers
|
||||
from .schemas import BASE_CONFIG_SCHEMA, SERVERNAME_SCHEMA
|
||||
from .schemas import (
|
||||
BASE_CONFIG_SCHEMA,
|
||||
SERVERNAME_SCHEMA,
|
||||
CERT_PATHS_SCHEMA,
|
||||
CERTS_SCHEMA,
|
||||
)
|
||||
from .utils import validate_schema
|
||||
|
||||
from . import app
|
||||
@@ -61,3 +66,22 @@ with app.subroute("/config") as app:
|
||||
@app.route("/config/{}".format(config), methods=["POST"])
|
||||
def set_sub_config(request, sub_config):
|
||||
model.set_config(json.loads(request.content.read()), sub_config=config)
|
||||
|
||||
|
||||
@app.route("/testcertpaths", methods=["POST"])
|
||||
@validate_schema(CERT_PATHS_SCHEMA)
|
||||
def test_cert_paths(request, body):
|
||||
result = {}
|
||||
for path in ["cert_path", "cert_key_path"]:
|
||||
try:
|
||||
with open(body[path], "r"):
|
||||
result[path + "_invalid"] = False
|
||||
except:
|
||||
result[path + "_invalid"] = True
|
||||
return json.dumps(result)
|
||||
|
||||
|
||||
@app.route("/certs", methods=["POST"])
|
||||
@validate_schema(CERTS_SCHEMA)
|
||||
def upload_certs(request, body):
|
||||
model.add_certs(**body)
|
||||
|
||||
@@ -82,3 +82,13 @@ def get_secret_key():
|
||||
|
||||
def verify_yaml():
|
||||
pass
|
||||
|
||||
|
||||
def add_certs(cert, cert_key):
|
||||
with open(
|
||||
path.join(config_dir, get_server_name() + ".tls.crt"), "w"
|
||||
) as cert_file, open(
|
||||
path.join(config_dir, get_server_name() + ".tls.key"), "w"
|
||||
) as key_file:
|
||||
cert_file.write(cert)
|
||||
key_file.write(cert_key)
|
||||
|
||||
Reference in New Issue
Block a user