trocla 0.5.1 → 0.6.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 +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +32 -1
- data/lib/VERSION +2 -2
- data/lib/trocla/hooks.rb +33 -0
- data/lib/trocla.rb +9 -0
- data/spec/fixtures/delete_test_hook.rb +12 -0
- data/spec/fixtures/set_test_hook.rb +12 -0
- data/spec/spec_helper.rb +15 -2
- data/spec/trocla/formats/x509_spec.rb +3 -4
- data/spec/trocla/hooks_spec.rb +42 -0
- data/spec/trocla_spec.rb +7 -0
- data/trocla.gemspec +19 -30
- 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: 4f7a0780a994967b2822530c7f6d0d705b76e35200e7829056d7d5ba1d78c754
|
4
|
+
data.tar.gz: ac7ca45af328553379edc3c4fe5e9f77c455a48078d9b4dec3c9499620ed855f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 650c500e320f1b67171e54efff85f6b519c7d577f6fd4f08ea9ea5eb06228a59430db544307f74846c7a9050f09d6a942a8c427aa7564c095432edfe85e40319
|
7
|
+
data.tar.gz: 8acc3a03116b77adbc13534a4d25ecd06d3eef9f6a6e8142ffcdd9bcb5cefce034936c0cfd149a6172cc2eeed80a88a3fac02300175e1c4abfd74b3b7d2ca1ef
|
data/.github/workflows/ruby.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## to 0.6.0
|
4
|
+
|
5
|
+
* move away from sha1 since they are not supported anymore on all distributions
|
6
|
+
* fix tests on various platforms and newer ruby versions
|
7
|
+
* introduce hooks for set and delete actions
|
8
|
+
|
3
9
|
## to 0.5.1
|
4
10
|
|
5
11
|
* support more moneta versions (#78) - Thank you [jcharaoui](https://github.com/jcharaoui)
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# trocla
|
2
|
-
[](https://github.com/duritong/trocla/actions/workflows/ruby.yml)
|
3
3
|
|
4
4
|
Trocla provides you a simple way to create and store (random) passwords on a
|
5
5
|
central server, which can be retrieved by other applications. An example for
|
@@ -373,6 +373,37 @@ encryption_options:
|
|
373
373
|
:public_key: '/var/lib/puppet/ssl/public_keys/trocla.pem'
|
374
374
|
```
|
375
375
|
|
376
|
+
## Hooks
|
377
|
+
|
378
|
+
You can specify hooks to be called whenever trocla sets or deletes a password. The idea is that this allows you to run custom code that can trigger further actions based on deleting or setting a password.
|
379
|
+
|
380
|
+
Enabling hooks is done through the following configuration:
|
381
|
+
|
382
|
+
```YAML
|
383
|
+
hooks:
|
384
|
+
set:
|
385
|
+
my_hook: /path/to/my_hook_file.rb
|
386
|
+
delete:
|
387
|
+
other_hook: /path/to/my_other_hook_file.rb
|
388
|
+
```
|
389
|
+
|
390
|
+
A hook must have the following implementation based on the above config:
|
391
|
+
|
392
|
+
```Ruby
|
393
|
+
class Trocla
|
394
|
+
module Hooks
|
395
|
+
def self.my_hook(trocla, key, format, options)
|
396
|
+
# [... your code ...]
|
397
|
+
end
|
398
|
+
end
|
399
|
+
end
|
400
|
+
```
|
401
|
+
You can specify only either one or both kinds of hooks.
|
402
|
+
|
403
|
+
Hooks must not raise any exceptions or interrupt the flow itself. They can also not change the value that was set or revert a deletion.
|
404
|
+
|
405
|
+
However, they have Trocla itself available (through `trocla`) and you must ensure to not create infinite loops.
|
406
|
+
|
376
407
|
## Update & Changes
|
377
408
|
|
378
409
|
See [Changelog](CHANGELOG.md)
|
data/lib/VERSION
CHANGED
data/lib/trocla/hooks.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Trocla
|
2
|
+
module Hooks
|
3
|
+
class Runner
|
4
|
+
attr_reader :trocla
|
5
|
+
def initialize(trocla)
|
6
|
+
@trocla = trocla
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(action, key, format, options)
|
10
|
+
return unless hooks[action]
|
11
|
+
hooks[action].each do |cmd|
|
12
|
+
Trocla::Hooks.send(cmd, trocla, key, format, options)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def hooks
|
19
|
+
@hooks ||= begin
|
20
|
+
res = {}
|
21
|
+
(trocla.config['hooks'] || {}).each do |action,action_hooks|
|
22
|
+
res[action] ||= []
|
23
|
+
action_hooks.each do |cmd,file|
|
24
|
+
require File.join(file)
|
25
|
+
res[action] << cmd
|
26
|
+
end
|
27
|
+
end
|
28
|
+
res
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/trocla.rb
CHANGED
@@ -3,6 +3,7 @@ require 'trocla/util'
|
|
3
3
|
require 'trocla/formats'
|
4
4
|
require 'trocla/encryptions'
|
5
5
|
require 'trocla/stores'
|
6
|
+
require 'trocla/hooks'
|
6
7
|
|
7
8
|
# Trocla class
|
8
9
|
class Trocla
|
@@ -67,6 +68,7 @@ class Trocla
|
|
67
68
|
|
68
69
|
def delete_password(key, format = nil, options = {})
|
69
70
|
v = store.delete(key, format)
|
71
|
+
hooks_runner.run('delete', key, format, options)
|
70
72
|
if v.is_a?(Hash)
|
71
73
|
Hash[*v.map do |f, encrypted_value|
|
72
74
|
[f, render(format, decrypt(encrypted_value), options)]
|
@@ -78,6 +80,7 @@ class Trocla
|
|
78
80
|
|
79
81
|
def set_password(key, format, password, options = {})
|
80
82
|
store.set(key, format, encrypt(password), options)
|
83
|
+
hooks_runner.run('set', key, format, options)
|
81
84
|
render(format, password, options)
|
82
85
|
end
|
83
86
|
|
@@ -122,6 +125,12 @@ class Trocla
|
|
122
125
|
clazz.new(config['store_options'], self)
|
123
126
|
end
|
124
127
|
|
128
|
+
def hooks_runner
|
129
|
+
@hooks_runner ||= begin
|
130
|
+
Trocla::Hooks::Runner.new(self)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
125
134
|
def read_config
|
126
135
|
if @config_file.nil?
|
127
136
|
default_config
|
data/spec/spec_helper.rb
CHANGED
@@ -241,13 +241,13 @@ def default_config
|
|
241
241
|
end
|
242
242
|
|
243
243
|
def test_config
|
244
|
-
@
|
244
|
+
@test_config ||= default_config.merge({
|
245
245
|
'store' => :memory,
|
246
246
|
})
|
247
247
|
end
|
248
248
|
|
249
249
|
def test_config_persistent
|
250
|
-
@
|
250
|
+
@test_config_persistent ||= default_config.merge({
|
251
251
|
'store_options' => {
|
252
252
|
'adapter' => :YAML,
|
253
253
|
'adapter_options' => {
|
@@ -267,6 +267,19 @@ def ssl_test_config
|
|
267
267
|
})
|
268
268
|
end
|
269
269
|
|
270
|
+
def hooks_config
|
271
|
+
@hooks_config ||= test_config.merge({
|
272
|
+
'hooks' => {
|
273
|
+
'set' => {
|
274
|
+
'set_test_hook' => File.expand_path(File.join(base_dir,'spec/fixtures/set_test_hook.rb'))
|
275
|
+
},
|
276
|
+
'delete' => {
|
277
|
+
'delete_test_hook' => File.expand_path(File.join(base_dir,'spec/fixtures/delete_test_hook.rb'))
|
278
|
+
}
|
279
|
+
}
|
280
|
+
})
|
281
|
+
end
|
282
|
+
|
270
283
|
def base_dir
|
271
284
|
File.dirname(__FILE__)+'/../'
|
272
285
|
end
|
@@ -45,7 +45,7 @@ describe "Trocla::Format::X509" do
|
|
45
45
|
expect((Date.parse(cert.not_after.localtime.to_s) - Date.today).to_i).to eq(365)
|
46
46
|
# it's a self signed cert and NOT a CA
|
47
47
|
# Change of behavior on openssl side: https://github.com/openssl/openssl/issues/15146
|
48
|
-
validates_self_even_if_no_ca = Gem::Version.new(%x{openssl version}.split(' ')[1]) > Gem::Version.new('1.1.1g')
|
48
|
+
validates_self_even_if_no_ca = RUBY_ENGINE == 'jruby' ? true : Gem::Version.new(%x{openssl version}.split(' ')[1]) > Gem::Version.new('1.1.1g')
|
49
49
|
expect(verify(cert,cert)).to be validates_self_even_if_no_ca
|
50
50
|
|
51
51
|
v = cert.extensions.find{|e| e.oid == 'basicConstraints' }.value
|
@@ -291,7 +291,7 @@ describe "Trocla::Format::X509" do
|
|
291
291
|
|
292
292
|
it 'respects all options' do
|
293
293
|
co = cert_options.merge({
|
294
|
-
'hash' => '
|
294
|
+
'hash' => 'sha512',
|
295
295
|
'keysize' => 2048,
|
296
296
|
'days' => 3650,
|
297
297
|
'subject' => nil,
|
@@ -311,8 +311,7 @@ describe "Trocla::Format::X509" do
|
|
311
311
|
expect(cert.subject.to_s).to match(/#{field}=#{co[field]}/)
|
312
312
|
end
|
313
313
|
expect(cert.subject.to_s).to match(/(Email|emailAddress)=#{co['emailAddress']}/)
|
314
|
-
|
315
|
-
expect(cert.signature_algorithm).to eq(hash_match)
|
314
|
+
expect(cert.signature_algorithm).to eq('sha512WithRSAEncryption')
|
316
315
|
expect(cert.not_before).to be < Time.now
|
317
316
|
expect((Date.parse(cert.not_after.localtime.to_s) - Date.today).to_i).to eq(3650)
|
318
317
|
# https://stackoverflow.com/questions/13747212/determine-key-size-from-public-key-pem-format
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe "Trocla::Hooks::Runner" do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
expect_any_instance_of(Trocla).to receive(:read_config).and_return(hooks_config)
|
7
|
+
@trocla = Trocla.new
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:each) do
|
11
|
+
Trocla::Hooks.set_messages.clear
|
12
|
+
Trocla::Hooks.delete_messages.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'running hooks' do
|
16
|
+
describe 'setting password' do
|
17
|
+
it "calls the set hook" do
|
18
|
+
@trocla.password('random1', 'plain')
|
19
|
+
expect(Trocla::Hooks.set_messages.length).to eql(1)
|
20
|
+
expect(Trocla::Hooks.delete_messages.length).to eql(0)
|
21
|
+
expect(Trocla::Hooks.set_messages.first).to eql("random1_plain")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
describe 'deleting password' do
|
25
|
+
it "calls the delete hook" do
|
26
|
+
@trocla.delete_password('random1', 'plain')
|
27
|
+
expect(Trocla::Hooks.delete_messages.length).to eql(1)
|
28
|
+
expect(Trocla::Hooks.set_messages.length).to eql(0)
|
29
|
+
expect(Trocla::Hooks.delete_messages.first).to eql("random1_plain")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
describe 'reset password' do
|
33
|
+
it "calls the delete and set hook" do
|
34
|
+
@trocla.reset_password('random1', 'plain')
|
35
|
+
expect(Trocla::Hooks.set_messages.length).to eql(1)
|
36
|
+
expect(Trocla::Hooks.set_messages.first).to eql("random1_plain")
|
37
|
+
expect(Trocla::Hooks.delete_messages.length).to eql(1)
|
38
|
+
expect(Trocla::Hooks.delete_messages.first).to eql("random1_plain")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/spec/trocla_spec.rb
CHANGED
@@ -22,6 +22,13 @@ describe "Trocla" do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
Trocla::Formats.all.each do |format|
|
25
|
+
if format == 'wireguard'
|
26
|
+
require 'open3'
|
27
|
+
before(:each) do
|
28
|
+
allow(Open3).to receive(:popen3).with('wg genkey').and_yield(nil, StringIO.new('key'), nil, nil)
|
29
|
+
allow(Open3).to receive(:popen3).with('wg pubkey').and_yield(StringIO.new, StringIO.new('key'), nil, nil)
|
30
|
+
end
|
31
|
+
end
|
25
32
|
describe "#{format} password format" do
|
26
33
|
it "retursn a password hashed in the #{format} format" do
|
27
34
|
expect(@trocla.password('some_test',format,format_options[format])).not_to be_empty
|
data/trocla.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: trocla 0.
|
5
|
+
# stub: trocla 0.6.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "trocla".freeze
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.6.0".freeze
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["mh".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2024-12-30"
|
15
15
|
s.description = "Trocla helps you to generate random passwords and to store them in various formats (plain, MD5, bcrypt) for later retrival.".freeze
|
16
16
|
s.email = "mh+trocla@immerda.ch".freeze
|
17
17
|
s.executables = ["trocla".freeze]
|
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
|
|
49
49
|
"lib/trocla/formats/sshkey.rb",
|
50
50
|
"lib/trocla/formats/wireguard.rb",
|
51
51
|
"lib/trocla/formats/x509.rb",
|
52
|
+
"lib/trocla/hooks.rb",
|
52
53
|
"lib/trocla/store.rb",
|
53
54
|
"lib/trocla/stores.rb",
|
54
55
|
"lib/trocla/stores/memory.rb",
|
@@ -57,12 +58,15 @@ Gem::Specification.new do |s|
|
|
57
58
|
"lib/trocla/util.rb",
|
58
59
|
"lib/trocla/version.rb",
|
59
60
|
"spec/data/.keep",
|
61
|
+
"spec/fixtures/delete_test_hook.rb",
|
62
|
+
"spec/fixtures/set_test_hook.rb",
|
60
63
|
"spec/spec_helper.rb",
|
61
64
|
"spec/trocla/encryptions/none_spec.rb",
|
62
65
|
"spec/trocla/encryptions/ssl_spec.rb",
|
63
66
|
"spec/trocla/formats/pgsql_spec.rb",
|
64
67
|
"spec/trocla/formats/sshkey_spec.rb",
|
65
68
|
"spec/trocla/formats/x509_spec.rb",
|
69
|
+
"spec/trocla/hooks_spec.rb",
|
66
70
|
"spec/trocla/store/memory_spec.rb",
|
67
71
|
"spec/trocla/store/moneta_spec.rb",
|
68
72
|
"spec/trocla/util_spec.rb",
|
@@ -71,35 +75,20 @@ Gem::Specification.new do |s|
|
|
71
75
|
]
|
72
76
|
s.homepage = "https://tech.immerda.ch/2011/12/trocla-get-hashed-passwords-out-of-puppet-manifests/".freeze
|
73
77
|
s.licenses = ["GPLv3".freeze]
|
74
|
-
s.rubygems_version = "3.
|
78
|
+
s.rubygems_version = "3.5.22".freeze
|
75
79
|
s.summary = "Trocla a simple password generator and storage".freeze
|
76
80
|
|
77
|
-
|
78
|
-
s.specification_version = 4
|
79
|
-
end
|
81
|
+
s.specification_version = 4
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
s.add_development_dependency(%q<rspec-pending_for>.freeze, [">= 0"])
|
92
|
-
else
|
93
|
-
s.add_dependency(%q<highline>.freeze, ["~> 2.0.0"])
|
94
|
-
s.add_dependency(%q<moneta>.freeze, ["~> 1.0"])
|
95
|
-
s.add_dependency(%q<bcrypt>.freeze, [">= 0"])
|
96
|
-
s.add_dependency(%q<sshkey>.freeze, [">= 0"])
|
97
|
-
s.add_dependency(%q<rake>.freeze, [">= 0"])
|
98
|
-
s.add_dependency(%q<addressable>.freeze, [">= 0"])
|
99
|
-
s.add_dependency(%q<jeweler>.freeze, ["~> 2.0"])
|
100
|
-
s.add_dependency(%q<rdoc>.freeze, [">= 0"])
|
101
|
-
s.add_dependency(%q<rspec>.freeze, [">= 0"])
|
102
|
-
s.add_dependency(%q<rspec-pending_for>.freeze, [">= 0"])
|
103
|
-
end
|
83
|
+
s.add_runtime_dependency(%q<highline>.freeze, ["~> 2.0.0".freeze])
|
84
|
+
s.add_runtime_dependency(%q<moneta>.freeze, ["~> 1.0".freeze])
|
85
|
+
s.add_runtime_dependency(%q<bcrypt>.freeze, [">= 0".freeze])
|
86
|
+
s.add_runtime_dependency(%q<sshkey>.freeze, [">= 0".freeze])
|
87
|
+
s.add_development_dependency(%q<rake>.freeze, [">= 0".freeze])
|
88
|
+
s.add_development_dependency(%q<addressable>.freeze, [">= 0".freeze])
|
89
|
+
s.add_development_dependency(%q<jeweler>.freeze, ["~> 2.0".freeze])
|
90
|
+
s.add_development_dependency(%q<rdoc>.freeze, [">= 0".freeze])
|
91
|
+
s.add_development_dependency(%q<rspec>.freeze, [">= 0".freeze])
|
92
|
+
s.add_development_dependency(%q<rspec-pending_for>.freeze, [">= 0".freeze])
|
104
93
|
end
|
105
94
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trocla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: highline
|
@@ -189,6 +189,7 @@ files:
|
|
189
189
|
- lib/trocla/formats/sshkey.rb
|
190
190
|
- lib/trocla/formats/wireguard.rb
|
191
191
|
- lib/trocla/formats/x509.rb
|
192
|
+
- lib/trocla/hooks.rb
|
192
193
|
- lib/trocla/store.rb
|
193
194
|
- lib/trocla/stores.rb
|
194
195
|
- lib/trocla/stores/memory.rb
|
@@ -197,12 +198,15 @@ files:
|
|
197
198
|
- lib/trocla/util.rb
|
198
199
|
- lib/trocla/version.rb
|
199
200
|
- spec/data/.keep
|
201
|
+
- spec/fixtures/delete_test_hook.rb
|
202
|
+
- spec/fixtures/set_test_hook.rb
|
200
203
|
- spec/spec_helper.rb
|
201
204
|
- spec/trocla/encryptions/none_spec.rb
|
202
205
|
- spec/trocla/encryptions/ssl_spec.rb
|
203
206
|
- spec/trocla/formats/pgsql_spec.rb
|
204
207
|
- spec/trocla/formats/sshkey_spec.rb
|
205
208
|
- spec/trocla/formats/x509_spec.rb
|
209
|
+
- spec/trocla/hooks_spec.rb
|
206
210
|
- spec/trocla/store/memory_spec.rb
|
207
211
|
- spec/trocla/store/moneta_spec.rb
|
208
212
|
- spec/trocla/util_spec.rb
|
@@ -227,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
227
231
|
- !ruby/object:Gem::Version
|
228
232
|
version: '0'
|
229
233
|
requirements: []
|
230
|
-
rubygems_version: 3.
|
234
|
+
rubygems_version: 3.5.22
|
231
235
|
signing_key:
|
232
236
|
specification_version: 4
|
233
237
|
summary: Trocla a simple password generator and storage
|