2009-06-19 09:42:54 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Martin Willi
|
|
|
|
* Hochschule fuer Technik Rapperswil, Switzerland
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2010-03-08 14:33:42 +00:00
|
|
|
#define _GNU_SOURCE
|
2009-06-19 09:42:54 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
|
|
|
#include <library.h>
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
integrity_checker_t *integrity;
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-06-19 09:42:54 +00:00
|
|
|
/* avoid confusing leak reports in build process */
|
|
|
|
setenv("LEAK_DETECTIVE_DISABLE", "1", 0);
|
|
|
|
library_init(NULL);
|
|
|
|
atexit(library_deinit);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-06-19 09:42:54 +00:00
|
|
|
integrity = integrity_checker_create(NULL);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-06-19 09:42:54 +00:00
|
|
|
printf("/**\n");
|
|
|
|
printf(" * checksums of files and loaded code segments.\n");
|
|
|
|
printf(" * created by %s\n", argv[0]);
|
|
|
|
printf(" */\n");
|
|
|
|
printf("\n");
|
|
|
|
printf("#include <library.h>\n");
|
|
|
|
printf("\n");
|
|
|
|
printf("integrity_checksum_t checksums[] = {\n");
|
2009-07-21 20:23:51 +00:00
|
|
|
fprintf(stderr, "integrity test data:\n");
|
|
|
|
fprintf(stderr, "module name, file size / checksum segment size / checksum\n");
|
2009-06-19 09:42:54 +00:00
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
{
|
2009-06-22 12:42:04 +00:00
|
|
|
char *name, *path, *sname = NULL;
|
2009-06-19 09:42:54 +00:00
|
|
|
void *handle, *symbol;
|
|
|
|
u_int32_t fsum, ssum;
|
2009-07-21 20:23:51 +00:00
|
|
|
size_t fsize = 0;
|
|
|
|
size_t ssize = 0;
|
|
|
|
|
2009-06-19 09:42:54 +00:00
|
|
|
path = argv[i];
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-06-19 09:42:54 +00:00
|
|
|
if ((name = strstr(path, "libstrongswan-")))
|
|
|
|
{
|
|
|
|
name = strdup(name + strlen("libstrongswan-"));
|
2010-03-09 08:01:28 +00:00
|
|
|
name[strlen(name) - 3] = '"';
|
|
|
|
name[strlen(name) - 2] = ',';
|
|
|
|
name[strlen(name) - 1] = '\0';
|
|
|
|
if (asprintf(&sname, "%.*s_plugin_create", strlen(name) - 2,
|
2010-03-08 14:33:42 +00:00
|
|
|
name) < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "failed to format plugin constructor "
|
|
|
|
"for '%s', ignored", path);
|
|
|
|
free(name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
translate(sname, "-", "_");
|
2009-06-19 09:42:54 +00:00
|
|
|
}
|
|
|
|
else if (strstr(path, "libstrongswan.so"))
|
|
|
|
{
|
|
|
|
name = strdup("libstrongswan\",");
|
2010-03-08 14:33:42 +00:00
|
|
|
sname = strdup("library_init");
|
2009-06-19 09:42:54 +00:00
|
|
|
}
|
2010-03-24 10:00:11 +00:00
|
|
|
else if (strstr(path, "libhydra.so"))
|
|
|
|
{
|
|
|
|
name = strdup("libhydra\",");
|
2010-03-24 14:25:35 +00:00
|
|
|
sname = strdup("libhydra_init");
|
2010-03-24 10:00:11 +00:00
|
|
|
}
|
2010-03-12 16:20:36 +00:00
|
|
|
else if (strstr(path, "libcharon.so"))
|
|
|
|
{
|
|
|
|
name = strdup("libcharon\",");
|
|
|
|
sname = strdup("libcharon_init");
|
|
|
|
}
|
2009-08-17 13:46:56 +00:00
|
|
|
else if (strstr(path, "pool"))
|
|
|
|
{
|
|
|
|
name = strdup("pool\",");
|
|
|
|
}
|
2009-06-22 12:42:04 +00:00
|
|
|
else if (strstr(path, "charon"))
|
|
|
|
{
|
|
|
|
name = strdup("charon\",");
|
|
|
|
}
|
|
|
|
else if (strstr(path, "pluto"))
|
|
|
|
{
|
|
|
|
name = strdup("pluto\",");
|
|
|
|
}
|
2009-08-17 12:25:18 +00:00
|
|
|
else if (strstr(path, "openac"))
|
|
|
|
{
|
|
|
|
name = strdup("openac\",");
|
|
|
|
}
|
|
|
|
else if (strstr(path, "scepclient"))
|
|
|
|
{
|
|
|
|
name = strdup("scepclient\",");
|
|
|
|
}
|
2009-08-26 09:22:09 +00:00
|
|
|
else if (strstr(path, "pki"))
|
|
|
|
{
|
|
|
|
name = strdup("pki\",");
|
|
|
|
}
|
2009-06-19 09:42:54 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "don't know how to handle '%s', ignored", path);
|
|
|
|
continue;
|
|
|
|
}
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-07-21 20:23:51 +00:00
|
|
|
fsum = integrity->build_file(integrity, path, &fsize);
|
2009-06-19 09:42:54 +00:00
|
|
|
ssum = 0;
|
2009-06-22 12:42:04 +00:00
|
|
|
if (sname)
|
2009-06-19 09:42:54 +00:00
|
|
|
{
|
2009-06-22 12:42:04 +00:00
|
|
|
handle = dlopen(path, RTLD_LAZY);
|
|
|
|
if (handle)
|
2009-06-19 09:42:54 +00:00
|
|
|
{
|
2009-06-22 12:42:04 +00:00
|
|
|
symbol = dlsym(handle, sname);
|
|
|
|
if (symbol)
|
|
|
|
{
|
2009-07-21 20:23:51 +00:00
|
|
|
ssum = integrity->build_segment(integrity, symbol, &ssize);
|
2009-06-22 12:42:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "symbol lookup failed: %s\n", dlerror());
|
|
|
|
}
|
|
|
|
dlclose(handle);
|
2009-06-19 09:42:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-22 12:42:04 +00:00
|
|
|
fprintf(stderr, "dlopen failed: %s\n", dlerror());
|
2009-06-19 09:42:54 +00:00
|
|
|
}
|
|
|
|
}
|
2009-07-21 20:23:51 +00:00
|
|
|
printf("\t{\"%-20s%7u, 0x%08x, %6u, 0x%08x},\n",
|
|
|
|
name, fsize, fsum, ssize, ssum);
|
2009-09-04 11:46:09 +00:00
|
|
|
fprintf(stderr, "\"%-20s%7u / 0x%08x %6u / 0x%08x\n",
|
2009-07-21 20:23:51 +00:00
|
|
|
name, fsize, fsum, ssize, ssum);
|
2010-03-08 14:33:42 +00:00
|
|
|
free(sname);
|
2009-06-19 09:42:54 +00:00
|
|
|
free(name);
|
|
|
|
}
|
|
|
|
printf("};\n");
|
|
|
|
printf("\n");
|
|
|
|
printf("int checksum_count = countof(checksums);\n");
|
|
|
|
printf("\n");
|
|
|
|
integrity->destroy(integrity);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2009-06-19 09:42:54 +00:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|