1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added /tls trusted command

This commit is contained in:
James Booth 2015-09-24 00:43:41 +01:00
parent d96e68ea53
commit 6f8ad6b8e8
4 changed files with 67 additions and 0 deletions

View File

@ -195,6 +195,7 @@ static struct cmd_t command_defs[] =
"/tls allow", "/tls allow",
"/tls always", "/tls always",
"/tls deny", "/tls deny",
"/tls trusted",
"/tls certpath", "/tls certpath",
"/tls certpath set <path>", "/tls certpath set <path>",
"/tls certpath clear") "/tls certpath clear")
@ -204,6 +205,7 @@ static struct cmd_t command_defs[] =
{ "allow", "Allow connection to continue with an invalid TLS certificate." }, { "allow", "Allow connection to continue with an invalid TLS certificate." },
{ "always", "Always allow connections with this invalid TLS certificate." }, { "always", "Always allow connections with this invalid TLS certificate." },
{ "deny", "Terminate TLS connection." }, { "deny", "Terminate TLS connection." },
{ "trusted", "List manually trusted certificates." },
{ "certpath", "Show the trusted certificate path." }, { "certpath", "Show the trusted certificate path." },
{ "certpath set <path>", "Specify filesystem path containing trusted certificates." }, { "certpath set <path>", "Specify filesystem path containing trusted certificates." },
{ "certpath clear", "Clear the trusted certificate path." }) { "certpath clear", "Clear the trusted certificate path." })
@ -2100,6 +2102,7 @@ cmd_init(void)
autocomplete_add(tls_ac, "allow"); autocomplete_add(tls_ac, "allow");
autocomplete_add(tls_ac, "always"); autocomplete_add(tls_ac, "always");
autocomplete_add(tls_ac, "deny"); autocomplete_add(tls_ac, "deny");
autocomplete_add(tls_ac, "trusted");
autocomplete_add(tls_ac, "certpath"); autocomplete_add(tls_ac, "certpath");
tls_certpath_ac = autocomplete_new(); tls_certpath_ac = autocomplete_new();

View File

@ -49,6 +49,7 @@
#include "config/account.h" #include "config/account.h"
#include "config/preferences.h" #include "config/preferences.h"
#include "config/theme.h" #include "config/theme.h"
#include "config/tlscerts.h"
#include "contact.h" #include "contact.h"
#include "roster_list.h" #include "roster_list.h"
#include "jid.h" #include "jid.h"
@ -190,6 +191,39 @@ cmd_tls(ProfWin *window, const char * const command, gchar **args)
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
return TRUE; return TRUE;
} }
} else if (g_strcmp0(args[0], "trusted") == 0) {
GList *certs = tlscerts_list();
GList *curr = certs;
if (curr) {
cons_show("Trusted certificates:");
cons_show("");
}
while (curr) {
TLSCertificate *cert = curr->data;
if (cert->domain) {
cons_show("Domain : %s", cert->domain);
}
if (cert->organisation) {
cons_show("Organisation : %s", cert->organisation);
}
if (cert->email) {
cons_show("Email : %s", cert->email);
}
if (cert->notbefore) {
cons_show("Start : %s", cert->notbefore);
}
if (cert->notafter) {
cons_show("End : %s", cert->notafter);
}
if (cert->fingerprint) {
cons_show("Fingerprint : %s", cert->fingerprint);
}
cons_show("");
curr = g_list_next(curr);
}
g_list_free_full(certs, (GDestroyNotify)tlscerts_free);
return TRUE;
} else { } else {
cons_bad_cmd_usage(command); cons_bad_cmd_usage(command);
return TRUE; return TRUE;

View File

@ -68,6 +68,34 @@ tlscerts_exists(const char * const fingerprint)
return g_key_file_has_group(tlscerts, 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]);
char *domain = g_key_file_get_string(tlscerts, fingerprint, "domain", NULL);
char *organisation = g_key_file_get_string(tlscerts, fingerprint, "organisation", NULL);
char *email = g_key_file_get_string(tlscerts, fingerprint, "email", NULL);
char *notbefore = g_key_file_get_string(tlscerts, fingerprint, "start", NULL);
char *notafter = g_key_file_get_string(tlscerts, fingerprint, "end", NULL);
TLSCertificate *cert = tlscerts_new(fingerprint, domain, organisation, email, notbefore, notafter);
res = g_list_append(res, cert);
}
if (groups) {
g_strfreev(groups);
}
return res;
}
TLSCertificate* TLSCertificate*
tlscerts_new(const char * const fingerprint, const char * const domain, const char * const organisation, tlscerts_new(const char * const fingerprint, const char * const domain, const char * const organisation,
const char * const email, const char * const notbefore, const char * const notafter) const char * const email, const char * const notbefore, const char * const notafter)

View File

@ -56,6 +56,8 @@ void tlscerts_add(TLSCertificate *cert);
void tlscerts_free(TLSCertificate *cert); void tlscerts_free(TLSCertificate *cert);
GList* tlscerts_list(void);
void tlscerts_close(void); void tlscerts_close(void);
#endif #endif