From e9fa138838e0ed2c6920ab51bc861b0358caee79 Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Mon, 2 Nov 2026 07:58:03 +0200 Subject: [PATCH 1/7] test: pin an empty msgGlobalData and every discard reason a request ends with A decode case for an SNMPv3 message whose msgGlobalData has no field: it fails at the msgID. Seven v3 scenarios answer every attempt with a reply that names it but does not answer it, one reason each (another version, the request sent back, another request ID, another security level, the empty user name, another engine ID, another context): the request times out with the reason, which matches no exported error today. --- codec_decode_test.go | 1 + engine_v3_test.go | 36 +++++ testdata/codec/decode.golden | 3 + testdata/engine/v3.golden | 304 +++++++++++++++++++++++++++++++++++ 4 files changed, 344 insertions(+) diff --git a/codec_decode_test.go b/codec_decode_test.go index 11648ad..3bb9b77 100644 --- a/codec_decode_test.go +++ b/codec_decode_test.go @@ -658,6 +658,7 @@ func decodeCraftedCases() []decodeCase { {name: "crafted/v3/flags-reserved-bits", in: craftedV3(intTLV(42), intTLV(65507), octets("\xfc"), intTLV(3), craftedNoAuthUSM, craftedScopedResp)}, {name: "crafted/v3/flags-integer", in: craftedV3(intTLV(42), intTLV(65507), intTLV(0), intTLV(3), craftedNoAuthUSM, craftedScopedResp)}, {name: "crafted/v3/security-model-2", in: craftedV3(intTLV(42), intTLV(65507), octets("\x00"), intTLV(2), craftedNoAuthUSM, craftedScopedResp)}, + {name: "crafted/v3/msg-global-data-empty", in: craftedV3(nil, nil, nil, nil, craftedNoAuthUSM, craftedScopedResp)}, {name: "crafted/v3/msg-id-negative", in: craftedV3(intTLV(-1), intTLV(65507), octets("\x00"), intTLV(3), craftedNoAuthUSM, craftedScopedResp)}, {name: "crafted/v3/msg-id-octet-string", in: craftedV3(octets("\x2a"), intTLV(65507), octets("\x00"), intTLV(3), craftedNoAuthUSM, craftedScopedResp)}, {name: "crafted/v3/msg-id-2147483647", in: craftedV3(intTLV(math.MaxInt32), intTLV(65507), octets("\x00"), intTLV(3), craftedNoAuthUSM, craftedScopedResp)}, diff --git a/engine_v3_test.go b/engine_v3_test.go index 7cd9a1d..cfdebde 100644 --- a/engine_v3_test.go +++ b/engine_v3_test.go @@ -1653,6 +1653,42 @@ func v3Scenarios() map[string]v3Scenario { } return agentAnswer{}, false }}, + // Every attempt answered with a reply that names it but does not + // answer it, by one reason each: the request's error ends with the + // reason and matches its category. + "discard/every-attempt/other-version": {user: "codec-noauth", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{why: "SNMPv2c Response", edit: asV2c}, n > 1 + }}, + "discard/every-attempt/reflected-request": {user: "codec-md5", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{reflect: true, why: "the request sent back"}, n > 1 + }}, + "discard/every-attempt/other-request-id": {user: "codec-md5", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{ + level: AuthNoPriv, why: "Response for another request", edit: func(p *agentOut) { p.RequestID += 100 }, + }, n > 1 + }}, + "discard/every-attempt/other-level": {user: "codec-sha-aes", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{level: AuthNoPriv, why: "Response without encryption"}, n > 1 + }}, + // Security processing rejects another user's name; the empty one of + // discovery passes it, and step 12 b discards it. + "discard/every-attempt/empty-user": {user: "codec-noauth", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{ + why: "Response without a user name", edit: func(p *agentOut) { p.SecurityParameters.UserName = "" }, + }, n > 1 + }}, + "discard/every-attempt/other-engine": {user: "codec-noauth", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{ + why: "Response naming the other engine ID", + edit: func(p *agentOut) { p.SecurityParameters.AuthoritativeEngineID = []byte(agentOtherEngineID) }, + }, n > 1 + }}, + "discard/every-attempt/other-context": {user: "codec-md5", script: func(n int, _ agentRequest) (agentAnswer, bool) { + return agentAnswer{ + level: AuthNoPriv, why: "Response with another context name", + edit: func(p *agentOut) { p.ContextName = "codec-other-name" }, + }, n > 1 + }}, // Every attempt answered with lower boots, then the request sent back // unchanged: the request's error is the time window's. "discard/not-in-time-window-then-reflected": { diff --git a/testdata/codec/decode.golden b/testdata/codec/decode.golden index 4382758..4fec375 100644 --- a/testdata/codec/decode.golden +++ b/testdata/codec/decode.golden @@ -1976,6 +1976,9 @@ decode: error (ErrInvalidMsgs) == crafted/v3/security-model-2 decode: error (ErrUnknownSecurityModels) +== crafted/v3/msg-global-data-empty +decode: error (ErrInvalidMsgs) + == crafted/v3/msg-id-negative decode: error (ErrInvalidMsgs) diff --git a/testdata/engine/v3.golden b/testdata/engine/v3.golden index d8d57a2..2ec60ed 100644 --- a/testdata/engine/v3.golden +++ b/testdata/engine/v3.golden @@ -2469,6 +2469,310 @@ 0s result: packet 3 msgID=2002 noAuthNoPriv Response id=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" usm="codec-noauth"/"\x80\x00\x1f\x88\x04codec-agent"/7/1000 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"], no error 0s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" +== v3/discard/every-attempt/empty-user +0s client: user="codec-noauth" noAuthNoPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: answers #2 with Response id=1002 msgID=2002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (Response without a user name) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2002 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: answers #3 with Response id=1003 msgID=2003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (Response without a user name) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 3 msgID=2003 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: answers #4 with Response id=1004 msgID=2004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (Response without a user name) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 3 msgID=2004 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's user name is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" + +== v3/discard/every-attempt/other-context +0s client: user="codec-md5" authNoPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: answers #2 with Response id=1002 msgID=2002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response with another context name) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2002 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"codec-other-name" Response id=1002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: answers #3 with Response id=1003 msgID=2003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response with another context name) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 3 msgID=2003 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"codec-other-name" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: answers #4 with Response id=1004 msgID=2004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response with another context name) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"codec-other-name" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's context is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" + +== v3/discard/every-attempt/other-engine +0s client: user="codec-noauth" noAuthNoPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: answers #2 with Response id=1002 msgID=2002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (Response naming the other engine ID) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2002 noAuthNoPriv user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-other" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: answers #3 with Response id=1003 msgID=2003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (Response naming the other engine ID) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 3 msgID=2003 noAuthNoPriv user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-other" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: answers #4 with Response id=1004 msgID=2004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (Response naming the other engine ID) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 3 msgID=2004 noAuthNoPriv user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-other" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's engine ID is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" + +== v3/discard/every-attempt/other-level +0s client: user="codec-sha-aes" authPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 authPriv+reportable user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 salt=0000000000000101 encrypted +0s agent: #2 decrypts to context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: answers #2 with Response id=1002 msgID=2002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response without encryption) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2002 authNoPriv user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 authPriv+reportable user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 salt=0000000000000102 encrypted +1s agent: #3 decrypts to context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: answers #3 with Response id=1003 msgID=2003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response without encryption) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 3 msgID=2003 authNoPriv user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 authPriv+reportable user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 salt=0000000000000103 encrypted +2s agent: #4 decrypts to context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: answers #4 with Response id=1004 msgID=2004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response without encryption) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's security level is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" + +== v3/discard/every-attempt/other-request-id +0s client: user="codec-md5" authNoPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: answers #2 with Response id=1102 msgID=2002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response for another request) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2002 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1102 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: answers #3 with Response id=1103 msgID=2003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response for another request) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 3 msgID=2003 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1103 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: answers #4 with Response id=1104 msgID=2004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at authNoPriv (Response for another request) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1104 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's request ID does not match the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" + +== v3/discard/every-attempt/other-version +0s client: user="codec-noauth" noAuthNoPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: answers #2 with Response id=1002 msgID=2002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (SNMPv2c Response) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 2c "public" Response id=1002 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: answers #3 with Response id=1003 msgID=2003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (SNMPv2c Response) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 2c "public" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 noAuthNoPriv+reportable user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: answers #4 with Response id=1004 msgID=2004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] at noAuthNoPriv (SNMPv2c Response) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 2c "public" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" + +== v3/discard/every-attempt/reflected-request +0s client: user="codec-md5" authNoPriv timeout=1s retries=2 +0s deadline +1s +0s hook PreSend +0s write #1: 3 msgID=2001 noAuthNoPriv+reportable user="" engine="" boots=0 time=0 context=""/"" GetRequest id=1001 [] +0s agent: answers #1 with Report id=1001 msgID=2001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] at noAuthNoPriv (unknown engine ID) +0s agent answers #1 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2001 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" Report id=1001 [.1.3.6.1.6.3.15.1.1.4.0=Counter32:1] +0s hook OnRecv +0s hook OnFinish +0s deadline +1s +0s hook PreSend +0s write #2: 3 msgID=2002 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s agent: reflects #2 unchanged (the request sent back) +0s agent answers #2 after 0s +0s hook OnSent +0s read from 127.0.0.2:161: 3 msgID=2002 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1002 [.1.3.6.1.2.1.1.1.0] +0s hook OnRecv +1s read from 127.0.0.2:161: deadline +1s hook OnRetry +1s deadline +1s +1s hook PreSend +1s write #3: 3 msgID=2003 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s agent: reflects #3 unchanged (the request sent back) +1s agent answers #3 after 0s +1s hook OnSent +1s read from 127.0.0.2:161: 3 msgID=2003 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1001 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1003 [.1.3.6.1.2.1.1.1.0] +1s hook OnRecv +2s read from 127.0.0.2:161: deadline +2s hook OnRetry +2s deadline +1s +2s hook PreSend +2s write #4: 3 msgID=2004 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s agent: reflects #4 unchanged (the request sent back) +2s agent answers #4 after 0s +2s hook OnSent +2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] +2s hook OnRecv +3s read from 127.0.0.2:161: deadline +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is neither a Response nor an SNMPv3 Report" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" + == v3/discard/not-encrypted-then-answer 0s client: user="codec-sha-aes" authPriv timeout=1s retries=2 0s deadline +1s From a20d9593861963487e6fe16156759fb8517748cc Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Mon, 2 Nov 2026 08:16:13 +0200 Subject: [PATCH 2/7] feat!: every rejection of an incoming message in one error category Each error of decoding a message (DecodeMessage, UnmarshalTrap, a request's reply), of its security processing and of matching a reply to a request now unwraps to exactly one exported category, named after the counter RFC 3412, RFC 3414 or RFC 3418 counts the message in, as net-snmp v5.9.4 counts it: - ErrASNParse (snmpInASNParseErrs): a message that does not parse, of any version: its encoding, a header field of another type or outside its range, the USM parameters, a scoped PDU of the wrong type for the privFlag or one that does not parse in plaintext, the PDU, an unknown PDU type, a varbind. SNMPv1 and SNMPv2c parse errors had no category; SNMPv3 header and scoped-PDU ones were ErrInvalidMsgs. - ErrBadVersion (snmpInBadVersions): a version other than 0, 1 and 3. - ErrInvalidMsgs: privacy without authentication only (RFC 3412 7.2 step 5 d). - ErrUnmatchedReply: a decoded reply a request discards because it does not answer it (another version, an ID of no attempt, not a Response or Report, another request ID, level, user name, engine ID or context); a request that times out after such a reply matches it. The security-processing and Report categories are unchanged; a decrypted scoped PDU that does not parse stays ErrDecryption (net-snmp counts a parse error). Error texts are unchanged. The categories live in errors.go, documented with a note on the variables: they are for errors.Is, and the library returns the values they had at init. BREAKING: the BER details ErrBase128IntegerTooLarge, ErrBase128IntegerTruncated, ErrFloatBufferTooShort, ErrFloatTooLarge, ErrIntegerTooLarge, ErrInvalidOidLength, ErrInvalidPacketLength, ErrZeroByteBuffer and ErrZeroLenInteger are no longer exported: an error matches its category only. The goldens print them as internal details. The fuzz targets check that every error they see has exactly one category. --- codec_failure_test.go | 4 +- codec_fuzz_test.go | 3 +- codec_golden_test.go | 49 +-- doc.go | 80 +++-- engine.go | 39 +-- engine_fuzz_test.go | 12 +- engine_harness_test.go | 15 +- errors.go | 83 +++++ errors_test.go | 87 +++++ helper.go | 25 -- internal/ber/ber.go | 4 +- pdu.go | 61 +++- testdata/codec/decode.golden | 542 ++++++++++++++--------------- testdata/engine/requests.golden | 22 +- testdata/engine/v3.golden | 16 +- testdata/usm/decrypt.golden | 72 ++-- testdata/usm/receiver-rules.golden | 40 +-- trap_timeliness_test.go | 2 +- usm_characterization_test.go | 12 +- usm_fuzz_test.go | 4 +- v3.go | 68 ++-- v3_parse_test.go | 6 +- v3_usm_test.go | 8 +- 23 files changed, 705 insertions(+), 549 deletions(-) create mode 100644 errors.go create mode 100644 errors_test.go diff --git a/codec_failure_test.go b/codec_failure_test.go index dc16506..f610885 100644 --- a/codec_failure_test.go +++ b/codec_failure_test.go @@ -208,7 +208,7 @@ func TestDecodeFailurePartialResults(t *testing.T) { // TestDecodeUSMFields pins RFC 3414 section 3.2 step 1: each USM field must // be of its type, and the engine boots and time within 0..2147483647 once cut // to 32 bits (as net-snmp v5.9.4 reads them); anything else fails the header -// parse with ErrInvalidMsgs, on the raw path too. +// parse with ErrASNParse, on the raw path too. func TestDecodeUSMFields(t *testing.T) { const engineID = "\x80\x00\x1f\x88\x04codec-engine" fields := func(edit func(f [][]byte)) []byte { @@ -238,7 +238,7 @@ func TestDecodeUSMFields(t *testing.T) { t.Run(name, func(t *testing.T) { _, err := (&Client{}).DecodeMessage(tc.in) if tc.invalid { - assert.ErrorIs(t, err, ErrInvalidMsgs) + assert.ErrorIs(t, err, ErrASNParse) } else { assert.NoError(t, err) } diff --git a/codec_fuzz_test.go b/codec_fuzz_test.go index 4a49679..a4e020e 100644 --- a/codec_fuzz_test.go +++ b/codec_fuzz_test.go @@ -36,7 +36,8 @@ func FuzzUnmarshal(f *testing.F) { f.Fuzz(func(t *testing.T, data []byte) { stime := time.Now() in := bytes.Clone(data) - _, _ = vhandle.DecodeMessage(in) + _, err := vhandle.DecodeMessage(in) + checkCategory(t, "DecodeMessage", err) if e := time.Since(stime); e > (time.Second * 1) { t.Errorf("DecodeMessage() took too long: %s", e) diff --git a/codec_golden_test.go b/codec_golden_test.go index 90ec74d..cb453b6 100644 --- a/codec_golden_test.go +++ b/codec_golden_test.go @@ -203,45 +203,24 @@ func readGoldenFile(path string) ([]goldenSection, error) { return sections, nil } -// codecSentinels are the exported errors a codec result is matched against. -var codecSentinels = []struct { - name string - err error -}{ - {"ErrBase128IntegerTooLarge", ErrBase128IntegerTooLarge}, - {"ErrBase128IntegerTruncated", ErrBase128IntegerTruncated}, - {"ErrFloatBufferTooShort", ErrFloatBufferTooShort}, - {"ErrFloatTooLarge", ErrFloatTooLarge}, - {"ErrIntegerTooLarge", ErrIntegerTooLarge}, - {"ErrInvalidOidLength", ErrInvalidOidLength}, - {"ErrInvalidPacketLength", ErrInvalidPacketLength}, - {"ErrZeroByteBuffer", ErrZeroByteBuffer}, - {"ErrZeroLenInteger", ErrZeroLenInteger}, - {"ErrDecryption", ErrDecryption}, - {"ErrInvalidMsgs", ErrInvalidMsgs}, - {"ErrNotInTimeWindow", ErrNotInTimeWindow}, - {"ErrUnknownEngineID", ErrUnknownEngineID}, - {"ErrUnknownPDUHandlers", ErrUnknownPDUHandlers}, - {"ErrUnknownReportPDU", ErrUnknownReportPDU}, - {"ErrUnknownSecurityLevel", ErrUnknownSecurityLevel}, - {"ErrUnknownSecurityModels", ErrUnknownSecurityModels}, - {"ErrUnknownUsername", ErrUnknownUsername}, - {"ErrWrongDigest", ErrWrongDigest}, -} - -// dumpError describes an error by the exported sentinels it matches; the -// message text is not part of the pinned behavior. +// dumpError describes an error by the categories it matches and the +// unexported decode errors it wraps besides (decodeDetails); the message text +// is not part of the pinned behavior. func dumpError(err error) string { - var matched []string - for _, s := range codecSentinels { - if errors.Is(err, s.err) { - matched = append(matched, s.name) + out := "error" + if names := categoriesOf(err); len(names) > 0 { + out += " (" + strings.Join(names, ", ") + ")" + } + var details []string + for _, d := range decodeDetails { + if errors.Is(err, d.err) { + details = append(details, d.name) } } - if len(matched) == 0 { - return "error" + if len(details) > 0 { + out += " detail (" + strings.Join(details, ", ") + ")" } - return "error (" + strings.Join(matched, ", ") + ")" + return out } // observe runs fn and reports whether it panicked and whether it wrote to diff --git a/doc.go b/doc.go index 7cba6ed..1cd3b41 100644 --- a/doc.go +++ b/doc.go @@ -68,14 +68,15 @@ // "request timeout (after N retries)", which matches the attempt's reason with // [errors.Is] and [errors.As] (the timeout, a [net.Error]). When the request // discarded messages, such an error, and one at the Context's deadline, also -// matches the reason of the one that came closest to answering it (the last -// authentic reply naming the request, by its SNMPv3 msgID, else the last naming -// it, by that msgID or as an SNMPv1 or SNMPv2c Response with one of its -// request IDs, else the last one whose ID could not be read, as one of another -// SNMP version; messages to other requests do not count), and its text ends -// with ": last discarded reply: " and that reason's text. An answer's error -// status ([Message].ErrorStatus) is not an error of the request. Connect uses -// Timeout and the Context too, for its lookup of Target and its dial together. +// matches the reason, and so the category (see Errors), of the one that came +// closest to answering it (the last authentic reply naming the request, by its +// SNMPv3 msgID, else the last naming it, by that msgID or as an SNMPv1 or +// SNMPv2c Response with one of its request IDs, else the last one whose ID +// could not be read, as one of another SNMP version; messages to other +// requests do not count), and its text ends with ": last discarded reply: " +// and that reason's text. An answer's error status ([Message].ErrorStatus) is +// not an error of the request. Connect uses Timeout and the Context too, for +// its lookup of Target and its dial together. // // # Hooks // @@ -151,7 +152,8 @@ // b; one that differs leaves the request outstanding, as in net-snmp). A reply // that fails is discarded like one that does not decode; the error of a request // that then times out or ends at the Context's deadline also matches the -// step's, [ErrNotInTimeWindow] for the time window (see Attempts and timeouts). +// step's, [ErrNotInTimeWindow] for the time window, and [ErrUnmatchedReply] +// for a reply that does not answer (see Attempts and timeouts). // // The client takes the engine ID of each answer whose digest it checked and of // each Response, which name the request's (security processing, the rule @@ -372,22 +374,46 @@ // // # Errors // -// The errors named after the counters a Report carries ([ErrUnknownUsername], -// [ErrWrongDigest] and the others) are also the categories of the library's -// own rejections of a message: an error of decoding an SNMPv3 message, a trap -// or a reply, unwraps ([errors.Is]) to the counter of the RFC 3412 section 7.2 -// or RFC 3414 section 3.2 step that rejected it, with its own text: -// [ErrUnknownSecurityModels] for another security model, [ErrInvalidMsgs] for -// privacy without authentication and, in place of snmpInASNParseErrs, which -// has no error of its own, for a header or a scoped PDU that does not parse -// before decryption, [ErrUnknownEngineID] through [ErrDecryption] for the -// security processing, [ErrUnknownSecurityLevel] for a trap receiver's minimum -// level too. A decode error also unwraps to [ErrInvalidPacketLength] when a -// length caused it, besides its category: after a wrong privacy key, a -// decrypted scoped PDU whose length runs past its plaintext matches both -// [ErrDecryption] and [ErrInvalidPacketLength]. A request that times out or -// ends at the Context's deadline after discarded replies fails with an error -// that also matches the reason of the one that came closest to answering it (see Attempts and timeouts), so it matches -// these errors without a Report. A local failure, such as a key that does not -// fit its protocol, matches none of them. +// Every error of an incoming message unwraps ([errors.Is]) to exactly one +// category, an exported error named after the counter RFC 3412, RFC 3414 or +// RFC 3418 counts the message in, as net-snmp v5.9.4 counts it, with a text of +// its own: an error of DecodeMessage, of UnmarshalTrap, and the reason a +// request discards a reply for. In the order a message meets them: +// +// - [ErrASNParse] (snmpInASNParseErrs): the message does not parse, of any +// version: its encoding, a header field of another type or outside its +// range, the USM parameters (RFC 3414 section 3.2 step 1), a scoped PDU of +// the other type than the privFlag asks for or one that does not parse in +// plaintext, the PDU, an unknown PDU type and a varbind (RFC 3412 section +// 7.2 steps 2 and 7); +// - [ErrBadVersion] (snmpInBadVersions): a version other than SNMPv1, SNMPv2c +// and SNMPv3 (RFC 3412 section 4.2.1); +// - [ErrUnknownSecurityModels]: another security model (step 4); +// - [ErrInvalidMsgs]: privacy without authentication (step 5 d); +// - [ErrUnknownEngineID] through [ErrDecryption]: the security processing +// (RFC 3414 section 3.2 steps 3 to 8), [ErrUnknownSecurityLevel] for a +// trap receiver's minimum level too, and [ErrDecryption] for a decrypted +// scoped PDU that does not parse, as a wrong privacy key yields (net-snmp +// counts it in snmpInASNParseErrs); +// - [ErrUnmatchedReply]: a reply that does not answer the request: of another +// version, naming none of its attempts, neither a Response nor a Report, +// or with another request ID, security level, user name, engine ID or +// context (RFC 3412 section 7.2 steps 10 a and 12 b). +// +// A request answered by an SNMPv3 Report fails with the error of the Report's +// counter, the same errors ([ErrUnknownPDUHandlers] too), or +// [ErrUnknownReportPDU] for a counter the library does not know. A request +// that times out or ends at the Context's deadline after discarded replies +// fails with an error that also matches the category of the one that came +// closest to answering it (see Attempts and timeouts). So a category says why +// a message was rejected, by the agent or by the library, not who rejected +// it. A local failure, such as a configuration error, a key that does not +// derive or fit its protocol, or a protocol FIPS 140-only mode refuses, +// matches none of them, nor does a transport error or a timeout without a +// discarded reply. +// +// The categories are variables only so that errors.Is can match them: the +// library returns the values they had when the package was initialized, so +// after a caller assigns another value to one, the library's errors no longer +// match it. package gosnmp diff --git a/engine.go b/engine.go index a8a9d33..d224843 100644 --- a/engine.go +++ b/engine.go @@ -630,18 +630,22 @@ func receiveReply(level SecurityLevel, got, want *SecurityParameters, keys *usmK } // The reasons a message is discarded for after the header decoded, besides -// security processing's (RFC 3412 section 7.2 steps 3, 10 and 12 b). +// security processing's (RFC 3412 section 7.2 steps 3, 10 and 12 b): the +// message does not answer the request, ErrUnmatchedReply. var ( - errOtherVersion = errors.New("the reply is of another SNMP version than the request") - errOtherMessage = errors.New("the reply's msgID names no attempt of the request") - errNotAnswer = errors.New("the reply is neither a Response nor an SNMPv3 Report") - errOtherRequestID = errors.New("the reply's request ID does not match the request") - errOtherLevel = errors.New("the reply's security level is not the request's") - errOtherUser = errors.New("the reply's user name is not the request's") - errOtherEngine = errors.New("the reply's engine ID is not the request's") - errOtherContext = errors.New("the reply's context is not the request's") + errOtherVersion = unmatched("the reply is of another SNMP version than the request") + errOtherMessage = unmatched("the reply's msgID names no attempt of the request") + errNotAnswer = unmatched("the reply is neither a Response nor an SNMPv3 Report") + errOtherRequestID = unmatched("the reply's request ID does not match the request") + errOtherLevel = unmatched("the reply's security level is not the request's") + errOtherUser = unmatched("the reply's user name is not the request's") + errOtherEngine = unmatched("the reply's engine ID is not the request's") + errOtherContext = unmatched("the reply's context is not the request's") ) +// unmatched returns the error with text, of ErrUnmatchedReply. +func unmatched(text string) error { return inCategory(ErrUnmatchedReply, errors.New(text)) } + // answers reports whether reply, a message decode read for the request, // answers it, with the error of a Report that does, or else the reason it does // not (RFC 3412 section 7.2 steps 11 and 12; net-snmp's snmpv3_verify_msg). An @@ -701,23 +705,6 @@ const ( snmpUnknownPDUHandlers = ".1.3.6.1.6.3.11.2.1.3.0" ) -// The errors of a request answered by a Report: one per Report counter the -// library knows, and ErrUnknownReportPDU for any other counter. The library's -// own rejections of a message unwrap to the counter's error too (see the -// package documentation, Errors). -var ( - ErrDecryption = errors.New("decryption error") - ErrInvalidMsgs = errors.New("invalid messages") - ErrNotInTimeWindow = errors.New("not in time window") - ErrUnknownEngineID = errors.New("unknown engine id") - ErrUnknownPDUHandlers = errors.New("unknown pdu handlers") - ErrUnknownReportPDU = errors.New("unknown report pdu") - ErrUnknownSecurityLevel = errors.New("unknown security level") - ErrUnknownSecurityModels = errors.New("unknown security models") - ErrUnknownUsername = errors.New("unknown username") - ErrWrongDigest = errors.New("wrong digest") -) - // reportKind is what the counter an SNMPv3 Report carries means to a request. type reportKind struct { // err is the request's error. diff --git a/engine_fuzz_test.go b/engine_fuzz_test.go index 1869e39..63b73ed 100644 --- a/engine_fuzz_test.go +++ b/engine_fuzz_test.go @@ -43,7 +43,17 @@ func FuzzEngineReply(f *testing.F) { } } f.Fuzz(func(t *testing.T, which uint8, reply []byte) { - x := engineReplyClient(engineReplyRequests[int(which)%len(engineReplyRequests)]) + r := engineReplyRequests[int(which)%len(engineReplyRequests)] + // The reason the first exchange would discard the reply for, or the + // error of a Report that answers it, is in exactly one category. + e := engineReplyExchange(t, r) + read, _, err := e.decode(reply, nil) + if err == nil { + _, err = e.answers(read, nil) + } + checkCategory(t, "the reply", err) + + x := engineReplyClient(r) // One read per exchange (the discovery, the request, a resend), each // followed by the attempt's timeout. exchange := []scriptedRead{{data: reply}, {err: os.ErrDeadlineExceeded}} diff --git a/engine_harness_test.go b/engine_harness_test.go index 5aeee0b..d71dc09 100644 --- a/engine_harness_test.go +++ b/engine_harness_test.go @@ -502,7 +502,8 @@ func replyTo(req []byte, edit func(*Message), vbs ...VarBind) []byte { return b } -// engineSentinels are the errors an engine result is checked against. +// engineSentinels are the errors an engine result is checked against besides +// the categories (errorCategories). var engineSentinels = []struct { name string err error @@ -517,16 +518,6 @@ var engineSentinels = []struct { {"syscall.EHOSTUNREACH", syscall.EHOSTUNREACH}, {"syscall.EACCES", syscall.EACCES}, {"errEngineWrite", errEngineWrite}, - {"ErrDecryption", ErrDecryption}, - {"ErrInvalidMsgs", ErrInvalidMsgs}, - {"ErrNotInTimeWindow", ErrNotInTimeWindow}, - {"ErrUnknownEngineID", ErrUnknownEngineID}, - {"ErrUnknownPDUHandlers", ErrUnknownPDUHandlers}, - {"ErrUnknownReportPDU", ErrUnknownReportPDU}, - {"ErrUnknownSecurityLevel", ErrUnknownSecurityLevel}, - {"ErrUnknownSecurityModels", ErrUnknownSecurityModels}, - {"ErrUnknownUsername", ErrUnknownUsername}, - {"ErrWrongDigest", ErrWrongDigest}, } // describeEngineError gives the text of err and what it is: the sentinels it @@ -535,7 +526,7 @@ var engineSentinels = []struct { func describeEngineError(err error) string { text := err.Error() var equals, is []string - for _, s := range engineSentinels { + for _, s := range slices.Concat(engineSentinels, errorCategories) { switch { case err == s.err: //nolint:errorlint // the identity is what is described equals = append(equals, s.name) diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..4cc9be4 --- /dev/null +++ b/errors.go @@ -0,0 +1,83 @@ +// Copyright 2026 Netdata Inc. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +package gosnmp + +import "errors" + +// The categories of the errors of incoming messages. Each error of decoding a +// message, of its security processing and of matching a reply to a request +// unwraps (errors.Is) to exactly one of them, and a request answered by an +// SNMPv3 Report fails with the one of the Report's counter. Each but +// ErrUnknownReportPDU and ErrUnmatchedReply is named after the counter of RFC +// 3412, RFC 3414 or RFC 3418 that counts the message (see the package +// documentation, Errors). A local failure, such as a configuration error, a +// key that does not derive or a protocol FIPS 140-only mode refuses, matches +// none of them. +// +// They are variables only so that errors.Is can match them: the library +// returns the values they had when the package was initialized, so after a +// caller assigns another value to one, the library's errors no longer match +// it. +var ( + // ErrASNParse is a message that does not parse, of any version: its + // encoding, a header field, the USM parameters, a plaintext scoped PDU, the + // PDU or a varbind, an unknown PDU type included (snmpInASNParseErrs, RFC + // 3412 section 7.2 steps 2 and 7, RFC 3414 section 3.2 step 1). + ErrASNParse = errors.New("ASN.1 parse error") + // ErrBadVersion is a message of another version than SNMPv1, SNMPv2c and + // SNMPv3 (snmpInBadVersions, RFC 3412 section 4.2.1). + ErrBadVersion = errors.New("bad version") + // ErrUnknownSecurityModels is an SNMPv3 message of another security model + // than the User-based Security Model (RFC 3412 section 7.2 step 4). + ErrUnknownSecurityModels = errors.New("unknown security models") + // ErrInvalidMsgs is an SNMPv3 message that asks for privacy without + // authentication (RFC 3412 section 7.2 step 5 d). + ErrInvalidMsgs = errors.New("invalid messages") + // ErrUnknownEngineID is an SNMPv3 message whose engine ID the receiver + // does not know (RFC 3414 section 3.2 step 3). + ErrUnknownEngineID = errors.New("unknown engine id") + // ErrUnknownUsername is an SNMPv3 message of a user the receiver does not + // know (step 4). + ErrUnknownUsername = errors.New("unknown username") + // ErrUnknownSecurityLevel is an SNMPv3 message at a level its user does + // not support (step 5), or below the level a trap receiver requires. + ErrUnknownSecurityLevel = errors.New("unknown security level") + // ErrWrongDigest is an SNMPv3 message whose digest does not check (step + // 6). + ErrWrongDigest = errors.New("wrong digest") + // ErrNotInTimeWindow is an authentic SNMPv3 message outside the time + // window (step 7). + ErrNotInTimeWindow = errors.New("not in time window") + // ErrDecryption is an SNMPv3 message that does not decrypt (step 8), + // or whose decrypted scoped PDU does not parse. + ErrDecryption = errors.New("decryption error") + // ErrUnknownPDUHandlers is a Report of snmpUnknownPDUHandlers (RFC 3412). + ErrUnknownPDUHandlers = errors.New("unknown pdu handlers") + // ErrUnknownReportPDU is a Report of a counter the library does not know, + // or of none. + ErrUnknownReportPDU = errors.New("unknown report pdu") + // ErrUnmatchedReply is a reply a request discards because it does not + // answer it: of another version, naming no attempt of the request, neither + // a Response nor a Report, or with another request ID, security level, + // user name, engine ID or context than the request's (RFC 3412 section 7.2 + // steps 10 a and 12 b). + ErrUnmatchedReply = errors.New("unmatched reply") +) + +// categorized is an error of an incoming message: it has the text of err and +// unwraps to err and to category, the error's category. +type categorized struct { + // errs holds err and category, so that Unwrap allocates nothing. + errs [2]error +} + +func (e *categorized) Error() string { return e.errs[0].Error() } + +func (e *categorized) Unwrap() []error { return e.errs[:] } + +// inCategory returns err, which unwraps to category too. +func inCategory(category, err error) error { + return &categorized{errs: [2]error{err, category}} +} diff --git a/errors_test.go b/errors_test.go new file mode 100644 index 0000000..34f6814 --- /dev/null +++ b/errors_test.go @@ -0,0 +1,87 @@ +// Copyright 2026 Netdata Inc. All rights reserved. Use of this +// source code is governed by a BSD-style license that can be found in the +// LICENSE file. + +package gosnmp + +import ( + "errors" + "testing" + + "github.com/netdata/gosnmp/internal/ber" +) + +// errorCategories are the exported categories of the errors of incoming +// messages, by name. +var errorCategories = []struct { + name string + err error +}{ + {"ErrASNParse", ErrASNParse}, + {"ErrBadVersion", ErrBadVersion}, + {"ErrUnknownSecurityModels", ErrUnknownSecurityModels}, + {"ErrInvalidMsgs", ErrInvalidMsgs}, + {"ErrUnknownEngineID", ErrUnknownEngineID}, + {"ErrUnknownUsername", ErrUnknownUsername}, + {"ErrUnknownSecurityLevel", ErrUnknownSecurityLevel}, + {"ErrWrongDigest", ErrWrongDigest}, + {"ErrNotInTimeWindow", ErrNotInTimeWindow}, + {"ErrDecryption", ErrDecryption}, + {"ErrUnknownPDUHandlers", ErrUnknownPDUHandlers}, + {"ErrUnknownReportPDU", ErrUnknownReportPDU}, + {"ErrUnmatchedReply", ErrUnmatchedReply}, +} + +// decodeDetails are the unexported errors a decode error can wrap besides its +// category, which the goldens print as details of its cause. +var decodeDetails = []struct { + name string + err error +}{ + {"ber.ErrBase128IntegerTooLarge", ber.ErrBase128IntegerTooLarge}, + {"ber.ErrBase128IntegerTruncated", ber.ErrBase128IntegerTruncated}, + {"ber.ErrFloatBufferTooShort", ber.ErrFloatBufferTooShort}, + {"ber.ErrFloatTooLarge", ber.ErrFloatTooLarge}, + {"ber.ErrIntegerTooLarge", ber.ErrIntegerTooLarge}, + {"ber.ErrInvalidOidLength", ber.ErrInvalidOidLength}, + {"ber.ErrInvalidPacketLength", ber.ErrInvalidPacketLength}, + {"ber.ErrZeroLenInteger", ber.ErrZeroLenInteger}, + {"errNoValue", errNoValue}, +} + +// categoriesOf returns the names of the categories err matches. +func categoriesOf(err error) []string { + var names []string + for _, c := range errorCategories { + if errors.Is(err, c.err) { + names = append(names, c.name) + } + } + return names +} + +// checkCategory fails t unless err, an error of an incoming message or nil, +// matches exactly one category. The fuzz targets that call it decode with +// valid users outside FIPS 140-only mode (their seeds derive MD5 keys), so no +// local failure is expected. +func checkCategory(t *testing.T, what string, err error) { + t.Helper() + if names := categoriesOf(err); err != nil && len(names) != 1 { + t.Errorf("%s: %q matches the categories %v, not exactly one", what, err, names) + } +} + +// TestUnmatchedReplyReasons checks that every reason a request discards a +// decoded reply for is ErrUnmatchedReply, the one of a msgID that names no +// attempt included, which never reaches a caller (rankOf records no message +// that names no attempt). +func TestUnmatchedReplyReasons(t *testing.T) { + for _, reason := range []error{ + errOtherVersion, errOtherMessage, errNotAnswer, errOtherRequestID, + errOtherLevel, errOtherUser, errOtherEngine, errOtherContext, + } { + if got := categoriesOf(reason); len(got) != 1 || got[0] != "ErrUnmatchedReply" { + t.Errorf("%q: categories %v, want [ErrUnmatchedReply]", reason, got) + } + } +} diff --git a/helper.go b/helper.go index 0ab7b04..de31136 100644 --- a/helper.go +++ b/helper.go @@ -8,31 +8,6 @@ package gosnmp -import ( - "errors" - - "github.com/netdata/gosnmp/internal/ber" -) - -// Errors that some decode errors wrap (match them with errors.Is): those of -// the BER decoder, ErrInvalidOidLength for an OBJECT IDENTIFIER of more than -// 128 arcs, ErrInvalidPacketLength for a message shorter than two octets and -// any length that breaks its rules or runs past its input (bytes after a TLV -// inside its container are another error), and ErrZeroByteBuffer for a -// varbind without a value. Other decode, configuration and authentication -// errors are not exported. -var ( - ErrBase128IntegerTooLarge = ber.ErrBase128IntegerTooLarge - ErrBase128IntegerTruncated = ber.ErrBase128IntegerTruncated - ErrFloatBufferTooShort = ber.ErrFloatBufferTooShort - ErrFloatTooLarge = ber.ErrFloatTooLarge - ErrIntegerTooLarge = ber.ErrIntegerTooLarge - ErrInvalidOidLength = ber.ErrInvalidOidLength - ErrInvalidPacketLength = ber.ErrInvalidPacketLength - ErrZeroByteBuffer = errors.New("zero byte buffer") - ErrZeroLenInteger = ber.ErrZeroLenInteger -) - // BitStringValue is an ASN.1 BIT STRING: the bits packed into bytes, the // first bit in the high bit of the first byte, and the number of valid bits; // the padding bits are zero. The encoder and decoder do not use it: BitString diff --git a/internal/ber/ber.go b/internal/ber/ber.go index ddac9a0..af70f60 100644 --- a/internal/ber/ber.go +++ b/internal/ber/ber.go @@ -15,8 +15,8 @@ import ( "strconv" ) -// Errors returned by the decoders. The root package exports them under the -// same names. +// Errors returned by the decoders. The root package does not export them: its +// decode errors wrap them besides their category. var ( ErrBase128IntegerTooLarge = errors.New("base 128 integer too large") ErrBase128IntegerTruncated = errors.New("base 128 integer truncated") diff --git a/pdu.go b/pdu.go index 2694e70..6519388 100644 --- a/pdu.go +++ b/pdu.go @@ -173,43 +173,55 @@ func readWhole(b []byte) ([]byte, error) { // -- Messages and PDUs -------------------------------------------------------- // errEmptyPacket is the error of a message shorter than a TLV header. -var errEmptyPacket = fmt.Errorf("%w: cannot unmarshal empty packet", ErrInvalidPacketLength) +var errEmptyPacket = fmt.Errorf("%w: cannot unmarshal empty packet", ber.ErrInvalidPacketLength) // readVersion reads the message SEQUENCE, which must span the whole packet, // and its version field, an INTEGER of SNMPv1 (0), SNMPv2c (1) or SNMPv3 (3). -// It returns the version and the offset of the field after it. +// It returns the version and the offset of the field after it. Another +// version is ErrBadVersion (RFC 3412 section 4.2.1), a message that does not +// parse that far ErrASNParse. func readVersion(packet []byte) (Version, int, error) { + r, version, err := readVersionField(packet) + switch { + case err != nil: + return 0, 0, inCategory(ErrASNParse, err) + case version != int32(Version1) && version != int32(Version2c) && version != int32(Version3): + return 0, 0, inCategory(ErrBadVersion, fmt.Errorf("error parsing SNMP packet version: %d is not 0, 1 or 3", version)) + case r.Len() == 0: + return 0, 0, inCategory(ErrASNParse, errors.New("error parsing SNMP packet: nothing after the version")) + } + return Version(version), len(packet) - r.Len(), nil //nolint:gosec // 0, 1 or 3 +} + +// readVersionField reads the message SEQUENCE, which must span the whole +// packet, and its first field, an INTEGER (readInt32); it returns the reader +// of the fields after it. +func readVersionField(packet []byte) (ber.Reader, int32, error) { if len(packet) < 2 { - return 0, 0, errEmptyPacket + return ber.Reader{}, 0, errEmptyPacket } if packet[0] != ber.Sequence { - return 0, 0, errors.New("invalid packet header") + return ber.Reader{}, 0, errors.New("invalid packet header") } msg, err := readWhole(packet) if err != nil { - return 0, 0, fmt.Errorf("error verifying packet sanity: %w", err) + return ber.Reader{}, 0, fmt.Errorf("error verifying packet sanity: %w", err) } r := ber.NewReader(msg) version, err := readInt32(&r) if err != nil { - return 0, 0, fmt.Errorf("error parsing SNMP packet version: %w", err) - } - if version != int32(Version1) && version != int32(Version2c) && version != int32(Version3) { - return 0, 0, fmt.Errorf("error parsing SNMP packet version: %d is not 0, 1 or 3", version) + return ber.Reader{}, 0, fmt.Errorf("error parsing SNMP packet version: %w", err) } - if r.Len() == 0 { - return 0, 0, errors.New("error parsing SNMP packet: nothing after the version") - } - return Version(version), len(packet) - r.Len(), nil //nolint:gosec // 0, 1 or 3 + return r, version, nil } // unmarshalHeader reads the message header into response: the version and, // for SNMPv1 and SNMPv2c, the community, or for SNMPv3 the header (parseV3), // whose USM fields it returns for security processing, also those that // decoded before an error. It returns the offset of the PDU, or of the scoped -// PDU. An SNMPv3 header error unwraps to ErrUnknownSecurityModels or -// ErrInvalidMsgs (v3ParseError). +// PDU. Its errors have their categories: the version's (readVersion), an +// SNMPv3 header's (v3ParseError), ErrASNParse for the community. func unmarshalHeader(packet []byte, response *Message) (int, v3Wire, error) { version, cursor, err := readVersion(packet) // Known bug: a packet that is not too short to read presets the variables @@ -233,15 +245,25 @@ func unmarshalHeader(packet []byte, response *Message) (int, v3Wire, error) { r := ber.NewReader(packet[cursor:]) community, err := readOctets(&r) if err != nil { - return 0, v3Wire{}, fmt.Errorf("error parsing community string: %w", err) + return 0, v3Wire{}, inCategory(ErrASNParse, fmt.Errorf("error parsing community string: %w", err)) } response.Community = string(community) return len(packet) - r.Len(), v3Wire{}, nil } // unmarshalPayload reads the PDU at packet[cursor:], which must span the rest -// of the packet. +// of the packet (readPayload); its errors are ErrASNParse (RFC 3412 section +// 7.2 step 7, an unknown PDU type included, as net-snmp v5.9.4 treats it). func unmarshalPayload(packet []byte, cursor int, response *Message) error { + if err := readPayload(packet, cursor, response); err != nil { + return inCategory(ErrASNParse, err) + } + return nil +} + +// readPayload reads the PDU at packet[cursor:], which must span the rest of +// the packet. +func readPayload(packet []byte, cursor int, response *Message) error { if len(packet) == 0 { return errors.New("cannot unmarshal nil or empty payload packet") } @@ -397,6 +419,9 @@ func unmarshalVBL(packet []byte, response *Message) error { return nil } +// errNoValue is the error of a varbind without a value. +var errNoValue = errors.New("error decoding value: zero byte buffer") + // readVarbind reads the next varbind: a SEQUENCE of the name (readName) and // the value TLV, which must span the rest of it. func readVarbind(r *ber.Reader) (VarBind, error) { @@ -416,7 +441,7 @@ func readVarbind(r *ber.Reader) (VarBind, error) { value := fields.Rest() if len(value) == 0 { - return VarBind{}, fmt.Errorf("error decoding value: %w", ErrZeroByteBuffer) + return VarBind{}, errNoValue } length, header, err := ber.Length(value) if err != nil { diff --git a/testdata/codec/decode.golden b/testdata/codec/decode.golden index 4fec375..a2fca27 100644 --- a/testdata/codec/decode.golden +++ b/testdata/codec/decode.golden @@ -150,34 +150,34 @@ vb[0]: .1.3.6.1.6.3.15.1.1.4.0 0x41 (Counter32) uint 21 reencode: identical == fixture/panicUnmarshalHeader -decode: error +decode: error (ErrBadVersion) == fixture/panicUnmarshalV3Header -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fixture/panicUnmarshalUserSecurityModelPacketLen -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fixture/panicUnmarshalV3HeaderFlagLen -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fixture/panicUnmarshalParseFloat32 -decode: error +decode: error (ErrASNParse) == fixture/panicUnmarshalParseFloat64 -decode: error +decode: error (ErrASNParse) == fixture/panicUnmarshalParseRawFieldTimeTicks -decode: error +decode: error (ErrASNParse) == fixture/panicUnmarshalDecryptPacketIndex -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fixture/panicUnmarshalDecryptNoPriv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fixture/panicUnmarshalV3Overflow -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fixture/kyoceraRequestBytes decode: ok @@ -265,13 +265,13 @@ vb[4]: .1.3.6.1.2.1.1.2 0x06 (ObjectIdentifier) string ".1.3.6.1.4.1.2.3.4.5" reencode: identical == fixture/invalidSNMPResponse/0 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fixture/invalidSNMPResponse/1 -decode: error +decode: error (ErrASNParse) == fixture/invalidSNMPResponse/2 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fixture/v3AuthNoPrivSHAResponse decode: ok @@ -574,22 +574,22 @@ reencode: 308202c9020103300f02021092020300ffe304010302010304643062041180001f8804 unmarshal-trap: ok == crafted/msg/empty -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/one-byte -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/empty-sequence -decode: error +decode: error (ErrASNParse) == crafted/msg/not-sequence -decode: error +decode: error (ErrASNParse) == crafted/msg/trailing-byte -decode: error +decode: error (ErrASNParse) == crafted/msg/truncated -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/long-form-length decode: ok @@ -610,19 +610,19 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: 302702010104067075626c6963a21a020101020100020100300f300d06082b06010201010500020105 == crafted/msg/indefinite-length -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/length-9-octets -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/length-4-octets-max -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/length-missing -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/length-9-octets-inside -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/msg/length-8-octets-inside decode: ok @@ -634,7 +634,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x04 (OctetString) []uint8 len=5 68656c6c6f reencode: 302b02010104067075626c6963a21e0201010201000201003013301106082b06010201010500040568656c6c6f == crafted/msg/length-8-octets-wrapping -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/version/0 decode: ok @@ -646,16 +646,16 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/version/2 -decode: error +decode: error (ErrBadVersion) == crafted/version/3-with-community -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/version/256 -decode: error +decode: error (ErrBadVersion) == crafted/version/-1 -decode: error +decode: error (ErrBadVersion) == crafted/version/2^32+1 decode: ok @@ -667,13 +667,13 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: 302602010104067075626c6963a219020101020100020100300e300c06082b060102010105000500 == crafted/version/octet-string -decode: error +decode: error (ErrASNParse) == crafted/version/empty-integer -decode: error (ErrZeroLenInteger) +decode: error (ErrASNParse) detail (ber.ErrZeroLenInteger) == crafted/version/only -decode: error +decode: error (ErrASNParse) == crafted/community/empty decode: ok @@ -685,7 +685,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/community/integer -decode: error +decode: error (ErrASNParse) == crafted/community/long-200 decode: ok @@ -706,13 +706,13 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/community/oid -decode: error +decode: error (ErrASNParse) == crafted/community/ipaddress -decode: error +decode: error (ErrASNParse) == crafted/community/missing-pdu -decode: error +decode: error (ErrASNParse) == crafted/pdu/get-request decode: ok @@ -769,7 +769,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/pdu/getbulk-non-repeaters-negative -decode: error +decode: error (ErrASNParse) == crafted/pdu/getbulk-max-repetitions-2147483647 decode: ok @@ -781,10 +781,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/pdu/getbulk-max-repetitions-negative -decode: error +decode: error (ErrASNParse) == crafted/pdu/getbulk-max-repetitions-2^31 -decode: error +decode: error (ErrASNParse) == crafted/pdu/inform-request decode: ok @@ -815,13 +815,13 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/pdu/unknown-tag -decode: error +decode: error (ErrASNParse) == crafted/pdu/sequence-tag -decode: error +decode: error (ErrASNParse) == crafted/pdu/length-short -decode: error +decode: error (ErrASNParse) == crafted/pdu/request-id-negative decode: ok @@ -851,13 +851,13 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: 302602010104067075626c6963a219020100020100020100300e300c06082b060102010105000500 == crafted/pdu/request-id-9-octets -decode: error (ErrIntegerTooLarge) +decode: error (ErrASNParse) detail (ber.ErrIntegerTooLarge) == crafted/pdu/request-id-octet-string -decode: error +decode: error (ErrASNParse) == crafted/pdu/request-id-empty -decode: error (ErrZeroLenInteger) +decode: error (ErrASNParse) detail (ber.ErrZeroLenInteger) == crafted/pdu/error-status-5 decode: ok @@ -878,10 +878,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/pdu/error-status-256 -decode: error +decode: error (ErrASNParse) == crafted/pdu/error-status-negative -decode: error +decode: error (ErrASNParse) == crafted/pdu/error-index-300 decode: ok @@ -902,10 +902,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/pdu/error-index-negative -decode: error +decode: error (ErrASNParse) == crafted/pdu/error-index-octet-string -decode: error +decode: error (ErrASNParse) == crafted/vbl/empty decode: ok @@ -916,16 +916,16 @@ varbinds: 0 reencode: identical == crafted/vbl/missing -decode: error +decode: error (ErrASNParse) == crafted/vbl/not-sequence -decode: error +decode: error (ErrASNParse) == crafted/vbl/length-exceeds -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/vbl/trailing-garbage -decode: error +decode: error (ErrASNParse) == crafted/vbl/100-varbinds decode: ok @@ -1036,10 +1036,10 @@ vb[99]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: identical == crafted/vb/not-sequence -decode: error +decode: error (ErrASNParse) == crafted/vb/empty-sequence -decode: error +decode: error (ErrASNParse) == crafted/vb/name-octet-string decode: ok @@ -1060,22 +1060,22 @@ vb[0]: 192.0.2.1 0x05 (Null) reencode: error == crafted/vb/name-ipaddress-empty -decode: error +decode: error (ErrASNParse) == crafted/vb/name-integer -decode: error +decode: error (ErrASNParse) == crafted/vb/missing-value -decode: error (ErrZeroByteBuffer) +decode: error (ErrASNParse) detail (errNoValue) == crafted/vb/two-values -decode: error +decode: error (ErrASNParse) == crafted/vb/length-exceeds-vbl -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/vb/value-tag-only -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/oid/empty decode: ok @@ -1114,10 +1114,10 @@ vb[0]: .1.3.4294967295 0x05 (Null) reencode: identical == crafted/oid/arc-2^32 -decode: error (ErrBase128IntegerTooLarge) +decode: error (ErrASNParse) detail (ber.ErrBase128IntegerTooLarge) == crafted/oid/truncated-arc -decode: error (ErrBase128IntegerTruncated) +decode: error (ErrASNParse) detail (ber.ErrBase128IntegerTruncated) == crafted/oid/non-minimal-arc decode: ok @@ -1129,7 +1129,7 @@ vb[0]: .1.3.6 0x05 (Null) reencode: 302002010104067075626c6963a2130201010201000201003008300606022b060500 == crafted/oid/130-arcs -decode: error (ErrInvalidOidLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidOidLength) == crafted/oid/128-arcs decode: ok @@ -1141,10 +1141,10 @@ vb[0]: .1.3.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1. reencode: identical == crafted/oid/129-arcs -decode: error (ErrInvalidOidLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidOidLength) == crafted/value/integer/empty -decode: error (ErrZeroLenInteger) +decode: error (ErrASNParse) detail (ber.ErrZeroLenInteger) == crafted/value/integer/0 decode: ok @@ -1237,10 +1237,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 0 reencode: 302702010104067075626c6963a21a020101020100020100300f300d06082b06010201010500020100 == crafted/value/integer/9-octets -decode: error (ErrIntegerTooLarge) +decode: error (ErrASNParse) detail (ber.ErrIntegerTooLarge) == crafted/value/integer/over-declared-by-1 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/counter32/empty decode: ok @@ -1486,16 +1486,16 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x04 (OctetString) []uint8 len=5 68656c6c6f reencode: 302b02010104067075626c6963a21e0201010201000201003013301106082b06010201010500040568656c6c6f == crafted/value/octet-string/over-declared-by-2 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/octet-string/under-declared -decode: error +decode: error (ErrASNParse) == crafted/value/octet-string/length-9-octets -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/octet-string/length-missing -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/null/with-content decode: ok @@ -1534,10 +1534,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x06 (ObjectIdentifier) string ".1.3.1.1.1.1.1.1.1.1.1 reencode: identical == crafted/value/oid/129-arcs -decode: error (ErrInvalidOidLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidOidLength) == crafted/value/oid/truncated-arc -decode: error (ErrBase128IntegerTruncated) +decode: error (ErrASNParse) detail (ber.ErrBase128IntegerTruncated) == crafted/value/ip-address/4-octets decode: ok @@ -1558,10 +1558,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x40 (IPAddress) reencode: error == crafted/value/ip-address/3-octets -decode: error +decode: error (ErrASNParse) == crafted/value/ip-address/5-octets -decode: error +decode: error (ErrASNParse) == crafted/value/ip-address/16-octets decode: ok @@ -1609,10 +1609,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x78 (OpaqueFloat) float32 NaN (0x7fc00001) reencode: identical == crafted/value/opaque/float-truncated -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/opaque/float-long -decode: error (ErrFloatTooLarge) +decode: error (ErrASNParse) detail (ber.ErrFloatTooLarge) == crafted/value/opaque/double decode: ok @@ -1624,7 +1624,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x79 (OpaqueDouble) float64 10 (0x4024000000000000) reencode: identical == crafted/value/opaque/double-truncated -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/opaque/inner-counter64 decode: ok @@ -1780,7 +1780,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x00 (EndOfContents) reencode: error == crafted/value/high-tag-number -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/value/constructed-context-tag decode: ok @@ -1820,7 +1820,7 @@ varbinds: 0 reencode: identical == crafted/trap-v1/missing-vbl -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/agent-address-empty decode: ok @@ -1833,7 +1833,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: error == crafted/trap-v1/agent-address-16-octets -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/agent-address-octet-string decode: ok @@ -1846,19 +1846,19 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: 303702010004067075626c6963a42a06082b06010401819f144004c000020102010602010143020100300e300c06082b060102010105000500 == crafted/trap-v1/agent-address-octet-string-5 -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/agent-address-octet-string-empty -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/agent-address-oid -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/enterprise-octet-string -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/generic-octet-string -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/specific-negative decode: ok @@ -1891,7 +1891,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: 303602010004067075626c6963a42906082b06010401819f144004c0000201020106020101430100300e300c06082b060102010105000500 == crafted/trap-v1/timestamp-integer -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/timestamp-counter32 decode: ok @@ -1924,10 +1924,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x05 (Null) reencode: 303702010004067075626c6963a42a06082b06010401819f144004c000020102010602010143020100300e300c06082b060102010105000500 == crafted/trap-v1/timestamp-counter64 -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/timestamp-empty -decode: error +decode: error (ErrASNParse) == crafted/trap-v1/in-v2c-message decode: ok @@ -1951,13 +1951,13 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: identical == crafted/v3/flags-empty -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/flags-two-octets -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/flags-two-octets-reportable -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/flags-reserved-bits decode: ok @@ -1971,19 +1971,19 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: 3077020103300e02012a020300ffe3040100020103042c302a041180001f8804636f6465632d656e67696e65020107020204d2040a636f6465632d75736572040004003034041180001f8804636f6465632d656e67696e650403637478a21a020101020100020100300f300d06082b06010201010500020105 == crafted/v3/flags-integer -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/security-model-2 decode: error (ErrUnknownSecurityModels) == crafted/v3/msg-global-data-empty -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/msg-id-negative -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/msg-id-octet-string -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/msg-id-2147483647 decode: ok @@ -1997,10 +1997,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: identical == crafted/v3/msg-id-2^31 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/max-size-483 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/max-size-484 decode: ok @@ -2025,19 +2025,19 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: identical == crafted/v3/max-size-2^31 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/max-size-octet-string -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-not-sequence -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-empty -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-boots-octet-string -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-engine-id-200 decode: error (ErrInvalidMsgs) @@ -2057,7 +2057,7 @@ reencode: identical decode: error (ErrInvalidMsgs) == crafted/v3/usm-user-name-200 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-user-name-32 decode: ok @@ -2071,7 +2071,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: identical == crafted/v3/usm-user-name-33 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-empty-engine-id decode: ok @@ -2085,13 +2085,13 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: identical == crafted/v3/scoped-pdu-octet-string-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/scoped-pdu-length-truncated -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/v3/scoped-pdu-over-declared -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/v3/scoped-pdu-under-declared decode: ok @@ -2105,30 +2105,30 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: 3077020103300e02012a020300ffe3040100020103042c302a041180001f8804636f6465632d656e67696e65020107020204d2040a636f6465632d75736572040004003034041180001f8804636f6465632d656e67696e650403637478a21a020101020100020100300f300d06082b06010201010500020105 == crafted/v3/scoped-pdu-sequence-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == crafted/v3/scoped-pdu-missing -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/context-engine-id-integer -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/context-engine-id-oid -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/context-name-ipaddress -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/context-name-missing -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/auth-flag-zero-decoder decode: error (ErrUnknownSecurityLevel) == crafted/v3/auth-params-integer -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == crafted/v3/auth-no-priv-sha/wrong-auth-pass decode: ok @@ -2147,8 +2147,8 @@ unmarshal-trap: error (ErrWrongDigest) decode: error (ErrUnknownSecurityLevel) == crafted/v3/auth-priv-sha-aes/wrong-priv-pass -decode: error (ErrInvalidPacketLength, ErrDecryption) -unmarshal-trap: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) +unmarshal-trap: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) == crafted/v3/auth-priv-sha-aes/no-priv-decoder decode: error (ErrUnknownSecurityLevel) @@ -2201,26 +2201,26 @@ unmarshal-trap: error (ErrDecryption) decode: error (ErrUnknownSecurityModels) == crafted/v3/parse/security-model-minus-253 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/security-model-0 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/security-model-octet-string -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/security-model-null -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/security-model-absent -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/security-model-2-privacy-only decode: error (ErrUnknownSecurityModels) == crafted/v3/parse/security-model-octet-string-auth -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == crafted/v3/parse/global-data-under-declared decode: ok @@ -2234,10 +2234,10 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: 3077020103300e02012a020300ffe3040100020103042c302a041180001f8804636f6465632d656e67696e65020107020204d2040a636f6465632d75736572040004003034041180001f8804636f6465632d656e67696e650403637478a21a020101020100020100300f300d06082b06010201010500020105 == crafted/v3/parse/global-data-over-declared -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/v3/parse/global-data-extra-field -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/security-parameters-cover-scoped-pdu decode: ok @@ -2251,19 +2251,19 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: 3077020103300e02012a020300ffe3040100020103042c302a041180001f8804636f6465632d656e67696e65020107020204d2040a636f6465632d75736572040004003034041180001f8804636f6465632d656e67696e650403637478a21a020101020100020100300f300d06082b06010201010500020105 == crafted/v3/parse/security-parameters-over-declared -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/v3/parse/security-parameters-trailing-data -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/usm-extra-field -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/usm-under-declared -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/parse/usm-over-declared -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/v3/parse/auth-params-long-form-length decode: ok @@ -2338,12 +2338,12 @@ reencode: identical unmarshal-trap: ok == crafted/v3/parse/encrypted-scoped-pdu-over-declared -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) +unmarshal-trap: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == crafted/v3/parse/encrypted-scoped-pdu-under-declared -decode: error (ErrInvalidPacketLength, ErrDecryption) -unmarshal-trap: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) +unmarshal-trap: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) == crafted/v3/parse/encrypted-scoped-pdu-trailing-octets decode: ok @@ -2366,403 +2366,403 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrDecryption) == fuzz/00ed9943f389d00f -decode: error +decode: error (ErrASNParse) == fuzz/03745052a2ee3f0e -decode: error +decode: error (ErrASNParse) == fuzz/0417cb36c0c20e24 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/0583a15304f27091 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/061e968f79a05516 -decode: error +decode: error (ErrASNParse) == fuzz/072ba75f7199c92f -decode: error +decode: error (ErrASNParse) == fuzz/07f6e020f769b72f -decode: error +decode: error (ErrASNParse) == fuzz/0a7dc0f965e608eb -decode: error +decode: error (ErrASNParse) == fuzz/0b4f5e959fc8c53b -decode: error +decode: error (ErrASNParse) == fuzz/0b9cde681aa5791f -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/0c014b73220900b7 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/0cbd3e6bb134ec4f -decode: error +decode: error (ErrASNParse) == fuzz/0db9658fefa89278 -decode: error +decode: error (ErrASNParse) == fuzz/0e803e5143265c17 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fuzz/0fa02af91d6937bb -decode: error +decode: error (ErrASNParse) == fuzz/10f65b2bf109c8bb -decode: error +decode: error (ErrASNParse) == fuzz/11feb782f38ce3bb -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/1424b8af6b20ae15 -decode: error +decode: error (ErrASNParse) == fuzz/19503ef8181a5aa0 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/198c4ca7652d127e -decode: error +decode: error (ErrASNParse) == fuzz/1abe6ef20e16164b -decode: error +decode: error (ErrASNParse) == fuzz/1ba486e14820bf7b -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/1bd072baf6e4e375 -decode: error (ErrIntegerTooLarge) +decode: error (ErrASNParse) detail (ber.ErrIntegerTooLarge) == fuzz/1cd4abb8d462958a -decode: error +decode: error (ErrASNParse) == fuzz/1e2f091a9b1beb4d -decode: error +decode: error (ErrASNParse) == fuzz/20e8ec6eae1353e3 -decode: error +decode: error (ErrASNParse) == fuzz/222200d30d7f9657 -decode: error +decode: error (ErrASNParse) == fuzz/25996f1275b0c9f9 -decode: error +decode: error (ErrASNParse) == fuzz/2cc593de11f61fd4 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/2ffa8ad3122bd6af -decode: error +decode: error (ErrASNParse) == fuzz/3078966c99ef0789 -decode: error +decode: error (ErrASNParse) == fuzz/30c9a6e671040a0f -decode: error +decode: error (ErrASNParse) == fuzz/31b6aa7460e25b7c -decode: error +decode: error (ErrASNParse) == fuzz/33ccaa9a2615716b -decode: error +decode: error (ErrASNParse) == fuzz/3441bfeb3cdf6739 -decode: error +decode: error (ErrASNParse) == fuzz/3527ca73dd43d05e -decode: error +decode: error (ErrASNParse) == fuzz/36867c9ed32206dc -decode: error +decode: error (ErrASNParse) == fuzz/3b7ca691b21f2e70 -decode: error +decode: error (ErrASNParse) == fuzz/413967ed097f48a9 -decode: error +decode: error (ErrASNParse) == fuzz/427ea9762072c10d -decode: error +decode: error (ErrASNParse) == fuzz/44221f656ab69e55 -decode: error +decode: error (ErrASNParse) == fuzz/49346266cafe87ac -decode: error +decode: error (ErrASNParse) == fuzz/4fabd7bff7d520eb -decode: error +decode: error (ErrASNParse) == fuzz/5049b62e5275e059 -decode: error +decode: error (ErrASNParse) == fuzz/51922e9be1b95340 -decode: error +decode: error (ErrASNParse) == fuzz/567b548b10cefa8a -decode: error +decode: error (ErrASNParse) == fuzz/5acabb000cc79cdb -decode: error +decode: error (ErrASNParse) == fuzz/5c1bd600e3907764 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/5ff8c360e1021173 -decode: error +decode: error (ErrASNParse) == fuzz/613806938fef7c58 -decode: error +decode: error (ErrASNParse) == fuzz/6156269706e344ef -decode: error +decode: error (ErrASNParse) == fuzz/642deb901e42fb17 -decode: error +decode: error (ErrASNParse) == fuzz/67218956c921ba7e -decode: error +decode: error (ErrASNParse) == fuzz/686c2ee7d2be6ff8 -decode: error +decode: error (ErrASNParse) == fuzz/6a8ace6305e92d7f -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/6b16f3feb63282cf -decode: error +decode: error (ErrASNParse) == fuzz/6d9c59dcdec089bb -decode: error +decode: error (ErrASNParse) == fuzz/6e935627ba90777f -decode: error +decode: error (ErrASNParse) == fuzz/71e9f05f8222cc55 -decode: error +decode: error (ErrASNParse) == fuzz/734912029ecb8f32 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fuzz/740667e8d2c30c33 -decode: error +decode: error (ErrASNParse) == fuzz/7427c7f27fd1cb99 -decode: error +decode: error (ErrASNParse) == fuzz/74c1c36caaca68a9 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/77dd102027aa77d0 -decode: error +decode: error (ErrASNParse) == fuzz/7858b68512791364 -decode: error +decode: error (ErrASNParse) == fuzz/7a1f98448c635bff -decode: error +decode: error (ErrASNParse) == fuzz/7b3a83e9ea4bb032 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/7c2cb81727f29d31 -decode: error +decode: error (ErrASNParse) == fuzz/7c836471fa973a9e -decode: error +decode: error (ErrASNParse) == fuzz/804b9aaf66a0ebb6 -decode: error +decode: error (ErrASNParse) == fuzz/83ee5e21b474a4bf -decode: error +decode: error (ErrASNParse) == fuzz/8735cd6a08877af1 -decode: error +decode: error (ErrASNParse) == fuzz/899371e3dc62a577 -decode: error +decode: error (ErrASNParse) == fuzz/8a5017647f61a699 -decode: error +decode: error (ErrASNParse) == fuzz/92d824be3ae76873 -decode: error +decode: error (ErrASNParse) == fuzz/949479b7515f22c0 -decode: error +decode: error (ErrASNParse) == fuzz/96012444e6c18b27 -decode: error +decode: error (ErrASNParse) == fuzz/96957614a6c2508b -decode: error +decode: error (ErrBadVersion) == fuzz/9982129b1fb05581 -decode: error +decode: error (ErrASNParse) == fuzz/9bb4a97bc78bb20b -decode: error (ErrInvalidPacketLength, ErrInvalidMsgs) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fuzz/9d76ee024c1df6b6 -decode: error +decode: error (ErrASNParse) == fuzz/9f572a36b0cdbe06 -decode: error +decode: error (ErrASNParse) == fuzz/a3d9c504b4c4b8cb -decode: error +decode: error (ErrASNParse) == fuzz/abd4da6d69742839 -decode: error +decode: error (ErrASNParse) == fuzz/b12e039ada7c3a9b -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/b190a2aa2687b324 -decode: error +decode: error (ErrASNParse) == fuzz/b1e09870cecc7600 -decode: error +decode: error (ErrASNParse) == fuzz/b9042e8cb9999519 -decode: error +decode: error (ErrASNParse) == fuzz/b9b8815525806b6a -decode: error +decode: error (ErrASNParse) == fuzz/bb4a95117f790a42 -decode: error +decode: error (ErrASNParse) == fuzz/bc23968f072b9a53 -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fuzz/be260a8bcbe076b0 -decode: error +decode: error (ErrASNParse) == fuzz/c2311e291823c0b0 -decode: error +decode: error (ErrASNParse) == fuzz/c2a0f7c0bc32f982 -decode: error +decode: error (ErrASNParse) == fuzz/c4dde55d57cda347 -decode: error +decode: error (ErrASNParse) == fuzz/c5933c6ee9480811 -decode: error +decode: error (ErrASNParse) == fuzz/c663a61a71f6f3a8 -decode: error +decode: error (ErrASNParse) == fuzz/c8682cb93acd4a49 -decode: error +decode: error (ErrASNParse) == fuzz/c8a4e5582e13c46d -decode: error +decode: error (ErrASNParse) == fuzz/c9bf29279c46af99 -decode: error +decode: error (ErrASNParse) == fuzz/cca8e26a87e73338 -decode: error +decode: error (ErrASNParse) == fuzz/ce2e50e8c1bce675 -decode: error +decode: error (ErrASNParse) == fuzz/d1c387aa45f0b6b5 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/d4998e6969fd8310 -decode: error +decode: error (ErrASNParse) == fuzz/d6c2c19fc7b77020 -decode: error +decode: error (ErrASNParse) == fuzz/d6cef9b37c94873f -decode: error +decode: error (ErrASNParse) == fuzz/db0b481b9ebdbb14 -decode: error +decode: error (ErrASNParse) == fuzz/dccdd5ba82bdf769 -decode: error +decode: error (ErrASNParse) == fuzz/dfb8544a79fd7237 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/e01df02a9aae7240 -decode: error +decode: error (ErrASNParse) == fuzz/e0b990e88a9e73be -decode: error +decode: error (ErrASNParse) == fuzz/e348df25e19f4c40 -decode: error +decode: error (ErrASNParse) == fuzz/e49c227bbc57bacf -decode: error +decode: error (ErrASNParse) == fuzz/e5c50f139ac69c05 -decode: error +decode: error (ErrASNParse) == fuzz/e5ee68adedc54cc8 -decode: error +decode: error (ErrASNParse) == fuzz/e6319eea943afd0d -decode: error (ErrInvalidPacketLength) +decode: error (ErrASNParse) detail (ber.ErrInvalidPacketLength) == fuzz/e66fb6050372cdfc -decode: error +decode: error (ErrASNParse) == fuzz/e6c6b0410c0929ed -decode: error +decode: error (ErrASNParse) == fuzz/e78f163b50140c72 -decode: error +decode: error (ErrASNParse) == fuzz/e7e0df1e75e56032 -decode: error +decode: error (ErrASNParse) == fuzz/e880876e09f4050a -decode: error +decode: error (ErrASNParse) == fuzz/e93330720c549da1 -decode: error +decode: error (ErrASNParse) == fuzz/e9ed2df9d5a93d22 -decode: error +decode: error (ErrASNParse) == fuzz/eace56b9af75cc96 -decode: error +decode: error (ErrASNParse) == fuzz/ed75dd82527cc7b2 -decode: error +decode: error (ErrASNParse) == fuzz/efc3207a2fb6e67a -decode: error +decode: error (ErrASNParse) == fuzz/f0d36cde3485322d -decode: error +decode: error (ErrASNParse) == fuzz/f17bd2c5dc7d0d1d -decode: error +decode: error (ErrASNParse) == fuzz/f38a2ab2f4e09a9b -decode: error +decode: error (ErrASNParse) == fuzz/f5df35aba98e7bbc -decode: error +decode: error (ErrASNParse) == fuzz/fa67a7e82489f94f -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == fuzz/fa6f71ca8c4ea7f3 -decode: error +decode: error (ErrASNParse) == fuzz/fae429517e0c46d8 -decode: error +decode: error (ErrASNParse) == fuzz/fc0adf3072ad6165 -decode: error +decode: error (ErrASNParse) diff --git a/testdata/engine/requests.golden b/testdata/engine/requests.golden index f3e6a57..dd51654 100644 --- a/testdata/engine/requests.golden +++ b/testdata/engine/requests.golden @@ -178,7 +178,7 @@ 2s read from 127.0.0.2:161: 4 octets, not decodable (error verifying packet sanity: invalid packet length: TLV length exceeds the remaining input) 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: error verifying packet sanity: invalid packet length: TLV length exceeds the remaining input" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: error verifying packet sanity: invalid packet length: TLV length exceeds the remaining input" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrASNParse, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/garbage-then-valid @@ -356,7 +356,7 @@ 2s read from 127.0.0.2:161: 1 "public" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/other-version-then-valid @@ -403,7 +403,7 @@ 2s read from 127.0.0.2:161: 3 msgID=0 noAuthNoPriv user="public" engine="" boots=0 time=0 context=""/"" Response id=1003 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/other-version-v3-get-response @@ -434,7 +434,7 @@ 2s read from 127.0.0.2:161: 3 msgID=7 noAuthNoPriv user="public" engine="" boots=0 time=0 scoped PDU not decodable 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/other-version-v3-msg-id-zero @@ -465,7 +465,7 @@ 2s read from 127.0.0.2:161: 3 msgID=0 noAuthNoPriv user="public" engine="" boots=0 time=0 scoped PDU not decodable 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/other-version-v3-report @@ -496,7 +496,7 @@ 2s read from 127.0.0.2:161: 3 msgID=7 noAuthNoPriv user="public" engine="" boots=0 time=0 scoped PDU not decodable 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/other-version-v3-unknown-engine-report @@ -527,7 +527,7 @@ 2s read from 127.0.0.2:161: 3 msgID=7 noAuthNoPriv user="public" engine="" boots=0 time=0 scoped PDU not decodable 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/reflected-request @@ -697,7 +697,7 @@ 2s read from 127.0.0.2:161: 4 octets, not decodable (error verifying packet sanity: invalid packet length: TLV length exceeds the remaining input) 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: error in unmarshalResponse: error parsing SNMP packet error: -1 is outside 0..255" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: error in unmarshalResponse: error parsing SNMP packet error: -1 is outside 0..255" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrASNParse, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/unknown-pdu-type @@ -728,7 +728,7 @@ 2s read from 127.0.0.2:161: 52 octets, not decodable (unknown PDUType 0xaf) 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: unknown PDUType 0xaf" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: unknown PDUType 0xaf" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrASNParse, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/v1-trap @@ -759,7 +759,7 @@ 2s read from 127.0.0.2:161: 1 "public" Trap id=0 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: retries=2 next request id=1004 == requests/answer/wrong-id @@ -1196,7 +1196,7 @@ 10ms read: 42 octets, not decodable (invalid packet header) 10ms hook OnRecv 1s read: deadline -1s result: packet nil, error "request timeout (after 0 retries): last discarded reply: invalid packet header" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +1s result: packet nil, error "request timeout (after 0 retries): last discarded reply: invalid packet header" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrASNParse, net.Error timeout) 1s client after: retries=0 next request id=1002 == requests/deadline-error diff --git a/testdata/engine/v3.golden b/testdata/engine/v3.golden index 2ec60ed..92e9547 100644 --- a/testdata/engine/v3.golden +++ b/testdata/engine/v3.golden @@ -2509,7 +2509,7 @@ 2s read from 127.0.0.2:161: 3 msgID=2004 noAuthNoPriv user="" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's user name is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's user name is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/every-attempt/other-context @@ -2552,7 +2552,7 @@ 2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"codec-other-name" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's context is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's context is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/every-attempt/other-engine @@ -2595,7 +2595,7 @@ 2s read from 127.0.0.2:161: 3 msgID=2004 noAuthNoPriv user="codec-noauth" engine="\x80\x00\x1f\x88\x04codec-other" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's engine ID is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's engine ID is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/every-attempt/other-level @@ -2641,7 +2641,7 @@ 2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv user="codec-sha-aes" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's security level is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's security level is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/every-attempt/other-request-id @@ -2684,7 +2684,7 @@ 2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" Response id=1104 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's request ID does not match the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's request ID does not match the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/every-attempt/other-version @@ -2727,7 +2727,7 @@ 2s read from 127.0.0.2:161: 2c "public" Response id=1004 [.1.3.6.1.2.1.1.1.0=OctetString:"codec agent"] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is of another SNMP version than the request" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=none context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/every-attempt/reflected-request @@ -2770,7 +2770,7 @@ 2s read from 127.0.0.2:161: 3 msgID=2004 authNoPriv+reportable user="codec-md5" engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1002 context="\x80\x00\x1f\x88\x04codec-agent"/"" GetRequest id=1004 [.1.3.6.1.2.1.1.1.0] 2s hook OnRecv 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is neither a Response nor an SNMPv3 Report" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply is neither a Response nor an SNMPv3 Report" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/discard/not-encrypted-then-answer @@ -4738,7 +4738,7 @@ 2s agent: drops #5 (silent) 2s hook OnSent 3s read from 127.0.0.2:161: deadline -3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's security level is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, net.Error timeout) +3s result: packet nil, error "request timeout (after 2 retries): last discarded reply: the reply's security level is not the request's" *gosnmp.attemptsError (is os.ErrDeadlineExceeded, ErrUnmatchedReply, net.Error timeout) 3s client after: engine="\x80\x00\x1f\x88\x04codec-agent" boots=7 time=1000 keys=current context engine="\x80\x00\x1f\x88\x04codec-agent" == v3/noauth/unknown-engine-report-without-engine-id diff --git a/testdata/usm/decrypt.golden b/testdata/usm/decrypt.golden index 37cd7bc..b454279 100644 --- a/testdata/usm/decrypt.golden +++ b/testdata/usm/decrypt.golden @@ -34,15 +34,15 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-des/ciphertext-minus-8 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-des/flags-no-auth-no-priv -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == decrypt/sha-des/flags-auth-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-des/flags-privacy-only @@ -50,12 +50,12 @@ decode: error (ErrInvalidMsgs) unmarshal-trap: error (ErrInvalidMsgs) == decrypt/sha-des/engine-id-empty -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrUnknownEngineID) == decrypt/sha-des/receiver-aes -decode: error (ErrInvalidPacketLength, ErrDecryption) -unmarshal-trap: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) +unmarshal-trap: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) == decrypt/sha-des/receiver-priv-pass-empty decode: error @@ -91,19 +91,19 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes/ciphertext-minus-1 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes/ciphertext-minus-8 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes/flags-no-auth-no-priv -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == decrypt/sha-aes/flags-auth-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes/flags-privacy-only @@ -111,7 +111,7 @@ decode: error (ErrInvalidMsgs) unmarshal-trap: error (ErrInvalidMsgs) == decrypt/sha-aes/engine-id-empty -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrUnknownEngineID) == decrypt/sha-aes/receiver-des @@ -152,19 +152,19 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192/ciphertext-minus-1 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192/ciphertext-minus-8 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192/flags-no-auth-no-priv -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == decrypt/sha-aes192/flags-auth-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192/flags-privacy-only @@ -172,7 +172,7 @@ decode: error (ErrInvalidMsgs) unmarshal-trap: error (ErrInvalidMsgs) == decrypt/sha-aes192/engine-id-empty -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrUnknownEngineID) == decrypt/sha-aes192/receiver-des @@ -213,19 +213,19 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256/ciphertext-minus-1 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256/ciphertext-minus-8 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256/flags-no-auth-no-priv -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == decrypt/sha-aes256/flags-auth-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256/flags-privacy-only @@ -233,7 +233,7 @@ decode: error (ErrInvalidMsgs) unmarshal-trap: error (ErrInvalidMsgs) == decrypt/sha-aes256/engine-id-empty -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrUnknownEngineID) == decrypt/sha-aes256/receiver-des @@ -274,19 +274,19 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192c/ciphertext-minus-1 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192c/ciphertext-minus-8 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192c/flags-no-auth-no-priv -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == decrypt/sha-aes192c/flags-auth-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes192c/flags-privacy-only @@ -294,7 +294,7 @@ decode: error (ErrInvalidMsgs) unmarshal-trap: error (ErrInvalidMsgs) == decrypt/sha-aes192c/engine-id-empty -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrUnknownEngineID) == decrypt/sha-aes192c/receiver-des @@ -335,19 +335,19 @@ decode: error (ErrDecryption) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256c/ciphertext-minus-1 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256c/ciphertext-minus-8 -decode: error (ErrInvalidPacketLength, ErrDecryption) +decode: error (ErrDecryption) detail (ber.ErrInvalidPacketLength) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256c/flags-no-auth-no-priv -decode: error (ErrInvalidMsgs) -unmarshal-trap: error (ErrInvalidMsgs) +decode: error (ErrASNParse) +unmarshal-trap: error (ErrASNParse) == decrypt/sha-aes256c/flags-auth-no-priv -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) unmarshal-trap: error (ErrWrongDigest) == decrypt/sha-aes256c/flags-privacy-only diff --git a/testdata/usm/receiver-rules.golden b/testdata/usm/receiver-rules.golden index 9684972..462bb6f 100644 --- a/testdata/usm/receiver-rules.golden +++ b/testdata/usm/receiver-rules.golden @@ -265,70 +265,70 @@ error (ErrUnknownEngineID): incoming packet names no authoritative engine ID, di error: UnmarshalTrap: an SNMPv3 message needs a client whose Version is Version3 == authPriv, INTEGER privacy parameters/no protocols/table -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/no protocols/single -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/no protocols/single, message flags -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/no protocols/DecodeMessage -error (ErrInvalidMsgs): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA/table -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA/single -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA/single, message flags -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA/DecodeMessage -error (ErrInvalidMsgs): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA-AES/table -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA-AES/single -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA-AES/single, message flags -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA-AES/DecodeMessage -error (ErrInvalidMsgs): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/unknown authentication protocol/table error: add: User.AuthProtocol AuthProtocol(99) is not supported == authPriv, INTEGER privacy parameters/unknown authentication protocol/single -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/unknown authentication protocol/single, message flags -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/unknown authentication protocol/DecodeMessage -error (ErrInvalidMsgs): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA without a passphrase/table error: add: usm: no authentication key, want 20 octets == authPriv, INTEGER privacy parameters/SHA without a passphrase/single -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA without a passphrase/single, message flags -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA without a passphrase/DecodeMessage -error (ErrInvalidMsgs): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): unable to decode packet header: error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/no parameters/single -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authPriv, INTEGER privacy parameters/SHA-AES/single, version unset -error (ErrInvalidMsgs): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING +error (ErrASNParse): error parsing SNMPV3 User Security Model msgPrivacyParameters: not an OCTET STRING == authNoPriv, long-form digest field length/no protocols/table error (ErrUnknownSecurityLevel): no credentials successfully unmarshaled trap: error parsing SNMPv3 User Security Model: authentication parameters are not configured to parse incoming authenticated message diff --git a/trap_timeliness_test.go b/trap_timeliness_test.go index fc601ef..6741f6b 100644 --- a/trap_timeliness_test.go +++ b/trap_timeliness_test.go @@ -136,7 +136,7 @@ func TestTrapTimeliness(t *testing.T) { } // invalid boots or time fail the header parse (RFC 3414 section 3.2 step 1). invalid := func(boots, time uint32) timelyMessage { - return timelyMessage{boots: boots, time: time, want: ErrInvalidMsgs} + return timelyMessage{boots: boots, time: time, want: ErrASNParse} } after := func(wait time.Duration, m timelyMessage) timelyMessage { m.wait = wait; return m } inform := func(m timelyMessage) timelyMessage { m.inform = true; return m } diff --git a/usm_characterization_test.go b/usm_characterization_test.go index 927b165..1e4302d 100644 --- a/usm_characterization_test.go +++ b/usm_characterization_test.go @@ -433,13 +433,13 @@ func TestUSMTrapUnauthenticated(t *testing.T) { in: func() []byte { return usmFlagsTrap(t, AES, usmPrivacyFlag, 8) }, priv: AES, receiver: table, is: ErrInvalidMsgs, }, "noAuthNoPriv flags, encrypted AES, table": { - in: func() []byte { return usmFlagsTrap(t, AES, NoAuthNoPriv, 8) }, priv: AES, receiver: table, is: ErrInvalidMsgs, + in: func() []byte { return usmFlagsTrap(t, AES, NoAuthNoPriv, 8) }, priv: AES, receiver: table, is: ErrASNParse, }, "noAuthNoPriv flags, encrypted AES, single user": { - in: func() []byte { return usmFlagsTrap(t, AES, NoAuthNoPriv, 8) }, priv: AES, is: ErrInvalidMsgs, + in: func() []byte { return usmFlagsTrap(t, AES, NoAuthNoPriv, 8) }, priv: AES, is: ErrASNParse, }, "noAuthNoPriv flags, OCTET STRING scoped PDU, table without privacy": { - in: wrappedTrap, priv: NoPriv, receiver: table, is: ErrInvalidMsgs, + in: wrappedTrap, priv: NoPriv, receiver: table, is: ErrASNParse, }, "privacy-only DES with a 7-octet salt, single user": { in: func() []byte { return usmFlagsTrap(t, DES, usmPrivacyFlag, 7) }, priv: DES, is: ErrInvalidMsgs, @@ -448,7 +448,7 @@ func TestUSMTrapUnauthenticated(t *testing.T) { in: func() []byte { return usmFlagsTrap(t, DES, usmPrivacyFlag, 7) }, priv: DES, receiver: table, is: ErrInvalidMsgs, }, "noAuthNoPriv flags, encrypted DES with a 7-octet salt, table": { - in: func() []byte { return usmFlagsTrap(t, DES, NoAuthNoPriv, 7) }, priv: DES, receiver: table, is: ErrInvalidMsgs, + in: func() []byte { return usmFlagsTrap(t, DES, NoAuthNoPriv, 7) }, priv: DES, receiver: table, is: ErrASNParse, }, "privacy-only AES with a 7-octet salt, table": { in: func() []byte { return usmFlagsTrap(t, AES, usmPrivacyFlag, 7) }, priv: AES, receiver: table, is: ErrInvalidMsgs, @@ -478,10 +478,10 @@ func TestUSMTrapUnauthenticated(t *testing.T) { in: func() []byte { return usmPlainTrap(3, usmCharEngineID, "") }, priv: AES, is: ErrUnknownUsername, }, "malformed header, single user": { - in: func() []byte { return usmMalformedV3Header }, priv: AES, is: ErrInvalidMsgs, + in: func() []byte { return usmMalformedV3Header }, priv: AES, is: ErrASNParse, }, "malformed header, table": { - in: func() []byte { return usmMalformedV3Header }, priv: AES, receiver: table, is: ErrInvalidMsgs, + in: func() []byte { return usmMalformedV3Header }, priv: AES, receiver: table, is: ErrASNParse, }, } diff --git a/usm_fuzz_test.go b/usm_fuzz_test.go index 17a738f..b06ea21 100644 --- a/usm_fuzz_test.go +++ b/usm_fuzz_test.go @@ -138,12 +138,14 @@ func FuzzDecodeV3(f *testing.F) { start := time.Now() // No spare capacity, so a write past the input panics. in := bytes.Clone(data)[:len(data):len(data)] - if v, stack := recoverPanic(func() { _ = r.decode(in) }); v != nil { + var err error + if v, stack := recoverPanic(func() { err = r.decode(in) }); v != nil { t.Fatalf("%s with %v/%v credentials panicked: %v\ninput: %x\n%s", r.name, p.auth, p.priv, v, data, stack) } if !bytes.Equal(in, data) { t.Fatalf("%s with %v/%v credentials wrote into its input: %x", r.name, p.auth, p.priv, data) } + checkCategory(t, r.name, err) if e := time.Since(start); e > time.Second { t.Errorf("%s took %s", r.name, e) } diff --git a/v3.go b/v3.go index 7b3f4ca..109b0d7 100644 --- a/v3.go +++ b/v3.go @@ -78,38 +78,25 @@ func (packet *Message) sign(msg []byte, auth int, keys *usmKeys) ([]byte, error) // digest wrap: the message is not authentic. var errNotAuthentic = errors.New("incoming packet is not authentic, discarding") -// categorized is an error of SNMPv3 message processing: it has the text of -// err and unwraps to err and to category, the exported error named after the -// counter of the RFC 3412 or RFC 3414 step that rejected the message -// (ErrInvalidMsgs stands in for snmpInASNParseErrs). -type categorized struct { - // errs holds err and category, so that Unwrap allocates nothing. - errs [2]error -} - -func (e *categorized) Error() string { return e.errs[0].Error() } - -func (e *categorized) Unwrap() []error { return e.errs[:] } - -// inCategory returns err, which unwraps to category too. -func inCategory(category, err error) error { - return &categorized{errs: [2]error{err, category}} -} - // The rejections of the security processing (RFC 3414 section 3.2), in the // order of its steps; the minimum level a trap receiver requires comes after // them. var ( - errNoEngineID = inCategory(ErrUnknownEngineID, errors.New("incoming packet names no authoritative engine ID, discarding")) - errUnknownUser = inCategory(ErrUnknownUsername, errNotAuthentic) - errNoAuthForMsg = inCategory(ErrUnknownSecurityLevel, errors.New("error parsing SNMPv3 User Security Model: authentication parameters are not configured to parse incoming authenticated message")) - errNoPrivForMsg = inCategory(ErrUnknownSecurityLevel, errors.New("error parsing SNMPv3 User Security Model: privacy parameters are not configured to parse incoming encrypted message")) - errWrongDigest = inCategory(ErrWrongDigest, errNotAuthentic) - errNotInTime = inCategory(ErrNotInTimeWindow, errors.New("incoming packet is not in the time window, discarding")) - errScopedPDUType = inCategory(ErrInvalidMsgs, errors.New("error parsing SNMPV3 scoped PDU: its type does not match the privacy flag")) - errBelowMinimum = inCategory(ErrUnknownSecurityLevel, errors.New("incoming packet has a lower security level than its user requires, discarding")) + errNoEngineID = inCategory(ErrUnknownEngineID, errors.New("incoming packet names no authoritative engine ID, discarding")) + errUnknownUser = inCategory(ErrUnknownUsername, errNotAuthentic) + errNoAuthForMsg = inCategory(ErrUnknownSecurityLevel, errors.New("error parsing SNMPv3 User Security Model: authentication parameters are not configured to parse incoming authenticated message")) + errNoPrivForMsg = inCategory(ErrUnknownSecurityLevel, errors.New("error parsing SNMPv3 User Security Model: privacy parameters are not configured to parse incoming encrypted message")) + errWrongDigest = inCategory(ErrWrongDigest, errNotAuthentic) + errNotInTime = inCategory(ErrNotInTimeWindow, errors.New("incoming packet is not in the time window, discarding")) + errBelowMinimum = inCategory(ErrUnknownSecurityLevel, errors.New("incoming packet has a lower security level than its user requires, discarding")) ) +// errScopedPDUType is the error of a scoped PDU whose type does not match the +// privFlag: a SEQUENCE in plaintext, an OCTET STRING encrypted (RFC 3412 +// section 6.7, ScopedPduData). The message does not parse, as net-snmp v5.9.4 +// counts both cases. +var errScopedPDUType = inCategory(ErrASNParse, errors.New("error parsing SNMPV3 scoped PDU: its type does not match the privacy flag")) + // appendV3 appends the SNMPv3 part of a message after the version: the header // (msgGlobalData), the security parameters in an OCTET STRING and the scoped // PDU, once the header fields (checkV3Header) fit and keys has the protocols @@ -247,14 +234,19 @@ var errMsgFlags = errors.New("error parsing SNMPV3 msgFlags: not an OCTET STRING // without authentication (RFC 3412 section 7.2 step 5 d). var errPrivWithoutAuth = errors.New("error parsing SNMPV3 msgFlags: privacy without authentication") -// v3ParseError returns err, an error of parseV3, unwrapping to the exported -// error of its counter: ErrUnknownSecurityModels for another security model -// (RFC 3412 section 7.2 step 4), ErrInvalidMsgs for the rest. +// v3ParseError returns err, an error of parseV3, in the category of its +// counter, as net-snmp v5.9.4 counts it: ErrUnknownSecurityModels for another +// security model (RFC 3412 section 7.2 step 4), ErrInvalidMsgs for privacy +// without authentication (step 5 d), ErrASNParse for the rest, a header field +// outside its range included (step 2, RFC 3414 section 3.2 step 1). func v3ParseError(err error) error { - if errors.Is(err, errNotUSM) { + switch { + case errors.Is(err, errNotUSM): return inCategory(ErrUnknownSecurityModels, err) + case errors.Is(err, errPrivWithoutAuth): + return inCategory(ErrInvalidMsgs, err) } - return inCategory(ErrInvalidMsgs, err) + return inCategory(ErrASNParse, err) } // parseV3 reads the SNMPv3 header at packet[cursor:]: the message ID, maximum @@ -438,13 +430,13 @@ func tlvAt(packet []byte, off, end int) (start, stop int, err error) { // read against the rest of the message, whatever its declared length. The // decrypted plaintext must be a SEQUENCE, which cuts off the padding, and // contextEngineID and contextName OCTET STRINGs. A scoped PDU of the other -// type, or one that does not parse before decryption, is ErrInvalidMsgs; a +// type, or one that does not parse before decryption, is ErrASNParse; a // decryption failure, or a decrypted plaintext that does not parse, as with a -// wrong key, ErrDecryption; a key the process cannot decrypt with -// (usm.Priv.CheckUse) neither. +// wrong key, ErrDecryption (net-snmp counts the latter as a parse error); a key +// the process cannot decrypt with (usm.Priv.CheckUse) neither. func unmarshalScopedPDU(packet []byte, cursor int, response *Message, encrypted bool, keys *usmKeys) ([]byte, int, error) { if cursor >= len(packet) { - return nil, 0, inCategory(ErrInvalidMsgs, errors.New("error parsing SNMPV3: truncated packet")) + return nil, 0, inCategory(ErrASNParse, errors.New("error parsing SNMPV3: truncated packet")) } var r ber.Reader @@ -453,11 +445,11 @@ func unmarshalScopedPDU(packet []byte, cursor int, response *Message, encrypted return nil, 0, errScopedPDUType } if tag != ber.Sequence && tag != byte(OctetString) { - return nil, 0, inCategory(ErrInvalidMsgs, errors.New("error parsing SNMPV3 scoped PDU")) + return nil, 0, inCategory(ErrASNParse, errors.New("error parsing SNMPV3 scoped PDU")) } start, stop, err := tlvAt(packet, cursor, len(packet)) if err != nil { - return nil, 0, inCategory(ErrInvalidMsgs, fmt.Errorf("error parsing SNMPV3 scoped PDU: %w", err)) + return nil, 0, inCategory(ErrASNParse, fmt.Errorf("error parsing SNMPV3 scoped PDU: %w", err)) } if encrypted { if err := keys.privProtocol.spec().CheckUse(keys.priv); err != nil { @@ -485,7 +477,7 @@ func unmarshalScopedPDU(packet []byte, cursor int, response *Message, encrypted if encrypted { return nil, 0, inCategory(ErrDecryption, err) } - return nil, 0, inCategory(ErrInvalidMsgs, err) + return nil, 0, inCategory(ErrASNParse, err) } return packet, len(packet) - r.Len(), nil } diff --git a/v3_parse_test.go b/v3_parse_test.go index 8a52ca8..78ef690 100644 --- a/v3_parse_test.go +++ b/v3_parse_test.go @@ -439,7 +439,7 @@ func TestV3ReplyDecode(t *testing.T) { reply, verified, err := e.decode(report, nil) assert.Nil(t, reply, "no msgID was read") assert.False(t, verified) - require.ErrorIs(t, err, ErrInvalidMsgs) + require.ErrorIs(t, err, ErrASNParse) }) // A message naming no attempt, or of another version, is discarded before @@ -473,7 +473,7 @@ func TestV3ReplyDecode(t *testing.T) { t.Run("authentic reply whose scoped PDU does not decode", func(t *testing.T) { e, _ := request(AuthNoPriv, NoPriv) reply, verified, err := e.decode(signedReply(tlv(0x30, craftedEngineID)), earlier) - require.ErrorIs(t, err, ErrInvalidMsgs) + require.ErrorIs(t, err, ErrASNParse) assert.True(t, verified) require.NotNil(t, reply, "the message as far as decode read it") assert.Equal(t, uint32(42), reply.MsgID) @@ -703,7 +703,7 @@ func TestV3DigestField(t *testing.T) { in []byte want error }{ - "the digest in an OBJECT IDENTIFIER": {signedWith(byte(ObjectIdentifier), 12), ErrInvalidMsgs}, + "the digest in an OBJECT IDENTIFIER": {signedWith(byte(ObjectIdentifier), 12), ErrASNParse}, "a field of 64 octets": {signedWith(byte(OctetString), 64), errNotAuthentic}, } for name, tc := range tests { diff --git a/v3_usm_test.go b/v3_usm_test.go index 934a6a6..5add517 100644 --- a/v3_usm_test.go +++ b/v3_usm_test.go @@ -443,8 +443,8 @@ func TestUSMTrapMistypedFields(t *testing.T) { want error // nil: accepted }{ "as sent": {in: trap(octets(usmCharEngineID), octets("secret-user"))}, - "user name as an INTEGER": {in: trap(octets(usmCharEngineID), intTLV(1)), want: ErrInvalidMsgs}, - "engine ID as an INTEGER": {in: trap(intTLV(1), octets("secret-user")), want: ErrInvalidMsgs}, + "user name as an INTEGER": {in: trap(octets(usmCharEngineID), intTLV(1)), want: ErrASNParse}, + "engine ID as an INTEGER": {in: trap(intTLV(1), octets("secret-user")), want: ErrASNParse}, } for name, tc := range tests { for rname, receiver := range receivers { @@ -663,9 +663,7 @@ func TestUSMFIPS140OnlyDecrypt(t *testing.T) { t.Run(name, func(t *testing.T) { err := decode() require.ErrorContains(t, err, "not allowed in FIPS 140-only mode") - for _, category := range []error{ErrDecryption, ErrWrongDigest, ErrInvalidMsgs} { - assert.NotErrorIs(t, err, category) - } + assert.Empty(t, categoriesOf(err), "a local failure is in no category") }) } }) From 8f6d4cfaa49b523603c07885553a134ce834a12a Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Mon, 2 Nov 2026 10:01:39 +0200 Subject: [PATCH 3/7] test: pin SNMPv1 and version-2 messages with an octet after them A version-2 message followed by an octet fails as a message that does not parse, before its version is checked; a version-1 one fails the same way. --- codec_decode_test.go | 4 ++++ testdata/codec/decode.golden | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/codec_decode_test.go b/codec_decode_test.go index 3bb9b77..b558e38 100644 --- a/codec_decode_test.go +++ b/codec_decode_test.go @@ -456,6 +456,10 @@ func decodeCraftedCases() []decodeCase { // Version and community. {name: "crafted/version/0", in: craftedMsg(0, craftedPDU(Response, craftedVBL(nullVB)))}, {name: "crafted/version/2", in: craftedMsg(2, craftedPDU(Response, craftedVBL(nullVB)))}, + // The version is known before the octets after the message: a bad + // version (RFC 3412 section 4.2.1). + {name: "crafted/version/2-trailing-octets", in: append(craftedMsg(2, craftedPDU(Response, craftedVBL(nullVB))), 0x00)}, + {name: "crafted/version/1-trailing-octets", in: append(craftedMsg(1, craftedPDU(Response, craftedVBL(nullVB))), 0x00)}, {name: "crafted/version/3-with-community", in: craftedMsg(3, craftedPDU(Response, craftedVBL(nullVB)))}, {name: "crafted/version/256", in: craftedMsg(256, craftedPDU(Response, craftedVBL(nullVB)))}, {name: "crafted/version/-1", in: craftedMsg(-1, craftedPDU(Response, craftedVBL(nullVB)))}, diff --git a/testdata/codec/decode.golden b/testdata/codec/decode.golden index a2fca27..a50f0c3 100644 --- a/testdata/codec/decode.golden +++ b/testdata/codec/decode.golden @@ -648,6 +648,12 @@ reencode: identical == crafted/version/2 decode: error (ErrBadVersion) +== crafted/version/2-trailing-octets +decode: error (ErrASNParse) + +== crafted/version/1-trailing-octets +decode: error (ErrASNParse) + == crafted/version/3-with-community decode: error (ErrASNParse) From d8a7bc0409a6d3ee4f2b0f84f9d2897683613d79 Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Mon, 2 Nov 2026 10:11:41 +0200 Subject: [PATCH 4/7] fix: a message's version is checked before the octets after it A version-2 message followed by an octet failed as a message that does not parse (ErrASNParse): the SEQUENCE had to span the packet before the version was read. The version is known once the SEQUENCE's declared extent and the version field parse, so such a message is now ErrBadVersion (RFC 3412 section 4.2.1); octets after a message of a supported version fail as before, with the same text, now pinned. --- codec_failure_test.go | 4 ++++ pdu.go | 30 +++++++++++++++++------------- testdata/codec/decode.golden | 2 +- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/codec_failure_test.go b/codec_failure_test.go index f610885..d6a03f3 100644 --- a/codec_failure_test.go +++ b/codec_failure_test.go @@ -114,6 +114,10 @@ func TestDecodeFailurePartialResults(t *testing.T) { "not a sequence": {in: cat([]byte{0x31}, craftedValue(intTLV(5))[1:]), wantErr: header + "invalid packet header", want: with(decodedFields{}, func(*decodedFields) {})}, "version": {in: tlv(0x30, bad, octets("public"), vbl), wantErr: header + "error parsing SNMP packet version" + notInt, want: with(decodedFields{}, func(*decodedFields) {})}, "community": {in: tlv(0x30, intTLV(1), bad, vbl), wantErr: header + "error parsing community string" + notStr, want: with(decodedFields{version: Version2c}, func(*decodedFields) {})}, + "octet after the message": { + in: cat(craftedMsg(1, craftedPDU(Response, vbl)), []byte{0x00}), wantErr: header + "error verifying packet sanity: 1 bytes after the TLV", + want: with(decodedFields{}, func(*decodedFields) {}), + }, // PDU header. "request ID": {in: craftedMsg(1, tlv(byte(Response), bad, intTLV(2), intTLV(3), vbl)), wantErr: body + "error parsing SNMP packet request ID" + notInt, want: resp}, diff --git a/pdu.go b/pdu.go index 6519388..c7304c0 100644 --- a/pdu.go +++ b/pdu.go @@ -178,42 +178,46 @@ var errEmptyPacket = fmt.Errorf("%w: cannot unmarshal empty packet", ber.ErrInva // readVersion reads the message SEQUENCE, which must span the whole packet, // and its version field, an INTEGER of SNMPv1 (0), SNMPv2c (1) or SNMPv3 (3). // It returns the version and the offset of the field after it. Another -// version is ErrBadVersion (RFC 3412 section 4.2.1), a message that does not -// parse that far ErrASNParse. +// version is ErrBadVersion (RFC 3412 section 4.2.1: the version is known once +// the SEQUENCE's declared extent and the version field parse, octets after the +// message or not), a message that does not parse ErrASNParse. func readVersion(packet []byte) (Version, int, error) { - r, version, err := readVersionField(packet) + r, version, after, err := readVersionField(packet) switch { case err != nil: return 0, 0, inCategory(ErrASNParse, err) case version != int32(Version1) && version != int32(Version2c) && version != int32(Version3): return 0, 0, inCategory(ErrBadVersion, fmt.Errorf("error parsing SNMP packet version: %d is not 0, 1 or 3", version)) + case after != 0: + return 0, 0, inCategory(ErrASNParse, fmt.Errorf("error verifying packet sanity: %d bytes after the TLV", after)) case r.Len() == 0: return 0, 0, inCategory(ErrASNParse, errors.New("error parsing SNMP packet: nothing after the version")) } return Version(version), len(packet) - r.Len(), nil //nolint:gosec // 0, 1 or 3 } -// readVersionField reads the message SEQUENCE, which must span the whole -// packet, and its first field, an INTEGER (readInt32); it returns the reader -// of the fields after it. -func readVersionField(packet []byte) (ber.Reader, int32, error) { +// readVersionField reads the message SEQUENCE, whose declared length must fit +// the packet, and its first field, an INTEGER (readInt32); it returns the +// reader of the fields after it and the number of octets after the SEQUENCE. +func readVersionField(packet []byte) (ber.Reader, int32, int, error) { if len(packet) < 2 { - return ber.Reader{}, 0, errEmptyPacket + return ber.Reader{}, 0, 0, errEmptyPacket } if packet[0] != ber.Sequence { - return ber.Reader{}, 0, errors.New("invalid packet header") + return ber.Reader{}, 0, 0, errors.New("invalid packet header") } - msg, err := readWhole(packet) + whole := ber.NewReader(packet) + _, msg, err := whole.Next() if err != nil { - return ber.Reader{}, 0, fmt.Errorf("error verifying packet sanity: %w", err) + return ber.Reader{}, 0, 0, fmt.Errorf("error verifying packet sanity: %w", err) } r := ber.NewReader(msg) version, err := readInt32(&r) if err != nil { - return ber.Reader{}, 0, fmt.Errorf("error parsing SNMP packet version: %w", err) + return ber.Reader{}, 0, 0, fmt.Errorf("error parsing SNMP packet version: %w", err) } - return r, version, nil + return r, version, whole.Len(), nil } // unmarshalHeader reads the message header into response: the version and, diff --git a/testdata/codec/decode.golden b/testdata/codec/decode.golden index a50f0c3..7caf63b 100644 --- a/testdata/codec/decode.golden +++ b/testdata/codec/decode.golden @@ -649,7 +649,7 @@ reencode: identical decode: error (ErrBadVersion) == crafted/version/2-trailing-octets -decode: error (ErrASNParse) +decode: error (ErrBadVersion) == crafted/version/1-trailing-octets decode: error (ErrASNParse) From 7e6a438b579c9fdc577f63956bda172690d38f2f Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Mon, 2 Nov 2026 10:11:53 +0200 Subject: [PATCH 5/7] test, docs: pin the trap paths' categories; correct the error docs Pins: UnmarshalTrap's version check and the PDU of an SNMPv1, an SNMPv2c and an SNMPv3 trap past security processing, on both paths, and an authPriv message without its scoped PDU (TestRejectionCategories); FuzzUnmarshal also checks UnmarshalTrap's single path for one category. Docs: the categories are variables that callers must not assign to (the library makes some errors with their values at initialization and others when they occur); net-snmp counts msgPrivacyParameters that do not parse as a decryption error, where the library follows RFC 3414 section 3.2 step 1 (ErrASNParse); ErrDecryption covers a decrypted plaintext that is not a SEQUENCE of a contextEngineID and a contextName, a PDU that does not parse after them being ErrASNParse; the category list no longer claims an order. --- codec_fuzz_test.go | 8 +++++-- doc.go | 24 +++++++++++---------- errors.go | 17 ++++++++------- errors_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+), 20 deletions(-) diff --git a/codec_fuzz_test.go b/codec_fuzz_test.go index a4e020e..61b4939 100644 --- a/codec_fuzz_test.go +++ b/codec_fuzz_test.go @@ -25,19 +25,23 @@ func codecFuzzSeeds(tb testing.TB) [][]byte { } // FuzzUnmarshal checks that DecodeMessage returns quickly, does not panic -// and does not write into its input. Its corpus in testdata/fuzz/FuzzUnmarshal -// is also pinned by TestDecodeCharacterization. +// and does not write into its input, and that its errors and those of +// UnmarshalTrap's single path each have one category. Its corpus in +// testdata/fuzz/FuzzUnmarshal is also pinned by TestDecodeCharacterization. func FuzzUnmarshal(f *testing.F) { for _, seed := range codecFuzzSeeds(f) { f.Add(seed) } vhandle := Client{} + receiver := Client{Version: Version3} f.Fuzz(func(t *testing.T, data []byte) { stime := time.Now() in := bytes.Clone(data) _, err := vhandle.DecodeMessage(in) checkCategory(t, "DecodeMessage", err) + _, err = receiver.UnmarshalTrap(bytes.Clone(data), true) + checkCategory(t, "UnmarshalTrap", err) if e := time.Since(stime); e > (time.Second * 1) { t.Errorf("DecodeMessage() took too long: %s", e) diff --git a/doc.go b/doc.go index 1cd3b41..6e50c18 100644 --- a/doc.go +++ b/doc.go @@ -378,14 +378,15 @@ // category, an exported error named after the counter RFC 3412, RFC 3414 or // RFC 3418 counts the message in, as net-snmp v5.9.4 counts it, with a text of // its own: an error of DecodeMessage, of UnmarshalTrap, and the reason a -// request discards a reply for. In the order a message meets them: +// request discards a reply for. The categories: // // - [ErrASNParse] (snmpInASNParseErrs): the message does not parse, of any // version: its encoding, a header field of another type or outside its -// range, the USM parameters (RFC 3414 section 3.2 step 1), a scoped PDU of -// the other type than the privFlag asks for or one that does not parse in -// plaintext, the PDU, an unknown PDU type and a varbind (RFC 3412 section -// 7.2 steps 2 and 7); +// range, the USM parameters (RFC 3414 section 3.2 step 1; net-snmp counts +// msgPrivacyParameters that do not parse in usmStatsDecryptionErrors), a +// scoped PDU of the other type than the privFlag asks for or one that does +// not parse in plaintext, the PDU, an unknown PDU type and a varbind (RFC +// 3412 section 7.2 steps 2 and 7); // - [ErrBadVersion] (snmpInBadVersions): a version other than SNMPv1, SNMPv2c // and SNMPv3 (RFC 3412 section 4.2.1); // - [ErrUnknownSecurityModels]: another security model (step 4); @@ -393,8 +394,9 @@ // - [ErrUnknownEngineID] through [ErrDecryption]: the security processing // (RFC 3414 section 3.2 steps 3 to 8), [ErrUnknownSecurityLevel] for a // trap receiver's minimum level too, and [ErrDecryption] for a decrypted -// scoped PDU that does not parse, as a wrong privacy key yields (net-snmp -// counts it in snmpInASNParseErrs); +// plaintext that is not a SEQUENCE of a contextEngineID and a contextName, +// as a wrong privacy key yields (net-snmp counts it in snmpInASNParseErrs; +// a PDU that does not parse after them is [ErrASNParse]); // - [ErrUnmatchedReply]: a reply that does not answer the request: of another // version, naming none of its attempts, neither a Response nor a Report, // or with another request ID, security level, user name, engine ID or @@ -412,8 +414,8 @@ // matches none of them, nor does a transport error or a timeout without a // discarded reply. // -// The categories are variables only so that errors.Is can match them: the -// library returns the values they had when the package was initialized, so -// after a caller assigns another value to one, the library's errors no longer -// match it. +// The categories are variables only so that errors.Is can match them; do not +// assign to them. The library makes some of its errors with their values when +// the package is initialized and others when the error occurs, so after an +// assignment its errors match the old value or the new one. package gosnmp diff --git a/errors.go b/errors.go index 4cc9be4..dd0a1ec 100644 --- a/errors.go +++ b/errors.go @@ -16,15 +16,17 @@ import "errors" // key that does not derive or a protocol FIPS 140-only mode refuses, matches // none of them. // -// They are variables only so that errors.Is can match them: the library -// returns the values they had when the package was initialized, so after a -// caller assigns another value to one, the library's errors no longer match -// it. +// They are variables only so that errors.Is can match them; do not assign to +// them. The library makes some of its errors with their values when the +// package is initialized and others when the error occurs, so after an +// assignment its errors match the old value or the new one. var ( // ErrASNParse is a message that does not parse, of any version: its // encoding, a header field, the USM parameters, a plaintext scoped PDU, the // PDU or a varbind, an unknown PDU type included (snmpInASNParseErrs, RFC - // 3412 section 7.2 steps 2 and 7, RFC 3414 section 3.2 step 1). + // 3412 section 7.2 steps 2 and 7, RFC 3414 section 3.2 step 1; net-snmp + // v5.9.4 counts msgPrivacyParameters that do not parse in + // usmStatsDecryptionErrors). ErrASNParse = errors.New("ASN.1 parse error") // ErrBadVersion is a message of another version than SNMPv1, SNMPv2c and // SNMPv3 (snmpInBadVersions, RFC 3412 section 4.2.1). @@ -50,8 +52,9 @@ var ( // ErrNotInTimeWindow is an authentic SNMPv3 message outside the time // window (step 7). ErrNotInTimeWindow = errors.New("not in time window") - // ErrDecryption is an SNMPv3 message that does not decrypt (step 8), - // or whose decrypted scoped PDU does not parse. + // ErrDecryption is an SNMPv3 message that does not decrypt (step 8), or + // whose decrypted plaintext is not a SEQUENCE of a contextEngineID and a + // contextName (a PDU that does not parse after them is ErrASNParse). ErrDecryption = errors.New("decryption error") // ErrUnknownPDUHandlers is a Report of snmpUnknownPDUHandlers (RFC 3412). ErrUnknownPDUHandlers = errors.New("unknown pdu handlers") diff --git a/errors_test.go b/errors_test.go index 34f6814..89e7247 100644 --- a/errors_test.go +++ b/errors_test.go @@ -71,6 +71,58 @@ func checkCategory(t *testing.T, what string, err error) { } } +// TestRejectionCategories pins the category of rejections no golden reaches +// through its entry point: UnmarshalTrap's version check and the PDU of an +// SNMPv1 and an SNMPv2c trap and of an SNMPv3 trap past security processing, +// on both paths, and an encrypted message without its scoped PDU. +func TestRejectionCategories(t *testing.T) { + useEngineTimes(t) + user := usmUser(NoAuth, "", NoPriv, "") + single := func(data []byte) error { + _, err := (&Client{Version: Version3, User: user}).UnmarshalTrap(data, true) + return err + } + table := func(data []byte) error { + tb := NewSnmpV3SecurityParametersTable() + if err := tb.Add(user, nil); err != nil { + return err + } + _, err := (&Client{Version: Version3, TrapSecurityParametersTable: tb}).UnmarshalTrap(data, false) + return err + } + decode := func(data []byte) error { + _, err := (&Client{User: usmUser(SHA, "codec-auth-pass", AES, "codec-priv-pass")}).DecodeMessage(data) + return err + } + // A PDU whose error status is missing. + badPDU := tlv(byte(SNMPv2Trap), intTLV(1)) + v3Trap := craftedV3NoAuth(tlv(0x30, craftedEngineID, octets(""), badPDU)) + authPrivWithoutScopedPDU := craftedV3(intTLV(42), intTLV(65507), octets("\x03"), intTLV(3), + craftedUSM(craftedEngineID, intTLV(7), intTLV(1234), octets("codec-user"), octets(string(make([]byte, 12))), + octets(string(make([]byte, 8)))), nil) + + tests := map[string]struct { + decode func([]byte) error + in []byte + want string + }{ + "trap of version 2": {single, craftedMsg(2, craftedPDU(SNMPv2Trap, craftedVBL(craftedVB(intTLV(5))))), "ErrBadVersion"}, + "SNMPv1 trap PDU": {single, craftedV1Trap(octets("x"), craftedAgentAddress, intTLV(6), intTLV(1), craftedTimestamp, craftedVBL()), "ErrASNParse"}, + "SNMPv2c trap PDU": {single, craftedMsg(1, badPDU), "ErrASNParse"}, + "SNMPv3 trap PDU, single path": {single, v3Trap, "ErrASNParse"}, + "SNMPv3 trap PDU, table path": {table, v3Trap, "ErrASNParse"}, + "authPriv without a scoped PDU": {decode, authPrivWithoutScopedPDU, "ErrASNParse"}, + } + for name, tc := range tests { + t.Run(name, func(t *testing.T) { + err := tc.decode(tc.in) + if got := categoriesOf(err); len(got) != 1 || got[0] != tc.want { + t.Errorf("%q: categories %v, want [%s]", err, got, tc.want) + } + }) + } +} + // TestUnmatchedReplyReasons checks that every reason a request discards a // decoded reply for is ErrUnmatchedReply, the one of a msgID that names no // attempt included, which never reaches a caller (rankOf records no message From 28c88cbfdee8b095bbd64b18e5ebf81f3abb08ee Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Mon, 2 Nov 2026 10:20:53 +0200 Subject: [PATCH 6/7] docs: net-snmp counts a negative version as a parse error too ErrBadVersion's docs name the one difference from net-snmp v5.9.4 for versions: it counts a negative version in snmpInASNParseErrs besides snmpInBadVersions; the library gives every error one category. --- doc.go | 3 ++- errors.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/doc.go b/doc.go index 6e50c18..9f41e89 100644 --- a/doc.go +++ b/doc.go @@ -388,7 +388,8 @@ // not parse in plaintext, the PDU, an unknown PDU type and a varbind (RFC // 3412 section 7.2 steps 2 and 7); // - [ErrBadVersion] (snmpInBadVersions): a version other than SNMPv1, SNMPv2c -// and SNMPv3 (RFC 3412 section 4.2.1); +// and SNMPv3 (RFC 3412 section 4.2.1; net-snmp counts a negative one in +// snmpInASNParseErrs too); // - [ErrUnknownSecurityModels]: another security model (step 4); // - [ErrInvalidMsgs]: privacy without authentication (step 5 d); // - [ErrUnknownEngineID] through [ErrDecryption]: the security processing diff --git a/errors.go b/errors.go index dd0a1ec..e24bc34 100644 --- a/errors.go +++ b/errors.go @@ -29,7 +29,8 @@ var ( // usmStatsDecryptionErrors). ErrASNParse = errors.New("ASN.1 parse error") // ErrBadVersion is a message of another version than SNMPv1, SNMPv2c and - // SNMPv3 (snmpInBadVersions, RFC 3412 section 4.2.1). + // SNMPv3 (snmpInBadVersions, RFC 3412 section 4.2.1; net-snmp v5.9.4 counts + // a negative one in snmpInASNParseErrs too). ErrBadVersion = errors.New("bad version") // ErrUnknownSecurityModels is an SNMPv3 message of another security model // than the User-based Security Model (RFC 3412 section 7.2 step 4). From 8f3e66a04941d26ccfaeacf97820adbb96a12c08 Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Wed, 11 Nov 2026 23:52:25 +0200 Subject: [PATCH 7/7] test: an engine ID longer than the decoder takes is a parse error The engine ID size cases take the category the header field rules have here: ErrASNParse, as a user name over 32 octets. --- codec_encode_test.go | 2 +- testdata/codec/decode.golden | 4 ++-- v3_usm_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codec_encode_test.go b/codec_encode_test.go index 0c1dcef..f603725 100644 --- a/codec_encode_test.go +++ b/codec_encode_test.go @@ -78,7 +78,7 @@ func TestMarshalLongOctetStringFields(t *testing.T) { // Longer than the decoder takes: the fields as the encoder // laid them out. _, err = (&Client{}).DecodeMessage(msg) - require.ErrorIs(t, err, ErrInvalidMsgs) + require.ErrorIs(t, err, ErrASNParse) m := splitV3Message(t, msg) if got := (fields{engineID: string(m.usm[0]), userName: string(m.usm[3])}); got != want { t.Errorf("encoded %+v, want %+v", got, want) diff --git a/testdata/codec/decode.golden b/testdata/codec/decode.golden index 7caf63b..2681005 100644 --- a/testdata/codec/decode.golden +++ b/testdata/codec/decode.golden @@ -2046,7 +2046,7 @@ decode: error (ErrASNParse) decode: error (ErrASNParse) == crafted/v3/usm-engine-id-200 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-engine-id-64 decode: ok @@ -2060,7 +2060,7 @@ vb[0]: .1.3.6.1.2.1.1.5.0 0x02 (Integer) int 5 reencode: identical == crafted/v3/usm-engine-id-65 -decode: error (ErrInvalidMsgs) +decode: error (ErrASNParse) == crafted/v3/usm-user-name-200 decode: error (ErrASNParse) diff --git a/v3_usm_test.go b/v3_usm_test.go index 5add517..d5d7439 100644 --- a/v3_usm_test.go +++ b/v3_usm_test.go @@ -877,7 +877,7 @@ func TestSignDigestOffset(t *testing.T) { x := &Client{Version: Version3, SecurityLevel: signedTestFlags(priv), User: u} res, err := x.UnmarshalTrap(bytes.Clone(data), false) if len(engineID) > maxDecodedEngineIDLen { - require.ErrorIs(t, err, ErrInvalidMsgs, "an engine ID longer than the decoder takes") + require.ErrorIs(t, err, ErrASNParse, "an engine ID longer than the decoder takes") return } require.NoError(t, err)