Skip to content

Commit

Permalink
add authenticated API endpoint to reload custom certificates
Browse files Browse the repository at this point in the history
- /api/do/ssl/custom/reload
  json is returned with the status and count of installed certificates
  • Loading branch information
astibal committed Apr 20, 2024
1 parent ca38879 commit 69a82f3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/service/httpd/do/do_comands.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Smithproxy- transparent proxy with SSL inspection capabilities.
Copyright (c) 2014, Ales Stibal <[email protected]>, All rights reserved.
Smithproxy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Smithproxy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Smithproxy. If not, see <http://www.gnu.org/licenses/>.
Linking Smithproxy statically or dynamically with other modules is
making a combined work based on Smithproxy. Thus, the terms and
conditions of the GNU General Public License cover the whole combination.
In addition, as a special exception, the copyright holders of Smithproxy
give you permission to combine Smithproxy with free software programs
or libraries that are released under the GNU LGPL and with code
included in the standard release of OpenSSL under the OpenSSL's license
(or modified versions of such code, with unchanged license).
You may copy and distribute such a system following the terms
of the GNU GPL for Smithproxy and the licenses of the other code
concerned, provided that you include the source code of that other code
when and as the GNU GPL requires distribution of source code.
Note that people who make modified versions of Smithproxy are not
obligated to grant this special exception for their modified versions;
it is their choice whether to do so. The GNU General Public License
gives permission to release a modified version without this exception;
this exception also makes it possible to release a modified version
which carries forward this exception.
*/

#include <nlohmann/json.hpp>

#include <ext/lmhpp/include/lmhttpd.hpp>
#include <service/httpd/util.hpp>
#include <service/http/jsonize.hpp>


static nlohmann::json json_do_ssl_custom_reload(struct MHD_Connection * connection, std::string const& meth, std::string const& req) {

using namespace jsonize;

auto& store = SSLFactory::factory();
auto lc_ = std::scoped_lock(store.lock());

store.cache_custom().clear();
auto ret = store.load_custom_certificates();

return {
{"result", ret },
{"count", store.cache_custom().size()},
};

}

13 changes: 13 additions & 0 deletions src/service/httpd/handlers/dispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <service/httpd/diag/diag_ssl.hpp>
#include <service/httpd/diag/daig_proxy.hpp>

#include <service/httpd/do/do_comands.hpp>

#include <service/httpd/cfg/add.hpp>
#include <service/httpd/cfg/set.hpp>
#include <service/httpd/cfg/get.hpp>
Expand Down Expand Up @@ -93,6 +95,17 @@ namespace sx::webserver::dispatchers {
server.addController(&handler);
}

for(auto const& meth: {"GET", "POST"}) {
static Http_Responder handler(
meth,
"/api/do/ssl/custom/reload",
authorized::token_protected<json>(json_do_ssl_custom_reload)
);
handler.Content_Type = "application/json";
server.addController(&handler);
}


}

void controller_add_uni(lmh::WebServer &server) {
Expand Down

0 comments on commit 69a82f3

Please sign in to comment.