udev servira à détecter le branchement et le débranchement de la clef, ainsi qu'à déclencher une execution automatique
gnupg2 servira à vérifier l'identité de l'utilisateur
mon window manager favoris ext xfce4 donc, c'est lui que j'utiliserais pour l'exemple
commençons :
préparons notre système à la vérification d'identité.
gnupg2
commençons par générer une clef pour la signature
CODE:
gpg2 --gen-key
gpg (GnuPG) 2.0.0; Copyright (C) 2006 Free Software Foundation, Inc.
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions. See the file COPYING for details.
gpg: directory `$HOME/.gnupg' created
gpg: can't open `/usr/share/gnupg/gpg-conf.skel': Aucun fichier ou répertoire de ce type
gpg: keyring `$HOME/.gnupg/secring.gpg' created
gpg: keyring `$HOME/.gnupg/pubring.gpg' created
Please select what kind of key you want:
(1) DSA and Elgamal (default)
(2) DSA (sign only)
(5) RSA (sign only)
Your selection? 2
DSA keypair will have 1024 bits.
Please specify how long the key should be valid.
0 = key does not expire
<n> = key expires in n days
<n>w = key expires in n weeks
<n>m = key expires in n months
<n>y = key expires in n years
Key is valid for? (0) 0
Key does not expire at all
Is this correct? (y/N) Y
You need a user ID to identify your key; the software constructs the user ID
from the Real Name, Comment and Email Address in this form:
"Heinrich Heine (Der Dichter) <heinrichh@duesseldorf.de>"
Real name: MyName
Email address: user@host
Comment:
You selected this USER-ID:
"MyName <user@host>"
Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
You need a Passphrase to protect your secret key.
can't connect server: `ERR 33554701 can't exec `/usr/bin/gpg-agent': Aucun fichier ou répertoire de ce type'
gpg: can't connect to the agent: IPC connect call failed
gpg: problem with the agent: Pas d'agent en cours d'exécution
You don't want a passphrase - this is probably a *bad* idea!
I will do it anyway. You can change your passphrase at any time,
using this program with the option "--edit-key".
We need to generate a lot of random bytes. It is a good idea to perform
some other action (type on the keyboard, move the mouse, utilize the
disks) during the prime generation; this gives the random number
generator a better chance to gain enough entropy.
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key B80A9DCD marked as ultimately trusted
public and secret key created and signed.
gpg: checking the trustdb
gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model
gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u
pub 1024D/B80A9DCD 2007-08-09
Key fingerprint = CD69 DED1 916D 95DF 7E9E 5967 31DA A46D B80A 9DCD
uid MyName <user@host>
Note that this key cannot be used for encryption. You may want to use
the command "--edit-key" to generate a subkey for this purpose.
préparons un fichier signé numériquement et un fichier nous identifiant
CODE:
echo "check me now" | gpg2 --sign > $HOSTNAME-check
whoami > $HOSTNAME-id
Nous allons maintenant partitionner notre clef usb de sorte d'avoir une
partition pricipale en FAT16 (compatibilité windows) et la seconde en
ext2 (pour cela utilisez la solution que vous préférez, par exemple
l'outil gparted)
/etc/fstab
CODE:
/dev/sdc1 /media/cle vfat rw,user,noauto 0 0
/dev/key /media/key_secure ext2 rw,user,noauto 0 0
la clef est presque prête
CODE:
mount /media/key_secure
mkdir /media/key_secure/.auth
suo mv $HOSTNAME-* /media/key_secure/.auth/
umount /media/key_secure
udev
créons un fichier de règles qui nous est propre : /etc/udev/rules.d/z80_local.rules (vérifiez avant que local.rules n'existe pas déjà)
CODE:
KERNEL=="sd?2", DRIVERS=="usb", ACTION=="add", NAME="key", RUN+="/usr/local/bin/auto_connect"
DRIVERS=="usb", ACTION=="remove", RUN+="/usr/local/bin/auto_disconnect"
relançons udev (/etc/init.d/udev restart)
voyons maintenant nos deux scripts:
/usr/local/bin/auto_connect
CODE:
#!/bin/bash
if [ $(cat /etc/default/autoconnect) == "yes" ]
then
if [ ! -f /media/key_secure/.auth/$HOSTNAME-id ]
then
exit
fi
mount /dev/key -t ext2 /media/key_secure
QUI=$(cat /media/key_secure/.auth/$HOSTNAME-id )
su - $QUI -c "gpg2 --verify /media/key_secure/.auth/$HOSTNAME-check"
verify=$?
umount /media/key_secure
if [ ! -e /var/run/autoX ]
then
ldapwhoami -x -D uid=$QUI,ou=Users,dc=chc -w $PW -h desnos.chc
if [ $verify == 0 ]
then
echo "$(date) $QUI bind successfull" >>/var/log/autoconnect.log
export DISPLAY=:2
X $DISPLAY vt8 &
echo $! > /var/run/autoX
xhost +$QUI@$HOSTNAME
su - $QUI -c 'DISPLAY=:2 xfce4-session'
fi
fi
fi
/usr/local/bin/auto_disconnect
CODE:
#!/bin/bash
echo "$(date) usb unplugged" >> /var/log/autoconnect.log
if [ -e /var/run/autoX ]
then
echo "/var/run/autoX exists" >> /var/log/autoconnect.log
if [ ! -e /dev/key ]
then
echo "/dev/key does not exists" >> /var/log/autoconnect.log
echo "$(date) key unplugged" >> /var/log/autoconnect.log
kill -9 $(cat /var/run/autoX)
rm /var/run/autoX
echo "$(date) auto logoff" >> /var/log/autoconnect.log
chvt 1
fi
fi
une petite fonctionnalité supplémentaire : si /etc/default/autoconnect contient yes, le démarrage automatique aura lieu, sinon, rien ne se passe
testons donc
sudo sh -c ' echo -e yes > /etc/default/autoconnect'
branchons la clef, normalement xfce4 se lance
débranchons la clef, normalement la sesion graphique se ferme (assez violement, assurez vous donc d'avoir enregistré vos documents avant de fermer.
pour ne pas entrer en conflit avec un éventuel serveur X opérationnel (DISPLAY :0.0 VT7) nous utilisons le DISPLAY :2.0 et le VT8, lors de la fermeture vous vous retrouvez automatiquement dans le VT1 (première consle texte)
voilà
ceci étant grandement améliorable, tant au niveau sécurité que 'cosmétique', je suis ouvert à toutes remarques et sugestions.