-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #148 #149
Fixes #148 #149
Changes from 2 commits
5d071d2
1bfca1e
37543b2
76b8a4d
acf0822
c9b929f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -105,11 +105,19 @@ def validate_host(cert, name): | |
ext = cert.get_extension(i) | ||
if ext.get_short_name() == b'subjectAltName': | ||
s = str(ext) | ||
# SANs are usually have form like: DNS:hostname | ||
if s.startswith('DNS:') and s[4:] == s_name: | ||
return True | ||
|
||
# TODO handle wildcards | ||
items = s.split(',') | ||
for item in items: | ||
dnsentry = item.strip() | ||
# SANs are usually have form like: DNS:hostname | ||
if dnsentry.startswith('DNS:') and s[4:] == s_name: | ||
return True | ||
if dnsentry.startswith('DNS:*.'): # support for wildcards, but only at the first position | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be better to extract SAN host name suffix before previous condition, and then check host name for exact match and for wildcard match. Instead of checking for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did that refactoring, hope it's fine now |
||
afterstar_parts = dnsentry[6:] | ||
afterstar_parts_sname = '.'.join(s_name.split('.')[1:]) # remove first part of dns name | ||
if afterstar_parts == afterstar_parts_sname: | ||
return True | ||
|
||
# TODO check if wildcard is needed in CN as well | ||
return False | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please refactor this code: extract logic inside this if branch into its own method
is_san_matching(san: str, host_name: str): bool
.Also add unit tests for that method for following conditions:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a number of tests in tls_san_test.py, I hope thats correct this way?