Skip to content
This repository has been archived by the owner on Dec 6, 2019. It is now read-only.

Commit

Permalink
Added Xcode unsign feature
Browse files Browse the repository at this point in the history
  • Loading branch information
inket committed Jul 25, 2016
1 parent 257cc1b commit 2d1721b
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 3 deletions.
57 changes: 56 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016
Copyright (c) Mahdi Bchetnia 2016

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,3 +19,58 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


---------------------------------------------------------

---------------------------------------------------------
unsign binary copyright notices
---------------------------------------------------------

---
unsign.c (ISC License)
Retrieved from https://github.com/steakknife/unsign
---

Copyright (c) 2010
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
The software is provided "as is" and the author disclaims all warranties
with regard to this software including all implied warranties of
merchantability and fitness. In no event shall the author be liable for
any special, direct, indirect, or consequential damages or any damages
whatsoever resulting from loss of use, data or profits, whether in an
action of contract, negligence or other tortious action, arising out of
or in connection with the use or performance of this software.


---
endian.c
---

Copyright (c) 2002 Thomas Moestl <tmm@FreeBSD.org>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

$FreeBSD$
2 changes: 2 additions & 0 deletions bin/update_xcode_plugins
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ if CLI.uninstall_launch_agent?
LaunchAgent.uninstall
elsif CLI.install_launch_agent?
LaunchAgent.install(__FILE__)
elsif CLI.unsign_xcode?
XcodeUnsigner.unsign_xcode
else
PluginsUpdater.update_plugins
end
Binary file added lib/bin/unsign
Binary file not shown.
8 changes: 8 additions & 0 deletions lib/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ def self.uninstall_launch_agent?
ARGV.include?('--uninstall-launch-agent')
end

def self.unsign_xcode?
ARGV.include?('--unsign')
end

def self.codesign_exists?
`which codesign` && $CHILD_STATUS.exitstatus == 0
end

{
title: :blue,
process: :magenta,
Expand Down
5 changes: 4 additions & 1 deletion lib/plugins_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ def self.update_plugins

if xcodes.any? { |xcode| xcode.version.to_f >= 8 }
separator
warning 'It seems that you have Xcode >= 8 installed!'
warning 'It seems that you have Xcode 8+ installed!'
puts 'Some plugins might not work on recent versions of Xcode because of library validation.',
"See #{'https://github.com/alcatraz/Alcatraz/issues/475'.underline}"

separator
puts "Run `#{'update_xcode_plugins --unsign'.bold}` to fix this."
end
end
end
4 changes: 4 additions & 0 deletions lib/update_xcode_plugins.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
require 'English'
require 'fileutils'
require 'colorize'
require 'inquirer'
require_relative 'plugins_updater'
require_relative 'xcode_unsigner'
require_relative 'launch_agent'
40 changes: 39 additions & 1 deletion lib/xcode.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require_relative 'bundle'

class Xcode < Bundle
attr_accessor :signed

def self.find_xcodes
output = `mdfind kMDItemCFBundleIdentifier = "com.apple.dt.Xcode"`
output.lines.collect do |xcode_path|
Expand All @@ -20,11 +22,47 @@ def valid?
is_app && has_info
end

def signed?
if signed.nil?
self.signed = `codesign -dv "#{path}" 2>/dev/null` &&
$CHILD_STATUS.exitstatus == 0
end

signed
end

def unsign!
`#{unsign_path} "#{binary_path}"` &&
$CHILD_STATUS.exitstatus == 0 &&
File.exist?(unsigned_binary_path) &&
FileUtils.mv(unsigned_binary_path, binary_path)
end

def uuid
defaults_read('DVTPlugInCompatibilityUUID')
end

def to_s
"Xcode (#{version}) [#{uuid}]: #{path}"
unless signed.nil?
codesign_status = signed ? '[Signed]' : '[Unsigned]'
end

"Xcode (#{version}) [#{uuid}]#{codesign_status}: #{path}"
end

private

def binary_path
"#{path}/Contents/MacOS/Xcode"
end

def unsigned_binary_path
"#{binary_path}.unsigned"
end

def unsign_path
lib_path = File.expand_path(File.dirname(__FILE__))

"#{lib_path}/bin/unsign"
end
end
69 changes: 69 additions & 0 deletions lib/xcode_unsigner.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require_relative 'xcode'

class XcodeUnsigner
extend CLI

def self.unsign_xcode
unless CLI.codesign_exists?
# Not sure if codesign comes pre-installed on fresh macOS, so we'll check
# Send a pull request if you think it does :)
error 'The `codesign` tool could not be found on your system'
return
end

process 'Looking for Xcode...'
xcodes = Xcode.find_xcodes
.select { |xcode| xcode.version.to_f >= 8 }
.select(&:signed?)

separator

if xcodes.empty?
error "Didn't find any Xcode 8+ installed on your system."
return
else
puts notice
end

separator

selection = Ask.list 'Choose which Xcode.app you would like to copy and unsign (use arrows)',
['Cancel', xcodes].flatten
return unless selection && selection != 0

xcode = xcodes[selection - 1]

new_xcode_path = '/Applications/Xcode-unsigned.app'
if Dir.exist?(new_xcode_path)
error 'Xcode-unsigned.app already exists.'
return
end

process 'Copying Xcode... (this might take a while)'
FileUtils.cp_r(xcode.path, new_xcode_path)

process 'Unsigning...'
new_xcode = Xcode.new(new_xcode_path)
if new_xcode.unsign!
success 'Finished! 🎉'
else
error "Could not unsign Xcode-unsigned.app\n"\
'Create an issue on https://github.com/inket/update_xcode_plugins/issues'
end
end

def self.notice
[
'Unsigning Xcode will make it skip library validation allowing it to load plugins.'.colorize(:yellow),
'',
'However, an unsigned Xcode presents security risks, '\
'and will be untrusted by both Apple and your system.'.colorize(:red),
'Please make sure that you have launched this version of Xcode at least '\
'once before unsigning.'.colorize(:red),
'',
'We recommend keeping a signed version of Xcode, so this tool will:',
'- Create a copy of Xcode.app called Xcode-unsigned.app (consider the disk space requirements)',
'- Unsign Xcode-unsigned.app'
]
end
end
1 change: 1 addition & 0 deletions update_xcode_plugins.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Gem::Specification.new do |s|
s.license = 'MIT'

spec.add_runtime_dependency 'colorize', '~> 0.8.1'
spec.add_runtime_dependency 'inquirer', '~> 0.2.1'
end

0 comments on commit 2d1721b

Please sign in to comment.