fix:1
This commit is contained in:
parent
fa6f029eea
commit
23987b5975
@ -1,47 +0,0 @@
|
|||||||
ls
|
|
||||||
。ã€./linux
|
|
||||||
./linux
|
|
||||||
exit
|
|
||||||
ls
|
|
||||||
./init.sh
|
|
||||||
exit
|
|
||||||
gcc -o linux linux.c -lpthread -lssl -lcrypto
|
|
||||||
gcc -o linux linux.c -lpthread -lssl -lcrypto
|
|
||||||
gcc -o linux linux.c -lpthread -lssl -lcrypto
|
|
||||||
./linux
|
|
||||||
openssl ecparam -name SM2 -genkey -noout -out sm2_key.pem
|
|
||||||
openssl ec -in sm2_key.pem -pubout -out sm2_pub.pem
|
|
||||||
ll
|
|
||||||
ls
|
|
||||||
cat sm2_key.pem
|
|
||||||
ls
|
|
||||||
exit
|
|
||||||
gcc client.c -o client -lssl -lcrypto
|
|
||||||
openssl version
|
|
||||||
openssl-devel version
|
|
||||||
yum install -y openssl-devel
|
|
||||||
find /usr/include/openssl -name sm4.h
|
|
||||||
which openssl
|
|
||||||
find /usr/bin/openssl -name sm4.h
|
|
||||||
find /usr/bin/openssl/ -name sm4.h
|
|
||||||
cd /usr/bin/openssl
|
|
||||||
wget https://www.openssl.org/source/openssl-3.0.12.tar.gz
|
|
||||||
yum install wget
|
|
||||||
wget https://www.openssl.org/source/openssl-3.0.12.tar.gz
|
|
||||||
find / -name sm4.h
|
|
||||||
cd /
|
|
||||||
ls
|
|
||||||
find / -name sm4.h
|
|
||||||
cd /usr/include/
|
|
||||||
ll
|
|
||||||
ls
|
|
||||||
ls
|
|
||||||
ls -l
|
|
||||||
exit
|
|
||||||
ll
|
|
||||||
alias ll 'ls -l'
|
|
||||||
alias 'll' 'ls -l'
|
|
||||||
alias ll 'ls -l'
|
|
||||||
alias 'ls -l' ll
|
|
||||||
gcc -o server server.c -lpthread -L/usr/local/lib -I/usr/local/include -lgmssl -lpthread -lz
|
|
||||||
exit
|
|
51
.gitignore
vendored
Normal file
51
.gitignore
vendored
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
# generated file
|
||||||
|
/build*
|
||||||
|
/demos/*.pem
|
||||||
|
/demos/.private
|
||||||
|
/demos/scripts/*.pem
|
||||||
|
/demos/scripts/*.der
|
||||||
|
/demos/scripts/*.txt
|
||||||
|
/demos/scripts/*.bin
|
||||||
|
/demos/scripts/*.sig
|
||||||
|
|
||||||
|
/examples/*
|
||||||
|
|
||||||
|
# Object files
|
||||||
|
*.o
|
||||||
|
*.obj
|
||||||
|
|
||||||
|
# All kinds of executables
|
||||||
|
*.so
|
||||||
|
*.so.*
|
||||||
|
*.dylib
|
||||||
|
*.dylib.*
|
||||||
|
*.dll
|
||||||
|
*.dll.*
|
||||||
|
*.exe
|
||||||
|
*.pyc
|
||||||
|
*.exp
|
||||||
|
*.lib
|
||||||
|
*.pdb
|
||||||
|
*.ilk
|
||||||
|
*.def
|
||||||
|
*.rc
|
||||||
|
*.res
|
||||||
|
|
||||||
|
# macOS
|
||||||
|
.DS_Store
|
||||||
|
*.tar.gz
|
||||||
|
|
||||||
|
# editor artefacts
|
||||||
|
.vscode/*
|
||||||
|
*.swp
|
||||||
|
.#*
|
||||||
|
\#*#
|
||||||
|
*~
|
||||||
|
|
||||||
|
/docs/*
|
||||||
|
|
||||||
|
/.vs/*
|
||||||
|
/out/*
|
||||||
|
|
||||||
|
*.plist
|
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -7,6 +7,7 @@
|
|||||||
"in.h": "c",
|
"in.h": "c",
|
||||||
"rand.h": "c",
|
"rand.h": "c",
|
||||||
"inet.h": "c",
|
"inet.h": "c",
|
||||||
"unistd.h": "c"
|
"unistd.h": "c",
|
||||||
|
"stdio.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
12
README.md
12
README.md
@ -2,8 +2,20 @@
|
|||||||
> macOS + Docker 部署 openeuler/openeuler(详细见 Dockefile 以及 docker-compose.yml)
|
> macOS + Docker 部署 openeuler/openeuler(详细见 Dockefile 以及 docker-compose.yml)
|
||||||
|
|
||||||
技术:
|
技术:
|
||||||
|
1. 客户端根据提示创建并上传一个文件到服务端。
|
||||||
|
2. 服务端对文件进行SM4加密后压缩并存储。
|
||||||
|
3. 客户端请求下载文件时,服务端解压解密文件,将内容返回客户端。
|
||||||
|
4. 使用线程和信号量限制客户端的并发连接数。
|
||||||
|
5. 通过进程间通信记录操作日志(使用管道)。
|
||||||
|
6. 客户端和服务端通过 socket 通信。
|
||||||
|
7. 文件操作会创建时间戳的目录管理文件。
|
||||||
|
|
||||||
~~~bash
|
~~~bash
|
||||||
gcc -o server server.c -lpthread -L/usr/local/lib -I/usr/local/include -lgmssl -lz
|
gcc -o server server.c -lpthread -L/usr/local/lib -I/usr/local/include -lgmssl -lz
|
||||||
gcc -o client client.c
|
gcc -o client client.c
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
|
启动测试:
|
||||||
|
1、启动服务端:./server
|
||||||
|
2、启动客户端:./client
|
||||||
|
3、客户端根据提示输入命令及内容
|
36
client.c
36
client.c
@ -5,6 +5,7 @@
|
|||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#define PORT 8001
|
#define PORT 8001
|
||||||
@ -14,18 +15,37 @@ void upload_file(int client_socket)
|
|||||||
{
|
{
|
||||||
char file_name[BUFFER_SIZE];
|
char file_name[BUFFER_SIZE];
|
||||||
char file_content[BUFFER_SIZE];
|
char file_content[BUFFER_SIZE];
|
||||||
|
mkdir("./newfile", 0777);
|
||||||
// 用户输入文件名
|
// 用户输入文件名
|
||||||
printf("输入要创建的文件名(不带路径): ");
|
printf("输入要创建的文件名(不带路径,需携带后缀)例如:abc.txt: ");
|
||||||
scanf("%s", file_name);
|
scanf("%s", file_name);
|
||||||
|
|
||||||
|
// 提取文件名部分(去掉后缀)
|
||||||
|
char base_name[BUFFER_SIZE];
|
||||||
|
const char *dot = strrchr(file_name, '.');
|
||||||
|
if (dot && dot != file_name)
|
||||||
|
{
|
||||||
|
strncpy(base_name, file_name, dot - file_name);
|
||||||
|
base_name[dot - file_name] = '\0';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// 如果没有后缀,直接使用原文件名
|
||||||
|
strcpy(base_name, file_name);
|
||||||
|
}
|
||||||
|
printf("文件名部分是: %s\n", base_name);
|
||||||
|
|
||||||
// 用户输入文件内容
|
// 用户输入文件内容
|
||||||
printf("输入文件内容(输入完毕后按回车结束):\n");
|
printf("输入文件内容(输入完毕后按回车结束):\n");
|
||||||
getchar(); // 清除上一次输入的换行符
|
getchar(); // 清除上一次输入的换行符
|
||||||
fgets(file_content, BUFFER_SIZE, stdin);
|
fgets(file_content, BUFFER_SIZE, stdin);
|
||||||
|
|
||||||
// 以file_name为文件名创建文件并将输入内容写入文件
|
char dir_name[256];
|
||||||
FILE *plain_file = fopen(file_name, "w");
|
snprintf(dir_name, 256, "./newfile/%s", file_name);
|
||||||
|
printf("文件路径是: %s\n", dir_name);
|
||||||
|
|
||||||
|
// 根据dir_name目录,file_name为文件名创建文件并将输入内容写入文件
|
||||||
|
FILE *plain_file = fopen(dir_name, "w");
|
||||||
if (!plain_file)
|
if (!plain_file)
|
||||||
{
|
{
|
||||||
perror("文件创建失败");
|
perror("文件创建失败");
|
||||||
@ -35,15 +55,17 @@ void upload_file(int client_socket)
|
|||||||
fclose(plain_file);
|
fclose(plain_file);
|
||||||
printf("文件创建成功,开始上传。\n");
|
printf("文件创建成功,开始上传。\n");
|
||||||
|
|
||||||
// 发送文件名到服务器
|
// 发送文件名(不含后缀)到服务器
|
||||||
send(client_socket, file_name, strlen(file_name), 0);
|
send(client_socket, base_name, strlen(base_name), 0);
|
||||||
// 等待服务器确认收到文件名
|
// 等待服务器确认收到文件名
|
||||||
char ack[BUFFER_SIZE] = {0};
|
char ack[BUFFER_SIZE] = {0};
|
||||||
read(client_socket, ack, BUFFER_SIZE);
|
read(client_socket, ack, BUFFER_SIZE);
|
||||||
if (strcmp(ack, "ACK") == 0)
|
if (strcmp(ack, "ACK") == 0)
|
||||||
{
|
{
|
||||||
printf("服务端确认文件名。\n");
|
printf("服务端确认文件名。\n");
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
printf("服务端未确认文件名。\n");
|
printf("服务端未确认文件名。\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
2
files/20241217111950/123.txt
Normal file
2
files/20241217111950/123.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
123
|
||||||
|
EOFDOWNLOAD123_decrypted.txt
|
0
files/20241218000302/123.txt
Normal file
0
files/20241218000302/123.txt
Normal file
0
files/20241218001945/DOWNLOAD123.txt.txt
Normal file
0
files/20241218001945/DOWNLOAD123.txt.txt
Normal file
1
newfile/123.txt
Normal file
1
newfile/123.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
123
|
1
newfile/init.sh
Normal file
1
newfile/init.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
123
|
2
server.c
2
server.c
@ -411,7 +411,7 @@ int main()
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
|
||||||
printf("客户端进入,当前资源被占用\n");
|
// printf("客户端进入,当前资源被占用\n");
|
||||||
|
|
||||||
int client_socket = accept(server_socket, (struct sockaddr *)&client_addr, &client_addr_len);
|
int client_socket = accept(server_socket, (struct sockaddr *)&client_addr, &client_addr_len);
|
||||||
if (client_socket == -1)
|
if (client_socket == -1)
|
||||||
|
Loading…
Reference in New Issue
Block a user