public async Task <IHttpActionResult> Post([FromBody] DecodeMessageInfo decodeInfo) { if (decodeInfo == null) { return(BadRequest()); } var certificateInformation = CertificateInfoRetriever.RetrieveCertificatePassword(this.Request); decodeInfo.DecryptionCertificatePassword = certificateInformation.DecryptionPassword; decodeInfo.SigningResponseCertificatePassword = certificateInformation.SigningPassword; try { var service = new DecodeService(); var processingResult = await service.Process(decodeInfo); if (processingResult == null || processingResult.ReceivedMessageType == EbmsMessageType.Unknown) { return(BadRequest()); } return(Ok(processingResult)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public async Task <DecodeResult> Process(DecodeMessageInfo info) { // Shortcuts have been taken. // Theoretically, it is possible that we receive an AS4Message that contains multiple // message-parts. We should process each message-part seperately. using (var receivedStream = new MemoryStream(info.ReceivedMessage)) { var as4Message = await RetrieveAS4Message(info.ContentType, receivedStream); if (as4Message == null) { return(DecodeResult.CreateForBadRequest()); } if (as4Message.IsSignalMessage) { return(DecodeResult.CreateAccepted(as4Message.FirstSignalMessage is Receipt ? EbmsMessageType.Receipt : EbmsMessageType.Error, as4Message.GetPrimaryMessageId(), (as4Message.FirstSignalMessage as Error))); } // Start Processing var receivingPMode = await AssembleReceivingPMode(info); var respondingPMode = await AssembleRespondingPMode(info); if (receivingPMode == null) { return(DecodeResult.CreateForBadRequest()); } if (respondingPMode == null) { return(DecodeResult.CreateForBadRequest()); } var context = CreateMessagingContext(as4Message, receivingPMode, respondingPMode); try { var decodeResult = await PerformInboundProcessing(context); return(decodeResult); } finally { context.Dispose(); } } }
private static async Task <SendingProcessingMode> AssembleRespondingPMode(DecodeMessageInfo info) { var pmode = await Deserializer.ToSendingPMode(info.RespondingPMode); if (pmode == null) { return(null); } if (pmode.Security?.Signing?.IsEnabled ?? false) { pmode.Security.Signing.SigningCertificateInformation = new PrivateKeyCertificate { Certificate = Convert.ToBase64String(info.SigningResponseCertificate ?? new byte[] { }), Password = info.SigningResponseCertificatePassword }; } return(pmode); }
private static async Task <ReceivingProcessingMode> AssembleReceivingPMode(DecodeMessageInfo info) { var pmode = await Deserializer.ToReceivingPMode(info.ReceivingPMode); if (pmode == null) { return(null); } if (info.DecryptionCertificate != null && info.DecryptionCertificate.Length > 0) { pmode.Security.Decryption.DecryptCertificateInformation = new PrivateKeyCertificate() { Certificate = Convert.ToBase64String(info.DecryptionCertificate), Password = info.DecryptionCertificatePassword }; } return(pmode); }