More SSL work

This commit is contained in:
Łukasz Magiera 2016-02-12 21:06:56 +01:00
parent 462138cb94
commit 29f1c6998c
4 changed files with 22 additions and 7 deletions

View File

@ -13,9 +13,9 @@ SOURCE = src/c
CORELUA = src/lua/core CORELUA = src/lua/core
RESOURCES = resources RESOURCES = resources
LIBS=-lm -lcrypto -lssl LIBS=-lm -lssl -lcrypto
INCLUDES=-I$(SOURCE) -Isrc/c/lib/lua -Iinclude INCLUDES=-I$(SOURCE) -Isrc/c/lib/lua -Iinclude -Idependencies/include -Idependencies/include-$(PREFIX)
GENERATED=include/luares.h src/c/gen/luares.c include/res.h src/c/gen/res.c GENERATED=include/luares.h src/c/gen/luares.c include/res.h src/c/gen/res.c
LUAPARAMS = $(CORELUA) include/luares.h src/c/gen/luares.c lua_ LUAPARAMS = $(CORELUA) include/luares.h src/c/gen/luares.c lua_

View File

@ -7,7 +7,7 @@ OUT=$TOOL
if [ $# -lt 1 ] if [ $# -lt 1 ]
then then
echo "Usage : $0 [arm32-musl|x86_64|x86_64-musl]" echo "Usage : $0 [arm32-musl|x86_64|musl]"
exit exit
fi fi
@ -32,6 +32,8 @@ case "$1" in
esac esac
mkdir -p dependencies mkdir -p dependencies
mkdir -p dependencies/include
mkdir -p dependencies/include-$OUT
rm -rf dependencies/lib-$OUT rm -rf dependencies/lib-$OUT
mkdir -p dependencies/lib-$OUT mkdir -p dependencies/lib-$OUT
@ -45,9 +47,13 @@ cd ..
rm -rf openssl-build rm -rf openssl-build
mkdir openssl-build mkdir openssl-build
cd openssl-build cd openssl-build
../openssl/Configure $OPENSSL_TARGET --unified no-asm -DOPENSSL_NO_HEARTBEATS --openssldir=$(cd ../lib-$OUT; pwd) no-shared ../openssl/Configure $OPENSSL_TARGET --unified no-asm -DOPENSSL_NO_HEARTBEATS --openssldir=$(cd ../lib-$OUT; pwd) no-shared no-threads no-dso
make libcrypto.a -j8 CC=$TOOL-gcc RANLIB=$TOOL-ranlib LD=$TOOL-ld MAKEDEPPROG=$TOOL-gcc PROCESSOR=ARM make libcrypto.a -j8 CC=$TOOL-gcc RANLIB=$TOOL-ranlib LD=$TOOL-ld MAKEDEPPROG=$TOOL-gcc PROCESSOR=ARM
make libssl.a -j8 CC=$TOOL-gcc RANLIB=$TOOL-ranlib LD=$TOOL-ld MAKEDEPPROG=$TOOL-gcc PROCESSOR=ARM make libssl.a -j8 CC=$TOOL-gcc RANLIB=$TOOL-ranlib LD=$TOOL-ld MAKEDEPPROG=$TOOL-gcc PROCESSOR=ARM
cp libcrypto.a ../lib-$OUT mkdir -p ../include/openssl
cp libssl.a ../lib-$OUT mkdir -p ../include-$OUT/openssl
cp -rfv ../openssl/include/openssl/* ../include/openssl
cp -rfv include/openssl/* ../include-$OUT/openssl
cp -rfv libcrypto.a ../lib-$OUT
cp -rfv libssl.a ../lib-$OUT

View File

@ -16,6 +16,8 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <openssl/ssl.h>
#include <openssl/conf.h>
static int l_open(lua_State *L) { //TODO: Any mem leaks? static int l_open(lua_State *L) { //TODO: Any mem leaks?
const char* hostaddr = lua_tostring(L, 1); const char* hostaddr = lua_tostring(L, 1);
@ -109,7 +111,14 @@ static int l_read(lua_State *L) {
return 1; return 1;
} }
static void ssl_init() {
(void)SSL_library_init();
SSL_load_error_strings();
OPENSSL_config(NULL);
}
void internet_start(lua_State *L) { void internet_start(lua_State *L) {
ssl_init();
signal(SIGPIPE, SIG_IGN); signal(SIGPIPE, SIG_IGN);
lua_createtable (L, 0, 1); lua_createtable (L, 0, 1);

View File

@ -63,7 +63,7 @@ function internet.start()
function component.request(url, post) function component.request(url, post)
checkArg(1, url, "string") checkArg(1, url, "string")
checkArg(2, post, "string", "nil") checkArg(2, post, "string", "nil")
local host, uri = url:match("http://([^/]+)([^#]+)") local host, uri = url:match("https?://([^/]+)([^#]+)")
if not host then native.log("internet.request host match error: " .. url .. "\n") end if not host then native.log("internet.request host match error: " .. url .. "\n") end
local socket = component.connect(host, 80) local socket = component.connect(host, 80)
if socket.finishConnect() then if socket.finishConnect() then