-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathapi-description.yaml
More file actions
539 lines (532 loc) · 19.9 KB
/
api-description.yaml
File metadata and controls
539 lines (532 loc) · 19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
openapi: "3.0.3"
info:
title: "Cryptify API"
description: "This is the cryptify server that manages encrypted files."
version: "1.0.0"
servers:
- url: http://localhost:8000
description: Development server
tags:
- name: "Health"
description: "Health check"
- name: "Metrics"
description: "Prometheus scrape endpoint"
- name: "File upload"
description: "Upload files"
- name: "File download"
description: "Download files"
- name: "Usage"
description: "Upload usage quotas"
paths:
/health:
get:
tags:
- "Health"
summary: "Health check endpoint"
operationId: "health"
responses:
"200":
description: "Service is healthy"
content:
text/plain:
schema:
type: "string"
example: "OK"
/metrics:
get:
tags:
- "Metrics"
summary: "Prometheus text-format metrics"
description: |
Returns usage counters and gauges suitable for Prometheus scraping
by the Grafana instance on Scaleway. Intended to be reachable only
from the internal monitoring network; firewall or reverse-proxy
allow-list in front of Cryptify.
Exposed metrics:
* `cryptify_uploads_total{channel}` — counter of finalized uploads.
* `cryptify_upload_bytes_total{channel}` — counter of bytes.
* `cryptify_storage_bytes` — gauge, current disk usage.
* `cryptify_active_files` — gauge, current file count.
* `cryptify_expired_files_total` — counter of uploads purged
before finalization.
The `channel` label is derived from the `X-Cryptify-Source` header,
falling back to `Authorization`/`X-Api-Key` (→ `api`), then the
`Origin` header (`website` / `staging-website`), then `User-Agent`
(`outlook` / `thunderbird`), then `unknown`.
operationId: "metrics"
responses:
"200":
description: "Prometheus text exposition format"
content:
text/plain:
schema:
type: "string"
/fileupload/init:
post:
tags:
- "File upload"
summary: "Initialize multipart file upload"
operationId: "initFileUpload"
requestBody:
content:
application/json:
schema:
type: "object"
required:
- recipient
- mailContent
- mailLang
- confirm
properties:
recipient:
type: "string"
format: "email"
example: "recipient@example.com"
description: "Email address of the recipient"
mailContent:
type: "string"
example: "Here is your encrypted file"
description: "Content to include in the email"
mailLang:
type: "string"
enum: ["EN", "NL"]
example: "EN"
description: "Email language (EN or NL)"
confirm:
type: "boolean"
example: true
description: "Whether to send a confirmation email to the sender"
notifyRecipients:
type: "boolean"
default: true
example: true
description: "Whether to email each recipient with a download link. Optional; defaults to true. Set to false to upload silently when the encrypted payload reaches recipients through another channel and a Cryptify-sent notification would be a duplicate."
responses:
"200":
description: "Successful operation"
headers:
cryptifytoken:
description: "Identifies the initial version of the file to be uploaded. Needs to be passed into the file part upload request."
required: true
schema:
type: "string"
content:
application/json:
schema:
type: "object"
required:
- uuid
- recovery_token
properties:
uuid:
type: "string"
format: "uuid"
description: "Unique identifier for the file upload"
recovery_token:
type: "string"
description:
"Bearer credential for the cross-refresh-resume
status endpoint (`GET /fileupload/{uuid}/status`).
The client should store this alongside the UUID
(e.g. in IndexedDB) and present it in an
`X-Recovery-Token` header to recover from a
page refresh, tab crash, or navigate-away-and-back.
Hex-encoded 32-byte random."
/fileupload/{uuid}:
put:
tags:
- "File upload"
summary: "Upload a file part"
description:
"Append a single chunk to the upload identified by `uuid`.\n\n
**Idempotent retry contract.** A chunk PUT whose response was lost
in flight can be safely retried with the *previous* `cryptifytoken`
value (the one the client sent on the failed attempt) at the same
`Content-Range` offset and with the same body. The server detects
this case — the request matches the cached `(prev_token, offset,
length, sha256)` of the most recently committed chunk — and
replays the previously returned `cryptifytoken` without
re-writing the file or double-counting against quotas. If the
request looks like a retry but the body bytes differ, the server
responds 400; clients must not retry the same offset with
different bytes.\n\n
Retries are only honoured for the *most recently committed*
chunk. If a client falls behind by more than one chunk it must
start a new upload."
operationId: "uploadFilePart"
parameters:
- in: "header"
name: "cryptifytoken"
description:
"Identifies the version of the upload file parts. Part of the header from the last fileupload response. On a retry of a chunk whose response was lost, send the *previous* token (the one originally sent on the failed PUT)."
schema:
type: "string"
required: true
- in: "header"
name: "Content-Range"
description:
"Which offset of a file is sent, example: `bytes 200-1000/*`."
schema:
type: "string"
required: true
- in: "path"
name: "uuid"
required: true
description: "The unique identifier received when initializing file upload."
schema:
type: "string"
format: "uuid"
requestBody:
content:
application/octet-stream:
schema:
type: "string"
format: "binary"
responses:
"200":
description: "Successful operation."
headers:
cryptifytoken:
required: true
schema:
description: "Identifies the new version of the upload file parts. Needs to be passed into the next file part upload request."
type: "string"
"409":
description: "Server file parts cryptifytoken differs from cryptifytoken in request."
headers:
cryptifytoken:
required: true
schema:
description:
"Identifies the version of the upload file parts. Needs to be passed into the next file part upload request."
type: "string"
"400":
description: "One of the input parameters is incorrect."
content:
application/json:
schema:
type: "object"
properties:
message:
type: "string"
"404":
description:
"The upload session is not known to the server. Either the
client never called `/fileupload/init`, the session was idle
past the configured TTL and got evicted, or the on-disk file
has been removed. Clients should not retry — start a new
upload via `/fileupload/init`."
content:
application/json:
schema:
$ref: "#/components/schemas/UploadSessionNotFound"
"413":
description: "The upload exceeds the per-upload size limit (5 GB for non-API-key uploads, 100 GB for API-key uploads)."
content:
application/json:
schema:
$ref: "#/components/schemas/PayloadTooLarge"
/fileupload/finalize/{uuid}:
post:
tags:
- "File upload"
summary: "Finalize multipart file upload and send mail to recipient"
operationId: "finalizeFileUpload"
parameters:
- in: "header"
name: "Content-Range"
description:
"Indicates the final file size: `bytes */1073741824`."
schema:
type: "string"
required: true
- in: "path"
name: "uuid"
description: "The unique identifier received when initializing file upload."
required: true
schema:
type: "string"
format: "uuid"
responses:
"200":
description: "Successful operation"
"409":
description: "Server file parts cryptifytoken differs from cryptifytoken in request"
headers:
cryptifytoken:
required: true
schema:
description: "Identifies the version of the upload file parts. Needs to be passed into the next file part upload request."
type: "string"
"400":
description: "One of the input parameters is incorrect."
content:
application/json:
schema:
type: "object"
properties:
message:
type: "string"
"404":
description:
"The upload session is not known to the server (see
`/fileupload/{uuid}` 404 for details). Clients should not
retry — start a new upload via `/fileupload/init`."
content:
application/json:
schema:
$ref: "#/components/schemas/UploadSessionNotFound"
"413":
description: "The sender has exceeded the rolling 14-day upload limit (5 GB for non-API-key uploads, 100 GB for API-key uploads)."
content:
application/json:
schema:
$ref: "#/components/schemas/PayloadTooLarge"
"422":
description: "Data is missing to form complete file."
/fileupload/{uuid}/status:
get:
tags:
- "File upload"
summary: "Read upload state for cross-refresh resume"
description:
"Returns the rolling-token state of an in-flight upload so a
client that lost track of the session (page refresh, tab crash,
navigate-away-and-back) can rehydrate and feed the next chunk
PUT through the idempotent-retry path
(`PUT /fileupload/{uuid}`). Authenticates via the
`X-Recovery-Token` header issued at `upload_init`. **Behaviour
on resume conflict:** if two clients hold the same UUID and
recovery token (e.g. two tabs), the first chunk PUT to land
wins and the second sees a 4xx as soon as it tries to advance
past the now-stale state — single-active-resumer semantics, no
lease enforcement on the server side. A successful call also
resets the session's idle eviction deadline so the very next
chunk PUT does not 404 because the rehydrate window aged out."
operationId: "uploadStatus"
parameters:
- in: "header"
name: "X-Recovery-Token"
description:
"Bearer credential issued in the `recovery_token` field of
the `upload_init` response. Compared in constant time on the
server. Missing / empty → 401."
schema:
type: "string"
required: true
- in: "path"
name: "uuid"
required: true
description: "The unique identifier received when initializing file upload."
schema:
type: "string"
format: "uuid"
responses:
"200":
description: "Successful operation."
content:
application/json:
schema:
$ref: "#/components/schemas/UploadStatus"
"401":
description:
"Missing or empty `X-Recovery-Token` header. Note: a
*valid-format* token that simply does not match the stored
value returns 404 with the same body shape as an evicted
session, deliberately, so attackers cannot probe for live
UUIDs by varying the token."
"404":
description:
"The upload session is not known to the server, OR the
recovery token does not match the stored value. The two
cases are deliberately collapsed — same response shape as
`PUT /fileupload/{uuid}` — to avoid leaking session
existence."
content:
application/json:
schema:
$ref: "#/components/schemas/UploadSessionNotFound"
/usage:
get:
tags:
- "Usage"
summary: "Get rolling upload usage for a sender email"
description:
"Returns the bytes uploaded by the given email address in the last 14 days,
together with the applicable limits. Frontends use this to warn the user
before they hit the limit."
operationId: "getUsage"
parameters:
- in: "query"
name: "email"
description: "The sender email address to query."
required: true
schema:
type: "string"
format: "email"
responses:
"200":
description: "Usage information for the given email."
content:
application/json:
schema:
type: "object"
required:
- email
- used_bytes
- limit_bytes
- window_days
- per_upload_limit_bytes
properties:
email:
type: "string"
format: "email"
used_bytes:
type: "integer"
format: "int64"
description: "Bytes uploaded by this email in the rolling window."
limit_bytes:
type: "integer"
format: "int64"
description: "Rolling-window upload limit in bytes for the requesting sender (5 GB for non-API-key uploads, 100 GB for API-key uploads)."
window_days:
type: "integer"
description: "Length of the rolling window in days."
per_upload_limit_bytes:
type: "integer"
format: "int64"
description: "Maximum size of a single upload in bytes for the requesting sender (5 GB for non-API-key uploads, 100 GB for API-key uploads)."
resets_at:
type: "string"
format: "date-time"
nullable: true
description:
"RFC-3339 timestamp at which the oldest recorded upload
falls out of the rolling window, partially freeing quota.
Null if the sender has no recorded uploads."
/filedownload/{uuid}:
get:
tags:
- "File download"
summary: "Download a file"
operationId: "downloadFile"
parameters:
- in: "path"
name: "uuid"
required: true
description: "The unique identifier received when initializing file upload."
schema:
type: "string"
format: "uuid"
responses:
"200":
description: "Successful operation."
content:
application/cryptify+octet-stream:
schema:
type: "string"
format: "binary"
"400":
description: "One of the input parameters is incorrect."
content:
application/json:
schema:
type: "object"
properties:
message:
type: "string"
"404":
description: "Uploaded file does not exist."
components:
schemas:
PayloadTooLarge:
type: "object"
required:
- error
- limit
- used_bytes
- limit_bytes
properties:
error:
type: "string"
description: "Human-readable explanation of which limit was hit."
limit:
type: "string"
enum:
- "per_upload"
- "rolling_window"
description: "Which limit tripped the 413 response."
used_bytes:
type: "integer"
format: "int64"
description:
"Bytes already attributed to the sender in the relevant window.
For per_upload, this is the bytes already written for the current
upload before the rejected chunk."
limit_bytes:
type: "integer"
format: "int64"
description: "The limit value in bytes."
UploadSessionNotFound:
type: "object"
required:
- error
- uuid
- reason
properties:
error:
type: "string"
enum:
- "upload_session_not_found"
description: "Stable machine-readable error code for clients."
uuid:
type: "string"
format: "uuid"
description: "The upload UUID the request targeted."
reason:
type: "string"
enum:
- "expired_or_unknown"
- "invalid_uuid"
- "file_missing"
description:
"Why the session is not retrievable. `expired_or_unknown`
means the session was either evicted after its idle TTL or
never existed (clients cannot tell these apart, by design).
`invalid_uuid` means the path UUID is malformed.
`file_missing` means the in-memory session exists but the
on-disk file is gone (server-state inconsistency)."
UploadStatus:
type: "object"
required:
- uploaded
- cryptify_token
properties:
uploaded:
type: "integer"
format: "int64"
description:
"Total bytes the server has committed for this upload so far.
The client should resume from this offset."
cryptify_token:
type: "string"
description:
"Current value of the rolling token. The client must send this
as `cryptifytoken` on the next chunk PUT."
prev_token:
type: "string"
description:
"Token the client sent on the most recently committed chunk
(i.e. the value of `cryptify_token` *before* that chunk
advanced it). Combined with `prev_offset`, lets the client
re-issue the most recent chunk on the idempotent-retry path
(PUT `/fileupload/{uuid}`) if it is unsure whether the chunk
was committed. Omitted until at least one chunk has been
committed."
prev_offset:
type: "integer"
format: "int64"
description:
"Byte offset where the most recently committed chunk started
(i.e. `uploaded - chunk_len`). Omitted until at least one
chunk has been committed."