搭建BOA服务器

1 篇文章 0 订阅
1 篇文章 0 订阅

BOA是什么我就不多说了,网上的资料很多,不过大多数都是基于官网的源码进行编译。

由于BOA很早之前官网就停止更新了,所以官网的源码当时是不支持HTTPS的,下面我分享一些BOA支持HTTPS的东西。

 

boa源码下载地址https://github.com/lanzhongheng/boa-0.94-13-ssl

我比较了和官网代码的区别,添加了https以及AUTHENTICATION,而且添加的代码都通过宏定义作为开关

交叉编译:

1、修改mk.sh

    compile = "arm-2440-linux-gnueabi-"

    ssl_inc = "/home/vince/workspace/code_reading/openssl-1.0.2/include"

    ssl_libdir = "/home/vince/workspace/code_reading/openssl-1.0.2"

    替换为

    compile = "arm-none-linux-gnueabi-"

    ssl_inc = "/home/mark/WEB_GUI/openssl-1.0.2/include"

    ssl_libdir = "/home/mark/WEB_GUI/openssl-1.0.2"

2、./mk.sh clean

3、./mk.sh all

 

openssl下载地址https://www.openssl.org.

版本选择为openssl-1.1.0i,我就得是8月份的时候,这个版本在当时是最新版,所以就选择了它。

交叉编译:

1、tar zxvf openssl-1.1.0i.tar.gz

2、cd openssl-1.1.0i

3、./config no-asm no-tls1 -static(禁止tls1.0)

4、修改Makefile

        CROSS_COMPILE = arm-none-linux-gnueabi-

         CLFAGS去除-m32选项(-m32生成32位机器的汇编代码)

5、make

 

编译好,BOA可以在板子上运行成功了。在使用的过程中,也做了一些修改记录

1、defines.h
   #define MAX_FILE_MMAP    10 * 1024 * 1024 (修复load比较大的图片时无法加载)
   #define SOCKETBUF_SIZE   8192 * 100 (修复CGI中显示较多数据的问题,缓存不够)
2、源码中MD5的算法有点问题,每次通过authgen生成的密码都不同,无法通过用户认证
    网上下载了md5.c和md5.h,替换原来的文件
    auth_check_userpass函数MD5Final调用之前添加
    memset(final, 0, 16);
    auth_check_userpass函数中
    struct MD5Context mc;替换为MD5_CTX mc;
    create_auth函数中
    struct MD5Context mc;替换为MD5_CTX mc;
    

md5.c代码

  1 #include <memory.h>
  2 #include <string.h>
  3 #include "md5.h"
  4
  5 unsigned char PADDING[]={0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  6 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  7 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  8 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  9
 10 void MD5Init(MD5_CTX *context)
 11 {
 12     context->count[0] = 0;
 13     context->count[1] = 0;
 14     context->state[0] = 0x67452301;
 15     context->state[1] = 0xEFCDAB89;
 16     context->state[2] = 0x98BADCFE;
 17     context->state[3] = 0x10325476;
 18     memset(context->buffer, 0, 64);
 19 }
 20 void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen)
 21 {
 22     unsigned int i = 0,index = 0,partlen = 0;
 23     index = (context->count[0] >> 3) & 0x3F;
 24     partlen = 64 - index;
 25     context->count[0] += inputlen << 3;
 26     if(context->count[0] < (inputlen << 3))
 27         context->count[1]++;
 28     context->count[1] += inputlen >> 29;
 29
 30     if(inputlen >= partlen)
 31     {
 32         memcpy(&context->buffer[index],input,partlen);
 33         MD5Transform(context->state,context->buffer);
 34         for(i = partlen;i+64 <= inputlen;i+=64)
 35             MD5Transform(context->state,&input[i]);
 36         index = 0;
 37     }
 38     else
 39     {
 40         i = 0;
 41     }
 42     memcpy(&context->buffer[index],&input[i],inputlen-i);
 43 }
 44 void MD5Final(MD5_CTX *context,unsigned char digest[16])
 45 {
 46     unsigned int index = 0,padlen = 0;
 47     unsigned char bits[8];
 48     index = (context->count[0] >> 3) & 0x3F;
 49     padlen = (index < 56)?(56-index):(120-index);
 50     MD5Encode(bits,context->count,8);
 51     MD5Update(context,PADDING,padlen);
 52     MD5Update(context,bits,8);
 53     MD5Encode(digest,context->state,16);
 54 }
 55 void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len)
 56 {
 57     unsigned int i = 0,j = 0;
 58     while(j < len)
 59     {
 60         output[j] = input[i] & 0xFF;
 61         output[j+1] = (input[i] >> 8) & 0xFF;
 62         output[j+2] = (input[i] >> 16) & 0xFF;
 63         output[j+3] = (input[i] >> 24) & 0xFF;
 64         i++;
 65         j+=4;
 66     }
 67 }
 68 void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len)
 69 {
 70     unsigned int i = 0,j = 0;
 71     while(j < len)
 72     {
 73         output[i] = (input[j]) |
 74             (input[j+1] << 8) |
 75             (input[j+2] << 16) |
 76             (input[j+3] << 24);
 77         i++;
 78         j+=4;
 79     }
 80 }
 81 void MD5Transform(unsigned int state[4],unsigned char block[64])
 82 {
 83     unsigned int a = state[0];
 84     unsigned int b = state[1];
 85     unsigned int c = state[2];
 86     unsigned int d = state[3];
 87     unsigned int x[64];
 88     MD5Decode(x,block,64);
 89     FF(a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */
 90     FF(d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */
 91     FF(c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */
 92     FF(b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */
 93     FF(a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */
 94     FF(d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */
 95     FF(c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */
 96     FF(b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */
 97     FF(a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */
 98     FF(d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */
 99     FF(c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */
100     FF(b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */
101     FF(a, b, c, d, x[12], 7, 0x6b901122); /* 13 */
102     FF(d, a, b, c, x[13], 12, 0xfd987193); /* 14 */
103     FF(c, d, a, b, x[14], 17, 0xa679438e); /* 15 */
104     FF(b, c, d, a, x[15], 22, 0x49b40821); /* 16 */
105
106     /* Round 2 */
107     GG(a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */
108     GG(d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */
109     GG(c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */
110     GG(b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */
111     GG(a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */
112     GG(d, a, b, c, x[10], 9,  0x2441453); /* 22 */
113     GG(c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */
114     GG(b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */
115     GG(a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */
116     GG(d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */
117     GG(c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */
118     GG(b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */
119     GG(a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */
120     GG(d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */
121     GG(c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */
122     GG(b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */
123
124     /* Round 3 */
125     HH(a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */
126     HH(d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */
127     HH(c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */
128     HH(b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */
129     HH(a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */
130     HH(d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */
131     HH(c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */
132     HH(b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */
133     HH(a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */
134     HH(d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */
135     HH(c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */
136     HH(b, c, d, a, x[ 6], 23,  0x4881d05); /* 44 */
137     HH(a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */
138     HH(d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */
139     HH(c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */
140     HH(b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */
141
142     /* Round 4 */
143     II(a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */
144     II(d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */
145     II(c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */
146     II(b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */
147     II(a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */
148     II(d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */
149     II(c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */
150     II(b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */
151     II(a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */
152     II(d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */
153     II(c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */
154     II(b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */
155     II(a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */
156     II(d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */
157     II(c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */
158     II(b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */
159     state[0] += a;
160     state[1] += b;
161     state[2] += c;
162     state[3] += d;
163 }

md5.h代码

  1 #ifndef MD5_H
  2 #define MD5_H
  3
  4 typedef struct
  5 {
  6     unsigned int count[2];
  7     unsigned int state[4];
  8     unsigned char buffer[64];
  9 }MD5_CTX;
 10
 11
 12 #define F(x,y,z) ((x & y) | (~x & z))
 13 #define G(x,y,z) ((x & z) | (y & ~z))
 14 #define H(x,y,z) (x^y^z)
 15 #define I(x,y,z) (y ^ (x | ~z))
 16 #define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
 17 #define FF(a,b,c,d,x,s,ac) \
 18 { \
 19     a += F(b,c,d) + x + ac; \
 20     a = ROTATE_LEFT(a,s); \
 21     a += b; \
 22 }
 23 #define GG(a,b,c,d,x,s,ac) \
 24 { \
 25     a += G(b,c,d) + x + ac; \
 26     a = ROTATE_LEFT(a,s); \
 27     a += b; \
 28 }
 29 #define HH(a,b,c,d,x,s,ac) \
 30 { \
 31     a += H(b,c,d) + x + ac; \
 32     a = ROTATE_LEFT(a,s); \
 33     a += b; \
 34 }
 35 #define II(a,b,c,d,x,s,ac) \
 36 { \
 37     a += I(b,c,d) + x + ac; \
 38     a = ROTATE_LEFT(a,s); \
 39     a += b; \
 40 }
 41 void MD5Init(MD5_CTX *context);
 42 void MD5Update(MD5_CTX *context,unsigned char *input,unsigned int inputlen);
 43 void MD5Final(MD5_CTX *context,unsigned char digest[16]);
 44 void MD5Transform(unsigned int state[4],unsigned char block[64]);
 45 void MD5Encode(unsigned char *output,unsigned int *input,unsigned int len);
 46 void MD5Decode(unsigned int *output,unsigned char *input,unsigned int len);
 47
 48 #endif

 

大家使用中如果有什么问题可以一起交流哦。

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值