aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/libcharon/Makefile.am2
-rw-r--r--src/libcharon/sa/ike_sa.c7
-rw-r--r--src/libcharon/sa/keymat.c33
-rw-r--r--src/libcharon/sa/keymat.h14
4 files changed, 50 insertions, 6 deletions
diff --git a/src/libcharon/Makefile.am b/src/libcharon/Makefile.am
index c4ba18c5f..5defff677 100644
--- a/src/libcharon/Makefile.am
+++ b/src/libcharon/Makefile.am
@@ -69,7 +69,7 @@ sa/ike_sa_id.c sa/ike_sa_id.h \
sa/ike_sa_manager.c sa/ike_sa_manager.h \
sa/task_manager.h sa/task_manager_v2.c sa/task_manager_v2.h \
sa/task_manager_v1.c sa/task_manager_v1.h \
-sa/keymat.h sa/keymat_v2.c sa/keymat_v2.h \
+sa/keymat.h sa/keymat.c sa/keymat_v2.c sa/keymat_v2.h \
sa/keymat_v1.c sa/keymat_v1.h \
sa/shunt_manager.c sa/shunt_manager.h \
sa/trap_manager.c sa/trap_manager.h \
diff --git a/src/libcharon/sa/ike_sa.c b/src/libcharon/sa/ike_sa.c
index b59586b8a..e060c5a42 100644
--- a/src/libcharon/sa/ike_sa.c
+++ b/src/libcharon/sa/ike_sa.c
@@ -28,7 +28,6 @@
#include <daemon.h>
#include <utils/linked_list.h>
#include <utils/lexparser.h>
-#include <sa/keymat_v2.h>
#include <sa/task_manager_v2.h>
#include <sa/tasks/ike_init.h>
#include <sa/tasks/ike_natd.h>
@@ -719,7 +718,8 @@ METHOD(ike_sa_t, reset, void,
flush_auth_cfgs(this);
this->keymat->destroy(this->keymat);
- this->keymat = &(keymat_v2_create(this->ike_sa_id->is_initiator(this->ike_sa_id))->keymat);
+ this->keymat = keymat_create(this->version,
+ this->ike_sa_id->is_initiator(this->ike_sa_id));
this->task_manager->reset(this->task_manager, 0, 0);
}
@@ -2210,6 +2210,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, ike_version_t version)
.other_host = host_create_any(AF_INET),
.my_id = identification_create_from_encoding(ID_ANY, chunk_empty),
.other_id = identification_create_from_encoding(ID_ANY, chunk_empty),
+ .keymat = keymat_create(version, ike_sa_id->is_initiator(ike_sa_id)),
.state = IKE_CREATED,
.stats[STAT_INBOUND] = time_monotonic(NULL),
.stats[STAT_OUTBOUND] = time_monotonic(NULL),
@@ -2223,7 +2224,7 @@ ike_sa_t * ike_sa_create(ike_sa_id_t *ike_sa_id, ike_version_t version)
.keepalive_interval = lib->settings->get_time(lib->settings,
"charon.keep_alive", KEEPALIVE_INTERVAL),
);
- this->keymat = &(keymat_v2_create(ike_sa_id->is_initiator(ike_sa_id))->keymat);
+
this->task_manager = &(task_manager_v2_create(&this->public)->task_manager);
this->my_host->set_port(this->my_host, IKEV2_UDP_PORT);
diff --git a/src/libcharon/sa/keymat.c b/src/libcharon/sa/keymat.c
new file mode 100644
index 000000000..7b5c95c1a
--- /dev/null
+++ b/src/libcharon/sa/keymat.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2011 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
+ * 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; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include "keymat.h"
+#include "keymat_v1.h"
+#include "keymat_v2.h"
+
+/**
+ * See header
+ */
+keymat_t *keymat_create(ike_version_t version, bool initiator)
+{
+ switch (version)
+ {
+ case IKEV1:
+ return &keymat_v1_create(initiator)->keymat;
+ case IKEV2:
+ return &keymat_v2_create(initiator)->keymat;
+ }
+ return NULL;
+}
diff --git a/src/libcharon/sa/keymat.h b/src/libcharon/sa/keymat.h
index c50d93322..7867898c1 100644
--- a/src/libcharon/sa/keymat.h
+++ b/src/libcharon/sa/keymat.h
@@ -21,15 +21,16 @@
#ifndef KEYMAT_H_
#define KEYMAT_H_
+typedef struct keymat_t keymat_t;
+
#include <library.h>
#include <utils/identification.h>
#include <crypto/prfs/prf.h>
#include <crypto/aead.h>
#include <config/proposal.h>
+#include <config/peer_cfg.h> /* for ike_version_t */
#include <sa/ike_sa_id.h>
-typedef struct keymat_t keymat_t;
-
/**
* Derivation an management of sensitive keying material.
*/
@@ -147,4 +148,13 @@ struct keymat_t {
void (*destroy)(keymat_t *this);
};
+/**
+ * Create the appropriate keymat_t implementation based on the IKE version.
+ *
+ * @param version requested IKE version
+ * @param initiator TRUE if we are initiator
+ * @return keymat_t implmenetation
+ */
+keymat_t *keymat_create(ike_version_t version, bool initiator);
+
#endif /** KEYMAT_H_ @}*/