ios

iOS OTA 环境部署

2016-05-05  本文已影响1675人  咖咖嘻

一、Mac OS X 启用 web 服务器

Mac OS X 自带了Apache环境,我们只需要启动它就行了,可以通过在终端(terminal)输入 httpd -v 来查看Apache的版本信息:

$ httpd -v
Server version: Apache/2.4.18 (Unix)
Server built:   Feb 20 2016 20:03:19

启动Apache

在终端输入 sudo apachectl start 就可以启动Apache。

启动后,在浏览器中输入 http://127.0.0.1http://localhost 如果看到 It Works! 页面:

itworks.png

Apache 就启动成功了,站点的根目录为系统级根目录:

/Library/WebServer/Documents

停止Apache:

sudo apachectl stop

重启Apache:

sudo apachectl restart

二、开启 HTTPS 服务

iOS 7.1 以上的设备部署OTA环境必须使用HTTPS,可以配置Apache开启HTTPS服务。

创建自签名证书

  1. 首先创建一个ssl目录用来存放证书:

     $ cd /etc/apache2/
     $ sudo mkdir ssl
     $ cd ssl
    
  2. 创建主机密钥:

     $ sudo ssh-keygen -f 192.168.3.112.key
     Generating public/private rsa key pair.
     Enter passphrase (empty for no passphrase): 
     Enter same passphrase again: 
     Your identification has been saved in   192.168.3.112.key.
     Your public key has been saved in 192.168.3.112.key.pub.
     The key fingerprint is:
     SHA256:bNX90ww2g2GCh38Q/h68JnazkZYtnbkMEb1G5E51QWw root@XXdeiMac.local
     The key's randomart image is:
     +---[RSA 2048]----+
     |         oo.o +o+|
     |        o.o+ B E.|
     |         oo.+ %  |
     |       . ..o.* B.|
     |        S  .= +.+|
     |       .   . X o.|
     |          o & =  |
     |         . = B . |
     |            . o  |
     +----[SHA256]-----+
     $
    

    执行 sudo ssh-keygen -f 192.168.2.112.key 命令,会被要求提供一个密码用于主机密钥,可以选择任何的密码或直接留空。其中192.168.2.112是指Mac的内网地址,下同。

    也可以使用下面的命令创建密钥:

     $ sudo openssl genrsa -out 192.168.2.112.key 2048
     Generating RSA private key, 2048 bit long modulus
     ....+++
     ....+++
     e is 65537 (0x10001)
     $
    
  3. 创建签署申请:

     $ sudo openssl req -new -key 192.168.2.112.key -out 192.168.2.112.csr
     You are about to be asked to enter information that will be incorporated
     into your certificate request.
     What you are about to enter is what is called a Distinguished Name or a DN.
     There are quite a few fields but you can leave some blank
     For some fields there will be a default value,
     If you enter '.', the field will be left blank.
     -----
     Country Name (2 letter code) [AU]:
     State or Province Name (full name) [Some-State]:
     Locality Name (eg, city) []:
     Organization Name (eg, company) [Internet Widgits Pty Ltd]:
     Organizational Unit Name (eg, section) []:
     Common Name (e.g. server FQDN or YOUR name) []:192.168.2.112
     Email Address []:
    
     Please enter the following 'extra' attributes
     to be sent with your certificate request
     A challenge password []:
     An optional company name []:
     $
    

执行 sudo openssl req -new -key 192.168.2.112.key -out 192.168.2.112.csr 命令后,系统会提示输入各项信息,由于这是自签名的证书,除了 Common Name (e.g. server FQDN or YOUR name) []: FQDN( fully qualified domain name)必须是服务器域名或 IP 外,其他都不重要,可以随意填写或一路回车。

  1. 创建SSL证书:

    在生产环境中,我们需要提交证书申请(CSR)文件给证书颁发机构,由证书颁发机构提供SSL证书。

     $ sudo openssl x509 -req -days 365 -in 192.168.2.112.csr -signkey 192.168.2.112.key -out 192.168.2.112.crt
     Signature ok
     subject=/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=192.168.2.112
     Getting Private key
     $
    

    我们也可以直接通过以下的命令创建证书:

     $ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout 192.168.2.112.key -out 192.168.2.112.crt
    
  2. 创建NOPASS密钥:

     $ sudo openssl rsa -in 192.168.2.112.key -out 192.168.2.112.nopass.key
    

    到目前为止SSL目录下已经创建了下面一些文件,这些文件将在后面被用到:

     $ ls -l
     -rw-r--r--  1 root  wheel  1180 10 22 13:08 192.168.2.112.crt
     -rw-r--r--  1 root  wheel   993 10 22 11:58 192.168.2.112.csr
     -rw-------  1 root  wheel  1679 10 22 11:44 192.168.2.112.key
     -rw-r--r--  1 root  wheel   408 10 22 11:44 192.168.2.112.key.pub
     -rw-r--r--  1 root  wheel  1679 10 22 13:19 192.168.2.112.nopass.key
    

配置 SSL

  1. 编辑 /etc/apache2/httpd.conf 文件,删除下列代码前的注释符号 #:

     LoadModule ssl_module libexec/apache2/mod_ssl.so
     Include /private/etc/apache2/extra/httpd-ssl.conf
    
  2. 编辑 /etc/apache2/extra/httpd-ssl.conf 文件,添加 <VirtualHost>httpd-ssl.conf 中已经有一条 <VirtualHost> 记录,我们将其注释掉,新建一条:

     <VirtualHost *:443>
     #General setup for the virtual host
     DocumentRoot "/Library/WebServer/Documents"
     ServerName 192.168.2.112
    
     #SSL Engine Switch:
     SSLEngine on
    
     #Server Certificate:
     SSLCertificateFile "/etc/apache2/ssl/192.168.2.112.crt"
    
     #Server Private Key:
     SSLCertificateKeyFile "/etc/apache2/ssl/192.168.2.112.key"
    
     #SSL Engine Options:
     <FilesMatch "\.(cgi|shtml|phtml|php)$">
         SSLOptions +StdEnvVars
     </FilesMatch>
     <Directory "/Library/WebServer/CGI-Executables">
         SSLOptions +StdEnvVars
     </Directory>
     </VirtualHost>
    

检查配置文件并重启 Apache

命令行输入 $ sudo apachectl -t,可能会提示:

AH00526: Syntax error on line 92 of /private/etc/apache2/extra/httpd-ssl.conf:
SSLSessionCache: 'shmcb' session cache not supported (known names: ). Maybe you need to load the appropriate socache module (mod_socache_shmcb?).

根据提示,编辑 /etc/apache2/httpd.conf 文件,删除下列这些代码前的注释符号 #

LoadModule socache_shmcb_module libexec/apache2/mod_socache_shmcb.so

再次测试,显示 Syntax OK:

$ sudo apachectl -t
Syntax OK

说明测试通过,重启 Apache:

$ sudo apachectl restart

此时,就可以使用 HTTPS 访问本地服务了,在浏览器中输入 https://192.168.2.112/ 。

三、使用企业级证书打包生成ipa及plist文件:

打包具体步骤这里就不详述了,主要说一点,打包最后一步中,填写如下manifet.plist文件:

manifest.png

其中,各项都必须填写,URL是指相应文件在web服务器中的URL,比如ipa文件,如果直接放在服务器主目录下,则App URL为 https://192.168.2.112/TESTAPP.ipa

各项都填写好,Export ipa成功后,需要将 ipa、两个image文件以及manifest.plist文件放到刚刚填写的URL对应的服务器目录下。

四、为web服务器生成首页文件:index.html :

  1. 创建一个如下内容的index.html文件:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://     www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>应用名字</title>
    </head>
    <body>
    <h1 style="font-size:40pt">iOS应用OTA安装<h1/>
    <h1 style="font-size:40pt">
    <a title="iPhone" href="itms-services://?action=download-manifest&url=https://192.168.3.112/manifest.plist">点击安装</a>
    <h1/>
    <a title="iPhone" href="http://192.168.3.112/192.168.3.112.crt">ssl 证书安装</a>
    <h1/>
    </body>
    </html>
    

    其中,https://192.168.3.112/manifest.plist指向打包生成的plist文件,http://192.168.3.112/192.168.3.112.crt指向服务器中的CA证书,也就是上述生成crt证书,因此,需要将上述生成的crt证书copy到web服务器目录下。

  2. 将index.html放到web服务器主目录下。

  3. 为了使web服务器能够正常的传输plist及ipa文件,需要配置 Web 服务器,设定服务器 MIME 类型,即编辑/etc/apache2/mime.types文件,添加如下两种类型:

     application/octet-stream ipa
     text/xml plist
    
  4. 打开iPhone或者iPad中的浏览器,输入web服务器地址:https://192.168.2.112,如果出现如下内容,说明服务器已搭建成功:

home.png

先点击ssl安装证书安装相应的CA证书,然后在点击点击安装进行app安装。

五、安装过程中可能遇到的问题及解决方案:

  1. 显示下载失败:

    官方文档中指出三种原因:

    1)请确定应用已正确进行签名。测试方法是使用 Apple Configurator 2 将它安装到设备上,然后查看是否发生错误。

    2)请确定清单文件的链接是否正确,清单文件是否可供网络用户访问。

    3)请确定 .ipa 文件(在清单文件中)的 URL 是否正确,并且该 .ipa 文件是否可供网络用户通过 HTTPS 访问。

  2. 无法连接到“192.168.3.112”:

    1)是否先下载了CA证书

    2)CA证书中的服务器与
    <a href="itms-services://?action=download-manifest&url=https://192.168.3.112/manifest.plist">Install App</a>中的url是否匹配,因为点击下载时,iOS会使用下载下来的CA证书进行验证,只有验证通过才能进行下载安装。比如我就出现这个问题,CA证书中服务器是自己定义的域名,而manifest中的url用的是IP地址。

  3. 无法下载应用程序 此时无法安装“XXX”:

    1)我出现这个问题的原因是,没有提供Xcode打包时,manifest.plist中指定的两个image,将两个相应的image放到web服务器中后就可以下载安装了。

参考文章:
http://help.apple.com/deployment/ios/#/apda0e3426d7
http://www.jianshu.com/p/35ca63ec0d8e
http://www.jianshu.com/p/d006a34a343f

上一篇 下一篇

猜你喜欢

热点阅读