Skip to content

Commit

Permalink
Add an option to enable/disable key links during publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Feb 12, 2024
1 parent f56b246 commit 14157f1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 16 deletions.
9 changes: 9 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@
<data name="RandomLength" xml:space="preserve">
<value>Taille aléatoire</value>
</data>
<data name="ResolveKeyLinks" xml:space="preserve">
<value>Résoudre la liaison des clés</value>
</data>
<data name="Salt" xml:space="preserve">
<value>Sel</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@
<data name="RandomLength" xml:space="preserve">
<value>Random Length</value>
</data>
<data name="ResolveKeyLinks" xml:space="preserve">
<value>Resolve Key links</value>
</data>
<data name="Salt" xml:space="preserve">
<value>Salt</value>
</data>
Expand Down
6 changes: 5 additions & 1 deletion KeyManager.Library.UI/PublishKeyStoreDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
<TabItem Header="{x:Static properties:Resources.Options}">
<StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<ToggleButton IsChecked="{Binding Properties.Options.GenerateKeys}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<ToggleButton IsChecked="{Binding Options.GenerateKeys}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.GenerateKeyEntries}" Padding="3" />
</StackPanel>
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="5">
<ToggleButton IsChecked="{Binding Options.ResolveKeyLinks}" Style="{StaticResource MaterialDesignSwitchLightToggleButton}" />
<TextBlock Text="{x:Static properties:Resources.ResolveKeyLinks}" Padding="3" />
</StackPanel>
<Expander HorizontalAlignment="Stretch" Header="{x:Static properties:Resources.WrappingKey}" Margin="5">
<StackPanel Orientation="Vertical" TextBlock.Foreground="{DynamicResource MaterialDesignBody}" Margin="24,8,24,16">
<local:KeyEntryIdControl KeyEntryId="{Binding Options.WrappingKey.KeyId, Mode=TwoWay}" />
Expand Down
40 changes: 25 additions & 15 deletions KeyManager.Library/KeyStore/KeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,36 @@ public virtual async Task Publish(KeyStore store, Func<string, KeyStore?> getFav
entry.Identifier = entry.Identifier.Clone(Attributes);
if (entry.Link != null && entry.Link.KeyIdentifier.IsConfigured() && !string.IsNullOrEmpty(entry.Link.KeyStoreFavorite))
{
var cryptogram = new KeyEntryCryptogram
if ((Options?.ResolveKeyLinks).GetValueOrDefault(true))
{
Identifier = id
// TODO: we may want to have a different wrapping key per Cryptogram later on
};

var ks = getFavoriteKeyStore(entry.Link.KeyStoreFavorite);
if (ks != null)
{
await ks.Open();
var divContext = new DivInput.DivInputContext
var cryptogram = new KeyEntryCryptogram
{
KeyStore = ks,
KeyEntry = entry
Identifier = id
// TODO: we may want to have a different wrapping key per Cryptogram later on
};
cryptogram.Value = await ks.ResolveKeyEntryLink(entry.Link.KeyIdentifier.Clone(Attributes), keClass, ComputeDivInput(divContext, entry.Link.DivInput), entry.Link.WrappingKey);
await ks.Close();

var ks = getFavoriteKeyStore(entry.Link.KeyStoreFavorite);
if (ks != null)
{
await ks.Open();
var divContext = new DivInput.DivInputContext
{
KeyStore = ks,
KeyEntry = entry
};
cryptogram.Value = await ks.ResolveKeyEntryLink(entry.Link.KeyIdentifier.Clone(Attributes), keClass, ComputeDivInput(divContext, entry.Link.DivInput), entry.Link.WrappingKey);
await ks.Close();
}
changes.Add(cryptogram);
}
else
{
changes.Add(entry);
}
}
else
{
if (entry.Variant != null)
if ((Options?.ResolveKeyLinks).GetValueOrDefault(true) && entry.Variant != null)
{
foreach (var kv in entry.Variant.KeyContainers)
{
Expand All @@ -301,6 +309,8 @@ public virtual async Task Publish(KeyStore store, Func<string, KeyStore?> getFav
kv.Key.SetAggregatedValueAsString(await ks.ResolveKeyLink(kv.Key.Link.KeyIdentifier.Clone(Attributes), keClass, kv.Key.Link.ContainerSelector, ComputeDivInput(divContext, kv.Key.Link.DivInput)));
await ks.Close();
}
// We remove link information from the being pushed key entry
kv.Key.Link = new KeyLink();
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions KeyManager.Library/KeyStore/StoreOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class StoreOptions : ObservableObject
public StoreOptions()
{
_wrappingKey = new WrappingKey();
_resolveKeyLinks = true;
}

private WrappingKey _wrappingKey;
Expand All @@ -22,5 +23,12 @@ public bool GenerateKeys
get => _generateKeys;
set => SetProperty(ref _generateKeys, value);
}

private bool _resolveKeyLinks;
public bool ResolveKeyLinks
{
get => _resolveKeyLinks;
set => SetProperty(ref _resolveKeyLinks, value);
}
}
}

0 comments on commit 14157f1

Please sign in to comment.