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

Low level Linux libsecret operations should throw exceptions #4497

Merged
merged 3 commits into from
Jan 13, 2024
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 @@ -3,6 +3,7 @@

using System;
using System.Runtime.InteropServices;
using Microsoft.Identity.Extensions;

namespace Microsoft.Identity.Client.Extensions.Msal
{
Expand Down Expand Up @@ -103,11 +104,14 @@ public void Clear()
try
{
GError err = (GError)Marshal.PtrToStructure(error, typeof(GError));
_logger.LogError($"An error was encountered while clearing secret from keyring in the {nameof(Storage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'");
throw new InteropException(
gladjohn marked this conversation as resolved.
Show resolved Hide resolved
$"An error was encountered while clearing secret from keyring in the {nameof(Storage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'",
err.Code);
}
catch (Exception e)
{
_logger.LogError($"An exception was encountered while processing libsecret error information during clearing secret in the {nameof(Storage)} ex:'{e}'");
throw new InteropException(
$"An exception was encountered while processing libsecret error information during clearing secret in the {nameof(Storage)} ex:'{e}'", 0, e);
}
}

Expand All @@ -116,8 +120,6 @@ public void Clear()

public byte[] Read()
{
_logger.LogInformation("ReadDataCore");

_logger.LogInformation($"ReadDataCore, Before reading from linux keyring");

byte[] fileData = null;
Expand All @@ -139,16 +141,18 @@ public byte[] Read()
try
{
GError err = (GError)Marshal.PtrToStructure(error, typeof(GError));
_logger.LogError($"An error was encountered while reading secret from keyring in the {nameof(Storage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'");
throw new InteropException(
$"An error was encountered while reading secret from keyring in the {nameof(Storage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'", err.Code);
}
catch (Exception e)
{
_logger.LogError($"An exception was encountered while processing libsecret error information during reading in the {nameof(Storage)} ex:'{e}'");
throw new InteropException(
$"An exception was encountered while processing libsecret error information during reading in the {nameof(Storage)} ex:'{e}'", 0, e);
}
}
else if (string.IsNullOrEmpty(secret))
{
_logger.LogError("No matching secret found in the keyring");
_logger.LogWarning("No matching secret found in the keyring");
}
else
{
Expand Down Expand Up @@ -184,11 +188,13 @@ public void Write(byte[] data)
try
{
GError err = (GError)Marshal.PtrToStructure(error, typeof(GError));
_logger.LogError($"An error was encountered while saving secret to keyring in the {nameof(Storage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'");
string message = $"An error was encountered while saving secret to keyring in the {nameof(Storage)} domain:'{err.Domain}' code:'{err.Code}' message:'{err.Message}'";
throw new InteropException(message, err.Code);
}
catch (Exception e)
{
_logger.LogError($"An exception was encountered while processing libsecret error information during saving in the {nameof(Storage)} ex:'{e}'");
throw new InteropException(
$"An exception was encountered while processing libsecret error information during saving in the {nameof(Storage)}", 0, e);
}
}

Expand All @@ -215,7 +221,7 @@ private IntPtr GetLibsecretSchema()

if (_libsecretSchema == IntPtr.Zero)
{
_logger.LogError($"Failed to create libsecret schema from the {nameof(Storage)}");
throw new InteropException("Failed to create libsecret schema from the {nameof(Storage)}", 0);
}

_logger.LogInformation("After creating libsecret schema");
Expand Down