gpsoauth 0.1.0 → 0.2.0

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: 204ea5290b6b19ac4b313ddc82c47b6a30f3924f
4
- data.tar.gz: 261ff8ab1af1e678a6d94eeb6e90e99c409332df
3
+ metadata.gz: 1eaebe898412ce66cec93768814c6e969a52a7bb
4
+ data.tar.gz: d4610c0b873235e30161dee5b87cc716849b9b48
5
5
  SHA512:
6
- metadata.gz: 5d562ca5ae735ff3662e0b5cf0ab9b0c2f10ed78ebcf099adc380b285639f88a906ecde2e63b0dd711202f1a1d4be55edb492b3a2f1a2b10f80e80e96f71677c
7
- data.tar.gz: ea4eba98bfa330fb52108c292fcd84f0ec4c9c20fbc2f3de300900ca1505a7e05586f1db9146e60b931e05f6f4d3f39cacd93838acecddfaee2d653cf82a5041
6
+ metadata.gz: 99bc53141aff810f80721186e8e629f87fac3d25831946bbb639702e191a12d46ccf4f2c1e7dccd158ba38a993023fa117f19d2175489f595613e228934ae3a4
7
+ data.tar.gz: 4f9222a04638f17c13a3fb48a048eb6e0d234c935ac97c3d9fb34f30f7db6c9aac0c42547416dc4429d64e5d3087892216a3eb43a6525cc6b005807972e5bf70
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  *.swo
12
12
  *.swp
13
+
14
+ .byebug_history
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Gpsoauth
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/gpsoauth.svg)](https://badge.fury.io/rb/gpsoauth)
4
+
3
5
  A Ruby client library for Google Play Services OAuth
4
6
 
5
7
  A port of the Python library [gpsoauth](https://github.com/simon-weber/gpsoauth) by [Simon Weber](https://github.com/simon-weber)
@@ -18,15 +20,15 @@ And then execute:
18
20
 
19
21
  $ bundle
20
22
 
21
- Or install it yourself as:
23
+ Or install it yourself as:
22
24
 
23
- $ gem install gpsoauth
25
+ $ gem install gpsoauth
24
26
 
25
27
  ## Usage
26
28
 
27
- Instantiate a Gpsoauth connection. This requires an Android ID:
29
+ Instantiate a Gpsoauth client. This requires an Android ID:
28
30
 
29
- g = Gpsoauth::Connection.new(android_id, [service, device_country, operator_country, lang, sdk_version])
31
+ g = Gpsoauth::Client.new(android_id, [service, device_country, operator_country, lang, sdk_version])
30
32
 
31
33
  Perform 'master login' with email/password:
32
34
 
@@ -22,6 +22,8 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.11"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.9"
26
+ spec.add_development_dependency "byebug", "~> 9.0"
25
27
 
26
- spec.add_dependency "httparty", "~> 0.13.7"
28
+ spec.add_dependency "httparty", "~> 0.14"
27
29
  end
@@ -1,10 +1,9 @@
1
1
  require "httparty"
2
2
  require "base64"
3
3
 
4
- require "gpsoauth/connection"
4
+ require "gpsoauth/client"
5
5
  require "gpsoauth/exceptions"
6
6
  require "gpsoauth/google"
7
- require "gpsoauth/utility"
8
7
  require "gpsoauth/version"
9
8
 
10
9
  module Gpsoauth
@@ -1,5 +1,5 @@
1
1
  module Gpsoauth
2
- class Connection
2
+ class Client
3
3
  AUTH_URL = "https://android.clients.google.com/auth"
4
4
  USER_AGENT = "gpsoauth/gpsoauth"
5
5
 
@@ -29,9 +29,7 @@ module Gpsoauth
29
29
  Email: email,
30
30
  has_permission: 1,
31
31
  add_account: 1,
32
- # @TODO Finish password encryption
33
- # EncryptedPasswd: Google::signature(email, password, android_key)
34
- Passwd: password,
32
+ EncryptedPasswd: Google::signature(email, password, android_key),
35
33
  service: @service,
36
34
  source: "android",
37
35
  androidId: @android_id,
@@ -17,26 +17,43 @@ module Gpsoauth
17
17
  end
18
18
 
19
19
  def self.signature(email, password, key)
20
- signature = "\x00".bytes
21
- struct = key_to_struct(key)
22
- signature.push Digest::SHA1.hexdigest(struct)[0,4]
23
-
24
- # @TODO Encryptedpasswd notes:
20
+ # Encryption scheme deconstructed here:
25
21
  # http://codedigging.com/blog/2014-06-09-about-encryptedpasswd/
26
- #
27
- # cipher = PKCS1_OAEP.new(key)
28
- # encrypted_login = cipher.encrypt((email + u'\x00' + password).encode('utf-8'))
29
- # signature.extend(encrypted_login)
30
- # return base64.urlsafe_b64encode(signature)
22
+
23
+ struct = key_to_struct(key).pack('c*')
24
+ first_four_bytes_sha1 = OpenSSL::Digest::SHA1.digest(struct)[0...4]
25
+
26
+ encrypted_login_password = key.public_encrypt(
27
+ email + "\x00" + password,
28
+ OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING
29
+ )
30
+
31
+ signature = "\x00" + first_four_bytes_sha1 + encrypted_login_password
32
+ Base64.urlsafe_encode64(signature)
31
33
  end
32
34
 
33
35
  private
34
36
 
37
+ def self.long_to_bytes(key)
38
+ arr = []
39
+ key, mod = key.divmod(256)
40
+
41
+ while mod > 0 || key > 0
42
+ arr << mod
43
+ key, mod = key.divmod(256)
44
+ end
45
+
46
+ arr = arr.reverse
47
+ end
48
+
35
49
  def self.key_to_struct(key)
36
- mod = key.n.to_s.bytes.map{ |x| x.to_s(16) }.join
37
- exponent = key.e.to_s.bytes.map{ |x| x.to_s(16) }.join
50
+ mod_buffer = "\x00\x00\x00\x80".unpack('C*')
51
+ exponent_buffer = "\x00\x00\x00\x03".unpack('C*')
52
+
53
+ mod = long_to_bytes(key.n.to_i)
54
+ exponent = long_to_bytes(key.e.to_i)
38
55
 
39
- "\x00\x00\x00\x80#{mod}\x00\x00\x00\x03#{exponent}".b
56
+ mod_buffer + mod + exponent_buffer + exponent
40
57
  end
41
58
  end
42
59
  end
@@ -1,3 +1,3 @@
1
1
  module Gpsoauth
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gpsoauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Mytko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-07-24 00:00:00.000000000 Z
11
+ date: 2016-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,20 +38,48 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: httparty
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
73
  - - "~>"
46
74
  - !ruby/object:Gem::Version
47
- version: 0.13.7
75
+ version: '0.14'
48
76
  type: :runtime
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
80
  - - "~>"
53
81
  - !ruby/object:Gem::Version
54
- version: 0.13.7
82
+ version: '0.14'
55
83
  description: |-
56
84
  A Ruby client library for Google Play Services OAuth.
57
85
  A port of the Python library gpsoauth by Simon Weber
@@ -68,10 +96,9 @@ files:
68
96
  - README.md
69
97
  - gpsoauth.gemspec
70
98
  - lib/gpsoauth.rb
71
- - lib/gpsoauth/connection.rb
99
+ - lib/gpsoauth/client.rb
72
100
  - lib/gpsoauth/exceptions.rb
73
101
  - lib/gpsoauth/google.rb
74
- - lib/gpsoauth/utility.rb
75
102
  - lib/gpsoauth/version.rb
76
103
  homepage: http://github.com/bryanmytko/gpsoauth
77
104
  licenses:
@@ -1,2 +0,0 @@
1
- module Gpsoauth
2
- end