https://github.com/ace4896/dbus.services.secrets
High-level .NET bindings for the D-Bus Secret Service API.
https://github.com/ace4896/dbus.services.secrets
csharp d-bus dotnet
Last synced: 5 months ago
JSON representation
High-level .NET bindings for the D-Bus Secret Service API.
- Host: GitHub
- URL: https://github.com/ace4896/dbus.services.secrets
- Owner: Ace4896
- License: mit
- Created: 2023-03-21T16:36:01.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T20:50:24.000Z (about 1 year ago)
- Last Synced: 2024-12-08T07:32:50.439Z (5 months ago)
- Topics: csharp, d-bus, dotnet
- Language: C#
- Homepage: https://ace4896.github.io/DBus.Services.Secrets/
- Size: 72.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# DBus.Services.Secrets
High-level .NET bindings for the [D-Bus Secret Service API](https://specifications.freedesktop.org/secret-service/latest/).
These bindings were made using [Tmds.DBus.Protocol](https://github.com/tmds/Tmds.DBus) and [Tmds.DBus.SourceGenerator](https://github.com/affederaffe/Tmds.DBus.SourceGenerator), making them trimmer and AOT friendly.
## Requirements
The bindings target .NET 6.0, .NET 7.0 and .NET 8.0.
## Basic Usage
To get started, add a reference to the [`Ace4896.DBus.Services.Secrets` NuGet package](https://www.nuget.org/packages/Ace4896.DBus.Services.Secrets/).
The example below shows how to create and retrieve a secret value in the default collection:
```csharp
// Connect to the D-Bus Secret Service API
// Sessions can use either plaintext or encrypted transport
SecretService secretService = await SecretService.ConnectAsync(EncryptionType.Dh); // DH Key Agreement for Encryption// Items are stored in within collections
// Collections can be retrieved using their alias
// Note that collection retrieval can fail, so this would need to be handled
Collection? defaultCollection = await secretService.GetDefaultCollectionAsync();
if (defaultCollection == null)
{
// ... handle case where collection is not found
}// Items are created with the following:
// - Label - The displayed label in e.g. GNOME Keyring, KWallet etc.
// - Lookup Attributes - These are used to search for the item later
// - Secret - The secret value as a byte array
// - Content Type - A content type hint for the secret value
string itemLabel = "MySecretValue";
Dictionary lookupAttributes = new()
{
{ "my-lookup-attribute", "my-lookup-attribute-value" }
};byte[] secretValue = Encoding.UTF8.GetBytes("my secret value");
string contentType = "text/plain; charset=utf8";// Note that item creation can fail, e.g. if the collection could not be unlocked
Item? createdItem = await defaultCollection.CreateItemAsync(label, lookupAttributes, secretBytes, contentType, true);
if (createdItem == null)
{
// ... handle case where item creation failed
}// Later, if we want to retrieve this secret value, we need to search using the same lookup attributes
// Note that it's possible for multiple items to match the provided lookup attributes
Item[] matchedItems = await defaultCollection.SearchItemsAsync(lookupAttributes);
foreach (Item matchedItem in matchedItems)
{
byte[] matchedSecret = await item.GetSecretAsync();
string matchedSecretString = Encoding.UTF8.GetString(secret); // my secret value
}
```## Documentation
The API documentation is auto-generated using [docfx](https://dotnet.github.io/docfx/index.html), and can be found [here](https://ace4896.github.io/DBus.Services.Secrets/).
To preview the generated documentation locally, run `docfx docfx_project/docfx.json --serve`, which will serve the website at http://localhost:8080.
## License
These bindings are licensed under the [MIT License](./LICENSE.md).