mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-04 17:11:01 +00:00
Portduino: Set Web SSL Cert / Key paths from yaml (#5961)
This commit is contained in:
@@ -65,6 +65,9 @@ mail: marchammermann@googlemail.com
|
||||
#define DEFAULT_REALM "default_realm"
|
||||
#define PREFIX ""
|
||||
|
||||
#define KEY_PATH settingsStrings[websslkeypath].c_str()
|
||||
#define CERT_PATH settingsStrings[websslcertpath].c_str()
|
||||
|
||||
struct _file_config configWeb;
|
||||
|
||||
// We need to specify some content-type mapping, so the resources get delivered with the
|
||||
@@ -384,13 +387,13 @@ char *read_file_into_string(const char *filename)
|
||||
int PiWebServerThread::CheckSSLandLoad()
|
||||
{
|
||||
// read certificate
|
||||
cert_pem = read_file_into_string("certificate.pem");
|
||||
cert_pem = read_file_into_string(CERT_PATH);
|
||||
if (cert_pem == NULL) {
|
||||
LOG_ERROR("ERROR SSL Certificate File can't be loaded or is missing");
|
||||
return 1;
|
||||
}
|
||||
// read private key
|
||||
key_pem = read_file_into_string("private_key.pem");
|
||||
key_pem = read_file_into_string(KEY_PATH);
|
||||
if (key_pem == NULL) {
|
||||
LOG_ERROR("ERROR file private_key can't be loaded or is missing");
|
||||
return 2;
|
||||
@@ -415,8 +418,8 @@ int PiWebServerThread::CreateSSLCertificate()
|
||||
return 2;
|
||||
}
|
||||
|
||||
// Ope file to write private key file
|
||||
FILE *pkey_file = fopen("private_key.pem", "wb");
|
||||
// Open file to write private key file
|
||||
FILE *pkey_file = fopen(KEY_PATH, "wb");
|
||||
if (!pkey_file) {
|
||||
LOG_ERROR("Error opening private key file");
|
||||
return 3;
|
||||
@@ -426,18 +429,19 @@ int PiWebServerThread::CreateSSLCertificate()
|
||||
fclose(pkey_file);
|
||||
|
||||
// open Certificate file
|
||||
FILE *x509_file = fopen("certificate.pem", "wb");
|
||||
FILE *x509_file = fopen(CERT_PATH, "wb");
|
||||
if (!x509_file) {
|
||||
LOG_ERROR("Error opening cert");
|
||||
return 4;
|
||||
}
|
||||
// write cirtificate
|
||||
// write certificate
|
||||
PEM_write_X509(x509_file, x509);
|
||||
fclose(x509_file);
|
||||
|
||||
EVP_PKEY_free(pkey);
|
||||
LOG_INFO("Create SSL Key %s successful", KEY_PATH);
|
||||
X509_free(x509);
|
||||
LOG_INFO("Create SSL Cert -certificate.pem- succesfull ");
|
||||
LOG_INFO("Create SSL Cert %s successful", CERT_PATH);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -524,7 +524,12 @@ bool loadConfig(const char *configPath)
|
||||
|
||||
if (yamlConfig["Webserver"]) {
|
||||
settingsMap[webserverport] = (yamlConfig["Webserver"]["Port"]).as<int>(-1);
|
||||
settingsStrings[webserverrootpath] = (yamlConfig["Webserver"]["RootPath"]).as<std::string>("");
|
||||
settingsStrings[webserverrootpath] =
|
||||
(yamlConfig["Webserver"]["RootPath"]).as<std::string>("/usr/share/meshtasticd/web");
|
||||
settingsStrings[websslkeypath] =
|
||||
(yamlConfig["Webserver"]["SSLKey"]).as<std::string>("/etc/meshtasticd/ssl/private_key.pem");
|
||||
settingsStrings[websslcertpath] =
|
||||
(yamlConfig["Webserver"]["SSLCert"]).as<std::string>("/etc/meshtasticd/ssl/certificate.pem");
|
||||
}
|
||||
|
||||
if (yamlConfig["General"]) {
|
||||
|
||||
@@ -81,6 +81,8 @@ enum configNames {
|
||||
webserver,
|
||||
webserverport,
|
||||
webserverrootpath,
|
||||
websslkeypath,
|
||||
websslcertpath,
|
||||
maxtophone,
|
||||
maxnodes,
|
||||
ascii_logs,
|
||||
|
||||
Reference in New Issue
Block a user