Migrated agent plugin to INIT/METHOD macros
This commit is contained in:
@@ -31,10 +31,8 @@ struct private_agent_plugin_t {
|
|||||||
agent_plugin_t public;
|
agent_plugin_t public;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
METHOD(plugin_t, destroy, void,
|
||||||
* Implementation of agent_plugin_t.agenttroy
|
private_agent_plugin_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_agent_plugin_t *this)
|
|
||||||
{
|
{
|
||||||
lib->creds->remove_builder(lib->creds,
|
lib->creds->remove_builder(lib->creds,
|
||||||
(builder_function_t)agent_private_key_open);
|
(builder_function_t)agent_private_key_open);
|
||||||
@@ -46,9 +44,11 @@ static void destroy(private_agent_plugin_t *this)
|
|||||||
*/
|
*/
|
||||||
plugin_t *agent_plugin_create()
|
plugin_t *agent_plugin_create()
|
||||||
{
|
{
|
||||||
private_agent_plugin_t *this = malloc_thing(private_agent_plugin_t);
|
private_agent_plugin_t *this;
|
||||||
|
|
||||||
this->public.plugin.destroy = (void(*)(plugin_t*))destroy;
|
INIT(this,
|
||||||
|
.public.plugin.destroy = _destroy,
|
||||||
|
);
|
||||||
|
|
||||||
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
|
lib->creds->add_builder(lib->creds, CRED_PRIVATE_KEY, KEY_RSA,
|
||||||
(builder_function_t)agent_private_key_open);
|
(builder_function_t)agent_private_key_open);
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ static bool read_key(private_agent_private_key_t *this, public_key_t *pubkey)
|
|||||||
{
|
{
|
||||||
break;;
|
break;;
|
||||||
}
|
}
|
||||||
if (pubkey && !private_key_belongs_to(&this->public.interface, pubkey))
|
if (pubkey && !private_key_belongs_to(&this->public.key, pubkey))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -221,11 +221,9 @@ static bool read_key(private_agent_private_key_t *this, public_key_t *pubkey)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, sign, bool,
|
||||||
* Implementation of agent_private_key.destroy.
|
private_agent_private_key_t *this, signature_scheme_t scheme,
|
||||||
*/
|
chunk_t data, chunk_t *signature)
|
||||||
static bool sign(private_agent_private_key_t *this, signature_scheme_t scheme,
|
|
||||||
chunk_t data, chunk_t *signature)
|
|
||||||
{
|
{
|
||||||
u_int32_t len, flags;
|
u_int32_t len, flags;
|
||||||
char buf[2048];
|
char buf[2048];
|
||||||
@@ -294,36 +292,27 @@ static bool sign(private_agent_private_key_t *this, signature_scheme_t scheme,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, get_type, key_type_t,
|
||||||
* Implementation of agent_private_key.destroy.
|
private_agent_private_key_t *this)
|
||||||
*/
|
|
||||||
static key_type_t get_type(private_agent_private_key_t *this)
|
|
||||||
{
|
{
|
||||||
return KEY_RSA;
|
return KEY_RSA;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, decrypt, bool,
|
||||||
* Implementation of agent_private_key.destroy.
|
private_agent_private_key_t *this, chunk_t crypto, chunk_t *plain)
|
||||||
*/
|
|
||||||
static bool decrypt(private_agent_private_key_t *this,
|
|
||||||
chunk_t crypto, chunk_t *plain)
|
|
||||||
{
|
{
|
||||||
DBG1(DBG_LIB, "private key decryption not supported by ssh-agent");
|
DBG1(DBG_LIB, "private key decryption not supported by ssh-agent");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, get_keysize, size_t,
|
||||||
* Implementation of agent_private_key.destroy.
|
private_agent_private_key_t *this)
|
||||||
*/
|
|
||||||
static size_t get_keysize(private_agent_private_key_t *this)
|
|
||||||
{
|
{
|
||||||
return this->key_size;
|
return this->key_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, get_public_key, public_key_t*,
|
||||||
* Implementation of agent_private_key.get_public_key.
|
private_agent_private_key_t *this)
|
||||||
*/
|
|
||||||
static public_key_t* get_public_key(private_agent_private_key_t *this)
|
|
||||||
{
|
{
|
||||||
chunk_t key, n, e;
|
chunk_t key, n, e;
|
||||||
|
|
||||||
@@ -336,20 +325,15 @@ static public_key_t* get_public_key(private_agent_private_key_t *this)
|
|||||||
BUILD_RSA_MODULUS, n, BUILD_RSA_PUB_EXP, e, BUILD_END);
|
BUILD_RSA_MODULUS, n, BUILD_RSA_PUB_EXP, e, BUILD_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, get_encoding, bool,
|
||||||
* Implementation of private_key_t.get_encoding
|
private_agent_private_key_t *this, cred_encoding_type_t type,
|
||||||
*/
|
chunk_t *encoding)
|
||||||
static bool get_encoding(private_agent_private_key_t *this,
|
|
||||||
cred_encoding_type_t type, chunk_t *encoding)
|
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, get_fingerprint, bool,
|
||||||
* Implementation of private_key_t.get_fingerprint
|
private_agent_private_key_t *this, cred_encoding_type_t type, chunk_t *fp)
|
||||||
*/
|
|
||||||
static bool get_fingerprint(private_agent_private_key_t *this,
|
|
||||||
cred_encoding_type_t type, chunk_t *fp)
|
|
||||||
{
|
{
|
||||||
chunk_t n, e, key;
|
chunk_t n, e, key;
|
||||||
|
|
||||||
@@ -366,19 +350,15 @@ static bool get_fingerprint(private_agent_private_key_t *this,
|
|||||||
CRED_PART_RSA_MODULUS, n, CRED_PART_RSA_PUB_EXP, e, CRED_PART_END);
|
CRED_PART_RSA_MODULUS, n, CRED_PART_RSA_PUB_EXP, e, CRED_PART_END);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, get_ref, private_key_t*,
|
||||||
* Implementation of agent_private_key.get_ref.
|
private_agent_private_key_t *this)
|
||||||
*/
|
|
||||||
static private_agent_private_key_t* get_ref(private_agent_private_key_t *this)
|
|
||||||
{
|
{
|
||||||
ref_get(&this->ref);
|
ref_get(&this->ref);
|
||||||
return this;
|
return &this->public.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
METHOD(private_key_t, destroy, void,
|
||||||
* Implementation of agent_private_key.destroy.
|
private_agent_private_key_t *this)
|
||||||
*/
|
|
||||||
static void destroy(private_agent_private_key_t *this)
|
|
||||||
{
|
{
|
||||||
if (ref_put(&this->ref))
|
if (ref_put(&this->ref))
|
||||||
{
|
{
|
||||||
@@ -420,20 +400,23 @@ agent_private_key_t *agent_private_key_open(key_type_t type, va_list args)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
this = malloc_thing(private_agent_private_key_t);
|
INIT(this,
|
||||||
|
.public.key = {
|
||||||
this->public.interface.get_type = (key_type_t (*)(private_key_t *this))get_type;
|
.get_type = _get_type,
|
||||||
this->public.interface.sign = (bool (*)(private_key_t *this, signature_scheme_t scheme, chunk_t data, chunk_t *signature))sign;
|
.sign = _sign,
|
||||||
this->public.interface.decrypt = (bool (*)(private_key_t *this, chunk_t crypto, chunk_t *plain))decrypt;
|
.decrypt = _decrypt,
|
||||||
this->public.interface.get_keysize = (size_t (*) (private_key_t *this))get_keysize;
|
.get_keysize = _get_keysize,
|
||||||
this->public.interface.get_public_key = (public_key_t* (*)(private_key_t *this))get_public_key;
|
.get_public_key = _get_public_key,
|
||||||
this->public.interface.belongs_to = private_key_belongs_to;
|
.belongs_to = private_key_belongs_to,
|
||||||
this->public.interface.equals = private_key_equals;
|
.equals = private_key_equals,
|
||||||
this->public.interface.get_fingerprint = (bool(*)(private_key_t*, cred_encoding_type_t type, chunk_t *fp))get_fingerprint;
|
.get_fingerprint = _get_fingerprint,
|
||||||
this->public.interface.has_fingerprint = (bool(*)(private_key_t*, chunk_t fp))private_key_has_fingerprint;
|
.has_fingerprint = private_key_has_fingerprint,
|
||||||
this->public.interface.get_encoding = (bool(*)(private_key_t*, cred_encoding_type_t type, chunk_t *encoding))get_encoding;
|
.get_encoding = _get_encoding,
|
||||||
this->public.interface.get_ref = (private_key_t* (*)(private_key_t *this))get_ref;
|
.get_ref = _get_ref,
|
||||||
this->public.interface.destroy = (void (*)(private_key_t *this))destroy;
|
.destroy = _destroy,
|
||||||
|
},
|
||||||
|
.ref = 1,
|
||||||
|
);
|
||||||
|
|
||||||
this->socket = open_connection(path);
|
this->socket = open_connection(path);
|
||||||
if (this->socket < 0)
|
if (this->socket < 0)
|
||||||
@@ -441,9 +424,6 @@ agent_private_key_t *agent_private_key_open(key_type_t type, va_list args)
|
|||||||
free(this);
|
free(this);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
this->key = chunk_empty;
|
|
||||||
this->ref = 1;
|
|
||||||
|
|
||||||
if (!read_key(this, pubkey))
|
if (!read_key(this, pubkey))
|
||||||
{
|
{
|
||||||
destroy(this);
|
destroy(this);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ struct agent_private_key_t {
|
|||||||
/**
|
/**
|
||||||
* Implements private_key_t interface
|
* Implements private_key_t interface
|
||||||
*/
|
*/
|
||||||
private_key_t interface;
|
private_key_t key;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user