Ejemplo n.º 1
0
        public async void TestCreateSecp256k1Key()
        {
            var token = await TestUtil.CreateIdentForTestUser();

            var vlt = Vault.InitVault(token);

            provide.Model.Vault.Vault vault = await vlt.CreateVault(
                new provide.Model.Vault.Vault
            {
                Name = "TestVault"
            }
                );

            var key = await vlt.CreateVaultKey(
                vault.Id.ToString(),
                new Key
            {
                Type        = "asymmetric",
                Usage       = "sign/verify",
                Spec        = "secp256k1",
                Name        = "TestKey",
                Description = "Key used to test signing"
            }
                );

            Assert.NotNull(key.Id);
            Assert.NotNull(key.Address);
            Assert.Equal("secp256k1", key.Spec);
        }
Ejemplo n.º 2
0
        public async Task can_delete_key_via_listed()
        {
            provide.Model.Vault.Vault vault = new provide.Model.Vault.Vault();
            vault.Name        = "Wallet Vault Test";
            vault.Description = "Test Vault used for test purposes";

            provide.Model.Vault.Vault createdVault = await _vaultService.CreateVault(vault);

            Key key = new Key();

            key.Name        = "Test Key";
            key.Description = "Test Key used for test purposes";
            key.Type        = "asymmetric";
            key.Spec        = "secp256k1";
            key.Usage       = "sign/verify";

            _ = await _vaultService.CreateKey(createdVault.Id.Value, key);

            var keys = await _vaultService.ListKeys(createdVault.Id.Value);

            foreach (var listedKey in keys)
            {
                await _vaultService.DeleteKey(createdVault.Id.Value, listedKey.Id.Value);
            }
        }
Ejemplo n.º 3
0
        public async void TestCreateSecret()
        {
            var token = await TestUtil.CreateIdentForTestUser();

            var vlt = Vault.InitVault(token);

            provide.Model.Vault.Vault vault = await vlt.CreateVault(
                new provide.Model.Vault.Vault
            {
                Name = "TestVault"
            }
                );

            var secret = await vlt.CreateVaultSecret(
                vault.Id.ToString(),
                new Secret
            {
                Type        = "some arbitrary type...",
                Name        = "TestKey",
                Description = "Key used to test signing",
                Value       = "my secret value"
            }
                );

            Assert.NotNull(secret.Id);
        }
Ejemplo n.º 4
0
        public async Task can_delete_a_vault()
        {
            ResultWrapper <string[]> listVaultsResponse = await _vaultModule.vault_listVaults();

            listVaultsResponse.Data.Should().HaveCount(2);

            provide.Model.Vault.Vault vault = new provide.Model.Vault.Vault();
            vault.Name        = "Name 0";
            vault.Description = "Test Vault used for test purposes";

            ResultWrapper <provide.Model.Vault.Vault> createVaultResponse
                = await _vaultModule.vault_createVault(vault);

            Guid?vaultId = createVaultResponse.Data.Id;

            vaultId.Should().NotBeNull();

            listVaultsResponse = await _vaultModule.vault_listVaults();

            listVaultsResponse.Data.Should().HaveCount(3);

            ResultWrapper <provide.Model.Vault.Vault> deleteVaultResponse
                = await _vaultModule.vault_deleteVault(vaultId.ToString());

            deleteVaultResponse.Result.Error.Should().BeNull();
            deleteVaultResponse.ErrorCode.Should().Be(0);
            deleteVaultResponse.Data.Should().BeNull();
            deleteVaultResponse.Result.ResultType.Should().Be(ResultType.Success);

            listVaultsResponse = await _vaultModule.vault_listVaults();

            listVaultsResponse.Data.Should().HaveCount(2);

            listVaultsResponse.Data.Should().NotContain(vaultId.ToString());
        }
Ejemplo n.º 5
0
        public async Task SetUp()
        {
            _config        = new VaultConfig();
            _config.Host   = "localhost:8082";
            _config.Scheme = "http";
            _config.Path   = "api/v1";
            _config.Token  = $"bearer  {TestContext.Parameters["token"]}";

            var vaultSealingForTestsHelper = new VaultSealingForTestsHelper(_config);
            await vaultSealingForTestsHelper.Unseal();

            _vaultService = new VaultService(_config, new TestLogManager(LogLevel.Trace));
            _vaultModule  = new VaultModule(_vaultService, new TestLogManager(LogLevel.Trace));

            provide.Model.Vault.Vault vault = new provide.Model.Vault.Vault();
            vault.Name        = "Test Vault";
            vault.Description = "Test Vault used for test purposes";
            ResultWrapper <provide.Model.Vault.Vault> res = await _vaultModule.vault_createVault(vault);

            if (res.Result != Result.Success || res.Data.Id is null)
            {
                throw new ApplicationException("Failed to create vault");
            }

            _vaultId = res.Data.Id.Value;
        }
Ejemplo n.º 6
0
        public async Task can_create_a_new_vault()
        {
            provide.Model.Vault.Vault vault = new provide.Model.Vault.Vault();
            vault.Name        = "Wallet Vault Test";
            vault.Description = "Test Vault used for test purposes";

            provide.Model.Vault.Vault result = await _vaultService.CreateVault(vault);

            result.Should().NotBeNull();
            result.Id.Should().NotBeNull();
        }
Ejemplo n.º 7
0
        public async Task <ResultWrapper <provide.Model.Vault.Vault> > vault_deleteVault(string vaultId)
        {
            try
            {
                provide.Model.Vault.Vault result = await _vaultService.DeleteVault(Guid.Parse(vaultId));

                return(ResultWrapper <provide.Model.Vault.Vault> .Success(result));
            }
            catch (Exception e)
            {
                return(ResultWrapper <provide.Model.Vault.Vault> .Fail(e));
            }
        }
Ejemplo n.º 8
0
        public async Task <ResultWrapper <provide.Model.Vault.Vault> > vault_createVault(provide.Model.Vault.Vault vault)
        {
            try
            {
                provide.Model.Vault.Vault vaultId = await _vaultService.CreateVault(vault);

                return(ResultWrapper <provide.Model.Vault.Vault> .Success(vaultId));
            }
            catch (Exception e)
            {
                return(ResultWrapper <provide.Model.Vault.Vault> .Fail(e));
            }
        }
Ejemplo n.º 9
0
        public async void TestCreateVault()
        {
            var token = await TestUtil.CreateIdentForTestUser();

            var vlt = Vault.InitVault(token);

            provide.Model.Vault.Vault vault = await vlt.CreateVault(new provide.Model.Vault.Vault
            {
                Name = "TestVault",
            });

            Assert.NotNull(vault.Id);
            Assert.Equal("TestVault", vault.Name);
        }
Ejemplo n.º 10
0
        public async Task can_create_a_new_vault()
        {
            provide.Model.Vault.Vault vault = new provide.Model.Vault.Vault();
            vault.Name        = "Test Vault";
            vault.Description = "Test Vault used for test purposes";

            ResultWrapper <provide.Model.Vault.Vault> createVaultResponse
                = await _vaultModule.vault_createVault(vault);

            createVaultResponse.Result.Error.Should().Be(null);
            createVaultResponse.ErrorCode.Should().Be(0);
            createVaultResponse.Data.Should().NotBeNull();
            createVaultResponse.Result.ResultType.Should().Be(ResultType.Success);
        }
Ejemplo n.º 11
0
        public async Task can_return_a_list_of_vaults()
        {
            provide.Model.Vault.Vault vault = new provide.Model.Vault.Vault();
            vault.Name        = "Wallet Vault Test";
            vault.Description = "Test Vault used for test purposes";

            provide.Model.Vault.Vault createdVault = await _vaultService.CreateVault(vault);

            createdVault.Id.Should().NotBeNull();

            IEnumerable <Guid> result = await _vaultService.ListVaultIds();

            result.Should().Contain(createdVault.Id !.Value);
        }
Ejemplo n.º 12
0
        public async void TestSignAndVerifyMessage()
        {
            var message = "02a285b1a277f7602dc115a3bf627a8b7603a4a1be9a72b3ab0284878afe443d"; // secp256k1 signing requests must send 32-byte `message` (ie hash the data first...)
            var token   = await TestUtil.CreateIdentForTestUser();

            var vlt = Vault.InitVault(token);

            provide.Model.Vault.Vault vault = await vlt.CreateVault(
                new provide.Model.Vault.Vault
            {
                Name = "TestVault"
            }
                );

            var generatedKey = await vlt.CreateVaultKey(
                vault.Id.ToString(),
                new Key
            {
                Type        = "asymmetric",
                Usage       = "sign/verify",
                Spec        = "secp256k1",
                Name        = "TestKey",
                Description = "Key used to test signing"
            }
                );

            // sign and assert
            var signReq = new SignMessageRequest
            {
                Message = message,
                Options = new Dictionary <string, object>()
            };
            var signedMessage = await vlt.SignMessage(vault.Id.ToString(), generatedKey.Id.ToString(), signReq);

            Assert.NotNull(signedMessage.Signature);
            Assert.NotEmpty(signedMessage.Signature);

            // verify and assert
            var verificationReq = new SignatureVerificationRequest
            {
                Message   = message,
                Signature = signedMessage.Signature,
                Options   = new Dictionary <string, object>()
            };
            var verifiedMessage = await vlt.VerifySignature(vault.Id.ToString(), generatedKey.Id.ToString(), verificationReq);

            Assert.True(verifiedMessage.Verified);
        }
Ejemplo n.º 13
0
        public async Task <provide.Model.Vault.Vault> CreateVault(provide.Model.Vault.Vault vault)
        {
            if (vault.Name == null)
            {
                throw new ArgumentException(
                          $"{nameof(provide.Model.Vault.Vault)} has to have a non-NULL {nameof(vault.Name)}");
            }

            if (vault.Description == null)
            {
                throw new ArgumentException(
                          $"{nameof(provide.Model.Vault.Vault)} has to have a non-NULL {nameof(vault.Description)}");
            }

            if (_logger.IsDebug)
            {
                _logger.Debug($"Creating a vault {vault.Name} {vault.Description}");
            }
            provide.Model.Vault.Vault result = await _vaultService.CreateVault(vault);

            return(result);
        }
Ejemplo n.º 14
0
        // CreateVault creates a new vault available within the key management service
        public async Task <provide.Model.Vault.Vault> CreateVault(provide.Model.Vault.Vault vault)
        {
            var uri = "vaults";

            return(await this.Post <provide.Model.Vault.Vault>(uri, vault));
        }