|
1 | 1 | # NIS2Assessment |
2 | 2 | Regulatory assessment tool, developed with python. It utilises a unified knowledge model (ontology - stored in GraphDB) to measure compliance with NIS2 Cybersecurity risk-management measures (Article 21 ). |
| 3 | + |
| 4 | +NIS2 Regulatory Assessment Tool: Development Documentation |
| 5 | + |
| 6 | +Introduction |
| 7 | +Overview of the Regulatory Assessment Tool |
| 8 | +The Regulatory Assessment Tool is designed to measure compliance with NIS2 Cybersecurity risk-management measures (Article 21). The tool utilises a unified knowledge model (ontology stored in GraphDB) to dynamically call multiple choice questions (MCQs) and assess compliance with the NIS2 directive. |
| 9 | + |
| 10 | +Purpose and Scope |
| 11 | +The purpose of this tool is to provide organisations with a means to conduct a comprehensive NIS2 gap analysis against the ISO 27001:2022 framework. It maps specific ISO 27001:2022 controls and the essential security controls outlined by ENISA against the ten NIS2 Cybersecurity risk-management measures as detailed in Article 21. |
| 12 | + |
| 13 | +Installation |
| 14 | +System Requirements |
| 15 | +• Python 3.7 or higher |
| 16 | +• Flask |
| 17 | +• SPARQLWrapper |
| 18 | +• ReportLab |
| 19 | +• Matplotlib |
| 20 | +• SQLite3 |
| 21 | +• Flask-Session |
| 22 | +• A running instance of GraphDB |
| 23 | + |
| 24 | +Installation Steps |
| 25 | +1. Clone the repository: |
| 26 | + git clone <repository-url> |
| 27 | + cd <repository-directory> |
| 28 | + |
| 29 | +2. Create a virtual environment: |
| 30 | + python -m venv venv |
| 31 | + source venv/bin/activate |
| 32 | +# On Windows: venv\Scripts\activate |
| 33 | + |
| 34 | +3. Install the required packages: |
| 35 | + pip install -r requirements.txt |
| 36 | + |
| 37 | +Configuration |
| 38 | +Setting up the SPARQL Endpoint |
| 39 | +Ensure that the GraphDB instance is running and accessible. Update the SPARQL endpoint URL in the `RegulatoryAssessmentTool` class within `main.py`: |
| 40 | +self.sparql = SPARQLWrapper("http://localhost:8080/repositories/NIS2Ontology") |
| 41 | + |
| 42 | +Configuring the Flask Application |
| 43 | +Ensure Flask is set up correctly by configuring the secret key: |
| 44 | +secret_key = binascii.hexlify(os.urandom(24)).decode() |
| 45 | +app = Flask(__name__, static_url_path='/static') |
| 46 | +app.secret_key = secret_key |
| 47 | + |
| 48 | + |
| 49 | +Usage |
| 50 | +Starting the Application |
| 51 | +Run the Flask application: |
| 52 | +flask run |
| 53 | +Access the application in the web browser at `http://127.0.0.1:5000`. |
| 54 | + |
| 55 | +Navigating the Welcome Page |
| 56 | +The welcome page introduces the tool and provides an overview of NIS2 requirements. Click "Begin Assessment" to start the compliance assessment. |
| 57 | + |
| 58 | +Conducting an Assessment |
| 59 | +Answer the multiple-choice questions presented. Each question is dynamically fetched from the ontology. |
| 60 | + |
| 61 | +Viewing Results |
| 62 | +After completing the assessment, view detailed results categorized by implementation status and article. Recommendations are provided for partial or non-implemented measures. |
| 63 | + |
| 64 | +Generating Reports |
| 65 | +Click "Download Report" on the results page to generate a PDF report of the assessment, including scores, compliance percentage, and recommendations. |
| 66 | + |
| 67 | +User Feedback |
| 68 | +Users can provide feedback through a feedback form available after the assessment. The feedback form includes questions on usability, content relevance, and overall satisfaction. |
| 69 | + |
| 70 | +Code Overview |
| 71 | +main.py: Explanation of the Main Application File |
| 72 | +Class: RegulatoryAssessmentTool |
| 73 | +`__init__`: Initializes the SPARQL endpoint and question label scores. |
| 74 | +`run_sparql_query`: Executes a SPARQL query and returns the results. |
| 75 | +`get_answer_definition`: Retrieves the definition for a given answer. |
| 76 | +`get_article_info`: Fetches information for a specific article. |
| 77 | +`get_article_label`: Gets the article label for a given MCQ number. |
| 78 | +`get_question_score`: Returns the score for a question label. |
| 79 | +`get_question_data`: Retrieves question and answer data for a given MCQ number. |
| 80 | +`get_recommendation`: Gets recommendations for a given MCQ number. |
| 81 | +`get_article_label_for_question`: Fetches the article label and definition for a given MCQ number. |
| 82 | + |
| 83 | +Flask Routes |
| 84 | +`/welcome`: Renders the welcome page. |
| 85 | +`/`: Renders the index page, starting the quiz if not already started. |
| 86 | +`/begin_assessment`: Starts the assessment. |
| 87 | +`/submit_answer`: Submits an answer and fetches the next question. |
| 88 | +`/get_next_question`: Fetches the next question's data. |
| 89 | +`/complete`: Renders the completion page with scores and charts. |
| 90 | +`/results`: Renders detailed results and recommendations. |
| 91 | +`/download_report`: Generates and downloads the PDF report. |
| 92 | +‘/consent’: Renders the consent form page and handles user consent. |
| 93 | +‘/feedback’: Renders the user feedback form. |
| 94 | +‘/submit_feedback’: Submits user feedback to the database. |
| 95 | +‘/view_feedback’: Displays all submitted feedback. |
| 96 | +‘/goodbye’: Renders the goodbye page if the user does not consent. |
| 97 | + |
| 98 | +Utility Functions |
| 99 | +`fetch_mcq_numbers`: Fetches and sorts MCQ numbers from the ontology. |
| 100 | +`add_page_number`: Adds page numbers to the PDF report. |
| 101 | +`create_pie_chart`: Creates and saves a pie chart of the question breakdown. |
| 102 | + |
| 103 | +Customization |
| 104 | +How to Modify the Assessment Questions |
| 105 | +Update the ontology in GraphDB with new questions and answers. Ensure the labels and definitions follow the same structure. |
| 106 | + |
| 107 | +Adding New SPARQL Queries |
| 108 | +Add new methods in the `RegulatoryAssessmentTool` class to handle additional SPARQL queries as needed. |
| 109 | + |
| 110 | +Customizing the Report Layout |
| 111 | +Modify the `download_report` route in `main.py` to change the layout, styles, and content of the PDF report. |
| 112 | + |
| 113 | +Troubleshooting |
| 114 | + |
| 115 | +Common Issues and Solutions |
| 116 | +SPARQL Query Errors: Ensure the SPARQL queries are correctly formatted and the endpoint is accessible. |
| 117 | +Flask Application Errors: Check for missing or misconfigured routes and templates. |
| 118 | + |
| 119 | +Logging and Debugging |
| 120 | +Enable logging in `main.py`: |
| 121 | +logging.basicConfig(level=logging.DEBUG) |
| 122 | +Check the console output for detailed logs. |
| 123 | + |
| 124 | + |
| 125 | +Contact |
| 126 | +For support or to contribute to this project, contact Jenni Parry at jenni.parry@ucdconnect.ie. |
0 commit comments