asherah 0.1.0-aarch64-linux

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: 5c39b64978d51c220093f649d48c78de122725daff2054c5d0c3065269c639ee
4
+ data.tar.gz: 0ad2f67e8d992766f72c1ed03a7a20e39383c7119d38123721fd254aae96d833
5
+ SHA512:
6
+ metadata.gz: 91d21ae90abcbc8b8611e5f462036998b06902b590998f1043fd9b78207da63781cf73d3deb91d1e8285abb4acd2f5ba8805845b6964690a13e6b658ae828487
7
+ data.tar.gz: d1ca174082aaf0cd1716eafad179ef8b447d66bf008e995144b598251e49b1844c64dc66200e5ed757f3c90edf9306eb15416ead5ea7b3a8b7a7fcf1a134032b
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - 'vendor/**/*' # Github Actions
7
+
8
+ Layout/LineLength:
9
+ Max: 120
10
+
11
+ Metrics/BlockLength:
12
+ Enabled: false
13
+
14
+ Metrics/MethodLength:
15
+ Enabled: false
16
+
17
+ Style/WordArray:
18
+ Enabled: false
19
+
20
+ Style/SymbolArray:
21
+ Enabled: false
22
+
23
+ Style/MultilineBlockChain:
24
+ Enabled: false
25
+
26
+ Style/BlockDelimiters:
27
+ Enabled: false
28
+
29
+ Metrics/AbcSize:
30
+ Enabled: false
31
+
32
+ Style/GuardClause:
33
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-03-14
4
+
5
+ - First official release
6
+
7
+ ## [0.1.0.beta2] - 2022-03-14
8
+
9
+ - Add smoke tests for native gems
10
+ - Change to use `SetupJson` instead of `Setup`
11
+ - Update config options to make them consistent with Asherah Go
12
+ - Add `shutdown`
13
+ - Add `encrypt_to_json` and `decrypt_from_json`
14
+ - Add coverage report
15
+
16
+ ## [0.1.0.beta1] - 2022-03-07
17
+
18
+ - 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,8 @@
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'
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,83 @@
1
+ # Asherah
2
+
3
+ Asherah is a Ruby wrapper around [Asherah Go](https://github.com/godaddy/asherah) application-layer encryption SDK that 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 its concepts:
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
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'asherah'
19
+ ```
20
+
21
+ ```bash
22
+ bundle install
23
+ ```
24
+
25
+ Or install it yourself as:
26
+
27
+ ```bash
28
+ gem install asherah
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ Configure Asherah:
34
+
35
+ ```ruby
36
+ Asherah.configure do |config|
37
+ config.kms_type = 'static'
38
+ config.metastore = 'memory'
39
+ config.service_name = 'gem'
40
+ config.product_id = 'sable'
41
+ end
42
+ ```
43
+
44
+ Encrypt some data for a `partition_id`
45
+
46
+ ```ruby
47
+ partition_id = 'user_1'
48
+ data = 'Some PII data'
49
+ data_row_record = Asherah.encrypt(partition_id, data)
50
+ p data_row_record
51
+ ```
52
+
53
+ Decrypt `data_row_record`
54
+
55
+ ```ruby
56
+ decrypted_data = Asherah.decrypt(partition_id, data_row_record)
57
+ p decrypted_data
58
+ ```
59
+
60
+ ## Development
61
+
62
+ 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.
63
+
64
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/godaddy/asherah-ruby.
69
+
70
+ ## Releasing new gem version
71
+
72
+ ```
73
+ # Create and push a version tag
74
+ git tag -a v$(rake version) -m "Version $(rake version)"
75
+ git push origin v$(rake version)
76
+
77
+ # Create a release in Github to trigger .github/workflows/publish.yml workflow
78
+ echo "Version $(rake version)"
79
+ ```
80
+
81
+ ## License
82
+
83
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubygems/package'
6
+ require 'open-uri'
7
+
8
+ RSpec::Core::RakeTask.new(:spec)
9
+
10
+ require 'rubocop/rake_task'
11
+
12
+ RuboCop::RakeTask.new
13
+
14
+ task default: %i[spec rubocop]
15
+
16
+ DISTRIBUTIONS = {
17
+ 'x86_64-linux' => ['libasherah-x64.so'],
18
+ 'x86_64-darwin' => ['libasherah-x64.dylib'],
19
+ 'aarch64-linux' => ['libasherah-arm64.so'],
20
+ 'arm64-darwin' => ['libasherah-arm64.dylib']
21
+ }.freeze
22
+
23
+ def native_build(platform, native_files)
24
+ puts "Building gem for #{platform}"
25
+
26
+ pkg_dir = File.join(__dir__, 'pkg')
27
+ FileUtils.mkdir_p(pkg_dir)
28
+
29
+ tmp_gem_dir = File.join(__dir__, 'tmp', platform)
30
+ FileUtils.rm_rf(tmp_gem_dir, verbose: true)
31
+ FileUtils.mkdir_p(tmp_gem_dir, verbose: true)
32
+
33
+ # Copy files to tmp gem dir
34
+ gemspec = Bundler.load_gemspec('asherah.gemspec')
35
+ gemspec.files.each do |file|
36
+ dir = File.dirname(file)
37
+ filename = File.basename(file)
38
+ FileUtils.mkdir_p(File.join(tmp_gem_dir, dir))
39
+ FileUtils.copy_file(file, File.join(tmp_gem_dir, dir, filename))
40
+ end
41
+
42
+ # Set platform for native gem build and remove extentions
43
+ gemspec.platform = Gem::Platform.new(platform)
44
+
45
+ native_dir = 'lib/asherah/native'
46
+ FileUtils.cd(tmp_gem_dir, verbose: true) do
47
+ FileUtils.mkdir_p(native_dir)
48
+ native_files.each do |native_file|
49
+ native_file_path = File.join(native_dir, native_file)
50
+ gemspec.files << native_file_path
51
+
52
+ File.open(native_file_path, 'wb') do |file|
53
+ url = "https://github.com/godaddy/asherah-cobhan/releases/download/current/#{native_file}"
54
+ puts "Downloading #{url}"
55
+ file << URI.parse(url).open.read
56
+ end
57
+ end
58
+
59
+ package = Gem::Package.build gemspec
60
+ FileUtils.mv package, File.join(pkg_dir, package)
61
+ end
62
+ end
63
+
64
+ namespace :native do
65
+ desc 'Build all native gems'
66
+ task :build do
67
+ DISTRIBUTIONS.each do |platform, native_files|
68
+ native_build(platform, native_files)
69
+ end
70
+ end
71
+
72
+ namespace :build do
73
+ DISTRIBUTIONS.each do |platform, native_files|
74
+ desc "Build native gem for #{platform}"
75
+ task :"#{platform}" do
76
+ native_build(platform, native_files)
77
+ end
78
+ end
79
+ end
80
+
81
+ namespace :smoke do
82
+ require 'cobhan'
83
+
84
+ filename = Class.new.extend(Cobhan).library_file_name('libasherah')
85
+ platform, _files = DISTRIBUTIONS.detect { |_k, v| v.include?(filename) }
86
+
87
+ desc "Smoke test native gem on #{platform} platform"
88
+ task "#{platform}": :"build:#{platform}" do
89
+ gemspec = Bundler.load_gemspec('asherah.gemspec')
90
+ gemspec.platform = Gem::Platform.new(platform)
91
+
92
+ sh("gem install pkg/#{gemspec.file_name}")
93
+ sh('ruby spec/smoke_test.rb')
94
+ end
95
+ end
96
+ end
97
+
98
+ task :version do
99
+ puts Asherah::VERSION
100
+ 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,43 @@
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
+
37
+ spec.add_dependency 'cobhan', '~> 0.1.3'
38
+ spec.add_development_dependency 'dotenv', '~> 2.7.6'
39
+ spec.add_development_dependency 'rspec', '~> 3.10.0'
40
+ spec.add_development_dependency 'rubocop', '~> 1.7'
41
+ spec.add_development_dependency 'simplecov', '~> 0.21.2'
42
+ spec.add_development_dependency 'simplecov-console', '~> 0.9.1'
43
+ 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,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asherah
4
+ # DataRowRecord contains the encrypted key and data, as well as the information
5
+ # required to decrypt the key encryption key. This object data should be stored
6
+ # in your data persistence as it's required to decrypt data.
7
+ class DataRowRecord
8
+ attr_reader :data, :key
9
+
10
+ # Initializes a new DataRowRecord
11
+ #
12
+ # @param data [String]
13
+ # @param key [EnvelopeKeyRecord]
14
+ # @return DataRowRecord
15
+ def initialize(data:, key:)
16
+ @data = data
17
+ @key = key
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asherah
4
+ # EnvelopeKeyRecord represents an encrypted key and is the data structure used
5
+ # to persist the key in the key table. It also contains the meta data
6
+ # of the key used to encrypt it.
7
+ class EnvelopeKeyRecord
8
+ attr_reader :encrypted_key, :created, :parent_key_meta
9
+
10
+ # Initializes a new EnvelopeKeyRecord
11
+ #
12
+ # @param encrypted_key [String]
13
+ # @param created [Integer]
14
+ # @param parent_key_meta [KeyMeta]
15
+ # @return EnvelopeKeyRecord
16
+ def initialize(encrypted_key:, created:, parent_key_meta:)
17
+ @encrypted_key = encrypted_key
18
+ @created = created
19
+ @parent_key_meta = parent_key_meta
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,28 @@
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
+
13
+ CODES = {
14
+ -100 => NotInitialized,
15
+ -101 => AlreadyInitialized,
16
+ -102 => GetSessionFailed,
17
+ -103 => EncryptFailed,
18
+ -104 => DecryptFailed
19
+ }.freeze
20
+
21
+ def self.check_result!(result, message)
22
+ return unless result.negative?
23
+
24
+ error_class = Error::CODES.fetch(result, StandardError)
25
+ raise error_class, message
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asherah
4
+ # KeyMeta contains the `id` and `created` timestamp for an encryption key.
5
+ class KeyMeta
6
+ attr_reader :id, :created
7
+
8
+ # Initializes a new KeyMeta
9
+ #
10
+ # @param id [String]
11
+ # @param created [Integer]
12
+ # @return KeyMeta
13
+ def initialize(id:, created:)
14
+ @id = id
15
+ @created = created
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Asherah
4
+ VERSION = '0.1.0'
5
+ end
data/lib/asherah.rb ADDED
@@ -0,0 +1,147 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'asherah/version'
4
+ require 'asherah/config'
5
+ require 'asherah/error'
6
+ require 'asherah/key_meta'
7
+ require 'asherah/data_row_record'
8
+ require 'asherah/envelope_key_record'
9
+ require 'cobhan'
10
+
11
+ # Asherah is a Ruby wrapper around Asherah Go application-layer encryption SDK.
12
+ module Asherah
13
+ extend Cobhan
14
+
15
+ LIB_ROOT_PATH = File.expand_path('asherah/native', __dir__)
16
+ load_library(LIB_ROOT_PATH, 'libasherah', [
17
+ [:SetupJson, [:pointer], :int32],
18
+ [:Encrypt, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :int32],
19
+ [:Decrypt, [:pointer, :pointer, :pointer, :int64, :pointer, :int64, :pointer], :int32],
20
+ [:EncryptToJson, [:pointer, :pointer, :pointer], :int32],
21
+ [:DecryptFromJson, [:pointer, :pointer, :pointer], :int32],
22
+ [:Shutdown, [], :void]
23
+ ].freeze)
24
+
25
+ class << self
26
+ # Configures Asherah
27
+ #
28
+ # @yield [Config]
29
+ # @return [void]
30
+ def configure
31
+ config = Config.new
32
+ yield config
33
+ config.validate!
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
42
+ #
43
+ # @param partition_id [String]
44
+ # @param data [String]
45
+ # @return [DataRowRecord]
46
+ def encrypt(partition_id, data)
47
+ partition_id_buffer = string_to_cbuffer(partition_id)
48
+ data_buffer = string_to_cbuffer(data)
49
+ output_encrypted_data_buffer = allocate_cbuffer(data.length + 256)
50
+ output_encrypted_key_buffer = allocate_cbuffer(256)
51
+ output_created_buffer = int_to_buffer(0)
52
+ output_parent_key_id_buffer = allocate_cbuffer(256)
53
+ output_parent_key_created_buffer = int_to_buffer(0)
54
+
55
+ result = Encrypt(
56
+ partition_id_buffer,
57
+ data_buffer,
58
+ output_encrypted_data_buffer,
59
+ output_encrypted_key_buffer,
60
+ output_created_buffer,
61
+ output_parent_key_id_buffer,
62
+ output_parent_key_created_buffer
63
+ )
64
+ Error.check_result!(result, 'Encrypt failed')
65
+
66
+ parent_key_meta = KeyMeta.new(
67
+ id: cbuffer_to_string(output_parent_key_id_buffer),
68
+ created: buffer_to_int(output_parent_key_created_buffer)
69
+ )
70
+ envelope_key_record = EnvelopeKeyRecord.new(
71
+ encrypted_key: cbuffer_to_string(output_encrypted_key_buffer),
72
+ created: buffer_to_int(output_created_buffer),
73
+ parent_key_meta: parent_key_meta
74
+ )
75
+
76
+ DataRowRecord.new(
77
+ data: cbuffer_to_string(output_encrypted_data_buffer),
78
+ key: envelope_key_record
79
+ )
80
+ end
81
+
82
+ # Decrypts a data_row_record for a partition_id and returns decrypted data
83
+ #
84
+ # @param partition_id [String]
85
+ # @param data_row_record [DataRowRecord]
86
+ # @return [String], Decrypted data
87
+ def decrypt(partition_id, data_row_record)
88
+ partition_id_buffer = string_to_cbuffer(partition_id)
89
+ encrypted_data_buffer = string_to_cbuffer(data_row_record.data)
90
+ encrypted_key_buffer = string_to_cbuffer(data_row_record.key.encrypted_key)
91
+ created = data_row_record.key.created
92
+ parent_key_id_buffer = string_to_cbuffer(data_row_record.key.parent_key_meta.id)
93
+ parent_key_created = data_row_record.key.parent_key_meta.created
94
+
95
+ output_data_buffer = allocate_cbuffer(encrypted_data_buffer.size + 256)
96
+
97
+ result = Decrypt(
98
+ partition_id_buffer,
99
+ encrypted_data_buffer,
100
+ encrypted_key_buffer,
101
+ created,
102
+ parent_key_id_buffer,
103
+ parent_key_created,
104
+ output_data_buffer
105
+ )
106
+ Error.check_result!(result, 'Decrypt failed')
107
+
108
+ cbuffer_to_string(output_data_buffer)
109
+ end
110
+
111
+ def shutdown
112
+ Shutdown()
113
+ end
114
+
115
+ # Encrypts data for a given partition_id and returns DataRowRecord in JSON format
116
+ #
117
+ # @param partition_id [String]
118
+ # @param data [String]
119
+ # @return [String], DataRowRecord in JSON format
120
+ def encrypt_to_json(partition_id, data)
121
+ partition_id_buffer = string_to_cbuffer(partition_id)
122
+ data_buffer = string_to_cbuffer(data)
123
+ output_buffer = allocate_cbuffer(data.length + 256)
124
+
125
+ result = EncryptToJson(partition_id_buffer, data_buffer, output_buffer)
126
+ Error.check_result!(result, 'EncryptToJson failed')
127
+
128
+ cbuffer_to_string(output_buffer)
129
+ end
130
+
131
+ # Decrypts a DataRowRecord in JSON format for a partition_id and returns decrypted data
132
+ #
133
+ # @param partition_id [String]
134
+ # @param json [String], DataRowRecord in JSON format
135
+ # @return [String], Decrypted data
136
+ def decrypt_from_json(partition_id, json)
137
+ partition_id_buffer = string_to_cbuffer(partition_id)
138
+ data_buffer = string_to_cbuffer(json)
139
+ output_buffer = allocate_cbuffer(json.length + 256)
140
+
141
+ result = DecryptFromJson(partition_id_buffer, data_buffer, output_buffer)
142
+ Error.check_result!(result, 'DecryptFromJson failed')
143
+
144
+ cbuffer_to_string(output_buffer)
145
+ end
146
+ end
147
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asherah
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: aarch64-linux
6
+ authors:
7
+ - GoDaddy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-14 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.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.3
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
+ extra_rdoc_files: []
105
+ files:
106
+ - ".rspec"
107
+ - ".rubocop.yml"
108
+ - ".ruby-version"
109
+ - CHANGELOG.md
110
+ - CODE_OF_CONDUCT.md
111
+ - CONTRIBUTING.md
112
+ - Gemfile
113
+ - LICENSE.txt
114
+ - README.md
115
+ - Rakefile
116
+ - SECURITY.md
117
+ - asherah.gemspec
118
+ - lib/asherah.rb
119
+ - lib/asherah/config.rb
120
+ - lib/asherah/data_row_record.rb
121
+ - lib/asherah/envelope_key_record.rb
122
+ - lib/asherah/error.rb
123
+ - lib/asherah/key_meta.rb
124
+ - lib/asherah/native/libasherah-arm64.so
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: []