aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/login.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/login.rs')
-rw-r--r--src/api/login.rs81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/api/login.rs b/src/api/login.rs
index 0658a69..ffcf9b8 100644
--- a/src/api/login.rs
+++ b/src/api/login.rs
@@ -8,6 +8,9 @@
//! * `POST /auth/challenge` and `POST /auth/login/key`, without a password: a challenge
//! to sign with one of the user's keys, then the same token for it, signed
//! (`access::challenge`).
+//! * `POST /auth/login/party`, without a password, on a node holding a federated store: a
+//! token as a party, for a challenge signed with one of the keys that sign for it there,
+//! which does federation work alone (`login_party`).
//! * `POST /auth/refresh`, with a token: a new one for the same login, signed by this
//! node, optionally narrower still (`limit`, within the token's).
//! * `POST /auth/logout`: every token of the user, of every login, no longer taken
@@ -279,6 +282,7 @@ fn new_login(
session_exp,
login_exp: session_exp,
limit,
+ party: None,
}
}
@@ -322,6 +326,82 @@ pub(crate) struct KeyLogin {
limit: Option<Vec<CapRequest>>,
}
+/// A party's login by one of its keys (`POST /auth/login/party`).
+#[cfg(feature = "federation")]
+#[derive(Deserialize)]
+pub(crate) struct PartyLogin {
+ party: String,
+ challenge: String,
+ /// Armored, as `ssh-keygen -Y sign -n continuum-login` writes it, or its blob in base64.
+ signature: String,
+}
+
+/// `POST /auth/login/party`: on a node holding a federated store, a token as `party` for a
+/// challenge signed with one of the keys that sign for it there, as its current version
+/// and its key set say (`fold::State::signing_keys`), as `ssh-keygen -Y sign -n
+/// continuum-login` signs, an ECDSA signature's `s` low (`401` if not, saying why): a
+/// party's session, which does federation work alone, while that key signs for the
+/// party (`api::access::federated`). `409` on a node holding none.
+#[cfg(feature = "federation")]
+pub(crate) async fn login_party(
+ State(state): State<AppState>,
+ Json(request): Json<PartyLogin>,
+) -> Result<Response, ApiError> {
+ let (swarm, now) = issuing(&state).await?;
+ let key = state
+ .node_key
+ .as_ref()
+ .ok_or(ApiError(StatusCode::SERVICE_UNAVAILABLE, None))?;
+ let party = request.party.as_str();
+ let keys = state
+ .holding
+ .with(|store| {
+ let read = store.state();
+ read.signing_keys(party, read.current())
+ })
+ .ok_or_else(|| {
+ ApiError(
+ StatusCode::CONFLICT,
+ Some("no federated store here, whose parties' keys log in".to_owned()),
+ )
+ })?;
+ let signer = {
+ let mut used = state.challenges.lock_or_recover();
+ let mut signer = None;
+ challenge::take_with(
+ key,
+ &request.challenge,
+ &format!("party {party}"),
+ now,
+ &mut used,
+ state.key_logins_per_user,
+ |challenge| {
+ if keys.is_empty() {
+ return Err(format!("{party} is no party of the current version"));
+ }
+ let found = crate::federation::keys::signer(
+ &keys,
+ challenge::NAMESPACE,
+ &request.signature,
+ challenge.as_bytes(),
+ )
+ .ok_or_else(|| format!("signed by none of the keys that sign for {party}"))?;
+ signer = Some(found.to_owned());
+ Ok(())
+ },
+ )
+ .map_err(|why| {
+ debug!(party = %party, reason = %why, "Refused a party's login");
+ ApiError(StatusCode::UNAUTHORIZED, Some(why))
+ })?;
+ signer
+ };
+ let mut claims = new_login(&state, swarm, now, party, "party", None, None);
+ claims.party = signer;
+ info!(party = %party, login = "party", session = %claims.session, "A party logged in");
+ answer(&state, &claims)
+}
+
/// `POST /auth/login/key`: a token, as `POST /auth/login` gives one, for a challenge
/// signed by one of the user's keys (`401` if not, saying why); `409` in a swarm without
/// a registry, which holds no keys.
@@ -745,6 +825,7 @@ pub(crate) async fn whoami(
"session": token.claims.session,
"sessionExpiresAt": token.claims.session_exp,
"limit": token.claims.limit,
+ "party": token.claims.party,
})
});
Json(json!({