charon-tkm: Register TKM private key on startup
authorReto Buerki <reet@codelabs.ch>
Tue, 16 Oct 2012 15:12:51 +0000 (17:12 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 19 Mar 2013 14:23:49 +0000 (15:23 +0100)
src/charon-tkm/src/charon-tkm.c

index 59c3ffa..eac9a27 100644 (file)
@@ -32,6 +32,7 @@
 #include <utils/backtrace.h>
 #include <threading/thread.h>
 #include <sa/keymat.h>
+#include <credentials/sets/mem_cred.h>
 
 #include "tkm.h"
 #include "tkm_nonceg.h"
@@ -40,6 +41,7 @@
 #include "tkm_listener.h"
 #include "tkm_kernel_ipsec.h"
 #include "tkm_public_key.h"
+#include "tkm_private_key.h"
 
 /**
  * TKM bus listener for IKE authorize events.
@@ -238,6 +240,10 @@ int main(int argc, char *argv[])
                dmn_name = "charon-tkm";
        }
 
+       /* credential set and TKM private key */
+       mem_cred_t *creds;
+       tkm_private_key_t *key;
+
        struct sigaction action;
        int status = SS_RC_INITIALIZATION_FAILED;
 
@@ -341,6 +347,12 @@ int main(int argc, char *argv[])
        listener = tkm_listener_create();
        charon->bus->add_listener(charon->bus, &listener->listener);
 
+       /* register TKM private key */
+       creds = mem_cred_create();
+       key = tkm_private_key_init();
+       creds->add_key(creds, (private_key_t *)key);
+       lib->credmgr->add_set(lib->credmgr, (credential_set_t*)creds);
+
        /* add handler for SEGV and ILL,
         * INT and TERM are handled by sigwait() in run() */
        action.sa_handler = segv_handler;
@@ -366,6 +378,7 @@ int main(int argc, char *argv[])
        status = 0;
        charon->bus->remove_listener(charon->bus, &listener->listener);
        listener->destroy(listener);
+       creds->destroy(creds);
 
 deinit:
        libcharon_deinit();