Code processing methods, apparatus, storage media and electronic devices

By treating code providers and requesters as blockchain nodes, and utilizing public-key encryption and broadcasting mechanisms to share and modify code, the problems of complexity and security risks associated with code sharing are solved, enabling flexible and secure code sharing.

CN115130072BActive Publication Date: 2026-11-17INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202210738222.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-27
Publication Date
2026-11-17
Estimated Expiration
2042-06-27

AI Technical Summary

Technical Problem

Existing methods of sharing code are complex and pose security risks, especially in sensitive areas such as finance, where they cannot be effectively addressed through open-source sharing communities.

Method used

The code provider and the requester are treated as nodes on the blockchain. The source code is provided through public key encryption and shared and modified on the blockchain, including code acquisition, modification, merging and export. Each operation is recorded using the blockchain's broadcast mechanism.

Benefits of technology

It enables flexible and secure code sharing, simplifies operational processes, reduces the tedium of manual management, and improves security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115130072B_ABST
    Figure CN115130072B_ABST
Patent Text Reader

Abstract

This application discloses a code processing method, apparatus, storage medium, and electronic device. Relating to the field of blockchain technology, the method includes: adding a code provider as a node to the blockchain, encrypting the provided source code using a public key, and uploading it to the blockchain; adding a code requester as a node to the blockchain, obtaining shared code on the blockchain and code submission records of all nodes in the blockchain; when any node in the blockchain has a code acquisition request, sending a code acquisition request to the corresponding code providing node, receiving the returned private key, and decrypting the code to be acquired using the private key; when any node in the blockchain has a code modification request, sending a code modification request to the associated nodes with the code modification request, and performing a code modification operation based on the messages returned by the associated nodes. This application solves the problems of complex code sharing methods and security vulnerabilities in related technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain technology, and more specifically, to a code processing method, apparatus, storage medium, and electronic device. Background Technology

[0002] With the widespread development of open systems, service providers can authorize the sharing of their code with service consumers through open-source sharing communities and other means, and provide corresponding technical support.

[0003] For open systems in sensitive fields such as finance, due to security considerations, it is not possible to authorize the code to the caller through open source sharing communities. If the source code is shared on the basis of confidentiality agreements signed by both parties, a lot of manpower and resources are needed for negotiation and rights protection after leakage, which will put great pressure on the service provider, impose many requirements on the caller, and pose certain security risks.

[0004] There is currently no effective solution to the problems of complex code-sharing methods and security risks in related technologies. Summary of the Invention

[0005] This application provides a code processing method, apparatus, storage medium, and electronic device to solve the problems of complex code sharing methods and security risks in related technologies.

[0006] According to one aspect of this application, a code processing method is provided. The method includes: adding a code provider as a node to a blockchain, encrypting the provided source code using a public key, and uploading the encrypted source code as shared code to the blockchain; adding a code requester as a node to the blockchain, obtaining the shared code on the blockchain and the code submission records of all nodes in the blockchain; when any node in the blockchain has a code acquisition request, sending a code acquisition request to the corresponding code provider node, receiving the private key returned by the code provider node in response to the code acquisition request, decrypting the code to be acquired using the private key, and receiving a first broadcast message sent by the code provider node, wherein the first broadcast message contains the code acquisition record; when any node in the blockchain has a code change request, sending a code change request to the associated node with the code change request, performing a code change operation based on the message returned by the associated node, and having the node submitting the code to be changed send a second broadcast message to all nodes in the blockchain, wherein the second broadcast message contains the code change record.

[0007] Optionally, when any node in the blockchain has a code acquisition need, after sending a code acquisition request to the corresponding code-providing node, the method further includes: receiving a third broadcast message sent by the code-providing node if it rejects the code acquisition request, wherein the third broadcast message contains a record of code acquisition failure.

[0008] Optionally, when any node in the blockchain has a code change requirement, a code change request is sent to the associated nodes with the code change requirement. The code change operation is performed based on the messages from the associated nodes, including: if the current node with the change requirement needs to create a branch code, and the object of the change requirement is code outside the current node, the current node determines the associated commit nodes based on the commit records of the code to be changed, and sends the code change request to the associated commit nodes in chronological order, where the chronological order is the reverse chronological order of the commit times of the code to be changed; if all associated commit nodes provide consent messages, a branch code is created on the current node, the branch code is encrypted using the current node's public key, and the encrypted branch code is synchronized to all nodes on the blockchain; if at least one associated commit node provides a rejection message, the creation of the branch code is terminated.

[0009] Optionally, when there is a code change requirement at any node in the blockchain, a code change request is sent to the associated node with the code change requirement. The code change operation is performed based on the message fed back by the associated node, including: when the current node with the change requirement needs to create branch code, and the object of the change requirement is the code of the current node, the branch code is created on the current node, the branch code is encrypted using the public key of the current node, and the encrypted branch code is synchronized to all nodes on the blockchain.

[0010] Optionally, when any node in the blockchain has a code change requirement, a code change request is sent to the associated nodes with the code change requirement. The code change operation is performed based on the messages from the associated nodes, including: if the current node with the change requirement does not need to create a branch code, the current node determines the associated commit nodes based on the commit records of the code to be changed, and sends the code change request to the associated commit nodes in chronological order, where the chronological order is the reverse chronological order of the commit times of the code to be changed; if all associated commit nodes have given their consent messages, it is determined whether the current node is the initial commit node of the code to be changed; if the current node is the initial commit node, the code to be changed is encrypted using the current node's public key, and the encrypted code is synchronized to all nodes in the blockchain; if the current node is not the initial commit node, the code is sent to the initial commit node, the code to be changed is encrypted using the initial commit node's public key, and the encrypted code is synchronized to all nodes in the blockchain; if at least one associated commit node has given its rejection message, the submission of the code to be changed is terminated.

[0011] Optionally, when any node in the blockchain has a code change requirement, a code change request is sent to the associated node with the code change requirement. The code change operation is performed based on the message from the associated node, including: if the change requirement is for the current node to merge the code of a target node, the current node sends a code merge request to the target node, where the target node is a node other than the current node, and the merge request carries the merged code obtained after the current node merges the target node's code; if the target node sends an agreement message, it is determined whether the current node is the initial commit node of the code to be merged; if the current node is the initial commit node of the code to be merged, the merged code is encrypted using the current node's public key, and the encrypted merged code is synchronized to all nodes in the blockchain; if the current node is not the initial commit node of the code to be merged, the merged code is sent to the initial commit node, the merged code is encrypted using the initial commit node's public key, and the encrypted merged code is synchronized to all nodes in the blockchain.

[0012] Optionally, the method further includes: when there is a code extraction requirement on any node of the blockchain, sending a code extraction request to the corresponding code-providing node, wherein the code extraction requirement is a requirement to extract the target code from the blockchain; upon receiving an agreement message from the code-providing node, sending a code extraction request to the associated nodes of the target code; upon receiving agreement messages from all associated nodes, performing an extraction operation on the target code and sending a fourth broadcast message to all nodes of the blockchain, wherein the fourth broadcast message contains the code extraction record.

[0013] Optionally, after receiving an agreement message from the code-providing node and sending a code-extraction request to the associated nodes of the target code, the method further includes: upon receiving a rejection message from at least one associated node, obtaining the association record between the rejection node and the target code, verifying the association record, and obtaining a verification result, wherein the association record is a record of the rejection node participating in the submission of the target code; sending the verification result to all nodes; if the verification result indicates that the rejection by the associated node is an invalid rejection, and a preset proportion of nodes pass the verification result, encrypting the target code using a communication key, sending the encrypted target code to the node that issued the code-extraction request, and sending a fifth broadcast message, wherein the fifth broadcast message contains the code-extraction record; if the verification result indicates that the rejection by the associated node is a valid rejection, terminating the target code-extraction operation, and sending a sixth broadcast message, wherein the sixth broadcast message contains the record of code-extraction failure.

[0014] According to another aspect of this application, a code processing apparatus is provided. The apparatus includes: a first node joining unit, configured to join a code provider as a node in a blockchain, encrypt the provided source code using a public key, and upload the encrypted source code as shared code to the blockchain; a second node joining unit, configured to join a code requester as a node in the blockchain, obtain the shared code on the blockchain and the code submission records of all nodes in the blockchain; a code acquisition unit, configured to send a code acquisition request to the corresponding code providing node when any node in the blockchain has a code acquisition request, receive the private key returned by the code providing node in response to the code acquisition request, decrypt the code to be acquired using the private key, and receive a first broadcast message sent by the code providing node, wherein the first broadcast message contains the code acquisition record; and a code modification unit, configured to send a code modification request to the associated node with the code modification request when any node in the blockchain has a code modification request, perform a code modification operation based on the message returned by the associated node, and have the submitting node of the code to be modified send a second broadcast message to all nodes in the blockchain, wherein the second broadcast message contains the code modification record.

[0015] According to another aspect of the present invention, a non-volatile storage medium is also provided, the non-volatile storage medium including a stored program, wherein the program, when running, controls the device where the non-volatile storage medium is located to execute a code processing method.

[0016] According to another aspect of the present invention, an electronic device is also provided, comprising a processor and a memory; the memory stores computer-readable instructions, and the processor is configured to execute the computer-readable instructions, wherein the computer-readable instructions execute a code processing method when they are run.

[0017] This application employs the following steps: The code provider joins the blockchain as a node, encrypts the provided source code using a public key, and uploads the encrypted source code as shared code to the blockchain; the code requester joins the blockchain as a node, obtains the shared code on the blockchain and the code submission records of all nodes in the blockchain; when any node in the blockchain has a code acquisition request, a code acquisition request is sent to the corresponding code provider node, the private key returned by the code provider node in response to the code acquisition request is received, the private key is used to decrypt the code to be acquired, and a first broadcast message sent by the code provider node is received, wherein the first broadcast message contains the code acquisition record; when any node in the blockchain has a code change request, a code change request is sent to the associated node with the code change request, the code change operation is executed based on the message returned by the associated node, and the submitting node of the code to be changed sends a second broadcast message to all nodes in the blockchain, wherein the second broadcast message contains the code change record. This solves the problems of complex code sharing methods and security vulnerabilities in related technologies. By using the code provider and code requester as nodes on the blockchain for encrypting uploaded code, decrypting shared code, performing code changes, and broadcasting each executed code operation, a flexible and secure code sharing effect is achieved. Attached Figure Description

[0018] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0019] Figure 1 This is a flowchart of the code processing method provided according to the embodiments of this application;

[0020] Figure 2 This is a schematic diagram of a code processing apparatus provided according to an embodiment of this application;

[0021] Figure 3 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation

[0022] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.

[0023] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0025] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for display, data used for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties. For example, this system has an interface with relevant users or organizations. Before obtaining relevant information, it is necessary to send an acquisition request to the aforementioned user or organization through the interface, and obtain the relevant information after receiving consent information from the aforementioned user or organization.

[0026] It should be noted that the code processing methods, apparatus, storage media and electronic devices defined in this disclosure can be used in the field of blockchain technology, or in any field other than blockchain technology. The application fields of the code processing methods, apparatus, storage media and electronic devices defined in this disclosure are not limited.

[0027] According to an embodiment of this application, a code processing method is provided.

[0028] Figure 1 This is a flowchart of a code processing method according to an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps:

[0029] Step S102: Add the code provider as a node to the blockchain, encrypt the provided source code with a public key, and upload the encrypted source code as shared code to the blockchain.

[0030] Specifically, a blockchain is established using each shared public code project as the smallest unit, with the code provider acting as the first node in the blockchain and encrypting and uploading the provided code to the blockchain.

[0031] Step S104: Add the code requester as a node to the blockchain and obtain the shared code on the blockchain as well as the code submission records of all nodes on the blockchain.

[0032] Specifically, the requesters of the shared public code project join the current blockchain as subsequent nodes. The shared content within the blockchain includes: the shared encrypted code, the code commit records of all nodes, and code confidentiality tools.

[0033] For example, if a partner wants to obtain shared code on the blockchain, it can join as a new node in the blockchain and, after joining, simultaneously obtain the shared encrypted code, code commit records of all nodes, and code confidentiality tools within the blockchain.

[0034] It's important to note that the shared encrypted code only needs to be the source code. The code security tool, however, must implement the following functions: Key management: It needs to store asymmetric keys used to encrypt and decrypt code within the blockchain. Each node submits the same set of encryption and decryption keys to all code on the blockchain, but these keys differ between nodes. Each node only retains the decryption key for the code it needs and the encryption / decryption key for its own submitted code. It also needs to store the key used to package, encrypt, and obfuscate code that is being taken out of the blockchain. Each blockchain node maintains one and only one such key, used to encrypt its code when other nodes request to package and take it out. Sandbox encryption capability: It manages the storage of the shared code on the blockchain and the configuration files within the code security tool. When code compilers, such as Eclipse and IntelliJ, access the blockchain through the sandbox, the sandbox decrypts the data before making it available to other programs. It also monitors code compilers accessing blockchain data through the sandbox, ensuring that code is only taken out when a blockchain node requests and receives permission. The interface is displayed with a watermark function throughout: When a code compiler program accesses encrypted data in the blockchain through the sandbox, an explicit watermark is added to the entire interface of the code compiler program. The watermark content can be the unique identification number of the current blockchain node plus the system time, which is obtained by obtaining the process handle of the program.

[0035] Step S106: When any node in the blockchain has a code acquisition requirement, a code acquisition request is sent to the corresponding code-providing node. The private key returned by the code-providing node in response to the code acquisition request is received, and the code to be acquired is decrypted using the private key. The first broadcast message sent by the code-providing node is also received, wherein the first broadcast message contains the code acquisition record.

[0036] Specifically, the node that requests the code obtains the decryption key A from the node that provides the code it needs. After the provider node agrees, it provides the decryption key A to the new node. The agreement information is then broadcast to all nodes in the blockchain. After all nodes acknowledge receipt of the information, they back up the handover information of the decryption key A, which is equivalent to an authorization record. Then, the provider provides the decryption key A to the new node.

[0037] Optionally, in the code processing method provided in the embodiments of this application, after sending a code acquisition request to the corresponding code providing node when any node in the blockchain has a code acquisition need, the method further includes: receiving a third broadcast message sent by the code providing node when it rejects the code acquisition request, wherein the third broadcast message contains a record of code acquisition failure.

[0038] Specifically, if the code provider disagrees with the code requester's access to the code, it will not provide the decryption key A and will broadcast a rejection message. This rejection message is equivalent to an authorization rejection record, which is then backed up by each node in the blockchain. Through this embodiment, messages are synchronized regardless of whether the code provider agrees or disagrees with the code requester's access to the code, allowing each node to obtain the latest code change records.

[0039] Step S108: When any node in the blockchain has a code change requirement, a code change request is sent to the associated node with the code change requirement. The code change operation is performed based on the message fed back by the associated node. The node that submits the code to be changed sends a second broadcast message to all nodes in the blockchain. The second broadcast message contains the code change record.

[0040] Specifically, code change requirements include various types, such as the need to create a new independent branch on the blockchain, the need to update an existing branch on the blockchain, and the need to synchronize and merge code. Among these, the need to create a new independent branch on the blockchain includes two situations: the submitted code is an update / modification of the code on other nodes, and the submitted code is a completely independent new project.

[0041] Regardless of the type of code change requirement, a code change request is sent to the associated node, and the code change operation is executed. If the current node is the committing node of the code to be changed, the current node sends a broadcast message of the code change to all nodes in the blockchain. If the current node is not the committing node of the code to be changed, the committing node sends a broadcast message of the code change to all nodes in the blockchain.

[0042] The code processing method provided in this application addresses the problems of complex code sharing methods and security vulnerabilities in related technologies. By adding the code provider as a node to the blockchain, encrypting the provided source code with a public key, and uploading the encrypted source code as shared code to the blockchain, the method also adds the code requester as a node to the blockchain, allowing them to obtain the shared code and code submission records of all nodes. When any node in the blockchain has a code acquisition request, a code acquisition request is sent to the corresponding code provider node. The method receives the private key returned by the code provider node in response to the code acquisition request, decrypts the code to be acquired using the private key, and receives a first broadcast message from the code provider node, which contains the code acquisition record. When any node in the blockchain has a code change request, a code change request is sent to the associated node with the code change request. Based on the feedback from the associated node, a code change operation is performed, and the node submitting the code to be changed sends a second broadcast message to all nodes in the blockchain, which contains the code change record. This method solves the problems of complex code sharing methods and security vulnerabilities in related technologies. By using the code provider and the code requester as nodes on the blockchain for encrypted code upload, decryption of shared code, code changes, and broadcasting each executed code operation, a flexible and secure code sharing effect is achieved.

[0043] Optionally, in the code processing method provided in this application embodiment, when there is a code change requirement on any node of the blockchain, a code change request is sent to the associated node with the code change requirement, and the code change operation is performed based on the message fed back by the associated node. This includes: when the current node with the change requirement needs to create branch code, and the object of the change requirement is code outside the current node, the current node determines the associated submission nodes according to the submission record of the code to be changed, and sends the code change request to the associated submission nodes in chronological order, wherein the chronological order is the reverse order of the submission time of the code to be changed; when all associated submission nodes have given their consent messages, a branch code is created on the current node, the branch code is encrypted using the public key of the current node, and the encrypted branch code is synchronized to all nodes on the blockchain; when at least one associated submission node has given its rejection message, the creation of the branch code is terminated.

[0044] Specifically, if the current node is creating a new independent branch on the blockchain, and the submitted code is an update / modification of the code of other nodes, the node that submitted the most recent code submission is found according to the code submission record to request modification. After the requested node agrees, it broadcasts the agreement information to all nodes in the blockchain. Each node saves the agreement information as an authorization record. If the code involves multiple requested nodes to modify it in turn, it needs to be confirmed in the order of code submission from the last to the first. That is, the node that submitted the code last has priority, and the node that has already confirmed it does not need to confirm it again.

[0045] If all the nodes that submitted the code agree, the current node that submitted the code creates a new code branch and generates a separate encryption key A and decryption key A for the branch. Encryption key A is used to encrypt the code in the branch. The encrypted code is synchronized to all nodes on the blockchain. Decryption key A is provided to authorized nodes as needed. The authorization record needs to be backed up by all nodes. It is independent of the encryption and decryption keys of other code on the blockchain.

[0046] If the requested node rejects the application, the code submission is terminated. The node that rejected the application broadcasts the rejection record, and the node that approved the application broadcasts the authorization record. Each node treats the rejection and authorization records as backups. The submitting node can adjust its submission based on the authorization and rejection results and then resubmit. If the code involves multiple nodes, the application is submitted to multiple nodes. If some of the multiple nodes reject the application, it means that the request is rejected.

[0047] Through this embodiment, when updating / modifying the code of other nodes, the consent of all associated requesting nodes is obtained. With their consent, a code branch is created by the current node submitting the code and uploaded in an encrypted manner, thereby achieving the purpose of updating / modifying the code of nodes in a reasonable and secure way.

[0048] Optionally, in the code processing method provided in this application embodiment, when there is a code change requirement on any node of the blockchain, a code change request is sent to the associated node with the code change requirement, and the code change operation is performed based on the message fed back by the associated node. This includes: when the current node with the change requirement needs to create branch code, and the object of the change requirement is the code of the current node, creating branch code on the current node, encrypting the branch code using the public key of the current node, and synchronizing the encrypted branch code to all nodes on the blockchain.

[0049] Specifically, if the submitted code is a completely independent new project, a new branch is created for that project, and this branch is regarded as the original branch of the project. A separate encryption key A and decryption key A are generated for this branch. Encryption key A is used to encrypt the code of this branch. The encrypted code is synchronized to all nodes on the blockchain. Decryption key A is provided to authorized nodes as needed. The authorization record needs to be backed up by all nodes.

[0050] Optionally, in the code processing method provided in this application embodiment, when any node in the blockchain has a code change requirement, a code change request is sent to the associated node with the code change requirement, and the code change operation is performed based on the message fed back by the associated node, including: when the current node with the change requirement does not need to create branch code, the current node determines the associated submission node according to the submission record of the code to be changed, and sends the code change request to the associated submission node in chronological order, wherein the chronological order is the reverse order of the submission time of the code to be changed; when all associated submission nodes have given their consent messages, it is determined whether the current node is the initial submission node of the code to be changed; when the current node is the initial submission node of the code to be changed, the code to be changed is encrypted using the public key of the current node, and the encrypted code to be changed is synchronized to all nodes on the blockchain; when the current node is not the initial submission node of the code to be changed, the code is sent to the initial submission node, the code to be changed is encrypted using the public key of the initial submission node, and the encrypted code to be changed is synchronized to all nodes on the blockchain; when at least one associated submission node has given its rejection message, the submission of the code to be changed is terminated.

[0051] Specifically, if the current node is not creating a new branch on the blockchain, but updating an existing branch, the code to be updated is confirmed sequentially from the last commit to the last commit, based on the commit records of the code to be updated. That is, the nodes that commit later have priority in confirmation, and those that have already been confirmed do not need to be confirmed again. The confirmation information is broadcast to all nodes in the blockchain.

[0052] Furthermore, once all nodes agree, each node saves the agreement information as an authorization record. If any node disagrees, the code submission is terminated. The node that rejects the code broadcasts the rejection record, while the node that approves the code broadcasts the authorization record. The submitting node can adjust its submission based on the authorization and rejection results and then resubmit.

[0053] If all nodes agree, the current node encrypts the code using the encryption key A of the branch containing the code, then broadcasts the encrypted code to all nodes for synchronization, along with the commit history. It's important to note that if encryption key A for that branch is not on the current node, the code is sent to the node holding encryption key A. That node encrypts the code, broadcasts it to all nodes for synchronization, and also synchronizes the commit history. In other words, this process requires the approval of the node holding encryption key A before it encrypts and broadcasts the code. If the node holding encryption key A rejects the commit request, the user can rectify the issues based on the reason provided in the rejection message and resubmit the request.

[0054] In this embodiment, when updating an existing branch, the consent of all associated application nodes is obtained, and with their consent, the existing branch is updated through the current node that submits the code, thus achieving the purpose of updating the existing branch reasonably and safely.

[0055] Optionally, in the code processing method provided in this application embodiment, when there is a code change requirement at any node in the blockchain, a code change request is sent to the associated node with the code change requirement, and the code change operation is performed based on the message fed back by the associated node. This includes: when the change requirement is for the current node to merge the code of the target node, the current node sends a code merge request to the target node, wherein the target node is a target node other than the current node, and the merge request carries the merged code obtained after the current node merges the code of the target node; when receiving an agreement message from the target node, it is determined whether the current node is the initial submission node of the code to be merged; when the current node is the initial submission node of the code to be merged, the merged code is encrypted using the public key of the current node, and the encrypted merged code is synchronized to all nodes on the blockchain; when the current node is not the initial submission node of the code to be merged, the merged code is sent to the initial submission node, the merged code is encrypted using the public key of the initial submission node, and the encrypted merged code is synchronized to all nodes on the blockchain.

[0056] It's important to note that synchronized code merging means that after creating a new branch, the code in the new branch is independent of the original branch and does not interfere with each other. However, if needed, one branch can merge subsequent changes from the other branch. The branch initiating the merge is designated as branch A, and the branch being merged is designated as branch B. Branch merges must be initiated by the node on branch A.

[0057] Specifically, branch A first performs code merging on its local node, and then sends a merge request to branch B. This request information is broadcast to all nodes as an application approval record for backup. After branch B agrees, this agreement information is broadcast to all nodes as an approval record for backup.

[0058] Furthermore, the local node encrypts the code using the encryption key A of the branch containing the code, then broadcasts the encrypted code to all nodes for synchronization, along with the commit history. If the encryption key A corresponding to this branch is not on the local node, the code is sent to the node containing encryption key A, which encrypts it and broadcasts it to all nodes for synchronization, along with the commit history. If the node containing encryption key A rejects the commit request, the user can rectify the issues based on the reason in the rejection message and resubmit the request.

[0059] In this embodiment, when merging code, the consent of the nodes being merged is obtained, and with their consent, branch merging is performed, thus achieving the purpose of merging code reasonably and safely.

[0060] Optionally, in the code processing method provided in the embodiments of this application, the method further includes: when there is a code extraction requirement at any node of the blockchain, sending a code extraction request to the corresponding code providing node, wherein the code extraction requirement is a requirement to extract the target code from the blockchain; upon receiving an agreement message from the code providing node, sending a code extraction request to the associated nodes of the target code; upon receiving agreement messages from all associated nodes, performing an extraction operation on the target code and sending a fourth broadcast message to all nodes of the blockchain, wherein the fourth broadcast message contains the code extraction record.

[0061] Specifically, code export refers to a node requesting to encrypt and package its code for use by a third party. If a node needs to package and release its code, it must submit a request to the node holding the encryption key A for the branch containing the code—that is, the node that created this branch, denoted as node X. If node X agrees (if node X refuses, the process terminates, but can be adjusted and resubmitted based on the refusal details), node X broadcasts confirmation to all nodes. All nodes reply that they agree to have node X use its key B to encrypt and obfuscate the code, then send it to the requesting node for export. It should be noted that all application, agreement, and refusal information throughout the entire process must be broadcast to all nodes for backup.

[0062] In this embodiment, when code is pulled out, the consent of all associated application nodes is obtained, and with their consent, the target code is pulled out by the current node that submitted the code, thereby achieving the purpose of updating the existing branch reasonably and safely.

[0063] Optionally, in the code processing method provided in this application embodiment, after receiving an agreement message from the code providing node and sending a code extraction request to the associated node of the target code, the method further includes: upon receiving a rejection message from at least one associated node, obtaining the association record between the rejection node and the target code, verifying the association record, and obtaining a verification result, wherein the association record is a record of the rejection node participating in the submission of the target code; sending the verification result to all nodes, and if the verification result indicates that the rejection of the associated node is an invalid rejection, and a preset proportion of nodes pass the verification result, encrypting the target code using a communication key, sending the encrypted target code to the node that issued the code extraction request, and sending a fifth broadcast message, wherein the fifth broadcast message contains the code extraction record; if the verification result indicates that the rejection of the associated node is a valid rejection, terminating the target code extraction operation, and sending a sixth broadcast message, wherein the sixth broadcast message contains the record of code extraction failure.

[0064] Specifically, when node X broadcasts confirmation to all nodes, if any node rejects, the process terminates. It can be re-initiated after adjustments based on the rejection details. However, the rejecting node must provide a record of its associated operations with the branch currently being packaged; that is, a record of the node successfully submitting its approval. After receiving the rejection information and the record, node X verifies the historical information in its local records. Only if the information matches and the submitted code is still within the code being requested is it considered a valid rejection; otherwise, it is considered an approval. This verification result is broadcast to all nodes for the same verification. The result of verification by more than half of the nodes is considered successful. For example, if 5 nodes succeed and 2 fail, the verification is successful.

[0065] This embodiment ensures that when sharing open-source code, participants can obtain only the required open-source code. At the same time, the participants supervise each other throughout the process to ensure that the code is approved by all participants during its use, thus avoiding the cumbersome manual management and potential oversight.

[0066] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0067] This application also provides a code processing apparatus. It should be noted that the code processing apparatus of this application can be used to execute the code processing method provided in this application. The code processing apparatus provided in this application will be described below.

[0068] Figure 2 This is a schematic diagram of a code processing apparatus according to an embodiment of this application. Figure 2 As shown, the device includes: a first node addition unit 201, a second node addition unit 202, a code acquisition unit 203, and a code modification unit 204.

[0069] Specifically, the first node joining unit 201 is used to add the code provider as a node to the blockchain, encrypt the provided source code with a public key, and upload the encrypted source code to the blockchain as shared code.

[0070] The second node joining unit 202 is used to add the code requester as a node to the blockchain, and obtain the shared code on the blockchain as well as the code submission records of all nodes in the blockchain.

[0071] The code acquisition unit 203 is used to send a code acquisition request to the corresponding code providing node when there is a code acquisition need on any node of the blockchain, receive the private key returned by the code providing node in the case of the code acquisition request, decrypt the code to be acquired with the private key, and receive a first broadcast message sent by the code providing node, wherein the first broadcast message contains the code acquisition record.

[0072] The code change unit 204 is used to send a code change request to the associated node when there is a code change requirement on any node of the blockchain, perform the code change operation based on the message fed back by the associated node, and send a second broadcast message to all nodes of the blockchain by the node that submits the code to be changed, wherein the second broadcast message contains the code change record.

[0073] The code processing apparatus provided in this application embodiment includes a first node joining unit 201, used to add the code provider as a node to the blockchain, encrypt the provided source code using a public key, and upload the encrypted source code as shared code to the blockchain; a second node joining unit 202, used to add the code requester as a node to the blockchain, obtain the shared code on the blockchain and the code submission records of all nodes in the blockchain; and a code acquisition unit 203, used to send a code acquisition request to the corresponding code provider node when any node in the blockchain has a code acquisition request, receive the private key returned by the code provider node in response to the code acquisition request, decrypt the code to be acquired using the private key, and receive a first broadcast sent by the code provider node. The message includes a first broadcast message containing code acquisition records; a code change unit 204 is used to send a code change request to the associated node when there is a code change requirement on any node of the blockchain, execute the code change operation based on the message fed back by the associated node, and send a second broadcast message containing code change records from the submitting node of the code to be changed to all nodes of the blockchain. This solves the problems of complex code sharing methods and security risks in related technologies. By using the code provider and the code requester as nodes on the blockchain, the code is encrypted and uploaded, shared, and changed, and each executed code operation is broadcast, thereby achieving flexible and secure code sharing.

[0074] Optionally, in the code processing apparatus provided in the embodiments of this application, the apparatus further includes: a first receiving unit, configured to, when any node in the blockchain has a code acquisition requirement, send a code acquisition request to the corresponding code providing node, and then receive a third broadcast message sent by the code providing node when it rejects the code acquisition request, wherein the third broadcast message contains a record of code acquisition failure.

[0075] Optionally, in the code processing apparatus provided in this application embodiment, the code change unit 204 includes: a submission module, used to determine associated submission nodes based on the submission records of the code to be changed by the current node when a branch code needs to be created at the current node and the object of the change request is code outside the current node, and to send code change requests to the associated submission nodes in chronological order, wherein the chronological order is the reverse order of the submission time of the code to be changed; a first branch creation module, used to create branch code at the current node after receiving consent messages from all associated submission nodes, encrypt the branch code using the public key of the current node, and synchronize the encrypted branch code to all nodes on the blockchain; and a first termination module, used to terminate the creation of the branch code after receiving rejection messages from at least one associated submission node.

[0076] Optionally, in the code processing apparatus provided in this application embodiment, the code change unit 204 includes: a second branch establishment module, used to establish branch code on the current node when there is a change requirement and the object of the change requirement is the code of the current node, encrypt the branch code using the public key of the current node, and synchronize the encrypted branch code to all nodes on the blockchain.

[0077] Optionally, in the code processing apparatus provided in this application embodiment, the code change unit 204 includes: a code change request sending module, used to determine the associated submission nodes based on the submission records of the code to be changed when the current node with change requirements does not need to create branch code, and send code change requests to the associated submission nodes in chronological order, wherein the chronological order is the reverse order of the submission time of the code to be changed; a first judgment module, used to determine whether the current node is the initial submission node of the code to be changed when receiving consent messages from all associated submission nodes; a first encryption module, used to encrypt the code to be changed using the public key of the current node when the current node is the initial submission node of the code to be changed, and synchronize the encrypted code to be changed to all nodes on the blockchain; a second encryption module, used to send the code to the initial submission node when the current node is not the initial submission node of the code to be changed, encrypt the code to be changed using the public key of the initial submission node, and synchronize the encrypted code to be changed to all nodes on the blockchain; and a second termination module, used to terminate the submission of the code to be changed when receiving rejection messages from at least one associated submission node.

[0078] Optionally, in the code processing apparatus provided in this application embodiment, the code change unit 204 includes: a code merge request sending module, used to send a code merge request from the current node to the target node when the change requirement is for the current node to merge the code of the target node, wherein the target node is a target node other than the current node, and the merge request carries the merged code obtained after the current node merges the code of the target node; a second judgment module, used to determine whether the current node is the initial submission node of the code to be merged when receiving an agreement message from the target node; a third encryption module, used to encrypt the merged code using the public key of the current node when the current node is the initial submission node of the code to be merged, and synchronize the encrypted merged code to all nodes on the blockchain; and a fourth encryption module, used to send the merged code to the initial submission node when the current node is not the initial submission node of the code to be merged, encrypt the merged code using the public key of the initial submission node, and synchronize the encrypted merged code to all nodes on the blockchain.

[0079] Optionally, in the code processing apparatus provided in this application embodiment, the apparatus further includes: a first sending unit, configured to send a code extraction request to the corresponding code providing node when there is a code extraction request at any node of the blockchain, wherein the code extraction request is a request to extract the target code from the blockchain; a second sending unit, configured to send a code extraction request to the associated nodes of the target code when receiving an agreement message from the code providing node; and an execution unit, configured to perform an extraction operation on the target code when receiving agreement messages from all associated nodes, and send a fourth broadcast message to all nodes of the blockchain, wherein the fourth broadcast message contains the code extraction record.

[0080] Optionally, in the code processing apparatus provided in this application embodiment, the apparatus further includes: an acquisition unit, configured to, upon receiving an agreement message from a code providing node, send a code extraction request to the associated node of the target code; and upon receiving a rejection message from at least one associated node, acquire an association record between the rejecting node and the target code, verify the association record, and obtain a verification result, wherein the association record is a record of the rejecting node participating in the submission of the target code; a code extraction unit, configured to send the verification result to all nodes; and, if the verification result indicates that the rejection by the associated node is invalid and a preset proportion of nodes pass the verification result, encrypt the target code using a communication key, send the encrypted target code to the node that issued the code extraction request, and send a fifth broadcast message, wherein the fifth broadcast message contains the code extraction record; and a termination unit, configured to, if the verification result indicates that the rejection by the associated node is valid, terminate the target code extraction operation and send a sixth broadcast message, wherein the sixth broadcast message contains a record of code extraction failure.

[0081] The aforementioned code processing device includes a processor and a memory. The first node addition unit 201, the second node addition unit 202, the code acquisition unit 203, and the code modification unit 204 are all stored in the memory as program units. The processor executes the aforementioned program units stored in the memory to realize the corresponding functions.

[0082] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the complexities and security vulnerabilities associated with code sharing in related technologies.

[0083] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0084] This application also provides a non-volatile storage medium, which includes a stored program, wherein the program, when running, controls the device where the non-volatile storage medium is located to execute a code processing method.

[0085] This application also provides an electronic device, such as... Figure 3 As shown, electronic device 301 includes a processor and a memory; the memory stores computer-readable instructions, and the processor executes the computer-readable instructions, wherein the computer-readable instructions perform a code processing method when executed. The electronic device in this document can be a server, PC, PAD, mobile phone, etc.

[0086] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0087] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0088] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0089] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0090] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0091] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0092] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0093] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0094] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A code processing method, characterized in that, include: The code provider is added to the blockchain as a node, the provided source code is encrypted with a public key, and the encrypted source code is uploaded to the blockchain as shared code. The code requester joins the blockchain as a node, obtains the shared code on the blockchain and the code submission records of all nodes on the blockchain, wherein the shared content within the blockchain also includes code confidentiality tools; When any node in the blockchain has a code acquisition requirement, a code acquisition request is sent to the corresponding code-providing node. The private key returned by the code-providing node in response to the code acquisition request is received, and the code to be acquired is decrypted using the private key. A first broadcast message sent by the code-providing node is also received, wherein the first broadcast message contains the code acquisition record. When any node in the blockchain has a code change requirement, a code change request is sent to the associated node of the code change requirement. Based on the message fed back by the associated node, the code change operation is performed, and the node that submitted the code to be changed sends a second broadcast message to all nodes in the blockchain, wherein the second broadcast message contains the code change record. Specifically, when any node in the blockchain has a code change requirement, a code change request is sent to the associated nodes of the code change requirement. The code change operation is then performed based on the messages from the associated nodes. This includes: if the current node with the change requirement does not need to create a branch, the current node determines the associated commit nodes based on the commit records of the code to be changed, and sends the code change request to the associated commit nodes sequentially in chronological order, where the chronological order is the reverse chronological order of the commit times of the code to be changed; and if all associated commit nodes return agreement messages, it is determined whether the current node is the node to be changed. The initial commit node for the code to be changed; if the current node is the initial commit node for the code to be changed, the code to be changed is encrypted using the public key of the current node, and the encrypted code to be changed is synchronized to all nodes on the blockchain; if the current node is not the initial commit node for the code to be changed, the code is sent to the initial commit node, the code to be changed is encrypted using the public key of the initial commit node, and the encrypted code to be changed is synchronized to all nodes on the blockchain; if a rejection message is received from at least one of the associated commit nodes, the submission of the code to be changed is terminated.

2. The method according to claim 1, characterized in that, When any node in the blockchain has a code acquisition need, after sending a code acquisition request to the corresponding code-providing node, the method further includes: Receive a third broadcast message sent by the code providing node in the event that the code retrieval request is rejected, wherein the third broadcast message contains a record of code retrieval failure.

3. The method according to claim 1, characterized in that, When any node in the blockchain requires a code change, a code change request is sent to the associated node with the code change request. The code change operation is then performed based on the message returned by the associated node, including: If the current node with the change requirement needs to create a branch code, and the object of the change requirement is code outside the current node, the current node determines the associated commit node based on the commit record of the code to be changed, and sends the code change request to the associated commit node in chronological order, wherein the chronological order is the reverse order of the commit time of the code to be changed. Upon receiving consent messages from all associated submission nodes, the branch code is created on the current node, encrypted using the public key of the current node, and the encrypted branch code is synchronized to all nodes on the blockchain. If a rejection message is received from at least one of the associated commit nodes, the creation of the branch code is terminated.

4. The method according to claim 1, characterized in that, When any node in the blockchain requires a code change, a code change request is sent to the associated node with the code change request. The code change operation is then performed based on the message returned by the associated node, including: If a current node with a change requirement needs to create a branch code, and the object of the change requirement is the code of the current node, the branch code is created on the current node, the branch code is encrypted using the public key of the current node, and the encrypted branch code is synchronized to all nodes on the blockchain.

5. The method according to claim 1, characterized in that, When any node in the blockchain requires a code change, a code change request is sent to the associated node with the code change request. The code change operation is then performed based on the message returned by the associated node, including: When the change request is for the current node to merge the code of the target node, the current node sends a code merge request to the target node, wherein the target node is a target node other than the current node, and the merge request carries the merged code obtained by the current node merging the code of the target node; Upon receiving an agreement message from the target node, determine whether the current node is the initial submission node for the code to be merged; If the current node is the initial submission node of the code to be merged, the merged code is encrypted using the public key of the current node, and the encrypted merged code is synchronized to all nodes on the blockchain; If the current node is not the initial commit node of the code to be merged, the merged code is sent to the initial commit node, the merged code is encrypted using the public key of the initial commit node, and the encrypted merged code is synchronized to all nodes on the blockchain.

6. The method according to claim 1, characterized in that, The method further includes: When any node in the blockchain has a code extraction requirement, a code extraction request is sent to the corresponding code providing node, wherein the code extraction requirement is the requirement to extract the target code from the blockchain. Upon receiving a consent message from the node providing the code, a code extraction request is sent to the associated node of the target code; Upon receiving consent messages from all associated nodes, a code-out operation is performed on the target code, and a fourth broadcast message is sent to all nodes of the blockchain, wherein the fourth broadcast message contains the code-out record.

7. The method according to claim 6, characterized in that, Upon receiving an agreement message from the code-providing node, after sending the code-extraction request to the associated node of the target code, the method further includes: Upon receiving a rejection message from at least one of the associated nodes, the association record between the rejection node and the target code is obtained, and the association record is verified to obtain a verification result, wherein the association record is a record of the rejection node participating in the submission of the target code; The verification result is sent to all nodes. If the verification result is that the rejection of the associated node is invalid and a preset proportion of nodes pass the verification result, the target code is encrypted using a communication key. The encrypted target code is then sent to the node that issued the code takeout request, and a fifth broadcast message is sent, wherein the fifth broadcast message contains the code takeout record. If the verification result indicates that the rejection of the associated node is a valid rejection, then the target code extraction operation is terminated, and a sixth broadcast message is sent, wherein the sixth broadcast message contains a record of code extraction failure.

8. A code processing device, characterized in that, include: The first node joining unit is used to add the code provider as a node to the blockchain, encrypt the provided source code with a public key, and upload the encrypted source code as shared code to the blockchain. The second node joining unit is used to add code requesters as nodes to the blockchain, obtain the shared code on the blockchain and the code submission records of all nodes in the blockchain, wherein the shared content within the blockchain also includes code confidentiality tools; The code acquisition unit is configured to send a code acquisition request to the corresponding code providing node when any node in the blockchain has a code acquisition need, receive the private key returned by the code providing node in response to the code acquisition request, decrypt the code to be acquired using the private key, and receive a first broadcast message sent by the code providing node, wherein the first broadcast message contains a code acquisition record. The code change unit is used to send a code change request to the associated node of the code change request when there is a code change requirement on any node of the blockchain, perform a code change operation based on the message fed back by the associated node, and send a second broadcast message to all nodes of the blockchain by the node that submits the code to be changed, wherein the second broadcast message contains the code change record. The code change unit includes: a code change request sending module, used to determine associated commit nodes based on the commit records of the code to be changed when the current node with change requirements does not need to create branch code, and to send code change requests to the associated commit nodes in chronological order, wherein the chronological order is the reverse order of the commit times of the code to be changed; a first judgment module, used to determine whether the current node is the initial commit node of the code to be changed when receiving consent messages from all associated commit nodes; a first encryption module, used to encrypt the code to be changed using the public key of the current node when the current node is the initial commit node of the code to be changed, and to synchronize the encrypted code to be changed to all nodes on the blockchain; a second encryption module, used to send the code to the initial commit node when the current node is not the initial commit node of the code to be changed, encrypt the code to be changed using the public key of the initial commit node, and to synchronize the encrypted code to be changed to all nodes on the blockchain; and a second termination module, used to terminate the submission of the code to be changed when receiving a rejection message from at least one associated commit node.

9. A non-volatile storage medium, characterized in that, The non-volatile storage medium includes a stored program, wherein the program, when running, controls the device where the non-volatile storage medium is located to execute the code processing method according to any one of claims 1 to 7.

10. An electronic device, characterized in that, The device includes a processor and a memory, the memory storing computer-readable instructions, and the processor being configured to execute the computer-readable instructions, wherein the computer-readable instructions, when executed, perform the code processing method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Public security system archive management method based on blockchain

    CN108491291A

  • Data sharing method, system and device, equipment and storage medium

    CN112532646A

  • Block chain-based co-construction code backup library processing method and system

    CN113220503A