# Cross-compile OpenSSL on ELF 32-bit MSB executable - 請先參考這兩篇 - https://pipi9baby.medium.com/cross-compiler-openssl%E5%9C%A8mips-32%E4%BD%8D%E5%85%83%E7%9A%84%E6%9D%BF%E5%AD%90%E4%B8%8A-3cbfd1f17aa7 - https://pipi9baby.medium.com/%E4%BD%BF%E7%94%A8-buildroot-%E5%BB%BA%E7%AB%8B-mips-cross-compiler-%E7%9A%84%E7%92%B0%E5%A2%83-e63a665b87f2 - 別人編譯好的package(沒試過) https://packages.debian.org/stretch/libssl1.1 - OpenSSL 麻煩的點在要得到 libcryto.a 和 libssl.a 這兩個library,通常情況是去git clone 你要的openssl版本,然後再./config no-shared做設定,接著make,最後再去資料夾裡面撈你要的.h和.a檔就好(新版還需要make install,不然openssl/include底下的.h是symbolic link) - 但是OpenSSL貌似從1.0.0版本後預設就是64位元了,你要用64位元編出來的.a檔弄進32位元的程式編譯器會直接說incompatible - 所以才需要cross-compile成32位元的 - 之後就參考那兩篇做就好,要注意的是那篇是用mipsel-linux去編譯,我要的是Big endian,所以是用mips-linux # 目標 - 在MIPS32 MSB的板子上執行TLS 1.2 server (Kernel version 2.6.0) - 板子上很難直接安裝新版Openssl - 上面有一個2004年版本的Openssl了,要處理環境衝突 - 板子沒多少Disk space可以裝 - 所以打算直接在別台電腦上編譯一個static linking 的 Executable,不用管library,編譯好後就直接燒到板子上就行了 # Step 1 - Setup Toolchain 1. 用BuildRoot來進行cross-compile ```shell= $ wget http://buildroot.uclibc.org/downloads/buildroot-2014.11.tar.gz ``` 這邊選2004年的版本是因為新版貌似編譯出來的執行檔會綁kernel版本,我不確定新版怎麼disable那個選項,所以直接用舊版了 2. 解壓cd進目錄 ```shell= $ apt-get install libncurses-dev $ apt-get install python $ make menuconfig ``` 3. 進入menuconfig選以下 ```shell= Target Architecture (MIPS (big endian)) Target Architecture Variant (mips 32) Toolchain type (Buildroot toolchain) ---> [*] Enable large file (files > 2 GB) support ``` 這邊要看你的目標板子是甚麼系統,不確定的會可以用file指令去看板子上的執行檔,Ex: ```shell= $ file someexe ELF 32-bit MSB executable, MIPS, MIPS64 version 1, dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=b9720b983cafb2a111bbac302b4ead891019e600, not stripped ``` 4. make ```shell= $ make ``` - make完後 ****buildroot-2014.11/output/host/usr**** 底下應該會有一堆執行檔,可以用這些執行檔來編譯了,我這邊主要用****mips-linux-gcc****來編譯程式 5. 把執行檔加入bash command list ```shell= $ vi ~/.bashrc ``` - 加兩行 ```shell= TOOLCHAINDIR=/YOUR/PATH/buildroot-2014.11/output/host/usr export PATH=${TOOLCHAINDIR}/bin:${PATH} ``` - Reload Bash settings ```shell= $ source ~/.bashrc ``` - Check Path ```shell= $ echo $PATH ``` # Step 2 - Build OpenSSL library for the board 1. 用OpenSSL 1.0.1 ```shell= $ wget https://www.openssl.org/source/old/1.0.1/openssl-1.0.1g.tar.gz ``` 這邊選1.0.1的原因是他這版有支援TLS1.2,而且編出來的執行檔差不多在板子容量極限(約1.8M),沒空間限制就選新版ㄅ 2. 解壓cd進目錄,設定config ```shell= $ setarch i386 ./config --prefix=/home/kenny/openssl_mips_toolchain --cross-compile-prefix=mips-linux- shared no-asm ``` i386是因為板子是32位元,prefix路徑就是最後make完那堆.h,.so,.a會在的地方,這邊其實還是加一對no-XX的option來縮小library容量,可以直接vi INSTALL去看有哪些可以設定。(有些版本的INSTALL寫的很偷懶,可以多看不同版本的) 3. make depend if needed 舊版OpenSSL如果有加一些no-XX的option,上一步弄完後會要求你make depend。 ```shell= $ make depend ``` 4. Edit Makefile 把 -m32 從Makefile刪掉 5. make ```shell= $ make $ make install_sw ``` 6. Check library 第2步的prefix path應該會有那些檔案了,可以去那邊找.a,.so,.h了
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up