From 06ba977249e6806571795d3257970c5f98fa0d16 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 13 Mar 2013 17:38:04 +0100 Subject: rsgtutil: begin to make rsgttlvdump a generic utility It will support various maintenaince operations, including verification of signatures in the future. To match its new scope, it also has been renamed. --- tools/Makefile.am | 10 ++-- tools/rsgttlvdump.c | 83 -------------------------- tools/rsgtutil.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 173 insertions(+), 88 deletions(-) delete mode 100644 tools/rsgttlvdump.c create mode 100644 tools/rsgtutil.c diff --git a/tools/Makefile.am b/tools/Makefile.am index 8af86cb4..2501331e 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -59,14 +59,14 @@ logctl_CPPFLAGS = $(LIBMONGO_CLIENT_CFLAGS) logctl_LDADD = $(LIBMONGO_CLIENT_LIBS) endif if ENABLE_GUARDTIME -bin_PROGRAMS += rsgttlvdump -#bin_PROGRAMS += logsigner rsgttlvdump +bin_PROGRAMS += rsgtutil +#bin_PROGRAMS += logsigner rsgtutil #logsigner = logsigner.c #logsigner_CPPFLAGS = $(RSRT_CFLAGS) $(GUARDTIME_CFLAGS) #logsigner_LDADD = ../runtime/librsgt.la $(GUARDTIME_LIBS) -rsgttlvdump = rsgttlvdump.c -rsgttlvdump_CPPFLAGS = $(RSRT_CFLAGS) $(GUARDTIME_CFLAGS) -rsgttlvdump_LDADD = ../runtime/librsgt.la $(GUARDTIME_LIBS) +rsgtutil = rsgtutil.c +rsgtutil_CPPFLAGS = $(RSRT_CFLAGS) $(GUARDTIME_CFLAGS) +rsgtutil_LDADD = ../runtime/librsgt.la $(GUARDTIME_LIBS) endif endif diff --git a/tools/rsgttlvdump.c b/tools/rsgttlvdump.c deleted file mode 100644 index 9b536db1..00000000 --- a/tools/rsgttlvdump.c +++ /dev/null @@ -1,83 +0,0 @@ -/* This is a tool for dumpoing the content of GuardTime TLV - * files in a (somewhat) human-readable manner. - * - * Copyright 2013 Adiscon GmbH - * - * This file is part of rsyslog. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * -or- - * see COPYING.ASL20 in the source distribution - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either exprs or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include -#include -#include -#include -#include -#include - -#include "librsgt.h" - -typedef unsigned char uchar; - -void -processFile(char *name) -{ - FILE *fp; - uchar hdr[9]; - uint16_t tlvtype, tlvlen; - void *obj; - int r = -1; - - if(!strcmp(name, "-")) - fp = stdin; - else { - printf("Processing file %s:\n", name); - if((fp = fopen(name, "r")) == NULL) { - perror(name); - goto err; - } - } - if((r = rsgt_tlvrdHeader(fp, hdr)) != 0) goto err; - printf("File Header: '%s'\n", hdr); - while(1) { /* we will err out on EOF */ - if((r = rsgt_tlvrd(fp, &tlvtype, &tlvlen, &obj)) != 0) { - if(feof(fp)) - break; - else - goto err; - } - rsgt_tlvprint(stdout, tlvtype, obj, 0); - } - - if(fp != stdin) - fclose(fp); - return; -err: fprintf(stderr, "error %d processing file %s\n", r, name); -} - -int -main(int argc, char *argv[]) -{ - int i; - if(argc == 1) - processFile("-"); - else { - for(i = 1 ; i < argc ; ++i) - processFile(argv[i]); - } - return 0; -} diff --git a/tools/rsgtutil.c b/tools/rsgtutil.c new file mode 100644 index 00000000..7b70a9a7 --- /dev/null +++ b/tools/rsgtutil.c @@ -0,0 +1,168 @@ +/* This is a tool for dumpoing the content of GuardTime TLV + * files in a (somewhat) human-readable manner. + * + * Copyright 2013 Adiscon GmbH + * + * This file is part of rsyslog. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * -or- + * see COPYING.ASL20 in the source distribution + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either exprs or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include +#include +#include +#include +#include +#include +#include + +#include "librsgt.h" + +typedef unsigned char uchar; + +static enum { MD_DUMP, MD_DETECT_FILE_TYPE, +} mode = MD_DUMP; +static int verbose = 0; + +static void +dumpFile(char *name) +{ + FILE *fp; + uchar hdr[9]; + uint16_t tlvtype, tlvlen; + void *obj; + int r = -1; + + if(!strcmp(name, "-")) + fp = stdin; + else { + printf("Processing file %s:\n", name); + if((fp = fopen(name, "r")) == NULL) { + perror(name); + goto err; + } + } + if((r = rsgt_tlvrdHeader(fp, hdr)) != 0) goto err; + printf("File Header: '%s'\n", hdr); + while(1) { /* we will err out on EOF */ + if((r = rsgt_tlvrd(fp, &tlvtype, &tlvlen, &obj)) != 0) { + if(feof(fp)) + break; + else + goto err; + } + rsgt_tlvprint(stdout, tlvtype, obj, verbose); + } + + if(fp != stdin) + fclose(fp); + return; +err: fprintf(stderr, "error %d processing file %s\n", r, name); +} + +static void +detectFileType(char *name) +{ + FILE *fp; + char *typeName; + char hdr[9]; + int r = -1; + + if(!strcmp(name, "-")) + fp = stdin; + else { + if((fp = fopen(name, "r")) == NULL) { + perror(name); + goto err; + } + } + if((r = rsgt_tlvrdHeader(fp, (uchar*)hdr)) != 0) goto err; + if(!strcmp(hdr, "LOGSIG10")) + typeName = "Log Signature File, Version 10"; + else + typeName = "unknown"; + + printf("%s: %s [%s]\n", name, hdr, typeName); + + if(fp != stdin) + fclose(fp); + return; +err: fprintf(stderr, "error %d processing file %s\n", r, name); +} + +static void +processFile(char *name) +{ + switch(mode) { + case MD_DETECT_FILE_TYPE: + detectFileType(name); + break; + case MD_DUMP: + dumpFile(name); + break; + } +} + + +static struct option long_options[] = +{ + {"dump", no_argument, NULL, 'D'}, + {"verbose", no_argument, NULL, 'v'}, + {"version", no_argument, NULL, 'V'}, + {"detect-file-type", no_argument, NULL, 'T'}, + {NULL, 0, NULL, 0} +}; + +int +main(int argc, char *argv[]) +{ + int i; + int opt; + + while(1) { + opt = getopt_long(argc, argv, "v", long_options, NULL); + if(opt == -1) + break; + switch(opt) { + case 'v': + verbose = 1; + break; + case 'V': + fprintf(stderr, "rsgtutil " VERSION "\n"); + exit(0); + case 'D': + mode = MD_DUMP; + break; + case 'T': + mode = MD_DETECT_FILE_TYPE; + break; + case '?': + break; + default:fprintf(stderr, "getopt_long() returns unknown value %d\n", opt); + return 1; + } + } + + if(optind == argc) + processFile("-"); + else { + for(i = optind ; i < argc ; ++i) + processFile(argv[i]); + } + + return 0; +} -- cgit v1.2.3