美文网首页
Fastlane 根据p12证书手动生成Match管理证书并 配

Fastlane 根据p12证书手动生成Match管理证书并 配

作者: marlonxlj | 来源:发表于2019-05-09 09:42 被阅读0次

    fastlane match 根据p12文件手动生成Match管理需要的证书。

    最近项目的情况是,由于公司产品发布的appstore账户的切换后,该appstore上已经存在了3个账户,已经无法生成match管理的证书了。只发了一个p12的正式的证书。

    下面的根据上面的情况,做的流程。
    注意:因为还有一个包含fastlane上传appstore的记录在本文中,所以看上去会有点乱。


    Fastlane 配置上传至AppStore相关


    生成appstore证书

    fastlane match appstore
    
    

    工具集说明如下:

    1. scan

    自动运行测试工具,并且可以生成HTML文档报告

    2. cert

    自动创建和管理iOS签名证书(Certificates)

    3. sigh

    创建、更新、下载、修复Provisioning Profiles的工具

    4. pem

    自动生成、更新推送配置文件

    5. snapshot

    使用Xcode7的UITest功能实现自动化截图

    6. frameit

    把截取的图片套上一层外边框

    7.gym

    自动化编译工具,用来打包ipa或者pkg文件

    8.deliver

    自动上传截图、App的元数据、二进制(ipa)文件到iTunes Connect

    9.produce

    在iTunes Connect或者Apple Developer Center上创建新的iOS应用程序

    上传至AppStore 需要创建:deliver

    安装方法:

    sudo gem install deliver
    
    

    初始化:deliver

    fastlane deliver
    
    

    报错信息:

    [!] The request could not be completed because:
        Could not set team ID to 'XXX', only found the following available teams:
    
    - 1********* (Mo**** ****** ***** (****) Co., Ltd.)
    - 1********* (Si**** ****** ***** ***** Co., Ltd.)
    
    

    原因是:team ID to 'XXX'不对

    修改id后成功,生成:metadata获取appconnect上面填写的基本信息, screenshots文件夹,是截屏的图片保存

    这里有个小问题,iTC和ADC中的Team ID是不一样的,在fastlane init中只会自动在Appfile里写入ADC的team_id,所以在这个过程中会不停的问你iTC的Team ID,所以在创建完Appfile后,手动在里面添加itc_team_id。
    app_identifier "com.**.**" # The bundle identifier of your app  
    username "njafei@163.com" # your Apple ID user
    force true #don’t show me the preview html
    submit_for_review false # 这个开关就是控制是否要展示的
    
    

    根据p12证书生成match需要的证书


    根据p12证书生成match需要的证书

    p12证书的密码:123456

    1. 拿到你想要复用证书的ID

    关于这个证书ID,从钥匙串和openssl工具库中没有找到方法来取到,但是可以通过spaceship这个库来实现,下面是相关脚本:

    这个脚本为fastlane里面的,需要单独创建;

    命令:
    fastlane spaceship
    
    

    报错提示:Could not find gem 'pry'

    安装:

    sudo gem install pry
    
    

    这是一个ruby脚本,需要创建ruby脚本,然后在运行这个脚本:

    require 'spaceship'
    Spaceship.login('38****@qq.com') #自己的AppID账号
    Spaceship.select_team
    Spaceship.certificate.all.each do |cert| 
      cert_type = Spaceship::Portal::Certificate::CERTIFICATE_TYPE_IDS[cert.type_display_id].to_s.split("::")[-1]
      puts "Cert id: #{cert.id}, name: #{cert.name}, expires: #{cert.expires.strftime("%Y-%m-%d")}, type: #{cert_type}"
    end
    
    

    执行上面代码,会输出所有证书的相应信息,你可以从中找到你想复用的那个证书的ID。

    
    ➜  推送证书相关 touch get_cer_id.rb
    ➜  推送证书相关 open .
    ➜  推送证书相关 ruby get_cer_id.rb 
    Multiple teams found on the Developer Portal, please enter the number of the team you want to use: 
    1) 247W*****8R "M****n ***** **** (****) Co., Ltd." (Company/Organization)
    2) 68Y******86 "S****** C****y **** Technology Co., Ltd." (Company/Organization)
    1
    Cert id: 3********, name: iOS Development, expires: 2019-05-18, type: Development
    Cert id: D*******, name: iOS Distribution, expires: 2019-05-18, type: Production
    Cert id: 2*******, name: iOS Development, expires: 2019-08-31, type: Development
    Cert id: 4********, name: iOS Development, expires: 2019-09-04, type: Development
    Cert id: X*********, name: APNs Development iOS, expires: 2019-09-04, type: DevelopmentPush
    Cert id: T*********, name: Apple Push Services, expires: 2019-10-04, type: ProductionPush
    Cert id: 9*******, name: iOS Distribution, expires: 2019-09-04, type: Production
    Cert id: 2*******, name: iOS Development, expires: 2019-09-19, type: Development
    Cert id: X********, name: iOS Distribution, expires: 2019-12-27, type: Production
    Cert id: Y********, name: APNs Development iOS, expires: 2020-05-06, type: DevelopmentPush
    Cert id: R*******, name: Apple Push Services, expires: 2020-06-05, type: ProductionPush
    Cert id: Y******, name: iOS Development, expires: 2020-05-06, type: Development
    ➜  推送证书相关 
    
    
    

    生成加密的证书:

    从Apple Developer中下载现有的证书及mobileprovision文件,将证书导入到钥匙中,并生成p12文件。得到的证书和配置文件还不能被match识别,需要通过加密命令加密后才符合match的验证要求,其中使用到的命令有:

    备注: bundleid 的绑定是根据match文件里面的bundleid来匹配的

    1、 生成key.pem文件;加密证书

    执行生成.pem文件,p12证书为想使用的p12证书,如果在哪个路径下面在执行这个,会在当面目录下生成pem的文件
    openssl pkcs12 -nocerts -nodes -out dev_key.pem -in dev.p12
    
    

    2、生成最后需要的证书

    2.1 生成:cret_id.p12文件

    2.2 生成:certificate.cer文件

    openssl aes-256-cbc -k <your_password> -in dev_key.pem -out <cert_id>.p12 -a
    openssl aes-256-cbc -k <your_password> -in dev.cer -out <cert_id>.cer -a
    
    

    pem.key 的密码是:123456
    dev: 123456
    dis: 123456

    到此配置基本结束,但是还有工作没有完成,很重要需要:

    fastlane match nuke development
    fastlane match nuke distribution
    fastlane match nuke appstore
    
    

    如果这里遇到问题,删除不了的话,就只有手动去开发网站删除。后再次创建描述文件就可以了:

    fastlane match adhoc
    fastlane match development
    fastlane match appstore
    
    

    总结:

    1. 最大的问题是因为对match的证书的反制作过程不了解原理
    2. 根据p12文件,安装到本地的keychain中,然后对其进行导出一个dis.cer文件,因存在dis.p12文件而不用再次导出。
    3. 因为dev的证书是直接从appstore中下载的,所以需要导出一个dev.cer文件,一个dev.p12文件
    4. 关于没个创建证书的时候会填写的creat_id是根据那个ruby脚本获取到的信息里找到到期时间匹配的id

    文章写的有点乱,可能有错误的地方,因时间关系,没有做仔细的校验工作。
    如有问题请issue me

    借鉴原文地址

    相关文章

      网友评论

          本文标题:Fastlane 根据p12证书手动生成Match管理证书并 配

          本文链接:https://www.haomeiwen.com/subject/uvyvoqtx.html