diaspora_federation 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +28 -0
- data/README.md +2 -1
- data/lib/diaspora_federation.rb +14 -14
- data/lib/diaspora_federation/callbacks.rb +4 -4
- data/lib/diaspora_federation/discovery.rb +1 -1
- data/lib/diaspora_federation/discovery/discovery.rb +8 -8
- data/lib/diaspora_federation/discovery/h_card.rb +11 -12
- data/lib/diaspora_federation/discovery/host_meta.rb +2 -2
- data/lib/diaspora_federation/discovery/web_finger.rb +10 -13
- data/lib/diaspora_federation/discovery/xrd_document.rb +1 -1
- data/lib/diaspora_federation/entities.rb +2 -2
- data/lib/diaspora_federation/entities/account_deletion.rb +4 -4
- data/lib/diaspora_federation/entities/comment.rb +3 -3
- data/lib/diaspora_federation/entities/contact.rb +4 -4
- data/lib/diaspora_federation/entities/conversation.rb +13 -13
- data/lib/diaspora_federation/entities/like.rb +5 -5
- data/lib/diaspora_federation/entities/location.rb +1 -1
- data/lib/diaspora_federation/entities/message.rb +5 -5
- data/lib/diaspora_federation/entities/participation.rb +6 -6
- data/lib/diaspora_federation/entities/person.rb +6 -6
- data/lib/diaspora_federation/entities/photo.rb +10 -10
- data/lib/diaspora_federation/entities/poll.rb +3 -3
- data/lib/diaspora_federation/entities/poll_answer.rb +2 -2
- data/lib/diaspora_federation/entities/poll_participation.rb +3 -3
- data/lib/diaspora_federation/entities/post.rb +7 -7
- data/lib/diaspora_federation/entities/profile.rb +6 -6
- data/lib/diaspora_federation/entities/related_entity.rb +4 -4
- data/lib/diaspora_federation/entities/relayable.rb +32 -24
- data/lib/diaspora_federation/entities/relayable_retraction.rb +17 -17
- data/lib/diaspora_federation/entities/request.rb +5 -5
- data/lib/diaspora_federation/entities/reshare.rb +7 -7
- data/lib/diaspora_federation/entities/retraction.rb +6 -6
- data/lib/diaspora_federation/entities/signed_retraction.rb +8 -8
- data/lib/diaspora_federation/entities/status_message.rb +8 -8
- data/lib/diaspora_federation/entity.rb +7 -7
- data/lib/diaspora_federation/federation/fetcher.rb +3 -3
- data/lib/diaspora_federation/federation/receiver.rb +3 -3
- data/lib/diaspora_federation/federation/receiver/abstract_receiver.rb +3 -3
- data/lib/diaspora_federation/federation/receiver/private.rb +1 -1
- data/lib/diaspora_federation/federation/receiver/public.rb +1 -1
- data/lib/diaspora_federation/federation/sender/hydra_wrapper.rb +7 -6
- data/lib/diaspora_federation/http_client.rb +2 -2
- data/lib/diaspora_federation/logging.rb +7 -7
- data/lib/diaspora_federation/properties_dsl.rb +3 -3
- data/lib/diaspora_federation/salmon.rb +1 -1
- data/lib/diaspora_federation/salmon/aes.rb +4 -4
- data/lib/diaspora_federation/salmon/encrypted_slap.rb +9 -9
- data/lib/diaspora_federation/salmon/magic_envelope.rb +16 -16
- data/lib/diaspora_federation/salmon/slap.rb +2 -2
- data/lib/diaspora_federation/validators.rb +1 -1
- data/lib/diaspora_federation/validators/account_deletion_validator.rb +1 -1
- data/lib/diaspora_federation/validators/comment_validator.rb +1 -1
- data/lib/diaspora_federation/validators/contact_validator.rb +1 -1
- data/lib/diaspora_federation/validators/conversation_validator.rb +4 -4
- data/lib/diaspora_federation/validators/h_card_validator.rb +2 -2
- data/lib/diaspora_federation/validators/like_validator.rb +1 -1
- data/lib/diaspora_federation/validators/location_validator.rb +1 -1
- data/lib/diaspora_federation/validators/message_validator.rb +4 -1
- data/lib/diaspora_federation/validators/participation_validator.rb +1 -1
- data/lib/diaspora_federation/validators/person_validator.rb +1 -1
- data/lib/diaspora_federation/validators/photo_validator.rb +3 -1
- data/lib/diaspora_federation/validators/poll_answer_validator.rb +1 -1
- data/lib/diaspora_federation/validators/poll_participation_validator.rb +1 -1
- data/lib/diaspora_federation/validators/poll_validator.rb +1 -1
- data/lib/diaspora_federation/validators/profile_validator.rb +3 -3
- data/lib/diaspora_federation/validators/related_entity_validator.rb +1 -1
- data/lib/diaspora_federation/validators/relayable_retraction_validator.rb +2 -2
- data/lib/diaspora_federation/validators/relayable_validator.rb +2 -2
- data/lib/diaspora_federation/validators/request_validator.rb +2 -2
- data/lib/diaspora_federation/validators/reshare_validator.rb +1 -1
- data/lib/diaspora_federation/validators/retraction_validator.rb +1 -1
- data/lib/diaspora_federation/validators/rules/birthday.rb +2 -2
- data/lib/diaspora_federation/validators/rules/boolean.rb +1 -1
- data/lib/diaspora_federation/validators/rules/diaspora_id.rb +5 -5
- data/lib/diaspora_federation/validators/rules/diaspora_id_count.rb +3 -3
- data/lib/diaspora_federation/validators/rules/guid.rb +4 -4
- data/lib/diaspora_federation/validators/rules/not_nil.rb +1 -1
- data/lib/diaspora_federation/validators/rules/public_key.rb +1 -1
- data/lib/diaspora_federation/validators/rules/tag_count.rb +2 -2
- data/lib/diaspora_federation/validators/signed_retraction_validator.rb +2 -2
- data/lib/diaspora_federation/validators/status_message_validator.rb +3 -1
- data/lib/diaspora_federation/validators/web_finger_validator.rb +3 -3
- data/lib/diaspora_federation/version.rb +1 -1
- metadata +3 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
module DiasporaFederation
|
2
2
|
# +Entity+ is the base class for all other objects used to encapsulate data
|
3
|
-
# for federation messages in the
|
3
|
+
# for federation messages in the diaspora* network.
|
4
4
|
# Entity fields are specified using a simple {PropertiesDSL DSL} as part of
|
5
5
|
# the class definition.
|
6
6
|
#
|
@@ -231,7 +231,7 @@ module DiasporaFederation
|
|
231
231
|
end
|
232
232
|
end
|
233
233
|
|
234
|
-
#
|
234
|
+
# Create simple node, fill it with text and append to root
|
235
235
|
def simple_node(doc, name, value)
|
236
236
|
xml_name = self.class.xml_names[name]
|
237
237
|
Nokogiri::XML::Element.new(xml_name ? xml_name.to_s : name, doc).tap do |node|
|
@@ -268,7 +268,7 @@ module DiasporaFederation
|
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
-
#
|
271
|
+
# Create simple entry in data hash
|
272
272
|
#
|
273
273
|
# @param [String] name xml tag to parse
|
274
274
|
# @param [Nokogiri::XML::Element] root_node XML root_node to parse
|
@@ -279,24 +279,24 @@ module DiasporaFederation
|
|
279
279
|
node.first.text if node.any?
|
280
280
|
end
|
281
281
|
|
282
|
-
#
|
282
|
+
# Create an entry in the data hash for the nested entity
|
283
283
|
#
|
284
284
|
# @param [Class] type target type to parse
|
285
285
|
# @param [Nokogiri::XML::Element] root_node XML node to parse
|
286
286
|
# @return [Entity] parsed child entity
|
287
287
|
private_class_method def self.parse_entity_from_node(type, root_node)
|
288
288
|
node = root_node.xpath(type.entity_name)
|
289
|
-
type.from_xml(node.first) if node.any?
|
289
|
+
type.from_xml(node.first) if node.any? && node.first.children.any?
|
290
290
|
end
|
291
291
|
|
292
|
-
#
|
292
|
+
# Collect all nested children of that type and create an array in the data hash
|
293
293
|
#
|
294
294
|
# @param [Class] type target type to parse
|
295
295
|
# @param [Nokogiri::XML::Element] root_node XML node to parse
|
296
296
|
# @return [Array<Entity>] array with parsed child entities
|
297
297
|
private_class_method def self.parse_array_from_node(type, root_node)
|
298
298
|
node = root_node.xpath(type.entity_name)
|
299
|
-
node.map {|child| type.from_xml(child) } unless node.empty?
|
299
|
+
node.select {|child| child.children.any? }.map {|child| type.from_xml(child) } unless node.empty?
|
300
300
|
end
|
301
301
|
|
302
302
|
# Raised, if entity is not valid
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module DiasporaFederation
|
2
2
|
module Federation
|
3
|
-
#
|
3
|
+
# This module is for fetching entities from other pods.
|
4
4
|
module Fetcher
|
5
|
-
#
|
6
|
-
# @param [String] author the diaspora ID of the author of the entity
|
5
|
+
# Fetches a public entity from a remote pod
|
6
|
+
# @param [String] author the diaspora* ID of the author of the entity
|
7
7
|
# @param [Symbol, String] entity_type snake_case version of the entity class
|
8
8
|
# @param [String] guid guid of the entity to fetch
|
9
9
|
def self.fetch_public(author, entity_type, guid)
|
@@ -1,10 +1,10 @@
|
|
1
1
|
module DiasporaFederation
|
2
2
|
module Federation
|
3
|
-
#
|
3
|
+
# This module parses and receives entities.
|
4
4
|
module Receiver
|
5
5
|
extend Logging
|
6
6
|
|
7
|
-
#
|
7
|
+
# Receive a public message
|
8
8
|
# @param [String] data message to receive
|
9
9
|
# @param [Boolean] legacy use old slap parser
|
10
10
|
def self.receive_public(data, legacy=false)
|
@@ -21,7 +21,7 @@ module DiasporaFederation
|
|
21
21
|
raise e
|
22
22
|
end
|
23
23
|
|
24
|
-
#
|
24
|
+
# Receive a private message
|
25
25
|
# @param [String] data message to receive
|
26
26
|
# @param [OpenSSL::PKey::RSA] recipient_private_key recipient private key to decrypt the message
|
27
27
|
# @param [Object] recipient_id the identifier to persist the entity for the correct user,
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module DiasporaFederation
|
2
2
|
module Federation
|
3
3
|
module Receiver
|
4
|
-
#
|
4
|
+
# Common functionality for receivers
|
5
5
|
class AbstractReceiver
|
6
6
|
include Logging
|
7
7
|
|
8
|
-
#
|
8
|
+
# Creates a new receiver
|
9
9
|
# @param [MagicEnvelope] magic_envelope the received magic envelope
|
10
10
|
# @param [Object] recipient_id the identifier of the recipient of a private message
|
11
11
|
def initialize(magic_envelope, recipient_id=nil)
|
@@ -14,7 +14,7 @@ module DiasporaFederation
|
|
14
14
|
@recipient_id = recipient_id
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
17
|
+
# Validates and receives the entity
|
18
18
|
def receive
|
19
19
|
validate_and_receive
|
20
20
|
rescue => e
|
@@ -11,12 +11,13 @@ module DiasporaFederation
|
|
11
11
|
# @return [Hash] hydra opts
|
12
12
|
def self.hydra_opts
|
13
13
|
@hydra_opts ||= {
|
14
|
-
maxredirs:
|
15
|
-
timeout:
|
16
|
-
method:
|
17
|
-
verbose:
|
18
|
-
cainfo:
|
19
|
-
|
14
|
+
maxredirs: DiasporaFederation.http_redirect_limit,
|
15
|
+
timeout: DiasporaFederation.http_timeout,
|
16
|
+
method: :post,
|
17
|
+
verbose: DiasporaFederation.http_verbose,
|
18
|
+
cainfo: DiasporaFederation.certificate_authorities,
|
19
|
+
forbid_reuse: true,
|
20
|
+
headers: {
|
20
21
|
"Expect" => "",
|
21
22
|
"Transfer-Encoding" => "",
|
22
23
|
"User-Agent" => DiasporaFederation.http_user_agent
|
@@ -2,7 +2,7 @@ require "faraday"
|
|
2
2
|
require "faraday_middleware/response/follow_redirects"
|
3
3
|
|
4
4
|
module DiasporaFederation
|
5
|
-
# A wrapper for {https://github.com/lostisland/faraday Faraday}
|
5
|
+
# A wrapper for {https://github.com/lostisland/faraday Faraday}
|
6
6
|
#
|
7
7
|
# @see Discovery::Discovery
|
8
8
|
# @see Federation::Fetcher
|
@@ -15,7 +15,7 @@ module DiasporaFederation
|
|
15
15
|
connection.get(uri)
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
18
|
+
# Gets the Faraday connection
|
19
19
|
#
|
20
20
|
# @return [Faraday::Connection] the response
|
21
21
|
def self.connection
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module DiasporaFederation
|
2
|
-
#
|
2
|
+
# Logging module for the diaspora* federation
|
3
3
|
#
|
4
|
-
#
|
4
|
+
# It uses the logging-gem if available.
|
5
5
|
module Logging
|
6
|
-
#
|
6
|
+
# Add +logger+ also as class method when included
|
7
7
|
# @param [Class] klass the class into which the module is included
|
8
8
|
def self.included(klass)
|
9
9
|
klass.extend(self)
|
@@ -11,15 +11,15 @@ module DiasporaFederation
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
#
|
14
|
+
# Get the logger for this class
|
15
15
|
#
|
16
|
-
#
|
16
|
+
# Use the logging-gem if available, else use a default logger.
|
17
17
|
def logger
|
18
18
|
@logger ||= begin
|
19
|
-
#
|
19
|
+
# Use logging-gem if available
|
20
20
|
return ::Logging::Logger[self] if defined?(::Logging::Logger)
|
21
21
|
|
22
|
-
#
|
22
|
+
# Use rails logger if running in rails and no logging-gem is available
|
23
23
|
return ::Rails.logger if defined?(::Rails)
|
24
24
|
|
25
25
|
# fallback logger
|
@@ -75,7 +75,7 @@ module DiasporaFederation
|
|
75
75
|
@xml_names ||= {}
|
76
76
|
end
|
77
77
|
|
78
|
-
#
|
78
|
+
# Finds a property by +xml_name+ or +name+
|
79
79
|
# @param [String] xml_name name of the property from the received xml
|
80
80
|
# @return [Hash] the property data
|
81
81
|
def find_property_for_xml_name(xml_name)
|
@@ -114,14 +114,14 @@ module DiasporaFederation
|
|
114
114
|
define_alias(name, opts[:alias]) if opts.has_key? :alias
|
115
115
|
end
|
116
116
|
|
117
|
-
#
|
117
|
+
# Checks if the name is a +Symbol+ or a +String+
|
118
118
|
# @param [String, Symbol] name the name to check
|
119
119
|
# @return [Boolean]
|
120
120
|
def name_valid?(name)
|
121
121
|
name.instance_of?(Symbol)
|
122
122
|
end
|
123
123
|
|
124
|
-
#
|
124
|
+
# Checks if the type extends {Entity}
|
125
125
|
# @param [Class] type the type to check
|
126
126
|
# @return [Boolean]
|
127
127
|
def type_valid?(type)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module DiasporaFederation
|
2
|
-
# This module contains a
|
2
|
+
# This module contains a diaspora*-specific implementation of parts of the
|
3
3
|
# {http://www.salmon-protocol.org/ Salmon Protocol}.
|
4
4
|
module Salmon
|
5
5
|
# XML namespace url
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module DiasporaFederation
|
2
2
|
module Salmon
|
3
|
-
#
|
3
|
+
# Class for AES encryption and decryption
|
4
4
|
class AES
|
5
5
|
# OpenSSL aes cipher definition
|
6
6
|
CIPHER = "AES-256-CBC".freeze
|
7
7
|
|
8
|
-
#
|
8
|
+
# Generates a random AES key and initialization vector
|
9
9
|
# @return [Hash] { key: "...", iv: "..." }
|
10
10
|
def self.generate_key_and_iv
|
11
11
|
cipher = OpenSSL::Cipher.new(CIPHER)
|
12
12
|
{key: cipher.random_key, iv: cipher.random_iv}
|
13
13
|
end
|
14
14
|
|
15
|
-
#
|
15
|
+
# Encrypts the given data with an AES cipher defined by the given key
|
16
16
|
# and iv and returns the resulting ciphertext base64 strict_encoded.
|
17
17
|
# @param [String] data plain input
|
18
18
|
# @param [String] key AES key
|
@@ -34,7 +34,7 @@ module DiasporaFederation
|
|
34
34
|
Base64.strict_encode64(ciphertext)
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
37
|
+
# Decrypts the given ciphertext with an AES cipher defined by the given key
|
38
38
|
# and iv. +ciphertext+ is expected to be base64 encoded
|
39
39
|
# @param [String] ciphertext input data
|
40
40
|
# @param [String] key AES key
|
@@ -3,14 +3,14 @@ require "json"
|
|
3
3
|
module DiasporaFederation
|
4
4
|
module Salmon
|
5
5
|
# +EncryptedSlap+ provides class methods for generating and parsing encrypted
|
6
|
-
# Slaps. (In principle the same as
|
6
|
+
# Slaps. (In principle the same as {Slap}, but with encryption.)
|
7
7
|
#
|
8
8
|
# The basic encryption mechanism used here is based on the knowledge that
|
9
9
|
# asymmetrical encryption is slow and symmetrical encryption is fast. Keeping in
|
10
10
|
# mind that a message we want to de-/encrypt may greatly vary in length,
|
11
11
|
# performance considerations must play a part of this scheme.
|
12
12
|
#
|
13
|
-
# A
|
13
|
+
# A diaspora*-flavored encrypted magic-enveloped XML message looks like the following:
|
14
14
|
#
|
15
15
|
# <?xml version="1.0" encoding="UTF-8"?>
|
16
16
|
# <diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env">
|
@@ -63,7 +63,7 @@ module DiasporaFederation
|
|
63
63
|
# @deprecated
|
64
64
|
class EncryptedSlap < Slap
|
65
65
|
# the author of the slap
|
66
|
-
# @param [String] value the author diaspora
|
66
|
+
# @param [String] value the author diaspora* ID
|
67
67
|
attr_writer :author_id
|
68
68
|
|
69
69
|
# the key and iv if it is an encrypted slap
|
@@ -100,7 +100,7 @@ module DiasporaFederation
|
|
100
100
|
|
101
101
|
# Creates an encrypted Salmon Slap.
|
102
102
|
#
|
103
|
-
# @param [String] author_id
|
103
|
+
# @param [String] author_id diaspora* ID of the author
|
104
104
|
# @param [OpenSSL::PKey::RSA] privkey sender private key for signing the magic envelope
|
105
105
|
# @param [Entity] entity payload
|
106
106
|
# @return [EncryptedSlap] encrypted Slap instance
|
@@ -136,7 +136,7 @@ module DiasporaFederation
|
|
136
136
|
|
137
137
|
private
|
138
138
|
|
139
|
-
#
|
139
|
+
# Decrypts and reads the data from the encrypted XML header
|
140
140
|
# @param [String] data base64 encoded, encrypted header data
|
141
141
|
# @param [OpenSSL::PKey::RSA] privkey private key for decryption
|
142
142
|
# @return [Hash] { iv: "...", aes_key: "...", author_id: "..." }
|
@@ -151,7 +151,7 @@ module DiasporaFederation
|
|
151
151
|
{iv: iv, aes_key: key, author_id: author_id}
|
152
152
|
end
|
153
153
|
|
154
|
-
#
|
154
|
+
# Decrypts the xml header
|
155
155
|
# @param [String] data base64 encoded, encrypted header data
|
156
156
|
# @param [OpenSSL::PKey::RSA] privkey private key for decryption
|
157
157
|
# @return [Nokogiri::XML::Element] header xml document
|
@@ -163,8 +163,8 @@ module DiasporaFederation
|
|
163
163
|
Nokogiri::XML::Document.parse(xml).root
|
164
164
|
end
|
165
165
|
|
166
|
-
#
|
167
|
-
# with the recipients public_key
|
166
|
+
# Encrypt the header xml with an AES cipher and encrypt the cipher params
|
167
|
+
# with the recipients public_key.
|
168
168
|
# @param [String] author_id diaspora_handle
|
169
169
|
# @param [Hash] envelope_key envelope cipher params
|
170
170
|
# @param [OpenSSL::PKey::RSA] pubkey recipient public_key
|
@@ -182,7 +182,7 @@ module DiasporaFederation
|
|
182
182
|
Base64.strict_encode64(json_header)
|
183
183
|
end
|
184
184
|
|
185
|
-
#
|
185
|
+
# Generate the header xml string, including the author, aes_key and iv
|
186
186
|
# @param [String] author_id diaspora_handle of the author
|
187
187
|
# @param [Hash] envelope_key { key: "...", iv: "..." } (values in base64)
|
188
188
|
# @return [String] header XML string
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module DiasporaFederation
|
2
2
|
module Salmon
|
3
|
-
# Represents a Magic Envelope for
|
3
|
+
# Represents a Magic Envelope for diaspora* federation messages
|
4
4
|
#
|
5
5
|
# When generating a Magic Envelope, an instance of this class is created and
|
6
6
|
# the contents are specified on initialization. Optionally, the payload can be
|
@@ -23,26 +23,26 @@ module DiasporaFederation
|
|
23
23
|
class MagicEnvelope
|
24
24
|
include Logging
|
25
25
|
|
26
|
-
#
|
26
|
+
# Encoding used for the payload data
|
27
27
|
ENCODING = "base64url".freeze
|
28
28
|
|
29
|
-
#
|
29
|
+
# Algorithm used for signing the payload data
|
30
30
|
ALGORITHM = "RSA-SHA256".freeze
|
31
31
|
|
32
|
-
#
|
32
|
+
# Mime type describing the payload data
|
33
33
|
DATA_TYPE = "application/xml".freeze
|
34
34
|
|
35
|
-
#
|
35
|
+
# Digest instance used for signing
|
36
36
|
DIGEST = OpenSSL::Digest::SHA256.new
|
37
37
|
|
38
38
|
# XML namespace url
|
39
39
|
XMLNS = "http://salmon-protocol.org/ns/magic-env".freeze
|
40
40
|
|
41
|
-
#
|
41
|
+
# The payload entity of the magic envelope
|
42
42
|
# @return [Entity] payload entity
|
43
43
|
attr_reader :payload
|
44
44
|
|
45
|
-
#
|
45
|
+
# The sender of the magic envelope
|
46
46
|
# @return [String] diaspora-ID of the sender
|
47
47
|
attr_reader :sender
|
48
48
|
|
@@ -101,7 +101,7 @@ module DiasporaFederation
|
|
101
101
|
# @see AES#decrypt
|
102
102
|
#
|
103
103
|
# @param [Nokogiri::XML::Element] magic_env XML root node of a magic envelope
|
104
|
-
# @param [String] sender diaspora
|
104
|
+
# @param [String] sender diaspora* ID of the sender or nil
|
105
105
|
# @param [Hash] cipher_params hash containing the key and iv for
|
106
106
|
# AES-decrypting previously encrypted data. E.g.: { iv: "...", key: "..." }
|
107
107
|
#
|
@@ -132,7 +132,7 @@ module DiasporaFederation
|
|
132
132
|
|
133
133
|
private
|
134
134
|
|
135
|
-
#
|
135
|
+
# The payload data as string
|
136
136
|
# @return [String] payload data
|
137
137
|
def payload_data
|
138
138
|
@payload_data ||= XmlPayload.pack(@payload).to_xml.strip.tap do |data|
|
@@ -155,7 +155,7 @@ module DiasporaFederation
|
|
155
155
|
}.doc.root
|
156
156
|
end
|
157
157
|
|
158
|
-
#
|
158
|
+
# Creates the signature for all fields according to specification
|
159
159
|
#
|
160
160
|
# @param [OpenSSL::PKey::RSA] privkey private key used for signing
|
161
161
|
# @return [String] the signature
|
@@ -173,7 +173,7 @@ module DiasporaFederation
|
|
173
173
|
end
|
174
174
|
|
175
175
|
# @param [Nokogiri::XML::Element] env magic envelope XML
|
176
|
-
# @param [String] sender diaspora
|
176
|
+
# @param [String] sender diaspora* ID of the sender or nil
|
177
177
|
# @return [Boolean]
|
178
178
|
private_class_method def self.signature_valid?(env, sender)
|
179
179
|
subject = sig_subject([Base64.urlsafe_decode64(env.at_xpath("me:data").content),
|
@@ -188,18 +188,18 @@ module DiasporaFederation
|
|
188
188
|
sender_key.verify(DIGEST, sig, subject)
|
189
189
|
end
|
190
190
|
|
191
|
-
#
|
191
|
+
# Reads the +key_id+ from the magic envelope.
|
192
192
|
# @param [Nokogiri::XML::Element] env magic envelope XML
|
193
|
-
# @return [String] diaspora
|
193
|
+
# @return [String] diaspora* ID of the sender
|
194
194
|
private_class_method def self.sender(env)
|
195
195
|
key_id = env.at_xpath("me:sig")["key_id"]
|
196
196
|
raise InvalidEnvelope, "no key_id" unless key_id # TODO: move to `envelope_valid?`
|
197
197
|
Base64.urlsafe_decode64(key_id)
|
198
198
|
end
|
199
199
|
|
200
|
-
#
|
201
|
-
#
|
202
|
-
# and the algorithm
|
200
|
+
# Constructs the signature subject.
|
201
|
+
# The given array should consist of the data, data_type (mimetype), encoding
|
202
|
+
# and the algorithm.
|
203
203
|
# @param [Array<String>] data_arr
|
204
204
|
# @return [String] signature subject
|
205
205
|
private_class_method def self.sig_subject(data_arr)
|
@@ -3,7 +3,7 @@ module DiasporaFederation
|
|
3
3
|
# +Slap+ provides class methods to create unencrypted Slap XML from payload
|
4
4
|
# data and parse incoming XML into a Slap instance.
|
5
5
|
#
|
6
|
-
# A
|
6
|
+
# A diaspora* flavored magic-enveloped XML message looks like the following:
|
7
7
|
#
|
8
8
|
# <?xml version="1.0" encoding="UTF-8"?>
|
9
9
|
# <diaspora xmlns="https://joindiaspora.com/protocol" xmlns:me="http://salmon-protocol.org/ns/magic-env">
|
@@ -51,7 +51,7 @@ module DiasporaFederation
|
|
51
51
|
|
52
52
|
# Creates an unencrypted Salmon Slap and returns the XML string.
|
53
53
|
#
|
54
|
-
# @param [String] author_id
|
54
|
+
# @param [String] author_id diaspora* ID of the author
|
55
55
|
# @param [OpenSSL::PKey::RSA] privkey sender private_key for signing the magic envelope
|
56
56
|
# @param [Entity] entity payload
|
57
57
|
# @return [String] Salmon XML string
|