Skip to content

Commit

Permalink
Merge pull request #244 from mjcheetham/libsecretfix
Browse files Browse the repository at this point in the history
Use down-level libsecret functions to get secret values
  • Loading branch information
mjcheetham committed Dec 3, 2020
2 parents a8e72d2 + 1fe1c38 commit 3c38f94
Showing 1 changed file with 4 additions and 2 deletions.
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

0 comments on commit 3c38f94

Please sign in to comment.