Skip to content
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

Verify the checksum of a package before installation, and fail if not matched #1144

Closed
donbecker opened this issue Jan 19, 2017 · 15 comments · Fixed by #3269
Closed

Verify the checksum of a package before installation, and fail if not matched #1144

donbecker opened this issue Jan 19, 2017 · 15 comments · Fixed by #3269
Assignees
Labels
5 - Released Has related issue This issue has a related issue that would need to be addressed before this issue could be closed. Improvement Security
Milestone

Comments

@donbecker
Copy link

What You Are Seeing?

The checksum options in "choco install" validate checksums of external package dependencies downloaded from the internet.

While this can ensure content of the external dependency, it does not ensure content of the package and it's files/content (and therefore does not ensure content of repackaged packages with all included dependencies).

What is Expected?

Suggest new options "packagechecksum" and "packagechecksumType" to validate the checksum of the entire nupkg file after chocolatey downloads it. Suggest supporting all checksum types supported by present external checksum types (md5, sha1, etc etc).

cinst chefdk --version 1.1.16 -y -packagechecksum 'ca1cbfe819128dbd252d53f31e3cfae7' -packagechecksumType 'md5'

I searched quite a bit to determine if this was possible in present functionality. Apologies in advance if I've missed something.

@ferventcoder
Copy link
Member

It already does this.

@ferventcoder
Copy link
Member

But I get what you mean. Ensuring that the package coming down has an external verification that you can run client side. I like it.

@ferventcoder
Copy link
Member

Suggest new options "packagechecksum" and "packagechecksumType" to validate the checksum of the entire nupkg file after chocolatey downloads it. Suggest supporting all checksum types supported by present external checksum types (md5, sha1, etc etc).

You wouldn't need to specify the type. That is determinable based on the value passed through and it's length.

@ferventcoder
Copy link
Member

It already does this.

Sorry, what I meant there is that NuGet.Core already gets an expected package checksum and then verifies it received that same size automatically.

Which isn't the same as this request.

@ferventcoder ferventcoder modified the milestones: 0.10.x, 0.10.4 Mar 23, 2017
@ferventcoder
Copy link
Member

@donbecker Recently I reviewed how packagehash was being used locally, and it doesn't appear that is it being used for verifying what was received was what was thought to be received (instead it appears to be only used for checking that a cached version of the package is the same as the remote to choose to redownload the file or not). I think this issue stands then as something that should be addressed.

@ferventcoder ferventcoder modified the milestones: 0.10.x, 0.10.13 Jan 17, 2019
@ferventcoder
Copy link
Member

This could play right into authenticode signatures we are looking at implementing as well.

@donbecker
Copy link
Author

@ferventcoder Sounds great. I still think this would be a great feature for Chocolatey to have regarding integrity of packages.

@ferventcoder ferventcoder modified the milestones: 0.10.13, 0.10.14 Mar 15, 2019
@ferventcoder ferventcoder modified the milestones: 0.10.14, 0.10.15 Apr 1, 2019
@gep13 gep13 modified the milestones: 0.10.15, 0.10.16 May 31, 2019
@pauby pauby modified the milestones: 0.10.16, 0.10.x May 11, 2021
@TheCakeIsNaOH
Copy link
Member

After the nuget library uplift, this should be able to be implemented for free as a side effect of implementing validating code signatures on packages, #504

@TheCakeIsNaOH
Copy link
Member

After previous discussion with @gep13, this issue depends on #508, as code signing has been added to newer nuget versions.

TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Jan 10, 2024
This adds a check to both install and upgrade to validate that the
downloaded .nupkg file has the same hash as the source metadata.
The check is conducted before the package is installed. If the
source does not provide a sha512 checksum or if
usePackageHashValidation is disabled, then the check is skipped.

Only sha512 is supported because it is the only provided package
hash type after download. The provided hash is used because it
accounts for package signing correctly.
@miketheitguy
Copy link

miketheitguy commented Apr 25, 2024

I'd like to add on to the OP's comments here. There is a valid use case for this even with internal repositories. Particularly when you have systems that span trust boundaries (where you have some environments with higher or lower classification levels) and you don't want to duplicate infrastructure throughout each environment.

In @TheCakeIsNaOH 's comments, you should "trust the infrastructure"--that's not entirely something that is true. Supply chain compromise, even internally, can be a risk in highly secure environments. Utilizing package checksums on the package download provides a really simple way for a critical system to trust packages retrieved from a system seen as less critical, often times because it could be run by an entirely different org within your company.

I could, for example, deploy execution commands on more secure systems that downloads packages from say, a company's singular internal repository for all things repo downloads (think: Artifactory) while simultaneously guaranteeing, that no matter what, under any circumstance, under any compromise of that system, that my higher privileged environments won't execute code from a malicious package by simply providing a command line hash validation argument on the entire nupkg.

Now, an attacker would have to both compromise the target system to modify the integrity check while simultaneously modifying the package--which renders utilizing the package as a privilege escalation or lateral movement scheme pretty much entirely invalid.

There are compensating capabilities here that exist today in Windows--and that's using Windows Defender Application Control to validate code signatures of PowerShell scripts as well as binaries executing on the target system. While this is inarguably the more secure solution, with policies capable of being protected by the TPM and UEFI NVRAM and Hypervisor separation, it's a lot of work to get that capability going on a Windows platform and would require signing all individual scripts and package files (if you don't trust existing authenticode signatures by 3rd party providers).

Implementing such a check in Chocolatey would provide a much lower barrier to entry for simple package validation rather than manually verifying the package prior to execution.

As far as dependency management goes, I think this should absolutely be an opt-in feature, and I don't see anything wrong with providing an option for the end user to checksum all of the dependencies either.

I think it's valid to say that if you can't include a checksum of each dependency in the nuspec file, then instruct the user when the command line argument is added that they must first install the dependencies (no automatic download). In this manner, it's up to the user whether they want to checksum the dependencies or not. My expectation is that users of course would.

gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 26, 2024
This feature is used to control if the checksum of the downloaded
.nupkg is checked against the checksum provided by the package
source. It is disabled by default, as it unknown if it works
correctly with all major NuGet v2 implementations.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 26, 2024
This class provides a method to convert base64 hashes into hex form,
returning the input if it is already in hex. It also returns the type
of the hash. Both are based on the length of the input hash. Sha1,
Sha256 and Sha512 are supported.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 26, 2024
This adds a check to both install and upgrade to validate that the
downloaded .nupkg file has the same hash as the source metadata.
The check is conducted before the package is installed. If the
source does not provide a sha512 checksum or if
usePackageHashValidation is disabled, then the check is skipped.

Only sha512 is supported because it is the only provided package
hash type after download. The provided hash is used because it
accounts for package signing correctly.
TheCakeIsNaOH added a commit to TheCakeIsNaOH/choco that referenced this issue Apr 28, 2024
This adds a check to both install and upgrade to validate that the
downloaded .nupkg file has the same hash as the source metadata.
The check is conducted before the package is installed. If the
source does not provide a sha512 checksum or if
usePackageHashValidation is disabled, then the check is skipped.

Only sha512 is supported because it is the only provided package
hash type after download. The provided hash is used because it
accounts for package signing correctly.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 30, 2024
This feature is used to control if the checksum of the downloaded
.nupkg is checked against the checksum provided by the package
source. It is disabled by default, as it unknown if it works
correctly with all major NuGet v2 implementations.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 30, 2024
This class provides a method to convert base64 hashes into hex form,
returning the input if it is already in hex. It also returns the type
of the hash. Both are based on the length of the input hash. Sha1,
Sha256 and Sha512 are supported.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 30, 2024
This adds a check to both install and upgrade to validate that the
downloaded .nupkg file has the same hash as the source metadata.
The check is conducted before the package is installed. If the
source does not provide a sha512 checksum or if
usePackageHashValidation is disabled, then the check is skipped.

Only sha512 is supported because it is the only provided package
hash type after download. The provided hash is used because it
accounts for package signing correctly.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 30, 2024
This feature is used to control if the checksum of the downloaded
.nupkg is checked against the checksum provided by the package
source. It is disabled by default, as it unknown if it works
correctly with all major NuGet v2 implementations.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 30, 2024
This class provides a method to convert base64 hashes into hex form,
returning the input if it is already in hex. It also returns the type
of the hash. Both are based on the length of the input hash. Sha1,
Sha256 and Sha512 are supported.
gep13 pushed a commit to TheCakeIsNaOH/choco that referenced this issue Apr 30, 2024
This adds a check to both install and upgrade to validate that the
downloaded .nupkg file has the same hash as the source metadata.
The check is conducted before the package is installed. If the
source does not provide a sha512 checksum or if
usePackageHashValidation is disabled, then the check is skipped.

Only sha512 is supported because it is the only provided package
hash type after download. The provided hash is used because it
accounts for package signing correctly.
gep13 added a commit that referenced this issue Apr 30, 2024
@gep13 gep13 modified the milestones: Future, 2.3.0 Apr 30, 2024
gep13 added a commit to gep13/choco that referenced this issue May 24, 2024
In the next release, when possible, Chocolatey CLI will now include
package hash validation to ensure that the package being installed is
the one that the server thinks it is. This is a feature flag that needs
to be toggled on.

This commit adds tests to cover that hash validation is being attempted
when it can be.
@gep13 gep13 changed the title Feature Request: choco install: verify checksum of entire package (not installer) Verify checksum of package (.nupkg file) prior to installation and fail if not matched May 24, 2024
corbob pushed a commit to gep13/choco that referenced this issue May 27, 2024
In the next release, when possible, Chocolatey CLI will now include
package hash validation to ensure that the package being installed is
the one that the server thinks it is. This is a feature flag that needs
to be toggled on.

This commit adds tests to cover that hash validation is being attempted
when it can be.
gep13 added a commit to gep13/choco that referenced this issue May 28, 2024
In the next release, when possible, Chocolatey CLI will now include
package hash validation to ensure that the package being installed is
the one that the server thinks it is. This is a feature flag that needs
to be toggled on.

This commit adds tests to cover that hash validation is being attempted
when it can be.
@pauby pauby changed the title Verify checksum of package (.nupkg file) prior to installation and fail if not matched Verify the checksum of a package before installation, and fail if not matched May 28, 2024
vexx32 pushed a commit to gep13/choco that referenced this issue May 30, 2024
In the next release, when possible, Chocolatey CLI will now include
package hash validation to ensure that the package being installed is
the one that the server thinks it is. This is a feature flag that needs
to be toggled on.

This commit adds tests to cover that hash validation is being attempted
when it can be.
gep13 added a commit to gep13/choco that referenced this issue May 30, 2024
In the next release, when possible, Chocolatey CLI will now include
package hash validation to ensure that the package being installed is
the one that the server thinks it is. This is a feature flag that needs
to be toggled on.

This commit adds tests to cover that hash validation is being attempted
when it can be.
gep13 added a commit that referenced this issue Jun 5, 2024
* release/2.3.0: (153 commits)
  (#23) Move call to SetRemotePackageNamesIfAllSpecified
  (#1901) Revert commit to display location
  (maint) Update Authenticode Signature
  (tests) Some minor tweaks for test consistency
  (#310) Set-EnvironmentVariable: delete values properly
  (tests) Remove v2 import tests
  (#310) Fix test issues
  (#310) Fixup v2 compatibility
  (tests) Working on tests during pairing session
  (#2050) Add Pester test for --ignore-pinned option
  (#3381) Add Pester tests for rule command
  (#1144) Add Pester test to cover hash validation
  (#72) Add Pester tests to cover new functionality
  (test) Update assertions for push commands
  (#1310) Add Pester test to validate output
  (#23) Add tests to handle install all
  (#2200) Add test for new enhanced exit code
  (#1764) Add test for new enhanced exit code
  (#1760) Add test for new enhanced exit code
  (#1759) Add test for new enhanced exit code
  ...
@choco-bot
Copy link

🎉 This issue has been resolved in version 2.3.0 🎉

The release is available on:

Your GitReleaseManager bot 📦 🚀

gep13 added a commit that referenced this issue Jun 5, 2024
* master: (37 commits)
  (#310) Fix path to chocolatey.lib files
  (maint) Corrected casing of file
  (#23) Move call to SetRemotePackageNamesIfAllSpecified
  (#1901) Revert commit to display location
  (maint) Update Authenticode Signature
  (tests) Some minor tweaks for test consistency
  (#310) Set-EnvironmentVariable: delete values properly
  (tests) Remove v2 import tests
  (#310) Fix test issues
  (#310) Fixup v2 compatibility
  (tests) Working on tests during pairing session
  (#2050) Add Pester test for --ignore-pinned option
  (#3381) Add Pester tests for rule command
  (#1144) Add Pester test to cover hash validation
  (#72) Add Pester tests to cover new functionality
  (test) Update assertions for push commands
  (#1310) Add Pester test to validate output
  (#23) Add tests to handle install all
  (#2200) Add test for new enhanced exit code
  (#1764) Add test for new enhanced exit code
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5 - Released Has related issue This issue has a related issue that would need to be addressed before this issue could be closed. Improvement Security
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants