Updated agent plugin to the new builder API
This commit is contained in:
parent
d3674e25a7
commit
0a139eeac9
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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_ @}*/
|
||||
|
||||
|
|
Loading…
Reference in New Issue