- using asn1 pluto stuff now
This commit is contained in:
1 parent
1ab689ee60
commit
1d025fbcea
14 files changed
+92
-21
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -26,6 +26,8 @@
|
||||
#include <types.h>
|
||||
#include <definitions.h>
|
||||
#include <crypto/rsa/rsa_public_key.h>
|
||||
#include <utils/identification.h>
|
||||
#include <utils/iterator.h>
|
||||
|
||||
|
||||
typedef struct certificate_t certificate_t;
|
||||
@@ -47,6 +49,14 @@ struct certificate_t {
|
||||
* @return public_key
|
||||
*/
|
||||
rsa_public_key_t *(*get_public_key) (certificate_t *this);
|
||||
|
||||
identification_t *(*get_issuer) (certificate_t *this);
|
||||
identification_t *(*get_subject) (certificate_t *this);
|
||||
iterator_t *(*create_subjectaltname_iter) (certificate_t *this);
|
||||
iterator_t *(*create_issueraltname_iter) (certificate_t *this);
|
||||
bool (*belongs_to) (certificate_t *this, identification_t *subject);
|
||||
bool (*issued_by) (certificate_t *this, identification_t *issuer);
|
||||
bool (*validate) (certificate_t *this, rsa_public_key_t *signer);
|
||||
|
||||
/**
|
||||
* @brief Destroys the private key.
|
||||
|
||||
@@ -84,6 +84,21 @@ enum id_type_t {
|
||||
ID_KEY_ID = 11
|
||||
};
|
||||
|
||||
/**
|
||||
* Old pluto id format
|
||||
*
|
||||
* @deprecated Do not use any more, only here for pluto.
|
||||
*/
|
||||
// struct id {
|
||||
// /** ID_* value, pluto pendant to id_type_t */
|
||||
// int kind;
|
||||
// /** ID_IPV4_ADDR, ID_IPV6_ADDR */
|
||||
// ip_address ip_addr;
|
||||
// /** ID_FQDN, ID_USER_FQDN (with @) */
|
||||
// /** ID_KEY_ID, ID_DER_ASN_DN */
|
||||
// chunk_t name;
|
||||
// };
|
||||
|
||||
/**
|
||||
* String mappings for id_type_t.
|
||||
*/
|
||||
@@ -143,6 +158,17 @@ struct identification_t {
|
||||
*/
|
||||
char *(*get_string) (identification_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get the id in the format used in pluto.
|
||||
*
|
||||
* We do this in pluto style here, which means no memory
|
||||
* is allocated.
|
||||
*
|
||||
* @param this the identification_t object
|
||||
* @return string
|
||||
*/
|
||||
// void (*get_pluto_id) (identification_t *this, struct id *pluto_id);
|
||||
|
||||
/**
|
||||
* @brief Check if two identification_t objects are equal.
|
||||
*
|
||||
@@ -195,7 +221,6 @@ struct identification_t {
|
||||
*/
|
||||
identification_t * identification_create_from_string(id_type_t type, char *string);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates an identification_t object from an encoded chunk.
|
||||
*
|
||||
@@ -207,5 +232,18 @@ identification_t * identification_create_from_string(id_type_t type, char *strin
|
||||
*/
|
||||
identification_t * identification_create_from_encoding(id_type_t type, chunk_t encoded);
|
||||
|
||||
/**
|
||||
* @brief Creates an identification_t object from the old pluto id format.
|
||||
*
|
||||
* Pluto uses struct id for identification stuff. Since we need to convert from
|
||||
* this format to our identification_t, we need this special constructor.
|
||||
*
|
||||
* @param id old pluto format id
|
||||
* @return identification_t object
|
||||
*
|
||||
* @ingroup utils
|
||||
*/
|
||||
// identification_t * identification_create_from_pluto_id(struct id *pluto_id);
|
||||
|
||||
|
||||
#endif /* IDENTIFICATION_H_ */
|
||||
@@ -30,10 +30,12 @@
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <dlfcn.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "leak_detective.h"
|
||||
|
||||
#include <types.h>
|
||||
#include <utils/logger_manager.h>
|
||||
|
||||
#ifdef LEAK_DETECTIVE
|
||||
|
||||
@@ -42,6 +44,10 @@
|
||||
*/
|
||||
#define MEMORY_HEADER_MAGIC 0xF1367ADF
|
||||
|
||||
/**
|
||||
* logger for the leak detective
|
||||
*/
|
||||
logger_t *logger;
|
||||
|
||||
static void install_hooks(void);
|
||||
static void uninstall_hooks(void);
|
||||
@@ -103,37 +109,39 @@ memory_header_t first_header = {
|
||||
*/
|
||||
void *old_malloc_hook, *old_realloc_hook, *old_free_hook;
|
||||
|
||||
|
||||
/**
|
||||
* Mutex to exclusivly uninstall hooks, access heap list
|
||||
*/
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void (*__malloc_initialize_hook) (void) = install_hooks;
|
||||
|
||||
/**
|
||||
* log stack frames queried by backtrace()
|
||||
* TODO: Dump symbols of static functions!!!
|
||||
*/
|
||||
void log_stack_frames(void *stack_frames, int stack_frame_count)
|
||||
void log_stack_frames(void **stack_frames, int stack_frame_count)
|
||||
{
|
||||
char **strings;
|
||||
size_t i;
|
||||
|
||||
strings = backtrace_symbols (stack_frames, stack_frame_count);
|
||||
|
||||
printf(" dumping %d stack frames.\n", stack_frame_count);
|
||||
logger->log(logger, ERROR, " dumping %d stack frame addresses.", stack_frame_count);
|
||||
|
||||
for (i = 0; i < stack_frame_count; i++)
|
||||
{
|
||||
printf (" %s\n", strings[i]);
|
||||
logger->log(logger, ERROR, " %s", strings[i]);
|
||||
}
|
||||
free (strings);
|
||||
}
|
||||
|
||||
void (*__malloc_initialize_hook) (void) = install_hooks;
|
||||
|
||||
/**
|
||||
* Installs the malloc hooks, enables leak detection
|
||||
*/
|
||||
void install_hooks()
|
||||
{
|
||||
logger = logger_manager->get_logger(logger_manager, LEAK_DETECT);
|
||||
old_malloc_hook = __malloc_hook;
|
||||
old_realloc_hook = __realloc_hook;
|
||||
old_free_hook = __free_hook;
|
||||
@@ -200,10 +208,10 @@ static void free_hook(void *ptr, const void *caller)
|
||||
pthread_mutex_unlock(&mutex);
|
||||
/* TODO: Since we get a lot of theses from the pthread lib, its deactivated for now... */
|
||||
return;
|
||||
printf("freeing of invalid memory (%p)\n", ptr);
|
||||
logger->log(logger, ERROR, "freeing of invalid memory (%p)", ptr);
|
||||
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
|
||||
log_stack_frames(stack_frames, stack_frame_count);
|
||||
kill(0, SIGSEGV);
|
||||
kill(getpid(), SIGKILL);
|
||||
return;
|
||||
}
|
||||
/* remove magic from hdr */
|
||||
@@ -239,10 +247,10 @@ static void *realloc_hook(void *old, size_t bytes, const void *caller)
|
||||
}
|
||||
if (hdr->magic != MEMORY_HEADER_MAGIC)
|
||||
{
|
||||
printf("reallocation of invalid memory (%p)\n", old);
|
||||
logger->log(logger, ERROR, "reallocation of invalid memory (%p)", old);
|
||||
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
|
||||
log_stack_frames(stack_frames, stack_frame_count);
|
||||
kill(0, SIGSEGV);
|
||||
kill(getpid(), SIGKILL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -264,20 +272,20 @@ void __attribute__ ((destructor)) report_leaks()
|
||||
|
||||
for (hdr = first_header.next; hdr != NULL; hdr = hdr->next)
|
||||
{
|
||||
printf("Leak (%d bytes at %p)\n", hdr->bytes, hdr + 1);
|
||||
logger->log(logger, ERROR, "Leak (%d bytes at %p)", hdr->bytes, hdr + 1);
|
||||
log_stack_frames(hdr->stack_frames, hdr->stack_frame_count);
|
||||
leaks++;
|
||||
}
|
||||
switch (leaks)
|
||||
{
|
||||
case 0:
|
||||
printf("No leaks detected\n");
|
||||
logger->log(logger, CONTROL, "No leaks detected");
|
||||
break;
|
||||
case 1:
|
||||
printf("One leak detected\n");
|
||||
logger->log(logger, ERROR, "One leak detected");
|
||||
break;
|
||||
default:
|
||||
printf("%d leaks detected\n", leaks);
|
||||
logger->log(logger, ERROR, "%d leaks detected", leaks);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -304,13 +312,18 @@ char *inet_ntoa(struct in_addr in)
|
||||
handle = dlopen("libc.so.6", RTLD_LAZY);
|
||||
if (handle == NULL)
|
||||
{
|
||||
kill(0, SIGSEGV);
|
||||
install_hooks();
|
||||
pthread_mutex_unlock(&mutex);
|
||||
kill(getpid(), SIGSEGV);
|
||||
}
|
||||
_inet_ntoa = dlsym(handle, "inet_ntoa");
|
||||
|
||||
if (_inet_ntoa == NULL)
|
||||
{
|
||||
kill(0, SIGSEGV);
|
||||
dlclose(handle);
|
||||
install_hooks();
|
||||
pthread_mutex_unlock(&mutex);
|
||||
kill(getpid(), SIGSEGV);
|
||||
}
|
||||
result = _inet_ntoa(in);
|
||||
dlclose(handle);
|
||||
@@ -336,13 +349,18 @@ int pthread_create(pthread_t *__restrict __threadp, __const pthread_attr_t *__re
|
||||
handle = dlopen("libpthread.so.0", RTLD_LAZY);
|
||||
if (handle == NULL)
|
||||
{
|
||||
kill(0, SIGSEGV);
|
||||
install_hooks();
|
||||
pthread_mutex_unlock(&mutex);
|
||||
kill(getpid(), SIGSEGV);
|
||||
}
|
||||
_pthread_create = dlsym(handle, "pthread_create");
|
||||
|
||||
if (_pthread_create == NULL)
|
||||
{
|
||||
kill(0, SIGSEGV);
|
||||
dlclose(handle);
|
||||
install_hooks();
|
||||
pthread_mutex_unlock(&mutex);
|
||||
kill(getpid(), SIGSEGV);
|
||||
}
|
||||
result = _pthread_create(__threadp, __attr, __start_routine, __arg);
|
||||
dlclose(handle);
|
||||
@@ -364,13 +382,18 @@ time_t mktime(struct tm *tm)
|
||||
handle = dlopen("libc.so.6", RTLD_LAZY);
|
||||
if (handle == NULL)
|
||||
{
|
||||
kill(0, SIGSEGV);
|
||||
install_hooks();
|
||||
pthread_mutex_unlock(&mutex);
|
||||
kill(getpid(), SIGSEGV);
|
||||
}
|
||||
_mktime = dlsym(handle, "mktime");
|
||||
|
||||
if (_mktime == NULL)
|
||||
{
|
||||
kill(0, SIGSEGV);
|
||||
dlclose(handle);
|
||||
install_hooks();
|
||||
pthread_mutex_unlock(&mutex);
|
||||
kill(getpid(), SIGSEGV);
|
||||
}
|
||||
result = _mktime(tm);
|
||||
dlclose(handle);
|
||||
|
||||
Reference in new issue
Block a user