aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/blog/2024-12-03-2fa/2fa.md116
1 files changed, 116 insertions, 0 deletions
diff --git a/src/blog/2024-12-03-2fa/2fa.md b/src/blog/2024-12-03-2fa/2fa.md
new file mode 100644
index 0000000..66f3661
--- /dev/null
+++ b/src/blog/2024-12-03-2fa/2fa.md
@@ -0,0 +1,116 @@
1# 2-factor authentication without a smartphone
2
3I am mildly annoyed by the not-so-recent trend of every single website
4and service forcing me into using a phone for 2-factor authentication. I
5mean, I get it is very important for security reasons, but now every
6time I try to log into some website I am forced to get up and pick
7up my phone, which is usually lying on the other side of the room. You
8can't just walk into a website nowadays.
9
10Another reason I don't like this is that a mobile phone can easily be
11lost, stolen or out of battery. I don't want to rely on it to get access
12to imortant services. As a partial workaround I always use SMS 2fa,
13which is quite insecure, but at least I just need to plug my SIM card
14into another phone if for some reason I can't use my device.
15
16And of course there are ways of using an authenticator app and sync your
17keys via some external cloud service. But I don't want to be dependent
18on external cloud services.
19
20But there is nothing special about my smartphone: there is
21no reason I should not be able to just use my laptop, or
22any other device, as a 2fa device. In fact, most services use
23[TOTP](https://en.wikipedia.org/wiki/Time-based_one-time_password),
24which is an open protocol. Yesterday I decided to figure out how
25this works, so that I would not need to detach my but from my chair
26ever again!
27
28## How TOTP works, as far as I understood
29
30Pairing an authenticator app with a website requiring 2fa is usually
31done by scanning a QR code. This QR code is not magic, it just contains a
32string that is going to be your *secret key* for this website. Then, every
33time you need to login, you get some code from your authentication app.
34The code is generated by the app by applying cryptography (which *is*
35magic, by the way) to your secret key, and it is only valid for a limited
36time span, usually 30 seconds. When you give this code to the website,
37they know it must have been generated from your secret key because of
38cryptographic magic.
39
40So in principle 2fa is just a way of forcing everyone to use a second
41properly-stored password, with your authenticator app as a password
42manager. Actually the password is stored on your device and never shared
43after the initial setup, so it is even safer than that. But it
44still falls short from a proper
45[public-key](https://en.wikipedia.org/wiki/Public-key_cryptography)
46protocol, because the secret key is shared publicly at the time of the
47initial setup.
48
49## Setting up 2fa with oathtool
50
51To generate TOTP codes I use
52[oathtool](https://man.archlinux.org/man/extra/oath-toolkit/oathtool.1.en),
53a command-line utility available in most linux distros and other
54operating systems. Keep in mind I have only used it on Void Linux
55for now, though.
56
57To generate a TOTP code from a `SECRET_KEY` you can simply use the
58following command:
59
60```
61$ athtool -b --totp "SECRET_KEY"
62```
63
64And that's it. However, you should not write you secret key in plain text
65like this: instead you should keep it encrypted and decrypt it just
66when you need it to generate a code. I do this by using my simple
67[2fa](https://git.tronto.net/scripts/file/2fa.html)
68script, which is based on my
69[secret](https://git.tronto.net/scripts/file/secret.html)
70tool that encrypts and decrypts stuff using openssl and a master
71password - which is obviously
72[correcthorsebatterystaple](https://xkcd.com/936/).
73
74## Troubleshooting
75
76The command as I wrote it above does not work for my laptop. The reason
77is that for reasons unknown my laptop's clock is steadily drifting
78- it is now 2 minutes and 4 seconds behind - and TOTP codes are only
79valid for a 30-seconds timespan. Luckily, you can trick oathtool
80into thinking we are in the future with the `--now` option:
81
82```
83$ athtool -b --totp "SECRET_KEY" --now=11:23
84```
85
86It's good to keep this in mind even when using other authentication
87systems. If it does not work, check the time!
88
89## Is this actually safe?
90
91This is a legit question, because by getting rid of your second device
92kinda defeats the purpose of 2-factor authentication. The principle
93of multi-factor authentication is that you should use at least two
94factors among:
95
961. Something you know (e.g. a password)
972. Something you have (e.g. a device)
983. Something you are (e.g. a fingerprint)
99
100And with the system I explained, I am pretty much only using passwords.
101However, I would argue that I am still using two factors:
102
1031. Something I have: my laptop, which sloppily stores some
104 passwords in my browser's "saved passwords" (this does not
105 count as "something I know", because anybody who has access
106 to the device can just use my browser's password auto-fill
107 functionality without knowing what these passwords are).
1082. Something I know: the master password (which is not stored
109 anywhere) that protects the encrypted keys stored on my laptop.
110
111If you are still not convinced and think using a smartphone for
112security is safer, let me ask you this: do you ever login
113in one of these services from your smarpthone, using the same
114smartphone as a second factor? Then it's the same thing as I do.
115You are probably just using a PIN code or a fingerprint instead
116of my master password.

Generated with cgit - Back to sebastiano.tronto.net