使用match证书管理

使用match证书管理

流程说明

目录结构

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-certs
-enterprise
-#{cert_id}.cer
-#{cert_id}.p12

-development
-#{cert_id}.cer
-#{cert_id}.p12

-distribution
-#{cert_id}.cer
-#{cert_id}.p12

-profiles
-enterprise
-InHouse_#{bundle_id}.mobileprovision

-appstore
-AppStore_#{bundle_id}.mobileprovision

-adhoc
-AdHoc_#{bundle_id}.mobileprovision

-development
-Development_#{bundle_id}.mobileprovision

自动化配置证书

cert和profile文件使用OpenSSL加密,需要通过设置环境变量MATCH_PASSWORD来解密,如果没有设置,则match会尝试去钥匙链的密码列表中寻找名称为match_#{:git_url}的钥匙串项,如果仍然没有,则需要用户手动输入。在CI环境中,最好事先设置环境变量MATCH_PASSWORD

match获取cert流程

首先,根据:type指定的类型,如development,则match遍历仓库的/certs/development/目录下的所有文件,将文件名符合*.cer格式的最后一个当做签名证书,将文件名符合*.p12格式的最后一个当做其对应私钥。
如果签名证书和其私钥都存在,则将签名证书的文件名去掉扩展名,剩余部分作为此证书的id。
如果签名证书或其私钥不存在,则异常退出。

使用说明

如何使用

  1. 安装fastlane sudo gem install fastlane

  2. 安装证书:在项目路径下 fastlane match <development/adhoc/appstore> --readonly

    注:为避免match 重新生成新证书,请添加--readonly

手动生成证书

1
2
3
openssl pkcs12 -nocerts -nodes -out key.pem -in #{export_cert_name}.p12
openssl aes-256-cbc -k #{password} -in key.pem -out #{cert_id}.p12 -a
openssl aes-256-cbc -k #{password} -in #{export_cert_name}.cer -out #{cert_id}.cer -a

手动解密证书

1
openssl aes-256-cbc -k #{password} -in #{need_decrypt_path} -out #{decrypted_file_path} -a -d

打印证书列表

创建ruby.rb文件,将以下代码复制进去,替换苹果账号

1
2
3
4
5
6
7
8
9
require 'spaceship'

Spaceship.login('yourappid@xxx.com')
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