Communication connection adaptive adjustment method and device, electronic equipment and system
By dynamically acquiring certificates and employing a multi-level verification system, the communication connection strategy is adaptively adjusted, solving the security and reliability issues of HTTPS connections and enabling secure and reliable communication in scenarios such as enterprise intranets and private clouds.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-14
- Publication Date
- 2026-04-14
Smart Images

Figure CN121864852A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer network technology, and in particular to a method, apparatus, electronic device, and system for adaptive adjustment of communication connections. Background Technology
[0002] In current technological practices, HTTPS (Hypertext Transfer Protocol Secure) has become the preferred solution for ensuring communication security compared to HTTP (Hypertext Transfer Protocol) due to its encrypted transmission and authentication mechanisms.
[0003] In existing technologies, when a client establishes an HTTPS connection with a server, a fixed certificate verification strategy is typically employed: one approach is to skip certificate verification and directly trust all certificates; the other is to strictly verify certificates and only trust pre-installed CA (Certificate Authority) certificates. However, both of these certificate verification strategies have significant drawbacks: the former exposes communication to the risk of man-in-the-middle attacks, rendering the HTTPS connection insecure; while the latter fails to establish a connection when using self-signed certificates or private CA certificates. Furthermore, existing technologies cannot dynamically adjust connection strategies in the event of network connectivity anomalies, resulting in low connection reliability and potential disruptions to the user's network usage.
[0004] Therefore, it is particularly important to propose a technical solution that can adaptively adjust the communication connection strategy, improve the flexibility and reliability of the communication connection selection between the client and the server, and thus ensure the availability and continuity of communication services. Summary of the Invention
[0005] This invention provides a method, apparatus, electronic device, and system for adaptive adjustment of communication connections, which can adaptively adjust communication connection strategies, improve the flexibility and reliability of communication connection selection between clients and servers, and thus ensure the availability and continuity of communication services.
[0006] To address the aforementioned technical problems, the first aspect of this invention discloses a communication connection adaptive adjustment method. This method is applied to an electronic device with an installed application, the electronic device being communicatively connected to a network-attached storage device (NAT), and the electronic device being able to access the NAT via the application. The method includes: Determine whether the server address received by the application meets the preset communication protocol switching conditions; When it is determined that the server address meets the communication protocol switching conditions, based on a pre-set certificate dynamic acquisition strategy, an information acquisition operation for the server address is performed to obtain an information acquisition result; the information acquisition result includes the operation execution result corresponding to the information acquisition operation; when the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result also includes server certificate information; Based on a pre-built multi-level certificate verification system, a certificate verification operation is performed on the server certificate information to obtain a certificate verification result; wherein, both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with an intelligent retry mechanism. Based on the information acquisition result and / or the certificate verification result, a first target communication protocol that can be used for the server address is determined; the first target communication protocol includes HTTP protocol or HTTPS protocol. Based on the first target communication protocol, a dynamic communication connection is established between the application and the server corresponding to the server address.
[0007] As an optional implementation, in the first aspect of the present invention, determining whether the server address received by the application meets the preset communication protocol switching conditions includes: Based on the regular expression matching algorithm, it is determined whether the address format of the server address matches the IP address format; When it is determined that the address format of the server address matches the IP address format, it is determined that the server address meets the pre-set communication protocol switching conditions; When it is determined that the address format of the server address does not match the IP address format, it is determined that the server address does not meet the pre-set communication protocol switching conditions.
[0008] As an optional implementation, in the first aspect of the present invention, the method further includes: When it is determined that the server address does not meet the communication protocol switching conditions, the second target communication protocol corresponding to the server address is determined to be the HTTP protocol; Based on the second target communication protocol, a static communication connection is established between the application and the server corresponding to the server address.
[0009] As an optional implementation, in the first aspect of the present invention, the step of performing the information acquisition operation of the server address based on a pre-set certificate dynamic acquisition strategy to obtain the information acquisition result includes: Based on the HTTP interface, send an HTTP request to the server corresponding to the server address; The system detects whether an HTTP response corresponding to the HTTP request has been received from the server, and obtains a first response detection result; wherein, the HTTP response includes a first response header and a second response header; the first response header is used to record the encoding certificate information corresponding to the server; the second response header is used to record the HTTPS service port number corresponding to the server; When the first response detection result is used to indicate that an HTTP response corresponding to the HTTP request has been received from the server, the operation execution result is determined to indicate that the operation was successfully executed, and the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number corresponding to the server. The server certificate information is the encoded certificate information; and the information acquisition result also includes the HTTPS service port number.
[0010] As an optional implementation, in the first aspect of the present invention, the step of performing a certificate verification operation on the server certificate information based on a pre-built multi-level certificate verification system to obtain a certificate verification result includes: Construct a local certificate trust system corresponding to the server certificate information; the local certificate trust system includes at least the trusted root certificate corresponding to the server certificate information and the local trust manager corresponding to the trusted root certificate. Based on a pre-defined standard root certificate library, a standard certificate verification operation is performed on the trusted root certificate to obtain a standard verification result. When the standard verification result is used to indicate verification failure, a custom verification operation is performed on the trusted root certificate based on the local trust manager to obtain a custom verification result; When the custom verification result is used to indicate verification failure, the intelligent retry mechanism corresponding to the multi-level certificate verification system is activated to obtain the retry verification result; When the retest verification result is used to indicate verification failure, the certificate verification result is determined to be certificate verification failure; When one of the standard verification result, the custom verification result, and the retest verification result is used to indicate successful verification, the certificate verification result is determined to be successful.
[0011] As an optional implementation, in the first aspect of the present invention, constructing the local certificate trust system corresponding to the server certificate information includes: Decode the server certificate information to obtain decoded certificate information; Parse the decoded certificate information to obtain the standard certificate object corresponding to the server certificate information; Create a local certificate trust store and store the standard certificate object as a trusted root certificate in the local certificate trust store; A local trust manager is generated based on the local certificate trust library.
[0012] As an optional implementation, in a first aspect of the invention, determining the first target communication protocol usable for the server address based on the information acquisition result and / or the certificate verification result includes: When the operation execution result of the information acquisition result is used to indicate that the operation was successfully executed and the certificate verification result is used to indicate that the certificate verification was successful, an HTTPS connection test is performed on the server address according to the information acquisition result to obtain the connection test result; When the connection test result indicates that the HTTPS connection corresponding to the server address is available, the first target communication protocol that can be used for the server address is determined to be the HTTPS protocol. When the operation execution result of the information acquisition result is used to indicate that the operation execution failed, or the certificate verification result is used to indicate that the certificate verification failed, or the connection test result is used to indicate that the HTTPS connection corresponding to the server address is unavailable, the first target communication protocol that can be used for the server address is determined to be the HTTP protocol.
[0013] A second aspect of the present invention discloses a communication connection adaptive adjustment device, which is applied to an electronic device with an application installed, the electronic device being communicatively connected to a network-attached storage device, and the electronic device being able to access the network-attached storage device through the application; wherein, the device comprises: The judgment module is used to determine whether the server address received by the application meets the preset communication protocol switching conditions; The certificate acquisition module is used to perform an information acquisition operation on the server address based on a pre-set certificate dynamic acquisition strategy when the judgment module determines that the server address meets the communication protocol switching conditions, and obtain an information acquisition result; the information acquisition result includes the operation execution result corresponding to the information acquisition operation; when the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result also includes server certificate information; The certificate verification module is used to perform certificate verification operations on the server certificate information based on a pre-built multi-level certificate verification system to obtain the certificate verification result; wherein, both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with an intelligent retry mechanism; The determining module is configured to determine a first target communication protocol that can be used for the server address based on the information acquisition result and / or the certificate verification result; the first target communication protocol includes HTTP protocol or HTTPS protocol. The connection module is used to establish a dynamic communication connection between the application and the server corresponding to the server address based on the first target communication protocol.
[0014] As an optional implementation, in the second aspect of the present invention, the specific method by which the determining module determines whether the server address received by the application meets the preset communication protocol switching conditions includes: Based on the regular expression matching algorithm, it is determined whether the address format of the server address matches the IP address format; When it is determined that the address format of the server address matches the IP address format, it is determined that the server address meets the pre-set communication protocol switching conditions; When it is determined that the address format of the server address does not match the IP address format, it is determined that the server address does not meet the pre-set communication protocol switching conditions.
[0015] As an optional implementation, in a second aspect of the present invention, the determining module is further configured to determine the second target communication protocol corresponding to the server address as the HTTP protocol when the judging module determines that the server address does not meet the communication protocol switching conditions; The connection module is also used to establish a static communication connection between the application and the server corresponding to the server address based on the second target communication protocol.
[0016] As an optional implementation, in a second aspect of the present invention, the certificate acquisition module performs an information acquisition operation on the server address based on a pre-set dynamic certificate acquisition strategy, and the specific method for obtaining the information acquisition result includes: Based on the HTTP interface, send an HTTP request to the server corresponding to the server address; The system detects whether an HTTP response corresponding to the HTTP request has been received from the server, and obtains a first response detection result; wherein, the HTTP response includes a first response header and a second response header; the first response header is used to record the encoding certificate information corresponding to the server; the second response header is used to record the HTTPS service port number corresponding to the server; When the first response detection result is used to indicate that an HTTP response corresponding to the HTTP request has been received from the server, the operation execution result is determined to indicate that the operation was successfully executed, and the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number corresponding to the server. The server certificate information is the encoded certificate information; and the information acquisition result also includes the HTTPS service port number.
[0017] As an optional implementation, in the second aspect of the present invention, the certificate verification module performs a certificate verification operation on the server certificate information based on a pre-built multi-level certificate verification system to obtain the certificate verification result, including the following specific methods: Construct a local certificate trust system corresponding to the server certificate information; the local certificate trust system includes at least the trusted root certificate corresponding to the server certificate information and the local trust manager corresponding to the trusted root certificate. Based on a pre-defined standard root certificate library, a standard certificate verification operation is performed on the trusted root certificate to obtain a standard verification result. When the standard verification result is used to indicate verification failure, a custom verification operation is performed on the trusted root certificate based on the local trust manager to obtain a custom verification result; When the custom verification result is used to indicate verification failure, the intelligent retry mechanism corresponding to the multi-level certificate verification system is activated to obtain the retry verification result; When the retest verification result is used to indicate verification failure, the certificate verification result is determined to be certificate verification failure; When one of the standard verification result, the custom verification result, and the retest verification result is used to indicate successful verification, the certificate verification result is determined to be successful.
[0018] As an optional implementation, in a second aspect of the present invention, the specific method by which the certificate verification module constructs the local certificate trust system corresponding to the server certificate information includes: Decode the server certificate information to obtain decoded certificate information; Parse the decoded certificate information to obtain the standard certificate object corresponding to the server certificate information; Create a local certificate trust store and store the standard certificate object as a trusted root certificate in the local certificate trust store; A local trust manager is generated based on the local certificate trust library.
[0019] As an optional implementation, in a second aspect of the invention, the determining module determines, based on the information acquisition result and / or the certificate verification result, the specific method of the first target communication protocol that can be used for the server address, including: When the operation execution result of the information acquisition result is used to indicate that the operation was successfully executed and the certificate verification result is used to indicate that the certificate verification was successful, an HTTPS connection test is performed on the server address according to the information acquisition result to obtain the connection test result; When the connection test result indicates that the HTTPS connection corresponding to the server address is available, the first target communication protocol that can be used for the server address is determined to be the HTTPS protocol. When the operation execution result of the information acquisition result is used to indicate that the operation execution failed, or the certificate verification result is used to indicate that the certificate verification failed, or the connection test result is used to indicate that the HTTPS connection corresponding to the server address is unavailable, the first target communication protocol that can be used for the server address is determined to be the HTTP protocol.
[0020] A third aspect of the present invention discloses an electronic device, the electronic device comprising: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute some or all of the steps of the communication connection adaptive adjustment method disclosed in the first aspect of the present invention.
[0021] A fourth aspect of the present invention discloses a communication connection adaptive adjustment system, the system comprising a communication connection adaptive adjustment device as disclosed in the second aspect of the present invention, and a network-attached storage device communicatively connected to the communication connection adaptive adjustment device; wherein the communication connection adaptive adjustment device adaptively adjusts the communication protocol used to establish the communication connection according to the communication connection adaptive adjustment method as disclosed in the first aspect of the present invention. or, The system includes an electronic device as disclosed in the third aspect of the present invention, and a network-attached storage device communicatively connected to the electronic device; wherein the electronic device adaptively adjusts the communication protocol used to establish the communication connection according to the communication connection adaptive adjustment method disclosed in the first aspect of the present invention.
[0022] The fifth aspect of the present invention discloses a computer storage medium storing computer instructions, which, when invoked, are used to execute some or all of the steps of the communication connection adaptive adjustment method disclosed in the first aspect of the present invention.
[0023] Compared with the prior art, the present invention has the following beneficial effects: Implementing this invention enables the application to dynamically acquire server certificate information after determining that the server address received by the application meets the pre-set communication protocol switching conditions. Upon successful acquisition, the application verifies the server certificate information using a multi-level certificate verification system. Based on the certificate acquisition and / or verification results, the invention determines the communication protocol currently usable by the server, establishing a dynamic communication connection between the application and the server corresponding to the server address. This allows for automatic acquisition, verification, and trust of server certificates, enabling adaptive adjustment of communication connection strategies based on actual certificate conditions and network status. It is suitable for various certificate verification scenarios, particularly those using self-signed certificates in enterprise intranets and private clouds. While ensuring communication security, this invention improves the flexibility and reliability of communication connection selection between the client and server, ensuring the availability and continuity of communication services, providing users with secure and reliable network connections, and ultimately enhancing the user experience. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 This is a flowchart illustrating a communication connection adaptive adjustment method disclosed in an embodiment of the present invention; Figure 2 This is a flowchart illustrating another adaptive adjustment method for communication connections disclosed in an embodiment of the present invention; Figure 3 This is a flowchart illustrating another adaptive adjustment method for communication connections disclosed in an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of a communication connection adaptive adjustment device disclosed in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention; Figure 6 This is a schematic diagram of the structure of a communication connection adaptive adjustment system disclosed in an embodiment of the present invention; Figure 7 This is a schematic diagram of another communication connection adaptive adjustment system disclosed in an embodiment of the present invention. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0027] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, product, or end that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or ends.
[0028] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0029] This invention discloses a method, apparatus, electronic device, and system for adaptive adjustment of communication connections. After determining that the server address received by an application meets pre-set communication protocol switching conditions, it attempts to dynamically acquire server certificate information using a dynamic certificate acquisition strategy. Upon successful acquisition, it verifies the server certificate information through a multi-level certificate verification system. Then, based on the certificate acquisition result and / or verification result, it determines the communication protocol currently usable by the server, thereby establishing a dynamic communication connection between the application and the server corresponding to the server address. This allows for automatic acquisition, verification, and trust of server certificates, enabling adaptive adjustment of communication connection strategies based on actual certificate conditions and network status. It is suitable for application scenarios with multiple certificate verification types, especially for communication connection scenarios using self-signed certificates, such as enterprise intranets and private clouds. While ensuring communication security, it improves the flexibility and reliability of communication connection selection between the client and server, thereby ensuring the availability and continuity of communication services, providing users with secure and reliable network connections, and ultimately improving the user experience. Detailed descriptions follow.
[0030] Example 1 Please see Figure 1 , Figure 1 This is a flowchart illustrating a communication connection adaptive adjustment method disclosed in an embodiment of the present invention. Figure 1 The described adaptive adjustment method for communication connections can be applied to a device for adaptive adjustment of communication connections. This device may include one of a smart device, a smart terminal, a smart system, and a server. The server may be a local server or a cloud server; this embodiment of the invention does not limit the application. The method can also be applied to an electronic device with an application installed. The electronic device is communicatively connected to a network-attached storage device (NAT), and the electronic device can access the NAT through the application; this embodiment of the invention does not limit the application. Figure 1 As shown, the adaptive adjustment method for the communication connection may include the following operations: 101. Determine whether the server address received by the application meets the pre-set communication protocol switching conditions.
[0031] In this embodiment of the invention, the application can act as a client and needs to establish a communication connection with the server corresponding to the server address.
[0032] In this embodiment of the invention, the server address can be an address string, which can be understood as a URL (Uniform Resource Locator); optionally, the server address can be the address of any server, for example, the server can be a NAS (Network Attached Storage), or it can be other types of servers, which is not limited in this embodiment of the invention; further optionally, the specific way in which the application receives the server address can be: the application receives the server address entered by the user, which is not limited in this embodiment of the invention.
[0033] In this embodiment of the invention, when step 101 determines that the server address meets the communication protocol switching conditions, that is, when the determination result of step 101 is yes, the operation of step 102 is executed.
[0034] 102. Based on the pre-defined certificate dynamic acquisition strategy, perform the server address information acquisition operation to obtain the information acquisition result.
[0035] In this embodiment of the invention, the information acquisition result may include the operation execution result corresponding to the information acquisition operation; wherein, when the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result may also include server certificate information; further optionally, the server certificate information may include the content of the server's currently valid SSL (Secure Sockets Layer) certificate, such as certificate configuration information.
[0036] In this embodiment of the invention, optionally, when the above operation execution result is used to indicate that the operation execution failed, the operation of step 104 can be executed directly. This embodiment of the invention does not impose any limitations.
[0037] 103. Based on a pre-built multi-level certificate verification system, perform certificate verification operations on the server certificate information to obtain the certificate verification result.
[0038] In this embodiment of the invention, both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with an intelligent retry mechanism. This intelligent retry mechanism automatically re-executes the corresponding operations (i.e., the aforementioned certificate acquisition and verification operations) in the event of network anomalies (e.g., network connection failure), improving operational fault tolerance and thus increasing the success rate of operation execution. For example, in scenarios with abnormal network conditions such as: a user remotely accessing their home NAS via 4G / 5G encountering a brief interruption due to weak signal or base station switching; or, the HTTPS service not being fully ready when the device is first started and requiring a short wait; or, network jitter when switching from mobile network to WiFi; or, use in environments with poor signal such as basements or elevators, this embodiment of the invention can improve the fault tolerance of certificate acquisition and verification operations through the intelligent retry mechanism, thereby enhancing the user experience.
[0039] 104. Based on the information acquisition results and / or certificate verification results, determine the first target communication protocol that can be used for the server address.
[0040] In this embodiment of the invention, the first target communication protocol includes HTTP (HyperText Transfer Protocol) or HTTPS (HyperText Transfer Protocol Secure).
[0041] 105. Based on the first target communication protocol, establish a dynamic communication connection between the application and the server corresponding to the server address.
[0042] In this embodiment of the invention, when the first target communication protocol is HTTP, the dynamic communication connection is an HTTP connection; when the first target communication protocol is HTTPS, the dynamic communication connection is an HTTPS connection.
[0043] As can be seen, the method described in the embodiments of the present invention can, after determining that the server address received by the application meets the pre-set communication protocol switching conditions, attempt to dynamically obtain server certificate information through a dynamic certificate acquisition strategy. After successfully obtaining the server certificate information, it verifies the server certificate information through a multi-level certificate verification system. Then, based on the certificate information acquisition result and / or certificate verification result, it determines the communication protocol that the server can currently use, so as to establish a dynamic communication connection between the application and the server corresponding to the server address. It can automatically obtain, verify, and trust server certificates, thereby adaptively adjusting the communication connection strategy based on the actual certificate situation and the actual network state. It is suitable for application scenarios with multiple types of certificate verification, especially for communication connection scenarios using self-signed certificates, such as enterprise intranets and private clouds. It can improve the flexibility and reliability of the choice of communication connection between the client and the server while ensuring communication security, thereby ensuring the availability and continuity of communication services, providing users with a secure and reliable network connection, and thus improving the user's experience of network connection.
[0044] In an optional embodiment, determining whether the server address received by the application meets the pre-defined communication protocol switching conditions may include the following operations: Based on regular expression matching algorithms, determine whether the address format of the server address matches the IP address format; When it is determined that the server address format matches the IP address format, the server address is deemed to meet the pre-set communication protocol switching conditions. When it is determined that the server address format does not match the IP address format, it is determined that the server address does not meet the pre-set communication protocol switching conditions.
[0045] Optionally, the IP address format may include IPv4 format and / or IPv6 format, which is not limited in this embodiment of the invention.
[0046] Optionally, when the server address is not an IP address, the server address can be a domain name or a local loopback address; this embodiment of the invention does not impose any limitations.
[0047] It is understandable that for IP addresses (e.g., 192.168.1.100), since self-signed certificates are usually used, a dynamic certificate acquisition process needs to be initiated; for domain names (e.g., nas.example.com), a standard CA certificate is usually configured, and the HTTP protocol can be used directly; for local loopback addresses (e.g., 127.0.0.1), in order to avoid unnecessary switching operations on the local debugging environment, there is no need to initiate a dynamic certificate acquisition process.
[0048] For example, in private cloud deployment scenarios, devices typically use self-signed certificates instead of public CA certificates; in enterprise intranet access scenarios, employees access the department's shared storage server via "192.168.10.50" on the company intranet; and in home NAS usage scenarios, home users access their personal NAS devices via "192.168.1.100". Therefore, in the above application scenarios, a dynamic certificate acquisition process needs to be initiated, that is, a process that adaptively adjusts the communication connection. This embodiment of the invention does not limit this process.
[0049] As can be seen, this optional embodiment can determine whether the address format of the server address matches the IP address format based on a regular expression matching algorithm. If the determination result is yes, it is determined that the server address meets the communication protocol switching conditions and the subsequent communication protocol switching process needs to be initiated; otherwise, it is determined that the server address does not meet the communication protocol switching conditions. It can automatically identify the server address type and intelligently determine whether to use a normal HTTP connection or initiate an adaptive switching process to obtain and use an HTTPS secure connection. This improves the accuracy of the adaptive switching process initiation determination while increasing the flexibility of communication connection strategy selection.
[0050] In an optional embodiment, based on a pre-defined certificate dynamic acquisition strategy, the server address information acquisition operation is performed to obtain the information acquisition result, which may include the following operations: Based on the HTTP interface, send an HTTP request to the server corresponding to the server address; The system detects whether an HTTP response corresponding to the HTTP request has been received from the server, thus obtaining a first response detection result. The HTTP response includes a first response header and a second response header. The first response header records the server's corresponding encoded certificate information, and the second response header records the server's corresponding HTTPS service port number. When the first response detection result is used to indicate that the HTTP response returned by the server corresponding to the HTTP request has been received, the operation execution result is determined to indicate that the operation was successfully executed, and the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number of the server. The server certificate information is encoded certificate information; and the information retrieval results also include the HTTPS service port number.
[0051] Regarding the steps of sending an HTTP request, it can be understood that since the application has not yet obtained the information required to establish an HTTPS connection, it needs to use the default, unencrypted HTTP protocol to initiate an initial "handshake" on a known, common port. That is, it obtains the certificate and port necessary to establish an HTTPS secure connection through the HTTP address. Furthermore, by encoding the server's certificate information before transmission, it can be ensured that special characters in the certificate information are not corrupted during transmission, thereby ensuring the integrity of information transmission and improving the reliability of information transmission.
[0052] Optionally, the first response header can be “X-Http-Shake” and the second response header can be “X-Https-port”, but this embodiment of the invention does not impose any limitations.
[0053] Optionally, the server can encode the currently valid SSL certificate information of the server using a preset encoding method to obtain the above-mentioned encoded certificate information; further optionally, the preset encoding method can be a double Base64 encoding method or other encoding methods, which are not limited in this embodiment of the invention.
[0054] One way to establish an HTTPS connection is through the HTTPS service port number.
[0055] For example, through the above-described dynamic certificate acquisition process, the following can be achieved in practical application scenarios: after the enterprise IT department regularly updates the intranet server certificate, the client can automatically adapt without issuing a new version; if the certificate changes after the NAS device firmware is upgraded, the application can automatically obtain the new certificate; when a user needs to manage multiple NAS devices, the application can dynamically adapt to the certificates of each device; and the requirement for all users to update the application version due to certificate changes is avoided. This embodiment of the invention does not impose any limitations.
[0056] As can be seen, this optional embodiment can send an HTTP request to the server corresponding to the server address through the HTTP interface and detect whether the server can return a corresponding HTTP response. If the response can be received, the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number. This enables the dynamic acquisition of the currently valid and encoded transmission server certificate information and HTTPS service port number through HTTP, which can improve the reliability and integrity of the transmission of server communication-related information, thereby improving the reliability of subsequent certificate verification operations.
[0057] In this optional embodiment, the above-mentioned operation of obtaining server address information based on a pre-set certificate dynamic acquisition strategy to obtain the information acquisition result may further include the following operations: When the first response detection result indicates that the HTTP response corresponding to the HTTP request cannot be received from the server, the intelligent retry mechanism corresponding to the dynamic certificate acquisition policy is activated to obtain the retry acquisition result; When the retry result is used to indicate that the HTTP response corresponding to the HTTP request is received from the server after the retry, the above-mentioned determination operation is triggered. The execution result is used to indicate that the operation was successfully executed, and the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number of the server. When the retry result indicates that the HTTP response corresponding to the HTTP request cannot be received from the server, the operation execution result indicates that the operation execution failed, and triggers the above-mentioned operation of determining the first target communication protocol that can be used for the server address based on the information retrieval result and / or certificate verification result.
[0058] It is understandable that when the retry result indicates that the server still cannot receive the HTTP response corresponding to the HTTP request, which contains server certificate information and HTTPS port number, it can be determined that the current network environment does not support the HTTPS protocol. Therefore, communication can be automatically downgraded to HTTP mode to prioritize the availability of communication services.
[0059] Optionally, activating the intelligent retry mechanism corresponding to the dynamic certificate acquisition strategy and obtaining the retry acquisition result may include the following operations: After waiting for the target delay duration, a second HTTP request is sent to the server corresponding to the server address via the HTTP interface; the content of the second HTTP request is the same as the content of the first HTTP request; the target delay duration is the estimated time required for the network state to return to stability; Check whether the server has received an HTTP response corresponding to the second HTTP request, obtain the result of the second first response detection, and use it as the result of the retry.
[0060] Optionally, the target delay duration can be an empirical value; for example, since network fluctuations usually recover within 1-3 seconds, the target delay duration can be 2 seconds. Of course, the target delay duration can also be other values, and this embodiment of the invention does not limit it.
[0061] As can be seen, this optional embodiment can also activate the intelligent retry mechanism corresponding to the dynamic certificate acquisition strategy when the HTTP response returned by the server cannot be received. If the HTTP response is received after the retry, the operation of parsing the HTTP response can continue. If the HTTP response is still not received after the retry, it is determined that the server certificate cannot be obtained, and it is determined that the current environment does not support HTTPS. The system will automatically downgrade to HTTP mode to ensure the availability of communication services. Through the above process, the automatic retry certificate acquisition function can be provided when the network is unstable or the server is temporarily unresponsive. This helps to improve the reliability of the adaptive communication protocol switching strategy and the success rate of server certificate acquisition, thereby improving the success rate of subsequent switching to a more secure HTTPS connection.
[0062] In an optional embodiment, based on a pre-built multi-level certificate verification system, a certificate verification operation is performed on the server certificate information to obtain the certificate verification result, which may include the following operations: Construct a local certificate trust system corresponding to the server certificate information; the local certificate trust system includes at least the trusted root certificate corresponding to the server certificate information and the local trust manager corresponding to the trusted root certificate. Based on a pre-defined standard root certificate store, standard certificate verification operations are performed on trusted root certificates to obtain standard verification results. When the standard verification result is used to indicate verification failure, a custom verification operation is performed on the trusted root certificate based on the local trust manager to obtain a custom verification result; When a custom verification result is used to indicate verification failure, the intelligent retry mechanism corresponding to the multi-level certificate verification system is activated to obtain the retry verification result; When the retest verification result is used to indicate verification failure, the certificate verification result is determined to be certificate verification failure; When one of the standard verification result, custom verification result, and retest verification result is used to indicate successful verification, the certificate verification result is determined to be successful.
[0063] The trusted root certificate corresponding to the server certificate information can be understood as: converting the certificate information provided by the server into a trust credential that the client can recognize.
[0064] Optionally, the standard root certificate store can be a CA root certificate store built into the system. Further optionally, based on the pre-set standard root certificate store, a standard certificate verification operation is performed on the trusted root certificate to obtain a standard verification result. Specifically, based on the CA root certificate store built into the system, the system verifies whether the trusted root certificate is issued by an authoritative organization to obtain a standard verification result. This embodiment of the invention does not limit the scope of the verification.
[0065] For example, by constructing a multi-level certificate verification system, the established communication connection can be adapted to application scenarios that require connecting to different types of servers. For instance, in a hybrid deployment environment where an enterprise mobile office application needs to access both an intranet file server (self-signed) and a cloud email system (CA certificate); or, when a server certificate is being updated and a smooth switch occurs during the coexistence of old and new certificates; or, when managing NAS devices from different vendors with varying certificate policies; or, in industries such as finance and government where strict certificate verification mechanisms are required for security audits (this embodiment of the invention does not limit this); furthermore, it can automatically detect expired certificates and attempt to obtain new certificates, achieving intelligent certificate expiration handling.
[0066] As can be seen, this optional embodiment can construct a local certificate trust system corresponding to the server certificate information. It first performs standard certificate verification on the trusted root certificate corresponding to the server certificate information. If the standard verification fails, it then performs custom verification on the trusted root certificate based on the local trust manager constructed in the local certificate trust system. If the custom verification also fails, it initiates the intelligent retry mechanism corresponding to the multi-level certificate verification system. Only if the retry result still fails is the certificate verification finally determined to have failed. Otherwise, when any one of the standard verification result, custom verification result, and retry verification result indicates successful verification, the certificate verification is determined to be successful. This allows for flexible verification of standard CA certificates and self-signed certificates through a multi-level certificate verification system while establishing a secure trust relationship between the client and the server by constructing a local certificate trust system. It also provides anomaly recovery capabilities through the intelligent retry mechanism, thereby improving the flexibility and reliability of certificate verification and ultimately enhancing the reliability of the certificate verification results.
[0067] In this optional embodiment, optionally, constructing a local certificate trust system corresponding to the server certificate information may include the following operations: Decode the server certificate information to obtain the decoded certificate information; Parse and decode the certificate information to obtain the standard certificate object corresponding to the server certificate information; Create a local certificate trust store and store the standard certificate object as a trusted root certificate in the local certificate trust store; A local trust manager is generated based on the local certificate trust library.
[0068] In this embodiment of the invention, when the server certificate information is an encoded string obtained after double Base64 encoding, it is optional to decode the server certificate information to obtain decoded certificate information. Specifically, the encoded string can be decoded twice to obtain certificate binary data, which is used as decoded certificate information.
[0069] Optionally, parsing and decoding the certificate information to obtain the standard certificate object corresponding to the server certificate information can specifically involve using a certificate factory to parse the decoded certificate information into a standard X.509 certificate object, which is used as the standard certificate object. This embodiment of the invention does not limit the scope of the invention.
[0070] For example, the local certificate trust store can be named KeyStore, but this embodiment of the invention does not limit the name.
[0071] Optionally, generating a local trust manager based on a local certificate trust store can specifically involve generating a local trust manager based on a local certificate trust store through a trust manager factory (TrustManagerFactory). This embodiment of the invention does not impose any limitations on this method.
[0072] For example, in application scenarios such as medical image storage, financial institution internal document management, industrial manufacturing production data collection, and government department internal data, for data security reasons, data is usually not opened to the public network or processed on the internal network. Therefore, server certificates in these scenarios usually use self-signed certificates, and thus it is necessary to build a local certificate trust system to establish a trust relationship between the application and the server.
[0073] As can be seen, this optional embodiment can first decode the server certificate information, then parse the decoded certificate information to obtain a standard certificate object, then store the standard certificate object as a trusted root certificate in the created local certificate trust store, and then generate a local trust manager based on the local certificate trust store. This can convert the certificate provided by the server into a trust credential that the client can recognize, establish a secure trust relationship, and generate a dedicated trust manager, thereby improving the efficiency and reliability of subsequent multi-level certificate verification operations.
[0074] In this optional embodiment, optionally, based on the local trust manager, a custom verification operation is performed on the trusted root certificate to obtain a custom verification result, which may specifically include the following operations: Based on the local trust manager, verify whether the trusted root certificate matches the root certificate entered in the local trust manager; When the trusted root certificate is verified to match the root certificate entered in the local trust manager, the custom verification result is determined to be successful. If the trusted root certificate is found to be inconsistent with the root certificate entered in the local trust manager, the custom verification result is determined to be verification failure.
[0075] It is understandable that when a trusted root certificate expires or is replaced, there will be a mismatch between the trusted root certificate and the root certificate entered in the local trust manager, resulting in verification failure. In this case, it is necessary to use the intelligent retry mechanism corresponding to the multi-level certificate verification system to re-obtain the server certificate information and build a corresponding new local trust manager to establish a new trust relationship between the client and the server, so that the custom verification may succeed.
[0076] As can be seen, this optional embodiment can also verify whether the trusted root certificate matches the root certificate entered by the local trust manager based on the local trust manager. Only when the trusted root certificate matches the root certificate entered by the local trust manager can the custom verification be determined to be successful. This can realize intelligent identification of the risk that the trusted root certificate to be verified is expired or replaced, thereby improving the reliability and efficiency of verification of self-signed certificates.
[0077] In this optional embodiment, optionally, activating the intelligent retry mechanism corresponding to the multi-level certificate verification system to obtain the retry verification result may include the following operations: Check if a retry flag exists; When a retry flag is detected, the retry verification result is used to indicate verification failure. When a retry flag is not found, a retry flag is generated, and the above-mentioned dynamic certificate acquisition strategy based on the pre-set certificate is re-executed to perform the information acquisition operation of the server address and obtain the information acquisition result until the aforementioned standard certificate verification result or custom verification operation is obtained; wherein, during the re-execution process, when the standard verification result or custom verification result is used to indicate successful verification, the retry verification result is determined to indicate successful verification.
[0078] As can be seen, this optional embodiment can also determine whether a retry operation has been performed by using a retry flag. If no retry is performed, the certificate is re-acquired and re-verified. If the re-verification is successful, the certificate verification is successful. If the re-verification fails, it is determined that there is a security risk and automatically downgrades to HTTP mode. Through the certificate refresh and retry mechanism, the certificate information can be automatically re-acquired when the certificate verification fails, which helps to improve the success rate of HTTPS connections.
[0079] In an optional embodiment, determining the first target communication protocol that can be used for the server address based on the information acquisition results and / or certificate verification results may include the following operations: When the operation execution result of the information retrieval result is used to indicate that the operation was successfully executed and the certificate verification result is used to indicate that the certificate verification was successful, an HTTPS connection test is performed on the server address based on the information retrieval result to obtain the connection test result; When the connection test result indicates that an HTTPS connection corresponding to a server address is available, the first target communication protocol that can be used for the server address is determined to be the HTTPS protocol. When the operation execution result of the information retrieval result is used to indicate that the operation execution failed, or the certificate verification result is used to indicate that the certificate verification failed, or the connection test result is used to indicate that the HTTPS connection corresponding to the server address is unavailable, the first target communication protocol that can be used for the server address is determined to be the HTTP protocol.
[0080] In practical communication applications, it is essential to first test the availability of HTTPS connections using the aforementioned HTTPS connection test. Examples include: enterprise firewalls may only open specific ports, requiring verification of HTTPS port accessibility; incomplete port forwarding configurations on home routers necessitate connectivity testing for external network access; enterprise networks accessing the internet via proxies require verification of correct HTTPS forwarding; cloud platform security group rules may restrict ports; and older devices may only support specific SSL / TLS versions. In these scenarios, HTTPS connection testing verifies the usability of HTTPS connections in a real-world environment, preventing situations where correct configurations result in connection failures.
[0081] As can be seen, this optional embodiment can perform an HTTPS connection test based on the information acquisition result after successfully obtaining the server certificate information and verifying the certificate. If the test shows that the HTTPS connection is available, the HTTPS protocol is selected. Otherwise, if the server certificate information cannot be obtained, the certificate verification fails, or the test shows that the HTTPS connection is unavailable, the HTTP protocol is downgraded. This can improve the flexibility and reliability of the communication protocol determination, while also improving the reliability and security of the HTTPS protocol for communication connection, thereby helping to improve the reliability of the communication connection and ensure the availability of the communication service.
[0082] In this optional embodiment, optionally, based on the information acquisition result, performing an HTTPS connection test on the server address to obtain the connection test result may include the following operations: Convert the server address to an HTTPS address; Based on the HTTPS address, an HTTPS request is sent to the heartbeat interface of the aforementioned server; during the process of sending the HTTPS request, the server and the application are forced to complete a full SSL handshake process; this SSL handshake process includes at least certificate verification and key negotiation operations; The system detects whether an HTTPS response corresponding to the HTTPS request has been received from the server, thus obtaining a second response detection result. When the second response detection result is used to indicate that an HTTPS response corresponding to the HTTPS request has been received from the server, the status code in the HTTPS response is parsed and it is determined whether the status code is consistent with the target status code. When it is determined that the status code matches the target status code, the connection test result indicates that the HTTPS connection corresponding to the server address is available. When the second response detection result is used to indicate that the HTTPS response corresponding to the HTTPS request cannot be received from the server, or when it is determined that the status code is inconsistent with the target status code, the connection test result is used to indicate that the HTTPS connection corresponding to the server address is unavailable.
[0083] Optionally, converting the server address to an HTTPS address can specifically involve changing the communication protocol in the original HTTP address corresponding to the server address (i.e., the HTTP address used in the aforementioned "handshake" process) to HTTPS, and replacing the port in the original HTTP address with the HTTPS service port number. This embodiment of the invention does not impose any limitations on this.
[0084] The target status code indicates that the network connection and SSL encrypted channel are accessible and that the server itself is working properly; optionally, the target status code is "200", which is not limited in this embodiment of the invention.
[0085] As can be seen, this optional embodiment can also send an HTTPS request to the heartbeat interface of the aforementioned server after converting the server address to an HTTPS address. If an HTTPS response corresponding to the HTTPS request is detected from the server and the status code in the parsed HTTPS response matches the target status code, the HTTPS connection can be determined to be available. Otherwise, the HTTPS connection is unavailable. This allows for verification of the availability of the HTTPS connection in a real environment through actual network request testing. Only when a real connection is successfully established is HTTPS availability confirmed. It can also detect practical problems such as firewall blocking, closed ports, and incompatible SSL versions, thereby effectively avoiding situations where the configuration is correct but the connection fails. Compared to configuration checks, this is more reliable, which in turn improves the reliability of the selection of the first target communication protocol and thus improves the reliability and stability of the HTTPS communication connection.
[0086] In an optional embodiment, before establishing a dynamic communication connection between the application and the server corresponding to the server address based on the first target communication protocol, the method further includes the following operations: When the certificate verification result indicates that the certificate verification is successful, the server certificate information and the above HTTPS address are saved as communication configuration information to local storage to achieve persistent storage; wherein, the persistent storage of the above communication configuration information is used so that the communication configuration information can be directly used to establish a communication connection after the application restarts; Based on the aforementioned HTTPS address, update the network request manager corresponding to the application for the base URL of the aforementioned server, so that the communication mode of all business modules of the application is switched to HTTPS mode. When the certificate verification result indicates that the certificate verification has failed, the above server certificate information and the cache configuration information related to the server certificate information are cleared; wherein, the cache configuration information includes the parsed data involved in the process of building the above local certificate trust system; for example, it may include decoded certificate information, standard certificate object, trusted root certificate, and local trust manager, but this embodiment of the invention is not limited.
[0087] For example, the above-mentioned persistent storage function can bring convenience to users in practical applications: In the daily office scenario of an enterprise, after an employee successfully configures HTTPS for the first time, since the certificate and URL have been saved, the communication configuration information can be directly loaded and used every time the application accesses the company's file server (such as NAS); or, after the application terminates (such as being cleared in the background) or the electronic device restarts, the HTTPS connection can be restored without re-obtaining the certificate; or, after a network change occurs, such as the connected network switching from the company network to the home network, or from Wi-Fi to the mobile network, as long as the server address remains unchanged, the electronic device can adaptively adjust the communication connection based on the communication configuration information; or, if the server maintenance causes the HTTPS service to be temporarily closed, it will automatically downgrade to HTTP to ensure that the communication function is not interrupted. After the server is restored, the communication connection can be adaptively adjusted through the above process. This embodiment of the invention does not limit the scope of the invention.
[0088] As can be seen, this optional embodiment can persistently save the successfully verified certificate information and HTTPS configuration, and globally switch the application's network communication protocol to HTTPS mode. This can improve the storage reliability of HTTPS configuration information, while also enhancing the intelligence and efficiency of communication connections, thereby providing users with more convenient and efficient communication connection services and improving the user experience.
[0089] Example 2 Please see Figure 2 , Figure 2 This is a flowchart illustrating a communication connection adaptive adjustment method disclosed in an embodiment of the present invention. Figure 2The described adaptive adjustment method for communication connections can be applied to a device for adaptive adjustment of communication connections. This device may include one of a smart device, a smart terminal, a smart system, and a server. The server may be a local server or a cloud server; this embodiment of the invention is not limited thereto. The method can also be applied to an electronic device with an application installed. The electronic device is communicatively connected to a network-attached storage device, and the electronic device can access the network-attached storage device through the application; this embodiment of the invention is not limited thereto. Figure 2 As shown, the adaptive adjustment method for the communication connection may include the following operations: 201. Determine whether the server address received by the application meets the pre-set communication protocol switching conditions.
[0090] In this embodiment of the invention, when step 201 determines that the server address meets the communication protocol switching conditions, that is, when the determination result of step 201 is yes, the operations of steps 202-205 are executed; when step 201 determines that the server address does not meet the communication protocol switching conditions, that is, when the determination result of step 201 is no, the operations of steps 206-207 are executed. This embodiment of the invention does not impose any limitations.
[0091] 202. Based on the pre-defined certificate dynamic acquisition strategy, perform the server address information acquisition operation to obtain the information acquisition result.
[0092] In this embodiment of the invention, the information acquisition result includes the operation execution result corresponding to the information acquisition operation; when the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result also includes server certificate information.
[0093] 203. Based on the pre-built multi-level certificate verification system, perform certificate verification operations on the server certificate information to obtain the certificate verification result.
[0094] In this embodiment of the invention, both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with an intelligent retry mechanism.
[0095] 204. Based on the information acquisition results and / or certificate verification results, determine the first target communication protocol that can be used for the server address.
[0096] In this embodiment of the invention, the first target communication protocol includes the HTTP protocol or the HTTPS protocol.
[0097] 205. Based on the first target communication protocol, establish a dynamic communication connection between the application and the server corresponding to the server address.
[0098] For further detailed descriptions of steps 201-205 in this embodiment of the invention, please refer to the detailed description of steps 101-105 in Embodiment 1. These descriptions will not be repeated in this embodiment of the invention.
[0099] 206. The second target communication protocol corresponding to the server address is determined to be the HTTP protocol.
[0100] 207. Based on the second target communication protocol, establish a static communication connection between the application and the server corresponding to the server address.
[0101] In this embodiment of the invention, when it is determined that the server address does not meet the conditions for switching communication protocols, the connection between the application and the server is kept in HTTP mode.
[0102] As can be seen, the method described in the embodiments of the present invention can, after determining that the server address received by the application meets the pre-set communication protocol switching conditions, attempt to dynamically obtain server certificate information through a dynamic certificate acquisition strategy. After successfully obtaining the server certificate information, it verifies the server certificate information through a multi-level certificate verification system. Then, based on the certificate information acquisition result and / or certificate verification result, it determines the communication protocol that the server can currently use, so as to establish a dynamic communication connection between the application and the server corresponding to the server address. It can automatically obtain, verify, and trust server certificates, thereby adaptively adjusting the communication connection strategy based on the actual certificate situation and the actual network state. It is suitable for application scenarios with multiple types of certificate verification, especially for communication connection scenarios using self-signed certificates, such as enterprise intranets and private clouds. It can improve the flexibility and reliability of the choice of communication connection between the client and the server while ensuring communication security, thereby ensuring the availability and continuity of communication services, providing users with a secure and reliable network connection, and thus improving the user's experience of network connection. Furthermore, it can determine the second target communication protocol as HTTP when it is determined that the server address does not meet the conditions for switching communication protocols, so as to maintain the HTTP mode. It can also improve the efficiency and reliability of establishing communication connections when it is determined that the communication between the application and the server does not require the advanced security protection of HTTPS.
[0103] In an optional embodiment, the method further includes the following operations: When the first target communication protocol is HTTPS, after step 204 or step 205, the observer pattern or event bus is used to send a global notification about the switching result of the first target communication protocol or dynamic communication connection. Set the HTTPS availability status in the global protocol availability status parameter in the application; Each business module of the application listens for communication switching events. Upon receiving the aforementioned global notification, it updates the network configuration of that business module according to its business requirements.
[0104] The global notification sending operation is executed in the main thread to ensure that the UI module can respond in a timely manner; by setting the above-mentioned global protocol availability status parameters, it is convenient for various business modules to refer to and make decisions.
[0105] For example, the aforementioned cross-module configuration synchronization function can be applied more flexibly and efficiently to applications with complex architectures in practical applications. For instance, when an application is a cross-platform application and uses modules from different technology stacks such as native code, Flutter, and React Native, each module acts as an independent listener, receiving configuration change instructions through a unified event bus, thus achieving cross-technology stack configuration synchronization. Alternatively, when the main interface uses Flutter, the file preview uses WebView, and the video uses the native SDK, the above function can receive the same communication switching event and update the configuration in an appropriate way. For example, high-traffic modules such as video streams may choose HTTP due to the performance overhead of HTTPS, but can still obtain the HTTPS availability status. Or, in scenarios with high security requirements, it is necessary to force all business modules to update their HTTPS configurations, covering all business modules. This embodiment of the invention does not impose any limitations.
[0106] As can be seen, this optional embodiment can notify all modules within the application that require network communication of the HTTPS switching result, which helps to keep the network protocol configuration of the entire application consistent, and also allows each module to set the communication protocol it uses differently, thereby improving the application flexibility and reliability of the communication protocol, and thus improving the reliability of the communication connection.
[0107] In an embodiment of the present invention, the flowchart of the communication connection adaptive adjustment method can be found in [reference needed]. Figure 3 , Figure 3 This is a flowchart illustrating another adaptive adjustment method for communication connections disclosed in an embodiment of the present invention; as shown below. Figure 3 As shown, the method may include the following steps: When the client (i.e., the application mentioned above) receives the server address (i.e. Figure 3 After the URL in the URL field, check the URL type to determine if the URL is an IP address; if it is not an IP address, it can be directly determined that an HTTP connection is maintained between the client and the server. If it is an IP address, then attempt to obtain the server certificate information. If the server certificate information cannot be obtained, then retry after a delay. If the retry fails, switch to HTTP mode and establish an HTTP connection. If the retry is successful or the certificate is obtained directly, then establish local certificate trust for the server certificate information and test whether the HTTPS connection is available. If the HTTPS connection test is successful, then cache the certificate and switch to HTTPS mode. If the HTTPS connection test fails, switch to HTTP mode. This embodiment of the invention is not limited.
[0108] Example 3 Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of a communication connection adaptive adjustment device disclosed in an embodiment of the present invention. Figure 4 The described adaptive adjustment device for communication connections may include one of a smart device, a smart terminal, a smart system, and a server, wherein the server may be a local server or a cloud server, and this embodiment of the invention is not limited thereto; the device can be applied to an electronic device with an application installed, the electronic device being communicatively connected to a network attached storage device, and the electronic device being able to access the network attached storage device through the application, and this embodiment of the invention is not limited thereto. Figure 4 As shown, the communication connection adaptive adjustment device 30 may include: The judgment module 301 is used to determine whether the server address received by the application meets the preset communication protocol switching conditions; The certificate acquisition module 302 is used to perform a server address information acquisition operation based on a pre-set certificate dynamic acquisition strategy when the judgment module 301 determines that the server address meets the communication protocol switching conditions, and obtain the information acquisition result. The information acquisition result includes the operation execution result corresponding to the information acquisition operation. When the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result also includes server certificate information. The certificate verification module 303 is used to perform certificate verification operations on server certificate information based on a pre-built multi-level certificate verification system and obtain the certificate verification result; both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with intelligent retry mechanisms. The determination module 304 is used to determine, based on the information acquisition result and / or certificate verification result, a first target communication protocol that can be used for the server address; the first target communication protocol includes HTTP protocol or HTTPS protocol. The connection module 305 is used to establish a dynamic communication connection between the application and the server corresponding to the server address based on the first target communication protocol.
[0109] As can be seen, the apparatus described in the embodiments of the present invention can, after determining that the server address received by the application meets the pre-set communication protocol switching conditions, attempt to dynamically acquire server certificate information through a dynamic certificate acquisition strategy. After successfully acquiring the server certificate information, it verifies the server certificate information through a multi-level certificate verification system. Then, based on the certificate information acquisition result and / or certificate verification result, it determines the communication protocol that the server can currently use, so as to establish a dynamic communication connection between the application and the server corresponding to the server address. It can automatically acquire, verify, and trust server certificates, thereby adaptively adjusting the communication connection strategy based on the actual certificate situation and the actual network state. It is suitable for application scenarios with multiple types of certificate verification, especially for communication connection scenarios using self-signed certificates, such as enterprise intranets and private clouds. It can improve the flexibility and reliability of the choice of communication connection between the client and the server while ensuring communication security, thereby ensuring the availability and continuity of communication services, providing users with a secure and reliable network connection, and thus improving the user's experience of network connection.
[0110] In an optional embodiment, the specific method by which the determining module 301 determines whether the server address received by the application meets the preset communication protocol switching conditions may include: Based on regular expression matching algorithms, determine whether the address format of the server address matches the IP address format; When it is determined that the server address format matches the IP address format, the server address is deemed to meet the pre-set communication protocol switching conditions. When it is determined that the server address format does not match the IP address format, it is determined that the server address does not meet the pre-set communication protocol switching conditions.
[0111] As can be seen, the apparatus described in this optional embodiment can determine whether the address format of the server address matches the IP address format based on a regular expression matching algorithm. If the determination result is yes, it is determined that the server address meets the communication protocol switching conditions and the subsequent communication protocol switching process needs to be initiated; otherwise, it is determined that the server address does not meet the communication protocol switching conditions. It can automatically identify the server address type and intelligently determine whether to use a normal HTTP connection or initiate an adaptive switching process to obtain and use an HTTPS secure connection. This improves the accuracy of the adaptive switching process initiation determination and enhances the flexibility of communication connection strategy selection.
[0112] In an optional embodiment, the determining module 304 is further configured to determine that the second target communication protocol corresponding to the server address is the HTTP protocol when the determining module 301 determines that the server address does not meet the communication protocol switching conditions. The connection module 305 is also used to establish a static communication connection between the application and the server corresponding to the server address based on the second target communication protocol.
[0113] As can be seen, the apparatus described in this optional embodiment can determine the second target communication protocol as HTTP when it is determined that the server address does not meet the conditions for switching communication protocols, so as to maintain the HTTP mode. It can improve the efficiency and reliability of establishing communication connections when it is determined that the communication between the application and the server does not require the advanced security protection of HTTPS.
[0114] In an optional embodiment, the certificate acquisition module 302 performs a server address information acquisition operation based on a pre-set certificate dynamic acquisition strategy. The specific method for obtaining the information acquisition result may include: Based on the HTTP interface, send an HTTP request to the server corresponding to the server address; The system detects whether an HTTP response corresponding to the HTTP request has been received from the server, thus obtaining a first response detection result. The HTTP response includes a first response header and a second response header. The first response header records the server's corresponding encoded certificate information, and the second response header records the server's corresponding HTTPS service port number. When the first response detection result is used to indicate that the HTTP response returned by the server corresponding to the HTTP request has been received, the operation execution result is determined to indicate that the operation was successfully executed, and the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number of the server. The server certificate information is encoded certificate information; and the information retrieval results also include the HTTPS service port number.
[0115] As can be seen, the apparatus described in this optional embodiment can send an HTTP request to the server corresponding to the server address via an HTTP interface and detect whether a corresponding HTTP response can be received from the server. If the response is received, the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number. This enables the dynamic acquisition of the currently valid and encoded transmission server certificate information and the HTTPS service port number via HTTP, which can improve the reliability and integrity of the transmission of server communication-related information, thereby improving the reliability of subsequent certificate verification operations.
[0116] In an optional embodiment, the certificate verification module 303 performs certificate verification operations on the server certificate information based on a pre-built multi-level certificate verification system, and the specific method for obtaining the certificate verification result may include: Construct a local certificate trust system corresponding to the server certificate information; the local certificate trust system includes at least the trusted root certificate corresponding to the server certificate information and the local trust manager corresponding to the trusted root certificate. Based on a pre-defined standard root certificate store, standard certificate verification operations are performed on trusted root certificates to obtain standard verification results. When the standard verification result is used to indicate verification failure, a custom verification operation is performed on the trusted root certificate based on the local trust manager to obtain a custom verification result; When a custom verification result is used to indicate verification failure, the intelligent retry mechanism corresponding to the multi-level certificate verification system is activated to obtain the retry verification result; When the retest verification result is used to indicate verification failure, the certificate verification result is determined to be certificate verification failure; When one of the standard verification result, custom verification result, and retest verification result is used to indicate successful verification, the certificate verification result is determined to be successful.
[0117] As can be seen, the apparatus described in this optional embodiment can construct a local certificate trust system corresponding to the server certificate information. It first performs a standard certificate verification operation on the trusted root certificate corresponding to the server certificate information. If the standard verification fails, it then performs a custom verification operation on the trusted root certificate based on the local trust manager constructed in the local certificate trust system. If the custom verification also fails, it initiates the intelligent retry mechanism corresponding to the multi-level certificate verification system. Only if the retry result still fails is the certificate verification finally determined to have failed. Otherwise, when any one of the standard verification result, custom verification result, and retry verification result indicates successful verification, the certificate verification is determined to be successful. This allows for flexible verification of standard CA certificates and self-signed certificates through a multi-level certificate verification system while establishing a secure trust relationship between the client and the server by constructing a local certificate trust system. It also provides anomaly recovery capabilities through the intelligent retry mechanism, thereby improving the flexibility and reliability of certificate verification and ultimately enhancing the reliability of the certificate verification results.
[0118] In this optional embodiment, the specific method by which the certificate verification module 303 constructs the local certificate trust system corresponding to the server certificate information may include: Decode the server certificate information to obtain the decoded certificate information; Parse and decode the certificate information to obtain the standard certificate object corresponding to the server certificate information; Create a local certificate trust store and store the standard certificate object as a trusted root certificate in the local certificate trust store; A local trust manager is generated based on the local certificate trust library.
[0119] As can be seen, the apparatus described in this optional embodiment can first decode the server certificate information, then parse the decoded certificate information to obtain a standard certificate object, then store the standard certificate object as a trusted root certificate in the created local certificate trust store, and then generate a local trust manager based on the local certificate trust store. This can convert the certificate provided by the server into a trust credential that the client can recognize, establish a secure trust relationship, and generate a dedicated trust manager, thereby improving the efficiency and reliability of subsequent multi-level certificate verification operations.
[0120] In an optional embodiment, the determining module 304 determines the specific method of the first target communication protocol that can be used for the server address based on the information acquisition result and / or certificate verification result, which may include: When the operation execution result of the information retrieval result is used to indicate that the operation was successfully executed and the certificate verification result is used to indicate that the certificate verification was successful, an HTTPS connection test is performed on the server address based on the information retrieval result to obtain the connection test result; When the connection test result indicates that an HTTPS connection corresponding to a server address is available, the first target communication protocol that can be used for the server address is determined to be the HTTPS protocol. When the operation execution result of the information retrieval result is used to indicate that the operation execution failed, or the certificate verification result is used to indicate that the certificate verification failed, or the connection test result is used to indicate that the HTTPS connection corresponding to the server address is unavailable, the first target communication protocol that can be used for the server address is determined to be the HTTP protocol.
[0121] As can be seen, the apparatus described in this optional embodiment can perform an HTTPS connection test based on the information acquisition result after successfully obtaining server certificate information and successfully verifying the certificate. If the test shows that the HTTPS connection is available, the HTTPS protocol is selected; otherwise, if the server certificate information cannot be obtained, the certificate verification fails, or the HTTPS connection is found to be unavailable, the HTTP protocol is downgraded. This can improve the flexibility and reliability of determining the communication protocol, while also improving the reliability and security of selecting the HTTPS protocol for communication connections, thereby helping to improve the reliability of communication connections and ensure the availability of communication services.
[0122] Example 4 Please see Figure 5 , Figure 5 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of the present invention. For example... Figure 5 As shown, the electronic device 40 may include: Memory 401 storing executable program code; Processor 402 coupled to memory 401; The processor 402 calls the executable program code stored in the memory 401 to execute some or all of the steps in the communication connection adaptive adjustment method described in Embodiment 1 or Embodiment 2 of the present invention.
[0123] Example 5 This invention discloses a communication connection adaptive adjustment system. Please refer to [link / reference]. Figure 6 , Figure 6 This is a schematic diagram of the structure of a communication connection adaptive adjustment system disclosed in an embodiment of the present invention. Figure 6 As shown, the communication connection adaptive adjustment system includes the communication connection adaptive adjustment device 30 described in Embodiment 3 of the present invention, and a network additional storage device 50 communicatively connected to the communication connection adaptive adjustment device 30; wherein, the communication connection adaptive adjustment device 30 adaptively adjusts the communication protocol used to establish the communication connection according to the communication connection adaptive adjustment method described in Embodiment 1 or Embodiment 2 of the present invention. or, In this embodiment of the invention, as another optional implementation, please refer to [link / reference needed]. Figure 7 , Figure 7 This is a schematic diagram of another communication connection adaptive adjustment system disclosed in an embodiment of the present invention. Figure 7 As shown, the communication connection adaptive adjustment system includes an electronic device 40 as described in Embodiment 4 of the present invention, and a network-attached storage device 50 that is communicatively connected to the electronic device 40; wherein, the electronic device 40 adaptively adjusts the communication protocol used to establish the communication connection according to the communication connection adaptive adjustment method described in Embodiment 1 or Embodiment 2 of the present invention.
[0124] Example 6 This invention discloses a computer storage medium storing computer instructions. When these computer instructions are invoked, they are used to execute some or all of the steps in the communication connection adaptive adjustment method described in Embodiment 1 or Embodiment 2 of this invention.
[0125] Example 7 This invention discloses a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to perform some or all of the steps in the communication connection adaptive adjustment method described in Embodiment 1 or Embodiment 2.
[0126] The device embodiments described above are merely illustrative. The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0127] Through the detailed description of the above embodiments, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium that can be used to carry or store data.
[0128] Finally, it should be noted that the communication connection adaptive adjustment method, apparatus, electronic device and system disclosed in the embodiments of the present invention are only preferred embodiments of the present invention, and are only used to illustrate the technical solutions of the present invention, and not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for adaptive adjustment of communication connections, characterized in that, The method is applied to an electronic device with an application installed, the electronic device being communicatively connected to a network-attached storage device (NAT), and the electronic device being able to access the NAT via the application; wherein the method includes: Determine whether the server address received by the application meets the preset communication protocol switching conditions; When it is determined that the server address meets the communication protocol switching conditions, based on a pre-set certificate dynamic acquisition strategy, an information acquisition operation for the server address is performed to obtain an information acquisition result; the information acquisition result includes the operation execution result corresponding to the information acquisition operation; when the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result also includes server certificate information; Based on a pre-built multi-level certificate verification system, a certificate verification operation is performed on the server certificate information to obtain a certificate verification result; wherein, both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with an intelligent retry mechanism; Based on the information acquisition result and / or the certificate verification result, a first target communication protocol that can be used for the server address is determined; the first target communication protocol includes HTTP protocol or HTTPS protocol. Based on the first target communication protocol, a dynamic communication connection is established between the application and the server corresponding to the server address.
2. The adaptive adjustment method for communication connection according to claim 1, characterized in that, The step of determining whether the server address received by the application meets the preset communication protocol switching conditions includes: Based on the regular expression matching algorithm, it is determined whether the address format of the server address matches the IP address format; When it is determined that the address format of the server address matches the IP address format, it is determined that the server address meets the pre-set communication protocol switching conditions; When it is determined that the address format of the server address does not match the IP address format, it is determined that the server address does not meet the pre-set communication protocol switching conditions.
3. The adaptive adjustment method for communication connection according to claim 1, characterized in that, The method further includes: When it is determined that the server address does not meet the communication protocol switching conditions, the second target communication protocol corresponding to the server address is determined to be the HTTP protocol; Based on the second target communication protocol, a static communication connection is established between the application and the server corresponding to the server address.
4. The adaptive adjustment method for communication connection according to claim 1, characterized in that, The process of obtaining server address information based on a pre-defined certificate dynamic acquisition strategy, and obtaining the information acquisition result, includes: Based on the HTTP interface, send an HTTP request to the server corresponding to the server address; The system detects whether an HTTP response corresponding to the HTTP request has been received from the server, and obtains a first response detection result; wherein, the HTTP response includes a first response header and a second response header; the first response header is used to record the encoding certificate information corresponding to the server; the second response header is used to record the HTTPS service port number corresponding to the server; When the first response detection result is used to indicate that an HTTP response corresponding to the HTTP request has been received from the server, the operation execution result is determined to indicate that the operation was successfully executed, and the HTTP response is parsed to obtain the server certificate information and the HTTPS service port number corresponding to the server. The server certificate information is the encoded certificate information; and the information acquisition result also includes the HTTPS service port number.
5. The adaptive adjustment method for communication connection according to any one of claims 1-4, characterized in that, The pre-built multi-level certificate verification system performs certificate verification operations on the server certificate information to obtain certificate verification results, including: Construct a local certificate trust system corresponding to the server certificate information; the local certificate trust system includes at least the trusted root certificate corresponding to the server certificate information and the local trust manager corresponding to the trusted root certificate. Based on a pre-defined standard root certificate library, a standard certificate verification operation is performed on the trusted root certificate to obtain a standard verification result. When the standard verification result is used to indicate verification failure, a custom verification operation is performed on the trusted root certificate based on the local trust manager to obtain a custom verification result; When the custom verification result is used to indicate verification failure, the intelligent retry mechanism corresponding to the multi-level certificate verification system is activated to obtain the retry verification result; When the retest verification result is used to indicate verification failure, the certificate verification result is determined to be certificate verification failure; When one of the standard verification result, the custom verification result, and the retest verification result is used to indicate successful verification, the certificate verification result is determined to be successful.
6. The adaptive adjustment method for communication connection according to claim 5, characterized in that, The construction of the local certificate trust system corresponding to the server certificate information includes: Decode the server certificate information to obtain decoded certificate information; Parse the decoded certificate information to obtain the standard certificate object corresponding to the server certificate information; Create a local certificate trust store and store the standard certificate object as a trusted root certificate in the local certificate trust store; A local trust manager is generated based on the local certificate trust library.
7. The adaptive adjustment method for communication connection according to any one of claims 1, 2, 3, 4, and 6, characterized in that, The step of determining the first target communication protocol that can be used for the server address based on the information acquisition result and / or the certificate verification result includes: When the operation execution result of the information acquisition result is used to indicate that the operation was successfully executed and the certificate verification result is used to indicate that the certificate verification was successful, an HTTPS connection test is performed on the server address according to the information acquisition result to obtain the connection test result; When the connection test result indicates that the HTTPS connection corresponding to the server address is available, the first target communication protocol that can be used for the server address is determined to be the HTTPS protocol. When the operation execution result of the information acquisition result is used to indicate that the operation execution failed, or the certificate verification result is used to indicate that the certificate verification failed, or the connection test result is used to indicate that the HTTPS connection corresponding to the server address is unavailable, the first target communication protocol that can be used for the server address is determined to be the HTTP protocol.
8. A communication connection adaptive adjustment device, characterized in that, The device is used in an electronic device with an application installed, the electronic device being communicatively connected to a network-attached storage device (NAT), and the electronic device being able to access the NAT via the application; wherein the device includes: The judgment module is used to determine whether the server address received by the application meets the preset communication protocol switching conditions; The certificate acquisition module is used to perform an information acquisition operation on the server address based on a pre-set certificate dynamic acquisition strategy when the judgment module determines that the server address meets the communication protocol switching conditions, and obtain an information acquisition result; the information acquisition result includes the operation execution result corresponding to the information acquisition operation; when the operation execution result is used to indicate that the operation was successfully executed, the information acquisition result also includes server certificate information; The certificate verification module is used to perform certificate verification operations on the server certificate information based on a pre-built multi-level certificate verification system to obtain the certificate verification result; wherein, both the dynamic certificate acquisition strategy and the multi-level certificate verification system are equipped with an intelligent retry mechanism; The determining module is configured to determine a first target communication protocol that can be used for the server address based on the information acquisition result and / or the certificate verification result; the first target communication protocol includes HTTP protocol or HTTPS protocol; The connection module is used to establish a dynamic communication connection between the application and the server corresponding to the server address based on the first target communication protocol.
9. An electronic device, characterized in that, The electronic device includes: Memory containing executable program code; A processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the communication connection adaptive adjustment method as described in any one of claims 1-7.
10. A communication connection adaptive adjustment system, characterized in that, The system includes the communication connection adaptive adjustment device as described in claim 8, and a network-attached storage device communicatively connected to the communication connection adaptive adjustment device; wherein the communication connection adaptive adjustment device adaptively adjusts the communication protocol used to establish the communication connection according to the communication connection adaptive adjustment method as described in any one of claims 1-7; or, The system includes the electronic device as described in claim 9, and a network-attached storage device communicatively connected to the electronic device; wherein the electronic device adaptively adjusts the communication protocol used to establish the communication connection according to the communication connection adaptive adjustment method as described in any one of claims 1-7.
11. A computer storage medium, characterized in that, The computer storage medium stores computer instructions, which, when invoked, are used to execute the communication connection adaptive adjustment method as described in any one of claims 1-7.