fep

FEP-ae97: Client-side activity signing

Summary

Existing Fediverse servers manage signing keys on behalf of their users. This proposal describes a new kind of ActivityPub client that lets users sign activities with their own keys, and a server that can distribute client-signed activities to other servers.

History

Initial version of this proposal relied on linking of cryptographic identities to actor objects via FEP-c390 identity proofs. That mechanism was superseded by FEP-ef61 which achieves full data portability.

Requirements

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC-2119.

Discovery

A server that supports clients capable of managing signing keys MUST have a discovery endpoint at the path /.well-known/apgateway.

When the server receives an HTTP GET request to this endpoint, it MUST respond with a JSON object containing information about itself. That object MAY be empty.

Example:

{
  "uploadMedia": "https://gateway.example/.well-known/apgateway-media"
}

Registering an actor

sequenceDiagram
  participant Client
  participant Server
  Note right of Client: Client generates signing keys and creates an actor
  Client ->> Server: GET /.well-known/apgateway
  Server ->> Client: Returns information about itself
  Client ->> Server: POST /.well-known/apgateway
  Note left of Server: Server creates an account for the actor
  Server ->> Client: Returns HTTP signature keys
  Note right of Client: Client adds server's keys to the actor
  Client ->> Server: POST Update(Actor) to outbox

Client creates portable actor objects according to FEP-ef61 and stores them. When a portable actor is created, the client MUST create a key for signing HTTP requests (the main actor key) and add a Multikey representation of the correspondng public key to the assertionMethod array as described in FEP-521a. The identifier of that key MUST NOT be a compatible identifier.

Before registering a portable actor on the server, the client MUST add the server URL to the gateways array of the actor object.

To register the actor, the client sends an HTTP POST request to the gateway endpoint at /.well-known/apgateway path. The body of the request MUST be the actor object.

The server SHOULD limit registrations (for example, by requiring an invite code).

If the server accepts the registration request, it generates its own signing keys and returns the corresponding public keys in a response. The response MUST have a 201 Created status code. The body of the response is a JSON object with an assertionMethod property. The value of this property is an array containing the public keys generated by the server in the Multikey format.

At a minimum, the server SHOULD provide an RSA key, because other signature types are not widely supported in Fediverse.

Example or a response:

{
  "assertionMethod": [
    {
      "type": "Multikey",
      "publicKeyMultibase": "z4MXj1wBzi9jUstyPMS4jQqB6KdJaiatPkAtVtGc6bQEQEEsKTic4G7Rou3iBf9vPmT5dbkm9qsZsuVNjq8HCuW1w24nhBFGkRE4cd2Uf2tfrB3N7h4mnyPp1BF3ZttHTYv3DLUPi1zMdkULiow3M1GfXkoC6DoxDUm1jmN6GBj22SjVsr6dxezRVQc7aj9TxE7JLbMH1wh5X3kA58H3DFW8rnYMakFGbca5CB2Jf6CnGQZmL7o5uJAdTwXfy2iiiyPxXEGerMhHwhjTA1mKYobyk2CpeEcmvynADfNZ5MBvcCS7m3XkFCMNUYBS9NQ3fze6vMSUPsNa6GVYmKx2x6JrdEjCk3qRMMmyjnjCMfR4pXbRMZa3i"
    }
  ]
}

If the actor is already registered, the server MUST return the same keys in a response with a 200 OK status code.

If the server can’t register the actor, it MUST return a 400 Bad Request status code.

If the registration is successful, the client MUST attach the RSA key to the actor object via publicKey property, and also add it to the assertionMethod array as described in FEP-521a. If the server’s response contains other keys, they SHOULD be added to the assertionMethod array as well.

If the client uses compatible identifiers, then key identifiers MUST be generated with the server’s origin. However, the client MUST NOT use key identifiers provided by the server (if they were present in the server’s response).

After updating the actor object, the client MUST publish an Update activity for it.

Sending activities

Activities generated by a client MUST adhere to ActivityPub server-to-server protocol specification.

The client submits signed FEP-ef61 activities to actor’s outbox. Contrary to what ActivityPub specification prescribes in section 6. Client to Server Interactions, the server MUST NOT overwrite the ID of an activity. Instead of assigning a new ID, the server MUST verify that provided ID has not been used before. If the server accepts activity, its response MUST have 202 Accepted status code.

If activity contains a wrapped object (as in Create and Update activities), it MUST be a portable object created according to FEP-ef61. The server MUST validate object IDs in the same way it validates activity IDs.

The server MUST deliver activities to their intended audiences without altering them. When signing HTTP requests, the server uses the RSA key generated during the registration.

If the owner of the outbox is not registered, the server MUST return a 404 Not Found status code.

If the actor of the submitted activity is different from the outbox owner, the server MUST return a 403 Forbidden status code.

Receiving activities

Client receives activities by polling the actor’s inbox.

Requests to inbox endpoint MUST have an HTTP signature created using the main actor key (the one generated by the client, not a server-generated key).

If the signature is not valid, the server MUST return a 401 Unauthorized status code.

If the owner of the inbox is not registered, the server MUST return a 404 Not Found status code.

If the actor that generated the signature is different from the inbox owner, the server MUST return a 403 Forbidden status code.

Clients MUST verify received portable activities. Non-portable activities MAY be accepted without verification.

Media API

Upload media

To upload a media file, the client sends an HTTP POST request to the gateway endpoint at the /.well-known/apgateway-media path. The body of the request MUST be the media in the form of binary data. The request MUST contain a Content-Type header and MUST be signed with the main key of the actor.

If the media is processed successfully, the server MUST return a response with a 201 Created status code and a JSON object as the body. This JSON object MUST have a url property whose value is a hashlink to the processed media file.

Example:

{
  "type": "Document",
  "url": "hl:zQmWvQxTqbG2Z9HPJgG57jjwR154cKhbtJenbyYTWkjgF3e"
}

The server MUST serve the processed media file at a /.well-known/apgateway-media/{hashlink} path.

If the signature is not valid, the server MUST return a 401 Unauthorized status code. If the signature is valid, but the actor is not registered, the server MUST return a 403 Forbidden status code.

If the media type is not supported, the server MUST return a 400 Bad Request status code.

If the media is too large, the server MUST return a 413 Payload Too Large status code.

Delete media

To delete a previously uploaded media file, the client sends an HTTP DELETE request to an endpoint at path /.well-known/apgateway-media/{hashlink}. The request MUST be signed with the main key of the actor.

If the signature is valid and the actor owns the media file, the server MUST delete the file.

If the signature is not valid, the server MUST return a 401 Unauthorized status code. If the signature is valid, but the actor is not registered, the server MUST return a 403 Forbidden status code.

If the media file doesn’t exist or not owned by the actor, the server MUST return a 404 Not Found status code.

Security considerations

If the server accepts portable objects with compatible identifiers, it MUST ensure that all objects served by the gateway are valid and that registered actors are sufficiently isolated from each other. Specifically, the server MUST verify that actors and activities generated by the client are permitted in the origin-based security model:

Precautions need also be taken when objects with compatible IDs are delivered to inboxes or fetched from remote servers.

Implementations

References

CC0 1.0 Universal (CC0 1.0) Public Domain Dedication

To the extent possible under law, the authors of this Fediverse Enhancement Proposal have waived all copyright and related or neighboring rights to this work.