gamecenter-auth 1.0.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 +7 -0
- data/.gitignore +38 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +85 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/gamecenter-auth.gemspec +25 -0
- data/lib/gamecenter/auth/version.rb +5 -0
- data/lib/gamecenter/auth.rb +192 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdf562542b694b74c953cb181097610dc52dc489
|
4
|
+
data.tar.gz: a65aca8f3058c1cdbc36381b4c164575b9d56fae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9b479c43be9c3e9ad7a8998c50333fe16feaaf0c9f703154180bc3d6b1714f3b3737a208901d2426df4a0d5c56279f15e9a960f50f3c8ae92bf4eb858256c61f
|
7
|
+
data.tar.gz: 93a436eeb3f928f5730aa61d93528ae78066ea2a799c77cfed4bda4b5c7037d8194ca56984d53c0d73120a0dfa73f1b36746d11bad71c2382ee879ad429259c3
|
data/.gitignore
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/test/tmp/
|
9
|
+
/test/version_tmp/
|
10
|
+
/tmp/
|
11
|
+
|
12
|
+
## Specific to RubyMotion:
|
13
|
+
.dat*
|
14
|
+
.repl_history
|
15
|
+
build/
|
16
|
+
|
17
|
+
## Documentation cache and generated files:
|
18
|
+
/.yardoc/
|
19
|
+
/_yardoc/
|
20
|
+
/doc/
|
21
|
+
/rdoc/
|
22
|
+
|
23
|
+
## Environment normalisation:
|
24
|
+
/.bundle/
|
25
|
+
/vendor/bundle
|
26
|
+
/lib/bundler/man/
|
27
|
+
|
28
|
+
# for a library or gem, you might want to ignore these files since the code is
|
29
|
+
# intended to run in multiple environments; otherwise, check them in:
|
30
|
+
Gemfile.lock
|
31
|
+
.ruby-version
|
32
|
+
.ruby-gemset
|
33
|
+
|
34
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
35
|
+
.rvmrc
|
36
|
+
|
37
|
+
# RubyMine
|
38
|
+
/.idea
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Bichinger Software & Consulting
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
# gamecenter-auth
|
2
|
+
|
3
|
+
Ruby gem for iOS GameKit/Game Center player authentication using the "Identity Verification Signature" provided by the generateIdentityVerificationSignatureWithCompletionHandler method in Apple's GameKit framework
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'gamecenter-auth'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install gamecenter-auth
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Gamecenter::Auth takes all parameters your iOS-App receives from the call generateIdentityVerificationSignatureWithCompletionHandler.
|
24
|
+
|
25
|
+
See https://developer.apple.com/library/prerelease/ios/documentation/GameKit/Reference/GKLocalPlayer_Ref/index.html
|
26
|
+
|
27
|
+
### Configuration
|
28
|
+
|
29
|
+
!This is likely to be changed a little in future versions!
|
30
|
+
|
31
|
+
Gamecenter::Auth can be statically configured using the following parameters (values show the default values):
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# if for some reason you don't want the public key certificate verified
|
35
|
+
# against the issuer's (Apple) certificate, set this to false
|
36
|
+
Gamecenter::Auth.verify_issuer_certificate = true
|
37
|
+
|
38
|
+
# public keys won't change often, this saves a lot of HTTP requests
|
39
|
+
Gamecenter::Auth.cache_public_keys = true
|
40
|
+
# cache this many public keys (has to be 1 at least!)
|
41
|
+
Gamecenter::Auth.public_key_cache_entries = 10
|
42
|
+
|
43
|
+
# if the salt is already base64-decoded, set this to false
|
44
|
+
Gamecenter::Auth.base64_decode_salt = true
|
45
|
+
# if the signature is already base64-decoded, set this to false
|
46
|
+
Gamecenter::Auth.base64_decode_signature = true
|
47
|
+
|
48
|
+
# HTTP timeouts in seconds
|
49
|
+
Gamecenter::Auth.request_public_key_open_timeout = 5
|
50
|
+
Gamecenter::Auth.request_public_key_read_timeout = 5
|
51
|
+
Gamecenter::Auth.request_public_key_ssl_timeout = 5
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
### Example usage
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
player_id = 'G:123148854'
|
59
|
+
bundle_id = 'de.bichinger.test.gamekit-auth'
|
60
|
+
public_key_url = 'https://static.gc.apple.com/public-key/gc-prod-2.cer'
|
61
|
+
signature = 'SGKgszgKffUshV4aMe0aQHAvzSointPjBlfF2MK34gHY50DycZlC5gwKDpRb+gBCS2OHQNLSRctYV5WORYsDbjAcNdrzR2Tl0oDMptpBiVJQX+kCilv45Fbs7szEJ2jw/4Xl/CAFlX/HtRxYZKb4oeC/knB5ueuDGcAyjFZJkl8FmFvyRn2ZeO0pGfefzQ2lz3bgHkwgcY+w8ZMQ5wIoHkgt4x44H21hnI5he/G0q48Il0lc3frWiojeZn2UWIo8j601svFHSDkX3mx9SJrYeP4f8goJ8ax1/fVVHxSdh2+uKW+9Zz/gAbrAC4xtVUiz12DjHZf9G6hxZ0etrjZYBQ=='
|
62
|
+
salt = 'Yt1c3Q=='
|
63
|
+
timestamp = 1445940012818
|
64
|
+
|
65
|
+
auth = Gamecenter::Auth.new
|
66
|
+
success = auth.verify_player(player_id, bundle_id, public_key_url, signature, salt, timestamp)
|
67
|
+
|
68
|
+
puts success ? 'player verified' : 'player not verified'
|
69
|
+
```
|
70
|
+
|
71
|
+
## Development
|
72
|
+
|
73
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
74
|
+
|
75
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
76
|
+
|
77
|
+
## Contributing
|
78
|
+
|
79
|
+
Bug reports and pull requests are very welcome on GitHub at https://github.com/bichinger/gamecenter-auth.
|
80
|
+
|
81
|
+
|
82
|
+
## License
|
83
|
+
|
84
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
85
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gamecenter/auth"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gamecenter/auth/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'gamecenter-auth'
|
8
|
+
spec.version = Gamecenter::Auth::VERSION
|
9
|
+
spec.authors = ['Niklas Bichinger', 'Kai Machemehl']
|
10
|
+
spec.email = %w(niklas@bichinger.de k.machemehl@bichinger.de)
|
11
|
+
|
12
|
+
spec.summary = %q{Server-side iOS GameKit/Game Center player authentication}
|
13
|
+
spec.description = %q{Server-side iOS GameKit/Game Center player authentication using the "Identity Verification Signature" provided by the method generateIdentityVerificationSignatureWithCompletionHandler in Apple's GameKit framework}
|
14
|
+
spec.homepage = 'https://github.com/bichinger/gamecenter-auth'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.10'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec'
|
25
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'gamecenter/auth/version'
|
2
|
+
require 'uri'
|
3
|
+
require 'logger'
|
4
|
+
require 'base64'
|
5
|
+
|
6
|
+
module Gamecenter
|
7
|
+
class Auth
|
8
|
+
|
9
|
+
@@verify_issuer_certificate = true
|
10
|
+
|
11
|
+
@@cache_public_keys = true
|
12
|
+
@@public_key_cache_entries = 10 # 1+: cache this many public keys (has to be 1 at least!)
|
13
|
+
|
14
|
+
@@base64_decode_salt = true
|
15
|
+
@@base64_decode_signature = true
|
16
|
+
|
17
|
+
@@request_public_key_open_timeout = 5 # seconds
|
18
|
+
@@request_public_key_read_timeout = 5 # seconds
|
19
|
+
@@request_public_key_ssl_timeout = 5 # seconds
|
20
|
+
|
21
|
+
@@ca_certificate = OpenSSL::X509::Certificate.new <<EOCACERT
|
22
|
+
-----BEGIN CERTIFICATE-----
|
23
|
+
MIIFWTCCBEGgAwIBAgIQPXjX+XZJYLJhffTwHsqGKjANBgkqhkiG9w0BAQsFADCB
|
24
|
+
yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
|
25
|
+
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
|
26
|
+
U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
|
27
|
+
ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
|
28
|
+
aG9yaXR5IC0gRzUwHhcNMTMxMjEwMDAwMDAwWhcNMjMxMjA5MjM1OTU5WjB/MQsw
|
29
|
+
CQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAdBgNV
|
30
|
+
BAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxMDAuBgNVBAMTJ1N5bWFudGVjIENs
|
31
|
+
YXNzIDMgU0hBMjU2IENvZGUgU2lnbmluZyBDQTCCASIwDQYJKoZIhvcNAQEBBQAD
|
32
|
+
ggEPADCCAQoCggEBAJeDHgAWryyx0gjE12iTUWAecfbiR7TbWE0jYmq0v1obUfej
|
33
|
+
DRh3aLvYNqsvIVDanvPnXydOC8KXyAlwk6naXA1OpA2RoLTsFM6RclQuzqPbROlS
|
34
|
+
Gz9BPMpK5KrA6DmrU8wh0MzPf5vmwsxYaoIV7j02zxzFlwckjvF7vjEtPW7ctZlC
|
35
|
+
n0thlV8ccO4XfduL5WGJeMdoG68ReBqYrsRVR1PZszLWoQ5GQMWXkorRU6eZW4U1
|
36
|
+
V9Pqk2JhIArHMHckEU1ig7a6e2iCMe5lyt/51Y2yNdyMK29qclxghJzyDJRewFZS
|
37
|
+
AEjM0/ilfd4v1xPkOKiE1Ua4E4bCG53qWjjdm9sCAwEAAaOCAYMwggF/MC8GCCsG
|
38
|
+
AQUFBwEBBCMwITAfBggrBgEFBQcwAYYTaHR0cDovL3MyLnN5bWNiLmNvbTASBgNV
|
39
|
+
HRMBAf8ECDAGAQH/AgEAMGwGA1UdIARlMGMwYQYLYIZIAYb4RQEHFwMwUjAmBggr
|
40
|
+
BgEFBQcCARYaaHR0cDovL3d3dy5zeW1hdXRoLmNvbS9jcHMwKAYIKwYBBQUHAgIw
|
41
|
+
HBoaaHR0cDovL3d3dy5zeW1hdXRoLmNvbS9ycGEwMAYDVR0fBCkwJzAloCOgIYYf
|
42
|
+
aHR0cDovL3MxLnN5bWNiLmNvbS9wY2EzLWc1LmNybDAdBgNVHSUEFjAUBggrBgEF
|
43
|
+
BQcDAgYIKwYBBQUHAwMwDgYDVR0PAQH/BAQDAgEGMCkGA1UdEQQiMCCkHjAcMRow
|
44
|
+
GAYDVQQDExFTeW1hbnRlY1BLSS0xLTU2NzAdBgNVHQ4EFgQUljtT8Hkzl699g+8u
|
45
|
+
K8zKt4YecmYwHwYDVR0jBBgwFoAUf9Nlp8Ld7LvwMAnzQzn6Aq8zMTMwDQYJKoZI
|
46
|
+
hvcNAQELBQADggEBABOFGh5pqTf3oL2kr34dYVP+nYxeDKZ1HngXI9397BoDVTn7
|
47
|
+
cZXHZVqnjjDSRFph23Bv2iEFwi5zuknx0ZP+XcnNXgPgiZ4/dB7X9ziLqdbPuzUv
|
48
|
+
M1ioklbRyE07guZ5hBb8KLCxR/Mdoj7uh9mmf6RWpT+thC4p3ny8qKqjPQQB6rqT
|
49
|
+
og5QIikXTIfkOhFf1qQliZsFay+0yQFMJ3sLrBkFIqBgFT/ayftNTI/7cmd3/SeU
|
50
|
+
x7o1DohJ/o39KK9KEr0Ns5cF3kQMFfo2KwPcwVAB8aERXRTl4r0nS1S+K4ReD6bD
|
51
|
+
dAUK75fDiSKxH3fzvc1D1PFMqT+1i4SvZPLQFCE=
|
52
|
+
-----END CERTIFICATE-----
|
53
|
+
EOCACERT
|
54
|
+
|
55
|
+
# Verifies the identity of the given player. Takes all return values from GameKit's generateIdentityVerificationSignatureWithCompletionHandler method.
|
56
|
+
# @see https://developer.apple.com/library/prerelease/ios/documentation/GameKit/Reference/GKLocalPlayer_Ref/index.html#//apple_ref/occ/instm/GKLocalPlayer/generateIdentityVerificationSignatureWithCompletionHandler:
|
57
|
+
# @param [String] player_id the playerID from the player to verify identity of
|
58
|
+
# @param [String] bundle_id the app's bundleID
|
59
|
+
# @param [String] public_key_url the publicKeyURL property returned from the GameKit framework
|
60
|
+
# @param [String] signature the signature property returned from the GameKit framework
|
61
|
+
# @param [String] salt the salt property returned from the GameKit framework
|
62
|
+
# @param [Integer] timestamp the timestamp property returned from the GameKit framework
|
63
|
+
# @return [Boolean] true if player could be verified, false if not
|
64
|
+
def verify_player(player_id, bundle_id, public_key_url, signature, salt, timestamp)
|
65
|
+
unless verify_public_key_url public_key_url
|
66
|
+
logger.debug { "public key url invalid: #{public_key_url}" }
|
67
|
+
return false
|
68
|
+
end
|
69
|
+
|
70
|
+
cert = get_public_key_certificate public_key_url
|
71
|
+
unless cert
|
72
|
+
logger.debug { "could not get certificate from: #{public_key_url}" }
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
if @@verify_issuer_certificate && !verify_public_key_certificate(cert)
|
76
|
+
logger.debug { "failed verification of public key certificate from: #{public_key_url}" }
|
77
|
+
return false
|
78
|
+
end
|
79
|
+
|
80
|
+
salt_decoded = @@base64_decode_salt ? Base64.decode64(salt) : salt
|
81
|
+
payload = "#{player_id}#{bundle_id}#{[timestamp.to_i].pack('Q>')}#{salt_decoded}"
|
82
|
+
signature_decoded = @@base64_decode_signature ? Base64.decode64(signature) : signature
|
83
|
+
unless verify_signature cert, signature_decoded, payload
|
84
|
+
logger.debug { "failed signature validation for player id #{player_id}, bundle id #{bundle_id}, timestamp #{timestamp}, salt #{salt} (decode: #{@@base64_decode_salt}), signature #{signature} (decode: #{@@base64_decode_signature}) with certificate from: #{public_key_url}" }
|
85
|
+
return false
|
86
|
+
end
|
87
|
+
|
88
|
+
true
|
89
|
+
end
|
90
|
+
|
91
|
+
# Verifies that the public key url originates from one of Apple's secured servers
|
92
|
+
# @param [String] public_key_url The publicKeyURL property returned from the GameKit framework
|
93
|
+
# @return [Boolean] true if url verification was successful, false if url fails verification
|
94
|
+
def verify_public_key_url(public_key_url)
|
95
|
+
url_ok = false
|
96
|
+
begin
|
97
|
+
uri = URI.parse public_key_url
|
98
|
+
url_ok = uri.scheme == 'https' && !!(uri.host =~ /\.apple\.com$/i)
|
99
|
+
rescue URI::InvalidURIError => e
|
100
|
+
logger.error e
|
101
|
+
end
|
102
|
+
|
103
|
+
url_ok
|
104
|
+
end
|
105
|
+
|
106
|
+
# Checks if given public key certificate can be verified with the CA certificate
|
107
|
+
# @param [OpenSSL::X509::Certificate] public_key_cert a previously fetched public key certificate object
|
108
|
+
# @return [Boolean] true if certificate could be verified against the CA certificate, false if it couldn't
|
109
|
+
def verify_public_key_certificate(public_key_cert)
|
110
|
+
verified = public_key_cert.verify(@@ca_certificate.public_key)
|
111
|
+
no_errors = OpenSSL.errors.empty? # this method has to be called always as it empties the OpenSSL error stack
|
112
|
+
|
113
|
+
verified && no_errors
|
114
|
+
end
|
115
|
+
|
116
|
+
# Verifies the signature of given payload with given public key certificate
|
117
|
+
# @param [OpenSSL:X509::Certificate] public_key_cert a previously fetched public key certificate object
|
118
|
+
# @param [String] signature the signature to be verified
|
119
|
+
# @param [String] payload the payload to verify the signature for
|
120
|
+
# @return [Boolean] true if signature is valid for given certificate and payload, false if it isn't
|
121
|
+
def verify_signature(public_key_cert, signature, payload)
|
122
|
+
verified = public_key_cert.public_key.verify(OpenSSL::Digest::SHA256.new, signature, payload)
|
123
|
+
no_errors = OpenSSL.errors.empty? # this method has to be called always as it empties the OpenSSL error stack
|
124
|
+
|
125
|
+
verified && no_errors
|
126
|
+
end
|
127
|
+
|
128
|
+
# Get a public key certificate for given URL. Caches the results, depending on the configuration.
|
129
|
+
# @param [String] public_key_url the URL of the certificate to fetch
|
130
|
+
# @return [OpenSSL::X509::Certificate] certificate found at given URL or nil if there was an error
|
131
|
+
def get_public_key_certificate(public_key_url)
|
132
|
+
if @@cache_public_keys
|
133
|
+
# caching is enabled
|
134
|
+
cache = (@@_public_key_cache ||= {})
|
135
|
+
unless cert = cache[public_key_url] && cert.not_after > Time.now
|
136
|
+
# no cache hit or certificate expired
|
137
|
+
cache.delete public_key_url
|
138
|
+
|
139
|
+
cert = request_public_key_certificate public_key_url
|
140
|
+
|
141
|
+
available_entries = @@public_key_cache_entries - cache.size
|
142
|
+
# check if there are free entries
|
143
|
+
unless available_entries > 0
|
144
|
+
# there are not, randomly delete enough to make room for this certificate
|
145
|
+
cache.keys.sample(available_entries.abs + 1).each { |key|
|
146
|
+
cache.delete key
|
147
|
+
}
|
148
|
+
end
|
149
|
+
cache[public_key_url] = cert
|
150
|
+
end
|
151
|
+
|
152
|
+
cert
|
153
|
+
else
|
154
|
+
# caching is disabled
|
155
|
+
request_public_key_certificate public_key_url
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# Fetch a certificate from given URL.
|
160
|
+
# @param [String] public_key_url the URL to fetch the certificate from
|
161
|
+
# @return [OpenSSL::X509::Certificate] certificate found at given URL or nil if there was an error
|
162
|
+
def request_public_key_certificate(public_key_url)
|
163
|
+
uri = URI.parse public_key_url
|
164
|
+
begin
|
165
|
+
Net::HTTP.start(uri.host, uri.port,
|
166
|
+
use_ssl: uri.scheme == 'https',
|
167
|
+
open_timeout: @@request_public_key_open_timeout,
|
168
|
+
read_timeout: @@request_public_key_read_timeout,
|
169
|
+
ssl_timeout: @@request_public_key_ssl_timeout) do |http|
|
170
|
+
request = Net::HTTP::Get.new uri.request_uri
|
171
|
+
response = http.request request # Net::HTTPResponse object
|
172
|
+
begin
|
173
|
+
return OpenSSL::X509::Certificate.new(response.body) if response.body
|
174
|
+
rescue OpenSSL::X509::CertificateError => e
|
175
|
+
logger.error e
|
176
|
+
end
|
177
|
+
end
|
178
|
+
rescue Net::OpenTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError => e
|
179
|
+
logger.error e
|
180
|
+
end
|
181
|
+
|
182
|
+
nil
|
183
|
+
end
|
184
|
+
|
185
|
+
private
|
186
|
+
|
187
|
+
def logger
|
188
|
+
@@logger ||= Logger.new(STDERR)
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gamecenter-auth
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Niklas Bichinger
|
8
|
+
- Kai Machemehl
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-11-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.10'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.10'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Server-side iOS GameKit/Game Center player authentication using the "Identity
|
57
|
+
Verification Signature" provided by the method generateIdentityVerificationSignatureWithCompletionHandler
|
58
|
+
in Apple's GameKit framework
|
59
|
+
email:
|
60
|
+
- niklas@bichinger.de
|
61
|
+
- k.machemehl@bichinger.de
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- ".gitignore"
|
67
|
+
- ".rspec"
|
68
|
+
- ".travis.yml"
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- bin/console
|
74
|
+
- bin/setup
|
75
|
+
- gamecenter-auth.gemspec
|
76
|
+
- lib/gamecenter/auth.rb
|
77
|
+
- lib/gamecenter/auth/version.rb
|
78
|
+
homepage: https://github.com/bichinger/gamecenter-auth
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.8
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Server-side iOS GameKit/Game Center player authentication
|
102
|
+
test_files: []
|