summaryrefslogtreecommitdiff
path: root/src/charon-tkm/src/tkm/tkm_diffie_hellman.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/charon-tkm/src/tkm/tkm_diffie_hellman.c')
-rw-r--r--src/charon-tkm/src/tkm/tkm_diffie_hellman.c108
1 files changed, 106 insertions, 2 deletions
diff --git a/src/charon-tkm/src/tkm/tkm_diffie_hellman.c b/src/charon-tkm/src/tkm/tkm_diffie_hellman.c
index 19f57de01..a34d0b1d4 100644
--- a/src/charon-tkm/src/tkm/tkm_diffie_hellman.c
+++ b/src/charon-tkm/src/tkm/tkm_diffie_hellman.c
@@ -21,10 +21,13 @@
#include "tkm_utils.h"
#include "tkm_diffie_hellman.h"
-#include <utils/debug.h>
+#include <daemon.h>
+#include <collections/hashtable.h>
typedef struct private_tkm_diffie_hellman_t private_tkm_diffie_hellman_t;
+static hashtable_t *group_map = NULL;
+
/**
* Private data of a tkm_diffie_hellman_t object.
*/
@@ -102,6 +105,95 @@ METHOD(tkm_diffie_hellman_t, get_id, dh_id_type,
return this->context_id;
}
+static u_int hash(void *key)
+{
+ diffie_hellman_group_t k = *(diffie_hellman_group_t*)key;
+ return chunk_hash(chunk_from_thing(k));
+}
+
+static bool equals(void *key, void *other_key)
+{
+ return *(diffie_hellman_group_t*)key == *(diffie_hellman_group_t*)other_key;
+}
+
+/*
+ * Described in header.
+ */
+int register_dh_mapping()
+{
+ int count, i;
+ char *iana_id_str, *tkm_id_str;
+ diffie_hellman_group_t *iana_id;
+ u_int64_t *tkm_id;
+ hashtable_t *map;
+ enumerator_t *enumerator;
+
+ map = hashtable_create((hashtable_hash_t)hash,
+ (hashtable_equals_t)equals, 16);
+
+ enumerator = lib->settings->create_key_value_enumerator(lib->settings,
+ "%s.dh_mapping",
+ lib->ns);
+
+ while (enumerator->enumerate(enumerator, &iana_id_str, &tkm_id_str))
+ {
+ iana_id = malloc_thing(diffie_hellman_group_t);
+ *iana_id = settings_value_as_int(iana_id_str, 0);
+ tkm_id = malloc_thing(u_int64_t);
+ *tkm_id = settings_value_as_int(tkm_id_str, 0);
+
+ map->put(map, iana_id, tkm_id);
+ }
+ enumerator->destroy(enumerator);
+
+ count = map->get_count(map);
+ plugin_feature_t f[count + 1];
+ f[0] = PLUGIN_REGISTER(DH, tkm_diffie_hellman_create);
+
+ i = 1;
+ enumerator = map->create_enumerator(map);
+ while (enumerator->enumerate(enumerator, &iana_id, &tkm_id))
+ {
+ f[i] = PLUGIN_PROVIDE(DH, *iana_id);
+ i++;
+ }
+ enumerator->destroy(enumerator);
+
+ lib->plugins->add_static_features(lib->plugins, "tkm-dh", f, countof(f), TRUE);
+
+ if (count > 0)
+ {
+ group_map = map;
+ }
+ else
+ {
+ map->destroy(map);
+ }
+
+ return count;
+}
+
+/*
+ * Described in header.
+ */
+void destroy_dh_mapping()
+{
+ enumerator_t *enumerator;
+ char *key, *value;
+
+ if (group_map)
+ {
+ enumerator = group_map->create_enumerator(group_map);
+ while (enumerator->enumerate(enumerator, &key, &value))
+ {
+ free(key);
+ free(value);
+ }
+ enumerator->destroy(enumerator);
+ group_map->destroy(group_map);
+ }
+}
+
/*
* Described in header.
*/
@@ -109,6 +201,11 @@ tkm_diffie_hellman_t *tkm_diffie_hellman_create(diffie_hellman_group_t group)
{
private_tkm_diffie_hellman_t *this;
+ if (!group_map)
+ {
+ return NULL;
+ }
+
INIT(this,
.public = {
.dh = {
@@ -130,7 +227,14 @@ tkm_diffie_hellman_t *tkm_diffie_hellman_create(diffie_hellman_group_t group)
return NULL;
}
- if (ike_dh_create(this->context_id, group, &this->pubvalue) != TKM_OK)
+ u_int64_t *dha_id = group_map->get(group_map, &group);
+ if (!dha_id)
+ {
+ free(this);
+ return NULL;
+ }
+
+ if (ike_dh_create(this->context_id, *dha_id, &this->pubvalue) != TKM_OK)
{
free(this);
return NULL;