From d96a92aa533a07ea10e57553aa167b1b0151bcac Mon Sep 17 00:00:00 2001 From: Daniel Golle Date: Mon, 4 Jun 2018 23:54:09 +0200 Subject: [PATCH] add shim executable and CMakeLists Signed-off-by: Daniel Golle This work was sponsored by WIO (wiowireless.com) --- CMakeLists.txt | 12 ++++ ucert.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 ucert.c diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..5b63312 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 2.6) + +PROJECT(ucert C) +ADD_DEFINITIONS(-Os -ggdb -Wall --std=gnu99 -Wmissing-declarations) + +SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") + +find_library(json NAMES json-c json) + +ADD_EXECUTABLE(ucert ucert.c) +TARGET_LINK_LIBRARIES(ucert ubox blobmsg_json ${json}) +INSTALL(TARGETS ucert RUNTIME DESTINATION bin) diff --git a/ucert.c b/ucert.c new file mode 100644 index 0000000..54ec223 --- /dev/null +++ b/ucert.c @@ -0,0 +1,179 @@ +/* + * Copyright (C) 2018 Daniel Golle + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 + * as published by the Free Software Foundation + * + * 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. + */ + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static enum { + CMD_APPEND, + CMD_DUMP, + CMD_ISSUE, + CMD_REVOKE, + CMD_VERIFY, + CMD_NONE, +} cmd = CMD_NONE; + +static bool quiet; + +static int cert_append(const char *certfile, const char *pubkeyfile, const char *sigfile) { + fprintf(stderr, "not implemented\n"); + return 1; +} + +static int cert_dump(const char *certfile) { + fprintf(stderr, "not implemented\n"); + return 1; +} + +static int cert_issue(const char *certfile, const char *pubkeyfile, const char *seckeyfile) { + fprintf(stderr, "not implemented\n"); + return 1; +} + +static int cert_process_revoker(const char *certfile) { + fprintf(stderr, "not implemented\n"); + return 1; +} + +static int cert_verify(const char *certfile, const char *pubkeyfile, const char *pubkeydir, const char *msgfile) { + fprintf(stderr, "not implemented\n"); + return 1; +} + +static int usage(const char *cmd) +{ + fprintf(stderr, + "Usage: %s \n" + "Commands:\n" + " -A: append (needs -c and -p and/or -x)\n" + " -D: dump\n" + " -I: issue cert and revoker (needs -c and -p and -s)\n" + " -R: process revoker certificate (needs -c)\n" + " -V: verify (needs -c and -p|-P)\n" + "Options:\n" + " -c : certificate file\n" + " -m : message file (verify only)\n" + " -p : public key file\n" + " -P : public key directory (verify only)\n" + " -q: quiet (do not print verification result, use return code only)\n" + " -s : secret key file (issue only)\n" + " -x : signature file\n" + "\n", + cmd); + return 1; +} + +int main(int argc, char *argv[]) { + int ch; + const char *msgfile = NULL; + const char *sigfile = NULL; + const char *pubkeyfile = NULL; + const char *pubkeydir = NULL; + const char *certfile = NULL; + const char *seckeyfile = NULL; + + quiet = false; + while ((ch = getopt(argc, argv, "ADIRVc:m:p:P:qs:x:")) != -1) { + switch (ch) { + case 'A': + cmd = CMD_APPEND; + break; + case 'D': + cmd = CMD_DUMP; + break; + case 'I': + cmd = CMD_ISSUE; + break; + case 'R': + cmd = CMD_REVOKE; + break; + case 'V': + cmd = CMD_VERIFY; + break; + case 'c': + certfile = optarg; + break; + case 'm': + msgfile = optarg; + break; + case 'p': + pubkeyfile = optarg; + break; + case 'P': + pubkeydir = optarg; + break; + case 's': + seckeyfile = optarg; + break; + case 'q': + quiet = true; + break; + case 'x': + sigfile = optarg; + break; + default: + return usage(argv[0]); + } + } + + switch (cmd) { + case CMD_APPEND: + if (certfile && (pubkeyfile || sigfile)) + return cert_append(certfile, pubkeyfile, sigfile); + else + return usage(argv[0]); + case CMD_DUMP: + if (certfile) + return cert_dump(certfile); + else + return usage(argv[0]); + case CMD_ISSUE: + if (certfile && pubkeyfile && seckeyfile) + return cert_issue(certfile, pubkeyfile, seckeyfile); + else + return usage(argv[0]); + case CMD_REVOKE: + if (certfile) + return cert_process_revoker(certfile); + else + return usage(argv[0]); + case CMD_VERIFY: + if (certfile && (pubkeyfile || pubkeydir)) + return cert_verify(certfile, pubkeyfile, pubkeydir, msgfile); + else + return usage(argv[0]); + case CMD_NONE: + return usage(argv[0]); + } + + /* unreachable */ + return usage(argv[0]); +} -- 2.25.1