Skip to content

Commit 6b6d6b9

Browse files
committed
Fix message counter issues
1 parent f0abded commit 6b6d6b9

File tree

4 files changed

+55
-45
lines changed

4 files changed

+55
-45
lines changed

src/ids/identity_manager.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,26 @@ pub struct KeyCache {
180180

181181
impl KeyCache {
182182
pub async fn new(path: PathBuf, conn: &APSConnectionResource, users: &[IDSUser], services: &[&IDSService]) -> KeyCache {
183+
let mut message_counter = HashMap::new();
183184
if let Ok(data) = fs::read(&path) {
184185
if let Ok(mut loaded) = plist::from_reader_xml::<_, KeyCache>(Cursor::new(&data)) {
185186
loaded.cache_location = path;
186187
loaded.verity(conn, users, services).await;
187188
return loaded
189+
} else {
190+
#[derive(Deserialize)]
191+
struct RecoveryKeyCache {
192+
message_counter: HashMap<String, u32>,
193+
}
194+
// Stop bad updates from WIPING MESSAGE COUNTERS
195+
if let Ok(recovery) = plist::from_reader_xml::<_, RecoveryKeyCache>(Cursor::new(&data)) {
196+
message_counter = recovery.message_counter;
197+
}
188198
}
189199
}
190200
let mut cache = KeyCache {
191201
cache: HashMap::new(),
192-
message_counter: HashMap::new(),
202+
message_counter,
193203
cache_location: path,
194204
};
195205
cache.verity(conn, users, services).await;
@@ -306,7 +316,7 @@ impl KeyCache {
306316
let Some(cached) = handle_cache.keys.get(r#for) else {
307317
return None
308318
};
309-
Some(cached.keys.sender_correlation_identifier.clone())
319+
cached.keys.sender_correlation_identifier.clone()
310320
}
311321

312322
pub fn does_not_need_refresh(&self, service: &str, handle: &str, keys_for: &str, refresh: bool) -> bool {

src/ids/user.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ struct IDSLookupResp {
626626
#[serde(rename_all = "kebab-case")]
627627
pub struct IDSLookupUser {
628628
pub identities: Vec<IDSDeliveryData>,
629-
pub sender_correlation_identifier: String,
629+
pub sender_correlation_identifier: Option<String>,
630630
}
631631

632632
#[derive(Deserialize, Clone, Debug, Serialize)]

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub use imessage::aps_client::{IMClient, MADRID_SERVICE};
4545
use util::encode_hex;
4646
pub use util::{NSArrayClass, EntitlementsResponse, EntitlementAuthState, ResourceState, NSDictionaryClass, NSURL, NSArray, ResourceFailure, NSAttributedString, NSString, NSDictionaryTypedCoder, NSNumber, coder_encode_flattened, coder_decode_flattened, StCollapsedValue};
4747
pub use ids::user::{IDSUser, register, IDSUserIdentity, IDSNGMIdentity, PrivateDeviceInfo, SupportAlert, SupportAction, ReportMessage};
48-
pub use ids::identity_manager::{SendJob, MessageTarget, IdentityManager};
48+
pub use ids::identity_manager::{SendJob, MessageTarget, IdentityManager, KeyCache};
4949
pub use ids::CertifiedContext;
5050
pub use auth::{authenticate_apple, login_apple_delegates, authenticate_phone, authenticate_smsless, AuthPhone, LoginDelegate, CircleClientSession, TokenProvider};
5151
pub use error::PushError;

src/test.rs

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ async fn main() {
860860
print!(">> ");
861861
std::io::stdout().flush().unwrap();
862862

863-
// let mut received_msgs = vec![];
863+
let mut received_msgs = vec![];
864864
let mut last_ft_guid = "AE271F00-2F67-42C4-8EF2-74600055A2B7".to_string();
865865

866866
let mut circle_session: Option<CircleServerSession<DefaultAnisetteProvider>> = None;
@@ -932,46 +932,46 @@ async fn main() {
932932
// }
933933
// }
934934
// }
935-
// let msg = client.handle(msg).await;
936-
// if msg.is_err() {
937-
// error!("Failed to receive {}", msg.err().unwrap());
938-
// continue;
939-
// }
940-
// if let Ok(Some(msg)) = msg {
941-
// if msg.has_payload() && !received_msgs.contains(&msg.id) {
942-
// received_msgs.push(msg.id.clone());
943-
// if let Message::ShareProfile(message) = &msg.message {
944-
// if let Err(e) = name_photo_client.get_record(&message).await {
945-
// error!("{e}");
946-
// }
947-
// }
948-
// if let Message::UpdateProfile(UpdateProfileMessage { profile: Some(profile), .. }) = &msg.message {
949-
// if let Ok(record) = name_photo_client.get_record(&profile).await {
950-
// // handle_record(record, &client, &name_photo_client, &profile).await;
951-
// }
952-
// }
953-
// if let Message::UpdateProfile(UpdateProfileMessage { profile: Some(profile), .. }) = &msg.message {
954-
// if let Ok(record) = name_photo_client.get_record(&profile).await {
955-
// // handle_record(record, &client, &name_photo_client, &profile).await;
956-
// }
957-
// }
958-
// if let Message::SetTranscriptBackground(msg) = &msg.message {
959-
// if let Some(mmcs) = msg.to_mmcs() {
960-
// let mut output = vec![];
961-
// let file = Cursor::new(&mut output);
962-
// mmcs.get_attachment(&*connection, file, |a, b| { }).await.unwrap();
963-
// SimplifiedTranscriptPoster::parse_payload(&output).unwrap();
964-
// }
965-
// }
966-
// println!("{}", msg);
967-
// print!(">> ");
968-
// std::io::stdout().flush().unwrap();
969-
// if let Some(context) = msg.certified_context {
970-
// println!("sending delivered {}", msg.send_delivered);
971-
// client.identity.certify_delivery("com.apple.madrid", &context, false).await.unwrap();
972-
// }
973-
// }
974-
// }
935+
let msg = client.handle(msg).await;
936+
if msg.is_err() {
937+
error!("Failed to receive {}", msg.err().unwrap());
938+
continue;
939+
}
940+
if let Ok(Some(msg)) = msg {
941+
if msg.has_payload() && !received_msgs.contains(&msg.id) {
942+
received_msgs.push(msg.id.clone());
943+
// if let Message::ShareProfile(message) = &msg.message {
944+
// if let Err(e) = name_photo_client.get_record(&message).await {
945+
// error!("{e}");
946+
// }
947+
// }
948+
// if let Message::UpdateProfile(UpdateProfileMessage { profile: Some(profile), .. }) = &msg.message {
949+
// if let Ok(record) = name_photo_client.get_record(&profile).await {
950+
// // handle_record(record, &client, &name_photo_client, &profile).await;
951+
// }
952+
// }
953+
// if let Message::UpdateProfile(UpdateProfileMessage { profile: Some(profile), .. }) = &msg.message {
954+
// if let Ok(record) = name_photo_client.get_record(&profile).await {
955+
// // handle_record(record, &client, &name_photo_client, &profile).await;
956+
// }
957+
// }
958+
// if let Message::SetTranscriptBackground(msg) = &msg.message {
959+
// if let Some(mmcs) = msg.to_mmcs() {
960+
// let mut output = vec![];
961+
// let file = Cursor::new(&mut output);
962+
// mmcs.get_attachment(&*connection, file, |a, b| { }).await.unwrap();
963+
// SimplifiedTranscriptPoster::parse_payload(&output).unwrap();
964+
// }
965+
// }
966+
println!("{}", msg);
967+
print!(">> ");
968+
std::io::stdout().flush().unwrap();
969+
if let Some(context) = msg.certified_context {
970+
println!("sending delivered {}", msg.send_delivered);
971+
client.identity.certify_delivery("com.apple.madrid", &context, false).await.unwrap();
972+
}
973+
}
974+
}
975975
// },
976976
// input = &mut read_task => {
977977
// let Ok(input) = input else {

0 commit comments

Comments
 (0)