From 59cc8a8b2a999fb377bea04dfc2c1cd1e05decee Mon Sep 17 00:00:00 2001 From: Luke Bennett Date: Mon, 14 Jun 2021 22:23:52 +0100 Subject: [PATCH 01/11] docs(README): add homebrew deps --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 120e215..6b32337 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,11 @@ CCash solves these issues and adds a level of abstraction, the main philosophy o drogon depedencies (varies by OS/distro) ``` +# Debian sudo apt install libjsoncpp-dev uuid-dev openssl libssl-dev zlib1g-dev + +# macOS +brew install jsoncpp ossp-uuid openssl zlib ``` building the project From 79f388af72e9f32353d5e5aa70697f631a8c0a45 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 14 Jun 2021 18:27:03 -0700 Subject: [PATCH 02/11] fixed major sendfunds bug --- src/bank.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bank.cpp b/src/bank.cpp index a4b57e1..5adfef7 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -119,7 +119,7 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name } })) { - if (state) + if (state > 0) { //if B does exist if (users.modify_if(b_name, [amount](User &b) { From dedc62f0f791c5b040b5eac7c6c60ae3a30eacc7 Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 14 Jun 2021 18:49:17 -0700 Subject: [PATCH 03/11] turned some conditionals into turnary for code cleanliness --- src/bank.cpp | 96 +++++++++++++--------------------------------------- 1 file changed, 24 insertions(+), 72 deletions(-) diff --git a/src/bank.cpp b/src/bank.cpp index 5adfef7..883280a 100644 --- a/src/bank.cpp +++ b/src/bank.cpp @@ -8,15 +8,10 @@ int_fast8_t Bank::AddUser(const std::string &name, const std::string &init_pass) } { std::shared_lock lock{size_l}; - if (users.try_emplace_l( - name, [](User &) {}, init_pass)) - { - return true; - } - else - { - return ErrorResponse::UserAlreadyExists; - } + return (users.try_emplace_l( + name, [](User &) {}, init_pass)) + ? true + : ErrorResponse::UserAlreadyExists; } } int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, uint32_t init_bal, std::string &&init_pass) @@ -31,55 +26,36 @@ int_fast8_t Bank::AdminAddUser(const std::string &attempt, std::string &&name, u } { std::shared_lock lock{size_l}; - if (users.try_emplace_l( - name, [](User &) {}, init_bal, std::move(init_pass))) - { - return true; - } - else - { - return ErrorResponse::UserAlreadyExists; - } + return (users.try_emplace_l( + name, [](User &) {}, init_bal, std::move(init_pass))) + ? true + : ErrorResponse::UserAlreadyExists; } } int_fast8_t Bank::DelUser(const std::string &name, const std::string &attempt) { std::shared_lock lock{size_l}; bool state = false; - if (!users.erase_if(name, [&state, &attempt](User &u) { return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password); })) + if (users.erase_if(name, [&state, &attempt](User &u) { return state = (XXH3_64bits(attempt.data(), attempt.size()) == u.password); })) { - return ErrorResponse::UserNotFound; + return (state) ? true : ErrorResponse::WrongPassword; } else { - if (state) - { - return true; - } - else - { - return ErrorResponse::WrongPassword; - } + return ErrorResponse::UserNotFound; } } int_fast8_t Bank::AdminDelUser(const std::string &name, const std::string &attempt) { std::shared_lock lock{size_l}; bool state = false; - if (!users.erase_if(name, [this, &state, &attempt](const User &) { return state = (admin_pass == attempt); })) + if (users.erase_if(name, [this, &state, &attempt](const User &) { return state = (admin_pass == attempt); })) { - return ErrorResponse::UserNotFound; + return (state) ? true : ErrorResponse::WrongPassword; } else { - if (state) - { - return true; - } - else - { - return ErrorResponse::WrongPassword; - } + return ErrorResponse::UserNotFound; } } @@ -162,25 +138,11 @@ int_fast8_t Bank::SendFunds(const std::string &a_name, const std::string &b_name int_fast8_t Bank::Contains(const std::string &name) const { - if (users.contains(name)) - { - return true; - } - else - { - return ErrorResponse::UserNotFound; - } + return (users.contains(name)) ? true : ErrorResponse::UserNotFound; } int_fast8_t Bank::AdminVerifyPass(const std::string &attempt) { - if (admin_pass == attempt) - { - return true; - } - else - { - return ErrorResponse::WrongPassword; - } + return (admin_pass == attempt) ? true : ErrorResponse::WrongPassword; } int_fast8_t Bank::SetBal(const std::string &name, const std::string &attempt, uint32_t amount) @@ -189,16 +151,12 @@ int_fast8_t Bank::SetBal(const std::string &name, const std::string &attempt, ui { return ErrorResponse::WrongPassword; } - if (users.modify_if(name, [amount](User &u) { - u.balance = amount; - })) - { - return true; - } - else - { - return ErrorResponse::UserNotFound; - } + + return (users.modify_if(name, [amount](User &u) { + u.balance = amount; + })) + ? true + : ErrorResponse::UserNotFound; } int_fast64_t Bank::GetBal(const std::string &name) const { @@ -213,14 +171,7 @@ int_fast8_t Bank::VerifyPassword(const std::string &name, const std::string &att { int_fast8_t res = ErrorResponse::UserNotFound; users.if_contains(name, [&res, &attempt](const User &u) { - if (u.password == XXH3_64bits(attempt.data(), attempt.size())) - { - res = true; - } - else - { - res = ErrorResponse::WrongPassword; - } + res = (u.password == XXH3_64bits(attempt.data(), attempt.size())) ? true : ErrorResponse::WrongPassword; }); return res; } @@ -234,6 +185,7 @@ int_fast8_t Bank::ChangePassword(const std::string &name, const std::string &att } else { + res = true; u.password = XXH3_64bits(new_pass.data(), new_pass.size()); } }); From 00aea60eaaa1555427d1b5471e007a290b9ed6fb Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 21:24:14 -0700 Subject: [PATCH 04/11] Update users.json --- users.json | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/users.json b/users.json index 9f79054..b785785 100644 --- a/users.json +++ b/users.json @@ -1,42 +1,8 @@ { - "jolly" : + "" : { - "balance" : 139, - "log" : - [ - { - "amount" : 100, - "from" : "twix", - "time" : 1623555387199, - "to" : "jolly" - }, - { - "amount" : 39, - "from" : "twix", - "time" : 1623693328822, - "to" : "jolly" - } - ], - "password" : 746744014776526199 + "balance" : 0, + "log" : null, + "password" : 0 }, - "twix" : - { - "balance" : 9861, - "log" : - [ - { - "amount" : 100, - "from" : "twix", - "time" : 1623555387199, - "to" : "jolly" - }, - { - "amount" : 39, - "from" : "twix", - "time" : 1623693328822, - "to" : "jolly" - } - ], - "password" : 746744014776526199 - } -} \ No newline at end of file +} From 706d304de8a1979541284cac203996f2483ab137 Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 21:38:13 -0700 Subject: [PATCH 05/11] Update services.md --- services.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services.md b/services.md index 3d11d73..4845c6e 100644 --- a/services.md +++ b/services.md @@ -24,3 +24,6 @@ - Shipping - High-level bank operations such as loans - Some trust based system for transactions similiar to Paypal + +- a better version of one of these existing ideas +- something completely different From f59c0793ee40b4709676ceca2e5e4aa7ff7e693e Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 22:08:23 -0700 Subject: [PATCH 06/11] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6b32337..cea51ac 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Thank you to the contributors | [Expand](https://github.com/Expand-sys) | Frontend | | [React](https://github.com/Reactified) | CC {API, Shops, and ATM, Logo} | | [Doggo](https://github.com/FearlessDoggo21) | Logs loading/adding Optimized, HTTP convention suggestions | +| [Luke](https://github.com/LukeeeeBennett) | Docs | ## Features From 8bffcb050da66ca286ecacd7087ac163943ef1e6 Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 22:09:01 -0700 Subject: [PATCH 07/11] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cea51ac..e34a750 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Thank you to the contributors | [Expand](https://github.com/Expand-sys) | Frontend | | [React](https://github.com/Reactified) | CC {API, Shops, and ATM, Logo} | | [Doggo](https://github.com/FearlessDoggo21) | Logs loading/adding Optimized, HTTP convention suggestions | -| [Luke](https://github.com/LukeeeeBennett) | Docs | +| [Luke](https://github.com/LukeeeeBennett) | Slight Doc edits | ## Features From bd357db0ac97a9c3682e8d4762a18596bbfa15de Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Mon, 14 Jun 2021 22:14:16 -0700 Subject: [PATCH 08/11] admin wrong password removed --- include/error_responses.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/include/error_responses.hpp b/include/error_responses.hpp index 5050d33..6c4de41 100644 --- a/include/error_responses.hpp +++ b/include/error_responses.hpp @@ -4,8 +4,7 @@ enum ErrorResponse UserNotFound = -1, WrongPassword = -2, InvalidRequest = -3, - WrongAdminPassword = -4, - NameTooLong = -5, - UserAlreadyExists = -6, - InsufficientFunds = -7, + NameTooLong = -4, + UserAlreadyExists = -5, + InsufficientFunds = -6, }; \ No newline at end of file From 18645f434699ededea746be269e6ca61bce10d5b Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 23:25:23 -0700 Subject: [PATCH 09/11] Update config.json --- config.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config.json b/config.json index 331a931..fa95be9 100644 --- a/config.json +++ b/config.json @@ -4,6 +4,13 @@ "address": "0.0.0.0", "port": 80, "https": false + }, + { + "address": "0.0.0.0", + "port": 443, + "https": true, + "cert": "", + "key": "" } ] } From 1b7a0159bbc996207df2013030d68fc7119db712 Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 23:25:59 -0700 Subject: [PATCH 10/11] Update help.md --- help.md | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/help.md b/help.md index 386966f..a52d42a 100644 --- a/help.md +++ b/help.md @@ -10,28 +10,24 @@ | -6 | InsufficientFunds | # Things of Note - -- all endpoints respond with **JSON** file type -- "**A**" denotes requiring Authentication in the form of a header titled "**Password**" +* all endpoints respond with **JSON** file type +* "**A**" denotes requiring Authentication in the form of a header titled "**Password**" # Usage - -| Name | Path | Method | A | Description | -| :------------: | :------------------------------------- | :----: | :---: | ------------------------------------------------------------------------------------------------------------ | -| GetBal | BankF/{name}/bal | GET | false | returns the balance of a given user `{name}` | -| GetLog | BankF/{name}/log | GET | true | returns a list of last `n` number of transactions (configurable in CCash webserver) of a given user `{name}` | -| SendFunds | BankF/{name}/send/{to}?amount={amount} | POST | true | sends `{amount}` from user `{name}` to user `{to}` | -| VerifyPassword | BankF/{name}/pass/verify | GET | true | returns `1` if the supplied user `{name}`'s password matches the password supplied in the header | +| Name | Path | Method | A | Description | +| :------------: | :------------------------------------- | :----: | :---: | -------------------------------------------------------------------------------------------------- | +| GetBal | BankF/{name}/bal | GET | false | returns the balance of a given user `{name}` | +| GetLog | BankF/{name}/log | GET | true | returns a list of last `n` number of transactions (a configurable amount) of a given user `{name}` | +| SendFunds | BankF/{name}/send/{to}?amount={amount} | POST | true | sends `{amount}` from user `{name}` to user `{to}` | +| VerifyPassword | BankF/{name}/pass/verify | GET | true | returns `1` if the supplied user `{name}`'s password matches the password supplied in the header | # Meta Usage - | Name | Path | Method | A | Description | | :------------: | :------------------------------------- | :----: | :---: | ---------------------------------------------------------------------------------------------------------------------------------------- | -| ChangePassword | BankF/{name}/pass/change | PATCH | true | if the password supplied in the header matches the user `{name}`'s password, the user's password is changed to the one given as the body | +| ChangePassword | BankF/{name}/pass/change | PATCH | true | if the password supplied in the header matches the user `{name}`'s password, the user's password is changed to the one given in the body | | SetBal | BankF/admin/{name}/bal?amount={amount} | PATCH | true | sets the balance of a give user `{name}` if the supplied password matches the admin password | # System Usage - | Name | Path | Method | A | Description | | :-------------: | :-------------------- | :----: | :---: | ------------------------------------------------------------------------------------- | | Help | BankF/help | GET | false | the page you're looking at right now! | @@ -41,10 +37,9 @@ | AdminVerifyPass | BankF/admin/verify | GET | true | returns `1` if the password supplied in the header matches the admin password | # User Management - -| Name | Path | Method | A | Description | -| :----------: | :------------------------------------------ | :----: | :---: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| AddUser | BankF/user/{name} | POST | true | registers a user with the name `{name}`, balance of 0 and a password of the password supplied in the header | -| AdminAddUser | BankF/admin/user/{name}?init_bal={init_bal} | POST | true | if the password supplied in the header matches the admin password, then it registers a user with the name `{name}`, balance of `init_bal` and a password that is supplied as the body of the request | -| DelUser | BankF/user/{name} | DELETE | true | if the password supplied in the header matches the user `{name}`'s password, then the user is deleted | -| AdminDelUser | BankF/admin/user/{name} | DELETE | true | if the password supplied in the header matches the admin password, then the user is deleted | +| Name | Path | Method | A | Description | +| :----------: | :------------------------------------------ | :----: | :---: | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| AddUser | BankF/user/{name} | POST | true | registers a user with the name `{name}`, balance of 0 and a password of the password supplied in the header | +| AdminAddUser | BankF/admin/user/{name}?init_bal={init_bal} | POST | true | if the password supplied in the header matches the admin password, then it registers a user with the name `{name}`, balance of `init_bal` and a password supplied by the body of the request | +| DelUser | BankF/user/{name} | DELETE | true | if the password supplied in the header matches the user `{name}`'s password, then the user is deleted | +| AdminDelUser | BankF/admin/user/{name} | DELETE | true | if the password supplied in the header matches the admin password, then the user is deleted | From 1f8df1e94cb6b49929e64f7c1d50626507f8e532 Mon Sep 17 00:00:00 2001 From: William Katz Date: Mon, 14 Jun 2021 23:38:39 -0700 Subject: [PATCH 11/11] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index e34a750..b4b4731 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ Thank you to the contributors - **multi-threaded** - **parallel hashmaps** a far [superior](https://greg7mdp.github.io/parallel-hashmap/) HashMap implementation to the STD, that also benefits from multi-threaded - **Drogon** is a very fast [web framework](https://www.techempower.com/benchmarks/#section=data-r20&hw=ph&test=composite) +- **xxHash** for the hashing of passwords, [graph](https://user-images.githubusercontent.com/750081/61976089-aedeab00-af9f-11e9-9239-e5375d6c080f.png) - **Lightweight**, anecodotally I experienced 0.0% idle, <1% CPU usage on average, 7% at peak, 1000 requests in 0.85s ### Safety