File: GettingStarted.md

package info (click to toggle)
pwdsphinx 2.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 856 kB
  • sloc: python: 3,793; javascript: 1,001; sh: 238; makefile: 74
file content (442 lines) | stat: -rw-r--r-- 14,100 bytes parent folder | download
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
# Getting started

So you want to start using SPHINX for handling your passwords. Great, Welcome!

First you need to decide if you want to host your own server (we call
it oracle), or you want to use someone elses oracle. It's ok to use
someone elses server, as we say the oracle can be hosted by your worst
nightmare enemy, they will not learn anything about your passwords[1].

It is important to note, that if you want to use sphinx, your client
needs to be able to connect to the oracle.

## Installing the sphinx CLI client

If you are on debian or derivates a simple
```
% sudo apt install pwdsphinx
```

should suffice and you can skip over to the next section to configure the client.
But before skipping you might also want to install these optional dependencies:
```
% apt install pinentry-gtk2 xdotool xinput
```

If you are not on debian derivates, you need to build two dependencies
manually. Let's start with libsphinx:

```
% git clone https://github.com/stef/libsphinx
% cd libsphinx/src
% sudo apt install install python3 libsodium libsodium-dev
% sudo PREFIX=/usr make install
```

We also need libequihash:

```
% git clone https://github.com/stef/equihash
% cd equihash
% sudo PREFIX=/usr make install
```

And finally install the client itself:

```
% pip install pwdsphinx
```

Dependencies might also needed for some things:

```
% apt install pinentry-gtk2 xdotool xinput
```

(replace `apt install` and the package names with whatever equivalent
your distro provides)

## Configuring the sphinx CLI client

Create a config file `~/.sphinxrc` and insert the correct address and
port for the server (oracle) you are going to use:

```
[client]
address = your.sphinx-server.tld
port = 443
timeout = 3
```

Now you should be ready to initialize your sphinx client:

```
% sphinx init
```

This will create a file `~/.sphinx/masterkey`, you should make a
backup of this file, and if you intend to use sphinx on other devices
sharing the same passwords on them, you must copy this file there as
well. If you intend to use `androsphinx` our android sphinx client,
you can also do:

```
sphinx qr key
```

And have this qr-code read by the androsphinx client to use the same
config as you have setup here.

You should be ready to go:

```
echo -n "password" | sphinx create testuser testhost
```

This should give you a long very random password as output. You can
now check if you get the same password back, but since echoing
passwords on the command line is not very smart, let's try with a tool
that comes with pwdsphinx: `getpwd`:

```
getpwd | sphinx get testuser testhost
```

This should pop up a password query window, where you should enter
'password' as the password, the response should be the long random
password that was returned when you used the create command.

And you can now also try to delete this test password, as you surely
don't want to litter around:

```
sphinx delete testuser testhost
```

You might wonder, why you don't need a password for deletion - that
actually depends on the `rwd_keys` setting, read about that in the man
page. However deletion does require that the masterkey in `~/.sphinx/`
is actually correct.

Now if you do again (being lazy and not using `getpwd`):

```
echo -n "password" | sphinx get testuser testhost
```
You should get an error.

Congrats, you just setup sphinx! Read up in the man pages
(https://github.com/stef/pwdsphinx/tree/master/man) more about how to
get the most out of sphinx.

## Setting up a Firefox addon

First install the sphinx CLI client - see the section above on more
info on that.

Then install the addon from the mozilla addons store:
https://addons.mozilla.org/en-US/firefox/addon/websphinx/

The WebSphinx addon also requires the installation of a native
messaging host - which is terminology and it really means backend.

Websphinx consists of two parts, the frontend which is the addon. And the backend which handles everything.

You can install the addon  from the [firefox addon store](https://addons.mozilla.org/en-US/firefox/addon/websphinx/).

The WebSphinx addon requires the installation of a native messaging host - which is terminology and it really means backend.

You will need to install a graphical pinentry,

   - either sudo apt-get install pinentry-qt
   - or sudo apt-get install pinentry-gtk2
   - or sudo apt-get install pinentry-gnome3
   - or sudo apt-get install pinentry-fltk

(or anything equivalent to apt-get install on your OS)

And set the pinentry variant if it is not invoked with
`/usr/bin/pinentry` in your sphinx config file in the `websphinx`
section

Your sphinx config file can be in a couple of locations:
 - globally: `/etc/sphinx/config`
 - for your user: `~/.sphinxrc`
 - or also:`~/.config/sphinx/config`
 - and always in the current directory.

To set the pinentry path, add or modify to have a section like this:

```
[websphinx]
pinentry=/usr/bin/pinentry-gtk-2
```

### Native Messaging Host Manifest

Copy [*websphinx.json*](https://github.com/stef/websphinx-firefox/raw/master/websphinx.json), depending on your browser to finish the installation:

- Linux/BSD
  - User only: `~/.mozilla/native-messaging-hosts/websphinx.json`
  - System-wide: `/usr/{lib,lib64,share}/mozilla/native-messaging-hosts/websphinx.json`
  - MacOS: `/Library/Application Support/Mozilla/NativeMessagingHosts/websphinx.json`

You need to change *%PATH%* in *websphinx.json* so it refers to *websphinx.py* which came with pwdsphinx.

1. `mkdir -p ~/.mozilla/native-messaging-hosts`
2. `curl -Lo ~/.mozilla/native-messaging-hosts/websphinx.json https://github.com/stef/websphinx-firefox/raw/master/websphinx.json`

if you followed this guide, `websphinx` should be installed in `/usr/bin` and you should replace the `%PATH%` in `~/.mozilla/native-messaging-hosts/websphinx.json` to `/usr/bin` so the file looks like this:

```
{
  "name": "websphinx",
  "description": "Host for communicating with pwdphinx",
  "path": "/usr/bin/websphinx",
  "type": "stdio",
  "allowed_extensions": [
    "sphinx@ctrlc.hu"
  ]
}

```

### Final step

Restart your browser in which the addon is installed and enjoy.

## Setting up a Chrome derivate addon (including ms edge, opera, brave, etc)

Websphinx consists of two parts, the frontend which is the addon. And
the backend which handles everything.

First install the sphinx CLI client, see the above for more information on that.

WebSphinx is not in the Chrome Web Store, if you want to install the addon
follow these steps (this applies to all Operating Systems):

 1. Create a directory on your filesystem containing the files in the
    websphinx directory. 
 2. Start your browser if it is not running,
 3. open [chrome://extension](chrome://extension) in your browser,
 4. enable `Developer Mode`,
 5. `Load Unpacked Extension` and provide the directory created in step 1.,
 6. If all went well, you should get a yellowyish sphinx button.

The WebSphinx addon requires the installation of a native messaging
host - which is terminology and it really means backend.

You will need to install a graphical pinentry,
   - either sudo apt-get install pinentry-qt
   - or sudo apt-get install pinentry-gtk2
   - or sudo apt-get install pinentry-gnome3
   - or sudo apt-get install pinentry-fltk

(or anything equivalent to apt-get install on your OS)

And set the pinentry variant if it is not invoked with
`/usr/bin/pinentry` in your sphinx config file in the `websphinx`
section

Your sphinx config file can be in a couple of locations:
 - globally: `/etc/sphinx/config`
 - for your user: `~/.sphinxrc`
 - or also:`~/.config/sphinx/config`
 - and always in the current directory.

To set the pinentry path, add or modify to have a section like this:

```
[websphinx]
pinentry=/usr/bin/pinentry-gtk-2
```

### Native Messaging Host Manifest

Copy [*websphinx.json*](https://github.com/stef/websphinx-firefox/raw/master/websphinx.json), depending on your browser to finish the installation:

- Linux/BSD
  - Per-user: `~/.config/{google-chrome,chromium}/NativeMessagingHosts/websphinx.json`
  - System: `/etc/{opt/chrome,chromium}/native-messaging-hosts/websphinx.json`
- MacOS
  - Per-user: `~/Library/Application Support/{Google/Chrome,Chromium}/NativeMessagingHosts/websphinx.json`
  - System-wide: `/Library/{Google/Chrome,Chromium}/NativeMessagingHosts/websphinx.json`

You need to change *%PATH%* in *websphinx.json* so it refers to *websphinx.py* which came with pwdsphinx.

Assuming you have chromium follow these steps (otherwise replace chromium with google-chrome, or even possibly opera?)

1. `mkdir -p ~/.config/chromium/NativeMessagingHosts`
2. `curl -Lo ~/.config/chromium/NativeMessagingHosts/websphinx.json https://github.com/stef/websphinx-chrom/raw/master/websphinx.json`

if you followed this guide, `websphinx` should be installed in `/usr/bin` and you should replace the `%PATH%` in `~/.config/chromium/NativeMessagingHosts/websphinx.json` to `/usr/bin` so the file looks like this:

```
{
  "name": "websphinx",
  "description": "Host for communicating with Sphinx",
  "path": "/usr/bin/websphinx",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://ojbhlhidchjkmjmpeonendekpoacahni/"
  ]
}

```

### Final step

Restart your browser in which the addon is installed and enjoy.

## Hosting your own oracle

Great! You should host your own oracle, and make it available also to
all your friends and family! The recommended way to do so is to
dedicate cheap and small single-board-computer to this task, which
does nothing else. An old Raspberry Pi 1 is enough, the oracle does
not use much resources.

## Installation

You need to install sphinx, either by using `pip`:

```
pip install pwdsphinx
```

or on Debian derivates:

```
apt install pwdsphinx
```

### Getting a TLS certificate using nginx and letsencrypt

First you need to generate an account and a domain key:

```
openssl genrsa 4096 > account.key
openssl genrsa 4096 > domain.key
```

Then you neeed to create a certificate signing request (CSR) for your
domains. For a single domain you can use:
```
openssl req -new -sha256 -key domain.key -subj "/CN=yoursite.com" > domain.csr
```

If you have multiple domains (like www.yoursite.com and yoursite.com) and a new openssl, then:

```
openssl req -new -sha256 -key domain.key -subj "/" -addext "subjectAltName = DNS:yoursite.com, DNS:www.yoursite.com" > domain.csr
```

Or if you have an old openssl < 1.1.1:
```
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /etc/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:yoursite.com,DNS:www.yoursite.com")) > domain.csr
```

Now you need nginx, and a challenges director it can serve:
```
apt install nginx
mkdir -p /var/www/challenges/
```
The configuration of nginx is the following:
```
# Example for nginx
server {
    listen 80;
    server_name yoursite.com www.yoursite.com;

    location /.well-known/acme-challenge/ {
        alias /var/www/challenges/;
        try_files $uri =404;
    }

    ...the rest of your config
}
```

And finally use acme-tiny to get our signed certificate
```
apt install acme-tiny
acme_tiny --account-key ./account.key --csr ./domain.csr --acme-dir /var/www/challenges/ > ./signed_chain.crt
```

Tada! you should have a file called `signed_chain.crt` which contains
your cert, and the file `domain.key` which you generated at the
beginning is your secret key for the oracle.

## Configuration

When you have a TLS cert and key, you can start configuring the
oracle. A full configuration file for the oracle looks as follows:

```
[server]
# the IP address the server is listening on
#address="127.0.0.1"

# the port on which the server is listening, use 443 if available, so that
# the oracle can be accessed from behind tight firewalls
#port=2355

# ssl key - no default must be specified
ssl_key="server.der"

# ssl cert - no default must be specified
ssl_cert="cert.pem"

# tcp connection timeouts, increase in case you have bad networks, with the
# caveat that this might lead to easier resource exhaustion - blocking all
# workers.
#timeout=3

# how many worker processes can run in parallel
# max_kids=5

# the root directory where all data is stored
#datadir= "/var/lib/sphinx"

# whether to produce some output on the console
#verbose=false

# decay ratelimit after rl_decay seconds
#rl_decay= 1800

# increase hardness after rl_threshold attempts if not decaying
#rl_threshold= 1

# when checking freshness of puzzle solution, allow this extra
# gracetime in addition to the hardness max solution time
#rl_gracetime=10
```

You need to set the `address` to whatever IP address you want the
oracle to be listening on. And you should set the `port` if possible
to 443, that will enable you to have always access to the oracle when
you are on the go, since other ports might very well be firewalled,
but port 443 is very-very rarely. You also need to set the `ssl_key`
to the file `domain.key` , and the `ssl_cert` to the file
`signed_chain.crt` both from the previous section "getting a tls cert..."

The rest of the config settings you don't have to touch. When done,
simply run `oracle`, this will start the server in the foreground.

Use whatever your distro provides to daemonize and log the output of
servers to have the server automatically started at reboot.

Congratulations! Now invite your friends (and enemies!) to use your
instance :) You might also want to setup the whole thing as a tor
hidden service, so you can protect the privacy of your users even
better, but how to do so is left as an exercise to the dear reader.


[1] The only thing they can learn is the frequency how often you
interact with a certain password, and which passwords belong to the
same user and host, for example if you have an admin and a
non-privileged account at the same host the oracle user could find out
that these two are related. Also whoever is hosting the oracle can
mount a denial-of-service against you by not responding or corrupting
their answers. But your passwords would be safe, nevertheless. Even if
their "database" leaks to the internet, or criminals.