]> git.saurik.com Git - apple/security.git/blob - certificates/ota_cert_tool/Scripts/File.rb
Security-57031.30.12.tar.gz
[apple/security.git] / certificates / ota_cert_tool / Scripts / File.rb
1 #
2 # File.rb
3 # ios_ota_cert_tool
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 :verbose
19
20 def validate_path(path, isDir = true)
21 return false if path.nil? || path.empty?
22 return false if !FileTest.exists?(path)
23 return false if isDir != FileTest.directory?(path)
24 true
25 end
26
27 def ensure_directory(path)
28 if !FileTest.exists?(path)
29 FileUtils.mkdir_p(path)
30 end
31 end
32
33 def initialize(input_dir, output_directory, staging_directory = "/tmp/staging")
34
35 @verbose = true
36
37 puts "In BuildPKIAsset.initialize" if @verbose
38 puts "input_dir = #{input_dir}" if @verbose
39 puts "output_directory = #{output_directory}" if @verbose
40 puts "staging_directory = #{staging_directory}" if @verbose
41
42 # Check the input parameter
43 if !validate_path(input_dir)
44 puts "Invalid base directory given: #{input_dir}"
45 exit
46 end
47
48 @base_path = File.expand_path(input_dir)
49
50 if output_directory.nil? || output_directory.empty?
51 puts "No output directory was given"
52 exit
53 end
54
55 exit if `xcodebuild -sdk iphoneos.internal -find assettool`.nil?
56
57 @output_directory = File.expand_path(output_directory)
58
59 @asset_directory = File.join(@output_directory, "Assets")
60 ensure_directory(@asset_directory)
61
62 @asset_top_directory = File.join(@asset_directory, "SecurityCertificatesAssets")
63 ensure_directory(@asset_top_directory)
64
65 @asset_data_directory = File.join(@asset_top_directory, "AssetData/PKITrustData")
66 ensure_directory(@asset_data_directory)
67
68 @staging_directory = File.expand_path(staging_directory)
69 ensure_directory(@staging_directory)
70
71
72 puts "@base_path = #{@base_path }" if @verbose
73 puts "@output_directory = #{@output_directory }" if @verbose
74 puts "@asset_directory = #{@asset_directory }" if @verbose
75 puts "@asset_top_directory = #{@asset_top_directory }" if @verbose
76 puts "@asset_data_directory = #{@asset_data_directory }" if @verbose
77 puts "@staging_directory = #{@staging_directory }" if @verbose
78
79 puts "Done with BuildPKIAsset.initialize" if @verbose
80
81 end
82
83 def stage
84
85 puts "In BuildPKIAsset.stage" if @verbose
86
87 #copy over the files into the asset directory
88 input_plist_file_path = File.join(@base_path, "Info.plist")
89 if !FileTest.exists?(input_plist_file_path)
90 puts "The asset data Info.plist file is missing #{input_plist_file_path}"
91 exit
92 end
93
94 puts "input_plist_file_path = #{input_plist_file_path}" if @verbose
95
96 FileUtils.cp(input_plist_file_path, @asset_top_directory)
97
98 puts "About to copy over the plist files" if @verbose
99
100 # copy all of the necessary files into the asset data directory
101 file_list = %w(EVRoots.plist certs.plist revoked.plist Manifest.plist distrusted.plist roots.plist)
102 file_list.each do |file|
103 file_path = File.join(@base_path, file)
104 if !FileTest.exists?(file_path)
105 puts "#{file_path} is missing in the base directory"
106 exit
107 end
108 FileUtils.cp(file_path, @asset_data_directory)
109 end
110
111 puts "Completed copying over the plist files" if @verbose
112
113 puts "About to call assettool stage" if @verbose
114 `xcrun -sdk iphoneos.internal assettool stage -p #{@asset_directory} -s #{@staging_directory}`
115 puts "Completed call to assettool stage" if @verbose
116
117 puts "Done with BuildPKIAsset.stage" if @verbose
118 end
119
120 def sign
121 puts "In BuildPKIAsset.sign" if @verbose
122 puts "About to call assettool sign" if @verbose
123 `xcrun -sdk iphoneos.internal assettool sign -s #{@staging_directory}`
124 puts "Completed call to assettool sign" if @verbose
125 puts "Done with BuildPKIAsset.sign" if @verbose
126 end
127
128 end
129
130 =begin
131 The following code is here ONLY for testing
132 =end
133
134 #b = BuildPKIAsset.new(File.expand_path("~/cert_out"), File.expand_path("~/bobby_cert"))
135 #b.stage
136 #b.sign
137 #puts "That's all folks@"
138
139
140
141