internal static string ConvertFromEnum(MachineKeyValidation enumValue) { switch (enumValue) { case MachineKeyValidation.SHA1: return("SHA1"); case MachineKeyValidation.MD5: return("MD5"); case MachineKeyValidation.TripleDES: return("3DES"); case MachineKeyValidation.AES: return("AES"); case MachineKeyValidation.HMACSHA256: return("HMACSHA256"); case MachineKeyValidation.HMACSHA384: return("HMACSHA384"); case MachineKeyValidation.HMACSHA512: return("HMACSHA512"); default: throw new ArgumentException(SR.GetString(SR.Wrong_validation_enum)); } }
public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) { if (value.GetType() != typeof(MachineKeyValidation)) { /* MS throws this exception on an invalid */ throw new FormatException("invalid validation value"); } MachineKeyValidation v = (MachineKeyValidation)value; if (v == MachineKeyValidation.MD5) { return("MD5"); } else if (v == MachineKeyValidation.SHA1) { return("SHA1"); } else if (v == MachineKeyValidation.TripleDES) { return("3DES"); } else if (v == MachineKeyValidation.AES) { return("AES"); } else { /* MS throws this exception on an invalid */ throw new FormatException("invalid validation value"); } }
internal static string ConvertFromEnum(MachineKeyValidation enumValue) { switch (enumValue) { case MachineKeyValidation.MD5: return "MD5"; case MachineKeyValidation.SHA1: return "SHA1"; case MachineKeyValidation.TripleDES: return "3DES"; case MachineKeyValidation.AES: return "AES"; case MachineKeyValidation.HMACSHA256: return "HMACSHA256"; case MachineKeyValidation.HMACSHA384: return "HMACSHA384"; case MachineKeyValidation.HMACSHA512: return "HMACSHA512"; } throw new ArgumentException(System.Web.SR.GetString("Wrong_validation_enum")); }
internal MachineKeyConfig (object parent) { if (parent is MachineKeyConfig) { MachineKeyConfig p = (MachineKeyConfig) parent; validation_key = p.validation_key; decryption_key = p.decryption_key; validation_type = p.validation_type; } }
private void CacheValidation() { this._cachedValidation = (string)base[_propValidation]; if (this._cachedValidation == null) { this._cachedValidation = "HMACSHA256"; } this._cachedValidationEnum = MachineKeyValidationConverter.ConvertToEnum(this._cachedValidation); this._validationIsCached = true; }
private static bool InitializeSettings(bool initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings) { if (!initializeGeneralSettings) { return(false); } s_HashAlgorithmType = settings.HashAlgorithmType; s_HashAlgorithmFromConfig = !string.IsNullOrEmpty(s_HashAlgorithmType); if (!s_HashAlgorithmFromConfig) { // If no hash algorithm is specified, use the same as the "validation" in "<machineKey>". // If the validation is "3DES", switch it to use "SHA1" instead. MachineKeyValidation v = appConfig.MachineKey.Validation; if (v != MachineKeyValidation.AES && v != MachineKeyValidation.TripleDES) { s_HashAlgorithmType = appConfig.MachineKey.ValidationAlgorithm; } else { s_HashAlgorithmType = "SHA1"; } } s_Providers = new MembershipProviderCollection(); if (HostingEnvironment.IsHosted) { ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(MembershipProvider)); } else { foreach (ProviderSettings ps in settings.Providers) { Type t = Type.GetType(ps.Type, true, true); if (!typeof(MembershipProvider).IsAssignableFrom(t)) { throw new ArgumentException(SR.GetString(SR.Provider_must_implement_type, typeof(MembershipProvider).ToString())); } MembershipProvider provider = (MembershipProvider)Activator.CreateInstance(t); NameValueCollection pars = ps.Parameters; NameValueCollection cloneParams = new NameValueCollection(pars.Count, StringComparer.Ordinal); foreach (string key in pars) { cloneParams[key] = pars[key]; } provider.Initialize(ps.Name, cloneParams); s_Providers.Add(provider); } } TimeSpan timeWindow = settings.UserIsOnlineTimeWindow; s_UserIsOnlineTimeWindow = (int)timeWindow.TotalMinutes; return(true); }
public object Create(object parent, object context, XmlNode section) { if (section.HasChildNodes) { ThrowException("Child nodes not allowed here", section.FirstChild); } MachineKeyConfig config = new MachineKeyConfig(parent); try { config.SetValidationKey(AttValue("validationKey", section)); } catch (ArgumentException e) { ThrowException(e.Message, section); } try { config.SetDecryptionKey(AttValue("decryptionKey", section)); } catch (ArgumentException e) { ThrowException(e.Message, section); } string validation = AttValue("validation", section); MachineKeyValidation valid = 0; if (validation == "SHA1") { valid = MachineKeyValidation.SHA1; } else if (validation == "MD5") { valid = MachineKeyValidation.MD5; } else if (validation == "TripleDES") { valid = MachineKeyValidation.TripleDES; } else { ThrowException("Invalid 'validation' value", section); } config.ValidationType = valid; if (section.Attributes != null && section.Attributes.Count != 0) { ThrowException("Unrecognized attribute", section); } return(config); }
private static bool InitializeSettings(bool initializeGeneralSettings, RuntimeConfig appConfig, MembershipSection settings) { if (!initializeGeneralSettings) { return(false); } s_HashAlgorithmType = settings.HashAlgorithmType; s_HashAlgorithmFromConfig = !string.IsNullOrEmpty(s_HashAlgorithmType); if (!s_HashAlgorithmFromConfig) { MachineKeyValidation validation = appConfig.MachineKey.Validation; if ((validation != MachineKeyValidation.AES) && (validation != MachineKeyValidation.TripleDES)) { s_HashAlgorithmType = appConfig.MachineKey.ValidationAlgorithm; } else { s_HashAlgorithmType = "SHA1"; } } s_Providers = new MembershipProviderCollection(); if (HostingEnvironment.IsHosted) { ProvidersHelper.InstantiateProviders(settings.Providers, s_Providers, typeof(MembershipProvider)); } else { foreach (ProviderSettings settings2 in settings.Providers) { Type c = Type.GetType(settings2.Type, true, true); if (!typeof(MembershipProvider).IsAssignableFrom(c)) { throw new ArgumentException(System.Web.SR.GetString("Provider_must_implement_type", new object[] { typeof(MembershipProvider).ToString() })); } MembershipProvider provider = (MembershipProvider)Activator.CreateInstance(c); NameValueCollection parameters = settings2.Parameters; NameValueCollection config = new NameValueCollection(parameters.Count, StringComparer.Ordinal); foreach (string str in parameters) { config[str] = parameters[str]; } provider.Initialize(settings2.Name, config); s_Providers.Add(provider); } } s_UserIsOnlineTimeWindow = (int)settings.UserIsOnlineTimeWindow.TotalMinutes; return(true); }
static Type GetValidationAlgorithmType(MachineKeyValidation enumValue) { switch (enumValue) { case MachineKeyValidation.MD5: return typeof (MD5CryptoServiceProvider); case MachineKeyValidation.SHA1: return typeof (SHA1); case MachineKeyValidation.TripleDES: return typeof (TripleDESCryptoServiceProvider); case MachineKeyValidation.AES: return typeof (AesCryptoServiceProvider); case MachineKeyValidation.HMACSHA256: return typeof (HMACSHA256); case MachineKeyValidation.HMACSHA384: return typeof (HMACSHA384); case MachineKeyValidation.HMACSHA512: return typeof (HMACSHA512); default: throw new ArgumentException("Unknown validation type."); } }
private void CacheValidation() { this._cachedValidation = (string) base[_propValidation]; if (this._cachedValidation == null) { this._cachedValidation = "HMACSHA256"; } this._cachedValidationEnum = MachineKeyValidationConverter.ConvertToEnum(this._cachedValidation); this._validationIsCached = true; }
public SetIisMachineKeyOperation(string validationKey, string decryptionKey, MachineKeyValidation validation) { _validationKey = validationKey; _decryptionKey = decryptionKey; _validation = validation; }
public MachineKeySection() { // get DefaultValue from ValidationAlgorithm validation = (MachineKeyValidation)converter.ConvertFrom(null, null, ValidationAlgorithm); }
public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { if (config == null) { throw new ArgumentNullException("config"); } // Get the machineKey section. Configuration conf = WebConfigurationManager.OpenWebConfiguration("~/Web.config"); MachineKeySection key = (MachineKeySection)conf.GetSection("system.web/machineKey"); this.machinekeyValidation = key.Validation; System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding(); //Atribuir os valores dos atributos definidos no web.config a variáveis locais this.sProviderName = name; this.sAppName = config["applicationName"]; this.bEnablePasswordRetrieval = config["enablePasswordRetrieval"].ToLower() == "true" ? true : false; this.bEnablePasswordReset = config["enablePasswordReset"].ToLower() == "true" ? true : false; this.bRequiresQuestionAndAnswer = config["requiresQuestionAndAnswer"].ToLower() == "true" ? true : false; this._DecryptionKey = ue.GetBytes(key.DecryptionKey); this._ValidationKey = ue.GetBytes(key.ValidationKey); this.bRequiresUniqueEMail = config["requiresUniqueEmail"].ToLower() == "true" ? true : false; ; this.ipasswordAttemptWindow = int.Parse(config["passwordAttemptWindow"]); this.iMinRequiredNonAlphanumericCharacters = int.Parse(config["minRequiredNonalphanumericCharacters"]); this.iminRequiredPasswordLength = int.Parse(config["minRequiredPasswordLength"]); this.imaxInvalidPasswordAttempts = int.Parse(config["maxInvalidPasswordAttempts"]); this.sPasswordStrengthRegularExpression = config["passwordStrengthRegularExpression"]; switch (config["passwordFormat"]) { case "Hashed": this.mPasswordFormat = MembershipPasswordFormat.Hashed; break; case "Encrypted": this.mPasswordFormat = MembershipPasswordFormat.Encrypted; break; case "Clear": this.mPasswordFormat = MembershipPasswordFormat.Clear; break; default: throw new ProviderException("Password format not supported."); } base.Initialize(name, config); }
private void CacheValidation() { _cachedValidation = GetValidationAttributeSkipValidation(); _cachedValidationEnum = MachineKeyValidationConverter.ConvertToEnum(_cachedValidation); _validationIsCached = true; }
/// <summary> /// Sets the IIS machine key. Configures algorithms and keys to use for encryption, /// decryption, and validation of forms-authentication data and view-state data, and /// for out-of-process session state identification. /// </summary> /// <param name="configuration"></param> /// <param name="validationKey">Specifies the key used to validate encrypted data</param> /// <param name="decryptionKey">Specifies the key that is used to encrypt and decrypt data or the process by which the key is generated</param> /// <param name="validation">Specifies the type of encryption that is used to validate data</param> /// <returns></returns> public static IOfferRemoteConfiguration IisMachineKey(this IOfferRemoteConfiguration configuration, string validationKey, string decryptionKey, MachineKeyValidation validation) { var operation = new SetIisMachineKeyOperation(validationKey, decryptionKey, validation); OperationExecutor.Execute((RemoteBuilder)configuration, operation); return(configuration); }
private void CacheValidation() { _validation = GetValidationAttributeSkipValidation(); _cachedValidationEnum = MachineKeyValidationConverter.ConvertToEnum(_validation); _validationIsCached = true; }
/// <summary> /// Sets the IIS machine key. Configures algorithms and keys to use for encryption, /// decryption, and validation of forms-authentication data and view-state data, and /// for out-of-process session state identification. /// </summary> /// <param name="configuration"></param> /// <param name="validationKey">Specifies the key used to validate encrypted data</param> /// <param name="decryptionKey">Specifies the key that is used to encrypt and decrypt data or the process by which the key is generated</param> /// <param name="validation">Specifies the type of encryption that is used to validate data</param> /// <returns></returns> public static IOfferRemoteConfiguration IisMachineKey(this IOfferRemoteConfiguration configuration, string validationKey, string decryptionKey, MachineKeyValidation validation) { var operation = new SetIisMachineKeyOperation(validationKey, decryptionKey, validation); Configure.Operation(configuration, operation); return(configuration); }
/// <summary> /// Sets the IIS machine key. Configures algorithms and keys to use for encryption, /// decryption, and validation of forms-authentication data and view-state data, and /// for out-of-process session state identification. /// </summary> /// <param name="configuration"></param> /// <param name="validationKey">Specifies the key used to validate encrypted data</param> /// <param name="decryptionKey">Specifies the key that is used to encrypt and decrypt data or the process by which the key is generated</param> /// <param name="validation">Specifies the type of encryption that is used to validate data</param> /// <returns></returns> public static IOfferRemoteConfiguration IisMachineKey(this IOfferRemoteConfiguration configuration, string validationKey, string decryptionKey, MachineKeyValidation validation) { var operation = new SetIisMachineKeyOperation(validationKey, decryptionKey, validation); Configure.Operation(configuration, operation); return configuration; }
public MachineKeySection () { // get DefaultValue from ValidationAlgorithm validation = (MachineKeyValidation) converter.ConvertFrom (null, null, ValidationAlgorithm); }