Skip to content
This repository has been archived by the owner on Feb 12, 2019. It is now read-only.

Commit

Permalink
CONTENT-8414: compatible with .net 35.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyhfish committed Jul 25, 2017
1 parent 9910833 commit 5b2f0fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
7 changes: 0 additions & 7 deletions Components/Checks/CheckDefaultPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ public class CheckDefaultPage : IAuditCheck
public CheckResult Execute()
{
var result = new CheckResult(SeverityEnum.Unverified, "CheckDefaultPage");
var version = Environment.Version.ToString(2);
if (version == "2.0")
{
result.Notes.Add("This check requires .Net Version 4.0 or above");
return result;
}

try
{
IList<string> modifiedFiles;
Expand Down
38 changes: 24 additions & 14 deletions Components/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static XmlDocument LoadFileSumData()

public static string GetFileCheckSum(string fileName)
{
using (var cryptographyProvider = SHA256.Create(AllowOnlyFipsAlgorithms() ? "System.Security.Cryptography.SHA256CryptoServiceProvider" : "System.Security.Cryptography.SHA256Cng"))
using (var cryptographyProvider = CreateCryptographyProvider())
{
if (cryptographyProvider != null)
{
Expand All @@ -197,6 +197,29 @@ public static string GetFileCheckSum(string fileName)
return string.Empty;
}

private static SHA256 CreateCryptographyProvider()
{
try
{
var property = typeof(CryptoConfig).GetProperty("AllowOnlyFipsAlgorithms", BindingFlags.Public | BindingFlags.Static);
if (property == null)
{
return SHA256.Create();
}

if ((bool) property.GetValue(null, null))
{
return SHA256.Create("System.Security.Cryptography.SHA256CryptoServiceProvider");
}

return SHA256.Create("System.Security.Cryptography.SHA256Cng");
}
catch (Exception)
{
return null;
}
}

public static string GetApplicationVersion()
{
return DotNetNukeContext.Current.Application.Version.ToString(3);
Expand Down Expand Up @@ -253,18 +276,5 @@ public static IList<FileInfo> GetLastModifiedExecutableFiles()
.Take(ModifiedFilesCount).ToList();

}

private static bool AllowOnlyFipsAlgorithms()
{
try
{
var property = typeof(CryptoConfig).GetProperty("AllowOnlyFipsAlgorithms", BindingFlags.Public | BindingFlags.Static);
return property != null && (bool)property.GetValue(null, null);
}
catch (Exception)
{
return false;
}
}
}
}

0 comments on commit 5b2f0fb

Please sign in to comment.