aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2020-11-28 21:51:27 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2020-11-28 21:51:27 +0300
commit50e47a215f9c473a308ba7e9ddea5e33099c5a9d (patch)
treec3d0aa424db970f3e7e5c2e911984dad46894896 /lib
parentf1b07a2b2b6439579f0a35694f693712fb5ec5f4 (diff)
parent5a5ff508aa47d5cf64f7be5938a9561e856854dd (diff)
downloadpleroma-50e47a215f9c473a308ba7e9ddea5e33099c5a9d.tar.gz
Merge remote-tracking branch 'remotes/origin/develop' into auth-improvements
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/pleroma.ex4
-rw-r--r--lib/pleroma/web/plugs/digest_plug.ex18
2 files changed, 18 insertions, 4 deletions
diff --git a/lib/mix/pleroma.ex b/lib/mix/pleroma.ex
index 6df1cf538..cd3f44074 100644
--- a/lib/mix/pleroma.ex
+++ b/lib/mix/pleroma.ex
@@ -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)
diff --git a/lib/pleroma/web/plugs/digest_plug.ex b/lib/pleroma/web/plugs/digest_plug.ex
index b521b3073..fb2723b97 100644
--- a/lib/pleroma/web/plugs/digest_plug.ex
+++ b/lib/pleroma/web/plugs/digest_plug.ex
@@ -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