diff options
Diffstat (limited to 'Source/lib')
-rw-r--r-- | Source/lib/asn1/Makefile.asn1 (renamed from Source/lib/asn1-pluto/Makefile.asn1) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/asn1-pluto.c (renamed from Source/lib/asn1-pluto/asn1-pluto.c) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/asn1-pluto.h (renamed from Source/lib/asn1-pluto/asn1-pluto.h) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/oid.c (renamed from Source/lib/asn1-pluto/oid.c) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/oid.h (renamed from Source/lib/asn1-pluto/oid.h) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/oid.pl (renamed from Source/lib/asn1-pluto/oid.pl) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/oid.txt (renamed from Source/lib/asn1-pluto/oid.txt) | 0 | ||||
-rwxr-xr-x | Source/lib/asn1/pem.c (renamed from Source/lib/asn1-pluto/pem.c) | 0 | ||||
-rwxr-xr-x | Source/lib/asn1/pem.h (renamed from Source/lib/asn1-pluto/pem.h) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/ttodata.c (renamed from Source/lib/asn1-pluto/ttodata.c) | 0 | ||||
-rw-r--r-- | Source/lib/asn1/ttodata.h (renamed from Source/lib/asn1-pluto/ttodata.h) | 0 | ||||
-rwxr-xr-x | Source/lib/crypto/certificate.h | 10 | ||||
-rw-r--r-- | Source/lib/utils/identification.h | 40 | ||||
-rw-r--r-- | Source/lib/utils/leak_detective.c | 63 |
14 files changed, 92 insertions, 21 deletions
diff --git a/Source/lib/asn1-pluto/Makefile.asn1 b/Source/lib/asn1/Makefile.asn1 index 44726ffa4..44726ffa4 100644 --- a/Source/lib/asn1-pluto/Makefile.asn1 +++ b/Source/lib/asn1/Makefile.asn1 diff --git a/Source/lib/asn1-pluto/asn1-pluto.c b/Source/lib/asn1/asn1-pluto.c index 01deb5c14..01deb5c14 100644 --- a/Source/lib/asn1-pluto/asn1-pluto.c +++ b/Source/lib/asn1/asn1-pluto.c diff --git a/Source/lib/asn1-pluto/asn1-pluto.h b/Source/lib/asn1/asn1-pluto.h index 3edaa3254..3edaa3254 100644 --- a/Source/lib/asn1-pluto/asn1-pluto.h +++ b/Source/lib/asn1/asn1-pluto.h diff --git a/Source/lib/asn1-pluto/oid.c b/Source/lib/asn1/oid.c index 7b0135d5e..7b0135d5e 100644 --- a/Source/lib/asn1-pluto/oid.c +++ b/Source/lib/asn1/oid.c diff --git a/Source/lib/asn1-pluto/oid.h b/Source/lib/asn1/oid.h index 4096af357..4096af357 100644 --- a/Source/lib/asn1-pluto/oid.h +++ b/Source/lib/asn1/oid.h diff --git a/Source/lib/asn1-pluto/oid.pl b/Source/lib/asn1/oid.pl index 52ac8eae0..52ac8eae0 100644 --- a/Source/lib/asn1-pluto/oid.pl +++ b/Source/lib/asn1/oid.pl diff --git a/Source/lib/asn1-pluto/oid.txt b/Source/lib/asn1/oid.txt index ad05a1270..ad05a1270 100644 --- a/Source/lib/asn1-pluto/oid.txt +++ b/Source/lib/asn1/oid.txt diff --git a/Source/lib/asn1-pluto/pem.c b/Source/lib/asn1/pem.c index 24c71c61f..24c71c61f 100755 --- a/Source/lib/asn1-pluto/pem.c +++ b/Source/lib/asn1/pem.c diff --git a/Source/lib/asn1-pluto/pem.h b/Source/lib/asn1/pem.h index a4332fd34..a4332fd34 100755 --- a/Source/lib/asn1-pluto/pem.h +++ b/Source/lib/asn1/pem.h diff --git a/Source/lib/asn1-pluto/ttodata.c b/Source/lib/asn1/ttodata.c index 5e8149955..5e8149955 100644 --- a/Source/lib/asn1-pluto/ttodata.c +++ b/Source/lib/asn1/ttodata.c diff --git a/Source/lib/asn1-pluto/ttodata.h b/Source/lib/asn1/ttodata.h index d57244ef5..d57244ef5 100644 --- a/Source/lib/asn1-pluto/ttodata.h +++ b/Source/lib/asn1/ttodata.h diff --git a/Source/lib/crypto/certificate.h b/Source/lib/crypto/certificate.h index 2b5459efb..8dc88e033 100755 --- a/Source/lib/crypto/certificate.h +++ b/Source/lib/crypto/certificate.h @@ -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. diff --git a/Source/lib/utils/identification.h b/Source/lib/utils/identification.h index b973da9a4..30796bd56 100644 --- a/Source/lib/utils/identification.h +++ b/Source/lib/utils/identification.h @@ -85,6 +85,21 @@ enum id_type_t { }; /** + * 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. */ extern mapping_t id_type_m[]; @@ -144,6 +159,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. * * @param this the identification_t object @@ -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_ */ diff --git a/Source/lib/utils/leak_detective.c b/Source/lib/utils/leak_detective.c index 67c123be2..0d90820ee 100644 --- a/Source/lib/utils/leak_detective.c +++ b/Source/lib/utils/leak_detective.c @@ -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); |