コード例 #1
0
        public void TestFiles(string fileName)
        {
            string filePath = Path.Combine("Mail\\TestFiles", fileName);
            string mailtext = File.ReadAllText(filePath);

            Message message = null;

            Assert.DoesNotThrow(() => message = Message.Load(mailtext));

            if (SMIMEStandard.IsContentMultipartSignature(message.ParsedContentType))
            {
                SignedEntity signedEntity = null;

                Assert.DoesNotThrow(() => signedEntity = SignedEntity.Load(message));
                message.Headers = message.Headers.SelectNonMimeHeaders();
                message.UpdateBody(signedEntity.Content); // this will merge in content + content specific mime headers
            }

            Message extracted = null;

            Assert.DoesNotThrow(() => extracted = WrappedMessage.ExtractInner(message));

            Header to = null;

            Assert.DoesNotThrow(() => to = extracted.To);

            MailAddressCollection addresses = null;

            Assert.DoesNotThrow(() => addresses = MailParser.ParseAddressCollection(to));
            Assert.True(addresses.Count > 0);

            Assert.DoesNotThrow(() => MailParser.ParseMailAddress(extracted.From));
        }
コード例 #2
0
        internal void VerifyOutgoingMessage(CDO.Message message)
        {
            Assert.True(string.IsNullOrEmpty(message.Subject));

            ContentType contentType = new ContentType(message.GetContentType());

            Assert.True(SMIMEStandard.IsContentEncrypted(contentType));
        }
コード例 #3
0
ファイル: SmtpAgent.cs プロジェクト: ywangmaxmd/nhin-d
        protected virtual MessageEnvelope ProcessEnvelope(ISmtpMessage message, MessageEnvelope envelope)
        {
            //
            // OUTGOING:
            //  Non-Encrypted messages from within the domain are treated as OUTGOING.
            //  Encrypted messages from within the domain are OPTIONALLY treated as Incoming
            //    - Only if InternalRelay is enabled
            // INCOMING:
            //  All messages sent by sources OUTSIDE the domain are ALWAYS treated as INCOMING
            //
            // The following boolean logic is the way it is to make it *easy to read*
            //
            bool isSenderInDomain = this.SecurityAgent.Domains.IsManaged(envelope.Sender);
            bool isOutgoing;

            if (isSenderInDomain)
            {
                isOutgoing = true;
                if (SMIMEStandard.IsEncrypted(envelope.Message))
                {
                    if (!m_settings.AllowInternalRelay)
                    {
                        throw new SmtpAgentException(SmtpAgentError.InternalRelayDisabled);
                    }
                    isOutgoing = false;
                }
            }
            else
            {
                isOutgoing = false;
            }

            if (isOutgoing)
            {
                envelope = this.ProcessOutgoing(message, envelope);
            }
            else
            {
                envelope = this.ProcessIncoming(message, envelope);
            }

            if (envelope == null)
            {
                throw new SmtpAgentException(SmtpAgentError.InvalidEnvelopeFromAgent);
            }

            return(envelope);
        }
コード例 #4
0
        /// <summary>
        /// Decrypt (optionally) the given message and try to extract signatures
        /// </summary>
        bool DecryptSignatures(IncomingMessage message, X509Certificate2 certificate, out SignedCms signatures, out MimeEntity payload)
        {
            MimeEntity decryptedEntity = null;

            signatures = null;
            payload    = null;

            if (certificate != null)
            {
                decryptedEntity = m_cryptographer.DecryptEntity(message.GetEncryptedBytes(m_cryptographer), certificate);
            }
            else
            {
                decryptedEntity = message.Message;
            }
            if (decryptedEntity == null)
            {
                return(false);
            }

            if (SMIMEStandard.IsContentEnvelopedSignature(decryptedEntity.ParsedContentType))
            {
                signatures = m_cryptographer.DeserializeEnvelopedSignature(decryptedEntity);
                payload    = MimeSerializer.Default.Deserialize <MimeEntity>(signatures.ContentInfo.Content);
            }
            else if (SMIMEStandard.IsContentMultipartSignature(decryptedEntity.ParsedContentType))
            {
                SignedEntity signedEntity = SignedEntity.Load(decryptedEntity);
                signatures = m_cryptographer.DeserializeDetachedSignature(signedEntity);
                payload    = signedEntity.Content;
            }
            else
            {
                throw new AgentException(AgentError.UnsignedMessage);
            }

            return(true);
        }
コード例 #5
0
        public void TestWithMessageObjects()
        {
            var message = MimeSerializer.Default.Deserialize <Message>(m_tester.ReadMessageText("simple.eml"));

            var outgoing = new OutgoingMessage(message);

            outgoing = m_tester.AgentA.ProcessOutgoing(outgoing);

            Assert.True(outgoing.Message.HasHeader(MailStandard.Headers.Date));

            Assert.True(SMIMEStandard.IsEncrypted(outgoing.Message));
            VerifyTrusted(outgoing.Recipients, m_tester.AgentA.MinTrustRequirement);
            Assert.True(outgoing.RejectedRecipients.Count == 0);

            var incoming = new IncomingMessage(outgoing.Message);

            incoming = m_tester.AgentB.ProcessIncoming(incoming);

            Assert.False(SMIMEStandard.IsEncrypted(incoming.Message));
            Assert.False(WrappedMessage.IsWrapped(incoming.Message));

            VerifyTrusted(incoming.Recipients, m_tester.AgentB.MinTrustRequirement);
            Assert.True(outgoing.RejectedRecipients.Count == 0);
        }
コード例 #6
0
        internal void VerifyIncomingMessage(CDO.Message message)
        {
            ContentType contentType = new ContentType(message.GetContentType());

            Assert.False(SMIMEStandard.IsContentEncrypted(contentType));
        }
コード例 #7
0
ファイル: TestSmtpAgentDSNs.cs プロジェクト: ssavarala/nhin-d
        public void TestFailedDSN_SecurityAndTrustOutGoingOnly_AlwaysGenerate_AllRecipientsRejected(
            string untrustedRecipientMessage
            , List <DSNPerRecipient> perRecipientExpected)
        {
            CleanMessages(m_agent.Settings);
            CleanMonitor();

            m_agent.Settings.InternalMessage.EnableRelay          = true;
            m_agent.Settings.Notifications.AutoResponse           = false; //don't care.  This is MDN specific
            m_agent.Settings.Notifications.AlwaysAck              = false; //don't care.  This is MDN specific
            m_agent.Settings.Notifications.AutoDsnFailureCreation =
                NotificationSettings.AutoDsnOption.Always.ToString();

            MdnMemoryStore.Clear();
            Mock <ClientSettings> mockClientSettings = MockMdnClientSettings();

            m_agent.Settings.MdnMonitor = mockClientSettings.Object;

            //
            // Process loopback messages.  Leaves un-encrypted mdns in pickup folder
            // Go ahead and pick them up and Process them as if they where being handled
            // by the SmtpAgent by way of (IIS)SMTP hand off.
            //
            var sendingMessage = LoadMessage(untrustedRecipientMessage);

            Assert.Equal(
                string.Format("Error={0}", AgentError.NoTrustedRecipients),
                Assert.Throws <OutgoingAgentException>(() => m_agent.ProcessMessage(sendingMessage)).Message
                );

            //No trusted recipients so not encrypted.
            ContentType contentType = new ContentType(sendingMessage.GetContentType());

            Assert.False(SMIMEStandard.IsContentEncrypted(contentType));


            //
            // grab the clear text dsn and delete others.
            // Process them as outgoing messages
            //
            bool foundDsn = false;

            foreach (var pickupMessage in PickupMessages())
            {
                string messageText = File.ReadAllText(pickupMessage);
                if (messageText.Contains("message/delivery-status"))
                {
                    foundDsn = true;
                    Assert.DoesNotThrow(() => RunMdnOutBoundProcessingTest(LoadMessage(messageText)));

                    //
                    // assert not in the monitor store.
                    // DSN messages are not monitored.
                    //
                    var queryMdn = BuildQueryFromDSN(LoadMessage(messageText));
                    var mdn      = MdnMemoryStore.FirstOrDefault(m => m.MdnIdentifier == queryMdn.MdnIdentifier);
                    Assert.Null(mdn);
                }
            }
            Assert.True(foundDsn);

            //
            // Now the messages are encrypted and can be handled as inbound messages.
            //
            foundDsn = false;
            foreach (var pickupMessage in PickupMessages())
            {
                foundDsn = true;
                string      messageText = File.ReadAllText(pickupMessage);
                CDO.Message message     = LoadMessage(messageText);
                Assert.DoesNotThrow(() => RunMdnInBoundProcessingTest(message));
                var dsnMessage = new CDOSmtpMessage(message).GetEnvelope();
                Assert.True(dsnMessage.Message.IsDSN());
                Assert.False(dsnMessage.Message.IsMDN());

                var dsn = DSNParser.Parse(dsnMessage.Message);
                foreach (var perRecipient in dsn.PerRecipient)
                {
                    Assert.Equal(perRecipientExpected.Count, dsn.PerRecipient.Count());
                    string finalRecipient       = perRecipient.FinalRecipient.Address;
                    var    expectedPerRecipient = perRecipientExpected.Find(d => d.FinalRecipient.Address == finalRecipient);
                    Assert.Equal(expectedPerRecipient.Action, perRecipient.Action);
                    Assert.Equal(expectedPerRecipient.Status, perRecipient.Status);
                }
            }
            Assert.True(foundDsn);

            //Ensure no MDNs where created by the DSN.
            Assert.True(!PickupMessages().Any());

            m_agent.Settings.InternalMessage.EnableRelay = false;
        }
コード例 #8
0
        public void TestDigestMicalgParameter(DigestAlgorithm algo)
        {
            ContentType type = SignedEntity.CreateContentType(algo);

            Assert.True(type.Parameters["micalg"] == SMIMEStandard.ToString(algo));
        }