/* * tlscerts.c * * Copyright (C) 2012 - 2019 James Booth * * This file is part of Profanity. * * Profanity is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Profanity is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Profanity. If not, see . * * In addition, as a special exception, the copyright holders give permission to * link the code of portions of this program with the OpenSSL library under * certain conditions as described in each individual source file, and * distribute linked combinations including the two. * * You must obey the GNU General Public License in all respects for all of the * code used other than OpenSSL. If you modify file(s) with this exception, you * may extend this exception to your version of the file(s), but you are not * obligated to do so. If you do not wish to do so, delete this exception * statement from your version. If you delete this exception statement from all * source files in the program, then also delete it here. * */ #include #include #include #include #include "log.h" #include "common.h" #include "config/files.h" #include "config/tlscerts.h" #include "tools/autocomplete.h" static char *tlscerts_loc; static GKeyFile *tlscerts; static void _save_tlscerts(void); static Autocomplete certs_ac; static char *current_fp; void tlscerts_init(void) { log_info("Loading TLS certificates"); tlscerts_loc = files_get_data_path(FILE_TLSCERTS); if (g_file_test(tlscerts_loc, G_FILE_TEST_EXISTS)) { g_chmod(tlscerts_loc, S_IRUSR | S_IWUSR); } tlscerts = g_key_file_new(); g_key_file_load_from_file(tlscerts, tlscerts_loc, G_KEY_FILE_KEEP_COMMENTS, NULL); certs_ac = autocomplete_new(); gsize len = 0; gchar **groups = g_key_file_get_groups(tlscerts, &len); int i = 0; for (i = 0; i < g_strv_length(groups); i++) { autocomplete_add(certs_ac, groups[i]); } g_strfreev(groups); current_fp = NULL; } void tlscerts_set_current(const char *const fp) { if (current_fp) { free(current_fp); } current_fp = strdup(fp); } char* tlscerts_get_current(void) { return current_fp; } void tlscerts_clear_current(void) { if (current_fp) { free(current_fp); current_fp = NULL; } } gboolean tlscerts_exists(const char *const fingerprint) { return g_key_file_has_group(tlscerts, fingerprint); } GList* tlscerts_list(void) { GList *res = NULL; gsize len = 0; gchar **groups = g_key_file_get_groups(tlscerts, &len); int i = 0; for (i = 0; i < g_strv_length(groups); i++) { char *fingerprint = strdup(groups[i]); int version = g_key_file_get_integer(tlscerts, fingerprint, "version", NULL); char *serialnumber = g_key_file_get_string(tlscerts, fingerprint, "serialnumber", NULL); char *subjectname = g_key_file_get_string(tlscerts, fingerprint, "subjectname", NULL); char *issuername = g_key_file_get_string(tlscerts, fingerprint, "issuername", NULL); char *notbefore = g_key_file_get_string(tlscerts, fingerprint, "start", NULL); char *notafter = g_key_file_get_string(tlscerts, fingerprint, "end", NULL); char *keyalg = g_key_file_get_string(tlscerts, fingerprint, "keyalg", NULL); char *signaturealg = g_key_file_get_string(tlscerts, fingerprint, "signaturealg", NULL); TLSCertificate *cert = tlscerts_new(fingerprint, version, serialnumber, subjectname, issuername, notbefore, notafter, keyalg, signaturealg); free(fingerprint); free(serialnumber); free(subjectname); free(issuername); free(notbefore); free(notafter); free(keyalg); free(signaturealg); res = g_list_append(res, cert); } if (groups) { g_strfreev(groups); } return res; } TLSCertificate* tlscerts_new(const char *const fingerprint, int version, const char *const serialnumber, const char *const subjectname, const char *const issuername, const char *const notbefore, const char *const notafter, const char *const key_alg, const char *const signature_alg) { TLSCertificate *cert = malloc(sizeof(TLSCertificate)); if (fingerprint) { cert->fingerprint = strdup(fingerprint); } else { cert->fingerprint = NULL; } cert->version = version; if (serialnumber) { cert->serialnumber = strdup(serialnumber); } else { cert->serialnumber = NULL; } if (subjectname) { cert->subjectname = strdup(subjectname); } else { cert->subjectname = NULL; } if (issuername) { cert->issuername = strdup(issuername); } else { cert->issuername = NULL; } if (notbefore) { cert->notbefore = strdup(notbefore); } else { cert->notbefore = NULL; } if (notafter) { cert->notafter = strdup(notafter); } else { cert->notafter = NULL; } if (key_alg) { cert->key_alg = strdup(key_alg); } else { cert->key_alg = NULL; } if (signature_alg) { cert->signature_alg = strdup(signature_alg); } else { cert->signature_alg = NULL; } cert->subject_country = NULL; cert->subject_state = NULL; cert->subject_distinguishedname = NULL; cert->subject_serialnumber = NULL; cert->subject_commonname = NULL; cert->subject_organisation =
### A debugging helper that lets you zoom in/out on a trace.

To try it out, first create an example trace (from the top-level `mu/`
directory):

  ```shell
  ./subx --trace run apps/factorial
  ```

This command will save a trace of its execution in a file called `last_run`.
The trace consists of a series of lines, each starting with an integer depth
and a single-word 'label', followed by a colon and whitespace.

Now browse this trace:

  ```shell
  tools/browse_trace last_run
  ```

You should now find yourself in a UI showing a subsequence of lines from the
trace, each line starting with a numeric depth, and ending with a parenthetical
count of trace lines hidden after it with greater depths.

For example, this line:

  ```
  2 app: line1 (30)
  ```

indicates that it was logged with depth 2, and that 30 following lines have
been hidden at a depth greater than 2.

(As an experiment, hidden counts of 1000 or more are highlighted in red.)

The UI provides the following hotkeys:

* `q` or `ctrl-c`: Quit.

* `Enter`: 'Zoom into' this line. Expand lines hidden after it that were at
  the next higher level.

* `Backspace`: 'Zoom out' on a line after zooming in, collapsing lines below
  expanded by some series of `Enter` commands.

* `j` or `down-arrow`: Move cursor down one line.
* `k` or `up-arrow`: Move cursor up one line.
* `J` or `ctrl-f` or `page-down`: Scroll cursor down one page.
* `K`