A logical repair method and system for a security protocol state machine
By dynamically maintaining the available knowledge set and using a historical state backtracking mechanism, the problem of low reliability of the security protocol state machine generation model in existing technologies is solved. Deep semantic inspection and fine-grained consistency verification are achieved, improving repair efficiency and reliability.
Patent Information
- Application Number
- CN202611288803.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-24
- Publication Date
- 2026-11-17
AI Technical Summary
Existing technologies lack in-depth semantic logic checks, precise backtracking and repair, and consistency verification when automatically generating security protocol state machines, resulting in low reliability of the generated models.
By dynamically maintaining the available knowledge set of each participant, structural and semantic checks are performed to generate structured anomaly results. Different types of anomalies are classified and repaired, including regular and irregular ones. A historical state backtracking mechanism is used to repair deep errors. Finally, the repair effect is quantitatively evaluated by verifying the fine-grained consistency with the benchmark model.
It implements deep semantic inspection, improves repair efficiency, ensures the self-consistency of state machine logic, and provides a fine-grained consistency verification method to quantitatively evaluate the repair effect.
Smart Images

Figure CN123122910A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of logic repair technology, and in particular to a logic repair method and system for a security protocol state machine. Background Technology
[0002] Security protocols form the foundational rules for authentication, key negotiation, and confidential communication over untrusted networks. However, flawed logical design in these protocols can lead to serious security risks such as identity impersonation, key leakage, or replay attacks. To identify and fix these flaws before deployment, systematic analysis and verification are essential. Currently, protocol specifications are primarily in natural language, often lengthy, logically complex, and containing numerous implicit premises, making manual analysis costly, time-consuming, and prone to errors. Therefore, automatically constructing analyzable structured models from protocol specifications has become a crucial prerequisite for automated verification of security protocols.
[0003] To achieve automated analysis, the mainstream approach in current technology is to automatically construct formal models such as finite state machines based on protocol specification documents. These approaches typically utilize large language models or neural language processing techniques to extract protocol states, events, and transition relationships from unstructured text to generate structured state machine models. For example, frameworks like PROSPER and SpecGPT use large language models to extract state machine elements from RFCs or 3GPP documents, while another research approach uses word representation learning or domain-specific languages to generate finite state machines, aiming to reduce reliance on manual modeling and provide a foundation for subsequent protocol vulnerability discovery.
[0004] However, existing technologies still have significant limitations in automatically generating security protocol state machines. First, current solutions primarily focus on the accuracy and syntactic correctness of extracting states, events, and state transitions, but lack systematic checks on the knowledge dependency logic unique to security protocols. Second, when handling generation errors, existing technologies mostly employ coarse-grained repair methods such as regeneration or local rule correction, lacking fine-grained analysis of the source of anomalies. Third, the state evolution of security protocols has strict temporal sequence and knowledge accumulation; errors in the current state are highly likely to be caused by defects in previous states. Finally, when evaluating the generation results, existing technologies mostly rely on general metrics such as accuracy and F1 score, lacking fine-grained consistency verification methods oriented towards protocol semantics. They cannot conduct in-depth comparisons between the generated model and the baseline model across multiple dimensions such as participants, operation sequences, and message fields, making it difficult to accurately assess the true quality and usability of the generated model.
[0005] Therefore, there is an urgent need in this field for a logic repair and consistency verification technology for security protocol state machines that can specifically address the above-mentioned challenges. Summary of the Invention
[0006] In view of this, embodiments of the present invention provide a logical repair method and system for a security protocol state machine to solve the problem that the automatically generated security protocol state machine in the prior art lacks in-depth semantic logic inspection, accurate backtracking repair and consistency verification mechanism, resulting in low reliability of the generated model.
[0007] One aspect of the present invention provides a logical repair method for a security protocol state machine, the method comprising the following steps: Obtain the security protocol state machine to be processed, which is automatically generated or manually constructed by the large language model. Then, parse and normalize the security protocol state machine to be processed, and extract the protocol name, the set of participants, the initial knowledge set of the participants, the state nodes, and the state transition relationships between the state nodes. Along the state path formed by the state transition relationship, based on the initial knowledge of each participant, the knowledge passed by the preceding state node, the message fields received by the current state node, and the state operation output of the current state node, the available knowledge set of each participant is dynamically maintained; based on the preset state machine structure template, the identification and reference relationship of the state node, the state transition relationship, the available knowledge set, and the message interaction relationship between the participants, the security protocol state machine to be processed is subjected to structural and semantic checks to generate structured anomaly results; For rule-based structured anomalies, repair is performed directly based on rules. For non-rule-based structured anomalies, the cause of the anomaly is analyzed and candidate repair targets are determined based on the anomaly type, anomaly object, anomaly location, associated objects, and anomaly context recorded therein. These candidate repair targets include initial knowledge layer targets, current state layer targets, historical state layer targets, subsequent state layer targets, or communication event layer targets. Each type of candidate repair target is then routed and targeted for repair according to a preset priority. Specifically, for historical state layer targets, repair is performed by tracing back to historical state nodes. Starting from these nodes, the subsequent state paths affected by the repair are reconstructed, and the available knowledge sets of the affected participants are updated along these subsequent state paths. The repaired security protocol state machine is then subjected to the structural and semantic checks again according to the scope of the repair. After the re-verification is passed, the final security protocol state machine is obtained.
[0008] In some embodiments of the present invention, the method further includes a consistency verification phase, the steps of which include: The final security protocol state machine after logical repair is used as the security protocol state machine to be verified. The baseline state machine corresponding to the security protocol state machine to be verified is obtained. The security protocol state machine to be verified and the baseline state machine are parsed and normalized respectively, and their respective protocol names, participant sets, participant initial knowledge sets, state nodes, and state transition relationships between state nodes are extracted. Based on the identification information and protocol semantic information of the participants in the security protocol state machine to be verified and the baseline state machine, the participants are aligned, and the knowledge items in the initial knowledge sets of the mutually aligned participants are aligned to establish element alignment relationships. Starting from the initial state nodes of the mutually aligned participants, recursive matching is performed while maintaining the state transition relationships of the security protocol state machine to be verified and the reference state machine. For the currently corresponding state nodes, based on the element alignment relationship, at least one of the following is matched: receive event, in-state operation, conditional branch, guard condition, send event, and subsequent state pointer. The number of successful matches, the number of missing matches, and the number of redundancies are determined with reference to the reference state machine. The corresponding subsequent state nodes are determined according to the state transition relationship. The updated element alignment relationship is passed to the subsequent state nodes to continue recursive matching until the preset recursive termination condition is met. Based on the results of the recursive matching, the number of successful matches, missing numbers, and redundant numbers are counted for each state machine element of the preset type. Based on this, a consistency evaluation index is calculated to obtain the overall consistency result, the sub-item consistency result, and the inconsistency location of the security protocol state machine to be verified relative to the baseline state machine.
[0009] In some embodiments of the present invention, the structural inspection step includes: Based on the preset state machine structure template, the existence, data type, and hierarchical relationship of the protocol name, participant set, participant initial knowledge set, and state node corresponding fields in the security protocol state machine to be processed are checked; when necessary fields are missing, field data types do not meet preset requirements, or hierarchical relationships do not meet preset requirements, a structural format anomaly is generated; wherein, the state node corresponding fields include at least one of receiving events, in-state operations, conditional branches, guard conditions, sending events, and subsequent state pointers; Based on the identifier and reference relationship of the state node, a consistency check is performed on the state name and the reference name that references the state name, and a duplicate check is performed on the state names under the same participant; when the state name and the corresponding reference name are inconsistent, a state reference inconsistency anomaly is generated; when there are duplicate state names under the same participant, a state name conflict anomaly is generated. Based on the state transition relationship, check whether the subsequent state pointer corresponds to an existing state node, a terminated state, or a loop state, whether the non-starting state node has a reachable preceding state, and whether the loop target corresponding to the loop state is valid; when the subsequent state pointer does not correspond to an existing state node, a terminated state, or a loop state that meets the preset conditions, the non-starting state node does not have a reachable preceding state, or the loop target does not meet the preset loop pointing conditions, respectively generate state connection anomaly, isolated state anomaly, or loop pointing anomaly. Generate a corresponding structured exception result based on at least one of the following: structure format exception, state reference inconsistency exception, state name conflict exception, state connection exception, isolated state exception, and circular pointer exception.
[0010] In some embodiments of the present invention, the semantic checking step includes: Based on the available knowledge set of each participant, according to the state path and the execution order of operations within the state, the knowledge source is checked for the input parameters of operations within the state, the variables referenced by guard conditions, and the sending fields in the sending event. The output parameters generated by the operations within the state are used as the newly added available knowledge of the corresponding participant. When the input parameters, the variables referenced by guard conditions, or the sending fields do not belong to the available knowledge of the corresponding participant at the corresponding execution position and do not belong to the predefined constants, a knowledge source exception is generated. Based on the guard conditions and condition branches in the state node, the comparison relationship of the guard conditions and the in-state operations, sent events and subsequent state pointers corresponding to different condition branches are checked; when the guard condition has the same variable compared with itself, a guard condition exception is generated; when the in-state operations, sent events and subsequent state pointers corresponding to multiple condition branches are the same, a duplicate branch exception is generated. Based on the message interaction relationship between the participants, a correspondence check is performed on the participants, event names, and message fields in the corresponding sending and receiving events. The naming relationship between the received fields and the existing knowledge of the receiving participants, as well as the target participant corresponding to the sending event, are also checked. If the sending and receiving events do not satisfy a preset correspondence, a message sending / receiving mismatch exception is generated. If the received fields conflict with existing knowledge in terms of naming, a received field conflict exception is generated. If the target participant does not exist, a sending target exception is generated. The combination and decomposition operations in the state operations and condition branch operations are checked; when the combination or decomposition operation only changes the organization of the field, does not generate new protocol semantics or cryptographic calculation results, and the intermediate field it introduces affects the subsequent state operation input, guard conditions or the source tracing of the original field of the sent field, it is identified as a redundant compound operation and a compound operation redundancy anomaly is generated. Generate a corresponding structured exception result based on at least one of the following: knowledge source anomaly, guard condition anomaly, duplicate branch anomaly, message sending and receiving mismatch anomaly, receive field conflict anomaly, send target anomaly, and composite operation redundancy anomaly.
[0011] In some embodiments of the present invention, the structured anomaly results of the rule type are directly repaired based on rules, and the steps include: The rule-based structured anomaly results include at least one of the following: inconsistent state reference anomaly, mergeable state name conflict anomaly, received field conflict anomaly, duplicate branch anomaly, and composite operation redundancy anomaly, and are classified and repaired according to the anomaly type. For the aforementioned state reference inconsistency anomaly, the state name of the generated state node pointed to by the reference position shall be used as the reference name, and the reference name at the reference position shall be modified to the state name, so that the reference name is consistent with the state name of the state node it points to. For the aforementioned mergeable state name conflict exception, when the received events, in-state operations, conditional branches, sent events, and subsequent state pointers of multiple state nodes with duplicate state names under the same participant are consistent, the multiple state nodes are merged, and the references pointing to the merged state node are uniformly updated to point to the merged state node. In the event of a conflict in the received field, if the received field has the same name as an existing knowledge item of the current participant but represents different semantic objects, the received field is renamed according to the preset field naming rules, and the references to it in subsequent guard conditions, in-state operations and sending events are updated synchronously. For the duplicate branch exception, when the operation, event sent and subsequent state of multiple condition branches are the same, the multiple condition branches are merged and a merged guard condition is formed according to the logical relationship between their guard conditions to replace the original guard condition. For the aforementioned redundant operation, when the corresponding redundant composite operation is a combination operation, the combination operation is deleted according to the correspondence between the output field and the input field set of the combination operation recorded during the inspection process, and subsequent references to the output field are replaced with the corresponding input field set; when the corresponding redundant composite operation is a disassembly operation, the disassembly operation is deleted according to the correspondence between the input field and the output field set of the disassembly operation recorded during the inspection process, and the output of the preceding operation that generated the input field is modified to the corresponding output field set.
[0012] In some embodiments of the present invention, targeted repair is performed on various candidate repair targets according to a preset priority, and the steps include: According to the preset priority rules, the priority of each candidate repair target is determined based on the anomaly type, associated object and anomaly context, the priority candidate repair target is selected, and the structured anomaly result is diverted to the targeted repair mechanism corresponding to the priority candidate repair target; When the priority candidate repair target is the initial knowledge layer target, the missing knowledge and its participating parties are determined according to the abnormal object, abnormal location, associated object and abnormal context. The missing knowledge is added to the initial knowledge set of the corresponding participating party, and the knowledge source check of the affected state node is re-executed based on the repaired initial knowledge set. When the priority candidate repair target is the current state layer target, the state generation method corresponding to the current state node is called according to the structured anomaly result to regenerate the current state node, and the original current state node is replaced by the regenerated current state node before connecting to the original state path. When the priority candidate repair target is a successor state layer target, the missing successor state node is determined according to the structured anomaly result, the corresponding state generation method is called to generate the successor state node, and it is connected to the corresponding state path according to the state transition relationship of the current state node. When the priority candidate repair target is a historical state layer target, the structured anomaly result will be diverted to the historical state backtracking repair mechanism; When the priority candidate repair target is a communication event layer target, the abnormal sending or receiving event is determined according to the message interaction relationship, and the participant identifier, event name or message field in the sending or receiving event is corrected in the state node where it is located, so that the sending event and the corresponding receiving event satisfy the preset correspondence relationship.
[0013] In some embodiments of the present invention, the historical state retrospective repair mechanism includes: When the priority candidate repair target is a historical state layer target, the historical state node corresponding to the cause of the anomaly is determined in the state path before the current state node based on the anomaly type, anomaly object, associated object, and anomaly context in the structured anomaly result; for anomaly variables that should be generated or transmitted by the preceding state node, the corresponding historical state node is determined based on their knowledge source; for cases where the received event of the current state node does not correspond to the preceding sent event, the historical state node containing the corresponding sent event is determined based on the message interaction relationship. Call the state generation method corresponding to the historical state node to regenerate the historical state node, and replace the original historical state node with the regenerated historical state node. Undo the existing construction results of subsequent state nodes affected by the repair of the historical state nodes, and reconstruct the affected subsequent state paths based on the regenerated state transition relationships, starting from the regenerated historical state nodes. During the reconstruction of the subsequent state path, the available knowledge set of the affected participants is updated along the subsequent state path based on the initial knowledge of each participant, the knowledge passed by the preceding state node, the message fields received by the current state node, and the state operation output of the current state node.
[0014] In some embodiments of the present invention, the structure check and semantic check are cyclically performed on the repaired security protocol state machine according to the repair range until the structured anomaly result meets the preset conditions. The steps include: After completing the rule-based repair or targeted repair, based on the objects and locations involved in this repair, update at least one of the state transition relationships, available knowledge sets, and message interaction relationships affected by this repair, and determine the affected part as the state check scope. Re-execute the structural check and semantic check on the state check scope, and update the structured anomaly results. If there are still unprocessed anomalies in the updated structured anomaly results, the unprocessed anomalies are re-determined as either regular or irregular anomalies. For regular anomalies, repairs are performed based on the corresponding rules. For irregular anomalies, the cause of the anomaly is re-identified, candidate repair targets are determined, and targeted repairs are performed according to a preset priority. After each repair, the state check range is re-determined, the structure check and semantic check are performed, and the structured anomaly results are updated until the updated structured anomaly results meet the preset conditions.
[0015] On the other hand, the present invention also provides a logic repair system for a security protocol state machine, including a processor, a memory, and a computer program or instructions stored in the memory, wherein the processor is used to execute the computer program or instructions, and when the computer program / instructions are executed, the system implements the steps of the method described in any of the above.
[0016] On the other hand, the present invention also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the method as described in any of the preceding claims.
[0017] The present invention discloses a method and system for logical repair of a security protocol state machine. This method innovatively constructs an automated logical repair and verification framework that includes dynamic knowledge tracking, deep inspection, categorized repair, and closed-loop verification. Specifically, the invention first dynamically tracks the available knowledge sets of each participant along the state path; based on this, it performs a comprehensive structural and semantic inspection of the automatically generated state machine to generate structured anomalies; then, it categorizes and processes the anomalies, addressing different types of logical defects through a combination of rule-based repair and multi-level targeted repair, particularly by introducing a historical state backtracking mechanism to repair deep-seated errors; finally, through fine-grained consistency verification with a benchmark model, it quantitatively evaluates the repair effect, forming a closed-loop optimization process of inspection, repair, and re-verification.
[0018] The beneficial effects of the technical solution of this invention are as follows: First, it realizes deep semantic inspection based on dynamic knowledge tracing. This method dynamically maintains the available knowledge set of each participant, overcoming the limitations of static format inspection in traditional solutions, and can accurately identify hidden logical errors. Second, it constructs a multi-level repair mechanism combining rules and orientation. This method, through precise positioning of multi-level targets such as initial knowledge, current state, and historical state, breaks through the bottleneck of single repair methods and insufficient targeting in existing technologies, significantly improving repair efficiency. Third, it innovatively creates a historical state backtracking repair mechanism. This method can trace and repair root causes of errors introduced by previous states and reconstruct subsequent state paths, fundamentally ensuring the self-consistency of the entire state machine logic. Fourth, it provides a fine-grained consistency verification and quantitative evaluation method. This method achieves quantitative evaluation of model consistency by recursively comparing the repaired state machine with the benchmark model in multiple dimensions, providing reliable feedback for the closed-loop process of inspection, repair, and re-verification.
[0019] Additional advantages, objects, and features of the invention will be set forth in part in the description which follows, and will also become apparent in part to those skilled in the art upon studying the description, or may be learned by practice of the invention. The objects and other advantages of the invention can be realized and obtained by means of the structures specifically pointed out in the description and drawings.
[0020] Those skilled in the art will understand that the objectives and advantages achievable with the present invention are not limited to those specifically described above, and that the above and other objectives achievable with the present invention will become clearer from the following detailed description. Attached Figure Description
[0021] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, are not intended to limit the scope of the invention. In the drawings: Figure 1 This is a flowchart illustrating the logic repair method for the security protocol state machine according to an embodiment of the present invention.
[0022] Figure 2 This is a general framework diagram of the logic repair and consistency verification method for the security protocol state machine according to another embodiment of the present invention.
[0023] Figure 3 This is a schematic diagram of the state machine check process in the logic repair method of the security protocol state machine according to another embodiment of the present invention.
[0024] Figure 4 This is a schematic diagram of the state machine repair process in the logic repair method of the security protocol state machine according to another embodiment of the present invention.
[0025] Figure 5 This is a flowchart illustrating the consistency verification method for the security protocol state machine according to another embodiment of the present invention. Detailed Implementation
[0026] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the embodiments and accompanying drawings. Here, the illustrative embodiments and descriptions of this invention are used to explain the invention, but are not intended to limit the invention.
[0027] It should also be noted that, in order to avoid obscuring the invention with unnecessary details, only the structures and / or processing steps closely related to the solution according to the invention are shown in the accompanying drawings, while other details that are not closely related to the invention are omitted.
[0028] It should be emphasized that the term "including / comprises" as used herein refers to the presence of a feature, element, step, or component, but does not exclude the presence or addition of one or more other features, elements, steps, or components.
[0029] It should also be noted that, unless otherwise specified, the term "connection" in this article can refer not only to a direct connection, but also to an indirect connection involving an intermediary.
[0030] The terms "first" and "second" used in this invention do not indicate a sequence number or a limitation on ordinal numbers, but should be understood as being used to distinguish different objects.
[0031] In the field of automated verification and state machine generation technology for security protocols, existing solutions mainly rely on two core mechanisms: extraction using large language models and generation based on neural natural language processing / domain-specific language. Facing the core challenges of achieving high semantic accuracy, rigorous logical consistency, and highly reliable security analysis of state machine models under complex and ambiguous natural language specifications, existing solutions have four main limitations in practical applications: First, they focus on extracting grammatical correctness, lacking in-depth semantic logic checks. Existing solutions mainly focus on the accuracy and surface format of extracting basic state machine elements, but lack systematic checks on the knowledge dependency logic specific to security protocols, resulting in serious semantic errors in the generated model even if it is grammatically compliant. Second, the repair granularity is coarse, lacking fine-grained localization of the root causes of anomalies. When dealing with generation errors, existing technologies mostly use coarse-grained methods such as overall regeneration or local rule correction, failing to effectively distinguish whether the error originates from the initial configuration, the current state, or historical nodes, leading to blind and insufficiently targeted repairs. Third, they ignore knowledge temporal dependencies and lack historical state backtracking and repair mechanisms. The state evolution of security protocols exhibits strict temporality and knowledge accumulation; current anomalies are highly likely caused by defects in previous states. Existing solutions lack backtracking and repair mechanisms, leading to subsequent states often being built upon errors, making it difficult to guarantee the self-consistency of global logic. Fourth, evaluation metrics are generalized, lacking fine-grained consistency verification oriented towards protocol semantics. Existing technologies largely rely on general metrics such as accuracy and F1 scores, lacking verification methods that deeply and recursively compare the generated model with the baseline model across multiple dimensions, including participants, operation sequences, and message interactions, making it difficult to accurately quantify and evaluate the true quality and usability of the generated model.
[0032] In view of this, one aspect of the present invention provides a logical repair method for a security protocol state machine, such as... Figure 1 As shown, the method includes the following steps S101~S104: Step S101: Obtain the security protocol state machine to be processed, which is automatically generated or manually constructed by the large language model. Parse and normalize the security protocol state machine to be processed, and extract the protocol name, the set of participants, the initial knowledge set of the participants, the state nodes, and the state transition relationships between the state nodes.
[0033] Step S102: Along the state path formed by the state transition relationship, based on the initial knowledge of each participant, the knowledge passed by the preceding state node, the message fields received by the current state node, and the state operation output of the current state node, dynamically maintain the available knowledge set of each participant; based on the preset state machine structure template, the identification and reference relationship of the state node, the state transition relationship, the available knowledge set, and the message interaction relationship between the participants, perform structural and semantic checks on the security protocol state machine to be processed, and generate structured anomaly results.
[0034] Step S103: For rule-based structured anomalies, repair is performed directly based on the rules; for non-rule-based structured anomalies, the cause of the anomaly is analyzed and candidate repair targets are determined based on the anomaly type, anomaly object, anomaly location, associated object, and anomaly context recorded therein. Candidate repair targets include initial knowledge layer targets, current state layer targets, historical state layer targets, subsequent state layer targets, or communication event layer targets. The various candidate repair targets are then distributed and targeted for repair according to a preset priority. For historical state layer targets, repair is performed by tracing back to the historical state node, and the subsequent state path affected by the repair is reconstructed from this node. The available knowledge set of the affected participants is then updated along this subsequent state path.
[0035] Step S104: For the repaired security protocol state machine, re-execute the structural check and semantic check according to the repair scope. After the re-verification is passed, the final security protocol state machine is obtained.
[0036] In some embodiments, the method further includes a consistency verification phase, including steps S201 to S204: Step S201: Take the final security protocol state machine after logic repair as the security protocol state machine to be verified, obtain the baseline state machine corresponding to the security protocol state machine to be verified, and parse and normalize the security protocol state machine to be verified and the baseline state machine respectively, extracting their respective protocol names, participant sets, participant initial knowledge sets, state nodes, and state transition relationships between state nodes.
[0037] Step S202: Align the participants based on the identification information and protocol semantic information of the participants in the security protocol state machine to be verified and the baseline state machine, and align the knowledge items in the initial knowledge sets of the mutually aligned participants to establish element alignment relationships.
[0038] Step S203: Starting from the initial state nodes of the mutually aligned participants, recursive matching is performed while maintaining the state transition relationships between the security protocol state machine to be verified and the baseline state machine. For the currently corresponding state nodes, based on the element alignment relationship, at least one of the following is matched: receive event, in-state operation, conditional branch, guard condition, send event, and subsequent state pointer. The number of successful matches, the number of missing matches, and the number of redundancies are determined with reference to the baseline state machine. The corresponding subsequent state nodes are determined according to the state transition relationship. The updated element alignment relationship is passed to the subsequent state nodes to continue recursive matching until the preset recursive termination condition is met.
[0039] Step S204: Based on the results of recursive matching, the number of successful matches, missing numbers, and redundant numbers are counted for each state machine element of the preset type. Based on this, the consistency evaluation index is calculated to obtain the overall consistency result, the sub-item consistency result, and the inconsistency location of the security protocol state machine to be verified relative to the baseline state machine.
[0040] In step S101, the logic repair method begins by acquiring a security protocol state machine to be processed. This security protocol state machine can be automatically generated after analyzing RFC documents describing natural language using large language models such as GPT-4 and Gemini, or it can be manually constructed by protocol designers or security analysts using specific modeling tools, such as UML state diagram tools or custom editors. The core purpose of this step is to transform state machine models from diverse sources and potentially inconsistent formats into a structured and standardized internal representation that can be uniformly processed in subsequent steps of the present invention.
[0041] When performing this step, the first step is to define the specific data structure of the core object—the security protocol state machine. In a preferred embodiment, the security protocol state machine to be processed is stored in a general, serializable format, such as a JSON or YAML file. This file has a hierarchical data structure. The top level contains protocol metadata, such as the `protocol_name` field. Below that is a `participants` field, which is a list of objects, each representing a protocol participant, such as a client or server. Each participant object contains an `initial_knowledge` field, a list of strings used to store the knowledge that the participant possesses at the start of the protocol, such as long-term public / private keys, certificates, or pre-shared keys. Furthermore, each participant object also contains a `states` field, a list of state node objects representing all possible states of the participant during protocol execution. Each state node object contains key information such as the state name, received events, operations within the state, conditional branches, sent events, and subsequent state pointers, collectively constituting the dynamic behavioral logic of the protocol. This JSON or YAML-based representation not only has good readability and scalability but also facilitates parsing by subsequent programs.
[0042] After obtaining the state machine file, the method processes it through a parser module. This parser module, executed by the computer processor, first reads the state machine file from storage media, such as hard drive or network storage, into memory. Next, according to a predefined format specification, such as a JSON Schema file, it performs syntax parsing on the file content, deserializing it from text format into a series of object instances in the program's memory. For example, in Python, this could be a series of interconnected custom class objects, such as Protocol, Participant, and StateNode classes. This process is called parsing and normalization. During parsing, the method systematically extracts key information, including the protocol name, a set containing all participant identifiers, a dictionary mapping participant identifiers to their initial knowledge lists (i.e., the participant initial knowledge set), and a set containing all state nodes. Simultaneously, by analyzing the next_state field in each state node, a directed graph can be constructed to represent the state transition relationships between state nodes. This graph can be represented as an adjacency list or adjacency matrix and stored in memory, laying the foundation for subsequent state path traversal.
[0043] The implementation of this step aims to address the fundamental problem in the background technology where the diverse sources and inconsistent formats of protocol descriptions hinder automated analysis. By forcibly unifying all inputs into a standardized internal data structure, this invention provides a stable and reliable data foundation for subsequent deep semantic inspection and logical repair steps. This avoids the enormous cost of developing a separate analysis tool for each different input format, significantly improving the versatility and applicability of the entire method. It provides the most original and fundamental data support for subsequent steps to identify the origin of knowledge and how states transition, serving as the entry point and cornerstone of the entire automated repair process.
[0044] In another embodiment, the format of the security protocol state machine to be processed is not limited to JSON or YAML. For example, it can be an XML-based format, such as SCXML (State Chart XML), in which case the parser will use an XML parsing library, such as Python's xml.etree.ElementTree, for processing. In another alternative, if the state machine is generated by a specific modeling tool, it may exist in a proprietary binary format, requiring the use of the tool's API or SDK to read and export the model information. Furthermore, the extraction of the initial knowledge set of the participants can be designed more intelligently than simply reading from fields. For example, it can automatically identify the type of knowledge through pattern matching, such as identifying a public key based on the 'pk_' prefix and a private key based on the 'sk_' prefix, and store it as a richer knowledge object. This object contains not only the knowledge name but also meta-information such as its type and source, thus facilitating subsequent more refined semantic checks. This approach can further enhance the depth and accuracy of subsequent checks.
[0045] In step S102, the method of the present invention enters its core inspection phase. The goal of this step is to perform in-depth structural and semantic checks on the normalized security protocol state machine, thereby accurately identifying logical defects hidden beneath the correct syntax. This step is a crucial bridge connecting the original model with subsequent repair steps, and the accuracy and granularity of its output directly determine the effectiveness of the entire repair process.
[0046] One of the core aspects of this step is the dynamic maintenance of the available knowledge set. In a preferred embodiment, the available knowledge set is a dictionary data structure with participant identifiers as keys and string sets as values. This structure is used to track in real time all knowledge fragments held by each participant at any given moment during protocol execution, such as variable names, key identifiers, and random numbers. Another core concept is a pre-defined state machine structure template, which can be a JSON Schema file. This template strictly defines the required fields, data types, and formats for each element in the state machine model. For example, a state node must contain fields such as `state_name`, `actions`, and `next_state`. The structured exception results generated during the inspection process are a list containing multiple exception objects. Each exception object is a dictionary or custom class instance, which records in detail the unique identifier of the exception, the exception type (e.g., `KNOWLEDGE_SOURCE_ERROR`, `UNREACHABLE_STATE`), the specific location where the exception occurred (e.g., participant and state node names), and related contextual descriptions. Specific exception types, such as knowledge source exceptions, are determined to occur when an operation within a state node attempts to use knowledge that does not exist in the currently available knowledge set of its participating participant. The message sending and receiving mismatch exception is determined to occur when a message sent by a participant does not match the message that the communication peer expects to receive in the corresponding state, including message name and fields.
[0047] At the underlying technical implementation level, the algorithm logic for this step is executed in memory by the computer's central processing unit. The algorithm first initializes the available knowledge set for all participants, typically containing only their initial knowledge. Then, the algorithm employs a graph traversal strategy, preferably depth-first search, starting from each participant's initial state node and exploring along the paths formed by state transition relationships. Upon reaching each state node, the algorithm first simulates the execution of the logic within that node: adding the received message fields and in-state operations, such as generating new random numbers or key outputs, to the current participant's available knowledge set, thereby dynamically updating the knowledge set. Next, the checking module is activated. In terms of structural checking, the algorithm verifies whether the next state identifier pointed to by the current state node's `next_state` field actually exists in the state machine model; if not, a state transition anomaly is recorded. After traversing all paths, by comparing the set of all visited state nodes with the total set of state nodes, any unvisited isolated states can be identified. In terms of semantic checks, for each operation in the state node, such as encryption and signing, the algorithm checks whether all required input knowledge, such as keys and data, exists in the available knowledge set of the current participants. If not, a structured result indicating a knowledge source anomaly is generated. Simultaneously, for the action of sending a message, the algorithm searches for the receiver's definition in the corresponding state and compares the sent and received message signatures. If they do not match, a message transmission mismatch anomaly is recorded. All detected anomalies are formatted into the aforementioned structured anomaly result object and added to a global anomaly list.
[0048] The fundamental purpose of this step is to overcome the limitations of existing technologies that only perform surface-level syntax checks and cannot detect deep-seated logical errors in the protocol. Through a unique dynamic knowledge tracking mechanism, this invention can simulate the entire protocol execution process, rigorously verifying the knowledge prerequisites for each operation, thereby accurately capturing semantic vulnerabilities caused by knowledge transfer errors, improper operation sequences, or message interaction mismatches. It addresses the core pain point of the background technology, which lacks in-depth semantic logic checks. Furthermore, by generating highly structured and information-rich anomaly results, this step provides precise targets for subsequent repair processes, completely changing the coarse-grained and insufficiently targeted nature of traditional repair methods. It is a crucial prerequisite and data input for realizing subsequent rule-based and targeted repair strategies.
[0049] To broaden the scope of protection of this invention, various alternative or modified implementations exist for this step. For example, when dynamically maintaining the available knowledge set, in addition to using a simple string set, a more advanced data structure, such as a dictionary, can be employed, where the key is the knowledge name and the value is an object containing the knowledge source, such as which state node or message and type it comes from. This approach can provide richer tracing information when anomalies are detected. During structure checks, in addition to finding isolated states through traversal and comparison, the in-degree of each state node can be pre-calculated during the parsing phase. Any node that is not an initial state and has an in-degree of zero can be directly determined as an isolated state, which is more efficient in certain scenarios. For the implementation of the preset state machine structure template, in addition to external schema files, it can also be a set of rules hard-coded in the program code, or implicitly implemented through class definitions and constructors in object-oriented programming, as long as it can serve to constrain and verify the model structure. Finally, the determination of abnormal knowledge sources can be further refined. It not only checks whether the knowledge exists, but also whether its type meets the operational requirements. For example, an encryption function must use knowledge of type encryption key, rather than signature key. This can achieve a deeper level of semantic correctness verification.
[0050] In some embodiments, the structural inspection includes steps S301 to S304: Step S301: Based on the preset state machine structure template, perform existence, data type, and hierarchical relationship checks on the protocol name, participant set, participant initial knowledge set, and corresponding fields of the state nodes in the security protocol state machine to be processed; if necessary fields are missing, field data types do not meet preset requirements, or hierarchical relationships do not meet preset requirements, generate a structural format anomaly; wherein, the corresponding fields of the state nodes include at least one of the following: receive event, in-state operation, conditional branch, guard condition, send event, and subsequent state pointer.
[0051] Step S302: Based on the identifier and reference relationship of the state node, perform a consistency check on the state name and the reference name of the referenced state name, and perform a duplicate check on the state names under the same participant; when the state name and the corresponding reference name are inconsistent, generate a state reference inconsistency exception; when there are duplicate state names under the same participant, generate a state name conflict exception.
[0052] Step S303: Based on the state transition relationship, check whether the subsequent state points to an existing state node, a terminated state, or a cyclic state, whether the non-starting state node has a reachable preceding state, and whether the cyclic target corresponding to the cyclic state is valid; when the subsequent state points to an existing state node, a terminated state, or a cyclic state that meets the preset conditions, the non-starting state node does not have a reachable preceding state, or the cyclic target does not meet the preset cyclic pointing conditions, generate state connection anomaly, isolated state anomaly, or cyclic pointing anomaly respectively.
[0053] Step S304: Generate the corresponding structured exception result based on at least one of the following: structure format exception, state reference inconsistency exception, state name conflict exception, state connection exception, isolated state exception, and circular pointer exception.
[0054] In some embodiments, semantic checking includes steps S401 to S405: Step S401: Based on the available knowledge set of each participant, according to the state path and the execution order of operations within the state, check the knowledge source of the input parameters of the operations within the state, the variables referenced by the guard conditions, and the sending fields in the sending event, and take the output parameters generated by the operations within the state as the newly added available knowledge of the corresponding participant; when the input parameters, the variables referenced by the guard conditions, or the sending fields do not belong to the available knowledge of the corresponding participant at the corresponding execution position and do not belong to the predefined constants, a knowledge source exception is generated.
[0055] Step S402: Based on the guard conditions and condition branches in the state node, check the comparison relationship of the guard conditions and the in-state operations, sending events and subsequent state pointers corresponding to different condition branches; when the guard condition has the same variable compared with itself, a guard condition exception is generated; when multiple condition branches correspond to the same in-state operations, sending events and subsequent state pointers, a duplicate branch exception is generated.
[0056] Step S403: Based on the message interaction relationship between the participants, check the correspondence between the participants, event names, and message fields in the corresponding sending and receiving events, and check the naming relationship between the receiving fields and the existing knowledge of the receiving participants, as well as the target participant corresponding to the sending event; when the sending event and the receiving event do not meet the preset correspondence, generate a message sending and receiving mismatch exception; when the receiving field has a naming conflict with the existing knowledge, generate a receiving field conflict exception; when the sending target participant does not exist, generate a sending target exception.
[0057] Step S404: Check the combination and decomposition operations in the state operations and condition branch operations; when the combination or decomposition operation only changes the organization of the field, does not generate new protocol semantics or cryptographic calculation results, and the intermediate field it introduces affects the source tracing of the original field in the subsequent state operation input, guard condition or sent field, it is identified as a redundant compound operation and a compound operation redundancy anomaly is generated.
[0058] Step S405: Generate a corresponding structured exception result based on at least one of the following: knowledge source exception, guard condition exception, duplicate branch exception, message sending and receiving mismatch exception, receive field conflict exception, sending target exception, and compound operation redundancy exception.
[0059] In step S103, the method of the present invention enters the crucial logic repair stage. The core of this step is to deploy a multi-layered, differentiated intelligent repair scheduling system, which can automatically select and execute various repair strategies, ranging from simple rule matching to complex logic backtracking, based on the nature and root cause of the anomaly, thereby achieving accurate and efficient automated correction of the protocol model.
[0060] This step first identifies and categorizes the structured anomaly results generated in the previous stage. Specifically, anomalies are divided into two main categories: regular structured anomalies and irregular structured anomalies. Regular anomalies refer to low-level errors with clear error patterns and deterministic repair paths. In a preferred embodiment, this includes at least state reference inconsistency anomalies, mergeable state name conflict anomalies, receive field conflict anomalies, duplicate branch anomalies, and compound operation redundancy anomalies. In contrast, irregular anomalies refer to deep logical errors with more complex causes, requiring in-depth reasoning and contextual analysis, such as the aforementioned knowledge source anomalies. For the former, the system directly applies a predefined set of repair rules for correction; for the latter, a more refined analysis and targeted repair process is initiated. This process first analyzes the anomaly context and generates a set of candidate repair targets. These targets are hypotheses for locating the root cause of the anomaly at different levels in the state machine model, specifically including: initial knowledge layer targets, current state layer targets, historical state layer targets, successor state layer targets, or communication event layer targets.
[0061] At the underlying technical implementation level, this step is performed by a central repair scheduler running on the computer's central processing unit. The scheduler receives a list of exception objects as input and processes them one by one. For each exception, the scheduler first checks its exception type field. If the type matches a regular exception library, the system will directly execute the corresponding repair action. For example, in cases of inconsistent state references, the system will automatically correct the incorrect reference name based on the actual name of the referenced state node. In cases of mergeable state name conflicts, the system will merge multiple state nodes with the same name into a single node after confirming that their internal logic, such as receiving events, operations, and subsequent pointers, is completely consistent, and redirect all related entry transitions. In cases of conflicting receive fields, the system will rename the conflicting fields according to preset naming rules, such as adding a prefix, and synchronously update all subsequent references. In cases of duplicate branches, the system will merge multiple branches with the same execution body and connect their guard conditions using a logical OR. In cases of redundant composite operations, the system will analyze their input-output relationships. If it is a redundant combined operation, the system will directly delete the operation and replace the subsequent references with its input fields. If it is a redundant decomposition operation, the system will delete the operation and allow the preceding operation to directly output the decomposed field set.
[0062] When an anomaly is determined to be irregular, the scheduler enters a priority-based targeted repair process. Based on a set of preset priority rules, combined with information such as the anomaly type and context, it selects the most likely repair target from multiple candidate targets. For example, a knowledge source anomaly might first suspect a problem in the initial knowledge layer or the historical state layer. Once the priority candidate repair target is determined, the scheduler assigns the repair task to the corresponding targeted repair mechanism. If the target is the initial knowledge layer, the system adds the missing knowledge items to the initial knowledge set of the corresponding participant and triggers a small-scale re-check; if the target is the communication event layer, the system modifies the parameters of the sent or received events to ensure matching of message interactions; if the target is the current state layer or the subsequent state layer, the system calls the state generation method to regenerate or supplement the missing state nodes and seamlessly integrates them into the existing state path.
[0063] Crucially, when priority analysis points to the historical state layer as the repair target, the system activates its most powerful and unique historical state backtracking and repair mechanism. This mechanism first traces back along the state path based on anomaly information, such as missing variable names or mismatched messages, precisely locating the historical state node that caused the problem. Once located, the system calls the state generation method to regenerate that historical state node to correct its internal logic. Next, to maintain the logical consistency of the entire protocol, the system decisively reverts and discards all subsequent states built on the erroneous historical node. Then, using the repaired and refreshed historical state node as a new starting point, it reconstructs the subsequent state paths step by step along the correct state transition relationships. During this rebuilding process, the system synchronously and dynamically updates the available knowledge sets of all affected participants, ensuring that each newly generated state is built on a completely correct knowledge foundation, thereby achieving fundamental repair of logical errors and restoration of global consistency.
[0064] The fundamental purpose of this design is to establish an automated repair framework capable of simulating the thinking of expert analysts. It completely solves the core pain points of existing technologies, such as simplistic repair strategies, inability to handle complex temporal dependency errors, and the potential introduction of new problems after repair. By combining rule-based and targeted repair, and prioritization analysis with historical backtracking, this invention achieves layered diagnosis and fundamental treatment of protocol logic errors. This not only significantly improves the automation and accuracy of repair but also ensures the global logical self-consistency of the repaired model through an innovative backtracking and reconstruction mechanism, providing unprecedented high-quality input for subsequent formal verification or code generation.
[0065] As an alternative embodiment of the present invention, the preset priority rule for determining the priority of irregular anomaly repairs is not limited to hard-coded logic, but can employ a lightweight machine learning classifier. By training on a large dataset of protocol defects and repair cases, the model can learn a complex mapping from anomaly features to the optimal repair strategy, thereby achieving more adaptive intelligent decision-making. Furthermore, when executing the historical state backtracking repair mechanism, in addition to completely reversing and rebuilding all subsequent states, a more refined incremental dependency update strategy can be adopted. This strategy pre-analyzes and maintains a fine-grained dependency graph between states. When a historical node is repaired, the system only reverses and rebuilds downstream nodes in the graph that are directly or indirectly affected by its changes, thereby significantly reducing the computational overhead of repairing large and complex protocol state machines while ensuring logical correctness.
[0066] In some embodiments, the repair of rule-based structured anomalies is performed directly based on rules, including steps S501 to S506: Step S501: The structured anomaly results of the regular type include at least one of the following: inconsistent state reference anomaly, mergeable state name conflict anomaly, received field conflict anomaly, duplicate branch anomaly, and compound operation redundancy anomaly, and are classified and repaired according to the anomaly type.
[0067] Step S502: For state reference inconsistency exceptions, take the state name of the generated state node pointed to by the reference position as the reference and modify the reference name at the reference position to the state name, so that the reference name is consistent with the state name of the state node it points to.
[0068] Step S503: For mergeable state name conflict exceptions, when the received events, in-state operations, conditional branches, sent events, and subsequent state pointers of multiple state nodes with duplicate state names under the same participant are consistent, the multiple state nodes are merged, and the references pointing to the merged state node are uniformly updated to point to the merged state node.
[0069] Step S504: For received field conflict exceptions, when the received field has the same name as the existing knowledge item of the current participant but represents different semantic objects, the received field is renamed according to the preset field naming rules, and the references to it in subsequent guard conditions, in-state operations and sending events are updated synchronously.
[0070] Step S505: For duplicate branch exceptions, when the operation, event sent and subsequent state of multiple condition branches are the same, the multiple condition branches are merged and a merged guard condition is formed according to the logical relationship between their guard conditions to replace the original guard condition.
[0071] Step S506: For redundant operations, when the corresponding redundant composite operation is a combination operation, delete the combination operation according to the correspondence between the output fields and input field sets of the combination operation recorded during the inspection process, and replace the subsequent references to the output fields with the corresponding input field sets; when the corresponding redundant composite operation is a disassembly operation, delete the disassembly operation according to the correspondence between the input fields and output field sets of the disassembly operation recorded during the inspection process, and modify the output of the preceding operation that generated the input fields to the corresponding output field sets.
[0072] In some embodiments, targeted repair is performed on various candidate repair targets according to preset priorities, including steps S601 to S606: Step S601: Based on the preset priority rules, determine the priority of each candidate repair target according to the anomaly type, associated object and anomaly context, select the priority candidate repair target, and divert the structured anomaly results to the targeted repair mechanism corresponding to the priority candidate repair target.
[0073] Step S602: When the priority candidate repair target is the initial knowledge layer target, determine the missing knowledge and its participating parties based on the abnormal object, abnormal location, associated object and abnormal context, add the missing knowledge to the initial knowledge set of the corresponding participating party, and re-execute the knowledge source check of the affected state node based on the repaired initial knowledge set.
[0074] Step S603: When the priority candidate repair target is the current state layer target, the state generation method corresponding to the current state node is called according to the structured anomaly result to regenerate the current state node, and the original current state node is replaced by the regenerated current state node before connecting to the original state path.
[0075] Step S604: When the priority candidate repair target is the successor state layer target, determine the missing successor state node based on the structured anomaly result, call the corresponding state generation method to generate the successor state node, and connect it to the corresponding state path according to the state transition relationship of the current state node.
[0076] Step S605: When the priority candidate repair target is a historical state layer target, the structured abnormal results are diverted to the historical state backtracking repair mechanism.
[0077] Step S606: When the priority candidate repair target is the communication event layer target, determine the abnormal sending event or receiving event according to the message interaction relationship, and correct the participant identifier, event name or message field in the sending event or receiving event in its state node so that the sending event and the corresponding receiving event meet the preset correspondence relationship.
[0078] In some embodiments, the historical state retrospective repair mechanism includes steps S701 to S704: Step S701: When the priority candidate repair target is a historical state layer target, determine the historical state node corresponding to the cause of the anomaly in the state path before the current state node based on the anomaly type, anomaly object, associated object and anomaly context in the structured anomaly result; for anomaly variables that should be generated or transmitted by the preceding state node, determine the corresponding historical state node based on its knowledge source; for cases where the received event of the current state node does not correspond to the preceding sent event, determine the historical state node containing the corresponding sent event based on the message interaction relationship.
[0079] Step S702: Call the state generation method corresponding to the historical state node to regenerate the historical state node, and replace the original historical state node with the regenerated historical state node.
[0080] Step S703: Undo the existing construction results of subsequent state nodes affected by the repair of historical state nodes, and reconstruct the affected subsequent state paths based on the regenerated state transition relationships, starting from the regenerated historical state nodes.
[0081] Step S704: In the process of reconstructing the subsequent state path, based on the initial knowledge of each participant, the knowledge passed by the preceding state node, the message fields received by the current state node, and the state operation output of the current state node, the available knowledge set of the affected participants is updated along the subsequent state path.
[0082] In step S104, the method of the present invention enters a crucial closed-loop verification phase. The core of this step is to establish an iterative, range-focused regression verification mechanism to ensure that the repair operation not only resolves known anomalies but also does not introduce new, unforeseen logical defects, thereby guaranteeing the overall correctness and robustness of the final output security protocol state machine model.
[0083] The core concept of this step is the precise definition of the repair scope and the state check scope. In a preferred embodiment, the repair scope refers to the set of all elements directly modified or indirectly affected in the previous step S103, such as modified initial knowledge, regenerated state nodes, or updated communication events. The state check scope is dynamically determined based on the repair scope, and consists of state path segments or sets of state nodes that require re-structural and semantic checks. The endpoint of this step is determined by a preset condition, which can be simply set as an empty list of structured anomaly results, or more loosely set as no longer containing anomalies with a severity level higher than a certain threshold in the structured anomaly results. This iterative verification and repair process ensures the convergence of the entire repair process and the quality of the final result.
[0084] At the underlying technical implementation level, this step is designed as an iterative loop control logic driven by the computer CPU. After each repair action in S103 is completed, the system does not immediately process the next original exception, but first enters the verification loop in S104. The system records the objects affected by this repair operation. For example, if a historical state node S_hist of participant A is repaired, then the repair scope includes S_hist and all subsequent reconstructed state nodes. Next, the system determines this repair scope as the scope of the current state check and calls the check module in step S102, but only performs structural and semantic checks on the states, transitions, and knowledge paths within this scope. This local rather than global check approach greatly improves verification efficiency. After the check is completed, the system obtains an updated list of structured exception results.
[0085] Subsequently, the system checks whether the new anomaly list meets the preset conditions. If not, meaning there are still anomalies to be processed, the entire process will seamlessly and iteratively return to the repair logic entry point in step S103. These newly discovered anomalies will be reclassified as regular or irregular, and a new round of priority analysis and targeted repair will be initiated. After each repair is completed, the system will redetermine the scope of the affected state checks, execute the local checks in S104 again, and update the anomaly list. This closed loop of repair, checking, and re-repairing will continue until, after a certain local check, the generated structured anomaly result list finally meets the preset termination conditions. At this point, the loop terminates, and the rigorously tested protocol model is confirmed as the final qualified security protocol state machine, which can be serialized into formats such as JSON and YAML and stored back to the hard disk file system or database for subsequent use.
[0086] The fundamental purpose of this step is to overcome the inherent flaws of traditional one-off repair methodologies, namely, the inability to guarantee the side effects and global consistency of the repair operation. In complex protocol logic, fixing one error is highly likely to trigger new, more subtle errors elsewhere. This invention addresses this core pain point by introducing an iterative, closed-loop verification mechanism focused on the scope of the repair's impact. It decomposes large, complex global verification problems into a series of small, local, iterative verification tasks, which not only greatly improves the efficiency and accuracy of the repair process but, more importantly, provides a rigorous quality convergence guarantee for the entire automated repair process. This closed-loop approach of repairing and verifying simultaneously until perfection is key to ensuring that the final model meets high-quality standards suitable for formal analysis or direct code generation.
[0087] As an alternative or variation of this step, when determining the scope of state checks, in addition to simply including all objects affected by the repair, a more refined method based on dependency propagation analysis can be adopted. The system can pre-construct a detailed dependency graph between state and knowledge. When a node is repaired, the scope of inspection is limited to all downstream dependencies of that node in the graph, thereby further narrowing the verification scope and improving efficiency. Another variation is that, for the termination condition of the loop, in addition to checking whether the anomaly list is empty, a maximum iteration limit can be introduced. When the number of iterations exceeds a preset threshold but still cannot eliminate all anomalies, the system can determine that the protocol model may have a fundamental design flaw that cannot be automatically repaired, terminate the process, and output a detailed diagnostic report, handing the problem over to human experts for intervention. This circuit breaker mechanism can effectively prevent the repair process from falling into an infinite loop in some extreme cases, enhancing the robustness of the entire system.
[0088] In some embodiments, the repaired security protocol state machine is subjected to cyclical structural and semantic checks according to the repair scope until the structured anomaly result meets preset conditions, including steps S801-S802: Step S801: After completing rule-based repair or targeted repair, based on the objects and locations involved in this repair, update at least one of the state transition relationships, available knowledge sets, and message interaction relationships affected by this repair, and determine the affected part as the state check scope. Re-execute structural and semantic checks on the state check scope and update the structured anomaly results.
[0089] Step S802: When there are still unprocessed anomalies in the updated structured anomaly results, re-determine whether the unprocessed anomalies are regular or irregular; for regular anomalies, repair them based on the corresponding rules; for irregular anomalies, re-locate the cause of the anomaly, determine the candidate repair targets, and perform targeted repair according to the preset priority; after each repair, redetermine the scope of the state check, perform structural and semantic checks, and update the structured anomaly results until the updated structured anomaly results meet the preset conditions.
[0090] In steps S201-S204, after completing the aforementioned logical repair and closed-loop verification to obtain an internally logically self-consistent security protocol state machine, in a preferred embodiment of the present invention, a final consistency verification stage is further included. The purpose of this stage is to objectively and quantitatively evaluate the semantic equivalence between the repaired model and an authoritative benchmark model from an external perspective, thereby providing a final and measurable proof of the effectiveness of the entire automated generation and repair process.
[0091] This phase begins with step S201, the preparation work. The system uses the final security protocol state machine, which has been fully repaired and verified, output from the previous phase as the security protocol state machine to be verified. Simultaneously, the system needs to obtain a baseline state machine. This baseline state machine serves as a gold standard or a reference point of fact, and its source can be diverse: it can be an idealized, hand-constructed correct model corresponding to the original protocol draft or requirements document initially used to inspire the generation of a large language model; it can also be a verified similar protocol model from an authoritative protocol library. Subsequently, the system performs independent parsing and normalization on these two state machines. Normalization is a crucial preprocessing step, aiming to eliminate non-semantic, superficial differences between the two, such as uniformly converting the names of all state nodes and knowledge items to capitalization, and sorting the list-based knowledge sets to ensure fairness in subsequent comparisons. After this process, the system extracts core structured information from both models, including the protocol name, the set of participants, the initial knowledge set of each participant, all state nodes and their internal details, and the state transition relationships defining the protocol flow.
[0092] Next, the method proceeds to step S202, performing crucial element alignment. This step aims to establish a one-to-one correspondence between equivalent elements in the model to be verified and the benchmark model, forming an element alignment mapping. In a typical implementation, this mapping can be a dictionary structure maintained in computer memory. The alignment process begins with the top-level participants, matching them based on their identification information or their semantic roles in the protocol. After aligning the participants, the system further aligns their respective initial knowledge sets by comparing the names and types of knowledge items, for example, mapping the public key pkA of participant A in the model to be verified to the public key pkC of the corresponding participant Client in the benchmark model. This continuously expanding element alignment mapping forms the basis for subsequent deep comparisons.
[0093] After the alignment relationship is established, step S203 initiates the core recursive matching algorithm. This algorithm executes on the computer CPU, comparing the behavior of two state machines one by one by simulating their synchronous operation. The algorithm uses mutually aligned initial state nodes as the entry point for recursion, for example, the initial state of participant A in the two models. In one recursive step, the algorithm processes a pair of currently corresponding state nodes. It utilizes the existing element alignment mapping to perform a detailed comparison of the logical elements within the two nodes. These elements include at least received events, in-state operations, conditional branches and their guard conditions, sent events, and pointers to subsequent states. During the comparison, the baseline state machine is used as a reference: if an event or operation existing in the baseline node finds a corresponding and aligned element in the node to be verified, it is recorded as a successful match; if it exists in the baseline node but cannot be found in the node to be verified, it is recorded as a missing element; conversely, if it exists in the node to be verified but cannot be found in the baseline node, it is recorded as a redundancy. After completing the comparison of the current node, the algorithm determines the corresponding successor state node pairs based on the state transition relationships. It then updates the element alignment relationship mapping with any newly generated, alignable knowledge items in the current state, and passes this updated mapping to the next recursive call for the successor node pair. This recursive process continues until all reachable state paths have been traversed, or other preset recursion termination conditions are met, such as reaching the maximum recursion depth.
[0094] Finally, in step S204, the system summarizes and analyzes the results of the entire recursive matching process. During execution, the recursive matching algorithm accumulates the number of successful matches, missing matches, and redundancies for various preset state machine element types, such as state nodes, sending events, and guard conditions. In this step, the system calculates a series of consistency evaluation indicators based on these raw counts. For example, it can calculate the integrity of a certain element type as the number of successful matches / (number of successful matches + number of missing matches) and the accuracy as the number of successful matches / (number of successful matches + number of redundancies). Ultimately, the system generates a detailed consistency verification report. This report not only includes an overall, quantitative consistency score but also provides the consistency results for each sub-item, such as message interaction, cryptographic operations, and conditional logic. It can also accurately list the specific locations, types, and contents of all inconsistencies, providing developers with valuable and actionable insights for evaluating the effectiveness of repairs and making final manual fine-tuning.
[0095] The irreplaceable role of this consistency verification phase lies in providing a final, objective, and quantifiable quality guarantee for the entire automated protocol model generation and repair system. Existing technologies often stop at eliminating internal errors, failing to address the fundamental question of whether the repaired model is truly the desired one. This phase, by introducing a benchmark comparison with the gold standard, elevates the evaluation from syntactic correctness to semantic equivalence for the first time. The quantitative metrics and inconsistency location it provides offer a solid data foundation for measuring system performance and iteratively improving algorithms, ultimately building a bridge of trust between humans and machines regarding the correctness of the protocol model.
[0096] As an alternative or variation of this stage, when performing element alignment in step S202, in addition to hard matching based on names and preset roles, a large language model can be introduced for semantic-assisted alignment. For example, when the names of two state nodes are not exactly the same, such as Wait_For_Key and Await_Secret, the LLM can be queried to determine whether the two names express the same or similar intent in the context of the security protocol, thereby achieving a more robust and intelligent alignment. Another variation is in the matching algorithm of step S203, where, in addition to using strict recursive path matching, graph edit distance or maximum common subgraph algorithms from graph theory can be referenced. This method does not require the two state machines to have exactly the same topology, but rather calculates the minimum operational cost required to transform one graph into another, thereby obtaining a more flexible overall similarity score, which is particularly suitable for evaluating protocol models that have reasonable variations in structure but consistent core logic.
[0097] On the other hand, the present invention also provides a logic repair system for a security protocol state machine, including a processor, a memory, and a computer program or instructions stored in the memory. The processor is used to execute the computer program or instructions, and when the computer program / instructions are executed, the system implements the steps of any of the methods described above.
[0098] On the other hand, the present invention also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of any of the methods described above.
[0099] The present invention will now be described with reference to a specific embodiment: This embodiment provides a method for logical repair and consistency verification of automatically generated security protocol state machines. The security protocol state machine can be generated by large language models, rule extraction, manual-assisted modeling, model conversion tools, or other automated methods.
[0100] This method does not limit the generation method, input timing, generation granularity, storage format, field names, or state organization of the security protocol state machine. The security protocol state machine to be processed can be input as a complete state machine all at once after all states have been generated, or it can be input gradually during the state-by-state or phased generation process. The state machine can be represented in JSON, YAML, XML, table structure, graph structure, state transition diagram, or other structured or semi-structured forms, as long as it can directly provide or, after parsing, yield protocol semantic information such as participants, state nodes, message events, operation steps, knowledge items, conditional branches, and successor pointers, it can be used as the input object of the method in this embodiment.
[0101] The core of this embodiment lies in constructing a state machine processing flow based on the knowledge evolution of participating parties, using anomaly repair target diversion and historical state backtracking repair as means, and benchmark state machine consistency verification as the evaluation basis. This flow, through unified input, structural and semantic checks, targeted repair, and consistency verification of automatically generated state machines, elevates the state machine from parsable to a structurally complete, logically self-consistent, and verifiable state machine model. The benchmark state machine referred to in this embodiment is a reference state machine written or verified by domain experts, or generated from trusted sources such as formal models or reference implementations, used as a benchmark for comparing the structural and semantic consistency of the state machine to be evaluated.
[0102] like Figure 2 As shown, the method in this embodiment generally includes a state machine input and normalization module, a state machine inspection module, a state machine repair module, a consistency verification module, and a result output module. These modules work collaboratively in the order of input, inspection, repair, verification, and output, forming a closed-loop iterative relationship between inspection and repair. Specifically: 1. State Machine Input and Normalization Module This module is used to obtain the state machine of the security protocol to be processed. The state machine can be generated by extracting it from the protocol's natural language document using a large language model, or by rule extraction, manual-assisted modeling, formal model transformation, or a combination of these methods. This module parses, standardizes, and normalizes the input state machine, converting it into a unified representation that can be used for subsequent state machine checks, state machine repairs, and consistency verification.
[0103] In different implementations, this module can standardize the state name, participant identifier, event field, operation parameter, condition expression and transition target to eliminate format differences caused by different state machine sources, different representation forms or different naming styles.
[0104] 2. State machine inspection module This module is used to perform structural and semantic checks on the input state machine, identify structural anomalies, knowledge dependency anomalies, conditional logic anomalies, and message field source anomalies in the state machine, and output structured anomaly results for subsequent repair modules to call.
[0105] Specifically, the module dynamically maintains the known knowledge set of each participant along the state transition path, checks whether the input variables of the operation within the state can be derived from the initial knowledge, the received message field, the output of the previous operation in the current state, or the inherited knowledge of the previous state; checks whether the operation output is correctly added to the knowledge set; checks whether the fields in the received event and sent event have a clear source; and checks whether the conditional branches, guard conditions, target states, and state connection relationships satisfy the protocol flow constraints.
[0106] When an anomaly is detected, this module generates a structured anomaly result according to a unified field format. The structured anomaly result includes the anomaly type, anomaly object, anomaly location, associated objects, and anomaly context, which are used for subsequent anomaly remediation target routing and state machine repair.
[0107] 3. State machine repair module This module receives structured anomaly results from the inspection module, and based on the anomaly type, anomaly object, anomaly location, associated objects, and anomaly context, it categorizes the anomaly repair targets. After determining the candidate repair targets, it performs targeted repair on the state machine. Repair methods include rule-based repair, current state repair, historical state backtracking repair, and post-repair verification.
[0108] Among them, for anomalies that can be directly corrected according to the rules, rule-based repair can be used first; for anomalies that require supplementation of the current state logic, the current state can be partially repaired; for anomalies that occur in the current state but whose root cause is in the previous state, historical state backtracking repair can be triggered, and the subsequent state path can be re-expanded from the repair point.
[0109] After the repair is completed, the system re-executes the state machine check corresponding to the repair scope; if anomalies still exist, the system continues to perform anomaly localization and targeted repair until the state machine meets the preset consistency conditions or reaches the preset termination conditions. Thus, the state machine check module and the state machine repair module together constitute a closed-loop processing mechanism of inspection, localization, repair, and re-verification.
[0110] 4. Consistency Verification Module This module compares the repaired state machine with the baseline state machine to verify the consistency of participants, initial knowledge, state nodes, operations, conditional branches, message events, and target states, and outputs the overall consistency result, the results of each item verification, and an explanation of the inconsistencies.
[0111] Specifically, this module can perform name alignment, semantic alignment, and expression normalization on state machine elements in the state machine to be evaluated and the baseline state machine. For elements with different names but the same or similar semantics, a correspondence can be established through semantic similarity models, equivalence rules, or name mapping relationships. Based on this, recursively matching is performed on participants, initial knowledge, state nodes, received events, in-state operations, conditional branches, guard conditions, sent events, message fields, and target states. Based on the matching results, true positives, false positives, and false negatives are statistically analyzed, and precision, recall, F1 score, or other consistency indicators are calculated. The overall consistency score, itemized verification results, and inconsistency locations are output.
[0112] This module enables fine-grained, quantifiable quality assessment of the repaired state machine, thereby determining whether it remains consistent with the baseline state machine at the structural and semantic layers.
[0113] 5. Result Output Module This module summarizes the processing results of the state machine repair module and the consistency verification module, and outputs the final state machine, the consistency verification report, and a description of inconsistencies. The final state machine is the security protocol state machine after inspection, repair, and verification; the consistency verification report includes overall consistency results, sub-item verification results, and consistency indicators; the description of inconsistencies identifies the participants, states, events, operations, conditions, or state transition locations where differences still exist between the state machine to be evaluated and the baseline state machine. For cases where repair is not completed even after meeting preset termination conditions, this module can also output the reason for the repair failure.
[0114] In summary, this embodiment, through the collaborative work of five modules—state machine input and normalization, state machine inspection, state machine repair, consistency verification, and result output—can automatically perform logical inspection, targeted repair, historical state backtracking repair, quantitative consistency assessment, and result output on the generated security protocol state machine. This results in a state machine model that is structurally complete, has self-consistent knowledge flow, and conforms to the protocol semantics, providing a more reliable input foundation for subsequent formal analysis and security verification.
[0115] Furthermore, in this embodiment, the security protocol state machine is represented in a unified structured or semi-structured format to describe the state evolution, message interaction, operation execution, and knowledge change relationships of each participant during protocol execution. It includes at least the protocol name, participant set, initial knowledge set of each participant, state set, and state transition relationships. Wherein: (1) The protocol name is used to identify the security protocol corresponding to the current state machine.
[0116] (2) The participant set is used to record the entities that perform the protocol, such as the initiator, responder, client, and server. Each participant is an independent local state machine, and its state transitions describe the local behavior of that participant during the protocol execution process.
[0117] (3) The initial knowledge set is used to record the information that each participant already holds before the start of the protocol, including identity identifiers, long-term keys, public keys, private keys, pre-shared keys, public parameters or other protocol-preset data.
[0118] (4) The state set is used to record all state nodes of each participant. Each state node corresponds to the execution context of a participant in a certain protocol phase. State nodes may include fields such as received events, operations within the state, conditional branches, locally added knowledge, sent events, and subsequent state pointers.
[0119] (5) The receive event is used to describe the protocol message received in the current state, including the message event name, the message source participant, and the set of message fields. For the protocol start state, if the state does not depend on external message triggering, the receive event can be empty.
[0120] (6) Operations within a state describe the processing steps performed by the current state after receiving a message, including decryption, signature verification, hash calculation, message authentication code verification, random number generation, key derivation, or protocol-specific operations. Each operation must include at least the operation type, input parameters, and output parameters.
[0121] (7) Conditional branches are used to describe the subsequent processing path to be executed based on different guard conditions after the common operation is completed. Each conditional branch may include guard conditions, branch operations, new knowledge, sent events, and subsequent state pointers.
[0122] (8) Guard conditions are used to express the judgment relationship that must be satisfied before the branch is selected, such as the random number matching, identity matching, signature verification result being true, message authentication code verification passing, etc.
[0123] (9) Intra-branch operations are used to describe the computation, verification, message construction or cryptographic processing steps that continue to be executed after the branch is established.
[0124] (10) Sending events are used to describe the protocol messages sent by the current state or the current transfer branch to other participants, including the message event name, the target participant, and the set of sending fields.
[0125] (11) The successor state refers to the position or termination result of the current participant after executing the current state or the current condition branch, including entering the next state of the same participant, waiting for messages from other participants, normal termination, abnormal termination, or returning to the existing state.
[0126] Furthermore, this embodiment also provides a more detailed technical solution for a logic repair and consistency verification method for automatically generated security protocol state machines.
[0127] 1. The state machine input and normalization module is used to receive the security protocol state machine to be processed and parse it into an internal representation that can be processed by the subsequent state machine inspection module, state machine repair module and consistency verification module.
[0128] This module reads and parses the input state machine, extracting the protocol name, participant set, participant initial knowledge set, state set, and the received events, in-state operations, conditional branches, sent events, and subsequent state pointers in the state nodes.
[0129] For each state node that is entered step by step, the state machine input and normalization module adds the new input state to the currently constructed partial state machine and saves the generated states, state connection relationships and participant knowledge evolution information.
[0130] In different implementations, if the input state machine adopts different structured or semi-structured representations, the module can convert it into a unified internal data object according to preset parsing rules for subsequent modules to continue processing.
[0131] 2. The state machine inspection module performs structural, semantic, and knowledge evolution checks on the automatically generated security protocol state machine, and outputs structured anomaly results for subsequent repair modules to call, such as... Figure 3 As shown, the structured anomaly results include anomaly type, anomaly object, anomaly location, associated objects, and anomaly context. The anomaly object records the state machine elements or relationships that directly trigger anomaly detection; the anomaly location identifies the participants, states, and specific locations associated with the anomaly; associated objects record other state machine elements or relationships related to the anomaly; and the anomaly context records the knowledge set, operation sequence, message sending and receiving relationships, state paths, and anomaly detection steps as the basis for detection. Because the security protocol state machine has characteristics of knowledge evolution, message interaction, and temporal dependencies, the inspection module performs checks based on these characteristics.
[0132] For the step-by-step input mode, the system immediately performs checks on any anomalies that can be determined by the currently generated state; for check items that require a state that has not yet been generated to be determined, the corresponding check tasks are temporarily stored and the checks are re-executed after the relevant state is generated.
[0133] Specifically, the following inspection mechanisms are included: (1) Structural integrity check Structural integrity checks are used to determine whether the input state machine possesses the basic structure required for subsequent semantic checks and repairs. This check first performs a structural format check, followed by a check of state connectivity relationships.
[0134] First, the system checks the input state machine's structure and format against a preset state machine structure template. This check includes verifying the existence of fields such as protocol name, participant set, initial knowledge set, state set, received events, in-state operations, conditional branches, sent events, and subsequent state pointers, as well as ensuring that the data types and hierarchical relationships of each field meet preset requirements. If the state machine lacks necessary fields, has incorrect field types, or incomplete hierarchical relationships, a structural format anomaly is generated.
[0135] Secondly, the system checks the identifiers and reference relationships of state nodes, including whether the state name is consistent with reference names in other locations, and whether there are duplicate state names under the same participant. If duplicate state names exist under the same participant, a state name conflict exception is generated; if the state name and reference name are inconsistent, a state reference inconsistency exception is generated.
[0136] Next, the system checks the connections between states. For each state node, the system checks whether its successor state corresponds to an already generated state node, a termination state, or a loop state; it also checks whether the current state can be reached from the protocol start state or a preceding state. If a successor state reference does not exist, a state connection anomaly is generated; if the current state has no preceding state and is not the protocol start state, an isolated state anomaly is generated. For loop pointers, the system checks whether the loop target is the current state node or an already generated historical state node. If the loop target cannot be found in the current state machine path, a loop pointer anomaly is generated.
[0137] (2) Knowledge Dependence and Knowledge Evolution Check Knowledge dependency and knowledge evolution checks are used to determine whether the variables used by each participant in different states have a clear source, and whether new knowledge generated during state execution is correctly recorded and transmitted. The system maintains the currently available knowledge of each participant along the state transition path. The currently available knowledge mainly includes the participant's initial knowledge, the knowledge passed from the previous state, the message fields in the currently received event, and the output results of the operations already performed in the current state.
[0138] For operations within a state, the system checks the input parameters according to the order of operation execution. If an input parameter does not belong to currently available knowledge, nor to predefined constants such as Boolean values, numbers, null values, preset state values, or string constants, then the generation of the operation's input variable is considered to have no source. For the output parameters generated by the operation, the system adds them as new knowledge records for the current state.
[0139] For receive events, the system treats the received fields as part of the available knowledge of the current state and records the source participant, message event name, and field name. For send events, the system checks whether each send field comes from the currently available knowledge or newly added knowledge of the current state; if the send field cannot find a source, a "send field has no source" exception is generated.
[0140] For guard conditions, the system checks whether the variables referenced in the condition can be obtained from currently available knowledge, except for predefined constants. If the variable referenced by the guard condition has no source, a guard condition variable without source exception is generated.
[0141] After the current state check is completed, the system passes the existing and newly added knowledge of the current state to the successor state as inherited knowledge. If the current state has multiple conditional branches, the system records the knowledge changes after each branch is executed and continues the check along its respective successor path.
[0142] (3) Guarding conditions and conditional branch checks The guard conditions and conditional branches in the state are checked. Specifically, this includes: checking if a guard condition compares itself with the same variable; and checking if multiple conditional branches form duplicate branches when the action, sent event, and target state are the same.
[0143] (4) Message sending and receiving inspection The state machine's receive and send events are inspected. For message interactions where there is a correspondence between the sender and receiver, the sender's send event and the receiver's receive event are checked for correspondence in terms of participants, event names, and message fields. For receive events, the receiver fields are checked for naming conflicts with existing knowledge of the current participants. For send events, the target participant is checked for existence. This inspection is used to identify mismatches between send and receive events, receive field conflicts, and abnormal send targets.
[0144] (5) Redundancy check of compound operations The system checks for composite operations such as combination and decomposition in the state machine and the redundant intermediate fields they introduce. It iterates through operations within the state and operations within conditional branches to identify whether there are combination operations used only for concatenating fields, or decomposition operations used only for splitting fields.
[0145] For combination operations, the system records the correspondence between the output fields of the combination operation and its input field set; for disassembly operations, the system records the correspondence between the input fields of the disassembly operation and its output field set. If the above combination or disassembly operation only changes the organization of fields, does not produce new protocol semantics or cryptographic calculation results, and the intermediate fields it introduces interfere with the subsequent operation inputs, guard conditions, or traceability of the original field's source, then the combination or disassembly operation is marked as a redundant composite operation.
[0146] This check is used to identify unnecessary combination operations, disassembly operations, and redundant intermediate fields introduced by the automatic generation process, and outputs the field correspondence and the location of redundant operations to the repair module for subsequent field replacement and operation deletion.
[0147] Through the above checks, the system can convert the exceptions in the automatically generated state machine into structured exception results and provide these structured exception results to the state machine repair module.
[0148] 3. The state machine repair module is used to perform targeted repairs on structural anomalies, knowledge dependency and knowledge evolution anomalies, guard condition and conditional branch anomalies, message sending and receiving anomalies, and composite operation redundancy anomalies in the security protocol state machine based on the structured anomaly results output by the inspection module. For example... Figure 4 As shown, the repair module does not indiscriminately regenerate the entire state machine. Instead, it uses a combination of rule-based repair, target-based anomaly repair, current state repair, historical state backtracking repair, and post-repair verification to improve the targeting and stability of the repair.
[0149] The repair module includes the following repair mechanisms: (1) Rule-based direct repair mechanism For anomalies with clear rule-based characteristics that can be handled without regenerating the state, rule-based direct repair should be prioritized. This type of repair is mainly used to handle anomalies such as inconsistent state references, mergeable state name conflicts, received field conflicts, duplicate conditional branches, and redundant composite operations.
[0150] The specific repair rules are as follows: For state reference inconsistency exceptions, the system modifies the reference location name based on the expected state name or the standard name in the generated state to ensure consistency between the name at the state definition and the reference location. For mergeable state name conflict exceptions, the system compares the content of states with duplicate names. If their received events, in-state operations, conditional branches, sent events, and subsequent states point to the same information, they are merged into the same state. If the content differs, the exception is handled by the current state-oriented repair mechanism, which regenerates the conflicting state.
[0151] In the event of a received field conflict, if the field name in the received event is the same as the name of a knowledge item in the existing knowledge set of the current participant, the system determines whether they represent the same semantic object. If the received field represents a candidate value sent by the other party, while the local existing knowledge item represents a locally stored reference value, the system renames the received field to a candidate field name that is different from the local knowledge item, and synchronously updates the reference of this field in subsequent guard conditions, operations, and sent events.
[0152] For duplicate conditional branch exceptions, if multiple conditional branches have the same action, sent event, and subsequent state, but differ only in guard conditions, the system merges equivalent branches, retains the necessary guard conditions, and deletes duplicate branches.
[0153] For abnormal redundant combination operations, the system deletes the combination operation based on the "combined field - pre-combination field set" correspondence recorded during the inspection phase, and replaces subsequent references to the combined field set with the pre-combination field set. For abnormal redundant decomposition operations, the system deletes the decomposition operation based on the "decomposition field - decomposition field set" correspondence recorded during the inspection phase, and modifies the output of the pre-decomposition field in the preceding operation to the decomposition field set.
[0154] (2) Abnormal repair target diversion mechanism When an anomaly cannot be directly repaired using rules, the system analyzes the cause of the anomaly based on the anomaly type, anomaly object, anomaly location, associated objects, and anomaly context in the structured anomaly results, and determines the corresponding candidate repair targets.
[0155] Candidate repair targets include the initial knowledge layer, the current state layer, the historical state layer, the successor state layer, or the communication event layer. For abnormal variable sources, the system determines whether the variable originates from initial knowledge, the result generated from the current state, or knowledge passed from a previous state. For abnormal send / receive event correspondence, the system determines whether the error lies in the current receiving state or the previous sending state. For abnormal state transitions, the system determines whether to repair the current state's successor pointer or generate a missing successor state.
[0156] The system determines the priority of candidate repair targets based on the anomaly type, associated objects, and anomaly context in the structured anomaly results, and then assigns the anomalies to the corresponding repair mechanisms. This mechanism avoids regenerating the entire state machine, enabling the repair process to pinpoint specific locations such as initial knowledge, current state, historical state, successor state, or communication events.
[0157] (3) Current state targeted repair mechanism When structural format anomalies, variable source anomalies, guard condition anomalies, message sending / receiving anomalies, sending target anomalies, or loop pointer anomalies are determined to be caused by incomplete or erroneous current state generation, the system performs targeted repair on the current state. Specifically, based on the anomaly type, anomaly object, anomaly location, associated objects, and anomaly context in the structured anomaly result, the system calls the state generation method corresponding to the current state to generate a repaired complete current state. The repaired current state replaces the original current state and is reconnected to the original state path. Subsequently, the system re-performs structural checks, knowledge dependency checks, and related semantic checks on the repaired current state to determine whether the current state repair was successful. For state transition anomalies, if the system determines that the anomaly is caused by an error in the successor pointer of the current state, it regenerates the current state through the current state targeted repair mechanism to correct its successor pointer; if the system determines that the anomaly is caused by the failure to generate a successor state, it calls the state generation method corresponding to that successor state to generate the missing successor state and connects it to the current state machine path.
[0158] (4) Historical status retrospective repair mechanism When the current state check fails, and the system determines that the exception may have been caused by a previous state based on the exception type, exception object, associated object, and exception context in the structured exception result, the system triggers historical state backtracking and repair. This mechanism is applicable to situations where variables should be generated or passed by a previous state, or where events sent by a previous state do not correspond to the currently received events.
[0159] Specifically, the system identifies potentially erroneous historical states based on abnormal results and calls the corresponding state generation method to regenerate those historical states. After regeneration, the system undoes the existing construction results of that historical state and its subsequent states, and adds the regenerated historical state to the state machine. Subsequently, the system continues to generate subsequent states starting from that historical state until the construction and checking of the subsequent state paths are completed.
[0160] (5) Initial knowledge repair mechanism When an anomaly in the source of a variable is determined to be caused by a lack of initial knowledge of the protocol, the system triggers initial knowledge repair. Specifically, when the anomaly object is a variable, the system determines the missing variable and its associated participants based on the anomaly object, anomaly location, associated objects, and anomaly context, and repairs the initial knowledge set of that participant. After the initial knowledge repair is completed, the system re-executes the knowledge dependency check of the relevant states to determine whether the variable can be provided by the repaired initial knowledge set.
[0161] (6) Post-repair re-inspection mechanism After each repair, the system re-executes the checks corresponding to the repair scope. When the repair object is the current state, the current state and its directly related state paths are re-checked; when the repair object is a historical state, subsequent paths starting from that historical state are re-checked. If the re-verification passes, the repair result is retained; if the re-verification still fails, the anomaly repair target routing and repair are re-executed based on the new structured anomaly results. The system can set a maximum number of repair attempts for different repair objects and records the repair targets that have been tried. When the same anomaly or the same state exceeds the preset number of repair attempts, or when all available repair paths have been tried but still fail the re-verification, the system terminates automatic repair and outputs the reason for the repair failure.
[0162] Thus, this embodiment forms a closed-loop iterative mechanism of inspection, location, repair, and re-verification, thereby continuously improving the structural integrity and logical self-consistency of the automatically generated state machine.
[0163] For the step-by-step input mode, the state machine repair module can perform targeted repairs on the current state or the historical states that have been generated during the state machine generation process; after the complete state machine is generated, the system will then perform a complete state path check and a global consistency verification.
[0164] 4. The consistency verification module compares the repaired security protocol state machine with the baseline state machine to determine whether the state machine to be evaluated is consistent with the baseline state machine at the structural and semantic layers, and outputs the quantitative verification results. Figure 5 As shown. The baseline state machine can be a state machine manually written and verified by a domain expert, or a standard state machine generated by a formal model, reference implementation, or other reliable methods. The state machine to be evaluated can be the state machine processed by the aforementioned inspection and repair module in this embodiment. Both can use the same data structure, or they can be converted into a unified structured state machine representation.
[0165] Before consistency verification, the system can first perform expression normalization processing on the state machine to be evaluated and the baseline state machine. Expression normalization processing includes, but is not limited to: unifying variable names, unifying equivalent operations, expanding composite data operations, normalizing field sets, and standardizing conditional expressions. This preprocessing can reduce mismatches caused by differences in representation, and improve the stability of subsequent consistency verification.
[0166] The consistency verification module preferably adopts a hierarchical recursive comparison method. Specifically, while preserving the state topology, it sequentially matches the participants, initial knowledge, state nodes, received events, in-state operations, conditional branches, guard conditions, branch execution results, sent events, and target state. Based on the matching results, it outputs the overall consistency result, the consistency results of each participant, the consistency results of each state, and an explanation of the inconsistency location.
[0167] The consistency verification module specifically includes the following steps: (1) Participant alignment First, the participants in the state machine to be evaluated and the baseline state machine are aligned. If the participant names are the same, a direct correspondence is established; if the names are different, a matching relationship is calculated based on the participant description, contextual semantics, or preset mapping rules, and an alignment relationship is established when the preset matching conditions are met. After establishing the participant alignment relationship, the participants in the state machine to be evaluated are uniformly mapped to the namespace of the baseline state machine for subsequent unified comparison.
[0168] (2) Alignment of the initial knowledge sets of the participants For each pair of aligned participants, their initial knowledge sets are compared. If the knowledge item names match, a match is directly determined; if the names do not match, a correspondence is established based on the knowledge item description, usage context, or similarity calculation results, forming a name alignment relationship. Name alignment relationships can be continuously updated and reused in subsequent state, event, operation, and condition matching processes. Knowledge items present in the baseline state machine but missing in the state machine to be evaluated are recorded as false negatives; knowledge items present in the state machine to be evaluated but not in the baseline state machine are recorded as false positives; and successfully matched knowledge items are recorded as true positives.
[0169] (3) State recursive matching After aligning the participants and initial knowledge, a recursive matching process is performed between the baseline state machine and the state machine to be evaluated, starting from the initial state of each participant. For the currently compared pair of state nodes, their received events, in-state operations, conditional branches, sent events, and target states are compared respectively. If the baseline state machine has a corresponding state but the state machine to be evaluated does not, it is determined to be a missing state; if the state machine to be evaluated has redundant states, it is determined to be a redundant state. To avoid redundant calculations caused by cyclic states or repeated paths, the system can employ a path deduplication control mechanism to limit repeated expansion.
[0170] (4) Event matching For the current state node, the existence of received events is first compared. If one event exists while the other does not, it is determined that the existence of received events is inconsistent. If both exist, the message source participants, event names, and received field sets are further compared. The source participants should be consistent after participant alignment; event names can be aligned using direct matching, equivalent name rules, or semantic matching; field sets are matched based on field names, field descriptions, or field semantics. Fields that cannot be matched are recorded as received field mismatches.
[0171] (5) In-state operation matching For the operation sequence in the current state, compare the operation type, input parameters, and output parameters. The operation type can be aligned using at least one of the following methods: direct matching of operation names, matching based on predefined equivalent operation rules, or similarity matching based on operation descriptions. After name alignment, the input parameters should be consistent with the input of the corresponding operation in the baseline state machine. Output parameters do not require absolute name consistency, but should be able to establish a correspondence based on output semantics, subsequent usage relationships, or knowledge registration relationships. For input / output items with list, set, or nested structures, normalization can be performed before matching. Operations present in the baseline state machine but missing in the state machine to be evaluated are recorded as false negatives; additional operations present in the state machine to be evaluated are recorded as false positives; successfully matched operations are recorded as true positives.
[0172] (6) Conditional branch matching When multiple conditional branches exist in the current state, the system compares each conditional branch in the baseline state machine with the candidate conditional branches in the state machine to be evaluated. The comparison for each conditional branch includes the guard condition, the operation within the branch, the knowledge items added after the branch execution, the sent event, and the target state. The system can sort the conditional branches according to a preset priority, prioritizing branches with stronger constraints or clearer semantics to improve matching stability. Baseline branches for which no corresponding candidate branch can be found are designated as missing branches; unmatched branches to be evaluated are designated as redundant branches.
[0173] (7) Guarding conditions matching Guard conditions describe the judgment relationships that must be satisfied before a conditional branch is triggered. After name alignment, the system compares the operators, parameter sets, and logical relationships in the guard conditions. For conditions where the parameter order does not affect the semantics, standardization can be performed before comparison. If the state machine to be evaluated lacks guard conditions required by the baseline state machine, or if the operators and parameter relationships cannot be aligned with the baseline conditions, it is determined that the guard conditions are mismatched.
[0174] (8) Branch execution result matching For each matched conditional branch, the system further compares whether the newly added knowledge items, generated intermediate results, and triggered message sending behaviors after the branch's execution are consistent with the baseline state machine. Newly added knowledge items present in the baseline state machine but missing in the state machine to be evaluated are recorded as false negatives; newly added knowledge items additionally present in the state machine to be evaluated are recorded as false positives; successful matches are recorded as true positives. This step verifies whether the state machine to be evaluated correctly expresses the knowledge evolution results after the conditional branch execution.
[0175] (9) Send event matching For sending events, the system compares the sending target, event name, and set of sending fields. The sending target should be consistent after alignment among the participants; the event name can be aligned using direct matching, equivalence rules, or semantic matching; the set of sending fields is compared after name alignment and normalization. If the sending target, event name, or set of fields cannot be aligned, the sending event is determined to be mismatched.
[0176] (10) Recursive verification of the target state When a conditional branch matches successfully, the system compares whether a corresponding relationship has been established between the target state in the baseline state machine and the state machine to be evaluated. If the target state matches successfully, the current name alignment relationship is passed to the subsequent state, and recursive matching continues; if the target state cannot be aligned, it is determined that the target states are inconsistent. Through this recursive verification process, the system can progressively compare the consistency between the state machine to be evaluated and the baseline state machine in terms of state structure, conditional logic, message interaction, and knowledge evolution along the state path.
[0177] (11) Consistency Quantitative Assessment After completing the above matching, the system counts true positives, false positives, and false negatives for each participant, initial knowledge, state node, received event, operation, conditional branch, guard condition, sent event, and target state, and calculates precision, recall, F1 score, or weighted consistency score accordingly. Finally, it outputs the overall consistency score, individual consistency scores, and explanations of inconsistencies, thereby achieving a quantitative assessment of the quality of the state machine under evaluation.
[0178] 5. The results output module summarizes and outputs the state machine repair results and consistency verification results. For state machines that have completed repair and re-verification, it outputs the final repaired state machine; for state machines that fail re-verification even after meeting the preset termination conditions, it outputs the current state machine and the reason for repair failure. After consistency verification is completed, it outputs a consistency verification report, which includes overall consistency results, sub-item consistency results, consistency indicators, and descriptions of inconsistencies. The output results can be represented in JSON, YAML, XML, report files, or other structured or semi-structured formats.
[0179] In summary, the logic repair method and system for the security protocol state machine described in this invention innovatively constructs an automated logic repair and verification framework that includes dynamic knowledge tracking, deep inspection, classification repair, and closed-loop verification. Specifically, this invention first dynamically tracks the available knowledge sets of each participant along the state path; based on this, it performs a comprehensive structural and semantic inspection on the automatically generated state machine to generate structured anomalies; then, it classifies and processes the anomalies, addressing different types of logical defects through a combination of rule-based repair and multi-level targeted repair, particularly by introducing a historical state backtracking mechanism to repair deep errors; finally, through fine-grained consistency verification with the benchmark model, it quantitatively evaluates the repair effect, forming a closed-loop optimization process of inspection, repair, and re-verification.
[0180] Compared with existing technologies, this invention achieves significant technological advancements. First, it realizes a paradigm shift from static syntax verification to dynamic semantic verification, enabling precise identification and location of deep logical defects dependent on protocol execution context that traditional methods cannot reach. Second, its unique diversionary and multi-level targeted repair strategy achieves precise targeting of protocol errors, completely overcoming the bottleneck of existing technologies' coarse-grained repair and tendency to inadvertently damage innocent logic, greatly improving the success rate and efficiency of repair. Most importantly, the historical state backtracking and reconstruction mechanism of this invention fundamentally solves the common problems of error propagation and temporal dependencies in security protocols, ensuring the global logical self-consistency of the repaired model, achieving a fundamental breakthrough. Finally, the consistency quantification evaluation method provided by this invention offers an objective and reliable metric for the final results of the automated generation and repair process, constructing an end-to-end, highly reliable security protocol model engineering solution from automatic generation and intelligent repair to final verification, which has significant application value in fields with stringent requirements for protocol correctness, such as network security, fintech, and the Internet of Things.
[0181] Those skilled in the art will understand that the exemplary components, systems, and methods described in conjunction with the embodiments disclosed herein can be implemented in hardware, software, or a combination of both. Whether implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention. When implemented in hardware, it can be, for example, electronic circuits, application-specific integrated circuits (ASICs), appropriate firmware, plug-ins, function cards, etc. When implemented in software, the elements of this invention are programs or code segments used to perform the desired tasks. The programs or code segments can be stored in a machine-readable medium or transmitted over a transmission medium or communication link via data signals carried in a carrier wave.
[0182] It should be clarified that the present invention is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications, and additions, or change the order of steps, after understanding the spirit of the present invention.
[0183] In this invention, features described and / or illustrated for one embodiment may be used in the same or similar manner in one or more other embodiments, and / or combined with or in place of features of other embodiments.
[0184] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations of the embodiments of the present invention are possible. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A logical repair method for a security protocol state machine, characterized in that, The method includes the following steps: Obtain the security protocol state machine to be processed, which is automatically generated or manually constructed by the large language model. Then, parse and normalize the security protocol state machine to be processed, and extract the protocol name, the set of participants, the initial knowledge set of the participants, the state nodes, and the state transition relationships between the state nodes. Along the state path formed by the state transition relationship, based on the initial knowledge of each participant, the knowledge passed by the preceding state node, the message fields received by the current state node, and the state operation output of the current state node, the available knowledge set of each participant is dynamically maintained; based on the preset state machine structure template, the identification and reference relationship of the state node, the state transition relationship, the available knowledge set, and the message interaction relationship between the participants, the security protocol state machine to be processed is subjected to structural and semantic checks to generate structured anomaly results; For rule-based structured anomalies, repair is performed directly based on rules. For non-rule-based structured anomalies, the cause of the anomaly is analyzed and candidate repair targets are determined based on the anomaly type, anomaly object, anomaly location, associated objects, and anomaly context recorded therein. These candidate repair targets include initial knowledge layer targets, current state layer targets, historical state layer targets, subsequent state layer targets, or communication event layer targets. Each type of candidate repair target is then routed and targeted for repair according to a preset priority. Specifically, for historical state layer targets, repair is performed by tracing back to historical state nodes. Starting from these nodes, the subsequent state paths affected by the repair are reconstructed, and the available knowledge sets of the affected participants are updated along these subsequent state paths. The repaired security protocol state machine is then subjected to the structural and semantic checks again according to the scope of the repair. After the re-verification is passed, the final security protocol state machine is obtained.
2. The logic repair method for the security protocol state machine according to claim 1, characterized in that, The method further includes a consistency verification phase, the steps of which are: The final security protocol state machine after logical repair is used as the security protocol state machine to be verified. The baseline state machine corresponding to the security protocol state machine to be verified is obtained. The security protocol state machine to be verified and the baseline state machine are parsed and normalized respectively, and their respective protocol names, participant sets, participant initial knowledge sets, state nodes, and state transition relationships between state nodes are extracted. Based on the identification information and protocol semantic information of the participants in the security protocol state machine to be verified and the baseline state machine, the participants are aligned, and the knowledge items in the initial knowledge sets of the mutually aligned participants are aligned to establish element alignment relationships. Starting from the initial state nodes of the mutually aligned participants, recursive matching is performed while maintaining the state transition relationships of the security protocol state machine to be verified and the reference state machine. For the currently corresponding state nodes, based on the element alignment relationship, at least one of the following is matched: receive event, in-state operation, conditional branch, guard condition, send event, and subsequent state pointer. The number of successful matches, the number of missing matches, and the number of redundancies are determined with reference to the reference state machine. The corresponding subsequent state nodes are determined according to the state transition relationship. The updated element alignment relationship is passed to the subsequent state nodes to continue recursive matching until the preset recursive termination condition is met. Based on the results of the recursive matching, the number of successful matches, missing numbers, and redundant numbers are counted for each state machine element of the preset type. Based on this, a consistency evaluation index is calculated to obtain the overall consistency result, the sub-item consistency result, and the inconsistency location of the security protocol state machine to be verified relative to the baseline state machine.
3. The logic repair method for the security protocol state machine according to claim 1, characterized in that, The structural inspection steps include: Based on the preset state machine structure template, the existence, data type, and hierarchical relationship of the protocol name, participant set, participant initial knowledge set, and state node corresponding fields in the security protocol state machine to be processed are checked; when necessary fields are missing, field data types do not meet preset requirements, or hierarchical relationships do not meet preset requirements, a structural format anomaly is generated; wherein, the state node corresponding fields include at least one of receiving events, in-state operations, conditional branches, guard conditions, sending events, and subsequent state pointers; Based on the identifier and reference relationship of the state node, a consistency check is performed on the state name and the reference name that references the state name, and a duplicate check is performed on the state names under the same participant; when the state name and the corresponding reference name are inconsistent, a state reference inconsistency anomaly is generated; when there are duplicate state names under the same participant, a state name conflict anomaly is generated. Based on the state transition relationship, check whether the subsequent state pointer corresponds to an existing state node, a terminated state, or a loop state, whether the non-starting state node has a reachable preceding state, and whether the loop target corresponding to the loop state is valid; when the subsequent state pointer does not correspond to an existing state node, a terminated state, or a loop state that meets the preset conditions, the non-starting state node does not have a reachable preceding state, or the loop target does not meet the preset loop pointing conditions, respectively generate state connection anomaly, isolated state anomaly, or loop pointing anomaly. Generate a corresponding structured exception result based on at least one of the following: structure format exception, state reference inconsistency exception, state name conflict exception, state connection exception, isolated state exception, and circular pointer exception.
4. The logic repair method for the security protocol state machine according to claim 1, characterized in that, The semantic checking steps include: Based on the available knowledge set of each participant, according to the state path and the execution order of operations within the state, the knowledge source is checked for the input parameters of operations within the state, the variables referenced by guard conditions, and the sending fields in the sending event. The output parameters generated by the operations within the state are used as the newly added available knowledge of the corresponding participant. When the input parameters, the variables referenced by guard conditions, or the sending fields do not belong to the available knowledge of the corresponding participant at the corresponding execution position and do not belong to the predefined constants, a knowledge source exception is generated. Based on the guard conditions and condition branches in the state node, the comparison relationship of the guard conditions and the in-state operations, sent events and subsequent state pointers corresponding to different condition branches are checked; when the guard condition has the same variable compared with itself, a guard condition exception is generated; when the in-state operations, sent events and subsequent state pointers corresponding to multiple condition branches are the same, a duplicate branch exception is generated. Based on the message interaction relationship between the participants, a correspondence check is performed on the participants, event names, and message fields in the corresponding sending and receiving events. The naming relationship between the received fields and the existing knowledge of the receiving participants, as well as the target participant corresponding to the sending event, are also checked. If the sending and receiving events do not satisfy a preset correspondence, a message sending / receiving mismatch exception is generated. If the received fields conflict with existing knowledge in terms of naming, a received field conflict exception is generated. If the target participant does not exist, a sending target exception is generated. The combination and decomposition operations in the state operations and condition branch operations are checked; when the combination or decomposition operation only changes the organization of the field, does not generate new protocol semantics or cryptographic calculation results, and the intermediate field it introduces affects the subsequent state operation input, guard conditions or the source tracing of the original field of the sent field, it is identified as a redundant compound operation and a compound operation redundancy anomaly is generated. Generate a corresponding structured exception result based on at least one of the following: knowledge source anomaly, guard condition anomaly, duplicate branch anomaly, message sending and receiving mismatch anomaly, receive field conflict anomaly, send target anomaly, and composite operation redundancy anomaly.
5. The logic repair method for the security protocol state machine according to claim 1, characterized in that, For rule-based structured anomalies, repair is performed directly based on rules, including the following steps: The rule-based structured anomaly results include at least one of the following: inconsistent state reference anomaly, mergeable state name conflict anomaly, received field conflict anomaly, duplicate branch anomaly, and composite operation redundancy anomaly, and are classified and repaired according to the anomaly type. For the aforementioned state reference inconsistency anomaly, the state name of the generated state node pointed to by the reference position shall be used as the reference name, and the reference name at the reference position shall be modified to the state name, so that the reference name is consistent with the state name of the state node it points to. For the aforementioned mergeable state name conflict exception, when the received events, in-state operations, conditional branches, sent events, and subsequent state pointers of multiple state nodes with duplicate state names under the same participant are consistent, the multiple state nodes are merged, and the references pointing to the merged state node are uniformly updated to point to the merged state node. In the event of a conflict in the received field, if the received field has the same name as an existing knowledge item of the current participant but represents different semantic objects, the received field is renamed according to the preset field naming rules, and the references to it in subsequent guard conditions, in-state operations and sending events are updated synchronously. For the duplicate branch exception, when the operation, event sent and subsequent state of multiple condition branches are the same, the multiple condition branches are merged and a merged guard condition is formed according to the logical relationship between their guard conditions to replace the original guard condition. For the aforementioned redundant operation, when the corresponding redundant composite operation is a combination operation, the combination operation is deleted according to the correspondence between the output field and the input field set of the combination operation recorded during the inspection process, and subsequent references to the output field are replaced with the corresponding input field set; when the corresponding redundant composite operation is a disassembly operation, the disassembly operation is deleted according to the correspondence between the input field and the output field set of the disassembly operation recorded during the inspection process, and the output of the preceding operation that generated the input field is modified to the corresponding output field set.
6. The logic repair method for the security protocol state machine according to claim 1, characterized in that, According to a preset priority, the candidate repair targets of each type are diverted and targeted for repair, and the steps include: According to the preset priority rules, the priority of each candidate repair target is determined based on the anomaly type, associated object and anomaly context, the priority candidate repair target is selected, and the structured anomaly result is diverted to the targeted repair mechanism corresponding to the priority candidate repair target; When the priority candidate repair target is the initial knowledge layer target, the missing knowledge and its participating parties are determined according to the abnormal object, abnormal location, associated object and abnormal context. The missing knowledge is added to the initial knowledge set of the corresponding participating party, and the knowledge source check of the affected state node is re-executed based on the repaired initial knowledge set. When the priority candidate repair target is the current state layer target, the state generation method corresponding to the current state node is called according to the structured anomaly result to regenerate the current state node, and the original current state node is replaced by the regenerated current state node before connecting to the original state path. When the priority candidate repair target is a successor state layer target, the missing successor state node is determined according to the structured anomaly result, the corresponding state generation method is called to generate the successor state node, and it is connected to the corresponding state path according to the state transition relationship of the current state node. When the priority candidate repair target is a historical state layer target, the structured anomaly result will be diverted to the historical state backtracking repair mechanism; When the priority candidate repair target is a communication event layer target, the abnormal sending or receiving event is determined according to the message interaction relationship, and the participant identifier, event name or message field in the sending or receiving event is corrected in the state node where it is located, so that the sending event and the corresponding receiving event satisfy the preset correspondence relationship.
7. The logic repair method for the security protocol state machine according to claim 6, characterized in that, The historical state retrospective and repair mechanism includes: When the priority candidate repair target is a historical state layer target, the historical state node corresponding to the cause of the anomaly is determined in the state path before the current state node based on the anomaly type, anomaly object, associated object, and anomaly context in the structured anomaly result; for anomaly variables that should be generated or transmitted by the preceding state node, the corresponding historical state node is determined based on their knowledge source; for cases where the received event of the current state node does not correspond to the preceding sent event, the historical state node containing the corresponding sent event is determined based on the message interaction relationship. Call the state generation method corresponding to the historical state node to regenerate the historical state node, and replace the original historical state node with the regenerated historical state node. Undo the existing construction results of subsequent state nodes affected by the repair of the historical state nodes, and reconstruct the affected subsequent state paths based on the regenerated state transition relationships, starting from the regenerated historical state nodes. During the reconstruction of the subsequent state path, the available knowledge set of the affected participants is updated along the subsequent state path based on the initial knowledge of each participant, the knowledge passed by the preceding state node, the message fields received by the current state node, and the state operation output of the current state node.
8. The logic repair method for the security protocol state machine according to claim 1, characterized in that, For the repaired security protocol state machine, the structural and semantic checks are performed cyclically according to the repair scope until the structured anomaly result meets the preset conditions. The steps include: After completing the rule-based repair or targeted repair, based on the objects and locations involved in this repair, update at least one of the state transition relationships, available knowledge sets, and message interaction relationships affected by this repair, and determine the affected part as the state check scope. Re-execute the structural check and semantic check on the state check scope, and update the structured anomaly results. If there are still unprocessed anomalies in the updated structured anomaly results, the unprocessed anomalies are re-determined as either regular or irregular anomalies. For regular anomalies, repairs are performed based on the corresponding rules. For irregular anomalies, the cause of the anomaly is re-identified, candidate repair targets are determined, and targeted repairs are performed according to a preset priority. After each repair, the state check range is re-determined, the structure check and semantic check are performed, and the structured anomaly results are updated until the updated structured anomaly results meet the preset conditions.
9. A logic repair system for a security protocol state machine, comprising a processor, a memory, and a computer program or instructions stored in the memory, characterized in that, The processor is used to execute the computer program or instructions, and when the computer program / instructions are executed, the system implements the steps of the method as described in any one of claims 1 to 8.
10. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method as described in any one of claims 1 to 8.
