Skip to content

Commit

Permalink
Add CAFile and CAPath config options, use mbedtls in static builds
Browse files Browse the repository at this point in the history
This is how we'll handle systems where the cert bundle and cert directory is stored where mbedtls doesn't expect it.

Also update tpt-libs to get new curl and mbedtls.
  • Loading branch information
LBPHacker committed Sep 25, 2022
1 parent b4213a2 commit 09c2704
Show file tree
Hide file tree
Showing 61 changed files with 214 additions and 185 deletions.
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ tpt_libs_debug = is_debug ? 'debug' : 'release'
tpt_libs_variant = '@0@-@1@-@2@-@3@'.format(host_arch, host_platform, host_libc, tpt_libs_static)
tpt_libs_vtag = get_option('tpt_libs_vtag')
if tpt_libs_vtag == ''
tpt_libs_vtag = 'v20220901212941'
tpt_libs_vtag = 'v20220922162009'
endif
if tpt_libs_static != 'none'
if tpt_libs_variant not in [
Expand Down
50 changes: 32 additions & 18 deletions src/PowderToySDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ std::map<ByteString, ByteString> readArguments(int argc, char * argv[])
//Defaults
arguments["scale"] = "";
arguments["proxy"] = "";
arguments["cafile"] = "";
arguments["capath"] = "";
arguments["nohud"] = "false"; //the nohud, sound, and scripts commands currently do nothing.
arguments["sound"] = "false";
arguments["kiosk"] = "false";
Expand All @@ -346,6 +348,20 @@ std::map<ByteString, ByteString> readArguments(int argc, char * argv[])
else
arguments["proxy"] = "false";
}
else if (!strncmp(argv[i], "cafile:", 7))
{
if(argv[i][7])
arguments["cafile"] = &argv[i][7];
else
arguments["cafile"] = "false";
}
else if (!strncmp(argv[i], "capath:", 7))
{
if(argv[i][7])
arguments["capath"] = &argv[i][7];
else
arguments["capath"] = "false";
}
else if (!strncmp(argv[i], "nohud", 5))
{
arguments["nohud"] = "true";
Expand Down Expand Up @@ -818,34 +834,32 @@ int main(int argc, char * argv[])
Client::Ref().SetPref("Scale", scale);
}

ByteString proxyString = "";
if(arguments["proxy"].length())
{
if(arguments["proxy"] == "false")
auto clientConfig = [](ByteString cmdlineValue, ByteString configName, ByteString defaultValue) {
ByteString value;
if (cmdlineValue.length())
{
proxyString = "";
Client::Ref().SetPref("Proxy", "");
value = cmdlineValue;
if (value == "false")
{
value = defaultValue;
}
Client::Ref().SetPref(configName, value);
}
else
{
proxyString = (arguments["proxy"]);
Client::Ref().SetPref("Proxy", arguments["proxy"]);
value = Client::Ref().GetPrefByteString(configName, defaultValue);
}
}
else
{
auto proxyPref = Client::Ref().GetPrefByteString("Proxy", "");
if (proxyPref.length())
{
proxyString = proxyPref;
}
}
return value;
};
ByteString proxyString = clientConfig(arguments["proxy"], "Proxy", "");
ByteString cafileString = clientConfig(arguments["cafile"], "CAFile", "");
ByteString capathString = clientConfig(arguments["capath"], "CAPath", "");

bool disableNetwork = false;
if (arguments.find("disable-network") != arguments.end())
disableNetwork = true;

Client::Ref().Initialise(proxyString, disableNetwork);
Client::Ref().Initialise(proxyString, cafileString, capathString, disableNetwork);

// TODO: maybe bind the maximum allowed scale to screen size somehow
if(scale < 1 || scale > SCALE_MAXIMUM)
Expand Down
4 changes: 2 additions & 2 deletions src/client/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Client::Client():
firstRun = true;
}

void Client::Initialise(ByteString proxyString, bool disableNetwork)
void Client::Initialise(ByteString proxy, ByteString cafile, ByteString capath, bool disableNetwork)
{
#if !defined(FONTEDITOR) && !defined(RENDERER)
if (GetPrefBool("version.update", false))
Expand All @@ -116,7 +116,7 @@ void Client::Initialise(ByteString proxyString, bool disableNetwork)

#ifndef NOHTTP
if (!disableNetwork)
http::RequestManager::Ref().Initialise(proxyString);
http::RequestManager::Ref().Initialise(proxy, cafile, capath);
#endif

//Read stamps library
Expand Down
2 changes: 1 addition & 1 deletion src/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Client: public Singleton<Client> {
void SetMessageOfTheDay(String message);
String GetMessageOfTheDay();

void Initialise(ByteString proxyString, bool disableNetwork);
void Initialise(ByteString proxy, ByteString cafile, ByteString capath, bool disableNetwork);
bool IsFirstRun();

bool ReadFile(std::vector<char> &fileData, ByteString filename);
Expand Down
8 changes: 8 additions & 0 deletions src/client/http/Request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ namespace http
{
curl_easy_setopt(easy, CURLOPT_PROXY, proxy.c_str());
}
if (cafile.size())
{
curl_easy_setopt(easy, CURLOPT_CAINFO, cafile.c_str());
}
if (capath.size())
{
curl_easy_setopt(easy, CURLOPT_CAPATH, capath.c_str());
}

curl_easy_setopt(easy, CURLOPT_PRIVATE, (void *)this);
curl_easy_setopt(easy, CURLOPT_USERAGENT, user_agent.c_str());
Expand Down
4 changes: 0 additions & 4 deletions src/client/http/Request.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ namespace http
};

String StatusText(int code);

extern const long timeout;
extern ByteString proxy;
extern ByteString user_agent;
}

#endif // REQUEST_H
8 changes: 6 additions & 2 deletions src/client/http/RequestManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace http
{
const long timeout = 15;
ByteString proxy;
ByteString cafile;
ByteString capath;
ByteString user_agent;

void RequestManager::Shutdown()
Expand All @@ -33,7 +35,7 @@ namespace http
}
}

void RequestManager::Initialise(ByteString Proxy)
void RequestManager::Initialise(ByteString newProxy, ByteString newCafile, ByteString newCapath)
{
curl_global_init(CURL_GLOBAL_DEFAULT);
multi = curl_multi_init();
Expand All @@ -42,7 +44,9 @@ namespace http
curl_multi_setopt(multi, CURLMOPT_MAX_HOST_CONNECTIONS, curl_max_host_connections);
}

proxy = Proxy;
proxy = newProxy;
cafile = newCafile;
capath = newCapath;

user_agent =
"PowderToy/" MTOS(SAVE_VERSION) "." MTOS(MINOR_VERSION) " ("
Expand Down
4 changes: 3 additions & 1 deletion src/client/http/RequestManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ namespace http
RequestManager() { }
~RequestManager() { }

void Initialise(ByteString proxy);
void Initialise(ByteString newProxy, ByteString newCafile, ByteString newCapath);
void Shutdown();

friend class Request;
};

extern const long timeout;
extern ByteString proxy;
extern ByteString cafile;
extern ByteString capath;
extern ByteString user_agent;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-aarch64-android-bionic-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-aarch64-android-bionic-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-aarch64-android-bionic-static-debug-v20220922162009.zip
source_hash = c588dbe9bda6e2fdfe18af0bea923bc219b0c34eae7666b530738d61e795e2cd

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-aarch64-android-bionic-static-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-aarch64-android-bionic-static-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-aarch64-android-bionic-static-release-v20220922162009.zip
source_hash = 60338e3e271d9cb22023ce29ffded26442b43f5a4c77ffb3eebb1a67638fff2c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-aarch64-darwin-macos-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-aarch64-darwin-macos-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-aarch64-darwin-macos-static-debug-v20220922162009.zip
source_hash = e26e7b15250d991e724fdb028e822b66e5b5a78ed79a7d38f133a19f07f1cbd6

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-aarch64-darwin-macos-static-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-aarch64-darwin-macos-static-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-aarch64-darwin-macos-static-release-v20220922162009.zip
source_hash = 68a7f6b39c3ec4cef01413fefffcd7a55e6ccd7942aba17436902a22d37a5b25

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-arm-android-bionic-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-arm-android-bionic-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-arm-android-bionic-static-debug-v20220922162009.zip
source_hash = 5d7c874ae9a9ced23c1baabe77439d7f731c2e21fc17a34bfc41cfcab47a5137

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-arm-android-bionic-static-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-arm-android-bionic-static-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-arm-android-bionic-static-release-v20220922162009.zip
source_hash = d8cd33587ef3073d4ef8b06277ab9a68966964adf784371984ec6e38e2eb6734

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86-android-bionic-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86-android-bionic-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86-android-bionic-static-debug-v20220922162009.zip
source_hash = a3f0d9dfa85a1c4200440288dd2722ca69ef1b1bfb3857c977d361547eabbc90

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86-android-bionic-static-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86-android-bionic-static-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86-android-bionic-static-release-v20220922162009.zip
source_hash = 53f4e74cc8f8513a105ab06cebcdcb6b4ba5bf6769bf86f67116d269566b0303

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86-windows-msvc-dynamic-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86-windows-msvc-dynamic-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86-windows-msvc-dynamic-debug-v20220922162009.zip
source_hash = a424585f7bc179d50e2e8f6687ee250156f8ff422af40d7368af737092735688

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86-windows-msvc-dynamic-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86-windows-msvc-dynamic-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86-windows-msvc-dynamic-release-v20220922162009.zip
source_hash = 54863c2913c4a52fca5f9877760ee02e03b8da5e8d13fea582af3a19c176bc7c

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86-windows-msvc-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86-windows-msvc-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86-windows-msvc-static-debug-v20220922162009.zip
source_hash = c6bb9d564d9d9101521ab7cbc8649168731a6753d4d6c1615d5f802200ee7e67

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86-windows-msvc-static-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86-windows-msvc-static-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86-windows-msvc-static-release-v20220922162009.zip
source_hash = d6c9a7f3939d8099a1e59a4a9de5a473e20496e33007b9d07785a8bc53e47013

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-android-bionic-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86_64-android-bionic-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86_64-android-bionic-static-debug-v20220922162009.zip
source_hash = 85978422d719ce70ea80e815a451a37978ae203b227e67ad8fc688de7795a6ad

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-android-bionic-static-release-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86_64-android-bionic-static-release-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86_64-android-bionic-static-release-v20220922162009.zip
source_hash = c7eb4d2c17b408253e3adf108c85e1338e58688a7e690c7471646ab0f336d013

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[wrap-file]
directory = tpt-libs-prebuilt-x86_64-darwin-macos-static-debug-v20220922162009

source_url = https://github.com/The-Powder-Toy/tpt-libs/releases/download/v20220922162009/tpt-libs-prebuilt-x86_64-darwin-macos-static-debug-v20220922162009.zip
source_filename = tpt-libs-prebuilt-x86_64-darwin-macos-static-debug-v20220922162009.zip
source_hash = e14b836dc267697addf7aeac650ed60e7d91659422c31eea7e6439ca9a5117df
Loading

0 comments on commit 09c2704

Please sign in to comment.