- applied patch from andreas, which allows certificate listing via stroke

This commit is contained in:
Martin Willi
2006-05-19 06:44:08 +00:00
parent 3e61d63a3a
commit 86a7937b45
17 changed files with 343 additions and 117 deletions
@@ -27,6 +27,7 @@
#include <crypto/rsa/rsa_private_key.h>
#include <crypto/rsa/rsa_public_key.h>
#include <utils/identification.h>
#include <utils/logger.h>
typedef struct credential_store_t credential_store_t;
@@ -80,6 +81,15 @@ struct credential_store_t {
*/
rsa_private_key_t *(*get_rsa_private_key) (credential_store_t *this, identification_t *identification);
/**
* @brief Lists all certificates kept in the local credential store.
*
* @param this calling object
* @param logger logger to be used
* @param utc log dates either in UTC or local time
*/
void (*log_certificates) (credential_store_t *this, logger_t *logger, bool utc);
/**
* @brief Destroys a credential_store_t object.
*
@@ -140,6 +140,30 @@ static rsa_private_key_t *get_rsa_private_key(private_local_credential_store_t *
return found;
}
/**
* Implements credential_store_t.log_certificates
*/
static void log_certificates(private_local_credential_store_t *this, logger_t *logger, bool utc)
{
iterator_t *iterator = this->certificates->create_iterator(this->certificates, TRUE);
if (iterator->get_count(iterator))
{
logger->log(logger, CONTROL, "");
logger->log(logger, CONTROL, "List of X.509 End Entity Certificates:");
logger->log(logger, CONTROL, "");
}
while (iterator->has_next(iterator))
{
x509_t *cert;
iterator->current(iterator, (void**)&cert);
cert->log_certificate(cert, logger, utc);
}
iterator->destroy(iterator);
}
/**
* Implements local_credential_store_t.load_certificates
*/
@@ -187,8 +211,8 @@ static void load_certificates(private_local_credential_store_t *this, const char
*/
static identification_t *get_id_for_private_key(private_local_credential_store_t *this, rsa_private_key_t *private_key)
{
iterator_t *iterator;
x509_t *cert;
iterator_t *iterator;
identification_t *found = NULL;
rsa_public_key_t *public_key;
@@ -368,6 +392,7 @@ local_credential_store_t * local_credential_store_create(void)
this->public.credential_store.get_shared_secret = (status_t(*)(credential_store_t*,identification_t*,chunk_t*))get_shared_secret;
this->public.credential_store.get_rsa_private_key = (rsa_private_key_t*(*)(credential_store_t*,identification_t*))get_rsa_private_key;
this->public.credential_store.get_rsa_public_key = (rsa_public_key_t*(*)(credential_store_t*,identification_t*))get_rsa_public_key;
this->public.credential_store.log_certificates = (void(*)(credential_store_t*,logger_t*,bool))log_certificates;
this->public.load_certificates = (void(*)(local_credential_store_t*,const char*))load_certificates;
this->public.load_private_keys = (void(*)(local_credential_store_t*,const char*, const char*))load_private_keys;
this->public.credential_store.destroy = (void(*)(credential_store_t*))destroy;
@@ -52,7 +52,7 @@ struct local_credential_store_t {
/**
* @brief Loads trusted certificates from a folder.
*
* Currently, all keys must be in binary DER format.
* Certificates in both DER and PEM format are accepted
*
* @param this calling object
* @param path directory to load certificates from
@@ -60,10 +60,10 @@ struct local_credential_store_t {
void (*load_certificates) (local_credential_store_t *this, const char *path);
/**
* @brief Loads RSA private keys from a folder.
* @brief Loads RSA private keys defined in ipsec.secrets
*
* Currently, all keys must be unencrypted in binary DER format. Anything
* other gets ignored. Further, a certificate for the specific private
* Currently, all keys must be unencrypted in either DER or PEM format.
* Other formats are ignored. Further, a certificate for the specific private
* key must already be loaded to get the ID from.
*
* @param this calling object
+27 -31
View File
@@ -358,6 +358,16 @@ static void stroke_status(private_stroke_t *this, stroke_msg_t *msg)
charon->ike_sa_manager->log_status(charon->ike_sa_manager, this->stroke_logger, msg->status.name);
}
/**
* list various information
*/
static void stroke_list(private_stroke_t *this, stroke_msg_t *msg, bool utc)
{
if (msg->type = STR_LIST_CERTS)
{
charon->credentials->log_certificates(charon->credentials, this->stroke_logger, utc);
}
}
logger_context_t get_context(char *context)
{
if (strcasecmp(context, "ALL") == 0) return ALL_LOGGERS;
@@ -399,11 +409,16 @@ static void stroke_logtype(private_stroke_t *this, stroke_msg_t *msg)
return;
}
if (strcasecmp(msg->logtype.type, "CONTROL") == 0) level = CONTROL;
else if (strcasecmp(msg->logtype.type, "ERROR") == 0) level = ERROR;
else if (strcasecmp(msg->logtype.type, "AUDIT") == 0) level = AUDIT;
else if (strcasecmp(msg->logtype.type, "RAW") == 0) level = RAW;
else if (strcasecmp(msg->logtype.type, "PRIVATE") == 0) level = PRIVATE;
if (strcasecmp(msg->logtype.type, "CONTROL") == 0)
level = CONTROL;
else if (strcasecmp(msg->logtype.type, "ERROR") == 0)
level = ERROR;
else if (strcasecmp(msg->logtype.type, "AUDIT") == 0)
level = AUDIT;
else if (strcasecmp(msg->logtype.type, "RAW") == 0)
level = RAW;
else if (strcasecmp(msg->logtype.type, "PRIVATE") == 0)
level = PRIVATE;
else
{
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid type (%s)!", msg->logtype.type);
@@ -425,13 +440,13 @@ static void stroke_logtype(private_stroke_t *this, stroke_msg_t *msg)
*/
static void stroke_loglevel(private_stroke_t *this, stroke_msg_t *msg)
{
log_level_t level;
logger_context_t context;
pop_string(msg, &(msg->loglevel.context));
this->logger->log(this->logger, CONTROL, "received stroke: loglevel for %s", msg->loglevel.context);
log_level_t level;
logger_context_t context = get_context(msg->loglevel.context);
context = get_context(msg->loglevel.context);
if (context == -2)
{
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid context (%s)!", msg->loglevel.context);
@@ -439,21 +454,13 @@ static void stroke_loglevel(private_stroke_t *this, stroke_msg_t *msg)
}
if (msg->loglevel.level == 0)
{
level = LEVEL0;
}
else if (msg->loglevel.level == 1)
{
level = LEVEL1;
}
else if (msg->loglevel.level == 2)
{
level = LEVEL2;
}
else if (msg->loglevel.level == 3)
{
level = LEVEL3;
}
else
{
this->stroke_logger->log(this->stroke_logger, ERROR, "invalid level (%d)!", msg->loglevel.level);
@@ -529,41 +536,30 @@ static void stroke_receive(private_stroke_t *this)
switch (msg->type)
{
case STR_INITIATE:
{
stroke_initiate(this, msg);
break;
}
case STR_TERMINATE:
{
stroke_terminate(this, msg);
break;
}
case STR_STATUS:
{
stroke_status(this, msg);
break;
}
case STR_STATUS_ALL:
{
this->stroke_logger->enable_level(this->stroke_logger, LEVEL1);
stroke_status(this, msg);
break;
}
case STR_ADD_CONN:
{
stroke_add_conn(this, msg);
break;
}
case STR_LOGTYPE:
{
stroke_logtype(this, msg);
break;
}
case STR_LOGLEVEL:
{
stroke_loglevel(this, msg);
break;
}
case STR_LIST_CERTS:
stroke_list(this, msg, FALSE);
break;
default:
this->logger->log(this->logger, ERROR, "received invalid stroke");
}