Esempio n. 1
0
        public void CanCreateContainer()
        {
            Stream publicPrivateKeyStream;
            var sdkUser = _ojibweClient.Register("TestUserCreateContainer", "Password01", out publicPrivateKeyStream);

            IContainer container = new Container();
            container.Name = "Top Secret";

            var sdkContainer = sdkUser.Containers.Add(container);
            Assert.True(sdkContainer.OwnerUserId == sdkUser.Id);
        }
Esempio n. 2
0
        public void CanGetUserKeyByBlobId()
        {
            Stream publicPrivateKeyStream;
            var sdkUser = _ojibweClient.Register("TestUserStoreBlob", "Password01", out publicPrivateKeyStream);

            Assert.False(sdkUser.PublicKeyId.Equals(Guid.Empty));

            IContainer container = new Container();
            container.Name = "Top Secret";

            var sdkContainer = sdkUser.Containers.Add(container);
            Assert.True(sdkContainer.OwnerUserId == sdkUser.Id);

            Random r = new Random();
            byte[] randomBuffer = new byte[16];
            r.NextBytes(randomBuffer);

            MemoryStream memoryStream = new MemoryStream(randomBuffer);
            memoryStream.Position = 0;

            ISdkBlob sdkBlob = sdkContainer.Blobs.New();
            sdkBlob.SetData(sdkUser, memoryStream);

            Assert.NotNull(sdkBlob.StorageKey);

            sdkBlob.Info.Add("key1", "value1");

            Assert.True(sdkBlob.Save());

            Assert.NotNull(sdkBlob);

            sdkBlob = _ojibweClient.GetBlob(sdkBlob.Id);

            using (var decrypted = sdkBlob.GetData(sdkUser))
            {

                byte[] actual = StreamUtility.GetBytes(decrypted);

                Assert.True(actual.SequenceEqual(randomBuffer), "Decrypted Stream does not equal source.");
            }

            var sdkKey = sdkUser.GetUserKeyByBlobId(sdkBlob.Id);

            Assert.NotNull(sdkKey);
        }
Esempio n. 3
0
        //Ignore .. used in testing.. not practical for CI to run
        //[Fact]
        public void CanStoreVeryLargeBlobInContainer()
        {
            Stream publicPrivateKeyStream;
            var sdkUser = _ojibweClient.Register("TestUserStoreBlob", "Password01", out publicPrivateKeyStream);

            Assert.False(sdkUser.PublicKeyId.Equals(Guid.Empty));

            IContainer container = new Container();
            container.Name = "Top Secret";

            var sdkContainer = sdkUser.Containers.Add(container);
            Assert.True(sdkContainer.OwnerUserId == sdkUser.Id);

            Random r = new Random();
            using (var expectedStream = StreamUtility.GetTempFileStream())
            {
                byte[] buffer = new byte[1024 * 1024 * 4];
                for (int i = 0; i < 1025; i++)
                {
                    r.NextBytes(buffer);
                    expectedStream.Write(buffer, 0, buffer.Length);
                }
                expectedStream.Position = 0;
                ISdkBlob sdkBlob = sdkContainer.Blobs.New();
                sdkBlob.SetData(sdkUser, expectedStream);

                Assert.NotNull(sdkBlob);

                using (var actualStream = sdkBlob.GetData(sdkUser))
                {
                    expectedStream.Position = 0;
                    actualStream.Position = 0;
                    Assert.True(StreamEquals(expectedStream, actualStream));
                }
            }
        }
Esempio n. 4
0
        //[Fact]
        public void CanStoreMultipleBlobInContainer_StressTest()
        {
            Stream publicPrivateKeyStream;
            var sdkUser = _ojibweClient.Register("TestUserStoreBlob", "Password01", out publicPrivateKeyStream);

            Assert.False(sdkUser.PublicKeyId.Equals(Guid.Empty));

            IContainer container = new Container();
            container.Name = "Top Secret";

            var sdkContainer = sdkUser.Containers.Add(container);
            Assert.True(sdkContainer.OwnerUserId == sdkUser.Id);

            int blobSizeInMb = 64;
            int numberOfBlobs = 24;
            int maxThreads = 8;

            Random r = new Random();

            Parallel.For(0, numberOfBlobs, new ParallelOptions() { MaxDegreeOfParallelism = maxThreads }, (j) =>
            {
                try
                {
                    using (var expectedStream = StreamUtility.GetTempFileStream())
                    {
                        byte[] buffer = new byte[1024 * 1024];
                        for (int i = 0; i < blobSizeInMb; i++)
                        {
                            r.NextBytes(buffer);
                            expectedStream.Write(buffer, 0, buffer.Length);
                        }
                        expectedStream.Position = 0;
                        ISdkBlob sdkBlob = sdkContainer.Blobs.New();
                        sdkBlob.SetData(sdkUser, expectedStream);

                        Assert.NotNull(sdkBlob);

                        using (var actualStream = sdkBlob.GetData(sdkUser))
                        {
                            expectedStream.Position = 0;
                            actualStream.Position = 0;
                            Assert.True(StreamEquals(expectedStream, actualStream));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    //Assert if we catch
                    Assert.Null(ex);
                }

            });
        }
Esempio n. 5
0
        public void CanSearchSharedBlobInfoGlobal()
        {
            string user1Username = "******";
            string user1Password = "******";
            string user2Username = "******";
            string user2Password = "******";

            Stream user1PrivateKey;
            var sdkUser1 = _ojibweClient.Register(user1Username, user1Password, out user1PrivateKey);
            Assert.NotNull(sdkUser1);
            Stream user2PrivateKey;
            var sdkUser2 = _ojibweClient.Register(user2Username, user2Password, out user2PrivateKey);
            Assert.NotNull(sdkUser2);

            var sdkCurrentUser = _ojibweClient.Login(user1Username, user1Password, user1PrivateKey);

            string user1Container = "Container1";

            Container container1 = new Container();
            container1.Name = user1Container;

            var sdkContainer1 = sdkCurrentUser.Containers.Add(container1);

            for (int i = 0; i < 10; i++)
            {
                Random r = new Random();
                byte[] randomBuffer = new byte[1024*1024];
                r.NextBytes(randomBuffer);

                ISdkBlob sdkBlob1 = sdkContainer1.Blobs.New();

                using (MemoryStream memoryStream = new MemoryStream(randomBuffer))
                {
                    sdkBlob1.SetData(sdkCurrentUser, memoryStream);
                }

                Assert.NotNull(sdkBlob1.StorageKey);

                sdkBlob1.Info.Add(string.Format("KEY-{0}", i), "VALUE");

                Assert.True(sdkBlob1.Save());
                sdkBlob1.Refresh();

                Assert.NotNull(sdkBlob1);

                var sdkUser2Object = _ojibweClient.GetUserByUsername(user2Username);

                Assert.True(sdkBlob1.Share(sdkCurrentUser, sdkUser2Object));

                sdkBlob1.Refresh();
            }

            //Switch Users

            sdkCurrentUser = _ojibweClient.Login(user2Username, user2Password, user2PrivateKey);

            for (int i = 0; i < 10; i++)
            {
                var results = _ojibweClient.SearchBlobsByInfo(string.Format("KEY-{0}", i));

                Assert.True(results.Count() == 1);
            }
        }
Esempio n. 6
0
        public void CanShareBlob()
        {
            string user1Username = "******";
            string user1Password = "******";
            string user2Username = "******";
            string user2Password = "******";

            Stream user1PrivateKey;
            var sdkUser1 = _ojibweClient.Register(user1Username, user1Password, out user1PrivateKey);
            Assert.NotNull(sdkUser1);
            Stream user2PrivateKey;
            var sdkUser2 = _ojibweClient.Register(user2Username, user2Password, out user2PrivateKey);
            Assert.NotNull(sdkUser2);

            var sdkCurrentUser = _ojibweClient.Login(user1Username, user1Password, user1PrivateKey);

            string user1Container = "Container1";

            Container container1 = new Container();
            container1.Name = user1Container;

            var sdkContainer1 = sdkCurrentUser.Containers.Add(container1);

            Random r = new Random();
            byte[] randomBuffer = new byte[1024*1024];
            r.NextBytes(randomBuffer);

            MemoryStream memoryStream = new MemoryStream(randomBuffer);

            ISdkBlob sdkBlob1 = sdkContainer1.Blobs.New();
            sdkBlob1.SetData(sdkUser1, memoryStream);

            Assert.True(sdkBlob1.Save());

            Assert.NotNull(sdkBlob1);

            var sdkUser2Object = _ojibweClient.GetUserByUsername(user2Username);

            Assert.True(sdkBlob1.Share(sdkUser1, sdkUser2Object));

            //Switch Users

            sdkCurrentUser = _ojibweClient.Login(user2Username, user2Password, user2PrivateKey);

            string user2Container = "Container2";

            Container container2 = new Container();
            container2.Name = user2Container;

            var sdkConatiner2 = sdkCurrentUser.Containers.Add(container2);

            //Find transfer for blob
            var sdkTransfer = sdkCurrentUser.Transfers.Items.FirstOrDefault(t => t.TargetBlobId == sdkBlob1.Id);

            Assert.NotNull(sdkTransfer);

            var sdkBlob1Shared = _ojibweClient.GetBlob(sdkTransfer.TargetBlobId);

            Assert.True(sdkConatiner2.Blobs.AddRef(sdkBlob1Shared.Id), "Could not add blob to container");

            using (var decrypted = sdkBlob1Shared.GetData(sdkCurrentUser))
            {
                byte[] actual = StreamUtility.GetBytes(decrypted);

                Assert.True(actual.SequenceEqual(randomBuffer), "Decrypted Stream does not equal source.");
            }
        }
Esempio n. 7
0
        public void CanSearchBlobInfo()
        {
            Stream publicPrivateKeyStream;
            var sdkUser = _ojibweClient.Register("TestUserSearchBlob", "Password01", out publicPrivateKeyStream);

            Assert.False(sdkUser.PublicKeyId.Equals(Guid.Empty));

            IContainer container = new Container();
            container.Name = "Top Secret";

            var sdkContainer = sdkUser.Containers.Add(container);
            Assert.True(sdkContainer.OwnerUserId == sdkUser.Id);

            Random r = new Random();
            byte[] randomBuffer = new byte[1024*1024];
            r.NextBytes(randomBuffer);

            MemoryStream memoryStream = new MemoryStream(randomBuffer);

            ISdkBlob sdkBlob = sdkContainer.Blobs.New();
            sdkBlob.SetData(sdkUser, memoryStream);

            Assert.NotNull(sdkBlob.StorageKey);

            sdkBlob.Info.Add("key1", "value1");

            Assert.True(sdkBlob.Save());

            Assert.NotNull(sdkBlob);

            sdkBlob = _ojibweClient.GetBlob(sdkBlob.Id);

            var results = _ojibweClient.SearchBlobsByInfo("key1", "value1");

            Assert.True(results.Any(), "Found no results when we should have.");

            results = _ojibweClient.SearchBlobsByInfo("key1");

            Assert.True(results.Any(), "Found no results when we should have.");

            results = _ojibweClient.SearchBlobsByInfo("key2");

            Assert.False(results.Any(), "Found results when we should not have.");
        }
Esempio n. 8
0
        public void CanSearchBlobInfoWithinContainer()
        {
            string user1Username = "******";
            string user1Password = "******";

            Stream user1PrivateKey;
            var sdkUser1 = _ojibweClient.Register(user1Username, user1Password, out user1PrivateKey);
            Assert.NotNull(sdkUser1);

            var sdkCurrentUser = _ojibweClient.Login(user1Username, user1Password, user1PrivateKey);

            string user1Container = "Container1";

            Container container1 = new Container();
            container1.Name = user1Container;

            var sdkContainer1 = sdkCurrentUser.Containers.Add(container1);

            Random r = new Random();
            byte[] randomBuffer = new byte[1024*1024];
            r.NextBytes(randomBuffer);

            var sdkBlob1 = sdkContainer1.Blobs.New();
            using (MemoryStream memoryStream = new MemoryStream(randomBuffer))
            {
                sdkBlob1.SetData(sdkCurrentUser, memoryStream);
            }

            Assert.NotNull(sdkBlob1.StorageKey);

            sdkBlob1.Info.Add("KEY1", "VALUE");

            Assert.True(sdkBlob1.Save());
            sdkBlob1.Refresh();

            Assert.NotNull(sdkBlob1);

            sdkBlob1.Refresh();
            //Switch Users

            var results = sdkContainer1.SearchBlobsByInfo("KEY1");

            Assert.True(results.Any());
        }
Esempio n. 9
0
        public void CanRetreiveBlobFromContainer()
        {
            string username = "******";
            string password = "******";

            string contaierName = string.Format("Top Secret{0}", DateTime.Now.Ticks);

            Stream publicPrivateKeyStream;
            var sdkUser = _ojibweClient.Register(username, password, out publicPrivateKeyStream);

            Assert.False(sdkUser.PublicKeyId.Equals(Guid.Empty));

            IContainer container = new Container();
            container.Name = contaierName;

            var sdkContainer = sdkUser.Containers.Add(container);
            Assert.True(sdkContainer.OwnerUserId == sdkUser.Id);

            Random r = new Random();
            byte[] randomBuffer = new byte[1024*1024];
            r.NextBytes(randomBuffer);

            MemoryStream memoryStream = new MemoryStream(randomBuffer);
            ISdkBlob sdkBlob = sdkContainer.Blobs.New();
            sdkBlob.SetData(sdkUser, memoryStream);

            Assert.NotNull(sdkBlob.StorageKey);

            Assert.True(sdkBlob.Save());

            Assert.NotNull(sdkBlob);

            sdkBlob = _ojibweClient.GetBlob(sdkBlob.Id);
            var storedBlobId = sdkBlob.Id;

            sdkUser = _ojibweClient.Login(username, password, publicPrivateKeyStream);

            Assert.NotNull(sdkUser);

            sdkContainer = sdkUser.Containers.Items.FirstOrDefault(c => c.Name == contaierName);

            Assert.NotNull(sdkContainer);

            sdkBlob = sdkContainer.Blobs.Items.FirstOrDefault(b => b.Id == storedBlobId);

            Assert.NotNull(sdkBlob);

            Assert.Equal(storedBlobId, sdkBlob.Id);

            using (var decrypted = sdkBlob.GetData(sdkUser))
            {
                byte[] actual = StreamUtility.GetBytes(decrypted);

                Assert.True(actual.SequenceEqual(randomBuffer), "Decrypted Stream does not equal source.");
            }
        }
Esempio n. 10
0
        public void CannotAccessOtherUsersData()
        {
            string user1Username = "******";
            string user1Password = "******";
            string user2Username = "******";
            string user2Password = "******";

            Stream user1PrivateKey;
            var sdkUser1 = _ojibweClient.Register(user1Username, user1Password, out user1PrivateKey);
            Assert.NotNull(sdkUser1);
            Stream user2PrivateKey;
            var sdkUser2 = _ojibweClient.Register(user2Username, user2Password, out user2PrivateKey);
            Assert.NotNull(sdkUser2);

            var sdkCurrentUser = _ojibweClient.Login(user1Username, user1Password, user1PrivateKey);

            string user1Container = "Container1";

            Container container1 = new Container();
            container1.Name = user1Container;

            var sdkContainer1 = sdkCurrentUser.Containers.Add(container1);

            sdkCurrentUser = _ojibweClient.Login(user2Username, user2Password, user2PrivateKey);

            sdkUser1 = _ojibweClient.GetUserByUsername(user1Username);
            Assert.Throws<UnauthorizedAccessException>(() =>
            {
                foreach (SdkContainer sdkContainer in sdkUser1.Containers.Items)
                {
                    Assert.Null(sdkContainer);
                }
            });
        }
Esempio n. 11
0
        public void FullUsageTest()
        {
            IUser user1 = new User();
            user1.Username = "******";

            var createdUser = _provider.UserCreate(user1);

            Assert.IsNotNull(createdUser);

            IUser user2 = new User();
            user2.Username = "******";

            var secondUser = _provider.UserCreate(user2);

            Assert.IsNotNull(secondUser);

            IContainer container = new Container();
            container.Name = "TestContainer";
            container.OwnerUserId = createdUser.Id;

            var createdContainer = _provider.ContainerCreate(container);

            Assert.IsNotNull(createdContainer);

            IBlob blob = new Blob();
            blob.OwnerUserId = createdUser.Id;

            var createdBlob = _provider.BlobCreate(blob);

            Assert.IsNotNull(createdBlob);

            //MemoryStream stream = new MemoryStream();

            //using (StreamWriter sw = new StreamWriter(stream))
            //{
            //    sw.Write("This is a test blob");
            //    sw.Flush();

            //    //var blobUpdateSuccess = _provider.BlobUpdateStream(createdBlob, stream);

            //    //Assert.IsTrue(blobUpdateSuccess);
            //}

            createdContainer.BlobIds = new List<Guid>();
            createdContainer.BlobIds.Add(createdBlob.Id);

            var updatedContainer = _provider.ContainerUpdate(createdContainer);

            Assert.IsTrue(updatedContainer);

            IBlob keyBlob = new Blob();
            keyBlob.OwnerUserId = secondUser.Id;

            var createdKeyBlob = _provider.BlobCreate(keyBlob);

            Assert.IsNotNull(createdKeyBlob);

            //MemoryStream keyStream = new MemoryStream();

            //using (StreamWriter sw = new StreamWriter(keyStream))
            //{
            //    sw.Write("Is this the key?!!!");
            //    sw.Flush();

            //    var blobUpdateSuccess = _provider.BlobUpdateStream(createdKeyBlob, keyStream);

            //    Assert.IsTrue(blobUpdateSuccess);
            //}

            ITransfer transfer = new Transfer();

            transfer.TargetBlobId = createdBlob.Id;
            transfer.KeyId = createdKeyBlob.Id;
            transfer.TargetUserId = secondUser.Id;

            var createdTransfer = _provider.TransferCreate(transfer);

            Assert.IsNotNull(createdTransfer);

            IContainer secondUserContainer = new Container();
            secondUserContainer.Name = "SecondUserContainer";
            secondUserContainer.OwnerUserId = secondUser.Id;

            var secondUserCreatedContainer = _provider.ContainerCreate(secondUserContainer);

            Assert.IsNotNull(secondUserCreatedContainer);

            if (secondUserCreatedContainer.BlobIds == null)
                secondUserCreatedContainer.BlobIds = new List<Guid>();

            var transfers = _provider.TransferRetrieveByList(t => t.TargetUserId == secondUser.Id && !t.Complete);

            Assert.IsNotNull(transfers);

            Assert.IsTrue(transfers.Any());

            foreach (ITransfer trans in transfers)
            {
                if (!trans.KeyId.Equals(Guid.Empty))
                {
                    IKey transKey = _provider.KeyRetrieve(trans.KeyId);

                    Assert.IsNotNull(transKey);

                    //Assert.IsNotNull(transKey.KeyData);
                    //Add to keyring
                }

                secondUserCreatedContainer.BlobIds.Add(trans.TargetBlobId);

                trans.Complete = true;

                var updatedTrans = _provider.TransferUpdate(trans);

                Assert.IsTrue(updatedTrans);
            }

            var updatedSecondUserContainer = _provider.ContainerUpdate(secondUserCreatedContainer);

            Assert.IsTrue(updatedSecondUserContainer);
        }
Esempio n. 12
0
        public void ContainerCollectionCrud()
        {
            IContainer container = new Container();
            container.Name = "testContainer";
            container.BlobIds = new List<Guid>();
            container.OwnerUserId = Guid.NewGuid();

            for (int i = 0; i < 10; i++)
            {
                container.BlobIds.Add(Guid.NewGuid());
            }

            var newContainer = _provider.ContainerCreate(container);

            Assert.IsNotNull(newContainer, "Container should not be null");

            Assert.AreEqual(container.Name, newContainer.Name);
            Assert.AreEqual(container.OwnerUserId, newContainer.OwnerUserId);
            Assert.AreEqual(container.BlobIds.Count, newContainer.BlobIds.Count);

            for (int i = 0; i < container.BlobIds.Count; i++)
            {
                Assert.IsTrue(newContainer.BlobIds.Contains(container.BlobIds[i]));
            }

            newContainer.Name = "testContainer2";
            newContainer.OwnerUserId = Guid.NewGuid();

            for (int i = 0; i < 10; i++)
            {
                newContainer.BlobIds.Add(Guid.NewGuid());
            }

            Assert.IsTrue(_provider.ContainerUpdate(newContainer));

            container = newContainer;

            newContainer = _provider.ContainerRetrieve(container.Id);

            Assert.IsNotNull(newContainer);

            Assert.AreEqual(container.Name, newContainer.Name);
            Assert.AreEqual(container.OwnerUserId, newContainer.OwnerUserId);
            Assert.AreEqual(container.BlobIds.Count, newContainer.BlobIds.Count);

            for (int i = 0; i < container.BlobIds.Count; i++)
            {
                Assert.IsTrue(newContainer.BlobIds.Contains(container.BlobIds[i]));
            }

            Assert.IsTrue(_provider.ContainerDelete(newContainer), "Container could not be deleted");

            var deletedContainer = _provider.ContainerRetrieve(newContainer.Id);

            Assert.IsNull(deletedContainer);
        }
Esempio n. 13
0
        static void Main(string[] args)
        {
            XmlConfigurator.Configure();
            if (args.Length < 1)
                throw new ApplicationException("Please specify Ojibwe endpoint.");

            string address = args[0];

            OjibweClient client = new OjibweClient(address);

            string username = string.Format("StressTest{0}", DateTime.Now.Ticks.ToString());
            Stream privateKey = null;
            var currentUser = client.Register(username, "Password01", out privateKey);

            for (int i = 0; i < 10; i++)
            {
                Container container = new Container();
                container.Name = string.Format("Container_{0}", i);
                currentUser.Containers.Add(container);
            }

            Random random = new Random();

            foreach (var container in currentUser.Containers.Items)
            {
                byte[] randomBytes = new byte[64];
                for (int i = 0; i < 100; i++)
                {
                    try
                    {
                        random.NextBytes(randomBytes);

                        Guid checksum = Guid.Empty;
                        lock (md5)
                            checksum = new Guid(md5.ComputeHash(randomBytes));
                        MemoryStream ms = new MemoryStream(randomBytes);

                        var sdkBlob = container.StoreBlob(ms, currentUser.PublicKey,
                            new KeyValuePair<string, string>("DateTime.Ticks", DateTime.Now.Ticks.ToString()),
                            new KeyValuePair<string, string>("CheckSum", checksum.ToString()));
                        Console.WriteLine("Stored BlobId: {0}", sdkBlob.Id);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Failed to store blob.");
                    }
                }
            }
            Parallel.ForEach(currentUser.Containers.Items, new ParallelOptions() { MaxDegreeOfParallelism = 8 },
                (container) =>
                {
                    foreach (var blob in container.Blobs.Items)
                    {
                        Console.WriteLine("BlobID: {0}", blob.Id);
                        string checkSum = null;
                        if (!blob.Info.TryGetValue("CheckSum", out checkSum))
                        {
                            Console.WriteLine("Could not find checksum.");
                            continue;
                        }

                        Guid g = Guid.Parse(checkSum);
                        var bytes = StreamUtility.GetBytes(currentUser.DecryptBlob(blob, privateKey));

                        if(!VerifyCheckSum(g, bytes))
                            Console.WriteLine("CheckSums did not match for BlobId: {0}", blob.Id);
                    }
                });
        }