netsnmp 0.4.2 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -3
  3. data/lib/netsnmp/client.rb +5 -2
  4. data/lib/netsnmp/encryption/aes.rb +3 -3
  5. data/lib/netsnmp/encryption/des.rb +4 -4
  6. data/lib/netsnmp/errors.rb +7 -4
  7. data/lib/netsnmp/extensions.rb +12 -1
  8. data/lib/netsnmp/loggable.rb +1 -2
  9. data/lib/netsnmp/message.rb +22 -11
  10. data/lib/netsnmp/mib/parser.rb +39 -39
  11. data/lib/netsnmp/mib.rb +17 -11
  12. data/lib/netsnmp/oid.rb +6 -3
  13. data/lib/netsnmp/pdu.rb +21 -24
  14. data/lib/netsnmp/scoped_pdu.rb +7 -6
  15. data/lib/netsnmp/security_parameters.rb +62 -54
  16. data/lib/netsnmp/session.rb +16 -14
  17. data/lib/netsnmp/timeticks.rb +1 -0
  18. data/lib/netsnmp/v3_session.rb +7 -7
  19. data/lib/netsnmp/varbind.rb +19 -11
  20. data/lib/netsnmp/version.rb +1 -1
  21. data/lib/netsnmp.rb +9 -9
  22. data/sig/client.rbs +8 -2
  23. data/sig/encryption/aes.rbs +23 -0
  24. data/sig/encryption/des.rbs +23 -0
  25. data/sig/errors.rbs +13 -0
  26. data/sig/extensions.rbs +12 -0
  27. data/sig/loggable.rbs +4 -7
  28. data/sig/message.rbs +13 -1
  29. data/sig/mib.rbs +20 -6
  30. data/sig/netsnmp.rbs +5 -5
  31. data/sig/oid.rbs +1 -0
  32. data/sig/pdu.rbs +14 -15
  33. data/sig/scoped_pdu.rbs +9 -4
  34. data/sig/security_parameters.rbs +29 -23
  35. data/sig/session.rbs +21 -6
  36. data/sig/timeticks.rbs +19 -0
  37. data/sig/v3_session.rbs +3 -2
  38. data/sig/varbind.rbs +13 -2
  39. data/spec/client_spec.rb +44 -35
  40. data/spec/handlers/celluloid_spec.rb +12 -12
  41. data/spec/pdu_spec.rb +2 -1
  42. data/spec/security_parameters_spec.rb +18 -0
  43. data/spec/support/celluloid.rb +11 -7
  44. data/spec/support/request_examples.rb +13 -4
  45. metadata +8 -4
  46. data/sig/openssl.rbs +0 -20
@@ -10,7 +10,7 @@ module NETSNMP
10
10
  using StringExtensions
11
11
  using ASNExtensions
12
12
 
13
- prepend Loggable
13
+ include Loggable
14
14
 
15
15
  IPAD = "\x36" * 64
16
16
  OPAD = "\x5c" * 64
@@ -22,13 +22,12 @@ module NETSNMP
22
22
  # The 150 Seconds is specified in https://www.ietf.org/rfc/rfc2574.txt 2.2.3
23
23
  TIMELINESS_THRESHOLD = 150
24
24
 
25
- attr_reader :security_level, :username
26
- attr_reader :engine_id
25
+ attr_reader :security_level, :username, :auth_protocol, :engine_id
27
26
 
28
27
  # @param [String] username the snmp v3 username
29
28
  # @param [String] engine_id the device engine id (initialized to '' for report)
30
29
  # @param [Symbol, integer] security_level allowed snmp v3 security level (:auth_priv, :auth_no_priv, etc)
31
- # @param [Symbol, nil] auth_protocol a supported authentication protocol (currently supported: :md5, :sha)
30
+ # @param [Symbol, nil] auth_protocol a supported authentication protocol (currently supported: :md5, :sha, :sha256)
32
31
  # @param [Symbol, nil] priv_protocol a supported privacy protocol (currently supported: :des, :aes)
33
32
  # @param [String, nil] auth_password the authentication password
34
33
  # @param [String, nil] priv_password the privacy password
@@ -39,24 +38,42 @@ module NETSNMP
39
38
  # not explicitly set), and :priv_password becomes mandatory.
40
39
  #
41
40
  def initialize(
42
- username:,
43
- engine_id: "",
44
- security_level: nil,
45
- auth_protocol: nil,
46
- auth_password: nil,
47
- priv_protocol: nil,
48
- priv_password: nil
41
+ username:,
42
+ engine_id: "",
43
+ security_level: nil,
44
+ auth_protocol: nil,
45
+ auth_password: nil,
46
+ priv_protocol: nil,
47
+ priv_password: nil,
48
+ **options
49
49
  )
50
- @security_level = security_level
50
+ @security_level = case security_level
51
+ when /no_?auth/ then 0
52
+ when /auth_?no_?priv/ then 1
53
+ when /auth_?priv/ then 3
54
+ when Integer then security_level
55
+ else 3 # rubocop:disable Lint/DuplicateBranch
56
+ end
51
57
  @username = username
52
58
  @engine_id = engine_id
53
59
  @auth_protocol = auth_protocol.to_sym unless auth_protocol.nil?
54
60
  @priv_protocol = priv_protocol.to_sym unless priv_protocol.nil?
55
- @auth_password = auth_password
56
- @priv_password = priv_password
57
- check_parameters
58
- @auth_pass_key = passkey(@auth_password) unless @auth_password.nil?
59
- @priv_pass_key = passkey(@priv_password) unless @priv_password.nil?
61
+
62
+ if @security_level.positive?
63
+ @auth_protocol ||= :md5 # this is the default
64
+ raise "security level requires an auth password" if auth_password.nil?
65
+ raise "auth password must have between 8 to 32 characters" unless (8..32).cover?(auth_password.length)
66
+ end
67
+
68
+ if @security_level > 1
69
+ @priv_protocol ||= :des
70
+ raise "security level requires a priv password" if priv_password.nil?
71
+ raise "priv password must have between 8 to 32 characters" unless (8..32).cover?(priv_password.length)
72
+ end
73
+
74
+ @auth_pass_key = passkey(auth_password) if auth_password
75
+ @priv_pass_key = passkey(priv_password) if priv_password
76
+ initialize_logger(**options)
60
77
  end
61
78
 
62
79
  def engine_id=(id)
@@ -72,9 +89,11 @@ module NETSNMP
72
89
  # @return [Array] a pair, where the first argument in the asn structure with the encoded pdu,
73
90
  # and the second is the calculated salt (if it has been encrypted)
74
91
  def encode(pdu, salt:, engine_time:, engine_boots:)
75
- if encryption
76
- encrypted_pdu, salt = encryption.encrypt(pdu.to_der, engine_boots: engine_boots,
77
- engine_time: engine_time)
92
+ encryptor = encryption
93
+
94
+ if encryptor
95
+ encrypted_pdu, salt = encryptor.encrypt(pdu.to_der, engine_boots: engine_boots,
96
+ engine_time: engine_time)
78
97
  [
79
98
  OpenSSL::ASN1::OctetString.new(encrypted_pdu).with_label(:encrypted_pdu),
80
99
  OpenSSL::ASN1::OctetString.new(salt).with_label(:salt)
@@ -92,10 +111,11 @@ module NETSNMP
92
111
  asn = OpenSSL::ASN1.decode(der)
93
112
  return asn if security_level < 3
94
113
 
95
- return asn unless encryption
114
+ encryptor = encryption
115
+ return asn unless encryptor
96
116
 
97
117
  encrypted_pdu = asn.value
98
- pdu_der = encryption.decrypt(encrypted_pdu, salt: salt, engine_time: engine_time, engine_boots: engine_boots)
118
+ pdu_der = encryptor.decrypt(encrypted_pdu, salt: salt, engine_time: engine_time, engine_boots: engine_boots)
99
119
  log(level: 2) { "message has been decrypted" }
100
120
  OpenSSL::ASN1.decode(pdu_der)
101
121
  end
@@ -110,7 +130,13 @@ module NETSNMP
110
130
 
111
131
  key = auth_key.dup
112
132
 
113
- key << "\x00" * (@auth_protocol == :md5 ? 48 : 44)
133
+ # SHA256 => https://datatracker.ietf.org/doc/html/rfc7860#section-4.2.2
134
+ # The 24 first octets of HMAC are taken as the computed MAC value
135
+ return OpenSSL::HMAC.digest("SHA256", key, message)[0, 24] if @auth_protocol == :sha256
136
+
137
+ # MD5 => https://datatracker.ietf.org/doc/html/rfc3414#section-6.3.2
138
+ # SHA1 => https://datatracker.ietf.org/doc/html/rfc3414#section-7.3.2
139
+ key << ("\x00" * (@auth_protocol == :md5 ? 48 : 44))
114
140
  k1 = key.xor(IPAD)
115
141
  k2 = key.xor(OPAD)
116
142
 
@@ -120,6 +146,7 @@ module NETSNMP
120
146
 
121
147
  digest.reset
122
148
  digest << (k2 + d1)
149
+ # The 12 first octets of the digest are taken as the computed MAC value
123
150
  digest.digest[0, 12]
124
151
  end
125
152
 
@@ -128,15 +155,18 @@ module NETSNMP
128
155
  #
129
156
  # @raise [NETSNMP::Error] if the message's integration has been violated
130
157
  def verify(stream, salt, security_level: @security_level)
131
- return if security_level < 1
158
+ return if security_level.nil? || security_level < 1
159
+
132
160
  verisalt = sign(stream)
133
161
  raise Error, "invalid message authentication salt" unless verisalt == salt
162
+
134
163
  log(level: 2) { "message has been verified" }
135
164
  end
136
165
 
137
166
  def must_revalidate?
138
167
  return @engine_id.empty? unless authorizable?
139
168
  return true if @engine_id.empty? || @timeliness.nil?
169
+
140
170
  (Process.clock_gettime(Process::CLOCK_MONOTONIC, :second) - @timeliness) >= TIMELINESS_THRESHOLD
141
171
  end
142
172
 
@@ -150,27 +180,6 @@ module NETSNMP
150
180
  @priv_key ||= localize_key(@priv_pass_key)
151
181
  end
152
182
 
153
- def check_parameters
154
- @security_level = case @security_level
155
- when Integer then @security_level
156
- when /no_?auth/ then 0
157
- when /auth_?no_?priv/ then 1
158
- when /auth_?priv/, nil then 3
159
- else
160
- raise Error, "security level not supported: #{@security_level}"
161
- end
162
-
163
- if @security_level.positive?
164
- @auth_protocol ||= :md5 # this is the default
165
- raise "security level requires an auth password" if @auth_password.nil?
166
- raise "auth password must have between 8 to 32 characters" unless (8..32).cover?(@auth_password.length)
167
- end
168
- return unless @security_level > 1
169
- @priv_protocol ||= :des
170
- raise "security level requires a priv password" if @priv_password.nil?
171
- raise "priv password must have between 8 to 32 characters" unless (8..32).cover?(@priv_password.length)
172
- end
173
-
174
183
  def localize_key(key)
175
184
  digest.reset
176
185
  digest << key
@@ -188,8 +197,8 @@ module NETSNMP
188
197
  password_length = password.length
189
198
  while password_index < 1048576
190
199
  initial = password_index % password_length
191
- rotated = password[initial..-1] + password[0, initial]
192
- buffer = rotated * (64 / rotated.length) + rotated[0, 64 % rotated.length]
200
+ rotated = String(password[initial..-1]) + String(password[0, initial])
201
+ buffer = (rotated * (64 / rotated.length)) + String(rotated[0, 64 % rotated.length])
193
202
  password_index += 64
194
203
  digest << buffer
195
204
  buffer.clear
@@ -197,13 +206,14 @@ module NETSNMP
197
206
 
198
207
  dig = digest.digest
199
208
  dig = dig[0, 16] if @auth_protocol == :md5
200
- dig
209
+ dig || ""
201
210
  end
202
211
 
203
212
  def digest
204
213
  @digest ||= case @auth_protocol
205
- when :md5 then OpenSSL::Digest::MD5.new
206
- when :sha then OpenSSL::Digest::SHA1.new
214
+ when :md5 then OpenSSL::Digest.new("MD5")
215
+ when :sha then OpenSSL::Digest.new("SHA1")
216
+ when :sha256 then OpenSSL::Digest.new("SHA256")
207
217
  else
208
218
  raise Error, "unsupported auth protocol: #{@auth_protocol}"
209
219
  end
@@ -211,10 +221,8 @@ module NETSNMP
211
221
 
212
222
  def encryption
213
223
  @encryption ||= case @priv_protocol
214
- when :des
215
- Encryption::DES.new(priv_key)
216
- when :aes
217
- Encryption::AES.new(priv_key)
224
+ when :des then Encryption::DES.new(priv_key)
225
+ when :aes then Encryption::AES.new(priv_key)
218
226
  end
219
227
  end
220
228
 
@@ -4,15 +4,23 @@ module NETSNMP
4
4
  # Let's just remind that there is no session in snmp, this is just an abstraction.
5
5
  #
6
6
  class Session
7
- prepend Loggable
7
+ include Loggable
8
8
 
9
9
  TIMEOUT = 2
10
10
 
11
11
  # @param [Hash] opts the options set
12
12
  def initialize(version: 1, community: "public", **options)
13
- @version = version
13
+ @version = case version
14
+ when Integer then version # assume the use know what he's doing
15
+ when /v?1/ then 0
16
+ when /v?2c?/ then 1
17
+ when /v?3/ then 3
18
+ else
19
+ raise "unsupported snmp version (#{version})"
20
+ end
14
21
  @community = community
15
22
  validate(**options)
23
+ initialize_logger(**options)
16
24
  end
17
25
 
18
26
  # Closes the session
@@ -28,7 +36,7 @@ module NETSNMP
28
36
  # @return [NETSNMP::PDU] a pdu
29
37
  #
30
38
  def build_pdu(type, *vars)
31
- PDU.build(type, headers: [@version, @community], varbinds: vars)
39
+ PDU.build(type, version: @version, community: @community, varbinds: vars)
32
40
  end
33
41
 
34
42
  # send a pdu, receives a pdu
@@ -58,16 +66,9 @@ module NETSNMP
58
66
  @transport = proxy
59
67
  else
60
68
  raise "you must provide an hostname/ip under :host" unless host
69
+
61
70
  @transport = Transport.new(host, port.to_i, timeout: timeout)
62
71
  end
63
- @version = case @version
64
- when Integer then @version # assume the use know what he's doing
65
- when /v?1/ then 0
66
- when /v?2c?/ then 1
67
- when /v?3/ then 3
68
- else
69
- raise "unsupported snmp version (#{@version})"
70
- end
71
72
  end
72
73
 
73
74
  class Transport
@@ -75,7 +76,7 @@ module NETSNMP
75
76
 
76
77
  def initialize(host, port, timeout:)
77
78
  @socket = UDPSocket.new
78
- @socket.connect(host, port)
79
+ @destaddr = Socket.sockaddr_in(port, host)
79
80
  @timeout = timeout
80
81
  end
81
82
 
@@ -90,13 +91,13 @@ module NETSNMP
90
91
 
91
92
  def write(payload)
92
93
  perform_io do
93
- @socket.send(payload, 0)
94
+ @socket.sendmsg(payload, Socket::MSG_DONTWAIT, @destaddr)
94
95
  end
95
96
  end
96
97
 
97
98
  def recv(bytesize = MAXPDUSIZE)
98
99
  perform_io do
99
- datagram, = @socket.recvfrom_nonblock(bytesize)
100
+ datagram, = @socket.recvmsg_nonblock(bytesize, Socket::MSG_DONTWAIT)
100
101
  datagram
101
102
  end
102
103
  end
@@ -117,6 +118,7 @@ module NETSNMP
117
118
 
118
119
  def wait(mode)
119
120
  return if @socket.__send__(mode, @timeout)
121
+
120
122
  raise Timeout::Error, "Timeout after #{@timeout} seconds"
121
123
  end
122
124
  end
@@ -5,6 +5,7 @@ module NETSNMP
5
5
  # @param [Integer] ticks number of microseconds since the time it was read
6
6
  def initialize(ticks)
7
7
  @ticks = ticks
8
+ super()
8
9
  end
9
10
 
10
11
  def to_s
@@ -16,7 +16,7 @@ module NETSNMP
16
16
  # @return [NETSNMP::ScopedPDU] a pdu
17
17
  def build_pdu(type, *vars)
18
18
  engine_id = security_parameters.engine_id
19
- ScopedPDU.build(type, headers: [engine_id, @context], varbinds: vars)
19
+ ScopedPDU.build(type, engine_id: engine_id, context: @context, varbinds: vars)
20
20
  end
21
21
 
22
22
  # @see {NETSNMP::Session#send}
@@ -42,11 +42,11 @@ module NETSNMP
42
42
  end
43
43
  else
44
44
  @security_parameters = SecurityParameters.new(security_level: options[:security_level],
45
- username: options[:username],
46
- auth_protocol: options[:auth_protocol],
47
- priv_protocol: options[:priv_protocol],
48
- auth_password: options[:auth_password],
49
- priv_password: options[:priv_password])
45
+ username: options[:username],
46
+ auth_protocol: options[:auth_protocol],
47
+ priv_protocol: options[:priv_protocol],
48
+ auth_password: options[:auth_password],
49
+ priv_password: options[:priv_password])
50
50
 
51
51
  end
52
52
  end
@@ -61,7 +61,7 @@ module NETSNMP
61
61
  def probe_for_engine
62
62
  report_sec_params = SecurityParameters.new(security_level: 0,
63
63
  username: @security_parameters.username)
64
- pdu = ScopedPDU.build(:get, headers: [])
64
+ pdu = ScopedPDU.build(:get)
65
65
  log { "sending probe..." }
66
66
  encoded_report_pdu = @message_serializer.encode(pdu, security_parameters: report_sec_params)
67
67
 
@@ -24,8 +24,10 @@ module NETSNMP
24
24
 
25
25
  def to_asn
26
26
  asn_oid = OID.to_asn(@oid)
27
- asn_val = if @type
28
- convert_to_asn(@type, @value)
27
+ type = @type
28
+
29
+ asn_val = if type
30
+ convert_to_asn(type, @value)
29
31
  else
30
32
  case @value
31
33
  when String
@@ -37,8 +39,10 @@ module NETSNMP
37
39
  when nil
38
40
  OpenSSL::ASN1::Null.new(nil)
39
41
  when IPAddr
42
+ # @type ivar @value: IPAddr
40
43
  OpenSSL::ASN1::ASN1Data.new(@value.hton, 0, :APPLICATION)
41
44
  when Timetick
45
+ # @type ivar @value: Timetick
42
46
  @value.to_asn
43
47
  else
44
48
  raise Error, "#{@value}: unsupported varbind type"
@@ -73,37 +77,41 @@ module NETSNMP
73
77
  end
74
78
 
75
79
  def convert_to_asn(typ, value)
76
- asn_type = typ
77
80
  asn_val = value
78
- if typ.is_a?(Symbol)
79
- asn_type = case typ
81
+
82
+ asn_type = if typ.is_a?(Symbol)
83
+ case typ
80
84
  when :ipaddress then 0
81
85
  when :counter32
82
86
  asn_val = [value].pack("N*")
83
- asn_val = asn_val[1..-1] while asn_val[0] == "\x00".b && asn_val[1].unpack1("B") != "1"
87
+ asn_val = asn_val.delete_prefix("\x00") while asn_val[0] == "\x00".b && String(asn_val[1]).unpack1("B") != "1"
84
88
  1
85
89
  when :gauge
86
90
  asn_val = [value].pack("N*")
87
- asn_val = asn_val[1..-1] while asn_val[0] == "\x00".b && asn_val[1].unpack1("B") != "1"
91
+ asn_val = asn_val.delete_prefix("\x00") while asn_val[0] == "\x00".b && String(asn_val[1]).unpack1("B") != "1"
88
92
  2
89
93
  when :timetick
94
+ # @type var value: Integer
90
95
  return Timetick.new(value).to_asn
91
96
  when :opaque then 4
92
97
  when :nsap then 5
93
98
  when :counter64
99
+ # @type var value: Integer
94
100
  asn_val = [
95
101
  (value >> 96) & 0xFFFFFFFF,
96
102
  (value >> 64) & 0xFFFFFFFF,
97
103
  (value >> 32) & 0xFFFFFFFF,
98
104
  value & 0xFFFFFFFF
99
105
  ].pack("NNNN")
100
- asn_val = asn_val[1..-1] while asn_val.start_with?("\x00")
106
+ asn_val = asn_val.delete_prefix("\x00") while asn_val.start_with?("\x00")
101
107
  6
102
108
  when :uinteger then 7
103
109
  else
104
110
  raise Error, "#{typ}: unsupported application type"
105
111
  end
106
- end
112
+ else
113
+ typ
114
+ end
107
115
  OpenSSL::ASN1::ASN1Data.new(asn_val, asn_type, :APPLICATION)
108
116
  end
109
117
 
@@ -128,12 +136,12 @@ module NETSNMP
128
136
 
129
137
  def unpack_32bit_integer(payload)
130
138
  payload.prepend("\x00") until (payload.bytesize % 4).zero?
131
- payload.unpack("N*")[-1] || 0
139
+ payload.unpack("N*")[-1].to_i
132
140
  end
133
141
 
134
142
  def unpack_64bit_integer(payload)
135
143
  payload.prepend("\x00") until (payload.bytesize % 16).zero?
136
- payload.unpack("NNNN").reduce(0) { |sum, elem| (sum << 32) + elem }
144
+ payload.unpack("NNNN").reduce(0) { |sum, elem| (sum << 32) + elem.to_i }
137
145
  end
138
146
  end
139
147
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NETSNMP
4
- VERSION = "0.4.2"
4
+ VERSION = "0.6.2"
5
5
  end
data/lib/netsnmp.rb CHANGED
@@ -8,13 +8,13 @@ require "ipaddr"
8
8
 
9
9
  # core structures
10
10
 
11
- begin
12
- require "xorcist"
13
- require "xorcist/refinements"
14
- NETSNMP::StringExtensions = Xorcist::Refinements
15
- rescue LoadError
16
- # "no xorcist"
17
- module NETSNMP
11
+ module NETSNMP
12
+ begin
13
+ require "xorcist"
14
+ require "xorcist/refinements"
15
+ StringExtensions = Xorcist::Refinements
16
+ rescue LoadError
17
+ # "no xorcist"
18
18
  module StringExtensions
19
19
  refine String do
20
20
  # Bitwise XOR operator for the String class
@@ -24,8 +24,8 @@ rescue LoadError
24
24
 
25
25
  b2 = other.unpack("C*")
26
26
  longest = [b1.length, b2.length].max
27
- b1 = [0] * (longest - b1.length) + b1
28
- b2 = [0] * (longest - b2.length) + b2
27
+ b1 = ([0] * (longest - b1.length)) + b1
28
+ b2 = ([0] * (longest - b2.length)) + b2
29
29
  b1.zip(b2).map { |a, b| a ^ b }.pack("C*")
30
30
  end
31
31
  end
data/sig/client.rbs CHANGED
@@ -1,5 +1,9 @@
1
1
  module NETSNMP
2
2
  class Client
3
+ RETRIES: Integer
4
+
5
+ @retries: Integer
6
+ @session: Session
3
7
 
4
8
  def get: (*untyped) -> untyped
5
9
  | (*untyped) { (PDU) -> void } -> untyped
@@ -13,12 +17,14 @@ module NETSNMP
13
17
  def inform: (*untyped) -> untyped
14
18
  | (*untyped) { (PDU) -> void } -> untyped
15
19
 
16
- def walk: (oid: oid) -> _Each[oid_type, oid_value]
20
+ def walk: (oid: oid) -> _Each[[oid_type, oid_value]]
17
21
 
18
22
  def close: () -> void
19
23
 
20
24
  private
21
25
 
22
- def initialize: (?version?: snmp_version, **untyped) -> untyped
26
+ def initialize: (?version: snmp_version, **untyped) ?{ (instance) -> void } -> void
27
+
28
+ def handle_retries: [U] { () -> U } -> U
23
29
  end
24
30
  end
@@ -0,0 +1,23 @@
1
+ module NETSNMP
2
+ module Encryption
3
+ class AES
4
+
5
+ @priv_key: String
6
+ @local: Integer
7
+
8
+ def encrypt: (String decrypted_data, engine_boots: Integer, engine_time: Integer) -> [String, String]
9
+
10
+ def decrypt: (String encrypted_data, salt: String, engine_boots: Integer, engine_time: Integer) -> String
11
+
12
+ private
13
+
14
+ def initialize: (String priv_key, ?local: Integer) -> untyped
15
+
16
+ def generate_encryption_key: (Integer boots, Integer time) -> [String, String]
17
+
18
+ def generate_decryption_key: (Integer boots, Integer time, String salt) -> String
19
+
20
+ def aes_key: () -> String
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module NETSNMP
2
+ module Encryption
3
+ class DES
4
+
5
+ @priv_key: String
6
+ @local: Integer
7
+
8
+ def encrypt: (String decrypted_data, engine_boots: Integer, **untyped) -> [String, String]
9
+
10
+ def decrypt: (String encrypted_data, salt: String, **untyped) -> String
11
+
12
+ private
13
+
14
+ def initialize: (String priv_key, ?local: Integer) -> untyped
15
+
16
+ def generate_encryption_key: (Integer boots) -> [String, String]
17
+
18
+ def generate_decryption_key: (String salt) -> String
19
+
20
+ def des_key: () -> String
21
+ end
22
+ end
23
+ end
data/sig/errors.rbs ADDED
@@ -0,0 +1,13 @@
1
+ module NETSNMP
2
+ class Error < StandardError
3
+ end
4
+
5
+ class ConnectionFailed < Error
6
+ end
7
+
8
+ class AuthenticationFailed < Error
9
+ end
10
+
11
+ class IdNotInTimeWindowError < Error
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module NETSNMP
2
+ module ASNExtensions
3
+ ASN_COLORS: Hash[singleton(OpenSSL::ASN1::ASN1Data), Integer]
4
+ end
5
+
6
+ module Hexdump
7
+ def self?.dump: (String data, ?width: Integer, ?in_groups_of: Integer, ?separator: String) -> String
8
+ end
9
+
10
+ class HexString < String
11
+ end
12
+ end
data/sig/loggable.rbs CHANGED
@@ -1,15 +1,12 @@
1
1
  module NETSNMP
2
2
  module Loggable
3
- interface _Debugger
4
- def <<: (string) -> void
5
- end
6
-
7
3
  DEBUG_LEVEL: Integer
8
- DEBUG: _Debugger
4
+ DEBUG: IO?
5
+ COLORS: Hash[Symbol, Integer]
9
6
 
10
- private
7
+ def initialize_logger: (?debug: IO, ?debug_level: Integer, **untyped) -> void
11
8
 
12
- def initialize: (?debug: _DEBUGGER, ?debug_level: Integer, **untyped) -> void
9
+ private
13
10
 
14
11
  def log: (?level: Integer) { () -> String } -> void
15
12
  end
data/sig/message.rbs CHANGED
@@ -1,11 +1,23 @@
1
1
  module NETSNMP
2
2
  class Message
3
- prepend Loggable
3
+ include Loggable
4
+
5
+ PRIVNONE: OpenSSL::ASN1::OctetString
6
+ MSG_MAX_SIZE: OpenSSL::ASN1::Integer
7
+ MSG_SECURITY_MODEL: OpenSSL::ASN1::Integer
8
+ MSG_VERSION: OpenSSL::ASN1::Integer
9
+ MSG_REPORTABLE: Integer
4
10
 
5
11
  def verify: (String stream, String auth_param, Integer? security_level, security_parameters: SecurityParameters) -> void
6
12
 
7
13
  def decode: (String stream, security_parameters: SecurityParameters) -> [ScopedPDU, String, Integer, Integer]
8
14
 
9
15
  def encode: (ScopedPDU pdu, security_parameters: SecurityParameters, ?engine_boots: Integer, ?engine_time: Integer) -> String
16
+
17
+ private
18
+
19
+ def initialize: (**untyped options) -> void
20
+
21
+ def authnone: (Symbol?) -> OpenSSL::ASN1::ASN1Data
10
22
  end
11
23
  end
data/sig/mib.rbs CHANGED
@@ -2,20 +2,34 @@ module NETSNMP
2
2
  module MIB
3
3
  type import = {ids: Array[{name: string}], name: string} | {ids: {name: string}, name: string}
4
4
 
5
-
5
+ OIDREGEX: Regexp
6
6
  MIBDIRS: Array[String]
7
7
  PARSER: Parser
8
8
 
9
- @parser_mutex: Mutex
9
+ TYPES: Array[String]
10
+ STATIC_MIB_TO_OID: Hash[String, String]
11
+
12
+ @parser_mutex: Thread::Mutex
10
13
  @modules_loaded: Array[String]
11
14
  @object_identifiers: Hash[String, String]
12
15
 
13
- def self?.oid: (String identifier) -> String?
14
- | (Array[_ToS] identifier) -> String?
16
+ def self?.oid: (oid identifier) -> String?
15
17
 
16
- def self?.load: (String mod) -> void
18
+ def self?.load: (String mod) -> bool
19
+
20
+ def self?.load_imports: (Array[import] | import | nil data) -> Hash[String, Array[String]]?
17
21
 
18
- def self?.load_imports: ((Array[import] | import)? data) -> Hash[String, Array[String]]?
19
22
  def self?.load_defaults: () -> void
23
+
24
+ def self?.do_load: (String mod) -> void
25
+
26
+ def self?.module_loaded?: (String mod) -> bool
27
+
28
+ def self?.store_oid_in_identifiers: (String name, Array[String] value, imports: Hash[String, Array[String]]?, declarations: Hash[String, Array[String]]) -> void
29
+
30
+ # workaround
31
+ class Parser
32
+ def parse: (String data) -> Hash[:imports | :declarations, untyped?]
33
+ end
20
34
  end
21
35
  end