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
1 parent
e98e165
commit 48cd1f1
Showing
18 changed files
with
195 additions
and
126 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
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,3 +1,5 @@ | ||
defmodule Blacksmith.Repo do | ||
use Ecto.Repo, otp_app: :blacksmith | ||
use Ecto.Repo, | ||
otp_app: :blacksmith, | ||
adapter: Ecto.Adapters.Postgres | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
defmodule HTTP.SignatureAuth do | ||
defmodule UnauthorizedError do | ||
@moduledoc """ | ||
Error raised when a signature is invalid | ||
""" | ||
|
||
defexception message: "Invaild Signature", plug_status: 401 | ||
end | ||
|
||
def verify_block_signature(conn) do | ||
public_key = conn.params.sender | ||
signature = get_signature(conn) | ||
body = Enum.fetch!(conn.assigns.raw_body, 0) | ||
|
||
if Crypto.valid_signature_ed25519?( | ||
signature, | ||
body, | ||
public_key | ||
) do | ||
conn | ||
else | ||
throw(UnauthorizedError) | ||
end | ||
end | ||
|
||
def verify_ed25519_signature(conn) do | ||
public_key = conn.params.sender | ||
signature = get_signature(conn) | ||
body = Enum.fetch!(conn.assigns.raw_body, 0) | ||
|
||
if Crypto.valid_signature_ed25519?( | ||
signature, | ||
body, | ||
public_key | ||
) do | ||
conn | ||
else | ||
throw(UnauthorizedError) | ||
end | ||
end | ||
|
||
defp get_signature(conn) do | ||
[authorization] = Plug.Conn.get_req_header(conn, "authorization") | ||
|
||
[ | ||
"Signature", | ||
signature_hex | ||
] = String.split(authorization, " ") | ||
|
||
Base.decode16!(signature_hex, case: :lower) | ||
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 was deleted.
Oops, something went wrong.
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
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.