Remove deprecated guid and public key from webfinger

Closes #39

This breaks compatibility with pods older than 0.5.3.0
This commit is contained in:
Benjamin Neff 2017-04-24 02:20:33 +02:00
parent f08db93d74
commit a3ad1ea7e4
No known key found for this signature in database
GPG key ID: 971464C3F1A90194
8 changed files with 7 additions and 284 deletions

View file

@ -74,10 +74,10 @@ module DiasporaFederation
def person def person
@person ||= Entities::Person.new( @person ||= Entities::Person.new(
guid: hcard.guid || webfinger.guid, guid: hcard.guid,
diaspora_id: diaspora_id, diaspora_id: diaspora_id,
url: webfinger.seed_url, url: webfinger.seed_url,
exported_key: hcard.public_key || webfinger.public_key, exported_key: hcard.public_key,
profile: profile profile: profile
) )
end end

View file

@ -167,8 +167,7 @@ module DiasporaFederation
photo_medium_url: photo_from_doc(doc, :photo_medium), photo_medium_url: photo_from_doc(doc, :photo_medium),
photo_small_url: photo_from_doc(doc, :photo_small), photo_small_url: photo_from_doc(doc, :photo_small),
searchable: (content_from_doc(doc, :searchable) == "true"), searchable: (content_from_doc(doc, :searchable) == "true"),
# TODO: public key is new and can be missing public_key: content_from_doc(doc, :key),
public_key: (content_from_doc(doc, :key) unless element_from_doc(doc, :key).nil?),
# TODO: remove first_name and last_name! # TODO: remove first_name and last_name!
first_name: content_from_doc(doc, :given_name), first_name: content_from_doc(doc, :given_name),

View file

@ -14,9 +14,7 @@ module DiasporaFederation
# seed_url: "https://server.example/", # seed_url: "https://server.example/",
# profile_url: "https://server.example/u/user", # profile_url: "https://server.example/u/user",
# 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",
# public_key: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
# ) # )
# xml_string = wf.to_xml # xml_string = wf.to_xml
# #
@ -76,42 +74,12 @@ module DiasporaFederation
# This url is used to find another user on the home-pod of the user in the webfinger. # This url is used to find another user on the home-pod of the user in the webfinger.
property :subscribe_url, :string property :subscribe_url, :string
# @!attribute [r] guid
# @deprecated Either convert these to +Property+ elements or move to the
# +hCard+, which actually has fields for an +UID+ defined in the +vCard+
# specification (will affect older diaspora* installations).
#
# @see HCard#guid
# @see Entities::Person#guid
# @return [String] guid
property :guid, :string
# @!attribute [r] public_key
# @deprecated Either convert these to +Property+ elements or move to the
# +hCard+, which actually has fields for an +KEY+ defined in the +vCard+
# specification (will affect older diaspora* installations).
#
# @see HCard#public_key
#
# When a user is created on the pod, the pod MUST generate a pgp keypair
# for them. This key is used for signing messages. The format is a
# DER-encoded PKCS#1 key beginning with the text
# "-----BEGIN PUBLIC KEY-----" and ending with "-----END PUBLIC KEY-----".
# @return [String] public key
property :public_key, :string
# +hcard_url+ link relation # +hcard_url+ link relation
REL_HCARD = "http://microformats.org/profile/hcard".freeze REL_HCARD = "http://microformats.org/profile/hcard".freeze
# +seed_url+ link relation # +seed_url+ link relation
REL_SEED = "http://joindiaspora.com/seed_location".freeze REL_SEED = "http://joindiaspora.com/seed_location".freeze
# @deprecated This should be a +Property+ or moved to the +hCard+, but +Link+
# is inappropriate according to the specification (will affect older
# diaspora* installations).
# +guid+ link relation
REL_GUID = "http://joindiaspora.com/guid".freeze
# +profile_url+ link relation. # +profile_url+ link relation.
# @note This might just as well be an +Alias+ instead of a +Link+. # @note This might just as well be an +Alias+ instead of a +Link+.
REL_PROFILE = "http://webfinger.net/rel/profile-page".freeze REL_PROFILE = "http://webfinger.net/rel/profile-page".freeze
@ -125,12 +93,6 @@ module DiasporaFederation
# +subscribe_url+ link relation # +subscribe_url+ link relation
REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe".freeze REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe".freeze
# @deprecated This should be a +Property+ or moved to the +hcard+, but +Link+
# is inappropriate according to the specification (will affect older
# diaspora* installations).
# +pubkey+ link relation
REL_PUBKEY = "diaspora-public-key".freeze
# Creates the XML string from the current WebFinger instance # Creates the XML string from the current WebFinger instance
# @return [String] XML string # @return [String] XML string
def to_xml def to_xml
@ -152,9 +114,6 @@ module DiasporaFederation
links = data[:links] links = data[:links]
# TODO: remove! public key is deprecated in webfinger
public_key = parse_link(links, REL_PUBKEY)
new( new(
acct_uri: data[:subject], acct_uri: data[:subject],
alias_url: parse_alias(data[:aliases]), alias_url: parse_alias(data[:aliases]),
@ -164,11 +123,7 @@ module DiasporaFederation
atom_url: parse_link(links, REL_ATOM), atom_url: parse_link(links, REL_ATOM),
salmon_url: parse_link(links, REL_SALMON), salmon_url: parse_link(links, REL_SALMON),
subscribe_url: parse_link_template(links, REL_SUBSCRIBE), subscribe_url: parse_link_template(links, REL_SUBSCRIBE)
# TODO: remove me! ##########
guid: parse_link(links, REL_GUID),
public_key: (Base64.strict_decode64(public_key) if public_key)
) )
end end
@ -195,21 +150,11 @@ module DiasporaFederation
doc.links << {rel: REL_HCARD, type: "text/html", href: @hcard_url} doc.links << {rel: REL_HCARD, type: "text/html", href: @hcard_url}
doc.links << {rel: REL_SEED, type: "text/html", href: @seed_url} doc.links << {rel: REL_SEED, type: "text/html", href: @seed_url}
# TODO: remove me! ##############
doc.links << {rel: REL_GUID, type: "text/html", href: @guid}
##################################
doc.links << {rel: REL_PROFILE, type: "text/html", href: @profile_url} doc.links << {rel: REL_PROFILE, type: "text/html", href: @profile_url}
doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: @atom_url} doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: @atom_url}
doc.links << {rel: REL_SALMON, href: @salmon_url} doc.links << {rel: REL_SALMON, href: @salmon_url}
doc.links << {rel: REL_SUBSCRIBE, template: @subscribe_url} doc.links << {rel: REL_SUBSCRIBE, template: @subscribe_url}
# TODO: remove me! ##############
doc.links << {rel: REL_PUBKEY,
type: "RSA",
href: Base64.strict_encode64(@public_key)}
##################################
end end
private_class_method def self.find_link(links, rel) private_class_method def self.find_link(links, rel)

View file

@ -11,7 +11,6 @@ module DiasporaFederation
Fabricate.sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export } Fabricate.sequence(:public_key) { OpenSSL::PKey::RSA.generate(1024).public_key.export }
Fabricator(:webfinger, class_name: DiasporaFederation::Discovery::WebFinger) do Fabricator(:webfinger, class_name: DiasporaFederation::Discovery::WebFinger) do
guid { Fabricate.sequence(:guid) }
acct_uri { "acct:#{Fabricate.sequence(:diaspora_id)}" } acct_uri { "acct:#{Fabricate.sequence(:diaspora_id)}" }
alias_url "http://localhost:3000/people/0123456789abcdef" alias_url "http://localhost:3000/people/0123456789abcdef"
hcard_url "http://localhost:3000/hcard/users/user" hcard_url "http://localhost:3000/hcard/users/user"
@ -19,7 +18,6 @@ module DiasporaFederation
profile_url "http://localhost:3000/u/user" profile_url "http://localhost:3000/u/user"
atom_url "http://localhost:3000/public/user.atom" atom_url "http://localhost:3000/public/user.atom"
salmon_url "http://localhost:3000/receive/users/0123456789abcdef" salmon_url "http://localhost:3000/receive/users/0123456789abcdef"
public_key { Fabricate.sequence(:public_key) }
subscribe_url "http://localhost:3000/people?q={uri}" subscribe_url "http://localhost:3000/people?q={uri}"
end end

View file

@ -2,14 +2,11 @@ module DiasporaFederation
module Validators module Validators
# This validates a {Discovery::HCard}. # This validates a {Discovery::HCard}.
# #
# @todo activate guid and public key validation after all pod have it in
# the hcard.
#
# @note # @note
class HCardValidator < Validation::Validator class HCardValidator < Validation::Validator
include Validation include Validation
# rule :guid, :guid rule :guid, :guid
# The name must not contain a semicolon because of mentions. # The name must not contain a semicolon because of mentions.
# @{<full_name> ; <diaspora_id>} # @{<full_name> ; <diaspora_id>}
@ -22,7 +19,7 @@ module DiasporaFederation
rule :photo_medium_url, [:not_nil, URI: [:path]] rule :photo_medium_url, [:not_nil, URI: [:path]]
rule :photo_small_url, [:not_nil, URI: [:path]] rule :photo_small_url, [:not_nil, URI: [:path]]
# rule :exported_key, :public_key rule :public_key, :public_key
rule :searchable, :boolean rule :searchable, :boolean
end end

View file

@ -144,98 +144,6 @@ module DiasporaFederation
expect { Discovery::Discovery.new(account).fetch_and_save }.to raise_error Discovery::DiscoveryError expect { Discovery::Discovery.new(account).fetch_and_save }.to raise_error Discovery::DiscoveryError
end end
it "reads old hcard without guid and public key" do
historic_hcard_html = <<-HTML
<div id="content">
<h1>#{account}</h1>
<div id="content_inner">
<div class="entity_profile vcard author" id="i">
<h2>User profile</h2>
<dl class="entity_nickname">
<dt>Nickname</dt>
<dd>
<a class="nickname url uid" href="#{alice.url}" rel="me"></a>
</dd>
</dl>
<dl class="entity_given_name">
<dt>First name</dt>
<dd>
<span class="given_name"></span>
</dd>
</dl>
<dl class="entity_family_name">
<dt>Family name</dt>
<dd>
<span class="family_name"></span>
</dd>
</dl>
<dl class="entity_fn">
<dt>Full name</dt>
<dd>
<span class="fn"></span>
</dd>
</dl>
<dl class="entity_url">
<dt>URL</dt>
<dd>
<a class="url" href="#{alice.url}" id="pod_location" rel="me">#{alice.url}</a>
</dd>
</dl>
<dl class="entity_photo">
<dt>Photo</dt>
<dd>
<img class="photo avatar" height="300px" src="#{default_image}" width="300px">
</dd>
</dl>
<dl class="entity_photo_medium">
<dt>Photo</dt>
<dd>
<img class="photo avatar" height="100px" src="#{default_image}" width="100px">
</dd>
</dl>
<dl class="entity_photo_small">
<dt>Photo</dt>
<dd>
<img class="photo avatar" height="50px" src="#{default_image}" width="50px">
</dd>
</dl>
<dl class="entity_searchable">
<dt>Searchable</dt>
<dd>
<span class="searchable">true</span>
</dd>
</dl>
</div>
</div>
</div>
HTML
stub_request(:get, "https://localhost:3000/.well-known/host-meta")
.to_return(status: 200, body: host_meta_xrd)
stub_request(:get, "http://localhost:3000/webfinger?q=acct:#{account}")
.to_return(status: 200, body: webfinger_xrd)
stub_request(:get, "http://localhost:3000/hcard/users/#{alice.guid}")
.to_return(status: 200, body: historic_hcard_html)
expect_callback(:save_person_after_webfinger, kind_of(Entities::Person))
person = Discovery::Discovery.new(account).fetch_and_save
expect(person.guid).to eq(alice.guid)
expect(person.diaspora_id).to eq(account)
expect(person.url).to eq(alice.url)
expect(person.exported_key).to eq(alice.serialized_public_key)
profile = person.profile
expect(profile.diaspora_id).to eq(alice.diaspora_id)
expect(profile.first_name).to be_nil
expect(profile.last_name).to be_nil
expect(profile.image_url).to eq(default_image)
expect(profile.image_url_medium).to eq(default_image)
expect(profile.image_url_small).to eq(default_image)
end
end end
end end
end end

View file

@ -258,85 +258,6 @@ HTML
expect(hcard.last_name).to be_nil expect(hcard.last_name).to be_nil
end end
it "reads old-style HTML" do
historic_html = <<-HTML
<div id="content">
<h1>#{person.full_name}</h1>
<div id="content_inner">
<div class="entity_profile vcard author" id="i">
<h2>User profile</h2>
<dl class="entity_nickname">
<dt>Nickname</dt>
<dd>
<a class="nickname url uid" href="#{person.url}" rel="me">#{person.full_name}</a>
</dd>
</dl>
<dl class="entity_given_name">
<dt>First name</dt>
<dd>
<span class="given_name">#{person.first_name}</span>
</dd>
</dl>
<dl class="entity_family_name">
<dt>Family name</dt>
<dd>
<span class="family_name">#{person.last_name}</span>
</dd>
</dl>
<dl class="entity_fn">
<dt>Full name</dt>
<dd>
<span class="fn">#{person.full_name}</span>
</dd>
</dl>
<dl class="entity_url">
<dt>URL</dt>
<dd>
<a class="url" href="#{person.url}" id="pod_location" rel="me">#{person.url}</a>
</dd>
</dl>
<dl class="entity_photo">
<dt>Photo</dt>
<dd>
<img class="photo avatar" height="300px" src="#{photo_large_url}" width="300px">
</dd>
</dl>
<dl class="entity_photo_medium">
<dt>Photo</dt>
<dd>
<img class="photo avatar" height="100px" src="#{photo_medium_url}" width="100px">
</dd>
</dl>
<dl class="entity_photo_small">
<dt>Photo</dt>
<dd>
<img class="photo avatar" height="50px" src="#{photo_small_url}" width="50px">
</dd>
</dl>
<dl class="entity_searchable">
<dt>Searchable</dt>
<dd>
<span class="searchable">#{person.searchable}</span>
</dd>
</dl>
</div>
</div>
</div>
HTML
hcard = Discovery::HCard.from_html(historic_html)
expect(hcard.photo_large_url).to eq(photo_large_url)
expect(hcard.photo_medium_url).to eq(photo_medium_url)
expect(hcard.photo_small_url).to eq(photo_small_url)
expect(hcard.searchable).to eq(person.searchable)
expect(hcard.first_name).to eq(person.first_name)
expect(hcard.last_name).to eq(person.last_name)
expect(hcard.guid).to be_nil
expect(hcard.public_key).to be_nil
end
it "fails if the document is incomplete" do it "fails if the document is incomplete" do
invalid_html = <<-HTML invalid_html = <<-HTML
<div id="content"> <div id="content">

View file

@ -13,8 +13,6 @@ module DiasporaFederation
profile_url: person.profile_url, profile_url: person.profile_url,
atom_url: person.atom_url, atom_url: person.atom_url,
salmon_url: person.salmon_url, salmon_url: person.salmon_url,
guid: person.guid,
public_key: person.serialized_public_key,
subscribe_url: person.subscribe_url subscribe_url: person.subscribe_url
} }
} }
@ -26,12 +24,10 @@ module DiasporaFederation
<Alias>#{person.alias_url}</Alias> <Alias>#{person.alias_url}</Alias>
<Link rel="http://microformats.org/profile/hcard" type="text/html" href="#{person.hcard_url}"/> <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/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://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="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="salmon" href="#{person.salmon_url}"/>
<Link rel="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/> <Link rel="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/>
<Link rel="diaspora-public-key" type="RSA" href="#{public_key_base64}"/>
</XRD> </XRD>
XML XML
@ -57,9 +53,6 @@ XML
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url) expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.subscribe_url).to eq(person.subscribe_url) expect(wf.subscribe_url).to eq(person.subscribe_url)
expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key)
end end
it "reads minimal xml" do it "reads minimal xml" do
@ -108,9 +101,6 @@ XML
expect(wf.profile_url).to eq(person.profile_url) expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url) expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key)
end end
it "reads friendica XML (two aliases, first with acct)" do it "reads friendica XML (two aliases, first with acct)" do
@ -169,9 +159,6 @@ XML
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url) expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.subscribe_url).to eq("https://pod.example.tld/follow?url={uri}") expect(wf.subscribe_url).to eq("https://pod.example.tld/follow?url={uri}")
expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key)
end end
it "reads redmatrix XML (no alias)" do it "reads redmatrix XML (no alias)" do
@ -214,38 +201,6 @@ XML
expect(wf.profile_url).to eq(person.profile_url) expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url) expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to be_nil expect(wf.salmon_url).to be_nil
expect(wf.guid).to eq(person.guid)
expect(wf.public_key).to eq(person.serialized_public_key)
end
it "reads future XML without guid and public key" do
future_xml = <<-XML
<?xml version="1.0" encoding="UTF-8"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Subject>#{acct}</Subject>
<Alias>#{person.alias_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://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="http://ostatus.org/schema/1.0/subscribe" template="#{person.subscribe_url}"/>
</XRD>
XML
wf = Discovery::WebFinger.from_xml(future_xml)
expect(wf.acct_uri).to eq(acct)
expect(wf.alias_url).to eq(person.alias_url)
expect(wf.hcard_url).to eq(person.hcard_url)
expect(wf.seed_url).to eq(person.url)
expect(wf.profile_url).to eq(person.profile_url)
expect(wf.atom_url).to eq(person.atom_url)
expect(wf.salmon_url).to eq(person.salmon_url)
expect(wf.subscribe_url).to eq(person.subscribe_url)
expect(wf.guid).to be_nil
expect(wf.public_key).to be_nil
end end
it "fails if the document is empty" do it "fails if the document is empty" do