### swtpm Emulator Setup Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-tpm2.md Steps to set up the swtpm emulator, including installing necessary packages, configuring D-Bus, and initializing the TPM state. This is for testing TPM2 support without physical hardware. ```sh dnf install swtpm swtpm-tools tpm2-abrmd tpm2-tss-devel eval `dbus-launch --sh-syntax` export XDG_CONFIG_HOME=$HOME/.config/swtpm /usr/share/swtpm/swtpm-create-user-config-files --root mkdir -p ${XDG_CONFIG_HOME}/mytpm1 swtpm_setup --tpm2 --tpmstate $XDG_CONFIG_HOME/mytpm1 --createek --allow-signing --decryption --create-ek-cert --create-platform-cert --lock-nvram --overwrite --display swtpm socket --tpm2 --tpmstate dir=$XDG_CONFIG_HOME/mytpm1 --flags startup-clear --ctrl type=tcp,port=2322 --server type=tcp,port=2321 --daemon tpm2-abrmd --logger=stdout --tcti=swtpm: --session --allow-root --flush-all & export TCTI=tabrmd:bus_type=session ``` -------------------------------- ### Build, Test, and Install libsecret Source: https://github.com/gnome/libsecret/blob/main/README.md These commands are used to set up, compile, test, and install the libsecret library using Meson build system. ```bash $ meson setup _build $ meson compile -C _build $ meson test -C _build $ meson install -C _build ``` -------------------------------- ### Build libsecret with TPM2 Support Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-tpm2.md Instructions to build the libsecret project with TPM2 support enabled using Meson. This requires setting the '-Dtpm2=true' flag. ```sh meson _build -Dtpm2=true ninja -C _build ninja -C _build install ``` -------------------------------- ### Vala: Compile with libsecret Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Specify the libsecret-1 package in your Makefile.am file to enable compilation with libsecret. ```makefile AM_VALAFLAGS = \ --pkg=libsecret-1 ``` -------------------------------- ### C: Configure libsecret with pkg-config Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Use pkg-config in configure.ac to check for libsecret and define compiler flags and libraries. Ensure you are checking for the correct version (e.g., libsecret-1). ```autoconf PKG_CHECK_MODULES(LIBSECRET, [libsecret-1 >= 1.0]) AC_SUBST(LIBSECRET_CFLAGS) AC_SUBST(LIBSECRET_LIBS) ``` -------------------------------- ### C: Configure unstable libsecret with pkg-config Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Use pkg-config in configure.ac to check for the unstable libsecret API. This allows access to APIs that are subject to change. ```autoconf PKG_CHECK_MODULES(LIBSECRET, [libsecret-unstable >= 1.0]) AC_SUBST(LIBSECRET_CFLAGS) AC_SUBST(LIBSECRET_LIBS) ``` -------------------------------- ### Store a Password Asynchronously with Variadic Arguments Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Stores a password asynchronously using variadic arguments for attributes, avoiding the need to explicitly create a GLib.HashTable. ```vala bool res = yield Secret.password_store (example_schema, Secret.COLLECTION_DEFAULT, "The label", "the password", null, "number", 8, "string", "eight", "even", true); ``` -------------------------------- ### Test TPM2 Support in libsecret Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-tpm2.md Commands to test the TPM2 support after building libsecret. This involves setting the secret backend, defining a test path, and using 'secret-tool' to store a secret. ```sh cd libsecret Meson _build -Dtpm2=true ninja -C _build export SECRET_BACKEND=file export SECRET_FILE_TEST_PATH=$PWD/keyring ./_build/tool/secret-tool store --label=foo bar baz ls # keyring ``` -------------------------------- ### Vala: Enable unstable libsecret API Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Define the SECRET_WITH_UNSTABLE C preprocessor macro in your Makefile.am to use the unstable parts of the libsecret API. This is required to avoid build failures when using unstable features. ```makefile AM_CPPFLAGS = \ -DSECRET_WITH_UNSTABLE=1 ``` -------------------------------- ### Python: Import libsecret Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Import the Secret module in Python using GObject Introspection. Ensure the correct version is required before importing. ```python import gi gi.require_version("Secret", "1") from gi.repository import Secret # ... and a here's sample line of code which uses the import schema = Secret.Schema.new("org.mock.Schema", Secret.SchemaFlags.NONE, { "name": Secret.SchemaAttributeType.STRING }) ``` -------------------------------- ### EGG_TPM2 API Functions Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-tpm2.md These are the core API functions for interacting with the TPM2 context, including initialization, finalization, and master password generation/decryption. ```c EggTpm2Context *egg_tpm2_initialize (GError **); void egg_tpm2_finalize (EggTpm2Context *); GBytes *egg_tpm2_generate_master_password (EggTpm2Context *, GError **); GBytes *egg_tpm2_decrypt_master_password (EggTpm2Context *, GBytes *, GError **); ``` -------------------------------- ### C: Include libsecret header Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Include the main libsecret header file in your C code. Including individual headers is not permitted. ```c #include ``` -------------------------------- ### Javascript: Import libsecret Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-using.md Import the Secret module in Javascript using the GObject Introspection mechanism. This allows access to libsecret functionalities. ```javascript const Secret = imports.gi.Secret; // ... and here's a sample line of code which uses the import var schema = new Secret.Schema.new("org.mock.Schema", Secret.SchemaFlags.NONE, { "name", Secret.SchemaAttributeType.STRING }); ``` -------------------------------- ### Store a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Stores a password using a GLib.HashTable for attributes. This asynchronous method is suitable for GUI applications to prevent UI blocking. ```vala var attributes = new GLib.HashTable (); attributes["number"] = "8"; attributes["string"] = "eight"; attributes["even"] = "true"; Secret.password_storev.begin (example_schema, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", null, (obj, async_res) => { bool res = Secret.password_store.end (async_res); /* ... do something now that the password has been stored */ }); ``` -------------------------------- ### Store a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Stores a password asynchronously, suitable for GUI applications to prevent UI blocking. Attributes must conform to the defined schema. ```c static void on_password_stored (GObject *source, GAsyncResult *result, gpointer unused) { GError *error = NULL; secret_password_store_finish (result, &error); if (error != NULL) { /* ... handle the failure here */ g_error_free (error); } else { /* ... do something now that the password has been stored */ } } /* * The variable argument list is the attributes used to later * lookup the password. These attributes must conform to the schema. */ secret_password_store (EXAMPLE_SCHEMA, SECRET_COLLECTION_DEFAULT, "The label", "the password", NULL, on_password_stored, NULL, "number", 8, "string", "eight", "even", TRUE, NULL); ``` -------------------------------- ### Asynchronous Password Lookup Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Looks up a password asynchronously using attributes. Suitable for GUI applications to prevent UI blocking. Requires a schema and attributes to match the stored password. ```c static void on_password_lookup (GObject *source, GAsyncResult *result, gpointer unused) { GError *error = NULL; gchar *password = secret_password_lookup_finish (result, &error); if (error != NULL) { /* ... handle the failure here */ g_error_free (error); } else if (password == NULL) { /* password will be null, if no matching password found */ } else { /* ... do something with the password */ secret_password_free (password); } } /* * The variable argument list is the attributes used to later * lookup the password. These attributes must conform to the schema. */ secret_password_lookup (EXAMPLE_SCHEMA, NULL, on_password_lookup, NULL, "string", "nine", "even", FALSE, NULL); ``` -------------------------------- ### Store a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Stores a password in the secret service asynchronously, suitable for GUI applications to prevent UI blocking. Requires a schema, attributes, collection, label, password, and a callback function. ```python from gi.repository import Secret def on_password_stored(source, result, unused): Secret.password_store_finish(result) # ... do something now that the password has been stored # The attributes used to later lookup the password. These # attributes should conform to the schema. attributes = { "number": "8", "string": "eight", "even": "true" } Secret.password_store(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", None, on_password_stored) ``` -------------------------------- ### Store a Password Asynchronously with Yield Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Stores a password asynchronously within an async function using the 'yield' keyword. This is an alternative to callbacks for asynchronous operations. ```vala var attributes = new GLib.HashTable (); attributes["number"] = "8"; attributes["string"] = "eight"; attributes["even"] = "true"; bool res = yield Secret.password_storev (example_schema, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", null); ``` -------------------------------- ### Lookup a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Looks up a stored password asynchronously using a GLib.HashTable for attributes. This non-blocking method is ideal for GUI applications. ```vala var attributes = new GLib.HashTable (); attributes["number"] = "8"; attributes["string"] = "eight"; attributes["even"] = "true"; Secret.password_lookupv.begin (example_schema, attributes, null, (obj, async_res) => { string password = Secret.password_lookup.end (async_res); }); ``` -------------------------------- ### Store a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Stores a password synchronously, blocking the calling thread until the operation completes. This is suitable for non-GUI applications. ```vala Secret.password_store_sync (example_schema, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", null, "number", 9, "string", "nine", "even", false); ``` -------------------------------- ### Store a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Stores a password asynchronously using the secret service. This is suitable for GUI applications to prevent UI blocking. It requires a predefined schema and attributes. ```javascript const Secret = imports.gi.Secret; function on_password_stored(source, result) { Secret.password_store_finish(result); /* ... do something now that the password has been stored */ } /* * The attributes used to later lookup the password. These * attributes should conform to the schema. */ var attributes = { "number": "8", "string": "eight", "even": "true" }; Secret.password_store(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", null, on_password_stored); ``` -------------------------------- ### Lookup a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Looks up a password synchronously using a schema and lookup attributes, blocking until completion. Suitable for non-GUI applications. Returns the password or None if not found. ```python from gi.repository import Secret password = Secret.password_lookup_sync(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, None) # password will be null, if no matching password found ``` -------------------------------- ### Lookup a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Looks up a password asynchronously using a schema and lookup attributes. Suitable for GUI applications to avoid blocking the UI. The callback function receives the password or None if not found. ```python from gi.repository import Secret def on_password_lookup(source, result, unused): password = Secret.password_lookup_finish(result) # password will be null, if no matching password found Secret.password_lookup(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, None, on_password_lookup) ``` -------------------------------- ### Store a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Stores a password synchronously, blocking the function call until completion. Appropriate for non-GUI applications. Attributes must conform to the defined schema. ```c GError *error = NULL; /* * The variable argument list is the attributes used to later * lookup the password. These attributes must conform to the schema. */ secret_password_store_sync (EXAMPLE_SCHEMA, SECRET_COLLECTION_DEFAULT, "The label", "the password", NULL, &error, "number", 9, "string", "nine", "even", FALSE, NULL); if (error != NULL) { /* ... handle the failure here */ g_error_free (error); } else { /* ... do something now that the password has been stored */ } ``` -------------------------------- ### Lookup a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Looks up a stored password synchronously, blocking the calling thread until the lookup is complete. Returns null if no matching password is found. ```vala string password = Secret.password_lookup_sync (example_schema, attributes, null, "number", 9, "string", "nine", "even", false); /* password will be null, if no matching password found */ ``` -------------------------------- ### Define a Password Schema Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Defines a schema for password attributes. Schemas specify the names and types of attributes used to look up stored passwords. ```vala var example = new Secret.Schema ("org.example.Password", Secret.SchemaFlags.NONE, "number", Secret.SchemaAttributeType.INTEGER, "string", Secret.SchemaAttributeType.STRING, "even", Secret.SchemaAttributeType.BOOLEAN); ``` -------------------------------- ### Store a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Stores a password in the secret service synchronously, blocking the function call until completion. Suitable for non-GUI applications. Requires a schema, attributes, collection, label, and password. ```python from gi.repository import Secret # The attributes used to later lookup the password. These # attributes should conform to the schema. attributes = { "number": "8", "string": "eight", "even": "true" } Secret.password_store_sync(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", None) ``` -------------------------------- ### Store a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Stores a password synchronously using the secret service. This function call blocks until the password is stored, making it appropriate for non-GUI applications. It requires a predefined schema and attributes. ```javascript const Secret = imports.gi.Secret; /* * The attributes used to later lookup the password. These * attributes should conform to the schema. */ var attributes = { "number": "9", "string": "nine", "even": "false" }; Secret.password_store_sync(EXAMPLE_SCHEMA, attributes, Secret.COLLECTION_DEFAULT, "The label", "the password", null); ``` -------------------------------- ### Lookup a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Looks up a password asynchronously using the secret service. This is suitable for GUI applications to prevent UI blocking. It uses attributes conforming to a predefined schema. ```javascript const Secret = imports.gi.Secret; function on_password_lookup(source, result) { var password = Secret.password_lookup_finish(result); /* password will be null if no matching password found */ } /* The attributes used to lookup the password should conform to the schema. */ Secret.password_lookup(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, null, on_password_lookup); ``` -------------------------------- ### Define a Password Schema Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Defines a static password schema used for attribute-based password lookups. This schema is typically defined once globally. ```c // in a header: const SecretSchema * example_get_schema (void) G_GNUC_CONST; #define EXAMPLE_SCHEMA example_get_schema () // in a .c file: const SecretSchema * example_get_schema (void) { static const SecretSchema the_schema = { "org.example.Password", SECRET_SCHEMA_NONE, { { "number", SECRET_SCHEMA_ATTRIBUTE_INTEGER }, { "string", SECRET_SCHEMA_ATTRIBUTE_STRING }, { "even", SECRET_SCHEMA_ATTRIBUTE_BOOLEAN }, { "NULL", 0 }, } }; return &the_schema; } ``` -------------------------------- ### Asynchronously Clear Password Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Removes a password asynchronously using attributes. Suitable for GUI applications to prevent UI blocking. Requires a defined schema and attributes. ```vala var attributes = new GLib.HashTable (); attributes["number"] = "8"; attributes["string"] = "eight"; attributes["even"] = "true"; Secret.password_clearv.begin (example_schema, attributes, null, (obj, async_res) => { bool removed = Secret.password_clearv.end (async_res); }); ``` -------------------------------- ### Synchronous Password Lookup Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Looks up a password synchronously using attributes. This function call blocks until the lookup completes, making it suitable for non-GUI applications. Attributes must conform to the schema. ```c GError *error = NULL; /* The attributes used to lookup the password should conform to the schema. */ gchar *password = secret_password_lookup_sync (EXAMPLE_SCHEMA, NULL, &error, "string", "nine", "even", FALSE, NULL); if (error != NULL) { /* ... handle the failure here */ g_error_free (error); } else if (password == NULL) { /* password will be null, if no matching password found */ } else { /* ... do something with the password */ secret_password_free (password); } ``` -------------------------------- ### Define a Password Schema Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Defines a schema for password attributes, specifying their names and types. This schema is typically defined once globally. ```javascript const Secret = imports.gi.Secret; /* This schema is usually defined once globally */ const EXAMPLE_SCHEMA = new Secret.Schema.new("org.example.Password", Secret.SchemaFlags.NONE, { "number": Secret.SchemaAttributeType.INTEGER, "string": Secret.SchemaAttributeType.STRING, "even": Secret.SchemaAttributeType.BOOLEAN, } ); ``` -------------------------------- ### Lookup a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Looks up a password synchronously using the secret service. This function call blocks until the lookup completes, making it appropriate for non-GUI applications. It uses attributes conforming to a predefined schema. ```javascript const Secret = imports.gi.Secret; /* The attributes used to lookup the password should conform to the schema. */ var password = Secret.password_lookup_sync(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, null); /* password will be null, if no matching password found */ ``` -------------------------------- ### Synchronously Clear Password Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-vala-examples.md Removes a password synchronously using attributes. This function call blocks until the removal completes, making it suitable for non-GUI applications. Requires a defined schema and attributes. ```vala var attributes = new GLib.HashTable (); attributes["number"] = "8"; attributes["string"] = "eight"; attributes["even"] = "true"; bool removed = Secret.password_clear_sync (example_schema, null, "number", 8, "string", "eight", "even", true); /* removed will be true if the password was removed */ ``` -------------------------------- ### Define a Password Schema Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Defines a schema for password attributes, specifying attribute names and their types (integer, string, boolean). This schema is typically defined globally and used for all stored passwords. ```python from gi.repository import Secret EXAMPLE_SCHEMA = Secret.Schema.new("org.mock.type.Store", Secret.SchemaFlags.NONE, { "number": Secret.SchemaAttributeType.INTEGER, "string": Secret.SchemaAttributeType.STRING, "even": Secret.SchemaAttributeType.BOOLEAN, } ) ``` -------------------------------- ### Remove a Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Removes a password asynchronously from the secret service using a schema and attributes. Suitable for GUI applications. The callback function receives a boolean indicating if the password was removed. ```python from gi.repository import Secret def on_password_clear(source, result, unused): removed = Secret.password_clear_finish(result) # removed will be true if the password was removed Secret.password_clear(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, None, on_password_clear) ``` -------------------------------- ### Synchronous Password Removal Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Removes a password synchronously using attributes. This function call blocks until the removal completes, making it suitable for non-GUI applications. Attributes must conform to the schema. ```c GError *error = NULL; /* * The variable argument list is the attributes used to later * lookup the password. These attributes must conform to the schema. */ gboolean removed = secret_password_clear_sync (EXAMPLE_SCHEMA, NULL, &error, "string", "nine", "even", FALSE, NULL); if (error != NULL) { /* ... handle the failure here */ g_error_free (error); } else { /* removed will be TRUE if a password was removed */ } ``` -------------------------------- ### Asynchronous Password Removal Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-c-examples.md Removes a password asynchronously using attributes. This is appropriate for GUI applications to avoid blocking the user interface. The function returns TRUE if a password was removed. ```c static void on_password_cleared (GObject *source, GAsyncResult *result, gpointer unused) { GError *error = NULL; gboolean removed = secret_password_clear_finish (result, &error); if (error != NULL) { /* ... handle the failure here */ g_error_free (error); } else { /* removed will be TRUE if a password was removed */ } } /* * The variable argument list is the attributes used to later * lookup the password. These attributes must conform to the schema. */ secret_password_clear (EXAMPLE_SCHEMA, NULL, on_password_cleared, NULL, "string", "nine", "even", FALSE, NULL); ``` -------------------------------- ### Remove a Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-python-examples.md Removes a password synchronously from the secret service using a schema and attributes, blocking until completion. Suitable for non-GUI applications. Returns a boolean indicating if the password was removed. ```python from gi.repository import Secret removed = Secret.password_clear_sync(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, None) # removed will be true if the password was removed ``` -------------------------------- ### Remove Password Asynchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Removes a password asynchronously using its attributes. This is suitable for GUI applications to prevent UI blocking. The callback function `on_password_clear` is invoked upon completion. ```javascript const Secret = imports.gi.Secret; function on_password_clear(source, result) { var removed = Secret.password_clear_finish(result); /* removed will be true if the password was removed */ } /* The attributes used to lookup which password to remove should conform to the schema. */ Secret.password_clear(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, null, on_password_clear); ``` -------------------------------- ### Remove Password Synchronously Source: https://github.com/gnome/libsecret/blob/main/docs/reference/libsecret/libsecret-js-examples.md Removes a password synchronously using its attributes. This function call blocks until the removal is complete, making it suitable for non-GUI applications. The return value indicates if the password was successfully removed. ```javascript const Secret = imports.gi.Secret; /* The attributes used to lookup which password to remove should conform to the schema. */ var removed = Secret.password_clear_sync(EXAMPLE_SCHEMA, { "number": "8", "even": "true" }, null); /* removed will be true if the password was removed */ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.