コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DkimSigningRoutingAgent"/> class.
        /// </summary>
        /// <param name="dkimSigner">The object that knows how to sign messages.</param>
        public DkimSigningRoutingAgent()
        {
            Logger.LogDebug("Initializing DkimSigner");
            Settings config = new Settings();
            config.InitHeadersToSign();

            this.dkimSigner = new DkimSigner();

            this.LoadSettings();
            this.WatchSettings();

            this.OnCategorizedMessage += this.WhenMessageCategorized;
            Logger.LogDebug("DkimSigner initiallized");
        }
コード例 #2
0
ファイル: Settings.cs プロジェクト: Benjile/dkim-exchange
 public static Settings LoadOrCreate(string FileName)
 {
     if (!System.IO.File.Exists(FileName))
     {
         // default settings
         Settings s = new Settings();
         s.HeadersToSign = new List<string>(new string[] {"From","Subject","To","Date","Message-ID"});
         return s;
     }
     else
     {
         return Load(FileName);
     }
 }
コード例 #3
0
ファイル: MainWindow.cs プロジェクト: Benjile/dkim-exchange
        /// <summary>
        /// Load the current configuration for Exchange DkimSigner from the registry
        /// </summary>
        private void LoadDkimSignerConfig()
        {
            try
            {
                this.oConfig = Settings.LoadOrCreate(Path.Combine(Constants.DKIM_SIGNER_PATH, "settings.xml"));

                switch (this.oConfig.Loglevel)
                {
                    case 1:
                        this.cbLogLevel.Text = "Error";
                        break;
                    case 2:
                        this.cbLogLevel.Text = "Warning";
                        break;
                    case 3:
                        this.cbLogLevel.Text = "Information";
                        break;
                    default:
                        this.cbLogLevel.Text = "Information";
                        MessageBox.Show("The log level is invalid. The log level have been set to Information.");
                        break;
                }

                this.rbRsaSha1.Checked = (oConfig.SigningAlgorithm == DkimAlgorithmKind.RsaSha1);

                this.rbSimpleHeaderCanonicalization.Checked = (this.oConfig.HeaderCanonicalization == DkimCanonicalizationKind.Simple);
                this.rbRelaxedHeaderCanonicalization.Checked = (this.oConfig.HeaderCanonicalization == DkimCanonicalizationKind.Relaxed);
                this.rbSimpleBodyCanonicalization.Checked = (this.oConfig.BodyCanonicalization == DkimCanonicalizationKind.Simple);
                this.rbRelaxedBodyCanonicalization.Checked = (this.oConfig.BodyCanonicalization == DkimCanonicalizationKind.Relaxed);

                this.lbxHeadersToSign.Items.Clear();

                foreach (string sItem in this.oConfig.HeadersToSign)
                {
                    this.lbxHeadersToSign.Items.Add(sItem);
                }

                this.lbxHeadersToSign.SelectedItem = null;

                this.ReloadDomainsList();

                this.bDataUpdated = false;
            }
            catch (Exception e)
            {
                MessageBox.Show("Couldn't load the settings file:\n" + e.Message + "\nSetting it to default values.", "Settings error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #4
0
ファイル: MainWindow.cs プロジェクト: ValiMail/dkim-exchange
        /// <summary>
        /// Load the current configuration for Exchange DkimSigner from the registry
        /// </summary>
        private void LoadDkimSignerConfig()
        {
            this.oConfig = new Settings();
            this.oConfig.InitHeadersToSign();

            if (!this.oConfig.Load(Path.Combine(Constants.DKIM_SIGNER_PATH, "settings.xml")))
            {
                this.ShowMessageBox("Settings error", "Couldn't load the settings file.\n Setting it to default values.", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            //
            // Log level
            //
            switch (this.oConfig.Loglevel)
            {
                case 1:
                    this.cbLogLevel.Text = "Error";
                    break;
                case 2:
                    this.cbLogLevel.Text = "Warning";
                    break;
                case 3:
                    this.cbLogLevel.Text = "Information";
                    break;
                case 4:
                    this.cbLogLevel.Text = "Debug";
                    break;
                default:
                    this.cbLogLevel.Text = "Information";
                    this.ShowMessageBox("Information", "The log level is invalid. Set to default: Information.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
            }

            //
            // Algorithm and Canonicalization
            //
            this.rbRsaSha1.Checked = (oConfig.SigningAlgorithm == DkimAlgorithmKind.RsaSha1);
            this.rbSimpleHeaderCanonicalization.Checked = (this.oConfig.HeaderCanonicalization == DkimCanonicalizationKind.Simple);
            this.rbRelaxedHeaderCanonicalization.Checked = (this.oConfig.HeaderCanonicalization == DkimCanonicalizationKind.Relaxed);
            this.rbSimpleBodyCanonicalization.Checked = (this.oConfig.BodyCanonicalization == DkimCanonicalizationKind.Simple);
            this.rbRelaxedBodyCanonicalization.Checked = (this.oConfig.BodyCanonicalization == DkimCanonicalizationKind.Relaxed);

            //
            // Headers to sign
            //
            this.lbxHeadersToSign.Items.Clear();
            foreach (string sItem in this.oConfig.HeadersToSign)
            {
                this.lbxHeadersToSign.Items.Add(sItem);
            }

            //
            // Domain
            //
            DomainElement oCurrentDomain = null;
            if (this.lbxDomains.SelectedItem != null)
            {
                oCurrentDomain = (DomainElement) this.lbxDomains.SelectedItem;
            }

            this.lbxDomains.Items.Clear();
            foreach (DomainElement oConfigDomain in this.oConfig.Domains)
            {
                this.lbxDomains.Items.Add(oConfigDomain);
            }

            if (oCurrentDomain != null)
            {
                this.lbxDomains.SelectedItem = oCurrentDomain;
            }

            this.bDataUpdated = false;
        }
コード例 #5
0
        private void LoadSettings()
        {
            Settings config = new Settings();
            config.InitHeadersToSign();

            if(config.Load(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "settings.xml")))
            {
                this.dkimSigner.UpdateSettings(config);
                Logger.logLevel = config.Loglevel;
                Logger.LogInformation("Exchange DKIM settings loaded: " + config.SigningAlgorithm.ToString() + ", Canonicalization Header Algorithm: " + config.HeaderCanonicalization.ToString() + ", Canonicalization Body Algorithm: " + config.BodyCanonicalization.ToString() + ", Number of domains: " + this.dkimSigner.GetDomains().Count);
            }
            else
            {
                Logger.LogError("Couldn't load the settings file.\n");
            }
        }
コード例 #6
0
 public void TestInitHeadersToSign()
 {
     Settings config = new Settings();
     config.InitHeadersToSign();
     Assert.AreEqual(new string[] { "From", "Subject", "To", "Date", "Message-ID" }, config.HeadersToSign);
 }
コード例 #7
0
ファイル: DkimSigner.cs プロジェクト: ser-genri/dkim-exchange
        public void UpdateSettings(Settings config)
        {
            // Load the list of domains
            this.domains.Clear();
            foreach (DomainElement domainElement in config.Domains)
            {
                try
                {
                    if (domainElement.InitElement(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)))
                    {
                        this.domains.Add(domainElement.Domain, domainElement);
                    }
                }
                catch (Exception e)
                {
                    Logger.LogError(e.Message);
                }
            }

            switch (config.SigningAlgorithm)
            {
                case DkimAlgorithmKind.RsaSha1:
                    this.hashAlgorithm = new SHA1CryptoServiceProvider();
                    this.hashAlgorithmCryptoCode = "SHA1";
                    this.hashAlgorithmDkimCode = "rsa-sha1";
                    break;
                case DkimAlgorithmKind.RsaSha256:
                    this.hashAlgorithm = new SHA256CryptoServiceProvider();
                    this.hashAlgorithmCryptoCode = "SHA256";
                    this.hashAlgorithmDkimCode = "rsa-sha256";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("signatureKind");
            }

            this.headerCanonicalization = config.HeaderCanonicalization;
            this.bodyCanonicalization = config.BodyCanonicalization;

            this.eligibleHeaders = new HashSet<string>();
            foreach (string headerToSign in config.HeadersToSign)
            {
                this.eligibleHeaders.Add(headerToSign.Trim());
            }

            // The From header must always be signed according to the
            // DKIM specification.
            if (!this.eligibleHeaders.Contains("From"))
            {
                this.eligibleHeaders.Add("From");
            }
        }