asherah 0.4.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e488eb972195bbc3f37253f2d71b54ad89d069c24260e7800de4602df9277ca5
4
+ data.tar.gz: c865721c410b6a887cbb89b425d64dd17bae9ceda8c2796ca68ff67537750bb9
5
+ SHA512:
6
+ metadata.gz: 141ef3ec23e647f077372e3026dc68539609fec19b05b4ce683d06b30ba8d7b9253ec62beb38a2edec4adfe63e62d1596ed5694e9ffa6822bd37a4a231b220e6
7
+ data.tar.gz: d8ca23008b6146270b4d13cbc0a1d0c8d84d798fe4a45b54cddacefc351040b7667823c19321aef09f8b142b628b84b8b27f0ae8840e16db59eeb4f99266426e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,34 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - 'vendor/**/*' # Github Actions
7
+ - 'tmp/**/*'
8
+
9
+ Layout/LineLength:
10
+ Max: 120
11
+
12
+ Metrics/BlockLength:
13
+ Enabled: false
14
+
15
+ Metrics/MethodLength:
16
+ Enabled: false
17
+
18
+ Style/WordArray:
19
+ Enabled: false
20
+
21
+ Style/SymbolArray:
22
+ Enabled: false
23
+
24
+ Style/MultilineBlockChain:
25
+ Enabled: false
26
+
27
+ Style/BlockDelimiters:
28
+ Enabled: false
29
+
30
+ Metrics/AbcSize:
31
+ Enabled: false
32
+
33
+ Style/GuardClause:
34
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,37 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.4.0] - 2022-03-25
4
+
5
+ - Download native file during gem install and verify checksum
6
+ - Upgrade to use asherah-cobhan v0.4.11
7
+
8
+ ## [0.3.0] - 2022-03-22
9
+
10
+ - Free up cobhan buffers after encrypt/decrypt to prevent growing heap memory
11
+ - Use local `estimate_buffer` calculation instead of FFI call
12
+ - Upgrade to use asherah-cobhan v0.4.3
13
+
14
+ ## [0.2.0] - 2022-03-21
15
+
16
+ - Implement versioning for asherah-cobhan binaries
17
+ - Upgrade to use asherah-cobhan v0.3.1
18
+ - Add BadConfig error and expose error codes
19
+ - Remove DRR methods and use JSON exclusively
20
+ - Cross language testing using Asherah Go
21
+
22
+ ## [0.1.0] - 2022-03-14
23
+
24
+ - First official release
25
+
26
+ ## [0.1.0.beta2] - 2022-03-14
27
+
28
+ - Add smoke tests for native gems
29
+ - Change to use `SetupJson` instead of `Setup`
30
+ - Update config options to make them consistent with Asherah Go
31
+ - Add `shutdown`
32
+ - Add `encrypt_to_json` and `decrypt_from_json`
33
+ - Add coverage report
34
+
35
+ ## [0.1.0.beta1] - 2022-03-07
36
+
37
+ - Initial proof of concept
@@ -0,0 +1,77 @@
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, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and 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 within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be 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 oss@godaddy.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 https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
77
+
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,128 @@
1
+ # Contributing
2
+
3
+ Everyone is welcome to contribute to GoDaddy's Open Source Software.
4
+ Contributing doesn’t just mean submitting pull requests. To get involved,
5
+ you can report or triage bugs, and participate in discussions on the
6
+ evolution of each project.
7
+
8
+ No matter how you want to get involved, we ask that you first learn what’s
9
+ expected of anyone who participates in the project by reading the Contribution
10
+ Guidelines and our [Code of Conduct][coc].
11
+
12
+ **Please Note:** GitHub is for bug reports and contributions primarily -
13
+ if you have a support question head over to [GoDaddy's Open Source
14
+ Software Slack channel][slack]. You can request an invite
15
+ [here][invite].
16
+
17
+ ## Answering Questions
18
+
19
+ One of the most important and immediate ways you can support this project is
20
+ to answer questions on [Slack][slack] or [Github][issues]. Whether you’re
21
+ helping a newcomer understand a feature or troubleshooting an edge case with a
22
+ seasoned developer, your knowledge and experience with a programming language
23
+ can go a long way to help others.
24
+
25
+ ## Reporting Bugs
26
+
27
+ **Do not report potential security vulnerabilities here. Refer to
28
+ [SECURITY.md](./SECURITY.md) for more details about the process of reporting
29
+ security vulnerabilities.**
30
+
31
+ Before submitting a ticket, please search our [Issue Tracker][issues] to make
32
+ sure it does not already exist and have a simple replication of the behavior. If
33
+ the issue is isolated to one of the dependencies of this project, please create
34
+ a Github issue in that project. All dependencies should be open source software
35
+ and can be found on Github.
36
+
37
+ Submit a ticket for your issue, assuming one does not already exist:
38
+
39
+ - Create it on the project's [issue Tracker][issues].
40
+ - Clearly describe the issue by following the template layout
41
+ - Make sure to include steps to reproduce the bug.
42
+ - A reproducible (unit) test could be helpful in solving the bug.
43
+ - Describe the environment that (re)produced the problem.
44
+
45
+ ## Triaging bugs or contributing code
46
+
47
+ If you're triaging a bug, first make sure that you can reproduce it. Once a bug
48
+ can be reproduced, reduce it to the smallest amount of code possible. Reasoning
49
+ about a sample or unit test that reproduces a bug in just a few lines of code
50
+ is easier than reasoning about a longer sample.
51
+
52
+ From a practical perspective, contributions are as simple as:
53
+
54
+ 1. Fork and clone the repo, [see Github's instructions if you need help.][fork]
55
+ 1. Create a branch for your PR with `git checkout -b pr/your-branch-name`
56
+ 1. Make changes on the branch of your forked repository.
57
+ 1. When committing, reference your issue (if present) and include a note about
58
+ the fix.
59
+ 1. Please also add/update unit tests for your changes.
60
+ 1. Push the changes to your fork and submit a pull request to the 'main
61
+ development branch' branch of the projects' repository.
62
+
63
+ If you are interested in making a large change and feel unsure about its overall
64
+ effect, start with opening an Issue in the project's [Issue Tracker][issues]
65
+ with a high-level proposal and discuss it with the core contributors through
66
+ Github comments or in [Slack][slack]. After reaching a consensus with core
67
+ contributors about the change, discuss the best way to go about implementing it.
68
+
69
+ > Tip: Keep your main branch pointing at the original repository and make
70
+ > pull requests from branches on your fork. To do this, run:
71
+ >
72
+ > ```sh
73
+ > git remote add upstream https://github.com/godaddy/asherah-ruby.git
74
+ > git fetch upstream
75
+ > git branch --set-upstream-to=upstream/main main
76
+ > ```
77
+ >
78
+ > This will add the original repository as a "remote" called "upstream," Then
79
+ > fetch the git information from that remote, then set your local main
80
+ > branch to use the upstream main branch whenever you run git pull. Then you
81
+ > can make all of your pull request branches based on this main branch.
82
+ > Whenever you want to update your version of main, do a regular git pull.
83
+
84
+ ## Code Review
85
+
86
+ Any open source project relies heavily on code review to improve software
87
+ quality. All significant changes, by all developers, must be reviewed before
88
+ they are committed to the repository. Code reviews are conducted on GitHub
89
+ through comments on pull requests or commits. The developer responsible for a
90
+ code change is also responsible for making all necessary review-related changes.
91
+
92
+ Sometimes code reviews will take longer than you would hope for, especially for
93
+ larger features. Here are some accepted ways to speed up review times for your
94
+ patches:
95
+
96
+ - Review other people’s changes. If you help out, others will more likely be
97
+ willing to do the same for you.
98
+ - Split your change into multiple smaller changes. The smaller your change,
99
+ the higher the probability that somebody will take a quick look at it.
100
+ - Mention the change on [Slack][slack]. If it is urgent, provide reasons why it
101
+ is important to get this change landed. Remember that you are asking for valuable
102
+ time from other professional developers.
103
+
104
+ **Note that anyone is welcome to review and give feedback on a change, but only
105
+ people with commit access to the repository can approve it.**
106
+
107
+ ## Attribution of Changes
108
+
109
+ When contributors submit a change to this project, after that change is
110
+ approved, other developers with commit access may commit it for the author. When
111
+ doing so, it is important to retain correct attribution of the contribution.
112
+ Generally speaking, Git handles attribution automatically.
113
+
114
+ ## Code Style and Documentation
115
+
116
+ Ensure that your contribution follows the standards set by the project's style
117
+ guide with respect to patterns, naming, documentation and testing.
118
+
119
+ # Additional Resources
120
+
121
+ - [General GitHub Documentation](https://help.github.com/)
122
+ - [GitHub Pull Request documentation](https://help.github.com/send-pull-requests/)
123
+
124
+ [issues]: https://github.com/godaddy/asherah-ruby/issues/
125
+ [coc]: ./CODE_OF_CONDUCT.md
126
+ [slack]: https://godaddy-oss.slack.com/
127
+ [fork]: https://help.github.com/en/articles/fork-a-repo
128
+ [invite]: https://godaddy-oss-slack.herokuapp.com
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in asherah.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'cucumber', '~> 7.1.0'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 GoDaddy Operating Company, LLC.
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.
data/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # Asherah
2
+
3
+ Asherah is a Ruby FFI wrapper around Go version of [Asherah](https://github.com/godaddy/asherah) application-layer encryption SDK. Asherah provides advanced encryption features and defense in depth against compromise. It uses a technique known as "envelope encryption" and supports cloud-agnostic data storage and key management.
4
+
5
+ Check out the following documentation to get more familiar with the concepts and configuration options:
6
+
7
+ - [Design and Architecture](https://github.com/godaddy/asherah/blob/master/docs/DesignAndArchitecture.md)
8
+ - [Key Caching](https://github.com/godaddy/asherah/blob/master/docs/KeyCaching.md)
9
+ - [Key Management Service](https://github.com/godaddy/asherah/blob/master/docs/KeyManagementService.md)
10
+ - [Metastore](https://github.com/godaddy/asherah/blob/master/docs/Metastore.md)
11
+ - [System Requirements](https://github.com/godaddy/asherah/blob/master/docs/SystemRequirements.md)
12
+
13
+ ## Supported Platforms
14
+
15
+ Currently supported platforms are Linux and Darwin operating systems for x64 and arm64 CPU architectures.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ ```ruby
22
+ gem 'asherah'
23
+ ```
24
+
25
+ ```bash
26
+ bundle install
27
+ ```
28
+
29
+ Or install it yourself as:
30
+
31
+ ```bash
32
+ gem install asherah
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ Configure Asherah:
38
+
39
+ ```ruby
40
+ Asherah.configure do |config|
41
+ config.kms = 'static'
42
+ config.metastore = 'memory'
43
+ config.service_name = 'service'
44
+ config.product_id = 'product'
45
+ end
46
+ ```
47
+
48
+ Encrypt some data for a `partition_id`
49
+
50
+ ```ruby
51
+ partition_id = 'user_1'
52
+ data = 'PII data'
53
+ data_row_record_json = Asherah.encrypt(partition_id, data)
54
+ puts data_row_record_json
55
+ ```
56
+
57
+ Decrypt `data_row_record_json`
58
+
59
+ ```ruby
60
+ decrypted_data = Asherah.decrypt(partition_id, data_row_record_json)
61
+ puts decrypted_data
62
+ ```
63
+
64
+ ## Development
65
+
66
+ 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.
67
+
68
+ To install this gem onto your local machine, run `rake install`.
69
+
70
+ To release a new version, update the version number in `version.rb`, create and push a version tag:
71
+
72
+ ```
73
+ git tag -a v$(rake version) -m "Version $(rake version)"
74
+ git push origin v$(rake version)
75
+ ```
76
+
77
+ And then create a release in Github with title `echo "Version $(rake version)"` that will trigger `.github/workflows/publish.yml` workflow and push the `.gem` file to [rubygems.org](https://rubygems.org):
78
+
79
+
80
+ ## Contributing
81
+
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/godaddy/asherah-ruby.
83
+
84
+ ## License
85
+
86
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ desc 'Download the binary for the current platform'
13
+ task :download do
14
+ tmp_dir = 'tmp'
15
+ FileUtils.mkdir_p(tmp_dir)
16
+ FileUtils.cd(tmp_dir, verbose: true) do
17
+ system('ruby ../ext/asherah/extconf.rb')
18
+ end
19
+ end
20
+
21
+ task default: %i[spec rubocop]
22
+ task spec: :download
23
+
24
+ desc 'Print current version'
25
+ task :version do
26
+ puts Asherah::VERSION
27
+ end
data/SECURITY.md ADDED
@@ -0,0 +1,19 @@
1
+ # Reporting Security Issues
2
+
3
+ We take security very seriously at GoDaddy. We appreciate your efforts to
4
+ responsibly disclose your findings, and will make every effort to acknowledge
5
+ your contributions.
6
+
7
+ ## Where should I report security issues?
8
+
9
+ In order to give the community time to respond and upgrade, we strongly urge you
10
+ report all security issues privately.
11
+
12
+ To report a security issue in one of our Open Source projects email us directly
13
+ at **oss@godaddy.com** and include the word "SECURITY" in the subject line.
14
+
15
+ This mail is delivered to our Open Source Security team.
16
+
17
+ After the initial reply to your report, the team will keep you informed of the
18
+ progress being made towards a fix and announcement, and may ask for additional
19
+ information or guidance.
data/asherah.gemspec ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/asherah/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'asherah'
7
+ spec.version = Asherah::VERSION
8
+ spec.authors = ['GoDaddy']
9
+ spec.email = ['oss@godaddy.com']
10
+
11
+ spec.summary = 'Application Layer Encryption SDK'
12
+ spec.description = <<~DESCRIPTION
13
+ Asherah is an application-layer encryption SDK that provides advanced
14
+ encryption features and defense in depth against compromise.
15
+ DESCRIPTION
16
+
17
+ spec.homepage = 'https://github.com/godaddy/asherah-ruby'
18
+ spec.license = 'MIT'
19
+ spec.required_ruby_version = '>= 2.5.0'
20
+
21
+ spec.metadata['homepage_uri'] = spec.homepage
22
+ spec.metadata['source_code_uri'] = 'https://github.com/godaddy/asherah-ruby'
23
+ spec.metadata['changelog_uri'] = 'https://github.com/godaddy/asherah-ruby/blob/main/CHANGELOG.md'
24
+ spec.metadata['rubygems_mfa_required'] = 'true'
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject do |f|
30
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
31
+ end
32
+ end
33
+ spec.bindir = 'exe'
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ['lib']
36
+ spec.extensions = ['ext/asherah/extconf.rb']
37
+
38
+ spec.add_dependency 'cobhan', '~> 0.2.0'
39
+ spec.add_development_dependency 'dotenv', '~> 2.7.6'
40
+ spec.add_development_dependency 'rspec', '~> 3.10.0'
41
+ spec.add_development_dependency 'rubocop', '~> 1.7'
42
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'
43
+ spec.add_development_dependency 'simplecov-console', '~> 0.9.1'
44
+ end
@@ -0,0 +1,5 @@
1
+ version: v0.4.11
2
+ libasherah-arm64.so: bc044b74453fc8fceca564fb127c9f2748aeac107791bd24c680ced1fcb7b816
3
+ libasherah-x64.so: 82f10505ef11fba2c8e027668d9b5c89584f73eb1e53a9f5ff21d5705ecffb3a
4
+ libasherah-arm64.dylib: 0b843d002212722c442c990d84e6ceac73c78e1663260be8c3f759a9a283b14a
5
+ libasherah-x64.dylib: fd0592ed4cdfbc7b3a2534b540c22301a9669c6c37dfb3d28f600ccc9ba975f8
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'mkmf'
4
+ create_makefile('asherah/asherah')
5
+
6
+ require_relative 'native_file'
7
+ NativeFile.download
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open-uri'
4
+ require 'fileutils'
5
+ require 'digest'
6
+ require 'yaml'
7
+ require 'cobhan'
8
+
9
+ # Downloads native file and verifies checksum
10
+ class NativeFile
11
+ LIB_NAME = 'libasherah'
12
+ ROOT_DIR = File.expand_path('../../', __dir__)
13
+ CHECKSUMS_FILE = File.expand_path('checksums.yml', __dir__)
14
+ CHECKSUMS = YAML.load_file(CHECKSUMS_FILE)
15
+ VERSION = CHECKSUMS.fetch('version')
16
+ RETRIES = 3
17
+ RETRY_DELAY = 1
18
+
19
+ class << self
20
+ def download
21
+ file_name = Class.new.extend(Cobhan).library_file_name(LIB_NAME)
22
+ lib_dir = File.join(ROOT_DIR, 'lib/asherah')
23
+ abort "#{lib_dir} does not exist" unless File.exist?(lib_dir)
24
+
25
+ native_dir = "#{lib_dir}/native"
26
+ FileUtils.mkdir_p(native_dir)
27
+
28
+ file_path = File.join(native_dir, file_name)
29
+ abort "#{file_path} already exists" if File.exist?(file_path)
30
+
31
+ checksum = CHECKSUMS.fetch(file_name) do
32
+ abort "Unsupported platform #{RUBY_PLATFORM}"
33
+ end
34
+
35
+ content = download_content(file_name)
36
+
37
+ sha256 = Digest::SHA256.hexdigest(content)
38
+ abort "Could not verify checksum of #{file_name}" if sha256 != checksum
39
+
40
+ File.binwrite(file_path, content)
41
+ end
42
+
43
+ private
44
+
45
+ def download_content(file_name)
46
+ tries = 0
47
+
48
+ begin
49
+ tries += 1
50
+ url = "https://github.com/godaddy/asherah-cobhan/releases/download/#{VERSION}/#{file_name}"
51
+ puts "Downloading #{url}"
52
+ URI.parse(url).open.read
53
+ rescue Net::OpenTimeout, Net::ReadTimeout => e
54
+ if tries <= RETRIES
55
+ puts "Got #{e.class}... retrying in #{RETRY_DELAY} seconds"
56
+ sleep RETRY_DELAY
57
+ retry
58
+ else
59
+ raise e
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module Asherah
6
+ # @attr [String] service_name, The name of this service
7
+ # @attr [String] product_id, The name of the product that owns this service
8
+ # @attr [String] kms, The master key management service (static or aws)
9
+ # @attr [String] metastore, The type of metastore for persisting keys (rdbms, dynamodb, memory)
10
+ # @attr [String] connection_string, The database connection string (required when metastore is rdbms)
11
+ # @attr [String] replica_read_consistency, For Aurora sessions using write forwarding (eventual, global, session)
12
+ # @attr [String] dynamo_db_endpoint, An optional endpoint URL (for dynamodb metastore)
13
+ # @attr [String] dynamo_db_region, The AWS region for DynamoDB requests (for dynamodb metastore)
14
+ # @attr [String] dynamo_db_table_name, The table name for DynamoDB (for dynamodb metastore)
15
+ # @attr [Boolean] enable_region_suffix, Configure the metastore to use regional suffixes (for dynamodb metastore)
16
+ # @attr [String] region_map, List of key-value pairs in the form of REGION1=ARN1[,REGION2=ARN2] (required for aws kms)
17
+ # @attr [String] preferred_region, The preferred AWS region (required for aws kms)
18
+ # @attr [Integer] session_cache_max_size, The maximum number of sessions to cache
19
+ # @attr [Integer] session_cache_duration, The amount of time in seconds a session will remain cached
20
+ # @attr [Integer] expire_after, The amount of time in seconds a key is considered valid
21
+ # @attr [Integer] check_interval, The amount of time in seconds before cached keys are considered stale
22
+ # @attr [Boolean] enable_session_caching, Enable shared session caching
23
+ # @attr [Boolean] verbose, Enable verbose logging output
24
+ class Config
25
+ MAPPING = {
26
+ service_name: :ServiceName,
27
+ product_id: :ProductID,
28
+ kms: :KMS,
29
+ metastore: :Metastore,
30
+ connection_string: :ConnectionString,
31
+ replica_read_consistency: :ReplicaReadConsistency,
32
+ dynamo_db_endpoint: :DynamoDBEndpoint,
33
+ dynamo_db_region: :DynamoDBRegion,
34
+ dynamo_db_table_name: :DynamoDBTableName,
35
+ enable_region_suffix: :EnableRegionSuffix,
36
+ region_map: :RegionMap,
37
+ preferred_region: :PreferredRegion,
38
+ session_cache_max_size: :SessionCacheMaxSize,
39
+ session_cache_duration: :SessionCacheDuration,
40
+ enable_session_caching: :EnableSessionCaching,
41
+ expire_after: :ExpireAfter,
42
+ check_interval: :CheckInterval,
43
+ verbose: :Verbose
44
+ }.freeze
45
+
46
+ KMS_TYPES = ['static', 'aws'].freeze
47
+ METASTORE_TYPES = ['rdbms', 'dynamodb', 'memory'].freeze
48
+
49
+ attr_accessor(*MAPPING.keys)
50
+
51
+ def validate!
52
+ validate_service_name
53
+ validate_product_id
54
+ validate_kms
55
+ validate_metastore
56
+ validate_kms_attributes
57
+ end
58
+
59
+ def to_json(*args)
60
+ config = {}.tap do |c|
61
+ MAPPING.each_pair do |our_key, their_key|
62
+ value = public_send(our_key)
63
+ c[their_key] = value unless value.nil?
64
+ end
65
+ end
66
+
67
+ JSON.generate(config, *args)
68
+ end
69
+
70
+ private
71
+
72
+ def validate_service_name
73
+ raise Error::ConfigError, 'config.service_name not set' if service_name.nil?
74
+ end
75
+
76
+ def validate_product_id
77
+ raise Error::ConfigError, 'config.product_id not set' if product_id.nil?
78
+ end
79
+
80
+ def validate_kms
81
+ raise Error::ConfigError, 'config.kms not set' if kms.nil?
82
+ unless KMS_TYPES.include?(kms)
83
+ raise Error::ConfigError, "config.kms must be one of these: #{KMS_TYPES.join(', ')}"
84
+ end
85
+ end
86
+
87
+ def validate_metastore
88
+ raise Error::ConfigError, 'config.metastore not set' if metastore.nil?
89
+ unless METASTORE_TYPES.include?(metastore)
90
+ raise Error::ConfigError, "config.metastore must be one of these: #{METASTORE_TYPES.join(', ')}"
91
+ end
92
+ end
93
+
94
+ def validate_kms_attributes
95
+ if kms == 'aws'
96
+ raise Error::ConfigError, 'config.region_map not set' if region_map.nil?
97
+ raise Error::ConfigError, 'config.region_map must be a Hash' unless region_map.is_a?(Hash)
98
+ raise Error::ConfigError, 'config.preferred_region not set' if preferred_region.nil?
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asherah
4
+ # Asherah Error converts the error code to error message
5
+ module Error
6
+ ConfigError = Class.new(StandardError)
7
+ NotInitialized = Class.new(StandardError)
8
+ AlreadyInitialized = Class.new(StandardError)
9
+ GetSessionFailed = Class.new(StandardError)
10
+ EncryptFailed = Class.new(StandardError)
11
+ DecryptFailed = Class.new(StandardError)
12
+ BadConfig = Class.new(StandardError)
13
+
14
+ CODES = {
15
+ -100 => NotInitialized,
16
+ -101 => AlreadyInitialized,
17
+ -102 => GetSessionFailed,
18
+ -103 => EncryptFailed,
19
+ -104 => DecryptFailed,
20
+ -105 => BadConfig
21
+ }.freeze
22
+
23
+ def self.check_result!(result, message)
24
+ return unless result.negative?
25
+
26
+ error_class = Error::CODES.fetch(result, StandardError)
27
+ raise error_class, "#{message} (#{result})"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asherah
4
+ VERSION = '0.4.0'
5
+ end
data/lib/asherah.rb ADDED
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'asherah/version'
4
+ require 'asherah/config'
5
+ require 'asherah/error'
6
+ require 'cobhan'
7
+
8
+ # Asherah is a Ruby wrapper around Asherah Go application-layer encryption SDK.
9
+ module Asherah
10
+ extend Cobhan
11
+
12
+ LIB_ROOT_PATH = File.expand_path('asherah/native', __dir__)
13
+ load_library(LIB_ROOT_PATH, 'libasherah', [
14
+ [:SetupJson, [:pointer], :int32],
15
+ [:EncryptToJson, [:pointer, :pointer, :pointer], :int32],
16
+ [:DecryptFromJson, [:pointer, :pointer, :pointer], :int32],
17
+ [:Shutdown, [], :void]
18
+ ].freeze)
19
+
20
+ ESTIMATED_ENCRYPTION_OVERHEAD = 48
21
+ ESTIMATED_ENVELOPE_OVERHEAD = 185
22
+ BASE64_OVERHEAD = 1.34
23
+
24
+ class << self
25
+ # Configures Asherah
26
+ #
27
+ # @yield [Config]
28
+ # @return [void]
29
+ def configure
30
+ config = Config.new
31
+ yield config
32
+ config.validate!
33
+ @intermediated_key_overhead_bytesize = config.product_id.bytesize + config.service_name.bytesize
34
+
35
+ config_buffer = string_to_cbuffer(config.to_json)
36
+
37
+ result = SetupJson(config_buffer)
38
+ Error.check_result!(result, 'SetupJson failed')
39
+ end
40
+
41
+ # Encrypts data for a given partition_id and returns DataRowRecord in JSON format.
42
+ #
43
+ # DataRowRecord contains the encrypted key and data, as well as the information
44
+ # required to decrypt the key encryption key. This object data should be stored
45
+ # in your data persistence as it's required to decrypt data.
46
+ #
47
+ # EnvelopeKeyRecord represents an encrypted key and is the data structure used
48
+ # to persist the key in the key table. It also contains the meta data
49
+ # of the key used to encrypt it.
50
+ #
51
+ # KeyMeta contains the `id` and `created` timestamp for an encryption key.
52
+ #
53
+ # @param partition_id [String]
54
+ # @param data [String]
55
+ # @return [String], DataRowRecord in JSON format
56
+ def encrypt(partition_id, data)
57
+ partition_id_buffer = string_to_cbuffer(partition_id)
58
+ data_buffer = string_to_cbuffer(data)
59
+ estimated_buffer_bytesize = estimate_buffer(data.bytesize, partition_id.bytesize)
60
+ output_buffer = allocate_cbuffer(estimated_buffer_bytesize)
61
+
62
+ result = EncryptToJson(partition_id_buffer, data_buffer, output_buffer)
63
+ Error.check_result!(result, 'EncryptToJson failed')
64
+
65
+ cbuffer_to_string(output_buffer)
66
+ ensure
67
+ [partition_id_buffer, data_buffer, output_buffer].map(&:free)
68
+ end
69
+
70
+ # Decrypts a DataRowRecord in JSON format for a partition_id and returns decrypted data.
71
+ #
72
+ # @param partition_id [String]
73
+ # @param json [String], DataRowRecord in JSON format
74
+ # @return [String], Decrypted data
75
+ def decrypt(partition_id, json)
76
+ partition_id_buffer = string_to_cbuffer(partition_id)
77
+ data_buffer = string_to_cbuffer(json)
78
+ output_buffer = allocate_cbuffer(json.bytesize)
79
+
80
+ result = DecryptFromJson(partition_id_buffer, data_buffer, output_buffer)
81
+ Error.check_result!(result, 'DecryptFromJson failed')
82
+
83
+ cbuffer_to_string(output_buffer)
84
+ ensure
85
+ [partition_id_buffer, data_buffer, output_buffer].map(&:free)
86
+ end
87
+
88
+ # Stop the Asherah instance
89
+ def shutdown
90
+ Shutdown()
91
+ end
92
+
93
+ private
94
+
95
+ def estimate_buffer(data_bytesize, partition_bytesize)
96
+ ESTIMATED_ENVELOPE_OVERHEAD +
97
+ @intermediated_key_overhead_bytesize +
98
+ partition_bytesize +
99
+ ((data_bytesize + ESTIMATED_ENCRYPTION_OVERHEAD) * BASE64_OVERHEAD)
100
+ end
101
+ end
102
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asherah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - GoDaddy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cobhan
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: dotenv
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.7.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.7.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.10.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.10.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.21.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.21.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov-console
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.9.1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.9.1
97
+ description: |
98
+ Asherah is an application-layer encryption SDK that provides advanced
99
+ encryption features and defense in depth against compromise.
100
+ email:
101
+ - oss@godaddy.com
102
+ executables: []
103
+ extensions:
104
+ - ext/asherah/extconf.rb
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - ".ruby-version"
110
+ - CHANGELOG.md
111
+ - CODE_OF_CONDUCT.md
112
+ - CONTRIBUTING.md
113
+ - Gemfile
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - SECURITY.md
118
+ - asherah.gemspec
119
+ - ext/asherah/checksums.yml
120
+ - ext/asherah/extconf.rb
121
+ - ext/asherah/native_file.rb
122
+ - lib/asherah.rb
123
+ - lib/asherah/config.rb
124
+ - lib/asherah/error.rb
125
+ - lib/asherah/version.rb
126
+ homepage: https://github.com/godaddy/asherah-ruby
127
+ licenses:
128
+ - MIT
129
+ metadata:
130
+ homepage_uri: https://github.com/godaddy/asherah-ruby
131
+ source_code_uri: https://github.com/godaddy/asherah-ruby
132
+ changelog_uri: https://github.com/godaddy/asherah-ruby/blob/main/CHANGELOG.md
133
+ rubygems_mfa_required: 'true'
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 2.5.0
143
+ required_rubygems_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ requirements: []
149
+ rubygems_version: 3.3.7
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Application Layer Encryption SDK
153
+ test_files: []