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 Levela security levelNoAuthNoPrivAuthNoPrivAuthPriv
impl Level
fn parse(s: &str) -> Option<Level>"noAuthNoPriv", "authNoPriv", "authPriv" (also shorter: as net-snmp's tools take them)fn word(self) -> &'static strfn flags(self) -> u8its bits of msgFlagsfn of_flags(f: u8) -> Option<Level>the level of msgFlags (None: privacy without authentication, which RFC 3412 7.2 refuses)enum AuthProtoan authentication protocolMd5Sha1Sha256Sha384Sha512
impl AuthProto
fn parse(s: &str) -> Option<AuthProto>fn name(self) -> &'static strfn tag_len(self) -> usizethe bytes of msgAuthenticationParametersenum PrivProtoa privacy protocolAes128
impl PrivProto
fn parse(s: &str) -> Option<PrivProto>fn name(self) -> &'static strfn 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 enginefn priv_key(kul: &[u8]) -> Vec<u8>the privacy key of RFC 3826 3.1.2.1fn tag(auth: AuthProto, key: &[u8], msg: &[u8]) -> Vec<u8>the truncated HMAC of a whole messagestruct UsmmsgSecurityParameters of the USMengine_id: Vec<u8>boots: i32time: i32user: Vec<u8>auth: Vec<u8>-- msgAuthenticationParametersprivacy: Vec<u8>-- msgPrivacyParameters: the salt
struct ScopedPdua PDU with its contextcontext_engine: Vec<u8>context_name: Vec<u8>pdu: Pdu
enum Scopedthe scoped PDU of a messagePlain(ScopedPdu)Encrypted(Vec<u8>)
struct V3an SNMPv3 messageid: i32max_size: i32flags: u8model: i32usm: Usmscoped: 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 flagsfn reportable(&self) -> boolfn plain(&self) -> Option<&ScopedPdu>the plain scoped PDU, if it is plainfn sign(bytes: &mut [u8], auth: AuthProto, key: &[u8]) -> boolputs the tag into a message written with zeros in msgAuthenticationParametersfn check(bytes: &[u8], auth: AuthProto, key: &[u8]) -> boolthe tag of a message is rightfn 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 wayfn 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 namedfn parse_engine_id(s: &str) -> Option<Vec<u8>>hexadecimal text, 5 to 32 bytesfn 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 strthe name of a report's counterfn report_pdu(request_id: i32, counter: &[u32], value: u32) -> Pdua Report PDU with one counter