rasn icon indicating copy to clipboard operation
rasn copied to clipboard

`rasn_snmp::v2::IpAddress` allows for !=4 byte IPs whereas the RFC does not

Open repnop opened this issue 2 years ago • 1 comments

Section 3 of the Version 2 of the Protocol Operations for the Simple Network Management Protocol (SNMP) RFC specifies IpAddress as the following: IpAddress ::= [APPLICATION 0] IMPLICIT OCTET STRING (SIZE (4)) which only allows 4-byte IPv4 addresses, whereas rasn_snmp::v2::IpAddress allows for arbitrarily sized, malformed IPs:

#[test]
fn bad_ip_address() {
    let ip = IpAddress {
        0: OctetString::from_static(&[255, 255, 255]),
    };
    assert_eq!(
        rasn::ber::decode::<IpAddress>(&rasn::ber::encode(&ip).unwrap()).unwrap(),
        ip
    );
}

Also unrelated, but I think the type alias for rasn_smi::v2::Integer32 is incorrect as well, its currently:

pub type Integer32 = u32;

but I think it should be

pub type Integer32 = i32;

since the unsigned 32-bit integer type is already covered by Gauge and by type alias Unsigned32

repnop avatar Feb 18 '22 16:02 repnop

Thank you for your issue! This is a known limitation currently. Rasn only guarantees that the type is a valid ASN.1 message, and doesn't do any checks for constraints, so you can receive semantically invalid messages. This will be fixed with the addition PER which requires constraints in the codec framework in order to properly encode.

XAMPPRocky avatar Mar 09 '22 10:03 XAMPPRocky