Resource verification method and device

By analyzing the attribute values ​​and hash values ​​of resource requests in the CDN, verifying the integrity of data resources in the content distribution network (CDN), solving the risks of malicious content injection or file replacement in the CDN, and achieving the security and integrity of resource loading.

CN114189374BActive Publication Date: 2025-04-18HUNAN HAPPLY SUNSHINE INTERACTIVE ENTERTAINMENT MEDIA CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111461729.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-02
Publication Date
2025-04-18
Estimated Expiration
2041-12-02

AI Technical Summary

Technical Problem

In the prior art, the content distribution network (CDN) has the risk of malicious content injection or file replacement, resulting in users being attacked or loading incorrect multimedia files.

Method used

Provide a resource verification method, by obtaining the sub-resource elements corresponding to the resource request, parsing its attribute values ​​to obtain the hash value of the encryption algorithm and the target data resource, asynchronously obtaining the target data resource stored by the CDN node, and calculating its hash value, and judging the consistency of the hash value to verify the integrity of the data resource.

Benefits of technology

It effectively avoids the risk of resource loading errors or malicious data resources, and ensures that the data resources received by users are complete and secure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114189374B_ABST
    Figure CN114189374B_ABST
Patent Text Reader

Abstract

The present invention provides a resource verification method and device, the method comprising: when receiving a resource request from a user, obtaining a sub-resource element corresponding to the resource request in a server; based on the sub-resource element, obtaining a first attribute value and a second attribute value of the sub-resource element; parsing the first attribute value to obtain an encryption algorithm applied by the server and a first target hash value of a target data resource to be obtained; based on the second attribute value and a preset first port, asynchronously obtaining a target data resource corresponding to the resource request stored in a preset content distribution network CDN node; applying an encryption algorithm to calculate a second target hash value of the target data resource; determining whether the first target hash value is consistent with the second target hash value; and if so, feeding back the target data resource to the user. By using the method provided by the present invention, the data resources to be fed back can be verified to avoid resource loading errors or malicious data resources.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of network security, and in particular to a resource verification method and device. Background Art

[0002] Using a content delivery network (CDN) to share files such as scripts and style sheets between multiple sites can improve site performance and save bandwidth. However, using a CDN also has risks. If an attacker gains control of a CDN, they can inject arbitrary malicious content into files on the CDN or replace files entirely, potentially attacking all sites that get files from that CDN.

[0003] In the prior art, when an internal error occurs in the CDN or an attacker gains control of the CDN, any malicious content can be injected into the multimedia files on the CDN or completely replace multimedia files such as pictures, audio and video. When users access the website through a Web browser, they may be attacked and load erroneous or malicious multimedia content such as pictures, audio and video. Summary of the invention

[0004] In view of this, the present invention provides a resource verification method, through which data resources to be fed back can be verified to avoid resource loading errors or malicious data resources.

[0005] The present invention also provides a resource verification device to ensure the implementation and application of the above method in practice.

[0006] A resource verification method, comprising:

[0007] When receiving a resource request from a user, obtaining a sub-resource element corresponding to the resource request in the server;

[0008] Based on the sub-resource element, obtaining a first attribute value and a second attribute value of the sub-resource element;

[0009] Parsing the first attribute value to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be acquired;

[0010] Based on the second attribute value and the preset first port, asynchronously obtain the target data resource corresponding to the resource request stored in a preset content delivery network CDN node;

[0011] Applying the encryption algorithm to calculate a second target hash value of the target data resource;

[0012] Determine whether the first target hash value is consistent with the second target hash value;

[0013] If the first target hash value is consistent with the second target hash value, the target data resource is fed back to the user.

[0014] The above method may optionally further include:

[0015] Obtaining the currently uploaded initial data resource and resource information of the initial data resource;

[0016] The initial data resource and the resource information are sent to the server, so that the server applies the encryption algorithm to calculate the initial hash value corresponding to the initial data resource, and based on the storage address corresponding to the initial data resource contained in the resource information, stores the initial data resource to the CDN node corresponding to the storage address; the server sets the initial hash value and the encryption algorithm as the first attribute value of the initial data resource, and sets the storage address as the second attribute value of the initial data resource.

[0017] In the above method, optionally, obtaining the first attribute value and the second attribute value of the sub-resource element based on the sub-resource element includes:

[0018] Determine a preset second port, and start a selector corresponding to the second port;

[0019] Applying the selector to query pre-stored resource information matching the sub-resource element;

[0020] Based on the resource information, a first attribute value and a second attribute value of the sub-resource element are acquired.

[0021] In the above method, optionally, the step of asynchronously acquiring the target data resource corresponding to the resource request stored in the CDN node in the server based on the second attribute value and the preset first port includes:

[0022] Based on the second attribute value, determining a target storage address corresponding to the target data resource to be acquired;

[0023] Connecting to a CDN node corresponding to the target storage address through the preset first port, generating a resource acquisition request corresponding to the resource request, and sending the resource acquisition request to the CDN node through the preset first port;

[0024] When receiving the response information fed back by the CDN node, calling a preset response statement to obtain the array buffer contained in the response information;

[0025] The target data resource corresponding to the resource request is obtained from the array buffer.

[0026] In the above method, optionally, the determining whether the first target hash value is consistent with the second target hash value includes:

[0027] Perform Base64 encoding on the first target hash value and the second target hash value to obtain a first ASCII character string corresponding to the first target hash value and a second ASCII character string corresponding to the second target hash value;

[0028] Determine whether the first ASCII character string is consistent with the second ASCII character string.

[0029] A resource verification device, comprising:

[0030] A first acquisition unit, configured to, when receiving a resource request from a user, acquire a sub-resource element corresponding to the resource request in the server;

[0031] A second acquiring unit, configured to acquire a first attribute value and a second attribute value of the sub-resource element based on the sub-resource element;

[0032] A parsing unit, configured to parse the first attribute value to obtain the encryption algorithm applied by the server and a first target hash value of the target data resource to be acquired;

[0033] A third acquisition unit, configured to asynchronously acquire a target data resource corresponding to the resource request stored in a preset content delivery network CDN node based on the second attribute value and a preset first port;

[0034] A calculation unit, configured to apply the encryption algorithm to calculate a second target hash value of the target data resource;

[0035] A judging unit, configured to judge whether the first target hash value is consistent with the second target hash value;

[0036] A feedback unit is configured to feed back the target data resource to the user if the first target hash value is consistent with the second target hash value.

[0037] The above device may optionally further include:

[0038] A fourth acquisition unit, used to acquire the currently uploaded initial data resource and resource information of the initial data resource;

[0039] A sending unit, used to send the initial data resource and the resource information to the server, so that the server applies the encryption algorithm to calculate the initial hash value corresponding to the initial data resource, and based on the storage address corresponding to the initial data resource contained in the resource information, stores the initial data resource to the CDN node corresponding to the storage address; the server sets the initial hash value and the encryption algorithm as the first attribute value of the initial data resource, and sets the storage address as the second attribute value of the initial data resource.

[0040] In the above device, optionally, the second acquisition unit includes:

[0041] An activation subunit, used for determining a preset second port and activating a selector corresponding to the second port;

[0042] A query subunit, used to apply the selector to query pre-stored resource information matching the sub-resource element;

[0043] The first acquisition subunit is used to acquire the first attribute value and the second attribute value of the sub-resource element based on the resource information.

[0044] In the above device, optionally, the third acquisition unit includes:

[0045] a determination subunit, configured to determine, based on the second attribute value, a target storage address corresponding to the target data resource to be acquired;

[0046] a connecting subunit, configured to connect to a CDN node corresponding to the target storage address through the preset first port, generate a resource acquisition request corresponding to the resource request, and send the resource acquisition request to the CDN node through the preset first port;

[0047] A second acquisition subunit is used to call a preset response statement when receiving the response information fed back by the CDN node, and acquire the array buffer contained in the response information;

[0048] The third acquisition subunit is used to acquire the target data resource corresponding to the resource request from the array buffer.

[0049] In the above device, optionally, the judging unit includes:

[0050] an encoding subunit, configured to perform Base64 encoding on the first target hash value and the second target hash value to obtain a first ASCII character string corresponding to the first target hash value and a second ASCII character string corresponding to the second target hash value;

[0051] The judging subunit is used to judge whether the first ASCII character string is consistent with the second ASCII character string.

[0052] A storage medium includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned resource verification method.

[0053] An electronic device comprises a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform the above-mentioned resource verification method.

[0054] Compared with the prior art, the present invention has the following advantages:

[0055] The present invention provides a resource verification method, including: when receiving a resource request from a user, obtaining a sub-resource element corresponding to the resource request in a server; based on the sub-resource element, obtaining a first attribute value and a second attribute value of the sub-resource element; parsing the first attribute value to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be obtained; based on the second attribute value and a preset first port, asynchronously obtaining the target data resource corresponding to the resource request stored in a preset content distribution network CDN node; applying the encryption algorithm to calculate the second target hash value of the target data resource; determining whether the first target hash value is consistent with the second target hash value; if the first target hash value is consistent with the second target hash value, then feeding back the target data resource to the user. By applying the method provided by the present invention, the data resources to be fed back can be verified to avoid resource loading errors or malicious data resources. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0057] Figure 1 A method flow chart of a resource verification method provided by an embodiment of the present invention;

[0058] Figure 2 A method flow chart of another method of a resource verification method provided by an embodiment of the present invention;

[0059] Figure 3 A flowchart of another method of a resource verification method provided by an embodiment of the present invention;

[0060] Figure 4 A device structure diagram of a resource verification device provided by an embodiment of the present invention;

[0061] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0062] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0063] In this application, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. The terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, the elements defined by the sentence "comprise one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0064] The present invention can be used in many general or special computing device environments or configurations, such as personal computers, server computers, handheld or portable devices, tablet devices, multi-processor devices, distributed computing environments including any of the above devices or devices, etc.

[0065] The embodiment of the present invention provides a resource verification method, which can be applied to a variety of system platforms, and its execution subject can be a processor of a computer terminal or various mobile devices. The method flow chart of the method is as follows: Figure 1 As shown, specifically including:

[0066] S101: When receiving a resource request from a user, obtaining a sub-resource element corresponding to the resource request in a server.

[0067] In the present invention, when a user needs to access a data source such as a picture, audio or video, a resource request corresponding to the resource is sent, and the corresponding sub-resource element is obtained according to the resource request.

[0068] The sub-resource element is related to the resource type of the target data resource to be acquired. The corresponding resource labels of data resources of each resource type are different. For example, the label corresponding to the image resource is , the audio resource is tagged with <audio>, the video resource is tagged as <video>When the target data resource to be obtained is a picture, the sub-resource element is element.

[0069] Specifically, the resource request is forwarded to the server, and the server returns the sub-resource element in response to the request.

[0070] S102: Based on the sub-resource element, obtain a first attribute value and a second attribute value of the sub-resource element.

[0071] It should be noted that, specifically, the resource element with a specified data-integrity attribute value is obtained through the querySelector() method provided by the document object model Document, and the resource element may be a picture element, an audio element or a video element.

[0072] The first attribute value and the second attribute value are custom data attributes of the resource, specifically data-integrity and data-src attribute values, respectively.

[0073] S103: Parse the first attribute value to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be acquired.

[0074] It should be noted that the first attribute value includes an encryption algorithm and a first target hash value of the target data resource to be obtained.

[0075] Specifically, the first attribute value is divided into two parts. The first part specifies the hash value generation algorithm (SHA-256, SHA-384, and SHA-512), and the second part is the Base64-encoded file hash value. The two are separated by a hyphen (-). By calling the string's split('-') method, you can get the hash algorithm and the Base64-encoded file hash value. The hash algorithm is actually the encryption algorithm obtained by parsing the first attribute value.

[0076] S104: Based on the second attribute value and the preset first port, asynchronously obtain the target data resource corresponding to the resource request stored in a preset content delivery network CDN node.

[0077] It should be noted that the CDN system includes multiple CDN nodes, each of which is used to store data resources. The resource request includes the URL address of the data resource to be obtained, connects to the CDN node corresponding to the URL address, and obtains the target data resource stored in the node.

[0078] Specifically, the first port is a fetch API, which is used to asynchronously obtain target data resources according to a src value.

[0079] Optionally, if the acquisition fails, a network error is thrown. Otherwise, if the target data resource is successfully acquired, the fetchAPI returns a promise value containing a Response object. By calling the Response.arrayBuffer() method, you can get the response body represented by the ArrayBuffer object. ArrayBuffer is a byte array used to represent a general, fixed-length raw binary data buffer.

[0080] S105: Apply the encryption algorithm to calculate a second target hash value of the target data resource.

[0081] It is understandable that in order to prevent the acquired target data resource from being tampered with during the transmission process, the acquired target data resource needs to be verified again. The second target hash value is obtained by calculating the target data resource again.

[0082] S106: Determine whether the first target hash value is consistent with the second target hash value.

[0083] It is understandable that it is verified whether the target data resource has been tampered with. If yes, S107 is executed, otherwise, an error is returned.

[0084] S107: If the first target hash value is consistent with the second target hash value, feeding back the target data resource to the user.

[0085] In the method provided by the embodiment of the present invention, when a user needs to obtain a resource, a resource request is sent. After receiving the resource request, the browser obtains the sub-resource element corresponding to the resource request in the server. The resource request contains the storage address of the target data resource to be obtained, and the storage address is a URL address. The first attribute value and the second attribute value of the target data resource to be obtained are obtained based on the sub-resource element. The first attribute value is composed of an encryption algorithm and a hash value. The first attribute value is parsed to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be obtained. The first target hash value is the real hash value of the target data resource to be obtained. The target data resource is obtained through the second attribute value and the preset port. The encryption algorithm is applied to calculate the second target hash value of the target data resource, and it is determined whether the two hash values ​​are consistent. If they are consistent, it indicates that the target data resource has not been attacked or tampered with during the transmission process.

[0086] By applying the method provided in the embodiment of the present invention, data resources to be fed back can be verified to avoid resource loading errors or malicious data resources.

[0087] refer to Figure 2 In the method provided in the embodiment of the present invention, the CDN node is used to store data resources. The backend technicians can upload data resources to the CDN node according to the requirements. Therefore, before receiving the resource request, the first attribute value and the second attribute value of the data resource need to be set in advance, so as to perform the above-mentioned process of S101 to S107 after receiving the resource request to realize the verification of the data resource. The specific process of setting the first attribute value and the second attribute value of the data resource includes:

[0088] S201: The browser obtains the initial data resource currently being uploaded and resource information of the initial data resource.

[0089] The resource information includes a storage address.

[0090] It is understandable that when any data resource needs to be stored in any CDN node of the CDN system, the user uploads the data resource to the browser, and the browser obtains the data resource uploaded by the user to be stored in the CDN node and uses the data resource as the initial data resource.

[0091] S202: The browser sends the initial data resource and the resource information to the server.

[0092] S203: The server applies the encryption algorithm to calculate the initial hash value corresponding to the initial data resource, and based on the storage address corresponding to the initial data resource included in the resource information, stores the initial data resource to the CDN node corresponding to the storage address.

[0093] It should be noted that the initial hash value is the first target hash value sent by the server according to the resource request when the user makes a resource request.

[0094] S204: The server sets the initial hash value and the encryption algorithm as the first attribute value of the initial data resource, and sets the storage address as the second attribute value of the initial data resource.

[0095] It should be noted that the first attribute value is the custom attribute data-integrity in the data resource tag, and the value of this attribute is the file summary sent by the server; the second attribute value is the custom attribute data-src in the data resource tag, and the value of this attribute is the URL address of the image. The integrity attribute value is divided into two parts. The first part specifies the hash value generation algorithm (SHA-256, SHA-384, and SHA-512), and the second part is the Base64-encoded file hash value. The two are separated by a hyphen (-). The hash algorithm and the Base64-encoded file hash value can be obtained by calling the split('-') method of the string.

[0096] In the method provided by the embodiment of the present invention, openssl is used on a Linux server to generate a Base64-encoded hash value for a multimedia resource file. The tag adds data-src and data-integrity attribute values ​​through HTML custom data attributes (data-*). After loading the web page, the user obtains the data resource by sending a resource request.

[0097] Specifically, the browser obtains the uploaded initial data resource and the resource information of the initial data resource, and sends the initial data resource and the resource information of the initial data resource to the server. The server applies the encryption algorithm currently supported by it to calculate the initial hash value of the initial data resource, and sets the initial hash value and the encryption algorithm as the first attribute value. The server obtains the storage address from the resource information, and stores the initial data resource to the CDN node corresponding to the storage address, and sets the storage address as the first attribute value. When a resource request corresponding to the initial data resource is subsequently received, the above-mentioned process from S101 to S107 is executed.

[0098] In the method provided in the embodiment of the present invention, obtaining the first attribute value and the second attribute value corresponding to the resource request based on the resource element includes:

[0099] Determine a preset second port, and start a selector corresponding to the second port;

[0100] Applying the selector to query pre-stored resource information matching the sub-resource element;

[0101] Based on the resource information, a first attribute value and a second attribute value of the sub-resource element are acquired.

[0102] Specifically, the second port is HTMLElement, and the src and integrity values ​​in the resource element are obtained through the dataset attribute defined by the HTMLElement port.

[0103] It should be noted that the resource element is a component of the data resource to be acquired.

[0104] refer to Figure 3 In an embodiment of the present invention, the step of asynchronously acquiring the target data resource corresponding to the resource request stored in the CDN node in the server based on the second attribute value and the preset first port includes:

[0105] S301: Determine a target storage address corresponding to the target data resource to be acquired based on the second attribute value.

[0106] The second attribute value is composed of a storage address.

[0107] S302: Connecting to a CDN node corresponding to the target storage address through the preset first port, generating a resource acquisition request corresponding to the resource request, and sending the resource acquisition request to the CDN node through the preset first port.

[0108] In the embodiment of the present invention, the resource acquisition request is a resource request that complies with the request format supported by the CDN node. That is, the resource request is format-converted according to the request format supported by the CDN node to obtain the resource acquisition request.

[0109] It should be noted that the preset first port is the fetch API interface.

[0110] S303: When the response information fed back by the CDN node is received, a preset response statement is called to obtain the array buffer contained in the response information.

[0111] It is understandable that after receiving the resource acquisition request, the CDN node parses the resource acquisition request to obtain the second attribute value, and queries the data resource matching the second attribute value. The CDN node feeds back the response information carrying the target data resource through the connection interface. The array buffer in the response information is ArrayBuffer.

[0112] S304: Acquire the target data resource corresponding to the resource request from the array buffer.

[0113] In the embodiment of the present invention, when the image resource is successfully obtained, the fetch API returns a promise value containing a Response object. By calling the Response.arrayBuffer() method, the response body represented by the ArrayBuffer object can be obtained. ArrayBuffer is a byte array used to represent a general, fixed-length raw binary data buffer.

[0114] Specifically, after obtaining the target data resource, it is necessary to calculate the second target hash value of the target data resource and determine whether the first target hash value is consistent with the second target hash value. The determination process is actually a comparison between two ASCII strings, specifically:

[0115] Perform Base64 encoding on the first target hash value and the second target hash value to obtain a first ASCII character string corresponding to the first target hash value and a second ASCII character string corresponding to the second target hash value;

[0116] Determine whether the first ASCII character string is consistent with the second ASCII character string.

[0117] By comparing the two ASCII strings to see if they are consistent, it is determined whether the target data resource has been attacked or tampered with. If so, a target data resource error is thrown to the user. Otherwise, the target data resource is fed back to the user normally.

[0118] Specifically, if the two ASCII strings are the same, the URL.createObjectURL method is used or the src attribute value of the target data resource is directly set to normally feed back the data resource to the user.

[0119] By applying the method provided in the embodiment of the present invention, data resources to be fed back can be verified to avoid resource loading errors or malicious data resources.

[0120] The specific implementation processes and derivative methods of the above-mentioned embodiments are all within the protection scope of the present invention.

[0121] and Figure 1 Corresponding to the method described above, the embodiment of the present invention further provides a resource verification device for Figure 1 In the specific implementation of the method, the resource verification device provided in the embodiment of the present invention can be applied to a computer terminal or various mobile devices, and its structural diagram is as follows Figure 4 As shown, specifically including:

[0122] The first acquisition unit 401 is used to acquire the sub-resource element corresponding to the resource request in the server when receiving a resource request from the user;

[0123] A second acquiring unit 402, configured to acquire a first attribute value and a second attribute value of the sub-resource element based on the sub-resource element;

[0124] A parsing unit 403 is used to parse the first attribute value to obtain the encryption algorithm applied by the server and a first target hash value of the target data resource to be acquired;

[0125] A third acquisition unit 404 is configured to asynchronously acquire a target data resource corresponding to the resource request stored in a preset content delivery network CDN node based on the second attribute value and the preset first port;

[0126] A calculation unit 405 is used to apply the encryption algorithm to calculate a second target hash value of the target data resource;

[0127] A judging unit 406 is configured to judge whether the first target hash value is consistent with the second target hash value;

[0128] The feedback unit 407 is configured to feed back the target data resource to the user if the first target hash value is consistent with the second target hash value.

[0129] In the device provided by the embodiment of the present invention, when the user needs to obtain resources, a resource request is sent. After receiving the resource request, the browser obtains the sub-resource element corresponding to the resource request in the server. The resource request contains the storage address of the target data resource to be obtained, and the storage address is a URL address. The first attribute value and the second attribute value of the target data resource to be obtained are obtained based on the sub-resource element. The first attribute value is composed of an encryption algorithm and a hash value. The first attribute value is parsed to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be obtained. The first target hash value is the real hash value of the target data resource to be obtained. The target data resource is obtained through the second attribute value and the preset first port. The encryption algorithm is applied to calculate the second target hash value of the target data resource, and it is determined whether the two hash values ​​are consistent. If they are consistent, it indicates that the target data resource has not been attacked or tampered with during the transmission process.

[0130] By using the device provided by the embodiment of the present invention, data resources to be fed back can be verified to avoid resource loading errors or malicious data resources.

[0131] The device provided in the embodiment of the present invention further includes:

[0132] A fourth acquisition unit, used to acquire the currently uploaded initial data resource and resource information of the initial data resource;

[0133] A sending unit, used to send the initial data resource and the resource information to the server, so that the server applies the encryption algorithm to calculate the initial hash value corresponding to the initial data resource, and based on the storage address corresponding to the initial data resource contained in the resource information, stores the initial data resource to the CDN node corresponding to the storage address; the server sets the initial hash value and the encryption algorithm as the first attribute value of the initial data resource, and sets the storage address as the second attribute value of the initial data resource.

[0134] In the device provided by the embodiment of the present invention, the second obtaining unit 402 includes:

[0135] An activation subunit, used for determining a preset second port and activating a selector corresponding to the second port;

[0136] A query subunit, used to apply the selector to query pre-stored resource information matching the sub-resource element;

[0137] The first acquisition subunit is used to acquire the first attribute value and the second attribute value of the sub-resource element based on the resource information.

[0138] In the device provided by the embodiment of the present invention, the third obtaining unit 405 includes:

[0139] a determination subunit, configured to determine, based on the second attribute value, a target storage address corresponding to the target data resource to be acquired;

[0140] a connecting subunit, configured to connect to a CDN node corresponding to the target storage address through the preset first port, generate a resource acquisition request corresponding to the resource request, and send the resource acquisition request to the CDN node through the preset first port;

[0141] A second acquisition subunit is used to call a preset response statement when receiving the response information fed back by the CDN node, and acquire the array buffer contained in the response information;

[0142] The third acquisition subunit is used to acquire the target data resource corresponding to the resource request from the array buffer.

[0143] In the device provided by the embodiment of the present invention, the determining unit 406 includes:

[0144] an encoding subunit, configured to perform Base64 encoding on the first target hash value and the second target hash value to obtain a first ASCII character string corresponding to the first target hash value and a second ASCII character string corresponding to the second target hash value;

[0145] The judging subunit is used to judge whether the first ASCII character string is consistent with the second ASCII character string.

[0146] The specific working process of each unit and sub-unit in the resource verification device disclosed in the above embodiment of the present invention can refer to the corresponding content in the resource verification method disclosed in the above embodiment of the present invention, and will not be repeated here.

[0147] An embodiment of the present invention further provides a storage medium, which includes stored instructions, wherein when the instructions are executed, the device where the storage medium is located is controlled to execute the above-mentioned resource verification method.

[0148] The embodiment of the present invention further provides an electronic device, the structural diagram of which is shown in FIG. Figure 5 As shown, it specifically includes a memory 501 and one or more instructions 502, wherein the one or more instructions 502 are stored in the memory 501 and are configured to be executed by one or more processors 503 to perform the following operations:

[0149] When receiving a resource request from a user, obtaining a sub-resource element corresponding to the resource request in the server;

[0150] Based on the sub-resource element, obtaining a first attribute value and a second attribute value of the sub-resource element;

[0151] Parsing the first attribute value to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be acquired;

[0152] Based on the second attribute value and the preset first port, asynchronously obtain the target data resource corresponding to the resource request stored in a preset content delivery network CDN node;

[0153] Applying the encryption algorithm to calculate a second target hash value of the target data resource;

[0154] Determine whether the first target hash value is consistent with the second target hash value;

[0155] If the first target hash value is consistent with the second target hash value, the target data resource is fed back to the user.

[0156] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0157] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein may be implemented by electronic hardware, computer software, or a combination of both.

[0158] In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the present invention.

[0159] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.< / video> < / audio>

Claims

1. A resource verification method, characterized in that: include: Obtaining the currently uploaded initial data resource and resource information of the initial data resource; Sending the initial data resource and the resource information to a server, so that the server applies an encryption algorithm to calculate an initial hash value corresponding to the initial data resource, and based on a storage address corresponding to the initial data resource included in the resource information, storing the initial data resource in a CDN node corresponding to the storage address; The server sets the initial hash value and the encryption algorithm as the first attribute value of the initial data resource, and sets the storage address as the second attribute value of the initial data resource; When receiving a resource request from a user, obtaining a sub-resource element corresponding to the resource request in the server; Based on the sub-resource element, obtaining a first attribute value and a second attribute value of the sub-resource element; Parsing the first attribute value to obtain the encryption algorithm applied by the server and the first target hash value of the target data resource to be acquired; The first target hash value is a real hash value of the target data resource to be acquired; Based on the second attribute value, determining a target storage address corresponding to the target data resource to be acquired; Connecting to a CDN node corresponding to the target storage address through a preset first port, generating a resource acquisition request corresponding to the resource request, and sending the resource acquisition request to the CDN node through the preset first port; When receiving the response information fed back by the CDN node, calling a preset response statement to obtain the array buffer contained in the response information; Acquire the target data resource corresponding to the resource request from the array buffer; Applying the encryption algorithm to calculate a second target hash value of the target data resource; Determine whether the first target hash value is consistent with the second target hash value; If the first target hash value is consistent with the second target hash value, it is determined that the target data resource stored in the CDN node has not been attacked or tampered with, and the target data resource is fed back to the user.

2. The method according to claim 1, characterized in that The acquiring, based on the sub-resource element, the first attribute value and the second attribute value of the sub-resource element comprises: Determine a preset second port, and start a selector corresponding to the second port; Applying the selector to query pre-stored resource information matching the sub-resource element; Based on the resource information, a first attribute value and a second attribute value of the sub-resource element are acquired.

3. The method according to claim 1, characterized in that The determining whether the first target Hash value is consistent with the second target Hash value includes: Perform Base64 encoding on the first target hash value and the second target hash value to obtain a first ASCII character string corresponding to the first target hash value and a second ASCII character string corresponding to the second target hash value; Determine whether the first ASCII character string is consistent with the second ASCII character string.

4. A resource verification device, characterized in that: include: A fourth acquisition unit, used to acquire the currently uploaded initial data resource and resource information of the initial data resource; a sending unit, configured to send the initial data resource and the resource information to a server, so that the server applies an encryption algorithm to calculate an initial hash value corresponding to the initial data resource, and based on a storage address corresponding to the initial data resource included in the resource information, stores the initial data resource in a CDN node corresponding to the storage address; The server sets the initial hash value and the encryption algorithm as the first attribute value of the initial data resource, and sets the storage address as the second attribute value of the initial data resource; A first acquisition unit, configured to, when receiving a resource request from a user, acquire a sub-resource element corresponding to the resource request in the server; A second acquiring unit, configured to acquire a first attribute value and a second attribute value of the sub-resource element based on the sub-resource element; A parsing unit, configured to parse the first attribute value to obtain the encryption algorithm applied by the server and a first target hash value of the target data resource to be acquired; The first target hash value is a real hash value of the target data resource to be acquired; A third acquisition unit, comprising: a determination subunit, a connection subunit, a second acquisition subunit and a third acquisition subunit; The determining subunit is used to determine the target storage address corresponding to the target data resource to be acquired based on the second attribute value; The connecting subunit is configured to connect to the CDN node corresponding to the target storage address through a preset first port, generate a resource acquisition request corresponding to the resource request, and send the resource acquisition request to the CDN node through the preset first port; The second acquisition subunit is configured to, when receiving the response information fed back by the CDN node, call a preset response statement to acquire the array buffer contained in the response information; A third acquisition subunit, configured to acquire the target data resource corresponding to the resource request from the array buffer; A calculation unit, configured to apply the encryption algorithm to calculate a second target hash value of the target data resource; A judging unit, configured to judge whether the first target hash value is consistent with the second target hash value; A feedback unit is configured to, if the first target hash value is consistent with the second target hash value, determine that the target data resource stored in the CDN node has not been attacked or tampered with, and then feed back the target data resource to the user.

5. The device according to claim 4, characterized in that The second acquisition unit includes: A starter unit, used for determining a preset second port and starting a selector corresponding to the second port; A query subunit, used to apply the selector to query pre-stored resource information matching the sub-resource element; The first acquisition subunit is used to acquire the first attribute value and the second attribute value of the sub-resource element based on the resource information.

6. The device according to claim 4, characterized in that The judging unit comprises: an encoding subunit, configured to perform Base64 encoding on the first target hash value and the second target hash value to obtain a first ASCII character string corresponding to the first target hash value and a second ASCII character string corresponding to the second target hash value; The judging subunit is used to judge whether the first ASCII character string is consistent with the second ASCII character string.

Citation Information

Patent Citations

  • A method and a terminal for detecting correctness of resource files

    CN109934014A