some updates...
This commit is contained in:
parent
ebd6d7466d
commit
7ed2435811
9
cli.cpp
9
cli.cpp
@ -5,11 +5,16 @@
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <algorithm>
|
||||
|
||||
#include "libs/linenoise.h"
|
||||
|
||||
#define CLR_RESET "\x1b[0m"
|
||||
#define CLR_CYAN "\x1b[36m"
|
||||
|
||||
static void completionCallback(const char *input, linenoiseCompletions *completions) {
|
||||
if (strncmp(input, "ni", 2) == 0) {
|
||||
if (strncmp(input, "nick", 4) == 0) {
|
||||
linenoiseAddCompletion(completions, "nick set ");
|
||||
linenoiseAddCompletion(completions, "nick generatekey");
|
||||
}
|
||||
@ -38,7 +43,7 @@ void runCLI(AppConfig &config) {
|
||||
<< " exit\n\n" CLR_RESET;
|
||||
|
||||
while (true) {
|
||||
char *line = linenoise(CLR_BOLD ">_ " CLR_RESET);
|
||||
char *line = linenoise(CLR_CYAN ">_ " CLR_RESET);
|
||||
if (!line) {
|
||||
std::cout << "\n[cli] EOF/Ctrl+C - выходим.\n";
|
||||
break;
|
||||
|
BIN
commands.o
Normal file
BIN
commands.o
Normal file
Binary file not shown.
@ -4,3 +4,12 @@ nick set platon
|
||||
nick generatekey
|
||||
web start
|
||||
web connect pm localhost
|
||||
web start
|
||||
web stop
|
||||
exit
|
||||
nick set platon
|
||||
nick generatekey
|
||||
web find
|
||||
web find
|
||||
sound find
|
||||
exit
|
||||
|
BIN
libs/linenoise.o
Normal file
BIN
libs/linenoise.o
Normal file
Binary file not shown.
BIN
libs/monocypher.o
Normal file
BIN
libs/monocypher.o
Normal file
Binary file not shown.
BIN
webserver.o
Normal file
BIN
webserver.o
Normal file
Binary file not shown.
@ -1,34 +1,38 @@
|
||||
#include "x25519_handshake.hpp"
|
||||
#include "config.hpp"
|
||||
|
||||
extern "C" {
|
||||
#include "libs/monocypher.h"
|
||||
}
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstring> // Для std::memcpy и std::memset
|
||||
#include <iostream>
|
||||
|
||||
// Подключаем Monocypher
|
||||
extern "C" {
|
||||
#include "monocypher.h"
|
||||
}
|
||||
|
||||
void x25519GenerateEphemeral(AppConfig &config) {
|
||||
FILE* f = fopen("/dev/urandom", "rb");
|
||||
if (!f) {
|
||||
std::cerr << "[x25519] Не удалось открыть /dev/urandom\n";
|
||||
std::cerr << CLR_RED "[x25519] Не удалось открыть /dev/urandom\n" CLR_RESET;
|
||||
return;
|
||||
}
|
||||
fread(config.ephemeralSec, 1, 32, f);
|
||||
size_t read = fread(config.ephemeralSec, 1, 32, f);
|
||||
fclose(f);
|
||||
if (read != 32) {
|
||||
std::cerr << CLR_RED "[x25519] Не удалось прочитать 32 байта из /dev/urandom\n" CLR_RESET;
|
||||
return;
|
||||
}
|
||||
|
||||
crypto_x25519_public_key(config.ephemeralPub, config.ephemeralSec);
|
||||
|
||||
memset(config.sharedSecret, 0, 32);
|
||||
std::memset(config.sharedSecret, 0, 32);
|
||||
config.haveSharedSecret = false;
|
||||
}
|
||||
|
||||
void x25519ComputeShared(AppConfig &config, const uint8_t otherPub[32]) {
|
||||
uint8_t shared[32];
|
||||
crypto_x25519(shared, config.ephemeralSec, otherPub);
|
||||
memcpy(config.sharedSecret, shared, 32);
|
||||
std::memcpy(config.sharedSecret, shared, 32);
|
||||
|
||||
config.haveSharedSecret = true;
|
||||
std::cout << "[x25519] Получен общий сеансовый ключ (32 байта).\n";
|
||||
std::cout << CLR_GREEN "[x25519] Общий сеансовый ключ вычислен!\n" CLR_RESET;
|
||||
}
|
||||
|
BIN
x25519_handshake.o
Normal file
BIN
x25519_handshake.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user