puresnmp_plugins.auth.hashbase module

This module provides common code for hashing based authentication.

class puresnmp_plugins.auth.hashbase.TIncoming(*args, **kwargs)

Bases: Protocol

Protocol for callables that authenticate incoming SNMP messages

class puresnmp_plugins.auth.hashbase.TOutgoing(*args, **kwargs)

Bases: Protocol

Protocol for callables that authenticate outgoing SNMP messages

puresnmp_plugins.auth.hashbase.for_incoming(hasher: Callable[[bytes, bytes], bytes], hmac_method: str) TIncoming

Create a new callable able to authenticate incoming messages.

Parameters:
  • hasher – A function used to apply a hashing algorithm.

  • hmac_method – The specific HMAC implementation to use

Returns:

A callable that can be used in a puresnmp authentication plugin

puresnmp_plugins.auth.hashbase.for_outgoing(hasher: Callable[[bytes, bytes], bytes], hmac_method: str) TOutgoing

Create a new callable able to authenticate outgoing messages.

Parameters:
  • hasher – A function used to apply a hashing algorithm.

  • hmac_method – The specific HMAC implementation to use

Returns:

A callable that can be used in a puresnmp authentication plugin

puresnmp_plugins.auth.hashbase.get_message_digest(hasher: Callable[[bytes, bytes], bytes], method: str, auth_key: bytes, encoded_message: bytes, engine_id: bytes) bytes

Calculate the digest for a given message.

Parameters:
  • hasher – A specific hash-implementation (f.ex.: hashlib.md5)

  • method – The digest-method to use

  • auth_key – The authentication key for the user

  • encoded_message – The SNMP message as bytes

  • engine_id – The ID of the receiving engine