Skip to content

Commit a5d21ee

Browse files
committed
user-auth: sketch basic publicly-visible user auth types
1 parent 1722393 commit a5d21ee

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

common/src/auth.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// user auth v1
2+
3+
use serde::{Deserialize, Serialize};
4+
use thiserror::Error;
5+
6+
use crate::cli::Network;
7+
use crate::ed25519::{self, Signed};
8+
9+
#[derive(Debug, Error)]
10+
pub enum Error {
11+
#[error("error verifying user signup request: {0}")]
12+
VerifyError(#[from] ed25519::Error),
13+
}
14+
15+
// TODO(phlip9): do we even need any signup fields?
16+
/// Sign up
17+
#[derive(Deserialize, Serialize)]
18+
pub struct UserSignupRequest {
19+
pub display_name: Option<String>,
20+
pub email: Option<String>,
21+
}
22+
23+
/// A user client's request for auth token with certain restrictions.
24+
#[derive(Deserialize, Serialize)]
25+
pub struct UserAuthRequest {
26+
/// The time the auth token should be issued in UTC Unix time, interpreted
27+
/// relative to the server clock.
28+
issued_timestamp: u64,
29+
30+
/// How long the auth token should be valid, in seconds. At most 1 hour.
31+
liftime_secs: u32,
32+
33+
// maybe (?)
34+
/// Limit the auth token to a specific Bitcoin network.
35+
btc_network: Network,
36+
}
37+
38+
/// An opaque user auth token for authenticating user clients against lexe infra
39+
/// as a particular [`UserPk`](crate::api::UserPk).
40+
///
41+
/// Most user clients should just treat this as an opaque Bearer token with a
42+
/// very short expiration.
43+
pub struct UserAuthToken(pub String);
44+
45+
// -- impl UserSignupRequest -- //
46+
47+
impl UserSignupRequest {
48+
pub fn deserialize_verify(
49+
serialized: &[u8],
50+
) -> Result<Signed<Self>, Error> {
51+
// for user sign up, the signed signup request is just used to prove
52+
// ownership of a user_pk.
53+
fn accept_any_signer(_: &ed25519::PublicKey) -> bool {
54+
true
55+
}
56+
ed25519::verify_signed_struct(accept_any_signer, serialized)
57+
.map_err(Error::VerifyError)
58+
}
59+
}
60+
61+
impl ed25519::Signable for UserSignupRequest {
62+
const DOMAIN_SEPARATOR_STR: &'static [u8] =
63+
b"LEXE-REALM::UserSignupRequest";
64+
}

common/src/cli.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use proptest::arbitrary::{any, Arbitrary};
1414
use proptest::strategy::{BoxedStrategy, Just, Strategy};
1515
#[cfg(all(test, not(target_env = "sgx")))]
1616
use proptest_derive::Arbitrary;
17+
use serde::{Deserialize, Serialize};
1718

1819
use crate::api::runner::Port;
1920
use crate::api::UserPk;
@@ -410,7 +411,7 @@ impl Arbitrary for BitcoindRpcInfo {
410411
/// - Testnet <-> "testnet",
411412
/// - Signet <-> "signet",
412413
/// - Regtest <-> "regtest"
413-
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
414+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
414415
pub struct Network(bitcoin::Network);
415416

416417
impl Network {

common/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub use secrecy::Secret;
1717

1818
pub mod api;
1919
pub mod attest;
20+
pub mod auth;
2021
pub mod cli;
2122
pub mod client;
2223
pub mod constants;

0 commit comments

Comments
 (0)