sshakery 0.0.5 → 0.0.6
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.
- data/Rakefile +1 -0
- data/changelog.md +47 -0
- data/lib/sshakery/auth_keys.rb +52 -24
- data/lib/sshakery/version.rb +1 -1
- data/test/fixtures/sshakery_malicous_pubkey.txt +1 -0
- data/test/lib/sshakery/auth_keys_test.rb +18 -2
- data/test/lib/sshakery/fs_utils_test.rb +1 -1
- data/test/lib/sshakery/version_test.rb +1 -1
- data/test/lib/sshakery_test.rb +2 -1
- data/test/test_helper.rb +1 -0
- metadata +7 -4
data/Rakefile
CHANGED
data/changelog.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
## 0.0.6 (Dec 19, 2012)
|
2
|
+
|
3
|
+
Bugfixes:
|
4
|
+
|
5
|
+
- fixed test_helper require that was broken in ruby 1.9.2
|
6
|
+
|
7
|
+
Features:
|
8
|
+
|
9
|
+
- Created this changelog
|
10
|
+
|
11
|
+
- Added load_pubkey method to auth_keys class that restricts
|
12
|
+
the attributes that can be set by a pubkey.
|
13
|
+
|
14
|
+
- Reworked load_raw_line in auth_keys class to accept optional
|
15
|
+
array of attributes to be set, ignoring all other attributes
|
16
|
+
not listed.
|
17
|
+
|
18
|
+
## 0.0.5 (Nov 9, 2012)
|
19
|
+
|
20
|
+
Bugfixes:
|
21
|
+
|
22
|
+
- fixed bug that prevented documentation generation by rubygems
|
23
|
+
|
24
|
+
## 0.0.4 (Nov 8, 2012)
|
25
|
+
|
26
|
+
Features:
|
27
|
+
|
28
|
+
- Added additional unit tests and documentation
|
29
|
+
|
30
|
+
## 0.0.3 (Nov 1, 2012)
|
31
|
+
|
32
|
+
Features:
|
33
|
+
|
34
|
+
- Added additional unit tests and documentation
|
35
|
+
|
36
|
+
## 0.0.2 (Oct 30, 2012)
|
37
|
+
|
38
|
+
Features:
|
39
|
+
|
40
|
+
- Added unit tests
|
41
|
+
- Added error class for auth_keys validation errors
|
42
|
+
|
43
|
+
## 0.0.1 (Oct 24, 2012)
|
44
|
+
|
45
|
+
Features:
|
46
|
+
|
47
|
+
- Initial commit
|
data/lib/sshakery/auth_keys.rb
CHANGED
@@ -236,6 +236,7 @@ class AuthKeys
|
|
236
236
|
f.puts line
|
237
237
|
end
|
238
238
|
end
|
239
|
+
return true
|
239
240
|
end
|
240
241
|
|
241
242
|
##
|
@@ -255,41 +256,68 @@ class AuthKeys
|
|
255
256
|
instance_variable_set("@#{attr}", args.has_key?( attr ) ? args[attr] : nil )
|
256
257
|
end
|
257
258
|
|
259
|
+
self.raw_line = args[:raw_pubkey] || args[:raw_line]
|
260
|
+
|
261
|
+
if args.has_key? :raw_pubkey
|
262
|
+
self.load_pubkey
|
263
|
+
return
|
264
|
+
end
|
265
|
+
|
258
266
|
unless self.raw_line.nil?
|
259
267
|
self.load_raw_line
|
260
268
|
end
|
261
269
|
end
|
262
|
-
|
270
|
+
|
271
|
+
##
|
272
|
+
# Instantiate key based on pubkey file
|
273
|
+
# only set key_data,key_type and note attributes
|
274
|
+
def load_pubkey
|
275
|
+
#filter line data
|
276
|
+
load_raw_line([:key_data,:key_type,:note])
|
277
|
+
|
278
|
+
# sanitize old raw line
|
279
|
+
self.raw_line = self.gen_raw_line
|
280
|
+
end
|
281
|
+
|
263
282
|
##
|
264
283
|
# Instantiate key object based on contents of raw_line
|
265
|
-
def load_raw_line
|
284
|
+
def load_raw_line opts = OPTS_REGEX.keys
|
266
285
|
self.raw_line.chomp!
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
self.instance_variable_set(field, true)
|
274
|
-
next
|
275
|
-
end
|
286
|
+
opts.each do |xfield|
|
287
|
+
pattern = OPTS_REGEX[xfield]
|
288
|
+
did_set = raw_setter xfield, pattern
|
289
|
+
#puts did_set
|
290
|
+
end
|
291
|
+
end
|
276
292
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
293
|
+
##
|
294
|
+
# set attribute (field) obtained from
|
295
|
+
# matching pattern in raw_line
|
296
|
+
def raw_setter xfield,pattern
|
297
|
+
field = "@#{xfield}"
|
298
|
+
m = self.raw_line.match pattern
|
299
|
+
return false if m.nil?
|
300
|
+
#p "#{field} => #{m.inspect}"
|
301
|
+
if BOOL_ATTRIBUTES.include? xfield
|
302
|
+
self.instance_variable_set(field, true)
|
303
|
+
return true
|
304
|
+
end
|
281
305
|
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
306
|
+
if STR_ATTRIBUTES.include? xfield
|
307
|
+
self.instance_variable_set(field, m[1])
|
308
|
+
return true
|
309
|
+
end
|
286
310
|
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
311
|
+
if ARR_STR_ATTRIBUTES.include? xfield
|
312
|
+
self.instance_variable_set(field, m.to_a)
|
313
|
+
return true
|
314
|
+
end
|
291
315
|
|
292
|
-
|
316
|
+
if SUB_STR_ATTRIBUTES.include? xfield
|
317
|
+
self.instance_variable_set(field, m[1])
|
318
|
+
return true
|
319
|
+
end
|
320
|
+
return false
|
293
321
|
end
|
294
322
|
|
295
323
|
##
|
data/lib/sshakery/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
command="fortune" ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsBWq5F1n4FcZILZt42B6NthVrfGo0whFfSbyPuc/wfQcACpOy8EeAsCIGw0m+pDF8KlmDhYJhC/DGv4zXqk6yO+X3n5x+zfJY4AL1bu72kBnOuXbPhiDfmoBmcApbHDVJnzhRzd8sWv6qLd7bF+Dd malicious
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'test_helper'
|
2
2
|
|
3
3
|
describe Sshakery::AuthKeys do
|
4
4
|
# create a copy of test data to manipulate
|
@@ -29,7 +29,23 @@ describe Sshakery::AuthKeys do
|
|
29
29
|
key.valid?.must_equal false
|
30
30
|
key.errors.wont_be_empty
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
|
+
it "must safely load pubkey files" do
|
34
|
+
src = "#{$dir}/fixtures/sshakery_malicous_pubkey.txt"
|
35
|
+
line = nil
|
36
|
+
File.open(src,'r'){|f|line=f.read}
|
37
|
+
key = @keys.new
|
38
|
+
key.raw_line = line
|
39
|
+
key.load_pubkey
|
40
|
+
key.key_type.must_equal 'ssh-rsa'
|
41
|
+
key.command.must_be_nil
|
42
|
+
key.note.must_equal 'malicious'
|
43
|
+
key.key_data.wont_be_empty
|
44
|
+
key.save.must_equal true
|
45
|
+
key.raw_line = line
|
46
|
+
key.load_raw_line
|
47
|
+
key.command.must_equal 'fortune'
|
48
|
+
end
|
33
49
|
it "must not save when empty" do
|
34
50
|
key=@keys.new
|
35
51
|
key.save.must_equal false
|
data/test/lib/sshakery_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshakery
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- hattwj
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-12-20 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: minitest
|
@@ -48,12 +48,14 @@ files:
|
|
48
48
|
- LICENSE.txt
|
49
49
|
- README.md
|
50
50
|
- Rakefile
|
51
|
+
- changelog.md
|
51
52
|
- lib/sshakery.rb
|
52
53
|
- lib/sshakery/auth_keys.rb
|
53
54
|
- lib/sshakery/errors.rb
|
54
55
|
- lib/sshakery/fs_utils.rb
|
55
56
|
- lib/sshakery/version.rb
|
56
57
|
- sshakery.gemspec
|
58
|
+
- test/fixtures/sshakery_malicous_pubkey.txt
|
57
59
|
- test/fixtures/sshakery_nofail_fixture.txt
|
58
60
|
- test/lib/sshakery/auth_keys_test.rb
|
59
61
|
- test/lib/sshakery/fs_utils_test.rb
|
@@ -94,6 +96,7 @@ signing_key:
|
|
94
96
|
specification_version: 3
|
95
97
|
summary: SSHakery is a ruby gem for manipulating OpenSSH authorized_keys files. It features file locking, backups (todo), and atomic writes
|
96
98
|
test_files:
|
99
|
+
- test/fixtures/sshakery_malicous_pubkey.txt
|
97
100
|
- test/fixtures/sshakery_nofail_fixture.txt
|
98
101
|
- test/lib/sshakery/auth_keys_test.rb
|
99
102
|
- test/lib/sshakery/fs_utils_test.rb
|