-
-
Notifications
You must be signed in to change notification settings - Fork 952
Fix: Python 3.12 SSL compatibility - replace ssl.wrap_socket #1177
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
base: master
Are you sure you want to change the base?
Fix: Python 3.12 SSL compatibility - replace ssl.wrap_socket #1177
Conversation
- Replace deprecated ssl.wrap_socket() with ssl.SSLContext().wrap_socket() - Update test mocks to use ssl.SSLContext.wrap_socket instead of ssl.wrap_socket - Add server_hostname parameter to wrap_socket calls for proper SSL/TLS handling - Fixes compatibility issues with Python 3.12 where ssl.wrap_socket was removed
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughReplace module-level ssl.wrap_socket calls with an explicit TLS client SSLContext (ssl.PROTOCOL_TLS_CLIENT) and use context.wrap_socket(..., server_hostname=host) in core socket/ssl code; tests updated to patch/assert ssl.SSLContext.wrap_socket. Previous non-TLS fallback behavior is preserved. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (3)**/*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
tests/**/test_*.py📄 CodeRabbit inference engine (AGENTS.md)
Files:
tests/**📄 CodeRabbit inference engine (AGENTS.md)
Files:
Tip ✨ Issue Enrichment is now available for GitHub issues!CodeRabbit can now help you manage issues more effectively:
Disable automatic issue enrichmentTo disable automatic issue enrichment, add the following to your issue_enrichment:
auto_enrich:
enabled: falseThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
nettacker/core/lib/socket.py(1 hunks)nettacker/core/lib/ssl.py(1 hunks)tests/core/lib/test_socket.py(2 hunks)tests/core/lib/test_ssl.py(3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
**/*.py: Use 4-space indents in Python code
Limit lines to 99 characters (ruff/ruff-format/isort profile=black)
Module and file names should use lower_snake_case
Function and variable names should use lower_snake_case
Class names should use PascalCase
Constants should use UPPER_SNAKE_CASE
Keep functions small and add type hints where practical
Files:
nettacker/core/lib/ssl.pytests/core/lib/test_ssl.pytests/core/lib/test_socket.pynettacker/core/lib/socket.py
nettacker/**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Add docstrings for public APIs in the nettacker package
Files:
nettacker/core/lib/ssl.pynettacker/core/lib/socket.py
nettacker/core/**
📄 CodeRabbit inference engine (AGENTS.md)
Place core libraries under nettacker/core/
Files:
nettacker/core/lib/ssl.pynettacker/core/lib/socket.py
tests/**/test_*.py
📄 CodeRabbit inference engine (AGENTS.md)
tests/**/test_*.py: Place tests under tests/ and name files as test_*.py
Use pytest (with pytest-asyncio, xdist) for tests
Files:
tests/core/lib/test_ssl.pytests/core/lib/test_socket.py
tests/**
📄 CodeRabbit inference engine (AGENTS.md)
Mirror package layout in tests (e.g., tests/core/, tests/lib/, etc.)
Files:
tests/core/lib/test_ssl.pytests/core/lib/test_socket.py
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
Repo: OWASP/Nettacker PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-09-07T19:20:58.332Z
Learning: Maintain coverage (pytest configured with --cov=nettacker); add tests for new features and bug fixes
🔇 Additional comments (3)
tests/core/lib/test_socket.py (1)
144-154: LGTM!Test correctly updated to patch
ssl.SSLContext.wrap_socketand verify theserver_hostnameparameter is passed, aligning with the new SSLContext-based implementation.tests/core/lib/test_ssl.py (2)
182-194: LGTM!Test correctly updated to patch
ssl.SSLContext.wrap_socketand verify theserver_hostnameparameter is passed.
438-440: LGTM!Assertion correctly updated to expect the
server_hostnameparameter in thewrap_socketcall.
- Add context.check_hostname = False to allow scanning self-signed certificates - Add context.verify_mode = ssl.CERT_NONE to match original ssl.wrap_socket behavior - Maintains backward compatibility for security scanner use cases
|
@securestep9 - Testing Results I've thoroughly tested the changes on Python 3.12 with real scanning: ✅ Full Nettacker scan completed successfully The SSL functionality is operating properly with the SSLContext changes. |
Proposed change
This PR fixes Python 3.12 compatibility issues in the Nettacker project. Python 3.12 removed the deprecated
ssl.wrap_socket()function, causing 2 tests to fail withAttributeError.This PR updates both the source code and tests to use the modern
ssl.SSLContext().wrap_socket()approach, which is the recommended method for SSL/TLS connections in Python 3.10+.Changes:
ssl.wrap_socket()withssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT).wrap_socket()innettacker/core/lib/ssl.pyandnettacker/core/lib/socket.pyserver_hostnameparameter for proper SSL/TLS certificate validationtests/core/lib/test_ssl.pyandtests/core/lib/test_socket.pyto patch the correct SSL methodTesting:
Type of change
Checklist
make test, all tests passed locally