Moving OpenSSL support to a separate folder (should fix embedded builds)
This commit is contained in:
parent
2167d39890
commit
6f5a991d81
1
Makefile
1
Makefile
|
@ -52,7 +52,6 @@ dist:
|
||||||
$(PACKAGE)-$(VERSION)/src/apptransport.h \
|
$(PACKAGE)-$(VERSION)/src/apptransport.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/common.h \
|
$(PACKAGE)-$(VERSION)/src/common.h \
|
||||||
$(PACKAGE)-$(VERSION)/src/project.conf \
|
$(PACKAGE)-$(VERSION)/src/project.conf \
|
||||||
$(PACKAGE)-$(VERSION)/src/transport/openssl.c \
|
|
||||||
$(PACKAGE)-$(VERSION)/src/transport/tcp.c \
|
$(PACKAGE)-$(VERSION)/src/transport/tcp.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/transport/udp.c \
|
$(PACKAGE)-$(VERSION)/src/transport/udp.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/transport/project.conf \
|
$(PACKAGE)-$(VERSION)/src/transport/project.conf \
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
prefix=@PREFIX@
|
prefix=@PREFIX@
|
||||||
includedir=${prefix}/include
|
includedir=${prefix}/include/System
|
||||||
exec_prefix=${prefix}
|
exec_prefix=${prefix}
|
||||||
libdir=${exec_prefix}/lib
|
libdir=${exec_prefix}/lib
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
TARGETS = openssl.so tcp.so udp.so
|
TARGETS = tcp.so udp.so
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
DESTDIR =
|
DESTDIR =
|
||||||
LIBDIR = $(PREFIX)/lib
|
LIBDIR = $(PREFIX)/lib
|
||||||
|
@ -18,13 +18,6 @@ INSTALL ?= install
|
||||||
|
|
||||||
all: $(TARGETS)
|
all: $(TARGETS)
|
||||||
|
|
||||||
openssl_OBJS = openssl.o
|
|
||||||
openssl_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
|
||||||
openssl_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
|
||||||
|
|
||||||
openssl.so: $(openssl_OBJS)
|
|
||||||
$(CCSHARED) -o openssl.so $(openssl_OBJS) $(openssl_LDFLAGS)
|
|
||||||
|
|
||||||
tcp_OBJS = tcp.o
|
tcp_OBJS = tcp.o
|
||||||
tcp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
tcp_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
|
||||||
tcp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
tcp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
|
@ -39,9 +32,6 @@ udp_LDFLAGS = $(LDFLAGSF) $(LDFLAGS)
|
||||||
udp.so: $(udp_OBJS)
|
udp.so: $(udp_OBJS)
|
||||||
$(CCSHARED) -o udp.so $(udp_OBJS) $(udp_LDFLAGS)
|
$(CCSHARED) -o udp.so $(udp_OBJS) $(udp_LDFLAGS)
|
||||||
|
|
||||||
openssl.o: openssl.c ../../config.h
|
|
||||||
$(CC) $(openssl_CFLAGS) -c openssl.c
|
|
||||||
|
|
||||||
tcp.o: tcp.c
|
tcp.o: tcp.c
|
||||||
$(CC) $(tcp_CFLAGS) -c tcp.c
|
$(CC) $(tcp_CFLAGS) -c tcp.c
|
||||||
|
|
||||||
|
@ -49,21 +39,18 @@ udp.o: udp.c
|
||||||
$(CC) $(udp_CFLAGS) -c udp.c
|
$(CC) $(udp_CFLAGS) -c udp.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -- $(openssl_OBJS) $(tcp_OBJS) $(udp_OBJS)
|
$(RM) -- $(tcp_OBJS) $(udp_OBJS)
|
||||||
|
|
||||||
distclean: clean
|
distclean: clean
|
||||||
$(RM) -- $(TARGETS)
|
$(RM) -- $(TARGETS)
|
||||||
|
|
||||||
install: $(TARGETS)
|
install: $(TARGETS)
|
||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/App/transport
|
|
||||||
$(INSTALL) -m 0644 -- openssl.so $(DESTDIR)$(LIBDIR)/App/transport/openssl.so
|
|
||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/App/transport
|
$(MKDIR) $(DESTDIR)$(LIBDIR)/App/transport
|
||||||
$(INSTALL) -m 0644 -- tcp.so $(DESTDIR)$(LIBDIR)/App/transport/tcp.so
|
$(INSTALL) -m 0644 -- tcp.so $(DESTDIR)$(LIBDIR)/App/transport/tcp.so
|
||||||
$(MKDIR) $(DESTDIR)$(LIBDIR)/App/transport
|
$(MKDIR) $(DESTDIR)$(LIBDIR)/App/transport
|
||||||
$(INSTALL) -m 0644 -- udp.so $(DESTDIR)$(LIBDIR)/App/transport/udp.so
|
$(INSTALL) -m 0644 -- udp.so $(DESTDIR)$(LIBDIR)/App/transport/udp.so
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/App/transport/openssl.so
|
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/App/transport/tcp.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/App/transport/tcp.so
|
||||||
$(RM) -- $(DESTDIR)$(LIBDIR)/App/transport/udp.so
|
$(RM) -- $(DESTDIR)$(LIBDIR)/App/transport/udp.so
|
||||||
|
|
||||||
|
|
|
@ -1,209 +0,0 @@
|
||||||
/* $Id$ */
|
|
||||||
/* Copyright (c) 2012 Pierre Pronchery <khorben@defora.org> */
|
|
||||||
/* This file is part of DeforaOS System libApp */
|
|
||||||
/* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, version 3 of the License.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <errno.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <System.h>
|
|
||||||
#include <openssl/ssl.h>
|
|
||||||
#include <openssl/err.h>
|
|
||||||
#include "App/apptransport.h"
|
|
||||||
#include "../../config.h"
|
|
||||||
|
|
||||||
#ifndef PREFIX
|
|
||||||
# define PREFIX "/usr/local"
|
|
||||||
#endif
|
|
||||||
#ifndef SYSCONFDIR
|
|
||||||
# define SYSCONFDIR PREFIX "/etc"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* OpenSSL */
|
|
||||||
/* private */
|
|
||||||
/* types */
|
|
||||||
typedef struct _AppTransportPlugin OpenSSL;
|
|
||||||
|
|
||||||
struct _AppTransportPlugin
|
|
||||||
{
|
|
||||||
AppTransportPluginHelper * helper;
|
|
||||||
int fd;
|
|
||||||
SSL_CTX * ssl_ctx;
|
|
||||||
/* client */
|
|
||||||
SSL * ssl;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* protected */
|
|
||||||
/* prototypes */
|
|
||||||
/* plug-in */
|
|
||||||
static OpenSSL * _openssl_init(AppTransportPluginHelper * helper,
|
|
||||||
AppTransportMode mode, char const * name);
|
|
||||||
static void _openssl_destroy(OpenSSL * openssl);
|
|
||||||
|
|
||||||
|
|
||||||
/* private */
|
|
||||||
/* prototypes */
|
|
||||||
static int _openssl_error(char const * message, int code);
|
|
||||||
static int _openssl_error_ssl(int code);
|
|
||||||
|
|
||||||
/* callbacks */
|
|
||||||
static int _openssl_callback_accept(int fd, OpenSSL * openssl);
|
|
||||||
|
|
||||||
|
|
||||||
/* public */
|
|
||||||
/* constants */
|
|
||||||
/* plug-in */
|
|
||||||
AppTransportPluginDefinition definition =
|
|
||||||
{
|
|
||||||
"OpenSSL",
|
|
||||||
NULL,
|
|
||||||
_openssl_init,
|
|
||||||
_openssl_destroy,
|
|
||||||
NULL
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* protected */
|
|
||||||
/* functions */
|
|
||||||
/* plug-in */
|
|
||||||
/* openssl_init */
|
|
||||||
static int _init_client(OpenSSL * openssl, char const * name);
|
|
||||||
static int _init_server(OpenSSL * openssl, char const * name);
|
|
||||||
|
|
||||||
static OpenSSL * _openssl_init(AppTransportPluginHelper * helper,
|
|
||||||
AppTransportMode mode, char const * name)
|
|
||||||
{
|
|
||||||
OpenSSL * openssl;
|
|
||||||
int res = -1;
|
|
||||||
|
|
||||||
if((openssl = object_new(sizeof(*openssl))) == NULL)
|
|
||||||
return NULL;
|
|
||||||
openssl->helper = helper;
|
|
||||||
openssl->fd = -1;
|
|
||||||
openssl->ssl_ctx = NULL;
|
|
||||||
openssl->ssl = NULL;
|
|
||||||
switch(mode)
|
|
||||||
{
|
|
||||||
case ATM_CLIENT:
|
|
||||||
res = _init_client(openssl, name);
|
|
||||||
break;
|
|
||||||
case ATM_SERVER:
|
|
||||||
res = _init_server(openssl, name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
/* check for errors */
|
|
||||||
if(res != 0)
|
|
||||||
{
|
|
||||||
_openssl_destroy(openssl);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return openssl;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _init_client(OpenSSL * openssl, char const * name)
|
|
||||||
{
|
|
||||||
if((openssl->ssl_ctx = SSL_CTX_new(SSLv3_client_method())) == NULL
|
|
||||||
|| SSL_CTX_set_cipher_list(openssl->ssl_ctx,
|
|
||||||
SSL_DEFAULT_CIPHER_LIST) != 1
|
|
||||||
|| (openssl->ssl = SSL_new(openssl->ssl_ctx)) == NULL)
|
|
||||||
return -_openssl_error_ssl(1);
|
|
||||||
if((openssl->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
|
||||||
return -_openssl_error("socket", 1);
|
|
||||||
/* FIXME implement the rest */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int _init_server(OpenSSL * openssl, char const * name)
|
|
||||||
{
|
|
||||||
String * crt;
|
|
||||||
struct sockaddr_in sa;
|
|
||||||
|
|
||||||
if((crt = string_new_append(SYSCONFDIR, "/AppServer/", name, ".crt"))
|
|
||||||
== NULL)
|
|
||||||
return -1;
|
|
||||||
if((openssl->ssl_ctx = SSL_CTX_new(SSLv3_server_method())) == NULL
|
|
||||||
|| SSL_CTX_set_cipher_list(openssl->ssl_ctx,
|
|
||||||
SSL_DEFAULT_CIPHER_LIST) != 1
|
|
||||||
|| SSL_CTX_use_certificate_file(openssl->ssl_ctx, crt,
|
|
||||||
SSL_FILETYPE_PEM) == 0
|
|
||||||
|| SSL_CTX_use_PrivateKey_file(openssl->ssl_ctx, crt,
|
|
||||||
SSL_FILETYPE_PEM) == 0)
|
|
||||||
{
|
|
||||||
string_delete(crt);
|
|
||||||
return -_openssl_error_ssl(1);
|
|
||||||
}
|
|
||||||
string_delete(crt);
|
|
||||||
if((openssl->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
|
||||||
return -_openssl_error("socket", 1);
|
|
||||||
sa.sin_family = AF_INET;
|
|
||||||
sa.sin_port = htons(4242); /* XXX hard-coded */
|
|
||||||
sa.sin_addr.s_addr = htonl(INADDR_ANY);
|
|
||||||
if(bind(openssl->fd, (struct sockaddr *)&sa, sizeof(sa)) != 0)
|
|
||||||
return -_openssl_error("bind", 1);
|
|
||||||
if(listen(openssl->fd, 5) != 0)
|
|
||||||
return -_openssl_error("listen", 1);
|
|
||||||
event_register_io_read(openssl->helper->event, openssl->fd,
|
|
||||||
(EventIOFunc)_openssl_callback_accept, openssl);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* openssl_destroy */
|
|
||||||
static void _openssl_destroy(OpenSSL * openssl)
|
|
||||||
{
|
|
||||||
if(openssl->ssl != NULL)
|
|
||||||
SSL_free(openssl->ssl);
|
|
||||||
if(openssl->fd != -1)
|
|
||||||
close(openssl->fd);
|
|
||||||
if(openssl->ssl_ctx != NULL)
|
|
||||||
SSL_CTX_free(openssl->ssl_ctx);
|
|
||||||
object_delete(openssl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* private */
|
|
||||||
/* functions */
|
|
||||||
/* openssl_error */
|
|
||||||
static int _openssl_error(char const * message, int code)
|
|
||||||
{
|
|
||||||
return error_set_code(code, "%s%s%s", (message != NULL) ? message : "",
|
|
||||||
(message != NULL) ? ": " : "", strerror(errno));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* openssl_error_ssl */
|
|
||||||
static int _openssl_error_ssl(int code)
|
|
||||||
{
|
|
||||||
return error_set_code(code, "%s", ERR_error_string(ERR_get_error(),
|
|
||||||
NULL));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* callbacks */
|
|
||||||
static int _openssl_callback_accept(int fd, OpenSSL * openssl)
|
|
||||||
{
|
|
||||||
struct sockaddr_in sa;
|
|
||||||
socklen_t sa_size = sizeof(sa);
|
|
||||||
int newfd;
|
|
||||||
|
|
||||||
if((newfd = accept(fd, (struct sockaddr *)&sa, &sa_size)) < 0)
|
|
||||||
return error_set_code(1, "%s%s", "accept: ", strerror(errno));
|
|
||||||
/* FIXME really implement */
|
|
||||||
close(newfd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,16 +1,8 @@
|
||||||
targets=openssl,tcp,udp
|
targets=tcp,udp
|
||||||
cppflags=-I ../../include
|
cppflags=-I ../../include
|
||||||
cflags_force=-W
|
cflags_force=-W
|
||||||
cflags=-Wall -g -O2 -pedantic -fPIC
|
cflags=-Wall -g -O2 -pedantic -fPIC
|
||||||
|
|
||||||
[openssl]
|
|
||||||
type=plugin
|
|
||||||
sources=openssl.c
|
|
||||||
install=$(LIBDIR)/App/transport
|
|
||||||
|
|
||||||
[openssl.c]
|
|
||||||
depends=../../config.h
|
|
||||||
|
|
||||||
[tcp]
|
[tcp]
|
||||||
type=plugin
|
type=plugin
|
||||||
sources=tcp.c
|
sources=tcp.c
|
||||||
|
|
Loading…
Reference in New Issue
Block a user