static void seahorse_pgp_subkey_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { SeahorsePgpSubkey *self = SEAHORSE_PGP_SUBKEY (object); switch (prop_id) { case PROP_INDEX: seahorse_pgp_subkey_set_index (self, g_value_get_uint (value)); break; case PROP_KEYID: seahorse_pgp_subkey_set_keyid (self, g_value_get_string (value)); break; case PROP_FLAGS: seahorse_pgp_subkey_set_flags (self, g_value_get_uint (value)); break; case PROP_LENGTH: seahorse_pgp_subkey_set_length (self, g_value_get_uint (value)); break; case PROP_ALGORITHM: seahorse_pgp_subkey_set_algorithm (self, g_value_get_string (value)); break; case PROP_CREATED: seahorse_pgp_subkey_set_created (self, g_value_get_ulong (value)); break; case PROP_EXPIRES: seahorse_pgp_subkey_set_expires (self, g_value_get_ulong (value)); break; case PROP_FINGERPRINT: seahorse_pgp_subkey_set_fingerprint (self, g_value_get_string (value)); break; case PROP_DESCRIPTION: seahorse_pgp_subkey_set_description (self, g_value_get_string (value)); break; } }
/** * response: The HKP server response to parse * * Extracts the key data from the HKP server response * * Returns A GList of keys **/ static GList* parse_hkp_index (const gchar *response) { /* Luckily enough, both the HKP server and NAI HKP interface to their * LDAP server are close enough in output so the same function can * parse them both. */ /* pub 2048/<a href="/pks/lookup?op=get&search=0x3CB3B415">3CB3B415</a> 1998/04/03 David M. Shaw <<a href="/pks/lookup?op=get&search=0x3CB3B415">[email protected]</a>> */ g_auto(GStrv) lines = NULL; gchar **l; SeahorsePgpKey *key = NULL; SeahorsePgpSubkey *subkey_with_id = NULL; GList *keys = NULL; GList *subkeys = NULL; GList *uids = NULL; SeahorseFlags flags; lines = g_strsplit (response, "\n", 0); for (l = lines; *l; l++) { gchar *line, *t; line = *l; dehtmlize (line); g_debug ("%s", line); /* Start a new key */ if (g_ascii_strncasecmp (line, "pub ", 4) == 0) { g_auto(GStrv) v = NULL; gchar *fingerprint, *fpr = NULL; const gchar *algo; gboolean has_uid = TRUE; SeahorsePgpSubkey *subkey; t = line + 4; while (*t && g_ascii_isspace (*t)) t++; v = g_strsplit_set (t, " ", 3); if (!v[0] || !v[1] || !v[2]) { g_message ("Invalid key line from server: %s", line); continue; } flags = SEAHORSE_FLAG_EXPORTABLE; /* Cut the length and fingerprint */ fpr = strchr (v[0], '/'); if (fpr == NULL) { g_message ("couldn't find key fingerprint in line from server: %s", line); fpr = ""; } else { *(fpr++) = 0; } /* Check out the key type */ switch (g_ascii_toupper (v[0][strlen (v[0]) - 1])) { case 'D': algo = "DSA"; break; case 'R': algo = "RSA"; break; default: algo = ""; break; }; /* Format the date for our parse function */ g_strdelimit (v[1], "/", '-'); /* Cleanup the UID */ g_strstrip (v[2]); if (g_ascii_strcasecmp (v[2], "*** KEY REVOKED ***") == 0) { flags |= SEAHORSE_FLAG_REVOKED; has_uid = FALSE; } if (key) { seahorse_pgp_key_set_uids (SEAHORSE_PGP_KEY (key), uids); g_list_free_full (uids, g_object_unref); seahorse_pgp_key_set_subkeys (SEAHORSE_PGP_KEY (key), subkeys); g_list_free_full (subkeys, g_object_unref); seahorse_pgp_key_realize (SEAHORSE_PGP_KEY (key)); uids = subkeys = NULL; subkey_with_id = NULL; key = NULL; } key = seahorse_pgp_key_new (); keys = g_list_prepend (keys, key); g_object_set (key, "object-flags", flags, NULL); /* Add all the info to the key */ subkey = seahorse_pgp_subkey_new (); seahorse_pgp_subkey_set_keyid (subkey, fpr); subkey_with_id = subkey; fingerprint = seahorse_pgp_subkey_calc_fingerprint (fpr); seahorse_pgp_subkey_set_fingerprint (subkey, fingerprint); g_free (fingerprint); seahorse_pgp_subkey_set_flags (subkey, flags); seahorse_pgp_subkey_set_created (subkey, parse_hkp_date (v[1])); seahorse_pgp_subkey_set_length (subkey, strtol (v[0], NULL, 10)); seahorse_pgp_subkey_set_algorithm (subkey, algo); subkeys = g_list_prepend (subkeys, subkey); /* And the UID if one was found */ if (has_uid) { SeahorsePgpUid *uid = seahorse_pgp_uid_new (key, v[2]); uids = g_list_prepend (uids, uid); } /* A UID for the key */ } else if (key && g_ascii_strncasecmp (line, " ", 4) == 0) { SeahorsePgpUid *uid; g_strstrip (line); uid = seahorse_pgp_uid_new (key, line); uids = g_list_prepend (uids, uid); /* Signatures */ } else if (key && g_ascii_strncasecmp (line, "sig ", 4) == 0) { /* TODO: Implement signatures */ } else if (key && subkey_with_id) { const char *fingerprint_str; g_autofree gchar *pretty_fingerprint = NULL; fingerprint_str = get_fingerprint_string (line); if (fingerprint_str == NULL) continue; pretty_fingerprint = seahorse_pgp_subkey_calc_fingerprint (fingerprint_str); /* FIXME: we don't check that the fingerprint actually matches * the key's ID. We also don't validate the fingerprint at * all; the keyserver may have returned some garbage and we * don't notice. */ if (pretty_fingerprint[0] != 0) seahorse_pgp_subkey_set_fingerprint (subkey_with_id, pretty_fingerprint); } } if (key) { seahorse_pgp_key_set_uids (SEAHORSE_PGP_KEY (key), g_list_reverse (uids)); g_list_free_full (uids, g_object_unref); seahorse_pgp_key_set_subkeys (SEAHORSE_PGP_KEY (key), g_list_reverse (subkeys)); g_list_free_full (subkeys, g_object_unref); seahorse_pgp_key_realize (SEAHORSE_PGP_KEY (key)); } return keys; }
static GList* parse_hkp_index (const gchar *response) { /* * Luckily enough, both the HKP server and NAI HKP interface to their * LDAP server are close enough in output so the same function can * parse them both. */ /* pub 2048/<a href="/pks/lookup?op=get&search=0x3CB3B415">3CB3B415</a> 1998/04/03 David M. Shaw <<a href="/pks/lookup?op=get&search=0x3CB3B415">[email protected]</a>> */ gchar **lines, **l; gchar **v; gchar *line, *t; SeahorsePgpKey *key = NULL; GList *keys = NULL; GList *subkeys = NULL; GList *uids = NULL; guint flags; lines = g_strsplit (response, "\n", 0); for (l = lines; *l; l++) { line = *l; dehtmlize (line); #if DEBUG_HKP_ENABLE fprintf(stderr,"%s\n", line); #endif /* Start a new key */ if (g_ascii_strncasecmp (line, "pub ", 4) == 0) { t = line + 4; while (*t && g_ascii_isspace (*t)) t++; v = g_strsplit_set (t, " ", 3); if (!v[0] || !v[1] || !v[2]) { g_warning ("Invalid key line from server: %s", line); } else { gchar *fingerprint, *fpr = NULL; const gchar *algo; gboolean has_uid = TRUE; SeahorsePgpSubkey *subkey; flags = SEAHORSE_FLAG_EXPORTABLE; /* Cut the length and fingerprint */ fpr = strchr (v[0], '/'); if (fpr == NULL) { g_warning ("couldn't find key fingerprint in line from server: %s", line); fpr = ""; } else { *(fpr++) = 0; } /* Check out the key type */ switch (g_ascii_toupper (v[0][strlen(v[0]) - 1])) { case 'D': algo = "DSA"; break; case 'R': algo = "RSA"; break; default: algo = ""; break; }; /* Format the date for our parse function */ g_strdelimit (v[1], "/", '-'); /* Cleanup the UID */ g_strstrip (v[2]); if (g_ascii_strcasecmp (v[2], "*** KEY REVOKED ***") == 0) { flags |= SEAHORSE_FLAG_REVOKED; has_uid = FALSE; } if (key) { seahorse_pgp_key_set_uids (SEAHORSE_PGP_KEY (key), uids); seahorse_object_list_free (uids); seahorse_pgp_key_set_subkeys (SEAHORSE_PGP_KEY (key), subkeys); seahorse_object_list_free (subkeys); uids = subkeys = NULL; key = NULL; } key = seahorse_pgp_key_new (); keys = g_list_prepend (keys, key); g_object_set (key, "location", SEAHORSE_LOCATION_REMOTE, "flags", flags, NULL); /* Add all the info to the key */ subkey = seahorse_pgp_subkey_new (); seahorse_pgp_subkey_set_keyid (subkey, fpr); fingerprint = seahorse_pgp_subkey_calc_fingerprint (fpr); seahorse_pgp_subkey_set_fingerprint (subkey, fingerprint); g_free (fingerprint); seahorse_pgp_subkey_set_flags (subkey, flags); seahorse_pgp_subkey_set_created (subkey, parse_hkp_date (v[1])); seahorse_pgp_subkey_set_length (subkey, strtol (v[0], NULL, 10)); seahorse_pgp_subkey_set_algorithm (subkey, algo); subkeys = g_list_prepend (subkeys, subkey); /* And the UID if one was found */ if (has_uid) { SeahorsePgpUid *uid = seahorse_pgp_uid_new (v[2]); uids = g_list_prepend (uids, uid); } } g_strfreev (v); /* A UID for the key */ } else if (key && g_ascii_strncasecmp (line, " ", 4) == 0) { SeahorsePgpUid *uid; g_strstrip (line); uid = seahorse_pgp_uid_new (line); uids = g_list_prepend (uids, uid); /* Signatures */ } else if (key && g_ascii_strncasecmp (line, "sig ", 4) == 0) { /* TODO: Implement signatures */ } } g_strfreev (lines); if (key) { seahorse_pgp_key_set_uids (SEAHORSE_PGP_KEY (key), g_list_reverse (uids)); seahorse_object_list_free (uids); seahorse_pgp_key_set_subkeys (SEAHORSE_PGP_KEY (key), g_list_reverse (subkeys)); seahorse_object_list_free (subkeys); } return keys; }
void seahorse_gpgme_subkey_set_subkey (SeahorseGpgmeSubkey *self, gpgme_subkey_t subkey) { gchar *description, *fingerprint, *name; SeahorsePgpSubkey *base; const gchar *algo_type; GObject *obj; gpgme_subkey_t sub; gint i, index; guint flags; g_return_if_fail (SEAHORSE_IS_GPGME_SUBKEY (self)); g_return_if_fail (subkey); /* Make sure that this subkey is in the pubkey */ index = -1; for (i = 0, sub = self->pv->pubkey->subkeys; sub; ++i, sub = sub->next) { if(sub == subkey) { index = i; break; } } g_return_if_fail (index >= 0); /* Calculate the algorithm */ algo_type = gpgme_pubkey_algo_name (subkey->pubkey_algo); if (algo_type == NULL) algo_type = C_("Algorithm", "Unknown"); else if (g_str_equal ("Elg", algo_type) || g_str_equal("ELG-E", algo_type)) algo_type = _("ElGamal"); /* Additional properties */ fingerprint = seahorse_pgp_subkey_calc_fingerprint (subkey->fpr); name = seahorse_gpgme_uid_calc_name (self->pv->pubkey->uids); description = seahorse_pgp_subkey_calc_description (name, index); self->pv->subkey = subkey; obj = G_OBJECT (self); g_object_freeze_notify (obj); base = SEAHORSE_PGP_SUBKEY (self); seahorse_pgp_subkey_set_index (base, index); seahorse_pgp_subkey_set_keyid (base, subkey->keyid); seahorse_pgp_subkey_set_algorithm (base, algo_type); seahorse_pgp_subkey_set_length (base, subkey->length); seahorse_pgp_subkey_set_description (base, description); seahorse_pgp_subkey_set_fingerprint (base, fingerprint); seahorse_pgp_subkey_set_created (base, subkey->timestamp); seahorse_pgp_subkey_set_expires (base, subkey->expires); /* The order below is significant */ flags = 0; if (subkey->revoked) flags |= SEAHORSE_FLAG_REVOKED; if (subkey->expired) flags |= SEAHORSE_FLAG_EXPIRED; if (subkey->disabled) flags |= SEAHORSE_FLAG_DISABLED; if (flags == 0 && !subkey->invalid) flags |= SEAHORSE_FLAG_IS_VALID; if (subkey->can_encrypt) flags |= SEAHORSE_FLAG_CAN_ENCRYPT; if (subkey->can_sign) flags |= SEAHORSE_FLAG_CAN_SIGN; if (subkey->can_certify) flags |= SEAHORSE_FLAG_CAN_CERTIFY; if (subkey->can_authenticate) flags |= SEAHORSE_FLAG_CAN_AUTHENTICATE; seahorse_pgp_subkey_set_flags (base, flags); g_object_notify (obj, "subkey"); g_object_thaw_notify (obj); g_free (description); g_free (name); g_free (fingerprint); }
/* Add a key to the key source from an LDAP entry */ static void search_parse_key_from_ldap_entry (SeahorseLDAPSource *self, GcrSimpleCollection *results, LDAP *ldap, LDAPMessage *res) { const gchar *algo; long int timestamp; long int expires; gchar *fpr, *fingerprint; gchar *uidstr; gboolean revoked; gboolean disabled; int length; g_return_if_fail (ldap_msgtype (res) == LDAP_RES_SEARCH_ENTRY); fpr = get_string_attribute (ldap, res, "pgpcertid"); uidstr = get_string_attribute (ldap, res, "pgpuserid"); revoked = get_boolean_attribute (ldap, res, "pgprevoked"); disabled = get_boolean_attribute (ldap, res, "pgpdisabled"); timestamp = get_date_attribute (ldap, res, "pgpkeycreatetime"); expires = get_date_attribute (ldap, res, "pgpkeyexpiretime"); algo = get_algo_attribute (ldap, res, "pgpkeytype"); length = get_int_attribute (ldap, res, "pgpkeysize"); if (fpr && uidstr) { SeahorsePgpSubkey *subkey; SeahorsePgpKey *key; SeahorsePgpUid *uid; GList *list; guint flags; /* Build up a subkey */ subkey = seahorse_pgp_subkey_new (); seahorse_pgp_subkey_set_keyid (subkey, fpr); fingerprint = seahorse_pgp_subkey_calc_fingerprint (fpr); seahorse_pgp_subkey_set_fingerprint (subkey, fingerprint); g_free (fingerprint); seahorse_pgp_subkey_set_created (subkey, timestamp); seahorse_pgp_subkey_set_expires (subkey, expires); seahorse_pgp_subkey_set_algorithm (subkey, algo); seahorse_pgp_subkey_set_length (subkey, length); flags = SEAHORSE_FLAG_EXPORTABLE; if (revoked) flags |= SEAHORSE_FLAG_REVOKED; if (disabled) flags |= SEAHORSE_FLAG_DISABLED; seahorse_pgp_subkey_set_flags (subkey, flags); key = seahorse_pgp_key_new (); /* Build up a uid */ uid = seahorse_pgp_uid_new (key, uidstr); if (revoked) seahorse_pgp_uid_set_validity (uid, SEAHORSE_VALIDITY_REVOKED); /* Now build them into a key */ list = g_list_prepend (NULL, uid); seahorse_pgp_key_set_uids (key, list); seahorse_object_list_free (list); list = g_list_prepend (NULL, subkey); seahorse_pgp_key_set_subkeys (key, list); seahorse_object_list_free (list); g_object_set (key, "object-flags", flags, "place", self, NULL); seahorse_pgp_key_realize (key); gcr_simple_collection_add (results, G_OBJECT (key)); g_object_unref (key); } g_free (fpr); g_free (uidstr); }