Skip to content

Improves Space-Track API interaction#7

Open
zfhassaan wants to merge 25 commits intoANG13T:mainfrom
zfhassaan:main
Open

Improves Space-Track API interaction#7
zfhassaan wants to merge 25 commits intoANG13T:mainfrom
zfhassaan:main

Conversation

@zfhassaan
Copy link
Copy Markdown

@zfhassaan zfhassaan commented Dec 4, 2024

Bug Fix (#5 (comment))

Refactors the code to handle Space-Track API authentication and data retrieval more robustly. Adds error handling and improves the clarity of the code. The changes ensure a more reliable and efficient interaction with the Space-Track API.

Update ( 09-12-2025 ):

Release Notes

Overview

This release introduces significant improvements to SatIntel, including enhanced security, interactive satellite search capabilities, favorites management, comprehensive test coverage, and better user experience.


New Features

1. Interactive Satellite Search & Filtering

Location: osint/osint.go:SelectSatellite()

  • Search Functionality:

    • Search satellites by name (case-insensitive partial matching)
    • Filter by country code (e.g., US, RU, CN)
    • Filter by object type (PAYLOAD, ROCKET BODY, DEBRIS, UNKNOWN, TBA)
    • Filter by launch year
  • Pagination:

    • Navigate through results with Previous/Next page controls
    • 20 results per page
    • Page indicators showing current page and total results
  • Enhanced Display:

    • Shows satellite name, NORAD ID, country, and object type
    • Interactive search menu before displaying results
    • "New Search" option to modify filters without exiting

Technical Details:

  • Client-side filtering for name searches (fetches up to 500 results)
  • Server-side filtering for country, object type, and launch year
  • Efficient caching of filtered results for better performance

2. Save/Load Favorites

Location: osint/favorites.go

  • Favorites Management:

    • Save frequently accessed satellites to favorites
    • Quick access to favorites from satellite selection menu
    • View all favorites with details (name, NORAD ID, country, type, added date)
    • Remove individual favorites
    • Clear all favorites with confirmation
  • Storage:

    • JSON file storage in ~/.satintel/favorites.json
    • Automatic directory creation
    • Prevents duplicate favorites
  • Integration:

    • "⭐ Select from Favorites" option at start of satellite selection
    • Option to save satellite to favorites after selection
    • "⭐ View Favorites" option in search results navigation

3. Enhanced Security Features

Password Masking

Location: main.go:readPassword()

  • Password input now displays asterisks (*) instead of being completely invisible
  • Provides visual feedback while maintaining security
  • Proper backspace handling
  • Cross-platform terminal support

Input Sanitization

Location: osint/tleparser.go:validateFilePath()

  • File Path Validation:
    • Prevents directory traversal attacks (blocks ../, ..\, etc.)
    • Validates path format (empty paths, null bytes, excessive length)
    • Checks for double slashes/backslashes
    • Verifies file exists and is not a directory before opening
    • Maximum path length enforcement (4096 characters)

API Key Validation

Location: main.go:validateAPIKeyFormat(), validateCredentials()

  • Format Validation:

    • Length checks (3-512 characters)
    • Character validation (no newlines, tabs, or carriage returns)
    • Specific validation for Space-Track credentials
    • Specific validation for N2YO API keys
  • Connection Testing:

    • Tests Space-Track API connection on startup
    • Tests N2YO API connection on startup
    • Provides clear error messages for invalid credentials
    • Validates credentials before use

Improvements

1. Environment Variable Management

  • .env File Support:
    • Load credentials from .env file automatically
    • Graceful fallback to manual input if .env not found
    • Supports quoted values and comments in .env files
    • Clear error messages for different failure scenarios

2. Error Handling

  • Improved error messages throughout the application
  • Context-specific error messages with suggestions
  • Better validation feedback for user inputs
  • Graceful handling of API failures

3. TLE Parsing Robustness

  • Enhanced Validation:

    • Lenient field count validation (minimum 4 for line 1, 3 for line 2)
    • Comprehensive bounds checking before array accesses
    • Better handling of variable field counts
    • Improved error messages with diagnostic information
  • Bug Fixes:

    • Fixed panic when TLE data has insufficient fields
    • Fixed validation to check data before split operation
    • Added validation in TLETextFile() and TLEPlainString() functions

4. HTTP Client Improvements

  • Session Management:

    • Cookie jar implementation for persistent Space-Track sessions
    • Fixed 401 Unauthorized errors after login
    • Proper session cookie handling
  • Error Handling:

    • Fixed nil pointer dereference in HTTP error handling
    • Early returns after HTTP errors
    • Better error messages for network failures

5. Code Quality

  • Replaced deprecated io/ioutil with os and io packages
  • Removed redundant return statements
  • Improved code documentation with natural language godoc comments
  • Better code organization and structure

Testing

Test Coverage

Main Package Tests (main_test.go, main_apivalidation_test.go)

  • Password Field Detection: 11 test cases
  • Environment File Loading: 7 test cases + 4 edge cases
  • API Key Format Validation: 27+ test cases
  • Credential Validation: Multiple test scenarios
  • Benchmark Tests: Performance testing for key functions

OSINT Package Tests (osint_test.go, osint/tleparser_test.go, osint/favorites_test.go)

  • NORAD ID Extraction: 8 test cases
  • String Formatting: 4 test cases
  • Query Building: 7 test cases
  • Name Filtering: 6 test cases
  • File Path Validation: 18 test cases + 5 edge cases
  • Favorites Management: 7 test functions covering all operations
  • Benchmark Tests: Performance testing

CLI Package Tests (cli/cli_test.go)

  • File reading tests
  • Banner display tests

Test Runner

  • Centralized test runner (run_tests.go)
  • Module-based testing organization
  • Options for coverage, verbose output, and benchmarks
  • Easy to add new test modules

Total Test Coverage: 100+ test cases across all modules


Bug Fixes

  1. TLE Parsing Panic: Fixed slice bounds out of range errors when parsing TLE data with insufficient fields
  2. HTTP Session Management: Fixed 401 Unauthorized errors by implementing proper cookie jar
  3. Nil Pointer Dereference: Fixed panics in HTTP error handling and file operations
  4. NORAD ID Extraction: Fixed bug where satellite name was extracted instead of NORAD ID
  5. String Formatting: Fixed panic with negative repeat count for very long inputs
  6. File Path Validation: Added missing validation in TLETextFile() function
  7. TLE Validation: Added validation checks in TLETextFile() and TLEPlainString() functions

Security Improvements

  1. Test Credentials: Replaced potentially misleading test values with clearly fake credentials (fake_test_* prefix)
  2. Input Validation: Comprehensive file path validation to prevent directory traversal attacks
  3. Password Masking: Enhanced password input with asterisk display
  4. API Key Validation: Format validation and connection testing for all API credentials
  5. No Hardcoded Secrets: All credentials loaded from environment variables or .env files

Migration Guide

For Existing Users

  1. Environment Variables:

    • No changes required - existing environment variables continue to work
    • New .env file support is optional
  2. Favorites:

    • Favorites are stored in ~/.satintel/favorites.json
    • Automatically created on first use
    • No migration needed
  3. API Credentials:

    • Credentials are now validated on startup
    • Invalid credentials will show clear error messages
    • Connection tests ensure credentials work before use

Breaking Changes

  • None - all changes are backward compatible

Dependencies

New Dependencies

  • None - all features use existing dependencies

Updated Dependencies

  • All dependencies remain the same
  • No breaking changes in dependencies

Performance Improvements

  • Efficient caching of filtered satellite results
  • Optimized API query building
  • Reduced redundant API calls
  • Better memory management in TLE parsing

Changelog Summary

Added

  • Interactive satellite search with filters
  • Pagination for search results
  • Favorites save/load functionality
  • File path validation
  • API key format validation
  • Connection testing for APIs
  • tests for all modules
  • Test runner script to run tests for all modules
  • .env file support
  • Password masking with asterisks

Changed

  • Enhanced TLE parsing validation
  • Improved error messages
  • Better HTTP session management
  • Replaced deprecated io/ioutil package
  • Improved code documentation

Fixed

  • TLE parsing panics
  • HTTP 401 errors after login
  • Null pointer dereferences
  • NORAD ID extraction bug
  • String formatting panics
  • Missing validation in TLE parser functions

Security

  • Input sanitization for file paths
  • Test credentials clearly marked as fake
  • Enhanced password input security
  • API credential validation

Screenshot 2024-12-05 at 2 18 13 AM

Refactors the code to handle Space-Track API authentication and data retrieval more robustly.  Adds error handling and improves the clarity of the code.  The changes ensure a more reliable and efficient interaction with the Space-Track API.
- Added a function to load environment variables from a `.env` file, improving credential management.
- Implemented checks for required environment variables, prompting users for input if not set.
- Refactored CLI options and display functions for better user interaction and clarity.
- Updated dependencies in `go.mod` and `go.sum` for improved package management.
- Added functionality to mask password input for sensitive environment variables.
- Introduced helper functions for password field detection and secure reading of passwords.
- Updated Go version in `go.mod` and added new dependencies for improved functionality.
- Modified `.gitignore` to include documentation and test runner files.
- Updated test cases to include more descriptive names indicating that password fields are masked with asterisks.
- Enhanced the readPassword function to handle non-terminal input and provide better user experience with character masking and input validation.
- Added validation checks for TLE data parsing to ensure sufficient field counts and correct format.
- Enhanced error messages to provide clearer feedback on parsing failures, including specific field counts and format issues.
- Introduced a new function to validate file paths, preventing directory traversal attacks and ensuring safe input.
- Enhanced error handling in the TLETextFile function to provide user feedback on invalid paths and file types.
- Cleaned and normalized file paths before processing to improve security and reliability.
- Added functions to validate the format of API keys and credentials, ensuring they meet specified criteria.
- Introduced connection tests for Space-Track and N2YO APIs to verify credentials and provide user feedback on validation results.
- Enhanced user prompts for credential input, including error handling for invalid formats and connection issues.
- Introduced new test cases for validating the format of API keys and credentials, including checks for valid and invalid inputs.
- Implemented tests for password field validation, ensuring proper handling of various password formats and lengths.
- Enhanced existing test suite to improve coverage and reliability of credential validation functionality.
- Introduced a new menu option to select satellites from user favorites, enhancing user experience.
- Implemented functionality to save or remove satellites from favorites after selection.
- Updated the satellite selection process to include viewing favorites alongside searching for new satellites.
- Modified `.gitignore` to include user favorites data files for better project management.
@gitguardian
Copy link
Copy Markdown

gitguardian bot commented Dec 9, 2025

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

- Replaced real test credentials with fake test values to ensure security and clarity in testing.
- Added comments to indicate that the test credentials are not real and are used solely for testing purposes.
- Updated various test cases to utilize the new fake credentials for consistency across the test suite.
…lite positions, and TLE data

- Integrated interactive prompts to allow users to export visual pass predictions, radio pass predictions, satellite positions, and TLE data.
- Implemented default filename generation based on satellite information for better user experience.
- Enhanced error handling during the export process to provide clear feedback on success or failure of the export operations.
- Updated the OSINT test module description to include export functionality.
- Added a new test module for export functionality, covering CSV, JSON, and Text export tests.
- Modified the runTests function to accept a test pattern filter for running specific tests.
- Updated the main function to include a flag for specifying the test pattern, enhancing test execution flexibility.
- Introduced a new test module for batch operations, including multi-satellite processing and exports.
- Updated the CLI to include a new option for batch operations, enhancing user functionality.
- Modified the options text file to reflect the addition of the batch operations feature.
Add batch operations tests and update CLI options
- Introduced a new test module for progress indicators, including spinners and progress bars.
- Enhanced input validation in the GetVisualPrediction and GetLocation functions to trim whitespace and clean numeric inputs.
- Implemented progress indicators during API calls for improved user experience.
- Added comprehensive tests for the new progress functionality, ensuring reliability and performance.
Add progress indicators and input validation enhancements
…and suggestions

- Created osint/errors.go with structured error handling module
- Implemented error codes for all error categories (AUTH, API, INPUT, TLE, FILE, SAT, NET)
- Added AppError struct with code, message, context, and suggestions
- Updated error messages throughout application with context-specific information
- Added helper functions: HandleError, HandleErrorWithContext, ValidateInput, ValidateNumericInput
- Updated IMPROVEMENTS.md to mark Better Error Messages as completed

Error codes:
- Authentication: AUTH-1001 to AUTH-1004
- API: API-1101 to API-1105
- Input validation: INPUT-1201 to INPUT-1204
- TLE: TLE-1301 to TLE-1304
- File: FILE-1401 to FILE-1404
- Satellite: SAT-1501 to SAT-1503
- Network: NET-1601 to NET-1603

Files modified:
- osint/errors.go (new)
- osint/osint.go
- osint/orbitalprediction.go
- osint/satelliteposition.go
- osint/tleparser.go
- IMPROVEMENTS.md
@zfhassaan
Copy link
Copy Markdown
Author

zfhassaan commented Dec 9, 2025

Hey @ANG13T Are you still maintaining this repository? Thanks.

- Added automatic location detection for latitude and longitude in satellite position queries.
- Updated prompts for altitude input to include default values and improved error handling.
- Introduced a new map visualization feature for satellite positions, offering options for ASCII, KML export, and web-based maps.
- Modified `.gitignore` to include the new `IMPROVEMENTS_COMPLETED.md` file for better documentation tracking.
- Cleaned up test files by removing unnecessary placeholders.

Files modified:
- osint/orbitalprediction.go
- osint/satelliteposition.go
- osint/favorites.go
- cli/cli_test.go
- osint/tleparser_test.go
- .gitignore
- Add SGP4 position calculation using github.com/joshuaferrara/go-satellite
- Implement CalculateSGP4Position function for local position prediction
- Add observer position and look angles calculations
- Include comprehensive test suite (sgp4_test.go)
- Update dependencies (go.mod, go.sum)
- Add test coverage output
- Update QUICK_TEST.md and cli_test.go
Implement SGP4 Algorithm Integration (#11)
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.

1 participant