MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / validate_mic

Method validate_mic

chirpstack/src/uplink/join.rs:394–451  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

392 }
393
394 async fn validate_mic(&self) -> Result<()> {
395 let device_keys = self.device_keys.as_ref().unwrap();
396
397 if let Some(relay_ctx) = self.relay_context.as_ref() {
398 if relay_ctx
399 .req
400 .payload
401 .validate_join_request_mic(&device_keys.nwk_key)?
402 {
403 return Ok(());
404 }
405 } else if self
406 .uplink_frame_set
407 .phy_payload
408 .validate_join_request_mic(&device_keys.nwk_key)?
409 {
410 return Ok(());
411 }
412
413 let app = self.application.as_ref().unwrap();
414 let dev = self.device.as_ref().unwrap();
415
416 integration::log_event(
417 app.id.into(),
418 &dev.variables,
419 &integration_pb::LogEvent {
420 time: Some(Utc::now().into()),
421 device_info: self.device_info.clone(),
422 level: integration_pb::LogLevel::Error.into(),
423 code: integration_pb::LogCode::UplinkMic.into(),
424 description: "MIC of join-request is invalid, make sure keys are correct".into(),
425 context: [(
426 "deduplication_id".to_string(),
427 self.uplink_frame_set.uplink_set_id.to_string(),
428 )]
429 .iter()
430 .cloned()
431 .collect(),
432 },
433 )
434 .await;
435
436 metrics::save(
437 &format!("device:{}", dev.dev_eui),
438 &metrics::Record {
439 time: Local::now(),
440 kind: metrics::Kind::ABSOLUTE,
441 metrics: [("error_UPLINK_MIC".into(), 1f64)]
442 .iter()
443 .cloned()
444 .collect(),
445 },
446 &metrics::Aggregation::default_aggregations(),
447 )
448 .await?;
449
450 Err(anyhow!("Invalid MIC"))
451 }

Callers 2

_handleMethod · 0.45
_handle_relayedMethod · 0.45

Calls 8

unwrapMethod · 0.80
as_refMethod · 0.80
iterMethod · 0.80
to_stringMethod · 0.80
log_eventFunction · 0.50
saveFunction · 0.50
intoMethod · 0.45

Tested by

no test coverage detected