From f3cbb64e20f7f1f8dbeb5867c72828fdf7d73dca Mon Sep 17 00:00:00 2001 From: Binu Ramakrishnan Date: Thu, 10 Sep 2020 05:29:33 +0000 Subject: [PATCH] json escape fix --- CHANGELOG | 3 ++- cert-parser.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 24a1e47..dd09f7c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,9 +1,10 @@ tls-scan -- History of changes. Bug numbers referenced in this log correspond to bug numbers at our issue tracker, +Version 1.4.5 (2020-09-09) Version 1.4.4 (2020-09-08) ----------------------------------- -* Tag: https://github.com/prbinu/tls-scan/releases/tag/1.4.4 +* Tag: https://github.com/prbinu/tls-scan/releases/tag/1.4.5 * Fix JSON outout encode bug (#38) diff --git a/cert-parser.c b/cert-parser.c index eb7473b..6ad81bb 100644 --- a/cert-parser.c +++ b/cert-parser.c @@ -551,6 +551,7 @@ long ts_tls_get_options(int index) size_t ts_json_escape(char *data, size_t length, char *outbuffer, size_t outbuffer_length) { + int i, j=0; for (i = 0; i < length; i++) { switch (data[i]) { @@ -804,7 +805,14 @@ void ts_tls_print_json(struct tls_cert *tls_cert, FILE *fp, bool pretty) bool_to_str(tls_cert->verify_ocsp_basic), fmt); } - if (tls_cert->x509_chain_depth > 0) { + if (tls_cert->x509_chain_depth <= 0) { + fprintf(fp, "%.*s\"ocspStapled\": %s%c", FMT_INDENT(2), + bool_to_str(tls_cert->ocsp_stapling_response), fmt); + } else { + fprintf(fp, "%.*s\"ocspStapled\": %s,%c", FMT_INDENT(2), + bool_to_str(tls_cert->ocsp_stapling_response), fmt); + + fprintf(fp, "%.*s\"certificateChain\": [%c", FMT_INDENT(2), fmt); } @@ -844,8 +852,10 @@ void ts_tls_print_json(struct tls_cert *tls_cert, FILE *fp, bool pretty) if (tls_cert->x509[i].subject_cname) { BIO_get_mem_ptr(tls_cert->x509[i].subject_cname, &bptr); + oblen = ts_json_escape(bptr->data, bptr->length, &outbuffer[0], + outbuffer_length); fprintf(fp, "%.*s\"subjectCN\": \"%.*s\",%c", FMT_INDENT(4), - (int)bptr->length, bptr->data, fmt); + (int)oblen, outbuffer, fmt); } if (0 == i) {