RFC 2264

User-based Security Model (USM) for version 3 of the Simple Network Management Protocol (SNMPv3)

๐Ÿ“… published January 1998, from ietf

RFC 2264: User-based Security Model (USM) for version 3 of the Simple Network Management Protocol (SNMPv3) ๐ŸŽ€

okay bestie, RFC 2264 is giving foundational SNMP security ๐Ÿ”โœจ. It's a Standards Track doc dated January 1998, written by U. Blumenthal and B. Wijnen, both from IBM T. J. Watson Research ๐Ÿ’…. Nothing in the title block says it obsoletes or updates anything, so it's not replacing or patching an older spec.

Status of This Memo

This document specifies an Internet standards track protocol for the Internet community, and requests discussion and suggestions for improvements. Please refer to the current edition of the "Internet Official Protocol Standards" (STD 1) for the standardization state and status of this protocol. Distribution of this memo is unlimited. ๐Ÿ“œ

Copyright (C) The Internet Society (1997). All Rights Reserved. ยฉ๏ธ๐ŸŒธ

Abstract

okay so this doc describes the User-based Security Model (USM) for SNMP version 3, which is meant for use in the SNMP architecture [RFC2261] ๐Ÿฆ‹. It defines the Elements of Procedure for providing SNMP message level security, and it also includes a MIB for remotely monitoring and managing the configuration parameters for this Security Model. main character energy, honestly ๐Ÿ‘‘.

Table of Contents โœจ

1.  Introduction                                                       3
1.1.  Threats                                                          4
1.2.  Goals and Constraints                                            5
1.3.  Security Services                                                6
1.4.  Module Organization                                              7
1.4.1.  Timeliness Module                                              7
1.4.2.  Authentication Protocol                                        8
1.4.3.  Privacy Protocol                                               8
1.5.  Protection against Message Replay, Delay and Redirection         8
1.5.1.  Authoritative SNMP engine                                      8
1.5.2.  Mechanisms                                                     8
1.6.  Abstract Service Interfaces.                                    10
1.6.1.  User-based Security Model Primitives for Authentication       11
1.6.2.  User-based Security Model Primitives for Privacy              11
2.  Elements of the Model                                             12
2.1.  User-based Security Model Users                                 12
2.2.  Replay Protection                                               13
2.2.1.  msgAuthoritativeEngineID                                      13
2.2.2.  msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime    14
2.2.3.  Time Window                                                   15
2.3.  Time Synchronization                                            15
2.4.  SNMP Messages Using this Security Model                         16
2.5.  Services provided by the User-based Security Model              17
2.5.1.  Services for Generating an Outgoing SNMP Message              17
2.5.2.  Services for Processing an Incoming SNMP Message              19
2.6.  Key Localization Algorithm.                                     21
3.  Elements of Procedure                                             21
3.1.  Generating an Outgoing SNMP Message                             22
3.2.  Processing an Incoming SNMP Message                             25
4.  Discovery                                                         30
5.  Definitions                                                       31
6.  HMAC-MD5-96 Authentication Protocol                               45
6.1.  Mechanisms                                                      45
6.1.1.  Digest Authentication Mechanism                               46
6.2.  Elements of the Digest Authentication Protocol                  46
6.2.1.  Users                                                         46
6.2.2.  msgAuthoritativeEngineID                                      47
6.2.3.  SNMP Messages Using this Authentication Protocol              47
6.2.4.  Services provided by the HMAC-MD5-96 Authentication Module    47
6.2.4.1.  Services for Generating an Outgoing SNMP Message            47
6.2.4.2.  Services for Processing an Incoming SNMP Message            48
6.3.  Elements of Procedure                                           49
6.3.1.  Processing an Outgoing Message                                49
6.3.2.  Processing an Incoming Message                                50
7.  HMAC-SHA-96 Authentication Protocol                               51
7.1.  Mechanisms                                                      51
7.1.1.  Digest Authentication Mechanism                               51
7.2.  Elements of the HMAC-SHA-96 Authentication Protocol             52
7.2.1.  Users                                                         52
7.2.2.  msgAuthoritativeEngineID                                      52
7.2.3.  SNMP Messages Using this Authentication Protocol              53
7.2.4.  Services provided by the HMAC-SHA-96 Authentication Module    53
7.2.4.1.  Services for Generating an Outgoing SNMP Message            53
7.2.4.2.  Services for Processing an Incoming SNMP Message            54
7.3.  Elements of Procedure                                           54
7.3.1.  Processing an Outgoing Message                                55
7.3.2.  Processing an Incoming Message                                55
8.  CBC-DES Symmetric Encryption Protocol                             56
8.1.  Mechanisms                                                      56
8.1.1.  Symmetric Encryption Protocol                                 57
8.1.1.1.  DES key and Initialization Vector.                          57
8.1.1.2.  Data Encryption.                                            58
8.1.1.3.  Data Decryption                                             59
8.2.  Elements of the DES Privacy Protocol                            59
8.2.1.  Users                                                         59
8.2.2.  msgAuthoritativeEngineID                                      59
8.2.3.  SNMP Messages Using this Privacy Protocol                     60
8.2.4.  Services provided by the DES Privacy Module                   60
8.2.4.1.  Services for Encrypting Outgoing Data                       60
8.2.4.2.  Services for Decrypting Incoming Data                       61
8.3.  Elements of Procedure.                                          61
8.3.1.  Processing an Outgoing Message                                61
8.3.2.  Processing an Incoming Message                                62
9.  Intellectual Property                                             62
10. Acknowledgements                                                  63
11. Security Considerations                                           64
11.1. Recommended Practices                                           64
11.2. Defining Users                                                  66
11.3. Conformance                                                     67
12. References                                                        67
13. Editors' Addresses                                                69
A.1.  SNMP engine Installation Parameters                             70
A.2.  Password to Key Algorithm                                       71
A.2.1.  Password to Key Sample Code for MD5                           71
A.2.2.  Password to Key Sample Code for SHA                           72
A.3.  Password to Key Sample Results                                  73
A.3.1.  Password to Key Sample Results using MD5                      73
A.3.2.  Password to Key Sample Results using SHA                      74
A.4.  Sample encoding of msgSecurityParameters                        74
B.  Full Copyright Statement                                          76

1. Introduction โœจ

okay so the Architecture for describing Internet Management Frameworks [RFC2261] says that an SNMP engine is made up of four pieces ๐Ÿงš:

  1. a Dispatcher
  2. a Message Processing Subsystem,
  3. a Security Subsystem, and
  4. an Access Control Subsystem.

Applications use the services of these subsystems ๐Ÿ’–.

It's really important to get the SNMP architecture and its terminology down, so you can see where the Security Model in this doc fits in and how it talks to the other subsystems ๐Ÿซถ. The reader is expected to have already read and understood the SNMP architecture as defined in [RFC2261], so no skipping that one bestie ๐Ÿ™ˆ.

This memo [RFC2264] describes the User-based Security Model as it's used inside the SNMP Architecture. The big idea is that we use the traditional concept of a user (identified by a userName) and attach security information to that user ๐ŸŽ€.

This memo describes using HMAC-MD5-96 and HMAC-SHA-96 as the authentication protocols, and CBC-DES as the privacy protocol ๐Ÿ”ฅ. The User-based Security Model does allow other protocols to be used instead of these, or alongside them ๐ŸŒˆ. So HMAC-MD5-96, HMAC-SHA-96 and CBC-DES each get their own self-contained sections, which means they can be swapped out or supplemented later on ๐Ÿฆ‹.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119] ๐Ÿ’œ.

1.1. Threats ๐Ÿ•ต๏ธโ€โ™€๏ธ

okay so bestie, a bunch of the classic network-protocol threats totally apply to network management, which means they'd apply to any SNMP Security Model too. Other threats just don't fit the network management problem, so we can skip those. This section covers the principal threats, the secondary threats, and the ones that matter less. ๐Ÿ’…

The principal threats this SNMP Security Model SHOULD protect against are:

  • Modification of Information The modification threat is the danger that some unauthorized entity may alter in-transit SNMP messages generated on behalf of an authorized user in such a way as to effect unauthorized management operations, including falsifying the value of an object. ๐Ÿ˜ค
  • Masquerade The masquerade threat is the danger that management operations not authorized for some user may be attempted by assuming the identity of another user that has the appropriate authorizations. ๐ŸŽญ

Two secondary threats are also identified. The Security Model defined in this memo provides limited protection against:

  • Disclosure The disclosure threat is the danger of eavesdropping on the exchanges between managed agents and a management station. Protecting against this threat may be required as a matter of local policy. ๐Ÿ‘€
  • Message Stream Modification The SNMP protocol is typically based upon a connection-less transport service which may operate over any sub-network service. The re-ordering, delay or replay of messages can and does occur through the natural operation of many such sub-network services. The message stream modification threat is the danger that messages may be maliciously re-ordered, delayed or replayed to an extent which is greater than can occur through the natural operation of a sub-network service, in order to effect unauthorized management operations. ๐ŸŒ€

There are at least two threats that an SNMP Security Model need not protect against. The security protocols defined in this memo do not provide protection against:

  • Denial of Service This SNMP Security Model does not attempt to address the broad range of attacks by which service on behalf of authorized users is denied. Indeed, such denial-of-service attacks are in many cases indistinguishable from the type of network failures with which any viable network management protocol must cope as a matter of course. ๐Ÿ™ƒ
  • Traffic Analysis This SNMP Security Model does not attempt to address traffic analysis attacks. Indeed, many traffic patterns are predictable (devices may be managed on a regular basis by a relatively small number of management applications), and therefore there is no significant advantage afforded by protecting against traffic analysis. ๐Ÿ“Š

1.2. Goals and Constraints ๐ŸŽฏ

Based on everything we just covered about threats in the SNMP network management environment, the goals of this SNMP Security Model are as follows.

  1. Provide for verification that each received SNMP message has not been modified during its transmission through the network. โœ…
  2. Provide for verification of the identity of the user on whose behalf a received SNMP message claims to have been generated. ๐Ÿชช
  3. Provide for detection of received SNMP messages, which request or contain management information, whose time of generation was not recent. โฐ
  4. Provide, when necessary, that the contents of each received SNMP message are protected from disclosure. ๐Ÿ”’

Besides the main goal of supporting secure network management, the design of this SNMP Security Model is also shaped by the following constraints.

  1. When the requirements of effective management in times of network stress are inconsistent with those of security, the design should prefer the former. ๐ŸŒช๏ธ
  2. Neither the security protocol nor its underlying security mechanisms should depend upon the ready availability of other network services (e.g., Network Time Protocol (NTP) or key management protocols). ๐Ÿง˜โ€โ™€๏ธ
  3. A security mechanism should entail no changes to the basic SNMP network management philosophy. ๐Ÿ’–

1.3. Security Services ๐Ÿ›ก๏ธ

The security services needed to support the goals of this SNMP Security Model are as follows.

  • Data Integrity is the provision of the property that data has not been altered or destroyed in an unauthorized manner, nor have data sequences been altered to an extent greater than can occur non-maliciously. ๐Ÿงฉ
  • Data Origin Authentication is the provision of the property that the claimed identity of the user on whose behalf received data was originated is corroborated. ๐Ÿซก
  • Data Confidentiality is the provision of the property that information is not made available or disclosed to unauthorized individuals, entities, or processes. ๐Ÿคซ
  • Message timeliness and limited replay protection is the provision of the property that a message whose generation time is outside of a specified time window is not accepted. Note that message reordering is not dealt with and can occur in normal conditions too. โŒ›

For the protocols specified in this memo, it is not possible to assure the specific originator of a received SNMP message. Instead, it is the user on whose behalf the message was originated that is authenticated. ๐ŸŽ€

For these protocols, it is not possible to obtain data integrity without data origin authentication, nor is it possible to obtain data origin authentication without data integrity. Further, there is no provision for data confidentiality without both data integrity and data origin authentication. ๐Ÿ”—

The security protocols used in this memo are considered acceptably secure at the time of writing. However, the procedures allow for new authentication and privacy methods to be specified at a future time if the need arises. ๐Ÿ”ฎ


1.4. Module Organization ๐Ÿงฉ

The security protocols defined in this memo are split into three different modules. Each one has its own specific responsibilities, and together they realize the goals and security services described above. ๐Ÿ“

  • The authentication module MUST provide for:
    • Data Integrity,
    • Data Origin Authentication
  • The timeliness module MUST provide for:
    • Protection against message delay or replay (to an extent greater than can occur through normal operation)

The privacy module MUST provide for

  • Protection against disclosure of the message payload.

The timeliness module is fixed for the User-based Security Model, while there is provision for multiple authentication and/or privacy modules. Each of those implements a specific authentication or privacy protocol, respectively. ๐Ÿงš

1.4.1. Timeliness Module โณ

Section 3 (Elements of Procedure) uses the timeliness values in an SNMP message to do timeliness checking. The timeliness check is only performed if authentication is applied to the message. Since the complete message is checked for integrity, we can assume that the timeliness values in a message that passes the authentication module are trustworthy. ๐Ÿ’ฏ

1.4.2. Authentication Protocol ๐Ÿ”‘

Section 6 describes the HMAC-MD5-96 authentication protocol, which is the first authentication protocol that MUST be supported with the User-based Security Model. Section 7 describes the HMAC-SHA-96 authentication protocol, which is another authentication protocol that SHOULD be supported with the User-based Security Model. In the future, additional or replacement authentication protocols may be defined as new needs arise. ๐ŸŒŸ

The User-based Security Model prescribes that, if authentication is used, then the complete message is checked for integrity in the authentication module. ๐Ÿ”

For a message to be authenticated, it needs to pass the authentication check by the authentication module and the timeliness check, which is a fixed part of this User-based Security Model. โœ…

1.4.3. Privacy Protocol ๐Ÿ™ˆ

Section 8 describes the CBC-DES Symmetric Encryption Protocol, which is the first privacy protocol to be used with the User-based Security Model. In the future, additional or replacement privacy protocols may be defined as new needs arise. ๐Ÿฆ‹

The User-based Security Model prescribes that the scopedPDU is protected from disclosure when a message is sent with privacy. ๐Ÿซฃ

The User-based Security Model also prescribes that a message needs to be authenticated if privacy is in use. ๐Ÿ’œ


1.5. Protection against Message Replay, Delay and Redirection ๐Ÿ”

1.5.1. Authoritative SNMP engine ๐Ÿ‘‘

In order to protect against message replay, delay and redirection, one of the SNMP engines involved in each communication is designated to be the authoritative SNMP engine. When an SNMP message contains a payload which expects a response (for example a Get, GetNext, GetBulk, Set or Inform PDU), then the receiver of such messages is authoritative. When an SNMP message contains a payload which does not expect a response (for example an SNMPv2-Trap, Response or Report PDU), then the sender of such a message is authoritative. ๐ŸŒธ

1.5.2. Mechanisms โœจ

okay so here's how they actually pull it off ๐Ÿฆ‹

  1. Okay bestie, first up ๐Ÿ•ฐ๏ธ we want to stop delayed or replayed messages from sneaking in, and I mean delays and replays way beyond what normal network lag could explain. So every message carries a set of timeliness indicators for the authoritative SNMP engine. An SNMP engine checks them to see if a received message is recent. It may also check that a message is at least as recent as the last message it got from that same source. A non-authoritative SNMP engine uses received authentic messages to advance its notion of the timeliness indicators at the remote authoritative source.

An SNMP engine MUST also use a mechanism to match incoming Responses to outstanding Requests, and it MUST drop any Responses that do not match an outstanding request. For example, a msgID can be inserted in every message to cater for this functionality. ๐Ÿงš

These mechanisms let you detect authenticated messages whose time of generation was not recent. Main character energy ๐Ÿ’…

This protection against delay or replay does not imply nor provide any protection against unauthorized deletion or suppression of messages. Also, an SNMP engine may not be able to detect message reordering if all the messages involved are sent within the Time Window interval. Other mechanisms defined independently of the security protocol can also be used to detect the re-ordering, replay, deletion, or suppression of messages containing Set operations (e.g., the MIB variable snmpSetSerialNo [RFC1907]). ๐Ÿ™ˆ

  1. Verification that a message sent to/from one authoritative SNMP engine cannot be replayed to/as-if-from another authoritative SNMP engine ๐Ÿ”

Included in each message is an identifier unique to the authoritative SNMP engine associated with the sender or intended recipient of the message.

A Report, Response or Trap message sent by an authoritative SNMP engine to one non-authoritative SNMP engine can potentially be replayed to another non-authoritative SNMP engine. The latter non-authoritative SNMP engine might (if it knows about the same userName with the same secrets at the authoritative SNMP engine) as a result update its notion of timeliness indicators of the authoritative SNMP engine, but that is not considered a threat. In this case, A Report or Response message will be discarded by the Message Processing Model, because there should not be an outstanding Request message. A Trap will possibly be accepted. Again, that is not considered a threat, because the communication was authenticated and timely. It is as if the authoritative SNMP engine was configured to start sending Traps to the second SNMP engine, which theoretically can happen without the knowledge of the second SNMP engine anyway. Anyway, the second SNMP engine may not expect to receive this Trap, but is allowed to see the management information contained in it. Honestly, this one's giving "it's not a threat, it's just a vibe" ๐Ÿซ 

  1. Detection of messages which were not recently generated โณ

A set of time indicators are included in the message, indicating the time of generation. Messages without recent time indicators are not considered authentic. In addition, an SNMP engine MUST drop any Responses that do not match an outstanding request. This however is the responsibility of the Message Processing Model.

This memo allows the same user to be defined on multiple SNMP engines ๐Ÿ‘ฏโ€โ™€๏ธ Each SNMP engine keeps a value called snmpEngineID, which uniquely identifies that SNMP engine. This value is included in each message sent to/from the SNMP engine that is authoritative (see section 1.5.1). When a message arrives, an authoritative SNMP engine checks the value to make sure it's the intended recipient, and a non-authoritative SNMP engine uses the value to make sure the message gets processed with the correct state information.

Each SNMP engine maintains two values, snmpEngineBoots and snmpEngineTime, which taken together give an indication of time at that SNMP engine โฐ Both of these values are included in an authenticated message sent to/received from that SNMP engine. On receipt, the values are checked to make sure the indicated timeliness value is within a Time Window of the current time. The Time Window is an administrative upper bound on acceptable delivery delay for protocol messages. Think of it as the cutoff for "this is too late, bestie" ๐Ÿšซ

For an SNMP engine to generate a message which an authoritative SNMP engine will accept as authentic, and to verify that a message received from that authoritative SNMP engine is authentic, such an SNMP engine must first achieve timeliness synchronization with the authoritative SNMP engine. See section 2.3. ๐Ÿซถ

1.6. Abstract Service Interfaces โœจ

Abstract service interfaces have been defined to describe the conceptual interfaces between the various subsystems within an SNMP entity. Similarly, a set of abstract service interfaces have been defined within the User-based Security Model (USM) to describe the conceptual interfaces between the generic USM services and the self-contained authentication and privacy services. It's giving layers, layers, and more layers ๐Ÿง

These abstract service interfaces are defined by a set of primitives that define the services provided and the abstract data elements that must be passed when the services are invoked. This section lists the primitives that have been defined for the User-based Security Model. ๐Ÿ“‹

1.6.1. User-based Security Model Primitives for Authentication ๐Ÿ”‘

The User-based Security Model provides the following internal primitives to pass data back and forth between the Security Model itself and the authentication service:

statusInformation =
  authenticateOutgoingMsg(
  IN   authKey                   -- secret key for authentication
  IN   wholeMsg                  -- unauthenticated complete message
  OUT  authenticatedWholeMsg     -- complete authenticated message
       )

statusInformation =
  authenticateIncomingMsg(
  IN   authKey                   -- secret key for authentication
  IN   authParameters            -- as received on the wire
  IN   wholeMsg                  -- as received on the wire
  OUT  authenticatedWholeMsg     -- complete authenticated message
       )

1.6.2. User-based Security Model Primitives for Privacy ๐Ÿ”’

The User-based Security Model provides the following internal primitives to pass data back and forth between the Security Model itself and the privacy service:

statusInformation =
  encryptData(
  IN    encryptKey               -- secret key for encryption
  IN    dataToEncrypt            -- data to encrypt (scopedPDU)
  OUT   encryptedData            -- encrypted data (encryptedPDU)
  OUT   privParameters           -- filled in by service provider
        )

statusInformation =
  decryptData(
  IN    decryptKey               -- secret key for decrypting
  IN    privParameters           -- as received on the wire
  IN    encryptedData            -- encrypted data (encryptedPDU)
  OUT   decryptedData            -- decrypted data (scopedPDU)
           )

2. Elements of the Model ๐Ÿงฉ

This section contains definitions required to realize the security model defined by this memo. Let's get into the nitty gritty ๐Ÿ’œ

2.1. User-based Security Model Users ๐Ÿ‘ค

Management operations using this Security Model make use of a defined set of user identities. For any user on whose behalf management operations are authorized at a particular SNMP engine, that SNMP engine must have knowledge of that user. An SNMP engine that wishes to communicate with another SNMP engine must also have knowledge of a user known to that engine, including knowledge of the applicable attributes of that user.

A user and its attributes are defined as follows:

  • userName: A string representing the name of the user.
  • securityName: A human-readable string representing the user in a format that is Security Model independent.
  • authProtocol: An indication of whether messages sent on behalf of this user can be authenticated, and if so, the type of authentication protocol which is used. Two such protocols are defined in this memo:
    • the HMAC-MD5-96 authentication protocol.
    • the HMAC-SHA-96 authentication protocol.
  • authKey: If messages sent on behalf of this user can be authenticated, the (private) authentication key for use with the authentication protocol. Note that a user's authentication key will normally be different at different authoritative SNMP engines. The authKey is not accessible via SNMP. The length requirements of the authKey are defined by the authProtocol in use. ๐Ÿคซ
  • authKeyChange and authOwnKeyChange: The only way to remotely update the authentication key. Does that in a secure manner, so that the update can be completed without the need to employ privacy protection. ๐Ÿ”„
  • privProtocol: An indication of whether messages sent on behalf of this user can be protected from disclosure, and if so, the type of privacy protocol which is used. One such protocol is defined in this memo: the CBC-DES Symmetric Encryption Protocol.
  • privKey: If messages sent on behalf of this user can be en/decrypted, the (private) privacy key for use with the privacy protocol. Note that a user's privacy key will normally be different at different authoritative SNMP engines. The privKey is not accessible via SNMP. The length requirements of the privKey are defined by the privProtocol in use. ๐Ÿ—๏ธ
  • privKeyChange and privOwnKeyChange: The only way to remotely update the encryption key. Does that in a secure manner, so that the update can be completed without the need to employ privacy protection. ๐Ÿ’Œ

2.2. Replay Protection ๐Ÿ”

Each SNMP engine maintains three objects:

  • snmpEngineID, which (at least within an administrative domain) uniquely and unambiguously identifies an SNMP engine.
  • snmpEngineBoots, which is a count of the number of times the SNMP engine has re-booted/re-initialized since snmpEngineID was last configured; and,
  • snmpEngineTime, which is the number of seconds since the snmpEngineBoots counter was last incremented.

Each SNMP engine is always authoritative with respect to these objects in its own SNMP entity. It is the responsibility of a non-authoritative SNMP engine to synchronize with the authoritative SNMP engine, as appropriate. ๐Ÿค

An authoritative SNMP engine is required to maintain the values of its snmpEngineID and snmpEngineBoots in non-volatile storage. Those two need to survive a reboot, so no cheating with RAM only ๐Ÿ’พ

2.2.1. msgAuthoritativeEngineID ๐Ÿชช

The msgAuthoritativeEngineID value contained in an authenticated message is used to defeat attacks in which messages from one SNMP engine to another SNMP engine are replayed to a different SNMP engine. It represents the snmpEngineID at the authoritative SNMP engine involved in the exchange of the message. Basically it's the ID card that stops messages from getting passed off to the wrong engine ๐Ÿšซ๐Ÿช„

When an authoritative SNMP engine is first installed, it sets its local value of snmpEngineID according to a enterprise-specific algorithm (see the definition of the Textual Convention for SnmpEngineID in the SNMP Architecture document [RFC2261]).

2.2.2. msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime โœจ

okay so msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime are the fields that stop replay attacks, where somebody grabs an old authenticated message and tries to send it again after it's already expired ๐Ÿ™…. They carry the snmpEngineBoots and snmpEngineTime values from the authoritative SNMP engine that's part of the exchange ๐Ÿ•ฐ๏ธ

Here's the lowkey genius part ๐Ÿ’… An SNMP engine does NOT need a clock that keeps ticking while it's powered off ๐Ÿ”ŒโŒ. Instead, every time an engine reboots, it grabs snmpEngineBoots, adds one to it, saves that to non-volatile storage, and resets snmpEngineTime to zero. No fancy hardware needed, bestie ๐Ÿงš

When an SNMP engine is first installed, both snmpEngineBoots and snmpEngineTime get set to zero ๐ŸŒฑ If snmpEngineTime ever hits its max value of 2147483647, then snmpEngineBoots goes up as if the engine rebooted, snmpEngineTime resets to zero, and it starts counting up again ๐Ÿ”„

Every time an authoritative SNMP engine reboots, any SNMP engines that are holding its snmpEngineBoots and snmpEngineTime values need to re-synchronize before they send correctly authenticated messages to it. Check Section 2.3 for the (re-)synchronization steps ๐Ÿค Also, the procedures do allow a notification to be accepted as authentic by a receiving SNMP engine when it was sent by an authoritative SNMP engine that has rebooted since the receiver last (re-)synchronized. Not me being impressed ๐Ÿ˜ญ

If an authoritative SNMP engine is ever unable to figure out its latest snmpEngineBoots value, then it MUST set snmpEngineBoots to 2147483647. ๐Ÿšจ

Once the local value of snmpEngineBoots sits at 2147483647, it latches there forever, and any authenticated message will always cause a notInTimeWindow authentication failure ๐Ÿ’€

Warning, bestie: an engine stuck at 2147483647 can't just be fixed remotely. Manual intervention is REQUIRED. Someone has to physically visit the engine and reconfigure it, either with a new snmpEngineID value or with new secret values for the authentication and privacy protocols of every user known to that SNMP engine. ๐Ÿ› ๏ธ

Also, even if an SNMP engine rebooted once a second, it would still take about 68 years to reach the max value of 2147483647. That's giving long-term stability ๐Ÿฆ‹


2.2.3. Time Window ๐ŸŒธ

The Time Window is the window of time in which a message generated on behalf of any user is valid โฐ This memo says the exact same Time Window, 150 seconds, is used for ALL users, so nobody gets special treatment ๐Ÿ‘‘


2.3. Time Synchronization ๐Ÿซถ

Time synchronization is REQUIRED for a non-authoritative SNMP engine before it can proceed with authentic communications. It's considered done once the non-authoritative engine has gotten its own local copy of the authoritative SNMP engine's snmpEngineBoots and snmpEngineTime values from that authoritative engine ๐Ÿ“ฅ Those values MUST be (and REMAIN) within the authoritative SNMP engine's Time Window, so the local copy has to stay loosely synced with what's actually stored at the authoritative engine โณ

On top of keeping those copies, a non-authoritative SNMP engine MUST also keep one more local variable, latestReceivedEngineTime ๐Ÿง  This records the highest snmpEngineTime value it has ever received from the authoritative engine. It's what stops someone from replaying messages to freeze the non-authoritative engine's idea of snmpEngineTime so it never moves forward ๐Ÿšซ

A non-authoritative SNMP engine MUST keep local copies of these values for EACH authoritative SNMP engine it wants to talk to ๐Ÿ’œ Since every authoritative SNMP engine is uniquely and unambiguously identified by its snmpEngineID, the non-authoritative engine MAY use that value as a key to cache its local copies ๐Ÿ—๏ธ

Time synchronization happens as part of the procedure for receiving an SNMP message (Section 3.2, step 7b). So no explicit time synchronization procedure is REQUIRED for a non-authoritative SNMP engine. Just know that whenever the local value of snmpEngineID changes (for example, through discovery), or whenever secure communications are first set up with an authoritative SNMP engine, the local values of snmpEngineBoots and latestReceivedEngineTime SHOULD be set to zero. That makes time synchronization happen when the next authentic message arrives ๐ŸŽ€


2.4. SNMP Messages Using this Security Model ๐Ÿ’–

An SNMP message using this Security Model follows the message format defined in the version-specific Message Processing Model document (for example, [RFC2262]) ๐Ÿ“จ

The msgSecurityParameters field in SNMPv3 messages is an OCTET STRING. Its value is the BER serialization of the ASN.1 sequence below ๐Ÿง

USMSecurityParametersSyntax DEFINITIONS IMPLICIT TAGS ::= BEGIN

   UsmSecurityParameters ::=
       SEQUENCE {
        -- global User-based security parameters
           msgAuthoritativeEngineID     OCTET STRING,
           msgAuthoritativeEngineBoots  INTEGER (0..2147483647),
           msgAuthoritativeEngineTime   INTEGER (0..2147483647),
           msgUserName                  OCTET STRING (SIZE(1..32)),
        -- authentication protocol specific parameters
           msgAuthenticationParameters  OCTET STRING,
        -- privacy protocol specific parameters
           msgPrivacyParameters         OCTET STRING
       }
END

Here's what each field in that sequence does ๐Ÿ‘‡

  • msgAuthoritativeEngineID tells you the snmpEngineID of the authoritative SNMP engine in the exchange ๐Ÿชช
  • msgAuthoritativeEngineBoots tells you the snmpEngineBoots value at that authoritative engine ๐Ÿ”
  • msgAuthoritativeEngineTime tells you the snmpEngineTime value at that authoritative engine โŒš
  • msgUserName says which user (principal) the message is being exchanged on behalf of ๐Ÿ‘ค
  • msgAuthenticationParameters are defined by whatever authentication protocol the message uses, as set in the usmUserAuthProtocol column of that user's entry in the usmUserTable ๐Ÿ”
  • msgPrivacyParameters are defined by whatever privacy protocol the message uses, as set in the usmUserPrivProtocol column of that user's entry in the usmUserTable) ๐Ÿ™ˆ

See appendix A.4 for an example of the BER encoding of the msgSecurityParameters field โœจ


2.5. Services provided by the User-based Security Model ๐Ÿฆ‹

This section covers the services the User-based Security Model provides, along with their inputs and outputs ๐Ÿ’…

The services are written up as primitives of an abstract service interface, and their inputs and outputs are written up as abstract data elements that get passed around in those abstract service primitives ๐Ÿงš

2.5.1. Services for Generating an Outgoing SNMP Message โœจ

okay so when the Message Processing (MP) Subsystem asks the User-based Security module to secure an outgoing SNMP message, it must use the right service that the Security module provides ๐Ÿ’…. there are two of these, bestie:

  1. A service to generate a Request message ๐ŸŽ€. the abstract service primitive looks like this:
statusInformation =            -- success or errorIndication
  generateRequestMsg(
  IN   messageProcessingModel  -- typically, SNMP version
  IN   globalData              -- message header, admin data
  IN   maxMessageSize          -- of the sending SNMP entity
  IN   securityModel           -- for the outgoing message
  IN   securityEngineID        -- authoritative SNMP entity
  IN   securityName            -- on behalf of this principal
  IN   securityLevel           -- Level of Security requested
  IN   scopedPDU               -- message (plaintext) payload
  OUT  securityParameters      -- filled in by Security Module
  OUT  wholeMsg                -- complete generated message
  OUT  wholeMsgLength          -- length of generated message
       )
  1. A service to generate a Response message ๐Ÿฆ‹. the abstract service primitive looks like this:
statusInformation =            -- success or errorIndication
  generateResponseMsg(
  IN   messageProcessingModel  -- typically, SNMP version
  IN   globalData              -- message header, admin data
  IN   maxMessageSize          -- of the sending SNMP entity
  IN   securityModel           -- for the outgoing message
  IN   securityEngineID        -- authoritative SNMP entity
  IN   securityName            -- on behalf of this principal
  IN   securityLevel           -- Level of Security requested
  IN   scopedPDU               -- message (plaintext) payload
  IN   securityStateReference  -- reference to security state
                               -- information from original
                               -- request
  OUT  securityParameters      -- filled in by Security Module
  OUT  wholeMsg                -- complete generated message
  OUT  wholeMsgLength          -- length of generated message
       )

the abstract data elements passed as parameters in these primitives work like this ๐ŸŒธ:

  • statusInformation: tells you whether encoding and securing the message was successful. if it wasn't, it tells you what the problem was.
  • essageProcessingModel: the SNMP version number for the message to be generated. the User-based Security module doesn't use this one ๐Ÿ™ˆ.
  • globalData: the message header, aka its administrative info. the User-based Security module doesn't use this either.
  • maxMessageSize: the maximum message size, as included in the message, of the sending SNMP entity. not used by the User-based Security module.
  • securityParameters: the security parameters. these get filled in by the User-based Security module.
  • securityModel: the securityModel in use. it should be the User-based Security Model. the User-based Security module doesn't use this data.
  • securityName: together with the snmpEngineID, it identifies a row in the usmUserTable that gets used for securing the message. the securityName has a format that doesn't depend on the Security Model. for a response this parameter is ignored and the value from the cache is used instead ๐Ÿงš.
  • securityLevel: the Level of Security. the User-based Security module uses it to figure out whether the message needs protecting from disclosure and whether it needs authenticating. for a response this is ignored and the cached value is used.
  • securityEngineID: the snmpEngineID of the authoritative SNMP engine a Request message is going to. for a response it's implied to be the processing SNMP engine's snmpEngineID, so if you do specify it, it gets ignored ๐Ÿ’….
  • scopedPDU: the message payload. the data is opaque as far as the User-based Security Model is concerned ๐Ÿซถ.
  • securityStateReference: a handle/reference to cachedSecurityData that gets used when securing an outgoing Response message. it's the exact same handle/reference the User-based Security module generated when it processed the incoming Request this Response answers. iconic, right? ๐Ÿ‘‘
  • wholeMsg: the fully encoded and secured message, ready to go out on the wire ๐Ÿš€.
  • wholeMsgLength: the length of the encoded and secured message (wholeMsg).

when the process is done, the User-based Security module returns statusInformation. if it worked, you get the completed message with privacy and authentication applied, as long as the specified securityLevel asked for them โœจ. if it didn't work, you get an errorIndication ๐Ÿ˜ญ.

2.5.2. Services for Processing an Incoming SNMP Message ๐Ÿ”

so, when the Message Processing (MP) Subsystem asks the User-based Security module to check that an incoming message is secure, it must use the service that's provided for incoming messages. the abstract service primitive is:

statusInformation =             -- errorIndication or success
                                -- error counter OID/value if error
  processIncomingMsg(
  IN   messageProcessingModel   -- typically, SNMP version
  IN   maxMessageSize           -- of the sending SNMP entity
  IN   securityParameters       -- for the received message
  IN   securityModel            -- for the received message
  IN   securityLevel            -- Level of Security
  IN   wholeMsg                 -- as received on the wire
  IN   wholeMsgLength           -- length as received on the wire
  OUT  securityEngineID         -- authoritative SNMP entity
  OUT  securityName             -- identification of the principal
  OUT  scopedPDU,               -- message (plaintext) payload
  OUT  maxSizeResponseScopedPDU -- maximum size of the Response PDU
  OUT  securityStateReference   -- reference to security state
       )                        -- information, needed for response

the abstract data elements passed as parameters in these primitives work like this ๐ŸŒท:

  • statusInformation: tells you whether the process was successful. if it wasn't, the statusInformation includes the OID and the value of the error counter that got incremented ๐Ÿ™ƒ.
  • messageProcessingModel: the SNMP version number as received in the message. the User-based Security module doesn't use this.
  • maxMessageSize: the maximum message size, as included in the message. the User-based Security module uses this value to calculate the maxSizeResponseScopedPDU ๐Ÿงฎ.
  • securityParameters: the security parameters, exactly as they were received in the message.
  • securityModel: the securityModel in use. it should be the User-based Security Model. the User-based Security module doesn't use this data.
  • securityLevel: the Level of Security. the User-based Security module uses it to figure out whether the message needs protecting from disclosure and whether it needs authenticating ๐Ÿ”.
  • wholeMsg: the whole message, exactly as it was received.
  • wholeMsgLength: the length of the message as it was received (wholeMsg).
  • securityEngineID: the snmpEngineID that was pulled out of the field msgAuthoritativeEngineID and that got used to look up the secrets in the usmUserTable ๐Ÿ—๏ธ.
  • securityName: the security name representing the user on whose behalf the message was received. the securityName has a format that's independent of the Security Model.
  • scopedPDU: the message payload. the data is opaque as far as the User-based Security Model is concerned.
  • maxSizeResponseScopedPDU: the maximum size of a scopedPDU that can be included in a possible Response message. the User-based Security module works this out from the mms (as received in the message) and the space needed for the message header, including the securityParameters, for that Response message ๐ŸŽ€.
  • securityStateReference: a handle/reference to cachedSecurityData that gets used when securing an outgoing Response message. when the Message Processing Subsystem asks the User-based Security module to generate a response to this incoming message, it has to pass this handle/reference back in ๐Ÿ’–.

when the process finishes, the User-based Security module returns statusInformation and, if it was successful, the extra data elements the message needs for further processing ๐Ÿฆ‹. if it wasn't successful, you get an errorIndication, possibly with an OID and value pair for whichever error counter got incremented.

2.6. Key Localization Algorithm. ๐Ÿ—๏ธ

okay this one is so clever ๐Ÿง . a localized key is a secret key shared between a user U and one authoritative SNMP engine E. even though a user might only have one password, and therefore one key for the whole network, the actual secrets shared between the user and each authoritative SNMP engine are different. the trick that makes this happen is called key localization [Localized-key] ๐Ÿ’œ.

first, if a user uses a password, that password gets converted into a key Ku using one of the two algorithms described in Appendices A.2.1 and A.2.2 ๐ŸŒˆ.

to turn the key Ku into a localized key Kul of user U at the authoritative SNMP engine E, you append the snmpEngineID of the authoritative SNMP engine to the key Ku, then append the key Ku to the result. that way the snmpEngineID gets wrapped up inside two copies of the user's key Ku ๐ŸŽ. then you run a secure hash function on it. which hash function depends on the authentication protocol defined for this user U at authoritative SNMP engine E. this document defines two authentication protocols with their associated algorithms, based on MD5 and SHA ๐Ÿ”ฅ. the output of the hash function is the localized key Kul for user U at the authoritative SNMP engine E โœจ.

3. Elements of Procedure โœจ

okay, this section is where the good stuff is ๐ŸŒธ. it describes the security related procedures that an SNMP engine follows when it processes SNMP messages according to the User-based Security Model ๐Ÿ’….

3.1. Generating an Outgoing SNMP Message โœจ

okay so this section is the recipe ๐Ÿณ an SNMP engine follows whenever it builds a message with a management operation (a request, a response, a notification, or a report) on behalf of a user at a particular securityLevel. let's get into it ๐Ÿ’…

  1. a) If any securityStateReference is passed (Response message), then information concerning the user is extracted from the cachedSecurityData. The securityEngineID and the securityLevel are extracted from the cachedSecurityData. The cachedSecurityData can now be discarded.

Otherwise,

b) based on the securityName, information concerning the user at the destination snmpEngineID, specified by the securityEngineID, is extracted from the Local Configuration Datastore (LCD, usmUserTable). If information about the user is absent from the LCD, then an error indication (unknownSecurityName) is returned to the calling module. ๐Ÿ™ˆ

  1. If the securityLevel specifies that the message is to be protected from disclosure, but the user does not support both an authentication and a privacy protocol then the message cannot be sent. An error indication (unsupportedSecurityLevel) is returned to the calling module. no privacy AND auth support? the message just doesn't go out ๐Ÿ’€
  2. If the securityLevel specifies that the message is to be authenticated, but the user does not support an authentication protocol, then the message cannot be sent. An error indication (unsupportedSecurityLevel) is returned to the calling module.
  3. a) If the securityLevel specifies that the message is to be protected from disclosure, then the octet sequence representing the serialized scopedPDU is encrypted according to the user's privacy protocol. To do so, a call is made to the privacy module that implements the user's privacy protocol according to the abstract primitive:
statusInformation =       -- success or failure
  encryptData(
  IN    encryptKey        -- user's localized privKey
  IN    dataToEncrypt     -- serialized scopedPDU
  OUT   encryptedData     -- serialized encryptedPDU
  OUT   privParameters    -- serialized privacy parameters
        )

statusInformation indicates if the encryption process was successful or not.

encryptKey is the user's localized private privKey, the secret key that can be used by the encryption algorithm.

dataToEncrypt is the serialized scopedPDU, the data that is to be encrypted.

encryptedData is the encryptedPDU, which represents the encrypted scopedPDU, encoded as an OCTET STRING.

privParameters are the privacy parameters, encoded as an OCTET STRING.

If the privacy module returns failure, then the message cannot be sent and an error indication (encryptionError) is returned to the calling module.

If the privacy module returns success, then the returned privParameters are put into the msgPrivacyParameters field of the securityParameters and the encryptedPDU serves as the payload of the message being prepared.

Otherwise,

b) If the securityLevel specifies that the message is not to be protected from disclosure, then the NULL string is encoded as an OCTET STRING and put into the msgPrivacyParameters field of the securityParameters, and the plaintext scopedPDU serves as the payload of the message being prepared.

  1. The snmpEngineID is encoded as an OCTET STRING into the msgAuthoritativeEngineID field of the securityParameters. Note that an empty (zero length) snmpEngineID is OK for a Request message, because that will cause the remote (authoritative) SNMP engine to return a Report PDU with the proper snmpEngineID included in the msgAuthoritativeEngineID in the securityParameters of that returned Report PDU. ๐Ÿฆ‹
  2. a) If the securityLevel specifies that the message is to be authenticated, then the current values of snmpEngineBoots and snmpEngineTime corresponding to the snmpEngineID from the LCD are used.

Otherwise,

b) If this is a Response message, then the current value of snmpEngineBoots and snmpEngineTime corresponding to the local snmpEngineID from the LCD are used.

Otherwise,

c) If this is a Request message, then a zero value is used for both snmpEngineBoots and snmpEngineTime. This zero value gets used if snmpEngineID is empty.

The values are encoded as INTEGER respectively into the msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime fields of the securityParameters. ๐Ÿงš

  1. The userName is encoded as an OCTET STRING into the msgUserName field of the securityParameters.
  2. a) If the securityLevel specifies that the message is to be authenticated, the message is authenticated according to the user's authentication protocol. To do so, a call is made to the authentication module that implements the user's authentication protocol according to the abstract service primitive:
statusInformation =
  authenticateOutgoingMsg(
  IN  authKey               -- the user's localized authKey
  IN  wholeMsg              -- unauthenticated message
  OUT authenticatedWholeMsg -- authenticated complete message
      )

statusInformation indicates if authentication was successful or not.

authKey is the user's localized private authKey, the secret key that can be used by the authentication algorithm.

wholeMsg is the complete serialized message to be authenticated.

authenticatedWholeMsg is the same as the input given to the authenticateOutgoingMsg service, but with msgAuthenticationParameters properly filled in.

If the authentication module returns failure, then the message cannot be sent and an error indication (authenticationFailure) is returned to the calling module.

If the authentication module returns success, then the msgAuthenticationParameters field is put into the securityParameters and the authenticatedWholeMsg represents the serialization of the authenticated message being prepared.

Otherwise,

b) If the securityLevel specifies that the message is not to be authenticated, then the NULL string is encoded as an OCTET STRING into the msgAuthenticationParameters field of the securityParameters. The wholeMsg is now serialized and then represents the unauthenticated message being prepared.

  1. The completed message with its length is returned to the calling module with the statusInformation set to success. ๐ŸŽ€

3.2. Processing an Incoming SNMP Message โœจ

this section is the flip side ๐Ÿ”„ the procedure an SNMP engine follows whenever it receives a message with a management operation on behalf of a user at a particular securityLevel.

the release of state information isn't always spelled out step by step, to keep things simple ๐Ÿงน as a general rule, if state information is available when a message gets discarded, the state information should also be released. also, when an error indication with an OID and value for an incremented counter is returned, the available information (like securityStateReference) must be passed back to the caller so it can generate a Report PDU. this part is lowkey important, don't skip it bestie ๐Ÿ‘‘

  1. If the received securityParameters is not the serialization (according to the conventions of [RFC1906]) of an OCTET STRING formatted according to the UsmSecurityParameters defined in section 2.4, then the snmpInASNParseErrs counter [RFC1907] is incremented, and an error indication (parseError) is returned to the calling module. Note that we return without the OID and value of the incremented counter, because in this case there is not enough information to generate a Report PDU. ๐Ÿ’€
  2. The values of the security parameter fields are extracted from the securityParameters. The securityEngineID to be returned to the caller is the value of the msgAuthoritativeEngineID field. The cachedSecurityData is prepared and a securityStateReference is prepared to reference this data. Values to be cached are:
    • msgUserName
    • securityEngineID
    • securityLevel
  3. If the value of the msgAuthoritativeEngineID field in the securityParameters is unknown, then:

a) a non-authoritative SNMP engine that performs discovery may optionally create a new entry in its Local Configuration Datastore (LCD) and continue processing;

or

b) the usmStatsUnknownEngineIDs counter is incremented, and an error indication (unknownEngineID) together with the OID and value of the incremented counter is returned to the calling module.

  1. Information about the value of the msgUserName and msgAuthoritativeEngineID fields is extracted from the Local Configuration Datastore (LCD, usmUserTable). If no information is available for the user, then the usmStatsUnknownUserNames counter is incremented and an error indication (unknownSecurityName) together with the OID and value of the incremented counter is returned to the calling module. ๐Ÿ™ˆ
  2. If the information about the user indicates that it does not support the securityLevel requested by the caller, then the usmStatsUnsupportedSecLevels counter is incremented and an error indication (unsupportedSecurityLevel) together with the OID and value of the incremented counter is returned to the calling module.
  3. If the securityLevel specifies that the message is to be authenticated, then the message is authenticated according to the user's authentication protocol. To do so, a call is made to the authentication module that implements the user's authentication protocol according to the abstract service primitive:
statusInformation =          -- success or failure
  authenticateIncomingMsg(
  IN   authKey               -- the user's localized authKey
  IN   authParameters        -- as received on the wire
  IN   wholeMsg              -- as received on the wire
  OUT  authenticatedWholeMsg -- checked for authentication
        )

statusInformation indicates if authentication was successful or not.

authKey is the user's localized private authKey, the secret key that can be used by the authentication algorithm.

wholeMsg is the complete serialized message to be authenticated.

authenticatedWholeMsg is the same as the input given to the authenticateIncomingMsg service, but after authentication has been checked.

If the authentication module returns failure, then the message cannot be trusted, so the usmStatsWrongDigests counter is incremented and an error indication (authenticationFailure) together with the OID and value of the incremented counter is returned to the calling module. not trusted = counter goes up and the error goes back, no exceptions ๐Ÿšซ

If the authentication module returns success, then the message is authentic and can be trusted, so processing continues. โœจ

  1. okay bestie, step 7 is where the time checks get SERIOUS ๐Ÿ•ฐ๏ธโœจ If the securityLevel says the message is authenticated, the local snmpEngineBoots and snmpEngineTime that match the msgAuthoritativeEngineID value get pulled out of the Local Configuration Datastore ๐Ÿ’…

a) If the extracted msgAuthoritativeEngineID is the same as your own snmpEngineID (so you're the authoritative engine ๐Ÿ‘‘), the message counts as outside of the Time Window if ANY of these is true:

  • the local snmpEngineBoots is 2147483647;
  • the msgAuthoritativeEngineBoots field differs from the local snmpEngineBoots; or
  • the msgAuthoritativeEngineTime field differs from your local snmpEngineTime by more than +/- 150 seconds.

If it's outside the Time Window, the usmStatsNotInTimeWindows counter goes up ๐Ÿ“ˆ and you return an error indication (notInTimeWindow) along with the OID and value of that counter ๐Ÿ™ˆ

b) If the extracted msgAuthoritativeEngineID is NOT the same as your snmpEngineID (so you're not the authoritative one, bestie ๐Ÿซถ), then:

  1. if at least one of these is true:
  • the extracted msgAuthoritativeEngineBoots is greater than your local snmpEngineBoots; or
  • the extracted msgAuthoritativeEngineBoots equals your local snmpEngineBoots AND the extracted msgAuthoritativeEngineTime is greater than latestReceivedEngineTime,

then the LCD entry for that msgAuthoritativeEngineID gets updated ๐Ÿ”„. You set the local snmpEngineBoots to the msgAuthoritativeEngineBoots field, the local snmpEngineTime to the msgAuthoritativeEngineTime field, and latestReceivedEngineTime to the value of the value of the msgAuthoritativeEngineTime field.

  1. if any of these is true, the message counts as outside of the Time Window:
  • the local snmpEngineBoots is 2147483647;
  • the msgAuthoritativeEngineBoots field is less than your local snmpEngineBoots; or
  • the msgAuthoritativeEngineBoots field equals your local snmpEngineBoots AND the msgAuthoritativeEngineTime field is more than 150 seconds less than your local snmpEngineTime.

If it's outside the Time Window, you return an error indication (notInTimeWindow) ๐Ÿšซ

Note that this means a too old (possibly replayed) message has been detected, and it's deemed unauthentic. Not it ๐Ÿ’€

Note that this procedure lets msgAuthoritativeEngineBoots in the message be greater than your local snmpEngineBoots. That way, messages from an authoritative engine that rebooted since the receiving engine last (re-)synchronized can still be accepted as authentic ๐Ÿฆ‹

Note that this procedure does not allow automatic time synchronization when the non-authoritative engine is really out of sync, meaning the authoritative engine is more than 150 seconds behind the non-authoritative engine ๐Ÿฅบ

  1. a) If the securityLevel says the message was protected from disclosure, the OCTET STRING representing the encryptedPDU gets decrypted using the user's privacy protocol, so you end up with an unencrypted serialized scopedPDU value ๐Ÿ” To do that, you call the privacy module that implements the user's privacy protocol, using this abstract primitive:
statusInformation =       -- success or failure
  decryptData(
  IN    decryptKey        -- the user's localized privKey
  IN    privParameters    -- as received on the wire
  IN    encryptedData     -- encryptedPDU as received
  OUT   decryptedData     -- serialized decrypted scopedPDU
        )

Here's what each piece means:

  • statusInformation tells you whether the decryption worked or not.
  • decryptKey is the user's localized private privKey, the secret key the decryption algorithm can use.
  • privParameters is the msgPrivacyParameters, encoded as an OCTET STRING.
  • encryptedData is the encryptedPDU, which represents the encrypted scopedPDU, encoded as an OCTET STRING.
  • decryptedData is the serialized scopedPDU, if decryption is successful.

If the privacy module returns failure, the message can't be processed ๐Ÿ˜ญ So the usmStatsDecryptionErrors counter goes up and you return an error indication (decryptionError) together with the OID and value of that counter.

If the privacy module returns success, the decrypted scopedPDU is the message payload that goes back to the calling module ๐ŸŽ‰

Otherwise,

b) The scopedPDU component is assumed to be in plain text, and it's the message payload that goes back to the calling module ๐Ÿ“

  1. The maxSizeResponseScopedPDU gets calculated. This is the maximum size allowed for a scopedPDU in a possible Response message. It leaves room for a message header that allows the same securityLevel as the received Request ๐Ÿ“
  2. The securityName for the user is retrieved from the usmUserTable ๐Ÿงพ
  3. The security data gets cached as cachedSecurityData, so a possible response to this message can use the same authentication and privacy secrets, the same securityLevel, and the same msgAuthoritativeEngineID value. Here's what gets saved:
  • msgUserName,
  • usmUserAuthProtocol, usmUserAuthKey
  • usmUserPrivProtocol, usmUserPrivKey
  • securityEngineID, securityLevel
  1. The statusInformation is set to success, and you return to the calling module, passing back the OUT parameters as specified in the processIncomingMsg primitive โœจ

4. Discovery ๐Ÿ”

The User-based Security Model needs a discovery process to get enough info about other SNMP engines so they can talk to each other ๐Ÿค Discovery means a non-authoritative SNMP engine has to learn the authoritative SNMP engine's snmpEngineID value before communication can go ahead. This can happen by generating a Request message with a securityLevel of noAuthNoPriv, a msgUserName of "initial", a msgAuthoritativeEngineID value of zero length, and the varBindList left empty. The response will be a Report message with the snmpEngineID of the authoritative SNMP engine as the value of the msgAuthoritativeEngineID field inside the msgSecurityParameters field. It also contains a Report PDU with the usmStatsUnknownEngineIDs counter in the varBindList ๐Ÿ’–

If authenticated communication is required, the discovery process should also set up time synchronization with the authoritative SNMP engine โฐ You can do this by sending an authenticated Request message where msgAuthoritativeEngineID is set to the newly learned snmpEngineID, and msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime are both set to zero. The response will be a Report message with the up to date values of the authoritative SNMP engine's snmpEngineBoots and snmpEngineTime, as the value of the msgAuthoritativeEngineBoots and msgAuthoritativeEngineTime fields respectively. It also has the usmStatsNotInTimeWindows counter in the varBindList of the Report PDU. After that, time synchronization happens automatically through the procedures in section 3.2 step 7b. See also section 2.3 ๐Ÿงš

5. Definitions ๐ŸŽ€

Here's the MIB module, and it's giving very official vibes ๐Ÿ’…

SNMP-USER-BASED-SM-MIB DEFINITIONS ::= BEGIN

IMPORTS
    MODULE-IDENTITY, OBJECT-TYPE,
    OBJECT-IDENTITY,
    snmpModules, Counter32                FROM SNMPv2-SMI
    TEXTUAL-CONVENTION, TestAndIncr,
    RowStatus, RowPointer,
    StorageType, AutonomousType           FROM SNMPv2-TC
    MODULE-COMPLIANCE, OBJECT-GROUP       FROM SNMPv2-CONF
    SnmpAdminString, SnmpEngineID,
    snmpAuthProtocols, snmpPrivProtocols  FROM SNMP-FRAMEWORK-MIB;

snmpUsmMIB MODULE-IDENTITY
    LAST-UPDATED "9711200000Z"            -- 20 Nov 1997, midnight
    ORGANIZATION "SNMPv3 Working Group"
    CONTACT-INFO "WG-email:   snmpv3@tis.com
                  Subscribe:  majordomo@tis.com
                              In msg body:  subscribe snmpv3

                  Chair:      Russ Mundy
                              Trusted Information Systems
                  postal:     3060 Washington Rd
                              Glenwood MD 21738
                              USA
                  email:      mundy@tis.com
                  phone:      +1-301-854-6889

                  Co-editor   Uri Blumenthal
                              IBM T. J. Watson Research
                  postal:     30 Saw Mill River Pkwy,
                              Hawthorne, NY 10532
                              USA
                  email:      uri@watson.ibm.com
                  phone:      +1-914-784-7964

                  Co-editor:  Bert Wijnen
                              IBM T. J. Watson Research
                  postal:     Schagen 33
                              3461 GL Linschoten
                              Netherlands
                  email:      wijnen@vnet.ibm.com
                  phone:      +31-348-432-794
                 "

    DESCRIPTION  "The management information definitions for the
                  SNMP User-based Security Model.
                 "
    ::= { snmpModules 4 }

-- Administrative assignments ****************************************

usmMIBObjects     OBJECT IDENTIFIER ::= { snmpUsmMIB 1 }
usmMIBConformance OBJECT IDENTIFIER ::= { snmpUsmMIB 2 }

-- Identification of Authentication and Privacy Protocols ************

usmNoAuthProtocol OBJECT-IDENTITY
    STATUS        current
    DESCRIPTION  "No Authentication Protocol."
    ::= { snmpAuthProtocols 1 }

usmHMACMD5AuthProtocol OBJECT-IDENTITY
    STATUS        current
    DESCRIPTION  "The HMAC-MD5-96 Digest Authentication Protocol."
    REFERENCE    "- H. Krawczyk, M. Bellare, R. Canetti HMAC:
                    Keyed-Hashing for Message Authentication,
                    RFC2104, Feb 1997.
                  - Rivest, R., Message Digest Algorithm MD5, RFC1321.
                 "
    ::= { snmpAuthProtocols 2 }

okay so we're still in the MIB, bestie ๐ŸŽ€ the next protocol up is HMAC-SHA, and it's giving main character energy ๐Ÿ’…

usmHMACSHAAuthProtocol OBJECT-IDENTITY
    STATUS        current
    DESCRIPTION  "The HMAC-SHA-96 Digest Authentication Protocol."
    REFERENCE    "- H. Krawczyk, M. Bellare, R. Canetti, HMAC:
                    Keyed-Hashing for Message Authentication,
                    RFC2104, Feb 1997.
                  - Secure Hash Algorithm. NIST FIPS 180-1.
                 "
    ::= { snmpAuthProtocols 3 }

usmNoPrivProtocol OBJECT-IDENTITY
    STATUS        current
    DESCRIPTION  "No Privacy Protocol."
    ::= { snmpPrivProtocols 1 }

usmDESPrivProtocol OBJECT-IDENTITY
    STATUS        current
    DESCRIPTION  "The CBC-DES Symmetric Encryption Protocol."
    REFERENCE    "- Data Encryption Standard, National Institute of
                    Standards and Technology.  Federal Information
                    Processing Standard (FIPS) Publication 46-1.
                    Supersedes FIPS Publication 46,
                    (January, 1977; reaffirmed January, 1988).

                  - Data Encryption Algorithm, American National
                    Standards Institute.  ANSI X3.92-1981,
                    (December, 1980).

                  - DES Modes of Operation, National Institute of
                    Standards and Technology.  Federal Information
                    Processing Standard (FIPS) Publication 81,
                    (December, 1980).

                  - Data Encryption Algorithm - Modes of Operation,
                    American National Standards Institute.
                    ANSI X3.106-1983, (May 1983).
                 "
    ::= { snmpPrivProtocols 2 }

Next up is the textual conventions bit, and this is where it gets spicy ๐ŸŒถ๏ธ The KeyChange convention is basically how you rotate a secret key without ever sending the actual key over the wire. Iconic, honestly ๐Ÿ˜ญโœจ

-- Textual Conventions ***********************************************


KeyChange ::=     TEXTUAL-CONVENTION
   STATUS         current
   DESCRIPTION
         "Every definition of an object with this syntax must identify
          a protocol P, a secret key K, and a hash algorithm H
          that produces output of L octets.

          The object's value is a manager-generated, partially-random
          value which, when modified, causes the value of the secret
          key K, to be modified via a one-way function.

          The value of an instance of this object is the concatenation
          of two components: first a 'random' component and then a
          'delta' component.

          The lengths of the random and delta components
          are given by the corresponding value of the protocol P;
          if P requires K to be a fixed length, the length of both the
          random and delta components is that fixed length; if P
          allows the length of K to be variable up to a particular
          maximum length, the length of the random component is that
          maximum length and the length of the delta component is any
          length less than or equal to that maximum length.
          For example, usmHMACMD5AuthProtocol requires K to be a fixed
          length of 16 octets and L - of 16 octets.
          usmHMACSHAAuthProtocol requires K to be a fixed length of
          20 octets and L - of 20 octets. Other protocols may define
          other sizes, as deemed appropriate.

          When a requestor wants to change the old key K to a new
          key keyNew on a remote entity, the 'random' component is
          obtained from either a true random generator, or from a
          pseudorandom generator, and the 'delta' component is
          computed as follows:

           - a temporary variable is initialized to the existing value
             of K;
           - if the length of the keyNew is greater than L octets,
             then:
              - the random component is appended to the value of the
                temporary variable, and the result is input to the
                the hash algorithm H to produce a digest value, and
                the temporary variable is set to this digest value;
              - the value of the temporary variable is XOR-ed with
                the first (next) L-octets (16 octets in case of MD5)
                of the keyNew to produce the first (next) L-octets
                (16 octets in case of MD5) of the 'delta' component.
              - the above two steps are repeated until the unused
                portion of the delta component is L octets or less,
           - the random component is appended to the value of the
             temporary variable, and the result is input to the
             hash algorithm H to produce a digest value;
           - this digest value, truncated if necessary to be the same
             length as the unused portion of the keyNew, is XOR-ed
             with the unused portion of the keyNew to produce the
             (final portion of the) 'delta' component.

           For example, using MD5 as the hash algorithm H:

              iterations = (lenOfDelta - 1)/16; /* integer division */
              temp = keyOld;
              for (i = 0; i < iterations; i++) {
                  temp = MD5 (temp || random);
                  delta[i*16 .. (i*16)+15] =
                         temp XOR keyNew[i*16 .. (i*16)+15];
              }
              temp = MD5 (temp || random);
              delta[i*16 .. lenOfDelta-1] =
                     temp XOR keyNew[i*16 .. lenOfDelta-1];

          The 'random' and 'delta' components are then concatenated as
          described above, and the resulting octet string is sent to
          the receipient as the new value of an instance of this
          object.

          At the receiver side, when an instance of this object is set
          to a new value, then a new value of K is computed as follows:

           - a temporary variable is initialized to the existing value
             of K;
           - if the length of the delta component is greater than L
             octets, then:
              - the random component is appended to the value of the
                temporary variable, and the result is input to the
                the hash algorithm H to produce a digest value, and
                the temporary variable is set to this digest value;
              - the value of the temporary variable is XOR-ed with
                the first (next) L-octets (16 octets in case of MD5)
                of the delta component to produce the first (next)
                L-octets (16 octets in case of MD5) of the new value
                of K.
              - the above two steps are repeated until the unused
                portion of the delta component is L octets or less,
           - the random component is appended to the value of the
             temporary variable, and the result is input to the
             hash algorithm H to produce a digest value;
           - this digest value, truncated if necessary to be the same
             length as the unused portion of the delta component, is
             XOR-ed with the unused portion of the delta component to
             produce the (final portion of the) new value of K.

           For example, using MD5 as the hash algorithm H:

              iterations = (lenOfDelta - 1)/16; /* integer division */
              temp = keyOld;
              for (i = 0; i < iterations; i++) {
                  temp = MD5 (temp || random);
                  keyNew[i*16 .. (i*16)+15] =
                         temp XOR delta[i*16 .. (i*16)+15];
              }
              temp = MD5 (temp || random);
              keyNew[i*16 .. lenOfDelta-1] =
                     temp XOR delta[i*16 .. lenOfDelta-1];

          The value of an object with this syntax, whenever it is
          retrieved by the management protocol, is always the zero
          length string.
         "
    SYNTAX       OCTET STRING

Now the stats ๐Ÿ“Š these counters are basically the tea on every dropped packet ๐Ÿต each one tells you exactly why a packet got yeeted

-- Statistics for the User-based Security Model **********************


usmStats         OBJECT IDENTIFIER ::= { usmMIBObjects 1 }


usmStatsUnsupportedSecLevels OBJECT-TYPE
    SYNTAX       Counter32
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "The total number of packets received by the SNMP
                 engine which were dropped because they requested a
                 securityLevel that was unknown to the SNMP engine
                 or otherwise unavailable.
                "
    ::= { usmStats 1 }

usmStatsNotInTimeWindows OBJECT-TYPE
    SYNTAX       Counter32
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "The total number of packets received by the SNMP
                 engine which were dropped because they appeared
                 outside of the authoritative SNMP engine's window.
                "
    ::= { usmStats 2 }

usmStatsUnknownUserNames OBJECT-TYPE
    SYNTAX       Counter32
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "The total number of packets received by the SNMP
                 engine which were dropped because they referenced a
                 user that was not known to the SNMP engine.
                "
    ::= { usmStats 3 }

usmStatsUnknownEngineIDs OBJECT-TYPE

    SYNTAX       Counter32
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "The total number of packets received by the SNMP
                 engine which were dropped because they referenced an
                 snmpEngineID that was not known to the SNMP engine.
                "
    ::= { usmStats 4 }

usmStatsWrongDigests OBJECT-TYPE
    SYNTAX       Counter32
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "The total number of packets received by the SNMP
                 engine which were dropped because they didn't
                 contain the expected digest value.
                "
    ::= { usmStats 5 }

usmStatsDecryptionErrors OBJECT-TYPE
    SYNTAX       Counter32
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "The total number of packets received by the SNMP
                 engine which were dropped because they could not be
                 decrypted.
                "
    ::= { usmStats 6 }

Last bit of this chunk is the usmUser group ๐Ÿฆ‹ it's the table of users, plus a spin lock so multiple apps don't step on each other's toes when they're changing secrets ๐Ÿซถ

-- The usmUser Group ************************************************

usmUser          OBJECT IDENTIFIER ::= { usmMIBObjects 2 }

usmUserSpinLock  OBJECT-TYPE
    SYNTAX       TestAndIncr
    MAX-ACCESS   read-write
    STATUS       current
    DESCRIPTION "An advisory lock used to allow several cooperating
                 Command Generator Applications to coordinate their
                 use of facilities to alter secrets in the
                 usmUserTable.
                "
    ::= { usmUser 1 }

-- The table of valid users for the User-based Security Model ********

usmUserTable     OBJECT-TYPE
    SYNTAX       SEQUENCE OF UsmUserEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION "The table of users configured in the SNMP engine's
                 Local Configuration Datastore (LCD)."
    ::= { usmUser 2 }

usmUserEntry     OBJECT-TYPE
    SYNTAX       UsmUserEntry
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION "A user configured in the SNMP engine's Local
                 Configuration Datastore (LCD) for the User-based
                 Security Model.
                "
    INDEX       { usmUserEngineID,
                  usmUserName
                }
    ::= { usmUserTable 1 }

UsmUserEntry ::= SEQUENCE
    {
        usmUserEngineID         SnmpEngineID,
        usmUserName             SnmpAdminString,
        usmUserSecurityName     SnmpAdminString,
        usmUserCloneFrom        RowPointer,
        usmUserAuthProtocol     AutonomousType,
        usmUserAuthKeyChange    KeyChange,
        usmUserOwnAuthKeyChange KeyChange,
        usmUserPrivProtocol     AutonomousType,
        usmUserPrivKeyChange    KeyChange,
        usmUserOwnPrivKeyChange KeyChange,
        usmUserPublic           OCTET STRING,
        usmUserStorageType      StorageType,
        usmUserStatus           RowStatus
    }

okay so we're deep in the usmUser table now and every single column is giving main character energy ๐Ÿ’…๐ŸŽ€

usmUserEngineID  OBJECT-TYPE
    SYNTAX       SnmpEngineID
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION "An SNMP engine's administratively-unique identifier.

                 In a simple agent, this value is always that agent's
                 own snmpEngineID value.

                 The value can also take the value of the snmpEngineID
                 of a remote SNMP engine with which this user can
                 communicate.

                "
    ::= { usmUserEntry 1 }

usmUserName      OBJECT-TYPE
    SYNTAX       SnmpAdminString (SIZE(1..32))
    MAX-ACCESS   not-accessible
    STATUS       current
    DESCRIPTION "A human readable string representing the name of
                 the user.

                 This is the (User-based Security) Model dependent
                 security ID.
                "
    ::= { usmUserEntry 2 }

usmUserSecurityName OBJECT-TYPE
    SYNTAX       SnmpAdminString
    MAX-ACCESS   read-only
    STATUS       current
    DESCRIPTION "A human readable string representing the user in
                 Security Model independent format.

                 The default transformation of the User-based Security
                 Model dependent security ID to the securityName and
                 vice versa is the identity function so that the
                 securityName is the same as the userName.
                "
    ::= { usmUserEntry 3 }

okay the usmUserName and engine ID combo is the key to the whole row, so these two are kinda the VIPs ๐Ÿ”‘๐Ÿ‘‘

usmUserCloneFrom OBJECT-TYPE
    SYNTAX       RowPointer
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "A pointer to another conceptual row in this
                 usmUserTable.  The user in this other conceptual
                 row is called the clone-from user.

                 When a new user is created (i.e., a new conceptual
                 row is instantiated in this table), the privacy and
                 authentication parameters of the new user are cloned
                 from its clone-from user.

                 The first time an instance of this object is set by
                 a management operation (either at or after its
                 instantiation), the cloning process is invoked.
                 Subsequent writes are successful but invoke no
                 action to be taken by the receiver.
                 The cloning process fails with an 'inconsistentName'
                 error if the conceptual row representing the
                 clone-from user is not in an active state when the
                 cloning process is invoked.

                 Cloning also causes the initial values of the secret
                 authentication key and the secret encryption key of
                 the new user to be set to the same value as the
                 corresponding secret of the clone-from user.

                 When this object is read, the ZeroDotZero OID
                 is returned.
                "
    ::= { usmUserEntry 4 }

usmUserAuthProtocol OBJECT-TYPE
    SYNTAX       AutonomousType
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "An indication of whether messages sent on behalf of
                 this user to/from the SNMP engine identified by
                 usmUserEngineID, can be authenticated, and if so,
                 the type of authentication protocol which is used.

                 An instance of this object is created concurrently
                 with the creation of any other object instance for
                 the same user (i.e., as part of the processing of
                 the set operation which creates the first object
                 instance in the same conceptual row).  Once created,
                 the value of an instance of this object can not be
                 changed.

                 If a set operation tries to set a value for an unknown
                 or unsupported protocol, then a wrongValue error must
                 be returned.
                "
    DEFVAL      { usmHMACMD5AuthProtocol }
    ::= { usmUserEntry 5 }

usmUserAuthKeyChange OBJECT-TYPE
    SYNTAX       KeyChange   -- typically (SIZE (0..32))
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "An object, which when modified, causes the secret
                 authentication key used for messages sent on behalf
                 of this user to/from the SNMP engine identified by
                 usmUserEngineID, to be modified via a one-way
                 function.

                 The associated protocol is the usmUserAuthProtocol.
                 The associated secret key is the user's secret
                 authentication key (authKey). The associated hash
                 algorithm is the algorithm used by the user's
                 usmUserAuthProtocol.

                 When creating a new user, it is an 'inconsistentName'
                 error for a Set operation to refer to this object
                 unless it is previously or concurrently initialized
                 through a set operation on the corresponding value
                 of usmUserCloneFrom.
                "
    DEFVAL      { ''H }    -- the empty string
    ::= { usmUserEntry 6 }

usmUserOwnAuthKeyChange OBJECT-TYPE
    SYNTAX       KeyChange  -- typically (SIZE (0..32))
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "Behaves exactly as usmUserAuthKeyChange, with one
                 notable difference: in order for the Set operation
                 to succeed, the usmUserName of the operation
                 requester must match the usmUserName that
                 indexes the row which is targeted by this
                 operation.

                 The idea here is that access to this column can be
                 public, since it will only allow a user to change
                 his own secret authentication key (authKey).
                "
    DEFVAL      { ''H }    -- the empty string
    ::= { usmUserEntry 7 }

usmUserPrivProtocol OBJECT-TYPE
    SYNTAX       AutonomousType
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "An indication of whether messages sent on behalf of
                 this user to/from the SNMP engine identified by
                 usmUserEngineID, can be protected from disclosure,
                 and if so, the type of privacy protocol which is used.

                 An instance of this object is created concurrently
                 with the creation of any other object instance for
                 the same user (i.e., as part of the processing of
                 the set operation which creates the first object
                 instance in the same conceptual row).  Once created,
                 the value of an instance of this object can not be
                 changed.

                 If a set operation tries to set a value for an unknown
                 or unsupported protocol, then a wrongValue error must
                 be returned.
                "
    DEFVAL      { usmNoPrivProtocol }
    ::= { usmUserEntry 8 }

usmUserPrivKeyChange OBJECT-TYPE
    SYNTAX       KeyChange  -- typically (SIZE (0..32))
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "An object, which when modified, causes the secret
                 encryption key used for messages sent on behalf
                 of this user to/from the SNMP engine identified by
                 usmUserEngineID, to be modified via a one-way
                 function.

                 The associated protocol is the usmUserPrivProtocol.
                 The associated secret key is the user's secret
                 privacy key (privKey). The associated hash
                 algorithm is the algorithm used by the user's
                 usmUserAuthProtocol.

                 When creating a new user, it is an 'inconsistentName'
                 error for a set operation to refer to this object
                 unless it is previously or concurrently initialized
                 through a set operation on the corresponding value
                 of usmUserCloneFrom.
                "
    DEFVAL      { ''H }    -- the empty string
    ::= { usmUserEntry 9 }

usmUserOwnPrivKeyChange OBJECT-TYPE
    SYNTAX       KeyChange  -- typically (SIZE (0..32))
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "Behaves exactly as usmUserPrivKeyChange, with one
                 notable difference: in order for the Set operation
                 to succeed, the usmUserName of the operation
                 requester must match the usmUserName that indexes
                 the row which is targeted by this operation.

                 The idea here is that access to this column can be
                 public, since it will only allow a user to change
                 his own secret privacy key (privKey).
                "

    DEFVAL      { ''H }    -- the empty string
    ::= { usmUserEntry 10 }

usmUserPublic    OBJECT-TYPE
    SYNTAX       OCTET STRING (SIZE(0..32))
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "A publicly-readable value which is written as part
                 of the procedure for changing a user's secret
                 authentication and/or privacy key, and later read to
                 determine whether the change of the secret was
                 effected.
                "
    DEFVAL      { ''H }  -- the empty string
    ::= { usmUserEntry 11 }

usmUserStorageType OBJECT-TYPE
    SYNTAX       StorageType
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "The storage type for this conceptual row.

                 Conceptual rows having the value 'permanent'
                 must allow write-access at a minimum to:

                 - usmUserAuthKeyChange, usmUserOwnAuthKeyChange
                   and usmUserPublic for a user who employs
                   authentication, and
                 - usmUserPrivKeyChange, usmUserOwnPrivKeyChange
                   and usmUserPublic for a user who employs
                   privacy.

                 Note that any user who employs authentication or
                 privacy must allow its secret(s) to be updated and
                 thus cannot be 'readOnly'.
                "
    DEFVAL      { nonVolatile }
    ::= { usmUserEntry 12 }

usmUserStatus    OBJECT-TYPE
    SYNTAX       RowStatus
    MAX-ACCESS   read-create
    STATUS       current
    DESCRIPTION "The status of this conceptual row.

                 Until instances of all corresponding columns are
                 appropriately configured, the value of the
                 corresponding instance of the usmUserStatus column
                 is 'notReady'.

                 In particular, a newly created row cannot be made
                 active until the corresponding usmUserCloneFrom,
                 usmUserAuthKeyChange, usmUserOwnAuthKeyChange,
                 usmUserPrivKeyChange and usmUserOwnPrivKeyChange
                 have all been set.

                 The  RowStatus TC [RFC1903] requires that this
                 DESCRIPTION clause states under which circumstances
                 other objects in this row can be modified:

                 The value of this object has no effect on whether
                 other objects in this conceptual row can be modified.
                "
    ::= { usmUserEntry 13 }

-- Conformance Information *******************************************

usmMIBCompliances OBJECT IDENTIFIER ::= { usmMIBConformance 1 }
usmMIBGroups      OBJECT IDENTIFIER ::= { usmMIBConformance 2 }

-- Compliance statements

6. HMAC-MD5-96 Authentication Protocol โœจ

Okay bestie, this section is all about HMAC-MD5-96 ๐Ÿ”. It's the very first authentication protocol defined for the User-based Security Model ๐Ÿ‘‘. It uses the MD5 hash function from [MD5], in the HMAC mode from [RFC2104], and then chops the output down to 96 bits โœ‚๏ธ.

This protocol is identified by usmHMACMD5AuthProtocol ๐Ÿ†”.

Over time, other authentication protocols may be defined, either to replace this one or to sit alongside it ๐Ÿฆ‹.

6.1. Mechanisms

  • In support of data integrity, a message digest algorithm is required. A digest is calculated over an appropriate portion of an SNMP message and included as part of the message sent to the recipient ๐Ÿ’Œ.
  • In support of data origin authentication and data integrity, a secret value is prepended to the SNMP message before the digest is computed. The calculated digest is partially inserted into the SNMP message before transmission, and the prepended value is never transmitted ๐Ÿคซ. The secret value is shared by all SNMP engines authorized to originate messages on behalf of the appropriate user ๐Ÿซถ.

6.1.1. Digest Authentication Mechanism

The Digest Authentication Mechanism defined in this memo gives you two main things ๐ŸŽ€:

  • verification of the integrity of a received message, i.e., the message received is the message sent ๐Ÿ”.

The integrity of the message is protected by computing a digest over an appropriate portion of the message. The digest is computed by the originator of the message, transmitted with the message, and verified by the recipient of the message ๐Ÿ“ฌ.

  • verification of the user on whose behalf the message was generated ๐Ÿชช.

A secret value known only to SNMP engines authorized to generate messages on behalf of a user is used in HMAC mode (see [RFC2104]). It also recommends truncating the hash-function output that's used as the Message Authentication Code ๐Ÿ’….

This protocol uses the MD5 [MD5] message digest algorithm. A 128-bit MD5 digest is calculated in a special (HMAC) way over the designated portion of an SNMP message, and the first 96 bits of that digest get included as part of the message sent to the recipient. The size of the digest carried in a message is 12 octets. The size of the private authentication key (the secret) is 16 octets. For the details, see section 6.3 ๐Ÿงš.

6.2. Elements of the Digest Authentication Protocol

This section has the definitions you need to realize the authentication module defined in this section of this memo ๐Ÿ“š.

6.2.1. Users

Authentication using this protocol makes use of a defined set of userNames. For any user on whose behalf a message must be authenticated at a particular SNMP engine, that SNMP engine must have knowledge of that user. An SNMP engine that wants to talk to another SNMP engine must also know a user known to that engine, including the applicable attributes of that user ๐Ÿ—ฃ๏ธ.

A user and its attributes are defined as follows:

  • <userName>: A string representing the name of the user.
  • <authKey>: A user's secret key to be used when calculating a digest. It MUST be 16 octets long for MD5 ๐Ÿ”‘.

6.2.2. msgAuthoritativeEngineID

The msgAuthoritativeEngineID value contained in an authenticated message specifies the authoritative SNMP engine for that particular message. (See the definition of SnmpEngineID in the SNMP Architecture document [RFC2261] ๐Ÿ“–.)

A user's (private) authentication key is normally different at each authoritative SNMP engine, so the snmpEngineID is used to select the proper key for the authentication process ๐Ÿ—๏ธโœจ.

6.2.3. SNMP Messages Using this Authentication Protocol

Messages using this authentication protocol carry a msgAuthenticationParameters field as part of the msgSecurityParameters. For this protocol, the msgAuthenticationParameters field is the serialized OCTET STRING representing the first 12 octets of the HMAC-MD5-96 output done over the wholeMsg ๐ŸŽ.

The digest is calculated over the wholeMsg, so if a message is authenticated, that also means all the fields in the message are intact and haven't been tampered with ๐Ÿ›ก๏ธ. No cap, that's iconic.

6.2.4. Services provided by the HMAC-MD5-96 Authentication Module

This section describes the inputs and outputs that the HMAC-MD5-96 Authentication module expects and produces when the User-based Security module calls it for services ๐Ÿงฉ.

6.2.4.1. Services for Generating an Outgoing SNMP Message

The HMAC-MD5-96 authentication protocol assumes that the caller does the selection of the authKey, and that the caller passes in the secret key to be used ๐Ÿ™Œ.

Upon completion, the authentication module returns statusInformation and, if the message digest was correctly calculated, the wholeMsg with the digest inserted at the proper place. The abstract service primitive is:

statusInformation =              -- success or failure
  authenticateOutgoingMsg(
  IN   authKey                   -- secret key for authentication
  IN   wholeMsg                  -- unauthenticated complete message
  OUT  authenticatedWholeMsg     -- complete authenticated message
       )

The abstract data elements are:

  • statusInformation: An indication of whether the authentication process was successful. If not, it is an indication of the problem.
  • authKey: The secret key to be used by the authentication algorithm. The length of this key MUST be 16 octets.
  • wholeMsg: The message to be authenticated.
  • authenticatedWholeMsg: The authenticated message (including the inserted digest) on output.

Note that the authParameters field is filled in by the authentication module, and this field should already be present in the wholeMsg before the Message Authentication Code (MAC) is generated โš ๏ธ.

6.2.4.2. Services for Processing an Incoming SNMP Message

The HMAC-MD5-96 authentication protocol assumes that the caller does the selection of the authKey, and that the caller passes in the secret key to be used ๐Ÿ™Œ.

Upon completion, the authentication module returns statusInformation and, if the message digest was correctly calculated, the wholeMsg as it was processed. The abstract service primitive is:

statusInformation =              -- success or failure
  authenticateIncomingMsg(
  IN   authKey                   -- secret key for authentication
  IN   authParameters            -- as received on the wire
  IN   wholeMsg                  -- as received on the wire
  OUT  authenticatedWholeMsg     -- complete authenticated message
       )

The abstract data elements are:

  • statusInformation: An indication of whether the authentication process was successful. If not, it is an indication of the problem.
  • authKey: The secret key to be used by the authentication algorithm. The length of this key MUST be 16 octets.
  • authParameters: The authParameters from the incoming message.
  • wholeMsg: The message to be authenticated on input, and the authenticated message on output.
  • authenticatedWholeMsg: The whole message after the authentication check is complete.

6.3. Elements of Procedure

This section describes the procedures for the HMAC-MD5-96 authentication protocol ๐Ÿ› ๏ธ.

6.3.1. Processing an Outgoing Message

This section describes the procedure an SNMP engine follows whenever it needs to authenticate an outgoing message using the usmHMACMD5AuthProtocol ๐Ÿš€.

  1. The msgAuthenticationParameters field is set to the serialization, according to the rules in [RFC1906], of an OCTET STRING containing 12 zero octets.
  2. From the secret authKey, two keys K1 and K2 are derived:

a) extend the authKey to 64 octets by appending 48 zero octets; save it as extendedAuthKey b) obtain IPAD by replicating the octet 0x36 64 times; c) obtain K1 by XORing extendedAuthKey with IPAD; d) obtain OPAD by replicating the octet 0x5C 64 times; e) obtain K2 by XORing extendedAuthKey with OPAD.

  1. Prepend K1 to the wholeMsg and calculate the MD5 digest over it according to [MD5].
  2. Prepend K2 to the result of step 4 and calculate the MD5 digest over it according to [MD5]. Take the first 12 octets of the final digest. This is the Message Authentication Code (MAC) ๐ŸŽฏ.
  3. Replace the msgAuthenticationParameters field with the MAC obtained in step 5.
  4. The authenticatedWholeMsg is then returned to the caller, together with statusInformation indicating success ๐ŸŽ‰.

6.3.2. Processing an Incoming Message ๐Ÿ“ฅ

okay so this is the receiving side, bestie ๐Ÿซถ It's the procedure an SNMP engine follows whenever it has to authenticate an incoming message with the usmHMACMD5AuthProtocol ๐Ÿ’…

  1. If the digest received in the msgAuthenticationParameters field is not 12 octets long, then a failure occurs and an errorIndication (authenticationError) is returned to the calling module. ๐Ÿ™ˆ
  2. The MAC received in the msgAuthenticationParameters field is saved. ๐Ÿ’พ
  3. The digest in the msgAuthenticationParameters field is replaced by the 12 zero octets. ๐Ÿงน
  4. From the secret authKey, two keys K1 and K2 are derived ๐Ÿ”‘โœจ
    • a) extend the authKey to 64 octets by appending 48 zero octets, and save it as extendedAuthKey
    • b) obtain IPAD by replicating the octet 0x36 64 times
    • c) obtain K1 by XORing extendedAuthKey with IPAD
    • d) obtain OPAD by replicating the octet 0x5C 64 times
    • e) obtain K2 by XORing extendedAuthKey with OPAD
  5. The MAC is calculated over the wholeMsg ๐Ÿงฎ
    • a) prepend K1 to the wholeMsg and calculate the MD5 digest over it
    • b) prepend K2 to the result of step 5.a and calculate the MD5 digest over it
    • c) the first 12 octets of the result of step 5.b is the MAC

Then the msgAuthenticationParameters field is replaced with the MAC value that was saved in step 2.

  1. Next, the newly calculated MAC is compared with the MAC saved in step 2. If they do not match, a failure occurs and an errorIndication (authenticationFailure) is returned to the calling module. ๐Ÿšซ
  2. The authenticatedWholeMsg and statusInformation indicating success are then returned to the caller. ๐ŸŽ‰

7. HMAC-SHA-96 Authentication Protocol ๐ŸŒˆ

this section is all about HMAC-SHA-96 ๐Ÿฆ‹ It uses the SHA hash function described in [SHA-NIST], in the HMAC mode described in [RFC2104], and the output gets truncated to 96 bits โœ‚๏ธ

this protocol is identified by usmHMACSHAAuthProtocol ๐Ÿท๏ธ

over time, other authentication protocols might be defined, either to replace this one or to sit alongside it, so stay tuned ๐Ÿ‘€

7.1. Mechanisms ๐Ÿ› ๏ธ

  • for data integrity, a message digest algorithm is required. A digest is calculated over an appropriate portion of an SNMP message and included as part of the message sent to the recipient. ๐Ÿ”
  • for data origin authentication and data integrity, a secret value is prepended to the SNMP message before the digest is computed. The calculated digest is then partially inserted into the message before it is transmitted. The prepended secret is never transmitted ๐Ÿคซ The secret value is shared by all SNMP engines that are authorized to originate messages on behalf of the appropriate user. ๐Ÿซข

7.1.1. Digest Authentication Mechanism ๐Ÿ’–

the Digest Authentication Mechanism in this memo gives you two things:

  • verification of the integrity of a received message, meaning that the message received is the message that was sent. ๐Ÿงพ

The integrity is protected by computing a digest over an appropriate portion of the message. The originator of the message computes the digest and transmits it with the message, and the recipient of the message verifies it.

  • verification of the user on whose behalf the message was generated. ๐Ÿ•ต๏ธโ€โ™€๏ธ

A secret value, known only to the SNMP engines that are authorized to generate messages on behalf of a user, is used in HMAC mode (see [RFC2104]). The hash-function output used as the Message Authentication Code is also recommended to be truncated.

this mechanism uses the SHA [SHA-NIST] message digest algorithm ๐ŸŒธ A 160-bit SHA digest is calculated, in a special (HMAC) way, over the designated portion of an SNMP message, and the first 96 bits of that digest are included as part of the message sent to the recipient. The digest carried in a message is 12 octets long, and the private authentication key (the secret) is 20 octets long. For the details, see section 7.3. ๐Ÿ“š

7.2. Elements of the HMAC-SHA-96 Authentication Protocol ๐Ÿงฉ

this section has the definitions you need to build the authentication module described in this section of this memo ๐Ÿ’…

7.2.1. Users ๐Ÿ™‹โ€โ™€๏ธ

authentication with this protocol uses a defined set of userNames. For any user on whose behalf a message must be authenticated at a particular SNMP engine, that engine has to know about that user. An SNMP engine that wants to talk to another SNMP engine must also know a user that is known to that engine, including the applicable attributes of that user. ๐Ÿค

a user and its attributes are defined like this:

  • <userName>: a string representing the name of the user.
  • <authKey>: the user's secret key, used when calculating a digest. It MUST be 20 octets long for SHA. ๐Ÿ”

7.2.2. msgAuthoritativeEngineID ๐Ÿ‘‘

the msgAuthoritativeEngineID value in an authenticated message specifies the authoritative SNMP engine for that particular message (see the definition of SnmpEngineID in the SNMP Architecture document [RFC2261]). ๐Ÿ“–

the user's (private) authentication key is normally different at each authoritative SNMP engine, so the snmpEngineID is used to pick the right key for the authentication process. ๐Ÿ—๏ธโœจ

7.2.3. SNMP Messages Using this Authentication Protocol ๐Ÿ’Œ

messages using this authentication protocol carry a msgAuthenticationParameters field as part of the msgSecurityParameters. For this protocol, the msgAuthenticationParameters field is the serialized OCTET STRING representing the first 12 octets of the HMAC-SHA-96 output done over the wholeMsg. ๐Ÿง

the digest is calculated over the wholeMsg, so if a message is authenticated, that also means every field in the message is intact and hasn't been tampered with. ๐Ÿ›ก๏ธ no sneaky edits allowed ๐Ÿ˜ค

7.2.4. Services provided by the HMAC-SHA-96 Authentication Module ๐ŸŽ€

this section describes the inputs and outputs that the HMAC-SHA-96 Authentication module expects and produces when the User-based Security module calls it for services ๐Ÿ“ž

7.2.4.1. Services for Generating an Outgoing SNMP Message ๐Ÿ“ค

HMAC-SHA-96 authentication assumes that the caller selects the authKey and passes in the secret key to be used ๐Ÿ”‘

when it's done, the authentication module returns statusInformation and, if the message digest was calculated correctly, the wholeMsg with the digest inserted in the proper place. The abstract service primitive looks like this:

statusInformation =              -- success or failure
     authenticateOutgoingMsg(
     IN   authKey                   -- secret key for authentication
     IN   wholeMsg                  -- unauthenticated complete message
     OUT  authenticatedWholeMsg     -- complete authenticated message
          )

the abstract data elements are:

  • statusInformation: an indication of whether the authentication process was successful. If it wasn't, it indicates the problem.
  • authKey: the secret key to be used by the authentication algorithm. The length of this key MUST be 20 octets. ๐Ÿ”
  • wholeMsg: the message to be authenticated.
  • authenticatedWholeMsg: the authenticated message, including the inserted digest, on output.

note that the authParameters field is filled in by the authentication module, and this field should already be present in the wholeMsg before the Message Authentication Code (MAC) is generated. โš ๏ธ

7.2.4.2. Services for Processing an Incoming SNMP Message ๐Ÿ“ฅ

HMAC-SHA-96 authentication assumes that the caller selects the authKey and passes in the secret key to be used ๐Ÿ—๏ธ

when it's done, the authentication module returns statusInformation and, if the message digest was calculated correctly, the wholeMsg as it was processed. The abstract service primitive looks like this:

statusInformation =              -- success or failure
     authenticateIncomingMsg(
     IN   authKey                   -- secret key for authentication
     IN   authParameters            -- as received on the wire
     IN   wholeMsg                  -- as received on the wire
     OUT  authenticatedWholeMsg     -- complete authenticated message
       )

the abstract data elements are:

  • statusInformation: an indication of whether the authentication process was successful. If it wasn't, it indicates the problem.
  • authKey: the secret key to be used by the authentication algorithm. The length of this key MUST be 20 octets. ๐Ÿ”
  • authParameters: the authParameters from the incoming message.
  • wholeMsg: the message to be authenticated on input, and the authenticated message on output.
  • authenticatedWholeMsg: the whole message after the authentication check is complete.

7.3. Elements of Procedure ๐Ÿ“‹

this section describes the procedures for the HMAC-SHA-96 authentication protocol ๐Ÿง 

7.3.1. Processing an Outgoing Message ๐Ÿ“ค

this section describes the procedure an SNMP engine follows whenever it must authenticate an outgoing message using the usmHMACSHAAuthProtocol ๐Ÿ’…

  1. The msgAuthenticationParameters field is set to the serialization, according to the rules in [RFC1906], of an OCTET STRING containing 12 zero octets. ๐Ÿงธ
  2. From the secret authKey, two keys K1 and K2 are derived ๐Ÿ”‘โœจ
    • a) extend the authKey to 64 octets by appending 44 zero octets, and save it as extendedAuthKey
    • b) obtain IPAD by replicating the octet 0x36 64 times
    • c) obtain K1 by XORing extendedAuthKey with IPAD
    • d) obtain OPAD by replicating the octet 0x5C 64 times
    • e) obtain K2 by XORing extendedAuthKey with OPAD
  3. Prepend K1 to the wholeMsg and calculate the SHA digest over it according to [SHA-NIST]. ๐Ÿงฎ
  4. Prepend K2 to the result of step 3 and calculate the SHA digest over it according to [SHA-NIST]. Take the first 12 octets of the final digest, which is the Message Authentication Code (MAC). โœ‚๏ธ
  5. Replace the msgAuthenticationParameters field with the MAC obtained in step 4. ๐Ÿ”
  6. The authenticatedWholeMsg is then returned to the caller, together with statusInformation indicating success. ๐ŸŽ‰

7.3.2. Processing an Incoming Message โœจ

Okay bestie, this section is the step-by-step for what an SNMP engine does when it has to authenticate an incoming message with the usmHMACSHAAuthProtocol ๐Ÿ”. Let's go!

  1. If the digest received in the msgAuthenticationParameters field is not 12 octets long, then a failure and an errorIndication (authenticationError) are returned to the calling module. ๐Ÿ’€
  2. The MAC received in the msgAuthenticationParameters field is saved. ๐Ÿ“ฅ
  3. The digest in the msgAuthenticationParameters field is replaced by the 12 zero octets. ๐Ÿงธ
  4. From the secret authKey, two keys K1 and K2 are derived ๐Ÿ”‘โœจ
    • a) extend the authKey to 64 octets by appending 44 zero octets; save it as extendedAuthKey
    • b) obtain IPAD by replicating the octet 0x36 64 times;
    • c) obtain K1 by XORing extendedAuthKey with IPAD;
    • d) obtain OPAD by replicating the octet 0x5C 64 times;
    • e) obtain K2 by XORing extendedAuthKey with OPAD.
  5. The MAC is calculated over the wholeMsg ๐Ÿ“
    • a) prepend K1 to the wholeMsg and calculate the SHA digest over it;
    • b) prepend K2 to the result of step 5.a and calculate the SHA digest over it;
    • c) first 12 octets of the result of step 5.b is the MAC.

The msgAuthenticationParameters field is replaced with the MAC value that was saved in step 2. ๐Ÿซถ

  1. The newly calculated MAC is compared with the MAC saved in step 2. If they do not match, then a failure and an errorIndication (authenticationFailure) are returned to the calling module. ๐Ÿ˜ญ
  2. The authenticatedWholeMsg and statusInformation indicating success are then returned to the caller. ๐ŸŽ€

8. CBC-DES Symmetric Encryption Protocol ๐ŸŒธ

This section is all about the CBC-DES Symmetric Encryption Protocol, and it's giving main character energy ๐Ÿ’…. It's the first privacy protocol defined for the User-based Security Model, so it's kind of a big deal ๐Ÿ‘‘.

This protocol is identified by usmDESPrivProtocol.

Over time, other privacy protocols may be defined, either as a replacement for this protocol or in addition to it. Stay tuned ๐Ÿฆ‹.

8.1. Mechanisms ๐Ÿ”

  • In support of data confidentiality, an encryption algorithm is required. An appropriate portion of the message is encrypted before it gets sent. The User-based Security Model says the scopedPDU is the part that needs to be encrypted ๐Ÿ™ˆ.
  • A secret value combined with a timeliness value is used to create the en/decryption key and the initialization vector. The secret value is shared by all SNMP engines that are authorized to originate messages on behalf of the appropriate user ๐Ÿงš.

8.1.1. Symmetric Encryption Protocol

The Symmetric Encryption Protocol defined in this memo provides support for data confidentiality ๐Ÿ”’. The designated portion of an SNMP message gets encrypted and then included as part of the message sent to the recipient.

Two organizations have published specifications defining the DES: the National Institute of Standards and Technology (NIST) [DES-NIST] and the American National Standards Institute [DES-ANSI]. Each definition has a companion Modes of Operation specification ([DESO-NIST] and [DESO-ANSI], respectively).

The NIST has also published three additional documents that implementors may find useful ๐Ÿ“š:

  • There is a document with guidelines for implementing and using the DES, including functional specifications for the DES and its modes of operation [DESG-NIST].
  • There is a specification of a validation test suite for the DES [DEST-NIST]. The suite is designed to test all aspects of the DES and is useful for pinpointing specific problems ๐Ÿ”.
  • There is a specification of a maintenance test for the DES [DESM-NIST]. The test uses a minimal amount of data and processing to test all components of the DES. It gives a simple yes-or-no indication of correct operation and is useful to run as part of an initialization step, e.g., when a computer re-boots ๐Ÿ”„.

8.1.1.1. DES key and Initialization Vector. ๐Ÿ”‘

The first 8 octets of the 16-octet secret (private privacy key) are used as a DES key. Since DES only uses 56 bits, the Least Significant Bit in each octet is disregarded ๐Ÿ™ƒ.

The Initialization Vector for encryption is obtained with the following procedure.

The last 8 octets of the 16-octet secret (private privacy key) are used as pre-IV.

Okay so, to make sure the IV for two different packets encrypted by the same key is not the same (so the IV never repeats), we need to "salt" the pre-IV with something unique per packet ๐Ÿง‚. An 8-octet string is used as the "salt". The salt is made by concatenating the generating SNMP engine's 32-bit snmpEngineBoots with a local 32-bit integer that the encryption engine maintains. That integer is initialized to an arbitrary value at boot time โฐ.

The 32-bit snmpEngineBoots is converted to the first 4 octets (Most Significant Byte first) of our "salt". The 32-bit integer is then converted to the last 4 octets (Most Significant Byte first) of our "salt". The resulting "salt" is then XOR-ed with the pre-IV. The 8-octet "salt" is then put into the privParameters field, encoded as an OCTET STRING. After that, the "salt" integer gets modified. We recommend that it be incremented by one and wrap when it reaches the maximum value ๐Ÿ”.

How exactly the value of the "salt" (and therefore of the IV) varies is an implementation issue, as long as measures are taken to avoid producing a duplicate IV ๐Ÿซถ.

The "salt" must be placed in the privParameters field so the receiving entity can compute the correct IV and decrypt the message. (Yes, MUST, I'm not joking ๐Ÿ’€.)

The "salt" MUST be placed in the privParameters field to enable the receiving entity to compute the correct IV and to decrypt the message.

8.1.1.2. Data Encryption. ๐Ÿฌ

The data to be encrypted is treated as a sequence of octets. Its length should be an integral multiple of 8, and if it isn't, the data is padded at the end as necessary. The actual pad value is irrelevant ๐Ÿคทโ€โ™€๏ธ.

The data is encrypted in Cipher Block Chaining mode ๐Ÿ”—.

The plaintext is divided into 64-bit blocks.

The plaintext for each block is XOR-ed with the ciphertext of the previous block, the result is encrypted, and the output of the encryption is the ciphertext for that block. This procedure repeats until there are no more plaintext blocks ๐Ÿ”.

For the very first block, the Initialization Vector is used instead of the ciphertext of the previous block ๐ŸŒฑ.

8.1.1.3. Data Decryption ๐Ÿ”“

Before decryption, the encrypted data length is verified. If the length of the OCTET STRING to be decrypted is not an integral multiple of 8 octets, the decryption process is halted and an appropriate exception is noted. When decrypting, the padding is ignored ๐Ÿ™ˆ.

The first ciphertext block is decrypted, the decryption output is XOR-ed with the Initialization Vector, and the result is the first plaintext block.

For each subsequent block, the ciphertext block is decrypted, the decryption output is XOR-ed with the previous ciphertext block, and the result is the plaintext block ๐Ÿฉท.

8.2. Elements of the DES Privacy Protocol ๐Ÿงฉ

This section has the definitions you need to realize the privacy module defined by this memo โœจ.

8.2.1. Users ๐Ÿ‘ค

Data en/decryption with this Symmetric Encryption Protocol uses a defined set of userNames. For any user on whose behalf a message must be en/decrypted at a particular SNMP engine, that SNMP engine must know about that user. An SNMP engine that wants to talk to another SNMP engine must also know about a user known to that SNMP engine, including the applicable attributes of that user ๐Ÿ’ฌ.

A user and its attributes are defined as follows:

  • <userName>: An octet string representing the name of the user.
  • <privKey>: A user's secret key to be used as input for the DES key and IV. The length of this key MUST be 16 octets.

8.2.2. msgAuthoritativeEngineID ๐Ÿชช

The msgAuthoritativeEngineID value contained in an authenticated message specifies the authoritative SNMP engine for that particular message (see the definition of SnmpEngineID in the SNMP Architecture document [RFC2261]).

The user's (private) privacy key is normally different at each authoritative SNMP engine, so the snmpEngineID is used to select the proper key for the en/decryption process ๐Ÿ”‘๐Ÿ’–.

8.2.3. SNMP Messages Using this Privacy Protocol ๐Ÿ“จ

Messages using this privacy protocol carry a msgPrivacyParameters field as part of the msgSecurityParameters. For this protocol, the msgPrivacyParameters field is the serialized OCTET STRING representing the "salt" that was used to create the IV ๐Ÿง‚.

8.2.4. Services provided by the DES Privacy Module ๐Ÿ›Ž๏ธ

This section describes the inputs and outputs that the DES Privacy module expects and produces when the User-based Security module invokes it for services ๐ŸŽ€.

8.2.4.1. Services for Encrypting Outgoing Data ๐Ÿ”

This DES privacy protocol assumes the caller selects the privKey and passes in the secret key to be used.

When it's done, the privacy module returns statusInformation and, if the encryption process was successful, the encryptedPDU and the msgPrivacyParameters encoded as an OCTET STRING. The abstract service primitive looks like this ๐Ÿ‘€:

statusInformation =              -- success of failure
  encryptData(
  IN    encryptKey               -- secret key for encryption
  IN    dataToEncrypt            -- data to encrypt (scopedPDU)
  OUT   encryptedData            -- encrypted data (encryptedPDU)
  OUT   privParameters           -- filled in by service provider
        )

The abstract data elements are:

  • statusInformation: An indication of the success or failure of the encryption process. In case of failure, it is an indication of the error.
  • encryptKey: The secret key to be used by the encryption algorithm. The length of this key MUST be 16 octets.
  • dataToEncrypt: The data that must be encrypted.
  • encryptedData: The encrypted data upon successful completion.
  • privParameters: The privParameters encoded as an OCTET STRING.

8.2.4.2. Services for Decrypting Incoming Data ๐Ÿ”“

This DES privacy protocol assumes the caller selects the privKey and passes in the secret key to be used ๐Ÿ—๏ธ.

When it's done, the privacy module returns statusInformation and, if the decryption process was successful, the scopedPDU in plain text. The abstract service primitive looks like this:

statusInformation =
  decryptData(
  IN    decryptKey               -- secret key for decryption
  IN    privParameters           -- as received on the wire
  IN    encryptedData            -- encrypted data (encryptedPDU)
  OUT   decryptedData            -- decrypted data (scopedPDU)
        )

The abstract data elements are:

  • statusInformation: An indication of whether the data was successfully decrypted and, if not, an indication of the error.
  • decryptKey: The secret key to be used by the decryption algorithm. The length of this key MUST be 16 octets.
  • privParameters: The "salt" to be used to calculate the IV.
  • encryptedData: The data to be decrypted.
  • decryptedData: The decrypted data.

8.3. Elements of Procedure. ๐ŸŽฌ

This section describes the procedures for the DES privacy protocol ๐Ÿ’œ.

8.3.1. Processing an Outgoing Message โœจ

okay so this section is the step-by-step for what an SNMP engine does whenever it needs to encrypt part of an outgoing message using the usmDESPrivProtocol ๐Ÿ” it's giving recipe card energy, honestly

  1. The secret cryptKey gets used to build the DES encryption key, the "salt", and the DES pre-IV (as described in section 8.1.1.1) ๐Ÿ—๏ธ
  2. The privParameters field gets set to the serialization, following the rules in [RFC1906], of an OCTET STRING representing the the "salt" string ๐Ÿ’…
  3. The scopedPDU gets encrypted (as described in section 8.1.1.2), and the encrypted data is serialized as an OCTET STRING following the rules in [RFC1906] ๐ŸŽ€
  4. The serialized OCTET STRING holding the encrypted scopedPDU, together with privParameters and a statusInformation saying success, gets returned to the calling module ๐Ÿฆ‹

8.3.2. Processing an Incoming Message ๐Ÿ“ฅ

this is the flip side, the decrypting part, and it's so important because you have to check stuff before you do anything ๐Ÿง

  1. If the privParameters field is not an 8-octet OCTET STRING, then an error indication (decryptionError) gets returned to the calling module ๐Ÿ™ˆ
  2. The "salt" gets pulled out of the privParameters field ๐Ÿง‚
  3. The secret cryptKey and the "salt" are then used to build the DES decryption key and pre-IV (as described in section 8.1.1.1) ๐Ÿ”‘
  4. The encryptedPDU then gets decrypted (as described in section 8.1.1.3) ๐Ÿ”“
  5. If the encryptedPDU can't be decrypted, then an error indication (decryptionError) gets returned to the calling module ๐Ÿ’€
  6. The decrypted scopedPDU and a statusInformation indicating success get returned to the calling module ๐Ÿ‘‘

9. Intellectual Property ๐ŸŒˆ

bestie, this part is all about the legal stuff, so here's the tea โ˜•

The IETF takes no position on whether any intellectual property or other rights that someone might claim over the tech in this document are valid or what their scope is, and it doesn't say whether any license under those rights would or wouldn't be available. It also doesn't claim it has tried to find any of those rights. ๐Ÿคทโ€โ™€๏ธ If you want info on how the IETF handles rights for standards-track and standards-related docs, check out BCP-11. Copies of claimed rights that were made available for publication, any assurances of licenses that will be made available, or the result of an attempt to get a general license or permission for implementers or users to use those proprietary rights can all be requested from the IETF Secretariat ๐Ÿ“ฌ

The IETF also invites any interested party to bring to its attention any copyrights, patents or patent applications, or other proprietary rights that might cover technology needed to practice this standard. Send that info to the IETF Executive Director ๐Ÿ’Œ

10. Acknowledgements ๐Ÿซถ

this doc is the result of the efforts of the SNMPv3 Working Group, and we need to give some seriously special thanks to these SNMPv3 WG members โœจ

  • Dave Battle (SNMP Research, Inc.)
  • Uri Blumenthal (IBM T.J. Watson Research Center)
  • Jeff Case (SNMP Research, Inc.)
  • John Curran (BBN)
  • T. Max Devlin (Hi-TECH Connections)
  • John Flick (Hewlett Packard)
  • David Harrington (Cabletron Systems Inc.)
  • N.C. Hien (IBM T.J. Watson Research Center)
  • Dave Levi (SNMP Research, Inc.)
  • Louis A Mamakos (UUNET Technologies Inc.)
  • Paul Meyer (Secure Computing Corporation)
  • Keith McCloghrie (Cisco Systems)
  • Russ Mundy (Trusted Information Systems, Inc.)
  • Bob Natale (ACE*COMM Corporation)
  • Mike O'Dell (UUNET Technologies Inc.)
  • Dave Perkins (DeskTalk)
  • Peter Polkinghorne (Brunel University)
  • Randy Presuhn (BMC Software, Inc.)
  • David Reid (SNMP Research, Inc.)
  • Shawn Routhier (Epilogue)
  • Juergen Schoenwaelder (TU Braunschweig)
  • Bob Stewart (Cisco Systems)
  • Bert Wijnen (IBM T.J. Watson Research Center)

the document is based on recommendations from the IETF Security and Administrative Framework Evolution for SNMP Advisory Team ๐Ÿง  the members of that Advisory Team were:

  • David Harrington (Cabletron Systems Inc.)
  • Jeff Johnson (Cisco Systems)
  • David Levi (SNMP Research Inc.)
  • John Linn (Openvision)
  • Russ Mundy (Trusted Information Systems) chair
  • Shawn Routhier (Epilogue)
  • Glenn Waters (Nortel)
  • Bert Wijnen (IBM T. J. Watson Research Center)

as the Advisory Team and the SNMPv3 Working Group Charter recommended, the design pulls in as much as is practical from previous RFCs and drafts ๐Ÿ“ so special thanks are also due to the authors of the earlier designs known as SNMPv2u and SNMPv2*:

  • Jeff Case (SNMP Research, Inc.)
  • David Harrington (Cabletron Systems Inc.)
  • David Levi (SNMP Research, Inc.)
  • Keith McCloghrie (Cisco Systems)
  • Brian O'Keefe (Hewlett Packard)
  • Marshall T. Rose (Dover Beach Consulting)
  • Jon Saperia (BGS Systems Inc.)
  • Steve Waldbusser (International Network Services)
  • Glenn W. Waters (Bell-Northern Research Ltd.)

11. Security Considerations ๐Ÿ”’

this is the serious section, so it's giving main character drama ๐Ÿ˜ญ but the stakes are real, so read every bit of it

this section lists practices that help the mechanisms in this memo run securely and effectively ๐Ÿ’–

  • An SNMP engine must discard SNMP Response messages that do not correspond to any currently outstanding Request message. It is the responsibility of the Message Processing module to take care of this. For example it can use a msgID for that.

An SNMP Command Generator Application must discard any Response PDU for which there is no currently outstanding Request PDU. For example, for SNMPv2 [RFC1905] PDUs, the request-id component in the PDU can be used to correlate Responses to outstanding Requests.

Although it would be typical for an SNMP engine and an SNMP Command Generator Application to do this as a matter of course, when using these security protocols it is significant because of the possibility of message duplication (malicious or otherwise) ๐Ÿ‘€

  • If an SNMP engine uses a msgID for correlating Response messages to outstanding Request messages, then it MUST use different msgIDs in all such Request messages that it sends out during a Time Window (150 seconds) period.

A Command Generator or Notification Originator Application MUST use different request-ids in all Request PDUs that it sends out during a TimeWindow (150 seconds) period.

This must be done to protect against the possibility of message duplication (malicious or otherwise) ๐Ÿšจ

For example, starting operations with a msgID and/or request-id value of zero is not a good idea. Initializing them with an unpredictable number (so they do not start out the same after each reboot) and then incrementing by one would be acceptable ๐Ÿ”ข

  • An SNMP engine should perform time synchronization using authenticated messages in order to protect against the possibility of message duplication (malicious or otherwise) โฐ
  • When sending state altering messages to a managed authoritative SNMP engine, a Command Generator Application should delay sending successive messages to that managed SNMP engine until a positive acknowledgement is received for the previous message or until the previous message expires.

No message ordering is imposed by the SNMP. Messages may be received in any order relative to their time of generation, and each will be processed in the order received. Note that when an authenticated message is sent to a managed SNMP engine, it will be valid for a period of time of approximately 150 seconds under normal circumstances, and it is subject to replay during this period. Indeed, an SNMP engine and SNMP Command Generator Applications must cope with the loss and re-ordering of messages resulting from anomalies in the network as a matter of course ๐ŸŒช๏ธ

However, a managed object, snmpSetSerialNo [RFC1907], is specifically defined for use with SNMP Set operations, in order to provide a mechanism that ensures SNMP messages are processed in a specific order โœจ

  • The frequency with which the secrets of a User-based Security Model user should be changed is indirectly related to the frequency of their use.

Protecting the secrets from disclosure is critical to the overall security of the protocols. Frequent use of a secret provides a continued source of data that may be useful to a cryptanalyst in exploiting known or perceived weaknesses in an algorithm. Frequent changes to the secret avoid this vulnerability ๐Ÿ”

Changing a secret after each use is generally regarded as the most secure practice, but a significant amount of overhead may be associated with that approach ๐Ÿ˜ฎโ€๐Ÿ’จ

Note, too, that in a local environment the threat of disclosure may be less significant, so changing secrets may be less frequent. However, when public data networks are used as the communication paths, more caution is prudent ๐ŸŒ

11.2. Defining Users โœจ

Okay so, "users" are the whole vibe here ๐Ÿ’…. The mechanisms in this document send messages on behalf of users, and how you define a user is up to the network administration's security policy ๐ŸŽ€. A user could be an individual (like "joe" or "jane"), a role (like "operator" or "administrator"), or a combo (like "joe-operator", "jane-operator" or "joe-admin") ๐Ÿฆ‹. And a user can even be a logical entity, like one SNMP Application or a whole set of them, acting for an individual, a role, a set of individuals, a set of roles, or any combination of those ๐Ÿ‘‘.

Appendix A has an algorithm that turns a user "password" into a 16 octet value ๐Ÿ”‘. That value can be the user's authentication key, their privacy key, or both. ngl, using the same password (and therefore the same key) for both auth and privacy is very poor security practice ๐Ÿ’€, and it should be strongly discouraged ๐Ÿ™…โ€โ™€๏ธ. Humans generate, remember and type in passwords, and those can be shorter than the 16 octets the protocols need. Brute force attacks can be pretty easy on a short ASCII character set ๐Ÿ˜ญ. So the Appendix A algorithm performs a transformation on the password. If you use the Appendix A algorithm, SNMP implementations (and SNMP configuration applications) must ensure that passwords are at least 8 characters in length ๐Ÿ’–.

Because the Appendix A algorithm uses these passwords (nearly) directly, it is very important that they not be easily guessed ๐Ÿ”. The suggestion is to mix uppercase and lowercase alphanumeric and punctuation characters, and avoid words or phrases you'd find in a dictionary ๐ŸŒธ. Longer passwords make the system more secure โœจ. Users can also type in multiword phrases, which makes the string longer and still memorable ๐Ÿงš.

Here's the tricky bit: it's basically impossible for humans to keep a different password for every SNMP engine, but security requirements strongly discourage using the same key on more than one SNMP engine ๐Ÿ˜ฉ. So the User-based Security Model uses a compromise proposed in [Localized-key]. It derives the user keys for each SNMP engine from the user's password, in a way that makes it practically impossible to either work out the user's password, or the user's key for another SNMP engine, from any combination of the user's keys on SNMP engines ๐Ÿฆ‹.

Note however, that if the user's password is disclosed, key localization won't help, and network security may be compromised in this case. So a user's password or non-localized key MUST NOT be stored on a managed device/node. Instead, the localized key SHALL be stored (if at all), so that if a device does get compromised, no other managed or managing devices get compromised ๐Ÿšจ.

11.3. Conformance ๐ŸŽ€

To be termed a "Secure SNMP implementation" based on the User-based Security Model, an SNMP implementation MUST:

  • implement one or more Authentication Protocol(s). The HMAC-MD5-96 and HMAC-SHA-96 Authentication Protocols defined in this memo are examples of such protocols.
  • to the maximum extent possible, prohibit access to the secret(s) of each user about which it maintains information in a Local Configuration Datastore (LCD) under all circumstances except as required to generate and/or validate SNMP messages with respect to that user.
  • implement the key-localization mechanism.
  • implement the SNMP-USER-BASED-SM-MIB.

In addition, an authoritative SNMP engine SHOULD provide initial configuration in accordance with Appendix A.1 ๐ŸŒˆ.

Implementing a Privacy Protocol is optional. The DES Symmetric Encryption Protocol defined in this memo is one such protocol ๐Ÿ”’.


12. References ๐Ÿ“š

[RFC1321] Rivest, R., "Message Digest Algorithm MD5", RFC 1321, April 1992.

[RFC1903] Case, J., McCloghrie, K., Rose, M. and S. Waldbusser, "Textual Conventions for Version 2 of the Simple Network Management Protocol (SNMPv2)", RFC 1903, January 1996.

[RFC1905] Case, J., McCloghrie, K., Rose, M. and S. Waldbusser, "Protocol Operations for Version 2 of the Simple Network Management Protocol (SNMPv2)", RFC 1905, January 1996.

[RFC1906] Case, J., McCloghrie, K., Rose, M. and S. Waldbusser, "Transport Mappings for Version 2 of the Simple Network Management Protocol (SNMPv2)", RFC 1906, January 1996.

[RFC1907] Case, J., McCloghrie, K., Rose, M. and S. Waldbusser, "Management Information Base for Version 2 of the Simple Network Management Protocol (SNMPv2)", RFC 1907 January 1996.

[RFC2104] Krawczyk, H., Bellare, M., and R. Canetti, "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997.

[RFC2028] Hovey, R., and S. Bradner, "The Organizations Involved in the IETF Standards Process", BCP 11, RFC 2028, October 1996.

[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997.

[RFC2261] Harrington, D., Presuhn, R., and B. Wijnen, "An Architecture for describing SNMP Management Frameworks", RFC 2261, January 1998.

[RFC2262] Case, J., Harrington, D., Presuhn, R., and B. Wijnen, "Message Processing and Dispatching for the Simple Network Management Protocol (SNMP)", RFC 2262, January 1998.

[Localized-Key] U. Blumenthal, N. C. Hien, B. Wijnen "Key Derivation for Network Management Applications" IEEE Network Magazine, April/May issue, 1997.

[DES-NIST] Data Encryption Standard, National Institute of Standards and Technology. Federal Information Processing Standard (FIPS) Publication 46-1. Supersedes FIPS Publication 46, (January, 1977; reaffirmed January, 1988).

[DES-ANSI] Data Encryption Algorithm, American National Standards Institute. ANSI X3.92-1981, (December, 1980).

[DESO-NIST] DES Modes of Operation, National Institute of Standards and Technology. Federal Information Processing Standard (FIPS) Publication 81, (December, 1980).

[DESO-ANSI] Data Encryption Algorithm - Modes of Operation, American National Standards Institute. ANSI X3.106-1983, (May 1983).

[DESG-NIST] Guidelines for Implementing and Using the NBS Data Encryption Standard, National Institute of Standards and Technology. Federal Information Processing Standard (FIPS) Publication 74, (April, 1981).

[DEST-NIST] Validating the Correctness of Hardware Implementations of the NBS Data Encryption Standard, National Institute of Standards and Technology. Special Publication 500-20.

[DESM-NIST] Maintenance Testing for the Data Encryption Standard, National Institute of Standards and Technology. Special Publication 500-61, (August, 1980).

[SHA-NIST] Secure Hash Algorithm. NIST FIPS 180-1, (April, 1995) http://csrc.nist.gov/fips/fip180-1.txt (ASCII) http://csrc.nist.gov/fips/fip180-1.ps (Postscript)


13. Editors' Addresses ๐Ÿ’Œ

Uri Blumenthal

  • IBM T. J. Watson Research
  • 30 Saw Mill River Pkwy,
  • Hawthorne, NY 10532
  • USA
  • EMail: uri@watson.ibm.com
  • Phone: +1-914-784-7064

Bert Wijnen

  • IBM T. J. Watson Research
  • Schagen 33
  • 3461 GL Linschoten
  • Netherlands
  • EMail: wijnen@vnet.ibm.com
  • Phone: +31-348-432-794

APPENDIX A - Installation ๐Ÿ› ๏ธ

A.1. SNMP engine Installation Parameters ๐ŸŒธ

During installation, an authoritative SNMP engine SHOULD (in the meaning as defined in [RFC2119]) be configured with several initial parameters. These include:

  1. A security posture

The choice of security posture determines whether initial configuration is implemented and, if so, how. One of three possible choices is selected:

  • minimum-secure,
  • semi-secure,
  • very-secure (i.e., no-initial-configuration)

In the case of a very-secure posture, there is no initial configuration, so the following steps are irrelevant ๐Ÿ™ˆ.

  1. one or more secrets

These are the authentication/privacy secrets for the first user to be configured.

One way to accomplish this is to have the installer enter a "password" for each required secret. The password is then algorithmically converted into the required secret by:

  • forming a string of length 1,048,576 octets by repeating the value of the password as often as necessary, truncating accordingly, and using the resulting string as the input to the MD5 algorithm [MD5]. The resulting digest, termed "digest1", is used in the next step.
  • a second string is formed by concatenating digest1, the SNMP engine's snmpEngineID value, and digest1. This string is used as input to the MD5 algorithm [MD5].

The resulting digest is the required secret (see Appendix A.2) ๐Ÿ”‘.

With these configured parameters, the SNMP engine instantiates the following usmUserEntry in the usmUserTable:

                       no privacy support     privacy support
                       ------------------     ---------------
usmUserEngineID        localEngineID          localEngineID
usmUserName            "initial"              "initial"
usmUserSecurityName    "initial"              "initial"
usmUserCloneFrom       ZeroDotZero            ZeroDotZero
usmUserAuthProtocol    usmHMACMD5AuthProtocol usmHMACMD5AuthProtocol
usmUserAuthKeyChange   ""                     ""
usmUserOwnAuthKeyChange ""                    ""
usmUserPrivProtocol    none                   usmDESPrivProtocol
usmUserPrivKeyChange   ""                     ""
usmUserOwnPrivKeyChange ""                    ""
usmUserPublic          ""                     ""
usmUserStorageType     anyValidStorageType    anyValidStorageType
usmUserStatus          active                 active

A.2. Password to Key Algorithm ๐Ÿ—๏ธ

A sample code fragment (section A.2.1) demonstrates the password to key algorithm, which can be used when mapping a password to an authentication or privacy key using MD5. The reference source code of MD5 is available in [RFC1321] ๐Ÿ’œ.

Another sample code fragment (section A.2.2) demonstrates the password to key algorithm, which can be used when mapping a password to an authentication or privacy key using SHA (documented in SHA-NIST) ๐Ÿฆ‹.

An example of the results of a correct implementation is provided (section A.3), which an implementor can use to check whether their implementation produces the same result โœจ.

A.2.1. Password to Key Sample Code for MD5 ๐Ÿ’ป

void password_to_key_md5(
   u_char *password,    /* IN */
   u_int   passwordlen, /* IN */
   u_char *engineID,    /* IN  - pointer to snmpEngineID  */
   u_int   engineLength /* IN  - length of snmpEngineID */
   u_char *key)         /* OUT - pointer to caller 16-octet buffer */
   {
   MD5_CTX     MD;
   u_char     *cp, password_buf[64];
   u_long      password_index = 0;
   u_long      count = 0, i;

   MD5Init (&MD);   /* initialize MD5 */
   /**********************************************/
   /* Use while loop until we've done 1 Megabyte */
   /**********************************************/
   while (count < 1048576) {
      cp = password_buf;
      for (i = 0; i < 64; i++) {
          /*************************************************/
          /* Take the next octet of the password, wrapping */
          /* to the beginning of the password as necessary.*/
          /*************************************************/
          *cp++ = password[password_index++ % passwordlen];
      }
      MD5Update (&MD, password_buf, 64);
      count += 64;
   }
   MD5Final (key, &MD);          /* tell MD5 we're done */

   /*****************************************************/
   /* Now localize the key with the engineID and pass   */
   /* through MD5 to produce final key                  */
   /* May want to ensure that engineLength <= 32,       */
   /* otherwise need to use a buffer larger than 64     */
   /*****************************************************/
   memcpy(password_buf, key, 16);
   memcpy(password_buf+16, engineID, engineLength);
   memcpy(password_buf+engineLength, key, 16);

   MD5Init(&MD);
   MD5Update(&MD, password_buf, 32+engineLength);
   MD5Final(key, &MD);

   return;
}

Okay so that's the end of the MD5 function, and it's giving full "keep looping until we hit 1 Megabyte, then mix in the engineID" energy ๐Ÿ’…โœจ. The loop just keeps grabbing the next octet of the password and wraps back around to the start when it runs out, so the password gets stretched out over the whole megabyte ๐ŸŒธ. Then the final key gets localized by sandwiching it around the engineID and hashing again ๐Ÿซถ.

A.2.2. Password to Key Sample Code for SHA

The SHA version is literally the same vibe, just with SHA instead of MD5 and a bigger buffer, so you know it's a sibling situation ๐Ÿฆ‹.

void password_to_key_sha(
   u_char *password,    /* IN */
   u_int   passwordlen, /* IN */
   u_char *engineID,    /* IN  - pointer to snmpEngineID  */
   u_int   engineLength /* IN  - length of snmpEngineID */
   u_char *key)         /* OUT - pointer to caller 20-octet buffer */
{
   SHA_CTX     SH;
   u_char     *cp, password_buf[72];
   u_long      password_index = 0;
   u_long      count = 0, i;
   SHAInit (&SH);   /* initialize SHA */

   /**********************************************/
   /* Use while loop until we've done 1 Megabyte */
   /**********************************************/
   while (count < 1048576) {
      cp = password_buf;
      for (i = 0; i < 64; i++) {
          /*************************************************/
          /* Take the next octet of the password, wrapping */
          /* to the beginning of the password as necessary.*/
          /*************************************************/
          *cp++ = password[password_index++ % passwordlen];
      }
      SHAUpdate (&SH, password_buf, 64);
      count += 64;
   }
   SHAFinal (key, &SH);          /* tell SHA we're done */

   /*****************************************************/
   /* Now localize the key with the engineID and pass   */
   /* through SHA to produce final key                  */
   /* May want to ensure that engineLength <= 32,       */
   /* otherwise need to use a buffer larger than 72     */
   /*****************************************************/
   memcpy(password_buf, key, 20);
   memcpy(password_buf+20, engineID, engineLength);
   memcpy(password_buf+engineLength, key, 20);

   SHAInit(&SH);
   SHAUpdate(&SH, password_buf, 40+engineLength);
   SHAFinal(key, &SH);

   return;
}

Same 1 Megabyte loop, same wrap-around trick, same localize-then-hash finish ๐ŸŽ€. The only real differences are the 20-octet output buffer and the 72-octet password_buf, which is the one to watch because of that engineLength note ๐Ÿ‘€.

A.3. Password to Key Sample Results

Okay now the fun part, where we get to see what the algorithm actually spits out ๐Ÿ”ฅ. These examples all use the same password, so you can compare them side by side and see how the localization changes things ๐Ÿงš.

A.3.1. Password to Key Sample Results using MD5

The following shows a sample output of the password to key algorithm for a 16-octet key using MD5.

With a password of "maplesyrup" the output of the password to key algorithm before the key is localized with the SNMP engine's snmpEngineID is:

'9f af 32 83 88 4e 92 83 4e bc 98 47 d8 ed d9 63'H

After the intermediate key (shown above) is localized with the snmpEngineID value of:

'00 00 00 00 00 00 00 00 00 00 00 02'H

the final output of the password to key algorithm is:

'52 6f 5e ed 9f cc e2 6f 89 64 c2 93 07 87 d8 2b'H

See how the intermediate key and the final key look totally different even though the password is the same? That's the localization doing its thing ๐Ÿ’œ

A.3.2. Password to Key Sample Results using SHA

The following shows a sample output of the password to key algorithm for a 20-octet key using SHA.

With a password of "maplesyrup" the output of the password to key algorithm before the key is localized with the SNMP engine's snmpEngineID is:

'f1 be a9 ae 66 7f 4f b6 34 1e 51 af 06 80 7e 91 e4 3b 01 ac'H

After the intermediate key (shown above) is localized with the snmpEngineID value of:

'00 00 00 00 00 00 00 00 00 00 00 02'H

the final output of the password to key algorithm is:

'8a a3 d9 9e 3e 30 56 f2 bf e3 a9 ee f3 45 d5 39 54 91 12 be'H

Same password, same engineID, but this one's 20 octets long because it's SHA ๐ŸŒˆ

A.4. Sample encoding of msgSecurityParameters

The msgSecurityParameters in an SNMP message are represented as an OCTET STRING, and this OCTET STRING should be considered opaque outside a specific Security Model ๐Ÿ™ˆ. So basically the other parts of the message just treat it as a blob ๐Ÿซง.

The User-based Security Model defines the contents of the OCTET STRING as a SEQUENCE (see section 2.4) ๐Ÿ’–.

Given these two properties, the following is an example of the msgSecurityParameters for the User-based Security Model, encoded as an OCTET STRING:

  04 <length>
  30 <length>
  04 <length> <msgAuthoritativeEngineID>
  02 <length> <msgAuthoritativeEngineBoots>
  02 <length> <msgAuthoritativeEngineTime>
  04 <length> <msgUserName>
  04 0c       <HMAC-MD5-96-digest>
  04 08       <salt>

Here is the example once more, but now with real values (except for the digest in msgAuthenticationParameters and the salt in msgPrivacyParameters, which depend on variable data that we have not defined here) ๐Ÿฆ‹:

  Hex Data                         Description
  --------------  -----------------------------------------------
  04 39           OCTET STRING,                  length 57
  30 37           SEQUENCE,                      length 55
  04 0c 80000002  msgAuthoritativeEngineID:      IBM
        01                                       IPv4 address
        09840301                                 9.132.3.1
  02 01 01        msgAuthoritativeEngineBoots:   1
  02 02 0101      msgAuthoritativeEngineTime:    257
  04 04 62657274  msgUserName:                   bert
  04 0c 01234567  msgAuthenticationParameters:   sample value
        89abcdef
        fedcba98
  04 08 01234567  msgPrivacyParameters:          sample value
        89abcdef

Copyright (C) The Internet Society (1997). All Rights Reserved.

Okay so the legal bit, but make it cute ๐ŸŽ€. You're totally allowed to copy and share this document and translations of it, and you can even write derivative works that comment on or explain it or help implement it, and publish and distribute those too, in whole or in part, with no restrictions of any kind ๐Ÿซถ. The one catch is that the above copyright notice and this paragraph have to be included on all of those copies and derivative works โœจ. This document itself may not be modified in any way, like by removing the copyright notice or the references to the Internet Society or other Internet organizations ๐Ÿ™…. The only exceptions are if it's needed for developing Internet standards (in which case the copyright procedures in the Internet Standards process must be followed) or if it's needed to translate it into languages other than English ๐ŸŒธ.

The limited permissions above are perpetual, and they will not be revoked by the Internet Society or its successors or assigns ๐Ÿ’….

Now the disclaimer, which is giving all caps energy for a reason ๐Ÿ˜ญ. This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. ๐Ÿ”ฅ

๐Ÿ“ฆ where this page comes from