Skip to content

Commit

Permalink
introduce CA single-file bundle support
Browse files Browse the repository at this point in the history
- smithproxy must be reconfigured, settings/ca_bundle_file must contain file
  with the CA bundle. The value is by default empty.
  Using this bundle is preferred, **if set** (non-default).

- add `sx_download_ca_bundle` helper script, which will download curl CA bundle.
  (distilled Mozilla CA bundle).

- patch for new feature request issue #33
  • Loading branch information
astibal committed Dec 7, 2022
1 parent 1cd9ba1 commit cdfa705
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 8 deletions.
6 changes: 6 additions & 0 deletions install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ if(UNIX)
WORLD_READ WORLD_EXECUTE
)

install(FILES tools/sx_download_ca_bundle DESTINATION bin
PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE
)

install(FILES man/TESTING_README.txt DESTINATION share/smithproxy/docs)

Expand Down
6 changes: 6 additions & 0 deletions snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ apps:
plugs:
- network

download-ca-bundle:
command: usr/bin/sx_download_ca_bundle
plugs:
- network


net:
command: usr/bin/sx_network
plugs:
Expand Down
2 changes: 1 addition & 1 deletion socle
Submodule socle updated 2 files
+107 −28 sslcertstore.cpp
+17 −3 sslcertstore.hpp
13 changes: 7 additions & 6 deletions src/service/cfgapi/cfgapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,10 @@ bool CfgFactory::upgrade_schema(int upgrade_to_num) {

return true;
}



else if(upgrade_to_num == 1013) {
log.event(INF, "added settings.certs_ca_file");
return true;
}

return false;
}
Expand Down Expand Up @@ -642,9 +643,8 @@ bool CfgFactory::load_settings () {
}


if(! load_if_exists(cfgapi.getRoot()["settings"], "ca_bundle_path",SSLFactory::factory().ca_path())) {
load_if_exists(cfgapi.getRoot()["settings"], "certs_ca_path", SSLFactory::factory().ca_path());
}
load_if_exists(cfgapi.getRoot()["settings"], "ca_bundle_path",SSLFactory::factory().ca_path());
load_if_exists(cfgapi.getRoot()["settings"], "ca_bundle_file", SSLFactory::factory().ca_file());

load_if_exists(cfgapi.getRoot()["settings"], "ssl_autodetect",MitmMasterProxy::ssl_autodetect);
load_if_exists(cfgapi.getRoot()["settings"], "ssl_autodetect_harder",MitmMasterProxy::ssl_autodetect_harder);
Expand Down Expand Up @@ -4565,6 +4565,7 @@ int save_settings(Config& ex) {
objects.add("certs_ca_key_password", Setting::TypeString) = SSLFactory::factory().certs_password();
objects.add("certs_ctlog", Setting::TypeString) = SSLFactory::factory().ctlogfile();
objects.add("ca_bundle_path", Setting::TypeString) = SSLFactory::factory().ca_path();
objects.add("ca_bundle_file", Setting::TypeString) = SSLFactory::factory().ca_file();

objects.add("plaintext_port", Setting::TypeString) = CfgFactory::get()->listen_tcp_port_base;
objects.add("plaintext_workers", Setting::TypeInt) = CfgFactory::get()->num_workers_tcp;
Expand Down
2 changes: 1 addition & 1 deletion src/service/cfgapi/cfgapi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class CfgFactory : public CfgFactoryBase {
// static inline bool config_changed_flag = false;

// Each version bump implies a config upgrade - we start on 1000
constexpr static inline const int SCHEMA_VERSION = 1012;
constexpr static inline const int SCHEMA_VERSION = 1013;

CfgFactory() = default;
CfgFactory(CfgFactory const &) = delete;
Expand Down
5 changes: 5 additions & 0 deletions src/service/cfgapi/cfgvalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ void CfgValueHelp::init() {
.may_be_empty(false)
.value_filter(CfgValue::VALUE_DIR);

add("settings.ca_bundle_file", "trusted CA bundle file (preferred over directory)")
.help_quick("<string>: enter valid path to file")
.may_be_empty(true)
.value_filter(CfgValue::VALUE_FILE);

// listening ports

add("settings.plaintext_port", "base divert port for non-SSL TCP traffic")
Expand Down
6 changes: 6 additions & 0 deletions src/service/cmd/diag/diag_cmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ int cli_diag_ssl_cache_stats(struct cli_def *cli, const char *command, char *arg

size_t n_cache = 0;
int n_maxsize = 0;
bool ver_bundle = store->stats.ca_verify_use_file;
bool sto_bundle = store->stats.ca_store_use_file;

{
auto lc_ = std::scoped_lock(store->lock());
n_cache = store->cache().cache().size();
Expand All @@ -116,6 +119,9 @@ int cli_diag_ssl_cache_stats(struct cli_def *cli, const char *command, char *arg
cli_print(cli,"certificate store stats: ");
cli_print(cli," cache size: %zu ", n_cache);
cli_print(cli," max size: %d ", n_maxsize);
cli_print(cli," cert verify from bundle: %d", ver_bundle);
cli_print(cli," cert store from bundle: %d", sto_bundle);


return CLI_OK;
}
Expand Down
18 changes: 18 additions & 0 deletions tools/sx_download_ca_bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

FILE_PATH="/etc/smithproxy/certs/ca_curl_bundle.pem"
FILE_URL="https://curl.se/ca/cacert.pem"

wget ${FILE_URL} -O ${FILE_PATH}

if [ $? -ne 0 ]; then
echo " !!! Sorry, something went wrong..."
else
echo
echo " => file saved here: ${FILE_PATH}"
echo " !!! Smithproxy must be reconfigured to use this CA bundle and then restarted."
echo
fi



0 comments on commit cdfa705

Please sign in to comment.