diff --git a/include/config.h b/include/config.h index 6cf23fb..f2db461 100644 --- a/include/config.h +++ b/include/config.h @@ -1,25 +1,20 @@ /* Server */ #define DEBUG 0 + #define PORT 20247 #define MAX_NAME 32 /* Max username length */ #define DATABASE_NAME "test.db" -#define MAX_MESSAGE_LENGTH 8192 +#define MAX_DATA_LENGTH 8192 /* Don't touch unless you know what you are doing */ -#define MAX_CONNECTION_QUEUE 128 #define MAX_THREADS 8 -#define MAX_EVENTS 64 /* Max events can be returned simulataneouly by epoll */ #define MAX_CLIENTS_PER_THREAD 1024 /* Client */ #define DOMAIN "127.0.0.1" +/* #define USERNAME "night" */ /* UI */ #define PANEL_HEIGHT 1 -#define DRAW_PREVIEW 1 #define CLIENT_DATA_DIR "~/.local/share/zsm/zen" - -/* Keybindings */ -#define DOWN 0x102 -#define UP 0x103 diff --git a/include/notification.h b/include/notification.h index 8a81a50..448404e 100644 --- a/include/notification.h +++ b/include/notification.h @@ -4,6 +4,6 @@ #include #include -void send_notification(uint8_t *content); +void send_notification(uint8_t *author, uint8_t *content); #endif diff --git a/include/packet.h b/include/packet.h index eba22ac..40ad798 100644 --- a/include/packet.h +++ b/include/packet.h @@ -26,8 +26,6 @@ #include "config.h" -#define ERROR_LENGTH 26 - #define ZSM_TYP_AUTH 0x1 #define ZSM_TYP_MESSAGE 0x2 #define ZSM_TYP_UPDATE_MESSAGE 0x3 @@ -51,32 +49,35 @@ #define ZSM_STA_AUTHORISED 0xE #define ADDRESS_SIZE MAX_NAME + 1 + 255 /* 1 for @, 255 for domain, defined in RFC 5321, Section 4.5.3.1.2 */ -#define CHALLENGE_SIZE 32 #define HASH_SIZE crypto_generichash_BYTES #define NONCE_SIZE crypto_aead_xchacha20poly1305_ietf_NPUBBYTES #define ADDITIONAL_SIZE crypto_aead_xchacha20poly1305_ietf_ABYTES +#define MAX_MESSAGE_LENGTH MAX_DATA_LENGTH - MAX_NAME * 2 - NONCE_SIZE -typedef struct packet { +typedef struct packet_t { uint8_t status; uint8_t type; uint32_t length; uint8_t *data; uint8_t *signature; -} packet; +} packet_t; + +typedef struct message_t { + uint8_t author[MAX_NAME]; + uint8_t recipient[MAX_NAME]; + uint8_t *content; + time_t creation; +} message_t; #include "key.h" /* Utilities functions */ -void print_packet(packet *msg); -int recv_packet(packet *pkt, int fd, uint8_t required_type); -packet *create_packet(uint8_t option, uint8_t type, uint32_t length, uint8_t *data, uint8_t *signature); -int send_packet(packet *msg, int fd); -void free_packet(packet *msg); -int encrypt_packet(int sockfd, key_pair *kp); -packet *verify_packet(packet *pkt, int fd); -uint8_t *encrypt_data(uint8_t *from, uint8_t *to, uint8_t *raw, uint32_t raw_length, uint32_t *length); -uint8_t *decrypt_data(packet *pkt); -int verify_integrity(packet *pkt, public_key *pk); +void print_packet(packet_t *msg); +int recv_packet(packet_t *pkt, int fd, uint8_t required_type); +packet_t *create_packet(uint8_t option, uint8_t type, uint32_t length, uint8_t *data, uint8_t *signature); +int send_packet(packet_t *msg, int fd); +void free_packet(packet_t *msg); +int verify_packet(packet_t *pkt, int fd); uint8_t *create_signature(uint8_t *data, uint32_t length, secret_key *sk); #endif diff --git a/include/server/server.h b/include/server/server.h new file mode 100644 index 0000000..03cf135 --- /dev/null +++ b/include/server/server.h @@ -0,0 +1,8 @@ +#ifndef SERVER_H_ +#define SERVER_H_ + +#define CHALLENGE_SIZE 32 +#define MAX_CONNECTION_QUEUE 128 /* for listen() */ +#define MAX_EVENTS 64 /* Max events can be returned simulataneouly by epoll */ + +#endif diff --git a/include/util.h b/include/util.h index c4defb2..54e28e9 100644 --- a/include/util.h +++ b/include/util.h @@ -9,7 +9,6 @@ void error(int fatal, const char *fmt, ...); void *memalloc(size_t size); void *estrdup(void *str); -int set_nonblocking(int fd); char *replace_home(char *str); void mkdir_p(const char *destdir); void write_log(int type, const char *fmt, ...);