diff --git a/libsignal-service/src/provisioning/manager.rs b/libsignal-service/src/provisioning/manager.rs index 94cf292f6..0d7821d78 100644 --- a/libsignal-service/src/provisioning/manager.rs +++ b/libsignal-service/src/provisioning/manager.rs @@ -16,12 +16,13 @@ use super::{ use crate::{ account_manager::encrypt_device_name, - configuration::Endpoint, pre_keys::{ - generate_last_resort_kyber_key, generate_signed_pre_key, - KyberPreKeyEntity, PreKeysStore, SignedPreKey, + generate_last_resort_kyber_key, generate_signed_pre_key, PreKeysStore, + }, + push_service::{ + HttpAuth, LinkAccountAttributes, LinkCapabilities, LinkRequest, + LinkResponse, PushService, ServiceIds, }, - push_service::{HttpAuth, HttpAuthOverride, PushService, ServiceIds}, utils::serde_base64, }; @@ -208,33 +209,6 @@ impl LinkingManager

{ ) .await?; - #[derive(Debug, Serialize)] - #[serde(rename_all = "camelCase")] - struct LinkRequest { - verification_code: String, - account_attributes: AccountAttributes, - aci_signed_pre_key: SignedPreKey, - pni_signed_pre_key: SignedPreKey, - aci_pq_last_resort_pre_key: KyberPreKeyEntity, - pni_pq_last_resort_pre_key: KyberPreKeyEntity, - } - - #[derive(Debug, Serialize)] - #[serde(rename_all = "camelCase")] - struct AccountAttributes { - fetches_messages: bool, - name: String, - registration_id: u32, - pni_registration_id: u32, - capabilities: Capabilities, - } - - #[derive(Debug, Serialize)] - #[serde(rename_all = "camelCase")] - struct Capabilities { - pni: bool, - } - let encrypted_device_name = base64::encode( encrypt_device_name( csprng, @@ -253,11 +227,11 @@ impl LinkingManager

{ let request = LinkRequest { verification_code: provisioning_code, - account_attributes: AccountAttributes { + account_attributes: LinkAccountAttributes { registration_id, pni_registration_id, fetches_messages: true, - capabilities: Capabilities { pni: true }, + capabilities: LinkCapabilities { pni: true }, name: encrypted_device_name, }, aci_signed_pre_key: aci_signed_pre_key.try_into()?, @@ -268,30 +242,18 @@ impl LinkingManager

{ .try_into()?, }; - #[derive(Debug, Deserialize)] - #[serde(rename_all = "camelCase")] - struct LinkResponse { - #[serde(rename = "uuid")] - aci: Uuid, - pni: Uuid, - device_id: u32, - } - let LinkResponse { aci, pni, device_id, } = self .push_service - .put_json( - Endpoint::Service, - "/v1/devices/link", - &[], - HttpAuthOverride::Identified(HttpAuth { + .link_device( + &request, + HttpAuth { username: phone_number.to_string(), password: self.password.clone(), - }), - &request, + }, ) .await?; diff --git a/libsignal-service/src/push_service.rs b/libsignal-service/src/push_service.rs index 1536f1817..41cd0fe83 100644 --- a/libsignal-service/src/push_service.rs +++ b/libsignal-service/src/push_service.rs @@ -5,7 +5,8 @@ use crate::{ envelope::*, groups_v2::GroupDecodingError, pre_keys::{ - KyberPreKeyEntity, PreKeyEntity, PreKeyState, SignedPreKeyEntity, + KyberPreKeyEntity, PreKeyEntity, PreKeyState, SignedPreKey, + SignedPreKeyEntity, }, profile_cipher::ProfileCipherError, proto::{attachment_pointer::AttachmentIdentifier, AttachmentPointer}, @@ -381,6 +382,42 @@ pub struct StaleDevices { pub stale_devices: Vec, } +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct LinkRequest { + pub verification_code: String, + pub account_attributes: LinkAccountAttributes, + pub aci_signed_pre_key: SignedPreKey, + pub pni_signed_pre_key: SignedPreKey, + pub aci_pq_last_resort_pre_key: KyberPreKeyEntity, + pub pni_pq_last_resort_pre_key: KyberPreKeyEntity, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct LinkAccountAttributes { + pub fetches_messages: bool, + pub name: String, + pub registration_id: u32, + pub pni_registration_id: u32, + pub capabilities: LinkCapabilities, +} + +#[derive(Debug, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct LinkCapabilities { + pub pni: bool, +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct LinkResponse { + #[serde(rename = "uuid")] + pub aci: Uuid, + pub pni: Uuid, + pub device_id: u32, +} + #[derive(Debug, Deserialize)] #[serde(rename_all = "camelCase")] pub struct SignalServiceProfile { @@ -954,6 +991,21 @@ pub trait PushService: MaybeSend { Ok(SenderCertificate::deserialize(&cert.certificate)?) } + async fn link_device( + &mut self, + link_request: &LinkRequest, + http_auth: HttpAuth, + ) -> Result { + self.put_json( + Endpoint::Service, + "/v1/devices/link", + &[], + HttpAuthOverride::Identified(http_auth), + &link_request, + ) + .await + } + async fn set_account_attributes( &mut self, attributes: AccountAttributes,