intirain 4 жил өмнө
parent
commit
b9e7a51095
6 өөрчлөгдсөн 124 нэмэгдсэн , 13 устгасан
  1. 6 5
      Makefile
  2. 91 0
      crypt.c
  3. 1 0
      include/vcc/vcc.h
  4. 2 2
      include/vcc/version.h
  5. 22 4
      main.c
  6. 2 2
      vcc.c

+ 6 - 5
Makefile

@@ -1,16 +1,17 @@
 VCC_MAJOR 		= 1
-VCC_MINOR 		= 6
+VCC_MINOR 		= 7
 VCC_PATCH 		= 0
 VCC_STR 		= -rc 
 
 VCC_COMPILE_TIME 	= $(shell date)
-VCC_COMPILE_BY 	= $(shell whoami)
+VCC_COMPILE_BY 		= $(shell whoami)
 VCC_SEMVER 		= vcc $(VCC_MAJOR).$(VCC_MINOR).$(VCC_PATCH)$(VCC_STR)
 
-srcs 			= main.c vcc.c pretty.c cmd.c 
-objs 			= main.o vcc.o pretty.o cmd.o 
+srcs 			= main.c vcc.c pretty.c cmd.c crypt.c 
+objs 			= main.o vcc.o pretty.o cmd.o crypt.o 
 target 			= vcc 
-CFLAGS 			= -std=gnu11 -Wall -Wextra -Werror -Iinclude -g 
+libgcrypt_cargs 	= $(shell libgcrypt-config --libs)
+CFLAGS 			= -std=gnu11 -Wall -Wextra -Werror -Iinclude -g $(libgcrypt_cargs)
 MAKEFLAGS 		= --no-print-directory
 
 VCC_VERSION 		= VCC $(VCC_MAJOR).$(VCC_MINOR).$(VCC_PATCH) \

+ 91 - 0
crypt.c

@@ -0,0 +1,91 @@
+/* vcc/crypt.c 
+ * 
+ * This file is part of vcc. 
+ * 
+ * vcc is free software: you can redistribute it and/or modify 
+ * it under the terms of the GNU General Public License as published by 
+ * the Free Software Foundation, either version 3 of the License, or 
+ * (at your option) any later version. 
+ * 
+ * vcc is distributed in the hope that it will be useful, 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
+ * GNU General Public License for more details. 
+ * 
+ * You should have received a copy of the GNU General Public License 
+ * along with vcc. If not, see <https://www.gnu.org/licenses/>
+ */ 
+
+
+
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <sys/times.h>
+
+#include <vcc/vcc.h>
+#include <vcc/version.h>
+#include <vcc/pretty.h>
+
+
+#define KEYSIZE 	8
+#define BLKSIZE 	8
+
+int 			keysize, blksize;
+int 			msgsize;
+__uint64_t	 	key;
+
+
+int show_algo_info(void) {
+	keysize = KEYSIZE;
+	blksize = BLKSIZE;
+
+	printf("key size: %d\n", keysize);
+	printf("block size: %d\n", blksize);
+	printf("maximum message size: %ld\n", MSG_SIZE);
+
+	return 0;
+}
+
+int crypt_init(void *k) {
+	key = *(__uint64_t *) &k;
+
+	return 0;
+}
+
+
+char *encrypt(char *msg) {
+	int i;
+
+	for (i = 0; msg[i]; i++) {
+		if (msg[i] == 'z') 
+			msg[i] = 'a';
+
+		else if (msg[i] == 'Z') 
+			msg[i] = 'A';
+
+		msg[i]++;
+	}
+
+	return msg;
+}
+
+
+int decrypt(char *msg) {
+	int i;
+
+	for (i = 0; msg[i]; i++) {
+		if (msg[i] == 'a') 
+			msg[i] = 'z';
+
+		else if (msg[i] == 'A') 
+			msg[i] = 'Z';
+
+		else 
+			msg[i]--;
+	}
+
+	return 0;
+}
+

+ 1 - 0
include/vcc/vcc.h

@@ -24,6 +24,7 @@
 
 /* magic number in vcc_request to check that it's really a vcc package */
 #define VCC_MAGIC 	0x01328e22
+#define VCC_MAGIC_CR 	0x01328e36
 
 /* the port that vccd is listening on */
 #define VCC_PORT 	46

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCC_VERSION "VCC 1.5.3 Sun Apr  3 19:40:00 CST 2022 root"
-#define VCC_SEMVER "vcc 1.5.3-rc "
+#define VCC_VERSION "VCC 1.7.0 Mon Apr  4 16:27:24 CST 2022 root"
+#define VCC_SEMVER "vcc 1.7.0-rc "

+ 22 - 4
main.c

@@ -47,6 +47,11 @@ int read_msg(struct vcc_request *buf);
 int get_msgs(void);
 int vcc_login(char *, char *);
 
+int show_algo_info(void);
+int crypt_init(void *key);
+char *encrypt(char *);
+int decrypt(char *);
+
 int do_cmd(char *s);
 int do_bh(struct vcc_request *);
 
@@ -141,7 +146,9 @@ int main(int argc, char **argv) {
 	struct pollfd 		fds[2];
 	struct vcc_request 	*req;
 	char 			*buf, *msg, *ip = "124.223.105.230";
+	char 			key[64];
 	int 			n, size, port = VCC_PORT, got_usrname;
+
 	(void) argc;
 
 #ifdef _WIN32
@@ -156,10 +163,17 @@ int main(int argc, char **argv) {
 	init_socket(ip, port);
 
 	printf("Connected to server. \n");
-	printf("%s@%s%d\n", usrname, ip, port);
-
 	login(got_usrname);
 
+	show_algo_info();
+
+	memset(key, 0, 64);
+
+	fprintf(stderr, "Key: ");
+	read(0, key, 64);
+
+	crypt_init(key);
+
 	fds[0].fd = 0;
 	fds[0].events = POLLIN;
 	fds[0].revents = 0;
@@ -217,7 +231,11 @@ int main(int argc, char **argv) {
 				do_cmd(buf);
 
 			else if (*buf != '\n') {
+				if (unlikely(!encrypt(buf))) 
+					continue;
+
 				send_msg(buf, usrname);
+				decrypt(buf);
 
 				pretty_new_msg(usrname, buf, current_sid);
 			}
@@ -242,8 +260,8 @@ int main(int argc, char **argv) {
 
 			msg = req->msg;
 
-			if (!*msg || *(unsigned char *) msg == 0xffu) 
-				continue;
+			if (strcmp(req->usrname, "system")) 
+				decrypt(msg);
 
 			pretty_new_msg(req->usrname, msg, ntohl(req->session));
 			pretty_prompt(usrname);

+ 2 - 2
vcc.c

@@ -98,13 +98,13 @@ int send_msg(const char *msg, const char *usrname) {
 
 	clear_req(&req);
 
-	req.magic = htonl(VCC_MAGIC);
+	req.magic = htonl(VCC_MAGIC_CR);
 	req.reqtype = htonl(REQ_MSG_SEND);
 	req.uid = 0;
 	req.session = htonl(current_sid);
        
 	strncpy(req.usrname, usrname, USRNAME_SIZE);
-	strncpy(req.msg, msg, MSG_SIZE);
+	memcpy(req.msg, msg, MSG_SIZE);
 	write(fd, &req, REQ_SIZE);
 
 	return 0;