summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorJob Snijders <job@cvs.openbsd.org>2023-03-07 14:49:33 +0000
committerJob Snijders <job@cvs.openbsd.org>2023-03-07 14:49:33 +0000
commit7750743128338ba2cc92e4267da11d0d2cc50143 (patch)
treef798934dec297f78c08dfbf7f6e38ecbe07d7f0b /usr.sbin
parent6564e8250d8315c63fea2d6fcb0a5039b9616b35 (diff)
Improve decoded content printing in filemode
Looks reasonable claudio@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rpki-client/filemode.c10
-rw-r--r--usr.sbin/rpki-client/print.c137
2 files changed, 96 insertions, 51 deletions
diff --git a/usr.sbin/rpki-client/filemode.c b/usr.sbin/rpki-client/filemode.c
index 9d0c7ebd576..e1c59aa2387 100644
--- a/usr.sbin/rpki-client/filemode.c
+++ b/usr.sbin/rpki-client/filemode.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: filemode.c,v 1.20 2023/03/03 16:19:05 job Exp $ */
+/* $OpenBSD: filemode.c,v 1.21 2023/03/07 14:49:32 job Exp $ */
/*
* Copyright (c) 2019 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -421,8 +421,12 @@ proc_parser_file(char *file, unsigned char *buf, size_t len)
if (outformats & FORMAT_JSON)
printf("\t\"validation\": \"");
- else
- printf("Validation: ");
+ else {
+ if (type == RTYPE_CRL)
+ printf("Validation: N/A\n");
+ else
+ printf("Validation: ");
+ }
if (aia != NULL) {
struct auth *a;
diff --git a/usr.sbin/rpki-client/print.c b/usr.sbin/rpki-client/print.c
index aceb8db7fbe..05bf8f0523f 100644
--- a/usr.sbin/rpki-client/print.c
+++ b/usr.sbin/rpki-client/print.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: print.c,v 1.26 2023/01/10 13:26:34 job Exp $ */
+/* $OpenBSD: print.c,v 1.27 2023/03/07 14:49:32 job Exp $ */
/*
* Copyright (c) 2021 Claudio Jeker <claudio@openbsd.org>
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -104,9 +104,12 @@ tal_print(const struct tal *p)
} else {
printf("Trust anchor name: %s\n", p->descr);
printf("Subject key identifier: %s\n", pretty_key_id(ski));
- printf("Trust anchor locations:\n");
- for (i = 0; i < p->urisz; i++)
- printf("%5zu: %s\n", i + 1, p->uri[i]);
+ printf("Trust anchor locations: ");
+ for (i = 0; i < p->urisz; i++) {
+ if (i > 0)
+ printf("%26s", "");
+ printf("%s\n", p->uri[i]);
+ }
}
EVP_PKEY_free(pk);
@@ -203,7 +206,7 @@ cert_print(const struct cert *p)
} else
printf("Certificate valid until: %s\n",
time2str(p->expires));
- printf("Subordinate resources:\n");
+ printf("Subordinate resources: ");
}
for (i = 0; i < p->asz; i++) {
@@ -211,23 +214,32 @@ cert_print(const struct cert *p)
case CERT_AS_ID:
if (outformats & FORMAT_JSON)
printf("\t\t{ \"asid\": %u }", p->as[i].id);
- else
- printf("%5zu: AS: %u", i + 1, p->as[i].id);
+ else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("AS: %u", p->as[i].id);
+ }
break;
case CERT_AS_INHERIT:
if (outformats & FORMAT_JSON)
printf("\t\t{ \"asid_inherit\": \"true\" }");
- else
- printf("%5zu: AS: inherit", i + 1);
+ else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("AS: inherit");
+ }
break;
case CERT_AS_RANGE:
if (outformats & FORMAT_JSON)
printf("\t\t{ \"asrange\": { \"min\": %u, "
"\"max\": %u }}", p->as[i].range.min,
p->as[i].range.max);
- else
- printf("%5zu: AS: %u -- %u", i + 1,
- p->as[i].range.min, p->as[i].range.max);
+ else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("AS: %u -- %u", p->as[i].range.min,
+ p->as[i].range.max);
+ }
break;
}
if (outformats & FORMAT_JSON && i + 1 < p->asz + p->ipsz)
@@ -241,16 +253,22 @@ cert_print(const struct cert *p)
case CERT_IP_INHERIT:
if (outformats & FORMAT_JSON)
printf("\t\t{ \"ip_inherit\": \"true\" }");
- else
- printf("%5zu: IP: inherit", i + j + 1);
+ else {
+ if (i > 0 || j > 0)
+ printf("%26s", "");
+ printf("IP: inherit");
+ }
break;
case CERT_IP_ADDR:
ip_addr_print(&p->ips[j].ip,
p->ips[j].afi, buf1, sizeof(buf1));
if (outformats & FORMAT_JSON)
printf("\t\t{ \"ip_prefix\": \"%s\" }", buf1);
- else
- printf("%5zu: IP: %s", i + j + 1, buf1);
+ else {
+ if (i > 0 || j > 0)
+ printf("%26s", "");
+ printf("IP: %s", buf1);
+ }
break;
case CERT_IP_RANGE:
sockt = (p->ips[j].afi == AFI_IPV4) ?
@@ -260,9 +278,11 @@ cert_print(const struct cert *p)
if (outformats & FORMAT_JSON)
printf("\t\t{ \"ip_range\": { \"min\": \"%s\""
", \"max\": \"%s\" }}", buf1, buf2);
- else
- printf("%5zu: IP: %s -- %s", i + j + 1, buf1,
- buf2);
+ else {
+ if (i > 0 || j > 0)
+ printf("%26s", "");
+ printf("IP: %s -- %s", buf1, buf2);
+ }
break;
}
if (outformats & FORMAT_JSON && i + j + 1 < p->asz + p->ipsz)
@@ -333,8 +353,8 @@ crl_print(const struct crl *p)
printf(",");
printf("\n");
} else
- printf(" Serial: %8s Revocation Date: %s"
- "\n", serial, time2str(t));
+ printf("%25s Serial: %8s Revocation Date: %s"
+ "\n", "", serial, time2str(t));
}
free(serial);
}
@@ -370,7 +390,7 @@ mft_print(const X509 *x, const struct mft *p)
printf("Manifest Number: %s\n", p->seqnum);
printf("Manifest valid since: %s\n", time2str(p->valid_since));
printf("Manifest valid until: %s\n", time2str(p->valid_until));
- printf("Files and hashes:\n");
+ printf("Files and hashes: ");
}
for (i = 0; i < p->filesz; i++) {
@@ -388,8 +408,10 @@ mft_print(const X509 *x, const struct mft *p)
printf(",");
printf("\n");
} else {
- printf("%5zu: %s\n", i + 1, p->files[i].file);
- printf("\thash %s\n", hash);
+ if (i > 0)
+ printf("%26s", "");
+ printf("%zu: %s (hash: %s)\n", i + 1, p->files[i].file,
+ hash);
}
free(hash);
@@ -421,7 +443,7 @@ roa_print(const X509 *x, const struct roa *p)
printf("Subject info access: %s\n", p->sia);
printf("ROA valid until: %s\n", time2str(p->expires));
printf("asID: %u\n", p->asid);
- printf("IP address blocks:\n");
+ printf("IP address blocks: ");
}
for (i = 0; i < p->ipsz; i++) {
@@ -438,9 +460,11 @@ roa_print(const X509 *x, const struct roa *p)
if (i + 1 < p->ipsz)
printf(",");
printf("\n");
- } else
- printf("%5zu: %s maxlen: %hhu\n", i + 1, buf,
- p->ips[i].maxlength);
+ } else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("%s maxlen: %hhu\n", buf, p->ips[i].maxlength);
+ }
}
if (outformats & FORMAT_JSON)
@@ -502,7 +526,7 @@ rsc_print(const X509 *x, const struct rsc *p)
x509_print(x);
printf("Authority info access: %s\n", p->aia);
printf("RSC valid until: %s\n", time2str(p->expires));
- printf("Signed with resources:\n");
+ printf("Signed with resources: ");
}
for (i = 0; i < p->asz; i++) {
@@ -510,17 +534,23 @@ rsc_print(const X509 *x, const struct rsc *p)
case CERT_AS_ID:
if (outformats & FORMAT_JSON)
printf("\t\t{ \"asid\": %u }", p->as[i].id);
- else
- printf("%5zu: AS: %u", i + 1, p->as[i].id);
+ else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("AS: %u", p->as[i].id);
+ }
break;
case CERT_AS_RANGE:
if (outformats & FORMAT_JSON)
printf("\t\t{ \"asrange\": { \"min\": %u, "
"\"max\": %u }}", p->as[i].range.min,
p->as[i].range.max);
- else
- printf("%5zu: AS: %u -- %u", i + 1,
- p->as[i].range.min, p->as[i].range.max);
+ else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("AS: %u -- %u", p->as[i].range.min,
+ p->as[i].range.max);
+ }
break;
case CERT_AS_INHERIT:
/* inheritance isn't possible in RSC */
@@ -539,8 +569,11 @@ rsc_print(const X509 *x, const struct rsc *p)
p->ips[j].afi, buf1, sizeof(buf1));
if (outformats & FORMAT_JSON)
printf("\t\t{ \"ip_prefix\": \"%s\" }", buf1);
- else
- printf("%5zu: IP: %s", i + j + 1, buf1);
+ else {
+ if (i > 0 || j > 0)
+ printf("%26s", "");
+ printf("IP: %s", buf1);
+ }
break;
case CERT_IP_RANGE:
sockt = (p->ips[j].afi == AFI_IPV4) ?
@@ -550,9 +583,11 @@ rsc_print(const X509 *x, const struct rsc *p)
if (outformats & FORMAT_JSON)
printf("\t\t{ \"ip_range\": { \"min\": \"%s\""
", \"max\": \"%s\" }}", buf1, buf2);
- else
- printf("%5zu: IP: %s -- %s", i + j + 1, buf1,
- buf2);
+ else {
+ if (i > 0 || j > 0)
+ printf("%26s", "");
+ printf("IP: %s -- %s", buf1, buf2);
+ }
break;
case CERT_IP_INHERIT:
/* inheritance isn't possible in RSC */
@@ -568,7 +603,7 @@ rsc_print(const X509 *x, const struct rsc *p)
printf("\t],\n");
printf("\t\"filenamesandhashes\": [\n");
} else
- printf("Filenames and hashes:\n");
+ printf("Filenames and hashes: ");
for (i = 0; i < p->filesz; i++) {
if (base64_encode(p->files[i].hash, sizeof(p->files[i].hash),
@@ -583,9 +618,11 @@ rsc_print(const X509 *x, const struct rsc *p)
printf(",");
printf("\n");
} else {
- printf("%5zu: %s\n", i + 1, p->files[i].filename
- ? p->files[i].filename : "no filename");
- printf("\thash %s\n", hash);
+ if (i > 0)
+ printf("%26s", "");
+ printf("%zu: %s (hash: %s)\n", i + 1,
+ p->files[i].filename ? p->files[i].filename
+ : "no filename", hash);
}
free(hash);
@@ -630,9 +667,11 @@ aspa_print(const X509 *x, const struct aspa *p)
printf("Subject info access: %s\n", p->sia);
printf("ASPA valid until: %s\n", time2str(p->expires));
printf("Customer AS: %u\n", p->custasid);
- printf("Provider Set:\n");
+ printf("Provider Set: ");
for (i = 0; i < p->providersz; i++) {
- printf("%5zu: AS: %d", i + 1, p->providers[i].as);
+ if (i > 0)
+ printf("%26s", "");
+ printf("AS: %d", p->providers[i].as);
switch (p->providers[i].afi) {
case AFI_IPV4:
printf(" (IPv4 only)");
@@ -771,9 +810,11 @@ geofeed_print(const X509 *x, const struct geofeed *p)
if (outformats & FORMAT_JSON)
printf("\t\t{ \"prefix\": \"%s\", \"location\": \"%s\""
"}", buf, p->geoips[i].loc);
- else
- printf("%5zu: IP: %s (%s)", i + 1, buf,
- p->geoips[i].loc);
+ else {
+ if (i > 0)
+ printf("%26s", "");
+ printf("IP: %s (%s)", buf, p->geoips[i].loc);
+ }
if (outformats & FORMAT_JSON && i + 1 < p->geoipsz)
printf(",\n");