Skip to content

XAML code always generates SHA1 checksums in binaries even when csproj file says SHA256 #7348

Closed

Description

@swenkeratmicrosoft
  • .NET Core Version: (e.g. 3.0 Preview1, or daily build number, use dotnet --info)
  • Windows version: (winver)

The following link has all the information about what's installed on the machine.
https://github.com/actions/runner-images/blob/main/images/win/Windows2022-Readme.md

  • Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes/No

Unknown

  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc...)? If yes, please file the issue via the instructions here.

No.

Problem description:

I'm compiling C# code with msbuild. The .csproj file has:
ChecksumAlgorithm SHA256 /ChecksumAlgorithm

Running ildasm on the binary, the manifest shows that the hash is still SHA1 via this line:
.hash algorithm 0x00008004

The csc.exe compiler team (Tomas Matousek) has also confirmed that SHA1 is being used for the XAML c# code.

This bug does not repro on projects without XAML.

I'm also a Microsoft FTE so you can contact me directly if you need anything MS-internal.

Actual behavior:

Binary checksum is SHA1.

Expected behavior:

Binary checksum should be SHA256 as requested by .csproj file.

Minimal repro:

The attached repro includes the entire project folder post-build. It thus includes the full -bl ".binlog" file, the source code including auto-generated XAML source, and the final DLL and symbols. The only thing it excludes are the dependency dlls that were not compiled by my project but were instead auto-added by the build, e.g. api-ms-win-core..., PresentationFramework..., etc. (Removing these was required to bring the zip file down to below 25 MB.)

hwdrmdisabler_all_shrunk.zip

Activity

  1. changed the title [-]XAML code always generates SHA1 hashed binaries even when csproj file says SHA256[/-] [+]XAML code always generates SHA1 checksums in binaries even when csproj file says SHA256[/+] on Dec 7, 2022
  2. added
    Investigate
    and removed on Dec 9, 2022
  3. swenkeratmicrosoft commented on Feb 7, 2023

    @swenkeratmicrosoft
    Author

    @singhashish-wpf - Is there a timeline on which someone will look at this? Our customers are demanding SHA256 checksums and we can't fulfill their request because of this bug.

  4. singhashish-wpf commented on Feb 15, 2023

    @singhashish-wpf
    Contributor

    @swenkeratmicrosoft Thanks for the issue. I did check the binlog you provided. The csc task is receiving the value for checksumalgorithm correctly as SHA256 and there also isn't any deviation to SHA1.
    @tmat Can you provide more details in here like do we need to modify at some place before calling the csc task with the proper parameter value for checksumalgorithm?

  5. tmat commented on Feb 15, 2023

    @tmat
    Member

    The SHA1 hash is written to the generated file obj\Release\net6.0-windows\win-x64\MainWindow.g.cs by XAML compiler:

    #pragma checksum "..\..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "00D38EA04A7DE07A83BC24879A0EDA49FFC0929E"
    
  6. ThomasGoulet73 commented on Feb 16, 2023

    @ThomasGoulet73
    Contributor

    I have local changes to change the "#pragma checksum" in the generated code according to the current ChecksumAlgorithm of the project.

    But I'm not able to reproduce how the manifest should look like (Line .hash algorithm 0x00008004 should change) in a non-WPF project. If I create a new C# Console project, add <ChecksumAlgorithm>SHA256</ChecksumAlgorithm> to the .csproj, build the project and ildasm the output assembly, the line .hash algorithm 0x00008004 never changes.
    @tmat Do you have some pointers on what I should do to be able to see the line .hash algorithm 0x00008004 change ?

  7. swenkeratmicrosoft commented on Feb 16, 2023

    @swenkeratmicrosoft
    Author

    In case it helps, you should first confirm that the .csproj file is using the following XML. If it is, I defer to @tmat.

    (Edited several times because I forgot how to insert a code block inn a github comment.)

    <Project ...> ... <PropertyGroup Label="Configuration"> <ChecksumAlgorithm>SHA256</ChecksumAlgorithm> </PropertyGroup> ... </Project>

  8. tmat commented on Feb 16, 2023

    @tmat
    Member

    You can ignore the value of .hash algorithm. It specifies a different hash, which is always SHA1. See ECMA-335 specification, paragraph II.6.2.1.1.

    The source document hash algorithm that #pragma checksum specifies is written to the PDB. You can use a tool like pdb2xml to display the content of the PDB file.

  9. added a commit that references this issue on Feb 21, 2023
    ffeba2b
  10. added a commit that references this issue on Mar 20, 2023
    3862454
  11. ghost locked as resolved and limited conversation to collaborators on Apr 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Investigate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions