pnthr 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: c69e755f251091dd59c1f981d2917afb1e612705
4
+ data.tar.gz: 2f871cd87237edb54903904b5fa1a994073fa02d
5
+ SHA512:
6
+ metadata.gz: c73241e5538e4b4250d970c9cd4423d403fb989f9d67e00a9bcdb83e6b7ed5aac40f18d56cc91cbde79ad4f7759575bb2b21812e55891482107a8771a0acb9c5
7
+ data.tar.gz: a3b7e45466fc785813534bf929a209ba2eb91bd2a5b3975ef1d060c8435e8d543caf1562d99823e0c43fad1d832d3349e6556317cc224be69e6b724102f05323
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pnthr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Clay McIlrath
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,31 @@
1
+ # Pnthr
2
+
3
+ A Ruby Gem for using the pnthr security service
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'pnthr'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install pnthr
18
+
19
+ ## Usage
20
+
21
+ @pnthr = Pnthr.new(app_id, app_secret)
22
+ @pnthr.roar('data to be encrypted')
23
+ # Response will be a string like: PR/Sfl7o4Y0gjlYZyWg=-534c33bb66373500
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/pnthr/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ module Pnthr
2
+ VERSION = "1.0.0"
3
+ end
data/lib/pnthr.rb ADDED
@@ -0,0 +1,85 @@
1
+ require "pnthr/version"
2
+ require "uri"
3
+ require "net/http"
4
+ require "net/https"
5
+ require "base64"
6
+
7
+ module Pnthr
8
+ class Security
9
+
10
+ attr_accessor :request, :cipher
11
+
12
+ def initialize(id, secret, options = {})
13
+ @cipher = OpenSSL::Cipher::AES.new(secret.length * 8, :CFB)
14
+
15
+ options[:url] ||= 'https://pnthr-api.herokuapp.com/'
16
+ options[:ssl].nil? ? true : options[:ssl]
17
+ options[:iv] ||= @cipher.random_iv
18
+
19
+ @request = {
20
+ url: options[:url],
21
+ uri: URI.parse(options[:url]),
22
+ id: id,
23
+ iv: options[:iv],
24
+ secret: secret,
25
+ ssl: options[:ssl]
26
+ }
27
+ end
28
+
29
+ #
30
+ # Roar - Encrypts the payload, makes the request and returns the response
31
+ #
32
+ def roar(payload)
33
+ make_request(encrypt(payload))
34
+ end
35
+
36
+ #
37
+ # Encrypt - Simple AES encryption
38
+ #
39
+ # - a variable length key is used for greatest flexibility
40
+ # - CFB is used
41
+ #
42
+ # + Needs HMAC
43
+ # + Needs variable IV to be passed with request
44
+ #
45
+ def encrypt(data, key = nil, iv = nil)
46
+ key ||= @request[:secret]
47
+ iv ||= @request[:iv]
48
+
49
+ @cipher.encrypt
50
+ @cipher.key = key
51
+ @cipher.iv = iv
52
+
53
+ @cipher.update(data)
54
+ end
55
+
56
+ #
57
+ # Decrypt - Simple AES decryption
58
+ #
59
+ # + Needs to retrieve IV from the first layer
60
+ #
61
+ def decrypt(data, key = nil, iv = nil)
62
+ key ||= @request[:secret]
63
+ iv ||= @request[:iv]
64
+
65
+ @cipher.decrypt
66
+ @cipher.key = key
67
+ @cipher.iv = iv
68
+
69
+ @cipher.update(Base64.decode64(data))
70
+ end
71
+
72
+ private
73
+
74
+ def make_request(payload)
75
+ https = Net::HTTP.new(@request[:uri].host, @request[:uri].port)
76
+ https.use_ssl = @request[:ssl]
77
+
78
+ package = Base64.encode64(payload).strip! + "-#{@request[:iv]}"
79
+ puts package
80
+
81
+ https.post(@request[:uri].path, package, { 'pnthr' => @request[:id] })
82
+ end
83
+
84
+ end
85
+ end
data/pnthr.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pnthr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pnthr"
8
+ spec.version = Pnthr::VERSION
9
+ spec.authors = ["Clay McIlrath"]
10
+ spec.email = ["clay.mcilrath@gmail.com"]
11
+ spec.summary = "Data Encryption with pnthr.net"
12
+ spec.description = "Encrypt anything and everything in a way that cannot be hacked through pnthr.net"
13
+ spec.homepage = "https://github.com/thinkclay/pnthr.git"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+ require 'pnthr'
3
+
4
+ describe Pnthr do
5
+
6
+ host_url = 'http://localhost:3000/'
7
+ ssl_on = false
8
+ app_id = '534c33bb6637350002000000'
9
+ app_secret = '9857ec6046ee8d22b90ce68214a8304b'
10
+
11
+ pnthr = Pnthr::Security.new(app_id, app_secret, url: host_url, ssl: ssl_on, iv: app_id[0..15])
12
+ response = pnthr.roar('this is a test')
13
+
14
+ it "should have a valid host url" do
15
+ URI.parse(host_url).should be_a_kind_of(URI::HTTP)
16
+ end
17
+
18
+ it "should have a host url with a trailing slash" do
19
+ /\/$/.match(host_url).should_not be_nil
20
+ end
21
+
22
+ it "should request the root path" do
23
+ pnthr.request[:uri].path.should eq "/"
24
+ end
25
+
26
+ it "should not use SSL for local tests" do
27
+ pnthr.request[:ssl].should be false
28
+ end
29
+
30
+ it "should properly set the request url" do
31
+ pnthr.request[:url].should eq host_url
32
+ end
33
+
34
+ it "should properly set the ssl option" do
35
+ pnthr.request[:ssl].should eq ssl_on
36
+ end
37
+
38
+ it "should properly set the app id" do
39
+ pnthr.request[:id].should eq app_id
40
+ end
41
+
42
+ it "should properly set the app secret" do
43
+ pnthr.request[:secret].should eq app_secret
44
+ end
45
+
46
+ it "should properly set the app initialization vector" do
47
+ pnthr.request[:iv].should eq app_id[0..15]
48
+ end
49
+
50
+ it "should respond with HTTP 200 code" do
51
+ response.code.should eq '200'
52
+ end
53
+
54
+ it "should respond with a predictable string" do
55
+ response.body.should eq 'NuCn7VFKvrcLzneoRG4='
56
+ end
57
+
58
+ it "should encrypt with a predictable string" do
59
+ test = Base64.encode64(pnthr.encrypt('this is a test')).strip! + "-#{app_id[0..15]}"
60
+
61
+ test.should eq 'PR/Sfl7o4Y0gjlYZyWg=-534c33bb66373500'
62
+ end
63
+
64
+ # it "should fail without user, password, name, city, state, and products" do
65
+ # expect { CorteraApi.new(user: 'foo').login }.to raise_error(RuntimeError, 'A password must be provided for Cortera API')
66
+ # expect { CorteraApi.new(password: 'bar').login }.to raise_error(RuntimeError, 'A user must be provided for Cortera API')
67
+ #
68
+ # cortera.get()["ReportResult"]["Status"].should eq 400
69
+ # end
70
+ #
71
+ # it "should fail authentication" do
72
+ # cortera.get({:params => {name: "Arrae", city: "Denver", state: "CO"}})["ReportResult"]["Status"].should eq 401
73
+ # end
74
+
75
+ end
@@ -0,0 +1,17 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pnthr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Clay McIlrath
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Encrypt anything and everything in a way that cannot be hacked through
42
+ pnthr.net
43
+ email:
44
+ - clay.mcilrath@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - lib/pnthr.rb
55
+ - lib/pnthr/version.rb
56
+ - pnthr.gemspec
57
+ - spec/lib/pnthr_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/thinkclay/pnthr.git
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Data Encryption with pnthr.net
83
+ test_files:
84
+ - spec/lib/pnthr_spec.rb
85
+ - spec/spec_helper.rb