porticor_bombarder 0.0.1

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: 0ac708f4a8e3487e9a8bd3d4158ee2758e424d44
4
+ data.tar.gz: d3d15e3b8961a89a332bbbc69ae4d77de0e110b5
5
+ SHA512:
6
+ metadata.gz: 385dce39493284703b9e88aa5c43c90cb5f8218248aaa1d56c3ac09b4d69ba5efbc22d93ef4ead9d9cb3feb59889a8f1c82f6c24e0ce7afddac27cf2d298efb5
7
+ data.tar.gz: c4b8c4f6cd55aa7e18741361763abb29adb8477c5d0805581b90574f85a6ec47a1cf3efbd47f2d9ebdf742de8114c65493d8873418abd7f7d1cefaec43048aa1
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
@@ -0,0 +1,63 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="FacetManager">
4
+ <facet type="gem" name="Ruby Gem">
5
+ <configuration>
6
+ <option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
7
+ <option name="GEM_APP_TEST_PATH" value="" />
8
+ <option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
9
+ </configuration>
10
+ </facet>
11
+ </component>
12
+ <component name="NewModuleRootManager">
13
+ <content url="file://$MODULE_DIR$" />
14
+ <orderEntry type="inheritedJdk" />
15
+ <orderEntry type="sourceFolder" forTests="false" />
16
+ <orderEntry type="module-library">
17
+ <library name="porticor_bombarder (v0.0.1, /home/kannav/workspace/headerlabs/gems/porticor_bombarder) [path][gem]">
18
+ <CLASSES>
19
+ <root url="file://$MODULE_DIR$/lib" />
20
+ <root url="file://$MODULE_DIR$/.idea" />
21
+ </CLASSES>
22
+ <SOURCES>
23
+ <root url="file://$MODULE_DIR$/lib" />
24
+ <root url="file://$MODULE_DIR$/.idea" />
25
+ </SOURCES>
26
+ </library>
27
+ </orderEntry>
28
+ <orderEntry type="library" scope="PROVIDED" name="actionmailer (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="actionpack (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="actionview (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="activemodel (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="activerecord (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="arel (v5.0.1.20140414130214, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.2, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="erubis (v2.7.0, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="faraday (v0.9.0, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="faraday_middleware (v0.9.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="hashie (v3.3.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="hike (v1.2.3, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v0.6.11, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="json (v1.8.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="mail (v2.5.4, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="mime-types (v1.25.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.4.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="multi_json (v1.10.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.0.0, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="polyglot (v0.3.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="rack (v1.5.2, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="rack-test (v0.6.2, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="rails (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="railties (v4.1.5, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="sprockets (v2.12.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="sprockets-rails (v2.1.4, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="strongbox (v0.7.0, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="thor (v0.19.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.4, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="tilt (v1.4.1, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="treetop (v1.4.15, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.2, RVM: ruby-2.0.0-p247 [banana]) [gem]" level="application" />
61
+ </component>
62
+ </module>
63
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in porticor_bombarder.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 rajeevkannav
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,85 @@
1
+ # PorticorBombarder
2
+
3
+ encrypts activerecord attributes with Porticor's encrypted keys management.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'porticor_bombarder'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install porticor_bombarder
18
+
19
+ create porticor_attrs.yml to your config folder of application with structure as given below.
20
+ Here you need to define model and attributes which need to be encrypted.
21
+
22
+ ```yml
23
+ ---
24
+ :model_name_1:
25
+ - attribute_name
26
+ :model_name_2:
27
+ :specific_pem_file_name:
28
+ - attribute_name
29
+ - attribute_name
30
+ :model_name_3:
31
+ :specific_pem_file_name:
32
+ - attribute_name
33
+ - attribute_name
34
+ :model_name_4:
35
+ :specific_pem_file_name:
36
+ - attribute_name
37
+ - attribute_name
38
+ - attribute_name
39
+ ```
40
+
41
+ create porticor.yml to your config folder of application with structure as given below.
42
+ Here you need to define porticor's instance url, key, secret.
43
+
44
+ ```yml
45
+ YOUR_RAILS_APP_ENVIRONMENT:
46
+ api_url: 'https://xxxxxxxxxxx-xxxxxxxxxxx.d.porticor.net'
47
+ api_key: 'YOUR_PORTICOR_API_KEY'
48
+ api_secret: 'YOUR_PORTICOR_API_SECRET'
49
+ backup_enabled: true # true if FileSystem storage required.
50
+ YOUR_RAILS_APP_ENVIRONMENT:
51
+ api_url: 'https://xxxxxxxxxxx-xxxxxxxxxxx.d.porticor.net'
52
+ api_key: 'YOUR_PORTICOR_API_KEY'
53
+ api_secret: 'YOUR_PORTICOR_API_SECRET'
54
+ backup_enabled: true # true if FileSystem storage required.
55
+ YOUR_RAILS_APP_ENVIRONMENT:
56
+ api_url: 'https://xxxxxxxxxxx-xxxxxxxxxxx.d.porticor.net'
57
+ api_key: 'YOUR_PORTICOR_API_KEY'
58
+ api_secret: 'YOUR_PORTICOR_API_SECRET'
59
+ backup_enabled: true # true if FileSystem storage required.
60
+ YOUR_RAILS_APP_ENVIRONMENT:
61
+ api_url: 'https://xxxxxxxxxxx-xxxxxxxxxxx.d.porticor.net'
62
+ api_key: 'YOUR_PORTICOR_API_KEY'
63
+ api_secret: 'YOUR_PORTICOR_API_SECRET'
64
+ backup_enabled: true # true if FileSystem storage required.
65
+ ```
66
+
67
+ For already existing records you need to run following rake task.
68
+
69
+ ```ruby
70
+ rake porticor_bombarder:encrypt
71
+ ```
72
+
73
+ ## To-do's
74
+
75
+ 1. Implement CacheClass.
76
+ 2. Backup key_pairs to AWS-S3.
77
+
78
+
79
+ ## Contributing
80
+
81
+ 1. Fork it ( https://github.com/rajeevkannav/porticor_bombarder/fork )
82
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
83
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
84
+ 4. Push to the branch (`git push origin my-new-feature`)
85
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,156 @@
1
+ require 'hashie'
2
+ require 'faraday_middleware'
3
+ require 'securerandom'
4
+
5
+ module PorticorBombarder
6
+
7
+ class Client
8
+
9
+ @@porticor_require_options = %w(api_key api_secret api_url)
10
+
11
+ attr_accessor *@@porticor_require_options
12
+
13
+ def initialize
14
+ @@porticor_require_options.each do |r_port_option|
15
+ raise InvalidOptions.new("You must specify your Porticor #{r_port_option}.") unless PORTICOR_CONFIGURATION[r_port_option].present?
16
+ public_send("#{r_port_option}=", PORTICOR_CONFIGURATION[r_port_option])
17
+ end
18
+ end
19
+
20
+ def fetch_encryption_key(name, source = 'cache')
21
+ begin
22
+ return case source
23
+ when 'cache'
24
+ get_encryption_key_via_cache(name)
25
+ when 'file_system'
26
+ get_encryption_key_via_file_system(name)
27
+ when 'appliance'
28
+ get_encryption_key(name)
29
+ else
30
+ raise Error.new('Invalid encryption_key source.')
31
+ end
32
+ rescue KeyPairCacheNotAvailable => e
33
+ PorticorBombarder::PorticorLogger.logger.warn e.message
34
+ fetch_encryption_key(name, 'file_system')
35
+ rescue KeyPairFileSystemNotAvailable => e
36
+ PorticorBombarder::PorticorLogger.logger.warn e.message
37
+ fetch_encryption_key(name, 'appliance')
38
+ rescue Exception => e
39
+ PorticorBombarder::PorticorLogger.logger.warn e.message
40
+ nil
41
+ end
42
+ end
43
+
44
+ def get_encryption_key_via_cache(name)
45
+ raise KeyPairCacheNotAvailable.new('Requested key_pair not available in Cache.')
46
+ end
47
+
48
+ def get_encryption_key_via_file_system(name)
49
+ begin
50
+ File.read(File.join(PORTICOR_STORAGE_PATH, "#{name}.pem"))
51
+ rescue
52
+ raise KeyPairFileSystemNotAvailable.new('Requested key_pair not available in FileSystem.')
53
+ end
54
+ end
55
+
56
+ def get_encryption_key(name)
57
+ response = get("/api/protected_items/#{URI.escape(name)}", api_cred: temp_cred)
58
+ if success?(response)
59
+ response.body.item
60
+ else
61
+ nil
62
+ end
63
+ end
64
+
65
+ def find_or_create_encryption_key(name, algorithm = 'RSA2048', export = true)
66
+ begin
67
+ create_encryption_key(name, algorithm, export)
68
+ rescue DuplicateItemError
69
+ fetch_encryption_key(name)
70
+ rescue Exception => e
71
+ PorticorBombarder::PorticorLogger.logger.warn e.message
72
+ nil
73
+ end
74
+ end
75
+
76
+ def create_encryption_key(name, algorithm = 'RSA2048', export = true)
77
+ response = post("/api/protected_items/#{URI.escape(name)}", algorithm: algorithm, exportable: export, api_cred: temp_cred)
78
+ if success?(response)
79
+ response.body.item
80
+ else
81
+ case response.body['error_code']
82
+ when 'CreateDuplicate'
83
+ raise DuplicateItemError.new response.body['error']
84
+ else
85
+ raise Error.new response.body['error_code']
86
+ end
87
+ end
88
+ end
89
+
90
+ def temp_cred
91
+ time = Time.now.to_i
92
+ nonce = generate_nonce
93
+ sig = sign_cred_request(nonce, time)
94
+
95
+ @@temp_cred = begin
96
+ response = get('/api/creds/get_temporary_credential',
97
+ api_key_id: api_key,
98
+ time: time,
99
+ nonce: nonce,
100
+ api_signature: sig)
101
+ if success?(response)
102
+ response.body.credential
103
+ else
104
+ nil
105
+ end
106
+ end
107
+ end
108
+
109
+ private
110
+
111
+ # return true for successful response code
112
+ def success?(response)
113
+ response.success? && response.body['error'].empty?
114
+ end
115
+
116
+ # return some random string
117
+ def generate_nonce
118
+ SecureRandom.hex(8)
119
+ end
120
+
121
+ # Computing the Signature for get_temporary_credential Currently it works for API V1
122
+ # VERSION - 2 will be done sometime later.
123
+ def sign_cred_request(nonce, time)
124
+ str_to_sign = "get_temporary_credential?api_key_id=#{api_key}&nonce=#{nonce}&time=#{time}"
125
+ digest = OpenSSL::Digest.new('sha256')
126
+ sig = OpenSSL::HMAC.hexdigest(digest, api_secret, str_to_sign)
127
+ return 'hmac-sha256:' + sig
128
+ end
129
+
130
+ # returns Porticor's client connection
131
+ def connection
132
+ Faraday.new(url: api_url) do |conn|
133
+ conn.request :json
134
+ conn.use Faraday::Response::Mashify
135
+ conn.response :json, content_type: /\bjson$/
136
+ conn.response :raise_error
137
+ conn.adapter Faraday.default_adapter
138
+ end
139
+ end
140
+
141
+ # Porticor's API GET request
142
+ def get(path, options = {})
143
+ connection.get(path, options)
144
+ end
145
+
146
+ # Porticor's API requires PUT request for creating an encryption_key
147
+ def post(path, options = {})
148
+ connection.put(path) do |request|
149
+ request.params = options
150
+ end
151
+ end
152
+
153
+ end
154
+ end
155
+
156
+
@@ -0,0 +1,5 @@
1
+ module PorticorBombarder
2
+ PORTICOR_CONFIGURATION = YAML.load_file(File.join('config', 'porticor.yml'))[Rails.env]
3
+ PORTICOR_ENCRYPTED_ATTRIBUTES = YAML.load_file(File.join('config', 'porticor_attrs.yml'))
4
+ PORTICOR_STORAGE_PATH = File.join('porticor', Rails.env)
5
+ end
@@ -0,0 +1,8 @@
1
+ module PorticorBombarder
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace PorticorBombarder
4
+
5
+ config.autoload_paths += %W(#{config.root}/lib/modules)
6
+
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module PorticorBombarder
2
+ class InvalidOptions < StandardError;
3
+ end
4
+
5
+ class Error < StandardError;
6
+ end
7
+
8
+ class DuplicateItemError < Error;
9
+ end
10
+
11
+ class KeyPairFileSystemNotAvailable < StandardError
12
+ end
13
+
14
+ class KeyPairCacheNotAvailable < StandardError
15
+ end
16
+
17
+ end
@@ -0,0 +1,31 @@
1
+ module PorticorBombarder
2
+ class Invigilator
3
+
4
+ def self.inspector!
5
+ PORTICOR_ENCRYPTED_ATTRIBUTES.each do |key, value|
6
+ columns = case true
7
+ when value.is_a?(Hash)
8
+ value.values.flatten
9
+ when value.is_a?(Array)
10
+ value
11
+ else
12
+ raise Error.new('while inspecting columns type in schema something went wrong.')
13
+ end
14
+ validate(key, columns)
15
+ end
16
+ end
17
+
18
+ def self.validate(model_name, columns)
19
+ begin
20
+ columns.each do |column_name|
21
+ type_in_schema = model_name.to_s.classify.constantize.columns_hash[column_name].type
22
+ puts "#{model_name.to_s.classify}'s column #{column_name} is not of type 'text' (is of type '#{type_in_schema}') and may lead to inadequate space while storing encrypted content." unless (type_in_schema == :text)
23
+ end
24
+ rescue Exception => e
25
+ PorticorBombarder::PorticorLogger.logger.warn e.message
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+
@@ -0,0 +1,15 @@
1
+ require 'logger'
2
+
3
+ module PorticorBombarder
4
+ class PorticorLogger < Logger
5
+ file = File.open(File.join('log', "porticor_bombarder_#{Rails.env}.log"), File::WRONLY | File::APPEND | File::CREAT)
6
+ @@logger ||= new(file, 10, 1024000)
7
+ @@logger.level = DEBUG
8
+
9
+ def self.logger
10
+ @@logger
11
+ end
12
+
13
+ end
14
+ end
15
+
@@ -0,0 +1,54 @@
1
+ require 'strongbox'
2
+
3
+ module PorticorBombarder
4
+
5
+ class Manager
6
+
7
+ def self.porticor_sandbox_registrar!
8
+ PORTICOR_ENCRYPTED_ATTRIBUTES.each do |key, value|
9
+ if value.is_a?(Hash)
10
+ value.each do |pem_name, columns|
11
+ columns.each do |column_name|
12
+ encrypt_and_alias_attribute(key.to_s, column_name, pem_name.to_s)
13
+ end
14
+ end
15
+ elsif value.is_a?(Array)
16
+ value.each do |column_name|
17
+ encrypt_and_alias_attribute(key.to_s, column_name, "#{key}_#{column_name}")
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.encrypt_and_alias_attribute(model_name, column_name, pem_name, options= {})
24
+ obj_class = model_name.classify.constantize
25
+
26
+ obj_class.class_eval do
27
+ encrypt_with_public_key column_name.to_sym,
28
+ key_pair: PorticorBombarder::Client.new.fetch_encryption_key(pem_name),
29
+ symmetric: options[:symmetric] || :never,
30
+ base64: options[:base64] || true
31
+ end
32
+
33
+ obj_class.instance_eval do
34
+ alias_method "encrypted_#{column_name}".to_sym, column_name.to_sym
35
+ define_method(column_name.to_sym) do
36
+ begin
37
+ send("encrypted_#{column_name}".to_sym).decrypt(PorticorBombarder::Client.new.fetch_encryption_key(pem_name))
38
+ rescue OpenSSL::PKey::RSAError => e
39
+ if e.message == "padding check failed"
40
+ PorticorBombarder::PorticorLogger.logger.warn "It seems #{self.class.name}:#{column_name} is not with adequate space to decrypt from RSA key."
41
+ PorticorBombarder::PorticorLogger.logger.warn e.message
42
+ PorticorBombarder::PorticorLogger.logger.warn e.backtrace.join("\n")
43
+ "###{send("encrypted_#{column_name}".to_sym).instance_variable_get(:@instance).attributes[column_name]}##"
44
+ else
45
+ raise e
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,18 @@
1
+ require 'porticor_bombarder/invigilator'
2
+ require 'porticor_bombarder/manager'
3
+
4
+ module PorticorBombarder
5
+
6
+ class Railtie < Rails::Railtie
7
+ initializer "porticor_bombarder.configure_rails_initialization" do
8
+ Worker.builder! #key_pair generator to Porticor
9
+ Invigilator.inspector!
10
+ Manager.porticor_sandbox_registrar!
11
+ end
12
+
13
+ rake_tasks do
14
+ Dir[File.join(File.dirname(__FILE__), '..', 'tasks', '*.rake')].each { |f| load f }
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,3 @@
1
+ module PorticorBombarder
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,37 @@
1
+ module PorticorBombarder
2
+
3
+ class Worker
4
+
5
+ def self.builder!
6
+ PORTICOR_ENCRYPTED_ATTRIBUTES.each do |key, value|
7
+ pem_names = case true
8
+ when value.is_a?(Hash)
9
+ value.keys.collect { |pem_name| pem_name.to_s }
10
+ when value.is_a?(Array)
11
+ value.collect { |column_name| "#{key}_#{column_name}" }
12
+ else
13
+ raise Error.new('some thing wrong.')
14
+ end
15
+ pem_generator(pem_names)
16
+ end
17
+ end
18
+
19
+ def self.pem_generator(pem_file_names)
20
+ pem_file_names.each do |pem_file_name|
21
+ key_pair_string = PorticorBombarder::Client.new.find_or_create_encryption_key(pem_file_name)
22
+ backup(pem_file_name, key_pair_string) if PORTICOR_CONFIGURATION['backup_enabled']
23
+ end
24
+ end
25
+
26
+ #Todo: backup key_pair to file systems later it will be on AWS-S3 bucket
27
+ def self.backup(filename, content)
28
+ FileUtils.mkdir_p PORTICOR_STORAGE_PATH
29
+ file_name_with_path = File.join(PORTICOR_STORAGE_PATH, "#{filename}.pem")
30
+ File.open(file_name_with_path, 'w+') do |f|
31
+ f.write(content)
32
+ end unless File.exists?(file_name_with_path)
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,7 @@
1
+ require 'porticor_bombarder/version'
2
+ require 'porticor_bombarder/constants'
3
+ require 'porticor_bombarder/logger'
4
+ require 'porticor_bombarder/railtie' if defined?(Rails::Railtie)
5
+ require 'porticor_bombarder/exceptions'
6
+ require 'porticor_bombarder/client'
7
+ require 'porticor_bombarder/worker'
@@ -0,0 +1,33 @@
1
+ require 'rake'
2
+ namespace :porticor_bombarder do
3
+ PORTICOR_ENCRYPTED_ATTRIBUTES = YAML.load_file(File.join('config', 'porticor_attrs.yml'))
4
+
5
+ desc 'encrypt existing attributes'
6
+ task :encrypt => :environment do
7
+ PORTICOR_ENCRYPTED_ATTRIBUTES.each do |key, value|
8
+ obj_class = key.to_s.classify.constantize
9
+ case true
10
+ when value.is_a?(Hash)
11
+ value.values.flatten.each do |column_name|
12
+ obj_class.all.each do |obj|
13
+ obj.send(column_name.to_sym)
14
+ if (_match_data = obj.send(column_name.to_sym).match(/^##([\s\S]*)##/))
15
+ obj.update(column_name => _match_data[1])
16
+ end
17
+ end
18
+ end
19
+ when value.is_a?(Array)
20
+ value.each do |column_name|
21
+ obj_class.all.each do |obj|
22
+ obj.send(column_name.to_sym)
23
+ if (_match_data = obj.send(column_name.to_sym).match(/^##([\s\S]*)##/))
24
+ obj.update(column_name => _match_data[1])
25
+ end
26
+ end
27
+ end
28
+ else
29
+ end
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'porticor_bombarder/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'porticor_bombarder'
8
+ spec.version = PorticorBombarder::VERSION
9
+ spec.authors = ['rajeevkannav']
10
+ spec.email = ['rajeevsharma86@gmail.com']
11
+ spec.summary = %q{Porticor + StrongBox}
12
+ spec.description = %q{Encrypt activerecord attributes with Porticor's encrypted keys management.}
13
+ spec.homepage = 'https://github.com/rajeevkannav/PorticorBombarder'
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', '~> 0.8'
23
+
24
+ #
25
+ #runtime_dependencies
26
+ #
27
+ spec.add_runtime_dependency 'rails', '~> 4.0'
28
+ spec.add_runtime_dependency 'activerecord', '~> 4.0'
29
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.9'
30
+ spec.add_runtime_dependency 'hashie', '~> 3.3'
31
+ spec.add_runtime_dependency 'strongbox', '~> 0.7'
32
+
33
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: porticor_bombarder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - rajeevkannav
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-06 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.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activerecord
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '4.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hashie
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '3.3'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '3.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: strongbox
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ description: Encrypt activerecord attributes with Porticor's encrypted keys management.
112
+ email:
113
+ - rajeevsharma86@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .idea/porticor_bombarder.iml
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/porticor_bombarder.rb
125
+ - lib/porticor_bombarder/client.rb
126
+ - lib/porticor_bombarder/constants.rb
127
+ - lib/porticor_bombarder/engine.rb
128
+ - lib/porticor_bombarder/exceptions.rb
129
+ - lib/porticor_bombarder/invigilator.rb
130
+ - lib/porticor_bombarder/logger.rb
131
+ - lib/porticor_bombarder/manager.rb
132
+ - lib/porticor_bombarder/railtie.rb
133
+ - lib/porticor_bombarder/version.rb
134
+ - lib/porticor_bombarder/worker.rb
135
+ - lib/tasks/encrypt_existing_attrs.rake
136
+ - porticor_bombarder.gemspec
137
+ homepage: https://github.com/rajeevkannav/PorticorBombarder
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.2.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Porticor + StrongBox
161
+ test_files: []