0

I would like to add a password from my application into the Linux secure store. I am trying to achieve this by using libsecret. What I have so far:

const SecretSchema *
example_get_schema (void)
{
    static const SecretSchema the_schema = {
        "TypingDnaActiveLock", SECRET_SCHEMA_NONE,
        {
            {  "value", SECRET_SCHEMA_ATTRIBUTE_STRING },
            {  "key", SECRET_SCHEMA_ATTRIBUTE_STRING },
        }
    };
    return &the_schema;
}

bool LinuxSecureStore::store(const std::string& key, const std::string& value) {

    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_get_schema(),
                               SECRET_COLLECTION_SESSION,
                               value.c_str(),
                               key.c_str(),
                               NULL,
                               &error);

    if (error != NULL) {
        /* ... handle the failure here */
        g_error_free (error);
        return false;
    } else {
        /* ... do something now that the password has been stored */
        return true;
    }
}

std::optional<std::string> LinuxSecureStore::get(const std::string& key, SecureStore::SecureStoreStatus& oppStatus) {
    GError *error = NULL;

    /* The attributes used to lookup the password should conform to the schema. */
    gchar *password = secret_password_lookup_sync (::example_get_schema(),NULL, &error, key.c_str());

    if (error != NULL) {
        /* ... handle the failure here */
        oppStatus = SecureStoreStatus::FAILURE;
        g_error_free (error);

    } else if (password == NULL) {
        /* password will be null, if no matching password found */
        oppStatus = SecureStoreStatus::ITEM_NOT_FOUND;
    } else {
        /* ... do something with the password */
        return password;
    }
    return std::nullopt;
}

And I make the following calls:

LinuxSecureStore ss;
ss.store("key","value");
LinuxSecureStore::SecureStoreStatus status;
ss.get("key",status);

The issue I see is that the secret_password_store_sync always sets the error to NULL like it would succeed, but I can not find the password in the keyring. And of course that the get method can not find it either. Do I miss something? The code is from libsecret examples

I have looked into the libsecret doc and every corner but I can not find anything useful.

avariant
  • 2,234
  • 5
  • 25
  • 33

0 Answers0