wifidog 編譯https通信、支持ssl加密、https通信

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版本上面就沒問題。

發佈了58 篇原創文章 · 獲贊 66 · 訪問量 29萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章