aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorReto Buerki <reet@codelabs.ch>2012-10-16 16:27:46 +0200
committerTobias Brunner <tobias@strongswan.org>2013-03-19 15:23:49 +0100
commit08d199fa3d02e1954e1c09fcabf98bb3d1ede675 (patch)
tree0d8d5f63044ef16a2017cf135ce5df39f76d94b0 /src
parentfe504b745d1a4eaf49fa60d62dc351aae1de1f93 (diff)
downloadstrongswan-08d199fa3d02e1954e1c09fcabf98bb3d1ede675.tar.bz2
strongswan-08d199fa3d02e1954e1c09fcabf98bb3d1ede675.tar.xz
Add TKM private key implementation
The key currently imitates the private key of alice@strongswan.org by returning it's fingerprint in the get_fingerprint function. This associates the private key with alice's X.509 cert and charon will use it to create a signature over the local AUTH octets of the test connection. The private key serves as a proxy to the TKM ike_isa_sign operation and extracts the required information from the auth octets chunk passed on by the keymat.
Diffstat (limited to 'src')
-rw-r--r--src/charon-tkm/src/tkm/tkm_private_key.c166
-rw-r--r--src/charon-tkm/src/tkm/tkm_private_key.h40
2 files changed, 206 insertions, 0 deletions
diff --git a/src/charon-tkm/src/tkm/tkm_private_key.c b/src/charon-tkm/src/tkm/tkm_private_key.c
new file mode 100644
index 000000000..d728f8d7e
--- /dev/null
+++ b/src/charon-tkm/src/tkm/tkm_private_key.c
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2012 Reto Buerki
+ * Copyright (C) 2012 Adrian-Ken Rueegsegger
+ * 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 <utils/debug.h>
+#include <tkm/constants.h>
+#include <tkm/client.h>
+
+#include "tkm_utils.h"
+#include "tkm_types.h"
+#include "tkm_private_key.h"
+
+typedef struct private_tkm_private_key_t private_tkm_private_key_t;
+
+/**
+ * Private data of a tkm_private_key_t object.
+ */
+struct private_tkm_private_key_t {
+
+ /**
+ * Public interface for this signer.
+ */
+ tkm_private_key_t public;
+
+ /**
+ * Key fingerprint.
+ */
+ chunk_t fingerprint;
+
+ /**
+ * Reference count.
+ */
+ refcount_t ref;
+
+};
+
+METHOD(private_key_t, get_type, key_type_t,
+ private_tkm_private_key_t *this)
+{
+ return KEY_RSA;
+}
+
+METHOD(private_key_t, sign, bool,
+ private_tkm_private_key_t *this, signature_scheme_t scheme,
+ chunk_t data, chunk_t *signature)
+{
+ signature_type sig;
+ init_message_type msg;
+
+ if (data.ptr == NULL)
+ {
+ DBG1(DBG_LIB, "unable to get signature information");
+ return FALSE;
+ }
+ sign_info_t sign = *(sign_info_t *)(data.ptr);
+
+ chunk_to_sequence(&sign.init_message, &msg, sizeof(init_message_type));
+ const isa_id_type isa_id = sign.isa_id;
+ chunk_free(&sign.init_message);
+
+ if (ike_isa_sign(isa_id, 1, msg, &sig) != TKM_OK)
+ {
+ DBG1(DBG_LIB, "signature operation failed");
+ return FALSE;
+ }
+
+ sequence_to_chunk(sig.data, sig.size, signature);
+ return TRUE;
+}
+
+METHOD(private_key_t, decrypt, bool,
+ private_tkm_private_key_t *this, encryption_scheme_t scheme,
+ chunk_t crypto, chunk_t *plain)
+{
+ return FALSE;
+}
+
+METHOD(private_key_t, get_keysize, int,
+ private_tkm_private_key_t *this)
+{
+ return 0;
+}
+
+METHOD(private_key_t, get_public_key, public_key_t*,
+ private_tkm_private_key_t *this)
+{
+ return NULL;
+}
+
+METHOD(private_key_t, get_encoding, bool,
+ private_tkm_private_key_t *this, cred_encoding_type_t type,
+ chunk_t *encoding)
+{
+ return FALSE;
+}
+
+METHOD(private_key_t, get_fingerprint, bool,
+ private_tkm_private_key_t *this, cred_encoding_type_t type, chunk_t *fp)
+{
+ *fp = this->fingerprint;
+ return TRUE;
+}
+
+METHOD(private_key_t, get_ref, private_key_t*,
+ private_tkm_private_key_t *this)
+{
+ ref_get(&this->ref);
+ return &this->public.key;
+}
+
+METHOD(private_key_t, destroy, void,
+ private_tkm_private_key_t *this)
+{
+ if (ref_put(&this->ref))
+ {
+ chunk_free(&this->fingerprint);
+ free(this);
+ }
+}
+
+/**
+ * See header.
+ */
+tkm_private_key_t *tkm_private_key_init(void)
+{
+ private_tkm_private_key_t *this;
+
+ INIT(this,
+ .public = {
+ .key = {
+ .get_type = _get_type,
+ .sign = _sign,
+ .decrypt = _decrypt,
+ .get_keysize = _get_keysize,
+ .get_public_key = _get_public_key,
+ .equals = private_key_equals,
+ .belongs_to = private_key_belongs_to,
+ .get_fingerprint = _get_fingerprint,
+ .has_fingerprint = private_key_has_fingerprint,
+ .get_encoding = _get_encoding,
+ .get_ref = _get_ref,
+ .destroy = _destroy,
+ },
+ },
+ .ref = 1,
+ );
+
+ /* fingerprint of alice@strongswan.org keypair */
+ const char fake_fp[] = "05da04208c02f428470acf6c772d066613da863c";
+ this->fingerprint = chunk_create((u_char *)fake_fp, strlen(fake_fp));
+ this->fingerprint = chunk_from_hex(this->fingerprint, NULL);
+
+ return &this->public;
+}
diff --git a/src/charon-tkm/src/tkm/tkm_private_key.h b/src/charon-tkm/src/tkm/tkm_private_key.h
new file mode 100644
index 000000000..aa472a1a8
--- /dev/null
+++ b/src/charon-tkm/src/tkm/tkm_private_key.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2012 Reto Buerki
+ * Copyright (C) 2012 Adrian-Ken Rueegsegger
+ * 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.
+ */
+
+#ifndef TKM_PRIVATE_KEY_H_
+#define TKM_PRIVATE_KEY_H_
+
+#include <credentials/keys/private_key.h>
+
+typedef struct tkm_private_key_t tkm_private_key_t;
+
+/**
+ * TKM private_key_t implementation.
+ */
+struct tkm_private_key_t {
+
+ /**
+ * Implements private_key_t interface
+ */
+ private_key_t key;
+};
+
+/**
+ * Initialize TKM private key.
+ */
+tkm_private_key_t *tkm_private_key_init(void);
+
+#endif /** TKM_PRIVATE_KEY_H_ */