aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/plugins/agent
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-09-09 16:19:08 +0200
committerMartin Willi <martin@strongswan.org>2009-09-10 16:20:18 +0200
commit0a139eeac98c8ce19def7be80a131ca6656d802d (patch)
treefd2cbc16fd7e866cea3d86cd34478c31b6a35494 /src/libstrongswan/plugins/agent
parentd3674e25a7c6152edcc2732901d011eabb75b738 (diff)
downloadstrongswan-0a139eeac98c8ce19def7be80a131ca6656d802d.tar.bz2
strongswan-0a139eeac98c8ce19def7be80a131ca6656d802d.tar.xz
Updated agent plugin to the new builder API
Diffstat (limited to 'src/libstrongswan/plugins/agent')
-rw-r--r--src/libstrongswan/plugins/agent/agent_plugin.c6
-rw-r--r--src/libstrongswan/plugins/agent/agent_private_key.c113
-rw-r--r--src/libstrongswan/plugins/agent/agent_private_key.h15
3 files changed, 42 insertions, 92 deletions
diff --git a/src/libstrongswan/plugins/agent/agent_plugin.c b/src/libstrongswan/plugins/agent/agent_plugin.c
index a8588a990..299b2cc1d 100644
--- a/src/libstrongswan/plugins/agent/agent_plugin.c
+++ b/src/libstrongswan/plugins/agent/agent_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Martin Willi
+ * Copyright (C) 2008-2009 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -37,7 +37,7 @@ struct private_agent_plugin_t {
static void destroy(private_agent_plugin_t *this)
{
lib->creds->remove_builder(lib->creds,
- (builder_constructor_t)agent_private_key_builder);
+ (builder_function_t)agent_private_key_open);
free(this);
}
@@ -51,7 +51,7 @@ plugin_t *plugin_create()
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
- (builder_constructor_t)agent_private_key_builder);
+ (builder_function_t)agent_private_key_open);
return &this->public.plugin;
}
diff --git a/src/libstrongswan/plugins/agent/agent_private_key.c b/src/libstrongswan/plugins/agent/agent_private_key.c
index f5ab36acb..1c48d706c 100644
--- a/src/libstrongswan/plugins/agent/agent_private_key.c
+++ b/src/libstrongswan/plugins/agent/agent_private_key.c
@@ -386,12 +386,37 @@ static void destroy(private_agent_private_key_t *this)
}
/**
- * Internal constructor
+ * See header.
*/
-static agent_private_key_t *agent_private_key_create(char *path,
- public_key_t *pubkey)
+agent_private_key_t *agent_private_key_open(key_type_t type, va_list args)
{
- private_agent_private_key_t *this = malloc_thing(private_agent_private_key_t);
+ private_agent_private_key_t *this;
+ public_key_t *pubkey = NULL;
+ char *path = NULL;
+
+ while (TRUE)
+ {
+ switch (va_arg(args, builder_part_t))
+ {
+ case BUILD_AGENT_SOCKET:
+ path = va_arg(args, char*);
+ continue;
+ case BUILD_PUBLIC_KEY:
+ pubkey = va_arg(args, public_key_t*);
+ continue;
+ case BUILD_END:
+ break;
+ default:
+ return NULL;
+ }
+ break;
+ }
+ if (!path)
+ {
+ return FALSE;
+ }
+
+ this = malloc_thing(private_agent_private_key_t);
this->public.interface.get_type = (key_type_t (*)(private_key_t *this))get_type;
this->public.interface.sign = (bool (*)(private_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t *signature))sign;
@@ -422,83 +447,3 @@ static agent_private_key_t *agent_private_key_create(char *path,
return &this->public;
}
-typedef struct private_builder_t private_builder_t;
-
-/**
- * Builder implementation for key loading/generation
- */
-struct private_builder_t {
- /** implements the builder interface */
- builder_t public;
- /** agent unix socket */
- char *socket;
- /** matching public key */
- public_key_t *pubkey;
-};
-
-/**
- * Implementation of builder_t.build
- */
-static agent_private_key_t *build(private_builder_t *this)
-{
- agent_private_key_t *key = NULL;
-
- if (this->socket)
- {
- key = agent_private_key_create(this->socket, this->pubkey);
- }
- free(this);
- return key;
-}
-
-/**
- * Implementation of builder_t.add
- */
-static void add(private_builder_t *this, builder_part_t part, ...)
-{
- va_list args;
-
- switch (part)
- {
- case BUILD_AGENT_SOCKET:
- {
- va_start(args, part);
- this->socket = va_arg(args, char*);
- va_end(args);
- return;
- }
- case BUILD_PUBLIC_KEY:
- {
- va_start(args, part);
- this->pubkey = va_arg(args, public_key_t*);
- va_end(args);
- return;
- }
- default:
- break;
- }
- builder_cancel(&this->public);
-}
-
-/**
- * Builder construction function
- */
-builder_t *agent_private_key_builder(key_type_t type)
-{
- private_builder_t *this;
-
- if (type != KEY_RSA)
- {
- return NULL;
- }
-
- this = malloc_thing(private_builder_t);
-
- this->pubkey = NULL;
- this->socket = NULL;
- this->public.add = (void(*)(builder_t *this, builder_part_t part, ...))add;
- this->public.build = (void*(*)(builder_t *this))build;
-
- return &this->public;
-}
-
diff --git a/src/libstrongswan/plugins/agent/agent_private_key.h b/src/libstrongswan/plugins/agent/agent_private_key.h
index 929e88a50..3d9500c1a 100644
--- a/src/libstrongswan/plugins/agent/agent_private_key.h
+++ b/src/libstrongswan/plugins/agent/agent_private_key.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 Martin Willi
+ * Copyright (C) 2008-2009 Martin Willi
* Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
#ifndef AGENT_PRIVATE_KEY_H_
#define AGENT_PRIVATE_KEY_H_
+#include <credentials/builder.h>
#include <credentials/keys/private_key.h>
typedef struct agent_private_key_t agent_private_key_t;
@@ -37,12 +38,16 @@ struct agent_private_key_t {
};
/**
- * Create the builder for a private key.
+ * Open connection to a private key stored in a SSH agent.
*
- * @param type type of the key
- * @return builder instance
+ * The function takes BUILD_AGENT_SOCKET and optionally a BUILD_PUBLIC_KEY
+ * to select a specific key loaded in ssh-agent.
+ *
+ * @param type type of the key, must be KEY_RSA
+ * @param args builder_part_t argument list
+ * @return built key, NULL on failure
*/
-builder_t *agent_private_key_builder(key_type_t type);
+agent_private_key_t *agent_private_key_open(key_type_t type, va_list args);
#endif /** AGENT_PRIVATE_KEY_H_ @}*/