Skip to content

Commit f2d2bdc

Browse files
committed
add way to disable cert verification
1 parent ed898a1 commit f2d2bdc

7 files changed

Lines changed: 62 additions & 5 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else()
99
set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
1010
endif()
1111

12-
project(argon VERSION 1.1.2)
12+
project(argon VERSION 1.1.3)
1313

1414
file(GLOB_RECURSE SOURCES
1515
src/*.cpp

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.1.3
2+
3+
* Improve error messages further
4+
* Add a way to disable SSL certificate verification for web requests
5+
16
# 1.1.2
27

38
* Slightly improve error messages

include/argon/argon.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ namespace argon {
3838
// Set the URL of the used Argon server, not thread-safe.
3939
geode::Result<> setServerUrl(std::string url);
4040

41+
// Enable or disable SSL certificate verification, by default is enabled.
42+
void setCertVerification(bool state);
43+
44+
// Get whether certificate verification is enabled
45+
bool getCertVerification();
46+
4147
// Initializes the config lock structure for interoperability between other mods using Argon.
4248
// Should be called from the main thread once the game has at least reached the loading screen
4349
// (what matters is that GameManager::init has been run.)

src/main.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ Result<> setServerUrl(std::string url) {
109109
return ArgonState::get().setServerUrl(std::move(url));
110110
}
111111

112+
void setCertVerification(bool state) {
113+
ArgonState::get().setCertVerification(true);
114+
}
115+
116+
bool getCertVerification() {
117+
return ArgonState::get().getCertVerification();
118+
}
119+
112120
void initConfigLock() {
113121
ArgonState::get().initConfigLock();
114122
}

src/state.cpp

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ asp::Mutex<>::Guard ArgonState::lockServerUrl() {
8080
return serverUrlMtx.lock();
8181
}
8282

83+
void ArgonState::setCertVerification(bool state) {
84+
this->certVerification = state;
85+
}
86+
87+
bool ArgonState::getCertVerification() const {
88+
return this->certVerification;
89+
}
90+
8391
std::lock_guard<std::mutex> ArgonState::acquireConfigLock() {
8492
if (!configLock) {
8593
this->initConfigLock();
@@ -227,9 +235,18 @@ void ArgonState::processStage1Response(PendingRequest* req, web::WebResponse* re
227235
auto res = response->json();
228236

229237
if (!res) {
238+
auto str = response->string().unwrapOrDefault();
239+
230240
log::warn("(Argon) Stage 1 request failed with code {}, server did not send a JSON, dumping server response.", response->code());
231-
log::warn("{}", response->string().unwrapOrDefault());
232-
this->handleStage1Error(req, fmt::format("Unknown server error ({})", response->code()));
241+
log::warn("Response: {}", str);
242+
log::warn("Curl (extra) error message: {}", response->errorMessage());
243+
244+
if (response->code() == -1) {
245+
this->handleStage1Error(req, fmt::format("Unknown request error: ", truncate(str).asBorrowed()));
246+
} else {
247+
this->handleStage1Error(req, fmt::format("Unknown server error (code {}): {}", response->code(), truncate(str).asBorrowed()));
248+
}
249+
233250
return;
234251
}
235252

@@ -299,9 +316,18 @@ void ArgonState::processStage3Response(PendingRequest* req, web::WebResponse* re
299316
auto res = response->json();
300317

301318
if (!res) {
319+
auto str = response->string().unwrapOrDefault();
320+
302321
log::warn("(Argon) Stage 3 request failed with code {}, server did not send a JSON, dumping server response.", response->code());
303-
log::warn("{}", response->string().unwrapOrDefault());
304-
this->handleStage3Error(req, fmt::format("Unknown server error ({})", response->code()));
322+
log::warn("Response: {}", str);
323+
log::warn("Curl (extra) error message: {}", response->errorMessage());
324+
325+
if (response->code() == -1) {
326+
this->handleStage3Error(req, fmt::format("Unknown request error: ", truncate(str).asBorrowed()));
327+
} else {
328+
this->handleStage3Error(req, fmt::format("Unknown server error (code {}): {}", response->code(), truncate(str).asBorrowed()));
329+
}
330+
305331
return;
306332
}
307333

src/state.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@ class ArgonState : public SingletonBase<ArgonState> {
3838
geode::Result<> setServerUrl(std::string url);
3939
std::string_view getServerUrl() const;
4040
asp::Mutex<>::Guard lockServerUrl();
41+
42+
void setCertVerification(bool state);
43+
bool getCertVerification() const;
44+
4145
std::lock_guard<std::mutex> acquireConfigLock();
4246
void initConfigLock();
47+
4348
std::optional<asp::time::Duration> isInProgress(int accountId);
4449
void killAuthAttempt(int accountId);
4550

@@ -53,6 +58,7 @@ class ArgonState : public SingletonBase<ArgonState> {
5358
friend class SingletonBase;
5459

5560
asp::Mutex<> serverUrlMtx;
61+
asp::AtomicBool certVerification = true;
5662
std::mutex* configLock = nullptr;
5763
std::string serverUrl;
5864
asp::Mutex<std::unordered_set<PendingRequest*>> pendingRequests;

src/web.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ WebTask startStage1(const AccountData& account, std::string_view preferredMethod
123123

124124
auto req = web::WebRequest()
125125
.userAgent(getUserAgent())
126+
.certVerification(argon.getCertVerification())
126127
.timeout(std::chrono::seconds(10))
127128
.bodyJSON(payload)
128129
.post(fmt::format("{}/v1/challenge/start", serverUrl));
@@ -145,6 +146,7 @@ WebTask restartStage1(const AccountData& account, std::string_view preferredMeth
145146

146147
auto req = web::WebRequest()
147148
.userAgent(getUserAgent())
149+
.certVerification(argon.getCertVerification())
148150
.timeout(std::chrono::seconds(10))
149151
.bodyJSON(payload)
150152
.post(fmt::format("{}/v1/challenge/restart", serverUrl));
@@ -164,6 +166,7 @@ WebTask startStage2Message(const AccountData& account, std::string_view serverUr
164166

165167
// Upload a message to the GD bot account
166168
auto req = web::WebRequest()
169+
.certVerification(getCertVerification())
167170
.timeout(std::chrono::seconds(20))
168171
.bodyString(payload)
169172
.userAgent("")
@@ -185,6 +188,7 @@ WebTask stage2MessageCleanup(const AccountData& account, int id, std::string_vie
185188

186189
// delete the message
187190
auto req = web::WebRequest()
191+
.certVerification(getCertVerification())
188192
.timeout(std::chrono::seconds(20))
189193
.bodyString(payload)
190194
.userAgent("")
@@ -210,6 +214,7 @@ WebTask startStage3(const AccountData& account, uint32_t challengeId, std::strin
210214

211215
auto req = web::WebRequest()
212216
.userAgent(getUserAgent())
217+
.certVerification(argon.getCertVerification())
213218
.timeout(std::chrono::seconds(10))
214219
.bodyJSON(payload)
215220
.post(fmt::format("{}/v1/challenge/verify", serverUrl));
@@ -229,6 +234,7 @@ WebTask pollStage3(const AccountData& account, uint32_t challengeId, std::string
229234

230235
auto req = web::WebRequest()
231236
.userAgent(getUserAgent())
237+
.certVerification(argon.getCertVerification())
232238
.timeout(std::chrono::seconds(10))
233239
.bodyJSON(payload)
234240
.post(fmt::format("{}/v1/challenge/verifypoll", serverUrl));

0 commit comments

Comments
 (0)