forked from cory/tildefriends
Show local identities in the ssb app.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3964 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
47
src/main.c
47
src/main.c
@ -64,6 +64,7 @@ static int _tf_command_sandbox(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_post(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_check(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_usage(const char* file, int argc, char* argv[]);
|
||||
static int _tf_command_private(const char* file, int argc, char* argv[]);
|
||||
|
||||
typedef struct _command_t {
|
||||
const char* name;
|
||||
@ -79,6 +80,7 @@ const command_t k_commands[] = {
|
||||
{ "export", _tf_command_export, "Export apps from SSB." },
|
||||
{ "test", _tf_command_test, "Test SSB." },
|
||||
{ "check", _tf_command_check, "Validate messages in the SSB database." },
|
||||
{ "private", _tf_command_private, "Check for private messages the SSB database (just an experiment)." },
|
||||
};
|
||||
|
||||
void shedPrivileges()
|
||||
@ -618,6 +620,51 @@ xopt_help:
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _tf_command_private(const char* file, int argc, char* argv[])
|
||||
{
|
||||
typedef struct args_t {
|
||||
bool help;
|
||||
} args_t;
|
||||
|
||||
xoptOption options[] = {
|
||||
{ "help", 'h', offsetof(args_t, help), NULL, XOPT_TYPE_BOOL, NULL, "Shows this help message." },
|
||||
XOPT_NULLOPTION,
|
||||
};
|
||||
|
||||
args_t args = { 0 };
|
||||
const char** extras = NULL;
|
||||
int extra_count = 0;
|
||||
const char *err = NULL;
|
||||
XOPT_PARSE(file, XOPT_CTX_KEEPFIRST | XOPT_CTX_STRICT, options, &args, argc, (const char**)argv, &extra_count, &extras, &err, stderr, "private [options]", "options:", NULL, 15);
|
||||
if (err)
|
||||
{
|
||||
if (extras)
|
||||
{
|
||||
free((void*)extras);
|
||||
}
|
||||
fprintf(stderr, "Error: %s\n", err);
|
||||
return 2;
|
||||
}
|
||||
|
||||
bool result = true;
|
||||
sqlite3* db = NULL;
|
||||
sqlite3_open("db.sqlite", &db);
|
||||
tf_ssb_db_private(db);
|
||||
sqlite3_close(db);
|
||||
if (extras)
|
||||
{
|
||||
free((void*)extras);
|
||||
}
|
||||
return result ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
|
||||
xopt_help:
|
||||
if (extras)
|
||||
{
|
||||
free((void*)extras);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int _tf_command_usage(const char* file, int argc, char* argv[])
|
||||
{
|
||||
printf("Usage: %s command [command-options]\n", file);
|
||||
|
57
src/ssb.db.c
57
src/ssb.db.c
@ -7,6 +7,9 @@
|
||||
|
||||
#include <base64c.h>
|
||||
#include <sodium/crypto_hash_sha256.h>
|
||||
#include <sodium/crypto_scalarmult.h>
|
||||
#include <sodium/crypto_scalarmult_curve25519.h>
|
||||
#include <sodium/crypto_secretbox.h>
|
||||
#include <sodium/crypto_sign.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdlib.h>
|
||||
@ -795,3 +798,57 @@ bool tf_ssb_db_identity_get_private_key(tf_ssb_t* ssb, const char* user, const c
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
static void _test_private(sqlite3* db, const uint8_t* private_key)
|
||||
{
|
||||
sqlite3_stmt* statement = NULL;
|
||||
if (sqlite3_prepare(db, "SELECT content FROM messages WHERE content LIKE '\"%.box\"'", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
uint8_t buffer[8192];
|
||||
//printf("==> %s\n", sqlite3_column_text(statement, 0));
|
||||
int r = base64c_decode(sqlite3_column_text(statement, 0) + 1, sqlite3_column_bytes(statement, 0) - strlen("\".box\""), buffer, sizeof(buffer));
|
||||
if (r > 1)
|
||||
{
|
||||
uint8_t* nonce = buffer;
|
||||
uint8_t* public_key = buffer + 24;
|
||||
if (public_key + 32 < buffer + r)
|
||||
{
|
||||
uint8_t shared_secret[crypto_scalarmult_curve25519_SCALARBYTES];
|
||||
if (crypto_scalarmult_curve25519(shared_secret, private_key, public_key) == 0)
|
||||
{
|
||||
for (uint8_t* p = public_key + 32; p < buffer + r + 49; p += 49)
|
||||
{
|
||||
uint8_t out[49];
|
||||
if (crypto_secretbox_open_easy(out, p, 49, nonce, shared_secret) == 0)
|
||||
{
|
||||
printf("opened secret box!\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
}
|
||||
|
||||
void tf_ssb_db_private(sqlite3* db)
|
||||
{
|
||||
sqlite3_stmt* statement = NULL;
|
||||
if (sqlite3_prepare(db, "SELECT public_key, private_key FROM identities", -1, &statement, NULL) == SQLITE_OK)
|
||||
{
|
||||
while (sqlite3_step(statement) == SQLITE_ROW)
|
||||
{
|
||||
uint8_t private_key[crypto_sign_SECRETKEYBYTES];
|
||||
printf("-> %s\n", sqlite3_column_text(statement, 0));
|
||||
int r = base64c_decode(sqlite3_column_text(statement, 1), sqlite3_column_bytes(statement, 1) - strlen(".ed25519"), private_key, sizeof(private_key));
|
||||
if (r > 0)
|
||||
{
|
||||
_test_private(db, private_key);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
}
|
||||
|
@ -23,3 +23,5 @@ bool tf_ssb_db_identity_add(tf_ssb_t* ssb, const char* user, const char* public_
|
||||
void tf_ssb_db_identity_visit(tf_ssb_t* ssb, const char* user, void (*callback)(const char* identity, void* user_data), void* user_data);
|
||||
void tf_ssb_db_identity_visit_all(tf_ssb_t* ssb, void (*callback)(const char* identity, void* user_data), void* user_data);
|
||||
bool tf_ssb_db_identity_get_private_key(tf_ssb_t* ssb, const char* user, const char* public_key, uint8_t* out_private_key, size_t private_key_size);
|
||||
|
||||
void tf_ssb_db_private(sqlite3* db);
|
||||
|
Reference in New Issue
Block a user