From 4d589d9788d4c8d038bef243e97035e7ab4aa01b Mon Sep 17 00:00:00 2001
From: digital <didev@dinid.net>
Date: Wed, 18 Jan 2023 23:21:23 +0100
Subject: [PATCH 1/2] feat: support end to bridge encryption

by implementing appservice logins
---
 src/api/client_server/session.rs | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs
index 64c00720..f8fc7f1a 100644
--- a/src/api/client_server/session.rs
+++ b/src/api/client_server/session.rs
@@ -26,6 +26,7 @@ pub async fn get_login_types_route(
 ) -> Result<get_login_types::v3::Response> {
     Ok(get_login_types::v3::Response::new(vec![
         get_login_types::v3::LoginType::Password(Default::default()),
+        get_login_types::v3::LoginType::ApplicationService(Default::default()),
     ]))
 }
 
@@ -103,6 +104,27 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
                 ));
             }
         }
+        login::v3::LoginInfo::ApplicationService(login::v3::ApplicationService { identifier }) => {
+            info!("hi");
+            if !body.from_appservice {
+                return Err(Error::BadRequest(
+                    ErrorKind::Forbidden,
+                    // TODO: is this the correct response
+                    "Wrong username or password.",
+                ));
+            };
+            let username = if let UserIdentifier::UserIdOrLocalpart(user_id) = identifier {
+                user_id.to_lowercase()
+            } else {
+                return Err(Error::BadRequest(ErrorKind::Forbidden, "Bad login type."));
+            };
+            let user_id =
+                UserId::parse_with_server_name(username, services().globals.server_name())
+                    .map_err(|_| {
+                        Error::BadRequest(ErrorKind::InvalidUsername, "Username is invalid.")
+                    })?;
+            user_id
+        }
         _ => {
             return Err(Error::BadRequest(
                 ErrorKind::Unknown,

From 664d6baace232e929dd248636625f9ae835938c5 Mon Sep 17 00:00:00 2001
From: digital <didev@dinid.net>
Date: Fri, 26 May 2023 13:06:28 +0200
Subject: [PATCH 2/2] fix: make requested changes

---
 src/api/client_server/session.rs | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/api/client_server/session.rs b/src/api/client_server/session.rs
index f8fc7f1a..b3328e48 100644
--- a/src/api/client_server/session.rs
+++ b/src/api/client_server/session.rs
@@ -105,12 +105,10 @@ pub async fn login_route(body: Ruma<login::v3::Request>) -> Result<login::v3::Re
             }
         }
         login::v3::LoginInfo::ApplicationService(login::v3::ApplicationService { identifier }) => {
-            info!("hi");
             if !body.from_appservice {
                 return Err(Error::BadRequest(
                     ErrorKind::Forbidden,
-                    // TODO: is this the correct response
-                    "Wrong username or password.",
+                    "Forbidden login type."
                 ));
             };
             let username = if let UserIdentifier::UserIdOrLocalpart(user_id) = identifier {