Expand description
Types describing the pubhubs API
The different endpoints offered by the PubHubs servers and hubs are described by types
implementing the EndpointDetails trait.
§Overview for web clients
For reference, the flows described below to enter pubhubs, to enter a hub and to obtain a pubhubs card
are also implemented by the pubhubs enter CLI tool see crate::cli, which
is usually invoked via cargo run enter.
§Entering pubhubs
-
Everything starts with the global client, knowing only the url of pubhubs central (PHC), obtaining general information about the rest of the pubhubs environment from the
phc::user::WelcomeEPendpoint of PHC, including, for example, the url of the authentication server and transcryptor. -
Next the user authenticates towards the authentication server in order to obtain
Attributes.- The global client first gets the available authentication methods via
auths::WelcomeEP, and - then obtains the attributes using the
auths::AuthStartEPandauths::AuthCompleteEPendpoints.
- The global client first gets the available authentication methods via
-
Using those
Attributes the global client can ‘enter’ PubHubs via thephc::user::EnterEP, registering a new account if needed. or logging into an existing account. The result of entering PubHubs is not a session cookie, but anphc::user::AuthTokenthat must be passed along in theAuthorizationheader of most subsequent requests from the global client to PHC. -
After having entered pubhubs, the global client retrieves details on the
phc::user::UserStatevia thephc::user::StateEPendpoint (authenticating using the previously obtained auth token).
The user state includes (among other details), a list of stored user objects,phc::user::UserState::stored_objects, which can be retrieved usingphc::user::GetObjectEP(and stored usingphc::user::OverwriteObjectEPandphc::user::NewObjectEP). -
The contents of user objects should be encrypted by the global client. Indeed, there’s no need for PHC to be able to read the contents of these user objects. But where can the global client store the ‘user object key’ used to encrypt these objects? Not in plaintext at PHC! Instead, the authentication server provides attribute keys via
auths::AttrKeysEPwith which the global client can encrypt its ‘user object key’ before storing it at PHC in a designated user object. Other user objects can then be encrypted using this user object key.
§Entering hubs
Entering a hub is slightly more involved, as pubhubs central is not allowed to know the hub and
the transcryptor is not allowed to know the user. These privacy guarantees can be achieved by
clever use of elliptic curves as described in the whitepaper
The procedure below uses the same
ideas but has been modified to prevent already generated pseudonyms from being linked
when a cryptographically relevant quantum computer materializes.
For the cryptographic details, see sso.
-
The global client obtains a sealed
sso::PolymorphicPseudonymPackage(PPP) from PHC viaphc::user::PppEPand a hub nonce and hub state pair from the hub viahub::EnterStartEP. -
The global client sends the PPP, hub nonce and hub id to the transcryptor’s
tr::EhppEP, which yields a sealedsso::EncryptedHubPseudonymPackage(EHPP). -
This EHPP is forwarded back to PHC, to the
phc::user::HhppEP, yielding a signedsso::HashedHubPseudonymPackage(HHPP). -
This HHPP is sent back by the global client to the hub’s
hub::EnterCompleteEP, together with the hub state, which results in a Synapse access token to the hub.
§PubHubs card
Pubhubs also issues yivi ‘PubHubs cards’. To obtain one for the user:
-
First enter pubhubs, and get a signed
phc::user::CardPseudPackagefrom PHC viaphc::user::CardPseudEP. -
Then pass this to
auths::CardEPto get:-
An
auths::CardResp::Success::attrAttribute that can be added to the user’s account via thephc::user::EnterEPendpoint. Note that instead of passing an identifying attribute, one may also authenticate by putting auth token in theAuthorizationheader. -
An
auths::CardResp::Success::issuance_requestthat can be used to start an issuance session with the authentication server’s yivi server to issue the card to the user. It’s important that this is done after adding the card to user’s yivi app lest the user might end up with a card that does not work.
-
In the flow above, the user may have to scan two Yivi QR codes: one to disclosure attributes to enter pubhubs, and then another QR code to receive the PubHubs card. The disclosure and issuance Yivi sessions can be combined into one ‘chained session’ as follows.
-
When entering PubHubs, set
auths::AuthStartReq::yivi_chained_sessiontotrue.This causes the yivi server to not immediately return the disclosure result to the browser, but first to the
auths::YIVI_NEXT_SESSION_PATHendpoint of this authentication server. -
When the authentication server receives this disclosure, it will keep the yivi server waiting, and will make the disclosure available via
auths::YiviWaitForResultEP. (The disclosure can unfortunately not be obtained in the regular way from the yivi server until the authentication server releases the yivi server.) -
Using this disclosure, one can obtain
Attributes, enter PubHubs, obtain a PubHubs card, and add this card to the user’s account, exactly as before. -
But now instead of passing it directly to the yivi server (which involves scanning a second QR code),
auths::CardResp::Success::issuance_requestcan be passed via theauths::YiviReleaseNextSessionEPendpoint of the authentication server to the waiting yivi server, which will cause the current disclosure session to be followed-up by the pubhubs card issuance session - without the user having to scan a second QR code.
§Errors
A request to a pubhubs endpoint may fail in several ways.
-
Errors that are par for the course are generally encoded in
EndpointDetails::ResponseTypetypes themselves. For example,phc::user::EnterResp::AccountDoesNotExistis returned when a user tries to log into an account that does not exist. It should always be clear to the caller how to act on these errors. -
Other errors, such as unexpected errors, or errors caused by the caller breaking protocol in some avoidable manner are generally returned via the
ErrorCodein theResult<EndpointDetails::ResponseType, ErrorCode>.-
ErrorCode::InternalError: something unexpected went wrong internally.
Consult the logs of the server for more details. Retrying the request is not recommended. -
ErrorCode::PleaseRetryjust wait a moment, and retry the same request. -
ErrorCode::BadRequest: there’s something unexpected is wrong with the request - do not retransmit the same request.
-
-
It may, however, happen that a request is rejected before it reaches our code, for example, by the HTTP framework
actix_webor by the reverse proxy. One may in that case encounter a HTTP status code (or even a TCP/TLS disconnect). Notable HTTP status codes are:-
400 - Bad Request Occurs, for example, when the json in the request body cannot be deserialized to the
EndpointDetails::RequestType. -
502 - Bad Gateway Occurs, for example, when one of the servers is (temporarily) down. The client should try the same request again.
-
-
A response may also be rejected when it arrives at a browser, for example, due to improperly set Cross-Origin Resource Sharing headers.
§Changelog of breaking changes
§2025-06-25
- Removed
ExpiredandInvalidSignatureerror codes. - Added
phc::user::EnterResp::RetryWithNewIdentifyingAttrandphc::user::EnterResp::RetryWithNewAddAttrvariants.
§2025-07-14
- Renamed
phc::user::EnterResp::Entered::auth_tokentophc::user::EnterResp::Entered::auth_token_package, and changed its type, replacingphc::user::AuthTokenwithphc::user::AuthTokenPackage(which contains an expiry date). Instead of{ "Ok": "AuThToken..." }theauth_token(_package)field will now be of the form{ "Ok": { "auth_token": "AuThToken", "expires": 123456789 } }.
Re-exports§
pub use crate::misc::jwt::NumericDate;pub use crypto::SealingKey;
Modules§
- admin
.ph/admin/...endpoints- auths
- Additional endpoints provided by the authentication server
- common 🔒
- discovery 🔒
- Endpoints for the ‘discovery’ process by which the pubhubs servers (pubhubs central, authentication server, and transcryptor) inform one another of updates in their configuration (URLs, public key material, etc.) and of updates to their binaries.
- hub
- Endpoints provided by a hub
- phc
- Additional endpoints provided by PubHubs Central
- sealed 🔒
- Sealing data using symmetric crypto
- server
- Endpoints served by every PubHubs server (PHC, Transcryptor, Authentication Server)
aside from the discovery related endpoints (
DiscoveryInfoandDiscoveryRun). - signed 🔒
- sso
- Data structures related to the authentication of users towards hubs.
- tr
- Additional endpoints provided by the Transcryptor
Macros§
- having_
message_ code - Implements
Signablefor the given struct. Use as follows:
Structs§
- Bytes
Payload - A payload (see
PayloadTrait) that can only hold bytes. Probably only useful for asEndpointDetails::RequestType. - Cached
Response - Cached response
- Constellation
Claim - Contents of the
CONSTELLATION_CLAIM - Constellation
Comp Res - Result of
ConstellationClaim::compare. - Curve
Point - Wrapper around
curve25519_dalek::ristretto::CompressedRistrettoenforcing base16 serialization. - Discovery
Info - Public details about this server, including its current
Constellation. Used byPHCto build and publish itsConstellation. - Discovery
Info Resp - What’s returned by the
DiscoveryInfo. - Discovery
Run - Has the server run its discovery procedure, if it isn’t already.
- Error
Info - Information about an ErrorCode.
- NoPayload
- Use
NoPayloadasEndpointDetails::RequestTypeto indicate no payload is expected. - Responder
- The
actix_web::Responderused for almost all API endpoints,EndpointDetailstogether with an instance ofResult<EndpointDetails::ResponseType>. - Scalar
- Wrapper around
curve25519_dalek::scalar::Scalarenforcing base16 serialization. - Sealed
- A symmetrically encrypted encoding of
T. - Signed
- A signed
Tby encodingTinto ajwt::JWT. - Signing
Key - Wrapper around
ed25519_dalek::SigningKeyenforcing base16 serialization. - Verifying
Key - Wrapper around
ed25519_dalek::VerifyingKeyenforcing base16 serialization.
Enums§
- Discovery
RunResp - What’s returned by the
DiscoveryRun. - Error
Code - List of possible errors. We use error codes in favour of more descriptive strings, because error codes can be more easily processed by the calling code, should change less often, and can be easily translated.
- Message
Code - A number that represents the type of a message. Every message type that’s Signed gets such a code to prevent reuse of a message of one type as another.
- Open
Error - Error returned by
Signed::open. - Payload
- Payload of a request or response to an api endpoint.
Constants§
- CONSTELLATION_
CLAIM - The claim name used to store the
ConstellationId. - MESSAGE_
CODE_ CLAIM - The claim name used to store the
MessageCode.
Traits§
- ApiResult
Ext - Extension trait for
Result<T,ErrorCode>. - Endpoint
Details - Details on a PubHubs server endpoint
- Payload
Trait - What’s expected from a
EndpointDetails::RequestType. - Result
Ext - Extension trait for
std::result::Result. - Result
Payload Trait - What’s expected from a
EndpointDetails::ResponseType. - Signable
- A type that’s used as the contents of a
Signedmessage.