-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
177 additions
and
680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
mod user; | ||
//! This module is the root of the admin API. | ||
//! | ||
//! reference: https://matrix-org.github.io/synapse/latest/usage/administration/admin_api/index.html | ||
mod room; | ||
// mod room; | ||
mod session; | ||
mod user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! This module contains handlers for user registration. | ||
//! | ||
//! reference: https://matrix-org.github.io/synapse/latest/admin_api/register_api.html | ||
use hmac::Mac; | ||
|
||
mod get_nonce; | ||
mod register; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct Hmac { | ||
inner: Vec<u8>, | ||
} | ||
|
||
impl Hmac { | ||
fn new( | ||
shared_secret: &str, | ||
nonce: &str, | ||
username: &str, | ||
password: &str, | ||
admin: bool, | ||
) -> Result<Self, hmac::digest::InvalidLength> { | ||
let mut mac = hmac::Hmac::<sha1::Sha1>::new_from_slice(shared_secret.as_bytes())?; | ||
let admin = match admin { | ||
true => "admin", | ||
false => "notadmin", | ||
}; | ||
|
||
mac.update( | ||
&[nonce, username, password, admin] | ||
.map(str::as_bytes) | ||
.join(&0x00), | ||
); | ||
|
||
let result = mac.finalize().into_bytes(); | ||
|
||
Ok(Self { | ||
inner: result.to_vec(), | ||
}) | ||
} | ||
|
||
fn get(&self) -> String { | ||
hex::encode(&self.inner) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use ruma_common::{ | ||
api::{request, response, Metadata}, | ||
metadata, | ||
}; | ||
|
||
#[allow(dead_code)] | ||
const METADATA: Metadata = metadata! { | ||
method: GET, | ||
rate_limited: false, | ||
authentication: AccessToken, | ||
history: { | ||
unstable => "/_synapse/admin/v1/register", | ||
} | ||
}; | ||
|
||
#[request(error = crate::Error)] | ||
pub struct Request {} | ||
|
||
#[response(error = crate::Error)] | ||
pub struct Response { | ||
nonce: String, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use ruma_common::{ | ||
api::{request, response, Metadata}, | ||
metadata, OwnedDeviceId, OwnedServerName, OwnedUserId, | ||
}; | ||
|
||
use super::Hmac; | ||
|
||
#[allow(dead_code)] | ||
const METADATA: Metadata = metadata! { | ||
method: GET, | ||
rate_limited: false, | ||
authentication: AccessToken, | ||
history: { | ||
unstable => "/_synapse/admin/v1/register", | ||
} | ||
}; | ||
|
||
#[request(error = crate::Error)] | ||
pub struct Request { | ||
pub nonce: String, | ||
|
||
pub username: String, | ||
|
||
pub password: String, | ||
|
||
#[serde(skip_deserializing_if = "String::is_empty")] | ||
pub displayname: String, | ||
|
||
pub admin: bool, | ||
|
||
pub hmac: Hmac, | ||
} | ||
|
||
#[response(error = crate::Error)] | ||
pub struct Response { | ||
pub access_token: String, | ||
|
||
pub user_id: OwnedUserId, | ||
|
||
pub home_server: OwnedServerName, | ||
|
||
pub device_id: OwnedDeviceId, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.