Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use down-level libsecret functions to get secret values #244

Merged
merged 1 commit into from
Dec 3, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private static unsafe ICredential CreateCredentialFromItem(SecretItem* item)
GHashTable* secretAttrs = null;
IntPtr serviceKeyPtr = IntPtr.Zero;
IntPtr accountKeyPtr = IntPtr.Zero;
SecretValue* value = null;
IntPtr passwordPtr = IntPtr.Zero;
GError* error = null;

Expand All @@ -264,14 +265,14 @@ private static unsafe ICredential CreateCredentialFromItem(SecretItem* item)

// Load the secret value
secret_item_load_secret_sync(item, IntPtr.Zero, out error);
SecretValue* value = secret_item_get_secret(item);
value = secret_item_get_secret(item);
if (value == null)
{
throw new InteropException("Failed to load secret", -1);
}

// Extract the secret/password
passwordPtr = secret_value_unref_to_password(value, out int passwordLength);
passwordPtr = secret_value_get(value, out int passwordLength);
string password = Marshal.PtrToStringAuto(passwordPtr, passwordLength);

return new SecretServiceCredential(service, account, password);
Expand All @@ -281,6 +282,7 @@ private static unsafe ICredential CreateCredentialFromItem(SecretItem* item)
if (secretAttrs != null) g_hash_table_unref(secretAttrs);
if (accountKeyPtr != IntPtr.Zero) Marshal.FreeHGlobal(accountKeyPtr);
if (serviceKeyPtr != IntPtr.Zero) Marshal.FreeHGlobal(serviceKeyPtr);
if (value != null) secret_value_unref(value);
if (passwordPtr != IntPtr.Zero) secret_password_free(passwordPtr);
if (error != null) g_error_free(error);
}
Expand Down