diaspora_federation 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,6 @@
1
1
 
2
2
  module DiasporaFederation
3
3
  module WebFinger
4
- ##
5
4
  # Generates and parses Host Meta documents.
6
5
  #
7
6
  # This is a minimal implementation of the standard, only to the degree of what
@@ -23,7 +22,6 @@ module DiasporaFederation
23
22
  # URL fragment to append to the base URL
24
23
  WEBFINGER_SUFFIX = "webfinger?q={uri}"
25
24
 
26
- ##
27
25
  # Returns the WebFinger URL that was used to build this instance (either from
28
26
  # xml or by giving a base URL).
29
27
  # @return [String] WebFinger template URL
@@ -31,7 +29,6 @@ module DiasporaFederation
31
29
  @webfinger_url
32
30
  end
33
31
 
34
- ##
35
32
  # Produces the XML string for the Host Meta instance with a +Link+ element
36
33
  # containing the +webfinger_url+.
37
34
  # @return [String] XML string
@@ -43,7 +40,6 @@ module DiasporaFederation
43
40
  doc.to_xml
44
41
  end
45
42
 
46
- ##
47
43
  # Builds a new HostMeta instance and constructs the WebFinger URL from the
48
44
  # given base URL by appending HostMeta::WEBFINGER_SUFFIX.
49
45
  # @return [HostMeta]
@@ -60,7 +56,6 @@ module DiasporaFederation
60
56
  hm
61
57
  end
62
58
 
63
- ##
64
59
  # Reads the given Host Meta XML document string and populates the
65
60
  # +webfinger_url+.
66
61
  # @param [String] hostmeta_xml Host Meta XML string
@@ -77,7 +72,6 @@ module DiasporaFederation
77
72
  hm
78
73
  end
79
74
 
80
- ##
81
75
  # Applies some basic sanity-checking to the given URL
82
76
  # @param [String] url validation subject
83
77
  # @return [Boolean] validation result
@@ -86,7 +80,6 @@ module DiasporaFederation
86
80
  end
87
81
  private_class_method :webfinger_url_valid?
88
82
 
89
- ##
90
83
  # Gets the webfinger url from an XRD data structure
91
84
  # @param [Hash] data extracted data
92
85
  # @return [String] webfinger url
@@ -1,6 +1,5 @@
1
1
  module DiasporaFederation
2
2
  module WebFinger
3
- ##
4
3
  # The WebFinger document used for Diaspora* user discovery is based on an older
5
4
  # draft of the specification you can find in the wiki of the "webfinger" project
6
5
  # on {http://code.google.com/p/webfinger/wiki/WebFingerProtocol Google Code}
@@ -9,18 +8,18 @@ module DiasporaFederation
9
8
  # In the meantime an actual RFC draft has been in development, which should
10
9
  # serve as a base for all future changes of this implementation.
11
10
  #
12
- # @example Creating a WebFinger document from account data
13
- # wf = WebFinger.from_person({
11
+ # @example Creating a WebFinger document from a person hash
12
+ # wf = WebFinger.new(
14
13
  # acct_uri: "acct:user@server.example",
15
14
  # alias_url: "https://server.example/people/0123456789abcdef",
16
- # hcard_url: "https://server.example/hcard/users/0123456789abcdef",
15
+ # hcard_url: "https://server.example/hcard/users/user",
17
16
  # seed_url: "https://server.example/",
18
17
  # profile_url: "https://server.example/u/user",
19
18
  # atom_url: "https://server.example/public/user.atom",
20
19
  # salmon_url: "https://server.example/receive/users/0123456789abcdef",
21
20
  # guid: "0123456789abcdef",
22
- # pubkey: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
23
- # })
21
+ # public_key: "-----BEGIN PUBLIC KEY-----\nABCDEF==\n-----END PUBLIC KEY-----"
22
+ # )
24
23
  # xml_string = wf.to_xml
25
24
  #
26
25
  # @example Creating a WebFinger instance from an xml document
@@ -34,62 +33,72 @@ module DiasporaFederation
34
33
  # @see http://code.google.com/p/webfinger/wiki/CommonLinkRelations
35
34
  # @see http://www.iana.org/assignments/link-relations/link-relations.xhtml
36
35
  # official list of IANA link relations
37
- class WebFinger
38
- private_class_method :new
39
-
40
- # The Subject element should contain the webfinger address that was asked
41
- # for. If it does not, then this webfinger profile MUST be ignored.
42
- # @return [String]
43
- attr_reader :acct_uri
44
-
45
- # @return [String] link to the users profile
46
- attr_reader :alias_url, :profile_url
47
-
48
- # @return [String] link to the +hCard+
49
- attr_reader :hcard_url
50
-
51
- # @return [String] link to the pod
52
- attr_reader :seed_url
53
-
54
- # This atom feed is an Activity Stream of the user's public posts. Diaspora
55
- # pods SHOULD publish an Activity Stream of public posts, but there is
56
- # currently no requirement to be able to read Activity Streams.
57
- # @see http://activitystrea.ms/ Activity Streams specification
36
+ class WebFinger < Entity
37
+ # @!attribute [r] acct_uri
38
+ # The Subject element should contain the webfinger address that was asked
39
+ # for. If it does not, then this webfinger profile MUST be ignored.
40
+ # @return [String]
41
+ property :acct_uri
42
+
43
+ # @!attribute [r] alias_url
44
+ # @return [String] link to the users profile
45
+ property :alias_url
46
+
47
+ # @!attribute [r] hcard_url
48
+ # @return [String] link to the +hCard+
49
+ property :hcard_url
50
+
51
+ # @!attribute [r] seed_url
52
+ # @return [String] link to the pod
53
+ property :seed_url
54
+
55
+ # @!attribute [r] profile_url
56
+ # @return [String] link to the users profile
57
+ property :profile_url
58
+
59
+ # @!attribute [r] atom_url
60
+ # This atom feed is an Activity Stream of the user's public posts. Diaspora
61
+ # pods SHOULD publish an Activity Stream of public posts, but there is
62
+ # currently no requirement to be able to read Activity Streams.
63
+ # @see http://activitystrea.ms/ Activity Streams specification
58
64
  #
59
- # Note that this feed MAY also be made available through the PubSubHubbub
60
- # mechanism by supplying a <link rel="hub"> in the atom feed itself.
61
- # @return [String] atom feed url
62
- attr_reader :atom_url
63
-
64
- # @return [String] salmon endpoint url
65
- # @see http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SMLR
66
- # Panzer draft for Salmon, paragraph 3.3
67
- attr_reader :salmon_url
68
-
69
- # @deprecated Either convert these to +Property+ elements or move to the
70
- # +hCard+, which actually has fields for an +UID+ defined in the +vCard+
71
- # specification (will affect older Diaspora* installations).
65
+ # Note that this feed MAY also be made available through the PubSubHubbub
66
+ # mechanism by supplying a <link rel="hub"> in the atom feed itself.
67
+ # @return [String] atom feed url
68
+ property :atom_url
69
+
70
+ # @!attribute [r] salmon_url
71
+ # @return [String] salmon endpoint url
72
+ # @see http://salmon-protocol.googlecode.com/svn/trunk/draft-panzer-salmon-00.html#SMLR
73
+ # Panzer draft for Salmon, paragraph 3.3
74
+ property :salmon_url
75
+
76
+ # @!attribute [r] guid
77
+ # @deprecated Either convert these to +Property+ elements or move to the
78
+ # +hCard+, which actually has fields for an +UID+ defined in the +vCard+
79
+ # specification (will affect older Diaspora* installations).
72
80
  #
73
- # @see HCard#guid
81
+ # @see HCard#guid
74
82
  #
75
- # This is just the guid. When a user creates an account on a pod, the pod
76
- # MUST assign them a guid - a random hexadecimal string of at least 8
77
- # hexadecimal digits.
78
- # @return [String] guid
79
- attr_reader :guid
80
-
81
- # @deprecated Either convert these to +Property+ elements or move to the
82
- # +hCard+, which actually has fields for an +KEY+ defined in the +vCard+
83
- # specification (will affect older Diaspora* installations).
83
+ # This is just the guid. When a user creates an account on a pod, the pod
84
+ # MUST assign them a guid - a random hexadecimal string of at least 8
85
+ # hexadecimal digits.
86
+ # @return [String] guid
87
+ property :guid
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).
84
93
  #
85
- # @see HCard#pubkey
94
+ # @see HCard#pubkey
86
95
  #
87
- # When a user is created on the pod, the pod MUST generate a pgp keypair
88
- # for them. This key is used for signing messages. The format is a
89
- # DER-encoded PKCS#1 key beginning with the text
90
- # "-----BEGIN PUBLIC KEY-----" and ending with "-----END PUBLIC KEY-----".
91
- # @return [String] public key
92
- attr_reader :pubkey
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
93
102
 
94
103
  # +hcard_url+ link relation
95
104
  REL_HCARD = "http://microformats.org/profile/hcard"
@@ -131,31 +140,6 @@ module DiasporaFederation
131
140
  doc.to_xml
132
141
  end
133
142
 
134
- # Create a WebFinger instance from the given person data Hash.
135
- # @param [Hash] data account data
136
- # @return [WebFinger] WebFinger instance
137
- # @raise [InvalidData] if the given data Hash is invalid or incomplete
138
- def self.from_person(data)
139
- raise InvalidData, "person data incomplete" unless account_data_complete?(data)
140
-
141
- wf = allocate
142
- wf.instance_eval {
143
- @acct_uri = data[:acct_uri]
144
- @alias_url = data[:alias_url]
145
- @hcard_url = data[:hcard_url]
146
- @seed_url = data[:seed_url]
147
- @profile_url = data[:profile_url]
148
- @atom_url = data[:atom_url]
149
- @salmon_url = data[:salmon_url]
150
-
151
- # TODO: remove me! #########
152
- @guid = data[:guid]
153
- @pubkey = data[:pubkey]
154
- #############################
155
- }
156
- wf
157
- end
158
-
159
143
  # Create a WebFinger instance from the given XML string.
160
144
  # @param [String] webfinger_xml WebFinger XML string
161
145
  # @return [WebFinger] WebFinger instance
@@ -163,40 +147,25 @@ module DiasporaFederation
163
147
  def self.from_xml(webfinger_xml)
164
148
  data = parse_xml_and_validate(webfinger_xml)
165
149
 
166
- hcard_url, seed_url, guid, profile_url, atom_url, salmon_url, pubkey = parse_links(data)
150
+ hcard_url, seed_url, guid, profile_url, atom_url, salmon_url, public_key = parse_links(data)
167
151
 
168
- wf = allocate
169
- wf.instance_eval {
170
- @acct_uri = data[:subject]
171
- @alias_url = data[:aliases].first
172
- @hcard_url = hcard_url
173
- @seed_url = seed_url
174
- @profile_url = profile_url
175
- @atom_url = atom_url
176
- @salmon_url = salmon_url
152
+ new(
153
+ acct_uri: data[:subject],
154
+ alias_url: data[:aliases].first,
155
+ hcard_url: hcard_url,
156
+ seed_url: seed_url,
157
+ profile_url: profile_url,
158
+ atom_url: atom_url,
159
+ salmon_url: salmon_url,
177
160
 
178
161
  # TODO: remove me! ##########
179
- @guid = guid
180
- @pubkey = Base64.strict_decode64(pubkey)
181
- ##############################
182
- }
183
- wf
162
+ guid: guid,
163
+ public_key: Base64.strict_decode64(public_key)
164
+ )
184
165
  end
185
166
 
186
167
  private
187
168
 
188
- # Checks the given account data Hash for correct type and completeness.
189
- # @param [Hash] data account data
190
- # @return [Boolean] validation result
191
- def self.account_data_complete?(data)
192
- data.instance_of?(Hash) &&
193
- %i(
194
- acct_uri alias_url hcard_url seed_url
195
- guid profile_url atom_url salmon_url pubkey
196
- ).all? {|k| data.key? k }
197
- end
198
- private_class_method :account_data_complete?
199
-
200
169
  # Parses the XML string to a Hash and does some rudimentary checking on
201
170
  # the data Hash.
202
171
  # @param [String] webfinger_xml WebFinger XML string
@@ -236,7 +205,7 @@ module DiasporaFederation
236
205
  # TODO: remove me! ##############
237
206
  doc.links << {rel: REL_PUBKEY,
238
207
  type: "RSA",
239
- href: Base64.strict_encode64(@pubkey)}
208
+ href: Base64.strict_encode64(@public_key)}
240
209
  ##################################
241
210
  end
242
211
 
@@ -1,6 +1,5 @@
1
1
  module DiasporaFederation
2
2
  module WebFinger
3
- ##
4
3
  # This class implements basic handling of XRD documents as far as it is
5
4
  # necessary in the context of the protocols used with Diaspora* federation.
6
5
  #
@@ -65,7 +64,6 @@ module DiasporaFederation
65
64
  @properties = {}
66
65
  end
67
66
 
68
- ##
69
67
  # Generates an XML document from the current instance and returns it as string
70
68
  # @return [String] XML document
71
69
  def to_xml
@@ -83,7 +81,6 @@ module DiasporaFederation
83
81
  builder.to_xml
84
82
  end
85
83
 
86
- ##
87
84
  # Parse the XRD document from the given string and create a hash containing
88
85
  # the extracted data.
89
86
  #
@@ -0,0 +1,17 @@
1
+ desc "Build gem into the pkg directory"
2
+ task build: :test do
3
+ FileUtils.rm_rf("pkg")
4
+ Dir["*.gemspec"].each do |gemspec|
5
+ system "gem build #{gemspec}"
6
+ end
7
+ FileUtils.mkdir_p("pkg")
8
+ FileUtils.mv(Dir["*.gem"], "pkg")
9
+ end
10
+
11
+ desc "Tags version, pushes to remote, and pushes gem"
12
+ task release: :build do
13
+ sh "git tag v#{DiasporaFederation::VERSION}"
14
+ sh "git push origin master"
15
+ sh "git push origin v#{DiasporaFederation::VERSION}"
16
+ sh "ls pkg/*.gem | xargs -n 1 gem push"
17
+ end
metadata CHANGED
@@ -1,45 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora_federation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: 4.2.2
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: 4.2.2
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: nokogiri
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 1.6.6.2
19
+ version: '1.6'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.6
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
27
  - - "~>"
39
28
  - !ruby/object:Gem::Version
40
- version: 1.6.6.2
41
- description: A rails engine that adds the diaspora* federation protocol to a rails
42
- app
29
+ version: '1.6'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.6
33
+ description: This gem provides the functionality for de-/serialization and de-/encryption
34
+ of Entities in the protocols used for communication among the various installations
35
+ of Diaspora*
43
36
  email:
44
37
  - benjamin@coding4.coffee
45
38
  executables: []
@@ -48,15 +41,11 @@ extra_rdoc_files: []
48
41
  files:
49
42
  - LICENSE
50
43
  - README.md
51
- - Rakefile
52
- - app/controllers/diaspora_federation/application_controller.rb
53
- - app/controllers/diaspora_federation/h_card_controller.rb
54
- - app/controllers/diaspora_federation/receive_controller.rb
55
- - app/controllers/diaspora_federation/webfinger_controller.rb
56
- - config/routes.rb
57
44
  - lib/diaspora_federation.rb
58
- - lib/diaspora_federation/engine.rb
45
+ - lib/diaspora_federation/callbacks.rb
46
+ - lib/diaspora_federation/entity.rb
59
47
  - lib/diaspora_federation/logging.rb
48
+ - lib/diaspora_federation/properties_dsl.rb
60
49
  - lib/diaspora_federation/version.rb
61
50
  - lib/diaspora_federation/web_finger.rb
62
51
  - lib/diaspora_federation/web_finger/exceptions.rb
@@ -64,6 +53,7 @@ files:
64
53
  - lib/diaspora_federation/web_finger/host_meta.rb
65
54
  - lib/diaspora_federation/web_finger/web_finger.rb
66
55
  - lib/diaspora_federation/web_finger/xrd_document.rb
56
+ - lib/tasks/build.rake
67
57
  - lib/tasks/diaspora_federation_tasks.rake
68
58
  - lib/tasks/tests.rake
69
59
  homepage: https://github.com/SuperTux88/diaspora_federation
@@ -76,9 +66,9 @@ require_paths:
76
66
  - lib
77
67
  required_ruby_version: !ruby/object:Gem::Requirement
78
68
  requirements:
79
- - - ">="
69
+ - - "~>"
80
70
  - !ruby/object:Gem::Version
81
- version: '0'
71
+ version: '2.0'
82
72
  required_rubygems_version: !ruby/object:Gem::Requirement
83
73
  requirements:
84
74
  - - ">="
@@ -89,6 +79,6 @@ rubyforge_project:
89
79
  rubygems_version: 2.4.6
90
80
  signing_key:
91
81
  specification_version: 4
92
- summary: diaspora* federation rails engine
82
+ summary: diaspora* federation library
93
83
  test_files: []
94
84
  has_rdoc:
data/Rakefile DELETED
@@ -1,26 +0,0 @@
1
- begin
2
- require "bundler/setup"
3
- rescue LoadError
4
- puts "You must `gem install bundler` and `bundle install` to run rake tasks"
5
- end
6
-
7
- require "rdoc/task"
8
-
9
- RDoc::Task.new(:rdoc) do |rdoc|
10
- rdoc.rdoc_dir = "rdoc"
11
- rdoc.title = "DiasporaFederation"
12
- rdoc.options << "--line-numbers"
13
- rdoc.rdoc_files.include("lib/**/*.rb")
14
- end
15
-
16
- APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
17
- load "rails/tasks/engine.rake"
18
-
19
- load "rails/tasks/statistics.rake"
20
-
21
- Bundler::GemHelper.install_tasks
22
-
23
- Rails.application.load_tasks
24
-
25
- task test: %w(spec:prepare spec)
26
- task default: :test