NETRAVE/lib/utils/utilities.rb

136 lines
4.1 KiB
Ruby
Raw Normal View History

Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
# frozen_string_literal: true
require 'securerandom'
require 'digest'
require 'base64'
require 'openssl'
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
require 'sudo'
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
# Utiltiies Module
Refactoring for Modularity, Code Reuse, and Security Considerations In this commit, we have undertaken a significant refactoring of the codebase to improve modularity, promote code reuse, and consider security aspects. Modularity and Code Reuse: We introduced classes and modules to better organize the code and facilitate code reuse. Specifically, we created a new Utilities module to hold common methods that are used across different parts of the application. This module includes methods such as convert_speed_to_mbps, services_to_hash, and calculate_total_bandwidth. By placing these methods in a module, we can include this module in any class that needs these methods, thereby promoting code reuse and reducing duplication. We also created two new classes, SystemInformationGather and DatabaseManager. The SystemInformationGather class is responsible for gathering system information, such as uplink and downlink speed, and services. The DatabaseManager class handles database operations, including testing the database connection, creating the system information table, and storing system information in the database. By encapsulating these responsibilities within their respective classes, we have made the code more organized and easier to maintain. Database Connection Details: We made a decision to store the database connection details in a config file (config.yml) instead of the database itself. This decision was made for security reasons, as storing these details in the database could expose them to potential security risks. Storing these details in a config file allows us to better control access to these details. Database Encryption: We discussed the possibility of encrypting the database for additional security. While we have not implemented this feature in this commit, we have laid the groundwork for it by discussing potential libraries/gems that could be used for this purpose. This is an area that we will revisit in the future. System Information Gathering: We wrote methods to gather system information, such as uplink and downlink speed, and services, and store this information in the database. This information will be useful for monitoring system performance and for making decisions about resource allocation. This refactoring effort has made the codebase more organized, easier to maintain, and more secure. It also aligns with our project goals and roadmap. However, it's important to note that with any refactoring effort, there may be potential issues or trade-offs. We will need to thoroughly test the refactored code to ensure that it works as expected and that there are no unintended side effects.
2023-06-04 14:41:12 -06:00
module Utilities
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
# Converts speed from Gbps to Mbps if necessary
def convert_speed_to_mbps(speed)
return nil unless speed.is_a?(String) && speed.downcase.match?(/\A\d+(gbps|mbps)\z/i)
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
# Extract the numeric part and the unit from the speed
numeric_speed, unit = speed.downcase.match(/(\d+)(gbps|mbps)/i).captures
# Convert the numeric part to an integer
numeric_speed = numeric_speed.to_i
# If the unit is 'gbps', multiply the numeric part by 1000
numeric_speed *= 1000 if unit == 'gbps'
numeric_speed
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
end
# Converts an array of services into a hash
def services_to_hash(services)
services_hash = {}
services.each { |service| services_hash[service] = true }
services_hash
end
# Calculates total bandwidth from uplink and downlink speeds
def calculate_total_bandwidth(uplink_speed, downlink_speed)
uplink_speed + downlink_speed
end
def generate_key
Base64.encode64(SecureRandom.bytes(32)).chomp
end
Implement Encryption for Sensitive Data and Switch to .env for Configuration Storage This commit introduces several significant changes to improve the security and configuration management of the application. Encryption of Sensitive Data: We've introduced encryption for sensitive data such as database passwords. This is done using the Blowfish algorithm. The encryption and decryption methods are added to the Utilities module. The encryption is applied when the user enters their database password during the first run setup. The encrypted password is then stored in the .env file. When the application needs to use the password, it is decrypted using the key that was generated during encryption. Switch from YAML to .env for Configuration Storage: The application now uses a .env file for storing configuration data instead of a YAML file. This change was made to take advantage of the .env file's ability to store environment variables, which can be easily accessed by the application. The .env file stores the database username, encrypted password, encryption key, and database name. First Run Setup Changes: The FirstRunInit class has been updated to ask the user for their database details, encrypt the password, and store these details in the .env file. It also checks if any of the necessary details are missing and runs the first run setup if they are. Database Connection Testing: The DatabaseManager class now decrypts the password before using it to test the database connection. It also checks if the password or key are nil before attempting to decrypt the password. Logging: A new LoggMan class has been added to handle logging. This class provides a simple method for logging messages, which can be used throughout the application to log errors or other important information. Bug Fixes and Error Handling: Several bugs were fixed and error handling was improved. For example, a bug that caused the application to crash if the .env file was missing has been fixed. Also, the application now checks if the .env file exists and creates it if it doesn't. These changes significantly improve the security, reliability, and usability of the application.
2023-06-11 15:46:53 -06:00
def encrypt_string_chacha20(data, key)
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
return nil if data.nil? || key.nil?
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
cipher = OpenSSL::Cipher.new('chacha20')
cipher.encrypt
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
cipher.key = Base64.decode64(key) # Decode the key from Base64
Implement Encryption for Sensitive Data and Switch to .env for Configuration Storage This commit introduces several significant changes to improve the security and configuration management of the application. Encryption of Sensitive Data: We've introduced encryption for sensitive data such as database passwords. This is done using the Blowfish algorithm. The encryption and decryption methods are added to the Utilities module. The encryption is applied when the user enters their database password during the first run setup. The encrypted password is then stored in the .env file. When the application needs to use the password, it is decrypted using the key that was generated during encryption. Switch from YAML to .env for Configuration Storage: The application now uses a .env file for storing configuration data instead of a YAML file. This change was made to take advantage of the .env file's ability to store environment variables, which can be easily accessed by the application. The .env file stores the database username, encrypted password, encryption key, and database name. First Run Setup Changes: The FirstRunInit class has been updated to ask the user for their database details, encrypt the password, and store these details in the .env file. It also checks if any of the necessary details are missing and runs the first run setup if they are. Database Connection Testing: The DatabaseManager class now decrypts the password before using it to test the database connection. It also checks if the password or key are nil before attempting to decrypt the password. Logging: A new LoggMan class has been added to handle logging. This class provides a simple method for logging messages, which can be used throughout the application to log errors or other important information. Bug Fixes and Error Handling: Several bugs were fixed and error handling was improved. For example, a bug that caused the application to crash if the .env file was missing has been fixed. Also, the application now checks if the .env file exists and creates it if it doesn't. These changes significantly improve the security, reliability, and usability of the application.
2023-06-11 15:46:53 -06:00
encrypted_data = cipher.update(data) + cipher.final
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
Implement Encryption for Sensitive Data and Switch to .env for Configuration Storage This commit introduces several significant changes to improve the security and configuration management of the application. Encryption of Sensitive Data: We've introduced encryption for sensitive data such as database passwords. This is done using the Blowfish algorithm. The encryption and decryption methods are added to the Utilities module. The encryption is applied when the user enters their database password during the first run setup. The encrypted password is then stored in the .env file. When the application needs to use the password, it is decrypted using the key that was generated during encryption. Switch from YAML to .env for Configuration Storage: The application now uses a .env file for storing configuration data instead of a YAML file. This change was made to take advantage of the .env file's ability to store environment variables, which can be easily accessed by the application. The .env file stores the database username, encrypted password, encryption key, and database name. First Run Setup Changes: The FirstRunInit class has been updated to ask the user for their database details, encrypt the password, and store these details in the .env file. It also checks if any of the necessary details are missing and runs the first run setup if they are. Database Connection Testing: The DatabaseManager class now decrypts the password before using it to test the database connection. It also checks if the password or key are nil before attempting to decrypt the password. Logging: A new LoggMan class has been added to handle logging. This class provides a simple method for logging messages, which can be used throughout the application to log errors or other important information. Bug Fixes and Error Handling: Several bugs were fixed and error handling was improved. For example, a bug that caused the application to crash if the .env file was missing has been fixed. Also, the application now checks if the .env file exists and creates it if it doesn't. These changes significantly improve the security, reliability, and usability of the application.
2023-06-11 15:46:53 -06:00
Base64.encode64(encrypted_data).chomp
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
rescue OpenSSL::Cipher::CipherError => e
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
@loggman.log_error("Failed to encrypt data: #{e.message}")
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
nil
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
end
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
def decrypt_string_chacha20(encrypted_data, key) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
return nil if encrypted_data.nil? || key.nil?
Implement Encryption for Sensitive Data and Switch to .env for Configuration Storage This commit introduces several significant changes to improve the security and configuration management of the application. Encryption of Sensitive Data: We've introduced encryption for sensitive data such as database passwords. This is done using the Blowfish algorithm. The encryption and decryption methods are added to the Utilities module. The encryption is applied when the user enters their database password during the first run setup. The encrypted password is then stored in the .env file. When the application needs to use the password, it is decrypted using the key that was generated during encryption. Switch from YAML to .env for Configuration Storage: The application now uses a .env file for storing configuration data instead of a YAML file. This change was made to take advantage of the .env file's ability to store environment variables, which can be easily accessed by the application. The .env file stores the database username, encrypted password, encryption key, and database name. First Run Setup Changes: The FirstRunInit class has been updated to ask the user for their database details, encrypt the password, and store these details in the .env file. It also checks if any of the necessary details are missing and runs the first run setup if they are. Database Connection Testing: The DatabaseManager class now decrypts the password before using it to test the database connection. It also checks if the password or key are nil before attempting to decrypt the password. Logging: A new LoggMan class has been added to handle logging. This class provides a simple method for logging messages, which can be used throughout the application to log errors or other important information. Bug Fixes and Error Handling: Several bugs were fixed and error handling was improved. For example, a bug that caused the application to crash if the .env file was missing has been fixed. Also, the application now checks if the .env file exists and creates it if it doesn't. These changes significantly improve the security, reliability, and usability of the application.
2023-06-11 15:46:53 -06:00
cipher = OpenSSL::Cipher.new('chacha20')
cipher.decrypt
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
cipher.key = Base64.decode64(key) # Decode the key from Base64
decrypted_data = cipher.update(Base64.decode64(encrypted_data)) + cipher.final
# Check if the decrypted data is valid ASCII
decrypted_data.force_encoding('UTF-8')
if decrypted_data.valid_encoding?
decrypted_data
else
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
@loggman.log_error("Decrypted data is not valid ASCII: #{decrypted_data.inspect}")
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
nil
end
rescue OpenSSL::Cipher::CipherError => e
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
@loggman.log_error("Failed to decrypt data: #{e.message}")
Major Refactoring and Feature Addition for Improved User Experience and Code Quality This commit includes several significant changes aimed at improving the functionality, user experience, and code quality of our Ruby project. 1. Decryption Fix: We identified and resolved an issue where the database password was being decrypted multiple times, leading to connection problems. The code was refactored to ensure that decryption only occurs once, thereby enhancing the efficiency and reliability of our database connections. 2. Infinite Loop Resolution: We addressed a critical issue where the program would enter an infinite loop if the .env file was missing or contained incorrect information. The code was updated to handle these situations appropriately, providing meaningful feedback to the user and preventing unnecessary resource consumption. 3. .env File Handling Improvement: We improved the handling of the .env file, ensuring that the program can function correctly even in the absence of this file or if it contains incorrect data. This change enhances the robustness of our application. 4. Curses Alerts Integration: We integrated a new feature to display alerts in the terminal using the Curses library. These alerts can have different severity levels (info, warning, error), which are displayed in different colors (blue, yellow, red). This feature improves the user experience by providing clear and immediate feedback on the program's status. 5. Automatic Alert Dismissal: We implemented a feature where alerts automatically disappear after 5 seconds. This was achieved using Ruby threads, ensuring that the rest of the program is not blocked while the alert is displayed. This change enhances the user experience by preventing the screen from being cluttered with old alerts. 6. Debugging Libraries Exploration: We explored the possibility of using the Tracer and Debug libraries to trace the execution of the program and assist with debugging. While these libraries were not integrated in this commit, they remain a potential resource for future debugging efforts. This commit represents a significant step forward in the development of our Ruby project, improving both the user experience and the quality of our codebase.
2023-06-12 15:31:34 -06:00
nil
end
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
def ask_for_sudo(logger)
@loggman = logger
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
@loggman.log_info('Asking for sudo password... (This log entry will be removed)')
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
Curses.addstr('Please enter your sudo password: ')
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
# use the dynamic curses input gem in secure mode to collect the sudo password
sudo_password = DCI.catch_input(false)
@loggman.log_info('Sudo password received. (This log entry will be removed)')
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
# Encrypt the sudo password right away and store it in an environment variable
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
encrypted_sudo_password = encrypt_string_chacha20(sudo_password, @secret_key)
ENV['SPW'] = encrypted_sudo_password
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
# Clear the unencrypted sudo password from memory
sudo_password.replace(' ' * sudo_password.length)
end
def test_sudo
# Run a simple ls command with sudo privileges to test
use_sudo('ls')
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
true
rescue Sudo::Wrapper::InvalidPassword
false
end
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
def deescalate_sudo
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
# Retrieve the encrypted sudo password from the environment variable
encrypted_sudo_password = ENV['SPW']
# Decrypt the sudo password
sudo_password = decrypt_string_chacha20(encrypted_sudo_password, @secret_key)
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
# Invalidate the user's cached credentials
Sudo::Wrapper.run('sudo -k', password: sudo_password)
Implement Initial System Setup and Packet Capture 1. Initial System Setup: - Implemented a first run initialization process that guides the user through setting up the necessary environment variables. - Created a method to securely ask for the user's sudo password, test it, and store it in an encrypted form in an environment variable for use during the first run setup process. - Added a method to clear the sudo password from memory and the environment variables at the end of the first run setup process. 2. Packet Capture: - Created a PacketCapture class that uses the PCAPRUB library to capture packets from a specified network interface. - Refactored the packet capture process to add each captured packet to a Redis queue for further processing, instead of processing the packets directly. - Removed the manual packet dissection from the packet capture process, as this will be handled by the workers. 3. Networking Setup: - Created a NetworkingGenie class to handle the setup of the necessary networking components. - Added methods to identify the main network interface, create a dummy network interface, and set up traffic mirroring from the main interface to the dummy interface. 4. Logging: - Implemented logging for all major actions and errors throughout the system. 5. General Refactoring and Code Cleanup: - Refactored and cleaned up various parts of the code to improve readability and maintainability. - Fixed various minor bugs and issues. This commit lays the groundwork for the packet processing workers and the orchestrator that will manage them. The next steps will be to implement these components and integrate them with the existing system.
2023-06-29 22:36:18 -06:00
# Clear the sudo password from memory
sudo_password.replace(' ' * sudo_password.length)
# Remove the encrypted sudo password from the environment variables
ENV.delete('SPW')
end
Implement Secure Sudo Usage, Error Handling in NetworkingGenie Class, and Create New Sudo Methods in Utilities Module This commit introduces substantial enhancements to both the NetworkingGenie class and the Utilities module, focusing on the secure usage of sudo permissions, improved error handling, and the creation of new sudo methods. 1. Secure Sudo Usage: The `use_sudo` method from the Utilities module is now integrated within the `find_main_interface`, `create_dummy_interface`, and `setup_traffic_mirroring` methods of the NetworkingGenie class. This method ensures that commands requiring sudo permissions are executed securely. It achieves this by encrypting the sudo password, using it for the required command, and then immediately clearing it from memory. This approach significantly enhances the security of operations that require elevated permissions. 2. New Sudo Methods in Utilities Module: This commit introduces several new methods in the Utilities module to handle sudo operations securely. The `ask_for_sudo`, `test_sudo`, `deescalate_sudo`, and `use_sudo` methods have been created. These methods handle the secure acquisition, testing, de-escalation, and usage of sudo permissions, respectively. They ensure that sudo operations are performed securely and efficiently, with the sudo password being encrypted and cleared from memory immediately after use. 3. Improved Error Handling: The error handling within the `setup_traffic_mirroring` method has been refined. Now, when an exception is raised during the execution of a command, the error message is not only logged using the LoggMan logger but also an alert is enqueued into the AlertQueueManager. This dual approach ensures that errors are properly logged for debugging purposes and also communicated to the user in real-time. 4. AlertQueueManager Integration: The `initialize` method of NetworkingGenie has been updated to accept an `alert_queue_manager` parameter. This allows the NetworkingGenie class to enqueue alerts directly into the AlertQueueManager, thereby improving the communication of errors and important information to the user. 5. Dummy Interface Creation: The `create_dummy_interface` method now checks if the dummy interface already exists before attempting to create it. This prevents unnecessary system calls and potential errors. These modifications significantly contribute to the overall security and reliability of the NETRAVE system. They ensure that network setup and traffic mirroring operations are performed securely and efficiently, with clear and immediate communication of any issues that may occur.
2023-07-05 17:40:03 -06:00
def use_sudo(command)
# Retrieve the encrypted sudo password from the environment variable
encrypted_sudo_password = ENV['SPW']
# Decrypt the sudo password
sudo_password = decrypt_string_chacha20(encrypted_sudo_password, @secret_key)
# Use the sudo password to run the command
result = Sudo::Wrapper.run(command, password: sudo_password)
# Clear the sudo password from memory
sudo_password.replace(' ' * sudo_password.length)
result
end
Detailed Refactoring of Database Interaction 1. **Refactoring of Database Interaction Methods** - Refactored the `store_services` method in the `DatabaseManager` class to handle an array of services instead of a hash. This change was made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - The `store_services` method now iterates over an array of services and inserts each service into the database with a default status of true. This design choice was made to ensure that all services are active by default. 2. **Modification of Database Schema** - Modified the `create_services_table` method in the `DatabaseManager` class to create a table with only two columns: `id` and `services`. This change was made to align the database schema with the new data structure used in the `store_services` method. - The `status` column was removed from the `services` table because the status of all services is now assumed to be true by default. 3. **Error Handling and Debugging** - Encountered a `Sequel::DatabaseError` with the message "Operand should contain 1 column(s)" during the execution of the `store_services` method. This error was caused by an attempt to insert a hash into a single database column. - The error was resolved by refactoring the `store_services` method to handle an array of services instead of a hash. 4. **Unorthodox Design Choices** - The decision to use an array of services instead of a hash and to assume that the status of all services is true by default may seem unorthodox. However, these design choices were made to simplify the interaction with the database and to avoid unnecessary complexity in the data structure. - These design choices also helped to resolve the `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method. This commit represents a significant refactoring of the database interaction methods in the NETRAVE project. The changes made in this commit have simplified the interaction with the database and have resolved a `Sequel::DatabaseError` that was encountered during the execution of the `store_services` method.
2023-06-09 19:39:54 -06:00
end