Add automatic SSL certificate generation
All checks were successful
Build and Push / build-all (push) Successful in 8m13s
All checks were successful
Build and Push / build-all (push) Successful in 8m13s
This commit is contained in:
parent
e13fffdaac
commit
42855330c0
11 changed files with 105 additions and 38 deletions
|
|
@ -598,25 +598,31 @@ void UserController::addPgpKey(const HttpRequestPtr &req,
|
|||
|
||||
std::string publicKey = (*json)["publicKey"].asString();
|
||||
std::string fingerprint = (*json)["fingerprint"].asString();
|
||||
|
||||
std::string origin = (*json).get("origin", "imported").asString();
|
||||
|
||||
// Validate origin value
|
||||
if (origin != "generated" && origin != "imported") {
|
||||
origin = "imported";
|
||||
}
|
||||
|
||||
if (publicKey.empty() || fingerprint.empty()) {
|
||||
callback(jsonError("Missing key data"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
auto dbClient = app().getDbClient();
|
||||
|
||||
|
||||
// Check if fingerprint already exists
|
||||
*dbClient << "SELECT id FROM pgp_keys WHERE fingerprint = $1"
|
||||
<< fingerprint
|
||||
>> [dbClient, user, publicKey, fingerprint, callback](const Result& r) {
|
||||
>> [dbClient, user, publicKey, fingerprint, origin, callback](const Result& r) {
|
||||
if (!r.empty()) {
|
||||
callback(jsonError("This PGP key is already registered"));
|
||||
return;
|
||||
}
|
||||
|
||||
*dbClient << "INSERT INTO pgp_keys (user_id, public_key, fingerprint) VALUES ($1, $2, $3)"
|
||||
<< user.id << publicKey << fingerprint
|
||||
|
||||
*dbClient << "INSERT INTO pgp_keys (user_id, public_key, fingerprint, key_origin) VALUES ($1, $2, $3, $4)"
|
||||
<< user.id << publicKey << fingerprint << origin
|
||||
>> [callback](const Result&) {
|
||||
Json::Value resp;
|
||||
resp["success"] = true;
|
||||
|
|
@ -641,22 +647,23 @@ void UserController::getPgpKeys(const HttpRequestPtr &req,
|
|||
}
|
||||
|
||||
auto dbClient = app().getDbClient();
|
||||
*dbClient << "SELECT public_key, fingerprint, created_at FROM pgp_keys "
|
||||
*dbClient << "SELECT public_key, fingerprint, key_origin, created_at FROM pgp_keys "
|
||||
"WHERE user_id = $1 ORDER BY created_at DESC"
|
||||
<< user.id
|
||||
>> [callback](const Result& r) {
|
||||
Json::Value resp;
|
||||
resp["success"] = true;
|
||||
Json::Value keys(Json::arrayValue);
|
||||
|
||||
|
||||
for (const auto& row : r) {
|
||||
Json::Value key;
|
||||
key["publicKey"] = row["public_key"].as<std::string>();
|
||||
key["fingerprint"] = row["fingerprint"].as<std::string>();
|
||||
key["keyOrigin"] = row["key_origin"].isNull() ? "imported" : row["key_origin"].as<std::string>();
|
||||
key["createdAt"] = row["created_at"].as<std::string>();
|
||||
keys.append(key);
|
||||
}
|
||||
|
||||
|
||||
resp["keys"] = keys;
|
||||
callback(jsonResp(resp));
|
||||
}
|
||||
|
|
@ -1038,7 +1045,7 @@ void UserController::getUserPgpKeys(const HttpRequestPtr &,
|
|||
try {
|
||||
// Public endpoint - no authentication required
|
||||
auto dbClient = app().getDbClient();
|
||||
*dbClient << "SELECT pk.public_key, pk.fingerprint, pk.created_at "
|
||||
*dbClient << "SELECT pk.public_key, pk.fingerprint, pk.key_origin, pk.created_at "
|
||||
"FROM pgp_keys pk JOIN users u ON pk.user_id = u.id "
|
||||
"WHERE u.username = $1 ORDER BY pk.created_at DESC"
|
||||
<< username
|
||||
|
|
@ -1046,15 +1053,16 @@ void UserController::getUserPgpKeys(const HttpRequestPtr &,
|
|||
Json::Value resp;
|
||||
resp["success"] = true;
|
||||
Json::Value keys(Json::arrayValue);
|
||||
|
||||
|
||||
for (const auto& row : r) {
|
||||
Json::Value key;
|
||||
key["publicKey"] = row["public_key"].as<std::string>();
|
||||
key["fingerprint"] = row["fingerprint"].as<std::string>();
|
||||
key["keyOrigin"] = row["key_origin"].isNull() ? "imported" : row["key_origin"].as<std::string>();
|
||||
key["createdAt"] = row["created_at"].as<std::string>();
|
||||
keys.append(key);
|
||||
}
|
||||
|
||||
|
||||
resp["keys"] = keys;
|
||||
callback(jsonResp(resp));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue