Skip to content

Commit 78356a2

Browse files
committed
Add verifing component pkg files mechanism.
1 parent fab68c5 commit 78356a2

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/xcode/install.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ def apply_variables(template)
576576
class InstalledXcode
577577
TEAM_IDENTIFIER = '59GAB85EFG'.freeze
578578
AUTHORITY = 'Apple Mac OS Application Signing'.freeze
579+
COMPONENT_SIGNING_COMMON_NAME = 'Apple Software'.freeze
579580

580581
attr_reader :path
581582
attr_reader :version
@@ -637,7 +638,7 @@ def install_components
637638
if Gem::Version.new(version) >= Gem::Version.new('9')
638639
`sudo #{@path}/Contents/Developer/usr/bin/xcodebuild -runFirstLaunch`
639640
else
640-
Dir.glob("#{@path}/Contents/Resources/Packages/*.pkg").each do |pkg|
641+
component_pkg_paths.each do |pkg|
641642
`sudo installer -pkg #{pkg} -target /`
642643
end
643644
end
@@ -655,7 +656,7 @@ def fetch_version
655656
end
656657

657658
def verify_integrity
658-
verify_app_security_assessment && verify_app_cert
659+
verify_app_security_assessment && verify_app_cert && verify_components
659660
end
660661

661662
:private
@@ -684,6 +685,20 @@ def verify_app_cert
684685
apple_authority_result = cert_info['authority'].include?(AUTHORITY)
685686
apple_team_identifier_result && apple_authority_result
686687
end
688+
689+
def verify_components
690+
return true if Gem::Version.new(version) >= Gem::Version.new('9')
691+
692+
result = component_pkg_paths.map do |pkg|
693+
result = `pkgutil --verbose --check-signature #{pkg} | grep 'Status'`
694+
result.strip.split(':')[1].strip == "signed #{COMPONENT_SIGNING_COMMON_NAME}"
695+
end
696+
result.all?
697+
end
698+
699+
def component_pkg_paths
700+
@component_paths ||= Dir.glob(File.join(@path, 'Contents/Resources/Packages/*.pkg'))
701+
end
687702
end
688703

689704
# A version of Xcode we fetched from the Apple Developer Portal

0 commit comments

Comments
 (0)