Skip to content

Commit

Permalink
SNMPv3: Do not sign and encrypt report (for MikroTik compatibility)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvolodin7 committed Oct 30, 2024
1 parent 821358e commit 413fb04
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions src/socket/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,31 @@ impl SnmpV3ClientSocket {
}
// Send GET+Report to adjust boots and time
fn async_send_refresh(&mut self) -> PyResult<()> {
// Send plaintext/unsigned report
let request_id = self.request_id.get_next();
Ok(self.wrap_and_send(
SnmpPdu::GetRequest(SnmpGet {
request_id,
vars: vec![],
let msg = SnmpV3Message {
msg_id: self.msg_id.get_next(),
flag_auth: false,
flag_priv: false,
flag_report: true,
usm: UsmParameters {
engine_id: &self.engine_id,
engine_boots: self.engine_boots,
engine_time: self.engine_time,
user_name: EMPTY.as_ref(),
auth_params: EMPTY.as_ref(),
privacy_params: EMPTY.as_ref(),
},
data: MsgData::Plaintext(ScopedPdu {
engine_id: &self.engine_id,
pdu: SnmpPdu::GetRequest(SnmpGet {
request_id,
vars: vec![],
}),
}),
true,
)?)
};
self.io.send(msg)?;
Ok(())
}
// Try to receive GETRESPONSE for GETBULK
fn recv_get_bulk(&mut self, iter: &mut GetBulkIter, py: Python) -> PyResult<PyObject> {
Expand Down Expand Up @@ -354,12 +371,22 @@ impl SnmpV3ClientSocket {
// Receive refresh report
fn async_recv_refresh(&mut self) -> PyResult<()> {
loop {
match self.recv_and_unwrap()? {
Some(_) => {
return Ok(());
}
None => continue,
let msg = self.io.recv::<SnmpV3Message>()?;
let data = match msg.data {
MsgData::Plaintext(x) => x,
MsgData::Encrypted(_) => continue,
};
// Global header check
if !(self.msg_id.check(msg.msg_id) && data.pdu.check(&self.request_id)) {
continue;
}
self.engine_boots = msg.usm.engine_boots;
self.engine_time = msg.usm.engine_time;
if self.engine_id.is_empty() {
// Auto-detect engine id
self.engine_id.extend_from_slice(msg.usm.engine_id);
}
return Ok(());
}
}
//
Expand Down

0 comments on commit 413fb04

Please sign in to comment.