Giter Club home page Giter Club logo

gfw.press.c's People

Contributors

chinashiyu avatar xzchsia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gfw.press.c's Issues

编译的时候,出现下面的报错,是啥回事啊?

gcc -o gfw.press src/client.c src/encrypt.c -ansi -O3 -lssl -lcrypto -lpthread -Wall
src/client.c: In function ‘load_config’:
src/client.c:480:3: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result]
fscanf(file, "%s", &text[pos]);
^

在树莓派中编译出错

系统信息

$ uname -a
Linux RPi 4.9.43-1-ARCH #1 SMP Fri Aug 18 01:18:17 UTC 2017 armv6l GNU/Linux
$ openssl version -a
OpenSSL 1.1.0f  25 May 2017

出错信息大意是有几个结构体没定义
修改以下几行后编译成功(附件:rpib+.txt

diff --git a/src/client.c b/src/client.c
index 5f5d15a..c1e2b38 100644
--- a/src/client.c
+++ b/src/client.c
@@ -23,6 +23,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <arpa/inet.h>
+#include <sys/time.h>
 #include <sys/types.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
diff --git a/src/encrypt.c b/src/encrypt.c
index f576dd1..fbc8f63 100644
--- a/src/encrypt.c
+++ b/src/encrypt.c
@@ -199,7 +199,7 @@ int encrypt(char *key, char *in, int inl, char *out) {
 
 	int cipher_len = 0;
 
-	EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *) malloc(sizeof(EVP_CIPHER_CTX));
+	EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
 
 	EVP_CIPHER_CTX_init(ctx);
 
@@ -229,7 +229,7 @@ int encrypt(char *key, char *in, int inl, char *out) {
 
 	free(cipher);
 
-	EVP_CIPHER_CTX_cleanup(ctx);
+	EVP_CIPHER_CTX_free(ctx);
 
 	return IV_SIZE + inl;
 
@@ -335,7 +335,7 @@ int decrypt(char *key, char *in, int inl, char *out) {
 
 	int outl = 0;
 
-	EVP_CIPHER_CTX *ctx = (EVP_CIPHER_CTX *) malloc(sizeof(EVP_CIPHER_CTX));
+	EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
 
 	EVP_CIPHER_CTX_init(ctx);
 
@@ -349,7 +349,7 @@ int decrypt(char *key, char *in, int inl, char *out) {
 
 	free(cipher);
 
-	EVP_CIPHER_CTX_cleanup(ctx);
+	EVP_CIPHER_CTX_free(ctx);
 
 	if (cipher_len != outl) {

random length to send() and recv() maybe better code here:

#include <time.h>

/** 缓冲区最小值,128K */
//change here
//static int BUFFER_SIZE_MIN = 1024 * 128;
int recv_len_seed = 30;//start with 30(recv_len_seed=ENCRYPT_SIZE)
int random_load = 0;
int get_random_load(){
return 1024+(rand()+65536);
}

//change here
int get_buffer_size_min(){
//return 16 + (rand() % 16318);//16318 for test maybe 32768 or bigger is better
return 16 + (rand() % random_load);
}

//change here
int get_head_block(){
//return recv_len_seed + (rand() % 16318);//16318 for test maybe 32768 or bigger is better
return recv_len_seed + (rand() % random_load);
}

/**

  • 浏览器IO线程
    */
    void *thread_io_agent(void _io) {
    struct IO io = ((struct IO) _io);
    while (1) {
    //change here
    int buffer_size_min = get_buffer_size_min();
    char buffer = malloc(buffer_size_min + 1);
    /
    接收浏览器数据 /
    int recvl = recv(io.socket_agent, buffer, buffer_size_min, MSG_NOSIGNAL);
    if (recvl < 1) {
    free(buffer);
    break;
    }
    buffer[recvl] = '\0';
    int outl = recvl + ENCRYPT_SIZE + NOISE_MAX;
    char out = malloc(outl + 1);
    int _outl = encrypt_net(key, buffer, recvl, out);
    out[_outl] = '\0';
    free(buffer);
    /
    发送数据到服务器 */
    int sendl = send(io.socket_server, out, _outl, MSG_NOSIGNAL);
    free(out);
    if (sendl < 1) {
    break;
    }
    }
    pthread_exit(0);
    }

/**

  • 服务器IO线程
    */
    void *thread_io_server(void _io) {
    struct IO io = ((struct IO) _io);
    //change here
    int free_head_temp = 1;
    int head_temp_last = 0;
    int head_len_temp = 0;
    char head_temp;
    while (1) {
    if(free_head_temp){
    int head_block_length = get_head_block();
    head_temp = malloc(head_block_length);
    /
    接收服务器头数据 /
    head_len_temp = recv(io.socket_server, head_temp, head_block_length, MSG_NOSIGNAL);
    if (head_len_temp < ENCRYPT_SIZE) {
    free(head_temp);
    break;
    }
    }else{
    int head_block_length = get_head_block();
    char head_temp_temp = malloc(head_block_length);
    memcpy(head_temp_temp, &head_temp[head_len_temp-head_temp_last], head_temp_last);
    free(head_temp);
    head_temp = head_temp_temp;
    /
    接收服务器头数据 */
    head_len_temp = recv(io.socket_server, &head_temp[head_temp_last], head_block_length-head_temp_last, MSG_NOSIGNAL);
    head_len_temp = head_len_temp + head_temp_last;
    if (head_len_temp < ENCRYPT_SIZE) {
    free(head_temp);
    break;
    }
    }
    int head_len = ENCRYPT_SIZE;
    int head_else = head_len_temp - head_len;
    char head = malloc(ENCRYPT_SIZE + 1);
    memcpy(head, head_temp, head_len);
    head[ENCRYPT_SIZE] = '\0';
    char head_out = malloc(SIZE_SIZE + 1);
    if (decrypt(key, head, head_len, head_out) == -1) {
    free(head_out);
    break;
    }
    head_out[SIZE_SIZE] = '\0';
    free(head);
    int sizes = malloc(2 * sizeof(int));
    if (get_block_sizes(head_out, sizes) == -1) {
    free(head_out);
    free(sizes);
    break;
    }
    int data = (int) sizes[0];
    int noise = (int) sizes[1];
    free(head_out);
    free(sizes);
    int size = data + noise;
    char in = malloc(size + 1);
    int _size = 0;
    if(head_else > size){
    memcpy(in, &head_temp[head_len], size);
    head_temp_last = head_else-size;
    if(head_temp_last<ENCRYPT_SIZE){
    recv_len_seed = ENCRYPT_SIZE;
    }else{
    recv_len_seed = head_temp_last;
    }
    free_head_temp = 0;
    _size = size;
    }else{
    if(head_else>0){
    memcpy(in, &head_temp[head_len], head_else);
    }
    //recv_len_seed = ENCRYPT_SIZE;
    free(head_temp);
    head_temp_last = 0;
    free_head_temp = 1;
    _size = head_else;
    }
    for (; _size < size;) {
    /
    接收服务器数据 /
    head_len = recv(io.socket_server, &in[_size], (size - _size), MSG_NOSIGNAL);
    if (head_len < 1) {
    break;
    }
    _size += head_len;
    }
    if (_size != size) {
    free(in);
    break;
    }
    in[size] = '\0';
    int outl = data - IV_SIZE;
    char * out = malloc(outl + 1);
    if (decrypt(key, in, data, out) == -1) {
    free(in);
    free(out);
    break;
    }
    out[outl] = '\0';
    free(in);
    /
    转发数据到浏览器 /
    int sendl = send(io.socket_agent, out, outl, MSG_NOSIGNAL);
    free(out);
    if (sendl < 1) {
    break;
    }
    }
    if(!free_head_temp){
    free(head_temp);
    }
    pthread_exit(0);
    }
    /

  • 客户端主程序
    */
    int main(int argc, char *argv[]) {

    _log("GFW.Press客户端开始运行......");
    //change here
    random_load = get_random_load();
    srand((unsigned)time(NULL));
    ......
    }

dear gfw.press users :
you can give me a little donate so i can fully time codeing

bitshares or bitBTC or bitUSD or bitCNY:
tutor-de

bitcoin:
19Q3S14uQYnQDirZ4f5BFjk4m42asdo2AG
DASH:
Xv6Lj6VMEtcDcCe6DPoNd149nJ44apBXah
ETH:
0xE242DbC096B316b0601878EDa9EC4Fffd58290C2
DOGE:
DNjXHJh3oCmAXCJW7nzaY6uktJLk7EGjgd
LTC:
LLJHTQME5MA98KGrBpnH1M7uFB6qSLiFpV
USDT:
1JAphejVsyAg2UhGT2E4noZJpETj9ZX4o6

check your donate:
https://bitshares.org/wallet/#/account/tutor-de/dashboard

丢包问题

大爷,测试了下C版的,似乎网络速度比JAVA版的快,但响应似乎有问题,丢包高,通过使用YouTube 推特 等,非专业测试!

代码改进意见,仅供参考

//新添加:
#include <errno.h>
#include <signal.h>

sockaddr_client.sin_port = htons(listen_port);

int tmp = 1;
//设置端口可以重复使用 省得退出后重启需要等一段时间
setsockopt(socket_client, SOL_SOCKET, SO_REUSEADDR, &tmp, sizeof(int));

int _bind = bind(socket_client, (struct sockaddr *) &sockaddr_client, sizeof(struct sockaddr));

另外如果需要使用 pthread_kill(thread_id, SIGKILL);
请在 makefile 里将 CFLAGS += -ansi 改成 CFLAGS += -D_POSIX_C_SOURCE=199506

完整的代码并没有仔细看,意见仅供参考
我觉得加密方法是绝对安全的。但是连接服务器时,
可以考虑把(密码+端口号)取hash,发送到服务器供服务器验证
如果要单端口多用户 可以(密码+邮箱用户名)取hash,发送到服务器供服务器验证
如果想要更安全可以(密码+邮箱用户名)取hash 再取 hash
或者(密码+邮箱用户名+"gfw.press")取hash

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.