Changeset eb4ac2ff2b9e0b43b1aa254fde4f3106f8d5386c
- Timestamp:
- 07/10/12 17:24:51 (11 months ago)
- git-parent:
[aa2a26950f252650791db1d942c440543fdd3992], [353258a7cab6bd5c7069ab335642da33a6c67a2a]
- Files:
-
- docs/config/modules/noit.module.imap.xml (modified) (1 diff)
- docs/config/modules/noit.module.tcp.xml (modified) (1 diff)
- src/modules-lua/noit/extras.lua (modified) (2 diffs)
- src/modules-lua/noit/module/http.lua (modified) (2 diffs)
- src/modules-lua/noit/module/imap.lua (modified) (4 diffs)
- src/modules-lua/noit/module/tcp.lua (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
docs/config/modules/noit.module.imap.xml
r23dea7e r353258a 282 282 </variablelist> 283 283 <para>A list of ciphers to be used in the SSL protocol (for SSL checks).</para> 284 </listitem> 285 </varlistentry> 286 </variablelist> 287 <variablelist> 288 <varlistentry> 289 <term>header_Host</term> 290 <listitem> 291 <variablelist> 292 <varlistentry> 293 <term>required</term> 294 <listitem> 295 <para>optional</para> 296 </listitem> 297 </varlistentry> 298 <varlistentry> 299 <term>allowed</term> 300 <listitem> 301 <para>.+</para> 302 </listitem> 303 </varlistentry> 304 </variablelist> 305 <para>The host header to validate against the SSL certificate (for SSL checks).</para> 284 306 </listitem> 285 307 </varlistentry> docs/config/modules/noit.module.tcp.xml
r51773e8 r353258a 226 226 </variablelist> 227 227 <para>A list of ciphers to be used in the SSL protocol (for SSL checks).</para> 228 </listitem> 229 </varlistentry> 230 </variablelist> 231 <variablelist> 232 <varlistentry> 233 <term>header_Host</term> 234 <listitem> 235 <variablelist> 236 <varlistentry> 237 <term>required</term> 238 <listitem> 239 <para>optional</para> 240 </listitem> 241 </varlistentry> 242 <varlistentry> 243 <term>allowed</term> 244 <listitem> 245 <para>.+</para> 246 </listitem> 247 </varlistentry> 248 </variablelist> 249 <para>The host header to validate against the SSL certificate (for SSL checks).</para> 228 250 </listitem> 229 251 </varlistentry> src/modules-lua/noit/extras.lua
rb4aa23f r353258a 29 29 -- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 30 31 local ipairs = ipairs 31 32 local string = require("string") 32 33 local table = require("table") … … 68 69 end 69 70 71 function check_host_header_against_certificate(host_header, cert_subject, san_list) 72 local san_list_check = function (array, value) 73 for i, line in ipairs(array) do 74 if line == value then 75 return true 76 else 77 line = string.gsub(line, '%.', "%%%.") 78 line = string.gsub(line, "%*", "[^\.]*") 79 local match = string.match(value, line) 80 if match == value then 81 return true 82 end 83 end 84 end 85 return false 86 end 87 -- First, check for SAN values if they exist - if they do, check for a match 88 local san_array = { } 89 if san_list ~= nil then 90 san_array = split(san_list, ", ") 91 end 92 if san_list_check(san_array, host_header) then 93 -- The host header was in the SAN list, so we're done 94 return nil 95 end 96 -- Next, pull out the CN value 97 local cn = string.sub(cert_subject, string.find(cert_subject, 'CN=[^/\n]*')) 98 if cn == nil or cn == '' then 99 -- no common name given, give an error 100 return 'CN not found in certificate' 101 end 102 cn = string.sub(cn, 4) 103 if cn == host_header then 104 -- CN and host_header match exactly, so no error 105 return nil 106 end 107 cn = string.gsub(cn, '%.', "%%%.") 108 cn = string.gsub(cn, "%*", "[^\.]*") 109 local match = string.match(host_header, cn) 110 if match == host_header then 111 return nil 112 end 113 return 'host header does not match CN or SANs in certificate' 114 end src/modules-lua/noit/module/http.lua
rf800a3f r353258a 294 294 toReturn = string.gsub(toReturn, "%./", "") 295 295 return toReturn 296 end297 298 function san_list_check(array, value)299 for i, line in ipairs(array) do300 if line == value then301 return true302 else303 line = string.gsub(line, '%.', "%%%.")304 line = string.gsub(line, "%*", "[^\.]*")305 local match = string.match(value, line)306 if match == value then307 return true308 end309 end310 end311 return false312 end313 314 function check_host_header_against_certificate(host_header, cert_subject, san_list)315 -- First, check for SAN values if they exist - if they do, check for a match316 local san_array = { }317 if san_list ~= nil then318 san_array = noit.extras.split(san_list, ", ")319 end320 if san_list_check(san_array, host_header) then321 -- The host header was in the SAN list, so we're done322 return nil323 end324 -- Next, pull out the CN value325 local cn = string.sub(cert_subject, string.find(cert_subject, 'CN=[^/\n]*'))326 if cn == nil or cn == '' then327 -- no common name given, give an error328 return 'CN not found in certificate'329 end330 cn = string.sub(cn, 4)331 if cn == host_header then332 -- CN and host_header match exactly, so no error333 return nil334 end335 cn = string.gsub(cn, '%.', "%%%.")336 cn = string.gsub(cn, "%*", "[^\.]*")337 local match = string.match(host_header, cn)338 if match == host_header then339 return nil340 end341 return 'host header does not match CN or SANs in certificate'342 296 end 343 297 … … 633 587 local ssl_ctx = client:ssl_ctx() 634 588 if ssl_ctx ~= nil then 635 local header_match_error = check_host_header_against_certificate(host_header, ssl_ctx.subject, ssl_ctx.san_list) 589 local header_match_error = nil 590 if host_header ~= '' then 591 header_match_error = noit.extras.check_host_header_against_certificate(host_header, ssl_ctx.subject, ssl_ctx.san_list) 592 end 636 593 if ssl_ctx.error ~= nil then status = status .. ',sslerror' end 637 594 if header_match_error == nil then src/modules-lua/noit/module/imap.lua
r4fae03b r353258a 68 68 required="optional" 69 69 allowed=".+">A list of ciphers to be used in the SSL protocol (for SSL checks).</parameter> 70 <parameter name="header_Host" 71 required="optional" 72 allowed=".+">The host header to validate against the SSL certificate (for SSL checks).</parameter> 70 73 </checkconfig> 71 74 <examples> … … 163 166 local _tok = 0 164 167 local last_msg = 0 168 local host_header = check.config.header_Host or '' 165 169 166 170 if check.target_ip == nil then … … 191 195 end 192 196 197 local ca_chain = 198 noit.conf_get_string("/noit/eventer/config/default_ca_chain") 199 200 if check.config.ca_chain ~= nil and check.config.ca_chain ~= '' then 201 ca_chain = check.config.ca_chain 202 end 203 193 204 if use_ssl == true then 194 205 rv, err = e:ssl_upgrade_socket(check.config.certificate_file, 195 206 check.config.key_file, 196 c heck.config.ca_chain,207 ca_chain, 197 208 check.config.ciphers) 198 209 end … … 212 223 local ssl_ctx = e:ssl_ctx() 213 224 if ssl_ctx ~= nil then 225 local header_match_error = nil 226 if host_header ~= '' then 227 header_match_error = noit.extras.check_host_header_against_certificate(host_header, ssl_ctx.subject, ssl_ctx.san_list) 228 end 214 229 if ssl_ctx.error ~= nil then status = status .. ',sslerror' end 215 check.metric_string("cert_error", ssl_ctx.error) 230 if header_match_error == nil then 231 check.metric_string("cert_error", ssl_ctx.error) 232 elseif ssl_ctx.error == nil then 233 check.metric_string("cert_error", header_match_error) 234 else 235 check.metric_string("cert_error", ssl_ctx.error .. ', ' .. header_match_error) 236 end 216 237 check.metric_string("cert_issuer", ssl_ctx.issuer) 217 238 check.metric_string("cert_subject", ssl_ctx.subject) 239 if ssl_ctx.san_list ~= nil then 240 check.metric_string("cert_subject_alternative_names", ssl_ctx.san_list) 241 end 218 242 check.metric_uint32("cert_start", ssl_ctx.start_time) 219 243 check.metric_uint32("cert_end", ssl_ctx.end_time) src/modules-lua/noit/module/tcp.lua
r91e019b r353258a 64 64 required="optional" 65 65 allowed=".+">A list of ciphers to be used in the SSL protocol (for SSL checks).</parameter> 66 <parameter name="header_Host" 67 required="optional" 68 allowed=".+">The host header to validate against the SSL certificate (for SSL checks).</parameter> 66 69 </checkconfig> 67 70 <examples> … … 128 131 local status = "" 129 132 local use_ssl = false 133 local host_header = check.config.header_Host or '' 130 134 131 135 if check.config.port == nil then … … 147 151 end 148 152 153 local ca_chain = 154 noit.conf_get_string("/noit/eventer/config/default_ca_chain") 155 156 if check.config.ca_chain ~= nil and check.config.ca_chain ~= '' then 157 ca_chain = check.config.ca_chain 158 end 159 149 160 if use_ssl == true then 150 161 rv, err = e:ssl_upgrade_socket(check.config.certificate_file, 151 162 check.config.key_file, 152 c heck.config.ca_chain,163 ca_chain, 153 164 check.config.ciphers) 154 165 end … … 168 179 local ssl_ctx = e:ssl_ctx() 169 180 if ssl_ctx ~= nil then 181 local header_match_error = nil 182 if host_header ~= '' then 183 header_match_error = noit.extras.check_host_header_against_certificate(host_header, ssl_ctx.subject, ssl_ctx.san_list) 184 end 170 185 if ssl_ctx.error ~= nil then status = status .. ',sslerror' end 171 check.metric_string("cert_error", ssl_ctx.error) 186 if header_match_error == nil then 187 check.metric_string("cert_error", ssl_ctx.error) 188 elseif ssl_ctx.error == nil then 189 check.metric_string("cert_error", header_match_error) 190 else 191 check.metric_string("cert_error", ssl_ctx.error .. ', ' .. header_match_error) 192 end 172 193 check.metric_string("cert_issuer", ssl_ctx.issuer) 173 194 check.metric_string("cert_subject", ssl_ctx.subject) 195 if ssl_ctx.san_list ~= nil then 196 check.metric_string("cert_subject_alternative_names", ssl_ctx.san_list) 197 end 174 198 check.metric_uint32("cert_start", ssl_ctx.start_time) 175 199 check.metric_uint32("cert_end", ssl_ctx.end_time)
