thecity-plugin 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2733a398109b8abd67889a6b06bf851fa10c3788
4
+ data.tar.gz: fac6692214067a499edf5f15f9b6b4e206f8aa26
5
+ SHA512:
6
+ metadata.gz: f1260cab2bad4645fbb6239661a123294c723ffd2ee1e8a293993f7afc62b5a2b6d0872911bb7917797902bd4356d6eb31e5560e16a126d2d85e9ba55e91bed2
7
+ data.tar.gz: 773f7b8103247c35f48d6b7bc6652fbadc79130349cc37f5e0b50aaa5ea568e20e5073977e58af07b6d4df816c25b5e804d8f864df35f0c692df473c58e84353
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .idea
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cityplugin.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Mark Blair
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # The City Plugin
2
+
3
+ Provides methods to decrypt data coming from The City plugin framework.
4
+
5
+ ## Installation
6
+
7
+ Tested with Ruby 1.9.3
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'thecity-plugin'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install thecity-plugin
20
+
21
+ ## Usage
22
+
23
+ The City Plugin framework will post data to your plugin to identify the user and provide a key for calling further City APIs.
24
+
25
+ The data that is posted consists of two pieces of data:
26
+
27
+ 1. city_data - encrypted data from The City
28
+ 2. city_data_iv - an initialization vector used to decrypt the data (along with your app secret key)
29
+
30
+ This gem provides a method to take your city_date, city_data_iv, and secret and it decrypts and returns the data.
31
+
32
+ example usage:
33
+
34
+ $ Thecity::Plugin::decrypt_city_data(ENCRYPTED_STRING, IV, SECRET)
35
+
36
+ NOTE: SECRET is actually the first 32 characters of your secret key
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ end
7
+
8
+ desc "Run tests"
9
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ require "thecity-plugin/version"
2
+ require "base64"
3
+ require 'openssl'
4
+ require 'uri'
5
+
6
+ module Thecity
7
+ module Plugin
8
+
9
+ def self.decrypt_city_data(city_data, city_data_iv, secret)
10
+ if !city_data.nil?
11
+ string_to_decrypt = Base64.urlsafe_decode64(city_data)
12
+ iv = Base64.urlsafe_decode64(city_data_iv)
13
+ return city_decrypt(string_to_decrypt, secret, iv)
14
+ else
15
+ return {}
16
+ end
17
+ end
18
+
19
+ def self.city_decrypt(encrypted_data, key, iv, cipher_type = "AES-256-CBC")
20
+ aes = OpenSSL::Cipher::Cipher.new(cipher_type)
21
+ aes.decrypt
22
+ aes.key = key
23
+ aes.iv = iv if iv != nil
24
+ aes.update(encrypted_data) + aes.final
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ module Thecity
2
+ module Plugin
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'thecity-plugin'
3
+
4
+
5
+ class CitypluginTest < Test::Unit::TestCase
6
+
7
+ TEST_ENCRYPTED_STRING = "mi8120mtdLklO7TLg_aaWGBVvIfSLnBXYhOH-ssYk308qJM0A8lJVVjOQW4bEqaQ82Trf2ur041zhE5EihnIeOz5C-rhuV9ChYLAZYhVM8-pDZBqWVLAfTaz6QjWzOjDtJwbKdDUElbPtrEZwPc8QlAB6EPwH-cITfy_5zbdUJVzVG4mELlL9OV61eBALQyLtE7Yhuwy8eZxzW30mEWWFqpKtfniUybX4GS3fhp-5VI="
8
+ TEST_DECRYPTED_STRING = '{"oauth_token":"7dcf516250bf550bf93bf2b12fbb4613ec6f562f1103c341299d2c3f06d50433","global_user_id":959745582,"account_id":1,"user_id":946060874,"subdomain":"local"}'
9
+
10
+ TEST_IV = 'fF_XYU82htUXkSH1c66eew=='
11
+ TEST_SECRET = '2566099a01ddb7913a9a37dd967a74bd'
12
+
13
+ def test_decrypt
14
+ assert_equal(TEST_DECRYPTED_STRING, Thecity::Plugin::decrypt_city_data(TEST_ENCRYPTED_STRING, TEST_IV, TEST_SECRET))
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'thecity-plugin/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "thecity-plugin"
8
+ gem.version = Thecity::Plugin::VERSION
9
+ gem.authors = ["Mark Blair"]
10
+ gem.email = ["mark@onthecity.org"]
11
+ gem.description = %q{Provides methods to decrypt data coming from The City plugin framework}
12
+ gem.summary = %q{Provides methods to decrypt data coming from The City plugin framework}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thecity-plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Blair
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Provides methods to decrypt data coming from The City plugin framework
14
+ email:
15
+ - mark@onthecity.org
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - lib/thecity-plugin.rb
26
+ - lib/thecity-plugin/version.rb
27
+ - test/test_cityplugin.rb
28
+ - thecity-plugin.gemspec
29
+ homepage: ''
30
+ licenses: []
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubyforge_project:
48
+ rubygems_version: 2.1.5
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Provides methods to decrypt data coming from The City plugin framework
52
+ test_files:
53
+ - test/test_cityplugin.rb
54
+ has_rdoc: