[go: up one dir, main page]

CN111523110B - Authority query configuration method and device based on chain codes - Google Patents

Authority query configuration method and device based on chain codes Download PDF

Info

Publication number
CN111523110B
CN111523110B CN202010307195.XA CN202010307195A CN111523110B CN 111523110 B CN111523110 B CN 111523110B CN 202010307195 A CN202010307195 A CN 202010307195A CN 111523110 B CN111523110 B CN 111523110B
Authority
CN
China
Prior art keywords
transaction
query
contract
historical transaction
code
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010307195.XA
Other languages
Chinese (zh)
Other versions
CN111523110A (en
Inventor
刘琦
闫莺
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ant Blockchain Technology Shanghai Co Ltd
Original Assignee
Alipay Hangzhou Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Alipay Hangzhou Information Technology Co Ltd filed Critical Alipay Hangzhou Information Technology Co Ltd
Priority to CN202010307195.XA priority Critical patent/CN111523110B/en
Publication of CN111523110A publication Critical patent/CN111523110A/en
Application granted granted Critical
Publication of CN111523110B publication Critical patent/CN111523110B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/30Authentication, i.e. establishing the identity or authorisation of security principals
    • G06F21/45Structures or tools for the administration of authentication
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/60Protecting data
    • G06F21/62Protecting access to data via a platform, e.g. using keys or access control rules
    • G06F21/6218Protecting access to data via a platform, e.g. using keys or access control rules to a system of files or objects, e.g. local or distributed file system or database
    • G06F21/6245Protecting personal data, e.g. for financial or medical purposes
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Business, Economics & Management (AREA)
  • Finance (AREA)
  • General Health & Medical Sciences (AREA)
  • Bioethics (AREA)
  • Health & Medical Sciences (AREA)
  • Accounting & Taxation (AREA)
  • Databases & Information Systems (AREA)
  • Strategic Management (AREA)
  • Probability & Statistics with Applications (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Mathematical Physics (AREA)
  • Fuzzy Systems (AREA)
  • General Business, Economics & Management (AREA)
  • Technology Law (AREA)
  • Marketing (AREA)
  • Economics (AREA)
  • Development Economics (AREA)
  • Medical Informatics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

本说明书一个或多个实施例提供一种基于链代码的权限查询配置方法及装置;该方法应用于区块链节点,可以包括:将获取到的分发代码读入可信执行环境,以对所述可信执行环境中维护的链代码进行更新,所述分发代码用于在接收到查询方针对与历史交易相关的隐私数据的查询交易时,调用所述历史交易所调用的业务合约以执行所述业务合约中定义的权限控制代码,确定所述查询方的查询权限;当接收到挑战方发起的针对所述分发代码的验证请求时,读取所述可信执行环境中维护的分发代码以生成验证报告,并向所述挑战方发送所述验证报告,以使得所述挑战方根据所述验证报告对所述可信执行环境中的分发代码进行验证。

Figure 202010307195

One or more embodiments of this specification provide a chaincode-based permission query configuration method and device; the method is applied to blockchain nodes, and may include: reading the obtained distribution code into a trusted execution environment to The chain code maintained in the above-mentioned trusted execution environment is updated, and the distribution code is used to call the business contract called by the historical transaction to execute the transaction when the query party receives the query transaction of the private data related to the historical transaction The authority control code defined in the above-mentioned business contract determines the inquiry authority of the inquiring party; when receiving the verification request for the distribution code initiated by the challenger, read the distribution code maintained in the trusted execution environment to generating a verification report, and sending the verification report to the challenger, so that the challenger verifies the distribution code in the trusted execution environment according to the verification report.

Figure 202010307195

Description

基于链代码的权限查询配置方法及装置Method and device for permission query configuration based on chain code

技术领域technical field

本说明书一个或多个实施例涉及区块链技术领域,尤其涉及一种基于链代码的权限查询配置方法及装置。One or more embodiments of this specification relate to the technical field of blockchain, and in particular to a chaincode-based authority query configuration method and device.

背景技术Background technique

区块链技术构建在传输网络(例如点对点网络)之上。传输网络中的网络节点利用链式数据结构来验证与存储数据,并采用分布式节点共识算法来生成和更新数据。Blockchain technology is built on top of transmission networks such as peer-to-peer networks. Network nodes in the transmission network use chained data structures to verify and store data, and use distributed node consensus algorithms to generate and update data.

目前企业级的区块链平台技术上最大的两个挑战就是隐私和性能,往往这两个挑战很难同时解决。大多解决方案都是通过损失性能换取隐私,或者不大考虑隐私去追求性能。常见的解决隐私问题的加密技术,如同态加密(Homomorphic encryption)和零知识证明(Zero-knowledge proof)等复杂度高,通用性差,而且还可能带来严重的性能损失。At present, the two biggest challenges in the technology of enterprise-level blockchain platforms are privacy and performance, and it is often difficult to solve these two challenges at the same time. Most solutions trade for privacy by losing performance, or pursue performance with little regard for privacy. Common encryption technologies to solve privacy problems, such as Homomorphic encryption and zero-knowledge proof, are highly complex, poor in versatility, and may cause serious performance loss.

可信执行环境(Trusted Execution Environment,TEE)是另一种解决隐私问题的方式。TEE可以起到硬件中的黑箱作用,在TEE中执行的代码和数据操作系统层都无法偷窥,只有代码中预先定义的接口才能对其进行操作。在效率方面,由于TEE的黑箱性质,在TEE中进行运算的是明文数据,而不是同态加密中的复杂密码学运算,计算过程效率没有损失,因此与TEE相结合可以在性能损失较小的前提下很大程度上提升区块链的安全性和隐私性。目前工业界十分关注TEE的方案,几乎所有主流的芯片和软件联盟都有自己的TEE解决方案,包括软件方面的TPM(Trusted Platform Module,可信赖平台模块)以及硬件方面的Intel SGX(Software Guard Extensions,软件保护扩展)、ARM Trustzone(信任区)和AMDPSP(Platform Security Processor,平台安全处理器)。Trusted Execution Environment (TEE) is another way to solve the privacy problem. TEE can function as a black box in the hardware, and the code and data operating system layer executed in the TEE cannot be peeked at, and only the predefined interface in the code can operate on it. In terms of efficiency, due to the black-box nature of TEE, plaintext data is used for operations in TEE, rather than complex cryptographic operations in homomorphic encryption, and there is no loss in the efficiency of the calculation process. Under the premise, the security and privacy of the blockchain are greatly improved. At present, the industry is very concerned about TEE solutions. Almost all mainstream chip and software alliances have their own TEE solutions, including TPM (Trusted Platform Module) in software and Intel SGX (Software Guard Extensions) in hardware. , Software Protection Extension), ARM Trustzone (Trust Zone) and AMDPSP (Platform Security Processor, Platform Security Processor).

发明内容Contents of the invention

有鉴于此,本说明书一个或多个实施例提供一种基于智能合约的权限查询配置方法及装置、电子设备、存储介质。In view of this, one or more embodiments of this specification provide a smart contract-based permission query configuration method and device, electronic equipment, and a storage medium.

为实现上述目的,本说明书一个或多个实施例提供技术方案如下:In order to achieve the above purpose, one or more embodiments of this specification provide technical solutions as follows:

根据本说明书一个或多个实施例的第一方面,提出了一种基于链代码的权限查询配置方法,应用于区块链节点;所述方法包括:According to the first aspect of one or more embodiments of this specification, a chaincode-based permission query configuration method is proposed, which is applied to blockchain nodes; the method includes:

将获取到的分发代码读入可信执行环境,以对所述可信执行环境中维护的链代码进行更新,所述分发代码用于在接收到查询方针对与历史交易相关的隐私数据的查询交易时,调用所述历史交易所调用的业务合约以执行所述业务合约中定义的权限控制代码,确定所述查询方的查询权限;Read the obtained distribution code into the trusted execution environment to update the chain code maintained in the trusted execution environment, and the distribution code is used for querying the privacy data related to the historical transaction by the party receiving the query During the transaction, call the business contract called by the historical transaction to execute the authority control code defined in the business contract, and determine the inquiry authority of the inquiring party;

当接收到挑战方发起的针对所述分发代码的验证请求时,读取所述可信执行环境中维护的分发代码以生成验证报告,并向所述挑战方发送所述验证报告,以使得所述挑战方根据所述验证报告对所述可信执行环境中的分发代码进行验证。When receiving a verification request for the distribution code initiated by the challenger, read the distribution code maintained in the trusted execution environment to generate a verification report, and send the verification report to the challenger, so that the The challenger verifies the distribution code in the trusted execution environment according to the verification report.

根据本说明书一个或多个实施例的第二方面,提出了一种隐私数据的查询方法,应用于区块链节点;所述方法包括:According to the second aspect of one or more embodiments of this specification, a private data query method is proposed, which is applied to blockchain nodes; the method includes:

当接收到查询方提交的与历史交易相关的隐私数据的查询交易时,读取可信执行环境中维护的分发代码,所述分发代码属于所述可信执行环境中维护的链代码的一部分;When receiving the query transaction of the privacy data related to the historical transaction submitted by the querying party, read the distribution code maintained in the trusted execution environment, and the distribution code is part of the chain code maintained in the trusted execution environment;

在所述可信执行环境中执行所述分发代码,以根据所述历史交易所调用的业务合约中定义的权限控制代码确定所述查询方的查询权限;Execute the distribution code in the trusted execution environment to determine the query authority of the inquiring party according to the authority control code defined in the business contract invoked by the historical transaction;

当确定出的查询权限为允许查询时,获取解密后的所述隐私数据以由所述查询方查看,所述隐私数据被读入可信执行环境进行解密。When it is determined that the query authority is allowed to query, the decrypted private data is obtained for viewing by the querying party, and the private data is read into a trusted execution environment for decryption.

根据本说明书一个或多个实施例的第三方面,提出了一种基于链代码的权限查询配置装置,应用于区块链节点;所述装置包括:According to a third aspect of one or more embodiments of this specification, a chaincode-based permission query configuration device is proposed, which is applied to blockchain nodes; the device includes:

第一更新单元,将获取到的分发代码读入可信执行环境,以对所述可信执行环境中维护的链代码进行更新,所述分发代码用于在接收到查询方针对与历史交易相关的隐私数据的查询交易时,调用所述历史交易所调用的业务合约以执行所述业务合约中定义的权限控制代码,确定所述查询方的查询权限;The first update unit reads the obtained distribution code into the trusted execution environment, so as to update the chain code maintained in the trusted execution environment, and the distribution code is used for the transaction related to the historical transaction when the query is received. When inquiring about private data of private data, call the business contract invoked by the historical transaction to execute the authority control code defined in the business contract, and determine the inquiry authority of the inquiring party;

验证单元,当接收到挑战方发起的针对所述分发代码的验证请求时,读取所述可信执行环境中维护的分发代码以生成验证报告,并向所述挑战方发送所述验证报告,以使得所述挑战方根据所述验证报告对所述可信执行环境中的分发代码进行验证。The verification unit reads the distribution code maintained in the trusted execution environment to generate a verification report when receiving a verification request for the distribution code initiated by the challenger, and sends the verification report to the challenger, so that the challenger verifies the distribution code in the trusted execution environment according to the verification report.

根据本说明书一个或多个实施例的第四方面,提出了一种隐私数据的查询装置,应用于区块链节点;所述装置包括:According to the fourth aspect of one or more embodiments of this specification, a device for querying private data is proposed, which is applied to blockchain nodes; the device includes:

代码读取单元,当接收到查询方提交的与历史交易相关的隐私数据的查询交易时,读取可信执行环境中维护的分发代码,所述分发代码属于所述可信执行环境中维护的链代码的一部分;The code reading unit reads the distribution code maintained in the trusted execution environment when receiving the query transaction of the private data related to the historical transaction submitted by the querying party, and the distribution code belongs to the distribution code maintained in the trusted execution environment part of the chaincode;

权限确定单元,在所述可信执行环境中执行所述分发代码,以根据所述历史交易所调用的业务合约中定义的权限控制代码确定所述查询方的查询权限;an authority determining unit, executing the distribution code in the trusted execution environment to determine the inquiry authority of the inquiring party according to the authority control code defined in the business contract invoked by the historical transaction;

数据获取单元,当确定出的查询权限为允许查询时,获取解密后的所述隐私数据以由所述查询方查看,所述隐私数据被读入可信执行环境进行解密。The data obtaining unit obtains the decrypted private data to be viewed by the querying party when the determined query authority is allowed to query, and the private data is read into a trusted execution environment for decryption.

根据本说明书一个或多个实施例的第五方面,提出了一种电子设备,包括:According to a fifth aspect of one or more embodiments of the present specification, an electronic device is provided, including:

处理器;processor;

用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;

其中,所述处理器通过运行所述可执行指令以实现如第一方面所述的方法。Wherein, the processor implements the method according to the first aspect by running the executable instruction.

根据本说明书一个或多个实施例的第六方面,提出了一种电子设备,包括:According to a sixth aspect of one or more embodiments of the present specification, an electronic device is provided, including:

处理器;processor;

用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;

其中,所述处理器通过运行所述可执行指令以实现如第二方面所述的方法。Wherein, the processor implements the method according to the second aspect by running the executable instruction.

根据本说明书一个或多个实施例的第七方面,提出了一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如第一方面所述方法的步骤。According to a seventh aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect are implemented.

根据本说明书一个或多个实施例的第八方面,提出了一种计算机可读存储介质,其上存储有计算机指令,该指令被处理器执行时实现如第二方面所述方法的步骤。According to an eighth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the second aspect are implemented.

附图说明Description of drawings

图1是一示例性实施例提供的一种创建智能合约的示意图。Fig. 1 is a schematic diagram of creating a smart contract provided by an exemplary embodiment.

图2是一示例性实施例提供的一种调用智能合约的示意图。Fig. 2 is a schematic diagram of invoking a smart contract provided by an exemplary embodiment.

图3是一示例性实施例提供的一种调用业务合约的示意图。Fig. 3 is a schematic diagram of invoking a service contract provided by an exemplary embodiment.

图4A是一示例性实施例提供的一种基于链代码的权限查询配置方法的流程图。Fig. 4A is a flowchart of a chaincode-based permission query configuration method provided by an exemplary embodiment.

图4B是一示例性实施例提供的一种隐私数据的查询方法的流程图。Fig. 4B is a flowchart of a private data query method provided by an exemplary embodiment.

图5是一示例性实施例提供的一种针对分发代码进行远程证明的示意图。Fig. 5 is a schematic diagram of remote attestation for distributed codes provided by an exemplary embodiment.

图6-7是一示例性实施例提供的另一种隐私数据的查询方法的流程图。6-7 are flowcharts of another private data query method provided by an exemplary embodiment.

图8是一示例性实施例提供的一种设备的结构示意图。Fig. 8 is a schematic structural diagram of a device provided by an exemplary embodiment.

图9是一示例性实施例提供的一种隐私数据的查询装置的框图。Fig. 9 is a block diagram of an apparatus for querying private data provided by an exemplary embodiment.

图10是一示例性实施例提供的另一种设备的结构示意图。Fig. 10 is a schematic structural diagram of another device provided by an exemplary embodiment.

图11是一示例性实施例提供的另一种隐私数据的查询装置的框图。Fig. 11 is a block diagram of another device for querying private data provided by an exemplary embodiment.

具体实施方式Detailed ways

这里将详细地对示例性实施例进行说明,其示例表示在附图中。下面的描述涉及附图时,除非另有表示,不同附图中的相同数字表示相同或相似的要素。以下示例性实施例中所描述的实施方式并不代表与本说明书一个或多个实施例相一致的所有实施方式。相反,它们仅是与如所附权利要求书中所详述的、本说明书一个或多个实施例的一些方面相一致的装置和方法的例子。Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, the same numerals in different drawings refer to the same or similar elements unless otherwise indicated. Implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with aspects of one or more embodiments of the present specification as recited in the appended claims.

需要说明的是:在其他实施例中并不一定按照本说明书示出和描述的顺序来执行相应方法的步骤。在一些其他实施例中,其方法所包括的步骤可以比本说明书所描述的更多或更少。此外,本说明书中所描述的单个步骤,在其他实施例中可能被分解为多个步骤进行描述;而本说明书中所描述的多个步骤,在其他实施例中也可能被合并为单个步骤进行描述。It should be noted that in other embodiments, the steps of the corresponding methods are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or less steps than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; multiple steps described in this specification may also be combined into a single step in other embodiments describe.

区块链一般被划分为三种类型:公有链(Public Blockchain),私有链(PrivateBlockchain)和联盟链(Consortium Blockchain)。此外,还有多种类型的结合,比如私有链+联盟链、联盟链+公有链等不同组合形式。其中去中心化程度最高的是公有链。公有链以比特币、以太坊为代表,加入公有链的参与者可以读取链上的数据记录、参与交易以及竞争新区块的记账权等。而且,各参与者(即节点)可自由加入以及退出网络,并进行相关操作。私有链则相反,该网络的写入权限由某个组织或者机构控制,数据读取权限受组织规定。简单来说,私有链可以为一个弱中心化系统,参与节点具有严格限制且少。这种类型的区块链更适合于特定机构内部使用。联盟链则是介于公有链以及私有链之间的区块链,可实现“部分去中心化”。联盟链中各个节点通常有与之相对应的实体机构或者组织;参与者通过授权加入网络并组成利益相关联盟,共同维护区块链运行。Blockchains are generally divided into three types: Public Blockchain, Private Blockchain and Consortium Blockchain. In addition, there are many types of combinations, such as private chain + alliance chain, alliance chain + public chain and other combinations. Among them, the public chain has the highest degree of decentralization. The public chain is represented by Bitcoin and Ethereum. Participants who join the public chain can read the data records on the chain, participate in transactions, and compete for the bookkeeping rights of new blocks. Moreover, each participant (ie node) can freely join and exit the network and perform related operations. On the contrary, the private chain, the write permission of the network is controlled by an organization or institution, and the data read permission is regulated by the organization. In simple terms, the private chain can be a weakly centralized system with strict restrictions and few participating nodes. This type of blockchain is more suitable for internal use by specific institutions. The alliance chain is a blockchain between the public chain and the private chain, which can realize "partial decentralization". Each node in the consortium chain usually has a corresponding entity or organization; participants join the network through authorization and form an alliance of stakeholders to jointly maintain the operation of the blockchain.

不论是公有链、私有链还是联盟链,都可能提供智能合约的功能。区块链上的智能合约是在区块链系统上可以被交易触发执行的合约。智能合约可以通过代码的形式定义。Whether it is a public chain, a private chain or an alliance chain, it is possible to provide the function of smart contracts. Smart contracts on the blockchain are contracts that can be triggered by transactions on the blockchain system. Smart contracts can be defined in the form of code.

以以太坊为例,支持用户在以太坊网络中创建并调用一些复杂的逻辑,这是以太坊区别于比特币区块链技术的最大挑战。以太坊作为一个可编程区块链的核心是以太坊虚拟机(EVM),每个以太坊节点都可以运行EVM。EVM是一个图灵完备的虚拟机,这意味着可以通过它实现各种复杂的逻辑。用户在以太坊中发布和调用智能合约就是在EVM上运行的。实际上,虚拟机直接运行的是虚拟机代码(虚拟机字节码,下简称“字节码”)。部署在区块链上的智能合约可以是字节码的形式。Taking Ethereum as an example, it supports users to create and invoke some complex logic in the Ethereum network, which is the biggest challenge that distinguishes Ethereum from Bitcoin blockchain technology. The core of Ethereum as a programmable blockchain is the Ethereum Virtual Machine (EVM), and each Ethereum node can run the EVM. EVM is a Turing-complete virtual machine, which means that various complex logic can be implemented through it. Users publish and call smart contracts in Ethereum that run on the EVM. In fact, the virtual machine directly runs virtual machine code (virtual machine bytecode, hereinafter referred to as “bytecode”). Smart contracts deployed on the blockchain can be in the form of bytecode.

例如图1所示,Bob将一个包含创建智能合约信息的交易发送到以太坊网络后,节点1的EVM可以执行这个交易并生成对应的合约实例。图中1中的“0x6f8ae93…”代表了这个合约的地址,交易的data字段保存的可以是字节码,交易的to字段为空。节点间通过共识机制达成一致后,这个合约成功创建,并且可以在后续过程中被调用。合约创建后,区块链上出现一个与该智能合约对应的合约账户,并拥有一个特定的地址,合约代码将保存在该合约账户中。智能合约的行为由合约代码控制。换句话说,智能合约使得区块链上产生包含合约代码和账户存储(Storage)的虚拟账户。For example, as shown in Figure 1, after Bob sends a transaction containing information about creating a smart contract to the Ethereum network, the EVM of node 1 can execute the transaction and generate a corresponding contract instance. "0x6f8ae93..." in Figure 1 represents the address of the contract, the data field of the transaction can store bytecode, and the to field of the transaction is empty. After the nodes reach a consensus through the consensus mechanism, the contract is successfully created and can be called in the subsequent process. After the contract is created, a contract account corresponding to the smart contract appears on the blockchain and has a specific address, and the contract code will be saved in the contract account. The behavior of smart contracts is controlled by the contract code. In other words, the smart contract makes a virtual account containing contract code and account storage (Storage) generated on the blockchain.

如图2所示,仍以以太坊为例,Bob将一个用于调用智能合约的交易发送到以太坊网络后,某一节点的EVM可以执行这个交易并生成对应的合约实例。图中2中交易的from字段是交易发起方(即Bob)的账户的地址,to字段中的“0x6f8ae93…”代表了被调用的智能合约的地址,value字段在以太坊中是以太币的值,交易的data字段保存的调用智能合约的方法和参数。智能合约以规定的方式在区块链网络中每个节点独立的执行,所有执行记录和数据都保存在区块链上,所以当交易完成后,区块链上就保存了无法篡改、不会丢失的交易凭证。As shown in Figure 2, still taking Ethereum as an example, after Bob sends a transaction for calling a smart contract to the Ethereum network, the EVM of a certain node can execute this transaction and generate a corresponding contract instance. The from field of the transaction in Figure 2 is the address of the account of the transaction initiator (ie Bob), the "0x6f8ae93..." in the to field represents the address of the called smart contract, and the value field in Ethereum is the value of ether , the method and parameters of calling the smart contract saved in the data field of the transaction. Smart contracts are independently executed by each node in the blockchain network in a prescribed manner, and all execution records and data are stored on the blockchain, so when the transaction is completed, the blockchain will store data that cannot be tampered with and will not be tampered with. Lost transaction credentials.

区块链网络中的节点在执行Bob发起的交易后,会生成相应的收据(receipt)数据,以用于记录该交易相关的收据信息。这样,可以通过查询交易的收据来获得该交易执行结果的相关信息。以以太坊为例,节点执行交易所得的收据数据可以包括如下内容:After the nodes in the blockchain network execute the transaction initiated by Bob, they will generate corresponding receipt data to record the receipt information related to the transaction. In this way, relevant information about the execution result of the transaction can be obtained by querying the receipt of the transaction. Taking Ethereum as an example, the receipt data obtained by nodes executing transactions can include the following:

Result字段,表示交易的执行结果;The Result field indicates the execution result of the transaction;

Gas used字段,表示交易消耗的gas值;The Gas used field indicates the gas value consumed by the transaction;

Logs字段,表示交易产生的日志,日志可以进一步包括From字段、To字段、Topic字段和Log data字段等,其中From字段表示调用的发起方的账户地址、To字段表示被调用对象(如智能合约)的账户地址、Topic字段表示日志的主题、Log data字段表示日志数据;The Logs field indicates the log generated by the transaction. The log can further include the From field, To field, Topic field, and Log data field, etc., where the From field represents the account address of the initiator of the call, and the To field represents the called object (such as a smart contract) account address, the Topic field represents the subject of the log, and the Log data field represents the log data;

Output字段,表示交易的输出。The Output field indicates the output of the transaction.

一般的,交易执行后生成的收据数据以明文形式进行存储,任何人都可以看到收据数据所含的上述各个收据字段的内容,无隐私保护的设置和能力。而在一些区块链与TEE相结合的解决方案中,为了实现隐私保护,收据数据的全部内容均被当作需要隐私保护的数据存储在区块链上。所述区块链,是存储在节点的数据库中特定逻辑组织而成的数据集合。所述数据库,如后所述,其物理载体可以是存储介质,例如持久性存储介质。实际上,收据数据中可能只有部分内容是敏感的,而其它内容并不敏感,只需要针对敏感的内容进行隐私保护、其他内容可以公开,甚至在一些情况下可能需要对部分内容实施检索以驱动相关操作的实施,那么针对这部分内容实施隐私保护将影响检索操作的实施。Generally, the receipt data generated after the transaction is executed is stored in plain text, and anyone can see the contents of the above receipt fields contained in the receipt data, without the settings and capabilities of privacy protection. In some solutions that combine blockchain and TEE, in order to achieve privacy protection, the entire content of the receipt data is stored on the blockchain as data that requires privacy protection. The blockchain is a data collection organized in a specific logic and stored in the database of the node. As described later, the physical carrier of the database may be a storage medium, such as a persistent storage medium. In fact, only part of the receipt data may be sensitive, while other content is not sensitive. Only sensitive content needs to be protected for privacy, and other content can be made public. In some cases, some content may even need to be retrieved to drive The implementation of relevant operations, then the implementation of privacy protection for this part of the content will affect the implementation of retrieval operations.

其中,保护用户隐私的过程可如图3所示:Among them, the process of protecting user privacy can be shown in Figure 3:

步骤302,用户A创建一笔调用业务合约的交易,并将创建好的交易发送至区块链节点。Step 302, user A creates a transaction calling a business contract, and sends the created transaction to the blockchain node.

用户A可通过创建一笔交易(包含所调用智能合约的账户地址)来调用部署于区块链上的智能合约(即业务合约),以使得区块链节点执行业务合约来完成相应的业务。出于隐私保护,用户A可采用数字信封加密的方式对创建好的交易进行加密,该数字信封加密结合对称加密算法和非对称加密算法。具体而言,采用对称加密算法加密交易内容(即采用自身使用的对称密钥对交易内容进行加密),再采用非对称加密算法的公钥对该对称密钥进行加密。User A can call the smart contract (ie business contract) deployed on the blockchain by creating a transaction (including the account address of the called smart contract), so that the blockchain node executes the business contract to complete the corresponding business. For privacy protection, user A can encrypt the created transaction by means of digital envelope encryption, which combines symmetric encryption algorithm and asymmetric encryption algorithm. Specifically, use a symmetric encryption algorithm to encrypt the transaction content (that is, use the symmetric key used by itself to encrypt the transaction content), and then use the public key of the asymmetric encryption algorithm to encrypt the symmetric key.

步骤304,区块链节点执行业务合约。Step 304, the blockchain node executes the business contract.

区块链节点在接收到被加密的交易后,将该交易读入TEE内部,先采用该非对称加密算法的私钥进行解密得到对称密钥,再采用解密得到的对称密钥对交易进行解密得到交易内容,进而在TEE内部执行业务合约的业务代码。After the blockchain node receives the encrypted transaction, it reads the transaction into the TEE, first uses the private key of the asymmetric encryption algorithm to decrypt to obtain the symmetric key, and then uses the decrypted symmetric key to decrypt the transaction Get the transaction content, and then execute the business code of the business contract inside the TEE.

步骤306,区块链节点存储与交易相关的隐私数据。Step 306, the blockchain node stores the privacy data related to the transaction.

一方面,区块链节点在接收到交易后,(通过共识之后)会将交易(被采用数字信封的形式进行加密)发布至区块链上进行存证。另一方面,区块链节点在执行交易后,还会将执行交易得到的相关数据进行加密存储(发布至区块链上进行存证,或者存储在本地);其中,针对对应于交易的交易收据,可采用用户A使用的对称密钥进行加密,针对响应于交易执行业务合约而得到的合约状态数据,可采用TEE内部的特定对称密钥进行加密。另外,针对用户A的账户属性信息、业务合约的账户属性信息、业务合约的合约代码等数据,也可采用TEE内部的特定对称密钥进行加密。而上述这些区块链节点加密的数据,均属于用户A在区块链上的隐私数据,即与用户A在步骤302中创建的交易相关的隐私数据。On the one hand, after the blockchain node receives the transaction, (after passing the consensus) it will publish the transaction (encrypted in the form of a digital envelope) to the blockchain for deposit. On the other hand, after the blockchain node executes the transaction, it will also encrypt and store the relevant data obtained by executing the transaction (publish it on the blockchain for deposit, or store it locally); among them, for the transaction corresponding to the transaction The receipt can be encrypted with the symmetric key used by user A, and the contract status data obtained in response to the execution of the transaction contract can be encrypted with a specific symmetric key inside the TEE. In addition, data such as account attribute information of user A, account attribute information of business contracts, and contract codes of business contracts can also be encrypted using a specific symmetric key inside the TEE. The data encrypted by the aforementioned blockchain nodes all belong to the private data of user A on the blockchain, that is, the private data related to the transaction created by user A in step 302 .

在上述隐私保护的场景下,用户可能需要将自身利用区块链所实现业务相关的隐私数据分享给一些特定的用户查看,也即这些特定的用户可查看与该用户发起的历史交易相关的隐私数据。那么,可针对用户的隐私数据设定查询权限,以供允许查询的其他用户进行查看。因此,可通过对链代码予以改进以对区块链配置针对隐私数据的权限查询的功能。以下结合图4A对本说明书的基于链代码的权限查询配置方案进行说明。In the above-mentioned privacy protection scenario, users may need to share their private data related to the business realized by using the blockchain to some specific users for viewing, that is, these specific users can view the privacy data related to the historical transactions initiated by the user. data. Then, the query permission can be set for the user's private data, so that other users who are allowed to query can view it. Therefore, the chain code can be improved to configure the permission query function for private data on the blockchain. The chaincode-based permission query configuration scheme of this manual will be described below in conjunction with FIG. 4A .

请参见图4A,图4A是一示例性实施例提供的一种基于链代码的权限查询配置方法的流程图。如图4A所示,该方法应用于区块链节点,可以包括以下步骤:Please refer to FIG. 4A . FIG. 4A is a flowchart of a chaincode-based permission query configuration method provided by an exemplary embodiment. As shown in Figure 4A, the method is applied to blockchain nodes and may include the following steps:

步骤402A,将获取到的分发代码读入可信执行环境,以对所述可信执行环境中维护的链代码进行更新,所述分发代码用于在接收到查询方针对与历史交易相关的隐私数据的查询交易时,调用所述历史交易所调用的业务合约以执行所述业务合约中定义的权限控制代码,确定所述查询方的查询权限。Step 402A, read the obtained distribution code into the trusted execution environment, so as to update the chain code maintained in the trusted execution environment, and the distribution code is used to verify the privacy related to the historical transaction by the party receiving the query. During data query transactions, call the business contract invoked by the historical transaction to execute the authority control code defined in the business contract to determine the query authority of the querying party.

在本实施例中,在开发业务合约时,除了在业务合约中定义业务代码之外,还需要在业务合约中定义与调用该业务合约的交易相关的隐私数据的权限控制代码,以用于判定针对该隐私数据的查询方是否被允许查询。通过上述在业务合约中定义权限控制代码的方式,可将隐私数据与控制该隐私数据的查询权限的权限控制代码建立关联关系,从而使得各个业务合约可以控制与调用自身的交易相关的隐私数据。其中,隐私数据的类型可以包括以下至少之一:历史交易、对应于历史交易的交易收据、历史交易的发起方的账户属性信息、历史交易调用的业务合约的账户属性信息、业务合约的合约代码、业务合约的合约状态数据。In this embodiment, when developing a business contract, in addition to defining the business code in the business contract, it is also necessary to define the authority control code of the private data related to the transaction that calls the business contract in the business contract, so as to determine Whether the query party for the private data is allowed to query. Through the above method of defining the authority control code in the business contract, the private data can be associated with the authority control code that controls the query authority of the private data, so that each business contract can control the private data related to the transaction that calls itself. Among them, the type of privacy data may include at least one of the following: historical transactions, transaction receipts corresponding to historical transactions, account attribute information of initiators of historical transactions, account attribute information of business contracts invoked by historical transactions, and contract codes of business contracts , The contract status data of the business contract.

可由区块链用户、区块链成员、区块链管理员等角色来完成对业务合约的开发和部署。以联盟链为例,由具备记账权限的区块链成员(或者区块链用户、管理员)来设定权限控制规则,并将权限控制规则以权限控制代码的形式定义在业务合约(还定义了业务代码)中。在完成对业务合约的开发后,该区块链成员可以通过联盟链中的任一节点设备将该业务合约发布至联盟链,并在该业务合约由该联盟链中的部分指定的成员节点设备(比如,联盟链中指定的若干个具有记账权限的权威节点设备)完成共识后,收录至该联盟链的分布式数据库(即分布式账本)。基于上述部署业务合约的方式,业务合约的部署方(即具备记账权限的普通用户或者普通成员)可控制是否允许其他人来查询与发送至该业务合约的交易(即调用该业务合约的交易)相关的隐私数据。The development and deployment of business contracts can be completed by roles such as blockchain users, blockchain members, and blockchain administrators. Taking the consortium chain as an example, the blockchain members (or blockchain users, administrators) with bookkeeping authority set the authority control rules, and define the authority control rules in the form of authority control codes in the business contract (also business code is defined). After completing the development of the business contract, the blockchain member can publish the business contract to the consortium chain through any node device in the consortium chain, and the member node device designated by the part of the consortium chain in the business contract (For example, several authoritative node devices with bookkeeping authority specified in the consortium chain) After the consensus is completed, it will be included in the distributed database (ie, distributed ledger) of the consortium chain. Based on the above method of deploying business contracts, the deployer of the business contract (that is, an ordinary user or ordinary member with accounting authority) can control whether other people are allowed to query and send transactions to the business contract (that is, the transaction that calls the business contract) ) related privacy data.

其中,区块链中支持的共识算法可以包括:Among them, the consensus algorithms supported in the blockchain can include:

第一类共识算法,即节点设备需要争夺每一轮的记账周期的记账权的共识算法;例如,工作量证明(Proof of Work,POW)、股权证明(Proof of Stake,POS)、委任权益证明(Delegated Proof of Stake,DPOS)等共识算法;The first type of consensus algorithm, that is, the consensus algorithm that node devices need to compete for the accounting rights of each round of accounting cycle; for example, Proof of Work (POW), Proof of Stake (POS), appointment Delegated Proof of Stake (DPOS) and other consensus algorithms;

第二类共识算法,即预先为每一轮记账周期选举记账节点(不需要争夺记账权)的共识算法;例如,实用拜占庭容错(Practical Byzantine Fault Tolerance,PBFT)等共识算法。The second type of consensus algorithm is a consensus algorithm that pre-elects accounting nodes for each round of accounting cycle (no need to compete for accounting rights); for example, consensus algorithms such as Practical Byzantine Fault Tolerance (PBFT).

在采用第一类共识算法的区块链网络中,争夺记账权的节点设备,都可以在接收到交易后执行该笔交易。争夺记账权的节点设备中可能有一个节点设备在本轮争夺记账权的过程中胜出,成为记账节点。记账节点可以将收到的交易与其它交易一起打包以生成最新区块,并将生成的最新区块或者该最新区块的区块头发送至其它节点设备进行共识。In the blockchain network using the first type of consensus algorithm, the node devices competing for the bookkeeping right can execute the transaction after receiving the transaction. Among the node devices competing for bookkeeping rights, there may be a node device that wins the current round of competition for bookkeeping rights and becomes a bookkeeping node. The accounting node can package the received transaction with other transactions to generate the latest block, and send the generated latest block or the block header of the latest block to other node devices for consensus.

在采用第二类共识算法的区块链网络中,具有记账权的节点设备在本轮记账前已经商定好。因此,节点设备在接收到交易后,如果自身不是本轮的记账节点,则可以将该交易发送至记账节点。对于本轮的记账节点,在将该交易与其它交易一起打包以生成最新区块的过程中或者之前,可以执行该交易。记账节点在生成最新区块后,可以将该最新区块或者该最新区块的区块头发送至其它节点设备进行共识。In the blockchain network using the second type of consensus algorithm, the node equipment with bookkeeping rights has been agreed before the current round of bookkeeping. Therefore, after the node device receives the transaction, if it is not the accounting node of the current round, it can send the transaction to the accounting node. For the bookkeeping nodes of this round, the transaction can be executed during or before the process of packaging the transaction with other transactions to generate the latest block. After the accounting node generates the latest block, it can send the latest block or the block header of the latest block to other node devices for consensus.

如上所述,无论区块链采用以上示出的哪种共识算法,本轮的记账节点都可以将接收到的交易打包以生成最新区块,并将生成的最新区块或者该最新区块的区块头发送至其它节点设备进行共识验证。如果其它节点设备接收到最新区块或者该最新区块的区块头后,经验证没有问题,可以将该最新区块追加到原有的区块链末尾,从而完成区块链的记账过程。其它节点验证记账节点发来的新的区块或区块头的过程中,也可以执行该区块中包含的交易。As mentioned above, no matter which consensus algorithm the blockchain adopts, the bookkeeping nodes of this round can package the received transactions to generate the latest block, and will generate the latest block or the latest block The block header is sent to other node devices for consensus verification. If other node devices receive the latest block or the block header of the latest block and verify that there is no problem, the latest block can be appended to the end of the original blockchain to complete the accounting process of the blockchain. In the process of verifying the new block or block header sent by the bookkeeping node, other nodes can also execute the transactions contained in the block.

基于上述部署用于控制查询权限的业务合约的方式,各个业务合约(包括更新合约)仅控制与调用自身的交易相关的隐私数据的查询权限。因此,当用户(作为查询方)发起一笔针对与历史交易(由其他任一用户发起)相关的隐私数据的查询交易时,区块链节点需确定出控制隐私数据的查询权限的业务合约,进而才可调用该业务合约来实现权限控制。Based on the above method of deploying business contracts for controlling query permissions, each business contract (including update contracts) only controls the query permissions of private data related to the transaction calling itself. Therefore, when a user (as a query party) initiates a query transaction for private data related to historical transactions (initiated by any other user), the blockchain node needs to determine the business contract that controls the query authority of private data, Then the business contract can be invoked to implement authority control.

而针对区块链节点调用业务合约来实现权限控制的方式,可在区块链节点的链代码中配置分发代码以用于识别区块链节点接收到的交易是否为查询交易,以及在接收到的交易为查询交易时,进一步调用相应的业务合约来执行权限控制代码(可理解为将查询交易分发给相应的业务合约)。例如,在开发好分发代码后,可通过特定的服务器向各个区块链节点下发配置分发代码的推送,使得区块链节点从该服务器中获取分发代码。当然,还可通过其他任意配置分发代码的方式使得区块链节点获取分发代码并对链代码进行版本更新。For the method of calling the business contract of the blockchain node to realize the permission control, the distribution code can be configured in the chain code of the blockchain node to identify whether the transaction received by the blockchain node is a query transaction, and when the transaction is received When the transaction is a query transaction, the corresponding business contract is further invoked to execute the authority control code (which can be understood as distributing the query transaction to the corresponding business contract). For example, after the distribution code is developed, a push to configure the distribution code can be sent to each blockchain node through a specific server, so that the blockchain node can obtain the distribution code from the server. Of course, the blockchain node can obtain the distribution code and update the version of the chain code through any other way of configuring the distribution code.

具体而言,可针对分发代码配置特定调用地址以用于识别查询交易。换言之,查询方创建的查询交易为用于调用分发代码的交易;那么,当区块链节点接收到的任一交易通过该特定调用地址调用分发代码时,可将该任一交易作为查询交易。以以太坊为例,查询方可在查询交易的to字段中写入该特定调用地址,那么区块链节点在接收到该查询交易时,根据to字段中记录的特定调用地址可识别出接收到的交易为查询交易,进而执行分发代码以调用相应的业务合约。通过将上述“分发查询交易”的分发逻辑以分发代码的形式固化到链代码中,跟随链代码一起发布,从而不需要管理员后续再部署,并且合约代码固化在链代码中,使得合约代码可控,有效提高了安全性。换言之,将查询交易分发至相应业务合约的操作,由区块链节点自身来完成,而无需通过调用智能合约来完成。Specifically, a specific call address can be configured for the distribution code to identify query transactions. In other words, the query transaction created by the query party is a transaction used to call the distribution code; then, when any transaction received by the blockchain node calls the distribution code through the specific call address, any transaction can be used as a query transaction. Taking Ethereum as an example, the inquiring party can write the specific calling address in the to field of the querying transaction, then when the blockchain node receives the querying transaction, it can recognize the receiving address according to the specific calling address recorded in the to field The transaction is a query transaction, and then the distribution code is executed to call the corresponding business contract. By solidifying the distribution logic of the above-mentioned "distribution query transaction" into the chain code in the form of distribution code, and releasing it together with the chain code, there is no need for the administrator to deploy it later, and the contract code is solidified in the chain code, so that the contract code can be control, effectively improving safety. In other words, the operation of distributing the query transaction to the corresponding business contract is completed by the blockchain node itself without calling the smart contract.

在本实施例中,除在链代码中配置分发代码以外,还可对区块链节点上的链代码进行版本更新,从而配合所配置的分发代码来共同完成权限查询的过程。例如,在开发好新版本链代码后,可通过特定的服务器向各个区块链节点下发链代码升级的推送,使得区块链节点从该服务器中获取新版本链代码,进而根据获取到的新版本链代码对链代码(维护在TEE中)进行更新。当然,还可通过其他任意更新链代码的方式使得区块链节点获取新版本链代码进行版本更新。In this embodiment, in addition to configuring the distribution code in the chain code, the version of the chain code on the blockchain node can also be updated, so as to cooperate with the configured distribution code to complete the process of permission query. For example, after developing a new version of the chain code, a chain code upgrade push can be sent to each blockchain node through a specific server, so that the blockchain node can obtain the new version of the chain code from the server, and then according to the acquired The new version of the chain code updates the chain code (maintained in the TEE). Of course, any other way to update the chain code can also be used to make the blockchain node obtain the new version of the chain code for version update.

在一种情况下,查询方在构建查询交易时,可仅在查询交易中写入与待查询的隐私数据相关的历史交易的交易标识。其中,历史交易的交易标识可由历史交易的发起方和查询方之间通过线下分享的方式得到,或者通过其他任意方式得到。在该情况下,新版本链代码用于根据查询交易中包含的交易标识获取历史交易,并基于获取到的历史交易确定该历史交易调用的业务合约;分发代码用于调用通过执行该新版本链代码确定出的业务合约,以执行所调用的业务合约中定义的权限控制代码。In one case, when the querying party constructs the querying transaction, it may only write in the querying transaction the transaction identification of the historical transaction related to the privacy data to be queried. Wherein, the transaction identifier of the historical transaction may be obtained by offline sharing between the initiator and the inquiring party of the historical transaction, or obtained by any other method. In this case, the new version of the chain code is used to obtain the historical transaction according to the transaction identifier contained in the query transaction, and determine the business contract called by the historical transaction based on the obtained historical transaction; the distribution code is used to call the new version of the chain code The business contract determined by the code is used to execute the authority control code defined in the called business contract.

以以太坊为例,查询方在创建查询交易时,可将历史交易的发起方告知的该历史交易的hash值(作为交易标识)记录在查询交易的data字段中。那么,区块链节点(已更新链代码)在接收到该查询交易时,通过执行新版本链代码以根据该hash值获取存证在区块链上的历史交易,进而根据历史交易的to字段(用于记录调用的智能合约的合约地址)确定该历史交易调用的业务合约。区块链节点在确定出历史交易调用的业务合约之后,执行分发代码以调用确定出的业务合约执行权限控制代码。Taking Ethereum as an example, when creating a query transaction, the inquiring party can record the hash value of the historical transaction notified by the originator of the historical transaction (as a transaction identifier) in the data field of the querying transaction. Then, when the blockchain node (updated chain code) receives the query transaction, it executes the new version of the chain code to obtain the historical transactions stored on the blockchain according to the hash value, and then according to the to field of the historical transaction (The contract address of the smart contract used to record the call) Determine the business contract called by the historical transaction. After the blockchain node determines the business contract called by the historical transaction, it executes the distribution code to call the determined business contract to execute the authority control code.

在另一种情况下,查询方在构建查询交易时,可在查询交易中写入与待查询的隐私数据相关的历史交易的交易标识,和该历史交易调用的业务合约的合约地址;其中,历史交易的交易标识和业务合约的合约地址可由历史交易的发起方和查询方之间通过线下分享的方式得到,或者通过其他任意方式得到。在该情况下,分发代码用于根据查询交易中包含的历史交易调用的业务合约的合约地址确定相应的业务合约,并调用确定出的业务合约以执行相应的权限控制代码来确定查询方的查询权限。需要注意的是,查询交易由查询方创建,该查询交易中包含的历史交易调用的业务合约的合约地址由查询方来声明,那么该合约地址并不一定是历史交易实际调用的业务合约的合约地址,即存在查询方伪造合约地址的风险。因此,在通过业务合约确定出查询方的查询权限为允许查询时,新版本链代码用于根据查询交易中包含的交易标识(即交易ID,通常为交易的hash值)获取该历史交易,并根据获取到的历史交易确定出该历史交易实际调用的业务合约的合约地址。当确定出的合约地址与查询交易中包含的历史交易调用的业务合约的合约地址不一致时,判定查询方的查询权限为禁止查询,从而可有效排除查询方通过伪造合约地址来盗取用户隐私数据的情况。In another case, when constructing a query transaction, the querying party can write in the query transaction the transaction identifier of the historical transaction related to the private data to be queried, and the contract address of the business contract invoked by the historical transaction; among them, The transaction identifier of the historical transaction and the contract address of the business contract can be obtained by offline sharing between the initiator and the inquiring party of the historical transaction, or by any other means. In this case, the distribution code is used to determine the corresponding business contract according to the contract address of the business contract called by the historical transaction contained in the query transaction, and call the determined business contract to execute the corresponding authority control code to determine the query of the querying party. authority. It should be noted that the query transaction is created by the query party, and the contract address of the business contract called by the historical transaction included in the query transaction is declared by the query party, so the contract address is not necessarily the contract of the business contract actually called by the historical transaction Address, that is, there is a risk that the inquiring party forges the contract address. Therefore, when it is determined through the business contract that the query authority of the querying party is allowed to query, the new version of the chain code is used to obtain the historical transaction according to the transaction identifier contained in the query transaction (that is, the transaction ID, usually the hash value of the transaction), and Determine the contract address of the business contract actually invoked by the historical transaction according to the obtained historical transaction. When the determined contract address is inconsistent with the contract address of the business contract invoked by the historical transaction included in the query transaction, it is determined that the query authority of the query party is to prohibit query, which can effectively exclude the query party from stealing user privacy data by forging the contract address Case.

进一步的,在最终确定出查询方的查询权限为允许查询时,新版本链代码还用于获取解密后的隐私数据以由查询方查看;其中,隐私数据被读入可信执行环境进行解密。例如,可根据查询交易中包含的历史交易的交易标识获取隐私数据,并将获取到的隐私数据读入可信执行环境进行解密,以由查询方获取。换言之,在最终确定出查询方的查询权限为允许查询时,区块链节点通过执行该新版本代码来获取隐私数据以供查询方查看。Furthermore, when it is finally determined that the inquiry authority of the inquiring party is allowed to inquire, the new version of the chain code is also used to obtain the decrypted private data for viewing by the inquiring party; wherein, the private data is read into the trusted execution environment for decryption. For example, the private data can be obtained according to the transaction identifier of the historical transaction included in the query transaction, and the obtained private data can be read into the trusted execution environment for decryption, so as to be obtained by the querying party. In other words, when it is finally determined that the inquiry authority of the inquiring party is allowed to inquire, the blockchain node executes the new version code to obtain private data for the inquiring party to view.

在本实施例中,业务合约中以权限控制代码形式定义的权限控制规则,可根据实际需求灵活设定;当然,本说明书一个或多个实施例并不对权限控制规则的具体内容进行限制。在一种情况下,可将查询方的身份信息作为权限控制的依据。相应的,查询方在创建查询交易时,查询交易中应包含查询方的身份信息。例如,查询方的身份信息为查询方的账户ID(即账户地址),该账户ID可记录于查询交易的from字段中。进一步的,权限控制规则可以设定为当查询方的身份信息符合特定的条件时,允许该查询方查询相应的隐私数据。比如,当查询方属于预先指定的查询用户集合时,可确定该查询方的查询权限为允许查询,或者当查询方的信用评分超过预设信用阈值时,可确定该查询方的查询权限为允许查询等等。因此,在确定查询方的查询权限时,可执行业务合约中定义的权限控制代码,以根据查询方的身份信息确定查询方针对隐私数据的查询权限。In this embodiment, the authority control rules defined in the form of authority control codes in the business contract can be flexibly set according to actual needs; of course, one or more embodiments of this specification do not limit the specific content of the authority control rules. In one case, the identity information of the inquiring party can be used as the basis for authority control. Correspondingly, when the querying party creates a querying transaction, the querying transaction should include the identity information of the querying party. For example, the identity information of the inquiring party is the account ID (ie, account address) of the inquiring party, and the account ID can be recorded in the from field of the inquiring transaction. Further, the authority control rule can be set to allow the querying party to query corresponding private data when the identity information of the querying party meets certain conditions. For example, when the inquiring party belongs to a pre-designated query user set, it can be determined that the querying authority of the inquiring party is allowed to query, or when the credit score of the inquiring party exceeds the preset credit threshold, it can be determined that the inquiring party’s querying authority is allowed query and so on. Therefore, when determining the inquiry authority of the inquiring party, the authority control code defined in the business contract can be executed to determine the inquiring party's inquiry authority for private data according to the identity information of the inquiring party.

在另一种情况下,可将查询方的身份信息和历史交易的发起方的身份信息共同作为权限控制的依据。那么,权限控制规则可以设定为当查询方的身份信息和发起方的身份信息符合特定的条件时,允许该查询方查询相应的隐私数据。比如,在权限控制规则中记录查询组和被查询组,属于查询组的成员允许查看被查询组成员的隐私数据;或者,权限控制规则中直接记录各个用户可以查看哪些其他用户的对应关系;或者当查询方和发起方属于同一团队时,可确定该查询方的查询权限为允许查询等等。因此,在确定查询方的查询权限时,可执行业务合约中定义的权限控制代码,以根据查询方的身份信息和发起方的身份信息确定查询方针对隐私数据的查询权限。其中,查询方可在创建的查询交易中写入历史交易的发起方的身份信息,或者由区块链节点(通过执行新版本链代码)根据查询交易中包含的交易标识获取历史交易,并基于获取到的历史交易得到。In another case, the identity information of the inquiring party and the initiator of historical transactions can be used together as the basis for authority control. Then, the permission control rule can be set to allow the querying party to query corresponding private data when the identity information of the querying party and the identity information of the initiator meet certain conditions. For example, the query group and the queried group are recorded in the permission control rules, and members belonging to the query group are allowed to view the private data of the members of the queried group; or, the permission control rules directly record the corresponding relationship of which other users can be viewed by each user; or When the inquiring party and the initiating party belong to the same team, it can be determined that the inquiry authority of the inquiring party is permission to inquire and so on. Therefore, when determining the inquiry authority of the inquiring party, the authority control code defined in the business contract can be executed to determine the inquiring party's inquiry authority for private data according to the identity information of the inquiring party and the identity information of the initiator. Among them, the query party can write the identity information of the originator of the historical transaction in the created query transaction, or the blockchain node (by executing the new version of the chain code) can obtain the historical transaction according to the transaction identifier contained in the query transaction, and based on The obtained historical transactions are obtained.

在又一种情况下,可将历史交易的发起方的身份信息作为权限控制的依据。那么,权限控制规则可以设定为当发起方的身份信息符合特定的条件时,允许该查询方查询相应的隐私数据。比如,当发起方属于预先指定的可被查询用户集合时,可确定查询方的查询权限为允许查询,或者当发起方的信用评分超过预设信用阈值时,可确定查询方的查询权限为允许查询等等。因此,在确定查询方的查询权限时,可执行业务合约中定义的权限控制代码,以根据发起方的身份信息确定查询方针对隐私数据的查询权限。In yet another case, the identity information of the originator of the historical transaction can be used as the basis for authority control. Then, the authority control rule can be set to allow the inquiring party to query the corresponding private data when the identity information of the originating party meets certain conditions. For example, when the originator belongs to the pre-designated set of users who can be queried, it can be determined that the inquiry authority of the inquiring party is allowed to inquire, or when the credit score of the initiator exceeds the preset credit threshold, it can be determined that the inquiry authority of the inquiring party is allowed query and so on. Therefore, when determining the query authority of the querying party, the authority control code defined in the business contract can be executed to determine the querying party's querying authority for private data according to the identity information of the initiator.

当权限控制的依据包括历史交易的发起方的身份信息时,由于查询交易中包含的发起方的身份信息仅仅是查询方声明的身份信息,而该身份信息并不一定是历史交易的发起方实际的身份信息,即存在查询方伪造发起方身份信息的风险。因此,可在区块链节点执行的新版本链代码中添加针对查询交易中包含的历史交易发起方的身份信息的校验逻辑,也即在根据权限控制代码确定出查询方的查询权限为允许查询后,区块链节点(通过执行新版本链代码)可根据查询交易中包含的历史交易的交易标识(即交易ID,通常为交易的hash值)获取该历史交易,从而根据获取到的历史交易确定出该历史交易的发起方的身份信息(即发起方实际的身份信息)。当确定出的身份信息与查询交易中包含的发起方的身份信息不一致时,禁止执行获取隐私数据的操作(即判定查询权限为禁止查询),从而可有效排除查询方通过伪造发起方身份信息来盗取用户隐私数据的情况。When the authority control basis includes the identity information of the initiator of the historical transaction, since the identity information of the initiator contained in the query transaction is only the identity information declared by the querying party, the identity information is not necessarily the actual information of the initiator of the historical transaction. identity information, that is, there is a risk that the query party forges the identity information of the originator. Therefore, the verification logic for the identity information of the initiator of the historical transaction contained in the query transaction can be added to the new version of the chain code executed by the blockchain node, that is, when the query permission of the query party is determined to be allowed according to the permission control code After the query, the blockchain node (by executing the new version of the chain code) can obtain the historical transaction according to the transaction ID of the historical transaction contained in the query transaction (that is, the transaction ID, usually the hash value of the transaction), so that according to the obtained historical transaction The transaction determines the identity information of the initiator of the historical transaction (that is, the actual identity information of the initiator). When the determined identity information is inconsistent with the initiator’s identity information contained in the query transaction, the operation of obtaining private data is prohibited (that is, the query authority is determined to be prohibited from querying), so that the query party can be effectively excluded by forging the initiator’s identity information. Stealing user privacy data.

在本实施例中,当确定出查询方的查询权限为禁止查询时,无需执行上述通过获取历史交易来校验发起方的身份信息或者校验业务合约的合约地址的步骤。由于在查询方的查询权限为禁止查询的情况下,该校验步骤为不必要的操作,因此可减少对区块链节点处理资源的占用,从而提高区块链节点的性能。同时,当确定出查询方的查询权限为禁止查询时,可生成用于表示该查询方禁止查询隐私数据的合约收据以由查询方查看。In this embodiment, when it is determined that the inquiry authority of the inquiring party is forbidden to inquire, there is no need to perform the above steps of verifying the identity information of the originator or verifying the contract address of the business contract by obtaining historical transactions. Since the verification step is an unnecessary operation when the query authority of the querying party is prohibited, it can reduce the occupation of processing resources of the blockchain node, thereby improving the performance of the blockchain node. At the same time, when it is determined that the inquiry authority of the inquiring party is prohibited from inquiring, a contract receipt indicating that the inquiring party is prohibited from inquiring private data can be generated for viewing by the inquiring party.

需要说明的是,接入区块链的用户在区块链上发起的请求的类型,具体可以是指传统的区块链中所采用的交易(transaction)。当然,接入区块链的用户在区块链上发起的请求的类型,具体也可以是交易以外的,其它形式的具有标准的数据结构的指令、消息等,本说明书一个或多个实施例并不进行特别限定。在以下的各实施例中,将以接入区块链的用户在区块链上发起的请求为交易为例进行说明。It should be noted that the types of requests initiated by users accessing the blockchain may specifically refer to transactions used in traditional blockchains. Of course, the types of requests initiated on the blockchain by users accessing the blockchain can also be other than transactions, other forms of instructions and messages with standard data structures, one or more embodiments of this specification It is not particularly limited. In each of the following embodiments, a request initiated by a user who accesses the blockchain is taken as a transaction as an example for illustration.

步骤404A,当接收到挑战方发起的针对所述分发代码的验证请求时,读取所述可信执行环境中维护的分发代码以生成验证报告,并向所述挑战方发送所述验证报告,以使得所述挑战方根据所述验证报告对所述可信执行环境中的分发代码进行验证。Step 404A, when receiving a verification request for the distribution code initiated by the challenger, read the distribution code maintained in the trusted execution environment to generate a verification report, and send the verification report to the challenger, so that the challenger verifies the distribution code in the trusted execution environment according to the verification report.

在本实施例中,可将链代码维护在区块链节点的TEE中,即区块链节点在TEE内执行链代码(包含分发代码),从而可利用远程证明机制来保证分发代码被非法篡改,进而保证TEE内维护的分发代码的真实可信。比如,可由上述特点服务器(即分发代码的来源处)作为挑战方来验证区块链节点的TEE内维护的分发代码,从而确定区块链节点的TEE内维护的分发代码是否与自身发布的分发代码一致,或者是否与自身维护的分发代码一致。In this embodiment, the chain code can be maintained in the TEE of the blockchain node, that is, the blockchain node executes the chain code (including the distribution code) in the TEE, so that the remote proof mechanism can be used to ensure that the distribution code is illegally tampered with , thus ensuring the authenticity and credibility of the distribution code maintained in the TEE. For example, the above-mentioned feature server (that is, the source of the distribution code) can be used as the challenger to verify the distribution code maintained in the TEE of the blockchain node, so as to determine whether the distribution code maintained in the TEE of the blockchain node is consistent with the distribution code issued by itself. The code is consistent, or whether it is consistent with the distribution code it maintains.

相应的,基于上述将分发代码固化至链代码的过程,本说明书还进一步提供一种隐私数据的查询方案。请参见图4B,图4B是一示例性实施例提供的一种隐私数据的查询方法的流程图。如图4B所示,该方法应用于区块链节点,可以包括以下步骤:Correspondingly, based on the above-mentioned process of solidifying the distribution code into the chain code, this specification further provides a private data query scheme. Please refer to FIG. 4B . FIG. 4B is a flow chart of a private data query method provided by an exemplary embodiment. As shown in Figure 4B, the method is applied to blockchain nodes and may include the following steps:

步骤402B,当接收到查询方提交的与历史交易相关的隐私数据的查询交易时,读取可信执行环境中维护的分发代码,所述分发代码属于所述可信执行环境中维护的链代码的一部分。Step 402B, when receiving the query transaction of the private data related to the historical transaction submitted by the querying party, read the distribution code maintained in the trusted execution environment, and the distribution code belongs to the chain code maintained in the trusted execution environment a part of.

步骤404B,在所述可信执行环境中执行所述分发代码,以根据所述历史交易所调用的业务合约中定义的权限控制代码确定所述查询方的查询权限。Step 404B, execute the distribution code in the trusted execution environment to determine the inquiry authority of the inquiring party according to the authority control code defined in the business contract invoked by the historical transaction.

步骤406B,当确定出的查询权限为允许查询时,获取所述隐私数据,并将获取到的隐私数据读入可信执行环境进行解密,以由所述查询方获取。Step 406B, when it is determined that the query authority is allowed to query, obtain the private data, and read the obtained private data into the trusted execution environment for decryption, so as to be obtained by the querying party.

在本实施例中,出于上述对用户隐私数据的保护,隐私数据被加密存储。因此,当确定出查询方的查询权限为允许查询时,区块链节点(通过执行更新后的链代码)可根据查询交易中包含的历史交易的交易标识获取隐私数据,并将获取到的隐私数据读入可信执行环境进行解密,以由查询方获取。而根据隐私数据中包含的数据类型的不同,所采用的解密方式也不同(因为加密方式不同)。In this embodiment, for the above-mentioned protection of user privacy data, the privacy data is encrypted and stored. Therefore, when it is determined that the query authority of the querying party is allowed to query, the blockchain node (by executing the updated chain code) can obtain private data according to the transaction identification of the historical transaction contained in the query transaction, and the obtained private data The data is read into the trusted execution environment for decryption to be obtained by the querying party. Depending on the type of data contained in the privacy data, the decryption method adopted is also different (because the encryption method is different).

当隐私数据包括历史交易和/或历史交易的交易收据时,由上述图3所示实施例可知,历史交易和历史交易的交易收据均被采用历史交易的发起方使用的对称密钥进行加密。因此,在获取到历史交易和/或历史交易的交易收据后,可先获取发起方(在图3所示实施例中即为用户A)使用的对称密钥,再在TEE内通过该对称密钥对历史交易和/或历史交易的交易收据进行解密。而对于发起方使用的对称密钥的获取,可先获取用于加密历史交易的对称密钥(该对称密钥被发起方使用的公钥加密,即上述图3所示实施例中采用数字信封进行加密的方式),在TEE内通过与发起方使用的公钥对应的私钥,对该对称密钥进行解密以得到解密后的对称密钥。需要说明的是,当隐私数据为历史交易时,获取历史交易并解密历史交易的过程在根据交易标识获取历史交易时进行,即根据交易标识获取历史交易,并对历史交易进行解密得到明文交易内容,从而根据明文交易内容确定历史交易调用的业务合约。因此,当确定出查询权限为允许查询时,(无需再执行获取历史交易和解密历史交易的操作)直接获取解密后的历史交易供查询方查看即可。When the privacy data includes historical transactions and/or transaction receipts of historical transactions, it can be known from the above embodiment shown in FIG. 3 that both historical transactions and transaction receipts of historical transactions are encrypted using the symmetric key used by the originator of the historical transactions. Therefore, after obtaining the historical transaction and/or the transaction receipt of the historical transaction, you can first obtain the symmetric key used by the initiator (in the embodiment shown in Figure 3, that is, user A), and then pass the symmetric key key to decrypt historical transactions and/or transaction receipts for historical transactions. For the acquisition of the symmetric key used by the initiator, the symmetric key used to encrypt historical transactions can be obtained first (the symmetric key is encrypted by the public key used by the initiator, that is, the digital envelope is used in the above-mentioned embodiment shown in Figure 3 encryption method), the symmetric key is decrypted in the TEE with the private key corresponding to the public key used by the initiator to obtain the decrypted symmetric key. It should be noted that when the private data is historical transactions, the process of obtaining historical transactions and decrypting historical transactions is carried out when obtaining historical transactions according to transaction identifiers, that is, obtaining historical transactions according to transaction identifiers, and decrypting historical transactions to obtain plaintext transaction content , so as to determine the business contract invoked by the historical transaction according to the plaintext transaction content. Therefore, when it is determined that the query authority is allowed to query, (no need to perform the operations of acquiring and decrypting historical transactions) the decrypted historical transactions can be obtained directly for the querying party to view.

其中,发起方使用的对称密钥可由发起方通过对称加密算法生成,或由发起方与区块链节点之间通过协商得到,或由密钥管理服务器发送得到。而对于对称加密算法,例如可以是DES算法、3DES算法、TDEA算法、Blowfish算法、RC5算法、IDEA算法等。发起方使用的公钥由密钥管理服务器通过远程证明发送至发起方,区块链节点的TEE由SGX架构建立,与公钥对应的私钥由密钥管理服务器通过远程证明发送至区块链节点的围圈(enclave,也称为飞地)。而用于生成公钥和私钥的非对称加密算法,例如可以是RSA、Elgamal、背包算法、Rabin、D-H、ECC(椭圆曲线加密算法)等。Among them, the symmetric key used by the initiator can be generated by the initiator through a symmetric encryption algorithm, or obtained through negotiation between the initiator and the blockchain node, or sent by the key management server. As for the symmetric encryption algorithm, for example, it may be a DES algorithm, a 3DES algorithm, a TDEA algorithm, a Blowfish algorithm, an RC5 algorithm, an IDEA algorithm, and the like. The public key used by the initiator is sent to the initiator by the key management server through remote certification, the TEE of the blockchain node is established by the SGX architecture, and the private key corresponding to the public key is sent to the blockchain by the key management server through remote certification An enclave (also known as an enclave) of nodes. The asymmetric encryption algorithm used to generate the public key and the private key may be, for example, RSA, Elgamal, Knapsack Algorithm, Rabin, D-H, ECC (Elliptic Curve Encryption Algorithm) and the like.

当隐私数据包括历史交易的发起方的账户属性信息、业务合约的账户属性信息、业务合约的合约代码、业务合约的合约状态数据中至少之一时,由上述图3所示实施例可知,这些隐私数据均被采用TEE内部的特定对称密钥进行加密。因此,在获取到这些隐私数据后,可在TEE内通过区块链节点的特定对称密钥对这些隐私数据进行解密。而对于TEE内部的特定对称密钥,在区块链节点的SGX架构通过远程证明后由密钥管理服务器发送,或者由区块链节点与其他区块链节点之间进行协商得到。When the privacy data includes at least one of the account attribute information of the originator of the historical transaction, the account attribute information of the business contract, the contract code of the business contract, and the contract state data of the business contract, it can be seen from the above-mentioned embodiment shown in Figure 3 that these privacy Data is encrypted using a specific symmetric key inside the TEE. Therefore, after obtaining these private data, they can be decrypted within the TEE through the specific symmetric key of the blockchain node. As for the specific symmetric key inside the TEE, it is sent by the key management server after the SGX architecture of the blockchain node passes remote certification, or it is obtained through negotiation between the blockchain node and other blockchain nodes.

在本实施例中,类似于上述对历史交易进行加密以保护隐私的方式,查询方在发起查询交易时,同样可采用自身使用的对称密钥对创建好的查询交易进行加密,并用自身使用的公钥对该对称密钥进行加密。因此,区块链节点在接收到查询交易后,先在TEE内通过与查询方使用的公钥对应的私钥对加密查询交易的对称密钥解密,再通过解密得到的对称密钥对查询交易进行解密,以获取查询交易包含的交易内容。而在获取到隐私数据并对隐私数据进行解密后,区块链节点可通过查询方的对称密钥对解密后的隐私数据进行加密,使得查询方可通过自身使用的对称密钥对隐私数据进行解密查看,从而避免隐私数据被泄露。In this embodiment, similar to the above-mentioned way of encrypting historical transactions to protect privacy, when the querying party initiates a querying transaction, it can also use its own symmetric key to encrypt the created querying transaction, and use its own The public key encrypts the symmetric key. Therefore, after the blockchain node receives the query transaction, it first decrypts the symmetric key of the encrypted query transaction through the private key corresponding to the public key used by the query party in the TEE, and then uses the decrypted symmetric key to query the transaction Decrypt to obtain the transaction content contained in the query transaction. After obtaining the private data and decrypting the private data, the blockchain node can encrypt the decrypted private data through the symmetric key of the querying party, so that the querying party can use the symmetric key used by the querying party to encrypt the private data. Decrypt to view, so as to avoid the leakage of private data.

其中,上述针对查询方进行隐私保护所使用的对称密钥、公钥和私钥的来源与上述类似,在此不再赘述。当然,该过程中使用的非对称密钥(公钥和私钥),可以是上述针对发起方进行隐私保护所使用的非对称密钥。Wherein, the sources of the above-mentioned symmetric key, public key and private key used for privacy protection for the query party are similar to the above, and will not be repeated here. Certainly, the asymmetric key (public key and private key) used in this process may be the above-mentioned asymmetric key used for privacy protection for the initiator.

为了便于理解,下面结合图5-7对本说明书的技术方案进行详细说明。For ease of understanding, the technical solution of this specification will be described in detail below with reference to FIGS. 5-7 .

请参见图5,图5是一示例性实施例提供的一种针对分发代码进行远程证明的示意图。如图5所示,该远程证明的过程可以包括以下步骤:Please refer to FIG. 5 . FIG. 5 is a schematic diagram of remote attestation for code distribution provided by an exemplary embodiment. As shown in Figure 5, the remote attestation process may include the following steps:

步骤502,挑战方51向区块链节点52发送针对分发代码的验证请求。Step 502, the challenger 51 sends a verification request for the distributed code to the blockchain node 52.

在本实施例中,区块链节点52在TEE内维护分发代码。TEE是基于CPU硬件的安全扩展,且与外部完全隔离的可信执行环境。TEE最早是由Global Platform提出的概念,用于解决移动设备上资源的安全隔离,平行于操作系统为应用程序提供可信安全的执行环境。ARM的Trust Zone技术最早实现了真正商用的TEE技术。伴随着互联网的高速发展,安全的需求越来越高,不仅限于移动设备,云端设备,数据中心都对TEE提出了更多的需求。TEE的概念也得到了高速的发展和扩充。现在所说的TEE相比与最初提出的概念已经是更加广义的TEE。例如,服务器芯片厂商Intel,AMD等都先后推出了硬件辅助的TEE并丰富了TEE的概念和特性,在工业界得到了广泛的认可。现在提起的TEE通常更多指这类硬件辅助的TEE技术。不同于移动端,云端访问需要远程访问,终端用户对硬件平台不可见,因此使用TEE的第一步就是要确认TEE的真实可信。因此可针对TEE技术引入远程证明机制,由硬件厂商(主要是CPU厂商)背书并通过数字签名技术确保用户对TEE状态可验证。同时仅仅是安全的资源隔离也无法满足的安全需求,进一步的数据隐私保护也被提出。包括Intel SGX,AMD SEV在内的商用TEE也都提供了内存加密技术,将可信硬件限定在CPU内部,总线和内存的数据均是密文防止恶意用户进行窥探。例如,英特尔的软件保护扩展(SGX)等TEE技术隔离了代码执行、远程证明、安全配置、数据的安全存储以及用于执行代码的可信路径。在TEE中运行的应用程序受到安全保护,几乎不可能被第三方访问。In this embodiment, blockchain nodes 52 maintain distribution codes within the TEE. TEE is a security extension based on CPU hardware and a trusted execution environment completely isolated from the outside world. TEE was first proposed by Global Platform to solve the security isolation of resources on mobile devices, and parallel to the operating system to provide applications with a trusted and secure execution environment. ARM's Trust Zone technology is the first to realize the real commercial TEE technology. With the rapid development of the Internet, the demand for security is getting higher and higher, not limited to mobile devices, cloud devices, and data centers have put forward more demands on TEE. The concept of TEE has also been developed and expanded at a high speed. The TEE now referred to is a broader TEE than the concept originally proposed. For example, server chip manufacturers Intel and AMD have launched hardware-assisted TEE successively and enriched the concept and characteristics of TEE, which have been widely recognized in the industry. The TEE mentioned now usually refers more to this kind of hardware-assisted TEE technology. Unlike mobile terminals, cloud access requires remote access, and end users are invisible to the hardware platform. Therefore, the first step in using TEE is to confirm the authenticity of TEE. Therefore, a remote certification mechanism can be introduced for TEE technology, endorsed by hardware manufacturers (mainly CPU manufacturers) and digitally signed to ensure that users can verify the state of TEE. At the same time, only secure resource isolation cannot meet the security requirements, and further data privacy protection has also been proposed. Commercial TEEs including Intel SGX and AMD SEV also provide memory encryption technology, which limits the trusted hardware inside the CPU, and the data on the bus and memory are encrypted to prevent malicious users from snooping. For example, TEE technologies such as Intel's Software Guard Extensions (SGX) isolate code execution, remote attestation, secure configuration, secure storage of data, and trusted paths for code execution. Applications running in TEE are secured and almost impossible to be accessed by third parties.

以Intel SGX技术为例,SGX提供了围圈,即内存中一个加密的可信执行区域,由CPU保护数据不被窃取。以区块链节点采用支持SGX的CPU为例,利用新增的处理器指令,在内存中可以分配一部分区域EPC(Enclave Page Cache,围圈页面缓存或飞地页面缓存),通过CPU内的加密引擎MEE(Memory Encryption Engine)对其中的数据进行加密。EPC中加密的内容只有进入CPU后才会被解密成明文。因此,在SGX中,用户可以不信任操作系统、VMM(Virtual Machine Monitor,虚拟机监控器)、甚至BIOS(Basic Input Output System,基本输入输出系统),只需要信任CPU便能确保隐私数据不会泄漏。Taking Intel SGX technology as an example, SGX provides an enclave, which is an encrypted trusted execution area in memory, and the CPU protects data from being stolen. Taking the blockchain node adopting a CPU that supports SGX as an example, using the newly added processor instructions, a part of the area EPC (Enclave Page Cache, enclave page cache or enclave page cache) can be allocated in the memory, through the encryption in the CPU The engine MEE (Memory Encryption Engine) encrypts the data in it. The encrypted content in the EPC will only be decrypted into plaintext after entering the CPU. Therefore, in SGX, users can not trust the operating system, VMM (Virtual Machine Monitor, virtual machine monitor), or even BIOS (Basic Input Output System, basic input and output system), only need to trust the CPU to ensure that private data will not leakage.

基于上述维护分发代码的方式,可由发布分发代码的服务器作为挑战方向区块链节点52发起挑战,要求区块链节点52出示验证报告以证明区块链节点52的TEE内维护的分发代码是由该服务器发布的,或者与该服务器维护的分发代码一致。Based on the above method of maintaining the distribution code, the server that issues the distribution code can initiate a challenge to the block chain node 52 as the challenger, requiring the block chain node 52 to produce a verification report to prove that the distribution code maintained in the TEE of the block chain node 52 is made by published by this server, or consistent with the distribution code maintained by this server.

步骤504,区块链节点52生成验证报告并采用SGX的CPU的私钥签名。Step 504, the blockchain node 52 generates a verification report and signs it with the private key of the CPU of SGX.

步骤506,区块链节点52向挑战方51返回验证报告。Step 506, the blockchain node 52 returns a verification report to the challenger 51.

步骤508,挑战方51向IAS53转发验证报告。Step 508, the challenger 51 forwards the verification report to the IAS53.

以Intel SGX技术为例,区块链节点52在接收到验证请求后,导出SGX中维护的分发代码以基于分发代码生成验证报告。比如,可对分发代码进行hash计算得到相应的hash值,并将该hash值存储在quote(引用结构体)中,并且采用SGX的CPU的私钥对quote(作为验证报告)签名。Taking Intel SGX technology as an example, after receiving the verification request, the blockchain node 52 exports the distribution code maintained in SGX to generate a verification report based on the distribution code. For example, hash calculation can be performed on the distribution code to obtain the corresponding hash value, and the hash value is stored in the quote (reference structure), and the quote (as a verification report) is signed with the private key of the CPU of SGX.

Intel在CPU出厂时向该CPU配置了私钥,但是并未公开与该私钥对应的公钥,而是配置在Intel的IAS(Intel Attestation Server,英特尔认证服务器)中。那么,在采用该CPU的私钥对验证报告签名后,由于没有相应的公钥,挑战方51在获取到区块链节点52返回的quote后,需要转发给IAS,以由IAS验证签名。Intel configures a private key to the CPU when the CPU leaves the factory, but does not disclose the public key corresponding to the private key, but configures it in Intel's IAS (Intel Attestation Server, Intel Authentication Server). Then, after using the private key of the CPU to sign the verification report, since there is no corresponding public key, the challenger 51 needs to forward the quote returned by the blockchain node 52 to the IAS to verify the signature by the IAS.

步骤510,IAS53采用SGX的CPU的公钥验证签名。In step 510, the IAS53 uses the public key of the CPU of the SGX to verify the signature.

在本实施例中,若验证通过,则向挑战方51返回验证结果。例如,可生成AVR报告,该AVR报告中采用“YES”表示验证签名通过,采用“NO”表示验证签名未通过。其中,为了防止AVR报告在传输过程中被截获或修改,除了针对传输的链路采用SSL(Secure SocketsLayer,安全套接层)加密之外,IAS还可采用自身的证书对AVR报告进行签名。In this embodiment, if the verification passes, the verification result is returned to the challenger 51 . For example, an AVR report may be generated, in which "YES" is used to indicate that the verification signature is passed, and "NO" is used to indicate that the verification signature is not passed. Among them, in order to prevent the AVR report from being intercepted or modified during transmission, in addition to using SSL (Secure Sockets Layer, Secure Sockets Layer) encryption for the transmission link, IAS can also use its own certificate to sign the AVR report.

步骤512,IAS53向挑战方51返回验证结果。In step 512, the IAS53 returns the verification result to the challenger 51.

步骤514,挑战方51验证分发代码。In step 514, the challenger 51 verifies the distribution code.

在本实施例中,挑战方51在接收到验证结果后,先验证IAS的签名,验证通过后再获取AVR报告中记录的验证结果。若为YES,则将quote中的hash值与本地的hash值(对本地维护的分发代码进行hash计算得到)进行比较。当比较结果一致时,判断通过远程证明的验证,进而判定区块链节点52的TEE内维护的分发代码是由挑战方51发布的,或者与挑战方51维护的分发代码一致。In this embodiment, after receiving the verification result, the challenger 51 first verifies the signature of the IAS, and then obtains the verification result recorded in the AVR report after the verification is passed. If it is YES, compare the hash value in the quote with the local hash value (obtained by hash calculation of the locally maintained distribution code). When the comparison results are consistent, it is determined that the verification of the remote proof is passed, and then it is determined that the distribution code maintained in the TEE of the blockchain node 52 is issued by the challenger 51, or is consistent with the distribution code maintained by the challenger 51.

请参见图6,图6是一示例性实施例提供的另一种隐私数据的查询方法的流程图。承接于上述图3的场景,在用户A发起调用业务合约的交易后,用户A可向用户B分享与该交易(在该场景下作为历史交易)相关的隐私数据,或者用户B存在查看该隐私数据的需求。如图6所示,用户B作为查询方查询隐私数据的过程可包括以下步骤:Please refer to FIG. 6 . FIG. 6 is a flow chart of another private data query method provided by an exemplary embodiment. Based on the scenario in Figure 3 above, after user A initiates a transaction calling a business contract, user A can share private data related to the transaction (in this scenario as a historical transaction) with user B, or user B exists to view the private data data needs. As shown in Figure 6, the process for user B to query private data as a query party may include the following steps:

步骤602,用户B通过使用的客户端创建查询交易。In step 602, user B creates a query transaction through the client.

在本实施例中,查询交易的to字段记录的是分发代码的特定调用地址,同时还可在查询交易的data字段(或者其他字段)中记录历史交易的hash值(即交易ID)、from字段的内容(历史交易的发起方的地址)和to字段的内容(历史交易调用的业务合约的合约地址)。其中,历史交易的hash值和发起方的地址可由用户B与用户A之间通过线下分享的方式得到,或者通过其他任意方式得到。In this embodiment, the to field of the query transaction records the specific calling address of the distribution code, and the hash value (ie transaction ID) and from field of the historical transaction can also be recorded in the data field (or other fields) of the query transaction The content of (the address of the originator of the historical transaction) and the content of the to field (the contract address of the business contract called by the historical transaction). Among them, the hash value of the historical transaction and the address of the originator can be obtained by sharing offline between user B and user A, or by any other means.

步骤604,用户B通过客户端采用数字信封加密查询交易。Step 604, user B uses the digital envelope to encrypt and query the transaction through the client.

步骤606,用户B通过客户端向区块链节点发起查询交易。Step 606, user B initiates a query transaction to the blockchain node through the client.

步骤608,区块链节点在TEE内解密查询交易。Step 608, the blockchain node decrypts the query transaction in the TEE.

在本实施例中,非对称加密算法的密钥,可由密钥管理服务器生成。通过远程证明的方式,密钥管理服务器将私钥发送至区块链节点,具体的,可以是传入区块链节点的围圈中。区块链节点可以包含多个围圈,而上述私钥可以被传入这些围圈中的安全围圈;例如,该安全围圈可以为QE(Quoting Enclave)围圈,而非AE(Application Enclave)围圈。对于非对称加密的公钥,可以由密钥管理服务器发送至用户的客户端。那么,客户端可采用对称加密算法加密创建好的交易,即采用对称加密算法的对称密钥加密交易内容,并用非对称加密算法加密对称加密算法中采用的对称密钥。一般的,采用非对称加密算法的公钥加密对称加密算法中采用的对称密钥。上述加密的方式被称为数字信封加密,那么区块链节点接收到加密的交易后,可以先采用非对称加密算法的私钥进行解密,得到对称加密算法的对称密钥,进而用对称加密算法的对称密钥解密得到交易内容。In this embodiment, the key of the asymmetric encryption algorithm may be generated by the key management server. Through remote certification, the key management server sends the private key to the blockchain node, specifically, it can be passed into the encirclement of the blockchain node. A blockchain node can contain multiple enclaves, and the above-mentioned private key can be passed into a security enclave in these enclaves; for example, the security enclave can be a QE (Quoting Enclave) enclave instead of an AE (Application Enclave ) circle. For the asymmetrically encrypted public key, it can be sent to the user's client by the key management server. Then, the client can use the symmetric encryption algorithm to encrypt the created transaction, that is, use the symmetric key of the symmetric encryption algorithm to encrypt the transaction content, and use the asymmetric encryption algorithm to encrypt the symmetric key used in the symmetric encryption algorithm. Generally, the public key of the asymmetric encryption algorithm is used to encrypt the symmetric key used in the symmetric encryption algorithm. The above encryption method is called digital envelope encryption. After receiving the encrypted transaction, the blockchain node can first use the private key of the asymmetric encryption algorithm to decrypt it to obtain the symmetric key of the symmetric encryption algorithm, and then use the symmetric encryption algorithm to decrypt it. The symmetric key decrypts to get the transaction content.

步骤610,区块链节点确定接收到的交易为查询交易。Step 610, the blockchain node determines that the received transaction is a query transaction.

在本实施例中,区块链节点在接收到任一交易后,读取该交易的to字段内容。当to字段内容为分发代码的特定调用地址时,说明该交易用于调用分发代码,那么可确定出该交易为查询交易。In this embodiment, after receiving any transaction, the blockchain node reads the content of the to field of the transaction. When the content of the to field is the specific call address of the distribution code, it means that the transaction is used to call the distribution code, and then it can be determined that the transaction is a query transaction.

步骤612,区块链节点根据查询交易中记录的历史交易的to字段确定历史交易调用的业务合约。Step 612, the blockchain node determines the business contract invoked by the historical transaction according to the to field of the historical transaction recorded in the query transaction.

步骤614,区块链节点调用业务合约。Step 614, the blockchain node invokes the business contract.

步骤616,业务合约根据查询交易的from字段和历史交易的from字段确定用户B的查询权限。Step 616, the business contract determines the query authority of user B according to the from field of the query transaction and the from field of the historical transaction.

在本实施例中,以查询方和历史交易的发起方的身份信息共同作为权限控制的依据为例。例如,权限控制规则(以权限控制代码的形式定义在业务合约中)中记录查询组和被查询组,属于查询组的成员允许查看被查询组成员的隐私数据;或者,权限控制规则中直接记录各个用户可以查看哪些其他用户的对应关系。其中,采用账户地址作为用户的身份信息。那么,区块链节点执行业务合约中定义的权限控制代码,从而根据查询方的账户地址(查询交易的from字段内容)和历史交易的发起方的账户地址(历史交易的from字段内容)来确定用户B的查询权限。In this embodiment, the identity information of the inquiring party and the originator of the historical transaction are jointly used as the basis for authority control as an example. For example, the access control rules (defined in the business contract in the form of access control codes) record the query group and the queried group, and members belonging to the query group are allowed to view the private data of the members of the queried group; or, directly record in the access control rules Which other users' correspondences can be viewed by each user. Wherein, the account address is used as the identity information of the user. Then, the blockchain node executes the authority control code defined in the business contract, so as to determine according to the account address of the inquiring party (the content of the from field of the query transaction) and the account address of the originator of the historical transaction (the content of the from field of the historical transaction) User B's query permission.

步骤618,业务合约向区块链节点返回用户B的查询权限。Step 618, the business contract returns the query authority of user B to the blockchain node.

步骤620,在确定出用户B的查询权限为允许查询后,区块链节点校验历史交易的from字段和to字段。Step 620, after determining that the query authority of user B is allowed to query, the blockchain node checks the from field and to field of the historical transaction.

在本实施例中,查询交易中记录的发起方的地址和业务合约的合约地址由用户B填入,因此该发起方的地址应理解为用户B声明的历史交易的发起方的地址,该合约地址应理解为用户B声明的历史交易调用的业务合约的合约地址。但是,历史交易实际的发起方的地址并不一定为用户B声明的发起方的地址,历史交易实际调用的业务合约的合约地址也并不一定为用户B声明的合约地址,即存在用户B伪造的可能。例如,用户B可通过上述部署业务合约的方式在区块链上部署业务合约,该业务合约中定义的权限控制代码允许用户B查看用户A的隐私数据;那么,用户B可在查询交易中将用户A发起的历史交易调用的业务合约的合约地址填写为用户B部署的上述业务合约的合约地址。因此,在确定出用户B的查询权限为允许查询的情况下,区块链节点可进一步对用户B声明的历史交易的发起方的地址和合约地址进行校验,从而保证隐私数据的安全性。In this embodiment, the initiator's address and the contract address of the business contract recorded in the query transaction are filled in by user B, so the initiator's address should be understood as the address of the initiator of the historical transaction declared by user B, the contract The address should be understood as the contract address of the business contract invoked by the historical transaction declared by user B. However, the actual address of the initiator of the historical transaction is not necessarily the address of the initiator declared by user B, and the contract address of the business contract actually called by the historical transaction is not necessarily the address of the contract declared by user B, that is, user B forged possible. For example, user B can deploy a business contract on the blockchain through the above-mentioned way of deploying business contracts, and the authority control code defined in the business contract allows user B to view user A's private data; then, user B can use The contract address of the business contract invoked by the historical transaction initiated by user A is filled in with the contract address of the above business contract deployed by user B. Therefore, when it is determined that user B's query authority is allowed to query, the blockchain node can further verify the initiator's address and contract address of the historical transaction declared by user B, so as to ensure the security of private data.

举例而言,区块链节点在确定出用户B的查询权限为允许查询后,可根据历史交易的hash值从区块链上获取历史交易(存证在区块链上),并读取出历史交易的from字段记录的内容和历史交易的to字段内容,若读取出的from字段内容与查询交易中声明的from字段内容相同,则可进一步执行获取隐私数据的操作;否则,禁止执行获取隐私数据的操作。同理,若读取出的to字段内容与查询交易中声明的to字段内容相同,则可进一步执行获取隐私数据的操作;否则,禁止执行获取隐私数据的操作。For example, after the blockchain node determines that the query authority of user B is allowed to query, it can obtain historical transactions from the blockchain (stored on the blockchain) according to the hash value of the historical transactions, and read out The content recorded in the from field of the historical transaction and the content of the to field of the historical transaction. If the content of the read from field is the same as the content of the from field declared in the query transaction, the operation of obtaining private data can be further performed; otherwise, the execution of the acquisition is prohibited Operation of private data. Similarly, if the content of the read to field is the same as that declared in the query transaction, the operation of obtaining private data can be further performed; otherwise, the operation of obtaining private data is prohibited.

需要说明的是,当确定出查询方的查询权限为禁止查询时,上述校验步骤为不必要的操作,因此无需执行上述校验的步骤,从而可减少对区块链节点处理资源的占用,进而提高区块链节点的性能。It should be noted that when it is determined that the query authority of the querying party is prohibited from querying, the above verification steps are unnecessary operations, so the above verification steps do not need to be performed, thereby reducing the occupation of blockchain node processing resources. This improves the performance of blockchain nodes.

进一步的,在利用业务合约确定出用户B的查询权限为禁止查询后,可生成关于用户B禁止查询隐私数据的合约收据以供用户B查看。或者,由区块链节点向用户B返回禁止查询的回执以告知用户B的查询权限为禁止查询。Further, after using the business contract to determine that the query authority of user B is prohibited from querying, a contract receipt about user B's prohibition of querying private data can be generated for user B to view. Alternatively, the block chain node returns to user B a receipt of prohibition of query to inform user B that the query authority is prohibited.

步骤622,区块链节点获取隐私数据。Step 622, the blockchain node acquires private data.

步骤624,区块链节点将隐私数据读入TEE进行解密。Step 624, the blockchain node reads the private data into the TEE for decryption.

在本实施例中,由上述图3所示实施例可知,出于隐私保护的目的,隐私数据被加密存储。同时,根据隐私数据中包含的数据类型的不同,所采用的加密方式也不同。因此,在获取隐私数据(例如,根据历史交易的hash值获取隐私数据)后,可将获取到的隐私数据读入可信执行环境进行解密,以由查询方获取。In this embodiment, it can be seen from the above embodiment shown in FIG. 3 that for the purpose of privacy protection, private data is encrypted and stored. At the same time, depending on the type of data contained in the privacy data, the encryption methods adopted are also different. Therefore, after obtaining the private data (for example, obtaining the private data according to the hash value of the historical transaction), the obtained private data can be read into the trusted execution environment for decryption, so as to be obtained by the querying party.

当隐私数据包括历史交易和/或历史交易的交易收据时,由上述图3所示实施例可知,历史交易和历史交易的交易收据均被采用历史交易的发起方使用的对称密钥进行加密。因此,在获取到历史交易和/或历史交易的交易收据后,可先获取用户A使用的对称密钥,再在TEE内通过该对称密钥对历史交易和/或历史交易的交易收据进行解密。而对于发起方使用的对称密钥的获取,可先获取用于加密历史交易的对称密钥(该对称密钥被用户A使用的公钥加密),在TEE内通过与用户A使用的公钥对应的私钥,对该对称密钥进行解密以得到解密后的对称密钥。When the privacy data includes historical transactions and/or transaction receipts of historical transactions, it can be known from the above embodiment shown in FIG. 3 that both historical transactions and transaction receipts of historical transactions are encrypted using the symmetric key used by the originator of the historical transactions. Therefore, after obtaining the historical transaction and/or the transaction receipt of the historical transaction, the symmetric key used by user A can be obtained first, and then the historical transaction and/or the transaction receipt of the historical transaction can be decrypted in the TEE by using the symmetric key . For the acquisition of the symmetric key used by the initiator, the symmetric key used to encrypt the historical transaction can be obtained first (the symmetric key is encrypted by the public key used by user A), and the public key used by user A can be used in the TEE The corresponding private key is decrypted to obtain the decrypted symmetric key.

当隐私数据包括用户A的账户属性信息、业务合约的账户属性信息、业务合约的合约代码、业务合约的合约状态数据中至少之一时,可在TEE内通过区块链节点的特定对称密钥对这些隐私数据进行解密。When the privacy data includes at least one of user A's account attribute information, account attribute information of business contracts, contract code of business contracts, and contract status data of business contracts, specific symmetric key pairs of blockchain nodes can be passed in TEE These private data are decrypted.

例如,特定对称密钥可以是seal(Simple Encrypted Arithmetic Library)密钥,该seal密钥可在通过远程证明后由密钥管理服务器发送给区块链节点,或者可以是各个区块链节点之间协商得到,进而区块链节点使用该seal密钥对隐私数据进行加密和解密。当然,通过远程证明后由密钥管理服务器发送给区块链节点,或者各个区块链节点之间协商得到的对称密钥,可以并非上述的seal密钥,而是root密钥(根密钥),且上述的seal密钥可以为该root密钥的衍生密钥。例如,root密钥可以不可逆地依次衍生出若干版本的衍生密钥,且任意相邻的两个密钥之间由高版本密钥不可逆地衍生出低版本密钥,从而形成链式的密钥衍生结构。比如,如果需要衍生出版本号分别为0~255的256个版本的密钥,可以将root密钥与版本因子0xFF(十进制的取值为255,即需要生成的密钥的版本号;当然,也可以采用其他取值)进行哈希计算,得到版本号为255的密钥key-255;通过将密钥key-255与版本因子0xFE进行哈希计算,得到版本号为254的密钥key-254;……通过将密钥key-1与版本因子0x00进行哈希计算,得到版本号为0的密钥key-0。由于哈希算法的特性,使得高版本密钥与低版本密钥之间的计算不可逆,比如可以由密钥key-1与版本因子0x00计算得到密钥key-0,但是不能够通过密钥key-0与版本因子0x00反推出密钥key-1。For example, the specific symmetric key can be a seal (Simple Encrypted Arithmetic Library) key, which can be sent to the blockchain node by the key management server after passing the remote certification, or can be the key between each blockchain node. Negotiated, and then blockchain nodes use the seal key to encrypt and decrypt private data. Of course, the symmetric key sent by the key management server to the blockchain node after remote certification, or negotiated between each blockchain node, may not be the above-mentioned seal key, but the root key (the root key ), and the above-mentioned seal key may be a derived key of the root key. For example, the root key can irreversibly derive several versions of derived keys in sequence, and any adjacent two keys can irreversibly derive a lower version key from a higher version key, thus forming a chained key derivative structure. For example, if you need to derive 256 versions of keys with version numbers from 0 to 255, you can combine the root key with the version factor 0xFF (the decimal value is 255, which is the version number of the key to be generated; of course, Other values) can also be used for hash calculation to obtain the key key-255 with the version number 255; by hashing the key key-255 and the version factor 0xFE, the key key-255 with the version number 254 is obtained. 254; ... By performing hash calculation on the key key-1 and the version factor 0x00, the key key-0 whose version number is 0 is obtained. Due to the characteristics of the hash algorithm, the calculation between the high version key and the low version key is irreversible. For example, the key key-0 can be calculated from the key key-1 and the version factor 0x00, but the key cannot be obtained through the key key. -0 and version factor 0x00 deduce the key key-1.

那么,可以指定某一版本的衍生密钥,作为上述的seal密钥对隐私数据进行加密。进一步地,还可以对seal密钥进行版本更新,且基于上文所述的特性,应当从低版本密钥向高版本密钥进行更新,使得即便低版本密钥泄露后,也无法反推出高版本密钥,确保足够的数据安全性。Then, a derived key of a certain version can be designated as the above-mentioned seal key to encrypt private data. Furthermore, it is also possible to update the version of the seal key, and based on the characteristics described above, it should be updated from the lower version key to the higher version key, so that even if the lower version key is leaked, the higher version key cannot be reversed. Version key to ensure sufficient data security.

步骤626,区块链节点采用用户B的对称密钥对隐私数据进行加密。Step 626, the blockchain node encrypts the private data using the symmetric key of user B.

步骤628,用户B查看隐私数据。Step 628, user B checks private data.

在一实施例中,区块链节点在对隐私数据进行加密后,可生成包含该隐私数据的事件存储到区块链日志中,那么,用户B可使用客户端通过区块链的回调机制来获取该事件,从而查看隐私数据。而在获取到隐私数据后,用户B通过客户端采用自身使用的对称密钥对隐私数据进行解密即可得到明文内容的隐私数据。In an embodiment, after the blockchain node encrypts the private data, it can generate an event containing the private data and store it in the blockchain log. Then, user B can use the client through the callback mechanism of the blockchain to Get this event to view private data. After obtaining the private data, user B can use the symmetric key used by the client to decrypt the private data to obtain the private data in plain text.

在另一实施例中,区块链节点在对隐私数据进行加密后,可直接向用户B使用的客户端返回加密后的隐私数据。同理,用户B通过客户端采用自身使用的对称密钥对隐私数据进行解密即可得到明文内容的隐私数据。In another embodiment, after the blockchain node encrypts the private data, it can directly return the encrypted private data to the client used by user B. In the same way, user B decrypts the private data through the client using its own symmetric key to obtain the private data in plain text.

在上述图5所示实施例中,用户B创建的查询交易中包含历史交易的hash值、from字段和to字段的内容,而经上述分析可知,查询交易中还可仅包含历史交易的hash值,无需写入from字段和to字段的内容。下面结合图7进行说明。如图7所示,用户B作为查询方查询隐私数据的过程可包括以下步骤:In the embodiment shown in Figure 5 above, the query transaction created by user B contains the hash value of the historical transaction, the from field and the content of the to field, but it can be known from the above analysis that the query transaction can only contain the hash value of the historical transaction , without writing the contents of the from field and to field. The following description will be made in conjunction with FIG. 7 . As shown in Figure 7, the process of user B querying private data as the querying party may include the following steps:

步骤702,用户B通过使用的客户端创建查询交易。In step 702, user B creates an inquiry transaction through the client used.

在本实施例中,查询交易的to字段记录的是分发代码的特定调用地址,同时还可在查询交易的data字段(或者其他字段)中记录历史交易的hash值(即交易ID)。其中,历史交易的hash值可由用户B与用户A之间通过线下分享的方式得到,或者通过其他任意方式得到。In this embodiment, the to field of the query transaction records the specific calling address of the distribution code, and the hash value of the historical transaction (that is, the transaction ID) can also be recorded in the data field (or other fields) of the query transaction. Among them, the hash value of the historical transaction can be obtained by offline sharing between user B and user A, or obtained by other arbitrary methods.

步骤704,用户B通过客户端采用数字信封加密查询交易。In step 704, user B uses the digital envelope to encrypt and query the transaction through the client.

步骤706,用户B通过客户端向区块链节点发起查询交易。Step 706, user B initiates a query transaction to the blockchain node through the client.

步骤708,区块链节点在TEE内解密查询交易。Step 708, the blockchain node decrypts the query transaction in the TEE.

需要说明的是,本实施例中加密和解密的过程与上述图5所示实施例类似,在此不再赘述。It should be noted that the process of encryption and decryption in this embodiment is similar to the above embodiment shown in FIG. 5 , and will not be repeated here.

步骤710,区块链节点确定接收到的交易为查询交易。Step 710, the blockchain node determines that the received transaction is a query transaction.

在本实施例中,区块链节点在接收到任一交易后,读取该交易的to字段内容。当to字段内容为分发代码的特定调用地址时,说明该交易用于调用分发代码,那么可确定出该交易为查询交易。In this embodiment, after receiving any transaction, the blockchain node reads the content of the to field of the transaction. When the content of the to field is the specific call address of the distribution code, it means that the transaction is used to call the distribution code, and then it can be determined that the transaction is a query transaction.

步骤712,区块链节点根据hash值获取历史交易的from字段和to字段。Step 712, the blockchain node obtains the from field and to field of the historical transaction according to the hash value.

在本实施例中,历史交易的from字段的内容为历史交易的发起方的地址(本实施例中为发起方的身份信息),历史交易的to字段的内容为历史交易调用的业务合约的合约地址。In this embodiment, the content of the from field of the historical transaction is the address of the initiator of the historical transaction (in this embodiment, the identity information of the initiator), and the content of the to field of the historical transaction is the contract of the business contract called by the historical transaction address.

步骤714,区块链节点根据历史交易的to字段确定历史交易调用的业务合约。Step 714, the blockchain node determines the business contract invoked by the historical transaction according to the to field of the historical transaction.

步骤716,区块链节点调用业务合约。Step 716, the blockchain node invokes the business contract.

步骤718,业务合约根据查询交易的from字段和历史交易的from字段确定用户B的查询权限。Step 718, the business contract determines the query authority of user B according to the from field of the query transaction and the from field of the historical transaction.

在本实施例中,以查询方和历史交易的发起方的身份信息共同作为权限控制的依据为例。例如,权限控制规则(以权限控制代码的形式定义在业务合约中)中记录查询组和被查询组,属于查询组的成员允许查看被查询组成员的隐私数据;或者,权限控制规则中直接记录各个用户可以查看哪些其他用户的对应关系。其中,采用账户地址作为用户的身份信息。那么,区块链节点执行业务合约中定义的权限控制代码,从而根据查询方的账户地址(查询交易的from字段内容)和历史交易的发起方的账户地址(历史交易的from字段内容)来确定用户B的查询权限。In this embodiment, the identity information of the inquiring party and the originator of the historical transaction are jointly used as the basis for authority control as an example. For example, the access control rules (defined in the business contract in the form of access control codes) record the query group and the queried group, and members belonging to the query group are allowed to view the private data of the members of the queried group; or, directly record in the access control rules Which other users' correspondences can be viewed by each user. Wherein, the account address is used as the identity information of the user. Then, the blockchain node executes the authority control code defined in the business contract, so as to determine according to the account address of the inquiring party (the content of the from field of the query transaction) and the account address of the originator of the historical transaction (the content of the from field of the historical transaction) User B's query permission.

步骤720,业务合约向区块链节点返回用户B的查询权限。Step 720, the business contract returns the query authority of user B to the blockchain node.

步骤722,当用户B的查询权限为允许查询时,区块链节点获取隐私数据。Step 722, when user B's query permission is allowed to query, the blockchain node obtains private data.

在本实施例中,在利用业务合约确定出用户B的查询权限为禁止查询后,可生成关于用户B禁止查询隐私数据的合约收据以供用户B查看。或者,由区块链节点向用户B返回禁止查询的回执以告知用户B的查询权限为禁止查询。In this embodiment, after using the business contract to determine that user B's query authority is prohibited from querying, a contract receipt for user B's prohibition of querying private data can be generated for user B to view. Alternatively, the block chain node returns to user B a receipt of prohibition of query to inform user B that the query authority is prohibited.

步骤724,区块链节点将隐私数据读入TEE进行解密。Step 724, the blockchain node reads the private data into the TEE for decryption.

步骤726,区块链节点采用用户B的对称密钥对隐私数据进行加密。Step 726, the blockchain node encrypts the private data using the symmetric key of user B.

需要说明的是,当隐私数据为历史交易时,获取历史交易并解密历史交易的过程在执行步骤712时执行,即根据历史交易的hash值获取历史交易,并对历史交易进行解密得到历史交易的明文交易内容,从而读取历史交易的from字段和to字段。因此,在该情况下,当确定出查询权限为允许查询时,(无需再执行获取历史交易和解密历史交易的操作)直接获取解密后的历史交易供查询方查看即可。It should be noted that when the private data is historical transactions, the process of obtaining historical transactions and decrypting historical transactions is performed when step 712 is executed, that is, obtaining historical transactions according to the hash value of historical transactions, and decrypting historical transactions to obtain the historical transaction Clear text transaction content, so as to read the from field and to field of the historical transaction. Therefore, in this case, when it is determined that the query authority is allowed to query, (there is no need to perform the operations of acquiring and decrypting historical transactions) the decrypted historical transactions can be obtained directly for the querying party to view.

步骤728,用户B查看隐私数据。Step 728, user B checks private data.

可见,通过本说明书隐私数据的查询方案,用户A无需向用户B分享自身使用的对称密钥,便可实现用户A与用户B之间隐私数据的分享,从而提高了安全性与便捷性。It can be seen that through the private data query scheme in this manual, user A can realize the sharing of private data between user A and user B without sharing the symmetric key used by user A with user B, thereby improving security and convenience.

与上述方法实施例相对应,本说明书还提供了一种基于链代码的权限查询配置装置的实施例。Corresponding to the above method embodiments, this specification also provides an embodiment of a chaincode-based permission query configuration device.

本说明书的基于链代码的权限查询配置装置的实施例可以应用在电子设备上。装置实施例可以通过软件实现,也可以通过硬件或者软硬件结合的方式实现。以软件实现为例,作为一个逻辑意义上的装置,是通过其所在电子设备的处理器将非易失性存储器中对应的计算机程序指令读取到内存中运行形成的。Embodiments of the chaincode-based permission query configuration device in this specification can be applied to electronic equipment. The device embodiments can be implemented by software, or by hardware or a combination of software and hardware. Taking software implementation as an example, as a device in a logical sense, it is formed by reading the corresponding computer program instructions in the non-volatile memory into the memory for operation by the processor of the electronic device where it is located.

从硬件层面而言,请参考图8,图8是一示例性实施例提供的一种设备的示意结构图。如图8所示,在硬件层面,该设备包括处理器802、内部总线804、网络接口806、内存808以及非易失性存储器810,当然还可能包括其他业务所需要的硬件。处理器802从非易失性存储器810中读取对应的计算机程序到内存808中然后运行,在逻辑层面上形成基于链代码的权限查询配置装置。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。From the perspective of hardware, please refer to FIG. 8 , which is a schematic structural diagram of a device provided by an exemplary embodiment. As shown in FIG. 8 , at the hardware level, the device includes a processor 802 , an internal bus 804 , a network interface 806 , a memory 808 and a non-volatile memory 810 , and of course may also include hardware required by other services. The processor 802 reads the corresponding computer program from the non-volatile memory 810 into the memory 808 and then runs it, forming a chaincode-based permission query configuration device on a logical level. Of course, in addition to software implementations, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each A logic unit, which can also be a hardware or logic device.

请参考图9,在软件实施方式中,该配置装置应用于区块链节点,可以包括:Please refer to FIG. 9, in a software implementation, the configuration device is applied to a block chain node, and may include:

第一更新单元91,将获取到的分发代码读入可信执行环境,以对所述可信执行环境中维护的链代码进行更新,所述分发代码用于在接收到查询方针对与历史交易相关的隐私数据的查询交易时,调用所述历史交易所调用的业务合约以执行所述业务合约中定义的权限控制代码,确定所述查询方的查询权限;The first update unit 91 reads the obtained distribution code into the trusted execution environment to update the chain code maintained in the trusted execution environment, and the distribution code is used to match the historical transaction with the party receiving the query When inquiring about the relevant privacy data, call the business contract invoked by the historical transaction to execute the authority control code defined in the business contract, and determine the inquiry authority of the inquiring party;

验证单元92,当接收到挑战方发起的针对所述分发代码的验证请求时,读取所述可信执行环境中维护的分发代码以生成验证报告,并向所述挑战方发送所述验证报告,以使得所述挑战方根据所述验证报告对所述可信执行环境中的分发代码进行验证。The verification unit 92, when receiving a verification request for the distribution code initiated by the challenger, reads the distribution code maintained in the trusted execution environment to generate a verification report, and sends the verification report to the challenger , so that the challenger verifies the distribution code in the trusted execution environment according to the verification report.

可选的,针对所述分发代码配置有特定调用地址;所述装置还包括:Optionally, a specific calling address is configured for the distribution code; the device also includes:

交易识别单元93,当接收到的任一交易通过所述特定调用地址调用所述分发代码时,将所述任一交易作为查询交易。The transaction identifying unit 93, when any received transaction calls the distribution code through the specific calling address, takes the any transaction as a query transaction.

可选的,optional,

还包括:第二更新单元94,根据获取到的新版本链代码对所述可信执行环境中维护的链代码进行更新,所述新版本链代码用于根据所述查询交易中包含的交易标识获取所述历史交易,并基于所述历史交易确定所述历史交易调用的业务合约;It also includes: a second update unit 94, which updates the chaincode maintained in the trusted execution environment according to the obtained new version chaincode, and the new version chaincode is used to identify Obtaining the historical transaction, and determining the business contract invoked by the historical transaction based on the historical transaction;

所述分发代码用于调用通过执行所述新版本链代码确定出的业务合约,以执行所调用的业务合约中定义的权限控制代码。The distribution code is used to call the business contract determined by executing the new version chain code, so as to execute the permission control code defined in the called business contract.

可选的,所述分发代码用于根据所述查询交易中包含的所述历史交易调用的业务合约的合约地址确定相应的业务合约,并调用确定出的业务合约以执行相应的权限控制代码来确定所述查询方的查询权限;所述装置还包括:Optionally, the distribution code is used to determine the corresponding business contract according to the contract address of the business contract called by the historical transaction contained in the query transaction, and call the determined business contract to execute the corresponding authority control code to Determine the inquiry authority of the inquiring party; the device also includes:

第三更新单元95,根据获取到的新版本链代码对所述可信执行环境中维护的链代码进行更新,所述新版本链代码用于在通过业务合约确定出查询方的查询权限为允许查询时,根据所述查询交易中包含的交易标识获取所述历史交易,并根据获取到的历史交易确定出所述历史交易实际调用的业务合约的合约地址,以及当确定出的合约地址与所述查询交易中包含的合约地址不一致时,判定所述查询方的查询权限为禁止查询。The third updating unit 95 updates the chain code maintained in the trusted execution environment according to the obtained new version of the chain code, and the new version of the chain code is used to determine that the query authority of the querying party is allowed through the business contract When querying, obtain the historical transaction according to the transaction identifier contained in the query transaction, and determine the contract address of the business contract actually called by the historical transaction according to the obtained historical transaction, and when the determined contract address is consistent with the When the contract addresses contained in the query transaction are inconsistent, it is determined that the query authority of the query party is prohibition of query.

可选的,所述新版本链代码还用于在确定出所述查询方的查询权限为允许查询时,获取解密后的所述隐私数据以由所述查询方查看,所述隐私数据被读入可信执行环境进行解密。Optionally, the new version of the chain code is also used to obtain the decrypted private data for viewing by the querying party when it is determined that the querying authority of the querying party is allowed to query, and the private data is read into the trusted execution environment for decryption.

可选的,所述隐私数据包括以下至少之一:Optionally, the private data includes at least one of the following:

所述历史交易、对应于所述历史交易的交易收据、所述历史交易的发起方的账户属性信息、所述历史交易调用的业务合约的账户属性信息、所述业务合约的合约代码、所述业务合约的合约状态数据。The historical transaction, the transaction receipt corresponding to the historical transaction, the account attribute information of the initiator of the historical transaction, the account attribute information of the business contract called by the historical transaction, the contract code of the business contract, the Contract state data for business contracts.

从硬件层面而言,请参考图10,图10是一示例性实施例提供的一种设备的示意结构图。如图10所示,在硬件层面,该设备包括处理器1002、内部总线1004、网络接口1006、内存1008以及非易失性存储器1010,当然还可能包括其他业务所需要的硬件。处理器1002从非易失性存储器1010中读取对应的计算机程序到内存10010中然后运行,在逻辑层面上形成隐私数据的查询装置。当然,除了软件实现方式之外,本说明书一个或多个实施例并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。From the perspective of hardware, please refer to FIG. 10 , which is a schematic structural diagram of a device provided by an exemplary embodiment. As shown in FIG. 10 , at the hardware level, the device includes a processor 1002 , an internal bus 1004 , a network interface 1006 , a memory 1008 and a non-volatile memory 1010 , and of course it may also include hardware required by other services. The processor 1002 reads the corresponding computer program from the non-volatile memory 1010 into the memory 10010 and then runs it, forming a private data query device on a logical level. Of course, in addition to software implementations, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is to say, the execution subject of the following processing flow is not limited to each A logic unit, which can also be a hardware or logic device.

请参考图11,在软件实施方式中,该查询装置应用于区块链节点,可以包括:Please refer to Figure 11. In a software implementation, the query device is applied to a block chain node and may include:

代码读取单元1101,当接收到查询方提交的与历史交易相关的隐私数据的查询交易时,读取可信执行环境中维护的分发代码,所述分发代码属于所述可信执行环境中维护的链代码的一部分;The code reading unit 1101 reads the distribution code maintained in the trusted execution environment when receiving the query transaction of the private data related to the historical transaction submitted by the querying party, and the distribution code belongs to the distribution code maintained in the trusted execution environment. part of the chaincode;

权限确定单元1102,在所述可信执行环境中执行所述分发代码,以根据所述历史交易所调用的业务合约中定义的权限控制代码确定所述查询方的查询权限;The authority determining unit 1102, executes the distribution code in the trusted execution environment, so as to determine the inquiry authority of the inquiring party according to the authority control code defined in the business contract invoked by the historical transaction;

数据获取单元1103,当确定出的查询权限为允许查询时,获取所述隐私数据,并将获取到的隐私数据读入可信执行环境进行解密,以由所述查询方获取。The data acquiring unit 1103 acquires the private data when it is determined that the query authority is allowed to query, and reads the acquired private data into a trusted execution environment for decryption, so as to be obtained by the querying party.

上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。The systems, devices, modules, or units described in the above embodiments can be specifically implemented by computer chips or entities, or by products with certain functions. A typical implementing device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or Combinations of any of these devices.

为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本说明书时可以把各单元的功能在同一个或多个软件和/或硬件中实现。For the convenience of description, when describing the above devices, functions are divided into various units and described separately. Of course, when implementing this specification, the functions of each unit can be implemented in one or more pieces of software and/or hardware.

本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art should understand that the embodiments of the present invention may be provided as methods, systems, or computer program products. Accordingly, the present invention can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention may 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.) having computer-usable program code embodied therein.

本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It should be understood that each procedure and/or block in the flowchart and/or block diagram, and a combination of procedures and/or blocks in the flowchart and/or block diagram can be realized by computer program instructions. These computer program instructions may be provided to a general purpose computer, special purpose computer, embedded processor, or processor of other programmable data processing equipment to produce a machine such that the instructions executed by the processor of the computer or other programmable data processing equipment produce a An apparatus for realizing the functions specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

本说明书可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对象、组件、数据结构等等。也可以在分布式计算环境中实践本说明书,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。The specification may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The present description may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including storage devices.

这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing apparatus to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture comprising instruction means, the instructions The device realizes the function specified in one or more procedures of the flowchart and/or one or more blocks of the block diagram.

这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。在一个典型的配置中,计算机包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。These computer program instructions can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby The instructions provide steps for implementing the functions specified in the flow chart or blocks of the flowchart and/or the block or blocks of the block diagrams. In a typical configuration, a computer includes one or more processors (CPUs), input/output interfaces, network interfaces and memory.

内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。Memory may include non-permanent storage in computer-readable media, in the form of random access memory (RAM) and/or nonvolatile memory such as read-only memory (ROM) or flash RAM. Memory is an example of computer readable media.

计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带、磁盘存储、量子存储器、基于石墨烯的存储介质或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer-readable media, including both permanent and non-permanent, removable and non-removable media, can be implemented by any method or technology for storage of information. Information may be computer readable instructions, data structures, modules of a program, 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 technology, Compact Disc Read-Only Memory (CD-ROM), Digital Versatile Disc (DVD) or other optical storage, Magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by computing devices. As defined herein, computer-readable media excludes transitory computer-readable media, such as modulated data signals and carrier waves.

还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。It should also be noted that the term "comprises", "comprises" or any other variation thereof is intended to cover a non-exclusive inclusion such that a process, method, article, or apparatus comprising a set of elements includes not only those elements, but also includes Other elements not expressly listed, or elements inherent in the process, method, commodity, or apparatus are also included. Without further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article or apparatus comprising said element.

上述对本说明书特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。The foregoing describes specific embodiments of this specification. Other implementations are within the scope of the following claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying figures do not necessarily require the particular order shown, or sequential order, to achieve desirable results. Multitasking and parallel processing are also possible or may be advantageous in certain embodiments.

在本说明书一个或多个实施例使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本说明书一个或多个实施例。在本说明书一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包括多数形式,除非上下文清楚地表示其他含义。还应当理解,本文中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。Terms used in one or more embodiments of the present specification are for the purpose of describing specific embodiments only, and are not intended to limit the one or more embodiments of the present specification. As used in one or more embodiments of this specification and the appended claims, the singular forms "a", "the", and "the" are also intended to include the plural forms unless the context clearly dictates otherwise. It should also be understood that the term "and/or" as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

应当理解,尽管在本说明书一个或多个实施例可能采用术语第一、第二、第三等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本说明书一个或多个实施例范围的情况下,第一信息也可以被称为第二信息,类似地,第二信息也可以被称为第一信息。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。It should be understood that although the terms first, second, third, etc. may be used in one or more embodiments of the present specification to describe various information, the information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of one or more embodiments of this specification, first information may also be called second information, and similarly, second information may also be called first information. Depending on the context, the word "if" as used herein may be interpreted as "at" or "when" or "in response to a determination."

以上所述仅为本说明书一个或多个实施例的较佳实施例而已,并不用以限制本说明书一个或多个实施例,凡在本说明书一个或多个实施例的精神和原则之内,所做的任何修改、等同替换、改进等,均应包含在本说明书一个或多个实施例保护的范围之内。The above descriptions are only preferred embodiments of one or more embodiments of this specification, and are not intended to limit one or more embodiments of this specification. Within the spirit and principles of one or more embodiments of this specification, Any modification, equivalent replacement, improvement, etc. should be included in the scope of protection of one or more embodiments of this specification.

Claims (21)

1. A permission query configuration method based on a chain code is applied to block chain nodes; the method comprises the following steps:
reading the acquired distribution codes into a trusted execution environment to update chain codes maintained in the trusted execution environment, wherein the distribution codes are used for determining corresponding business contracts according to contract addresses of business contracts called by historical transaction contained in query transactions when query transactions of query parties aiming at privacy data related to the historical transaction are received, and executing authority control codes defined in the determined business contracts to determine query authorities of the query parties; wherein, when the historical transaction invokes a business contract, business codes defined in the business contract invoked by the historical transaction are executed;
updating the chain code maintained in the trusted execution environment according to the acquired new version chain code, wherein the new version chain code is used for acquiring the historical transaction according to the transaction identifier contained in the query transaction when the query authority of the query party is determined to be allowed to query, determining the contract address of the service contract actually called by the historical transaction according to the acquired historical transaction, and judging that the query authority of the query party is forbidden to query when the determined contract address is inconsistent with the contract address contained in the query transaction.
2. The method of claim 1, configured with a specific call address for the distribution code; the method further comprises the steps of:
and when any received transaction calls the distribution code through the specific call address, taking any transaction as a query transaction.
3. The method of claim 1, further comprising:
when a verification request for the distributed code initiated by a challenger is received, the distributed code maintained in the trusted execution environment is read to generate a verification report, and the verification report is sent to the challenger, so that the challenger verifies the distributed code in the trusted execution environment according to the verification report.
4. The method of claim 1, wherein the new version chain code is further configured to, when determining that the querying authority of the querying party is permission to query, obtain the decrypted private data for viewing by the querying party, where the private data is read into a trusted execution environment for decryption.
5. The method of claim 1, the privacy data comprising at least one of:
the historical transaction, a transaction receipt corresponding to the historical transaction, account attribute information of an initiator of the historical transaction, account attribute information of a business contract invoked by the historical transaction, a contract code of the business contract invoked by the historical transaction, and contract status data of the business contract invoked by the historical transaction.
6. A query method of privacy data is applied to a blockchain node; the method comprises the following steps:
when a query transaction submitted by a query party for privacy data related to historical transactions is received, reading a distribution code maintained in a trusted execution environment, wherein the distribution code belongs to a part of chain codes maintained in the trusted execution environment;
executing the distributing code in the trusted execution environment to determine a corresponding business contract according to the contract address of the business contract called by the historical transaction contained in the query transaction, and executing the authority control code defined in the determined business contract to determine the query authority of the query party; wherein, when the historical transaction calls a business contract, a business code defined in the business contract called by the historical transaction is executed;
when the determined inquiry authority is the permission of inquiry, executing other chain codes different from the distribution codes in the chain codes in the trusted execution environment so as to acquire the historical transaction according to the transaction identifier contained in the inquiry transaction, and determining the contract address of the business contract actually invoked by the historical transaction according to the acquired historical transaction; if the determined contract address is consistent with the contract address contained in the inquiry transaction, acquiring the decrypted privacy data to be checked by the inquirer, wherein the privacy data is read into a trusted execution environment for decryption; otherwise, judging the query authority of the query party as forbidden query.
7. The method of claim 6, configured with a specific call address for the dispatch code; the method further comprises the steps of:
and when any received transaction calls the distribution code through the specific call address, taking any transaction as a query transaction.
8. The method of claim 6, the privacy data comprising at least one of:
the historical transaction, a transaction receipt corresponding to the historical transaction, account attribute information of an initiator of the historical transaction, account attribute information of a business contract invoked by the historical transaction, a contract code of the business contract, and contract state data of the business contract.
9. The method of claim 8, the privacy data comprising the historical transaction and/or the transaction receipt; the method further comprises the steps of:
acquiring a symmetric key used by an initiator of the historical transaction;
decrypting the private data within the trusted execution environment with the symmetric key.
10. The method of claim 9, the obtaining a symmetric key used by an initiator of the historical transaction, comprising:
obtaining a symmetric key for encrypting the historical transaction, the symmetric key being encrypted by a public key used by an initiator of the historical transaction;
And decrypting the symmetric key in the trusted execution environment through a private key corresponding to the public key used by the initiator of the historical transaction to obtain a decrypted symmetric key.
11. The method of claim 10, wherein a public key used by an initiator of the historical transaction is sent by a key management server to the initiator of the historical transaction through remote attestation, wherein a trusted execution environment of the blockchain node is established by an SGX architecture, and wherein a private key corresponding to the public key used by the initiator of the historical transaction is sent by the key management server to an enclosure of the blockchain node through remote attestation.
12. The method of claim 8, the privacy data comprising at least one of account attribute information of an initiator of the historical transaction, account attribute information of a business contract invoked by the historical transaction, a contract code of the business contract, contract status data of the business contract; the method further comprises the steps of:
decrypting the private data within the trusted execution environment with a symmetric key of the blockchain node.
13. The method of claim 12, the trusted execution environment of the blockchain node is established by an SGX architecture, and the symmetric key of the blockchain node is sent by a key management server after the SGX architecture of the blockchain node passes remote attestation, or is negotiated between the blockchain node and other blockchain nodes.
14. The method according to claim 6, wherein the method comprises,
executing the rights control code defined in the determined business contract to determine the query rights of the querying party includes: executing the authority control codes defined in the determined business contracts to determine the inquiring authority of the inquiring party for the privacy data according to the identity information of the inquiring party;
or the inquiry transaction also comprises the identity information of the initiator of the historical transaction; executing the rights control code defined in the determined business contract to determine the query rights of the querying party includes: executing authority control codes defined in the determined business contracts to determine the inquiring authority of the inquiring party for the privacy data according to the identity information of the inquiring party and the identity information of the initiator of the historical transaction; or determining the query authority of the querying party for the private data according to the identity information of the initiator of the historical transaction.
15. The method of claim 14, after determining that the query authority is permissible for the query, the method further comprising:
acquiring the historical transaction according to the transaction identifier;
Determining identity information of an initiator of the historical transaction according to the acquired historical transaction;
and when the determined identity information is inconsistent with the identity information of the initiator of the historical transaction contained in the inquiry transaction, prohibiting the operation of acquiring the privacy data.
16. The method of claim 6, wherein a symmetric key that encrypts the query transaction is encrypted by a public key used by the querying party;
after receiving the query transaction, the method further comprises: decrypting a symmetric key for encrypting the query transaction through a private key corresponding to a public key used by the query party in the trusted execution environment, and decrypting the query transaction through the symmetric key obtained through decryption to obtain transaction content contained in the query transaction;
after decrypting the private data, the method further comprises: and encrypting the decrypted private data by the symmetric key of the inquiring party.
17. The method of claim 6, further comprising:
and when the determined inquiry authority is inquiry prohibition, generating a contract receipt for indicating that the inquirer prohibits inquiring the private data for viewing by the inquirer.
18. A permission query configuration device based on a chain code is applied to a blockchain node; the device comprises:
the first updating unit reads the acquired distribution codes into a trusted execution environment to update chain codes maintained in the trusted execution environment, wherein the distribution codes are used for determining corresponding business contracts according to contract addresses of business contracts called by historical transactions contained in query transactions when query transactions of query parties aiming at privacy data related to the historical transactions are received, and executing authority control codes defined in the determined business contracts to determine query authorities of the query parties; wherein, when the historical transaction calls a business contract, a business code defined in the business contract called by the historical transaction is executed;
the second updating unit is used for updating the chain code maintained in the trusted execution environment according to the acquired new version chain code, wherein the new version chain code is used for acquiring the historical transaction according to the transaction identifier contained in the query transaction when the query permission of the query party is determined to be permission for query, determining the contract address of the service contract actually invoked by the historical transaction according to the acquired historical transaction, and judging that the query permission of the query party is prohibition of query when the determined contract address is inconsistent with the contract address contained in the query transaction.
19. A query device of privacy data is applied to a blockchain node; the device comprises:
a code reading unit for reading a distribution code maintained in a trusted execution environment when a query transaction for privacy data related to a historical transaction submitted by a querying party is received, wherein the distribution code belongs to a part of chain codes maintained in the trusted execution environment;
a right determining unit executing the distribution code in the trusted execution environment to determine a corresponding business contract according to a contract address of the business contract called by the history transaction included in the query transaction, and executing a right control code defined in the determined business contract to determine a query right of the querying party; wherein, when the historical transaction calls a business contract, a business code defined in the business contract called by the historical transaction is executed;
the data acquisition unit is used for executing other chain codes different from the distribution codes in the chain codes in the trusted execution environment when the determined query permission is the permission for query so as to acquire the historical transaction according to the transaction identifier contained in the query transaction and determining the contract address of the service contract actually invoked by the historical transaction according to the acquired historical transaction; if the determined contract address is consistent with the contract address contained in the inquiry transaction, acquiring the decrypted privacy data to be checked by the inquirer, wherein the privacy data is read into a trusted execution environment for decryption; otherwise, judging the query authority of the query party as forbidden query.
20. An electronic device, comprising:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to implement the method of any one of claims 1-17 by executing the executable instructions.
21. A computer readable storage medium having stored thereon computer instructions which, when executed by a processor, implement the steps of the method of any of claims 1-17.
CN202010307195.XA 2019-11-08 2019-11-08 Authority query configuration method and device based on chain codes Active CN111523110B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010307195.XA CN111523110B (en) 2019-11-08 2019-11-08 Authority query configuration method and device based on chain codes

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201911085167.1A CN110580412B (en) 2019-11-08 2019-11-08 Permission query configuration method and device based on chain codes
CN202010307195.XA CN111523110B (en) 2019-11-08 2019-11-08 Authority query configuration method and device based on chain codes

Related Parent Applications (1)

Application Number Title Priority Date Filing Date
CN201911085167.1A Division CN110580412B (en) 2019-11-08 2019-11-08 Permission query configuration method and device based on chain codes

Publications (2)

Publication Number Publication Date
CN111523110A CN111523110A (en) 2020-08-11
CN111523110B true CN111523110B (en) 2023-05-02

Family

ID=68815544

Family Applications (2)

Application Number Title Priority Date Filing Date
CN201911085167.1A Active CN110580412B (en) 2019-11-08 2019-11-08 Permission query configuration method and device based on chain codes
CN202010307195.XA Active CN111523110B (en) 2019-11-08 2019-11-08 Authority query configuration method and device based on chain codes

Family Applications Before (1)

Application Number Title Priority Date Filing Date
CN201911085167.1A Active CN110580412B (en) 2019-11-08 2019-11-08 Permission query configuration method and device based on chain codes

Country Status (2)

Country Link
CN (2) CN110580412B (en)
WO (1) WO2021088549A1 (en)

Families Citing this family (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110580412B (en) * 2019-11-08 2020-03-06 支付宝(杭州)信息技术有限公司 Permission query configuration method and device based on chain codes
JP6830635B1 (en) * 2020-02-21 2021-02-17 株式会社LayerX Data management method
CN112329041B (en) * 2020-03-18 2024-01-23 支付宝(杭州)信息技术有限公司 Method and device for deploying contracts
CN112199701B (en) * 2020-03-18 2024-06-14 支付宝(杭州)信息技术有限公司 Method and device for calling contract
CN111090876B (en) * 2020-03-18 2020-07-17 支付宝(杭州)信息技术有限公司 Method and device for calling a contract
CN111988141B (en) * 2020-03-18 2022-08-02 支付宝(杭州)信息技术有限公司 Method and device for sharing cluster key
WO2021253299A1 (en) * 2020-06-17 2021-12-23 达闼机器人有限公司 Data processing method, storage medium, electronic device and data transaction system
CN113595732B (en) * 2021-06-11 2024-03-19 上海淇玥信息技术有限公司 A smart contract interaction method, device and electronic device
CN113495924B (en) * 2021-06-28 2024-06-07 成都金融梦工场投资管理有限公司 Anti-fake data safe sharing method based on blockchain
CN114327759B (en) * 2021-07-06 2024-09-13 支付宝(杭州)信息技术有限公司 Blockchain data processing method and device
CN114244851B (en) * 2021-12-24 2023-07-07 四川启睿克科技有限公司 Block chain-based data distribution method
CN116932582A (en) * 2022-04-02 2023-10-24 腾讯科技(深圳)有限公司 Block chain-based data processing method, device and equipment, medium and product
CN115760391A (en) * 2022-11-09 2023-03-07 网易(杭州)网络有限公司 Intelligent contract changing method and device in block chain, electronic equipment and storage medium

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107870788A (en) * 2016-09-26 2018-04-03 展讯通信(上海)有限公司 The startup method and terminal device of terminal device under more credible performing environment
WO2018076761A1 (en) * 2016-10-27 2018-05-03 上海亿账通区块链科技有限公司 Block chain-based transaction permission control method and system, electronic device, and storage medium
CN108632292A (en) * 2018-05-16 2018-10-09 苏宁易购集团股份有限公司 Data sharing method based on alliance's chain and system
CN109255210A (en) * 2018-09-27 2019-01-22 上海点融信息科技有限责任公司 The method, apparatus and storage medium of intelligent contract are provided in block chain network
CN109936626A (en) * 2019-02-19 2019-06-25 阿里巴巴集团控股有限公司 Method, node and storage medium for implementing privacy protection in block chain
CN110032883A (en) * 2019-01-31 2019-07-19 阿里巴巴集团控股有限公司 Method, system and the node of secret protection are realized in block chain
CN110049111A (en) * 2019-03-27 2019-07-23 厦门大学 A kind of industrial control system teleinstruction control method based on block chain technology
CN110245506A (en) * 2019-05-30 2019-09-17 阿里巴巴集团控股有限公司 Intelligent contract management method and device based on block chain and electronic equipment
CN110245945A (en) * 2019-05-20 2019-09-17 阿里巴巴集团控股有限公司 In conjunction with the receipt storage method and node of code mark and user type
CN110268691A (en) * 2017-02-07 2019-09-20 微软技术许可有限责任公司 Consortium blockchain network with proven blockchain and consensus protocol
CN110321721A (en) * 2019-07-02 2019-10-11 石家庄铁道大学 Electronic health record access control method based on block chain

Family Cites Families (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3454519B1 (en) * 2016-12-23 2021-07-21 CloudMinds (Shanghai) Robotics Co., Ltd. Block generation method and device, and blockchain network
CN106920169A (en) * 2017-03-07 2017-07-04 中钞信用卡产业发展有限公司北京智能卡技术研究院 A kind of digital ticket method of commerce and system based on block chain and digital cash
CN107038242B (en) * 2017-04-24 2020-02-07 杭州趣链科技有限公司 Block chain-oriented global intelligent contract service data analysis method
US20190121669A1 (en) * 2017-10-20 2019-04-25 American Express Travel Related Services Company, Inc. Executing tasks using modular and intelligent code and data containers
US10601911B2 (en) * 2017-11-16 2020-03-24 International Business Machines Corporation Partitioning of a blockchain ledger
CN109408461A (en) * 2018-09-14 2019-03-01 中国农业大学 A kind of distributed memory system and method for block chain
CN109523385A (en) * 2018-12-07 2019-03-26 深圳市智税链科技有限公司 A method, accounting node and medium for querying transaction information in a blockchain network
CN109829013A (en) * 2018-12-27 2019-05-31 上海点融信息科技有限责任公司 For running the method for intelligent contract in block chain network, storage medium, calculating equipment
CN110580412B (en) * 2019-11-08 2020-03-06 支付宝(杭州)信息技术有限公司 Permission query configuration method and device based on chain codes

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107870788A (en) * 2016-09-26 2018-04-03 展讯通信(上海)有限公司 The startup method and terminal device of terminal device under more credible performing environment
WO2018076761A1 (en) * 2016-10-27 2018-05-03 上海亿账通区块链科技有限公司 Block chain-based transaction permission control method and system, electronic device, and storage medium
CN110268691A (en) * 2017-02-07 2019-09-20 微软技术许可有限责任公司 Consortium blockchain network with proven blockchain and consensus protocol
CN108632292A (en) * 2018-05-16 2018-10-09 苏宁易购集团股份有限公司 Data sharing method based on alliance's chain and system
CN109255210A (en) * 2018-09-27 2019-01-22 上海点融信息科技有限责任公司 The method, apparatus and storage medium of intelligent contract are provided in block chain network
CN110032883A (en) * 2019-01-31 2019-07-19 阿里巴巴集团控股有限公司 Method, system and the node of secret protection are realized in block chain
CN109936626A (en) * 2019-02-19 2019-06-25 阿里巴巴集团控股有限公司 Method, node and storage medium for implementing privacy protection in block chain
CN110049111A (en) * 2019-03-27 2019-07-23 厦门大学 A kind of industrial control system teleinstruction control method based on block chain technology
CN110245945A (en) * 2019-05-20 2019-09-17 阿里巴巴集团控股有限公司 In conjunction with the receipt storage method and node of code mark and user type
CN110245506A (en) * 2019-05-30 2019-09-17 阿里巴巴集团控股有限公司 Intelligent contract management method and device based on block chain and electronic equipment
CN110321721A (en) * 2019-07-02 2019-10-11 石家庄铁道大学 Electronic health record access control method based on block chain

Also Published As

Publication number Publication date
WO2021088549A1 (en) 2021-05-14
CN111523110A (en) 2020-08-11
CN110580412B (en) 2020-03-06
CN110580412A (en) 2019-12-17

Similar Documents

Publication Publication Date Title
CN110580418B (en) Private data query method and device based on block chain account
CN111523110B (en) Authority query configuration method and device based on chain codes
CN110580414B (en) Private data query method and device based on block chain account
CN110580413B (en) Private data query method and device based on down-link authorization
CN110580262B (en) Private data query method and device based on intelligent contract
CN110580417B (en) Private data query method and device based on intelligent contract
CN110580245B (en) Private data sharing method and device
CN110580411B (en) Permission query configuration method and device based on intelligent contract
HK40035754A (en) Permission query configuration method and device based on chain code
HK40019385A (en) Permission query configuration method and device based on chain codes
HK40019385B (en) Permission query configuration method and device based on chain codes
HK40035754B (en) Permission query configuration method and device based on chain code
HK40019390B (en) Private data query method and device based on blockchain account
HK40019390A (en) Private data query method and device based on blockchain account
HK40018908B (en) Private data sharing method and device
HK40018908A (en) Private data sharing method and device
HK40034597A (en) Private data query method and device based on block chain account
HK40019386A (en) Private data query method and device based on off-chain authorization
HK40019386B (en) Private data query method and device based on off-chain authorization
HK40019389B (en) Privacy data query method and device based on smart contract
HK40019389A (en) Privacy data query method and device based on smart contract
HK40034596A (en) Privacy data query method and device based on smart contract
HK40018909A (en) Privacy data query method and device based on smart contract
HK40018909B (en) Privacy data query method and device based on smart contract
HK40019384B (en) Permission query configuration method and device based on smart contract

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40035754

Country of ref document: HK

GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20240924

Address after: Room 803, floor 8, No. 618 Wai Road, Huangpu District, Shanghai 200010

Patentee after: Ant blockchain Technology (Shanghai) Co.,Ltd.

Country or region after: China

Address before: 310000 801-11 section B, 8th floor, 556 Xixi Road, Xihu District, Hangzhou City, Zhejiang Province

Patentee before: Alipay (Hangzhou) Information Technology Co.,Ltd.

Country or region before: China

TR01 Transfer of patent right