diff options
author | Sebastian Reichel <sre@ring0.de> | 2015-02-13 16:20:36 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2015-02-13 16:20:36 +0100 |
commit | 06c4d13da6267d9c5698bec9521c76e3efdb1efa (patch) | |
tree | 8621b0d2fcc02937888a83c6830bba7a8ed79001 | |
parent | 2493262379dca2f01e07c9c83103240d67218fb3 (diff) | |
download | serial-barcode-scanner-06c4d13da6267d9c5698bec9521c76e3efdb1efa.tar.bz2 |
web: add tls support
-rw-r--r-- | TODO.md | 1 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | src/web/main.vala | 20 | ||||
-rw-r--r-- | src/web/web.vala | 14 |
4 files changed, 30 insertions, 7 deletions
@@ -52,7 +52,6 @@ * Support to generate a sorted best before dates list * Implement a more fine-grained authentication system * OpenID based login - * SSL support #### LOG * implement log daemon @@ -24,7 +24,7 @@ check_dependencies() { check_pkg_version libarchive 3.0 "force" check_prg_version libesmtp 0.1 $ESMTP_VERSION "force" check_pkg_version librsvg-2.0 2.36 "force" - check_pkg_version libsoup-2.4 2.38 "force" + check_pkg_version libsoup-2.4 2.48 "force" check_pkg_version pangocairo 1.32 "force" check_pkg_version sqlite3 3.7 "force" check_pkg_version libssl 1.0.0 "force" diff --git a/src/web/main.vala b/src/web/main.vala index b5fdde3..dd354c5 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -20,19 +20,37 @@ public Config cfg; string templatedir; public static int main(string[] args) { + TlsCertificate? cert = null; + string certificate; + string privatekey; + uint port; + try { db = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); pgp = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); cfg = Bus.get_proxy_sync(BusType.SESSION, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); templatedir = cfg.get_string("WEB", "filepath"); + port = cfg.get_integer("WEB", "port"); + certificate = cfg.get_string("WEB", "cert"); + privatekey = cfg.get_string("WEB", "key"); } catch(IOError e) { error("IOError: %s\n", e.message); } catch(KeyFileError e) { error("KeyFileError: %s\n", e.message); } + stdout.printf("Web Server Port: %u\n", port); + stdout.printf("TLS certificate: %s\n", certificate); + stdout.printf("TLS private key: %s\n", privatekey); + /* attach WebServer to MainLoop */ - new WebServer(); + try { + if(certificate != "" && privatekey != "") + cert = new TlsCertificate.from_files(certificate, privatekey); + new WebServer(port, cert); + } catch(Error e) { + error("Could not start Webserver: %s\n", e.message); + } /* start MainLoop */ new MainLoop().run(); diff --git a/src/web/web.vala b/src/web/web.vala index 1ff8acf..aa00586 100644 --- a/src/web/web.vala +++ b/src/web/web.vala @@ -987,8 +987,16 @@ public class WebServer { } } - public WebServer(int port = 8080) { - srv = new Soup.Server(Soup.SERVER_PORT, port); + public WebServer(uint port = 8080, TlsCertificate? cert = null) throws Error { + srv = new Soup.Server("tls-certificate", cert); + Soup.ServerListenOptions options = 0; + + if(cert != null) + options |= Soup.ServerListenOptions.HTTPS; + + if(!srv.listen_all(port, options)) { + throw new GLib.IOError.FAILED("Could not setup webserver!"); + } /* index */ srv.add_handler("/", handler_default); @@ -1022,7 +1030,5 @@ public class WebServer { srv.add_handler("/users", handler_users); srv.add_handler("/users/import", handler_user_import); srv.add_handler("/users/import-pgp", handler_user_pgp_import); - - srv.run_async(); } } |