Overview
Comment: | Integrated dlmopen() wrapper library (not for general use) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: | 59356166dca94716646b6fc9901520c77f26060b |
User & Date: | rkeene on 2017-12-27 18:54:57 |
Other Links: | manifest | tags |
Context
2017-12-27
| ||
18:59 | CACKey 0.7.9 check-in: ac7bd0bf8f user: rkeene tags: trunk | |
18:54 | Integrated dlmopen() wrapper library (not for general use) check-in: 59356166dc user: rkeene tags: trunk | |
18:48 | Added a wrapper PKCS#11 module which uses GNU dlmopen to segregate loading cackey and its libraries to avoid issues with different linkspaces Closed-Leaf check-in: 45c70bc44d user: rkeene tags: dlopen-wrapper | |
2017-07-17
| ||
13:56 | Updated to treat returning a zero-length signed message as an error check-in: 0c7c510048 user: rkeene tags: trunk | |
Changes
Modified .fossil-settings/ignore-glob from [9b544d0473] to [3e95b51b2f].
13 13 libcackey_g.so 14 14 libcackey.so 15 15 libcackey_g.dll 16 16 libcackey.dll 17 17 libcackey_g.a 18 18 libcackey.a 19 19 libcackey.syms 20 +libcackey_wrap.so 21 +libcackey_wrap.o 22 +libcackey_wrap.c 20 23 build/certs 21 24 test 22 25 test-afl 23 26 test-afl.data 24 27 build/chrome/archive 25 28 build/chrome/workdir-* 26 29 build/chrome/lib
Modified Makefile.in from [6effe24266] to [abdaf2d437].
45 45 -$(RANLIB) libcackey.a 46 46 47 47 libcackey_g.a: cackey_g.o 48 48 rm -f libcackey_g.a 49 49 $(AR) rc libcackey_g.a cackey_g.o 50 50 -$(RANLIB) libcackey_g.a 51 51 52 +libcackey_wrap.@SHOBJEXT@: libcackey_wrap.o 53 + $(CC) $(SHOBJFLAGS) $(SHOBJLDFLAGS) -o libcackey_wrap.@SHOBJEXT@ libcackey_wrap.o 54 + -@WEAKENSYMS@ "libcackey_wrap.@SHOBJEXT@" 55 + -@REMOVESYMS@ "libcackey_wrap.@SHOBJEXT@" 56 + 57 +libcackey_wrap.o: libcackey_wrap.c 58 + $(CC) $(SHOBJFLAGS) -o libcackey_wrap.o -c libcackey_wrap.c 59 + 52 60 test: test.c libcackey_g.@SHOBJEXT@ 53 61 $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -o test test.c -Wl,-R,. libcackey_g.@SHOBJEXT@ $(LIBS) 54 62 55 63 test-afl.data: test 56 64 tmpLogFile='log.$(shell openssl rand -hex 16)'; \ 57 65 ./test 2> $${tmpLogFile}; \ 58 66 echo -ne "$$( \ ................................................................................ 74 82 cp "libcackey.@SHOBJEXT@" "$(DESTDIR)$(libdir)/" 75 83 -cp "libcackey_g.@SHOBJEXT@" "$(DESTDIR)$(libdir)/" 76 84 77 85 clean: 78 86 rm -f libcackey.@SHOBJEXT@ libcackey_g.@SHOBJEXT@ 79 87 rm -f libcackey.@SHOBJEXT@.def libcackey_g.@SHOBJEXT@.def 80 88 rm -f libcackey.@SHOBJEXT@.a libcackey_g.@SHOBJEXT@.a 89 + rm -f libcackey_wrap.@SHOBJEXT@ libcackey_wrap.o 81 90 rm -f cackey.o cackey_g.o 82 91 rm -f test 83 92 rm -f splint-cackey.txt 84 93 85 94 distclean: clean 86 95 rm -f config.log config.status config.h Makefile libcackey.syms 87 96 88 97 mrproper: distclean 89 98 rm -f configure config.h.in aclocal.m4 *~ 90 99 91 100 .PHONY: all shared static clean distclean mrproper install
Modified autogen.sh from [daf2ac0fe1] to [de474aeb75].
1 1 #! /bin/sh 2 2 3 3 rm -f aclocal.m4 4 4 5 +rm -f libcackey_wrap.c 6 +./build/make-libcackey_wrap > libcackey_wrap.c 7 + 5 8 ${MAKE:-make} -C aclocal 6 9 autoconf; autoheader 7 10 8 11 rm -rf autom4te.cache/ 9 12 10 13 for basefile in install-sh config.sub config.guess; do 11 14 for path in /usr/share/automake-*; do
Added build/libcackey_wrap.c.in version [4c95cbc88b].
1 +#define _GNU_SOURCE 2 +#include <dlfcn.h> 3 + 4 +#include "config.h" 5 + 6 +#include <stdlib.h> 7 +#include <string.h> 8 +#include <stdio.h> 9 + 10 +#define CK_PTR * 11 +#define CK_DEFINE_FUNCTION(returnType, name) returnType name 12 +#define CK_DECLARE_FUNCTION(returnType, name) returnType name 13 +#define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name) 14 +#define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name) 15 +#ifndef NULL_PTR 16 +# define NULL_PTR 0 17 +#endif 18 + 19 +#include "./pkcs11/pkcs11.h" 20 + 21 +static void *libcackey_wrap_handle = NULL_PTR; 22 + 23 +static void libcackey_wrap_init(void) { 24 + Dl_info libinfo; 25 + int dladdr_ret; 26 + char *library, *libraryDir, *libraryDirLastSlash; 27 + 28 + if (libcackey_wrap_handle) { 29 + return; 30 + } 31 + 32 + dladdr_ret = dladdr(libcackey_wrap_init, &libinfo); 33 + if (dladdr_ret == 0) { 34 + fprintf(stderr, "Unable to resolve path: %s\n", dlerror()); 35 + 36 + abort(); 37 + 38 + return; 39 + } 40 + 41 + if (!libinfo.dli_fname) { 42 + fprintf(stderr, "Unable to lookup filename\n"); 43 + 44 + abort(); 45 + 46 + return; 47 + } 48 + 49 + libraryDir = strdup(libinfo.dli_fname); 50 + libraryDirLastSlash = strrchr(libraryDir, '/'); 51 + if (!libraryDirLastSlash) { 52 + fprintf(stderr, "File name returned is not an absolute path: %s\n", libraryDir); 53 + 54 + abort(); 55 + 56 + return; 57 + } 58 + *libraryDirLastSlash = '\0'; 59 + 60 + asprintf(&library, "%s/libcackey.so", libraryDir); 61 + 62 + libcackey_wrap_handle = dlmopen(LM_ID_NEWLM, library, RTLD_LOCAL | RTLD_NOW); 63 + 64 + if (!libcackey_wrap_handle) { 65 + fprintf(stderr, "Unable to load \"%s\": %s\n", library, dlerror()); 66 + 67 + abort(); 68 + 69 + return; 70 + } 71 + 72 + free(library); 73 + 74 + return; 75 +}
Added build/make-libcackey_wrap version [833dbdb173].
1 +#! /usr/bin/env bash 2 + 3 +cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 4 + 5 +cat libcackey_wrap.c.in 6 + 7 +grep '^CK_DEFINE_FUNCTION' ../cackey.c | while IFS='' read -r line; do 8 + function="$(echo "${line}" | cut -f 2 -d , | cut -f 1 -d ')' | sed 's@ *@@g')" 9 + args="$(echo "${line}" | cut -f 3 -d '(' | cut -f 1 -d ')' | tr ',' $'\n' | sed 's@^ *@@')" 10 + argNames=() 11 + while read argType argName; do 12 + argNames=("${argNames[@]}" "${argName}") 13 + done <<<"${args}" 14 + 15 + argNamesList='' 16 + for argName in "${argNames[@]}"; do 17 + argNamesList="${argNamesList}, ${argName}" 18 + done 19 + argNamesList="$(echo "${argNamesList}" | cut -c 3-)" 20 + 21 + echo '' 22 + echo "${line}" 23 + echo $'\t'"CK_RV (*func)($(echo "${args}" | tr $'\n' ',' | sed 's@,*$@@;s@,@, @g'));" 24 + echo '' 25 + echo $'\t''libcackey_wrap_init();' 26 + echo '' 27 + echo $'\t'"func = dlsym(libcackey_wrap_handle, \"${function}\");" 28 + echo '' 29 + echo $'\t'"return(func($argNamesList));" 30 + echo '}' 31 +done