hxtool: Add OID symbol resolution

This commit is contained in:
Nicolas Williams
2019-08-24 17:02:51 -05:00
parent 5465b2ddec
commit 93e48f8fba
2 changed files with 63 additions and 7 deletions

View File

@@ -32,6 +32,13 @@
*/
/* $Id$ */
command = {
name = "list-oids"
help = "List known OIDs"
function = "hxtool_list_oids"
min_args="0"
max_args="0"
}
command = {
name = "cms-create-sd"
name = "cms-sign"
@@ -171,6 +178,11 @@ command = {
type = "string"
help = "file containing content"
}
option = {
long = "oid-sym"
type = "flag"
help = "show symbolic name for OID"
}
min_args="1"
max_args="2"
argument="in-file [out-file]"
@@ -575,6 +587,11 @@ command = {
type = "string"
help = "type of CMS algorithm"
}
option = {
long = "oid-syms"
type = "flag"
help = "show symbolic names for OIDs"
}
name = "crypto-available"
min_args="0"
help = "Print available CMS crypto types"
@@ -595,6 +612,11 @@ command = {
type = "strings"
help = "peer limiting cmstypes"
}
option = {
long = "oid-sym"
type = "flag"
help = "show symbolic name for OID"
}
name = "crypto-select"
min_args="0"
help = "Print selected CMS type"

View File

@@ -101,11 +101,19 @@ static void
parse_oid(const char *str, const heim_oid *def, heim_oid *oid)
{
int ret;
if (str)
ret = der_parse_heim_oid (str, " .", oid);
else
if (str) {
const heim_oid *found = NULL;
ret = der_find_heim_oid_by_name(str, &found);
if (ret == 0)
ret = der_copy_oid(found, oid);
else
ret = der_parse_heim_oid (str, " .", oid);
} else {
ret = der_copy_oid(def, oid);
if (ret)
}
if (ret)
errx(1, "parse_oid failed for: %s", str ? str : "default oid");
}
@@ -296,7 +304,10 @@ cms_verify_sd(struct cms_verify_sd_options *opt, int argc, char **argv)
{
char *str;
der_print_heim_oid(&type, '.', &str);
if (opt->oid_sym_flag)
der_print_heim_oid_sym(&type, '.', &str);
else
der_print_heim_oid(&type, '.', &str);
printf("type: %s\n", str);
free(str);
der_free_oid(&type);
@@ -1530,7 +1541,10 @@ crypto_available(struct crypto_available_options *opt, int argc, char **argv)
for (i = 0; i < len; i++) {
char *s;
der_print_heim_oid (&val[i].algorithm, '.', &s);
if (opt->oid_syms_flag)
der_print_heim_oid_sym(&val[i].algorithm, '.', &s);
else
der_print_heim_oid(&val[i].algorithm, '.', &s);
printf("%s\n", s);
free(s);
}
@@ -1566,7 +1580,10 @@ crypto_select(struct crypto_select_options *opt, int argc, char **argv)
if (ret)
errx(1, "hx509_crypto_available");
der_print_heim_oid (&selected.algorithm, '.', &s);
if (opt->oid_sym_flag)
der_print_heim_oid_sym(&selected.algorithm, '.', &s);
else
der_print_heim_oid(&selected.algorithm, '.', &s);
printf("%s\n", s);
free(s);
free_AlgorithmIdentifier(&selected);
@@ -2288,6 +2305,23 @@ crl_sign(struct crl_sign_options *opt, int argc, char **argv)
return 0;
}
int
hxtool_list_oids(void *opt, int argc, char **argv)
{
const heim_oid *oid;
int cursor = -1;
while (der_match_heim_oid_by_name("", &cursor, &oid) == 0) {
char *s = NULL;
if ((errno = der_print_heim_oid_sym(oid, '.', &s)) > 0)
err(1, "der_print_heim_oid_sym");
printf("%s\n", s);
free(s);
}
return 0;
}
/*
*
*/