summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2018-11-16 03:46:52 +0300
committerDmitry Eremin-Solenikov <dbaryshkov@gmail.com>2018-11-26 16:56:34 +0300
commit2e6f022fda292eeedfb1289aa1593af4a31f77b6 (patch)
tree17d8f3e007008ff655e03634f8b58e4b26d1f68c
parentf9874f9feac63ea25d462d15ccdeb2d2f883298e (diff)
downloadgnutls-2e6f022fda292eeedfb1289aa1593af4a31f77b6.tar.gz
certtool: don't output textual information if --no-text was given
Disable text output if --no-text option was given for --p7-info and --p12-info. Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
-rw-r--r--src/certtool.c35
-rw-r--r--tests/cert-tests/data/key-corpus-rc2-1.p12.out2
2 files changed, 21 insertions, 16 deletions
diff --git a/src/certtool.c b/src/certtool.c
index e32541319f..2708b9e9b0 100644
--- a/src/certtool.c
+++ b/src/certtool.c
@@ -3249,7 +3249,7 @@ static const char *BAGTYPE(gnutls_pkcs12_bag_type_t x)
}
}
-static void print_bag_data(gnutls_pkcs12_bag_t bag)
+static void print_bag_data(gnutls_pkcs12_bag_t bag, int outtext)
{
int result;
int count, i, type;
@@ -3263,7 +3263,8 @@ static void print_bag_data(gnutls_pkcs12_bag_t bag)
app_exit(1);
}
- fprintf(outfile, "\tElements: %d\n", count);
+ if (outtext)
+ fprintf(outfile, "\tElements: %d\n", count);
for (i = 0; i < count; i++) {
type = gnutls_pkcs12_bag_get_type(bag, i);
@@ -3273,7 +3274,8 @@ static void print_bag_data(gnutls_pkcs12_bag_t bag)
app_exit(1);
}
- fprintf(outfile, "\tType: %s\n", BAGTYPE(type));
+ if (outtext)
+ fprintf(outfile, "\tType: %s\n", BAGTYPE(type));
result = gnutls_pkcs12_bag_get_data(bag, i, &cdata);
if (result < 0) {
@@ -3283,7 +3285,7 @@ static void print_bag_data(gnutls_pkcs12_bag_t bag)
}
if (type == GNUTLS_BAG_PKCS8_ENCRYPTED_KEY &&
- outcert_format == GNUTLS_X509_FMT_PEM)
+ outtext)
pkcs8_info_int(&cdata, GNUTLS_X509_FMT_DER, 1, outfile, "\t");
name = NULL;
@@ -3296,7 +3298,7 @@ static void print_bag_data(gnutls_pkcs12_bag_t bag)
app_exit(1);
}
- if (name)
+ if (name && outtext)
fprintf(outfile, "\tFriendly name: %s\n", name);
id.data = NULL;
@@ -3308,7 +3310,7 @@ static void print_bag_data(gnutls_pkcs12_bag_t bag)
app_exit(1);
}
- if (id.size > 0)
+ if (id.size > 0 && outtext)
fprintf(outfile, "\tKey ID: %s\n",
raw_to_string(id.data, id.size));
@@ -3338,7 +3340,7 @@ static void print_bag_data(gnutls_pkcs12_bag_t bag)
fprintf(stderr, "Error in base64 encoding: %s\n", gnutls_strerror(result));
app_exit(1);
}
- fprintf(outfile, "%s\n", out.data);
+ fprintf(outfile, "%s", out.data);
gnutls_free(out.data);
}
@@ -3436,11 +3438,11 @@ void pkcs12_info(common_info_st * cinfo)
salt_size = sizeof(salt);
result = gnutls_pkcs12_mac_info(pkcs12, &mac_algo, salt, &salt_size, &mac_iter, &mac_oid);
- if (result == GNUTLS_E_UNKNOWN_HASH_ALGORITHM) {
+ if (result == GNUTLS_E_UNKNOWN_HASH_ALGORITHM && cinfo->outtext) {
fprintf(outfile, "MAC info:\n");
if (mac_oid != NULL)
fprintf(outfile, "\tMAC: unknown (%s)\n", mac_oid);
- } else if (result >= 0) {
+ } else if (result >= 0 && cinfo->outtext) {
gnutls_datum_t bin;
fprintf(outfile, "MAC info:\n");
@@ -3491,7 +3493,8 @@ void pkcs12_info(common_info_st * cinfo)
app_exit(1);
}
- fprintf(outfile, "BAG #%d\n", indx);
+ if (cinfo->outtext)
+ fprintf(outfile, "%sBAG #%d\n", indx ? "\n" : "", indx);
result = gnutls_pkcs12_bag_get_type(bag, 0);
if (result < 0) {
@@ -3502,9 +3505,11 @@ void pkcs12_info(common_info_st * cinfo)
}
if (result == GNUTLS_BAG_ENCRYPTED) {
- fprintf(outfile, "\tType: %s\n", BAGTYPE(result));
- pkcs12_bag_enc_info(bag, outfile);
- fprintf(outfile, "\n\tDecrypting...\n");
+ if (cinfo->outtext) {
+ fprintf(outfile, "\tType: %s\n", BAGTYPE(result));
+ pkcs12_bag_enc_info(bag, outfile);
+ fprintf(outfile, "\n\tDecrypting...\n");
+ }
result = gnutls_pkcs12_bag_decrypt(bag, pass);
@@ -3525,7 +3530,7 @@ void pkcs12_info(common_info_st * cinfo)
}
}
- print_bag_data(bag);
+ print_bag_data(bag, cinfo->outtext);
gnutls_pkcs12_bag_deinit(bag);
}
@@ -3663,7 +3668,7 @@ void pkcs7_info(common_info_st *cinfo, unsigned display_data)
app_exit(1);
}
} else {
- if (outcert_format == GNUTLS_X509_FMT_PEM) {
+ if (cinfo->outtext) {
ret = gnutls_pkcs7_print(pkcs7, GNUTLS_CRT_PRINT_FULL, &str);
if (ret < 0) {
fprintf(stderr, "printing error: %s\n",
diff --git a/tests/cert-tests/data/key-corpus-rc2-1.p12.out b/tests/cert-tests/data/key-corpus-rc2-1.p12.out
index 6246ca31b9..1781059233 100644
--- a/tests/cert-tests/data/key-corpus-rc2-1.p12.out
+++ b/tests/cert-tests/data/key-corpus-rc2-1.p12.out
@@ -9,6 +9,7 @@ BAG #0
Schema: unsupported (1.2.840.113549.1.5.13)
Decrypting...
+
BAG #1
Elements: 1
Type: PKCS #8 Encrypted key
@@ -46,4 +47,3 @@ XPvobYe2HqIYKwkDOpP9wX7ClCiPoOlt7VKMuBJQy/1JFC6DRA7oBYmcZbZxw2uo
j/dC2cK5jsPC75a5+8HqySwQGlBGxlMOeyi/pKzSdWOdZ9NEshvTje/mnme3Hx05
JWamOc7reYsFpA==
-----END ENCRYPTED PRIVATE KEY-----
-