This repository was archived by the owner on Sep 10, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed
Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -130,6 +130,9 @@ struct SynapseDeactivateUserRequest {
130130 erase : bool ,
131131}
132132
133+ #[ derive( Serialize ) ]
134+ struct SynapseAllowCrossSigningResetRequest { }
135+
133136#[ async_trait:: async_trait]
134137impl HomeserverConnection for SynapseConnection {
135138 type Error = anyhow:: Error ;
@@ -366,4 +369,37 @@ impl HomeserverConnection for SynapseConnection {
366369 async fn unset_displayname ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > {
367370 self . set_displayname ( mxid, "" ) . await
368371 }
372+
373+ #[ tracing:: instrument(
374+ name = "homeserver.allow_cross_signing_reset" ,
375+ skip_all,
376+ fields(
377+ matrix. homeserver = self . homeserver,
378+ matrix. mxid = mxid,
379+ ) ,
380+ err( Display ) ,
381+ ) ]
382+ async fn allow_cross_signing_reset ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > {
383+ let mut client = self
384+ . http_client_factory
385+ . client ( "homeserver.allow_cross_signing_reset" )
386+ . request_bytes_to_body ( )
387+ . json_request ( ) ;
388+
389+ let request = self
390+ . post ( & format ! (
391+ "_synapse/admin/v1/users/{mxid}/_allow_cross_signing_replacement_without_uia"
392+ ) )
393+ . body ( SynapseAllowCrossSigningResetRequest { } ) ?;
394+
395+ let response = client. ready ( ) . await ?. call ( request) . await ?;
396+
397+ if response. status ( ) != StatusCode :: OK {
398+ return Err ( anyhow:: anyhow!(
399+ "Failed to allow cross signing reset in Synapse"
400+ ) ) ;
401+ }
402+
403+ Ok ( ( ) )
404+ }
369405}
Original file line number Diff line number Diff line change @@ -282,6 +282,18 @@ pub trait HomeserverConnection: Send + Sync {
282282 /// Returns an error if the homeserver is unreachable or the displayname
283283 /// could not be unset.
284284 async fn unset_displayname ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > ;
285+
286+ /// Temporarily allow a user to reset their cross-signing keys.
287+ ///
288+ /// # Parameters
289+ ///
290+ /// * `mxid` - The Matrix ID of the user to allow cross-signing key reset
291+ ///
292+ /// # Errors
293+ ///
294+ /// Returns an error if the homeserver is unreachable or the cross-signing
295+ /// reset could not be allowed.
296+ async fn allow_cross_signing_reset ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > ;
285297}
286298
287299#[ async_trait:: async_trait]
@@ -319,4 +331,8 @@ impl<T: HomeserverConnection + Send + Sync + ?Sized> HomeserverConnection for &T
319331 async fn unset_displayname ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > {
320332 ( * * self ) . unset_displayname ( mxid) . await
321333 }
334+
335+ async fn allow_cross_signing_reset ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > {
336+ ( * * self ) . allow_cross_signing_reset ( mxid) . await
337+ }
322338}
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ struct MockUser {
2626 displayname : Option < String > ,
2727 devices : HashSet < String > ,
2828 emails : Option < Vec < String > > ,
29+ cross_signing_reset_allowed : bool ,
2930}
3031
3132/// A mock implementation of a [`HomeserverConnection`], which never fails and
@@ -74,6 +75,7 @@ impl crate::HomeserverConnection for HomeserverConnection {
7475 displayname : None ,
7576 devices : HashSet :: new ( ) ,
7677 emails : None ,
78+ cross_signing_reset_allowed : false ,
7779 } ) ;
7880
7981 anyhow:: ensure!(
@@ -136,6 +138,13 @@ impl crate::HomeserverConnection for HomeserverConnection {
136138 user. displayname = None ;
137139 Ok ( ( ) )
138140 }
141+
142+ async fn allow_cross_signing_reset ( & self , mxid : & str ) -> Result < ( ) , Self :: Error > {
143+ let mut users = self . users . write ( ) . await ;
144+ let user = users. get_mut ( mxid) . context ( "User not found" ) ?;
145+ user. cross_signing_reset_allowed = true ;
146+ Ok ( ( ) )
147+ }
139148}
140149
141150#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments