fix(inputs.snmp_trap): Enable SHA ciphers (#14665)

This commit is contained in:
Juha Keski-Saari 2024-02-02 11:40:52 +02:00 committed by GitHub
parent 120167501b
commit f9f2adf3ae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 244 additions and 245 deletions

View File

@ -65,13 +65,13 @@ details.
## Deprecated in 1.20.0; no longer running snmptranslate ## Deprecated in 1.20.0; no longer running snmptranslate
## Timeout running snmptranslate command ## Timeout running snmptranslate command
# timeout = "5s" # timeout = "5s"
## Snmp version ## Snmp version; one of "1", "2c" or "3".
# version = "2c" # version = "2c"
## SNMPv3 authentication and encryption options. ## SNMPv3 authentication and encryption options.
## ##
## Security Name. ## Security Name.
# sec_name = "myuser" # sec_name = "myuser"
## Authentication protocol; one of "MD5", "SHA" or "". ## Authentication protocol; one of "MD5", "SHA", "SHA224", "SHA256", "SHA384", "SHA512" or "".
# auth_protocol = "MD5" # auth_protocol = "MD5"
## Authentication password. ## Authentication password.
# auth_password = "pass" # auth_password = "pass"

View File

@ -17,13 +17,13 @@
## Deprecated in 1.20.0; no longer running snmptranslate ## Deprecated in 1.20.0; no longer running snmptranslate
## Timeout running snmptranslate command ## Timeout running snmptranslate command
# timeout = "5s" # timeout = "5s"
## Snmp version ## Snmp version; one of "1", "2c" or "3".
# version = "2c" # version = "2c"
## SNMPv3 authentication and encryption options. ## SNMPv3 authentication and encryption options.
## ##
## Security Name. ## Security Name.
# sec_name = "myuser" # sec_name = "myuser"
## Authentication protocol; one of "MD5", "SHA" or "". ## Authentication protocol; one of "MD5", "SHA", "SHA224", "SHA256", "SHA384", "SHA512" or "".
# auth_protocol = "MD5" # auth_protocol = "MD5"
## Authentication password. ## Authentication password.
# auth_password = "pass" # auth_password = "pass"

View File

@ -156,14 +156,14 @@ func (s *SnmpTrap) Start(acc telegraf.Accumulator) error {
authenticationProtocol = gosnmp.MD5 authenticationProtocol = gosnmp.MD5
case "sha": case "sha":
authenticationProtocol = gosnmp.SHA authenticationProtocol = gosnmp.SHA
//case "sha224": case "sha224":
// authenticationProtocol = gosnmp.SHA224 authenticationProtocol = gosnmp.SHA224
//case "sha256": case "sha256":
// authenticationProtocol = gosnmp.SHA256 authenticationProtocol = gosnmp.SHA256
//case "sha384": case "sha384":
// authenticationProtocol = gosnmp.SHA384 authenticationProtocol = gosnmp.SHA384
//case "sha512": case "sha512":
// authenticationProtocol = gosnmp.SHA512 authenticationProtocol = gosnmp.SHA512
case "": case "":
authenticationProtocol = gosnmp.NoAuth authenticationProtocol = gosnmp.NoAuth
default: default:

View File

@ -61,14 +61,14 @@ func newUsmSecurityParametersForV3(authProto string, privProto string, username
authenticationProtocol = gosnmp.MD5 authenticationProtocol = gosnmp.MD5
case "sha": case "sha":
authenticationProtocol = gosnmp.SHA authenticationProtocol = gosnmp.SHA
//case "sha224": case "sha224":
// authenticationProtocol = gosnmp.SHA224 authenticationProtocol = gosnmp.SHA224
//case "sha256": case "sha256":
// authenticationProtocol = gosnmp.SHA256 authenticationProtocol = gosnmp.SHA256
//case "sha384": case "sha384":
// authenticationProtocol = gosnmp.SHA384 authenticationProtocol = gosnmp.SHA384
//case "sha512": case "sha512":
// authenticationProtocol = gosnmp.SHA512 authenticationProtocol = gosnmp.SHA512
case "": case "":
authenticationProtocol = gosnmp.NoAuth authenticationProtocol = gosnmp.NoAuth
default: default:
@ -501,255 +501,254 @@ func TestReceiveTrap(t *testing.T) {
), ),
}, },
}, },
/* //ordinary v3 coldstart trap SHA224 auth and no priv
//ordinary v3 coldstart trap SHA224 auth and no priv {
{ name: "v3 coldStart authShaNoPriv",
name: "v3 coldStart authShaNoPriv", version: gosnmp.Version3,
version: gosnmp.Version3, secName: "authSha224NoPriv",
secName: "authSha224NoPriv", secLevel: "authNoPriv",
secLevel: "authNoPriv", authProto: "SHA224",
authProto: "SHA224", authPass: "passpass",
authPass: "passpass", trap: gosnmp.SnmpTrap{
trap: gosnmp.SnmpTrap{ Variables: []gosnmp.SnmpPDU{
Variables: []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.3.0",
Type: gosnmp.TimeTicks,
Value: now,
},
{
Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
Type: gosnmp.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
},
},
},
entries: []entry{
{ {
oid: ".1.3.6.1.6.3.1.1.4.1.0", Name: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{ Type: gosnmp.TimeTicks,
MibName: "SNMPv2-MIB", Value: now,
OidText: "snmpTrapOID.0",
},
}, },
{ {
oid: ".1.3.6.1.6.3.1.1.5.1", Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
e: snmp.MibEntry{ Type: gosnmp.ObjectIdentifier,
MibName: "SNMPv2-MIB", Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
OidText: "coldStart",
},
}, },
{
oid: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{
MibName: "UNUSED_MIB_NAME",
OidText: "sysUpTimeInstance",
},
},
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"snmp_trap", // name
map[string]string{ // tags
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
}, },
}, },
//ordinary v3 coldstart trap SHA256 auth and no priv entries: []entry{
{ {
name: "v3 coldStart authSha256NoPriv", oid: ".1.3.6.1.6.3.1.1.4.1.0",
version: gosnmp.Version3, e: snmp.MibEntry{
secName: "authSha256NoPriv", MibName: "SNMPv2-MIB",
secLevel: "authNoPriv", OidText: "snmpTrapOID.0",
authProto: "SHA256",
authPass: "passpass",
trap: gosnmp.SnmpTrap{
Variables: []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.3.0",
Type: gosnmp.TimeTicks,
Value: now,
},
{
Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
Type: gosnmp.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
},
}, },
}, },
entries: []entry{ {
{ oid: ".1.3.6.1.6.3.1.1.5.1",
oid: ".1.3.6.1.6.3.1.1.4.1.0", e: snmp.MibEntry{
e: snmp.MibEntry{ MibName: "SNMPv2-MIB",
MibName: "SNMPv2-MIB", OidText: "coldStart",
OidText: "snmpTrapOID.0",
},
},
{
oid: ".1.3.6.1.6.3.1.1.5.1",
e: snmp.MibEntry{
MibName: "SNMPv2-MIB",
OidText: "coldStart",
},
},
{
oid: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{
MibName: "UNUSED_MIB_NAME",
OidText: "sysUpTimeInstance",
},
}, },
}, },
metrics: []telegraf.Metric{ {
testutil.MustMetric( oid: ".1.3.6.1.2.1.1.3.0",
"snmp_trap", // name e: snmp.MibEntry{
map[string]string{ // tags MibName: "UNUSED_MIB_NAME",
"oid": ".1.3.6.1.6.3.1.1.5.1", OidText: "sysUpTimeInstance",
"name": "coldStart", },
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
}, },
}, },
//ordinary v3 coldstart trap SHA384 auth and no priv metrics: []telegraf.Metric{
{ testutil.MustMetric(
name: "v3 coldStart authSha384NoPriv", "snmp_trap", // name
version: gosnmp.Version3, map[string]string{ // tags
secName: "authSha384NoPriv", "oid": ".1.3.6.1.6.3.1.1.5.1",
secLevel: "authNoPriv", "name": "coldStart",
authProto: "SHA384", "mib": "SNMPv2-MIB",
authPass: "passpass", "version": "3",
trap: gosnmp.SnmpTrap{ "source": "127.0.0.1",
Variables: []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.3.0",
Type: gosnmp.TimeTicks,
Value: now,
},
{
Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
Type: gosnmp.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
},
}, },
}, map[string]interface{}{ // fields
entries: []entry{ "sysUpTimeInstance": now,
},
fakeTime,
),
},
},
//ordinary v3 coldstart trap SHA256 auth and no priv
{
name: "v3 coldStart authSha256NoPriv",
version: gosnmp.Version3,
secName: "authSha256NoPriv",
secLevel: "authNoPriv",
authProto: "SHA256",
authPass: "passpass",
trap: gosnmp.SnmpTrap{
Variables: []gosnmp.SnmpPDU{
{ {
oid: ".1.3.6.1.6.3.1.1.4.1.0", Name: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{ Type: gosnmp.TimeTicks,
MibName: "SNMPv2-MIB", Value: now,
OidText: "snmpTrapOID.0",
},
}, },
{ {
oid: ".1.3.6.1.6.3.1.1.5.1", Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
e: snmp.MibEntry{ Type: gosnmp.ObjectIdentifier,
MibName: "SNMPv2-MIB", Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
OidText: "coldStart",
},
}, },
{
oid: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{
MibName: "UNUSED_MIB_NAME",
OidText: "sysUpTimeInstance",
},
},
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"snmp_trap", // name
map[string]string{ // tags
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
}, },
}, },
//ordinary v3 coldstart trap SHA512 auth and no priv entries: []entry{
{ {
name: "v3 coldStart authShaNoPriv", oid: ".1.3.6.1.6.3.1.1.4.1.0",
version: gosnmp.Version3, e: snmp.MibEntry{
secName: "authSha512NoPriv", MibName: "SNMPv2-MIB",
secLevel: "authNoPriv", OidText: "snmpTrapOID.0",
authProto: "SHA512",
authPass: "passpass",
trap: gosnmp.SnmpTrap{
Variables: []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.3.0",
Type: gosnmp.TimeTicks,
Value: now,
},
{
Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
Type: gosnmp.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
},
}, },
}, },
entries: []entry{ {
{ oid: ".1.3.6.1.6.3.1.1.5.1",
oid: ".1.3.6.1.6.3.1.1.4.1.0", e: snmp.MibEntry{
e: snmp.MibEntry{ MibName: "SNMPv2-MIB",
MibName: "SNMPv2-MIB", OidText: "coldStart",
OidText: "snmpTrapOID.0",
},
},
{
oid: ".1.3.6.1.6.3.1.1.5.1",
e: snmp.MibEntry{
MibName: "SNMPv2-MIB",
OidText: "coldStart",
},
},
{
oid: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{
MibName: "UNUSED_MIB_NAME",
OidText: "sysUpTimeInstance",
},
}, },
}, },
metrics: []telegraf.Metric{ {
testutil.MustMetric( oid: ".1.3.6.1.2.1.1.3.0",
"snmp_trap", // name e: snmp.MibEntry{
map[string]string{ // tags MibName: "UNUSED_MIB_NAME",
"oid": ".1.3.6.1.6.3.1.1.5.1", OidText: "sysUpTimeInstance",
"name": "coldStart", },
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
}, },
},*/ },
metrics: []telegraf.Metric{
testutil.MustMetric(
"snmp_trap", // name
map[string]string{ // tags
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
},
},
//ordinary v3 coldstart trap SHA384 auth and no priv
{
name: "v3 coldStart authSha384NoPriv",
version: gosnmp.Version3,
secName: "authSha384NoPriv",
secLevel: "authNoPriv",
authProto: "SHA384",
authPass: "passpass",
trap: gosnmp.SnmpTrap{
Variables: []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.3.0",
Type: gosnmp.TimeTicks,
Value: now,
},
{
Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
Type: gosnmp.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
},
},
},
entries: []entry{
{
oid: ".1.3.6.1.6.3.1.1.4.1.0",
e: snmp.MibEntry{
MibName: "SNMPv2-MIB",
OidText: "snmpTrapOID.0",
},
},
{
oid: ".1.3.6.1.6.3.1.1.5.1",
e: snmp.MibEntry{
MibName: "SNMPv2-MIB",
OidText: "coldStart",
},
},
{
oid: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{
MibName: "UNUSED_MIB_NAME",
OidText: "sysUpTimeInstance",
},
},
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"snmp_trap", // name
map[string]string{ // tags
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
},
},
//ordinary v3 coldstart trap SHA512 auth and no priv
{
name: "v3 coldStart authShaNoPriv",
version: gosnmp.Version3,
secName: "authSha512NoPriv",
secLevel: "authNoPriv",
authProto: "SHA512",
authPass: "passpass",
trap: gosnmp.SnmpTrap{
Variables: []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.3.0",
Type: gosnmp.TimeTicks,
Value: now,
},
{
Name: ".1.3.6.1.6.3.1.1.4.1.0", // SNMPv2-MIB::snmpTrapOID.0
Type: gosnmp.ObjectIdentifier,
Value: ".1.3.6.1.6.3.1.1.5.1", // coldStart
},
},
},
entries: []entry{
{
oid: ".1.3.6.1.6.3.1.1.4.1.0",
e: snmp.MibEntry{
MibName: "SNMPv2-MIB",
OidText: "snmpTrapOID.0",
},
},
{
oid: ".1.3.6.1.6.3.1.1.5.1",
e: snmp.MibEntry{
MibName: "SNMPv2-MIB",
OidText: "coldStart",
},
},
{
oid: ".1.3.6.1.2.1.1.3.0",
e: snmp.MibEntry{
MibName: "UNUSED_MIB_NAME",
OidText: "sysUpTimeInstance",
},
},
},
metrics: []telegraf.Metric{
testutil.MustMetric(
"snmp_trap", // name
map[string]string{ // tags
"oid": ".1.3.6.1.6.3.1.1.5.1",
"name": "coldStart",
"mib": "SNMPv2-MIB",
"version": "3",
"source": "127.0.0.1",
},
map[string]interface{}{ // fields
"sysUpTimeInstance": now,
},
fakeTime,
),
},
},
//ordinary v3 coldstart trap SHA auth and no priv //ordinary v3 coldstart trap SHA auth and no priv
{ {
name: "v3 coldStart authShaNoPriv", name: "v3 coldStart authShaNoPriv",