poke-go-api 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d4e06820ff24205fd6343be9abac2400d08b2e3
4
- data.tar.gz: 1f3294582db49573f3805226e6515d6b42c94d37
3
+ metadata.gz: 44e400f988fa8c9fac5ce45524b7479e1abc6122
4
+ data.tar.gz: 747e7c6b71e2f2736d50eacdb8b9f535c7a9d8f0
5
5
  SHA512:
6
- metadata.gz: 73b3a3e1c09ffdaca9bfbb14d5f08023dafc78ee4dc0b5339b673ad99e0d91ad401e0957fdd0701846747b25c98c01b78dd7d790d5634c0faf39c3eac6f0125c
7
- data.tar.gz: d8b0b6f96f603393cd721172ca9308f4de3198605910c8d3b54b64ff892f6dfcf901811aa433d1f6790ff43667afe1537a3d45ce6ff59b90d322d808a3f47d12
6
+ metadata.gz: 9293d55c4802524510183d77a3e2666e9522a74b4d50a58e519048a4773b37dd404b6a6fbe7382949ddc488bae6278da755386df2152be9475b885c1f3382600
7
+ data.tar.gz: 9d290770cc439b156b6337b3a609b29e99718a6cbbe08e84ab4fae1fd7575611d2dd020b8f83a3dc78c92b339d195b849e0dd5cee127d3bc00b4b1fb9c8e34e0
@@ -6,6 +6,7 @@ require 'poke-api/request_builder'
6
6
  require 'poke-api/response'
7
7
  require 'poke-api/errors'
8
8
  require 'poke-api/version'
9
+ require 'poke-api/signature'
9
10
  require 'poke-api/auth/ptc'
10
11
  require 'poke-api/auth/google'
11
12
  require 'poke-api/auth/ticket'
@@ -2,17 +2,19 @@ module Poke
2
2
  module API
3
3
  class Client
4
4
  include Logging
5
- attr_accessor :lat, :lng, :alt, :endpoint, :ticket, :sig_path
5
+ attr_accessor :lat, :lng, :alt, :endpoint, :ticket, :sig_loaded
6
+ attr_reader :sig_path
6
7
 
7
8
  def initialize
8
- @auth = nil
9
- @endpoint = 'https://pgorelease.nianticlabs.com/plfe/rpc'
10
- @reqs = []
11
- @lat = 0
12
- @lng = 0
13
- @alt = 8
14
- @ticket = Auth::Ticket.new
15
- @sig_path = nil
9
+ @auth = nil
10
+ @endpoint = 'https://pgorelease.nianticlabs.com/plfe/rpc'
11
+ @reqs = []
12
+ @lat = 0
13
+ @lng = 0
14
+ @alt = 8
15
+ @ticket = Auth::Ticket.new
16
+ @sig_path = nil
17
+ @sig_loaded = false
16
18
  end
17
19
 
18
20
  def login(username, password, provider)
@@ -50,9 +52,9 @@ module Poke
50
52
  end
51
53
 
52
54
  def activate_signature(file_path)
53
- if File.exist?(path)
55
+ if File.exist?(file_path)
54
56
  logger.info "[+] File #{file_path} has been set for signature generation"
55
- @sig_path = path
57
+ @sig_path = file_path
56
58
  else
57
59
  raise Errors::InvalidSignatureFilePath, file_path
58
60
  end
@@ -1,10 +1,8 @@
1
- require 'ffi'
2
1
  require 'securerandom'
3
2
 
4
3
  module Poke
5
4
  module API
6
5
  class RequestBuilder
7
- extend FFI::Library
8
6
  include Logging
9
7
 
10
8
  def initialize(auth, pos, endpoint)
@@ -14,7 +12,6 @@ module Poke
14
12
  @position = pos
15
13
  @client = HTTPClient.new(agent_name: 'PokeAPI/0.0.1')
16
14
  @start_time = (Time.now.to_f * 1000).to_i
17
- @ffi_enabled = false
18
15
  end
19
16
 
20
17
  def request(reqs, client)
@@ -58,8 +55,8 @@ module Poke
58
55
  expire_timestamp_ms: client.ticket.expire
59
56
  )
60
57
 
61
- load_library(client.sig_path) if client.sig_path && !@ffi_enabled
62
- set_signature(req, request_envelope) if @ffi_enabled
58
+ Signature.load_signature(client) if client.sig_path
59
+ set_signature(req, request_envelope) if client.sig_loaded
63
60
  else
64
61
  logger.info '[+] Using Provider token'
65
62
  token = request_envelope::AuthInfo::JWT.new(contents: @access_token, unknown2: 59)
@@ -68,7 +65,7 @@ module Poke
68
65
  end
69
66
 
70
67
  def set_signature(req, _request_envelope)
71
- signature = Signature.new(
68
+ signature = ::Signature.new(
72
69
  location_hash1: Helpers.generate_location_one(req.auth_ticket.to_proto, @position),
73
70
  location_hash2: Helpers.generate_location_two(@position),
74
71
  unk22: SecureRandom.random_bytes(32),
@@ -80,47 +77,18 @@ module Poke
80
77
  signature.request_hash << Helpers.generate_request(req.auth_ticket.to_proto, r.to_proto)
81
78
  end
82
79
 
83
- unknown6 = POGOProtos::Networking::Envelopes::Unknown6
80
+ unk6 = POGOProtos::Networking::Envelopes::Unknown6
84
81
 
85
- req.unknown6 = unknown6.new(
82
+ logger.info '[+] Generating Signature'
83
+
84
+ req.unknown6 = unk6.new(
86
85
  unknown1: 6,
87
- unknown2: unknown6::Unknown2.new(unknown1: generate_signature(signature.to_proto))
86
+ unknown2: unk6::Unknown2.new(unknown1: Signature.generate_signature(signature.to_proto))
88
87
  )
89
88
 
90
89
  logger.info '[+] Setting Signature'
91
90
  end
92
91
 
93
- def generate_signature(signature)
94
- attempts = 5
95
-
96
- begin
97
- logger.info '[+] Generating Signature'
98
- output_size = FFI::MemoryPointer.new(:size_t)
99
-
100
- iv = SecureRandom.random_bytes(32)
101
- RequestBuilder.encrypt(signature, signature.length, iv, 32, nil, output_size)
102
-
103
- output = FFI::MemoryPointer.new(output_size.read_int)
104
- RequestBuilder.encrypt(signature, signature.length, iv, 32, output, output_size)
105
- rescue StandardError => ex
106
- raise ex if (attempts -= 1) == 0
107
- retry
108
- end
109
-
110
- output.read_string
111
- end
112
-
113
- def load_library(path)
114
- RequestBuilder.ffi_lib(path)
115
- RequestBuilder.attach_function(
116
- :encrypt,
117
- [:string, :size_t, :string, :size_t, :pointer, :pointer],
118
- :int
119
- )
120
-
121
- @ffi_enabled = true
122
- end
123
-
124
92
  def build_sub_request(req, sub_reqs)
125
93
  sub_reqs.each do |sub_req|
126
94
  if sub_req.is_a?(Symbol)
@@ -0,0 +1,29 @@
1
+ module Poke
2
+ module API
3
+ module Signature
4
+ extend Fiddle::Importer
5
+ extend Logging
6
+
7
+ def self.load_signature(client)
8
+ dlload client.sig_path
9
+ extern "int encrypt(const unsigned char *input, size_t input_size," \
10
+ " const unsigned char* iv, size_t iv_size, unsigned char* " \
11
+ "output, size_t * output_size)"
12
+ logger.info '[+] Loaded Signature module'
13
+ client.sig_loaded = true
14
+ end
15
+
16
+ def self.generate_signature(signature)
17
+ output_size = Fiddle::Pointer.malloc(1)
18
+
19
+ iv = SecureRandom.random_bytes(32)
20
+ encrypt(signature, signature.length, iv, 32, nil, output_size)
21
+
22
+ output = Fiddle::Pointer.malloc(288)
23
+ encrypt(signature, signature.length, iv, 32, output, output_size)
24
+
25
+ output.to_str
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,29 @@
1
1
  # Load Poke-API related classes
2
2
  require 'pp'
3
- require 'poke-api'
3
+ require 'pry'
4
+ require_relative 'logging'
5
+ require_relative 'client'
6
+ require_relative 'helpers'
7
+ require_relative 'request_builder'
8
+ require_relative 'response'
9
+ require_relative 'errors'
10
+ require_relative 'version'
11
+ require_relative 'signature'
12
+ require_relative 'auth/ptc'
13
+ require_relative 'auth/google'
14
+ require_relative 'auth/ticket'
15
+
16
+ # Load Geometry libraries (native Ruby)
17
+ require_relative 'geometry/s2_base'
18
+ require_relative 'geometry/s2_cell_id'
19
+ require_relative 'geometry/s2_lat_lon'
20
+ require_relative 'geometry/s2_point'
21
+
22
+ # Load Google Generated POGOProtos
23
+ require_relative 'POGOProtos/Signature'
24
+ require_relative 'POGOProtos/Networking/Envelopes/RequestEnvelope'
25
+ require_relative 'POGOProtos/Networking/Envelopes/ResponseEnvelope'
26
+
4
27
 
5
28
  def get_cells(lat, lng, radius = 10)
6
29
  s2_point = Poke::API::Geometry::S2LatLon.new(lat, lng).to_point
@@ -1,5 +1,5 @@
1
1
  module Poke
2
2
  module API
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poke-go-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nabeel Amjad
@@ -80,20 +80,6 @@ dependencies:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.4.0.1
83
- - !ruby/object:Gem::Dependency
84
- name: ffi
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - '='
88
- - !ruby/object:Gem::Version
89
- version: 1.9.14
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - '='
95
- - !ruby/object:Gem::Version
96
- version: 1.9.14
97
83
  description: An API wrapper for Pokemon GO
98
84
  email:
99
85
  executables: []
@@ -561,6 +547,7 @@ files:
561
547
  - lib/poke-api/logging.rb
562
548
  - lib/poke-api/request_builder.rb
563
549
  - lib/poke-api/response.rb
550
+ - lib/poke-api/signature.rb
564
551
  - lib/poke-api/testing.rb
565
552
  - lib/poke-api/version.rb
566
553
  homepage: https://github.com/nabeelamjad/poke-api