moved RAW public key support to a separate plugin (pubkey)
This commit is contained in:
@@ -6,7 +6,6 @@ AM_CFLAGS = -rdynamic
|
||||
plugin_LTLIBRARIES = libcharon-medsrv.la
|
||||
libcharon_medsrv_la_SOURCES = medsrv_plugin.h medsrv_plugin.c \
|
||||
medsrv_creds.h medsrv_creds.c \
|
||||
medsrv_config.h medsrv_config.c \
|
||||
medsrv_pubkey.h medsrv_pubkey.c
|
||||
medsrv_config.h medsrv_config.c
|
||||
libcharon_medsrv_la_LDFLAGS = -module
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
*/
|
||||
|
||||
#include "medsrv_creds.h"
|
||||
#include "medsrv_pubkey.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <library.h>
|
||||
@@ -60,6 +59,7 @@ typedef struct {
|
||||
static bool cert_enumerator_enumerate(cert_enumerator_t *this,
|
||||
certificate_t **cert)
|
||||
{
|
||||
certificate_t *trusted;
|
||||
public_key_t *public;
|
||||
chunk_t chunk;
|
||||
|
||||
@@ -73,8 +73,15 @@ static bool cert_enumerator_enumerate(cert_enumerator_t *this,
|
||||
{
|
||||
if (this->type == KEY_ANY || this->type == public->get_type(public))
|
||||
{
|
||||
*cert = this->current = (certificate_t*)medsrv_pubkey_create(public);
|
||||
return TRUE;
|
||||
trusted = lib->creds->create(lib->creds,
|
||||
CRED_CERTIFICATE, CERT_TRUSTED_PUBKEY,
|
||||
BUILD_PUBLIC_KEY, public, BUILD_END);
|
||||
if (trusted)
|
||||
{
|
||||
*cert = this->current = trusted;
|
||||
return TRUE;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
public->destroy(public);
|
||||
}
|
||||
|
||||
@@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Martin Willi
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "medsrv_pubkey.h"
|
||||
|
||||
typedef struct private_medsrv_pubkey_t private_medsrv_pubkey_t;
|
||||
|
||||
/**
|
||||
* private data of medsrv_pubkey
|
||||
*/
|
||||
struct private_medsrv_pubkey_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
medsrv_pubkey_t public;
|
||||
|
||||
/**
|
||||
* wrapped public key
|
||||
*/
|
||||
public_key_t *key;
|
||||
|
||||
/**
|
||||
* dummy issuer id, ID_ANY
|
||||
*/
|
||||
identification_t *issuer;
|
||||
|
||||
/**
|
||||
* reference count
|
||||
*/
|
||||
refcount_t ref;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.get_type
|
||||
*/
|
||||
static certificate_type_t get_type(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
return CERT_TRUSTED_PUBKEY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.get_subject
|
||||
*/
|
||||
static identification_t* get_subject(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
return this->key->get_id(this->key, ID_PUBKEY_SHA1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.get_issuer
|
||||
*/
|
||||
static identification_t* get_issuer(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
return this->issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.has_subject.
|
||||
*/
|
||||
static id_match_t has_subject(private_medsrv_pubkey_t *this,
|
||||
identification_t *subject)
|
||||
{
|
||||
identification_t *id;
|
||||
|
||||
id = this->key->get_id(this->key, subject->get_type(subject));
|
||||
if (id)
|
||||
{
|
||||
return id->matches(id, subject);
|
||||
}
|
||||
return ID_MATCH_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.has_subject.
|
||||
*/
|
||||
static id_match_t has_issuer(private_medsrv_pubkey_t *this,
|
||||
identification_t *issuer)
|
||||
{
|
||||
return ID_MATCH_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.equals.
|
||||
*/
|
||||
static bool equals(private_medsrv_pubkey_t *this, certificate_t *other)
|
||||
{
|
||||
if (this == (private_medsrv_pubkey_t*)other)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
if (other->get_type(other) != CERT_TRUSTED_PUBKEY)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return other->has_subject(other, this->key->get_id(this->key, ID_PUBKEY_SHA1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.issued_by
|
||||
*/
|
||||
static bool issued_by(private_medsrv_pubkey_t *this, certificate_t *issuer)
|
||||
{
|
||||
return equals(this, issuer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.get_public_key
|
||||
*/
|
||||
static public_key_t* get_public_key(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
this->key->get_ref(this->key);
|
||||
return this->key;
|
||||
}
|
||||
/**
|
||||
* Implementation of certificate_t.get_validity.
|
||||
*/
|
||||
static bool get_validity(private_medsrv_pubkey_t *this, time_t *when,
|
||||
time_t *not_before, time_t *not_after)
|
||||
{
|
||||
if (not_before)
|
||||
{
|
||||
*not_before = 0;
|
||||
}
|
||||
if (not_after)
|
||||
{
|
||||
*not_after = ~0;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.is_newer.
|
||||
*/
|
||||
static bool is_newer(certificate_t *this, certificate_t *that)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.get_encoding.
|
||||
*/
|
||||
static chunk_t get_encoding(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
return this->key->get_encoding(this->key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of certificate_t.get_ref
|
||||
*/
|
||||
static private_medsrv_pubkey_t* get_ref(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
ref_get(&this->ref);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of medsrv_pubkey_t.destroy
|
||||
*/
|
||||
static void destroy(private_medsrv_pubkey_t *this)
|
||||
{
|
||||
if (ref_put(&this->ref))
|
||||
{
|
||||
this->issuer->destroy(this->issuer);
|
||||
this->key->destroy(this->key);
|
||||
free(this);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* see header file
|
||||
*/
|
||||
medsrv_pubkey_t *medsrv_pubkey_create(public_key_t *key)
|
||||
{
|
||||
private_medsrv_pubkey_t *this = malloc_thing(private_medsrv_pubkey_t);
|
||||
|
||||
this->public.interface.get_type = (certificate_type_t (*)(certificate_t *this))get_type;
|
||||
this->public.interface.get_subject = (identification_t* (*)(certificate_t *this))get_subject;
|
||||
this->public.interface.get_issuer = (identification_t* (*)(certificate_t *this))get_issuer;
|
||||
this->public.interface.has_subject = (id_match_t (*)(certificate_t*, identification_t *subject))has_subject;
|
||||
this->public.interface.has_issuer = (id_match_t (*)(certificate_t*, identification_t *issuer))has_issuer;
|
||||
this->public.interface.issued_by = (bool (*)(certificate_t *this, certificate_t *issuer))issued_by;
|
||||
this->public.interface.get_public_key = (public_key_t* (*)(certificate_t *this))get_public_key;
|
||||
this->public.interface.get_validity = (bool (*)(certificate_t*, time_t *when, time_t *, time_t*))get_validity;
|
||||
this->public.interface.is_newer = (bool (*)(certificate_t*,certificate_t*))is_newer;
|
||||
this->public.interface.get_encoding = (chunk_t (*)(certificate_t*))get_encoding;
|
||||
this->public.interface.equals = (bool (*)(certificate_t*, certificate_t *other))equals;
|
||||
this->public.interface.get_ref = (certificate_t* (*)(certificate_t *this))get_ref;
|
||||
this->public.interface.destroy = (void (*)(certificate_t *this))destroy;
|
||||
|
||||
this->ref = 1;
|
||||
this->key = key;
|
||||
this->issuer = identification_create_from_encoding(ID_ANY, chunk_empty);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Martin Willi
|
||||
* 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.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup medsrv_pubkey medsrv_pubkey
|
||||
* @{ @ingroup medsrv
|
||||
*/
|
||||
|
||||
#ifndef MEDSRV_PUBKEY_H_
|
||||
#define MEDSRV_PUBKEY_H_
|
||||
|
||||
#include <credentials/keys/public_key.h>
|
||||
#include <credentials/certificates/certificate.h>
|
||||
|
||||
typedef struct medsrv_pubkey_t medsrv_pubkey_t;
|
||||
|
||||
/**
|
||||
* A trusted public key wrapped into certificate of type CERT_TRUSTED_PUBKEY.
|
||||
*/
|
||||
struct medsrv_pubkey_t {
|
||||
|
||||
/**
|
||||
* Implements certificate_t.
|
||||
*/
|
||||
certificate_t interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a wrapped public key instance using a public_key.
|
||||
*
|
||||
* The certifcate uses the public_key ID as subject.
|
||||
*
|
||||
* @param key public key to wrap
|
||||
* @return public key implementing certificate interface
|
||||
*/
|
||||
medsrv_pubkey_t *medsrv_pubkey_create(public_key_t *key);
|
||||
|
||||
#endif /* MEDSRV_PUBKEY_H_ @}*/
|
||||
Reference in New Issue
Block a user