Skip to content

Commit

Permalink
fetchurl: only allow empty hash when cacert is available
Browse files Browse the repository at this point in the history
We can use cacert to validate that the data passes SSL certificates.
Normally, this doesn’t happen because we already have the hash, but in
the hash = "" case we don’t.
  • Loading branch information
matthewbauer committed Jun 9, 2020
1 parent a528cc1 commit 0046802
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkgs/build-support/fetchurl/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ curl=(
--retry 3
--disable-epsv
--cookie-jar cookies
--insecure
--user-agent "curl/$curlVersion Nixpkgs/$nixpkgsVersion"
)

if ! [ -f "$SSL_CERT_FILE" ]; then
curl+=(--insecure)
fi

curl+=(
$curlOpts
$NIX_CURL_FLAGS
)
Expand Down
11 changes: 9 additions & 2 deletions pkgs/build-support/fetchurl/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ lib, buildPackages ? { inherit stdenvNoCC; }, stdenvNoCC, curl }: # Note that `curl' may be `null', in case of the native stdenvNoCC.
{ lib, buildPackages ? { inherit stdenvNoCC; }, stdenvNoCC
, curl # Note that `curl' may be `null', in case of the native stdenvNoCC.
, cacert ? null }:

let

Expand Down Expand Up @@ -112,7 +114,8 @@ let
else if sha512 != "" then { outputHashAlgo = "sha512"; outputHash = sha512; }
else if sha256 != "" then { outputHashAlgo = "sha256"; outputHash = sha256; }
else if sha1 != "" then { outputHashAlgo = "sha1"; outputHash = sha1; }
else { outputHashAlgo = "sha256"; outputHash = ""; };
else if cacert != null then { outputHashAlgo = "sha256"; outputHash = ""; }
else throw "fetchurl requires a hash for fixed-output derivation: ${lib.concatStringsSep ", " urls_}";
in

stdenvNoCC.mkDerivation {
Expand All @@ -134,6 +137,10 @@ stdenvNoCC.mkDerivation {
# New-style output content requirements.
inherit (hash_) outputHashAlgo outputHash;

SSL_CERT_FILE = if hash_.outputHash == ""
then "${cacert}/etc/ssl/certs/ca-bundle.crt"
else "/no-cert-file.crt";

outputHashMode = if (recursiveHash || executable) then "recursive" else "flat";

inherit curlOpts showURLs mirrorsFile postFetch downloadToTemp executable;
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ in
then buildPackages.fetchurl # No need to do special overrides twice,
else makeOverridable (import ../build-support/fetchurl) {
inherit lib stdenvNoCC buildPackages;
inherit cacert;
curl = buildPackages.curl.override (old: rec {
# break dependency cycles
fetchurl = stdenv.fetchurlBoot;
Expand Down

0 comments on commit 0046802

Please sign in to comment.