public KeyVaultClient(ConnectionParams connection, CredentialParams credential)
        {
            _keyVault = connection.GetAsNullableString("key_vault")
                        ?? connection.GetAsNullableString("uri")
                        ?? connection.GetAsNullableString("KeyVault");
            if (_keyVault == null)
            {
                throw new ArgumentNullException("KeyVault parameter is not defined");
            }
            if (!_keyVault.StartsWith("http"))
            {
                _keyVault = "https://" + _keyVault + ".vault.azure.net";
            }

            _clientId = credential.AccessId ?? credential.GetAsNullableString("ClientId");
            if (_clientId == null)
            {
                throw new ArgumentNullException("CliendId parameter is not defined");
            }

            _clientKey  = credential.AccessKey ?? credential.GetAsNullableString("ClientKey");
            _thumbPrint = credential.GetAsNullableString("thumbprint")
                          ?? credential.GetAsNullableString("ThumbPrint");
            if (_clientKey == null && _thumbPrint == null)
            {
                throw new ArgumentNullException("Neither ClientKey or ThumbPrint parameters are not defined");
            }

            _client = new Microsoft.Azure.KeyVault.KeyVaultClient(
                new Microsoft.Azure.KeyVault.KeyVaultClient.AuthenticationCallback(GetAccessToken));
        }
Ejemplo n.º 2
0
 public void Invoke(CancellationToken cancellationToken)
 {
     if (cancellationToken.IsCancellationRequested)
     {
         return;
     }
     ThreadHelper.JoinableTaskFactory.Run(() =>
     {
         string name, secret;
         var prompt = new Prompt();
         prompt.promptMessage.Text = "Supply the name for the secret!";
         prompt.ShowDialog();
         name = prompt.ResponseText;
         if (name is null || name == string.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         var promptv = new Prompt();
         promptv.promptMessage.Text = "Validate the secret (remove '', etc.)!";
         promptv.ResponseText       = value;
         promptv.ShowDialog();
         secret = promptv.ResponseText;
         if (secret is null || secret == string.Empty)
         {
             return(System.Threading.Tasks.Task.CompletedTask);
         }
         var vaultClient = new Microsoft.Azure.KeyVault.KeyVaultClient(new KeyVaultClient.AuthenticationCallback(new AzureServiceTokenProvider().KeyVaultTokenCallback));
         vaultClient.SetSecretAsync(Options.Instance.AKVUrl, name, secret).Wait();
         string aKVUrl = language == "PowerShell" || language == "InBoxPowerShell" ? Options.Instance.AKVShortName : Options.Instance.AKVUrl;
         _span.TextBuffer.Replace(_span.GetSpan(_snapshot), string.Format(replacementTexts[language], aKVUrl, name));
         return(System.Threading.Tasks.Task.CompletedTask);
     });
 }
Ejemplo n.º 3
0
        public async Task <SecretBundle> ReadSecret(string pubKey)
        {
            string kvUrl = "https://ready20kv.vault.azure.net/";

            kvClient = new Microsoft.Azure.KeyVault.KeyVaultClient(GetToken);

            return(await kvClient.GetSecretAsync(kvUrl, pubKey));
        }
 /// <summary>
 /// Verifies a signature using the specified key.
 /// </summary>
 /// <param name="verifyKey">The verification key</param>
 /// <param name="algorithm">The signing algorithm. For more information on possible algorithm types, see JsonWebKeyEncryptionAlgorithm.</param>
 /// <param name="digest">The digest hash value</param>
 /// <param name="signature">The signature to verify</param>
 /// <returns>True if verification succeeds, false if verification fails</returns>
 public static async Task <bool> VerifyAsync(this KeyVaultClient client, KeyBundle verifyKey, string algorithm, byte[] digest, byte[] signature)
 {
     return(await client.VerifyAsync(verifyKey.Key, algorithm, digest, signature).ConfigureAwait(false));
 }