public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool?importToHsm) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } if (webKey == null) { throw new ArgumentNullException("webKey"); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes; webKey.KeyOps = keyAttributes.KeyOps; Client.KeyBundle clientKeyBundle = new Client.KeyBundle() { Attributes = clientAttributes, Key = webKey }; clientKeyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, clientKeyBundle, importToHsm).GetAwaiter().GetResult(); return(new KeyBundle(clientKeyBundle, this.vaultUriHelper)); }
public KeyBundle CreateKey(string vaultName, string keyName, KeyAttributes keyAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes; Client.KeyBundle clientKeyBundle = this.keyVaultClient.CreateKeyAsync( vaultAddress, keyName, keyAttributes.KeyType, key_ops: keyAttributes.KeyOps, keyAttributes: clientAttributes).GetAwaiter().GetResult(); return(new KeyBundle(clientKeyBundle, this.vaultUriHelper)); }
internal KeyBundle(Azure.KeyVault.Models.KeyBundle keyBundle, VaultUriHelper vaultUriHelper) { if (keyBundle == null) { throw new ArgumentNullException("keyBundle"); } if (keyBundle.Key == null || keyBundle.Attributes == null) { throw new ArgumentException(KeyVaultProperties.Resources.InvalidKeyBundle); } SetObjectIdentifier(vaultUriHelper, keyBundle.KeyIdentifier); Key = keyBundle.Key; Attributes = new KeyAttributes( keyBundle.Attributes.Enabled, keyBundle.Attributes.Expires, keyBundle.Attributes.NotBefore, keyBundle.Key.Kty, keyBundle.Key.KeyOps.ToArray(), keyBundle.Attributes.Created, keyBundle.Attributes.Updated, keyBundle.Attributes.RecoveryLevel, keyBundle.Tags); }
public KeyBundle SetKey(string vaultName, string keyName, KeyAttributes keyAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes; string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); Client.KeyBundle clientKeyBundle; try { clientKeyBundle = this.keyVaultClient.UpdateKeyAsync(vaultAddress, keyName, keyAttributes.KeyOps, attributes: clientAttributes).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new KeyBundle(clientKeyBundle, this.vaultUriHelper)); }
public RemoveKeyVaultKeyTests() { base.SetupTest(); cmdlet = new RemoveAzureKeyVaultKey() { CommandRuntime = commandRuntimeMock.Object, DataServiceClient = keyVaultClientMock.Object, VaultName = VaultName }; keyAttributes = new KeyAttributes(true, DateTime.Now, DateTime.Now, "HSM", new string[]{"All"}); webKey = new WebKey.JsonWebKey(); keyBundle = new KeyBundle() { Attributes = keyAttributes, Key = webKey, Name = KeyName, VaultName = VaultName }; }
public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool?importToHsm) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } if (webKey == null) { throw new ArgumentNullException("webKey"); } if (webKey.Kty == JsonWebKeyType.RsaHsm && (importToHsm.HasValue && !importToHsm.Value)) { throw new ArgumentException(KeyVaultProperties.Resources.ImportByokAsSoftkeyError); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); webKey.KeyOps = keyAttributes.KeyOps; var keyBundle = new Azure.KeyVault.Models.KeyBundle() { Attributes = (Azure.KeyVault.Models.KeyAttributes)keyAttributes, Key = webKey, Tags = keyAttributes.TagsDirectionary }; try { keyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, keyBundle, importToHsm).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new KeyBundle(keyBundle, this.vaultUriHelper)); }
public SetKeyVaultKeyTests() { base.SetupTest(); keyAttributes = new KeyAttributes(true, DateTime.Now, DateTime.Now, null, null); webKey = new WebKey.JsonWebKey(); keyBundle = new KeyBundle() { Attributes = keyAttributes, Key = webKey, Name = KeyName, VaultName = VaultName, Version = KeyVersion }; cmdlet = new SetAzureKeyVaultKey() { CommandRuntime = commandRuntimeMock.Object, DataServiceClient = keyVaultClientMock.Object, VaultName = VaultName, Enable = (bool)keyAttributes.Enabled, Expires = keyAttributes.Expires, NotBefore = keyAttributes.NotBefore, Name = KeyName }; }
internal KeyBundle(Azure.KeyVault.KeyBundle keyBundle, VaultUriHelper vaultUriHelper) { if (keyBundle == null) throw new ArgumentNullException("keyBundle"); if (keyBundle.Key == null || keyBundle.Attributes == null) throw new ArgumentException(KeyVaultProperties.Resources.InvalidKeyBundle); SetObjectIdentifier(vaultUriHelper,keyBundle.KeyIdentifier); Key = keyBundle.Key; Attributes = new KeyAttributes( keyBundle.Attributes.Enabled, keyBundle.Attributes.Expires, keyBundle.Attributes.NotBefore, keyBundle.Key.Kty, keyBundle.Key.KeyOps, keyBundle.Attributes.Created, keyBundle.Attributes.Updated, keyBundle.Tags); }
internal KeyBundle(Client.KeyBundle clientKeyBundle, VaultUriHelper vaultUriHelper) { if (clientKeyBundle == null) { throw new ArgumentNullException("clientKeyBundle"); } if (clientKeyBundle.Key == null || clientKeyBundle.Attributes == null) { throw new ArgumentException(Resources.InvalidKeyBundle); } SetObjectIdentifier(vaultUriHelper, new Client.KeyIdentifier(clientKeyBundle.Key.Kid)); Key = clientKeyBundle.Key; Attributes = new KeyAttributes( clientKeyBundle.Attributes.Enabled, clientKeyBundle.Attributes.Expires, clientKeyBundle.Attributes.NotBefore, clientKeyBundle.Key.Kty, clientKeyBundle.Key.KeyOps); Id = clientKeyBundle.Key.Kid; }
internal KeyIdentityItem(Client.KeyItem clientKeyItem, VaultUriHelper vaultUriHelper) { if (clientKeyItem == null) { throw new ArgumentNullException("clientKeyItem"); } if (String.IsNullOrEmpty(clientKeyItem.Kid) || clientKeyItem.Attributes == null) { throw new ArgumentException(Resources.InvalidKeyBundle); } SetObjectIdentifier(vaultUriHelper, new Client.KeyIdentifier(clientKeyItem.Kid)); var attribute = new KeyAttributes( clientKeyItem.Attributes.Enabled, clientKeyItem.Attributes.Expires, clientKeyItem.Attributes.NotBefore); Enabled = attribute.Enabled; Expires = attribute.Expires; NotBefore = attribute.NotBefore; Id = clientKeyItem.Kid; }
public KeyBundle CreateKey(string vaultName, string keyName, KeyAttributes keyAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); var attributes = (Azure.KeyVault.Models.KeyAttributes)keyAttributes; Azure.KeyVault.Models.KeyBundle keyBundle; try { keyBundle = this.keyVaultClient.CreateKeyAsync( vaultAddress, keyName, keyAttributes.KeyType, keyOps: keyAttributes.KeyOps == null ? null : new List <string> (keyAttributes.KeyOps), keyAttributes: attributes, tags: keyAttributes.TagsDirectionary).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new KeyBundle(keyBundle, this.vaultUriHelper)); }
public KeyBundle CreateKey(string vaultName, string keyName, KeyAttributes keyAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes; Client.KeyBundle clientKeyBundle; try { clientKeyBundle = this.keyVaultClient.CreateKeyAsync( vaultAddress, keyName, keyAttributes.KeyType, key_ops: keyAttributes.KeyOps, keyAttributes: clientAttributes).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return new KeyBundle(clientKeyBundle, this.vaultUriHelper); }
public KeyBundle UpdateKey(string vaultName, string keyName, string keyVersion, KeyAttributes keyAttributes) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } var attributes = (Azure.KeyVault.Models.KeyAttributes)keyAttributes; var keyIdentifier = new KeyIdentifier(this.vaultUriHelper.CreateVaultAddress(vaultName), keyName, keyVersion); Azure.KeyVault.Models.KeyBundle keyBundle; try { keyBundle = this.keyVaultClient.UpdateKeyAsync( keyIdentifier.Identifier, keyAttributes.KeyOps, attributes: attributes, tags: keyAttributes.TagsDirectionary).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return(new KeyBundle(keyBundle, this.vaultUriHelper)); }
public KeyBundle ImportKey(string vaultName, string keyName, KeyAttributes keyAttributes, JsonWebKey webKey, bool? importToHsm) { if (string.IsNullOrEmpty(vaultName)) { throw new ArgumentNullException("vaultName"); } if (string.IsNullOrEmpty(keyName)) { throw new ArgumentNullException("keyName"); } if (keyAttributes == null) { throw new ArgumentNullException("keyAttributes"); } if (webKey == null) { throw new ArgumentNullException("webKey"); } string vaultAddress = this.vaultUriHelper.CreateVaultAddress(vaultName); Client.KeyAttributes clientAttributes = (Client.KeyAttributes)keyAttributes; webKey.KeyOps = keyAttributes.KeyOps; Client.KeyBundle clientKeyBundle = new Client.KeyBundle() { Attributes = clientAttributes, Key = webKey }; try { clientKeyBundle = this.keyVaultClient.ImportKeyAsync(vaultAddress, keyName, clientKeyBundle, importToHsm).GetAwaiter().GetResult(); } catch (Exception ex) { throw GetInnerException(ex); } return new KeyBundle(clientKeyBundle, this.vaultUriHelper); }
public override void ExecuteCmdlet() { KeyAttributes attributes = new KeyAttributes { Enabled = this.Enable, Expires = this.Expires, NotBefore = this.NotBefore, KeyOps = this.KeyOps }; WriteObject(DataServiceClient.SetKey(VaultName, Name, attributes)); }