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

Commit 9a8683b

Browse files
committed
Add some missing routes, fix mix-up between challenge-str and sensitive actions
1 parent 0cca82d commit 9a8683b

File tree

2 files changed

+77
-43
lines changed

2 files changed

+77
-43
lines changed

api/src/core/routes/federated_identity.tsp

Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,30 @@ namespace FederatedIdentity {
1717
@tag("Federated Identity - Registration required")
1818
@useAuth(BearerAuth)
1919
namespace Registered {
20-
@route("/session/idcert")
21-
@summary("Rotate session ID-Cert")
20+
21+
@route("/idcert")
22+
@summary("Get a new ID-Cert")
2223
@added(Version.`v1.0-alpha.1`)
2324
@post
25+
@tag("Sensitive Actions")
2426
/**
25-
* Rotate your keys for a given session. The `session_id` in the supplied `csr` must correspond to the
26-
* session token used in the `authorization`-Header.
27-
* @param csr A new [certificate signing request (CSR)](/Protocol%20Specifications/core/#71-home-server-signed-certificates-for-public-client-identity-keys-id-cert) with the same session ID
28-
* @returns Contains your new ID-Cert, along with a new session token.
29-
*/
30-
op rotateIdCert(@body csr: string;): {
31-
@doc("Contains your new ID-Cert in PEM encoding, along with a new session token.")
32-
@statusCode statusCode: 201;
33-
@body newIdCert: {
34-
@doc("The generated [ID-Cert](/Protocol%20Specifications/core/#71-home-server-signed-certificates-for-public-client-identity-keys-id-cert) in PEM format.")
35-
@example("------BEGIN CERTIFICATE------...")
36-
id_cert: string,
37-
@doc("An authorization secret, called a \"token\", valid for this `id_cert`.")
38-
token: string
39-
}
27+
* Request a new ID-Cert, usually done when wanting to authenticate a new session, or after
28+
* an ID-Cert has been revoked, to re-authenticate a session.
29+
*/
30+
op newIdCert(
31+
@doc("Sensitive actions require a second factor of authentication to be executed. Read [section 4.1.2 of the protocol definition](https://docs.polyphony.chat/Protocol%20Specifications/core/#412-sensitive-actions) for more information.")
32+
@header({name: "X-P2-Sensitive-Solution"}) sensitiveSolution: string,
33+
@body csr: string;
34+
): {
35+
@doc("Contains your new ID-Cert in PEM encoding, along with a new session token.")
36+
@statusCode statusCode: 201;
37+
@body newIdCert: {
38+
@doc("The generated [ID-Cert](/Protocol%20Specifications/core/#71-home-server-signed-certificates-for-public-client-identity-keys-id-cert) in PEM format.")
39+
@example("------BEGIN CERTIFICATE------...")
40+
id_cert: string,
41+
@doc("An authorization secret, called a \"session token\", valid for this `id_cert`/session.")
42+
token: string
43+
}
4044
};
4145

4246
@route("/session/keymaterial")
@@ -86,7 +90,7 @@ namespace FederatedIdentity {
8690
};
8791

8892
@route("/session/keymaterial")
89-
@tag("Sensitive Action")
93+
@tag("Sensitive Actions")
9094
@summary("Delete encrypted private key material")
9195
@added(Version.`v1.0-alpha.1`)
9296
@delete
@@ -95,8 +99,8 @@ namespace FederatedIdentity {
9599
* the serial numbers of ID-Certs that the client has uploaded key material for.
96100
*/
97101
op deleteEncryptedPKM(
98-
@doc("Sensitive actions require a [challenge string solution](/docs/Protocol%20Specifications/core.md) to be executed.")
99-
@header({name: "X-P2-CHALLENGE-STRING-SOLUTION"}) challengeStringSolution: string,
102+
@doc("Sensitive actions require a second factor of authentication to be executed. Read [section 4.1.2 of the protocol definition](https://docs.polyphony.chat/Protocol%20Specifications/core/#412-sensitive-actions) for more information.")
103+
@header({name: "X-P2-Sensitive-Solution"}) sensitiveSolution: string,
100104
@query serials: uint64[]): {
101105
@statusCode statusCode: 204;
102106
} | {
@@ -118,18 +122,38 @@ namespace FederatedIdentity {
118122
@header({name: "X-MAX-PAYLOAD-SIZE"}) size: uint32;
119123
@statusCode statusCode: 200;
120124
};
125+
126+
@route("/session")
127+
@delete
128+
@added(Version.`v1.0-alpha.1`)
129+
@summary("Delete/Revoke Session")
130+
@useAuth(BearerAuth)
131+
/**
132+
* Invalidate a session and its' associated ID-Cert by providing the session ID associated
133+
* with it.
134+
*/
135+
op deleteSession(
136+
@doc("Sensitive actions require a second factor of authentication to be executed. Read [section 4.1.2 of the protocol definition](https://docs.polyphony.chat/Protocol%20Specifications/core/#412-sensitive-actions) for more information.")
137+
@header({name: "X-P2-Sensitive-Solution"}) sensitiveSolution: string,
138+
@query session_id: string
139+
): {
140+
@statusCode statusCode: 204;
141+
@header({name: "Content-Length"}) contentLength: 0;
142+
} | {
143+
@statusCode statusCode: 404;
144+
};
121145
}
122146

123147
@tag("Federated Identity - Registration not required")
124148
namespace Unregistered {
125149
@route("/challenge")
126-
@summary("Get challenge string")
150+
@summary("Receive a challenge string")
127151
@useAuth(BearerAuth)
128152
@added(Version.`v1.0-alpha.1`)
129153
@get
130154
/**
131155
* Request a challenge string. See the corresponding
132-
* [protocol definition chapter](/docs/Protocol%20Specifications/core/#)
156+
* [protocol definition chapter](https://docs.polyphony.chat/Protocol%20Specifications/core/#42-challenge-strings)
133157
* for more information.
134158
*/
135159
op challengeString(): {
@@ -142,12 +166,13 @@ namespace FederatedIdentity {
142166
@added(Version.`v1.0-alpha.1`)
143167
@post
144168
@useAuth(BearerAuth)
145-
@tag("Sensitive Action")
169+
@tag("Sensitive Actions")
146170
/**
147171
* Rotate the server's identity key. Requires server administrator permissions.
148172
* @returns The servers' new ID-Cert, encoded as PEM
149173
*/
150-
op name(@header({name: "X-P2-CHALLENGE-STRING-SOLUTION"}) challengeStringSolution: string): string;
174+
op name(@doc("Sensitive actions require a second factor of authentication to be executed. Read [section 4.1.2 of the protocol definition](https://docs.polyphony.chat/Protocol%20Specifications/core/#412-sensitive-actions) for more information.")
175+
@header({name: "X-P2-Sensitive-Solution"}) sensitiveSolution: string,): string;
151176

152177
@route("/idcert/server")
153178
@get
@@ -209,25 +234,20 @@ namespace FederatedIdentity {
209234
@useAuth(BearerAuth)
210235
@summary("Update session ID-Cert")
211236
/**
212-
* Lets a foreign server know that the ID-Cert of this session has changed.
237+
* Lets a foreign server know that the ID-Cert of a session has changed. This route is also
238+
* used to inform foreign servers about the revocation of an ID-Cert. The ID-Cert passed as
239+
* body in this route must belong to the actor making the request.
240+
* @returns 201 on success, 400 if the body is somehow invalid.
213241
*/
214242
op updateSessionCert(@body id_cert: string): {
215243
@statusCode statusCode: 201;
216-
};
217-
218-
@route("/session")
219-
@delete
220-
@added(Version.`v1.0-alpha.1`)
221-
@summary("Delete/Revoke Session")
222-
@useAuth(BearerAuth)
223-
/**
224-
* Invalidate a session token by naming the session ID associated with it.
225-
*/
226-
op deleteSession(@query session_id: string): {
227-
@statusCode statusCode: 204;
228-
@header({name: "Content-Length"}) contentLength: 0;
229244
} | {
230-
@statusCode statusCode: 404;
245+
@statusCode statusCode: 400;
231246
};
232247
}
233-
}
248+
}
249+
250+
/*
251+
TODO: Missing routes:
252+
- Changing actor federation ID
253+
*/

api/src/core/routes/services.tsp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,34 @@ namespace Services {
3838
@delete
3939
@summary("Delete discoverable service")
4040
@added(Version.`v1.0-alpha.1`)
41+
@tag("Sensitive Actions")
4142
/**
4243
* Remove a service from the list of services discoverable by other actors.
4344
* If a primary service is removed and there are still other providers available for the same service,
4445
* the server will select a new primary service provider from the list of available providers.
4546
* This new provider will be returned in the response body.
4647
* @param url List of urls of the service providers to remove. The indices of the urls list must match the indices of the service name list.
48+
* @param sensitiveSolution: Required only when deleting a primary service provider.
4749
* @param name List of urls of the service providers to remove. The indices of the service name list must match the indices of the urls list.
4850
*/
49-
op unregisterService(@query url: url[], @query name: string[]): {
51+
op unregisterService(
52+
@doc("Sensitive actions require a second factor of authentication to be executed. Read [section 4.1.2 of the protocol definition](https://docs.polyphony.chat/Protocol%20Specifications/core/#412-sensitive-actions) for more information.")
53+
@header({name: "X-P2-Sensitive-Solution"}) sensitiveSolution?: string,
54+
@query url: url[],
55+
@query name: string[]
56+
): {
5057
@statusCode statusCode: 200;
5158
@body returnedBody?: {
5259
service: string,
5360
new_primary: url
5461
}[]
5562
} | {
56-
@statusCode statusCode: 400 | 404;
63+
@statusCode statusCode: 400 | 403 | 404;
5764
};
5865

5966
@route("/services/primary")
6067
@put
68+
@tag("Sensitive Actions")
6169
@summary("Set primary service provider")
6270
@added(Version.`v1.0-alpha.1`)
6371
/**
@@ -70,11 +78,17 @@ namespace Services {
7078
* with the new primary service provider.
7179
* @param body URL of a service provider and name of a service.
7280
*/
73-
op setPrimaryProvider(@body body: {url: url, @minLength(2) @maxLength(64) name: string}): {
81+
op setPrimaryProvider(
82+
@doc("Sensitive actions require a second factor of authentication to be executed. Read [section 4.1.2 of the protocol definition](https://docs.polyphony.chat/Protocol%20Specifications/core/#412-sensitive-actions) for more information.")
83+
@header({name: "X-P2-Sensitive-Solution"}) sensitiveSolution: string,
84+
@body body: {url: url, @minLength(2) @maxLength(64) name: string}
85+
): {
7486
@statusCode statusCode: 200;
7587
@maxItems(2)
7688
@minItems(1)
7789
@body body: polyproto.core.models.Service[];
90+
} | {
91+
@statusCode statusCode: 400 | 403;
7892
};
7993
}
8094

0 commit comments

Comments
 (0)