aboutsummaryrefslogtreecommitdiffstats
path: root/smime/lib
diff options
context:
space:
mode:
Diffstat (limited to 'smime/lib')
-rw-r--r--smime/lib/e-cert.c52
-rw-r--r--smime/lib/e-cert.h2
2 files changed, 54 insertions, 0 deletions
diff --git a/smime/lib/e-cert.c b/smime/lib/e-cert.c
index e6fbd57e76..d5a5f2b6e1 100644
--- a/smime/lib/e-cert.c
+++ b/smime/lib/e-cert.c
@@ -92,6 +92,8 @@ struct _ECertPrivate {
char *serial_number;
+ char *usage_string;
+
char *sha1_fingerprint;
char *md5_fingerprint;
@@ -132,6 +134,8 @@ e_cert_dispose (GObject *object)
if (ec->priv->serial_number)
PORT_Free (ec->priv->serial_number);
+ g_free(ec->priv->usage_string);
+
if (ec->priv->sha1_fingerprint)
PORT_Free (ec->priv->sha1_fingerprint);
if (ec->priv->md5_fingerprint)
@@ -412,6 +416,38 @@ e_cert_get_expires_on (ECert *cert)
return cert->priv->expires_on_string;
}
+static struct {
+ int bit;
+ const char *text;
+} usageinfo[] = {
+ /* x509 certificate usage types */
+ { certificateUsageEmailSigner, N_("Sign") },
+ { certificateUsageEmailRecipient, N_("Encrypt") },
+};
+
+const char*
+e_cert_get_usage(ECert *cert)
+{
+ if (cert->priv->usage_string == NULL) {
+ int i;
+ GString *str = g_string_new("");
+ CERTCertificate *icert = e_cert_get_internal_cert (cert);
+
+ for (i=0;i<sizeof(usageinfo)/sizeof(usageinfo[0]);i++) {
+ if (icert->keyUsage & usageinfo[i].bit) {
+ if (str->len != 0)
+ g_string_append(str, ", ");
+ g_string_append(str, _(usageinfo[i].text));
+ }
+ }
+
+ cert->priv->usage_string = str->str;
+ g_string_free(str, FALSE);
+ }
+
+ return cert->priv->usage_string;
+}
+
const char*
e_cert_get_serial_number (ECert *cert)
{
@@ -455,6 +491,22 @@ e_cert_get_chain (ECert *ecert)
return l;
}
+ECert *
+e_cert_get_ca_cert(ECert *ecert)
+{
+ CERTCertificate *cert, *next = e_cert_get_internal_cert(ecert);
+
+ do {
+ cert = next;
+ next = CERT_FindCertIssuer (cert, PR_Now(), certUsageAnyCA);
+ } while (next && next != cert);
+
+ if (cert == e_cert_get_internal_cert(ecert))
+ return g_object_ref(ecert);
+ else
+ return e_cert_new(cert);
+}
+
static gboolean
get_int_value (SECItem *versionItem,
unsigned long *version)
diff --git a/smime/lib/e-cert.h b/smime/lib/e-cert.h
index 243ce1539b..5e0ae78fba 100644
--- a/smime/lib/e-cert.h
+++ b/smime/lib/e-cert.h
@@ -88,12 +88,14 @@ PRTime e_cert_get_issued_on_time (ECert *cert);
const char* e_cert_get_issued_on (ECert *cert);
PRTime e_cert_get_expires_on_time (ECert *cert);
const char* e_cert_get_expires_on (ECert *cert);
+const char* e_cert_get_usage(ECert *cert);
const char* e_cert_get_serial_number (ECert *cert);
const char* e_cert_get_sha1_fingerprint (ECert *cert);
const char* e_cert_get_md5_fingerprint (ECert *cert);
GList* e_cert_get_chain (ECert *cert);
+ECert * e_cert_get_ca_cert (ECert *ecert);
EASN1Object* e_cert_get_asn1_struct (ECert *cert);
gboolean e_cert_mark_for_deletion (ECert *cert);