use webfinger xml generator
- fix: encode rsa key with base64
This commit is contained in:
parent
5792afb427
commit
2bcf877b5c
7 changed files with 44 additions and 56 deletions
|
|
@ -23,12 +23,12 @@ module DiasporaFederation
|
||||||
#
|
#
|
||||||
# GET /webfinger?q=<uri>
|
# GET /webfinger?q=<uri>
|
||||||
def legacy_webfinger
|
def legacy_webfinger
|
||||||
@person = find_person(params[:q]) if params[:q]
|
person = find_person(params[:q]) if params[:q]
|
||||||
|
|
||||||
return render nothing: true, status: 404 if @person.nil?
|
return render nothing: true, status: 404 if person.nil?
|
||||||
|
|
||||||
logger.info "webfinger profile request for: #{@person.diaspora_handle}"
|
logger.info "webfinger profile request for: #{person.diaspora_handle}"
|
||||||
render "webfinger", content_type: "application/xrd+xml"
|
render body: WebFinger::WebFinger.from_person(person.webfinger_hash).to_xml, content_type: "application/xrd+xml"
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -1,14 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
|
||||||
<Subject>acct:<%=@person.diaspora_handle%></Subject>
|
|
||||||
<Alias>"<%= @person.url %>"</Alias>
|
|
||||||
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="<%=@person.hcard_url%>"/>
|
|
||||||
<Link rel="http://joindiaspora.com/seed_location" type="text/html" href="<%=@person.url%>"/>
|
|
||||||
<Link rel="http://joindiaspora.com/guid" type="text/html" href="<%=@person.guid%>"/>
|
|
||||||
|
|
||||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="<%=@person.profile_url%>"/>
|
|
||||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="<%=@person.atom_url%>"/>
|
|
||||||
<Link rel="salmon" href="<%=@person.salmon_url%>"/>
|
|
||||||
|
|
||||||
<Link rel="diaspora-public-key" type="RSA" href="<%=Base64.strict_encode64(@person.serialized_public_key)%>"/>
|
|
||||||
</XRD>
|
|
||||||
|
|
@ -46,14 +46,7 @@ module DiasporaFederation
|
||||||
raise ConfigurationError, "missing server_uri" unless @server_uri.respond_to? :host
|
raise ConfigurationError, "missing server_uri" unless @server_uri.respond_to? :host
|
||||||
validate_class(@person_class, "person_class", %i(
|
validate_class(@person_class, "person_class", %i(
|
||||||
find_local_by_diaspora_handle
|
find_local_by_diaspora_handle
|
||||||
guid
|
webfinger_hash
|
||||||
url
|
|
||||||
diaspora_handle
|
|
||||||
serialized_public_key
|
|
||||||
salmon_url
|
|
||||||
atom_url
|
|
||||||
profile_url
|
|
||||||
hcard_url
|
|
||||||
))
|
))
|
||||||
logger.info "successfully configured the federation engine"
|
logger.info "successfully configured the federation engine"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ module DiasporaFederation
|
||||||
# serve as a base for all future changes of this implementation.
|
# serve as a base for all future changes of this implementation.
|
||||||
#
|
#
|
||||||
# @example Creating a WebFinger document from account data
|
# @example Creating a WebFinger document from account data
|
||||||
# wf = WebFinger.from_account({
|
# wf = WebFinger.from_person({
|
||||||
# acct_uri: "acct:user@server.example",
|
# acct_uri: "acct:user@server.example",
|
||||||
# alias_url: "https://server.example/people/0123456789abcdef",
|
# alias_url: "https://server.example/people/0123456789abcdef",
|
||||||
# hcard_url: "https://server.example/hcard/users/user",
|
# hcard_url: "https://server.example/hcard/users/user",
|
||||||
|
|
@ -19,7 +19,7 @@ module DiasporaFederation
|
||||||
# atom_url: "https://server.example/public/user.atom",
|
# atom_url: "https://server.example/public/user.atom",
|
||||||
# salmon_url: "https://server.example/receive/users/0123456789abcdef",
|
# salmon_url: "https://server.example/receive/users/0123456789abcdef",
|
||||||
# guid: "0123456789abcdef",
|
# guid: "0123456789abcdef",
|
||||||
# pubkey: "ABCDEF=="
|
# pubkey: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
||||||
# })
|
# })
|
||||||
# xml_string = wf.to_xml
|
# xml_string = wf.to_xml
|
||||||
#
|
#
|
||||||
|
|
@ -88,8 +88,8 @@ module DiasporaFederation
|
||||||
# @param [Hash] data account data
|
# @param [Hash] data account data
|
||||||
# @return [WebFinger] WebFinger instance
|
# @return [WebFinger] WebFinger instance
|
||||||
# @raise [InvalidData] if the given data Hash is invalid or incomplete
|
# @raise [InvalidData] if the given data Hash is invalid or incomplete
|
||||||
def self.from_account(data)
|
def self.from_person(data)
|
||||||
raise InvalidData, "account data incomplete" unless account_data_complete?(data)
|
raise InvalidData, "person data incomplete" unless account_data_complete?(data)
|
||||||
|
|
||||||
wf = allocate
|
wf = allocate
|
||||||
wf.instance_eval {
|
wf.instance_eval {
|
||||||
|
|
@ -130,7 +130,7 @@ module DiasporaFederation
|
||||||
|
|
||||||
# TODO: change me! ##########
|
# TODO: change me! ##########
|
||||||
@guid = guid
|
@guid = guid
|
||||||
@pubkey = pubkey
|
@pubkey = Base64.strict_decode64(pubkey)
|
||||||
##############################
|
##############################
|
||||||
}
|
}
|
||||||
wf
|
wf
|
||||||
|
|
@ -189,7 +189,7 @@ module DiasporaFederation
|
||||||
# TODO: change me! ##############
|
# TODO: change me! ##############
|
||||||
doc.links << {rel: REL_PUBKEY,
|
doc.links << {rel: REL_PUBKEY,
|
||||||
type: "RSA",
|
type: "RSA",
|
||||||
href: @pubkey}
|
href: Base64.strict_encode64(@pubkey)}
|
||||||
##################################
|
##################################
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,19 +37,29 @@ module DiasporaFederation
|
||||||
|
|
||||||
describe "#legacy_webfinger" do
|
describe "#legacy_webfinger" do
|
||||||
it "succeeds when the person exists" do
|
it "succeeds when the person exists" do
|
||||||
post :legacy_webfinger, "q" => "alice@localhost:3000"
|
get :legacy_webfinger, "q" => "alice@localhost:3000"
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "succeeds with 'acct:' in the query when the person exists" do
|
it "succeeds with 'acct:' in the query when the person exists" do
|
||||||
post :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "contains the diaspora handle" do
|
||||||
|
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
||||||
|
expect(response.body).to include "<Subject>acct:alice@localhost:3000</Subject>"
|
||||||
|
end
|
||||||
|
|
||||||
it "404s when the person does not exist" do
|
it "404s when the person does not exist" do
|
||||||
post :legacy_webfinger, "q" => "me@mydiaspora.pod.com"
|
get :legacy_webfinger, "q" => "me@mydiaspora.pod.com"
|
||||||
expect(response).to be_not_found
|
expect(response).to be_not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "calls WebFinger::WebFinger.from_person" do
|
||||||
|
expect(WebFinger::WebFinger).to receive(:from_person).and_call_original
|
||||||
|
get :legacy_webfinger, "q" => "acct:alice@localhost:3000"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ module DiasporaFederation
|
||||||
profile_url = "https://pod.example.tld/u/user"
|
profile_url = "https://pod.example.tld/u/user"
|
||||||
atom_url = "https://pod.example.tld/public/user.atom"
|
atom_url = "https://pod.example.tld/public/user.atom"
|
||||||
salmon_url = "https://pod.example.tld/receive/users/abcdef0123456789"
|
salmon_url = "https://pod.example.tld/receive/users/abcdef0123456789"
|
||||||
pubkey = "AAAAAA=="
|
pubkey = "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
||||||
|
pubkey_base64 = Base64.strict_encode64(pubkey)
|
||||||
|
|
||||||
xml = <<-XML
|
xml = <<-XML
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
@ -21,7 +22,7 @@ module DiasporaFederation
|
||||||
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{profile_url}"/>
|
<Link rel="http://webfinger.net/rel/profile-page" type="text/html" href="#{profile_url}"/>
|
||||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{atom_url}"/>
|
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{atom_url}"/>
|
||||||
<Link rel="salmon" href="#{salmon_url}"/>
|
<Link rel="salmon" href="#{salmon_url}"/>
|
||||||
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey}"/>
|
<Link rel="diaspora-public-key" type="RSA" href="#{pubkey_base64}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ XML
|
||||||
|
|
||||||
context "generation" do
|
context "generation" do
|
||||||
it "creates a nice XML document" do
|
it "creates a nice XML document" do
|
||||||
wf = WebFinger::WebFinger.from_account(
|
wf = WebFinger::WebFinger.from_person(
|
||||||
acct_uri: acct,
|
acct_uri: acct,
|
||||||
alias_url: alias_url,
|
alias_url: alias_url,
|
||||||
hcard_url: hcard_url,
|
hcard_url: hcard_url,
|
||||||
|
|
@ -47,7 +48,7 @@ XML
|
||||||
|
|
||||||
it "fails if some params are missing" do
|
it "fails if some params are missing" do
|
||||||
expect {
|
expect {
|
||||||
WebFinger::WebFinger.from_account(
|
WebFinger::WebFinger.from_person(
|
||||||
acct_uri: acct,
|
acct_uri: acct,
|
||||||
alias_url: alias_url,
|
alias_url: alias_url,
|
||||||
hcard_url: hcard_url
|
hcard_url: hcard_url
|
||||||
|
|
@ -56,11 +57,11 @@ XML
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if empty was given" do
|
it "fails if empty was given" do
|
||||||
expect { WebFinger::WebFinger.from_account({}) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::WebFinger.from_person({}) }.to raise_error(WebFinger::InvalidData)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "fails if nil was given" do
|
it "fails if nil was given" do
|
||||||
expect { WebFinger::WebFinger.from_account(nil) }.to raise_error(WebFinger::InvalidData)
|
expect { WebFinger::WebFinger.from_person(nil) }.to raise_error(WebFinger::InvalidData)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -93,7 +94,7 @@ XML
|
||||||
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{atom_url}"/>
|
<Link rel="http://schemas.google.com/g/2010#updates-from" type="application/atom+xml" href="#{atom_url}"/>
|
||||||
<Link rel="salmon" href="#{salmon_url}"/>
|
<Link rel="salmon" href="#{salmon_url}"/>
|
||||||
|
|
||||||
<Link rel="diaspora-public-key" type = "RSA" href="#{pubkey}"/>
|
<Link rel="diaspora-public-key" type = "RSA" href="#{pubkey_base64}"/>
|
||||||
</XRD>
|
</XRD>
|
||||||
XML
|
XML
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,18 @@
|
||||||
class Person < ActiveRecord::Base
|
class Person < ActiveRecord::Base
|
||||||
include ::Diaspora::Guid
|
include ::Diaspora::Guid
|
||||||
|
|
||||||
def salmon_url
|
def webfinger_hash
|
||||||
"#{url}receive/users/#{guid}"
|
{
|
||||||
end
|
acct_uri: "acct:#{diaspora_handle}",
|
||||||
|
alias_url: "#{url}people/#{guid}",
|
||||||
def atom_url
|
hcard_url: "#{url}hcard/users/#{guid}",
|
||||||
"#{url}public/#{diaspora_handle.split('@')[0]}.atom"
|
seed_url: url,
|
||||||
end
|
profile_url: "#{url}u/#{diaspora_handle.split('@')[0]}",
|
||||||
|
atom_url: "#{url}public/#{diaspora_handle.split('@')[0]}.atom",
|
||||||
def profile_url
|
salmon_url: "#{url}receive/users/#{guid}",
|
||||||
"#{url}u/#{diaspora_handle.split('@')[0]}"
|
guid: guid,
|
||||||
end
|
pubkey: serialized_public_key
|
||||||
|
}
|
||||||
def hcard_url
|
|
||||||
"#{url}hcard/users/#{guid}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find_by_diaspora_handle(identifier)
|
def self.find_by_diaspora_handle(identifier)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue