/
signing.rb
112 lines (90 loc) · 3.04 KB
/
signing.rb
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
require './libs/encryption.rb'
# Creates the signing configuration for the build.
#
# @param folder Folder of the certificate and provisioning profile
# @param key Decryption key for the certificate and provisioning profile
def create_signing_configuration(folder, key)
decrypt(folder, key)
keychain_name = 'ios_build.keychain'
keychain_password = key # only for temporary use
create_keychain({
name: keychain_name,
password: keychain_password,
})
unlock_keychain({
path: FastlaneCore::Helper.keychain_path(keychain_name),
add_to_search_list: true,
set_default: true,
password: keychain_password
})
import_certificates_in_keychain(
folder,
FastlaneCore::Helper.keychain_path(keychain_name),
keychain_password
)
copy_mobile_provisioning_profiles(folder)
end
# Imports certificates from a folder to the keychain
#
# @param folder Folder of the certificate and provisioning profile
# @param keychain_path Path for the temporary keychain
# @param keychain_password Password for the temporary keychain
def import_certificates_in_keychain(folder, keychain_path, keychain_password)
supported_extensions = [".p12", ".cer"]
Find.find(folder) do |file|
next if !supported_extensions.include?(File.extname(file))
puts "import: " + file
FastlaneCore::KeychainImporter.import_file(
file,
keychain_path,
keychain_password: keychain_password,
output: FastlaneCore::Globals.verbose?)
end
end
# Copies mobile provisioning profiles from a folder to the Provisioning Profiles folder
#
# @param folder Folder of the certificate and provisioning profile
def copy_mobile_provisioning_profiles(folder)
supported_extensions = [".mobileprovision"]
Find.find(folder) do |file|
next if !supported_extensions.include?(File.extname(file))
basename = File.basename(file)
FileUtils.mkdir_p("#{Dir.home}/Library/MobileDevice/Provisioning\ Profiles/")
FileUtils.cp(file, "#{Dir.home}/Library/MobileDevice/Provisioning\ Profiles/#{basename}")
end
end
# Removes the temporary keychain
def remove_keychain
keychain_name = 'ios_build.keychain'
delete_keychain ({
name: keychain_name
})
end
# Deletes encrypted certificates for a configuration
#
# @param configuration Configuration for the build
def delete_certificates(folder)
supported_extensions = [".p12", ".cer"]
Find.find(folder) do |file|
next if !supported_extensions.include?(File.extname(file))
FileUtils.rm(file)
end
end
# Deletes encrypted mobile provisioning profiles
#
# @param configuration Configuration for the build
def delete_mobile_provisioning_profiles(folder)
supported_extensions = [".mobileprovision"]
Find.find(folder) do |file|
next if !supported_extensions.include?(File.extname(file))
FileUtils.rm(file)
end
end
# Clears the signing configuration and deletes the certificates, profiles and keychains
#
# @param configuration Configuration for the build
def clear_signing_configuration(folder)
delete_certificates(folder)
delete_mobile_provisioning_profiles(folder)
remove_keychain
end