mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-22 08:06:55 +00:00
Make key fetching use ostatus fetching.
This commit is contained in:
parent
427bac0966
commit
ba1ea77001
3 changed files with 15 additions and 13 deletions
|
@ -21,24 +21,16 @@ defmodule Pleroma.Web.Salmon do
|
|||
[data, type, encoding, alg, sig]
|
||||
end
|
||||
|
||||
# TODO rewrite in with-stile
|
||||
# Make it fetch the key from the saved user if there is one
|
||||
def fetch_magic_key(salmon) do
|
||||
[data, _, _, _, _] = decode(salmon)
|
||||
doc = XML.parse_document(data)
|
||||
{:xmlObj, :string, uri} = :xmerl_xpath.string('string(//author[1]/uri)', doc)
|
||||
uri = XML.string_from_xpath("/entry/author[1]/uri", doc)
|
||||
|
||||
uri = to_string(uri)
|
||||
base = URI.parse(uri).host
|
||||
{:ok, info} = Pleroma.Web.OStatus.gather_user_info(uri)
|
||||
|
||||
# TODO: Find out if this endpoint is mandated by the standard.
|
||||
# At least diaspora does it differently
|
||||
{:ok, response} = HTTPoison.get(base <> "/.well-known/webfinger", ["Accept": "application/xrd+xml"], [params: [resource: uri]])
|
||||
|
||||
doc = XML.parse_document(response.body)
|
||||
|
||||
{:xmlObj, :string, magickey} = :xmerl_xpath.string('string(//Link[@rel="magic-public-key"]/@href)', doc)
|
||||
"data:application/magic-public-key," <> magickey = to_string(magickey)
|
||||
|
||||
magickey
|
||||
info.magic_key
|
||||
end
|
||||
|
||||
def decode_and_validate(magickey, salmon) do
|
||||
|
|
2
test/fixtures/salmon2.xml
vendored
Normal file
2
test/fixtures/salmon2.xml
vendored
Normal file
File diff suppressed because one or more lines are too long
|
@ -49,4 +49,12 @@ defmodule Pleroma.Web.Salmon.SalmonTest do
|
|||
|
||||
assert doc == decoded_doc
|
||||
end
|
||||
|
||||
test "it gets a magic key" do
|
||||
# TODO: Make test local
|
||||
salmon = File.read!("test/fixtures/salmon2.xml")
|
||||
key = Salmon.fetch_magic_key(salmon)
|
||||
|
||||
assert key == "RSA.uzg6r1peZU0vXGADWxGJ0PE34WvmhjUmydbX5YYdOiXfODVLwCMi1umGoqUDm-mRu4vNEdFBVJU1CpFA7dKzWgIsqsa501i2XqElmEveXRLvNRWFB6nG03Q5OUY2as8eE54BJm0p20GkMfIJGwP6TSFb-ICp3QjzbatuSPJ6xCE=.AQAB"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue