Start of HTTP Signatures.
This commit is contained in:
parent
270c903220
commit
9cefbaf016
4 changed files with 96 additions and 0 deletions
27
lib/pleroma/web/http_signatures/http_signatures.ex
Normal file
27
lib/pleroma/web/http_signatures/http_signatures.ex
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# https://tools.ietf.org/html/draft-cavage-http-signatures-08
|
||||
defmodule Pleroma.Web.HTTPSignatures do
|
||||
def split_signature(sig) do
|
||||
default = %{"headers" => ["date"]}
|
||||
|
||||
sig
|
||||
|> String.trim()
|
||||
|> String.split(",")
|
||||
|> Enum.reduce(default, fn(part, acc) ->
|
||||
[key | rest] = String.split(part, "=")
|
||||
value = Enum.join(rest, "=")
|
||||
Map.put(acc, key, String.trim(value, "\""))
|
||||
end)
|
||||
end
|
||||
|
||||
def validate(headers, signature, public_key) do
|
||||
sigstring = build_signing_string(headers, signature["headers"])
|
||||
{:ok, sig} = Base.decode64(signature["signature"])
|
||||
verify = :public_key.verify(sigstring, :sha256, sig, public_key)
|
||||
end
|
||||
|
||||
def build_signing_string(headers, used_headers) do
|
||||
used_headers
|
||||
|> Enum.map(fn (header) -> "#{header}: #{headers[header]}" end)
|
||||
|> Enum.join("\n")
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue