@@ -344,9 +344,16 @@ def _choose_vhost_from_list(self, target_name, temp=False):
344344
345345 def included_in_wildcard (self , names , target_name ):
346346 """Helper function to see if alias is covered by wildcard"""
347- wildcards = [domain for domain in names if domain .startswith ("*" )]
347+ target_name = target_name .split ("." )[::- 1 ]
348+ wildcards = [domain .split ("." )[1 :] for domain in names if domain .startswith ("*" )]
348349 for wildcard in wildcards :
349- if wildcard .split ("." )[1 ] == target_name .split ("." )[1 ]:
350+ if len (wildcard ) > len (target_name ):
351+ continue
352+ for idx , segment in enumerate (wildcard [::- 1 ]):
353+ if segment != target_name [idx ]:
354+ break
355+ else :
356+ # https://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
350357 return True
351358 return False
352359
@@ -359,9 +366,11 @@ def _find_best_vhost(self, target_name):
359366 :returns: VHost or None
360367
361368 """
362- # Points 4 - Servername SSL
363- # Points 3 - Address name with SSL
364- # Points 2 - Servername no SSL
369+ # Points 6 - Servername SSL
370+ # Points 5 - Wildcard SSL
371+ # Points 4 - Address name with SSL
372+ # Points 3 - Servername no SSL
373+ # Points 2 - Wildcard no SSL
365374 # Points 1 - Address name with no SSL
366375 best_candidate = None
367376 best_points = 0
@@ -381,7 +390,7 @@ def _find_best_vhost(self, target_name):
381390 continue # pragma: no cover
382391
383392 if vhost .ssl :
384- points += 2
393+ points += 3
385394
386395 if points > best_points :
387396 best_points = points
0 commit comments