Skip to content

Commit

Permalink
(GH-36) check for official public key
Browse files Browse the repository at this point in the history
When choco.exe detects that it is not using the official
publickeytoken, throw an error requiring an explicit override (this is
already overridden in debug builds). When AllowUnofficialBuild flag is
set to true, log a very important warning so that folks can receive
clues that the state of their system may be compromised.
  • Loading branch information
ferventcoder committed Jan 25, 2015
1 parent 8e97e3f commit a3158ec
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ namespace chocolatey.infrastructure.app.runners
using System;
using System.Linq;
using SimpleInjector;
using adapters;
using attributes;
using configuration;
using infrastructure.commands;
using logging;
using Console = System.Console;
using Environment = System.Environment;

public sealed class GenericRunner
{
Expand Down Expand Up @@ -62,6 +66,28 @@ public void run(ChocolateyConfiguration config, Container container, bool isCons
Environment.Exit(1);
}

var token = Assembly.GetExecutingAssembly().get_public_key_token();
if (string.IsNullOrWhiteSpace(token) || token != ApplicationParameters.OfficialChocolateyPublicKey)
{
if (!config.AllowUnofficialBuild)
{
throw new Exception(@"
Custom unofficial builds are not allowed by default.
To override this behavior, explicitly set --allow-unofficial.
See the help menu (choco -h) for options.");
}
else
{
this.Log().Warn(ChocolateyLoggers.Important, @"
choco.exe is not an official build (bypassed with --allow-unofficial).
If you are seeing this message and it is not expected, your system may
now be in a bad state. Only official builds are to be trusted.
"
);

}
}

if (config.Noop)
{
if (config.RegularOuptut)
Expand Down

0 comments on commit a3158ec

Please sign in to comment.