diaspora_federation 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -1
  3. data/lib/diaspora_federation.rb +66 -1
  4. data/lib/diaspora_federation/discovery/h_card.rb +2 -3
  5. data/lib/diaspora_federation/discovery/web_finger.rb +3 -6
  6. data/lib/diaspora_federation/entities.rb +18 -0
  7. data/lib/diaspora_federation/entities/account_deletion.rb +14 -0
  8. data/lib/diaspora_federation/entities/comment.rb +26 -0
  9. data/lib/diaspora_federation/entities/conversation.rb +38 -0
  10. data/lib/diaspora_federation/entities/like.rb +35 -0
  11. data/lib/diaspora_federation/entities/location.rb +23 -0
  12. data/lib/diaspora_federation/entities/message.rb +38 -0
  13. data/lib/diaspora_federation/entities/participation.rb +28 -0
  14. data/lib/diaspora_federation/entities/person.rb +6 -3
  15. data/lib/diaspora_federation/entities/photo.rb +59 -0
  16. data/lib/diaspora_federation/entities/poll.rb +24 -0
  17. data/lib/diaspora_federation/entities/poll_answer.rb +19 -0
  18. data/lib/diaspora_federation/entities/poll_participation.rb +28 -0
  19. data/lib/diaspora_federation/entities/profile.rb +10 -8
  20. data/lib/diaspora_federation/entities/relayable.rb +101 -0
  21. data/lib/diaspora_federation/entities/relayable_retraction.rb +95 -0
  22. data/lib/diaspora_federation/entities/request.rb +21 -0
  23. data/lib/diaspora_federation/entities/reshare.rb +49 -0
  24. data/lib/diaspora_federation/entities/retraction.rb +24 -0
  25. data/lib/diaspora_federation/entities/signed_retraction.rb +66 -0
  26. data/lib/diaspora_federation/entities/status_message.rb +55 -0
  27. data/lib/diaspora_federation/entity.rb +5 -6
  28. data/lib/diaspora_federation/fetcher.rb +1 -2
  29. data/lib/diaspora_federation/properties_dsl.rb +18 -8
  30. data/lib/diaspora_federation/salmon.rb +17 -0
  31. data/lib/diaspora_federation/salmon/aes.rb +58 -0
  32. data/lib/diaspora_federation/salmon/encrypted_slap.rb +187 -0
  33. data/lib/diaspora_federation/salmon/exceptions.rb +50 -0
  34. data/lib/diaspora_federation/salmon/magic_envelope.rb +191 -0
  35. data/lib/diaspora_federation/salmon/slap.rb +128 -0
  36. data/lib/diaspora_federation/salmon/xml_payload.rb +158 -0
  37. data/lib/diaspora_federation/signing.rb +56 -0
  38. data/lib/diaspora_federation/validators.rb +20 -0
  39. data/lib/diaspora_federation/validators/account_deletion_validator.rb +10 -0
  40. data/lib/diaspora_federation/validators/comment_validator.rb +17 -0
  41. data/lib/diaspora_federation/validators/conversation_validator.rb +14 -0
  42. data/lib/diaspora_federation/validators/like_validator.rb +14 -0
  43. data/lib/diaspora_federation/validators/location_validator.rb +11 -0
  44. data/lib/diaspora_federation/validators/message_validator.rb +16 -0
  45. data/lib/diaspora_federation/validators/participation_validator.rb +16 -0
  46. data/lib/diaspora_federation/validators/photo_validator.rb +24 -0
  47. data/lib/diaspora_federation/validators/poll_answer_validator.rb +11 -0
  48. data/lib/diaspora_federation/validators/poll_participation_validator.rb +16 -0
  49. data/lib/diaspora_federation/validators/poll_validator.rb +11 -0
  50. data/lib/diaspora_federation/validators/relayable_retraction_validator.rb +15 -0
  51. data/lib/diaspora_federation/validators/relayable_validator.rb +14 -0
  52. data/lib/diaspora_federation/validators/request_validator.rb +11 -0
  53. data/lib/diaspora_federation/validators/reshare_validator.rb +18 -0
  54. data/lib/diaspora_federation/validators/retraction_validator.rb +14 -0
  55. data/lib/diaspora_federation/validators/rules/diaspora_id_count.rb +37 -0
  56. data/lib/diaspora_federation/validators/signed_retraction_validator.rb +15 -0
  57. data/lib/diaspora_federation/validators/status_message_validator.rb +14 -0
  58. data/lib/diaspora_federation/version.rb +1 -1
  59. metadata +49 -4
@@ -0,0 +1,56 @@
1
+ module DiasporaFederation
2
+ # this module defines operations of signing an arbitrary hash with an arbitrary key
3
+ module Signing
4
+ extend Logging
5
+
6
+ # Sign the data with the key
7
+ #
8
+ # @param [Hash] hash data to sign
9
+ # @param [OpenSSL::PKey::RSA] key An RSA key
10
+ # @return [String] A Base64 encoded signature of #signable_string with key
11
+ def self.sign_with_key(hash, key)
12
+ sig = Base64.strict_encode64(
13
+ key.sign(
14
+ OpenSSL::Digest::SHA256.new,
15
+ signable_string(hash)
16
+ )
17
+ )
18
+ logger.info "event=sign_with_key status=complete guid=#{hash[:guid]}"
19
+ sig
20
+ end
21
+
22
+ # Check that signature is a correct signature
23
+ #
24
+ # @param [Hash] hash data to verify
25
+ # @param [String] signature The signature to be verified.
26
+ # @param [OpenSSL::PKey::RSA] key An RSA key
27
+ # @return [Boolean]
28
+ def self.verify_signature(hash, signature, key)
29
+ if key.nil?
30
+ logger.warn "event=verify_signature status=abort reason=no_key guid=#{hash[:guid]}"
31
+ return false
32
+ elsif signature.nil?
33
+ logger.warn "event=verify_signature status=abort reason=no_signature guid=#{hash[:guid]}"
34
+ return false
35
+ end
36
+
37
+ validity = key.verify(
38
+ OpenSSL::Digest::SHA256.new,
39
+ Base64.decode64(signature),
40
+ signable_string(hash)
41
+ )
42
+ logger.info "event=verify_signature status=complete guid=#{hash[:guid]} validity=#{validity}"
43
+ validity
44
+ end
45
+
46
+ private
47
+
48
+ # @param [Hash] hash data to sign
49
+ # @return [String] signature data string
50
+ def self.signable_string(hash)
51
+ hash.map { |name, value|
52
+ value.to_s unless name.match(/signature/)
53
+ }.compact.join(";")
54
+ end
55
+ end
56
+ end
@@ -3,6 +3,7 @@ require "validation/rule/regular_expression"
3
3
  require "validation/rule/length"
4
4
  require "validation/rule/not_empty"
5
5
  require "validation/rule/uri"
6
+ require "validation/rule/numeric"
6
7
 
7
8
  # +valid+ gem namespace
8
9
  module Validation
@@ -22,6 +23,7 @@ require "diaspora_federation/validators/rules/guid"
22
23
  require "diaspora_federation/validators/rules/not_nil"
23
24
  require "diaspora_federation/validators/rules/public_key"
24
25
  require "diaspora_federation/validators/rules/tag_count"
26
+ require "diaspora_federation/validators/rules/diaspora_id_count"
25
27
 
26
28
  module DiasporaFederation
27
29
  # Validators to perform basic sanity-checks on {DiasporaFederation::Entities federation entities}.
@@ -32,7 +34,25 @@ module DiasporaFederation
32
34
  end
33
35
  end
34
36
 
37
+ require "diaspora_federation/validators/relayable_validator"
35
38
  require "diaspora_federation/validators/h_card_validator"
36
39
  require "diaspora_federation/validators/person_validator"
37
40
  require "diaspora_federation/validators/profile_validator"
38
41
  require "diaspora_federation/validators/web_finger_validator"
42
+ require "diaspora_federation/validators/request_validator"
43
+ require "diaspora_federation/validators/photo_validator"
44
+ require "diaspora_federation/validators/location_validator"
45
+ require "diaspora_federation/validators/status_message_validator"
46
+ require "diaspora_federation/validators/participation_validator"
47
+ require "diaspora_federation/validators/like_validator"
48
+ require "diaspora_federation/validators/comment_validator"
49
+ require "diaspora_federation/validators/account_deletion_validator"
50
+ require "diaspora_federation/validators/message_validator"
51
+ require "diaspora_federation/validators/conversation_validator"
52
+ require "diaspora_federation/validators/relayable_retraction_validator"
53
+ require "diaspora_federation/validators/reshare_validator"
54
+ require "diaspora_federation/validators/retraction_validator"
55
+ require "diaspora_federation/validators/signed_retraction_validator"
56
+ require "diaspora_federation/validators/poll_answer_validator"
57
+ require "diaspora_federation/validators/poll_validator"
58
+ require "diaspora_federation/validators/poll_participation_validator"
@@ -0,0 +1,10 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::AccountDeletion}
4
+ class AccountDeletionValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :diaspora_id, %i(not_empty diaspora_id)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Comment}
4
+ class CommentValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ include RelayableValidator
10
+
11
+ rule :text, [:not_empty,
12
+ length: {maximum: 65_535}]
13
+
14
+ rule :diaspora_id, %i(not_empty diaspora_id)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Conversation}
4
+ class ConversationValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ rule :diaspora_id, %i(not_empty diaspora_id)
10
+
11
+ rule :participant_ids, diaspora_id_count: {maximum: 20}
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Like}
4
+ class LikeValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ include RelayableValidator
10
+
11
+ rule :diaspora_id, %i(not_empty diaspora_id)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Location}
4
+ class LocationValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :lat, :not_empty
8
+ rule :lng, :not_empty
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Message}
4
+ class MessageValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ include RelayableValidator
10
+
11
+ rule :diaspora_id, %i(not_empty diaspora_id)
12
+
13
+ rule :conversation_guid, :guid
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Participation}
4
+ class ParticipationValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ rule :target_type, :not_empty
10
+
11
+ include RelayableValidator
12
+
13
+ rule :diaspora_id, %i(not_empty diaspora_id)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Photo}
4
+ class PhotoValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ rule :diaspora_id, %i(not_empty diaspora_id)
10
+
11
+ rule :public, :boolean
12
+
13
+ rule :remote_photo_path, :not_empty
14
+
15
+ rule :remote_photo_name, :not_empty
16
+
17
+ rule :status_message_guid, :guid
18
+
19
+ rule :height, :numeric
20
+
21
+ rule :width, :numeric
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::PollAnswer}
4
+ class PollAnswerValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+ rule :answer, [:not_empty, length: {maximum: 255}]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::PollParticipation}
4
+ class PollParticipationValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ include RelayableValidator
10
+
11
+ rule :diaspora_id, %i(not_empty diaspora_id)
12
+
13
+ rule :poll_answer_guid, :guid
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Poll}
4
+ class PollValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+ rule :question, [:not_empty, length: {maximum: 255}]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::RelayableRetraction}
4
+ # @deprecated the {Entities::RelayableRetraction} will be replaced with {Entities::Retraction}
5
+ class RelayableRetractionValidator < Validation::Validator
6
+ include Validation
7
+
8
+ rule :target_guid, :guid
9
+
10
+ rule :target_type, :not_empty
11
+
12
+ rule :diaspora_id, %i(not_empty diaspora_id)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This is included to validatros which validate entities which include {Entities::Relayable}
4
+ module RelayableValidator
5
+ # when this module is included in a Validator child it adds rules for relayable validation
6
+ # @param [Validation::Validator] validator the validator in which it is included
7
+ def self.included(validator)
8
+ validator.class_eval do
9
+ rule :parent_guid, :guid
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Request}
4
+ class RequestValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :sender_id, %i(not_empty diaspora_id)
8
+ rule :recipient_id, %i(not_empty diaspora_id)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Reshare}
4
+ class ReshareValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :root_diaspora_id, %i(not_empty diaspora_id)
8
+
9
+ rule :root_guid, :guid
10
+
11
+ rule :guid, :guid
12
+
13
+ rule :diaspora_id, %i(not_empty diaspora_id)
14
+
15
+ rule :public, :boolean
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::Retraction}
4
+ class RetractionValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :target_guid, :guid
8
+
9
+ rule :diaspora_id, %i(not_empty diaspora_id)
10
+
11
+ rule :target_type, :not_empty
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ module Validation
2
+ module Rule
3
+ # Rule for validating the number of Diaspora* ids in a string.
4
+ # The evaluated string is split at ";" and the result will be counted.
5
+ class DiasporaIdCount
6
+ # This rule must have a +maximum+ param
7
+ # @return [Hash] params
8
+ attr_reader :params
9
+
10
+ # create a new rule for a maximum diaspora id count validation
11
+ # @param [Hash] params
12
+ # @option params [Fixnum] :maximum maximum allowed id count
13
+ def initialize(params)
14
+ unless params.include?(:maximum) && params[:maximum].is_a?(Fixnum)
15
+ raise ArgumentError, "A number has to be specified for :maximum"
16
+ end
17
+
18
+ @params = params
19
+ end
20
+
21
+ # The error key for this rule
22
+ # @return [Symbol] error key
23
+ def error_key
24
+ :diaspora_id_count
25
+ end
26
+
27
+ def valid_value?(value)
28
+ ids = value.split(";")
29
+ return false unless ids.count <= params[:maximum]
30
+ ids.each do |id|
31
+ return false unless DiasporaId.new.valid_value?(id)
32
+ end
33
+ true
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::SignedRetraction}
4
+ # @deprecated the {Entities::RelayableRetraction} will be replaced with {Entities::Retraction}
5
+ class SignedRetractionValidator < Validation::Validator
6
+ include Validation
7
+
8
+ rule :target_guid, :guid
9
+
10
+ rule :target_type, :not_empty
11
+
12
+ rule :diaspora_id, %i(not_empty diaspora_id)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module DiasporaFederation
2
+ module Validators
3
+ # This validates a {Entities::StatusMessage}
4
+ class StatusMessageValidator < Validation::Validator
5
+ include Validation
6
+
7
+ rule :guid, :guid
8
+
9
+ rule :diaspora_id, %i(not_empty diaspora_id)
10
+
11
+ rule :public, :boolean
12
+ end
13
+ end
14
+ end
@@ -1,4 +1,4 @@
1
1
  module DiasporaFederation
2
2
  # the gem version
3
- VERSION = "0.0.8"
3
+ VERSION = "0.0.9"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora_federation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Neff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-19 00:00:00.000000000 Z
11
+ date: 2015-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.6'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.6.6
22
+ version: 1.6.6.4
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.6'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.6.6
32
+ version: 1.6.6.4
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: faraday
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -107,23 +107,68 @@ files:
107
107
  - lib/diaspora_federation/discovery/web_finger.rb
108
108
  - lib/diaspora_federation/discovery/xrd_document.rb
109
109
  - lib/diaspora_federation/entities.rb
110
+ - lib/diaspora_federation/entities/account_deletion.rb
111
+ - lib/diaspora_federation/entities/comment.rb
112
+ - lib/diaspora_federation/entities/conversation.rb
113
+ - lib/diaspora_federation/entities/like.rb
114
+ - lib/diaspora_federation/entities/location.rb
115
+ - lib/diaspora_federation/entities/message.rb
116
+ - lib/diaspora_federation/entities/participation.rb
110
117
  - lib/diaspora_federation/entities/person.rb
118
+ - lib/diaspora_federation/entities/photo.rb
119
+ - lib/diaspora_federation/entities/poll.rb
120
+ - lib/diaspora_federation/entities/poll_answer.rb
121
+ - lib/diaspora_federation/entities/poll_participation.rb
111
122
  - lib/diaspora_federation/entities/profile.rb
123
+ - lib/diaspora_federation/entities/relayable.rb
124
+ - lib/diaspora_federation/entities/relayable_retraction.rb
125
+ - lib/diaspora_federation/entities/request.rb
126
+ - lib/diaspora_federation/entities/reshare.rb
127
+ - lib/diaspora_federation/entities/retraction.rb
128
+ - lib/diaspora_federation/entities/signed_retraction.rb
129
+ - lib/diaspora_federation/entities/status_message.rb
112
130
  - lib/diaspora_federation/entity.rb
113
131
  - lib/diaspora_federation/fetcher.rb
114
132
  - lib/diaspora_federation/logging.rb
115
133
  - lib/diaspora_federation/properties_dsl.rb
134
+ - lib/diaspora_federation/salmon.rb
135
+ - lib/diaspora_federation/salmon/aes.rb
136
+ - lib/diaspora_federation/salmon/encrypted_slap.rb
137
+ - lib/diaspora_federation/salmon/exceptions.rb
138
+ - lib/diaspora_federation/salmon/magic_envelope.rb
139
+ - lib/diaspora_federation/salmon/slap.rb
140
+ - lib/diaspora_federation/salmon/xml_payload.rb
141
+ - lib/diaspora_federation/signing.rb
116
142
  - lib/diaspora_federation/validators.rb
143
+ - lib/diaspora_federation/validators/account_deletion_validator.rb
144
+ - lib/diaspora_federation/validators/comment_validator.rb
145
+ - lib/diaspora_federation/validators/conversation_validator.rb
117
146
  - lib/diaspora_federation/validators/h_card_validator.rb
147
+ - lib/diaspora_federation/validators/like_validator.rb
148
+ - lib/diaspora_federation/validators/location_validator.rb
149
+ - lib/diaspora_federation/validators/message_validator.rb
150
+ - lib/diaspora_federation/validators/participation_validator.rb
118
151
  - lib/diaspora_federation/validators/person_validator.rb
152
+ - lib/diaspora_federation/validators/photo_validator.rb
153
+ - lib/diaspora_federation/validators/poll_answer_validator.rb
154
+ - lib/diaspora_federation/validators/poll_participation_validator.rb
155
+ - lib/diaspora_federation/validators/poll_validator.rb
119
156
  - lib/diaspora_federation/validators/profile_validator.rb
157
+ - lib/diaspora_federation/validators/relayable_retraction_validator.rb
158
+ - lib/diaspora_federation/validators/relayable_validator.rb
159
+ - lib/diaspora_federation/validators/request_validator.rb
160
+ - lib/diaspora_federation/validators/reshare_validator.rb
161
+ - lib/diaspora_federation/validators/retraction_validator.rb
120
162
  - lib/diaspora_federation/validators/rules/birthday.rb
121
163
  - lib/diaspora_federation/validators/rules/boolean.rb
122
164
  - lib/diaspora_federation/validators/rules/diaspora_id.rb
165
+ - lib/diaspora_federation/validators/rules/diaspora_id_count.rb
123
166
  - lib/diaspora_federation/validators/rules/guid.rb
124
167
  - lib/diaspora_federation/validators/rules/not_nil.rb
125
168
  - lib/diaspora_federation/validators/rules/public_key.rb
126
169
  - lib/diaspora_federation/validators/rules/tag_count.rb
170
+ - lib/diaspora_federation/validators/signed_retraction_validator.rb
171
+ - lib/diaspora_federation/validators/status_message_validator.rb
127
172
  - lib/diaspora_federation/validators/web_finger_validator.rb
128
173
  - lib/diaspora_federation/version.rb
129
174
  - lib/tasks/build.rake