Exemple #1
0
        public void GivenACommunicationVaultCreationRequest_WhenSendingTheMasterkey_ThenEncryptItUsingRSA()
        {
            const string data = "plainText";

            var rsa = new RSA();

            var manager       = rsa.RSAGenerateManager();
            var encryptedData = RSAHelper.EncryptWithPubKey(data, manager.PublicKey);
            var decryptedData = manager.Decrypt(encryptedData);

            Assert.AreEqual(data, decryptedData);
        }
        public async Task GivenRequestToCreateCommunicationVault_WhenCreatingACommunicationVault_ReturnACommunicationVaultInstance()
        {
            var vaultId   = "some-vault-id";
            var vaultName = "some-vault-name";
            var tags      = new List <string> {
                "some-vault-tag-1", "some-vault-tag-2"
            };

            var security       = new Security();
            var vaultMasterkey = security.Aes.GenerateStringMasterKey();

            Mock.Server.Given(Request.Create().WithPath("/vault/communication").UsingPost())
            .RespondWith(new ResponseProviderInterceptor((RequestMessage requestMessage) =>
            {
                var secLevelMasterkey  = security.Aes.GenerateStringMasterKey();
                var secLevelIv         = security.Aes.GenerateStringIv();
                var encryptedMasterKey = security.Aes.Encrypt(secLevelMasterkey, secLevelIv, vaultMasterkey);

                var request = JObject.Parse(requestMessage.Body);

                return(Response.Create()
                       .WithStatusCode(HttpStatusCode.OK)
                       .WithBody(JsonConvert.SerializeObject(new
                {
                    Id = vaultId,
                    Name = vaultName,
                    MasterKey = encryptedMasterKey.EncryptedData,
                    encryptedMasterKey.AuthTag,
                    encryptedMasterKey.Iv,
                    SessionKey = RSAHelper.EncryptWithPubKey(secLevelMasterkey, request.Value <string>("publicKey")),
                    Tags = tags
                })));
            }));

            var client = new Client();
            await client.Authenticate(Mock.API_KEY);

            var vault = await client.CreateCommunicationVault(vaultName, tags);

            Assert.AreEqual(vault.VaultId, vaultId);
            Assert.AreEqual(vault.VaultName, vaultName);
            Assert.AreEqual(vault.MasterKey, vaultMasterkey);

            Assert.IsNotNull(vault.Email);
        }