netsnmp 0.1.4 → 0.1.5

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: faea873fa6ca9eaf4c453c77dc2f897af13b523521344f8e39e72006f1493d23
4
- data.tar.gz: 6e671ad1fb6ecb01ddbad7647ce2c01f532537845cd74fcd3db188a8af543010
3
+ metadata.gz: 48d02a452a0dee151b936f9e8ff6af2c0c305f6a235a42a23ce5426a5dcd33f2
4
+ data.tar.gz: 05b2efdcbac79cba8d4e749dca163446fab1214c355a609c3e855762af1018a5
5
5
  SHA512:
6
- metadata.gz: 2a49e950ce387bf6c0e41d928b7a2617540990b399814cc5811969cedd4a65483454af203b990e4dcc041aa95cac7cdb19aa2c2fba3c7b16cfb24c424eef5b43
7
- data.tar.gz: 007eb164271090585dbcab085a0a4bdef899c8acbb8b79ac43cba99c7b859326b7c2b89c08af03716f24d2980110196ac8f1795b527377fedb178b53ca013055
6
+ metadata.gz: a26c9601d225cb1a3008a11890955acf1372fafba39e07ea4eed8f70969fd22ebdacd655ddafbf62681ba4dd1d95159e2b348fd627dc8063e9c6c8f5f244579a
7
+ data.tar.gz: 3d0a6cfac763709d76cfc83b3d3d38261be9cb84d144a58267b3135a46b98418dd1cf882b5ff0866fabd1c74b59a82f641bbaad49387cbfc3a9d49242ef323b1
@@ -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 "xorcist"
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
- To start the simulator locally, you'll need docker 1.9 or higher (Why 1.9? ```--build-arg``` parameter support was needed for our builds in the CI. You could use a lower version by providing the proxy environment variables in the Dockerfile directly, provided you don't merge these changes to master, thereby exposing your proxy).
224
+ ### RSpec
225
+
226
+ You can run all tests by typing:
225
227
 
226
228
  ```
227
- > spec/support/start_docker.sh
229
+ > bundle exec rake spec
230
+ # or
231
+ > bundle exec rspec
232
+ ...
228
233
  ```
229
234
 
230
- this builds and starts the docker image in deamonized mode. You can afterwards run your specs:
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
- > bundle exec rspec
246
+ > spec/support/spec.sh start
234
247
  ```
235
248
 
236
- To stop the image, you can just:
249
+ after, you just need to set the `SNMP_PORT` variable to the port found typing:
237
250
 
238
251
  ```
239
- > spec/supoprt/stop_docker.sh
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
@@ -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 = des_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 = des_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 des_key
78
+ def aes_key
80
79
  @priv_key[0, 16]
81
80
  end
82
81
  end
@@ -50,6 +50,8 @@ module NETSNMP
50
50
  when :getnext then 1
51
51
  # when :getbulk then 5
52
52
  when :set then 3
53
+ when :inform then 6
54
+ when :trap then 7
53
55
  when :response then 2
54
56
  else raise Error, "#{type} is not supported as type"
55
57
  end
@@ -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("n*")
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("n*")
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
- asn.value.unpack("n*")[0] || 0
107
- when 2 # gauge
108
- asn.value.unpack("n*")[0] || 0
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NETSNMP
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -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
- start
31
- sleep 20 # give some time for the simulator to boot
32
-
33
- port="$(docker port test-snmp 1161/udp)"
34
- export SNMP_PORT=$(echo $port | cut -d':' -f2)
35
-
36
- bundle exec rake spec:ci
37
- bundle exec rubocop
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
@@ -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("A\x02>\x14".b)
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
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-02-16 00:00:00.000000000 Z
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.4
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
-