Skip to content

Commit

Permalink
remove undocumented jwt token login
Browse files Browse the repository at this point in the history
  • Loading branch information
JadedBlueEyes authored and girlbossceo committed Jan 17, 2025
1 parent 9ebb39c commit 77f18f5
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 76 deletions.
15 changes: 0 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ features = ["parse"]
[workspace.dependencies.sanitize-filename]
version = "0.6.0"

[workspace.dependencies.jsonwebtoken]
version = "9.3.0"
default-features = false

[workspace.dependencies.base64]
version = "0.22.1"
default-features = false
Expand Down
4 changes: 0 additions & 4 deletions conduwuit-example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,6 @@
#
#proxy = "none"

# This item is undocumented. Please contribute documentation for it.
#
#jwt_secret =

# Servers listed here will be used to gather public keys of other servers
# (notary trusted key servers).
#
Expand Down
1 change: 0 additions & 1 deletion src/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ http.workspace = true
http-body-util.workspace = true
hyper.workspace = true
ipaddress.workspace = true
jsonwebtoken.workspace = true
log.workspace = true
rand.workspace = true
reqwest.workspace = true
Expand Down
38 changes: 4 additions & 34 deletions src/api/client/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@ use ruma::{
},
OwnedUserId, UserId,
};
use serde::Deserialize;

use super::{DEVICE_ID_LENGTH, TOKEN_LENGTH};
use crate::{utils, utils::hash, Error, Result, Ruma};

#[derive(Debug, Deserialize)]
struct Claims {
sub: String,
//exp: usize,
}

/// # `GET /_matrix/client/v3/login`
///
/// Get the supported login types of this server. One of these should be used as
Expand Down Expand Up @@ -106,34 +99,11 @@ pub(crate) async fn login_route(

user_id
},
| login::v3::LoginInfo::Token(login::v3::Token { token }) => {
| login::v3::LoginInfo::Token(login::v3::Token { token: _ }) => {
debug!("Got token login type");
if let Some(jwt_decoding_key) = services.globals.jwt_decoding_key() {
let token = jsonwebtoken::decode::<Claims>(
token,
jwt_decoding_key,
&jsonwebtoken::Validation::default(),
)
.map_err(|e| {
warn!("Failed to parse JWT token from user logging in: {e}");
Error::BadRequest(ErrorKind::InvalidUsername, "Token is invalid.")
})?;

let username = token.claims.sub.to_lowercase();

UserId::parse_with_server_name(username, services.globals.server_name()).map_err(
|e| {
err!(Request(InvalidUsername(debug_error!(
?e,
"Failed to parse login username"
))))
},
)?
} else {
return Err!(Request(Unknown(
"Token login is not supported (server has no jwt decoding key)."
)));
}
return Err!(Request(Unknown(
"Token login is not supported."
)));
},
#[allow(deprecated)]
| login::v3::LoginInfo::ApplicationService(login::v3::ApplicationService {
Expand Down
6 changes: 0 additions & 6 deletions src/core/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,6 @@ pub struct Config {
#[serde(default)]
pub proxy: ProxyConfig,

pub jwt_secret: Option<String>,

/// Servers listed here will be used to gather public keys of other servers
/// (notary trusted key servers).
///
Expand Down Expand Up @@ -2005,10 +2003,6 @@ impl fmt::Display for Config {
"Lockdown public room directory (only allow admins to publish)",
&self.lockdown_public_room_directory.to_string(),
);
line("JWT secret", match self.jwt_secret {
| Some(_) => "set",
| None => "not set",
});
line(
"Trusted key servers",
&self
Expand Down
1 change: 0 additions & 1 deletion src/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ image.workspace = true
image.optional = true
ipaddress.workspace = true
itertools.workspace = true
jsonwebtoken.workspace = true
log.workspace = true
loole.workspace = true
lru-cache.workspace = true
Expand Down
11 changes: 0 additions & 11 deletions src/service/globals/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub struct Service {
pub db: Data,

pub config: Config,
jwt_decoding_key: Option<jsonwebtoken::DecodingKey>,
pub bad_event_ratelimiter: Arc<RwLock<HashMap<OwnedEventId, RateLimitState>>>,
pub server_user: OwnedUserId,
pub admin_alias: OwnedRoomAliasId,
Expand All @@ -33,11 +32,6 @@ impl crate::Service for Service {
let db = Data::new(&args);
let config = &args.server.config;

let jwt_decoding_key = config
.jwt_secret
.as_ref()
.map(|secret| jsonwebtoken::DecodingKey::from_secret(secret.as_bytes()));

let turn_secret =
config
.turn_secret_file
Expand Down Expand Up @@ -66,7 +60,6 @@ impl crate::Service for Service {
let mut s = Self {
db,
config: config.clone(),
jwt_decoding_key,
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name))
.expect("#admins:server_name is valid alias name"),
Expand Down Expand Up @@ -158,10 +151,6 @@ impl Service {

pub fn trusted_servers(&self) -> &[OwnedServerName] { &self.config.trusted_servers }

pub fn jwt_decoding_key(&self) -> Option<&jsonwebtoken::DecodingKey> {
self.jwt_decoding_key.as_ref()
}

pub fn turn_password(&self) -> &String { &self.config.turn_password }

pub fn turn_ttl(&self) -> u64 { self.config.turn_ttl }
Expand Down

0 comments on commit 77f18f5

Please sign in to comment.