public void HttpService050Test() { using (var clientChannel = new HttpServiceChannel(new Uri("http://192.168.0.235:5000/api/safevault"))) { clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"data\\server\\server.pem"); clientChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM($"data\\client\\test-user\\cer.pem", $"data\\client\\test-user\\cer.pem.key"); var dbxData = Random.Get(3838); var qm = new QueryMessage { Command = "dbx-Upload" }; qm.Params["username"] = "******"; qm.Params["uuid"] = "safevault"; qm.Params["password"] = "******"; qm.Params["md5"] = Security.Hash.MD5(dbxData); qm.Params["last-modified"] = "2017-01-01 12:00:00Z"; clientChannel.Encrypt(); clientChannel.WriteObject(qm); clientChannel.Write(dbxData); clientChannel.Post(); var response = clientChannel.ReadObject <ResponseMessage>(); Console.WriteLine(response.StatusCode + " " + response.StatusText); Assert.AreEqual(200, response.StatusCode); Console.WriteLine(response.Header["data"]); } }
public void HttpService040Test() { using (var clientChannel = new HttpServiceChannel(new Uri("http://192.168.0.235:5000/api/safevault"))) { clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM($"data\\server\\server.pem"); clientChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromX509Store("Evgeny Zyuzin SafeVault Client"); var qm = new QueryMessage { Command = "dbx-Download" }; qm.Params["username"] = "******"; qm.Params["uuid"] = "safevault"; qm.Params["password"] = "******"; clientChannel.Encrypt(); clientChannel.WriteObject(qm); clientChannel.Post(); var response = clientChannel.ReadObject <ResponseMessage>(); Console.WriteLine(response.StatusCode + " " + response.StatusText); Assert.AreEqual(200, response.StatusCode); Console.WriteLine(response.Header["data"]); var data = clientChannel.Read(); Assert.AreEqual(response.Header["md5"], Security.Hash.MD5(data)); Console.WriteLine(data.Length); } }
private static ResponseMessage GetResponseMessage(HttpServiceChannel channel) { var response = channel.ReadObject <ResponseMessage>(); if (response.StatusCode != (int)HttpStatusCode.OK) { throw new HttpChannelException(response.StatusText) { StatusCode = (int)response.StatusCode } } ; if ((DateTime.UtcNow - response.Timestamp).TotalMinutes > 5) { throw new HttpChannelException("Invalid Response Time"); } return(response); }
public void HttpService020Test() { using (var clientChannel = new HttpServiceChannel(new Uri("http://192.168.0.235:5000/api/safevault"))) { clientChannel.CipherLib["rsa-public"] = RsaCipher.LoadFromPEM("data\\server\\server.pem"); clientChannel.CipherLib["rsa-private"] = RsaCipher.LoadFromPEM("data\\client\\test-user\\cer.pem", "data\\client\\test-user\\cer.pem.key"); var queryMessage = new QueryMessage(); queryMessage.Command = "ping"; clientChannel.Encrypt(); clientChannel.WriteObject(queryMessage); clientChannel.Post(); var response = clientChannel.ReadObject <ResponseMessage>(); Console.WriteLine(response.StatusCode); Console.WriteLine(response.StatusText); Console.WriteLine(response.Header["data"]); Assert.AreEqual(200, response.StatusCode); //Console.WriteLine(response.Header["data"]); } }