ostatus2 0.3.2 → 1.0.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 134189e93db8131de1acf2540494830cc3b0b9f7
4
- data.tar.gz: 84091c342802e334d3607af0791286315a01d4eb
3
+ metadata.gz: bbf294e569b899f5aeb8406caca3a35230ac66d1
4
+ data.tar.gz: dfb5ffa9813a7738bdaa54fca1726fcdd58375ac
5
5
  SHA512:
6
- metadata.gz: cbd9646dccf41f97984ad4dbe537ff649e3ff2ac3d3a85f61524039796e5b72b9da4857282854238a7b9584051788d4863376f6cf926c948de065ecb7fc1d1ae
7
- data.tar.gz: 03de1727bfecddebb66092507e5a265757bfc97bca2723ef534eafe8ac7c8526cdbe8f0dfddb6bfd8e186062512d9c8d4346867872875bf9858f8d998ade15d2
6
+ metadata.gz: 327e56801a53d5c0cf885c5d8523b5d05c7773aa0a44f6a5017fc35f08dc3c5360ab9a543a17a300f646d8cf1babdb150a428652301f0929ce7959a883392c7b
7
+ data.tar.gz: 20eb364b94680f55ce7421e6cb202a99eecacb411e84f7ed376fcfd063601beb964e07b03152a998092ad9c5c03aa578766d1d57e20edb99012f2d6636cf258a
@@ -0,0 +1,26 @@
1
+ module OStatus2
2
+ module MagicKey
3
+ def magic_key_to_pem(magic_key)
4
+ _, modulus, exponent = magic_key.split('.')
5
+ modulus, exponent = [modulus, exponent].map { |n| decode_base64(n).bytes.inject(0) { |a, e| (a << 8) | e } }
6
+
7
+ key = OpenSSL::PKey::RSA.new
8
+ key.n = modulus
9
+ key.e = exponent
10
+
11
+ key.to_pem
12
+ end
13
+
14
+ def decode_base64(string)
15
+ retries = 0
16
+
17
+ begin
18
+ return Base64::urlsafe_decode64(string)
19
+ rescue ArgumentError
20
+ retries += 1
21
+ string = "#{string}="
22
+ retry unless retries > 2
23
+ end
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,7 @@
1
1
  module OStatus2
2
2
  class Salmon
3
+ include OStatus2::MagicKey
4
+
3
5
  XMLNS = 'http://salmon-protocol.org/ns/magic-env'
4
6
 
5
7
  # Create a magical envelope XML document around the original body
@@ -68,9 +70,9 @@ module OStatus2
68
70
 
69
71
  data = xml.at_xpath('//me:data')
70
72
  type = data.attribute('type').value
71
- body = Base64::urlsafe_decode64(data.content) rescue ''
73
+ body = decode_base64(data.content)
72
74
  sig = xml.at_xpath('//me:sig')
73
- signature = Base64::urlsafe_decode64(sig.content) rescue ''
75
+ signature = decode_base64(sig.content)
74
76
  encoding = xml.at_xpath('//me:encoding').content
75
77
  alg = xml.at_xpath('//me:alg').content
76
78
  plaintext = plaintext_signature(body, type, encoding, alg)
@@ -1,3 +1,3 @@
1
1
  module OStatus2
2
- VERSION = "0.3.2"
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/ostatus2.rb CHANGED
@@ -8,6 +8,7 @@ require 'ostatus2/version'
8
8
  require 'ostatus2/publication'
9
9
  require 'ostatus2/subscription_response'
10
10
  require 'ostatus2/subscription'
11
+ require 'ostatus2/magic_key'
11
12
  require 'ostatus2/salmon'
12
13
 
13
14
  module OStatus2
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ostatus2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eugen Rochko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-06 00:00:00.000000000 Z
11
+ date: 2016-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -75,6 +75,7 @@ extra_rdoc_files: []
75
75
  files:
76
76
  - README.md
77
77
  - lib/ostatus2.rb
78
+ - lib/ostatus2/magic_key.rb
78
79
  - lib/ostatus2/publication.rb
79
80
  - lib/ostatus2/salmon.rb
80
81
  - lib/ostatus2/subscription.rb