diff options
author | James Booth <boothj5@gmail.com> | 2015-11-10 01:20:40 +0000 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2015-11-10 01:20:40 +0000 |
commit | 9302188a32fe2065927555a2a1d5438b8f128e1a (patch) | |
tree | 75927adeffd7c29d2580ce0089dc3140ff2ab8db /src/config | |
parent | bee27f47736d5d16500bb83e7ae9b5cd80cd4b26 (diff) | |
download | profani-tty-9302188a32fe2065927555a2a1d5438b8f128e1a.tar.gz |
Show current TLS certificate
Diffstat (limited to 'src/config')
-rw-r--r-- | src/config/tlscerts.c | 64 | ||||
-rw-r--r-- | src/config/tlscerts.h | 6 |
2 files changed, 38 insertions, 32 deletions
diff --git a/src/config/tlscerts.c b/src/config/tlscerts.c index 299b98cf..15433a92 100644 --- a/src/config/tlscerts.c +++ b/src/config/tlscerts.c @@ -119,13 +119,11 @@ tlscerts_list(void) 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 *subjectname = g_key_file_get_string(tlscerts, fingerprint, "subjectname", 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); + TLSCertificate *cert = tlscerts_new(fingerprint, subjectname, notbefore, notafter); res = g_list_append(res, cert); } @@ -138,30 +136,21 @@ tlscerts_list(void) } TLSCertificate* -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) +tlscerts_new(const char *const fingerprint, const char *const subjectname, const char *const notbefore, + const char *const notafter) { TLSCertificate *cert = malloc(sizeof(TLSCertificate)); + + if (subjectname) { + cert->subjectname = strdup(subjectname); + } else { + cert->subjectname = NULL; + } if (fingerprint) { cert->fingerprint = strdup(fingerprint); } else { cert->fingerprint = NULL; } - if (domain) { - cert->domain = strdup(domain); - } else { - cert->domain = NULL; - } - if (organisation) { - cert->organisation = strdup(organisation); - } else { - cert->organisation = NULL; - } - if (email) { - cert->email = strdup(email); - } else { - cert->email= NULL; - } if (notbefore) { cert->notbefore = strdup(notbefore); } else { @@ -173,6 +162,28 @@ tlscerts_new(const char *const fingerprint, const char *const domain, const char cert->notafter = NULL; } + cert->domain = NULL; + cert->email = NULL; + cert->organisation = NULL; + gchar** fields = g_strsplit(subjectname, "/", 0); + int i = 0; + for (i = 0; i < g_strv_length(fields); i++) { + gchar** keyval = g_strsplit(fields[i], "=", 2); + if (g_strv_length(keyval) == 2) { + if (g_strcmp0(keyval[0], "CN") == 0) { + cert->domain = strdup(keyval[1]); + } + if (g_strcmp0(keyval[0], "O") == 0) { + cert->organisation = strdup(keyval[1]); + } + if (g_strcmp0(keyval[0], "emailAddress") == 0) { + cert->email = strdup(keyval[1]); + } + } + g_strfreev(keyval); + } + g_strfreev(fields); + return cert; } @@ -189,14 +200,8 @@ tlscerts_add(TLSCertificate *cert) autocomplete_add(certs_ac, cert->fingerprint); - if (cert->domain) { - g_key_file_set_string(tlscerts, cert->fingerprint, "domain", cert->domain); - } - if (cert->organisation) { - g_key_file_set_string(tlscerts, cert->fingerprint, "organisation", cert->organisation); - } - if (cert->email) { - g_key_file_set_string(tlscerts, cert->fingerprint, "email", cert->email); + if (cert->subjectname) { + g_key_file_set_string(tlscerts, cert->fingerprint, "subjectname", cert->subjectname); } if (cert->notbefore) { g_key_file_set_string(tlscerts, cert->fingerprint, "start", cert->notbefore); @@ -237,6 +242,7 @@ void tlscerts_free(TLSCertificate *cert) { if (cert) { + free(cert->subjectname); free(cert->fingerprint); free(cert->domain); free(cert->organisation); diff --git a/src/config/tlscerts.h b/src/config/tlscerts.h index c3b273e7..e1ab4748 100644 --- a/src/config/tlscerts.h +++ b/src/config/tlscerts.h @@ -38,6 +38,7 @@ typedef struct tls_cert_t { char *fingerprint; char *domain; + char *subjectname; char *organisation; char *email; char *notbefore; @@ -46,9 +47,8 @@ typedef struct tls_cert_t { void tlscerts_init(void); -TLSCertificate* 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); +TLSCertificate* tlscerts_new(const char *const fingerprint, const char *const subjectname, const char *const notbefore, + const char *const notafter); void tlscerts_set_current(const char *const fp); |