]> git.saurik.com Git - apple/security.git/blob - certificates/CertificateTool/BuildiOSAsset/BuildAsset.rb
Security-57031.1.35.tar.gz
[apple/security.git] / certificates / CertificateTool / BuildiOSAsset / BuildAsset.rb
1 #
2 # BuildAsset.rb
3 # CertificateTool
4 #
5 # Copyright 2012 Apple Inc. All rights reserved.
6 #
7
8 require 'FileUtils'
9
10 class BuildPKIAsset
11 attr_reader :ios_SDK_path
12 attr_reader :base_path
13 attr_reader :output_directory
14 attr_reader :asset_directory
15 attr_reader :asset_top_directory
16 attr_reader :asset_data_directory
17 attr_reader :staging_directory
18 attr_reader :info_plist_path
19 attr :verbose
20
21 def validate_path(path, isDir = true)
22 return false if path.nil? || path.empty?
23 return false if !FileTest.exists?(path)
24 return false if isDir != FileTest.directory?(path)
25 true
26 end
27
28 def output_str(str, header = false)
29 return if !@verbose
30
31 puts "=====================================================" if header
32 puts str if !str.nil?
33 end
34
35 def ensure_directory(path)
36 FileUtils.mkdir_p path if !validate_path(path)
37 validate_path(path)
38 end
39
40
41 def initialize(input_dir, output_directory, project_path, staging_directory, verbose = false)
42
43 @verbose = verbose
44
45 output_str(nil, true)
46 output_str "In BuildPKIAsset.initialize"
47 output_str "input_dir = #{input_dir}"
48 output_str "output_directory = #{output_directory}"
49 output_str "staging_directory = #{staging_directory}"
50 output_str(nil, true)
51 output_str( " ")
52
53 # Check the input parameter
54 if !ensure_directory(input_dir)
55 puts "Invalid base directory given: #{input_dir}"
56 exit
57 end
58
59 @base_path = File.expand_path(input_dir)
60
61 @info_plist_path = File.join(File.join(File.expand_path(project_path), "CertificateTool"), "Info.plist")
62
63 if !FileTest.exists? @info_plist_path
64 puts "Could not find the Info.plist file"
65 exit
66 end
67
68
69 if output_directory.nil? || output_directory.empty?
70 puts "No output directory was given"
71 exit
72 end
73
74 asset_tool_path = `xcodebuild -sdk iphoneos.internal -find assettool`
75 if asset_tool_path.nil?
76 puts "Unable to find the mobile asset tool in the iPhone SDK"
77 exit
78 end
79
80
81 @output_directory = File.expand_path(output_directory)
82
83 @asset_directory = File.join(@output_directory, "Assets")
84 ensure_directory(@asset_directory)
85
86 @asset_top_directory = File.join(@asset_directory, "SecurityCertificatesAssets")
87 ensure_directory(@asset_top_directory)
88
89 @asset_data_directory = File.join(@asset_top_directory, "AssetData/PKITrustData")
90 ensure_directory(@asset_data_directory)
91
92 @staging_directory = File.expand_path(staging_directory)
93 ensure_directory(@staging_directory)
94
95
96 output_str(nil, true)
97 output_str "@base_path = #{@base_path }"
98 output_str "@output_directory = #{@output_directory }"
99 output_str "@asset_directory = #{@asset_directory }"
100 output_str "@asset_top_directory = #{@asset_top_directory }"
101 output_str "@asset_data_directory = #{@asset_data_directory }"
102 output_str "@staging_directory = #{@staging_directory }"
103 output_str "@info_plist_path = #{@info_plist_path}"
104 output_str "Done with BuildPKIAsset.initialize"
105 output_str(nil, true)
106 output_str( " ")
107
108 end
109
110 def stage
111
112 output_str(nil, true)
113 output_str "In BuildPKIAsset.stage"
114 output_str(nil, true)
115 output_str( " ")
116
117 #copy over the files into the asset directory
118 input_plist_file_path = @info_plist_path
119
120 output_str(nil, true)
121 output_str "input_plist_file_path = #{input_plist_file_path}"
122
123 FileUtils.cp(input_plist_file_path, @asset_top_directory)
124
125 output_str "About to copy over the plist files"
126
127 # copy all of the necessary files into the asset data directory
128 file_list = %w(AppleESCertificates.plist AssetVersion.plist Blocked.plist GrayListedKeys.plist EVRoots.plist certsIndex.data certsTable.data manifest.data)
129 file_list.each do |file|
130 file_path = File.join(@base_path, file)
131 if !FileTest.exists?(file_path)
132 output_str(nil, true)
133 output_str( " ")
134 puts "#{file_path} is missing in the base directory"
135 exit
136 end
137 FileUtils.cp(file_path, @asset_data_directory)
138 end
139
140 output_str "Completed copying over the plist files"
141
142 output_str "About to call assettool stage"
143 `xcrun -sdk iphoneos.internal assettool stage -p #{@asset_directory} -s #{@staging_directory}`
144 output_str "Completed call to assettool stage"
145 output_str(nil, true)
146 output_str( " ")
147
148 output_str(nil, true)
149 output_str "Done with BuildPKIAsset.stage"
150 output_str(nil, true)
151 output_str( " ")
152 end
153
154 def sign
155 output_str(nil, true)
156 output_str "In BuildPKIAsset.sign"
157 output_str "About to call assettool sign"
158 `xcrun -sdk iphoneos.internal assettool sign -s #{@staging_directory}`
159 output_str "Completed call to assettool sign"
160 output_str "Done with BuildPKIAsset.sign"
161 output_str(nil, true)
162 output_str( " ")
163 end
164
165 end
166
167 @verbose = false
168
169 def do_output_str(str, header = false)
170 return if !@verbose
171
172 puts "=====================================================" if header
173 puts str if !str.nil?
174 end
175
176 build_dir = ENV["BUILT_PRODUCTS_DIR"]
177 project_dir = ENV["PROJECT_DIR"]
178
179 do_output_str "Environment variables"
180 do_output_str " "
181 do_output_str "build_dir = #{build_dir}"
182 do_output_str "project_dir = #{project_dir}"
183 do_output_str(nil, true)
184 do_output_str(" ")
185
186 input_path = File.join(build_dir, "asset_out")
187 output_path = File.join(build_dir, "Asset")
188 staging_path = File.join(build_dir, "staging")
189 asset_name = "com_apple_MobileAsset_PKITrustServices_PKITrustData"
190 full_asset_path = File.join(staging_path, asset_name)
191
192 do_output_str(nil, true)
193 do_output_str "Path variables"
194 do_output_str " "
195 do_output_str "input_path = #{input_path}"
196 do_output_str "output_path = #{output_path}"
197 do_output_str "staging_path = #{staging_path}"
198 do_output_str "full_asset_path = #{full_asset_path}"
199 do_output_str(nil, true)
200 do_output_str(" ")
201
202 do_output_str(nil, true)
203 do_output_str "Creating a BuildPKIAsset object to stage and sign the asset"
204 b = BuildPKIAsset.new(input_path, output_path, project_dir, staging_path, @verbose)
205 b.stage
206 b.sign
207
208 do_output_str "Finished with BuildAsset"
209 do_output_str(nil, true)
210 do_output_str(" ")
211
212 do_output_str(nil, true)
213 do_output_str "Output Path variables"
214 do_output_str(" ")
215 do_output_str "build_dir = #{build_dir}"
216 do_output_str "full_asset_path = #{full_asset_path}"
217
218 #FileUtils.cp_r(full_asset_path, build_dir)
219
220 do_output_str "That's all folks!"
221 do_output_str(nil, true)
222 do_output_str(" ")