public void ProcessOutbound(EventContext context, Action continueProcessing) { Envelope env = context.Envelope; if (env.IsRequest()) { Guid requestId = env.GetMessageId(); TimeSpan timeout = env.GetRpcTimeout(); lock (_listLock) { _log.Debug(string.Format("Adding requestId {0} to the RPC Filter list", requestId.ToString())); _sentRequests.Add(requestId); } if (timeout.IsNotEmpty()) { Timer gc = new Timer(this.RequestTimeout_GarbageCollect, requestId, timeout.Add(timeout), TimeSpan.Zero); } else { _log.Warn(string.Format( "Request {0} was sent without a timeout: it will never be removed from the RPC Filter list", requestId.ToString())); } } continueProcessing(); }
public void ProcessInbound(EventContext context, Action continueProcessing) { bool ourOwnRequest = false; Envelope env = context.Envelope; try { if (env.IsRequest()) { Guid requestId = env.GetMessageId(); lock (_listLock) { if (_sentRequests.Contains(requestId)) { _log.Info("Filtering out our own request: " + requestId.ToString()); ourOwnRequest = true; } } } } catch (Exception ex) { _log.Error("Failed to inspect an incoming event for potential filtering", ex); } if (!ourOwnRequest) { continueProcessing(); } }
public virtual void ProcessEvent(EventContext context, Action continueProcessing) { // only process outbound events if (context.Direction != EventContext.Directions.Out) { continueProcessing(); } Envelope env = context.Envelope; Guid messageId = env.GetMessageId(); messageId = Guid.Equals(Guid.Empty, messageId) ? Guid.NewGuid() : messageId; env.SetMessageId(messageId.ToString()); Guid correlationId = env.GetCorrelationId(); string messageType = env.GetMessageType(); messageType = string.IsNullOrEmpty(messageType) ? this.GetMessageType(context.Event) : messageType; env.SetMessageType(messageType); string messageTopic = env.GetMessageTopic(); messageTopic = string.IsNullOrEmpty(messageTopic) ? this.GetMessageTopic(context.Event) : messageTopic; if (Guid.Empty != correlationId) { messageTopic = messageTopic + "#" + correlationId.ToString(); } env.SetMessageTopic(messageTopic); string senderIdentity = env.GetSenderIdentity(); senderIdentity = string.IsNullOrEmpty(senderIdentity) ? UserPrincipal.Current.DistinguishedName.Replace(",", ", ") : senderIdentity; senderIdentity = string.IsNullOrEmpty(senderIdentity) ? UserPrincipal.Current.Name : senderIdentity; env.SetSenderIdentity(senderIdentity); continueProcessing(); }
public void ProcessEvent(EventContext context, Action continueProcessing) { if (EventContext.Directions.In == context.Direction) { this.ProcessInbound(context, continueProcessing); } if (EventContext.Directions.Out == context.Direction) { this.ProcessOutbound(context, continueProcessing); } }
public void ProcessInbound(EventContext context, Action continueProcessing) { bool signatureVerified = false; Envelope env = context.Envelope; // start by getting the purported sender's identity string sender = env.GetSenderIdentity(); if (string.IsNullOrEmpty(sender)) { _log.Error("An inbound event arrived with no sender identity"); } else { // use the identity to lookup their certificate X509Certificate2 senderCert = _certProvider.GetCertificateFor(sender); if (null == senderCert) { _log.Error("Sender " + sender + " does not have a public key certificate available"); } else { // get the digital signature from the headers byte[] digitalSignature = env.GetDigitalSignature(); if (0 == digitalSignature.LongLength) { _log.Error("Sender " + sender + " did not digitally sign the event"); } else { // verify that the payload hasn't been tampered with by using the // sender's public key and the digital signature on the envelope RSACryptoServiceProvider rsaProvider = senderCert.PublicKey.Key as RSACryptoServiceProvider; signatureVerified = rsaProvider.VerifyData(env.Payload, new SHA1CryptoServiceProvider(), digitalSignature); } } } if (signatureVerified) { continueProcessing(); } }
protected override void ProcessEvent(EventContext context, IEnumerable<IEventProcessor> processorChain, Action processingComplete) { // set the payload of the envelope to something, or an exception will be thrown context.Envelope = new Envelope() {Payload = Encoding.UTF8.GetBytes("Test")}; base.ProcessEvent(context, processorChain, processingComplete); }
public void ProcessOutbound(EventContext context, Action continueProcessing) { if (null == _cert) { return; } Envelope env = context.Envelope; env.SetSenderIdentity(_cert.Subject); try { RSACryptoServiceProvider rsaProvider = _cert.PrivateKey as RSACryptoServiceProvider; env.SetDigitalSignature(rsaProvider.SignData(env.Payload, new SHA1CryptoServiceProvider())); continueProcessing(); } catch (Exception ex) { _log.Error("Failed to digitally sign the event", ex); throw; } }