Beispiel #1
0
        /// <summary>
        /// Serialize a SealedDelivery2 object to a XmlDocument. using defaultnamespaceV2, that is a property from config file, add this to xmlserializer.
        /// </summary>
        public XmlDocument SerializeToXmlDocumentV3(SealedDelivery2 sealedDelivery, string defaultNameSpaceV3, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.BusinessLayer.Helper.SerializeHelper: incoming SerializeToXmlDocumentV3 with RequestId: {0}", requestId));

            var xmlDocument = new XmlDocument();

            xmlDocument.PreserveWhitespace = false;

            var xmlSerializerNameSpace = new XmlSerializerNamespaces();

            xmlSerializerNameSpace.Add("", defaultNameSpaceV3);

            using (var memoryStream = new MemoryStream())
            {
                var xmlWriterSettings = new XmlWriterSettings();
                xmlWriterSettings.OmitXmlDeclaration = true;
                xmlWriterSettings.Encoding           = Encoding.UTF8;

                using (var xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings))
                {
                    var xmlSerializer = new XmlSerializer(typeof(SealedDelivery2), defaultNameSpaceV3);
                    xmlSerializer.Serialize(xmlWriter, sealedDelivery, xmlSerializerNameSpace);
                }

                memoryStream.Position = 0;
                xmlDocument.Load(memoryStream);
            }

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.BusinessLayer.Helper.SerializeHelper: leaving SerializeToXmlDocumentV3 with RequestId: {0}", requestId));
            return(xmlDocument);
        }
Beispiel #2
0
        /// <summary>
        /// Handler that creates a SealedDelivery from a SignedDelivery.
        /// </summary>
        public SealedDelivery2 GetSealedDeliveryV3(SignedDelivery2 signedDelivery, bool signDelivery, string defaultNameSpaceV3, string signingCertificateSubjectName, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.BusinessLayer.Handler.SealedDeliveryHandler: incoming GetSealedDeliveryV3 with RequestId: {0}", requestId));

            var sDelivery = new SealedDelivery2();

            sDelivery.Seal = new Seal();
            sDelivery.Seal.ReceivedTime = DateTime.Now;
            sDelivery.Seal.SignaturesOK = true;

            sDelivery.SignedDelivery = signedDelivery;

            //Check configfile to see if we should sign delivery.
            if (signDelivery)
            {
                try
                {
                    // Serialize SignedDelivery to XmlDocument
                    var serializeHelperV3 = new SerializeHelperV3();
                    var xmlDocument       = serializeHelperV3.SerializeToXmlDocumentV3(sDelivery, defaultNameSpaceV3, requestId);

                    // Get signing certificate helper
                    var signingCertificateHelper = new SigningCertificateHelper();
                    var signXmlDocumentHandler   = new SignXmlDocumentHandler();

                    // Sign xml document with certificate
                    var certificate       = signingCertificateHelper.GetXMLSigningCertificate(signingCertificateSubjectName, requestId);
                    var signedXmlDocument = signXmlDocumentHandler.SignSealedDeliveryXmlDocument(xmlDocument, certificate, requestId);

                    // Deserialize signed xml document to SignedDelivery
                    sDelivery = serializeHelperV3.DeserializeXmlToSealedDeliveryV3(signedXmlDocument, defaultNameSpaceV3, requestId);
                }
                catch (CryptographicException ce)
                {
                    string errorMessage = string.Format("SE.GOV.MM.Integration.DeliveryMailbox.BusinessLayer.Handler: Certification error. RequestId: {0}. ExceptionMessage: {1}", requestId, ce.Message);
                    LogManager.Log(new Log.Log()
                    {
                        Exception = ce, Message = errorMessage, EventId = EventId.XmlDocumentSigningException, Level = Level.Error
                    });
                    throw new Exception(errorMessage);
                }
                catch (Exception e)
                {
                    string errorMessage = string.Format("SE.GOV.MM.Integration.DeliveryMailbox.BusinessLayer.Handler: Exception have been thrown. RequestId: {0}. ExceptionMessage: {1}", requestId, e.Message);
                    LogManager.Log(new Log.Log()
                    {
                        EventId = EventId.GenerelizedException, Exception = e, Level = Level.Error, Message = errorMessage
                    });
                    throw e;
                }
            }

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.BusinessLayer.Handler.SignedDeliveryHandler: leaving GetSealedDeliveryV3 with RequestId: {0}", requestId));
            return(sDelivery);
        }
Beispiel #3
0
        /// <summary>
        /// Calls MailboxOperatorService to deliver SealedDelivery1 and converts response to known object in DeliveryMailbox.
        /// </summary>
        /// <param name="delivery"></param>
        /// <param name="box"></param>
        /// <param name="certificateFindByThumbprint"></param>
        /// <param name="requestId"></param>
        /// <returns></returns>
        public SendPackageToMailboxResponse SendPackageToMailboxV3(SealedDelivery2 delivery, Mailbox box, string certificateFindByThumbprint, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.DataManager: incoming SendPackageToMailboxV3 with RequestId: {0}", requestId));
            var service = new MailboxOperatorService();

            var result = service.SendMessageToMailboxOperatorV3(delivery, box, certificateFindByThumbprint, requestId);


            var sendMessageToMailboxResponse = createNewSendMessageToMailboxResponse(result);

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.DataManager: leaving SendPackageToMailboxV3 with RequestId: {0}", requestId));
            return(sendMessageToMailboxResponse);
        }
Beispiel #4
0
        /// <summary>
        /// Sends a SealedDelivery object to the recipient mailbox using the certificate configured in web.config.
        /// </summary>
        /// <param name="delivery"></param>
        /// <param name="mailbox"></param>
        /// <param name="SSLCertificate_FindByThumbprint"></param>
        /// <param name="requestId"></param>
        /// <returns></returns>
        public DeliveryResult SendMessageToMailboxOperatorV3(SealedDelivery2 delivery, Mailbox mailbox, string SSLCertificate_FindByThumbprint, Guid requestId)
        {
            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: incoming SendMessageToMailboxOperatorV3 with RequestId: {0}", requestId));
            DeliveryResult result = null;

            var binding = new BasicHttpBinding()
            {
                Security = new BasicHttpSecurity()
                {
                    Transport = new HttpTransportSecurity()
                    {
                        ClientCredentialType = HttpClientCredentialType.Certificate
                    },
                    Mode = BasicHttpSecurityMode.Transport
                }
            };


            try
            {
                //MG Relight ändrade FindByThumbprint  X509FindType.FindBySubjectName

                var client = new ServicePortv3Client(binding, new EndpointAddress(mailbox.ServiceAdress));
                client.Endpoint.Behaviors.Add(new FaultFormatingBehavior());

                client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, SSLCertificate_FindByThumbprint);
                result = client.deliverSecure(delivery);
            }
            catch (FaultException fe)
            {
                string errorMessage = string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: SOAPFAULT SendMessageToMailboxOperatorV3 with RequestId: {0}", requestId);
                LogManager.Log(new Log.Log()
                {
                    EventId = EventId.CommunicationExceptionWithService, Exception = fe, Level = Level.Error, Message = errorMessage
                });
                throw fe;
            }
            catch (Exception e)
            {
                string errorMessage = string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: EXCEPTION in SendMessageToMailboxV3 with RequestId: {0}", requestId);
                LogManager.Log(new Log.Log()
                {
                    EventId = EventId.CommunicationExceptionWithService, Exception = e, Level = Level.Error, Message = errorMessage
                });
                throw e;
            }

            LogManager.LogTrace(string.Format("SE.GOV.MM.Integration.DeliveryMailbox.DataLayer.MailboxOperatorService: leaving SendMessageToMailboxV3 with RequestId: {0}", requestId));

            return(result);
        }