asherah 0.2.0-arm64-darwin → 0.4.2-arm64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +20 -0
- data/README.md +16 -13
- data/Rakefile +11 -103
- data/asherah.gemspec +2 -1
- data/ext/asherah/checksums.yml +5 -0
- data/ext/asherah/extconf.rb +7 -0
- data/ext/asherah/native_file.rb +64 -0
- data/lib/asherah/native/libasherah-arm64.dylib +0 -0
- data/lib/asherah/version.rb +1 -1
- data/lib/asherah.rb +37 -3
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34d47b2db28aa131ed491bcde4103874619ba8f1418828f6ba79b2559a9e8e22
|
4
|
+
data.tar.gz: bb960818de77ad0646b2316b0ad69794675a0119440962b5f6bb9e4d451fd86b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 941effe8033e537d1d4da344a8f5558da8423dae55c557e7679cee47885f9b69200eb2091784f98d6599f3fca4560891d74f681c60739fb3c932c518ed942c7a
|
7
|
+
data.tar.gz: 8f21885d6f43677a18efc443e51505e7c1f0019d07463b593c37c0bf38224b924181d1ad372d3fd48d9e08b1011c96551f527348368eaf0f12fe12c693bfd28c
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [0.4.2] - 2022-07-25
|
4
|
+
|
5
|
+
- Upgrade to use asherah-cobhan v0.4.15
|
6
|
+
- Add `set_env` method to set environment variables for Asherah
|
7
|
+
|
8
|
+
## [0.4.1] - 2022-03-25
|
9
|
+
|
10
|
+
- Build and release platform gems
|
11
|
+
|
12
|
+
## [0.4.0] - 2022-03-25
|
13
|
+
|
14
|
+
- Download native file during gem install and verify checksum
|
15
|
+
- Upgrade to use asherah-cobhan v0.4.11
|
16
|
+
|
17
|
+
## [0.3.0] - 2022-03-22
|
18
|
+
|
19
|
+
- Free up cobhan buffers after encrypt/decrypt to prevent growing heap memory
|
20
|
+
- Use local `estimate_buffer` calculation instead of FFI call
|
21
|
+
- Upgrade to use asherah-cobhan v0.4.3
|
22
|
+
|
3
23
|
## [0.2.0] - 2022-03-21
|
4
24
|
|
5
25
|
- Implement versioning for asherah-cobhan binaries
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# Asherah
|
2
2
|
|
3
|
-
Asherah is a Ruby wrapper around [Asherah
|
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
4
|
|
5
|
-
Check out the following documentation to get more familiar with
|
5
|
+
Check out the following documentation to get more familiar with the concepts and configuration options:
|
6
6
|
|
7
7
|
- [Design and Architecture](https://github.com/godaddy/asherah/blob/master/docs/DesignAndArchitecture.md)
|
8
8
|
- [Key Caching](https://github.com/godaddy/asherah/blob/master/docs/KeyCaching.md)
|
@@ -10,6 +10,10 @@ Check out the following documentation to get more familiar with its concepts:
|
|
10
10
|
- [Metastore](https://github.com/godaddy/asherah/blob/master/docs/Metastore.md)
|
11
11
|
- [System Requirements](https://github.com/godaddy/asherah/blob/master/docs/SystemRequirements.md)
|
12
12
|
|
13
|
+
## Supported Platforms
|
14
|
+
|
15
|
+
Currently supported platforms are Linux and Darwin operating systems for x64 and arm64 CPU architectures.
|
16
|
+
|
13
17
|
## Installation
|
14
18
|
|
15
19
|
Add this line to your application's Gemfile:
|
@@ -45,7 +49,7 @@ Encrypt some data for a `partition_id`
|
|
45
49
|
|
46
50
|
```ruby
|
47
51
|
partition_id = 'user_1'
|
48
|
-
data = '
|
52
|
+
data = 'PII data'
|
49
53
|
data_row_record_json = Asherah.encrypt(partition_id, data)
|
50
54
|
puts data_row_record_json
|
51
55
|
```
|
@@ -61,23 +65,22 @@ puts decrypted_data
|
|
61
65
|
|
62
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.
|
63
67
|
|
64
|
-
To install this gem onto your local machine, run `
|
68
|
+
To install this gem onto your local machine, run `rake install`.
|
65
69
|
|
66
|
-
|
67
|
-
|
68
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/godaddy/asherah-ruby.
|
69
|
-
|
70
|
-
## Releasing new gem version
|
70
|
+
To release a new version, update the version number in `version.rb`, create and push a version tag:
|
71
71
|
|
72
72
|
```
|
73
|
-
# Create and push a version tag
|
74
73
|
git tag -a v$(rake version) -m "Version $(rake version)"
|
75
74
|
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
75
|
```
|
80
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
|
+
|
81
84
|
## License
|
82
85
|
|
83
86
|
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
data/Rakefile
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'bundler/gem_tasks'
|
4
4
|
require 'rspec/core/rake_task'
|
5
|
-
require 'rubygems/package'
|
6
5
|
|
7
6
|
RSpec::Core::RakeTask.new(:spec)
|
8
7
|
|
@@ -10,112 +9,21 @@ require 'rubocop/rake_task'
|
|
10
9
|
|
11
10
|
RuboCop::RakeTask.new
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
'aarch64-linux' => ['libasherah-arm64.so'],
|
20
|
-
'arm64-darwin' => ['libasherah-arm64.dylib']
|
21
|
-
}.freeze
|
22
|
-
|
23
|
-
def current_filename
|
24
|
-
@current_filename ||=
|
25
|
-
begin
|
26
|
-
require 'cobhan'
|
27
|
-
Class.new.extend(Cobhan).library_file_name('libasherah')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def current_platform
|
32
|
-
@distribution ||= DISTRIBUTIONS.detect { |_k, v| v.include?(current_filename) }
|
33
|
-
@distribution.first
|
34
|
-
end
|
35
|
-
|
36
|
-
def native_build(platform, native_files)
|
37
|
-
puts "Building gem for #{platform}"
|
38
|
-
|
39
|
-
pkg_dir = File.join(__dir__, 'pkg')
|
40
|
-
FileUtils.mkdir_p(pkg_dir)
|
41
|
-
|
42
|
-
tmp_gem_dir = File.join(__dir__, 'tmp', platform)
|
43
|
-
FileUtils.rm_rf(tmp_gem_dir, verbose: true)
|
44
|
-
FileUtils.mkdir_p(tmp_gem_dir, verbose: true)
|
45
|
-
|
46
|
-
# Copy files to tmp gem dir
|
47
|
-
gemspec = Bundler.load_gemspec('asherah.gemspec')
|
48
|
-
(gemspec.files + [ASHERAH_BIN]).each do |file|
|
49
|
-
dir = File.dirname(file)
|
50
|
-
filename = File.basename(file)
|
51
|
-
FileUtils.mkdir_p(File.join(tmp_gem_dir, dir))
|
52
|
-
FileUtils.copy_file(file, File.join(tmp_gem_dir, dir, filename))
|
53
|
-
end
|
54
|
-
|
55
|
-
# Set platform for native gem build
|
56
|
-
gemspec.platform = Gem::Platform.new(platform)
|
57
|
-
|
58
|
-
native_dir = 'lib/asherah/native'
|
59
|
-
FileUtils.cd(tmp_gem_dir, verbose: true) do
|
60
|
-
FileUtils.mkdir_p(native_dir)
|
61
|
-
native_files.each do |native_file|
|
62
|
-
native_file_path = File.join(native_dir, native_file)
|
63
|
-
|
64
|
-
# Download native file
|
65
|
-
download_asherah_path = File.join(tmp_gem_dir, ASHERAH_BIN)
|
66
|
-
system("#{download_asherah_path} #{native_file}")
|
67
|
-
|
68
|
-
# Add native file in gemspec
|
69
|
-
gemspec.files << native_file_path
|
70
|
-
end
|
71
|
-
|
72
|
-
package = Gem::Package.build(gemspec)
|
73
|
-
FileUtils.mv package, File.join(pkg_dir, package)
|
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')
|
74
18
|
end
|
75
19
|
end
|
76
20
|
|
77
|
-
|
78
|
-
|
79
|
-
task :build do
|
80
|
-
DISTRIBUTIONS.each do |platform, native_files|
|
81
|
-
native_build(platform, native_files)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
namespace :build do
|
86
|
-
DISTRIBUTIONS.each do |platform, native_files|
|
87
|
-
desc "Build native gem for #{platform}"
|
88
|
-
task :"#{platform}" do
|
89
|
-
native_build(platform, native_files)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
namespace :current do
|
95
|
-
desc 'Download asherah binary for current platform'
|
96
|
-
task :download do
|
97
|
-
download_asherah_path = File.join(__dir__, ASHERAH_BIN)
|
98
|
-
system("#{download_asherah_path} #{current_filename}")
|
99
|
-
end
|
100
|
-
|
101
|
-
desc 'Build native gem for current platform'
|
102
|
-
task :build do
|
103
|
-
native_build(current_platform, DISTRIBUTIONS[current_platform])
|
104
|
-
end
|
105
|
-
|
106
|
-
desc 'Smoke test native gem for current platform'
|
107
|
-
task smoke: :build do
|
108
|
-
platform = current_platform
|
109
|
-
gemspec = Bundler.load_gemspec('asherah.gemspec')
|
110
|
-
gemspec.platform = Gem::Platform.new(platform)
|
111
|
-
|
112
|
-
sh('gem uninstall asherah')
|
113
|
-
sh("gem install pkg/#{gemspec.file_name}")
|
114
|
-
sh('ruby spec/smoke_test.rb')
|
115
|
-
end
|
116
|
-
end
|
117
|
-
end
|
21
|
+
task default: %i[spec rubocop]
|
22
|
+
task spec: :download
|
118
23
|
|
24
|
+
desc 'Print current version'
|
119
25
|
task :version do
|
120
26
|
puts Asherah::VERSION
|
121
27
|
end
|
28
|
+
|
29
|
+
Rake.add_rakelib 'tasks'
|
data/asherah.gemspec
CHANGED
@@ -27,12 +27,13 @@ Gem::Specification.new do |spec|
|
|
27
27
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
28
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
29
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)})
|
30
|
+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|tasks)/|\.(?:git|travis|circleci)|appveyor)})
|
31
31
|
end
|
32
32
|
end
|
33
33
|
spec.bindir = 'exe'
|
34
34
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
35
35
|
spec.require_paths = ['lib']
|
36
|
+
spec.extensions = ['ext/asherah/extconf.rb']
|
36
37
|
|
37
38
|
spec.add_dependency 'cobhan', '~> 0.2.0'
|
38
39
|
spec.add_development_dependency 'dotenv', '~> 2.7.6'
|
@@ -0,0 +1,5 @@
|
|
1
|
+
version: v0.4.15
|
2
|
+
libasherah-arm64.so: 43122390d0f851ac67bb197d688dd040832292e79675e4a9c9268d4ef5d3aef7
|
3
|
+
libasherah-x64.so: 3d29f32f6560858c54dc3cc87fa59347f2981a0e206849f0f3ab9a905de02242
|
4
|
+
libasherah-arm64.dylib: e7d64c2857c120b065c1761445d797f6fd5f6696c26676857ce327a772d6c025
|
5
|
+
libasherah-x64.dylib: 331ea09b160de80a3e40aeeb737779da3c043e2476f7cbfe4b83cf55fccdf0c7
|
@@ -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
|
+
dir: File.join(ROOT_DIR, 'lib/asherah/native')
|
23
|
+
)
|
24
|
+
file_path = File.join(dir, file_name)
|
25
|
+
if File.exist?(file_path)
|
26
|
+
puts "#{file_path} already exists ... skipping download"
|
27
|
+
return
|
28
|
+
end
|
29
|
+
|
30
|
+
checksum = CHECKSUMS.fetch(file_name) do
|
31
|
+
abort "Unsupported platform #{RUBY_PLATFORM}"
|
32
|
+
end
|
33
|
+
|
34
|
+
content = download_content(file_name)
|
35
|
+
|
36
|
+
sha256 = Digest::SHA256.hexdigest(content)
|
37
|
+
abort "Could not verify checksum of #{file_name}" if sha256 != checksum
|
38
|
+
|
39
|
+
FileUtils.mkdir_p(dir)
|
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
|
Binary file
|
data/lib/asherah/version.rb
CHANGED
data/lib/asherah.rb
CHANGED
@@ -11,14 +11,34 @@ module Asherah
|
|
11
11
|
|
12
12
|
LIB_ROOT_PATH = File.expand_path('asherah/native', __dir__)
|
13
13
|
load_library(LIB_ROOT_PATH, 'libasherah', [
|
14
|
+
[:SetEnv, [:pointer], :int32],
|
14
15
|
[:SetupJson, [:pointer], :int32],
|
15
16
|
[:EncryptToJson, [:pointer, :pointer, :pointer], :int32],
|
16
17
|
[:DecryptFromJson, [:pointer, :pointer, :pointer], :int32],
|
17
|
-
[:EstimateBuffer, [:int32, :int32], :int32],
|
18
18
|
[:Shutdown, [], :void]
|
19
19
|
].freeze)
|
20
20
|
|
21
|
+
ESTIMATED_ENCRYPTION_OVERHEAD = 48
|
22
|
+
ESTIMATED_ENVELOPE_OVERHEAD = 185
|
23
|
+
BASE64_OVERHEAD = 1.34
|
24
|
+
|
21
25
|
class << self
|
26
|
+
# Set environment variables needed by Asherah dependencies for when
|
27
|
+
# Go os.Getenv() doesn't see variables set by C.setenv().
|
28
|
+
# References:
|
29
|
+
# https://github.com/golang/go/wiki/cgo#environmental-variables
|
30
|
+
# https://github.com/golang/go/issues/44108
|
31
|
+
#
|
32
|
+
# @yield [Config]
|
33
|
+
# @param env [Hash], Key-value pairs to set Asherah ENV
|
34
|
+
# @return [void]
|
35
|
+
def set_env(env = {})
|
36
|
+
env_buffer = string_to_cbuffer(env.to_json)
|
37
|
+
|
38
|
+
result = SetEnv(env_buffer)
|
39
|
+
Error.check_result!(result, 'SetEnv failed')
|
40
|
+
end
|
41
|
+
|
22
42
|
# Configures Asherah
|
23
43
|
#
|
24
44
|
# @yield [Config]
|
@@ -27,6 +47,7 @@ module Asherah
|
|
27
47
|
config = Config.new
|
28
48
|
yield config
|
29
49
|
config.validate!
|
50
|
+
@intermediated_key_overhead_bytesize = config.product_id.bytesize + config.service_name.bytesize
|
30
51
|
|
31
52
|
config_buffer = string_to_cbuffer(config.to_json)
|
32
53
|
|
@@ -52,13 +73,15 @@ module Asherah
|
|
52
73
|
def encrypt(partition_id, data)
|
53
74
|
partition_id_buffer = string_to_cbuffer(partition_id)
|
54
75
|
data_buffer = string_to_cbuffer(data)
|
55
|
-
|
56
|
-
output_buffer = allocate_cbuffer(
|
76
|
+
estimated_buffer_bytesize = estimate_buffer(data.bytesize, partition_id.bytesize)
|
77
|
+
output_buffer = allocate_cbuffer(estimated_buffer_bytesize)
|
57
78
|
|
58
79
|
result = EncryptToJson(partition_id_buffer, data_buffer, output_buffer)
|
59
80
|
Error.check_result!(result, 'EncryptToJson failed')
|
60
81
|
|
61
82
|
cbuffer_to_string(output_buffer)
|
83
|
+
ensure
|
84
|
+
[partition_id_buffer, data_buffer, output_buffer].map(&:free)
|
62
85
|
end
|
63
86
|
|
64
87
|
# Decrypts a DataRowRecord in JSON format for a partition_id and returns decrypted data.
|
@@ -75,11 +98,22 @@ module Asherah
|
|
75
98
|
Error.check_result!(result, 'DecryptFromJson failed')
|
76
99
|
|
77
100
|
cbuffer_to_string(output_buffer)
|
101
|
+
ensure
|
102
|
+
[partition_id_buffer, data_buffer, output_buffer].map(&:free)
|
78
103
|
end
|
79
104
|
|
80
105
|
# Stop the Asherah instance
|
81
106
|
def shutdown
|
82
107
|
Shutdown()
|
83
108
|
end
|
109
|
+
|
110
|
+
private
|
111
|
+
|
112
|
+
def estimate_buffer(data_bytesize, partition_bytesize)
|
113
|
+
ESTIMATED_ENVELOPE_OVERHEAD +
|
114
|
+
@intermediated_key_overhead_bytesize +
|
115
|
+
partition_bytesize +
|
116
|
+
((data_bytesize + ESTIMATED_ENCRYPTION_OVERHEAD) * BASE64_OVERHEAD)
|
117
|
+
end
|
84
118
|
end
|
85
119
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asherah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2
|
4
|
+
version: 0.4.2
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- GoDaddy
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cobhan
|
@@ -100,7 +100,8 @@ description: |
|
|
100
100
|
email:
|
101
101
|
- oss@godaddy.com
|
102
102
|
executables: []
|
103
|
-
extensions:
|
103
|
+
extensions:
|
104
|
+
- ext/asherah/extconf.rb
|
104
105
|
extra_rdoc_files: []
|
105
106
|
files:
|
106
107
|
- ".rspec"
|
@@ -115,6 +116,9 @@ files:
|
|
115
116
|
- Rakefile
|
116
117
|
- SECURITY.md
|
117
118
|
- asherah.gemspec
|
119
|
+
- ext/asherah/checksums.yml
|
120
|
+
- ext/asherah/extconf.rb
|
121
|
+
- ext/asherah/native_file.rb
|
118
122
|
- lib/asherah.rb
|
119
123
|
- lib/asherah/config.rb
|
120
124
|
- lib/asherah/error.rb
|