mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 18:27:55 +08:00
Medium Trust: Fixing machinekey validation code to avoid securityexception on web.config getsection code.
--HG-- branch : dev
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using System.Web.Configuration;
|
||||
using System.Web.Mvc;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Setup.Services;
|
||||
using Orchard.Setup.ViewModels;
|
||||
@@ -41,11 +43,21 @@ namespace Orchard.Setup.Controllers {
|
||||
|
||||
private bool ValidateMachineKey() {
|
||||
// Get the machineKey section.
|
||||
var section = ConfigurationManager.GetSection("system.web/machineKey") as MachineKeySection;
|
||||
MachineKeySection machineKeySection = null;
|
||||
|
||||
if (section == null
|
||||
|| section.DecryptionKey.Contains("AutoGenerate")
|
||||
|| section.ValidationKey.Contains("AutoGenerate")) {
|
||||
string webConfigFile = Path.Combine(HttpContext.Request.PhysicalApplicationPath, "web.config");
|
||||
using (XmlTextReader webConfigReader = new XmlTextReader(new StreamReader(webConfigFile))) {
|
||||
if (webConfigReader.ReadToFollowing("machineKey")) {
|
||||
machineKeySection = new MachineKeySection {
|
||||
DecryptionKey = webConfigReader.GetAttribute("decryptionKey"),
|
||||
ValidationKey = webConfigReader.GetAttribute("validationKey")
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (machineKeySection == null
|
||||
|| machineKeySection.DecryptionKey.Contains("AutoGenerate")
|
||||
|| machineKeySection.ValidationKey.Contains("AutoGenerate")) {
|
||||
|
||||
var rng = new RNGCryptoServiceProvider();
|
||||
var decryptionData = new byte[32];
|
||||
|
Reference in New Issue
Block a user