iOS

iOS 超级签

2021-11-21  本文已影响0人  贾小敏1234

签名原理

使用了苹果提供给开发者的Ad-Hoc分发通道,把安装设备当做开发设备进行分发。

优势:
直接分发,安装即可运行
稳定,不会有证书吊销导致的风险

缺点:
单开发者账号的iPhone设备数量只有100个

整体架构

5d5e06d190ed3.png

设备安装描述文件后,会向服务器发送设备的UDID。
服务器收到UDID后,将UDID注册到某个开发者账号下。
再生成签名用的描述文件,给IPA签名。
然后iPA传Server,使用itms-services方式让用户下载。

一、使用配置文件获取UDID

在你的Web服务器上创建一个.mobileconfig的描述文件;
用户点击完成.mobileconfig描述文件的安装;
服务器需要的数据,比如:UDID,需要在.mobileconfig描述文件中配置好,以及服务器接收数据的URL地址;
当用户设备安装描述文件后,设备会回调你设置的URL
注:.mobileconfig的demo如下:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 <dict>
     <key>PayloadContent</key>
     <dict>
         <key>URL</key>
         <string>http://192.168.1.40/data/receive.php</string> <!--接收数据的接口地址-->
         <key>DeviceAttributes</key>
         <array>
             <string>UDID</string>
             <string>IMEI</string>
             <string>ICCID</string>
             <string>VERSION</string>
             <string>PRODUCT</string>
         </array>
     </dict>
     <key>PayloadOrganization</key>
     <string>com.sssss.orgName</string>  <!--组织名称-->
     <key>PayloadDisplayName</key>
     <string>获取设备UDID</string>  <!--安装时显示的标题-->
     <key>PayloadVersion</key>
     <integer>1</integer>
     <key>PayloadUUID</key>
     <string>3C4DC7D2-E475-3375-489C-0BB8D737A653</string>  <!--随机填写的字符串-->
     <key>PayloadIdentifier</key>
     <string>dev.skyfox.profile-service</string>
     <key>PayloadDescription</key>
     <string>获取设备UDID</string>   <!--描述-->
     <key>PayloadType</key>
     <string>Profile Service</string>
 </dict>
</plist>

注意:mobileconfig下载时设置文件内容类型Content Type为:application/x-apple-aspen-config

HTTPS服务器上的文件
当访问mobileconfig文件不能直接下载时,可能就需要设置mime content type了,application/x-apple-aspen-config,
设置content type大体上两种方法
.htaccess增加如下配置

<IfModule mod_mime.c>
     AddType application/x-apple-aspen-config .mobileconfig
</IfModule>

php等动态语言直接设置

//读取文件流为$mobileconfig
header('Content-type: application/x-apple-aspen-config; chatset=utf-8');
header('Content-Disposition: attachment; filename="test.mobileconfig"');
echo $mobileconfig;

服务器接收返回数据并显示

设置好mobileconfig文件中的URL,并且下载安装mobileconfig之后,iOS设备会POST XML数据流给你的mobileconfig文件,PayloadContent节点中设置的URL。以下是返回数据的格式

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
   <dict>
     <key>IMEI</key>
     <string>*********</string>
     <key>PRODUCT</key>
     <string>iPhone7,1</string>
     <key>UDID</key>
     <string>*************</string>
     <key>VERSION</key>
     <string>15B206</string>
   </dict>
 </plist>

receive.php

<?php
$data = file_get_contents('php://input');
//这里可以进行xml解析
header('HTTP/1.1 301 Moved Permanently');  //这里一定要301跳转,否则设备安装会提示"无效的描述文件"
header("Location: http://192.168.1.40/udid.php?".$params);
?>

index.php

<?php
$UDID =  $_GET['UDID'] ? $_GET['UDID'] : $_POST['UDID'];
?>
UDID:<input style="width:300px;" name="" value="<?php echo $UDID;?>" />

值得注意的是重定向一定要使用301重定向,有些重定向默认是302重定向,这样就会导致安装失败,设备安装会提示”无效的描述文件
获取UDID第三方库

Apple Developer Center 自动化工具

接下来的就是在获取到用户的UDID之后,注册新的开发者设备+更新Provisioning Profile。 这里需要借助开源工具:Spaceship
[Apple Developer Center]

添加设备命令:

Spaceship::Portal.device.create!(name: "Private iPhone 6", udid: "32123898...")
下载描述文件:
profiles_appstore_adhoc = Spaceship::Portal.provisioning_profile.ad_hoc.all
File.write("NFname.mobileprovision", profile.download)

自动签名

推荐使用 Sigh 这个框架(只能mac环境), 还可以使用开心命令行签名工具,利用p12证书来实现在linux服务器上也能重签名。

自动签名封包工具

分发已签名的应用

可参照部署企业包的方式

上一篇下一篇

猜你喜欢

热点阅读