public void SessionConstructorInitialisesTheValues() { var sessionId = "MyNewSession"; var request = new EncryptedRequest(sessionId); Assert.AreEqual(sessionId, request.SessionToken); }
/// <summary> /// Sends a message to a remote server. /// </summary> /// <param name="action">The action to perform.</param> /// <param name="request">The request to send to the server.</param> /// <returns>The response from the server.</returns> public Response SendMessage(string action, ServerRequest request) { // Make sure there is a password if ((cryptoKey.Length == 0) || (cryptoIv.Length == 0)) { InitialisePassword(); } // Generate the encrypted request var encryptedRequest = new EncryptedRequest(); encryptedRequest.Action = action; var crypto = new RijndaelManaged(); crypto.Key = cryptoKey; crypto.IV = cryptoIv; encryptedRequest.EncryptedData = EncryptMessage(crypto, request.ToString()); // Send the request var response = innerConnection.SendMessage("ProcessSecureRequest", encryptedRequest); var encryptedResponse = response as EncryptedResponse; // Generate the actual response if ((response.Result == ResponseResult.Success) && (encryptedResponse != null)) { var data = DecryptMessage(crypto, encryptedResponse.EncryptedData); response = XmlConversionUtil.ProcessResponse(data); } return(response); }
public void RequestConstructorInitialisesTheValues() { var request = new EncryptedRequest(); var response = new FileTransferResponse(request); // Only check one property is set, since the properties are set by the base class Assert.AreEqual(request.Identifier, response.RequestIdentifier); }
public void EncryptedDataCanBeSetAndRetrieved() { var request = new EncryptedRequest(); var data = "SomeEncryptedData"; request.EncryptedData = data; Assert.AreEqual(data, request.EncryptedData); }
public void FullConstructorInitialisesTheValues() { var sessionId = "MyNewSession"; var data = "SomeEncryptedData"; var request = new EncryptedRequest(sessionId, data); Assert.AreEqual(sessionId, request.SessionToken); Assert.AreEqual(data, request.EncryptedData); }
EncryptedResponse Any(EncryptedRequest request) { var requestType = Type.GetType("{0}.{1}" .Fmt(typeof(EncryptedRequest).Namespace, request.Type)); var json = CryptUtils.Decrypt(PrivateKey, request.EncryptedBody); var requestDto = JsonSerializer.DeserializeFromString(json, requestType); var responseDto = GetAppHost().Config.ServiceController .Execute(requestDto, base.RequestContext); return(new EncryptedResponse { Type = responseDto.GetType().Name, EncryptedBody = CryptUtils.Encrypt(PublicKey, responseDto.ToJson()), }); }
public async Task SendRequestAsync(EncryptedRequest request) { await _connectionContainer.Caller.SendRemoteCommand(request); }