Пример #1
0
        public void ServiceChannel070Test()
        {
            var location = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var clientChannel = new ServiceChannel())
                        using (var serviceChannel = new ServiceChannel())
                        {
                            serviceChannel.SetReadStream(stream1, false);
                            serviceChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem", $"{location}\\data\\server\\server.pem.key");

                            clientChannel.SetWriteStream(stream2, false);
                            clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"{location}\\data\\server\\server.pem");
                            clientChannel.Encrypt();

                            var data = Security.Random.Get(128 * 1024 + 1);
                            clientChannel.Encrypt();
                            clientChannel.Write(data);

                            clientChannel.Flush();
                            Console.WriteLine(stream2.Length);

                            TransferData(stream2, stream1);
                            var data1 = serviceChannel.Read();
                            Assert.AreEqual(Hash.MD5(data), Hash.MD5(data1));
                        }
        }
Пример #2
0
        public void DbxUploadCommandTest010()
        {
            if (Directory.Exists($"{_location}/data/client/test-user/dbx"))
            {
                Directory.Delete($"{_location}/data/client/test-user/dbx", true);
            }

            using (var stream1 = new MemoryStream())
                using (var stream2 = new MemoryStream())
                    using (var channel1 = new ServiceChannel())
                        using (var channel2 = new ServiceChannel())
                        {
                            byte[] dbxData = Random.Get(256);
                            channel2.SetReadStream(stream1, canDispose: false);
                            channel2.SetWriteStream(stream2, canDispose: false);
                            channel2.Write(dbxData);

                            stream2.Position = 0;
                            channel1.SetReadStream(stream2, canDispose: false);
                            channel1.SetWriteStream(stream1, canDispose: false);

                            Context ctx = new Context();
                            ctx.ClientIP = IPAddress.None;
                            ctx.Channel  = channel1;

                            ctx.Query = new QueryMessage {
                                Command = "dbx-Upload"
                            };
                            ctx.Query.Params["username"]      = "******";
                            ctx.Query.Params["uuid"]          = "safevault";
                            ctx.Query.Params["password"]      = "******";
                            ctx.Query.Params["md5"]           = Hash.MD5(dbxData);
                            ctx.Query.Params["last-modified"] = "2017-01-01 12:00:00Z";

                            Command.Process(ctx);

                            stream1.Position = 0;
                            channel2.CipherLib["rsa-private"] = RsaCipher
                                                                .LoadFromPEM($"{_location}/data/client/test-user/cer.pem", $"{_location}/data/client/test-user/cer.pem.key");

                            var response = channel2.ReadObject <ResponseMessage>();
                            Assert.AreEqual(200, response.StatusCode);
                            Assert.AreEqual("OK", response.Header["data"]);

                            var data = File.ReadAllBytes($"{_location}/data/client/test-user/dbx/safevault.dbx");
                            Assert.AreEqual(dbxData, data);

                            var fileInfo = new FileInfo($"{_location}/data/client/test-user/dbx/safevault.dbx");
                            Assert.AreEqual(fileInfo.CreationTime, DateTime.Parse(ctx.Query.Params["last-modified"]));
                        }
        }