• iOS ipa 重签名 resign


    这篇关于codesign的文章不错 https://www.objccn.io/issue-17-2/ 英文原文:https://www.objc.io/issues/17-security/inside-code-signing/

    第二篇 http://blog.cnbang.net/tech/3386/

    首先ipa重签名并不是一个程序发布的标准途径,多用于特殊情况。作用就是让因签名问题无法运行在真机上的ipa能在真机上顺利运行。

    因为我要在ios10上测试,而网上的教程大多比较早,曾经一度认为这种重签名方法在ios10上失效了,结果是自己没有用对命令。

    重签名的核心就是运行codesign命令,不但需要签名程序,还需要对ipa中的embeded framework进行签名(没使用就不用了),否则会闪退。

    详细的步奏我就不写了,请参考:http://stackoverflow.com/questions/6896029/re-sign-ipa-iphone 

    这里列出2个关键命令:


    //重签名应用
    /usr/bin/codesign -f -s "iPhone Distribution: xxx" --entitlements entitlements.plist Payload/12121212.app //重签名应用中的embeded framework(如果存在的话就需要运行) /usr/bin/codesign -f -s "iPhone Distribution: xxx" --entitlements entitlements.plist Payload/12121212.app/Frameworks/* 

    对framrworks中的文件签名,再利用codesign 命令查看,可以有如下截图

    MacBook-Air:test Rufus$ codesign -vv -d /Users/Rufus/Desktop/test/Payload/12121212.app/Frameworks/libswiftDarwin.dylib 
    Executable=/Users/Rufus/Desktop/test/Payload/12121212.app/Frameworks/libswiftDarwin.dylib
    Identifier=com.apple.dt.runtime.swiftDarwin
    Format=Mach-O universal (armv7 armv7s arm64)
    CodeDirectory v=20200 size=1024 flags=0x0(none) hashes=24+5 location=embedded
    Signature size=4714
    Authority=iPhone Distribution: xxx(隐藏了)
    Authority=Apple Worldwide Developer Relations Certification Authority
    Authority=Apple Root CA
    Signed Time=24 Apr 2017, 1:34:52 PM
    Info.plist entries=5
    TeamIdentifier= xxx(隐藏了)
    Sealed Resources=none
    Internal requirements count=1 size=200

    可以看到,这个dylib被顺利签名了。

    另外,对12121212.app的签名,其实就是对其中的2进制文件12121212进行了签名,还顺便计算了一下app中的其他文件的hash值,保存在了_CodeSignature下的CodeResources文件中。

    codesign命令针对的就是 可执行2进制文件 和 动态链接库文件,其他的比如png,nib等资源文件,一概不会codesign。

     这里 entitlements.plist 比较关键,先贴出一个基本的配置

    <?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>application-identifier</key>
        <string>xxx.com.xxx.xxx</string>
        <key>get-task-allow</key>
        <false/>
    </dict>
    </plist>

    如果ipa中使用了keychain,还需要向entitlements加入下面这对键值,并且,要修改info.plist文件里的bundle id。

    <key>keychain-access-groups</key>
    <array>
            <string>xxx.com.xxx.xxx</string>
    </array>

    说到这里,重签名能够把别人ipa重新签名,当成自己的ipa向app store 发布吗?我们测试一下

    测试过程如下,我使用公司的账户签名一个企业级应用,之后使用自己的帐号吧这个ipa重签名,并上传到app sotre。

    由于xcode默认只支持使用xarchiver 上传,而我们这里是ipa文件,所以我们使用Application Loader上传。

    首先,我使用了最基本的重签名方式,即:没有改变ipa的bundle id。上传出现了错误:

    看来必须把bundle id改了才行。修改info.plist中的bundle id后,再次上传,进行到了下面的步奏,卡住不动了:

    经过了漫长app上传和校验过程,返回了错误:

    ERROR ITMS-90035: "Invalid Signature. A sealed resource is missing or invalid. Make sure you have signed your application with a distribution certificate, not an ad hoc certificate or a development certificate. Verify that the code signing settings in Xcode are correct at the target level (which override any values at the project level). Additionally, make sure the bundle you are uploading was built using a Release target in Xcode, not a Simulator target. If you are certain your code signing settings are correct, choose "Clean All" in Xcode, delete the "build" directory in the Finder, and rebuild your release target. For more information, please consult https://developer.apple.com/library/ios/documentation/Security/Conceptual/CodeSigningGuide/Introduction/Introduction.html"

    没什么有意思的信息,就是提示签名是有问题的,无法上传app store。

    要明白为什么苹果认为这个ipa是非法的,就需要仔细研究一下ipa签名的过程了。

  • 相关阅读:
    本地坐标转世界坐标为什么是 先缩放后旋转再平移
    cocos子节点转父节点坐标 原理浅析(局部坐标转世界坐标同理)
    Github上关于iOS的各种开源项目集合2(强烈建议大家收藏,查看,总有一款你需要)
    Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)
    Masonry基本语法
    WebStorm 10.0.4注册码
    如何让CCLayer创造的地图,左右滑动不出现黑边
    GitHub 上排名前 100 的 Objective-C 项目简介
    C语言fmod()函数:对浮点数取模(求余)
    查看笔记本最大支持内存
  • 原文地址:https://www.cnblogs.com/breezemist/p/6756585.html
Copyright © 2020-2023  润新知