Python3-打包脚本之解析p12文件与描述证书

2019-07-31  本文已影响0人  037e3257fa3b

脚本自动导出ipa包时需要导入证书到keychain以及读取描述文件中的信息。

iOS自动打包脚本会用到的相关命令

将下列Log.printError()修改为print()即可

    @staticmethod
    def parseP12File(p12File,password):
        importResult = os.system("security import %s -k ~/Library/Keychains/login.keychain -P \"%s\" -T /usr/bin/codesign"%(p12File,password))
        if importResult != 0:
            Log.printError("导入p12失败")
            exit()
        infoResult = os.popen("openssl pkcs12 -nodes -in %s -info -nokeys -passin 'pass:%s' 2>/dev/null | grep 'friendlyName'"%(p12File,password))
        friendlyName = ProjectUtil.readLine(infoResult)
        friendlyName = friendlyName.replace("friendlyName:","").strip()
        Log.printInfo(friendlyName)
        return friendlyName


    @staticmethod
    def parseMobileProvision(mobileFile):
        mobileInfo = MobileProvisionInfo()
        # os.system("touch tmp_provisionProfile.plist")
        # provisonPath = os.getcwd() + "/tmp_provisionProfile.plist"
        # print(provisonPath)
        inputResult = os.system("openssl smime -in %s -inform der -verify >tmp_provisionProfile.plist"%mobileFile)
        if inputResult != 0:
            Log.printError("导出mobileProvision信息失败")
            exit()

        originUUID = os.popen("/usr/libexec/PlistBuddy -c 'print UUID' tmp_provisionProfile.plist")
        uuid = ProjectUtil.readLine(originUUID)
        mobileInfo.uuid = uuid

        originName = os.popen("/usr/libexec/PlistBuddy -c 'print Name' tmp_provisionProfile.plist")
        name = ProjectUtil.readLine(originName)
        mobileInfo.name = name

        originTeamId = os.popen("/usr/libexec/PlistBuddy -c 'print TeamIdentifier:0' tmp_provisionProfile.plist")
        teamId = ProjectUtil.readLine(originTeamId)
        mobileInfo.teamId = teamId

        if os.path.isfile("~/Library/MobileDevice/Provisioning Profiles/%s.mobileprovision"%(uuid)):
            Log.printInfo("%s.mobileprovision文件已经加载"%(uuid))
        else:
            instalResult = os.system("open %s"%(mobileFile))
            if instalResult != 0:
                Log.printInfo("加载%s.mobileprovison失败"%(uuid))

        return mobileInfo
上一篇下一篇

猜你喜欢

热点阅读