response_encryption 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +100 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/response_encryption/act_as_a_encryption_controller.rb +24 -0
- data/lib/response_encryption/active_model_service.rb +27 -0
- data/lib/response_encryption/asymmetric_encrypter.rb +23 -0
- data/lib/response_encryption/encrypt_attributes.rb +56 -0
- data/lib/response_encryption/railtie.rb +23 -0
- data/lib/response_encryption/serialization_ext.rb +26 -0
- data/lib/response_encryption/symmetric_encrypter.rb +37 -0
- data/lib/response_encryption/version.rb +3 -0
- data/lib/response_encryption.rb +56 -0
- data/response_encryption.gemspec +33 -0
- metadata +176 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5b66d0f12107ea82773c56e4ee90322d1820ee7d
|
4
|
+
data.tar.gz: 870397c8c4e178af6ccce7785873fb47143e3827
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 17ab55dddfd71dbbecdc8549fefe5702efb72136d63e8547eb9c8c8dd8f38a90f7d253848606587e500122527195383795a7ae2678bf6fb5a981b9674b3c2485
|
7
|
+
data.tar.gz: 17409cf29c9c478fe10c47166a5c791cbee95a854dfa0005c8412a27f8cb3bae4bff3738e8a7798aa47ebd30add8257e728e248f44981fef1f0b2f9aea25ca4c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at diego.f.gomez.pardo@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Diego Gomez
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
# ResponseEncryption
|
2
|
+
|
3
|
+
This gem can be used to encrypt the attributes of your rails application or then entired body. It can be integrated with jsonapi-resources, active-model-serializer or just with a normal Rails application.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'response_encryption'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install response_encryption
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### JSON API resources
|
24
|
+
- Install and configure the `jsonapi-resource` gem in your project
|
25
|
+
- add an initializer with the ResponseEncryption config
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
ResponseEncryption.configure do |config|
|
29
|
+
config.encryption_strategy = :encrypted_attributes
|
30
|
+
config.serializer_gem = :jsonapi_resources
|
31
|
+
config.algothim = 'AES'
|
32
|
+
config.algorithm_key_length = '256'
|
33
|
+
config.block_cipher_mode = 'CBC'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
- include the `ResponseEncryption::ActsAsEncryptionController` module into your `ApplicationController` and define a context method there, as follows:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class ApiController < ApplicationController
|
41
|
+
include ResponseEncryption::ActsAsEncryptionController
|
42
|
+
|
43
|
+
def context
|
44
|
+
default_context.merge({
|
45
|
+
encoded_symmetric_key: get_encoded_symmetric_key_from(database_or_file)
|
46
|
+
})
|
47
|
+
end
|
48
|
+
end
|
49
|
+
```
|
50
|
+
- include the `include ResponseEncryption::EncryptAttributes` your XResource
|
51
|
+
- add the fields that you want to encrypt as parameters in the your XResource
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
encrypted_attrs :field1, field2, ... , fieldn
|
55
|
+
```
|
56
|
+
### Active model serializer
|
57
|
+
- Install and configure the `active_model_serializers` gem in your project
|
58
|
+
- add an initializer with the ResponseEncryption config
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
ResponseEncryption.configure do |config|
|
62
|
+
config.encryption_strategy = :encrypted_attributes
|
63
|
+
config.serializer_gem = :active_model_serializers
|
64
|
+
config.algothim = 'AES'
|
65
|
+
config.algorithm_key_length = '256'
|
66
|
+
config.block_cipher_mode = 'CBC'
|
67
|
+
end
|
68
|
+
```
|
69
|
+
|
70
|
+
- include the `ResponseEncryption::ActsAsEncryptionController` module into your `ApplicationController`
|
71
|
+
- include the `include ResponseEncryption::EncryptAttributes` your XSerializer
|
72
|
+
- add the fields that you want to encrypt as parameters in the your XSerializer
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
encrypted_attrs :field1, field2, ... , fieldn
|
76
|
+
```
|
77
|
+
## TODO
|
78
|
+
- explain ResponseEncryption config parameters
|
79
|
+
- show examples
|
80
|
+
- add encryption_strategy for encrypt_body
|
81
|
+
- test other algorithms to encrypt
|
82
|
+
- implement responses without any serializer
|
83
|
+
|
84
|
+
## Development
|
85
|
+
|
86
|
+
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.
|
87
|
+
|
88
|
+
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).
|
89
|
+
|
90
|
+
## Contributing
|
91
|
+
|
92
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/response_encryption. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
93
|
+
|
94
|
+
## License
|
95
|
+
|
96
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
97
|
+
|
98
|
+
## Code of Conduct
|
99
|
+
|
100
|
+
Everyone interacting in the ResponseEncryption project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/response_encryption/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "response_encryption"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'response_encryption/serialization_ext'
|
2
|
+
module ResponseEncryption
|
3
|
+
module ActsAsEncryptionController
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
before_action :add_nonce_header
|
8
|
+
|
9
|
+
# @return [ Hash ]
|
10
|
+
def default_context
|
11
|
+
@encoded_nonce ||= ResponseEncryption::SymmetricEncrypter.encoded_nonce
|
12
|
+
{
|
13
|
+
encoded_nonce: @encoded_nonce,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def add_nonce_header
|
20
|
+
response.headers['Replay-Nonce'] = context[:encoded_nonce]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_model'
|
2
|
+
class ResponseEncryption::ActiveModelService
|
3
|
+
include ::ActiveModel::Model
|
4
|
+
ActiveModel::Errors.class_eval do
|
5
|
+
# Add errors from another ActiveModel::Errors
|
6
|
+
# @params errors [ ActiveModel::Errors ]
|
7
|
+
# @model_name [ String ]
|
8
|
+
def add_many(errors, label=nil)
|
9
|
+
if errors.is_a? ActiveModel::Errors
|
10
|
+
errors.each do |attribute, message|
|
11
|
+
label ||= attribute
|
12
|
+
add(label, message)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
super
|
20
|
+
@errors = ::ActiveModel::Errors.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [ Boolean ]
|
24
|
+
def valid?
|
25
|
+
errors.blank?
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module ResponseEncryption
|
2
|
+
class AsymmetricEncrypter < ResponseEncryption::ActiveModelService
|
3
|
+
attr_reader :public_key, :encrypted_data
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
validate(options)
|
7
|
+
@public_key = OpenSSL::PKey::RSA.new(options[:public_key])
|
8
|
+
end
|
9
|
+
|
10
|
+
# @param data [ Object ] which should respond to #to_s
|
11
|
+
# @param encode_data [ Boolean ]
|
12
|
+
# @return [ String ] with the encrypted and encoded information
|
13
|
+
def encrypt(data, encode_data = true)
|
14
|
+
return data if data.blank?
|
15
|
+
encrypted = public_key.public_encrypt(data.to_s)
|
16
|
+
@encrypted_data = encode_data ? Base64.encode64(encrypted) : encrypted
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate(options)
|
20
|
+
errors.add(:param_missing, 'You must to provide public_key option') if options[:public_key].blank?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'response_encryption/serialization_ext'
|
2
|
+
module ResponseEncryption::EncryptAttributes
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
def initialize(object, options)
|
7
|
+
super(object, options)
|
8
|
+
context = context_from(options)
|
9
|
+
if ResponseEncryption.encrypted_attributes_strategy?
|
10
|
+
raise(ActionController::ParameterMissing, 'You must to set the context for the resource/serializer') if context.blank?
|
11
|
+
@encrypter = ResponseEncryption::SymmetricEncrypter.new(encoded_iv: context[:encoded_nonce], encoded_key: context[:encoded_symmetric_key])
|
12
|
+
self.class.encrypt_attributes!(object)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Retrieve the context variable that will be send to the Serializer or Resource in order to pass
|
17
|
+
# some important variables.
|
18
|
+
# @param param [ Hash ]
|
19
|
+
# @return [ Hash ]
|
20
|
+
def context_from(param)
|
21
|
+
case ResponseEncryption.serializer_gem
|
22
|
+
when :active_model_serializers
|
23
|
+
raise "You must to set encoded_symmetric_key option in the context hash" if param[:context]&.slice(:encoded_symmetric_key).blank?
|
24
|
+
param[:context]
|
25
|
+
when :jsonapi_resources
|
26
|
+
raise "You must to set encoded_symmetric_key option in the context hash" if param[:encoded_symmetric_key].blank?
|
27
|
+
param
|
28
|
+
when :none
|
29
|
+
raise 'pending!!'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def cipher
|
34
|
+
ResponseEncryption.cipher
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ClassMethods
|
39
|
+
attr_accessor :encrypted_attrs
|
40
|
+
def encrypted_attrs(*attributes)
|
41
|
+
@encrypted_attrs = attributes.map { |attr| attr.to_s }
|
42
|
+
end
|
43
|
+
|
44
|
+
def encrypt_attributes!(model)
|
45
|
+
@encrypted_attrs.each do |column_name|
|
46
|
+
if model.respond_to? column_name
|
47
|
+
define_method(column_name) do
|
48
|
+
@encrypter.encrypt(model.__send__(column_name).try(:to_s))
|
49
|
+
end
|
50
|
+
else
|
51
|
+
# TODO: get methods form Serializer
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "response_encryption"
|
4
|
+
require "rails"
|
5
|
+
|
6
|
+
module ResponseEncryption
|
7
|
+
class Railtie < Rails::Railtie # :nodoc:
|
8
|
+
#
|
9
|
+
# Set up our default config options
|
10
|
+
# Do this before the app initializers run so we don't override custom settings
|
11
|
+
#
|
12
|
+
config.before_initialize do
|
13
|
+
ResponseEncryption.configure do |config|
|
14
|
+
config.enabled = true
|
15
|
+
config.encryption_strategy = :encrypted_attributes # encrypted_body
|
16
|
+
config.serializer_gem = :none # :json-resource, :active_serializer
|
17
|
+
config.algothim = 'AES'
|
18
|
+
config.algorithm_key_length = '256'
|
19
|
+
config.block_cipher_mode = 'CBC'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
begin
|
2
|
+
require 'action_controller'
|
3
|
+
require 'action_controller/serialization'
|
4
|
+
# mokey patch for add context to Serilization options
|
5
|
+
ActionController::Serialization.class_eval do
|
6
|
+
def get_serializer(resource, options = {})
|
7
|
+
unless use_adapter?
|
8
|
+
warn 'ActionController::Serialization#use_adapter? has been removed. '\
|
9
|
+
"Please pass 'adapter: false' or see ActiveSupport::SerializableResource.new"
|
10
|
+
options[:adapter] = false
|
11
|
+
end
|
12
|
+
|
13
|
+
options.fetch(:namespace) { options[:namespace] = namespace_for_serializer }
|
14
|
+
options[:context] = context# TODO: take this context var and define it into app controller.
|
15
|
+
|
16
|
+
serializable_resource = ActiveModelSerializers::SerializableResource.new(resource, options)
|
17
|
+
serializable_resource.serialization_scope ||= options.fetch(:scope) { serialization_scope }
|
18
|
+
serializable_resource.serialization_scope_name = options.fetch(:scope_name) { _serialization_scope }
|
19
|
+
# For compatibility with the JSON renderer: `json.to_json(options) if json.is_a?(String)`.
|
20
|
+
# Otherwise, since `serializable_resource` is not a string, the renderer would call
|
21
|
+
# `to_json` on a String and given odd results, such as `"".to_json #=> '""'`
|
22
|
+
serializable_resource.adapter.is_a?(String) ? serializable_resource.adapter : serializable_resource
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ResponseEncryption
|
2
|
+
class SymmetricEncrypter < ResponseEncryption::ActiveModelService
|
3
|
+
attr_reader :cipher, :iv, :key, :encrypted_data
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
validate(options)
|
7
|
+
@cipher = ResponseEncryption.cipher
|
8
|
+
@iv = Base64.decode64(options[:encoded_iv])
|
9
|
+
@key = Base64.decode64(options[:encoded_key])
|
10
|
+
end
|
11
|
+
|
12
|
+
# @param data [ Object ] which respond to #to_s
|
13
|
+
# @param encode_data [ Boolean ]
|
14
|
+
# @return [ String ] with the encrypted and encoded information
|
15
|
+
def encrypt(data, encode_data = true)
|
16
|
+
return data if data.blank?
|
17
|
+
cipher.encrypt
|
18
|
+
cipher.key = key
|
19
|
+
# This is the initial vector that we will use as nonce code.
|
20
|
+
# This nonce is going in the headers as a 'Replay-Nonce'
|
21
|
+
cipher.iv = iv
|
22
|
+
encrypted = cipher.update(data.to_s) + cipher.final
|
23
|
+
@encrypted_data = encode_data ? Base64.encode64(encrypted) : encrypted
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate(options)
|
27
|
+
errors.add(:param_missing, 'You must to set the encoded_iv (nonce) option') if options[:encoded_iv].blank?
|
28
|
+
errors.add(:param_missing, 'You must to set the encoded_key (symmetric-key) option') if options[:encoded_key].blank?
|
29
|
+
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def encoded_nonce
|
33
|
+
Base64.encode64(ResponseEncryption.cipher.random_iv)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'response_encryption/railtie' if defined?(Rails)
|
2
|
+
# # require 'active_support/core_ext/object/blank'
|
3
|
+
|
4
|
+
require "response_encryption/version"
|
5
|
+
require "response_encryption/active_model_service"
|
6
|
+
require "response_encryption/asymmetric_encrypter"
|
7
|
+
require "response_encryption/symmetric_encrypter"
|
8
|
+
require "response_encryption/act_as_a_encryption_controller"
|
9
|
+
require "response_encryption/encrypt_attributes"
|
10
|
+
require "response_encryption/serialization_ext"
|
11
|
+
|
12
|
+
|
13
|
+
module ResponseEncryption
|
14
|
+
class << self
|
15
|
+
|
16
|
+
WRITER_METHODS = []
|
17
|
+
ACCESSOR_METHODS = [:serializer_gem, :algothim, :algorithm_key_length, :block_cipher_mode, :enabled, :cipher, :encryption_strategy]
|
18
|
+
|
19
|
+
attr_accessor(*ACCESSOR_METHODS)
|
20
|
+
attr_writer(*WRITER_METHODS)
|
21
|
+
|
22
|
+
def configure
|
23
|
+
yield self if block_given?
|
24
|
+
raise "The serializer_gem value is invalid. Please select one of these: #{ available_serializer_gems.join(', ') }" unless available_serializer_gems.include? serializer_gem
|
25
|
+
raise "The available_encryption_strategies value is invalid. Please select one of these: #{ available_serializer_gems.join(', ') }" unless available_encryption_strategies.include? encryption_strategy
|
26
|
+
end
|
27
|
+
|
28
|
+
def cipher
|
29
|
+
@cipher = OpenSSL::Cipher.new("#{ algothim }-#{ algorithm_key_length }-#{ block_cipher_mode }")
|
30
|
+
end
|
31
|
+
|
32
|
+
def available_serializer_gems
|
33
|
+
%i(active_model_serializers jsonapi_resources none)
|
34
|
+
end
|
35
|
+
|
36
|
+
def available_encryption_strategies
|
37
|
+
%i(encrypted_attributes encrypted_body)
|
38
|
+
end
|
39
|
+
|
40
|
+
def encrypted_attributes_strategy?
|
41
|
+
self.encryption_strategy == :encrypted_attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
def encrypted_body_strategy?
|
45
|
+
self.encryption_strategy == :encrypted_body
|
46
|
+
end
|
47
|
+
|
48
|
+
def active_model_serializers?
|
49
|
+
self.serializer_gem == :active_model_serializers
|
50
|
+
end
|
51
|
+
|
52
|
+
def jsonapi_resources?
|
53
|
+
self.serializer_gem == :jsonapi_resources
|
54
|
+
end
|
55
|
+
end
|
56
|
+
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 "response_encryption/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "response_encryption"
|
8
|
+
spec.version = ResponseEncryption::VERSION
|
9
|
+
spec.authors = ["Diego Gomez"]
|
10
|
+
spec.email = ["diego.f.gomez.pardo@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gem to encrypt the API response}
|
13
|
+
spec.description = %q{Gem to encrypt the API response.}
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.homepage = "https://github.com/degzcs/response_encryption"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency 'rspec-rails', "~> 3.0"
|
27
|
+
spec.add_development_dependency "spirit_hands", "~> 2.1"
|
28
|
+
spec.add_development_dependency "sqlite3", "~> 1.3"
|
29
|
+
spec.add_development_dependency 'active_model_serializers', '~> 0.10'
|
30
|
+
spec.add_development_dependency 'jsonapi-resources', '~> 0.9'
|
31
|
+
spec.add_dependency "rails", "~> 5.1"
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: response_encryption
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Diego Gomez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-13 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.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: spirit_hands
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.1'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sqlite3
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: active_model_serializers
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: jsonapi-resources
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.9'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.9'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.1'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.1'
|
125
|
+
description: Gem to encrypt the API response.
|
126
|
+
email:
|
127
|
+
- diego.f.gomez.pardo@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- CODE_OF_CONDUCT.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- bin/console
|
141
|
+
- bin/setup
|
142
|
+
- lib/response_encryption.rb
|
143
|
+
- lib/response_encryption/act_as_a_encryption_controller.rb
|
144
|
+
- lib/response_encryption/active_model_service.rb
|
145
|
+
- lib/response_encryption/asymmetric_encrypter.rb
|
146
|
+
- lib/response_encryption/encrypt_attributes.rb
|
147
|
+
- lib/response_encryption/railtie.rb
|
148
|
+
- lib/response_encryption/serialization_ext.rb
|
149
|
+
- lib/response_encryption/symmetric_encrypter.rb
|
150
|
+
- lib/response_encryption/version.rb
|
151
|
+
- response_encryption.gemspec
|
152
|
+
homepage: https://github.com/degzcs/response_encryption
|
153
|
+
licenses:
|
154
|
+
- MIT
|
155
|
+
metadata: {}
|
156
|
+
post_install_message:
|
157
|
+
rdoc_options: []
|
158
|
+
require_paths:
|
159
|
+
- lib
|
160
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - ">="
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
|
+
requirements:
|
167
|
+
- - ">="
|
168
|
+
- !ruby/object:Gem::Version
|
169
|
+
version: '0'
|
170
|
+
requirements: []
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 2.6.11
|
173
|
+
signing_key:
|
174
|
+
specification_version: 4
|
175
|
+
summary: Gem to encrypt the API response
|
176
|
+
test_files: []
|