netsnmp 0.1.4 → 0.1.5
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/.travis.yml +1 -3
- data/Gemfile +2 -3
- data/README.md +33 -7
- data/Rakefile +7 -1
- data/lib/netsnmp/client.rb +12 -0
- data/lib/netsnmp/encryption/aes.rb +3 -4
- data/lib/netsnmp/pdu.rb +2 -0
- data/lib/netsnmp/varbind.rb +9 -6
- data/lib/netsnmp/version.rb +1 -1
- data/spec/support/specs.sh +22 -10
- data/spec/varbind_spec.rb +1 -2
- metadata +3 -5
- data/spec/support/start-docker.sh +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48d02a452a0dee151b936f9e8ff6af2c0c305f6a235a42a23ce5426a5dcd33f2
|
4
|
+
data.tar.gz: 05b2efdcbac79cba8d4e749dca163446fab1214c355a609c3e855762af1018a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a26c9601d225cb1a3008a11890955acf1372fafba39e07ea4eed8f70969fd22ebdacd655ddafbf62681ba4dd1d95159e2b348fd627dc8063e9c6c8f5f244579a
|
7
|
+
data.tar.gz: 3d0a6cfac763709d76cfc83b3d3d38261be9cb84d144a58267b3135a46b98418dd1cf882b5ff0866fabd1c74b59a82f641bbaad49387cbfc3a9d49242ef323b1
|
data/.travis.yml
CHANGED
@@ -12,7 +12,7 @@ install:
|
|
12
12
|
- bundle install --path .bundle
|
13
13
|
|
14
14
|
script:
|
15
|
-
- spec/support/specs.sh
|
15
|
+
- spec/support/specs.sh run
|
16
16
|
|
17
17
|
language: ruby
|
18
18
|
rvm:
|
@@ -22,7 +22,6 @@ rvm:
|
|
22
22
|
- 2.4
|
23
23
|
- 2.5
|
24
24
|
- ruby-head
|
25
|
-
- jruby-9.1.15.0
|
26
25
|
- jruby-head
|
27
26
|
- rbx-2
|
28
27
|
matrix:
|
@@ -30,5 +29,4 @@ matrix:
|
|
30
29
|
- rvm: ruby-head
|
31
30
|
- rvm: jruby-head
|
32
31
|
# to figure out later
|
33
|
-
- rvm: jruby-9.1.15.0
|
34
32
|
- rvm: rbx-2
|
data/Gemfile
CHANGED
@@ -16,8 +16,7 @@ gem "nio4r", "~> 1.2" if RUBY_VERSION < "2.2"
|
|
16
16
|
platforms :mri do
|
17
17
|
gem "pry-byebug", require: false
|
18
18
|
gem "stackprof", require: false
|
19
|
+
gem "xorcist", require: false
|
19
20
|
end
|
20
21
|
|
21
|
-
gem "
|
22
|
-
|
23
|
-
gem "rubocop", require: false
|
22
|
+
gem "rubocop", "0.52.1", require: false
|
data/README.md
CHANGED
@@ -219,26 +219,52 @@ All encoding/decoding/encryption/decryption/digests are done using `openssl`, wh
|
|
219
219
|
|
220
220
|
## Tests
|
221
221
|
|
222
|
-
This library uses RSpec. The client specs are "integration" tests, in that we communicate with an snmp agent simulator.
|
222
|
+
This library uses RSpec. The client specs are "integration" tests, in that we communicate with an [snmpsim-built snmp agent simulator](https://github.com/etingof/snmpsim).
|
223
223
|
|
224
|
-
|
224
|
+
### RSpec
|
225
|
+
|
226
|
+
You can run all tests by typing:
|
225
227
|
|
226
228
|
```
|
227
|
-
> spec
|
229
|
+
> bundle exec rake spec
|
230
|
+
# or
|
231
|
+
> bundle exec rspec
|
232
|
+
...
|
228
233
|
```
|
229
234
|
|
230
|
-
|
235
|
+
### SNMP Simulator
|
236
|
+
|
237
|
+
You can install the package yourself (ex: `pip install snmpsim`) and run the server locally, and then set the `SNMP_PORT` environment variable, where the snmp simulator is running.
|
238
|
+
|
239
|
+
#### Docker
|
240
|
+
|
241
|
+
The preferred way to use the snmp simulator is by using docker.
|
242
|
+
|
243
|
+
In order to start the simulator container, run:
|
231
244
|
|
232
245
|
```
|
233
|
-
>
|
246
|
+
> spec/support/spec.sh start
|
234
247
|
```
|
235
248
|
|
236
|
-
|
249
|
+
after, you just need to set the `SNMP_PORT` variable to the port found typing:
|
237
250
|
|
238
251
|
```
|
239
|
-
>
|
252
|
+
> docker port test-snmp 1161/udp
|
240
253
|
```
|
241
254
|
|
255
|
+
and run the tests.
|
256
|
+
|
257
|
+
#### CI
|
258
|
+
|
259
|
+
If you want to replicate what the CI is doing, just do:
|
260
|
+
|
261
|
+
```
|
262
|
+
> spec/support/spec.sh run
|
263
|
+
```
|
264
|
+
|
265
|
+
Which should: build and run the simulator container, run the tests, run rubocop, and remove all artifacts.
|
266
|
+
|
267
|
+
|
242
268
|
## Contributing
|
243
269
|
|
244
270
|
* Fork this repository
|
data/Rakefile
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rspec/core/rake_task"
|
5
5
|
require "coveralls/rake/task"
|
6
|
+
require "rubocop/rake_task"
|
6
7
|
|
7
8
|
desc "runs the tests and sends to coveralls server"
|
8
9
|
Coveralls::RakeTask.new
|
@@ -10,6 +11,11 @@ Coveralls::RakeTask.new
|
|
10
11
|
desc "runs the tests"
|
11
12
|
RSpec::Core::RakeTask.new
|
12
13
|
|
14
|
+
desc "Run rubocop"
|
15
|
+
task :rubocop do
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
end
|
18
|
+
|
13
19
|
task default: [:spec]
|
14
20
|
|
15
21
|
namespace :spec do
|
@@ -20,5 +26,5 @@ namespace :spec do
|
|
20
26
|
end
|
21
27
|
|
22
28
|
desc "runs tests, check coverage, pushes to coverage server"
|
23
|
-
task ci: ["spec:coverage", "coveralls:push"]
|
29
|
+
task ci: ["spec:coverage", "coveralls:push", "rubocop"]
|
24
30
|
end
|
data/lib/netsnmp/client.rb
CHANGED
@@ -135,6 +135,18 @@ module NETSNMP
|
|
135
135
|
values.size > 1 ? values : values.first
|
136
136
|
end
|
137
137
|
|
138
|
+
# Perform a SNMP INFORM Request
|
139
|
+
#
|
140
|
+
# @see {NETSNMP::Varbind#new}
|
141
|
+
#
|
142
|
+
def inform(*oid_opts)
|
143
|
+
request = @session.build_pdu(:inform, *oid_opts)
|
144
|
+
response = handle_retries { @session.send(request) }
|
145
|
+
yield response if block_given?
|
146
|
+
values = response.varbinds.map(&:value)
|
147
|
+
values.size > 1 ? values : values.first
|
148
|
+
end
|
149
|
+
|
138
150
|
private
|
139
151
|
|
140
152
|
# Handles timeout errors by reissuing the same pdu until it runs out or retries.
|
@@ -15,7 +15,7 @@ module NETSNMP
|
|
15
15
|
|
16
16
|
cipher.encrypt
|
17
17
|
cipher.iv = iv
|
18
|
-
cipher.key =
|
18
|
+
cipher.key = aes_key
|
19
19
|
|
20
20
|
if (diff = decrypted_data.length % 8) != 0
|
21
21
|
decrypted_data << ("\x00" * (8 - diff))
|
@@ -29,7 +29,6 @@ module NETSNMP
|
|
29
29
|
|
30
30
|
def decrypt(encrypted_data, salt:, engine_boots:, engine_time:)
|
31
31
|
raise Error, "invalid priv salt received" unless (salt.length % 8).zero?
|
32
|
-
raise Error, "invalid encrypted PDU received" unless (encrypted_data.length % 8).zero?
|
33
32
|
|
34
33
|
cipher = OpenSSL::Cipher::AES128.new(:CFB)
|
35
34
|
cipher.padding = 0
|
@@ -37,7 +36,7 @@ module NETSNMP
|
|
37
36
|
iv = generate_decryption_key(engine_boots, engine_time, salt)
|
38
37
|
|
39
38
|
cipher.decrypt
|
40
|
-
cipher.key =
|
39
|
+
cipher.key = aes_key
|
41
40
|
cipher.iv = iv
|
42
41
|
decrypted_data = cipher.update(encrypted_data) + cipher.final
|
43
42
|
NETSNMP.debug { "decrypted:\n#{Hexdump.dump(decrypted_data)}" }
|
@@ -76,7 +75,7 @@ module NETSNMP
|
|
76
75
|
0xff & time].pack("c*") + salt
|
77
76
|
end
|
78
77
|
|
79
|
-
def
|
78
|
+
def aes_key
|
80
79
|
@priv_key[0, 16]
|
81
80
|
end
|
82
81
|
end
|
data/lib/netsnmp/pdu.rb
CHANGED
data/lib/netsnmp/varbind.rb
CHANGED
@@ -80,10 +80,12 @@ module NETSNMP
|
|
80
80
|
asn_type = case typ
|
81
81
|
when :ipaddress then 0
|
82
82
|
when :counter32
|
83
|
-
asn_val = [value].pack("
|
83
|
+
asn_val = [value].pack("N*")
|
84
|
+
asn_val = asn_val[1..-1] while asn_val.start_with?("\x00")
|
84
85
|
1
|
85
86
|
when :gauge
|
86
|
-
asn_val = [value].pack("
|
87
|
+
asn_val = [value].pack("N*")
|
88
|
+
asn_val = asn_val[1..-1] while asn_val.start_with?("\x00")
|
87
89
|
2
|
88
90
|
when :timetick
|
89
91
|
return Timetick.new(value).to_asn
|
@@ -102,10 +104,11 @@ module NETSNMP
|
|
102
104
|
case asn.tag
|
103
105
|
when 0 # IP Address
|
104
106
|
IPAddr.new_ntoh(asn.value)
|
105
|
-
when 1 # ASN counter 32
|
106
|
-
|
107
|
-
|
108
|
-
|
107
|
+
when 1, # ASN counter 32
|
108
|
+
2 # gauge
|
109
|
+
val = asn.value
|
110
|
+
val.prepend("\x00") while val.bytesize < 4
|
111
|
+
asn.value.unpack("N*")[0] || 0
|
109
112
|
when 3 # timeticks
|
110
113
|
Timetick.new(asn.value.unpack("N*")[0] || 0)
|
111
114
|
# when 4 # opaque
|
data/lib/netsnmp/version.rb
CHANGED
data/spec/support/specs.sh
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env bash
|
2
|
+
|
2
3
|
function start {
|
3
4
|
docker pull honeyryderchuck/snmp-server-emulator:latest
|
4
5
|
docker run -d -p :1161/udp --name test-snmp -v $(pwd)/spec/support/snmpsim:/home/snmp_server/.snmpsim honeyryderchuck/snmp-server-emulator \
|
@@ -19,6 +20,14 @@ function start {
|
|
19
20
|
|
20
21
|
}
|
21
22
|
|
23
|
+
function run {
|
24
|
+
sleep 20 # give some time for the simulator to boot
|
25
|
+
|
26
|
+
port="$(docker port test-snmp 1161/udp)"
|
27
|
+
export SNMP_PORT=$(echo $port | cut -d':' -f2)
|
28
|
+
|
29
|
+
bundle exec rake spec:ci
|
30
|
+
}
|
22
31
|
|
23
32
|
function finish {
|
24
33
|
docker stop test-snmp
|
@@ -27,13 +36,16 @@ function finish {
|
|
27
36
|
|
28
37
|
trap finish EXIT
|
29
38
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
39
|
+
case "$1" in
|
40
|
+
start)
|
41
|
+
start
|
42
|
+
docker logs -f test-snmp
|
43
|
+
;;
|
44
|
+
run)
|
45
|
+
start
|
46
|
+
run
|
47
|
+
;;
|
48
|
+
*)
|
49
|
+
echo $"Usage: $0 {start|run}"
|
50
|
+
exit 1
|
51
|
+
esac
|
data/spec/varbind_spec.rb
CHANGED
@@ -16,7 +16,6 @@ RSpec.describe NETSNMP::Varbind do
|
|
16
16
|
expect(varbind.to_der).to end_with("\x04\x00\x00\x00\x01".b) # ends with an octet string rep of 1 timetick
|
17
17
|
end
|
18
18
|
context "when passed a type" do
|
19
|
-
# TODO: tidy this for IP Addresses
|
20
19
|
it "converts gauge32" do
|
21
20
|
gauge = 805
|
22
21
|
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :gauge, value: gauge)
|
@@ -25,7 +24,7 @@ RSpec.describe NETSNMP::Varbind do
|
|
25
24
|
it "converts counter32" do
|
26
25
|
gauge = 998932
|
27
26
|
varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter32, value: gauge)
|
28
|
-
expect(varbind.to_der).to end_with("
|
27
|
+
expect(varbind.to_der).to end_with("\x0F>\x14".b)
|
29
28
|
end
|
30
29
|
it "converts integer ticks" do
|
31
30
|
timetick = 1
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netsnmp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Cardoso
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -117,7 +117,6 @@ files:
|
|
117
117
|
- spec/support/celluloid.rb
|
118
118
|
- spec/support/request_examples.rb
|
119
119
|
- spec/support/specs.sh
|
120
|
-
- spec/support/start-docker.sh
|
121
120
|
- spec/support/stop_docker.sh
|
122
121
|
- spec/timeticks_spec.rb
|
123
122
|
- spec/v3_session_spec.rb
|
@@ -144,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
143
|
requirements:
|
145
144
|
- net-snmp
|
146
145
|
rubyforge_project:
|
147
|
-
rubygems_version: 2.7.
|
146
|
+
rubygems_version: 2.7.6
|
148
147
|
signing_key:
|
149
148
|
specification_version: 4
|
150
149
|
summary: SNMP Client library
|
@@ -160,7 +159,6 @@ test_files:
|
|
160
159
|
- spec/support/celluloid.rb
|
161
160
|
- spec/support/request_examples.rb
|
162
161
|
- spec/support/specs.sh
|
163
|
-
- spec/support/start-docker.sh
|
164
162
|
- spec/support/stop_docker.sh
|
165
163
|
- spec/timeticks_spec.rb
|
166
164
|
- spec/v3_session_spec.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
docker build -t snmp-server -f spec/support/Dockerfile .
|
2
|
-
docker run -p :1161/udp --name test-snmp-emulator -v $(pwd)/spec/support/snmpsim:/home/snmp_server/.snmpsim snmp-server \
|
3
|
-
--v3-engine-id=000000000000000000000002 \
|
4
|
-
--agent-udpv4-endpoint=0.0.0.0:1161 --agent-udpv6-endpoint='[::0]:1161' \
|
5
|
-
--v3-user=simulator --v3-auth-key=auctoritas --v3-priv-key=privatus \
|
6
|
-
--v3-user=authmd5 --v3-auth-key=maplesyrup --v3-auth-proto=MD5 --v3-priv-proto=NONE \
|
7
|
-
--v3-user=authsha --v3-auth-key=maplesyrup --v3-auth-proto=SHA --v3-priv-proto=NONE \
|
8
|
-
--v3-user=authprivshaaes --v3-auth-key=maplesyrup --v3-auth-proto=SHA \
|
9
|
-
--v3-priv-key=maplesyrup --v3-priv-proto=AES \
|
10
|
-
--v3-user=authprivmd5aes --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
|
11
|
-
--v3-priv-key=maplesyrup --v3-priv-proto=AES \
|
12
|
-
--v3-user=authprivshades --v3-auth-key=maplesyrup --v3-auth-proto=SHA \
|
13
|
-
--v3-priv-key=maplesyrup --v3-priv-proto=DES \
|
14
|
-
--v3-user=authprivmd5des --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
|
15
|
-
--v3-priv-key=maplesyrup --v3-priv-proto=DES \
|
16
|
-
--v3-user=unsafe --v3-auth-proto=NONE --v3-priv-proto=NONE
|
17
|
-
#sleep 20 # give some time for the simulator to boot
|
18
|
-
export SNMP_PORT=`echo $(docker port test-snmp-emulator 1161/udp) | cut -d':' -f2`
|
19
|
-
|