Commit b050e41e authored by jan.koester's avatar jan.koester
Browse files

realod certs

parent 938a730e
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -1828,5 +1828,30 @@ std::vector<netplus::socket*> libhttppp::HttpD::getServerSockets(){
    return sockets;
}

bool libhttppp::HttpD::reloadCertificates(const std::string &certpath, const std::string &keypath, const std::string &password) {
    netplus::ssl::CertificateBundle bundle;
    if (!bundle.loadFromFile(certpath, keypath, password)) {
        return false;
    }
    if (!bundle.cert.checkValidity()) {
        return false;
    }

    // Update internal bundle map
    for (auto &[addr, _] : _certBundle) {
        _certBundle[addr] = bundle;
    }

    // Push new certs to all ssl/quic server sockets
    for (auto &sock : _ServerSockets) {
        if (auto *s = dynamic_cast<netplus::ssl*>(sock.get())) {
            s->setCertificates(_certBundle);
        } else if (auto *q = dynamic_cast<netplus::quic*>(sock.get())) {
            q->setCertificates(_certBundle);
        }
    }
    return true;
}

libhttppp::HttpD::~HttpD(){
}
+3 −0
Original line number Diff line number Diff line
@@ -130,6 +130,9 @@ namespace libhttppp {
        HttpD(const std::string &httpaddr, int port, int maxconnections, const std::string &sslcertpath, const  std::string &sslkeypath, const std::string &sslpassword = "");
        ~HttpD();
        std::vector<netplus::socket*> getServerSockets();

        // Reload SSL certificates from file(s). Updates all ssl/quic server sockets.
        bool reloadCertificates(const std::string &certpath, const std::string &keypath, const std::string &password = "");
    protected:
        void                        FileServer();
    private: