JFLib

netpkt/snmpv3.rs#

Source: lib/netpkt/snmpv3.rs

snmpv3 -- SNMPv3 messages with the User-based Security Model (RFC 3412, RFC 3414), AES-128 for
privacy (RFC 3826), HMAC-SHA-2 for authentication (RFC 7860) and engine IDs (RFC 3411 5); the PDUs
are those of netpkt::snmp

  F_AUTH, F_PRIV, F_REPORTABLE     the bits of msgFlags; MODEL_USM (3)
  Level                            NoAuthNoPriv | AuthNoPriv | AuthPriv: parse, word(), flags(),
                                   of_flags(flags) (None: privacy without authentication)
  AuthProto                        Md5 | Sha1 | Sha256 | Sha384 | Sha512: parse ("MD5", "SHA",
                                   "SHA-256" ...), name(), tag_len() (12, 12, 24, 32, 48)
  PrivProto                        Aes128: parse ("AES", "AES128"), name()
  password_to_key(auth, password)  RFC 3414 A.2: a megabyte of the repeated password hashed
  localize(auth, ku, engine_id)    the key of one engine (RFC 3414 A.2.2), hash length
  priv_key(kul)                    the first 16 bytes (RFC 3826 3.1.2.1)
  tag(auth, key, msg)              the truncated HMAC
  Usm { engine_id, boots, time, user, auth, privacy }   msgSecurityParameters
  ScopedPdu { context_engine, context_name, pdu }
  Scoped                           Plain(ScopedPdu) | Encrypted(bytes)
  V3 { id, max_size, flags, model, usm, scoped }: parse(b), to_bytes(), level(), reportable()
  sign(bytes, auth, key)           puts the tag into a message written with zeros in msgAuthParameters;
  check(bytes, auth, key)          compares it (false also when it is no message or has
                                   another length)
  encrypt(key, boots, time, salt, plain) / decrypt(...) AES-128-CFB with the IV of RFC 3826 3.1.2.1
  open(enc) -> ScopedPdu           the plain bytes as a scoped PDU
  engine_id_mac(mac)               format 3 (MAC) under the enterprise number 32473 for
                                   documentation (RFC 5612), parse_engine_id(hex) (5 to 32 bytes),
                                   engine_id_text(bytes) (hex)
  USM_STATS_* , UNKNOWN_CONTEXTS   the counters of report PDUs; report_name(oid)

DES (the other privacy protocol of RFC 3414) has no place in crypto and is not here.
F_AUTH: u8 = 1
F_PRIV: u8 = 2
F_REPORTABLE: u8 = 4
/// the User-based Security Model
MODEL_USM: i64 = 3
/// the message size we say we take
MAX_SIZE: i64 = 65507
  • enum Level a security level
    • NoAuthNoPriv
    • AuthNoPriv
    • AuthPriv

impl Level

  • fn parse(s: &str) -> Option<Level> "noAuthNoPriv", "authNoPriv", "authPriv" (also shorter: as net-snmp's tools take them)

  • fn word(self) -> &'static str

  • fn flags(self) -> u8 its bits of msgFlags

  • fn of_flags(f: u8) -> Option<Level> the level of msgFlags (None: privacy without authentication, which RFC 3412 7.2 refuses)

  • enum AuthProto an authentication protocol

    • Md5
    • Sha1
    • Sha256
    • Sha384
    • Sha512

impl AuthProto

  • fn parse(s: &str) -> Option<AuthProto>

  • fn name(self) -> &'static str

  • fn tag_len(self) -> usize the bytes of msgAuthenticationParameters

  • enum PrivProto a privacy protocol

    • Aes128

impl PrivProto

  • fn parse(s: &str) -> Option<PrivProto>

  • fn name(self) -> &'static str

  • fn password_to_key(auth: AuthProto, password: &[u8]) -> Vec<u8> RFC 3414 A.2: a password as a key for any engine (an empty password gives no key)

  • fn localize(auth: AuthProto, ku: &[u8], engine_id: &[u8]) -> Vec<u8> RFC 3414 A.2.2: the key of one engine

  • fn priv_key(kul: &[u8]) -> Vec<u8> the privacy key of RFC 3826 3.1.2.1

  • fn tag(auth: AuthProto, key: &[u8], msg: &[u8]) -> Vec<u8> the truncated HMAC of a whole message

  • struct Usm msgSecurityParameters of the USM

    • engine_id: Vec<u8>
    • boots: i32
    • time: i32
    • user: Vec<u8>
    • auth: Vec<u8> -- msgAuthenticationParameters
    • privacy: Vec<u8> -- msgPrivacyParameters: the salt
  • struct ScopedPdu a PDU with its context

    • context_engine: Vec<u8>
    • context_name: Vec<u8>
    • pdu: Pdu
  • enum Scoped the scoped PDU of a message

    • Plain(ScopedPdu)
    • Encrypted(Vec<u8>)
  • struct V3 an SNMPv3 message

    • id: i32
    • max_size: i32
    • flags: u8
    • model: i32
    • usm: Usm
    • scoped: Scoped

impl ScopedPdu

  • fn to_bytes(&self) -> Vec<u8>
  • fn parse(b: &[u8]) -> Result<ScopedPdu, Bad> plain bytes as a scoped PDU

impl V3

  • fn parse(b: &[u8]) -> Result<V3, Bad> bytes as a message (Bad::Version: another version)

  • fn to_bytes(&self) -> Vec<u8>

  • fn level(&self) -> Option<Level> the security level of its flags

  • fn reportable(&self) -> bool

  • fn plain(&self) -> Option<&ScopedPdu> the plain scoped PDU, if it is plain

  • fn sign(bytes: &mut [u8], auth: AuthProto, key: &[u8]) -> bool puts the tag into a message written with zeros in msgAuthenticationParameters

  • fn check(bytes: &[u8], auth: AuthProto, key: &[u8]) -> bool the tag of a message is right

  • fn encrypt(key: &[u8], boots: i32, time: i32, salt: &[u8], plain: &[u8]) -> Option<Vec<u8>> AES-128-CFB of RFC 3826 (None: a key or salt of another length)

  • fn decrypt(key: &[u8], boots: i32, time: i32, salt: &[u8], cipher: &[u8]) -> Option<Vec<u8>> the other way

  • fn engine_id_mac(mac: Mac) -> Vec<u8> format 3 (a MAC address) under the enterprise number for documentation (RFC 5612), so no real vendor is named

  • fn parse_engine_id(s: &str) -> Option<Vec<u8>> hexadecimal text, 5 to 32 bytes

  • fn engine_id_text(b: &[u8]) -> String

report PDUs

USM_STATS_UNSUPPORTED_SEC_LEVELS: [u32; 11] = [1, 3, 6, 1, 6, 3, 15, 1, 1, 1, 0]
USM_STATS_NOT_IN_TIME_WINDOWS: [u32; 11] = [1, 3, 6, 1, 6, 3, 15, 1, 1, 2, 0]
USM_STATS_UNKNOWN_USER_NAMES: [u32; 11] = [1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0]
USM_STATS_UNKNOWN_ENGINE_IDS: [u32; 11] = [1, 3, 6, 1, 6, 3, 15, 1, 1, 4, 0]
USM_STATS_WRONG_DIGESTS: [u32; 11] = [1, 3, 6, 1, 6, 3, 15, 1, 1, 5, 0]
USM_STATS_DECRYPTION_ERRORS: [u32; 11] = [1, 3, 6, 1, 6, 3, 15, 1, 1, 6, 0]
/// snmpUnknownContexts of RFC 3413 (a context name the engine does not have)
UNKNOWN_CONTEXTS: [u32; 10] = [1, 3, 6, 1, 6, 3, 12, 1, 5, 0]
  • fn report_name(oid: &[u32]) -> &'static str the name of a report's counter

  • fn report_pdu(request_id: i32, counter: &[u32], value: u32) -> Pdu a Report PDU with one counter

Source: docs/API.md in the JFLib repository.