Comparison

core/portmanager.lua @ 5426:1b20095eb230

portmanager: add logic to allow specification of service default values for ssl config and / or overrides.
author Marco Cirillo <maranda@lightwitch.org>
date Thu, 04 Apr 2013 23:36:30 +0000
parent 5399:13454b2b86bf
child 5432:53b16286509a
comparison
equal deleted inserted replaced
5424:7318527c6dea 5426:1b20095eb230
68 prosody.events.add_handler("item-removed/net-provider", function (event) 68 prosody.events.add_handler("item-removed/net-provider", function (event)
69 local item = event.item; 69 local item = event.item;
70 unregister_service(item.name, item); 70 unregister_service(item.name, item);
71 end); 71 end);
72 72
73 local function duplicate_ssl_config(ssl_config)
74 local ssl_config = type(ssl_config) == "table" and ssl_config or {};
75
76 local _config = {};
77 for k, v in pairs(ssl_config) do
78 _config[k] = v;
79 end
80 return _config;
81 end
82
73 --- Public API 83 --- Public API
74 84
75 function activate(service_name) 85 function activate(service_name)
76 local service_info = services[service_name][1]; 86 local service_info = services[service_name][1];
77 if not service_info then 87 if not service_info then
112 log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "<unnamed>", service_name or "<unnamed>"); 122 log("error", "Multiple services configured to listen on the same port ([%s]:%d): %s, %s", interface, port, active_services:search(nil, interface, port)[1][1].service.name or "<unnamed>", service_name or "<unnamed>");
113 else 123 else
114 local err; 124 local err;
115 -- Create SSL context for this service/port 125 -- Create SSL context for this service/port
116 if service_info.encryption == "ssl" then 126 if service_info.encryption == "ssl" then
117 local ssl_config = config.get("*", config_prefix.."ssl"); 127 local ssl_config = duplicate_ssl_config((config.get("*", config_prefix.."ssl") and config.get("*", config_prefix.."ssl")[interface])
118 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config and (ssl_config[port_number] 128 or (config.get("*", config_prefix.."ssl") and config.get("*", config_prefix.."ssl")[port])
119 or (ssl_config.certificate and ssl_config))); 129 or config.get("*", config_prefix.."ssl")
130 or (config.get("*", "ssl") and config.get("*", "ssl")[interface])
131 or (config.get("*", "ssl") and config.get("*", "ssl")[port])
132 or config.get("*", "ssl"));
133 -- add default entries for, or override ssl configuration
134 if ssl_config and service_info.ssl_config then
135 for key, value in pairs(service_info.ssl_config) do
136 if not service_info.ssl_config_override and not ssl_config[key] then
137 ssl_config[key] = value;
138 elseif service_info.ssl_config_override then
139 ssl_config[key] = value;
140 end
141 end
142 end
143
144 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config);
120 if not ssl then 145 if not ssl then
121 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port_number, err) or "unknown error"); 146 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port_number, err) or "unknown error");
122 end 147 end
123 end 148 end
124 if not err then 149 if not err then