enable debug level setting

This commit is contained in:
Andreas Steffen
2009-09-14 19:29:05 +02:00
parent af0dfe4987
commit 5a4dee6dc4
8 changed files with 61 additions and 1 deletions
+4
View File
@@ -32,6 +32,9 @@ static int gen(int argc, char *argv[])
{ {
case 'h': case 'h':
return command_usage(NULL); return command_usage(NULL);
case 'v':
dbg_level = atoi(optarg);
continue;
case 't': case 't':
if (streq(optarg, "rsa")) if (streq(optarg, "rsa"))
{ {
@@ -118,6 +121,7 @@ static void __attribute__ ((constructor))reg()
{"type", 't', 1, "type of key, default: rsa"}, {"type", 't', 1, "type of key, default: rsa"},
{"size", 's', 1, "keylength in bits, default: rsa 2048, ecdsa 384"}, {"size", 's', 1, "keylength in bits, default: rsa 2048, ecdsa 384"},
{"outform", 'f', 1, "encoding of generated private key"}, {"outform", 'f', 1, "encoding of generated private key"},
{"debug", 'v', 1, "set debug level, default: 1"},
} }
}); });
} }
+11 -1
View File
@@ -17,6 +17,7 @@
#include "pki.h" #include "pki.h"
#include <debug.h>
#include <utils/linked_list.h> #include <utils/linked_list.h>
#include <utils/optionsfrom.h> #include <utils/optionsfrom.h>
#include <credentials/certificates/certificate.h> #include <credentials/certificates/certificate.h>
@@ -56,6 +57,9 @@ static int issue(int argc, char *argv[])
{ {
case 'h': case 'h':
goto usage; goto usage;
case 'v':
dbg_level = atoi(optarg);
continue;
case '+': case '+':
if (!options->from(options, optarg, &argc, &argv, optind)) if (!options->from(options, optarg, &argc, &argv, optind))
{ {
@@ -150,6 +154,8 @@ static int issue(int argc, char *argv[])
goto end; goto end;
} }
} }
DBG2("Reading ca certificate:");
ca = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509, ca = lib->creds->create(lib->creds, CRED_CERTIFICATE, CERT_X509,
BUILD_FROM_FILE, cacert, BUILD_END); BUILD_FROM_FILE, cacert, BUILD_END);
if (!ca) if (!ca)
@@ -163,13 +169,14 @@ static int issue(int argc, char *argv[])
error = "CA certificate misses CA basicConstraint"; error = "CA certificate misses CA basicConstraint";
goto end; goto end;
} }
public = ca->get_public_key(ca); public = ca->get_public_key(ca);
if (!public) if (!public)
{ {
error = "extracting CA certificate public key failed"; error = "extracting CA certificate public key failed";
goto end; goto end;
} }
DBG2("Reading ca private key:");
private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, private = lib->creds->create(lib->creds, CRED_PRIVATE_KEY,
public->get_type(public), public->get_type(public),
BUILD_FROM_FILE, cakey, BUILD_END); BUILD_FROM_FILE, cakey, BUILD_END);
@@ -208,6 +215,7 @@ static int issue(int argc, char *argv[])
identification_t *subjectAltName; identification_t *subjectAltName;
pkcs10_t *req; pkcs10_t *req;
DBG2("Reading certificate request");
if (file) if (file)
{ {
cert_req = lib->creds->create(lib->creds, CRED_CERTIFICATE, cert_req = lib->creds->create(lib->creds, CRED_CERTIFICATE,
@@ -247,6 +255,7 @@ static int issue(int argc, char *argv[])
} }
else else
{ {
DBG2("Reading public key:");
if (file) if (file)
{ {
public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY, public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_ANY,
@@ -348,6 +357,7 @@ static void __attribute__ ((constructor))reg()
{"crl", 'u', 1, "CRL distribution point URI to include"}, {"crl", 'u', 1, "CRL distribution point URI to include"},
{"ocsp", 'o', 1, "OCSP AuthorityInfoAccess URI to include"}, {"ocsp", 'o', 1, "OCSP AuthorityInfoAccess URI to include"},
{"digest", 'g', 1, "digest for signature creation, default: sha1"}, {"digest", 'g', 1, "digest for signature creation, default: sha1"},
{"debug", 'v', 1, "set debug level, default: 1"},
{"options", '+', 1, "read command line options from file"}, {"options", '+', 1, "read command line options from file"},
} }
}); });
+4
View File
@@ -38,6 +38,9 @@ static int keyid(int argc, char *argv[])
{ {
case 'h': case 'h':
return command_usage(NULL); return command_usage(NULL);
case 'v':
dbg_level = atoi(optarg);
continue;
case 't': case 't':
if (streq(optarg, "rsa-priv")) if (streq(optarg, "rsa-priv"))
{ {
@@ -152,6 +155,7 @@ static void __attribute__ ((constructor))reg()
{"help", 'h', 0, "show usage information"}, {"help", 'h', 0, "show usage information"},
{"in", 'i', 1, "input file, default: stdin"}, {"in", 'i', 1, "input file, default: stdin"},
{"type", 't', 1, "type of key, default: rsa-priv"}, {"type", 't', 1, "type of key, default: rsa-priv"},
{"debug", 'v', 1, "set debug level, default: 1"},
} }
}); });
} }
+4
View File
@@ -39,6 +39,9 @@ static int pub(int argc, char *argv[])
{ {
case 'h': case 'h':
return command_usage(NULL); return command_usage(NULL);
case 'v':
dbg_level = atoi(optarg);
continue;
case 't': case 't':
if (streq(optarg, "rsa")) if (streq(optarg, "rsa"))
{ {
@@ -145,6 +148,7 @@ static void __attribute__ ((constructor))reg()
{"in", 'i', 1, "input file, default: stdin"}, {"in", 'i', 1, "input file, default: stdin"},
{"type", 't', 1, "type of credential, default: rsa"}, {"type", 't', 1, "type of credential, default: rsa"},
{"outform", 'f', 1, "encoding of extracted public key"}, {"outform", 'f', 1, "encoding of extracted public key"},
{"debug", 'v', 1, "set debug level, default: 1"},
} }
}); });
} }
+4
View File
@@ -52,6 +52,9 @@ static int self(int argc, char *argv[])
{ {
case 'h': case 'h':
goto usage; goto usage;
case 'v':
dbg_level = atoi(optarg);
continue;
case '+': case '+':
if (!options->from(options, optarg, &argc, &argv, optind)) if (!options->from(options, optarg, &argc, &argv, optind))
{ {
@@ -240,6 +243,7 @@ static void __attribute__ ((constructor))reg()
{"ca", 'b', 0, "include CA basicConstraint, default: no"}, {"ca", 'b', 0, "include CA basicConstraint, default: no"},
{"ocsp", 'o', 1, "OCSP AuthorityInfoAccess URI to include"}, {"ocsp", 'o', 1, "OCSP AuthorityInfoAccess URI to include"},
{"digest", 'g', 1, "digest for signature creation, default: sha1"}, {"digest", 'g', 1, "digest for signature creation, default: sha1"},
{"debug", 'v', 1, "set debug level, default: 1"},
{"options", '+', 1, "read command line options from file"}, {"options", '+', 1, "read command line options from file"},
} }
}); });
+4
View File
@@ -33,6 +33,9 @@ static int verify(int argc, char *argv[])
{ {
case 'h': case 'h':
return command_usage(NULL); return command_usage(NULL);
case 'v':
dbg_level = atoi(optarg);
continue;
case 'i': case 'i':
file = optarg; file = optarg;
continue; continue;
@@ -129,6 +132,7 @@ static void __attribute__ ((constructor))reg()
{"help", 'h', 0, "show usage information"}, {"help", 'h', 0, "show usage information"},
{"in", 'i', 1, "x509 certifcate to verify, default: stdin"}, {"in", 'i', 1, "x509 certifcate to verify, default: stdin"},
{"cacert", 'c', 1, "CA certificate, default: verify self signed"}, {"cacert", 'c', 1, "CA certificate, default: verify self signed"},
{"debug", 'v', 1, "set debug level, default: 1"},
} }
}); });
} }
+25
View File
@@ -16,6 +16,29 @@
#include "command.h" #include "command.h"
#include "pki.h" #include "pki.h"
#include <debug.h>
/**
* Default debug level
*/
int dbg_level = 1;
/**
* Logging to stderr with configurable debug level
*/
void dbg_pki(int level, char *fmt, ...)
{
if (level <= dbg_level)
{
va_list args;
va_start(args, fmt);
vfprintf(stderr, fmt, args);
fprintf(stderr, "\n");
va_end(args);
}
}
/** /**
* Convert a form string to a encoding type * Convert a form string to a encoding type
*/ */
@@ -78,6 +101,8 @@ hash_algorithm_t get_digest(char *name)
*/ */
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
dbg = dbg_pki;
atexit(library_deinit); atexit(library_deinit);
if (!library_init(NULL)) if (!library_init(NULL))
{ {
+5
View File
@@ -26,6 +26,11 @@
#include <library.h> #include <library.h>
#include <credentials/keys/private_key.h> #include <credentials/keys/private_key.h>
/**
* Defines the settable debug level
*/
extern int dbg_level;
/** /**
* Convert a form string to a encoding type * Convert a form string to a encoding type
*/ */