5 Commits
v2 ... v3.0.0

Author SHA1 Message Date
cb05047fed Script-Bugfixes, init.d 2022-04-15 18:49:40 +02:00
f0baee2d91 Have more information about the conf file 2022-04-15 18:24:03 +02:00
3eed323364 Debian-Packaging 2022-04-15 18:17:58 +02:00
ee44662cd3 I deleted too much!11!! 2022-04-11 19:29:50 +02:00
aacb9c9669 Coding-Style; First floor and basement are now the same with the
authentication user
2022-04-11 18:47:42 +02:00
13 changed files with 135 additions and 108 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
foodoord*.deb

View File

@ -1,32 +1,29 @@
#foodoord # foodoord
Das Schließsystem läuft auf einem RaspberryPi mit der Erweiterungsplatine "PiFaceDigitalIO". Das Schließsystem läuft auf einem RaspberryPi mit der Erweiterungsplatine "PiFaceDigitalIO".
##Software##
###Installation### ## Konfiguration
<code>apt-get install python-pifacedigitalio </code>
Um das Paket zu installieren muss die */etc/apt/sources.list* angepasst werden. Falls `/etc/foodoord.conf` nicht vorhanden ist:
<code>deb http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi</code> * `mv /etc/foodoord.conf_example /etc/foodoord.conf`
<code>deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi</code> 1. Trage dort die API-Config für den Türstatus ein.
2. Sind wir oben oder unten? Diese Information in `where` eintragen. Also bspw. `where = oben`.
Wer apt-get benutzt, kann den Raspbian Pubkey zum keyring hinzufügen.
<code>wget http://archive.raspbian.org/raspbian.public.key -O - | sudo apt-key add -</code>
###Dateiliste### ## Software
### Dateiliste
Der Deamon besteht aus folgenden Dateien. Der Deamon besteht aus folgenden Dateien.
* foodoor * foodoor
* foodoord * foodoord
* foodoord.conf * foodoord.conf
* foodoord_initd * foodoord_initd
* foodoor-ssh-wrapper
* foodoor-update-keydb * foodoor-update-keydb
Zusätzlich sollte für das git-repo eine Config angelegt werden: Zusätzlich sollte für das git-repo eine Config angelegt werden:
@ -42,30 +39,37 @@ Host git.chaospott.de
Das IdentityFile ist der Deploy-SSH-Key, der im [Repo](https://git.chaospott.de/Chaospott/foodoor-keys) hinterlegt ist. Das IdentityFile ist der Deploy-SSH-Key, der im [Repo](https://git.chaospott.de/Chaospott/foodoor-keys) hinterlegt ist.
##Schüssel ## Schüssel
###Schlüsselupdate ### Schlüsselupdate
<pre><code>foodoor-update-keydb
</code></pre> `foodoor-update-keydb`
Aktualisiert die die Schlüssel auf der Tür und baut die *Authorized_Keys* für die User *open* und *close*. Keys die nicht dem OpenSSH-Format mit 4096 bit entsprechen, werden ignoriert. Wenn das Script von Hand aufgerufen wird, werden die betroffenen Keys angezeigt. Über einen Cronjob werden die Keys alle **5 Min aktualisiert**. Aktualisiert die die Schlüssel auf der Tür und baut die *Authorized_Keys* für die User *open* und *close*. Keys die nicht dem OpenSSH-Format mit 4096 bit entsprechen, werden ignoriert. Wenn das Script von Hand aufgerufen wird, werden die betroffenen Keys angezeigt. Über einen Cronjob werden die Keys alle **5 Min aktualisiert**.
###Schlüsselformate### ### Schlüsselformate
Der foodoord akzeptiert nur Pub-Keys im *OpenSSH2-Format*. Keys lassen sich unter anderem mit OpenSSH oder PuTTygen erzeugen. Der foodoord akzeptiert nur Pub-Keys im *OpenSSH2-Format*. Keys lassen sich unter anderem mit OpenSSH oder PuTTygen erzeugen.
###OpenSSH#### ### OpenSSH
#### Keys generieren
* Mit `ssh-keygen -b 4096` lassen sich Keys generieren.
* `ssh-add $Pfad_zum_Key` fügt den Key dem ssh-Agent hinzu. Die Option `ssh-add -l` zeigt geladene Keys an.
* `ssh-kegen -l -f $Pfad_zum_Key ` gibt den Fingerprint und andere Informationen zurück.
####Keys generieren####
* Mit <code>ssh-keygen -b 4096 </code> lassen sich Keys generieren.
* <code>ssh-add $Pfad_zum_Key</code> fügt den Key dem ssh-Agent hinzu. Die Option <code>ssh-add -l</code> zeigt geladene Keys an.
* <code>ssh-kegen -l -f $Pfad_zum_Key </code> gibt den Fingerprint und andere Informationen zurück.
####Keys konvertieren(PuTTy>OpenSSH):#### ####Keys konvertieren(PuTTy>OpenSSH):####
* <code>ssh-keygen -i $Pfad_zum_Key > $Pfad_neuer_Pfad.pub</code> liest ssh2-kompatible Keys(RFC 4716) ein und speichert diese im OpenSSH-Format.
* `ssh-keygen -i $Pfad_zum_Key > $Pfad_neuer_Pfad.pub<` liest ssh2-kompatible Keys(RFC 4716) ein und speichert diese im OpenSSH-Format.
###PuTTy### ###PuTTy###
Da die Tür nur Keys im OpenSSH-Format verträgt, dürfen auch mit Putty nur OpenSSH-Keys genutzt werden. Da die Tür nur Keys im OpenSSH-Format verträgt, dürfen auch mit Putty nur OpenSSH-Keys genutzt werden.
###Keys generieren (OpenSSH-Format mit PuttyGen):### ###Keys generieren (OpenSSH-Format mit PuttyGen):###
1. PuTTYgen öffnen 1. PuTTYgen öffnen
2. Unten "Number of Bits in a generated Key:" 4096 eintippen 2. Unten "Number of Bits in a generated Key:" 4096 eintippen
3. "Generate" klicken um Key zu generieren 3. "Generate" klicken um Key zu generieren
@ -74,21 +78,28 @@ Da die Tür nur Keys im OpenSSH-Format verträgt, dürfen auch mit Putty nur Ope
Es ist zu beachten, dass Putty den PrivateKey im Putty-Format benötigt! Das heißt, falls der generierte Key vor dem Export nicht gespeichert wurde, muss der private Key noch konvertiert werden, siehe nächster Punkt! Es ist zu beachten, dass Putty den PrivateKey im Putty-Format benötigt! Das heißt, falls der generierte Key vor dem Export nicht gespeichert wurde, muss der private Key noch konvertiert werden, siehe nächster Punkt!
###Keys konvertieren(OpenSSH>PuTTy):### ###Keys konvertieren(OpenSSH>PuTTy):###
1. PuTTYgen öffnen 1. PuTTYgen öffnen
2. "Load" drücken 2. "Load" drücken
3. OpenSSH-Key auswählen 3. OpenSSH-Key auswählen
4. "Save Private-Key" drücken 4. "Save Private-Key" drücken
5. Speichern 5. Speichern
##Hardware ##Hardware
### Input: ### Input:
* ssh-login * ssh-login
* Klingel * Klingel
* Statustaster * Statustaster
### Output: ### Output:
* Status LEDs * Status LEDs
* Summer * Summer
* Keymatic * Keymatic

2
build-package Executable file
View File

@ -0,0 +1,2 @@
#!/bin/bash
dpkg-deb --root-owner-group -b debian foodoord_3.0.0_all.deb

5
debian/DEBIAN/control vendored Normal file
View File

@ -0,0 +1,5 @@
Package: foodoord
Version: 3.0
Maintainer: Bandie <bandie@chaospott.de>
Architecture: all
Description: Control the doors of the club, ja!

22
debian/DEBIAN/postinst vendored Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
set -x
echo "Creating group and users.."
groupadd foodoor
useradd -M -d /var/lib/foodoor/close -G foodoor -s /bin/sh close
useradd -M -d /var/lib/foodoor/open -G foodoor -s /bin/sh open
useradd -M -d /var/lib/foodoor/door -G foodoor -s /bin/sh door
echo "Chown homes"
for u in close open door; do
groupadd ${u}
chown ${u}:${u} /var/lib/foodoor/${u}
done
echo "Create /state"
touch /state
chown root:foodoor /state
chmod 664 /state
systemctl daemon-reload
systemctl enable foodoord
systemctl restart foodoord

1
debian/etc/cron.d/foodoord vendored Normal file
View File

@ -0,0 +1 @@
*/5 * * * * root [ -x /usr/sbin/foodoor-update-keydb ] && /usr/sbin/foodoor-update-keydb >/dev/null 2>&1

View File

@ -2,3 +2,7 @@
status_url = status_url =
key = key =
secret = secret =
[foodoord]
# oben or unten
where=

View File

@ -16,7 +16,8 @@
# PATH should only include /usr/* if it runs after the mountnfs.sh script # PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="foodoor daemon" DESC="foodoor daemon"
NAME=foodoord WHERE=$(cat /etc/foodoord.conf | grep 'where' | awk -F '=' '{ print $2 }' | tr -d ' ')
NAME=foodoord_${WHERE}
DAEMON=/usr/sbin/$NAME DAEMON=/usr/sbin/$NAME
#DAEMON_ARGS="--options args" #DAEMON_ARGS="--options args"
PIDFILE=/var/run/$NAME.pid PIDFILE=/var/run/$NAME.pid

View File

63
debian/usr/sbin/foodoor-update-keydb vendored Executable file
View File

@ -0,0 +1,63 @@
#!/bin/bash
set -e
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
dest=/var/run/foodoor-keys
temp_outfile="$dest.tmp"
if [ ! -e "${dest}/.git/config" ]
then
#echo "Repo does not exist, trying to clone..."
( cd /var/run && git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "${dest}" )
else
#echo "Repo exists, updating..."
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
fi
rm -f ${temp_outfile}
find "${dest}/keys" -name '*.pub' | sort | \
while read keyfile
do
ssh-keygen -l -f ${keyfile} &> /dev/null
if [ $? -eq 0 ]; then
valid=false
keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information
crypto=$(echo "${keyinfo}" | cut -d" " -f4) # Looks like "(RSA)" or "(ED25519)"
key_length=$(echo "${keyinfo}" | cut -d" " -f1)
if [ "${crypto}" == "(RSA)" ]; then
if [ ${key_length} -lt 4096 ]; then
echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2
continue
else
valid=true
fi
elif [ "${crypto}" == "(ED25519)" ]; then
valid=true
fi
if [ "$valid" = true ]; then
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile})" >> ${temp_outfile}
fi
fi
done
for appendix in open close door
do
action="$appendix"
if [ "$appendix" = "door" ]; then
action=""
fi
export action
outfile="${dest}/authorized_keys.${appendix}"
cat ${temp_outfile} |envsubst > ${outfile}
# Oben und unten
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
done

View File

@ -1,83 +0,0 @@
#!/bin/bash
set -e
export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
dest=/var/run/foodoor-keys
temp_outfile="$dest.tmp"
if [ ! -e "${dest}/.git/config" ]
then
#echo "Repo does not exist, trying to clone..."
( cd /var/run && git clone --quiet --single-branch --depth=1 ssh://git.chaospott.de/Keyverwaltung/foodoor-keys.git "${dest}" )
else
#echo "Repo exists, updating..."
( cd "${dest}" && git fetch --quiet && git merge --quiet origin/master master )
fi
rm -f ${temp_outfile}
find "${dest}/keys" -name '*.pub' | sort | \
while read keyfile
do
ssh-keygen -l -f ${keyfile} &> /dev/null
if [ $? -eq 0 ]; then
valid=false
keyinfo=$(ssh-keygen -l -f ${keyfile}) # The whole key information
crypto=$(echo "${keyinfo}" | cut -d" " -f4) # Looks like "(RSA)" or "(ED25519)"
key_length=$(echo "${keyinfo}" | cut -d" " -f1)
if [ "${crypto}" == "(RSA)" ]; then
if [ ${key_length} -lt 4096 ]; then
echo "Key size of key ${keyfile} not equal to 4096. Not adding it to key database." >&2
continue
else
valid=true
fi
elif [ "${crypto}" == "(ED25519)" ]; then
valid=true
fi
if [ "$valid" = true ]; then
echo "command=\"/usr/sbin/foodoor \$action \",no-port-forwarding,no-X11-forwarding,no-agent-forwarding $(cat ${keyfile})" >> ${temp_outfile}
fi
fi
done
for appendix in open close door
do
action="$appendix"
if [ "$action" = "door" ]
then
action=""
fi
export action
outfile="${dest}/authorized_keys.${appendix}"
cat ${temp_outfile} |envsubst > ${outfile}
# Oben
if [ "$(hostname)" = "foodoor" ]; then
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
fi
# Unten
if [ "$(hostname)" = "kellertuer" ]; then
if [ "${action}" = "open" ]; then
owner="unlock"
elif [ "${action}" = "close" ]; then
owner="lock"
fi
install -d -o ${owner} -g nogroup -m 0700 /var/lib/foodoor/${action}/.ssh
install -b -S .last -o ${owner} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${action}/.ssh/authorized_keys
if [ "${appendix}" = "door" ]; then
install -d -o ${appendix} -g nogroup -m 0700 /var/lib/foodoor/${appendix}/.ssh
install -b -S .last -o ${appendix} -g nogroup -m 0600 ${outfile} /var/lib/foodoor/${appendix}/.ssh/authorized_keys
fi
fi
done