lighttpd
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
| Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
| lighttpd [2016-09-15 08:09:06] – [nur LTS 1.2] manfred | lighttpd [2017-01-06 14:48:23] (aktuell) – [MySQL-Auth mit LighttpD] manfred | ||
|---|---|---|---|
| Zeile 1: | Zeile 1: | ||
| + | ====== Lighttpd ====== | ||
| + | |||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | |||
| + | |||
| + | ===== Sicherheit ===== | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | |||
| + | ==== HTTP Strict Transport Security (HSTS) ==== | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | To enable HTTP Strict Transport Security in lighttpd use the following config: | ||
| + | server.modules += ( " | ||
| + | $HTTP[" | ||
| + | setenv.add-response-header | ||
| + | } | ||
| + | |||
| + | The max-age value is in seconds. Use 31536000 for 12 months or 63072000 for 24 months. | ||
| + | |||
| + | Adding includeSubdomains means that subdomains of the main domain should also be accessed using SSL. | ||
| + | |||
| + | |||
| + | ==== Content Security Policy (CSP) ==== | ||
| + | |||
| + | * [[http:// | ||
| + | |||
| + | Dieses Beispiel führt ein Upgrade der '' | ||
| + | server.modules += ( " | ||
| + | $HTTP[" | ||
| + | setenv.add-response-header | ||
| + | " | ||
| + | } | ||
| + | |||
| + | ==== nur LTS 1.2 ==== | ||
| + | |||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | |||
| + | SSL-Cipher auflisten: | ||
| + | > openssl ciphers -V | ||
| + | > openssl ciphers | tr -s ':' | ||
| + | > openssl ciphers -V ' | ||
| + | > openssl ciphers -V ' | ||
| + | > openssl ciphers -V ' | ||
| + | > openssl ciphers -V ' | ||
| + | |||
| + | > vi / | ||
| + | ... | ||
| + | ## | ||
| + | ## Documentation: | ||
| + | ## | ||
| + | #### SSL engine | ||
| + | $SERVER[" | ||
| + | ssl.engine | ||
| + | ssl.pemfile | ||
| + | ssl.ca-file | ||
| + | ssl.use-sslv2 | ||
| + | ssl.use-sslv3 | ||
| + | ssl.honor-cipher-order | ||
| + | ssl.use-compression | ||
| + | ssl.cipher-list | ||
| + | ssl.disable-client-renegotiation | ||
| + | | ||
| + | $HTTP[" | ||
| + | server.max-keep-alive-requests = 0 | ||
| + | } | ||
| + | } | ||
| + | ... | ||
| + | |||
| + | |||
| + | ===== Datenübertragung ===== | ||
| + | |||
| + | |||
| + | ==== nur GET und POST ==== | ||
| + | |||
| + | viele HTML-Aufruf-Methoden können gefährlich sein, deshalb lassen wir mit diesem Teil nur " | ||
| + | > vi / | ||
| + | ... | ||
| + | $HTTP[" | ||
| + | url.access-deny = ("" | ||
| + | } | ||
| + | ... | ||
| + | |||
| + | Das kann mit diesem SED-Kommando ganz leicht eingestellt werden: | ||
| + | > sed -i ' | ||
| + | |||
| + | |||
| + | ===== Logging ===== | ||
| + | |||
| + | |||
| + | ==== Debug-Level ==== | ||
| + | |||
| + | [[http:// | ||
| + | |||
| + | um Fehler zu finden ist es oft gut, ins Log zu sehen, damit im Log auch genug zu sehen ist, muss **'' | ||
| + | > vi / | ||
| + | ... | ||
| + | debug.log-request-header | ||
| + | | ||
| + | server.errorlog-use-syslog = " | ||
| + | # | ||
| + | | ||
| + | accesslog.format | ||
| + | accesslog.use-syslog | ||
| + | # | ||
| + | ... | ||
| + | |||
| + | |||
| + | ===== MySQL-Auth mit LighttpD ===== | ||
| + | |||
| + | Leider gibt es für LighttpD kein Modul um die Passwortabfrage auf eine DB zu realisieren, | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | __Die Dateien, die Passwörter enthalten, dürfen nicht für die Welt lesbar sein!__ | ||
| + | > chown 33:33 / | ||
| + | > chmod 0640 / | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | hier muß die IP ("'' | ||
| + | <file lighttpd / | ||
| + | # | ||
| + | $HTTP[" | ||
| + | magnet.attract-physical-path-to = ( "/ | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <file lua / | ||
| + | -- vim: set ts=4 sw=4 sts=4 noai noet: | ||
| + | --[[ | ||
| + | |||
| + | MySQL-Auth - IQ | ||
| + | |||
| + | lighttpd-mod-magnet | ||
| + | lua-socket | ||
| + | lua-sql-mysql | ||
| + | |||
| + | *************************** 1. row *************************** | ||
| + | id: 1 | ||
| + | | ||
| + | password: a8e13417253337017fb29cbe1a647bba2d7dca95b232f70f782bd64da49855606d122e5715d6a63754d88d1ea3fe561af26260fedd7b2425044c7e565fa1dfa0 | ||
| + | ]] | ||
| + | |||
| + | --[[ | ||
| + | https:// | ||
| + | |||
| + | Known Problems: | ||
| + | |||
| + | This Script is blocking!!! Lighttpd will hang, if there are MySQL connection problems. | ||
| + | Additionally, | ||
| + | Passwords are stored plain in MySQL - well, easy to fix. Look for MySQL' | ||
| + | ]] | ||
| + | |||
| + | -- nur "/ | ||
| + | if ( string.format(' | ||
| + | |||
| + | -- Force https | ||
| + | if (lighty.env[" | ||
| + | lighty.header[" | ||
| + | return 302 | ||
| + | end | ||
| + | |||
| + | --[[ | ||
| + | Config Variables | ||
| + | ]] | ||
| + | local dbConf = {} | ||
| + | dbConf.database = ' | ||
| + | dbConf.username = ' | ||
| + | dbConf.password = ' | ||
| + | dbConf.hostname = ' | ||
| + | dbConf.port = " | ||
| + | --[[ | ||
| + | dbConf.users_table = " | ||
| + | dbConf.col_user = " | ||
| + | dbConf.col_pass = " | ||
| + | ]] | ||
| + | |||
| + | --[[ | ||
| + | Requires | ||
| + | ]] | ||
| + | |||
| + | -- Debian package: liblua5.1-socket2 | ||
| + | |||
| + | -- required for Base64 De-/ | ||
| + | require(" | ||
| + | |||
| + | -- Debian package: liblua5.1-sql-mysql-2 | ||
| + | |||
| + | -- Lua Mysql Driver | ||
| + | luasql = require(" | ||
| + | |||
| + | --[[ | ||
| + | Function to send HTTP-Auth request | ||
| + | ]] | ||
| + | |||
| + | function doAuth() | ||
| + | lighty.header[" | ||
| + | return 401 | ||
| + | end | ||
| + | |||
| + | --[[ | ||
| + | Function to check Auth Creds against MySQL Database | ||
| + | ]] | ||
| + | local env = assert(luasql.mysql()) | ||
| + | local con = assert(env: | ||
| + | dbConf.database | ||
| + | , | ||
| + | , | ||
| + | , | ||
| + | , | ||
| + | )) | ||
| + | |||
| + | function checkAuthMySQL(user, | ||
| + | local res = con: | ||
| + | SELECT login, password | ||
| + | FROM `dealer_logins` | ||
| + | WHERE `login` = ' | ||
| + | AND `password` = ' | ||
| + | ]], user, pass) | ||
| + | ) | ||
| + | |||
| + | -- Die Tabelle wir in ein Array gespeichert | ||
| + | local row = res:fetch ({}, " | ||
| + | |||
| + | -- print(type(row)) | ||
| + | |||
| + | |||
| + | -- close everything | ||
| + | -- res: | ||
| + | con:close() | ||
| + | -- env:close() | ||
| + | |||
| + | |||
| + | if (not row) then | ||
| + | return false | ||
| + | else | ||
| + | lighty.req_env[' | ||
| + | return true | ||
| + | end | ||
| + | end | ||
| + | |||
| + | |||
| + | -- MAIN | ||
| + | |||
| + | --[[ | ||
| + | Check for Authorization Header | ||
| + | and force Basic Auth if not set. | ||
| + | ]] | ||
| + | |||
| + | if (not lighty.request.Authorization) then | ||
| + | return doAuth() | ||
| + | end | ||
| + | |||
| + | --[[ | ||
| + | Header found: check string for " | ||
| + | - upb = User Password Base64 encoded | ||
| + | ]] | ||
| + | _, _, upb = string.find(lighty.request.Authorization, | ||
| + | up = mime.unb64(upb) -- Base64 Decode | ||
| + | _, _, username, password = string.find(up, | ||
| + | |||
| + | |||
| + | -- ============================================================================= | ||
| + | -- In der DB steht das Passwort nicht im klartext drin, sondern verschlüsselt | ||
| + | -- deshalb muss auch der Passwort-Hash und nicht das Passwort verglichen werden. | ||
| + | -- | ||
| + | -- hier wird aus dem Passwort der Passwort-Hash generiert | ||
| + | -- | ||
| + | -- / | ||
| + | |||
| + | local start = ("/ | ||
| + | datei = assert (io.popen (start)) | ||
| + | pwhash = datei:read (" | ||
| + | |||
| + | -- ============================================================================= | ||
| + | |||
| + | if (not checkAuthMySQL(username, | ||
| + | return doAuth() | ||
| + | end | ||
| + | |||
| + | |||
| + | end | ||
| + | |||
| + | -- return nothing to proceed normal operation | ||
| + | return | ||
| + | </ | ||
| + | |||
| + | Leider gibt es nur für eine SHA256-Verschlüsselung eine native LUA-Umsetzung. | ||
| + | Für SHA512 müssen wir uns eines externen Programmes (in diesem Fall ein PHP-Skript) bedienen. | ||
| + | |||
| + | Der **Salz-hash** aus der Live-Umgebung => '< | ||
| + | <file php / | ||
| + | <?php | ||
| + | $salt = ' | ||
| + | echo hash(' | ||
| + | ?> | ||
| + | </ | ||
