public static async Task<IEncryptor> CreateEncryptor(IOptimisticStore store, StoreLocation keyLocation, RSAServiceProvider rsaCert)
        {
            bool isFound;
            byte[] blob;
            do
            {
                var data = await store.LoadData(keyLocation).ConfigureAwait(false);
                if (data == null)
                {
                    // Have to create a new key
                    blob = AESBlob.CreateBlob(DefaultKeySize, rsaCert);
                    var ct = CancellationToken.None;

                    // We use an optimistic write so that it will only create the file IF THE FILE DOES NOT EXIST
                    // This will catch rare cases where two server calls may try to create two keys
                    var result = await store.TryOptimisticWrite(keyLocation, null, null, async (s) =>
                    {
                        await s.WriteAsync(blob, 0, blob.Length, ct).ConfigureAwait(false);
                        return blob.Length;
                    }, ct).ConfigureAwait(false);
                    isFound = result.Result;
                }
                else
                {
                    blob = await data.Stream.ReadBytes().ConfigureAwait(false);
                    isFound = true;
                }
            } while (!isFound);

            var encryptor = AESBlob.CreateEncryptor(blob, rsaCert);
            return new CertProtectedEncryptor(keyLocation.Container, encryptor);
        }
Esempio n. 2
0
        public void Init()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();

            _store = new AzureStore(client, false, null); // Do not snapshot and do tracing!
            _store.CreateContainerIfNotExists("testindexer");

            var store = new SecureStore(_store);

            _indexer = new LuceneIndex(store, "testindexer", "basePath", null);
        }
Esempio n. 3
0
 public UniqueIdGenerator(
     IOptimisticStore store,
     StoreLocation location,
     int rangeSize  = 10,
     int maxRetries = 25)
 {
     _taskLock   = new object();
     _rangeSize  = rangeSize;
     _maxRetries = maxRetries;
     _store      = store;
     _location   = location;
 }
Esempio n. 4
0
 public UniqueIdGenerator(
     IOptimisticStore store,
     StoreLocation location,
     int rangeSize = 10,
     int maxRetries = 25)
 {
     _taskLock = new object();
     _rangeSize = rangeSize;
     _maxRetries = maxRetries;
     _store = store;
     _location = location;
 }
Esempio n. 5
0
        public SecureStore(IOptimisticStore store, IQueue backupQueue = null, IQueue indexQueue = null, ICompressor compressor = null)
        {
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }

            _store       = store;
            _backupQueue = backupQueue;
            _indexQueue  = indexQueue;
            _compressor  = compressor;
        }
Esempio n. 6
0
        public void Init()
        {
            var client = CloudStorageAccount.DevelopmentStorageAccount.CreateCloudBlobClient();
            _store = new AzureStore(client, false, null); // Do not snapshot and do tracing!
            _store.CreateContainerIfNotExists("testindexer");

            // Use a file based cache for tests (more common use case)
            _tempDir = IO.Path.Combine(IO.Path.GetTempPath(), IO.Path.GetFileNameWithoutExtension(IO.Path.GetRandomFileName()));
            IO.Directory.CreateDirectory(_tempDir);

            var store = new SecureStore(_store);
            _indexer = new LuceneIndex(store, "testindexer", "basePath", null, _tempDir);
        }
Esempio n. 7
0
        public static async Task <IEncryptor> CreateEncryptor(IOptimisticStore store, StoreLocation keyLocation, RSA rsaCert)
        {
            bool isFound;

            byte[] blob;
            do
            {
                var data = await store.LoadData(keyLocation);

                if (data == null)
                {
                    // Have to create a new key
                    blob = AESBlob.CreateBlob(DefaultKeySize, rsaCert);
                    var ct = CancellationToken.None;

                    // We use an optimistic write so that it will only create the file IF THE FILE DOES NOT EXIST
                    // This will catch rare cases where two server calls may try to create two keys
                    var result = await store.TryOptimisticWrite(keyLocation, null, null, async (s) =>
                    {
                        await s.WriteAsync(blob, 0, blob.Length, ct);
                        return(blob.Length);
                    }, ct);

                    isFound = result.Result;
                }
                else
                {
                    blob = await data.Stream.ReadBytes();

                    isFound = true;
                }
            } while (!isFound);

            var encryptor = AESBlob.CreateEncryptor(blob, rsaCert);

            return(new CertProtectedEncryptor(keyLocation.Container, encryptor));
        }
 public void Init()
 {
     _loc = new StoreLocation();
     _store = Substitute.For<IOptimisticStore>();
 }
Esempio n. 9
0
 public void Init()
 {
     _loc   = new StoreLocation();
     _store = Substitute.For <IOptimisticStore>();
 }