const gchar* gkm_certificate_get_label (GkmCertificate *self) { gchar *label; g_return_val_if_fail (GKM_IS_CERTIFICATE (self), ""); if (!self->pv->label) { g_return_val_if_fail (self->pv->asn1, ""); /* Look for the CN in the certificate */ label = egg_dn_read_part (egg_asn1x_node (self->pv->asn1, "tbsCertificate", "subject", "rdnSequence", NULL), "cn"); /* Otherwise use the full DN */ if (!label) label = egg_dn_read (egg_asn1x_node (self->pv->asn1, "tbsCertificate", "subject", "rdnSequence", NULL)); if (!label) label = g_strdup (_("Unnamed Certificate")); self->pv->label = label; } return self->pv->label; }
/** * gcr_certificate_get_subject_part: * @self: a #GcrCertificate * @part: a DN type string or OID. * * Get a part of the DN of the subject of this certificate. * * Examples of a @part might be the 'OU' (organizational unit) * or the 'CN' (common name). Only the value of that part * of the DN is returned. * * The string returned should be freed by the caller when no longer * required. * * Returns: The allocated part of the subject DN, or NULL if no such part is present. */ gchar* gcr_certificate_get_subject_part (GcrCertificate *self, const char *part) { GcrCertificateInfo *info; g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL); info = certificate_info_load (self); g_return_val_if_fail (info, NULL); return egg_dn_read_part (egg_asn1x_node (info->asn1, "tbsCertificate", "subject", "rdnSequence", NULL), part); }
static gchar* name_for_subject (const guchar *subject, gsize n_subject) { GNode *asn; gchar *name; g_assert (subject); g_assert (n_subject); asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Name", subject, n_subject); g_return_val_if_fail (asn, NULL); name = egg_dn_read_part (egg_asn1x_node (asn, "rdnSequence", NULL), "CN"); egg_asn1x_destroy (asn); return name; }