| 1 |
# Browserpass Communication Protocol |
| 2 |
|
| 3 |
This document describes the protocol used for communication between the browser extension, |
| 4 |
and the native host application. |
| 5 |
|
| 6 |
## Response Types |
| 7 |
|
| 8 |
### OK |
| 9 |
|
| 10 |
Consists solely of an `ok` status, an integer app version, and a `data` field which |
| 11 |
may be of any type. |
| 12 |
|
| 13 |
The app version is an integer, calculated by `(MAJOR * 1000000) + (MINOR * 1000) + PATCH`. |
| 14 |
|
| 15 |
``` |
| 16 |
{ |
| 17 |
"status": "ok", |
| 18 |
"version": <int>, |
| 19 |
"data": <any type> |
| 20 |
} |
| 21 |
``` |
| 22 |
|
| 23 |
### Error |
| 24 |
|
| 25 |
Consists solely of an `error` status, a nonzero integer error code, and an optional `params` |
| 26 |
object that provides any parameters that should accompany the error. |
| 27 |
|
| 28 |
``` |
| 29 |
{ |
| 30 |
"status": "error", |
| 31 |
"code": <int>, |
| 32 |
"version": <int>, |
| 33 |
"params": { |
| 34 |
"<paramN>": <valueN> |
| 35 |
} |
| 36 |
} |
| 37 |
``` |
| 38 |
|
| 39 |
When the error message is relaying a message from a native system component, then that message |
| 40 |
should be supplied as a `message` parameter. |
| 41 |
|
| 42 |
## List of Error Codes |
| 43 |
|
| 44 |
| Code | Description | Parameters | |
| 45 |
| ---- | ----------------------------------------------------------------------- | ----------------------------------------------------------- | |
| 46 |
| 10 | Unable to parse browser request length | message, error | |
| 47 |
| 11 | Unable to parse browser request | message, error | |
| 48 |
| 12 | Invalid request action | message, action | |
| 49 |
| 13 | Inaccessible user-configured password store | message, action, error, storeId, storePath, storeName | |
| 50 |
| 14 | Inaccessible default password store | message, action, error, storePath | |
| 51 |
| 15 | Unable to determine the location of the default password store | message, action, error | |
| 52 |
| 16 | Unable to read the default settings of a user-configured password store | message, action, error, storeId, storePath, storeName | |
| 53 |
| 17 | Unable to read the default settings of the default password store | message, action, error, storePath | |
| 54 |
| 18 | Unable to list files in a password store | message, action, error, storeId, storePath, storeName | |
| 55 |
| 19 | Unable to determine a relative path for a file in a password store | message, action, error, storeId, storePath, storeName, file | |
| 56 |
| 20 | Invalid password store ID | message, action, storeId | |
| 57 |
| 21 | Invalid gpg path | message, action, error, gpgPath | |
| 58 |
| 22 | Unable to detect the location of the gpg binary | message, action, error | |
| 59 |
| 23 | Invalid password file extension | message, action, file | |
| 60 |
| 24 | Unable to decrypt the password file | message, action, error, storeId, storePath, storeName, file | |
| 61 |
|
| 62 |
## Settings |
| 63 |
|
| 64 |
The `settings` object is a key / value map of individual settings. It's provided by the |
| 65 |
browser to the native app as part of every request. |
| 66 |
|
| 67 |
Settings are saved in browser local storage. Each top-level setting is saved separately, |
| 68 |
JSON-encoded and saved by its key. |
| 69 |
|
| 70 |
Settings may also be supplied via a `.browserpass.json` file in the root of a password store, |
| 71 |
and via parameters in individual `*.gpg` files. |
| 72 |
|
| 73 |
Settings are applied using the following priority, highest first: |
| 74 |
|
| 75 |
1. Configured by the user in specific `*.gpg` files (e.g. autosubmit: true) |
| 76 |
1. Configured by the user in `.browserpass.json` file in specific password stores |
| 77 |
1. Configured by the user via the extension options |
| 78 |
1. Defaults shipped with the browser extension |
| 79 |
|
| 80 |
### Global Settings |
| 81 |
|
| 82 |
| Setting | Description | Default | |
| 83 |
| ------- | ---------------------------------------------------- | ------- | |
| 84 |
| gpgPath | Optional path to gpg binary | `null` | |
| 85 |
| stores | List of password stores with store-specific settings | `{}` | |
| 86 |
|
| 87 |
### Store-specific Settings |
| 88 |
|
| 89 |
| Setting | Description | Default | |
| 90 |
| ------- | --------------------------------------- | ------- | |
| 91 |
| id | Unique store id (same as the store key) | `<key>` | |
| 92 |
| name | Store name | `""` | |
| 93 |
| path | Path to the password store directory | `""` | |
| 94 |
|
| 95 |
## Actions |
| 96 |
|
| 97 |
### Configure |
| 98 |
|
| 99 |
Returns a response containing the per-store config. Used to check that the host app |
| 100 |
is alive, determine the version at startup, and provide per-store defaults. |
| 101 |
|
| 102 |
#### Request |
| 103 |
|
| 104 |
``` |
| 105 |
{ |
| 106 |
"settings": <settings object>, |
| 107 |
"defaultStoreSettings": <store-specific settings for default store>, |
| 108 |
"action": "configure" |
| 109 |
} |
| 110 |
``` |
| 111 |
|
| 112 |
#### Response |
| 113 |
|
| 114 |
``` |
| 115 |
{ |
| 116 |
|
| 117 |
"status": "ok", |
| 118 |
"version": <int>, |
| 119 |
"data": { |
| 120 |
"defaultStore": { |
| 121 |
"path": "/path/to/default/store", |
| 122 |
"settings": "<raw contents of $defaultPath/.browserpass.json>", |
| 123 |
}, |
| 124 |
“storeSettings”: { |
| 125 |
“storeId”: "<raw contents of storePath/.browserpass.json>" |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
``` |
| 130 |
|
| 131 |
### List |
| 132 |
|
| 133 |
Get a list of all `*.gpg` files for each of a provided array of directory paths. The `storeN` |
| 134 |
is the ID of a password store, the key in `"settings.stores"` object. |
| 135 |
|
| 136 |
#### Request |
| 137 |
|
| 138 |
``` |
| 139 |
{ |
| 140 |
"settings": <settings object>, |
| 141 |
"action": "list" |
| 142 |
} |
| 143 |
``` |
| 144 |
|
| 145 |
#### Response |
| 146 |
|
| 147 |
``` |
| 148 |
{ |
| 149 |
"status": "ok", |
| 150 |
"version": <int>, |
| 151 |
"data": { |
| 152 |
"files": { |
| 153 |
"storeN": ["<storeNPath/file1.gpg>", "<...>"], |
| 154 |
"storeN+1": ["<storeN+1Path/file1.gpg>", "<...>"] |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
``` |
| 159 |
|
| 160 |
### Fetch |
| 161 |
|
| 162 |
Get the decrypted contents of a specific file. |
| 163 |
|
| 164 |
#### Request |
| 165 |
|
| 166 |
``` |
| 167 |
{ |
| 168 |
"settings": <settings object>, |
| 169 |
"action": "fetch", |
| 170 |
"storeId": "<storeId>", |
| 171 |
"file": "relative/path/to/file.gpg" |
| 172 |
} |
| 173 |
``` |
| 174 |
|
| 175 |
#### Response |
| 176 |
|
| 177 |
``` |
| 178 |
{ |
| 179 |
"status": "ok", |
| 180 |
"version": <int>, |
| 181 |
"data": { |
| 182 |
"contents": "<decrypted file contents>" |
| 183 |
} |
| 184 |
} |
| 185 |
``` |
| 186 |
|
| 187 |
### Echo |
| 188 |
|
| 189 |
Send the `echoResponse` in the request as a response. |
| 190 |
|
| 191 |
#### Request |
| 192 |
|
| 193 |
``` |
| 194 |
{ |
| 195 |
"action": "echo", |
| 196 |
"echoResponse": <anything> |
| 197 |
} |
| 198 |
``` |
| 199 |
|
| 200 |
#### Response |
| 201 |
|
| 202 |
``` |
| 203 |
<echoResponse> |
| 204 |
``` |