diff --git a/include/api.h b/include/api.h index 1480771..e79dc71 100644 --- a/include/api.h +++ b/include/api.h @@ -73,7 +73,7 @@ class API apiConfig config; userDetails user; - API(const std::string& token,const std::string& secret, const bool& verbose = false); + API(const std::string& token,const std::string& secret, const bool& verbose = false, const bool& bVerifyPeer = true); int init(); int login(const std::string& email, const std::string& password); int getAPIConfig(); diff --git a/include/config.h b/include/config.h index f29ed28..ddfc654 100644 --- a/include/config.h +++ b/include/config.h @@ -29,6 +29,7 @@ class Config bool bNoExtras; bool bNoUnicode; // don't use Unicode in console output bool bNoColor; // don't use colors + bool bVerifyPeer; std::string sGameRegex; std::string sDirectory; std::string sXMLFile; diff --git a/main.cpp b/main.cpp index adacc75..af09ba2 100644 --- a/main.cpp +++ b/main.cpp @@ -75,6 +75,7 @@ int main(int argc, char *argv[]) bpo::options_description config_file_options("Configuration"); try { + bool bUnsecure = false; desc.add_options() ("help,h", "Print help message") ("login", bpo::value(&config.bLogin)->zero_tokens()->default_value(false), "Login") @@ -100,6 +101,7 @@ int main(int argc, char *argv[]) ("no-unicode", bpo::value(&config.bNoUnicode)->zero_tokens()->default_value(false), "Don't use Unicode in the progress bar") ("no-color", bpo::value(&config.bNoColor)->zero_tokens()->default_value(false), "Don't use coloring in the progress bar") ("verbose", bpo::value(&config.bVerbose)->zero_tokens()->default_value(false), "Print lots of information") + ("unsecure", bpo::value(&bUnsecure)->zero_tokens()->default_value(false), "Don't verify authenticity of SSL certificates") ; bpo::store(bpo::parse_command_line(argc, argv, desc), vm); @@ -139,6 +141,8 @@ int main(int argc, char *argv[]) if (vm.count("limit-rate")) config.iDownloadRate <<= 10; // Convert download rate from bytes to kilobytes + + config.bVerifyPeer = !bUnsecure; } catch (std::exception& e) { diff --git a/src/api.cpp b/src/api.cpp index a0dd3ac..87369c9 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -33,7 +33,7 @@ gameFile::~gameFile() } -API::API(const std::string& token, const std::string& secret, const bool& verbose) +API::API(const std::string& token, const std::string& secret, const bool& verbose, const bool& bVerifyPeer) { curlhandle = curl_easy_init(); curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, verbose); @@ -42,7 +42,7 @@ API::API(const std::string& token, const std::string& secret, const bool& verbos curl_easy_setopt(curlhandle, CURLOPT_CONNECTTIMEOUT, 10); curl_easy_setopt(curlhandle, CURLOPT_PROGRESSDATA, this); curl_easy_setopt(curlhandle, CURLOPT_FAILONERROR, true); - curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, bVerifyPeer); this->error = false; this->getAPIConfig(); diff --git a/src/downloader.cpp b/src/downloader.cpp index c229b83..ca7fdb8 100644 --- a/src/downloader.cpp +++ b/src/downloader.cpp @@ -58,12 +58,12 @@ int Downloader::init() curl_easy_setopt(curlhandle, CURLOPT_FAILONERROR, true); curl_easy_setopt(curlhandle, CURLOPT_COOKIEFILE, config.sCookiePath.c_str()); curl_easy_setopt(curlhandle, CURLOPT_COOKIEJAR, config.sCookiePath.c_str()); - curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, config.bVerifyPeer); if (config.bVerbose) curl_easy_setopt(curlhandle, CURLOPT_VERBOSE, 1); - gogAPI = new API(config.sToken, config.sSecret, config.bVerbose); + gogAPI = new API(config.sToken, config.sSecret, config.bVerbose, config.bVerifyPeer); progressbar = new ProgressBar(!config.bNoUnicode, !config.bNoColor); if (config.bLogin || !gogAPI->init()) @@ -313,7 +313,7 @@ void Downloader::repair() curl_easy_setopt(curlhandle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, Downloader::writeData); curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, Downloader::readData); - curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, config.bVerifyPeer); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curlhandle, CURLOPT_PROGRESSFUNCTION, Downloader::progressCallback); #ifndef ENVIRONMENT32 @@ -386,7 +386,7 @@ void Downloader::download() curl_easy_setopt(curlhandle, CURLOPT_FOLLOWLOCATION, 1); curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, Downloader::writeData); curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, Downloader::readData); - curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, config.bVerifyPeer); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curlhandle, CURLOPT_PROGRESSFUNCTION, Downloader::progressCallback); #ifndef ENVIRONMENT32 @@ -806,7 +806,7 @@ int Downloader::repairFile(const std::string& url, const std::string& filepath, curl_easy_setopt(curlhandle, CURLOPT_URL, url.c_str()); curl_easy_setopt(curlhandle, CURLOPT_WRITEFUNCTION, Downloader::writeData); curl_easy_setopt(curlhandle, CURLOPT_READFUNCTION, Downloader::readData); - curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(curlhandle, CURLOPT_SSL_VERIFYPEER, config.bVerifyPeer); curl_easy_setopt(curlhandle, CURLOPT_NOPROGRESS, 0); curl_easy_setopt(curlhandle, CURLOPT_PROGRESSFUNCTION, Downloader::progressCallback); curl_easy_setopt(curlhandle, CURLOPT_WRITEDATA, outfile);