Nettacker icon indicating copy to clipboard operation
Nettacker copied to clipboard

API service masks SSL certificate errors with the misleading "Cannot specify targets" message

Open jess-tech-lab opened this issue 8 months ago • 2 comments

Summary

Testing the API service with invalid certificate paths (e.g., /etc/hosts) caused the SSL handshake to fail (e.g., PEM lib error). The child process dies, and the parent process "falls through" to the CLI target validation, resulting in a misleading Cannot specify the target(s) error instead of the actual SSL failure.

Steps to Reproduce

Start the API service with the command:

poetry run nettacker --start-api --api-host 127.0.0.1 --api-port 8080 --api-debug-mode --api-cert /etc/hosts --api-cert-key /etc/hosts

The error message of Cannot specify the target(s) was returned:

Image

Expected Behavior

The API service should terminate immediately with a clear message such as Failed to load SSL configuration. Please check your --api-cert and --api-cert-key files..

Environment

  • macOS (Apple Silicon, Homebrew Python)
  • Python 3.12
  • Nettacker 0.4.0
  • Installed and executed via Poetry

jess-tech-lab avatar Mar 06 '26 03:03 jess-tech-lab

I can take this. The root cause is in start_api_server() in nettacker/api/engine.py: when the API subprocess dies (e.g., SSL error), the function returns without checking the exit code, and execution falls through to the CLI target validation which shows the misleading error. Will submit a PR with the fix.

xovishnukosuri avatar Mar 14 '26 00:03 xovishnukosuri

Hi @xovishnukosuri, thanks for the contribution!

I actually addressed this in PR #1355 already. One thing to note is that p.exitcode > 0 can be triggered by many things other than SSL issues (like port conflicts or environment errors), so a hardcoded PEM-specific message misleads users in those cases.

You can easily verify this by starting Nettacker on a port that has already been used with your proposed fix.

In #1355, I also used the i18n system to provide a localized error message and kept the exit logic non-blocking. Since that PR is already linked to the issue and follows the project's localization standards, it's probably best to stick with that implementation to keep the error handling flexible and consistent. Happy to hear your thoughts though!

jess-tech-lab avatar Mar 14 '26 01:03 jess-tech-lab