/// <summary>
        /// Load the settings from the settings.xml file and apply the new settings to the dkimSigner instance.
        /// </summary>
        private void LoadSettings()
        {
            Settings config = new Settings();
            config.InitHeadersToSign();

            string assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            if (assemblyDir != null && config.Load(Path.Combine(assemblyDir, "settings.xml")))
            {
                dkimSigner.UpdateSettings(config);
                Logger.LogLevel = config.Loglevel;
                Logger.LogInformation("Exchange DKIM settings loaded: " + config.SigningAlgorithm + ", Canonicalization Header Algorithm: " + config.HeaderCanonicalization + ", Canonicalization Body Algorithm: " + config.BodyCanonicalization + ", Number of domains: " + dkimSigner.GetDomains().Count);
            }
            else
            {
                Logger.LogError("Couldn't load the settings file.\n");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the current configuration for Exchange DkimSigner from the registry
        /// </summary>
        private void LoadDkimSignerConfig()
        {
            oConfig = new Settings();
            oConfig.InitHeadersToSign();

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

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

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

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

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

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

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

            bDataUpdated = false;
        }