1
0

Cert endpoints.

This commit is contained in:
Jorik Schellekens
2019-08-02 19:05:06 +01:00
parent cd0cb18d94
commit 9280882cb9
3 changed files with 53 additions and 1 deletions

View File

@@ -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"],
}

View File

@@ -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)

View File

@@ -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)