Comparison

core/portmanager.lua @ 6295:cb12ff49503d

core.portmanager: Simplify and take advantage of new ssl config merging in certmanager
author Kim Alvefur <zash@zash.se>
date Thu, 03 Jul 2014 15:33:11 +0200
parent 6054:7a5ddbaf758d
child 6549:46d7ede2e037
comparison
equal deleted inserted replaced
6294:0033b021038f 6295:cb12ff49503d
70 prosody.events.add_handler("item-removed/net-provider", function (event) 70 prosody.events.add_handler("item-removed/net-provider", function (event)
71 local item = event.item; 71 local item = event.item;
72 unregister_service(item.name, item); 72 unregister_service(item.name, item);
73 end); 73 end);
74 74
75 local function duplicate_ssl_config(ssl_config)
76 local ssl_config = type(ssl_config) == "table" and ssl_config or {};
77
78 local _config = {};
79 for k, v in pairs(ssl_config) do
80 _config[k] = v;
81 end
82 return _config;
83 end
84
85 --- Public API 75 --- Public API
86 76
87 function activate(service_name) 77 function activate(service_name)
88 local service_info = services[service_name][1]; 78 local service_info = services[service_name][1];
89 if not service_info then 79 if not service_info then
125 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>"); 115 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>");
126 else 116 else
127 local err; 117 local err;
128 -- Create SSL context for this service/port 118 -- Create SSL context for this service/port
129 if service_info.encryption == "ssl" then 119 if service_info.encryption == "ssl" then
130 local ssl_config = duplicate_ssl_config((config.get("*", config_prefix.."ssl") and config.get("*", config_prefix.."ssl")[interface]) 120 local global_ssl_config = config.get("*", "ssl") or {};
131 or (config.get("*", config_prefix.."ssl") and config.get("*", config_prefix.."ssl")[port]) 121 local prefix_ssl_config = config.get("*", config_prefix.."ssl") or global_ssl_config;
132 or config.get("*", config_prefix.."ssl") 122 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server",
133 or (config.get("*", "ssl") and config.get("*", "ssl")[interface]) 123 service_info.ssl_config or {},
134 or (config.get("*", "ssl") and config.get("*", "ssl")[port]) 124 prefix_ssl_config[interface],
135 or config.get("*", "ssl")); 125 prefix_ssl_config[port],
136 -- add default entries for, or override ssl configuration 126 prefix_ssl_config,
137 if ssl_config and service_info.ssl_config then 127 global_ssl_config[interface],
138 for key, value in pairs(service_info.ssl_config) do 128 global_ssl_config[port]);
139 if not service_info.ssl_config_override and not ssl_config[key] then
140 ssl_config[key] = value;
141 elseif service_info.ssl_config_override then
142 ssl_config[key] = value;
143 end
144 end
145 end
146
147 ssl, err = certmanager.create_context(service_info.name.." port "..port, "server", ssl_config);
148 if not ssl then 129 if not ssl then
149 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port_number, err) or "unknown error"); 130 log("error", "Error binding encrypted port for %s: %s", service_info.name, error_to_friendly_message(service_name, port_number, err) or "unknown error");
150 end 131 end
151 end 132 end
152 if not err then 133 if not err then