Skip to content

Commit

Permalink
feat: time password generation and database initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
csirianni committed Dec 19, 2023
1 parent 9e14cb2 commit 8292c84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
17 changes: 13 additions & 4 deletions backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
#include "sodium.h"
#include "cryptography.hpp"
#include "spdlog/spdlog.h"
#include <chrono>

int main(int argc, char *argv[])
{
spdlog::set_level(spdlog::level::debug);

if (argc < 2 || argc > 3)
{
printf("Usage: %s <database file> [--build]\n", argv[0]);
Expand Down Expand Up @@ -44,7 +43,7 @@ int main(int argc, char *argv[])

database::Database db = database::Database(argv[1], build);
// TODO: store this data in server because same file with different offset will have different passwords
const size_t offset = 1;
const size_t offset = 0;
spdlog::info("Password offset: {}", offset);

// limit the number of leaked bytes to 4
Expand All @@ -64,7 +63,9 @@ int main(int argc, char *argv[])
}

// generate and insert the passwords into the database
std::unordered_set<std::string> passwords = password::generatePasswords(100, 20);
spdlog::info("Generating passwords...");
auto start = std::chrono::high_resolution_clock::now();
std::unordered_set<std::string> passwords = password::generatePasswords(1000000, 20);
passwords.insert("TestPass1&");
passwords.insert("ChocolateCake1!");

Expand All @@ -74,8 +75,13 @@ int main(int argc, char *argv[])

// 2. encrypt each password with b (and hash to point)
std::vector<std::string> encrypted_passwords = cryptography::encrypt(passwords, b, offset);
auto stop = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
spdlog::info("Passwords generated in {} ms", duration.count());

// 3. insert into database
spdlog::info("Inserting passwords into database...");
start = std::chrono::high_resolution_clock::now();
for (const auto &password : encrypted_passwords)
{
// determine which table to insert into based on leaked byte
Expand All @@ -86,6 +92,9 @@ int main(int argc, char *argv[])
// encode password before inserting into database
db.execute("INSERT INTO `" + std::to_string(table_num) + "` (password) VALUES ('" + crow::utility::base64encode(raw_password, raw_password.size()) + "');");
}
stop = std::chrono::high_resolution_clock::now();
duration = std::chrono::duration_cast<std::chrono::milliseconds>(stop - start);
spdlog::info("Passwords inserted into database in {} ms", duration.count());

// create key table
db.execute("CREATE TABLE secret (key TEXT);");
Expand Down
8 changes: 4 additions & 4 deletions frontend/tests/psi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ describe("testing applySeed", () => {
describe("testing expected server response", () => {
test("sending breached password should return fail status", async () => {
const password = "TestPass1&";
const response = await checkSecurity(password, 1);
const response = await checkSecurity(password, 0);
expect(response.status).toBe("fail");
});
}, 60000000);
test("sending non-breach password should return success status", async () => {
const password = "NiniIsTheBest!4";
const response = await checkSecurity(password, 1);
const response = await checkSecurity(password, 0);
expect(response.status).toBe("success");
});
}, 60000000);
});

0 comments on commit 8292c84

Please sign in to comment.