certificate processing functions stubs
authorMarcel Poul <marcel.poul@cern.ch>
Wed, 30 Nov 2011 22:54:27 +0000 (22:54 +0000)
committerMarcel Poul <marcel.poul@cern.ch>
Wed, 30 Nov 2011 22:54:27 +0000 (22:54 +0000)
emi.canl.canl-c/Makefile
emi.canl.canl-c/src/canl.c
emi.canl.canl-c/src/canl.h
emi.canl.canl-c/src/canl_err.c
emi.canl.canl-c/src/canl_locl.h

index 50024cd..3efd510 100644 (file)
@@ -25,7 +25,7 @@ LFLAGS_CLI=-L. -lcanl
 CFLAGS_SER=-Wall -g -I${top_srcdir}/src
 LFLAGS_SER=-L. -lcanl
 
-HEAD_CANL=canl.h canl_locl.h
+HEAD_CANL=canl.h canl_locl.h canl_err.h
 
 SRC_CLI=canl_sample_client.c
 HEAD_CLI=canl.h
@@ -51,21 +51,24 @@ major:=${shell \
 
 all: libcanl.la server client
 
-libcanl.la: canl.lo canl_err.lo canl_dns.lo canl_ssl.lo
+libcanl.la: canl.lo canl_err.lo canl_dns.lo canl_ssl.lo canl_cert.lo
        ${LINK} -rpath ${stagedir}${prefix}/${libdir} ${version_info} $+ ${LFLAGS_LIB} -o $@
 
-canl.lo: canl.c ${HEAD_CANL} canl_err.h
+canl.lo: canl.c ${HEAD_CANL} 
        ${COMPILE} -c ${top_srcdir}/src/canl.c ${CFLAGS_LIB} -o $@
 
-canl_dns.lo: canl_dns.c ${HEAD_CANL}
+canl_dns.lo: canl_dns.c ${HEAD_CANL} 
        ${COMPILE} -c ${top_srcdir}/src/canl_dns.c ${CFLAGS_LIB} -o $@
 
-canl_err.lo: canl_err.c ${HEAD_CANL}
+canl_err.lo: canl_err.c ${HEAD_CANL} 
        ${COMPILE} -c ${top_srcdir}/src/canl_err.c ${CFLAGS_LIB} -o $@
 
 canl_ssl.lo: canl_ssl.c ${HEAD_CANL}
        ${COMPILE} -c ${top_srcdir}/src/canl_ssl.c ${CFLAGS_LIB} -o $@
 
+canl_cert.lo: canl_cert.c ${HEAD_CANL}
+       ${COMPILE} -c ${top_srcdir}/src/canl_cert.c ${CFLAGS_LIB} -o $@
+
 client: ${OBJ_CLI}
        ${LINK} $< ${LFLAGS_CLI} -o $@
 
index 83fe282..42dc539 100644 (file)
@@ -2,7 +2,6 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <arpa/inet.h>
-#include "canl.h"
 #include "canl_locl.h"
 #include "sys/socket.h"
 #include "string.h"
@@ -498,8 +497,34 @@ size_t canl_io_write(canl_ctx cc, canl_io_handler io, void *buffer, size_t size,
     }
 
 end:
-    if (err)
+    if (err) {
         update_error(glb_cc, "can't write to connection"
                 " (canl_io_write)");
+        return -1;
+    }
     return b_written;
 }
+
+int canl_set_ctx_own_cert(canl_ctx cc, canl_x509 cert, 
+        canl_stack_of_x509 chain, canl_pkey key)
+{
+    glb_ctx *glb_cc = (glb_ctx*) cc;
+    int err = 0;
+
+    if (!cc)
+        return EINVAL;
+    if(!cert || !key) {
+        err = EINVAL;
+        set_error(glb_cc, err, posix_error, "invalid parameter value"
+               " (canl_set_ctx_own_cert)");
+        return err;
+    }
+
+    do_set_ctx_own_cert(glb_cc, cert, chain, key);
+
+    if(err) {
+        update_error(glb_cc, "can't set cert or key to context"
+                " (canl_set_ctx_own_cert)");
+    }
+        return err;
+}
index aa8cfd8..055a583 100644 (file)
@@ -7,6 +7,10 @@ typedef void *canl_io_handler;
 typedef void *canl_ctx;
 typedef void *cred_handler;
 
+typedef void *canl_x509;
+typedef void *canl_stack_of_x509;
+typedef void *canl_pkey;
+
 canl_ctx canl_create_ctx();
 void canl_free_ctx(canl_ctx cc);
 canl_io_handler canl_create_io_handler(canl_ctx cc);
@@ -22,4 +26,7 @@ int canl_get_error(canl_ctx cc, char ** reason);
 int canl_io_close(canl_ctx cc, canl_io_handler io);
 int canl_io_destroy(canl_ctx cc, canl_io_handler io);
 
+int canl_set_ctx_own_cert(canl_ctx cc, canl_x509 cert,
+        canl_stack_of_x509 chain, canl_pkey key);
+
 #endif
index fba5566..ef9cdf7 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
-#include "canl.h"
 #include "canl_locl.h"
 
 static int resolve_error(glb_ctx *cc, CANL_ERROR err_code, 
index 10d28c7..3800236 100644 (file)
@@ -1,20 +1,33 @@
-#ifndef CANL_LOCL_H
-#define CANL_LOCL_H
+#ifndef _CANL_LOCL_H
+#define _CANL_LOCL_H
+
 #include <errno.h>
 #include "canl_err.h"
+#include "canl.h"
 #include <ares.h>
 #include <ares_version.h>
 #include <netdb.h>
 #include <openssl/ssl.h>
+#include <openssl/x509.h>
+#include <openssl/x509v3.h>
+#include <openssl/evp.h>
+#include <openssl/err.h>
+#include <openssl/safestack.h>
 #include <unistd.h>
 #include <fcntl.h>
 
+typedef struct _cert_key_store {
+    X509 *cert;
+    EVP_PKEY *key;
+} cert_key_store;
+
 typedef struct _glb_ctx
 {
     int opened_ios;
     char * err_msg;
     CANL_ERROR err_code;
     CANL_ERROR_ORIGIN err_orig;
+    cert_key_store *cert_key;
 } glb_ctx;
 
 typedef struct _ossl_ctx
@@ -54,4 +67,6 @@ int ssl_read(glb_ctx *cc, io_handler *io, void *buffer, size_t size,
 int ssl_write(glb_ctx *cc, io_handler *io, void *buffer, size_t size, 
         struct timeval *tout);
 
+int do_set_ctx_own_cert(glb_ctx *cc, canl_x509 cert, canl_stack_of_x509 chain, 
+        canl_pkey key);
 #endif