背景:
之前交叉编译出来的wget文件,在板子上运行时,不支持https解析。
需要在交叉编译wget时,加上openssl库文件。
交叉编译链中没有该库,所以需要自己交叉编译openssl。
交叉编译openssl:
配置文件:
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
tar -vxf openssl-1.1.1a.tar.gz
cd openssl-1.1.1a/
mkdir __install
./config no-asm shared --prefix=$PWD/__install
修改Makefile文件:
#CROSS_COMPILE=
CROSS_COMPILE=aarch64-himix100-linux-
#CNF_CFLAGS=-pthread -m64
CNF_CFLAGS=-pthread
#CNF_CXXFLAGS=-std=c++11 -pthread -m64
CNF_CXXFLAGS=-std=c++11 -pthread
保存退出,继续编译。
make
make install
查看编译出来的库文件:
root@ubuntu:/neo/arm/openssl/openssl/__install/lib# file *
engines-3: directory
libcrypto.a: current ar archive
libcrypto.so: symbolic link to `libcrypto.so.3'
libcrypto.so.3: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
libssl.a: current ar archive
libssl.so: symbolic link to `libssl.so.3'
libssl.so.3: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, not stripped
pkgconfig: directory
root@ubuntu:/neo/arm/openssl/openssl/__install/lib#
是ARM架构下的。
把库文件和头文件拷贝到交叉编译链的对应目录下。
root@ubuntu:/neo/arm/openssl/openssl/__install# cp -af ./lib/* /opt/hisi-linux/x86-arm/aarch64-himix100-linux/target/usr/lib
root@ubuntu:/neo/arm/openssl/openssl/__install# cp -af ./include/* /opt/hisi-linux/x86-arm/aarch64-himix100-linux/target/usr/include/
交叉编译Wget:
wget https://ftp.gnu.org/gnu/wget/wget-1.20.1.tar.gz
tar -vxf wget-1.20.1.tar.gz
cd wget-1.20.1/
mkdir __install
./configure --prefix=$PWD/__install --host=arm-linux CC=aarch64-himix100-linux-gcc --without-zlib --with-ssl=openssl
make
make install
查看编译出来的二进制文件:
root@ubuntu:/neo/arm/wget/wget-1.20.1/__install/bin# file *
wget: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.7.0, not stripped
root@ubuntu:/neo/arm/wget/wget-1.20.1/__install/bin#
是ARM架构下的。
运行测试:
下面在板子上运行测试一下。确定是否可以解析https链接。
之前交叉编译的结果:
/mnt/test # wget https://www.baidu.com/?tn=44004473_1_oem_dg
https://www.baidu.com/?tn=44004473_1_oem_dg: HTTPS support not compiled in.
/mnt/test #
刚才交叉编译出来的结果:
/mnt/test # ./wget https://www.baidu.com/?tn=44004473_1_oem_dg
./wget: error while loading shared libraries: libssl.so.3: cannot open shared object file: No such file or directory
/mnt/test #
需要把交叉编译出来的库文件拷贝到板子上。
openssl -> nfs:
root@ubuntu:/neo/arm/openssl/openssl/__install/lib# ls
engines-3 libcrypto.a libcrypto.so libcrypto.so.3 libssl.a libssl.so libssl.so.3 pkgconfig
root@ubuntu:/neo/arm/openssl/openssl/__install/lib# cp -af * /nfs/lib/
nfs -> /usr/lib:
/mnt/test/lib # ls -l
total 8740
drwxr-xr-x 2 root root 4096 Jan 19 11:35 engines-3
-rw-r--r-- 1 root root 4732418 Jan 19 11:35 libcrypto.a
lrwxrwxrwx 1 root root 14 Jan 19 11:35 libcrypto.so -> libcrypto.so.3
-rwxr-xr-x 1 root root 2674128 Jan 19 11:35 libcrypto.so.3
-rw-r--r-- 1 root root 919258 Jan 19 11:35 libssl.a
lrwxrwxrwx 1 root root 11 Jan 19 11:35 libssl.so -> libssl.so.3
-rwxr-xr-x 1 root root 608504 Jan 19 11:35 libssl.so.3
drwxr-xr-x 2 root root 4096 Jan 19 11:35 pkgconfig
/mnt/test/lib # cp -af * /usr/lib/
/mnt/test/lib #
报错:
报错1:
/mnt/test # ./wget https://dwz.cn/Apvd6brX
--2019-01-19 14:39:02-- https://dwz.cn/Apvd6brX
Disabling SSL due to encountered errors.
/mnt/test #
如果有上述报错,应该是openssl下载的不对,需要重新下载openslsl,重新生成库,编译出wget文件。
经测试,如下两个有上述问题:
1、
git clone https://github.com/openssl/openssl.git
下载下来有300M左右。
2、
wget https://codeload.github.com/openssl/openssl/zip/master
下载下来有8.2M。
可以使用的:
wget https://www.openssl.org/source/openssl-1.1.1a.tar.gz
报错2:
/mnt/test # ./wget https://www.baidu.com/?tn=44004473_1_oem_dg
--2019-01-19 16:06:18-- https://www.baidu.com/?tn=44004473_1_oem_dg
Resolving www.baidu.com... 14.215.177.39, 14.215.177.38
Connecting to www.baidu.com|14.215.177.39|:443... connected.
ERROR: cannot verify www.baidu.com's certificate, issued by 'CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE':
Unable to locally verify the issuer's authority.
To connect to www.baidu.com insecurely, use `--no-check-certificate'.
需要在运行wget时,加上参数"–no-check-certificate":(不检查证书)
/mnt/test # ./wget https://www.baidu.com/?tn=44004473_1_oem_dg --no-check-certificate
--2019-01-19 16:07:46-- https://www.baidu.com/?tn=44004473_1_oem_dg
Resolving www.baidu.com... 14.215.177.39, 14.215.177.38
Connecting to www.baidu.com|14.215.177.39|:443... connected.
WARNING: cannot verify www.baidu.com's certificate, issued by 'CN=GlobalSign Organization Validation CA - SHA256 - G2,O=GlobalSign nv-sa,C=BE':
Unable to locally verify the issuer's authority.
HTTP request sent, awaiting response... 200 OK
Length: 2443 (2.4K) [text/html]
Saving to: 'index.html?tn=44004473_1_oem_dg'
index.html?tn=44004473_1_oem_dg 100%[===================================================================================================================>] 2.39K --.-KB/s in 0s
2019-01-19 16:07:46 (327 MB/s) - 'index.html?tn=44004473_1_oem_dg' saved [2443/2443]
/mnt/test #
完成。
参考链接:
https://blog.csdn.net/u013401853/article/details/60875306