Installazione di PrivacyIDEA in Debian per gestione Token TOTP
PrivacyIDEA è un'applicativo web in Python per gestire i token per la two factor authentication.
I token possono essere utilizzati con l'applicazione per smartphone Google Authenticator installabile dal Google Play Store oppure da Apple App Store
L'applicativo web permette di generare dei token, poi configurabili sull'applicativo smartphone.
In questo documento affronteremo
- Teoria dei token TOTP
- Installazione di PrivacyIDEA
- Creazione di un Token
- Verifica del funzionamento di un token su Android
Teoria dei token TOTP
Google utilizza i token TOTP con timeframe di 30 secondi e chiavi base32 con algoritmo sha1 e lunghezza del codice token di 6 caratteri
Generare e validare dei token TOTP è fattibile anche da commandline tramite il tool
Dato che TOTP si baa su intervalli temporale, è cruciale che il clock di tutti i dispositivi utilizati sia sincronizzato, quindi installare e configurare innazitutto sul proprio server ntp:
sudo apt-get install ntp ntpdate
- Installiamo il tool di test
sudo apt-get install oathtool
- Utilizziamo la chiave (seed) in Base32 (ad esempio questa pagina permette di generare sia chiave che qrcode)
mjne sdil qofw zhc3 vork lyd2 rfz7 73bp
- La chiave seed è tutto ciò che serve per replicare il token, è come la chiave privata di ssh, e pertanto va tenuta SEGRETA.
- L'url corrispondente a questa chiave per il QRCODE è
otpauth://totp/Example:alice@google.com?secret=mjnesdilqofwzhc3vorklyd2rfz773bp&issuer=Example
- Il QRCode si può generare qui:
http://dan.hersam.com/tools/gen-qr-code.html
- Per generare un numero di token valido con questa chiave (seed):
oathtool --totp --base32 "mjne sdil qofw zhc3 vork lyd2 rfz7 73bp"
597301
- Per verificarlo entro il tempo di validità tipico di 30 secondi:
oathtool --totp --base32 "mjne sdil qofw zhc3 vork lyd2 rfz7 73bp" 597301
0
- In Google autenticator, fare lo scan del QRCODE, oppure inserire la chiave o inserire il secret, e testare il codice
Riferimenti
- macosx: oathtool totp google 2 factor authentication
- Key Uri Format · google/google-authenticator Wiki
- TOTP Generator
- Speakeasy Demo
- Beginner's Guide to TOTP
- speakeasy
- otp.js by Nicolas Jessel
- Download dynalogin
Installazione di PrivacyIDEA
- Si utilizza Debian Jessie, per Wheezy, vedere lhowto nei riferimenti
- Assicurarsi della sincronizzazione dell'orologio:
sudo apt-get install ntp ntpdate sudo /etc/init.d/ntp restart
- Verificare:
timedatectl status| grep synchronized NTP synchronized: yes
- Verificare offset:
ntpq -p
remote refid st t when poll reach delay offset jitter ============================================================================== mini.blesmrt.ne .INIT. 16 u - 1024 0 0.000 0.000 0.000 vodka.sublink.O .INIT. 16 u - 1024 0 0.000 0.000 0.000 95.141.36.27 .INIT. 16 u - 1024 0 0.000 0.000 0.000 nettuno.ntp.irh .INIT. 16 u - 1024 0 0.000 0.000 0.000
- Abilitare il repository ed installare la chiave gpg:
sudoedit /etc/apt/sources.list.d/privacyidea.list
deb http://ppa.launchpad.net/privacyidea/privacyidea/ubuntu trusty main
sudo gpg --keyserver keyserver.ubuntu.com --recv-keys C24DCF7D
sudo gpg --armor --export C24DCF7D | apt-key add - apt-get update
- Installare il pacchetto (installerà apache2 e mysql come dipendenze, e configurerà il tutto):
apt-get install privacyidea-apache2 phpmyadmin
- Terminata l'installazione, aggiungere lo user di amministrazione. Gli user di amministrazione possono essere gestiti solo da commandline e non da web:
sudo pi-manage admin add administrator
- Per la gestione vedere:
pi-manage admin -h
usage: Create new administrators or modify existing ones.
Create new administrators or modify existing ones.
positional arguments:
{add,list,change,delete}
add Register a new administrator in the database.
list List all administrators.
change Change the email address or the password of an
existing administrator.
delete Delete an existing administrator.
optional arguments:
-h, --help show this help message and exit
- Per cambiare password:
sudo pi-manage admin change -p administrator
- Loggarsi con lo user appena creato via web sud https://servername.example.priv NON creare il REALM di default quando richiesto, lo si farà nello step successivo.
Riferimenti
- 2.3. Debian Packages — privacyIDEA 2.10dev3 documentation
- HowTo: Verify My NTP Working Or Not
- Red Hat Customer Portal
Creazione del primo token
Teoria
- PrivacyIDEA offre una piattaforma per la gestione completa del token: permette di generare un seed, e verificare la validità dei codici generati, mantenendo cifrato il seed stesso alinterno del DB.
- Il seed ed il QRCODE una volta generati non saranno più visualizzabili
- Un token deve avere un PIN che si imposta alla sua creazione
- Un token viene assegnato ad un utente con una password, durante la sua creazione
- Un utente può gestire con la propria password il proprio token, cambiando ad esempio il PIN
Creazione del REALM
- Il REALM è un database di utenti, e può essere creato utilizzando ad esempio gli utenti using locali o un database SQL
- Per semplicità, creiamo il primo REALM utilizzando gli utenti local, che sono definiti in /etc/passwd
- Create a UserIdResolver. The UserIdResolver is the connector to the user source
Go to Config -> Users to create a UserIdResolver. Choose New passwdresolver and Enter the name “myusers”. Save it. You just created your first connection to a user source.
- Create a Realm. User sources are grouped togeather to a so called “realm”
Go to Config -> Realms Enter “realm1” as the new realm name and select the priority 1. Check the resolver “myusers” to be included into this realm. Save it. Go to Users and you will see the users from the /etc/passwd.
Emissione del Token
- Enroll your first token. You may now enroll a new token. In this example we are using the Google Authenticator App, that you need to install on your smartphone.
Go to Tokens -> Enroll Token Enroll a new token -> TOTP Select the username root. When you start typing “r”, “o”... the system will find the user root automatically. Enter a PIN. I entered “test” ... ... and click “Enroll Token”. After enrolling the token you will see a QR code, that you need to scan with the Google Authenticator App. Click on the serial number link at the top of the dialog.
- Test the Token
Now you see the token details. Left to the button “Test Token” you can enter the PIN and the OTP value generated by the Google Authenticator. Click the button “Test Token”. You should see a green “matching 1 tokens”. Congratulations! You just enrolled your first token to a user.
Riferimenti
Personalizzazione dei Token tramite Policy
- È possibile impostare delle policy di default per i token che vengono creati.
- Queste policy possono essere legate a REALM, USER o altro
Policy per cambiare la label dell'issuer nel QRCODE
- Di default un token quando viene importato in Google autenticator, è identificato dall'issuer "PrivacyIDEA" e dal seriale (identificativo) del token
- Se si vuole cambiare l'issuer per tutti i token impostandolo in "ACME TOKEN"
Config->Policy->Create new Policy Policy name=TOKEN_DEFAULTS Scope->Enrollment tokenissuer->ACME TOKEN Create Policy
- Generare un nuovo token, e verrà importato in Google autenticator con il nome "ACME TOKEN"