public async override Task PopulateValue(string version = null, bool force = false) { if (version == null) { version = Identifier.Version; } if (Value != null && !force) { return; } try { if (Identifier.Version != null) { Value = (await Client.GetKeyAsync(Identifier.Vault, Identifier.Name, version)).Key; } else { Value = (await Client.GetKeyAsync(Identifier.Vault, Identifier.Name)).Key; } ValueRetrievalSuccess = true; AccessPolicy = new KeyAccessPolicy() { AccessPermissionString = Value.KeyOps }; } catch { ValueRetrievalSuccess = false; } }
public KeyVaultKey(KeyVaultClient client, KeyBundle keyBundleObject, bool currentVersion) : base(client, keyBundleObject) { CurrentVersion = currentVersion; Value = keyBundleObject.Key; AccessPolicy = new KeyAccessPolicy() { AccessPermissionString = Value.KeyOps }; }
public EntityAccessPolicy(AccessPolicyEntry originalPolicyEntry) { OriginalPolicyEntry = originalPolicyEntry; KeyPolicy = new KeyAccessPolicy() { AccessPermissionString = originalPolicyEntry.PermissionsToKeys }; SecretPolicy = new SecretAccessPolicy() { AccessPermissionString = originalPolicyEntry.PermissionsToSecrets }; }
public CreateKey() { AccessPolicy = new KeyAccessPolicy(); InitializeComponent(); operations.DataContext = AccessPolicy; }
public KeyVaultKey(KeyVaultClient client, KeyItem keyObject, bool currentVersion) : base(client, keyObject) { CurrentVersion = currentVersion; AccessPolicy = new KeyAccessPolicy(); }
public async Task <KeyVaultKey> CreateKey(string keyName, KeyAccessPolicy operations, KeyAttributes attributes = null) { var key = await Client.CreateKeyAsync(Vault.Properties.VaultUri, keyName, JsonWebKeyType.Rsa, key_ops : operations.AccessPermissionString, keyAttributes : attributes); return(new KeyVaultKey(Client, key, true)); }
private async void VaultSelector_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (e.AddedItems.Count == 0) { return; } var item = (IKeyVault)e.AddedItems.Single(); await ShowProgressDialog("Getting items from vault..."); var vault = (IKeyVault)item; var keyVaultServiceToken = (await Authentication.Instance.GetKeyVaultApiToken(vault.TenantId.ToString("D"))).AsBearer(); var svc = Factory.GetKeyVaultService(vault, keyVaultServiceToken); var secrets = await svc.GetSecrets(); var keys = await svc.GetKeys(); var castSecrets = secrets.Select(s => (IKeyVaultSecureItem)s); var castKeys = keys.Select(k => (IKeyVaultSecureItem)k); var secretsAndKeys = castSecrets.Union(castKeys); SelectedVault = new KeyVaultViewModel(vault) { ShowAccessPermissions = new ActionCommand(() => ShowAccessPermissions(vault)), ShowDeleteConfirmation = new ActionCommand(() => ShowVaultDeleteConfirmation(vault)), ShowAddKey = new ActionCommand(() => ShowAddKey(vault)), ShowAddSecret = new ActionCommand(() => ShowAddSecret(vault)), }; OnPropertyChanged(nameof(VaultSelectedVisibility)); OnPropertyChanged(nameof(SelectedVault)); var currentUserPolicy = vault.Properties.AccessPolicies.FirstOrDefault(p => p.ObjectId == LoggedInOid); if (currentUserPolicy == null) { SelectedVaultKeyPermissions = new KeyAccessPolicy(); SelectedVaultSecretPermissions = new SecretAccessPolicy(); } else { SelectedVaultKeyPermissions = new KeyAccessPolicy() { AccessPermissionString = currentUserPolicy.Permissions.Keys.ToArray() }; SelectedVaultSecretPermissions = new SecretAccessPolicy() { AccessPermissionString = currentUserPolicy.Permissions.Secrets.ToArray() }; } UpdateSecrets(secretsAndKeys.Select(x => { if (x is IKeyVaultSecret) { var vm = new KeyVaultSecretViewModel((IKeyVaultSecret)x); vm.ShowSecret = new ActionCommand(async() => vm.Secret = await svc.GetSecretValue((IKeyVaultSecret)x)); vm.SetSecret = new ActionCommand(async() => vm.Secret = await svc.SetSecretValue((IKeyVaultSecret)x, vm.Secret)); vm.ShowDeleteConfirmation = new ActionCommand(() => ShowItemDeleteConfirmation(x)); return((IKeyVaultItemViewModel)vm); } else if (x is IKeyVaultKey) { var vm = new KeyVaultKeyViewModel((IKeyVaultKey)x); vm.ShowKey = new ActionCommand(async() => vm.Key = await svc.GetKeyValue((IKeyVaultKey)x)); vm.ShowDeleteConfirmation = new ActionCommand(() => ShowItemDeleteConfirmation(x)); vm.ShowEncryptDialog = new ActionCommand(() => ShowEncryptDialog((IKeyVaultKey)x)); vm.ShowSignDialog = new ActionCommand(() => ShowSignDialog((IKeyVaultKey)x)); vm.ShowWrapDialog = new ActionCommand(() => ShowWrapDialog((IKeyVaultKey)x)); return((IKeyVaultItemViewModel)vm); } return(null); })); } catch (Exception ex) { ShowErrorDialog(ex.ToString()); } await HideProgressDialog(); }