Exemplo n.º 1
0
        /// <summary>
        /// Deserialize a SettingsStruct>
        /// </summary>
        /// 
        /// <param name="SettingsStream">Stream containing a serialized SettingsStruct</param>
        /// 
        /// <returns>A populated SettingsStruct</returns>
        internal static SettingsContainer DeSerialize(MemoryStream SettingsStream)
        {
            BinaryReader reader = new BinaryReader(SettingsStream);
            SettingsContainer settings = new SettingsContainer();

            settings.Authority = new KeyAuthority(SettingsStream);
            settings.Description = new CipherDescription(SettingsStream);
            settings.SignChecked = reader.ReadBoolean();
            settings.DomainRestrictChecked = reader.ReadBoolean();
            settings.VolatileChecked = reader.ReadBoolean();
            settings.SingleUseChecked = reader.ReadBoolean();
            settings.PostOverwriteChecked = reader.ReadBoolean();
            settings.PackageAuthChecked = reader.ReadBoolean();
            settings.NoNarrativeChecked = reader.ReadBoolean();
            settings.NoExportChecked = reader.ReadBoolean();

            return settings;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Convert a SettingsStruct to a string representation
 /// </summary>
 /// 
 /// <param name="Package">The SettingsStruct</param>
 /// 
 /// <returns>A base 64 string representation of the structure</returns>
 internal static string ToString(SettingsContainer Settings)
 {
     return Encoding.ASCII.GetString(Serialize(Settings).ToArray());
 }
Exemplo n.º 3
0
        /// <summary>
        /// Serialize a SettingsStruct structure
        /// </summary>
        /// 
        /// <param name="Settings">A SettingsStruct structure</param>
        /// 
        /// <returns>A stream containing the SettingsStruct data</returns>
        internal static MemoryStream Serialize(SettingsContainer Settings)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            writer.Write(Settings.Authority.ToBytes());
            writer.Write(Settings.Description.ToBytes());
            writer.Write(Settings.SignChecked);
            writer.Write(Settings.DomainRestrictChecked);
            writer.Write(Settings.VolatileChecked);
            writer.Write(Settings.SingleUseChecked);
            writer.Write(Settings.PostOverwriteChecked);
            writer.Write(Settings.PackageAuthChecked);
            writer.Write(Settings.NoNarrativeChecked);
            writer.Write(Settings.NoExportChecked);

            return stream;
        }
Exemplo n.º 4
0
 private void LoadSettings()
 {
     if (string.IsNullOrEmpty(Properties.Settings.Default.AppSettings))
     {
         // first run
         LoadDefaults();
         return;
     }
     else
     {
         try
         {
             // get the encrypted _container string and convert to byte array
             byte[] appData = Convert.FromBase64String(Properties.Settings.Default.AppSettings);
             // decrypt the array with DAPI, requires same user context
             appData = DataProtect.DecryptProtectedData(appData, Utilities.GetCredentials());
             // deserialize the settings container
             _container = SettingsContainer.DeSerialize(new MemoryStream(appData));
             _container.Authority.OptionFlag = 0;
             _container.Authority.KeyPolicy = 0;
             // apply the container values to controls
             cbEngines.SelectedIndex = _container.Description.EngineType;
             SetComboParams((SymmetricEngines)_container.Description.EngineType);
             SetKeySizes((SymmetricEngines)_container.Description.EngineType, (Digests)_container.Description.KdfEngine);
             cbCipherMode.SelectedIndex = _container.Description.CipherType;
             cbHkdf.SelectedIndex = _container.Description.KdfEngine;
             cbHmac.SelectedIndex = _container.Description.MacEngine;
             cbKeySize.SelectedIndex = ComboHelper.IndexFromValue(_container.Description.KeySize, typeof(KeySizes), cbKeySize);
             cbPaddingMode.SelectedIndex = _container.Description.PaddingType;
             cbRounds.SelectedIndex = ComboHelper.IndexFromValue(_container.Description.RoundCount, typeof(RoundCounts), cbRounds);
             cbVectorSize.SelectedIndex = ComboHelper.IndexFromValue(_container.Description.IvSize, typeof(IVSizes), cbVectorSize);
             chkDomainRestrict.Checked = _container.DomainRestrictChecked;
             chkNoExport.Checked = _container.NoExportChecked;
             chkNoNarrative.Checked = _container.NoNarrativeChecked;
             chkPackageAuth.Checked = _container.PackageAuthChecked;
             chkPostOverwrite.Checked = _container.PostOverwriteChecked;
             chkSign.Checked = _container.SignChecked;
             chkSingleUse.Checked = _container.SingleUseChecked;
             chkVolatile.Checked = _container.VolatileChecked;
             _container.Authority.DomainId = Utilities.GetDomainId();
         }
         catch
         {
             LoadDefaults();
         }
     }
 }
Exemplo n.º 5
0
        private void LoadDefaults()
        {
            byte[] origin = _container.Authority.OriginId;
            if (!IdValid(origin))
                origin = Utilities.GetOriginId();

            _container = new SettingsContainer()
            {
                Authority = new KeyAuthority(Utilities.GetDomainId(), origin, new byte[0], new byte[0], KeyPolicies.None),
                Description = new CipherDescription(SymmetricEngines.RHX, (int)KeySizes.K2560, IVSizes.V128, CipherModes.CTR, PaddingModes.X923, BlockSizes.B128, RoundCounts.R22),
                DomainRestrictChecked = false,
                NoNarrativeChecked = false,
                PackageAuthChecked = false,
                PostOverwriteChecked = false,
                SignChecked = false,
                SingleUseChecked = false,
                VolatileChecked = false
            };
        }
Exemplo n.º 6
0
 /// <summary>
 /// Convert a SettingsStruct to a string representation
 /// </summary>
 ///
 /// <param name="Package">The SettingsStruct</param>
 ///
 /// <returns>A base 64 string representation of the structure</returns>
 internal static string ToString(SettingsContainer Settings)
 {
     return(Encoding.ASCII.GetString(Serialize(Settings).ToArray()));
 }