-
Notifications
You must be signed in to change notification settings - Fork 1
/
encrypt_all.rb
62 lines (51 loc) · 1.61 KB
/
encrypt_all.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
#!/usr/bin/env ruby
origins_path = "origins"
TYPES = ["development", "distribution", "enterprise", "appstore", "adhoc"]
password = ENV['MATCH_PASSWORD']
if password == nil
puts "Input your decrypt password:"
password = gets
end
PASSWORD = password
def iterate(source_path, ext)
Dir[File.join(source_path, "**", "*.#{ext}")].each do |path|
next if File.directory?(path)
yield(path)
end
end
def en_cert(path)
name = File.basename(path)
base_path = path.gsub(name,"")
cert_id = File.basename(path, ".*")
out_path = base_path.gsub("origins/", "")
`mkdir -p #{out_path}`
`openssl pkcs12 -nocerts -nodes -out #{out_path}key.pem -in #{base_path}#{cert_id}.p12`
`openssl aes-256-cbc -k "#{PASSWORD}" -in #{out_path}key.pem -out #{out_path}#{cert_id}.p12 -a`
`openssl aes-256-cbc -k "#{PASSWORD}" -in #{base_path}#{cert_id}.cer -out #{out_path}#{cert_id}.cer -a`
`rm #{out_path}key.pem`
end
def en_profile(path)
name = File.basename(path)
base_path = path.gsub(name,"")
file = path
bundle_id = File.basename(path, ".*")
prefixs = ["Development", "Distribution", "InHouse", "AppStore", "AdHoc"]
prefix = ""
for i in 0..TYPES.count
if path.include? TYPES[i]
prefix = prefixs[i]
break
end
end
out_path = base_path.gsub("origins/", "")
`mkdir -p #{out_path}`
`openssl aes-256-cbc -k "#{PASSWORD}" -in #{file} -out #{out_path}#{prefix}_#{bundle_id}.mobileprovision -a`
end
certs_path = origins_path + "/certs/"
iterate(certs_path, "p12") do |path|
en_cert(path)
end
mps_path = origins_path + "/profiles/"
iterate(mps_path, "mobileprovision") do |path|
en_profile(path)
end