Skip to content

Commit

Permalink
json escape fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tls-scan committed Sep 10, 2020
1 parent 17b8fe8 commit f3cbb64
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
14 changes: 12 additions & 2 deletions cert-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f3cbb64

Please sign in to comment.