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
|
:LastChangedDate: $LastChangedDate$
:LastChangedRevision: $LastChangedRevision$
:LastChangedBy: $LastChangedBy$
.. _bitmask_core:
============
Bitmask Core
============
The bitmask core daemon can be launched like this::
bitmaskd
The command-line program ``bitmaskctl`` and the GUI will launch the
daemon when needed.
Starting the REST service
=========================
If configured to do so, the bitmask core will expose all of the commands
throught a REST API. In bitmaskd.cfg::
[services]
web = True
Global API Authentication
=========================
To avoid some kind of attacks, the Bitmask API is protected by a global
authentication token.
The JS API receives this value when the initial entrypoint is loaded for the
first time, in the anchor part of the url.
To authenticate any request to the API, the ``X-Bitmask-Auth`` header has to be
added to it, set to the single value that is initialized during the bitmask
deaemon startup::
curl -X POST http://localhost:7070/API/mail/status
unauthorized:bad auth token
curl -X POST http://localhost:7070/API/mail/status -H 'X-Bitmask-Auth: fae20706aa4f4f98ac0e67996787a370'
{"result": {"status": "on", "childrenStatus": {"smtp": {"status": "on", "error": null}, "imap": {"status": "on", "error": null}}, "error": null}, "error": null}
This token can be found in ``.config/leap/authtoken``
API Authentication (this section not implemented yet)
======================================================
By default, the resources in the API are protected by an authentication token.
The rationale is that, since the Bitmask core can be used simultaneously by
several users, no single user should be able to interfere with others by
querying for sensible information or disrupting other users' interaction with
running services.
Therefore, there's a small white list of resources that do not
need authentication, based on which is the subset of the API that needs to
provide functionality for the creation of new accounts (the first-run wizard
from the UI perspective).
The local authentication token is sent back in the response for an
authentication call.
This local session token is different from the remote SRP token, although both
are returned together. In the case that the remote SRP authentication with the
provider fails (or with no network connectivity), the backend **should** signal
the error but equally return a local authentication token (this is not
implemented yet, but needs to be done to support an offline mode of operation).
To authenticate any request to the API, the ``Authorization`` header has to be
added to it. You need to pass a ``Token`` field, with a value equal to the
concatenation of the username and the local session token , base64-encoded::
$ curl -X POST localhost:7070/API/core/stop
$ Unauthorized
>>> import base64
>>> base64.b64encode('user@provider.org:52dac27fcf633b1dba58')
'dXNlckBwcm92aWRlci5vcmc6NTJkYWMyN2ZjZjYzM2IxZGJhNTg='
$ curl -X POST localhost:7070/API/core/stop -H 'Authorization: Token dXNlckBwcm92aWRlci5vcmc6NTJkYWMyN2ZjZjYzM2IxZGJhNTg='
$ {'shutdown': 'ok'}
Resources
=========
Following is a list of currently available resources and a brief description of
each one. For details click on the resource name.
**By default, all the resources need authentication**. An asterisk next to it
means that it does not need an authentication header.
+------------------------------------+---------------------------------+
| Resource | Description |
+====================================+=================================+
| ``POST`` :ref:`cmd_core_version` * | Get Bitmask Core Version Info |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_core_stats` * | Get Stats about Bitmask Usage |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_core_status` | Get Bitmask Status |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_core_stop` | Stop Bitmask Core |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_prov_list` * | List all providers |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_prov_create` * | Create a new provider |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_prov_read` * | Get info about a provider |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_prov_del` | Delete a given provider |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_user_list` | List all users |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_user_active` | Get active user |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_user_create` * | Create a new user |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_user_update` | Change the user password |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_user_auth` * | Authenticate an user |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_user_logout` | End session for an user |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_keys_list` | Get all known keys for an user |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_keys_insert` | Insert a new key |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_keys_del` | Delete a given key |
+------------------------------------+---------------------------------+
| ``POST`` :ref:`cmd_keys_export` | Export keys |
+------------------------------------+---------------------------------+
.. _cmd_parameters:
Passing parameters
------------------
In all the cases that need data passed as parameter, those will be passed as
JSON-encoded data to the POST.
.. _cmd_core_version:
/core/version
-------------
**POST /core/version**
Get Bitmask Core Version Info
**Example request**::
curl -X POST localhost:7070/API/core/version
**Example response**::
{
"error": null,
"result":
{
"version_core": "0.9.3+185.g59ee6c29.dirty"
}
}
.. _cmd_core_stats:
/core/stats
-----------
**POST /core/stats**
Get Stats about Bitmask Usage
.. _cmd_core_status:
/core/status
------------
**POST /core/status**
Get Bitmask status
.. _cmd_core_stop:
/core/stop
----------
**POST /core/stop**
Stop Bitmask core (daemon shutdown).
.. _cmd_prov_list:
/bonafide/provider/list
-----------------------
**POST /bonafide/provider/list**
List all known providers.
.. _cmd_prov_create:
/bonafide/provider/create
--------------------------
**POST /bonafide/provider**
Create a new provider.
.. _cmd_prov_read:
/bonafide/provider/read
-----------------------
**POST /bonafide/provider/read**
Get info about a given provider.
**Example request**::
curl -X POST localhost:7070/API/bonafide/provider/read -d '["dev.bitmask.net"]'
**Example response**::
{
"error": null,
"result": {
"api_uri": "https://api.dev.bitmask.net:4430",
"api_version": "1",
"ca_cert_fingerprint": "SHA256: 0f17c033115f6b76ff67871872303ff65034efe7dd1b910062ca323eb4da5c7e",
"ca_cert_uri": "https://dev.bitmask.net/ca.crt",
"default_language": "es",
"description": {
"en": "Bitmask is a project of LEAP",
},
"domain": "dev.bitmask.net",
"enrollment_policy": "open",
"languages": [
"es"
],
"name": {
"en": "Bitmask"
},
"service": {
"allow_anonymous": false,
"allow_free": true,
"allow_limited_bandwidth": false,
"allow_paid": false,
"allow_registration": true,
"allow_unlimited_bandwidth": true,
"bandwidth_limit": 102400,
"default_service_level": 1,
"levels": {
"1": {
"description": "Please donate.",
"name": "free"
}
}
},
"services": [
"mx",
"openvpn"
]
}
}
**Form parameters**:
* ``domain`` *(required)* - domain to obtain the info for.
.. _cmd_prov_del:
/bonafide/provider/delete
-------------------------
**POST /bonafide/provider/delete**
Delete a given provider.
.. _cmd_user_list:
/bonafide/user/list
-------------------
**POST /bonafide/user/list**
List all the users known to the local backend.
**Form parameters**:
**Status codes**:
* ``200`` - no error
.. _cmd_user_active:
/bonafide/user/active
---------------------
**POST /bonafide/user/active**
Get the active user.
.. _cmd_user_create:
/bonafide/user/create
---------------------
**POST /bonafide/user/create**
Create a new user.
**Form parameters**:
* ``username`` *(required)* - in the form user@provider.
* ``pass`` *(required)* - the username passphrase
* ``invitecode`` *(optional)* - an optional invitecode, to be used if
the provider requires it for creating a new account.
* ``autoconf`` *(optional)* - whether to autoconfigure the provider, if
we have not seen it before.
**Status codes**:
* ``200`` - no error
.. _cmd_user_update:
/bonafide/user/update
---------------------
**POST /bonafide/user/update**
Change the user password.
**Form parameters**:
* ``username`` *(required)* - in the form user@provider
* ``oldpass`` *(required)* - current password
* ``newpass`` *(required)* - new password
**Status codes**:
* ``200`` - no error
.. _cmd_user_auth:
/bonafide/user/authenticate
---------------------------
**POST /bonafide/user/authenticate**
Authenticate an user.
**Form parameters**:
* ``username`` *(required)* - in the form user@provider
* ``pass`` *(required)* - passphrase
* ``autoconf`` *(optional)* - whether to autoconfigure the provider, if
we don't have seen it before.
**Status codes**:
* ``200`` - no error
.. _cmd_user_logout:
/bonafide/user/logout
---------------------
**POST /bonafide/user/logout**
Logs out an user, and destroys its local session.
.. _cmd_keys_list:
/mail/status
-----------------------
**POST /mail/status
Get the status of the mail service
**Example request**::
curl -X POST localhost:7070/API/mail/status -d '["foobar@mail.bitmask.net"]'
**Example response**::
{
"result": {
"status": "on",
"keys": "found",
"unread": 5,
"childrenStatus": {
"keymanager": {
"status": "on",
"keys": "found",
"error": null
},
"smtp": {
"status": "on",
"error": null
},
"incoming": {
"status": "on",
"unread": 5,
"error": null
},
"imap": {
"status": "on",
"error": null
}
},
"error": null
},
"error": null
}
**Form parameters**:
* ``address`` *(required)* - the email address of the account.
**Values**:
The possible values for ``status`` are:
* ``on``
* ``off``
* ``starting``
* ``stopping``
* ``failed``
The possible values for the ``keys`` field are:
* ``null`` - nothing is known about the private key status.
* ``sync`` - syncing soledad to see if there is a private key.
* ``generating`` - creating a new private key as none was found.
* ``found`` - there is a valid private key in KeyManager.
.. _cmd_prov_del:
/keys/list
-------------------
**POST /keys/list**
Get all keys for an user.
.. _cmd_keys_insert:
/keys/insert/
-------------------
**POST /keys/insert**
Insert a new key for an user.
.. _cmd_keys_del:
/keys/delete/
-------------------
**POST /keys/delete**
Delete a key for an user.
.. _cmd_keys_export:
/keys/export/
-------------------
**POST /keys/export**
Export keys for an user.
|