Skip to content
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

Merged
merged 6 commits into from
Mar 21, 2023
Merged

Fixes #148 #149

merged 6 commits into from
Mar 21, 2023

Conversation

aersam
Copy link
Contributor

@aersam aersam commented Mar 17, 2023

Fixes for #148

Copy link
Owner

@denisenkom denisenkom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, see comments inline

@@ -105,11 +105,19 @@ def validate_host(cert, name):
ext = cert.get_extension(i)
if ext.get_short_name() == b'subjectAltName':
s = str(ext)
Copy link
Owner

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:

  • exact SAN match
  • wildcard SAN match
  • SAN mismatch

Copy link
Contributor Author

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?

src/pytds/tls.py Outdated
# 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
Copy link
Owner

Choose a reason for hiding this comment

The 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 DNS: prefix twice

Copy link
Contributor Author

@aersam aersam Mar 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that refactoring, hope it's fine now

@codecov
Copy link

codecov bot commented Mar 21, 2023

Codecov Report

Merging #149 (c9b929f) into master (ebd441b) will increase coverage by 0.02%.
The diff coverage is 95.23%.

@@            Coverage Diff             @@
##           master     #149      +/-   ##
==========================================
+ Coverage   91.73%   91.75%   +0.02%     
==========================================
  Files          27       28       +1     
  Lines        7743     7763      +20     
==========================================
+ Hits         7103     7123      +20     
  Misses        640      640              
Impacted Files Coverage Δ
src/pytds/tls.py 25.58% <91.66%> (+6.93%) ⬆️
tests/tls_san_test.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@denisenkom denisenkom merged commit e697481 into denisenkom:master Mar 21, 2023
@denisenkom
Copy link
Owner

Thank you! Merged

@aersam
Copy link
Contributor Author

aersam commented Mar 21, 2023

Thank you!
May I ask for a release with this?

@denisenkom
Copy link
Owner

Sure, I have one more PR pending, I will make a release after it is merged too: #151

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants