forked from hexpm/hex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
48 changed files
with
1,845 additions
and
891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/_build | ||
/deps | ||
/tmp | ||
/src/safe_erl_term.erl | ||
erl_crash.dump | ||
*.ez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,49 @@ | ||
defmodule Hex.API.Registry do | ||
alias Hex.API | ||
alias Hex.Crypto.PublicKey | ||
|
||
def get(opts \\ []) do | ||
@default_repo "https://repo.hex.pm" | ||
@public_keys_html "https://hex.pm/docs/public_keys" | ||
|
||
def get_package(name, opts \\ []) do | ||
headers = | ||
if etag = opts[:etag] do | ||
%{'if-none-match' => '"' ++ etag ++ '"'} | ||
%{'if-none-match' => etag} | ||
end | ||
|
||
API.request(:get, API.repo_url("registry.ets.gz"), headers || []) | ||
API.request(:get, API.repo_url("packages/#{name}"), headers || []) | ||
end | ||
|
||
def verify(body) do | ||
%{signature: signature, payload: payload} = :hex_pb_signed.decode_msg(body, :Signed) | ||
if Hex.State.fetch!(:check_registry?) do | ||
do_verify(payload, signature) | ||
end | ||
payload | ||
end | ||
|
||
defp do_verify(payload, signature) do | ||
repo = Hex.State.fetch!(:repo) || @default_repo | ||
key = PublicKey.public_key(repo) | ||
|
||
unless key do | ||
Mix.raise "No public key stored for #{repo}. Either install a public " <> | ||
"key with `mix hex.public_keys` or disable the registry " <> | ||
"verification check by setting `HEX_UNSAFE_REGISTRY=1`." | ||
end | ||
|
||
unless Hex.Crypto.PublicKey.verify(payload, :sha512, signature, [key]) do | ||
Mix.raise "Could not verify authenticity of fetched registry file. " <> | ||
"This may happen because a proxy or some entity is " <> | ||
"interfering with the download or because you don't have a " <> | ||
"public key to verify the registry.\n\nYou may try again " <> | ||
"later or check if a new public key has been released on " <> | ||
"our public keys page: #{@public_keys_html}" | ||
end | ||
end | ||
|
||
def get_signature() do | ||
API.request(:get, API.repo_url("registry.ets.gz.signed"), []) | ||
def decode(body) do | ||
%{releases: releases} = :hex_pb_package.decode_msg(body, :Package) | ||
releases | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.