From 4e4122e402b2f27912b775b6df872c072873f29f Mon Sep 17 00:00:00 2001 From: 4cuck <40539855+4cuck@users.noreply.github.com> Date: Wed, 18 Oct 2023 23:54:06 +0200 Subject: [PATCH] switch to .well-known/ and improve login errors + page --- server/src/admin.rs | 9 +++++---- server/templates/login.html.j2 | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/src/admin.rs b/server/src/admin.rs index 034b21a..2a946c5 100644 --- a/server/src/admin.rs +++ b/server/src/admin.rs @@ -47,9 +47,10 @@ pub struct ActiveLogin { } const LOGIN_KEY: &'static str = "LOGIN"; +/// Error shown to user, details aren't part of the error message, as they're displayed separately. #[derive(Error, Debug)] pub enum LoginError { - #[error("Couldn't get login file at '{0}': {1}")] + #[error("Couldn't get login file at '{0}'")] HttpFailure(Url, reqwest::Error), #[error("Invalid instance URL '{0}'")] InstanceUrl(String), @@ -63,11 +64,11 @@ pub enum LoginError { DisabledHost(String), #[error("Server responded with status code '{0}'")] ServerResponse(u16, String), - #[error("Invalid hash found")] + #[error("Invalid hash, found:")] InvalidHash(String), #[error("Failed to fetch DNS TXT records")] DNSError(#[from] trust_dns_resolver::error::ResolveError), - #[error("No valid DNS TXT entry found for your key")] + #[error("No valid DNS TXT entry found for your key, found:")] DNSNoValidEntry(String), } type LoginResult = std::result::Result; @@ -200,7 +201,7 @@ async fn fetch_host_txt( ) -> LoginResult { let mut request_url = Url::parse(&instance_url).map_err(|_| LoginError::InstanceUrl(instance_url.to_string()))?; - request_url.set_path(&[".", &config.login_token_name].concat()); + request_url.set_path(&[".well-known/", &config.login_token_name].concat()); request_url.set_query(None); let result = client .get(request_url.clone()) diff --git a/server/templates/login.html.j2 b/server/templates/login.html.j2 index 91d8ebf..285712e 100644 --- a/server/templates/login.html.j2 +++ b/server/templates/login.html.j2 @@ -26,18 +26,18 @@
- +
Instance domain, without https.
- +
Private token to verify against your host.
@@ -56,15 +56,15 @@
    -
  • Run this in bash: uuidgen | tee >(tr -d $'\n' | sha256sum) +

  • Run this in bash: uuidgen -r | tee >(tr -d $'\n' | sha256sum)

  • OR: generate it in the browser

The output is like this: -

9FF98B96-9CCF-4624-85F4-453BBF8BB96D
-        6c9872185d6975f0f51d7d16a6428aadb1df494af0f68166f790ef0d51b0bc8f
+
00000000-0000-0000-0000-000000000000
+        12B9377CBE7E5C94E8A70D9D23929523D14AFA954793130F8A3959C7B849ACA8

The first line is your random value, and the second line's hex part is the hash.