


https protocol is http+ssl protocol. The connection process is shown in the figure below:
The client sends an https request to the server;
After receiving the request, the server generates the public key and private key. The public key is equivalent to a lock, and the private key is equivalent to a key. Only the private key can open the content locked by the public key;
The server returns the public key (certificate) to the client. The public key contains a lot of information, such as the issuing authority of the certificate, expiration time, etc.;
After the client receives the public key, it will first verify whether it is valid, such as the issuing authority or expiration time, etc. If any problem is found, an exception will be thrown, prompting that there is a problem with the certificate. If there is no problem, then generate a random value as the client's key, and then encrypt it with the server's public key;
The client encrypts the key with the server's public key and then sends it to the server.
The server receives the encrypted key, and then decrypts it with the private key to obtain the client's key. Then the server symmetrically encrypts the content to be transmitted and the client's key, so that unless the key is known, Otherwise there is no way to know what was transmitted.
The server transmits the encrypted content to the client.
After the client obtains the encrypted content, it uses the previously generated key to decrypt it and obtain the content.
https is not absolutely safe. As shown in the figure below, it is a man-in-the-middle hijacking attack. The man-in-the-middle can obtain all communication content between the client and the server.
The middleman intercepts the request sent by the client to the server, and then pretends to be the client to communicate with the server; sends the content returned by the server to the client to the client, and pretends to be the server to communicate with the client.
In this way, all content of the communication between the client and the server can be obtained.
To use a man-in-the-middle attack, the client must trust the certificate of the middleman. If the client does not trust it, this attack method will not work.
The reason for man-in-the-middle hijacking is that the server certificate and domain name are not verified or the verification is incomplete. For convenience, the default verification method of the open source framework is directly used for https requests
Such as volley
OKhttp3.0
Prevention methods:
There are two ways to prevent it
1. For apps with relatively high security requirements, the certificate can be locked by pre-embedding the certificate on the client side. Communication is only allowed when the client certificate and the server certificate are completely consistent, such as some banks. app, but this method faces a problem, the problem of certificate expiration. Because the certificate has a certain validity period, when the pre-embedded certificate expires, it can only be solved by forcing the update or requiring the user to download the certificate.
Take volley as an example: the verification is implemented as follows
Create SSLSocketFactory through pre-embedded certificate;
private static SSLSocketFactory buildSSLSocketFactory(Context context, int certRawResId) { KeyStore keyStore = null; try { keyStore = buildKeyStore(context, certRawResId); } catch (KeyStoreException e) { e.printStackTrace(); } catch (CertificateException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmf = null; try { tmf = TrustManagerFactory.getInstance(tmfAlgorithm); tmf.init(keyStore); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyStoreException e) { e.printStackTrace(); } SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLS"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } try { sslContext.init(null, tmf.getTrustManagers(), null); } catch (KeyManagementException e) { e.printStackTrace(); } return sslContext.getSocketFactory();
Generate a connection that has been verified by SSL and domain name
2 For apps with general security requirements, you can use the method of verifying the domain name, certificate validity, certificate key information and certificate chain
Take volley as an example, rewrite the checkServerTrusted method in HTTPSTrustManager, and enable strong domain name verification
Many applications currently use webview to load H5 pages. If the server uses a certificate issued by a trusted CA, overload WebViewClient's onReceivedSslError() when webView.setWebViewClient(webviewClient). If a certificate error occurs, call the handler directly. .proceed() will ignore the error and continue to load the page with the certificate problem. If handler.cancel() is called, it can terminate the loading of the page with the certificate problem. If there is a problem with the certificate, the user can be prompted for risks and let the user choose whether to load or not. If so, If the security level is relatively high, the page loading can be terminated directly, prompting the user that the network environment is risky:
It is not recommended to use handler.proceed() directly. If the webview needs to strongly verify the server certificate when loading https, you can use HttpsURLConnection to strongly verify the certificate in onPageStarted() to verify the server certificate. If the verification does not pass, stop loading the web page. Of course, this will slow down the loading speed of the web page and requires further optimization. The specific optimization methods are beyond the scope of this discussion and will not be explained in detail here.
The above is the detailed content of Detailed explanation of HTTPS connection process and man-in-the-middle attack and hijacking. For more information, please follow other related articles on the PHP Chinese website!

linux设备节点是应用程序和设备驱动程序沟通的一个桥梁;设备节点被创建在“/dev”,是连接内核与用户层的枢纽,相当于硬盘的inode一样的东西,记录了硬件设备的位置和信息。设备节点使用户可以与内核进行硬件的沟通,读写设备以及其他的操作。

区别:1、open是UNIX系统调用函数,而fopen是ANSIC标准中的C语言库函数;2、open的移植性没fopen好;3、fopen只能操纵普通正规文件,而open可以操作普通文件、网络套接字等;4、open无缓冲,fopen有缓冲。

在linux中,可以利用“rpm -qa pcre”命令判断pcre是否安装;rpm命令专门用于管理各项套件,使用该命令后,若结果中出现pcre的版本信息,则表示pcre已经安装,若没有出现版本信息,则表示没有安装pcre。

端口映射又称端口转发,是指将外部主机的IP地址的端口映射到Intranet中的一台计算机,当用户访问外网IP的这个端口时,服务器自动将请求映射到对应局域网内部的机器上;可以通过使用动态或固定的公共网络IP路由ADSL宽带路由器来实现。

在linux中,eof是自定义终止符,是“END Of File”的缩写;因为是自定义的终止符,所以eof就不是固定的,可以随意的设置别名,linux中按“ctrl+d”就代表eof,eof一般会配合cat命令用于多行文本输出,指文件末尾。

linux查询mac地址的方法:1、打开系统,在桌面中点击鼠标右键,选择“打开终端”;2、在终端中,执行“ifconfig”命令,查看输出结果,在输出信息第四行中紧跟“ether”单词后的字符串就是mac地址。

手机远程linux工具有:1、JuiceSSH,是一款功能强大的安卓SSH客户端应用,可直接对linux服务进行管理;2、Termius,可以利用手机来连接Linux服务器;3、Termux,一个强大的远程终端工具;4、向日葵远程控制等等。

linux中,lsb是linux标准基础的意思,是“Linux Standards Base”的缩写,是linux标准化领域中的标准;lsb制定了应用程序与运行环境之间的二进制接口,保证了linux发行版与linux应用程序之间的良好结合。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment