diaspora_federation 0.1.9 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +34 -0
- data/lib/diaspora_federation/discovery/discovery.rb +2 -2
- data/lib/diaspora_federation/discovery/h_card.rb +2 -10
- data/lib/diaspora_federation/discovery/host_meta.rb +1 -1
- data/lib/diaspora_federation/discovery/web_finger.rb +47 -87
- data/lib/diaspora_federation/discovery/xrd_document.rb +20 -7
- data/lib/diaspora_federation/entities/account_migration.rb +74 -0
- data/lib/diaspora_federation/entities/comment.rb +0 -4
- data/lib/diaspora_federation/entities/event_participation.rb +0 -8
- data/lib/diaspora_federation/entities/like.rb +6 -10
- data/lib/diaspora_federation/entities/message.rb +14 -49
- data/lib/diaspora_federation/entities/participation.rb +23 -13
- data/lib/diaspora_federation/entities/poll_participation.rb +0 -4
- data/lib/diaspora_federation/entities/profile.rb +5 -0
- data/lib/diaspora_federation/entities/related_entity.rb +17 -0
- data/lib/diaspora_federation/entities/relayable.rb +82 -113
- data/lib/diaspora_federation/entities/relayable_retraction.rb +4 -43
- data/lib/diaspora_federation/entities/request.rb +4 -12
- data/lib/diaspora_federation/entities/reshare.rb +11 -7
- data/lib/diaspora_federation/entities/retraction.rb +4 -5
- data/lib/diaspora_federation/entities/signable.rb +54 -0
- data/lib/diaspora_federation/entities/signed_retraction.rb +4 -44
- data/lib/diaspora_federation/entities.rb +2 -0
- data/lib/diaspora_federation/entity.rb +74 -96
- data/lib/diaspora_federation/federation/fetcher.rb +1 -1
- data/lib/diaspora_federation/federation/receiver.rb +1 -1
- data/lib/diaspora_federation/federation/sender/hydra_wrapper.rb +37 -12
- data/lib/diaspora_federation/federation/sender.rb +2 -2
- data/lib/diaspora_federation/parsers/base_parser.rb +61 -0
- data/lib/diaspora_federation/parsers/json_parser.rb +60 -0
- data/lib/diaspora_federation/parsers/relayable_json_parser.rb +25 -0
- data/lib/diaspora_federation/parsers/relayable_xml_parser.rb +22 -0
- data/lib/diaspora_federation/parsers/xml_parser.rb +84 -0
- data/lib/diaspora_federation/parsers.rb +13 -0
- data/lib/diaspora_federation/properties_dsl.rb +1 -1
- data/lib/diaspora_federation/salmon/encrypted_magic_envelope.rb +1 -1
- data/lib/diaspora_federation/salmon/encrypted_slap.rb +2 -99
- data/lib/diaspora_federation/salmon/magic_envelope.rb +3 -19
- data/lib/diaspora_federation/salmon/slap.rb +1 -42
- data/lib/diaspora_federation/salmon/xml_payload.rb +0 -19
- data/lib/diaspora_federation/schemas/federation_entities.json +379 -0
- data/lib/diaspora_federation/validators/account_deletion_validator.rb +1 -1
- data/lib/diaspora_federation/validators/account_migration_validator.rb +12 -0
- data/lib/diaspora_federation/validators/contact_validator.rb +2 -2
- data/lib/diaspora_federation/validators/conversation_validator.rb +1 -1
- data/lib/diaspora_federation/validators/event_validator.rb +1 -1
- data/lib/diaspora_federation/validators/h_card_validator.rb +2 -5
- data/lib/diaspora_federation/validators/message_validator.rb +1 -1
- data/lib/diaspora_federation/validators/participation_validator.rb +1 -1
- data/lib/diaspora_federation/validators/person_validator.rb +2 -2
- data/lib/diaspora_federation/validators/photo_validator.rb +1 -1
- data/lib/diaspora_federation/validators/profile_validator.rb +1 -1
- data/lib/diaspora_federation/validators/related_entity_validator.rb +1 -1
- data/lib/diaspora_federation/validators/relayable_validator.rb +1 -1
- data/lib/diaspora_federation/validators/reshare_validator.rb +2 -2
- data/lib/diaspora_federation/validators/retraction_validator.rb +1 -1
- data/lib/diaspora_federation/validators/rules/boolean.rb +2 -2
- data/lib/diaspora_federation/validators/status_message_validator.rb +1 -1
- data/lib/diaspora_federation/validators/web_finger_validator.rb +5 -6
- data/lib/diaspora_federation/validators.rb +1 -5
- data/lib/diaspora_federation/version.rb +1 -1
- data/lib/diaspora_federation.rb +6 -2
- metadata +14 -11
- data/lib/diaspora_federation/validators/relayable_retraction_validator.rb +0 -15
- data/lib/diaspora_federation/validators/request_validator.rb +0 -12
- data/lib/diaspora_federation/validators/signed_retraction_validator.rb +0 -15
- data/lib/tasks/build.rake +0 -14
- data/lib/tasks/diaspora_federation_tasks.rake +0 -4
- data/lib/tasks/rails4.rake +0 -15
- data/lib/tasks/tests.rake +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0143fd95b478d62bc2fb26b136df5103c0074fce
|
4
|
+
data.tar.gz: 919d5d547e686a4994305c8a42514762072784be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40f7824b9fa501dee9fe1683ec5ab33ee22e6da144d5a55d278252c4f365893ee9478ff97e9113ada59d9fb722ddb69fa35eaf63abdfc247200de63e05ba4418
|
7
|
+
data.tar.gz: fb88dd79852c1bb5ff77260165bdaca7ae10745205cd1baa2719033b43b7f8cba97ede1136e323e7f9e3c30121d08a32ee6065f71495759549e7c872acf96457
|
data/Changelog.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
# 0.2.0
|
2
|
+
|
3
|
+
## Features
|
4
|
+
|
5
|
+
* Add JSON support to entities [#52](https://github.com/diaspora/diaspora_federation/pull/52)
|
6
|
+
* Add `AccountMigration` entity [#54](https://github.com/diaspora/diaspora_federation/pull/54)
|
7
|
+
* Add `public` flag to `Profile` entity [#59](https://github.com/diaspora/diaspora_federation/pull/59)
|
8
|
+
* Allow to generate WebFinger with additional data [#61](https://github.com/diaspora/diaspora_federation/pull/61) [1b9dfc8](https://github.com/diaspora/diaspora_federation/commit/1b9dfc812e8b63c64a2d98db8999cae21d102c87)
|
9
|
+
* Provide RFC 7033 WebFinger [#63](https://github.com/diaspora/diaspora_federation/pull/63)
|
10
|
+
* Validate the author of the root post for a reshare [92ce4ea](https://github.com/diaspora/diaspora_federation/commit/92ce4eacf842f7a2fa74f298407062a4e0c891a3)
|
11
|
+
|
12
|
+
## Refactor
|
13
|
+
|
14
|
+
* Replace `factory_girl` with `fabrication` [184954e](https://github.com/diaspora/diaspora_federation/commit/184954e09ce72242cb7ec06c15fed0ad7b6c57c6)
|
15
|
+
* Use `actionpack` as dependency instead of `rails` (for `diaspora_federation-rails`) [f860a62](https://github.com/diaspora/diaspora_federation/commit/f860a62382999dcf0adaf41a24b50b74611f6ed9)
|
16
|
+
* Remove old backward-compatibility from WebFinger [#60](https://github.com/diaspora/diaspora_federation/pull/60)
|
17
|
+
* Make optional properties optional when generating WebFinger [#61](https://github.com/diaspora/diaspora_federation/pull/61) [5fef763](https://github.com/diaspora/diaspora_federation/commit/5fef7633c3aaf47db2592749e506f40b581c0371)
|
18
|
+
* Make `Message` entity non-relayable (see [#36](https://github.com/diaspora/diaspora_federation/issues/36)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [b7167b9](https://github.com/diaspora/diaspora_federation/commit/b7167b9fde4d614fb8f7510720918e029d3624f4)
|
19
|
+
* Make `Participation` entity non-relayable (see [#35](https://github.com/diaspora/diaspora_federation/issues/35)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [41ebe13](https://github.com/diaspora/diaspora_federation/commit/41ebe13126a28b95dbe5acc5db3939ee9dae7e4b)
|
20
|
+
* Remove legacy signature order and order by property order in entity (see [#26](https://github.com/diaspora/diaspora_federation/issues/26)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [87033e4](https://github.com/diaspora/diaspora_federation/commit/87033e4cd63f7d237b9d02d95b739e971d205ea1)
|
21
|
+
* Send new property names in XML (see [#29](https://github.com/diaspora/diaspora_federation/issues/29)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [52a8c89](https://github.com/diaspora/diaspora_federation/commit/52a8c89d4c0f1f66b188ab4a2ac36ffafb0bfa1a)
|
22
|
+
* Send unwrapped entities (see [#28](https://github.com/diaspora/diaspora_federation/issues/28)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [221d87d](https://github.com/diaspora/diaspora_federation/commit/221d87d7fe664bde8718182178cb31ba532977c6)
|
23
|
+
* Send the raw magic envelope and new encrypted magic envelope with crypt-json-wrapper (see [#30](https://github.com/diaspora/diaspora_federation/issues/30)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [1f99518](https://github.com/diaspora/diaspora_federation/commit/1f99518706e6bef3dca51453bf571373cd389942) [e5b2ef7](https://github.com/diaspora/diaspora_federation/commit/e5b2ef71e8cfa299874e3f80175526b8999839f7)
|
24
|
+
* Remove sign-code and prevent creation of `SignedRetraction` and `RelayableRetraction` (see [#27](https://github.com/diaspora/diaspora_federation/issues/27)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [cd3a7ab](https://github.com/diaspora/diaspora_federation/commit/cd3a7abf4d778f7e3139bcb73a42a9dc4cbcb835)
|
25
|
+
* Rename `xml_order` to `signature_order` on relayables [b510ed8](https://github.com/diaspora/diaspora_federation/commit/b510ed868f12e15fd5c7b91909cc35281efeb10e)
|
26
|
+
* Prevent creation of `Request` entity (see [#32](https://github.com/diaspora/diaspora_federation/issues/32)) [#62](https://github.com/diaspora/diaspora_federation/pull/62) [deed1c3](https://github.com/diaspora/diaspora_federation/commit/deed1c3f3ea76658074a4e34f534a12f083e8622)
|
27
|
+
* Don't check `parent_author_signature` and don't check the `author_signature` when the author is the parent author for relayables (see [#64](https://github.com/diaspora/diaspora_federation/issues/64)) [#65](https://github.com/diaspora/diaspora_federation/pull/65) [6817579](https://github.com/diaspora/diaspora_federation/commit/681757907204885735bc60b18929938ec2ad04bb) [57edc8b](https://github.com/diaspora/diaspora_federation/commit/57edc8baabcf884b0ac5395266ffe148cff5da1d)
|
28
|
+
* Add `created_at` to `Comment` entity [#67](https://github.com/diaspora/diaspora_federation/pull/67)
|
29
|
+
* Improve logging when validation fails [c0ea38d](https://github.com/diaspora/diaspora_federation/commit/c0ea38d258ccd76a7499bff0197434d8e42768e8)
|
30
|
+
|
31
|
+
## Bug fixes
|
32
|
+
|
33
|
+
* Fix issues when used without rails [ed2c2b7](https://github.com/diaspora/diaspora_federation/commit/ed2c2b7f47b91c308321076344459aee839318a8) [b25e229](https://github.com/diaspora/diaspora_federation/commit/b25e2293b0b83bc083bccdbf1523ee691dbb7b2e) [6615233](https://github.com/diaspora/diaspora_federation/commit/66152337f2b47c1cf6639646f55d21f69fe99708)
|
34
|
+
|
1
35
|
# 0.1.9
|
2
36
|
|
3
37
|
## Bug fixes
|
@@ -74,10 +74,10 @@ module DiasporaFederation
|
|
74
74
|
|
75
75
|
def person
|
76
76
|
@person ||= Entities::Person.new(
|
77
|
-
guid: hcard.guid
|
77
|
+
guid: hcard.guid,
|
78
78
|
diaspora_id: diaspora_id,
|
79
79
|
url: webfinger.seed_url,
|
80
|
-
exported_key: hcard.public_key
|
80
|
+
exported_key: hcard.public_key,
|
81
81
|
profile: profile
|
82
82
|
)
|
83
83
|
end
|
@@ -160,15 +160,14 @@ module DiasporaFederation
|
|
160
160
|
doc = parse_html_and_validate(html_string)
|
161
161
|
|
162
162
|
new(
|
163
|
-
guid:
|
163
|
+
guid: content_from_doc(doc, :uid),
|
164
164
|
nickname: content_from_doc(doc, :nickname),
|
165
165
|
full_name: content_from_doc(doc, :fn),
|
166
166
|
photo_large_url: photo_from_doc(doc, :photo),
|
167
167
|
photo_medium_url: photo_from_doc(doc, :photo_medium),
|
168
168
|
photo_small_url: photo_from_doc(doc, :photo_small),
|
169
169
|
searchable: (content_from_doc(doc, :searchable) == "true"),
|
170
|
-
|
171
|
-
public_key: (content_from_doc(doc, :key) unless element_from_doc(doc, :key).nil?),
|
170
|
+
public_key: content_from_doc(doc, :key),
|
172
171
|
|
173
172
|
# TODO: remove first_name and last_name!
|
174
173
|
first_name: content_from_doc(doc, :given_name),
|
@@ -276,13 +275,6 @@ module DiasporaFederation
|
|
276
275
|
private_class_method def self.photo_from_doc(doc, photo_selector)
|
277
276
|
element_from_doc(doc, photo_selector)["src"]
|
278
277
|
end
|
279
|
-
|
280
|
-
# @deprecated hack for old hcard
|
281
|
-
# @todo remove this when all pods have the new generator
|
282
|
-
private_class_method def self.guid_from_doc(doc)
|
283
|
-
uid_element = element_from_doc(doc, :uid)
|
284
|
-
uid_element.content unless uid_element[:class].include? "nickname"
|
285
|
-
end
|
286
278
|
end
|
287
279
|
end
|
288
280
|
end
|
@@ -26,7 +26,7 @@ module DiasporaFederation
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# URL fragment to append to the base URL
|
29
|
-
WEBFINGER_SUFFIX = "/webfinger?
|
29
|
+
WEBFINGER_SUFFIX = "/.well-known/webfinger.xml?resource={uri}".freeze
|
30
30
|
|
31
31
|
# Returns the WebFinger URL that was used to build this instance (either from
|
32
32
|
# xml or by giving a base URL).
|
@@ -9,14 +9,11 @@ module DiasporaFederation
|
|
9
9
|
# @example Creating a WebFinger document from a person hash
|
10
10
|
# wf = WebFinger.new(
|
11
11
|
# acct_uri: "acct:user@server.example",
|
12
|
-
# alias_url: "https://server.example/people/0123456789abcdef",
|
13
12
|
# hcard_url: "https://server.example/hcard/users/user",
|
14
13
|
# seed_url: "https://server.example/",
|
15
14
|
# profile_url: "https://server.example/u/user",
|
16
15
|
# atom_url: "https://server.example/public/user.atom",
|
17
|
-
# salmon_url: "https://server.example/receive/users/0123456789abcdef"
|
18
|
-
# guid: "0123456789abcdef",
|
19
|
-
# public_key: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
|
16
|
+
# salmon_url: "https://server.example/receive/users/0123456789abcdef"
|
20
17
|
# )
|
21
18
|
# xml_string = wf.to_xml
|
22
19
|
#
|
@@ -37,11 +34,6 @@ module DiasporaFederation
|
|
37
34
|
# @return [String]
|
38
35
|
property :acct_uri, :string
|
39
36
|
|
40
|
-
# @!attribute [r] alias_url
|
41
|
-
# @note could be nil
|
42
|
-
# @return [String] link to the users profile
|
43
|
-
property :alias_url, :string
|
44
|
-
|
45
37
|
# @!attribute [r] hcard_url
|
46
38
|
# @return [String] link to the +hCard+
|
47
39
|
property :hcard_url, :string
|
@@ -52,7 +44,7 @@ module DiasporaFederation
|
|
52
44
|
|
53
45
|
# @!attribute [r] profile_url
|
54
46
|
# @return [String] link to the users profile
|
55
|
-
property :profile_url, :string
|
47
|
+
property :profile_url, :string, default: nil
|
56
48
|
|
57
49
|
# @!attribute [r] atom_url
|
58
50
|
# This atom feed is an Activity Stream of the user's public posts. diaspora*
|
@@ -63,42 +55,18 @@ module DiasporaFederation
|
|
63
55
|
# Note that this feed MAY also be made available through the PubSubHubbub
|
64
56
|
# mechanism by supplying a <link rel="hub"> in the atom feed itself.
|
65
57
|
# @return [String] atom feed url
|
66
|
-
property :atom_url, :string
|
58
|
+
property :atom_url, :string, default: nil
|
67
59
|
|
68
60
|
# @!attribute [r] salmon_url
|
69
61
|
# @note could be nil
|
70
62
|
# @return [String] salmon endpoint url
|
71
63
|
# @see https://cdn.rawgit.com/salmon-protocol/salmon-protocol/master/draft-panzer-salmon-00.html#SMLR
|
72
64
|
# Panzer draft for Salmon, paragraph 3.3
|
73
|
-
property :salmon_url, :string
|
65
|
+
property :salmon_url, :string, default: nil
|
74
66
|
|
75
67
|
# @!attribute [r] subscribe_url
|
76
68
|
# This url is used to find another user on the home-pod of the user in the webfinger.
|
77
|
-
property :subscribe_url, :string
|
78
|
-
|
79
|
-
# @!attribute [r] guid
|
80
|
-
# @deprecated Either convert these to +Property+ elements or move to the
|
81
|
-
# +hCard+, which actually has fields for an +UID+ defined in the +vCard+
|
82
|
-
# specification (will affect older diaspora* installations).
|
83
|
-
#
|
84
|
-
# @see HCard#guid
|
85
|
-
# @see Entities::Person#guid
|
86
|
-
# @return [String] guid
|
87
|
-
property :guid, :string
|
88
|
-
|
89
|
-
# @!attribute [r] public_key
|
90
|
-
# @deprecated Either convert these to +Property+ elements or move to the
|
91
|
-
# +hCard+, which actually has fields for an +KEY+ defined in the +vCard+
|
92
|
-
# specification (will affect older diaspora* installations).
|
93
|
-
#
|
94
|
-
# @see HCard#public_key
|
95
|
-
#
|
96
|
-
# When a user is created on the pod, the pod MUST generate a pgp keypair
|
97
|
-
# for them. This key is used for signing messages. The format is a
|
98
|
-
# DER-encoded PKCS#1 key beginning with the text
|
99
|
-
# "-----BEGIN PUBLIC KEY-----" and ending with "-----END PUBLIC KEY-----".
|
100
|
-
# @return [String] public key
|
101
|
-
property :public_key, :string
|
69
|
+
property :subscribe_url, :string, default: nil
|
102
70
|
|
103
71
|
# +hcard_url+ link relation
|
104
72
|
REL_HCARD = "http://microformats.org/profile/hcard".freeze
|
@@ -106,12 +74,6 @@ module DiasporaFederation
|
|
106
74
|
# +seed_url+ link relation
|
107
75
|
REL_SEED = "http://joindiaspora.com/seed_location".freeze
|
108
76
|
|
109
|
-
# @deprecated This should be a +Property+ or moved to the +hCard+, but +Link+
|
110
|
-
# is inappropriate according to the specification (will affect older
|
111
|
-
# diaspora* installations).
|
112
|
-
# +guid+ link relation
|
113
|
-
REL_GUID = "http://joindiaspora.com/guid".freeze
|
114
|
-
|
115
77
|
# +profile_url+ link relation.
|
116
78
|
# @note This might just as well be an +Alias+ instead of a +Link+.
|
117
79
|
REL_PROFILE = "http://webfinger.net/rel/profile-page".freeze
|
@@ -125,22 +87,31 @@ module DiasporaFederation
|
|
125
87
|
# +subscribe_url+ link relation
|
126
88
|
REL_SUBSCRIBE = "http://ostatus.org/schema/1.0/subscribe".freeze
|
127
89
|
|
128
|
-
#
|
129
|
-
#
|
130
|
-
|
131
|
-
|
132
|
-
|
90
|
+
# Additional WebFinger data
|
91
|
+
# @return [Hash] additional elements
|
92
|
+
attr_reader :additional_data
|
93
|
+
|
94
|
+
# Initializes a new WebFinger Entity
|
95
|
+
#
|
96
|
+
# @param [Hash] data WebFinger data
|
97
|
+
# @param [Hash] additional_data additional WebFinger data
|
98
|
+
# @option additional_data [Array<String>] :aliases additional aliases
|
99
|
+
# @option additional_data [Hash] :properties properties
|
100
|
+
# @option additional_data [Array<Hash>] :links additional link elements
|
101
|
+
# @see DiasporaFederation::Entity#initialize
|
102
|
+
def initialize(data, additional_data={})
|
103
|
+
@additional_data = additional_data
|
104
|
+
super(data)
|
105
|
+
end
|
133
106
|
|
134
107
|
# Creates the XML string from the current WebFinger instance
|
135
108
|
# @return [String] XML string
|
136
109
|
def to_xml
|
137
|
-
|
138
|
-
|
139
|
-
doc.aliases << @alias_url
|
140
|
-
|
141
|
-
add_links_to(doc)
|
110
|
+
to_xrd.to_xml
|
111
|
+
end
|
142
112
|
|
143
|
-
|
113
|
+
def to_json
|
114
|
+
to_xrd.to_json
|
144
115
|
end
|
145
116
|
|
146
117
|
# Creates a WebFinger instance from the given XML string
|
@@ -152,23 +123,16 @@ module DiasporaFederation
|
|
152
123
|
|
153
124
|
links = data[:links]
|
154
125
|
|
155
|
-
# TODO: remove! public key is deprecated in webfinger
|
156
|
-
public_key = parse_link(links, REL_PUBKEY)
|
157
|
-
|
158
126
|
new(
|
159
127
|
acct_uri: data[:subject],
|
160
|
-
|
128
|
+
|
161
129
|
hcard_url: parse_link(links, REL_HCARD),
|
162
130
|
seed_url: parse_link(links, REL_SEED),
|
163
131
|
profile_url: parse_link(links, REL_PROFILE),
|
164
132
|
atom_url: parse_link(links, REL_ATOM),
|
165
133
|
salmon_url: parse_link(links, REL_SALMON),
|
166
134
|
|
167
|
-
subscribe_url: parse_link_template(links, REL_SUBSCRIBE)
|
168
|
-
|
169
|
-
# TODO: remove me! ##########
|
170
|
-
guid: parse_link(links, REL_GUID),
|
171
|
-
public_key: (Base64.strict_decode64(public_key) if public_key)
|
135
|
+
subscribe_url: parse_link_template(links, REL_SUBSCRIBE)
|
172
136
|
)
|
173
137
|
end
|
174
138
|
|
@@ -191,25 +155,31 @@ module DiasporaFederation
|
|
191
155
|
end
|
192
156
|
end
|
193
157
|
|
158
|
+
def to_xrd
|
159
|
+
XrdDocument.new.tap do |xrd|
|
160
|
+
xrd.subject = acct_uri
|
161
|
+
xrd.aliases.concat(additional_data[:aliases]) if additional_data[:aliases]
|
162
|
+
xrd.properties.merge!(additional_data[:properties]) if additional_data[:properties]
|
163
|
+
|
164
|
+
add_links_to(xrd)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
194
168
|
def add_links_to(doc)
|
195
|
-
doc.links << {rel: REL_HCARD, type: "text/html", href:
|
196
|
-
doc.links << {rel: REL_SEED, type: "text/html", href:
|
169
|
+
doc.links << {rel: REL_HCARD, type: "text/html", href: hcard_url}
|
170
|
+
doc.links << {rel: REL_SEED, type: "text/html", href: seed_url}
|
197
171
|
|
198
|
-
|
199
|
-
doc.links << {rel: REL_GUID, type: "text/html", href: @guid}
|
200
|
-
##################################
|
172
|
+
add_optional_links_to(doc)
|
201
173
|
|
202
|
-
doc.links
|
203
|
-
|
204
|
-
doc.links << {rel: REL_SALMON, href: @salmon_url}
|
174
|
+
doc.links.concat(additional_data[:links]) if additional_data[:links]
|
175
|
+
end
|
205
176
|
|
206
|
-
|
177
|
+
def add_optional_links_to(doc)
|
178
|
+
doc.links << {rel: REL_PROFILE, type: "text/html", href: profile_url} if profile_url
|
179
|
+
doc.links << {rel: REL_ATOM, type: "application/atom+xml", href: atom_url} if atom_url
|
180
|
+
doc.links << {rel: REL_SALMON, href: salmon_url} if salmon_url
|
207
181
|
|
208
|
-
|
209
|
-
doc.links << {rel: REL_PUBKEY,
|
210
|
-
type: "RSA",
|
211
|
-
href: Base64.strict_encode64(@public_key)}
|
212
|
-
##################################
|
182
|
+
doc.links << {rel: REL_SUBSCRIBE, template: subscribe_url} if subscribe_url
|
213
183
|
end
|
214
184
|
|
215
185
|
private_class_method def self.find_link(links, rel)
|
@@ -225,16 +195,6 @@ module DiasporaFederation
|
|
225
195
|
element = find_link(links, rel)
|
226
196
|
element ? element[:template] : nil
|
227
197
|
end
|
228
|
-
|
229
|
-
# This method is used to parse the alias_url from the XML.
|
230
|
-
# * redmatrix has sometimes no alias, return nil
|
231
|
-
# * old pods had quotes around the alias url, this can be removed later
|
232
|
-
# * friendica has two aliases and the first is with "acct:": return only an URL starting with http (or https)
|
233
|
-
private_class_method def self.parse_alias(aliases)
|
234
|
-
return nil unless aliases
|
235
|
-
# TODO: Old pods had quotes around alias. Remove the +map+ in next line, when all pods use this gem
|
236
|
-
aliases.map {|a| a.gsub(/\A"|"\Z/, "") }.find {|a| a.start_with?("http") }
|
237
|
-
end
|
238
198
|
end
|
239
199
|
end
|
240
200
|
end
|
@@ -32,7 +32,7 @@ module DiasporaFederation
|
|
32
32
|
XMLNS = "http://docs.oasis-open.org/ns/xri/xrd-1.0".freeze
|
33
33
|
|
34
34
|
# +Link+ element attributes
|
35
|
-
LINK_ATTRS = %i
|
35
|
+
LINK_ATTRS = %i[rel type href template].freeze
|
36
36
|
|
37
37
|
# format string for datetime (+Expires+ element)
|
38
38
|
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ".freeze
|
@@ -69,9 +69,9 @@ module DiasporaFederation
|
|
69
69
|
def to_xml
|
70
70
|
Nokogiri::XML::Builder.new(encoding: "UTF-8") {|xml|
|
71
71
|
xml.XRD("xmlns" => XMLNS) {
|
72
|
-
xml.Expires(
|
72
|
+
xml.Expires(expires.strftime(DATETIME_FORMAT)) if expires.instance_of?(DateTime)
|
73
73
|
|
74
|
-
xml.Subject(
|
74
|
+
xml.Subject(subject) if !subject.nil? && !subject.empty?
|
75
75
|
|
76
76
|
add_aliases_to(xml)
|
77
77
|
add_properties_to(xml)
|
@@ -80,6 +80,16 @@ module DiasporaFederation
|
|
80
80
|
}.to_xml
|
81
81
|
end
|
82
82
|
|
83
|
+
def to_json
|
84
|
+
{
|
85
|
+
subject: subject,
|
86
|
+
expires: expires,
|
87
|
+
aliases: (aliases if aliases.any?),
|
88
|
+
links: (links if links.any?),
|
89
|
+
properties: (properties if properties.any?)
|
90
|
+
}.reject {|_, v| v.nil? }
|
91
|
+
end
|
92
|
+
|
83
93
|
# Parse the XRD document from the given string and create a hash containing
|
84
94
|
# the extracted data.
|
85
95
|
#
|
@@ -107,23 +117,26 @@ module DiasporaFederation
|
|
107
117
|
|
108
118
|
private
|
109
119
|
|
120
|
+
attr_reader :expires
|
121
|
+
attr_reader :subject
|
122
|
+
|
110
123
|
NS = {xrd: XMLNS}.freeze
|
111
124
|
|
112
125
|
def add_aliases_to(xml)
|
113
|
-
|
126
|
+
aliases.each do |a|
|
114
127
|
next if !a.instance_of?(String) || a.empty?
|
115
128
|
xml.Alias(a.to_s)
|
116
129
|
end
|
117
130
|
end
|
118
131
|
|
119
132
|
def add_properties_to(xml)
|
120
|
-
|
133
|
+
properties.each do |type, val|
|
121
134
|
xml.Property(val.to_s, type: type)
|
122
135
|
end
|
123
136
|
end
|
124
137
|
|
125
138
|
def add_links_to(xml)
|
126
|
-
|
139
|
+
links.each do |l|
|
127
140
|
attrs = {}
|
128
141
|
LINK_ATTRS.each do |attr|
|
129
142
|
attrs[attr.to_s] = l[attr] if l.key?(attr)
|
@@ -135,7 +148,7 @@ module DiasporaFederation
|
|
135
148
|
private_class_method def self.parse_xrd_document(xrd_doc)
|
136
149
|
raise ArgumentError unless xrd_doc.instance_of?(String)
|
137
150
|
|
138
|
-
doc = Nokogiri::XML
|
151
|
+
doc = Nokogiri::XML(xrd_doc)
|
139
152
|
raise InvalidDocument, "Not an XRD document" if !doc.root || doc.root.name != "XRD"
|
140
153
|
doc
|
141
154
|
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module DiasporaFederation
|
2
|
+
module Entities
|
3
|
+
# This entity is sent when a person changes their diaspora* ID (e.g. when a user migration
|
4
|
+
# from one to another pod happens).
|
5
|
+
#
|
6
|
+
# @see Validators::AccountMigrationValidator
|
7
|
+
class AccountMigration < Entity
|
8
|
+
include Signable
|
9
|
+
|
10
|
+
# @!attribute [r] author
|
11
|
+
# The old diaspora* ID of the person who changes their ID
|
12
|
+
# @see Person#author
|
13
|
+
# @return [String] author diaspora* ID
|
14
|
+
property :author, :string
|
15
|
+
|
16
|
+
# @!attribute [r] profile
|
17
|
+
# Holds new updated profile of a person, including diaspora* ID
|
18
|
+
# @return [Person] person new data
|
19
|
+
entity :profile, Entities::Profile
|
20
|
+
|
21
|
+
# @!attribute [r] signature
|
22
|
+
# Signature that validates original and target diaspora* IDs with the new key of person
|
23
|
+
# @return [String] signature
|
24
|
+
property :signature, :string, default: nil
|
25
|
+
|
26
|
+
# @return [String] string representation of this object
|
27
|
+
def to_s
|
28
|
+
"AccountMigration:#{author}:#{profile.author}"
|
29
|
+
end
|
30
|
+
|
31
|
+
# Shortcut for calling super method with sensible arguments
|
32
|
+
#
|
33
|
+
# @see DiasporaFederation::Entities::Signable#verify_signature
|
34
|
+
def verify_signature
|
35
|
+
super(profile.author, :signature)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Calls super and additionally does signature verification for the instantiated entity.
|
39
|
+
#
|
40
|
+
# @see DiasporaFederation::Entity.from_hash
|
41
|
+
def self.from_hash(*args)
|
42
|
+
super.tap(&:verify_signature)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# @see DiasporaFederation::Entities::Signable#signature_data
|
48
|
+
def signature_data
|
49
|
+
to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def enriched_properties
|
53
|
+
super.tap do |hash|
|
54
|
+
hash[:signature] = signature || sign_with_new_key
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Sign with new user's key
|
59
|
+
# @raise [NewPrivateKeyNotFound] if the new user's private key is not found
|
60
|
+
# @return [String] A Base64 encoded signature of #signature_data with key
|
61
|
+
def sign_with_new_key
|
62
|
+
privkey = DiasporaFederation.callbacks.trigger(:fetch_private_key, profile.author)
|
63
|
+
raise NewPrivateKeyNotFound, "author=#{profile.author} obj=#{self}" if privkey.nil?
|
64
|
+
sign_with_key(privkey).tap do
|
65
|
+
logger.info "event=sign status=complete signature=signature author=#{profile.author} obj=#{self}"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# Raised, if creating the signature fails, because the new private key of a user was not found
|
70
|
+
class NewPrivateKeyNotFound < RuntimeError
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -4,10 +4,6 @@ module DiasporaFederation
|
|
4
4
|
#
|
5
5
|
# @see Validators::CommentValidator
|
6
6
|
class Comment < Entity
|
7
|
-
# Old signature order
|
8
|
-
# @deprecated
|
9
|
-
LEGACY_SIGNATURE_ORDER = %i(guid parent_guid text author).freeze
|
10
|
-
|
11
7
|
# The {Comment} parent is a {Post}
|
12
8
|
PARENT_TYPE = "Post".freeze
|
13
9
|
|
@@ -4,19 +4,11 @@ module DiasporaFederation
|
|
4
4
|
#
|
5
5
|
# @see Validators::EventParticipationValidator
|
6
6
|
class EventParticipation < Entity
|
7
|
-
# Old signature order
|
8
|
-
# @deprecated
|
9
|
-
LEGACY_SIGNATURE_ORDER = %i(author guid parent_guid status).freeze
|
10
|
-
|
11
7
|
# The {EventParticipation} parent is an {Event}
|
12
8
|
PARENT_TYPE = "Event".freeze
|
13
9
|
|
14
10
|
include Relayable
|
15
11
|
|
16
|
-
# Redefine the author property without +diaspora_handle+ +xml_name+
|
17
|
-
# @deprecated Can be removed after XMLs are generated with new names
|
18
|
-
property :author, :string
|
19
|
-
|
20
12
|
# @!attribute [r] status
|
21
13
|
# The participation status of the user
|
22
14
|
# "accepted", "declined" or "tentative"
|
@@ -4,24 +4,20 @@ module DiasporaFederation
|
|
4
4
|
#
|
5
5
|
# @see Validators::LikeValidator
|
6
6
|
class Like < Entity
|
7
|
-
# Old signature order
|
8
|
-
# @deprecated
|
9
|
-
LEGACY_SIGNATURE_ORDER = %i(positive guid parent_type parent_guid author).freeze
|
10
|
-
|
11
7
|
include Relayable
|
12
8
|
|
13
|
-
# @!attribute [r] positive
|
14
|
-
# If +true+ set a like, if +false+, set a dislike (dislikes are currently not
|
15
|
-
# implemented in the diaspora* frontend).
|
16
|
-
# @return [Boolean] is it a like or a dislike
|
17
|
-
property :positive, :boolean
|
18
|
-
|
19
9
|
# @!attribute [r] parent_type
|
20
10
|
# A string describing the type of the parent
|
21
11
|
# Can be "Post" or "Comment" (Comments are currently not implemented in the
|
22
12
|
# diaspora* frontend).
|
23
13
|
# @return [String] parent type
|
24
14
|
property :parent_type, :string, xml_name: :target_type
|
15
|
+
|
16
|
+
# @!attribute [r] positive
|
17
|
+
# If +true+ set a like, if +false+, set a dislike (dislikes are currently not
|
18
|
+
# implemented in the diaspora* frontend).
|
19
|
+
# @return [Boolean] is it a like or a dislike
|
20
|
+
property :positive, :boolean
|
25
21
|
end
|
26
22
|
end
|
27
23
|
end
|
@@ -4,11 +4,17 @@ module DiasporaFederation
|
|
4
4
|
#
|
5
5
|
# @see Validators::MessageValidator
|
6
6
|
class Message < Entity
|
7
|
-
#
|
8
|
-
#
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
# @!attribute [r] author
|
8
|
+
# The diaspora* ID of the author
|
9
|
+
# @see Person#author
|
10
|
+
# @return [String] diaspora* ID
|
11
|
+
property :author, :string, xml_name: :diaspora_handle
|
12
|
+
|
13
|
+
# @!attribute [r] guid
|
14
|
+
# A random string of at least 16 chars
|
15
|
+
# @see Validation::Rule::Guid
|
16
|
+
# @return [String] guid
|
17
|
+
property :guid, :string
|
12
18
|
|
13
19
|
# @!attribute [r] text
|
14
20
|
# Text of the message composed by a user
|
@@ -26,50 +32,9 @@ module DiasporaFederation
|
|
26
32
|
# @return [String] conversation guid
|
27
33
|
property :conversation_guid, :string
|
28
34
|
|
29
|
-
#
|
30
|
-
|
31
|
-
|
32
|
-
def sender_valid?(sender)
|
33
|
-
sender == author || (sender == parent_author && verify_author_signature)
|
34
|
-
end
|
35
|
-
|
36
|
-
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
37
|
-
def to_h
|
38
|
-
super.tap {|hash| hash[:created_at] = created_at.utc.iso8601 }
|
39
|
-
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
44
|
-
def verify_author_signature
|
45
|
-
verify_signature(author, :author_signature)
|
46
|
-
true
|
47
|
-
end
|
48
|
-
|
49
|
-
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
50
|
-
def parent_author
|
51
|
-
parent = DiasporaFederation.callbacks.trigger(:fetch_related_entity, "Conversation", conversation_guid)
|
52
|
-
raise Federation::Fetcher::NotFetchable, "parent of #{self} not found" unless parent
|
53
|
-
parent.author
|
54
|
-
end
|
55
|
-
|
56
|
-
# old timestamp format, because this signature is only used from old pods which also relay with old format
|
57
|
-
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
58
|
-
def normalize_property(name, value)
|
59
|
-
if name == :created_at
|
60
|
-
value.to_s
|
61
|
-
else
|
62
|
-
super
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Default implementation, don't verify signatures for a {Message}.
|
67
|
-
# @see Entity.populate_entity
|
68
|
-
# @deprecated remove after {Message} doesn't include {Relayable} anymore
|
69
|
-
# @param [Nokogiri::XML::Element] root_node xml nodes
|
70
|
-
# @return [Entity] instance
|
71
|
-
private_class_method def self.populate_entity(root_node)
|
72
|
-
new({parent_guid: nil, parent: nil}.merge(entity_data(root_node)))
|
35
|
+
# @return [String] string representation of this object
|
36
|
+
def to_s
|
37
|
+
"#{super}:#{conversation_guid}"
|
73
38
|
end
|
74
39
|
end
|
75
40
|
end
|