2022-06-27 23:57:00 +00:00
|
|
|
#include "speer.h"
|
|
|
|
|
2022-09-02 01:00:37 +00:00
|
|
|
#include "core/lmem.h"
|
|
|
|
#include "net/lpacket.h"
|
2022-03-18 04:05:18 +00:00
|
|
|
#include "sterm.h"
|
2022-02-25 04:13:05 +00:00
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
tShell_peer *shellP_newPeer(PEERTYPE type, OSTYPE osType, uint8_t *pubKey, char *hostname,
|
|
|
|
char *inet, char *ipStr)
|
|
|
|
{
|
|
|
|
tShell_peer *peer = (tShell_peer *)laikaM_malloc(sizeof(tShell_peer));
|
2022-02-25 04:13:05 +00:00
|
|
|
peer->type = type;
|
2022-03-18 04:05:18 +00:00
|
|
|
peer->osType = osType;
|
2022-02-25 04:13:05 +00:00
|
|
|
|
|
|
|
/* copy pubKey to peer's pubKey */
|
|
|
|
memcpy(peer->pub, pubKey, crypto_kx_PUBLICKEYBYTES);
|
|
|
|
|
2022-06-04 15:11:28 +00:00
|
|
|
/* copy hostname & ip */
|
2022-02-25 04:13:05 +00:00
|
|
|
memcpy(peer->hostname, hostname, LAIKA_HOSTNAME_LEN);
|
2022-06-04 15:11:28 +00:00
|
|
|
memcpy(peer->inet, inet, LAIKA_INET_LEN);
|
|
|
|
memcpy(peer->ipStr, ipStr, LAIKA_IPSTR_LEN);
|
2022-02-25 04:13:05 +00:00
|
|
|
|
|
|
|
/* restore NULL terminators */
|
2022-06-27 23:57:00 +00:00
|
|
|
peer->hostname[LAIKA_HOSTNAME_LEN - 1] = '\0';
|
|
|
|
peer->inet[LAIKA_INET_LEN - 1] = '\0';
|
|
|
|
peer->ipStr[LAIKA_IPSTR_LEN - 1] = '\0';
|
2022-02-25 04:13:05 +00:00
|
|
|
|
|
|
|
return peer;
|
|
|
|
}
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
void shellP_freePeer(tShell_peer *peer)
|
|
|
|
{
|
2022-02-25 04:13:05 +00:00
|
|
|
laikaM_free(peer);
|
|
|
|
}
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
char *shellP_typeStr(tShell_peer *peer)
|
|
|
|
{
|
2022-02-25 04:13:05 +00:00
|
|
|
switch (peer->type) {
|
2022-06-30 14:18:01 +00:00
|
|
|
case PEER_PEER:
|
|
|
|
return "Peer";
|
2022-06-27 23:57:00 +00:00
|
|
|
case PEER_BOT:
|
|
|
|
return "Bot";
|
|
|
|
case PEER_CNC:
|
|
|
|
return "CNC";
|
|
|
|
case PEER_AUTH:
|
|
|
|
return "Auth";
|
|
|
|
default:
|
|
|
|
return "err";
|
2022-02-25 04:13:05 +00:00
|
|
|
}
|
2022-03-18 04:05:18 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
char *shellP_osTypeStr(tShell_peer *peer)
|
|
|
|
{
|
2022-03-18 04:05:18 +00:00
|
|
|
switch (peer->osType) {
|
2022-06-27 23:57:00 +00:00
|
|
|
case OS_WIN:
|
|
|
|
return "Windows";
|
|
|
|
case OS_LIN:
|
|
|
|
return "Linux";
|
|
|
|
default:
|
|
|
|
return "unkn";
|
2022-03-18 04:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 23:57:00 +00:00
|
|
|
void shellP_printInfo(tShell_peer *peer)
|
|
|
|
{
|
|
|
|
char buf[128]; /* i don't expect bin2hex to write outside this, but it's only user-info and
|
|
|
|
doesn't break anything (ie doesn't write outside the buffer) */
|
2022-03-18 04:05:18 +00:00
|
|
|
|
|
|
|
sodium_bin2hex(buf, sizeof(buf), peer->pub, crypto_kx_PUBLICKEYBYTES);
|
2022-06-27 23:57:00 +00:00
|
|
|
shellT_printf("\t%s-%s\n\tOS: %s\n\tINET: %s\n\tPUBKEY: %s\n", peer->ipStr, peer->hostname,
|
|
|
|
shellP_osTypeStr(peer), peer->inet, buf);
|
2022-02-25 04:13:05 +00:00
|
|
|
}
|