Skip to content

Commit 0485080

Browse files
committed
fix MD5 not work on FIPS enabled machine issue
1 parent 3514f55 commit 0485080

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,5 +622,32 @@ 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+
protected static bool FIPSEnabled
630+
{
631+
get
632+
{
633+
if (fIPSEnabled.HasValue)
634+
{
635+
return fIPSEnabled.Value;
636+
}
637+
638+
try
639+
{
640+
System.Security.Cryptography.MD5.Create();
641+
}
642+
catch (System.Reflection.TargetInvocationException)
643+
{
644+
fIPSEnabled = true;
645+
return true;
646+
}
647+
fIPSEnabled = false;
648+
return false;
649+
}
650+
}
651+
private static bool? fIPSEnabled = null;
625652
}
626653
}

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)