public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { if (encryptedValue.Base64Iv == hardcodedValue.Base64Iv && encryptedValue.EncryptedBase64Value == hardcodedValue.EncryptedBase64Value) return "A secret"; throw new InvalidOperationException("Failed to decrypt"); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { if (encryptedValue == null || String.IsNullOrEmpty(encryptedValue.EncryptedBase64Value)) { return(null); } if (!context.Headers.ContainsKey(EncryptionHeaders.RijndaelKeyIdentifier)) { return(null); } var decryptlabel = context.Headers[EncryptionHeaders.RijndaelKeyIdentifier]; var decryptRequest = new DecryptRequest { KeyId = decryptlabel }; var value = Convert.FromBase64String(encryptedValue.EncryptedBase64Value); decryptRequest.CiphertextBlob = new System.IO.MemoryStream(value); var response = _client.DecryptAsync(decryptRequest).GetAwaiter().GetResult(); if (response != null) { return(Encoding.UTF8.GetString(response.Plaintext.ToArray())); } return(null); }
public override async Task Invoke(IIncomingLogicalMessageContext context, Func <Task> next) { var uow = new EntityFrameworkUnitOfWork <TDbContext>(context.Builder, _schema, _log); context.Extensions.Set <EntityFrameworkUnitOfWork <TDbContext> >(uow); await next(); context.Extensions.Remove <EntityFrameworkUnitOfWork <TDbContext> >(); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { if (encryptedValue.Base64Iv == hardcodedValue.Base64Iv && encryptedValue.EncryptedBase64Value == hardcodedValue.EncryptedBase64Value) { return("A secret"); } throw new InvalidOperationException("Failed to decrypt"); }
public static void DecryptValue(this IEncryptionService encryptionService, WireEncryptedString wireEncryptedString, IIncomingLogicalMessageContext context) { if (wireEncryptedString.EncryptedValue == null) { throw new Exception("Encrypted property is missing encryption data"); } wireEncryptedString.Value = encryptionService.Decrypt(wireEncryptedString.EncryptedValue, context); }
public override async Task Invoke( IIncomingLogicalMessageContext context, Func <Task> next) { var ef = new EntityFrameworkHelper <T>(contextFactory); context.Extensions.Set(ef); await next().ConfigureAwait(false); context.Extensions.Remove <EntityFrameworkHelper <T> >(); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { string keyIdentifier; if (TryGetKeyIdentifierHeader(out keyIdentifier, context)) { return DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier); } Log.Warn($"Encrypted message has no '{Headers.RijndaelKeyIdentifier}' header. Possibility of data corruption. Upgrade endpoints that send message with encrypted properties."); return DecryptUsingAllKeys(encryptedValue); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { string keyIdentifier; if (TryGetKeyIdentifierHeader(out keyIdentifier, context)) { return(DecryptUsingKeyIdentifier(encryptedValue, keyIdentifier)); } Log.Warn($"Encrypted message has no '{Headers.RijndaelKeyIdentifier}' header. Possibility of data corruption. Upgrade endpoints that send message with encrypted properties."); return(DecryptUsingAllKeys(encryptedValue)); }
public static MessageIntentEnum GetMessageIntent(this IIncomingLogicalMessageContext message) { var messageIntent = default(MessageIntentEnum); if (message.MessageHeaders.TryGetValue(Headers.MessageIntent, out var messageIntentString)) { Enum.TryParse(messageIntentString, true, out messageIntent); } return(messageIntent); }
public static void DecryptValue(this IEncryptionService encryptionService, ref string stringToDecrypt, IIncomingLogicalMessageContext context) { var parts = stringToDecrypt.Split(splitChars, StringSplitOptions.None); stringToDecrypt = encryptionService.Decrypt( new EncryptedValue { EncryptedBase64Value = parts[0], Base64Iv = parts[1] }, context ); }
public override async Task Invoke(IIncomingLogicalMessageContext context, Func <Task> next) { var id = getId(context.Message.Instance); if (id == null) { await next(); return; } var(entity, version) = await repository.Get(id); var hasBeenProcessed = await tokenStore.HasBeenProcessed(context.MessageId); if (hasBeenProcessed) { if (entity.OutboxState.ContainsKey(context.MessageId)) { entity.OutboxState.Remove(context.MessageId); await repository.Put(entity, version); } return; //Duplicate } if (!entity.OutboxState.TryGetValue(context.MessageId, out var outboxState)) { context.Extensions.Set(entity); var messages = await InvokeMessageHandler(context, next); outboxState = new OutboxState { OutgoingMessages = messages.Serialize() }; entity.OutboxState[context.MessageId] = outboxState; version = await repository.Put(entity, version); } var toDispatch = outboxState.OutgoingMessages.Deserialize(); await Dispatch(toDispatch, context); await tokenStore.MarkProcessed(context.MessageId); entity.OutboxState.Remove(context.MessageId); await repository.Put(entity, version); }
public override async Task Invoke(IIncomingLogicalMessageContext context, Func <Task> next) { var id = getId(context.Message.Instance); if (id == null) { await next(); return; } OutboxState outboxState; var(entity, version) = await repository.Get(id); if (entity.TransactionId != null) { outboxState = await outboxStore.Get(entity.TransactionId); version = await FinishTransaction(context, outboxState, entity, version); } var hasBeenProcessed = await inboxStore.HasBeenProcessed(context.MessageId); if (hasBeenProcessed) { return; } var transactionId = Guid.NewGuid().ToString(); context.Extensions.Set(entity); var messages = await InvokeMessageHandler(context, next); outboxState = new OutboxState { OutgoingMessages = messages.Serialize() }; await outboxStore.Put(transactionId, outboxState); entity.TransactionId = transactionId; version = await repository.Put(entity, version); await FinishTransaction(context, outboxState, entity, version); }
internal InvokeHandlerContext(MessageHandler handler, SynchronizedStorageSession storageSession, IIncomingLogicalMessageContext parentContext) : this(handler, parentContext.MessageId, parentContext.ReplyToAddress, parentContext.Headers, parentContext.Message.Metadata, parentContext.Message.Instance, storageSession, parentContext) { }
static Task SetSagaNotFound(IIncomingLogicalMessageContext context) { context.Extensions.Get<SagaInvocationResult>().SagaNotFound(); return TaskEx.CompletedTask; }
static Task SetSagaNotFound(IIncomingLogicalMessageContext context) { context.Extensions.Get <SagaInvocationResult>().SagaNotFound(); return(Task.CompletedTask); }
public override async Task Invoke(IIncomingLogicalMessageContext context, Func <Task> next) { var id = getId(context.Message.Instance); if (id == null) { await next(); return; } context.Headers.TryGetValue("TokenId", out var tokenId); var(entity, version) = await repository.Get(id); string tokenVersion = null; if (tokenId != null) { bool tokenExists; (tokenExists, tokenVersion) = await tokenStore.Exists(tokenId); if (!tokenExists) { //Cleanup if (entity.OutboxState.ContainsKey(context.MessageId)) { entity.OutboxState.Remove(context.MessageId); await repository.Put(entity, version); } return; //Duplicate } } if (!entity.OutboxState.TryGetValue(context.MessageId, out var outboxState)) { context.Extensions.Set(entity); var messages = await InvokeMessageHandler(context, next); outboxState = new OutboxState { OutgoingMessages = messages.Serialize() }; entity.OutboxState[context.MessageId] = outboxState; version = await repository.Put(entity, version); } if (!outboxState.TokensGenerated) { foreach (var message in outboxState.OutgoingMessages) { message.Headers["TokenId"] = Guid.NewGuid().ToString(); await tokenStore.Create(message.Headers["TokenId"]); } outboxState.TokensGenerated = true; version = await repository.Put(entity, version); } var toDispatch = outboxState.OutgoingMessages.Deserialize(); await Dispatch(toDispatch, context); if (tokenId != null) { await tokenStore.Delete(tokenId, tokenVersion); } entity.OutboxState.Remove(context.MessageId); await repository.Put(entity, version); }
protected override bool TryGetKeyIdentifierHeader(out string keyIdentifier, IIncomingLogicalMessageContext context) { keyIdentifier = IncomingKeyIdentifier; return IncomingKeyIdentifier != null; }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { throw new NotImplementedException(); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { return(new string(encryptedValue.EncryptedBase64Value.Reverse().ToArray())); }
//TODO: need to duplicate both methods for now until NSB has base class/interface for Incoming/Outgoing Logical Messages. public static Guid GetMessageId(this IIncomingLogicalMessageContext context) { return((context.Message.Instance as IEvent)?.EventId ?? (context.Message.Instance as IPaymentsCommand)?.CommandId ?? Guid.Empty); }
protected virtual bool TryGetKeyIdentifierHeader(out string keyIdentifier, IIncomingLogicalMessageContext context) { return context.Headers.TryGetValue(Headers.RijndaelKeyIdentifier, out keyIdentifier); }
public TransformedIncomingLogicalMessageContext(object instance, IIncomingLogicalMessageContext context) { Message = new LogicalMessage(new MessageMetadata(instance.GetType()), instance); originalContext = context; }
public override async Task Invoke(IIncomingLogicalMessageContext context, Func <Task> next) { var id = getId(context.Message.Instance); if (id == null) { await next(); return; } OutboxState outboxState; var(entity, version) = await repository.Get(id); var hasBeenProcessed = await inboxStore.HasBeenProcessed(context.MessageId); if (hasBeenProcessed) { if (entity.TransactionIds.ContainsKey(context.MessageId)) { entity.TransactionIds.Remove(context.MessageId); await repository.Put(entity, version); } return; } if (!entity.TransactionIds.TryGetValue(context.MessageId, out var transactionId)) { transactionId = Guid.NewGuid().ToString(); context.Extensions.Set(entity); var messages = await InvokeMessageHandler(context, next); outboxState = new OutboxState { OutgoingMessages = messages.Serialize() }; await outboxStore.Put(transactionId, outboxState); entity.TransactionIds[context.MessageId] = transactionId; version = await repository.Put(entity, version); } else { outboxState = await outboxStore.Get(transactionId); } if (outboxState != null) { var toDispatch = outboxState.OutgoingMessages.Deserialize(); await Dispatch(toDispatch, context); await outboxStore.Delete(transactionId); } await inboxStore.MarkProcessed(context.MessageId); entity.TransactionIds.Remove(context.MessageId); await repository.Put(entity, version); }
public static void DecryptValue(this IEncryptionService encryptionService, ref string stringToDecrypt, IIncomingLogicalMessageContext context) { var parts = stringToDecrypt.Split(splitChars, StringSplitOptions.None); stringToDecrypt = encryptionService.Decrypt( new EncryptedValue { EncryptedBase64Value = parts[0], Base64Iv = parts[1] }, context ); }
/// <summary> /// Creates a <see cref="IInvokeHandlerContext" /> based on the current context. /// </summary> public static IInvokeHandlerContext CreateInvokeHandlerContext(this StageConnector <IIncomingLogicalMessageContext, IInvokeHandlerContext> stageConnector, MessageHandler messageHandler, CompletableSynchronizedStorageSession storageSession, IIncomingLogicalMessageContext sourceContext) { Guard.AgainstNull(nameof(messageHandler), messageHandler); Guard.AgainstNull(nameof(storageSession), storageSession); Guard.AgainstNull(nameof(sourceContext), sourceContext); return(new InvokeHandlerContext(messageHandler, storageSession, sourceContext)); }
public static void DecryptValue(this IEncryptionService encryptionService, EncryptedString encryptedString, IIncomingLogicalMessageContext context) { if (encryptedString.EncryptedValue == null) { throw new Exception("Encrypted property is missing encryption data"); } encryptedString.Value = encryptionService.Decrypt(encryptedString.EncryptedValue, context); }
protected virtual bool TryGetKeyIdentifierHeader(out string keyIdentifier, IIncomingLogicalMessageContext context) { return(context.Headers.TryGetValue(Headers.RijndaelKeyIdentifier, out keyIdentifier)); }
public static string GetMessageName(this IIncomingLogicalMessageContext context) { return(context.Message.Instance.GetType().Name); }
internal InvokeHandlerContext(MessageHandler handler, SynchronizedStorageSession storageSession, IIncomingLogicalMessageContext parentContext) : this(handler, parentContext.MessageId, parentContext.ReplyToAddress, parentContext.Headers, parentContext.Message.Metadata, parentContext.Message.Instance, storageSession, parentContext) { }
public static AuditFilterContext GetAuditContext(this IIncomingLogicalMessageContext context) { return(context.Extensions.Get <AuditFilterContext>()); }
public string Decrypt(EncryptedValue encryptedValue, IIncomingLogicalMessageContext context) { throw new System.NotImplementedException(); }
protected internal override bool TryGetKeyIdentifierHeader(out string keyIdentifier, IIncomingLogicalMessageContext context) { keyIdentifier = IncomingKeyIdentifier; return(IncomingKeyIdentifier != null); }
/// <summary> /// Creates a <see cref="IInvokeHandlerContext" /> based on the current context. /// </summary> public static IInvokeHandlerContext CreateInvokeHandlerContext(this StageConnector<IIncomingLogicalMessageContext, IInvokeHandlerContext> stageConnector, MessageHandler messageHandler, CompletableSynchronizedStorageSession storageSession, IIncomingLogicalMessageContext sourceContext) { Guard.AgainstNull(nameof(messageHandler), messageHandler); Guard.AgainstNull(nameof(storageSession), storageSession); Guard.AgainstNull(nameof(sourceContext), sourceContext); return new InvokeHandlerContext(messageHandler, storageSession, sourceContext); }