Merge remote-tracking branch 'remotes/origin/develop' into auth-improvements
This commit is contained in:
commit
50e47a215f
6 changed files with 68 additions and 21 deletions
|
|
@ -22,8 +22,8 @@ defmodule Mix.Pleroma do
|
|||
Pleroma.Application.limiters_setup()
|
||||
Application.put_env(:phoenix, :serve_endpoints, false, persistent: true)
|
||||
|
||||
if Pleroma.Config.get(:env) != :test do
|
||||
Application.put_env(:logger, :console, level: :debug)
|
||||
unless System.get_env("DEBUG") do
|
||||
Logger.remove_backend(:console)
|
||||
end
|
||||
|
||||
adapter = Application.get_env(:tesla, :adapter)
|
||||
|
|
|
|||
|
|
@ -7,8 +7,22 @@ defmodule Pleroma.Web.Plugs.DigestPlug do
|
|||
require Logger
|
||||
|
||||
def read_body(conn, opts) do
|
||||
digest_algorithm =
|
||||
with [digest_header] <- Conn.get_req_header(conn, "digest") do
|
||||
digest_header
|
||||
|> String.split("=", parts: 2)
|
||||
|> List.first()
|
||||
else
|
||||
_ -> "SHA-256"
|
||||
end
|
||||
|
||||
unless String.downcase(digest_algorithm) == "sha-256" do
|
||||
raise ArgumentError,
|
||||
message: "invalid value for digest algorithm, got: #{digest_algorithm}"
|
||||
end
|
||||
|
||||
{:ok, body, conn} = Conn.read_body(conn, opts)
|
||||
digest = "SHA-256=" <> (:crypto.hash(:sha256, body) |> Base.encode64())
|
||||
{:ok, body, Conn.assign(conn, :digest, digest)}
|
||||
encoded_digest = :crypto.hash(:sha256, body) |> Base.encode64()
|
||||
{:ok, body, Conn.assign(conn, :digest, "#{digest_algorithm}=#{encoded_digest}")}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue