arver 0.1.9 → 0.2

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: eeb29f1cdc8ba4b8fd5a05791fe282f1a016440253f0b3591c95e30f573343f5
4
- data.tar.gz: d41505b368abe1d3aa20c3fdf0ed13c3e382aadeb18e9b000778f156279dce0d
3
+ metadata.gz: 42ca84af2d596b0eed3141d4a198b6b232786a398363a47579aa0d1af4bea645
4
+ data.tar.gz: 8161dce60e9c7968b808962c6426edc44503bfd09d9180367c0a5b78310160da
5
5
  SHA512:
6
- metadata.gz: f63236b680841a83333b3fce1c6a6c379e0a35820554f016821f1aff3998011c844655a883cd5f0514481b20618490aec95d005f320cfa57472b9f95585c73ff
7
- data.tar.gz: 5734e53e093a97465751ae5e9cd95cee18f9565337ea94208f7eea9448c7a32f79b53aa1f92a8e82f0ac4a88127ca13fd91ca6e9838f5b7aaa284a4b05ea8e91
6
+ metadata.gz: 12102d7730ac2a893f7a0fe8593c6e20d1c4141d2a9ba227ee3db5aaf55d9fe5fccd9baaf9d8a8dbf80b2a4968d7c60ebc04b1f1326a3a08457421435f55431f
7
+ data.tar.gz: 704abd36bc00fde5746cb91edb9602426d7bed46a1dfde2ed4e62e93bc9cc4d8c945cab8f6bf63ff5f2857eda7f474e5b2abff2d009a75e7e315b3e3ccf3d5dc
data/CHANGELOG.textile CHANGED
@@ -1,3 +1,7 @@
1
+ === 0.2 2023-05-29
2
+
3
+ * Ruby 3.2 compatible release.
4
+
1
5
  === 0.1.9 2022-01-29
2
6
 
3
7
  * Add a new --open-systemd to support opening disks at startup. This mode is compatible with systemd-ask-password which is used to open disks in the initrd.
data/lib/arver/config.rb CHANGED
@@ -26,7 +26,7 @@ module Arver
26
26
  end
27
27
 
28
28
  def load_file( filename )
29
- if !File.exists?(filename)
29
+ if !File.exist?(filename)
30
30
  Arver::Log.error("missing config #{filename}")
31
31
  exit 1
32
32
  end
@@ -34,7 +34,7 @@ module Arver
34
34
  end
35
35
 
36
36
  def save
37
- FileUtils.mkdir_p( path ) unless File.exists?( path )
37
+ FileUtils.mkdir_p( path ) unless File.exist?( path )
38
38
  File.open( File.join(path,'users'), 'w' ) { |f| f.write( users.to_yaml ) }
39
39
  File.open( File.join(path,'disks'), 'w' ) { |f| f.write( tree.to_yaml ) }
40
40
  end
@@ -43,10 +43,10 @@ module Arver
43
43
  end
44
44
 
45
45
  config_path = Arver::LocalConfig.instance.config_dir
46
- FileUtils.mkdir_p "#{config_path}/keys/public" unless File.exists?( "#{config_path}/keys/public" )
46
+ FileUtils.mkdir_p "#{config_path}/keys/public" unless File.exist?( "#{config_path}/keys/public" )
47
47
  key = _key_of( user )
48
48
  user_pubkey_file = config_path+"/keys/public/"+user
49
- on_disk = File.exists?( user_pubkey_file )
49
+ on_disk = File.exist?( user_pubkey_file )
50
50
 
51
51
  if ! key && ! on_disk
52
52
  Arver::Log.error( "No publickey for #{user} found. Aborting all actions." )
@@ -2,13 +2,12 @@ require 'securerandom'
2
2
 
3
3
  module Arver
4
4
  class KeySaver
5
-
6
5
  def self.save( user, key )
7
6
  tmp_path = tmp_key_path( user )
8
7
  back_path = backup_key_path( user )
9
8
  path = key_path( user )
10
9
  filename = save_to( user, key, tmp_path )
11
- FileUtils.mv(path,back_path) if File.exists?(path)
10
+ FileUtils.mv(path,back_path) if File.exist?(path)
12
11
  FileUtils.mv(tmp_path,path)
13
12
  FileUtils.rm_rf(back_path)
14
13
  File.join(path,filename)
@@ -57,7 +56,7 @@ module Arver
57
56
  end
58
57
  key_encrypted = encrypted.read
59
58
  unless( Arver::RuntimeConfig.instance.dry_run )
60
- FileUtils.mkdir_p path unless File.exists?( path )
59
+ FileUtils.mkdir_p path unless File.exist?( path )
61
60
  filename = "#{OpenSSL::Digest::SHA256.new << key_encrypted}"
62
61
  File.open( File.join("#{path}","#{filename}"), 'w' ) do |f|
63
62
  f.write key_encrypted
@@ -92,7 +91,7 @@ module Arver
92
91
 
93
92
  def self.read( user )
94
93
  GPGKeyManager.check_key_of( user )
95
- return [] unless File.exists?( key_path( user ) )
94
+ return [] unless File.exist?( key_path( user ) )
96
95
  decrypted = []
97
96
  crypto = GPGME::Crypto.new
98
97
  Dir.entries( key_path( user ) ).sort.each do | file |
@@ -15,7 +15,7 @@ class Arver::LocalConfig
15
15
  end
16
16
 
17
17
  def load_file(filename)
18
- content = YAML.load(File.read(filename)) if File.exists?(filename)
18
+ content = YAML.load(File.read(filename)) if File.exist?(filename)
19
19
  self.default.merge(content||{})
20
20
  end
21
21
 
@@ -13,26 +13,45 @@ module Arver
13
13
  return false
14
14
  end
15
15
  return false unless load_key( partition )
16
+
17
+ if verify_partition(partition)
18
+ Arver::Log.info( "#{partition.path} is already open! Skipping..." )
19
+ return false
20
+ end
16
21
  true
17
22
  end
18
23
 
19
24
  def get_socket(host, partid)
20
25
  # Check which partitions are waiting for a password
21
- # see https://www.freedesktop.org/wiki/Software/systemd/PasswordAgents/
22
- files_exec = Arver::SSHCommandWrapper.create("ls", ["/run/systemd/ask-password/ask.*"], host, true, true)
23
- files_exec.execute
24
- files = files_exec.output.split("\n")
26
+ # see https://systemd.io/PASSWORD_AGENTS/
27
+ # systemd might have a while until they pop up does we try a few times
28
+ 3.times do
29
+ found = false
30
+ files_exec = ''
31
+ 3.times do
32
+ files_exec = Arver::SSHCommandWrapper.create("ls", ["/run/systemd/ask-password/ask.*","2>","/dev/null"], host, true, true)
33
+ files_exec.execute
34
+ found = files_exec.success?
35
+ break if found
36
+ Arver::Log.error( "No ask-password definition found, retrying in 3 secs..." )
37
+ sleep 3
38
+ end
39
+ if found
40
+ files = files_exec.output.split("\n")
25
41
 
26
- # Find the socket for the partition we want to open
27
- files.each do |f|
28
- f_exec = Arver::SSHCommandWrapper.create("cat", [f], host, true, true)
29
- f_exec.execute
30
- ask_file = f_exec.output
31
- if ask_file =~ /#{partid}/
32
- ask_file =~ /Socket=(.*)/
33
- return $1
42
+ # Find the socket for the partition we want to open
43
+ files.each do |f|
44
+ f_exec = Arver::SSHCommandWrapper.create("cat", [f], host, true, true)
45
+ f_exec.execute
46
+ ask_file = f_exec.output
47
+ if ask_file =~ /#{partid}/
48
+ ask_file =~ /Socket=(.*)/
49
+ return $1
50
+ end
51
+ end
34
52
  end
35
53
  end
54
+ Arver::Log.error( "No ask-password definitions found to scan. Aborting..." )
36
55
  nil
37
56
  end
38
57
 
@@ -42,24 +61,16 @@ module Arver
42
61
  partid = nil
43
62
  host = partition.parent
44
63
 
45
- # Find the uuid of this partition
46
- partid_exec = Arver::SSHCommandWrapper.create("blkid", ["/dev/#{partition.device}"], host, true, true)
47
- partid_exec.execute
48
- partid = partid_exec.output.chomp.gsub(/.* UUID=\"([^"]+)\" .*/,'\1')
49
- unless partid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
50
- puts "Could not get uuid of disk"
51
- throw( :abort_action )
52
- end
53
-
64
+ partid = get_uuid(partition)
54
65
  socket = get_socket(host, partid)
55
66
  if socket.nil?
56
- puts "Disk is not waiting to be opened"
67
+ Arver::Log.error( "Disk is not waiting to be opened" )
57
68
  throw( :abort_action )
58
69
  end
59
70
 
60
71
  # Upload password-agent binary and supply password to the correct socket
61
72
  binary = File.join(ROOT_DIR, "vendor", "password-agent")
62
- unless File.exists?(binary)
73
+ unless File.exist?(binary)
63
74
  puts "This gem is missing the native password-agent binary"
64
75
  throw( :abort_action )
65
76
  end
@@ -77,7 +88,39 @@ module Arver
77
88
  a = Arver::SSHCommandWrapper.create("/run/password-agent", [socket], host, true, true)
78
89
  a.execute(key)
79
90
 
80
- # Cannot check if it worked, since if it did, the server rebooted
91
+ Arver::Log.info("Trying to validate opening of #{partition.path} ..." )
92
+ verified = false
93
+ 3.times do
94
+ verified = verify_partition(partition)
95
+ break if verified
96
+ sleep 3
97
+ end
98
+ if verified
99
+ Arver::Log.info("Success in validating opening of #{partition.path} ..." )
100
+ else
101
+ Arver::Log.error("Failed to validate opening of #{partition.path} ..." )
102
+ end
103
+ end
104
+
105
+ private
106
+
107
+ def get_uuid(partition)
108
+ # Find the uuid of this partition
109
+ partid_exec = Arver::SSHCommandWrapper.create("blkid", ["/dev/#{partition.device}"], partition.parent, true, true)
110
+ partid_exec.execute
111
+ partid = partid_exec.output.chomp.gsub(/.* UUID=\"([^"]+)\" .*/,'\1')
112
+ unless partid =~ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
113
+ puts "Could not get uuid of disk"
114
+ throw( :abort_action )
115
+ end
116
+ partid
117
+ end
118
+
119
+ def verify_partition(partition)
120
+ partid = get_uuid(partition)
121
+ r = Arver::SSHCommandWrapper.create("test", ['-b',"/dev/mapper/luks-#{partid}"], partition.parent, true, true)
122
+ r.execute
123
+ r.success?
81
124
  end
82
125
  end
83
126
  end
data/lib/arver/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arver
2
- VERSION = '0.1.9'
2
+ VERSION = '0.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - o
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-01-29 00:00:00.000000000 Z
13
+ date: 2024-01-27 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: gpgme
@@ -137,7 +137,8 @@ files:
137
137
  - man/arver.5
138
138
  - vendor/password-agent
139
139
  homepage: https://code.immerda.ch/immerda/apps/arver
140
- licenses: []
140
+ licenses:
141
+ - MIT
141
142
  metadata: {}
142
143
  post_install_message:
143
144
  rdoc_options: []
@@ -154,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
155
  - !ruby/object:Gem::Version
155
156
  version: 1.3.6
156
157
  requirements: []
157
- rubygems_version: 3.1.2
158
+ rubygems_version: 3.4.10
158
159
  signing_key:
159
160
  specification_version: 4
160
161
  summary: LUKS for groups