Skip to content

[Storage] Fix MD5 not work on FIPS enabled machine issue #5746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Storage/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
- Additional information about change #1
-->
## Current Release
* Fix the issue that upload Blob and upload File cmdlets fail on FIPS policy enabled machines
- Set-AzureStorageBlobContent
- Set-AzureStorageFileContent
* Updated to the latest version of the Azure ClientRuntime

## Version 4.2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ public override void ExecuteCmdlet()
ValidateBlobProperties(BlobProperties);
}

// if FIPS policy is enabled, must use native MD5
if (fipsEnabled)
{
CloudStorageAccount.UseV1MD5 = false;
}

string containerName = string.Empty;

switch (ParameterSetName)
Expand Down
18 changes: 18 additions & 0 deletions src/Storage/Commands.Storage/Common/StorageCloudCmdletBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -622,5 +622,23 @@ protected override void StopProcessing()
cancellationTokenSource.Cancel();
base.StopProcessing();
}

/// <summary>
/// true if FIPS policy is enabled on the current machine
/// </summary>
public static bool fipsEnabled { get; } = IsFIPSEnabled();

internal static bool IsFIPSEnabled()
{
try
{
System.Security.Cryptography.MD5.Create();
return false;
}
catch (System.Reflection.TargetInvocationException)
{
return true;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public override void ExecuteCmdlet()
throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.Source));
}

// if FIPS policy is enabled, must use native MD5
if (fipsEnabled)
{
CloudStorageAccount.UseV1MD5 = false;
}

bool isDirectory;
string[] path = NamingUtil.ValidatePath(this.Path, out isDirectory);
var cloudFileToBeUploaded =
Expand Down