Exemplo n.º 1
0
 public static SignStrategy ForAS4Message(AS4Message as4Message, CalculateSignatureConfig config)
 {
     return(new SignStrategy(
                as4Message,
                as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message, CancellationToken.None),
                config));
 }
        public async Task CanDeserializeAndReSerializeMultiHopReceipt()
        {
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(multihopreceipt)))
            {
                AS4Message multihopReceipt =
                    await SerializerProvider.Default.Get(Constants.ContentTypes.Soap)
                    .DeserializeAsync(
                        stream,
                        Constants.ContentTypes.Soap,
                        CancellationToken.None);

                Assert.NotNull(multihopReceipt);
                Assert.NotNull(multihopReceipt.FirstSignalMessage);
                Assert.True(
                    multihopReceipt.FirstSignalMessage.IsMultihopSignal,
                    "Should have multihop routing information");

                // Serialize the Deserialized receipt again, and make sure the RoutingInput element is present and correct.
                XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(multihopReceipt, CancellationToken.None);

                XmlNode routingInput = doc.UnsafeSelectEbmsNode("/s12:Envelope/s12:Header/mh:RoutingInput");

                Assert.NotNull(routingInput);
            }
        }
        private static string RetrieveSigningCertificateThumbPrint(AS4Message as4Message, ICertificateRepository certificateRepository)
        {
            var token =
                SecurityTokenReferenceProvider.Get(as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message, CancellationToken.None),
                                                   SecurityTokenType.Signing,
                                                   certificateRepository);

            return(token.Certificate.Thumbprint);
        }
        public void MultihopUserMessageCreatedWhenSpecifiedInPMode()
        {
            // Arrange
            AS4Message as4Message = CreateAS4MessageWithPMode(CreateMultiHopPMode());

            // Act
            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message, CancellationToken.None);

            // Assert
            AssertUserMessageMultihopHeaders(doc);
        }
        public void ThenRelatedUserMessageElementBelongsToCorrectNamespace()
        {
            var receipt = CreateReceiptWithRelatedUserMessageInfo();

            var as4Message = AS4Message.Create(receipt);

            XmlDocument document = AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message, CancellationToken.None);

            var node = document.UnsafeSelectEbmsNode("/s12:Envelope/s12:Header/eb:Messaging/eb:SignalMessage/eb:Receipt/ebbp:UserMessage");

            Assert.NotNull(node);
            Assert.Equal(Constants.Namespaces.EbmsXmlSignals, node.NamespaceURI);
        }
Exemplo n.º 6
0
        private static string CreateErrorInformationString(Error error)
        {
            if (error.ErrorLines == null || error.ErrorLines.Any() == false)
            {
                return(null);
            }

            XmlDocument soapEnv =
                AS4XmlSerializer.ToSoapEnvelopeDocument(
                    AS4Message.Create(error),
                    CancellationToken.None);

            XmlNode signalNode = soapEnv.SelectSingleNode("//*[local-name()='SignalMessage']");

            return(signalNode?.OuterXml);
        }
        public async Task ReceiptMessageForNonMultiHopMessageIsNotMultiHop()
        {
            AS4Message as4Message = await CreateReceivedAS4Message(CreateNonMultiHopPMode());

            var receipt = Receipt.CreateFor($"receipt-{Guid.NewGuid()}", as4Message.FirstUserMessage, as4Message.IsMultiHopMessage);

            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(receipt), CancellationToken.None);

            // No MultiHop related elements may be present:
            // - No Action element in the wsa namespace
            // - No UserElement in the multihop namespace.
            // - No RoutingInput node
            Assert.False(ContainsActionElement(doc));
            Assert.False(ContainsUserMessageElement(doc));
            Assert.Null(doc.UnsafeSelectEbmsNode("/s12:Envelope/s12:Header/mh:RoutingInput"));
        }
        public async Task MultihopUserMessageStillContainsMultihopHeadersWhenSerializeDeserializedMessage()
        {
            // Arrange
            var          input       = new MemoryStream(as4_multihop_usermessage);
            const string contentType =
                "multipart/related; boundary=\"=-AAB+iUI3phXyeG3w4aGnFA==\";\ttype=\"application/soap+xml\"";

            ISerializer sut          = SerializerProvider.Default.Get(contentType);
            AS4Message  deserialized = await sut.DeserializeAsync(input, contentType);

            // Act
            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(deserialized, CancellationToken.None);

            // Assert
            AssertUserMessageMultihopHeaders(doc);
        }
        public async void ReceiptMessageForMultihopUserMessageIsMultihop()
        {
            AS4Message as4Message = await CreateReceivedAS4Message(CreateMultiHopPMode());

            var receipt = Receipt.CreateFor($"receipt-{Guid.NewGuid()}", as4Message.FirstUserMessage, as4Message.IsMultiHopMessage);

            XmlDocument doc = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(receipt), CancellationToken.None);

            // Following elements should be present:
            // - To element in the wsa namespace
            // - Action element in the wsa namespace
            // - UserElement in the multihop namespace.
            AssertToElement(doc);
            Assert.True(ContainsActionElement(doc));
            Assert.True(ContainsUserMessageElement(doc));
            AssertUserMessageMessagingElement(as4Message, doc);

            AssertIfSenderAndReceiverAreReversed(as4Message, doc);
        }
        public async Task ErrorMessageForMultihopUserMessageIsMultihop()
        {
            // Arrange
            AS4Message expectedAS4Message = await CreateReceivedAS4Message(CreateMultiHopPMode());

            var error = Error.CreateFor($"error-{Guid.NewGuid()}", expectedAS4Message.FirstUserMessage, userMessageSendViaMultiHop: true);

            // Act
            XmlDocument document = AS4XmlSerializer.ToSoapEnvelopeDocument(AS4Message.Create(error), CancellationToken.None);

            // Following elements should be present:
            // - To element in the wsa namespace
            // - Action element in the wsa namespace
            // - UserElement in the multihop namespace.
            AssertToElement(document);
            Assert.True(ContainsActionElement(document));
            Assert.True(ContainsUserMessageElement(document));

            AssertMessagingElement(document);
            AssertIfSenderAndReceiverAreReversed(expectedAS4Message, document);
        }
        private async Task <NotifyMessageEnvelope> CreateMinderNotifyMessageEnvelope(
            AS4Message as4Message, Type receivedEntityMessageType)
        {
            UserMessage   userMessage   = as4Message.FirstUserMessage;
            SignalMessage signalMessage = as4Message.FirstSignalMessage;

            if (userMessage == null && signalMessage != null)
            {
                userMessage = await RetrieveRelatedUserMessage(signalMessage);
            }

            if (userMessage == null)
            {
                Logger.Warn("The related usermessage for the received signalmessage could not be found");
                userMessage = new UserMessage(IdentifierFactory.Instance.Create());
            }

            UserMessage minderUserMessage = CreateUserMessageFromMinderProperties(userMessage, signalMessage);

            NotifyMessage notifyMessage =
                AS4MessageToNotifyMessageMapper.Convert(
                    as4Message.FirstSignalMessage,
                    receivedEntityMessageType,
                    as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message));

            // The NotifyMessage that Minder expects, is an AS4Message which contains the specific UserMessage.
            var msg        = AS4Message.Create(minderUserMessage, new SendingProcessingMode());
            var serializer = SerializerProvider.Default.Get(msg.ContentType);

            byte[] content;

            using (var memoryStream = new MemoryStream())
            {
                serializer.Serialize(msg, memoryStream);
                content = memoryStream.ToArray();
            }

            return(new NotifyMessageEnvelope(notifyMessage.MessageInfo, notifyMessage.StatusInfo.Status, content, msg.ContentType, receivedEntityMessageType));
        }
Exemplo n.º 12
0
        protected virtual async Task <NotifyMessageEnvelope> CreateNotifyMessageEnvelopeAsync(
            AS4Message as4Message,
            string receivedEntityMessageId,
            Type receivedEntityType)
        {
            SignalMessage tobeNotifiedSignal =
                as4Message.SignalMessages.FirstOrDefault(s => s.MessageId == receivedEntityMessageId);

            NotifyMessage notifyMessage =
                AS4MessageToNotifyMessageMapper.Convert(
                    tobeNotifiedSignal,
                    receivedEntityType,
                    as4Message.EnvelopeDocument ?? AS4XmlSerializer.ToSoapEnvelopeDocument(as4Message));

            var serialized = await AS4XmlSerializer.ToStringAsync(notifyMessage).ConfigureAwait(false);

            return(new NotifyMessageEnvelope(
                       notifyMessage.MessageInfo,
                       notifyMessage.StatusInfo.Status,
                       System.Text.Encoding.UTF8.GetBytes(serialized),
                       "application/xml",
                       receivedEntityType));
        }