您的位置:首页 > 理论基础 > 计算机网络

wifidog 编译https通信、支持ssl加密、https通信

2017-03-22 14:19 573 查看
openwrt 版本:CC

wifidog 1.2.1

之前编译wifidog 用https通信时,遇到以下错误

1、首先在打开宏USE_CYASSL,在simple_http.h头文件定义 #define USE_CYASSL

2、在simple_http.c 文件包含自己的头文件,因为https接口函数都在此文件中

#include "simple_http.h"

#ifdef USE_CYASSL

#include <cyassl/ssl.h>

#include <wolfssl/ssl.h>

当然你需要加上 以下函数的头文件。

3、在Makefile里面加入 -lwolfssl

libgateway.a(simple_http.o): In function `https_get':

simple_http.c:(.text+0x24a): undefined reference to `wolfSSL_Init'

simple_http.c:(.text+0x250): undefined reference to `wolfTLSv1_client_method'

simple_http.c:(.text+0x256): undefined reference to `wolfSSL_CTX_new'

simple_http.c:(.text+0x29a): undefined reference to `wolfSSL_CTX_set_cipher_list'

simple_http.c:(.text+0x2e6): undefined reference to `wolfSSL_CTX_load_verify_locations'

simple_http.c:(.text+0x350): undefined reference to `wolfSSL_CTX_set_verify'

simple_http.c:(.text+0x3a8): undefined reference to `wolfSSL_new'

simple_http.c:(.text+0x3de): undefined reference to `wolfSSL_check_domain_name'

simple_http.c:(.text+0x3e8): undefined reference to `wolfSSL_set_fd'

simple_http.c:(.text+0x40c): undefined reference to `wolfSSL_send'

simple_http.c:(.text+0x418): undefined reference to `wolfSSL_get_error'

simple_http.c:(.text+0x424): undefined reference to `wolfSSL_ERR_error_string'

simple_http.c:(.text+0x4e0): undefined reference to `wolfSSL_read'

simple_http.c:(.text+0x4ee): undefined reference to `wolfSSL_get_error'

simple_http.c:(.text+0x4fa): undefined reference to `wolfSSL_ERR_error_string'

simple_http.c:(.text+0x566): undefined reference to `wolfSSL_free'

simple_http.c:(.text+0x578): undefined reference to `wolfSSL_free'

本以为大功告成,make V=s,又出现以下错误

Package wifidog is missing dependencies for the following libraries:

libwolfssl.so.3

最后发现需要 在./staging_dir/target-mips_34kc_uClibc-0.9.33.2/pkginfo/libc.provides 文件中加入

libwolfssl.so.3

make V=s

搞定

另外1.2.1版本的wifidog有一个bug,util.c get_iface_ip函数,就是从GatewayInterface 获取不到ip地址

原来:

  /* Create a socket */

    if ((sockd = socket(AF_INET, SOCK_RAW, htons(0x8086))) < 0) {

        debug(LOG_ERR, "socket(): %s", strerror(errno));

        return NULL;

    } 

修改后:

/* Create a socket */

    if ((sockd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {

        debug(LOG_ERR, "socket(): %s", strerror(errno));

        return NULL;

    }

    memset(&if_data,0,sizeof(if_data));

如果是1.3版本的wifidog,则只需要 加上 memset(&if_data,0,sizeof(if_data)); 即可。

如果你的路由器用的BB版本,wifidog 移植上去会出现另外的一个错误

firewall.c文件里,arp_get(const char *req_ip) 根据ip地址获取MAC地址的函数,会导致用户无法认证上网。

修改前:

arp_get(const char *req_ip)

{

    FILE *proc;

    char ip[16];

    char mac[18];

    char *reply;

    s_config *config = config_get_config();

    if (!(proc = fopen(config->arp_table_path, "r"))) {

        return NULL;

    }

    /* Skip first line */

    while (!feof(proc) && fgetc(proc) != '\n') ;

    /* Find ip, copy mac in reply */

    reply = NULL;

    while (!feof(proc) && (fscanf(proc, " %15[0-9.] %*s %*s %17[A-Fa-f0-9:] %*s %*s", ip, mac) == 2)) {

        if (strcmp(ip, req_ip) == 0) {

            reply = safe_strdup(mac);

            break;

        }

    }

    fclose(proc);

    return reply;

}

修改后:

arp_get(const char *req_ip)

{

    FILE *proc;

    char ip[16];

    char mac[18];

    char *reply;

    char buf[1024]={0};

    s_config *config = config_get_config();

    if (!(proc = fopen(config->arp_table_path, "r"))) {

        debug(LOG_INFO, "----------------------------fopen /proc/net/arp error");

        return NULL;

    }

    /* Skip first line */

    while (!feof(proc) && fgetc(proc) != '\n') ;

    debug(LOG_INFO, "----req_ip====%s  ",req_ip);

    /* Find ip, copy mac in reply */

    reply = NULL;

    while (!feof(proc)) 

    {

        if(fgets(buf, sizeof(buf) - 1, proc)!=NULL)

        {

            if (strstr(buf, req_ip) !=NULL)

            {

                sscanf(buf, " %*s %*s %*s %17[A-Fa-f0-9:] %*s %*s", mac);

                reply = safe_strdup(mac);

                //debug(LOG_INFO, "buf=%s----====  mac=%s",buf,mac);

                break;

            }

        }

        memset(buf,0,sizeof(buf));

    }

    fclose(proc);

    return reply;

}

出现的原因是fscanf函数,可能是路由器的库版本过低导致,因为同样的函数在CC版本上面就没问题。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: