Skip to content

gufo.snmp.user

User structure definition.

Aes128Key

Bases: BasePrivKey

AES-128 Key.

Aes192Key

Bases: BasePrivKey

AES-192 Key.

Aes256Key

Bases: BasePrivKey

AES-256 Key.

BaseAuthKey

Bases: BaseKey

Authentication key base class.

BaseKey

Basic key class.

Parameters:

Name Type Description Default
key bytes

Key value.

required
key_type KeyType

Key type.

Password

get_localized_key(master_key, engine_id) classmethod

Convert master key to localized key.

Parameters:

Name Type Description Default
master_key bytes

Master key, must have size according to algorithm.

required
engine_id bytes

SNMP engine id.

required

Returns:

Type Description
bytes

Localized key. Resulting length same as master_key.

get_master_key(passwd) classmethod

Convert password to master key.

Parameters:

Name Type Description Default
passwd bytes

Password

required

Returns:

Type Description
bytes

Master key. Resulting length depends on the algorithm.

snmpd_key()

Returns key and prefix for createUser.

BasePrivKey

Bases: BaseKey

Privacy key base class.

DesKey

Bases: BasePrivKey

Des Key.

KeyExpansion

Bases: IntEnum

Key expansion policy for AES-192/256 privacy keys.

Specifies how a localized authentication key is expanded when it is shorter than the key required by AES-192 or AES-256. This is relevant primarily for MD5 and SHA-1 authentication, whose localized keys are shorter than the required AES key.

Different SNMP implementations use different expansion schemes:

  • Blumenthal — Blumenthal AES-192/256 key expansion.
  • Cisco — Cisco/Reeder AES-192/256 key expansion.

The policy has no effect when the localized key is already long enough or when a different privacy protocol is used.

Attributes:

Name Type Description
Blumenthal

Use the Blumenthal key-expansion scheme.

Cisco

Use the Cisco/Reeder key-expansion scheme.

KeyType

Bases: IntEnum

Key type.

Attributes:

Name Type Description
Password

Raw password (least security).

Master

Master key (hashed password).

Localized

Localized key, mixed with engine id.

is_localized property

Check if key type is localized.

is_master property

Check if key type is a master.

is_password property

Check if key type is a password.

snmpd_option()

Get key option for snmpd.conf.

Returns:

Type Description
str

Key type prefix like -m, -l, ...

Md5Key

Bases: BaseAuthKey

MD5 Key.

Sha1Key

Bases: BaseAuthKey

SHA-1 Key.

Sha224Key

Bases: BaseAuthKey

SHA-224 Key.

Sha256Key

Bases: BaseAuthKey

SHA-256 Key.

Sha384Key

Bases: BaseAuthKey

SHA-384 Key.

Sha512Key

Bases: BaseAuthKey

SHA-512 Key.

User

SNMPv3 user.

Parameters:

Name Type Description Default
name str

user name.

required
auth_key BaseAuthKey | None

Optional authentication key.

None
priv_key BasePrivKey | None

Optional privacy key.

None
key_expansion KeyExpansion

Key expansion policy for AES-192/256 privacy keys.

Blumenthal

snmpd_create_user property

CreateUser part of snmpd.conf.

Returns:

Type Description
str

createUser configuration directive.

snmpd_rouser property

rouser part of snmpd.conf.

Returns:

Type Description
str

rouser configuration directive.

__repr__()

repr() implementation.

__str__()

str() implementation.

default() classmethod

Default user without name and keys.

Returns:

Type Description
User

Default user instance.

get_auth_alg()

Return the authentication algorithm index with the key type mask.

When the privacy key requires more key material than the authentication algorithm provides, the configured key expansion policy is encoded into the algorithm index.

Algorithm indexes:

  • 0 - No auth
  • 1 - MD5
  • 2 - MD5 with Blumenthal key expansion
  • 3 - MD5 with Cisco key expansion
  • 4 - SHA-1
  • 5 - SHA-1 with Blumenthal key expansion
  • 6 - SHA-1 with Cisco key expansion

The expansion policy only affects algorithms whose key is shorter than the selected privacy key.

Returns: Authentication algorithm index with the key type mask applied.

get_auth_key()

Authentication key.

get_priv_alg()

Privacy algorithm index.

Algorithms
  • 0 - No privacy
  • 1 - DES
  • 2 - AES-128
  • 3 - AES-192
  • 4 - AES-256

KeyType.mask applied

get_priv_key()

Privacy key.

require_auth()

Chech if user requires authentication.

Returns:

Type Description
bool

True, if user requires authetication