VPATH=${top_srcdir}/src
LIBCARES_LIBS?=-lcares
+LIBSSL_LIBS?=-lssl
CC=gcc
COMPILE=libtool --mode=compile ${CC} ${CFLAGS}
LINK=libtool --mode=link ${CC} ${LDFLAGS}
INSTALL=libtool --mode=install install
-CFLAGS_LIB=-Wall -fPIC -c -g -I${top_srcdir}/src ${LIBCARES_CFLAGS}
-LFLAGS_LIB=-shared ${LIBCARES_LIBS}
+CFLAGS_LIB=-Wall -fPIC -c -g -I${top_srcdir}/src ${LIBCARES_CFLAGS} ${LIBSSL_CFLAGS}
+LFLAGS_LIB=-shared ${LIBCARES_LIBS} ${LIBSSL_LIBS}
CFLAGS_CLI=-Wall -g -I${top_srcdir}/src
LFLAGS_CLI=-L. -lcanl
all: libcanl.la server client
-libcanl.la: canl.lo canl_err.lo canl_dns.lo
+libcanl.la: canl.lo canl_err.lo canl_dns.lo canl_ssl.lo
${LINK} -rpath ${stagedir}${prefix}/${libdir} ${version_info} $+ ${LFLAGS_LIB} -o $@
canl.lo: canl.c ${HEAD_CANL} canl_err.h
canl_err.lo: canl_err.c ${HEAD_CANL}
${COMPILE} -c ${top_srcdir}/src/canl_err.c ${CFLAGS_LIB} -o $@
+canl_ssl.lo: canl_err.c ${HEAD_CANL}
+ ${COMPILE} -c ${top_srcdir}/src/canl_ssl.c ${CFLAGS_LIB} -o $@
+
client: ${OBJ_CLI}
${LINK} $< ${LFLAGS_CLI} -o $@
#include <stdlib.h>
#include <sys/types.h>
#include <arpa/inet.h>
-#include <unistd.h>
#include "canl.h"
#include "canl_locl.h"
#include "sys/socket.h"
goto end;
}
+ io->s_ctx = (ossl_ctx *) calloc(1, sizeof(*(io->s_ctx)));
+ if (!io->s_ctx) {
+ err = ENOMEM;
+ goto end;
+ }
+
end:
if (err)
update_error(cc, err, "failed to initialize io_handler"
int sock;
struct sockaddr_in *sa_in = NULL;
int i = 0;
+ int err_clear = 0;
/*check cc and io*/
if (!glb_cc) {
sa_in->sin_family = AF_INET;
sa_in->sin_port = htons(port);
- //TODO loop through h_addr_list
+
i = 0;
while (io_cc->ar->ent->h_addr_list[i])
{
if (err)
err = errno;
else
- goto end; //success
+ break; //success
i++;
}
- /*TODO Maybe continue with select()*/
/*call openssl */
-
+ err = ssl_init(glb_cc, io_cc);
+ if (err)
+ goto end;
+ err = ssl_connect(glb_cc, io_cc, timeout); //TODO timeout
+
/*write succes or failure to cc, io*/
//if (err)
/*cc or io set error*/
end:
if (err) {
update_error(cc, err, "failed to connect (canl_io_connect)");
- if ((err = io_clear(glb_cc, io_cc)))
+ if ((err_clear = io_clear(glb_cc, io_cc)))
update_error(cc, err, "failed to clean io_handler"
" (canl_io_connect)");
}
#include <ares.h>
#include <ares_version.h>
#include <netdb.h>
+#include <openssl/ssl.h>
+#include <unistd.h>
+#include <fcntl.h>
typedef struct _glb_ctx
{
char * err_msg;
CANL_ERROR err_code;
} glb_ctx;
-/*
- struct ossl_ctx
- {
- SSL_METHOD ssl_meth;
- SSL_CTX ssl_ctx;
- SSL ssl_conn_ctx;
- }
- */
+
+typedef struct _ossl_ctx
+{
+ SSL_CTX *ssl_ctx;
+ SSL_METHOD *ssl_meth;
+ SSL *ssl_io;
+ BIO *bio_conn;
+} ossl_ctx;
+
typedef struct _asyn_result {
struct hostent *ent;
int err;
asyn_result *ar;
struct sockaddr *s_addr;
int sock;
+ ossl_ctx * s_ctx;
} io_handler;
#endif
void free_hostent(struct hostent *h); //TODO is there some standard funcion to free hostent?
int asyn_getservbyname(int a_family, asyn_result *ares_result,char const *name,
struct timeval *timeout);
+int ssl_init(glb_ctx *cc, io_handler *io);
+int ssl_connect(glb_ctx *cc, io_handler *io, struct timeval *timeout);
char *p_server = NULL;
char *def_server = "www.linuxfoundation.org";
int opt, port = 80;
+ struct timeval timeout;
while ((opt = getopt(argc, argv, "hp:s:")) != -1) {
switch (opt) {
goto end;
}
- err = canl_io_connect(my_ctx, my_io_h, p_server, port, 0, NULL, NULL);
+ timeout.tv_sec = 15;
+ timeout.tv_usec = 0;
+
+ err = canl_io_connect(my_ctx, my_io_h, p_server, port, 0, NULL, &timeout);
if (err) {
printf("connection cannot be established\n");
goto end;