From b14f87c5a70131e47e625cd196be42d99cd66a70 Mon Sep 17 00:00:00 2001 From: JuanJakobo Date: Fri, 9 Sep 2022 09:30:14 +0200 Subject: [PATCH] #26 Add option to ignore cert validation --- src/api/webDAV.cpp | 21 ++++++++++++++++----- src/api/webDAV.h | 4 ++-- src/handler/eventHandler.cpp | 2 +- src/ui/loginView/loginView.cpp | 20 +++++++++++++++++++- src/ui/loginView/loginView.h | 3 +++ 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/api/webDAV.cpp b/src/api/webDAV.cpp index 4071919..1790940 100644 --- a/src/api/webDAV.cpp +++ b/src/api/webDAV.cpp @@ -36,16 +36,18 @@ WebDAV::WebDAV() _username = Util::accessConfig(Action::IReadString,"username",{}); _password = Util::accessConfig(Action::IReadSecret,"password",{}); _url = Util::accessConfig(Action::IReadString, "url",{}); + _ignoreCert = Util::accessConfig(Action::IReadInt, "ignoreCert",{}); } } -std::vector WebDAV::login(const string &Url, const string &Username, const string &Pass) +std::vector WebDAV::login(const string &Url, const string &Username, const string &Pass, bool ignoreCert) { string uuid; _password = Pass; _username = Username; + _ignoreCert = ignoreCert; std::size_t found = Url.find(NEXTCLOUD_ROOT_PATH); if (found != std::string::npos) @@ -69,6 +71,7 @@ std::vector WebDAV::login(const string &Url, const string &Username, Util::accessConfig( Action::IWriteString, "username", _username); Util::accessConfig( Action::IWriteString, "UUID", uuid); Util::accessConfig( Action::IWriteSecret, "password", _password); + Util::accessConfig( Action::IWriteInt, "ignoreCert", _ignoreCert); } else { @@ -232,8 +235,12 @@ string WebDAV::propfind(const string &pathUrl) curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Util::writeCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); - if (iv_access(CACERT_PATH.c_str(), R_OK) == 0) - curl_easy_setopt(curl, CURLOPT_CAINFO, CACERT_PATH.c_str()); + if(_ignoreCert) + { + Log::writeInfoLog("Cert ignored"); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + } curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "<\?xml version=\"1.0\" encoding=\"UTF-8\"\?> \ \ @@ -314,8 +321,12 @@ bool WebDAV::get(WebDAVItem &item) curl_easy_setopt(curl, CURLOPT_NOPROGRESS, false); curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, Util::progress_callback); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - if (iv_access(CACERT_PATH.c_str(), R_OK) == 0) - curl_easy_setopt(curl, CURLOPT_CAINFO, CACERT_PATH.c_str()); + if(_ignoreCert) + { + Log::writeInfoLog("Cert ignored"); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L); + } res = curl_easy_perform(curl); curl_easy_cleanup(curl); iv_fclose(fp); diff --git a/src/api/webDAV.h b/src/api/webDAV.h index eab38c6..8386041 100644 --- a/src/api/webDAV.h +++ b/src/api/webDAV.h @@ -18,7 +18,6 @@ const std::string NEXTCLOUD_ROOT_PATH = "/remote.php/dav/files/"; const std::string NEXTCLOUD_START_PATH = "/remote.php/"; const std::string NEXTCLOUD_PATH = "/mnt/ext1/system/config/nextcloud"; -const std::string CACERT_PATH = NEXTCLOUD_PATH + "/customCert.pem"; class WebDAV { @@ -29,7 +28,7 @@ class WebDAV */ WebDAV(); - std::vector login(const std::string &Url, const std::string &Username, const std::string &Pass); + std::vector login(const std::string &Url, const std::string &Username, const std::string &Pass, bool ignoreCert = false); void logout(bool deleteFiles = false); @@ -51,6 +50,7 @@ class WebDAV std::string _username; std::string _password; std::string _url; + bool _ignoreCert; }; #endif diff --git a/src/handler/eventHandler.cpp b/src/handler/eventHandler.cpp index 7ebae3a..128f26d 100644 --- a/src/handler/eventHandler.cpp +++ b/src/handler/eventHandler.cpp @@ -371,7 +371,7 @@ int EventHandler::pointerHandler(const int type, const int par1, const int par2) { ShowHourglassForce(); - std::vector currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword()); + std::vector currentWebDAVItems = _webDAV.login(_loginView->getURL(), _loginView->getUsername(), _loginView->getPassword(), _loginView->getIgnoreCert());; if (currentWebDAVItems.empty()) { Message(ICON_ERROR, "Error", "Login failed.", 1000); diff --git a/src/ui/loginView/loginView.cpp b/src/ui/loginView/loginView.cpp index b1d1bb0..42fe7e5 100644 --- a/src/ui/loginView/loginView.cpp +++ b/src/ui/loginView/loginView.cpp @@ -22,6 +22,7 @@ LoginView::LoginView(const irect &contentRect) : _contentRect(contentRect) int contentHeight = contentRect.h / 2; int contentWidth = _contentRect.w * 0.9; + int checkBoxWidth = _contentRect.w * 0.1; int beginY = 0.4 * contentHeight; int beginX = (_contentRect.w - contentWidth) / 2; @@ -46,7 +47,11 @@ LoginView::LoginView(const irect &contentRect) : _contentRect(contentRect) DrawTextRect(_passwordButton.x, _passwordButton.y - _loginFontHeight - _loginFontHeight/4, _passwordButton.w, _passwordButton.h, "Password:", ALIGN_LEFT); DrawRect(_passwordButton.x - 1, _passwordButton.y - 1, _passwordButton.w + 2, _passwordButton.h + 2, BLACK); - _loginButton = iRect(beginX, beginY + 6 * contents, contentWidth, contents, ALIGN_CENTER); + _ignoreCertButton = iRect(_contentRect.w - 2 * checkBoxWidth, beginY + 6 * contents, checkBoxWidth, contents, ALIGN_CENTER); + DrawTextRect(beginX, _ignoreCertButton.y, contentWidth, _ignoreCertButton.h, "Ignore Cert (unsecure):", ALIGN_LEFT); + DrawRect(_ignoreCertButton.x - 1, _ignoreCertButton.y - 1, _ignoreCertButton.w + 2, _ignoreCertButton.h + 2, BLACK); + + _loginButton = iRect(beginX, beginY + 8 * contents, contentWidth, contents, ALIGN_CENTER); FillAreaRect(&_loginButton, BLACK); SetFont(_loginFont, WHITE); @@ -90,6 +95,19 @@ int LoginView::logginClicked(int x, int y) return 1; } + else if (IsInRect(x, y, &_ignoreCertButton)) + { + _ignoreCert = !_ignoreCert; + FillAreaRect(&_ignoreCertButton, WHITE); + if(_ignoreCert) + FillArea(_ignoreCertButton.x - 1, _ignoreCertButton.y - 1, _ignoreCertButton.w + 2, _ignoreCertButton.h + 2, BLACK); + else + DrawRect(_ignoreCertButton.x - 1, _ignoreCertButton.y - 1, _ignoreCertButton.w + 2, _ignoreCertButton.h + 2, BLACK); + + PartialUpdate(_ignoreCertButton.x, _ignoreCertButton.y, _ignoreCertButton.w, _ignoreCertButton.h); + + return 1; + } else if (IsInRect(x, y, &_loginButton)) { if (_username.empty() || _password.empty() || _url.empty()) diff --git a/src/ui/loginView/loginView.h b/src/ui/loginView/loginView.h index 901fd5d..206e778 100644 --- a/src/ui/loginView/loginView.h +++ b/src/ui/loginView/loginView.h @@ -47,6 +47,7 @@ public: std::string getUsername() { return _username; }; std::string getPassword() { return _password; }; std::string getURL() { return _url; }; + bool getIgnoreCert() { return _ignoreCert; }; private: static std::unique_ptr _loginViewStatic; @@ -57,10 +58,12 @@ private: irect _loginButton; irect _usernameButton; irect _passwordButton; + irect _ignoreCertButton; KeyboardTarget _target; std::string _username; std::string _password; std::string _url; + bool _ignoreCert = false; std::string _temp; /**