Beispiel #1
0
        public void SendApplicationData(byte[] data)
        {
            if (!_session.IsAuthenticated)
            {
                throw new Exception("Not authenticated");
            }
            var aesIv           = TLS12.GetIV();
            var applicationData = new ApplicationData
            {
                SessionId = _session.Id,
                AesIv     = aesIv,
                Data      = EncryptAes(data, _session.ClientWriteKey, aesIv)
            };
            var bytes   = _serializer.Serialize <ApplicationData>(applicationData);
            var message = new SecurityLayerMessage
            {
                Type = SecurityMessageType.ApplicationData,
                Data = bytes
            };

            Send(_serializer.Serialize <SecurityLayerMessage>(message));
        }
Beispiel #2
0
        private void HandleApplicationData(byte[] message)
        {
            var applicationData = _serializer.Deserialize <ApplicationData>(message);
            var session         = _sessionCache.Get(applicationData.SessionId);

            if (!session.IsAuthenticated)
            {
                // TODO: Send error
            }
            else
            {
                var data                    = DecryptAes(applicationData.Data, session.ClientWriteKey, applicationData.AesIv);
                var responseData            = ProcessApplicationData(data);
                var aesIv                   = TLS12.GetIV();
                var applicationDataResponse = new ApplicationData
                {
                    SessionId = session.Id,
                    AesIv     = aesIv,
                    Data      = EncryptAes(responseData, session.ServerWriteKey, aesIv)
                };
                var bytes = _serializer.Serialize <ApplicationData>(applicationDataResponse);
                Send(bytes);
            }
        }