slosilo 2.2.2 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eee5855bf8948e460edebcc7e04399ad32ea9085f101860ddddb4687139a0bf8
4
- data.tar.gz: 415fa1a618fbffda2ebf1dcb59abc42285d11d01afbc4697299708bbe3bd01fb
3
+ metadata.gz: 239f3678eb01bdaf97f3c7c243740ff3cf8c1b8507833ea07b150380d5a79ee2
4
+ data.tar.gz: 2226342fa45964d0fb368712c6c181c3c587aa5a3e46bda6a780f19346cc4d0e
5
5
  SHA512:
6
- metadata.gz: '098214ef9bbb3ac810a28425e943fe81528573d54e7cdf85261c45cd1ab95fdc57a2387c629adc246339bc04488ff01a04d5655163bf8f423c2edacbb60f7a80'
7
- data.tar.gz: 163a3a8097d4bafc592718d1bb37f1f2f8e25cbb5b637ba68c6478d787f131e08cc5d2a017f9d80bb5127c757d8f817b0a39c0e7c77557b45fc9e01206139305
6
+ metadata.gz: 2ace59188f2bcdf101d45cfc94d1924f469522d3d1e4d076e444d017804fee4ebd862163d7bb9e07358c289257a9d485ade42a28b4bbab4f7cbfd6b70e3612e2
7
+ data.tar.gz: 061ade3a431b2a6073971343a2a15403ec93628a99aecd0150cfa7eb97c69382879a2c4ee45d5525053adfb2bf4b9ada5107d811eceeba4fe71280add15717a8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # v3.0.1
2
+
3
+ * The symmetric cipher class now encrypts and decrypts in a thread-safe manner.
4
+ [cyberark/slosilo#31](https://github.com/cyberark/slosilo/pull/31)
5
+
6
+ # v3.0.0
7
+
8
+ * Transition to Ruby 3. Consuming projects based on Ruby 2 shall use slosilo V2.X.X.
9
+
1
10
  # v2.2.2
2
11
 
3
12
  * Add rake task `slosilo:recalculate_fingerprints` which rehashes the fingerprints in the keystore.
data/Jenkinsfile CHANGED
@@ -3,6 +3,10 @@
3
3
  pipeline {
4
4
  agent { label 'executor-v2' }
5
5
 
6
+ triggers {
7
+ cron(getDailyCronString())
8
+ }
9
+
6
10
  options {
7
11
  timestamps()
8
12
  buildDiscarder(logRotator(daysToKeepStr: '30'))
@@ -10,13 +14,22 @@ pipeline {
10
14
 
11
15
  stages {
12
16
  stage('Test') {
13
- steps {
14
- sh './test.sh'
17
+ parallel {
18
+ stage('Run tests on EE') {
19
+ agent { label 'executor-v2-rhel-ee' }
20
+ steps {
21
+ sh './test.sh'
22
+ }
23
+ post { always {
24
+ stash name: 'eeTestResults', includes: 'spec/reports/*.xml', allowEmpty:true
25
+ }}
26
+ }
15
27
 
16
- junit 'spec/reports/*.xml'
17
- cobertura coberturaReportFile: 'spec/coverage/coverage.xml'
18
- sh 'cp spec/coverage/coverage.xml cobertura.xml'
19
- ccCoverage("cobertura", "github.com/cyberark/slosilo")
28
+ stage('Run tests') {
29
+ steps {
30
+ sh './test.sh'
31
+ }
32
+ }
20
33
  }
21
34
  }
22
35
 
@@ -24,7 +37,6 @@ pipeline {
24
37
  agent { label 'executor-v2' }
25
38
  when {
26
39
  allOf {
27
- branch 'master'
28
40
  expression {
29
41
  boolean publish = false
30
42
 
@@ -52,6 +64,14 @@ pipeline {
52
64
 
53
65
  post {
54
66
  always {
67
+ dir('ee-results'){
68
+ unstash 'eeTestResults'
69
+ }
70
+ junit 'spec/reports/*.xml, ee-results/spec/reports/*.xml'
71
+ cobertura coberturaReportFile: 'spec/coverage/coverage.xml'
72
+ sh 'cp spec/coverage/coverage.xml cobertura.xml'
73
+ ccCoverage("cobertura", "github.com/cyberark/slosilo")
74
+
55
75
  cleanupAndNotify(currentBuild.currentResult)
56
76
  }
57
77
  }
data/README.md CHANGED
@@ -19,6 +19,9 @@ And then execute:
19
19
 
20
20
  ## Compatibility
21
21
 
22
+ Version 3.0 introduced full transition to Ruby 3.
23
+ Consumers who use slosilo in Ruby 2 projects, shall use slosilo V2.X.X.
24
+
22
25
  Version 2.0 introduced new symmetric encryption scheme using AES-256-GCM
23
26
  for authenticated encryption. It allows you to provide AAD on all symmetric
24
27
  encryption primitives. It's also **NOT COMPATIBLE** with CBC used in version <2.
@@ -0,0 +1,7 @@
1
+ FROM ruby
2
+
3
+ COPY ./ /src/
4
+
5
+ WORKDIR /src
6
+
7
+ RUN bundle
@@ -0,0 +1,8 @@
1
+ version: '3'
2
+ services:
3
+ dev:
4
+ build:
5
+ context: ..
6
+ dockerfile: dev/Dockerfile.dev
7
+ volumes:
8
+ - ../:/src
@@ -26,7 +26,10 @@ module Slosilo
26
26
  aad = options[:aad]
27
27
  # note nil.to_s is "", which is exactly the right thing
28
28
  auth_data = aad.respond_to?(:to_proc) ? aad.to_proc : proc{ |_| aad.to_s }
29
- raise ":aad proc must take one argument" unless auth_data.arity.abs == 1 # take abs to allow *args arity, -1
29
+
30
+ # In ruby 3 .arity for #proc returns both 1 and 2, depends on internal #proc
31
+ # This method is also being called with aad which is string, in such case the arity is 1
32
+ raise ":aad proc must take two arguments" unless (auth_data.arity.abs == 2 || auth_data.arity.abs == 1)
30
33
 
31
34
  # push a module onto the inheritance hierarchy
32
35
  # this allows calling super in classes
@@ -5,6 +5,7 @@ module Slosilo
5
5
 
6
6
  def initialize
7
7
  @cipher = OpenSSL::Cipher.new 'aes-256-gcm' # NB: has to be lower case for whatever reason.
8
+ @cipher_mutex = Mutex.new
8
9
  end
9
10
 
10
11
  # This lets us do a final sanity check in migrations from older encryption versions
@@ -13,14 +14,18 @@ module Slosilo
13
14
  end
14
15
 
15
16
  def encrypt plaintext, opts = {}
16
- @cipher.reset
17
- @cipher.encrypt
18
- @cipher.key = (opts[:key] or raise("missing :key option"))
19
- @cipher.iv = iv = random_iv
20
- @cipher.auth_data = opts[:aad] || "" # Nothing good happens if you set this to nil, or don't set it at all
21
- ctext = @cipher.update(plaintext) + @cipher.final
22
- tag = @cipher.auth_tag(TAG_LENGTH)
23
- "#{VERSION_MAGIC}#{tag}#{iv}#{ctext}"
17
+ # All of these operations in OpenSSL must occur atomically, so we
18
+ # synchronize their access to make this step thread-safe.
19
+ @cipher_mutex.synchronize do
20
+ @cipher.reset
21
+ @cipher.encrypt
22
+ @cipher.key = (opts[:key] or raise("missing :key option"))
23
+ @cipher.iv = iv = random_iv
24
+ @cipher.auth_data = opts[:aad] || "" # Nothing good happens if you set this to nil, or don't set it at all
25
+ ctext = @cipher.update(plaintext) + @cipher.final
26
+ tag = @cipher.auth_tag(TAG_LENGTH)
27
+ "#{VERSION_MAGIC}#{tag}#{iv}#{ctext}"
28
+ end
24
29
  end
25
30
 
26
31
  def decrypt ciphertext, opts = {}
@@ -28,19 +33,23 @@ module Slosilo
28
33
 
29
34
  raise "Invalid version magic: expected #{VERSION_MAGIC} but was #{version}" unless version == VERSION_MAGIC
30
35
 
31
- @cipher.reset
32
- @cipher.decrypt
33
- @cipher.key = opts[:key]
34
- @cipher.iv = iv
35
- @cipher.auth_tag = tag
36
- @cipher.auth_data = opts[:aad] || ""
37
- @cipher.update(ctext) + @cipher.final
36
+ # All of these operations in OpenSSL must occur atomically, so we
37
+ # synchronize their access to make this step thread-safe.
38
+ @cipher_mutex.synchronize do
39
+ @cipher.reset
40
+ @cipher.decrypt
41
+ @cipher.key = opts[:key]
42
+ @cipher.iv = iv
43
+ @cipher.auth_tag = tag
44
+ @cipher.auth_data = opts[:aad] || ""
45
+ @cipher.update(ctext) + @cipher.final
46
+ end
38
47
  end
39
-
48
+
40
49
  def random_iv
41
50
  @cipher.random_iv
42
51
  end
43
-
52
+
44
53
  def random_key
45
54
  @cipher.random_key
46
55
  end
@@ -1,3 +1,3 @@
1
1
  module Slosilo
2
- VERSION = "2.2.2"
2
+ VERSION = "3.0.1"
3
3
  end
data/publish-rubygem.sh CHANGED
@@ -2,10 +2,10 @@
2
2
 
3
3
  docker pull registry.tld/conjurinc/publish-rubygem
4
4
 
5
- docker run -i --rm -v $PWD:/src -w /src alpine/git clean -fxd
5
+ git clean -fxd
6
6
 
7
7
  summon --yaml "RUBYGEMS_API_KEY: !var rubygems/api-key" \
8
8
  docker run --rm --env-file @SUMMONENVFILE -v "$(pwd)":/opt/src \
9
9
  registry.tld/conjurinc/publish-rubygem slosilo
10
10
 
11
- docker run -i --rm -v $PWD:/src -w /src alpine/git clean -fxd
11
+ git clean -fxd
data/slosilo.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |gem|
22
22
  gem.name = "slosilo"
23
23
  gem.require_paths = ["lib"]
24
24
  gem.version = Slosilo::VERSION
25
- gem.required_ruby_version = '>= 1.9.3'
25
+ gem.required_ruby_version = '>= 3.0.0'
26
26
 
27
27
  gem.add_development_dependency 'rake'
28
28
  gem.add_development_dependency 'rspec', '~> 3.0'
@@ -30,13 +30,13 @@ describe Slosilo::Adapters::SequelAdapter do
30
30
  describe "#put_key" do
31
31
  let(:id) { "id" }
32
32
  it "creates the key" do
33
- expect(model).to receive(:create).with id: id, key: key.to_der
33
+ expect(model).to receive(:create).with(hash_including(:id => id, :key => key.to_der))
34
34
  allow(model).to receive_messages columns: [:id, :key]
35
35
  subject.put_key id, key
36
36
  end
37
37
 
38
38
  it "adds the fingerprint if feasible" do
39
- expect(model).to receive(:create).with id: id, key: key.to_der, fingerprint: key.fingerprint
39
+ expect(model).to receive(:create).with(hash_including(:id => id, :key => key.to_der, :fingerprint => key.fingerprint))
40
40
  allow(model).to receive_messages columns: [:id, :key, :fingerprint]
41
41
  subject.put_key id, key
42
42
  end
@@ -14,8 +14,29 @@ describe Slosilo::Symmetric do
14
14
  expect(subject.encrypt(plaintext, key: key, aad: auth_data)).to eq(ciphertext)
15
15
  end
16
16
  end
17
-
17
+
18
18
  describe '#decrypt' do
19
+
20
+ it "doesn't fail when called by multiple threads" do
21
+ threads = []
22
+
23
+ begin
24
+ # Verify we can successfuly decrypt using many threads without OpenSSL
25
+ # errors.
26
+ 1000.times do
27
+ threads << Thread.new do
28
+ 100.times do
29
+ expect(
30
+ subject.decrypt(ciphertext, key: key, aad: auth_data)
31
+ ).to eq(plaintext)
32
+ end
33
+ end
34
+ end
35
+ ensure
36
+ threads.each(&:join)
37
+ end
38
+ end
39
+
19
40
  it "decrypts with AES-256-GCM" do
20
41
  expect(subject.decrypt(ciphertext, key: key, aad: auth_data)).to eq(plaintext)
21
42
  end
@@ -56,7 +77,7 @@ describe Slosilo::Symmetric do
56
77
  end
57
78
  end
58
79
  end
59
-
80
+
60
81
  describe '#random_iv' do
61
82
  it "generates a random iv" do
62
83
  expect_any_instance_of(OpenSSL::Cipher).to receive(:random_iv).and_return :iv
data/test.sh CHANGED
@@ -3,7 +3,7 @@
3
3
  iid=slosilo-test-$(date +%s)
4
4
 
5
5
  docker build -t $iid -f - . << EOF
6
- FROM ruby
6
+ FROM ruby:3.0
7
7
  WORKDIR /app
8
8
  COPY Gemfile slosilo.gemspec ./
9
9
  RUN bundle
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slosilo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rafał Rzepecki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -146,7 +146,6 @@ extra_rdoc_files: []
146
146
  files:
147
147
  - ".dockerignore"
148
148
  - ".github/CODEOWNERS"
149
- - ".github/PULL_REQUEST_TEMPLATE.md"
150
149
  - ".gitignore"
151
150
  - ".gitleaks.toml"
152
151
  - ".kateproject"
@@ -158,6 +157,8 @@ files:
158
157
  - README.md
159
158
  - Rakefile
160
159
  - SECURITY.md
160
+ - dev/Dockerfile.dev
161
+ - dev/docker-compose.yml
161
162
  - lib/slosilo.rb
162
163
  - lib/slosilo/adapters/abstract_adapter.rb
163
164
  - lib/slosilo/adapters/file_adapter.rb
@@ -199,14 +200,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
200
  requirements:
200
201
  - - ">="
201
202
  - !ruby/object:Gem::Version
202
- version: 1.9.3
203
+ version: 3.0.0
203
204
  required_rubygems_version: !ruby/object:Gem::Requirement
204
205
  requirements:
205
206
  - - ">="
206
207
  - !ruby/object:Gem::Version
207
208
  version: '0'
208
209
  requirements: []
209
- rubygems_version: 3.1.2
210
+ rubygems_version: 3.1.6
210
211
  signing_key:
211
212
  specification_version: 4
212
213
  summary: Store SSL keys in a database
@@ -1,21 +0,0 @@
1
- ### What does this PR do?
2
- - _What's changed? Why were these changes made?_
3
- - _How should the reviewer approach this PR, especially if manual tests are required?_
4
- - _Are there relevant screenshots you can add to the PR description?_
5
-
6
- ### What ticket does this PR close?
7
- Connected to #[relevant GitHub issues, eg 76]
8
-
9
- ### Checklists
10
-
11
- #### Change log
12
- - [ ] The CHANGELOG has been updated, or
13
- - [ ] This PR does not include user-facing changes and doesn't require a CHANGELOG update
14
-
15
- #### Test coverage
16
- - [ ] This PR includes new unit and integration tests to go with the code changes, or
17
- - [ ] The changes in this PR do not require tests
18
-
19
- #### Documentation
20
- - [ ] Docs (e.g. `README`s) were updated in this PR, and/or there is a follow-on issue to update docs, or
21
- - [ ] This PR does not require updating any documentation