HTTPS Secure communication based on Nginx server and iOS9

Source: Internet
Author: User

Brief introduction

In network communication, the use of packet capture software can be used to analyze network requests and replay attacks, replay attack solution is generally using a change of parameters, such as RSA encryption timestamp, but considering the network transmission delay, time stamp needs to have a certain error tolerance, so still can not fundamentally prevent replay attacks. To better solve the replay attack problem, should consider the use of HTTPS communication, HTTPS protocol is built by the SSL+HTTP protocol can be encrypted transmission, identity authentication network protocol, than the HTTP protocol security.

Realize

For Web sites visited by the browser, you need to request a certificate from the CA to ensure that the HTTPS Web page is properly browsed, otherwise it will be warned of unsafe or unauthenticated sites, and for some background data transmission, the use of self-signed certificates.

Configuration of the server side
  1. Generate certificate
    At the command line of the server, do the following
    ① generate the private key of the server, you need to enter a 4~8191 bit password

    openssl genrsa -des3 -out server.key2048

    ② Remove the key file password, here you need to enter the password ① fill in

    openssl rsa -in server.key -out server.key

    ③ generate a CSR file, this step requires a variety of information, you can all press ENTER to skip

    openssl req -new -key server.key -out server.csr

    ④ Generate CRT files, this step after the-days is valid, you can write a bit longer

    3650 -in server.csr -signkey server.key -out server.crt

    ⑤ merge CRT with key to make PEM for subsequent CER generation for client validation

    serverserverserver.pem

    ⑥ generate cer,cer files with PEM stored on the client for authentication

    openssl x509 -in server.pem -outform der -out server.cer
  2. modifying Nginx configuration Files
    If you do not know the path to the configuration file, use the following command to print.

    -t

    This command can be used to test whether the configuration file is correct and also prints out the path.

    Based on the printed content, open nginx.conf, you can find that there is an HTTP {...} configuration tab, add a server configuration label to the HTTP tag.

    Server{Listen443; server_name localhost;# Configure the file name and type of the root and home page of the siteIndex Index. htmlIndex. htmIndex. php;root < Here fill in the root directory of the website >ssl on;ssl_certificate < fill in the CRT file hereServer. CRT full path >ssl_certificate_key < here to fill in the private key key fileServer. Key's full path ># Below is the configuration of PHP, if not configured, will not be able to parse the PHP file, this configuration is from the Nginx 80 port configuration of HTTP copied over, if this configuration does not work properly, from its own server on the 80 port configuration file copied over. Location ~. *\. (PHP|PHP5)? ${#fastcgi_pass Unix:/tmp/php-cgi.sock;Fastcgi_pass127.0. 0. 1:9000; Fastcgi_indexIndex. php; Include fastcgi.conf;} Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) ${expires -D;} Location ~. *\. (JS|CSS)? ${expires1H;}# If you do not know how to fill in this, please refer to the 80 port configuration fileConf directory path for include <nginx >/rewrite/default. Conf;access_log <nginx the path to the server log >/default. log;}
  3. Update configuration

    #测试配置文件是否正确-s#重新加载配置文件

    Here, the server configuration is over.

Configuration of the Client

If it is a CA-issued certificate, use the HTTPS request directly, but we are self-signed certificate, if the direct access will be error, the following describes the use of AFN to configure the self-signed certificate of HTTPS request method.

    1. Import the CER certificate mentioned above into the bundle of the app

    2. Before using AFN to make a request, make the following configuration

      *policy*manager = [AFHTTPSessionManager manager];manager.securityPolicy = policy;// 下面使用manager进行HTTPS请求即可。

HTTPS Secure communication based on Nginx server and iOS9

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.