static void
gkm_secret_object_set_property (GObject *obj, guint prop_id, const GValue *value,
                                GParamSpec *pspec)
{
	GkmSecretObjectClass *klass = GKM_SECRET_OBJECT_GET_CLASS (obj);
	GkmSecretObject *self = GKM_SECRET_OBJECT (obj);
	const gchar *identifier;

	switch (prop_id) {
	case PROP_LABEL:
		gkm_secret_object_set_label (self, g_value_get_string (value));
		break;
	case PROP_IDENTIFIER:
		g_return_if_fail (!self->pv->identifier);
		identifier = g_value_get_string (value);
		g_return_if_fail (identifier);
		self->pv->identifier = register_identifier (klass, identifier);
		break;
	case PROP_CREATED:
		gkm_secret_object_set_created (self, g_value_get_long (value));
		break;
	case PROP_MODIFIED:
		gkm_secret_object_set_modified (self, g_value_get_long (value));
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
		break;
	}
}
示例#2
0
static void
setup_item_from_info (GkmSecretItem *item, GkmSecretData *data, ItemInfo *info)
{
	GkmSecretObject *obj = GKM_SECRET_OBJECT (item);
	const gchar *schema_name;
	GkmSecret *secret;

	gkm_secret_object_set_label (obj, info->display_name);
	gkm_secret_object_set_created (obj, info->ctime);
	gkm_secret_object_set_modified (obj, info->mtime);

	schema_name = g_hash_table_lookup (info->attributes, GKM_SECRET_FIELD_SCHEMA);
	if (schema_name == NULL)
		schema_name = gkm_secret_compat_format_item_type (info->type);
	gkm_secret_item_set_schema (item, schema_name);

	gkm_secret_item_set_fields (item, info->attributes);

	/* Collection is locked */
	if (!data) {
		g_object_set_data (G_OBJECT (item), "compat-acl", NULL);

	} else {
		secret = gkm_secret_new (info->ptr_secret, info->n_secret);
		gkm_secret_data_set_secret (data, gkm_secret_object_get_identifier (obj), secret);
		g_object_unref (secret);
		g_object_set_data_full (G_OBJECT (item), "compat-acl", info->acl, gkm_secret_compat_acl_free);
		info->acl = NULL;
	}
}
void
gkm_secret_object_was_modified (GkmSecretObject *self)
{
	GTimeVal tv;
	g_return_if_fail (GKM_IS_SECRET_OBJECT (self));
	g_get_current_time (&tv);
	gkm_secret_object_set_modified (self, tv.tv_sec);
}
示例#4
0
GkmDataResult
gkm_secret_binary_read (GkmSecretCollection *collection, GkmSecretData *sdata,
                        gconstpointer data, gsize n_data)
{
	gsize offset;
	guchar major, minor, crypto, hash;
	guint32 flags;
	guint32 lock_timeout;
	time_t mtime, ctime;
	char *display_name;
	guint32 tmp;
	guint32 num_items;
	guint32 crypto_size;
	guint32 hash_iterations;
	guchar salt[8];
	ItemInfo *items;
	GkmSecret* master;
	GkmSecretObject *obj;
	EggBuffer to_decrypt = EGG_BUFFER_EMPTY;
	GkmDataResult res = GKM_DATA_FAILURE;
	GHashTable *checks = NULL;
	GkmSecretItem *item;
	EggBuffer buffer;
	GList *l, *iteml;
	int i;

	display_name = NULL;
	items = 0;
	obj = GKM_SECRET_OBJECT (collection);

	/* The buffer we read from */
	egg_buffer_init_static (&buffer, data, n_data);

	if (buffer.len < KEYRING_FILE_HEADER_LEN ||
	    memcmp (buffer.buf, KEYRING_FILE_HEADER, KEYRING_FILE_HEADER_LEN) != 0) {
		egg_buffer_uninit (&buffer);
		return GKM_DATA_UNRECOGNIZED;
	}

	offset = KEYRING_FILE_HEADER_LEN;
	major = buffer.buf[offset++];
	minor = buffer.buf[offset++];
	crypto = buffer.buf[offset++];
	hash = buffer.buf[offset++];

	if (major != 0 || minor != 0 || crypto != 0 || hash != 0) {
		egg_buffer_uninit (&buffer);
		return GKM_DATA_UNRECOGNIZED;
	}

	if (!buffer_get_utf8_string (&buffer, offset, &offset, &display_name) ||
	    !buffer_get_time (&buffer, offset, &offset, &ctime) ||
	    !buffer_get_time (&buffer, offset, &offset, &mtime) ||
	    !egg_buffer_get_uint32 (&buffer, offset, &offset, &flags) ||
	    !egg_buffer_get_uint32 (&buffer, offset, &offset, &lock_timeout) ||
	    !egg_buffer_get_uint32 (&buffer, offset, &offset, &hash_iterations) ||
	    !buffer_get_bytes (&buffer, offset, &offset, salt, 8))
		goto bail;

	for (i = 0; i < 4; i++) {
		if (!egg_buffer_get_uint32 (&buffer, offset, &offset, &tmp))
			goto bail;
	}

	if (!egg_buffer_get_uint32 (&buffer, offset, &offset, &num_items))
		goto bail;

	items = g_new0 (ItemInfo, num_items + 1);

	/* Hashed data, without secrets */
	if (!read_hashed_item_info (&buffer, &offset, items, num_items))
		goto bail;

	if (!egg_buffer_get_uint32 (&buffer, offset, &offset, &crypto_size))
		goto bail;

	/* Make the crypted part is the right size */
	if (crypto_size % 16 != 0)
		goto bail;

	/* Ensure the file is large enough to hold all the data (in case it got truncated) */
	if (buffer.len < offset + crypto_size)
		goto bail;

	/* Copy the data into to_decrypt into non-pageable memory */
	egg_buffer_set_allocator (&to_decrypt, egg_secure_realloc);
	egg_buffer_reserve (&to_decrypt, crypto_size);
	memcpy (to_decrypt.buf, buffer.buf + offset, crypto_size);
	to_decrypt.len = crypto_size;

	if (sdata != NULL) {
		master = gkm_secret_data_get_master (sdata);
		if (!decrypt_buffer (&to_decrypt, master, salt, hash_iterations))
			goto bail;
		if (!verify_decrypted_buffer (&to_decrypt)) {
			res = GKM_DATA_LOCKED;
			goto bail;
		} else {
			offset = 16; /* Skip hash */
			if (!read_full_item_info (&to_decrypt, &offset, items, num_items))
				goto bail;
		}
	}

	/* Correctly read all data, possibly including the decrypted data.
	 * Now update the keyring and items: */

	gkm_secret_object_set_label (obj, display_name);
	gkm_secret_object_set_modified (obj, mtime);
	gkm_secret_object_set_created (obj, ctime);
	if (flags & LOCK_ON_IDLE_FLAG)
		gkm_secret_collection_set_lock_idle (collection, lock_timeout);
	else if (flags & LOCK_AFTER_FLAG)
		gkm_secret_collection_set_lock_after (collection, lock_timeout);

	/* Build a Hash table where we can track ids we haven't yet seen */
	checks = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
	iteml = gkm_secret_collection_get_items (collection);
	for (l = iteml; l; l = g_list_next (l))
		g_hash_table_insert (checks, g_strdup (gkm_secret_object_get_identifier (l->data)), "unused");
	g_list_free (iteml);

	for (i = 0; i < num_items; i++) {

		/* We've seen this id */
		g_hash_table_remove (checks, items[i].identifier);

		item = gkm_secret_collection_get_item (collection, items[i].identifier);
		if (item == NULL)
			item = gkm_secret_collection_new_item (collection, items[i].identifier);

		setup_item_from_info (item, sdata, &items[i]);
	}

	g_hash_table_foreach (checks, remove_unavailable_item, collection);
	res = GKM_DATA_SUCCESS;

bail:
	egg_buffer_uninit (&to_decrypt);
	if (checks)
		g_hash_table_destroy (checks);
	g_free (display_name);

	for (i = 0; items && i < num_items; i++)
		free_item_info (&items[i]);
	g_free (items);

	return res;
}