From afd03e17d3e3756dd360b1d8890244be2746c79c Mon Sep 17 00:00:00 2001 From: Kedar Sovani Date: Wed, 8 Feb 2023 19:11:01 +0530 Subject: [PATCH 1/2] Minor fixes --- examples/onoff_light/src/main.rs | 2 +- matter/src/fabric.rs | 2 +- matter/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/onoff_light/src/main.rs b/examples/onoff_light/src/main.rs index 2d64027..1eb5d63 100644 --- a/examples/onoff_light/src/main.rs +++ b/examples/onoff_light/src/main.rs @@ -32,7 +32,7 @@ fn main() { // vid/pid should match those in the DAC let dev_info = BasicInfoConfig { vid: 0xFFF1, - pid: 0x8002, + pid: 0x8000, hw_ver: 2, sw_ver: 1, sw_ver_str: "1".to_string(), diff --git a/matter/src/fabric.rs b/matter/src/fabric.rs index c5a2ce6..3299f4d 100644 --- a/matter/src/fabric.rs +++ b/matter/src/fabric.rs @@ -31,7 +31,7 @@ use crate::{ tlv::{OctetStr, TLVWriter, TagType, ToTLV, UtfStr}, }; -const MAX_CERT_TLV_LEN: usize = 300; +const MAX_CERT_TLV_LEN: usize = 350; const COMPRESSED_FABRIC_ID_LEN: usize = 8; macro_rules! fb_key { diff --git a/matter/src/lib.rs b/matter/src/lib.rs index f276961..9f03ac5 100644 --- a/matter/src/lib.rs +++ b/matter/src/lib.rs @@ -45,7 +45,7 @@ //! //! /// The basic information about this device //! let dev_info = BasicInfoConfig { -//! vid: 0x8002, +//! vid: 0x8000, //! pid: 0xFFF1, //! hw_ver: 2, //! sw_ver: 1, From 11d50485a4e630b4792ea78b49ed9a0663e4b671 Mon Sep 17 00:00:00 2001 From: Kedar Sovani Date: Wed, 8 Feb 2023 19:11:14 +0530 Subject: [PATCH 2/2] ASN1: Fix incorrect time encoding for year >= 2050 --- matter/src/cert/asn1_writer.rs | 12 ++++++-- matter/src/cert/mod.rs | 54 +++++++++++++++++----------------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/matter/src/cert/asn1_writer.rs b/matter/src/cert/asn1_writer.rs index 3cb7f47..b3bb13c 100644 --- a/matter/src/cert/asn1_writer.rs +++ b/matter/src/cert/asn1_writer.rs @@ -17,7 +17,7 @@ use super::{CertConsumer, MAX_DEPTH}; use crate::error::Error; -use chrono::{TimeZone, Utc}; +use chrono::{Datelike, TimeZone, Utc}; use log::warn; #[derive(Debug)] @@ -277,7 +277,13 @@ impl<'a> CertConsumer for ASN1Writer<'a> { } }; - let time_str = format!("{}Z", dt.format("%y%m%d%H%M%S")); - self.write_str(0x17, time_str.as_bytes()) + if dt.year() >= 2050 { + // If year is >= 2050, ASN.1 requires it to be Generalised Time + let time_str = format!("{}Z", dt.format("%Y%m%d%H%M%S")); + self.write_str(0x18, time_str.as_bytes()) + } else { + let time_str = format!("{}Z", dt.format("%y%m%d%H%M%S")); + self.write_str(0x17, time_str.as_bytes()) + } } } diff --git a/matter/src/cert/mod.rs b/matter/src/cert/mod.rs index 61d7bf2..b3f9338 100644 --- a/matter/src/cert/mod.rs +++ b/matter/src/cert/mod.rs @@ -668,7 +668,7 @@ impl<'a> CertVerifier<'a> { let k = KeyPair::new_from_public(parent.get_pubkey())?; k.verify_msg(asn1, self.cert.get_signature()).map_err(|e| { error!( - "Error in signature verification of certificate: {:#02x?}", + "Error in signature verification of certificate: {:x?}", self.cert.get_subject_key_id() ); e @@ -706,7 +706,7 @@ pub trait CertConsumer { } const MAX_DEPTH: usize = 10; -const MAX_ASN1_CERT_SIZE: usize = 800; +const MAX_ASN1_CERT_SIZE: usize = 1000; mod asn1_writer; mod printer; @@ -1025,8 +1025,8 @@ mod tests { 0xbf, 0x68, 0x18, 0x59, 0x7f, 0xf7, 0xe8, 0xaf, 0x88, 0x91, 0x1c, 0x72, 0x32, 0xf7, 0x52, ]; - pub const ASN1_OUTPUT_TXT_IN_DN: [u8; 427] = [ - 0x30, 0x82, 0x01, 0xa7, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x01, 0x30, 0x0a, + pub const ASN1_OUTPUT_TXT_IN_DN: [u8; 429] = [ + 0x30, 0x82, 0x01, 0xa9, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x01, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x56, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, @@ -1034,29 +1034,29 @@ mod tests { 0x74, 0x65, 0x72, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xa2, 0x7c, 0x01, 0x04, 0x0c, 0x10, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, - 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x31, 0x31, 0x32, 0x30, 0x38, 0x32, 0x30, 0x33, 0x30, - 0x35, 0x35, 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x31, 0x32, 0x30, 0x38, 0x32, 0x30, 0x33, - 0x30, 0x35, 0x35, 0x5a, 0x30, 0x56, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, - 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, 0x04, 0x0a, - 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x31, 0x14, 0x30, 0x12, 0x06, 0x03, - 0x55, 0x04, 0x03, 0x0c, 0x0b, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, 0x52, 0x6f, - 0x6f, 0x74, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, - 0xa2, 0x7c, 0x01, 0x04, 0x0c, 0x10, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, 0x45, - 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, - 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, - 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x5b, 0x37, 0xdf, 0x65, 0x49, 0xc2, 0x0d, - 0xc8, 0xd7, 0x22, 0xa6, 0xb8, 0xac, 0xb6, 0x60, 0xa8, 0xa7, 0x64, 0xce, 0x7b, 0xaf, - 0x6c, 0x6c, 0x22, 0x4f, 0x7e, 0xe8, 0x43, 0x49, 0x68, 0x4a, 0xd7, 0xd8, 0x09, 0xff, - 0x65, 0x00, 0x33, 0xd1, 0x52, 0x7d, 0xcf, 0x1f, 0xba, 0xac, 0x6a, 0x9c, 0x3a, 0xd8, - 0xb4, 0x1e, 0xda, 0xc9, 0x09, 0xf7, 0xb5, 0xc7, 0x60, 0xfd, 0x54, 0x2c, 0x89, 0x23, - 0x75, 0xa3, 0x66, 0x30, 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, - 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01, 0x30, 0x0e, 0x06, - 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, - 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x72, 0xc2, 0x01, 0xf7, - 0x57, 0x19, 0x13, 0xb3, 0x48, 0xca, 0x00, 0xca, 0x7b, 0x45, 0xf4, 0x77, 0x46, 0x68, - 0xc9, 0x7e, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, - 0x14, 0x72, 0xc2, 0x01, 0xf7, 0x57, 0x19, 0x13, 0xb3, 0x48, 0xca, 0x00, 0xca, 0x7b, - 0x45, 0xf4, 0x77, 0x46, 0x68, 0xc9, 0x7e, + 0x30, 0x20, 0x17, 0x0d, 0x32, 0x31, 0x31, 0x32, 0x30, 0x38, 0x32, 0x30, 0x33, 0x30, + 0x35, 0x35, 0x5a, 0x18, 0x0f, 0x32, 0x31, 0x32, 0x31, 0x31, 0x32, 0x30, 0x38, 0x32, + 0x30, 0x33, 0x30, 0x35, 0x35, 0x5a, 0x30, 0x56, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, + 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x0f, 0x30, 0x0d, 0x06, 0x03, 0x55, + 0x04, 0x0a, 0x0c, 0x06, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x31, 0x14, 0x30, 0x12, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0b, 0x4d, 0x61, 0x74, 0x74, 0x65, 0x72, 0x20, + 0x52, 0x6f, 0x6f, 0x74, 0x31, 0x20, 0x30, 0x1e, 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, + 0x01, 0x82, 0xa2, 0x7c, 0x01, 0x04, 0x0c, 0x10, 0x46, 0x46, 0x46, 0x46, 0x46, 0x46, + 0x46, 0x45, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x59, 0x30, 0x13, + 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, + 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0x5b, 0x37, 0xdf, 0x65, 0x49, + 0xc2, 0x0d, 0xc8, 0xd7, 0x22, 0xa6, 0xb8, 0xac, 0xb6, 0x60, 0xa8, 0xa7, 0x64, 0xce, + 0x7b, 0xaf, 0x6c, 0x6c, 0x22, 0x4f, 0x7e, 0xe8, 0x43, 0x49, 0x68, 0x4a, 0xd7, 0xd8, + 0x09, 0xff, 0x65, 0x00, 0x33, 0xd1, 0x52, 0x7d, 0xcf, 0x1f, 0xba, 0xac, 0x6a, 0x9c, + 0x3a, 0xd8, 0xb4, 0x1e, 0xda, 0xc9, 0x09, 0xf7, 0xb5, 0xc7, 0x60, 0xfd, 0x54, 0x2c, + 0x89, 0x23, 0x75, 0xa3, 0x66, 0x30, 0x64, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, + 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01, 0x30, + 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, + 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x72, 0xc2, + 0x01, 0xf7, 0x57, 0x19, 0x13, 0xb3, 0x48, 0xca, 0x00, 0xca, 0x7b, 0x45, 0xf4, 0x77, + 0x46, 0x68, 0xc9, 0x7e, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0x72, 0xc2, 0x01, 0xf7, 0x57, 0x19, 0x13, 0xb3, 0x48, 0xca, 0x00, + 0xca, 0x7b, 0x45, 0xf4, 0x77, 0x46, 0x68, 0xc9, 0x7e, ]; } }