Skip to content

Commit 815af56

Browse files
authored
Merge pull request #5746 from wastoresh/FIPSissue
[Storage] Fix MD5 not work on FIPS enabled machine issue
2 parents ef88f7b + f473e81 commit 815af56

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Storage/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Fix the issue that upload Blob and upload File cmdlets fail on FIPS policy enabled machines
22+
- Set-AzureStorageBlobContent
23+
- Set-AzureStorageFileContent
2124
* Updated to the latest version of the Azure ClientRuntime
2225

2326
## Version 4.2.0

src/Storage/Commands.Storage/Blob/Cmdlet/SetAzureStorageBlobContent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@ public override void ExecuteCmdlet()
500500
ValidateBlobProperties(BlobProperties);
501501
}
502502

503+
// if FIPS policy is enabled, must use native MD5
504+
if (fipsEnabled)
505+
{
506+
CloudStorageAccount.UseV1MD5 = false;
507+
}
508+
503509
string containerName = string.Empty;
504510

505511
switch (ParameterSetName)

src/Storage/Commands.Storage/Common/StorageCloudCmdletBase.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,5 +622,23 @@ protected override void StopProcessing()
622622
cancellationTokenSource.Cancel();
623623
base.StopProcessing();
624624
}
625+
626+
/// <summary>
627+
/// true if FIPS policy is enabled on the current machine
628+
/// </summary>
629+
public static bool fipsEnabled { get; } = IsFIPSEnabled();
630+
631+
internal static bool IsFIPSEnabled()
632+
{
633+
try
634+
{
635+
System.Security.Cryptography.MD5.Create();
636+
return false;
637+
}
638+
catch (System.Reflection.TargetInvocationException)
639+
{
640+
return true;
641+
}
642+
}
625643
}
626644
}

src/Storage/Commands.Storage/File/Cmdlet/SetAzureStorageFileContent.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ public override void ExecuteCmdlet()
8080
throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, Resources.SourceFileNotFound, this.Source));
8181
}
8282

83+
// if FIPS policy is enabled, must use native MD5
84+
if (fipsEnabled)
85+
{
86+
CloudStorageAccount.UseV1MD5 = false;
87+
}
88+
8389
bool isDirectory;
8490
string[] path = NamingUtil.ValidatePath(this.Path, out isDirectory);
8591
var cloudFileToBeUploaded =

0 commit comments

Comments
 (0)