Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 4a736d1

Browse files
committed
add todos, add foreign server auth
1 parent 8bf2a5a commit 4a736d1

File tree

3 files changed

+96
-78
lines changed

3 files changed

+96
-78
lines changed

api/src/core/main.tsp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,16 @@ namespace models {
5555
primary: boolean;
5656
}
5757

58-
/**
59-
* A challenge string response, as received from a server when requesting a challenge string.
60-
*
61-
* From the polyproto protocol definition: "verify an actor's private identity key possession,
62-
* without revealing the private key itself. These strings, ranging from 32 to 256 characters,
63-
* have a UNIX timestamp lifetime. If the current timestamp surpasses this lifetime, the
64-
* challenge fails. The actor signs the string, sending the signature and their ID-Cert to the
65-
* server, which then verifies the signature's authenticity."
66-
*/
67-
model ChallengeStringResponse {
68-
@minLength(32)
69-
@maxLength(256)
70-
@doc("The challenge string, which the client should sign with its private identity key.")
71-
challenge: string;
72-
73-
@doc("The UNIX timestamp after which the challenge expires.")
74-
expires: uint64;
75-
}
76-
7758
/**
7859
* A key trial as sent from the server to an actor.
60+
*
61+
* Used to verify an actor's private identity key possession,
62+
* without revealing the private key itself
7963
*/
8064
model KeyTrial {
8165
@minLength(32)
8266
@maxLength(256)
83-
@doc("The key trial, which the client should sign with all of their private identity keys.")
67+
@doc("The key trial, which the client should sign with their private identity key.")
8468
trial: string;
8569

8670
@minLength(1)

api/src/core/routes/federated_identity.tsp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,21 @@ namespace FederatedIdentity {
261261
} | {
262262
@statusCode statusCode: 400;
263263
};
264+
265+
/**
266+
* Authenticate on a foreign server, creating a session with an authentication token. Requires
267+
* completing a key trial for the ID-Cert the session is supposed to be generated for.
268+
*/
269+
@route("/session/auth")
270+
@post
271+
@added(Version.`v1.0-beta.1`)
272+
@summary("Authenticate on a foreign server")
273+
op requestToken(
274+
@body
275+
completedChallengeString: polyproto.core.models.KeyTrialCompleted,
276+
): {
277+
@body _: string;
278+
@statusCode statusCode: 200;
279+
};
264280
}
265281
}

api/src/core/routes/migration.tsp

Lines changed: 76 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,32 +24,49 @@ namespace Migration {
2424
* to move to another home server. To fulfill this action,
2525
*
2626
* 1. A key trial must be passed
27+
* // TODO: Must it? If yes, specify for which cert(s) ^
2728
* 2. The "new" actor named in this request must confirm setting up this redirect.
2829
*
2930
* @returns
3031
* - `200` if the link has been created
31-
* - `202` if the other account still needs to accept to establish the link. Contains a key trial
32+
* - `202` if the other account still needs to accept to establish the link.
3233
* @param newActorFid The FID of the actor, that this actor would like to be redirected to.
3334
*/
3435
@route("/redirect")
3536
@post
3637
@added(Version.`v1.0-beta.1`)
3738
@summary("Set up a redirect for migrating identities")
38-
op setupRedirect(@body newActorFid: string): {
39+
op setupRedirect(
40+
@body newActorFid: string,
41+
42+
@doc("A completed `KeyTrial`.")
43+
@header({
44+
name: "X-P2-core-keytrial",
45+
})
46+
keyTrial: polyproto.core.models.KeyTrialCompleted,
47+
): {
3948
@statusCode statusCode: 200 | 202;
40-
@body body: polyproto.core.models.KeyTrial;
4149
};
4250

4351
/**
44-
* Stop an in-progress or existing redirection process.
45-
* @returns A key trial
52+
* Stop an in-progress or existing redirection process. Requires a completed key trial.
53+
* // TODO: Does it? ^ If yes, specify for which cert(s)
54+
*
4655
* @param removeActorFid The FID of the actor to which a redirect should no longer exist
4756
*/
4857
@route("/redirect")
4958
@delete
5059
@added(Version.`v1.0-beta.1`)
5160
@summary("Remove a redirect for migrating identities")
52-
op removeRedirect(@query removeActorFid: string): {
61+
op removeRedirect(
62+
@query removeActorFid: string,
63+
64+
@doc("A completed `KeyTrial`.")
65+
@header({
66+
name: "X-P2-core-keytrial",
67+
})
68+
keyTrial: polyproto.core.models.KeyTrialCompleted,
69+
): {
5370
@statusCode statusCode: 200;
5471
@body body: polyproto.core.models.KeyTrial;
5572
} | {
@@ -79,6 +96,7 @@ namespace Migration {
7996
@body importData?: polyproto.core.models.P2Export,
8097
): {
8198
@statusCode statusCode: 202;
99+
82100
@header({
83101
name: "Content-Length",
84102
})
@@ -118,6 +136,7 @@ namespace Migration {
118136
@statusCode statusCode: 404;
119137
} | {
120138
@statusCode statusCode: 204;
139+
121140
@header({
122141
name: "Content-Length",
123142
})
@@ -126,7 +145,6 @@ namespace Migration {
126145

127146
/**
128147
* Request allowing message re-signing. To fulfill this action, a key trial must be passed.
129-
* @returns a key trial
130148
* @param allowedResigningKeys List of PEM encoded `SubjectPublicKeyInfo`s. Only key pairs mentioned in this list are allowed to re-sign messages after the key trial has been passed.
131149
*/
132150
@route("/messages")
@@ -138,16 +156,24 @@ namespace Migration {
138156
newActorFid: string;
139157
allowedResigningKeys: string[];
140158
},
159+
160+
@doc("A completed `KeyTrial`.")
161+
@header({
162+
name: "X-P2-core-keytrial",
163+
})
164+
keyTrial: polyproto.core.models.KeyTrialCompleted, // TODO doesnt this have to be an array?
141165
): {
142-
@statusCode statusCode: 200;
143-
@body body: polyproto.core.models.KeyTrial;
166+
@statusCode statusCode: 200 | 403;
144167
};
145168

146169
/**
147170
* Commit messages that have been re-signed to the server.
148171
* @param messages Messages. The distinct format of messages is up to the specific p2 extension to define.
149172
* @returns
150-
* - `200` On success
173+
* - `200` On success. Returns another `MessageBatch`, if there are more messages to re-sign.
174+
* If this endpoint is queried again while
175+
* the previous batch of messages has not yet been re-signed (or only partially so), the
176+
* returned message batch will contain those uncommitted messages again.
151177
* - `400` if re-signed messages are improperly formatted
152178
* - `403` if messages have been modified where the original keys have not passed the key
153179
* trial, if a key trial has not been passed at all or if the messages have been signed
@@ -167,22 +193,34 @@ namespace Migration {
167193
name: "Retry-After",
168194
})
169195
retryAfter: uint16;
196+
197+
@doc("This header tells the client whether the route to commit re-signed messages has an upload size limit, and what the size of that limit is. A value of `0` means that there is no limit. This header not being present can also be interpreted as no limit existing.")
198+
@header({
199+
name: "X-P2-Return-Body-Size-Limit ",
200+
})
201+
sizeLimit?: uint64;
202+
203+
@doc("Another message batch, if there are still messages left to re-sign.")
204+
@body
205+
message?: polyproto.core.models.MessageBatch<string>[];
170206
} | {
171207
@statusCode _: 400 | 403;
172208
};
173209

174210
/**
175211
* Fetch messages to be re-signed. Must only return messages where the signatures correlate to
176-
* ID-Certs for which a key trial has been passed.
177-
* @param limit How many messages to request from the server. Defaults to 100.
212+
* ID-Certs for which a key trial has been passed. If this endpoint is queried again while
213+
* the previous batch of messages has not yet been re-signed (or only partially so), the
214+
* returned message batch will contain those uncommitted messages again.
215+
* @param limit How many messages to request from the server. Defaults to 300.
178216
* @param serialNumber If specified, query for non-re-signed messages corresponding to a specific ID-Cert.
179217
* @returns Messages. The distinct format of messages is up to the specific p2 extension to define.
180218
*/
181219
@route("/messages")
182220
@get
183221
@added(Version.`v1.0-beta.1`)
184222
@summary("Fetch messages to-be-resigned")
185-
op getMessages(@query limit?: uint32 = 100, serialNumber?: uint64): {
223+
op getMessages(@query limit?: uint32 = 300, serialNumber?: uint64): {
186224
@statusCode statusCode: 200;
187225

188226
@doc("This header tells the client whether the route to commit re-signed messages has an upload size limit, and what the size of that limit is. A value of `0` means that there is no limit. This header not being present can also be interpreted as no limit existing.")
@@ -196,39 +234,6 @@ namespace Migration {
196234
@statusCode statusCode: 403;
197235
};
198236

199-
/**
200-
* Complete a key trial. After the successful completion of the key trial, the action that
201-
* required this key trial to be performed may be executed until the `expires` UNIX timestamp
202-
* of the key trial has been reached. After that point, another key trial must be performed
203-
* before executing the action.
204-
*
205-
* If only a subset of all trialed keys had a trial completed for them, the server must only
206-
* allow changes which concern information tied to these exact keys.
207-
*
208-
* @param body Completed key trials.
209-
* @returns
210-
* - `200` if the key trials were processed and deemed to be valid
211-
* - `202`, if the server needs additional time to process the key trials
212-
* - `400`, if one or more completed key trials were faulty. Contains faulty key trials in the response body.
213-
*/
214-
@route("/keytrial")
215-
@post
216-
@added(Version.`v1.0-beta.1`)
217-
@summary("Complete key trial")
218-
op completeKeyTrial(
219-
@body body: polyproto.core.models.KeyTrialCompleted[],
220-
): {
221-
@doc("Returns `200` if the key trials were processed and deemed to be valid. Returns `202`, if the server needs additional time to process the key trials.")
222-
@statusCode
223-
statusCode: 202 | 200;
224-
} | {
225-
@doc("Received if one or more completed key trials were faulty. Contains faulty key trials in the response body.")
226-
@statusCode
227-
statusCode: 400;
228-
229-
@body body: polyproto.core.models.KeyTrialCompleted[];
230-
};
231-
232237
/**
233238
* Fetch key trials and their responses from other actors.
234239
* This route exists for transparency reasons, and allows actors in contact with the actor
@@ -259,6 +264,7 @@ namespace Migration {
259264
@query notAfter?: uint64,
260265
): {
261266
@statusCode statusCode: 204;
267+
262268
@header({
263269
name: "Content-Length",
264270
})
@@ -276,32 +282,40 @@ namespace Migration {
276282
};
277283

278284
/**
279-
* Delete all data associated with you from the server.
285+
* Delete all data associated with you from the server. Only deletes data associated with the
286+
* keys for which the `KeyTrial` has been passed.
280287
* @param breakRedirect If a redirect has been set up previously: Whether to break that redirect
281288
* with this action. Defaults to false.
289+
* @param keyTrial: A completed key trial.
282290
* @returns
283-
* - `202` and a key trial, if one still needs to be passed
284291
* - `204`: Action executed
285292
*/
286293
@route("/data")
287294
@delete
288295
@added(Version.`v1.0-beta.1`)
289296
@summary("Delete own actor data from the sever")
290-
op deleteData(@query breakRedirect?: boolean = false): {
291-
@statusCode statusCode: 202;
292-
@body response: polyproto.core.models.KeyTrial;
293-
} | {
297+
op deleteData(
298+
@query breakRedirect?: boolean = false,
299+
300+
@doc("A completed `KeyTrial`.")
301+
@header({
302+
name: "X-P2-core-keytrial",
303+
})
304+
keyTrial: polyproto.core.models.KeyTrialCompleted, // TODO: Must be array. re-evaluate if keytrial responses should be part of header. i think they are better suited as a body
305+
): {
294306
@statusCode statusCode: 204;
307+
295308
@header({
296309
name: "Content-Length",
297310
})
298311
contentLength: 0;
312+
} | {
313+
@statusCode statusCode: 403 | 401;
299314
};
300315

301316
/**
302-
* Export all of your data for safekeeping or for importing it to another server
317+
* Export all of your data for safekeeping or for importing it to another server.
303318
* @returns
304-
* - `202` and a key trial, if one still needs to be passed
305319
* - `200` and the appropriate data if the key trial has been passed and is not yet expired.
306320
* See the `P2Export` schema for more information.
307321
* - `204` if the server needs time to gather the data. A `Retry-After` header is included in
@@ -314,14 +328,18 @@ namespace Migration {
314328
@get
315329
@added(Version.`v1.0-beta.1`)
316330
@summary("Export all data")
317-
op exportData(): {
318-
@statusCode statusCode: 202;
319-
@body body: polyproto.core.models.KeyTrial;
320-
} | {
331+
op exportData(
332+
@doc("A completed `KeyTrial`.")
333+
@header({
334+
name: "X-P2-core-keytrial",
335+
})
336+
keyTrial: polyproto.core.models.KeyTrialCompleted,
337+
): {
321338
@statusCode statusCode: 200;
322339
@body body: polyproto.core.models.P2Export;
323340
} | {
324341
@statusCode statusCode: 204;
342+
325343
@header({
326344
name: "Retry-After",
327345
})

0 commit comments

Comments
 (0)