Commit f7e73bab authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Merge branch 'wip/dueno/simple-item' into 'master'

secret-password: Add necessary functions to migrate from D-Bus based API

See merge request !32
parents 9a8f49f2 6886aebb
Pipeline #97747 passed with stages
in 6 minutes and 46 seconds
......@@ -26,6 +26,7 @@
<xi:include href="xml/secret-service.xml"/>
<xi:include href="xml/secret-collection.xml"/>
<xi:include href="xml/secret-item.xml"/>
<xi:include href="xml/secret-retrievable.xml"/>
<xi:include href="xml/secret-value.xml"/>
<xi:include href="xml/secret-attributes.xml"/>
<xi:include href="xml/secret-prompt.xml"/>
......
......@@ -120,6 +120,10 @@ secret_password_storev
secret_password_store_finish
secret_password_store_sync
secret_password_storev_sync
secret_password_store_binary
secret_password_store_binary_sync
secret_password_storev_binary
secret_password_storev_binary_sync
secret_password_lookup
secret_password_lookupv
secret_password_lookup_finish
......@@ -128,15 +132,38 @@ secret_password_lookup_sync
secret_password_lookup_nonpageable_sync
secret_password_lookupv_sync
secret_password_lookupv_nonpageable_sync
secret_password_lookup_binary_finish
secret_password_lookup_binary_sync
secret_password_lookupv_binary_sync
secret_password_clear
secret_password_clearv
secret_password_clear_finish
secret_password_clear_sync
secret_password_clearv_sync
secret_password_search
secret_password_search_finish
secret_password_search_sync
secret_password_searchv
secret_password_searchv_sync
secret_password_wipe
secret_password_free
</SECTION>
<SECTION>
<FILE>secret-retrievable</FILE>
<INCLUDE>libsecret/secret.h</INCLUDE>
SECRET_TYPE_RETRIEVABLE
SecretRetrievable
SecretRetrievableInterface
secret_retrievable_get_attributes
secret_retrievable_get_created
secret_retrievable_get_label
secret_retrievable_get_modified
secret_retrievable_retrieve_secret
secret_retrievable_retrieve_secret_finish
secret_retrievable_retrieve_secret_sync
</SECTION>
<SECTION>
<FILE>secret-schema</FILE>
<INCLUDE>libsecret/secret.h</INCLUDE>
......@@ -306,6 +333,7 @@ secret_value_get_text
secret_value_get_content_type
secret_value_ref
secret_value_unref
secret_value_unref_to_password
<SUBSECTION Standard>
SECRET_TYPE_VALUE
secret_value_get_type
......
......@@ -12,6 +12,7 @@ libsecret_HEADS = \
libsecret/secret-password.h \
libsecret/secret-paths.h \
libsecret/secret-prompt.h \
libsecret/secret-retrievable.h \
libsecret/secret-schema.h \
libsecret/secret-schemas.h \
libsecret/secret-service.h \
......@@ -42,6 +43,7 @@ libsecret_PUBLIC = \
libsecret/secret-methods.c \
libsecret/secret-password.h libsecret/secret-password.c \
libsecret/secret-prompt.h libsecret/secret-prompt.c \
libsecret/secret-retrievable.h libsecret/secret-retrievable.c \
libsecret/secret-schema.h libsecret/secret-schema.c \
libsecret/secret-schemas.h libsecret/secret-schemas.c \
libsecret/secret-service.h libsecret/secret-service.c \
......
......@@ -7,6 +7,7 @@ libsecret_sources = [
'secret-methods.c',
'secret-password.c',
'secret-prompt.c',
'secret-retrievable.c',
'secret-schema.c',
'secret-schemas.c',
'secret-service.c',
......@@ -24,6 +25,7 @@ libsecret_headers = [
'secret-password.h',
'secret-paths.h',
'secret-prompt.h',
'secret-retrievable.h',
'secret-schema.h',
'secret-schemas.h',
'secret-service.h',
......@@ -104,6 +106,8 @@ libsecret_gir_sources = [
'secret-paths.h',
'secret-prompt.c',
'secret-prompt.h',
'secret-retrievable.c',
'secret-retrievable.h',
'secret-schema.c',
'secret-schema.h',
'secret-schemas.c',
......
......@@ -19,6 +19,7 @@
#include "secret-item.h"
#include "secret-paths.h"
#include "secret-private.h"
#include "secret-retrievable.h"
#include "secret-service.h"
#include "secret-types.h"
#include "secret-value.h"
......@@ -105,16 +106,21 @@ struct _SecretItemPrivate {
gint disposed;
};
static SecretRetrievableInterface *secret_item_retrievable_parent_iface = NULL;
static GInitableIface *secret_item_initable_parent_iface = NULL;
static GAsyncInitableIface *secret_item_async_initable_parent_iface = NULL;
static void secret_item_retrievable_iface (SecretRetrievableInterface *iface);
static void secret_item_initable_iface (GInitableIface *iface);
static void secret_item_async_initable_iface (GAsyncInitableIface *iface);
G_DEFINE_TYPE_WITH_CODE (SecretItem, secret_item, G_TYPE_DBUS_PROXY,
G_ADD_PRIVATE (SecretItem)
G_IMPLEMENT_INTERFACE (SECRET_TYPE_RETRIEVABLE, secret_item_retrievable_iface);
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, secret_item_initable_iface);
G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, secret_item_async_initable_iface);
);
......@@ -355,9 +361,7 @@ secret_item_class_init (SecretItemClass *klass)
* The attributes set on this item. Attributes are used to locate an
* item. They are not guaranteed to be stored or transferred securely.
*/
g_object_class_install_property (gobject_class, PROP_ATTRIBUTES,
g_param_spec_boxed ("attributes", "Attributes", "Item attributes",
G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (gobject_class, PROP_ATTRIBUTES, "attributes");
/**
* SecretItem:label:
......@@ -368,9 +372,7 @@ secret_item_class_init (SecretItemClass *klass)
* set asynchronously. To properly track the changing of the label use the
* secret_item_set_label() function.
*/
g_object_class_install_property (gobject_class, PROP_LABEL,
g_param_spec_string ("label", "Label", "Item label",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (gobject_class, PROP_LABEL, "label");
/**
* SecretItem:locked:
......@@ -391,9 +393,7 @@ secret_item_class_init (SecretItemClass *klass)
* The date and time (in seconds since the UNIX epoch) that this
* item was created.
*/
g_object_class_install_property (gobject_class, PROP_CREATED,
g_param_spec_uint64 ("created", "Created", "Item creation date",
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (gobject_class, PROP_CREATED, "created");
/**
* SecretItem:modified:
......@@ -401,9 +401,7 @@ secret_item_class_init (SecretItemClass *klass)
* The date and time (in seconds since the UNIX epoch) that this
* item was last modified.
*/
g_object_class_install_property (gobject_class, PROP_MODIFIED,
g_param_spec_uint64 ("modified", "Modified", "Item modified date",
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_override_property (gobject_class, PROP_MODIFIED, "modified");
}
typedef struct {
......@@ -1320,6 +1318,55 @@ secret_item_load_secret_sync (SecretItem *self,
return result;
}
static void
on_retrieve_load (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
SecretItem *self = SECRET_ITEM (source_object);
GTask *task = G_TASK (user_data);
GError *error = NULL;
if (secret_item_load_secret_finish (self, res, &error)) {
g_task_return_pointer (task,
secret_item_get_secret (self),
secret_value_unref);
g_object_unref (task);
} else {
g_task_return_error (task, error);
g_object_unref (task);
}
}
static void
secret_item_retrieve_secret (SecretRetrievable *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task = g_task_new (self, cancellable, callback, user_data);
secret_item_load_secret (SECRET_ITEM (self), cancellable, on_retrieve_load, task);
}
static SecretValue *
secret_item_retrieve_secret_finish (SecretRetrievable *self,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, self), NULL);
return g_task_propagate_pointer (G_TASK (result), error);
}
static void
secret_item_retrievable_iface (SecretRetrievableInterface *iface)
{
secret_item_retrievable_parent_iface = g_type_interface_peek_parent (iface);
iface->retrieve_secret = secret_item_retrieve_secret;
iface->retrieve_secret_finish = secret_item_retrieve_secret_finish;
}
typedef struct {
SecretService *service;
GCancellable *cancellable;
......
This diff is collapsed.
......@@ -25,8 +25,9 @@ G_BEGIN_DECLS
#include "secret-schema.h"
#include "secret-types.h"
#include "secret-value.h"
void secret_password_store (const SecretSchema *schema,
void secret_password_store (const SecretSchema *schema,
const gchar *collection,
const gchar *label,
const gchar *password,
......@@ -35,7 +36,7 @@ void secret_password_store (const SecretSchema *sche
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
void secret_password_storev (const SecretSchema *schema,
void secret_password_storev (const SecretSchema *schema,
GHashTable *attributes,
const gchar *collection,
const gchar *label,
......@@ -44,10 +45,28 @@ void secret_password_storev (const SecretSchema *sche
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_password_store_finish (GAsyncResult *result,
void secret_password_store_binary (const SecretSchema *schema,
const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...);
void secret_password_storev_binary (const SecretSchema *schema,
GHashTable *attributes,
const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_password_store_finish (GAsyncResult *result,
GError **error);
gboolean secret_password_store_sync (const SecretSchema *schema,
gboolean secret_password_store_sync (const SecretSchema *schema,
const gchar *collection,
const gchar *label,
const gchar *password,
......@@ -55,7 +74,7 @@ gboolean secret_password_store_sync (const SecretSchema *sche
GError **error,
...) G_GNUC_NULL_TERMINATED;
gboolean secret_password_storev_sync (const SecretSchema *schema,
gboolean secret_password_storev_sync (const SecretSchema *schema,
GHashTable *attributes,
const gchar *collection,
const gchar *label,
......@@ -63,72 +82,127 @@ gboolean secret_password_storev_sync (const SecretSchema *sche
GCancellable *cancellable,
GError **error);
void secret_password_lookup (const SecretSchema *schema,
gboolean secret_password_store_binary_sync (const SecretSchema *schema,
const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
GError **error,
...);
gboolean secret_password_storev_binary_sync (const SecretSchema *schema,
GHashTable *attributes,
const gchar *collection,
const gchar *label,
SecretValue *value,
GCancellable *cancellable,
GError **error);
void secret_password_lookup (const SecretSchema *schema,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
void secret_password_lookupv (const SecretSchema *schema,
void secret_password_lookupv (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gchar * secret_password_lookup_finish (GAsyncResult *result,
gchar * secret_password_lookup_finish (GAsyncResult *result,
GError **error);
gchar * secret_password_lookup_nonpageable_finish (GAsyncResult *result,
GError **error);
gchar * secret_password_lookup_nonpageable_finish (GAsyncResult *result,
GError **error);
SecretValue *secret_password_lookup_binary_finish (GAsyncResult *result,
GError **error);
gchar * secret_password_lookup_sync (const SecretSchema *schema,
gchar * secret_password_lookup_sync (const SecretSchema *schema,
GCancellable *cancellable,
GError **error,
...) G_GNUC_NULL_TERMINATED;
gchar * secret_password_lookup_nonpageable_sync (const SecretSchema *schema,
gchar * secret_password_lookup_nonpageable_sync (const SecretSchema *schema,
GCancellable *cancellable,
GError **error,
...);
SecretValue *secret_password_lookup_binary_sync (const SecretSchema *schema,
GCancellable *cancellable,
GError **error,
...);
gchar * secret_password_lookupv_sync (const SecretSchema *schema,
gchar * secret_password_lookupv_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
gchar * secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
gchar * secret_password_lookupv_nonpageable_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
SecretValue *secret_password_lookupv_binary_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
void secret_password_clear (const SecretSchema *schema,
void secret_password_clear (const SecretSchema *schema,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
void secret_password_clearv (const SecretSchema *schema,
void secret_password_clearv (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean secret_password_clear_finish (GAsyncResult *result,
gboolean secret_password_clear_finish (GAsyncResult *result,
GError **error);
gboolean secret_password_clear_sync (const SecretSchema* schema,
gboolean secret_password_clear_sync (const SecretSchema* schema,
GCancellable *cancellable,
GError **error,
...) G_GNUC_NULL_TERMINATED;
gboolean secret_password_clearv_sync (const SecretSchema *schema,
gboolean secret_password_clearv_sync (const SecretSchema *schema,
GHashTable *attributes,
GCancellable *cancellable,
GError **error);
void secret_password_free (gchar *password);
void secret_password_search (const SecretSchema *schema,
SecretSearchFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data,
...) G_GNUC_NULL_TERMINATED;
void secret_password_searchv (const SecretSchema *schema,
GHashTable *attributes,
SecretSearchFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
GList * secret_password_search_sync (const SecretSchema *schema,
SecretSearchFlags flags,
GCancellable *cancellable,
GError **error,
...) G_GNUC_NULL_TERMINATED;
GList * secret_password_searchv_sync (const SecretSchema *schema,
GHashTable *attributes,
SecretSearchFlags flags,
GCancellable *cancellable,
GError **error);
GList * secret_password_search_finish (GAsyncResult *result,
GError **error);
void secret_password_free (gchar *password);
void secret_password_wipe (gchar *password);
void secret_password_wipe (gchar *password);
G_END_DECLS
......
/* libsecret - GLib wrapper for Secret Service
*
* Copyright 2019 Red Hat, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 of the licence or (at
* your option) any later version.
*
* See the included COPYING file for more information.
*
* Author: Daiki Ueno
*/
#include "config.h"
#include "secret-retrievable.h"
#include "secret-private.h"
/**
* SECTION:secret-retrievable
* @title: SecretRetrievable
* @short_description: A read-only secret item
*
* #SecretRetrievable provides a read-only view of a secret item
* stored in the Secret Service.
*
* Each item has a value, represented by a #SecretValue, which can be
* retrieved by secret_retrievable_retrieve_secret() and
* secret_retrievable_retrieve_secret_finish().
*
* Stability: Stable
*/
/**
* SecretRetrievable:
*
* An object representing a read-only view of a secret item in the
* Secret Service.
*
* Since: 0.19.0
*/
/**
* SecretRetrievableInterface:
* @parent_iface: the parent interface
* @retrieve_secret: implementation of secret_retrievable_retrieve_secret(),
* required
* @retrieve_secret_finish: implementation of
* secret_retrievable_retrieve_secret_finish(), required
*
* The interface for #SecretRetrievable.
*
* Since: 0.19.0
*/
G_DEFINE_INTERFACE (SecretRetrievable, secret_retrievable, G_TYPE_OBJECT);
static void
secret_retrievable_default_init (SecretRetrievableInterface *iface)
{
/**
* SecretRetrievable:attributes: (type GLib.HashTable(utf8,utf8)) (transfer full)
*
* The attributes set on this item. Attributes are used to locate an
* item. They are not guaranteed to be stored or transferred securely.
*
* Since: 0.19.0
*/
g_object_interface_install_property (iface,
g_param_spec_boxed ("attributes", "Attributes", "Item attributes",
G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* SecretRetrievable:label:
*
* The human readable label for the item.
*
* Since: 0.19.0
*/
g_object_interface_install_property (iface,
g_param_spec_string ("label", "Label", "Item label",
NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* SecretRetrievable:created:
*
* The date and time (in seconds since the UNIX epoch) that this
* item was created.
*
* Since: 0.19.0
*/
g_object_interface_install_property (iface,
g_param_spec_uint64 ("created", "Created", "Item creation date",
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
/**
* SecretRetrievable:modified:
*
* The date and time (in seconds since the UNIX epoch) that this
* item was last modified.
*
* Since: 0.19.0
*/
g_object_interface_install_property (iface,
g_param_spec_uint64 ("modified", "Modified", "Item modified date",
0UL, G_MAXUINT64, 0UL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
}
/**
* secret_retrievable_retrieve_secret:
* @self: a retrievable object
* @cancellable: (nullable): optional cancellation object
* @callback: called when the operation completes
* @user_data: data to pass to the callback
*
* Retrieve the secret value of this object.
*
* Each retrievable object has a single secret which might be a
* password or some other secret binary value.
*
* This function returns immediately and completes asynchronously.
*
* Since: 0.19.0
*/
void
secret_retrievable_retrieve_secret (SecretRetrievable *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
SecretRetrievableInterface *iface;
g_return_if_fail (SECRET_IS_RETRIEVABLE (self));
iface = SECRET_RETRIEVABLE_GET_IFACE (self);
g_return_if_fail (iface->retrieve_secret != NULL);
iface->retrieve_secret (self, cancellable, callback, user_data);
}
/**
* secret_retrievable_retrieve_secret_finish:
* @self: a retrievable object
* @result: asynchronous result passed to callback
* @error: location to place error on failure
*
* Complete asynchronous operation to retrieve the secret value of this object.
*
* Returns: (transfer full) (nullable): the secret value which should be
* released with secret_value_unref(), or %NULL
*
* Since: 0.19.0
*/
SecretValue *
secret_retrievable_retrieve_secret_finish (SecretRetrievable *self,
GAsyncResult *result,
GError **error)
{
SecretRetrievableInterface *iface;
g_return_val_if_fail (SECRET_IS_RETRIEVABLE (self), NULL);
iface = SECRET_RETRIEVABLE_GET_IFACE (self);
g_return_val_if_fail (iface->retrieve_secret_finish != NULL, NULL);
return iface->retrieve_secret_finish (self, result, error);
}
/**
* secret_retrievable_retrieve_secret_sync:
* @self: a retrievable object
* @cancellable: (nullable): optional cancellation object
* @error: location to place error on failure
*
* Retrieve the secret value of this object synchronously.
*
* Each retrievable object has a single secret which might be a
* password or some other secret binary value.
*
* This method may block indefinitely and should not be used in user interface
* threads.
*
* Returns: (transfer full) (nullable): the secret value which should be
* released with secret_value_unref(), or %NULL
*
* Since: 0.19.0
*/