Skip to content

Commit

Permalink
Merged PR 32017: [7.0] Fix regression loading null-password encrypted…
Browse files Browse the repository at this point in the history
… PFX certificates

When decrypting the payload with empty string and null passwords, try reading the payload with the Asn reader to ensure the header matches the expected format. If that succeeds, then proceed with the iteration counting. This guards against a false-positive match that previously caused our iteration count work to throw/abort, thus preventing some null-password encrypted payloads from being loaded.
  • Loading branch information
jeffhand authored and mmitche committed Jun 18, 2023
1 parent d9294c8 commit 4b05509
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Expand Up @@ -249,6 +249,12 @@ private static ArraySegment<byte> DecryptContentInfo(ContentInfoAsn contentInfo,
default,
encryptedData.EncryptedContentInfo.EncryptedContent.Value.Span,
destination);

// When padding happens to be as expected (false-positive), we can detect gibberish and prevent unexpected failures later
// This extra check makes it so it's very unlikely we'll end up with false positive.
AsnValueReader outerSafeBag = new AsnValueReader(destination.AsSpan(0, written), AsnEncodingRules.BER);
AsnValueReader safeBagReader = outerSafeBag.ReadSequence();
outerSafeBag.ThrowIfNotEmpty();
}
catch
{
Expand All @@ -259,6 +265,12 @@ private static ArraySegment<byte> DecryptContentInfo(ContentInfoAsn contentInfo,
default,
encryptedData.EncryptedContentInfo.EncryptedContent.Value.Span,
destination);

// When padding happens to be as expected (false-positive), we can detect gibberish and prevent unexpected failures later
// This extra check makes it so it's very unlikely we'll end up with false positive.
AsnValueReader outerSafeBag = new AsnValueReader(destination.AsSpan(0, written), AsnEncodingRules.BER);
AsnValueReader safeBagReader = outerSafeBag.ReadSequence();
outerSafeBag.ThrowIfNotEmpty();
}
}
finally
Expand Down
Expand Up @@ -5,8 +5,8 @@
<!-- Reference the outputs for the dependency nodes calculation. -->
<NoTargetsDoNotReferenceOutputAssemblies>false</NoTargetsDoNotReferenceOutputAssemblies>
<IsPackable>true</IsPackable>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ServicingVersion>3</ServicingVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ServicingVersion>4</ServicingVersion>
<!-- This is a meta package and doesn't contain any libs. -->
<NoWarn>$(NoWarn);NU5128</NoWarn>
<PackageDescription>This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard.</PackageDescription>
Expand Down
Expand Up @@ -7,8 +7,8 @@
<NoWarn>$(NoWarn);CA5384</NoWarn>
<IsPackable>true</IsPackable>
<!-- If you enable GeneratePackageOnBuild for this package and bump ServicingVersion, make sure to also bump ServicingVersion in Microsoft.Windows.Compatibility.csproj once for the next release. -->
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<ServicingVersion>2</ServicingVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<ServicingVersion>3</ServicingVersion>
<PackageDescription>Provides support for PKCS and CMS algorithms.

Commonly Used Types:
Expand Down

0 comments on commit 4b05509

Please sign in to comment.