Module: Cask::Quarantine Private

Extended by:
T::Sig
Defined in:
cask/quarantine.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper module for quarantining files.

Constant Summary collapse

QUARANTINE_ATTRIBUTE =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"com.apple.quarantine"
QUARANTINE_SCRIPT =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

(HOMEBREW_LIBRARY_PATH/"cask/utils/quarantine.swift").freeze

Class Method Summary collapse

Class Method Details

.available?Boolean

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Boolean)


59
60
61
62
63
# File 'cask/quarantine.rb', line 59

def available?
  @status ||= check_quarantine_support

  @status == :quarantine_available
end

.cask!(cask: nil, download_path: nil, action: true) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'cask/quarantine.rb', line 113

def cask!(cask: nil, download_path: nil, action: true)
  return if cask.nil? || download_path.nil?

  return if detect(download_path)

  odebug "Quarantining #{download_path}"

  quarantiner = system_command(swift,
                               args:         [
                                 QUARANTINE_SCRIPT,
                                 download_path,
                                 cask.url.to_s,
                                 cask.homepage.to_s,
                               ],
                               print_stderr: false)

  return if quarantiner.success?

  case quarantiner.exit_status
  when 2
    raise CaskQuarantineError.new(download_path, "Insufficient parameters")
  else
    raise CaskQuarantineError.new(download_path, quarantiner.stderr)
  end
end

.check_quarantine_supportSymbol

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



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
# File 'cask/quarantine.rb', line 31

def check_quarantine_support
  odebug "Checking quarantine support"

  if !system_command(xattr, args: ["-h"], print_stderr: false).success?
    odebug "There's no working version of `xattr` on this system."
    :xattr_broken
  elsif swift.nil?
    odebug "Swift is not available on this system."
    :no_swift
  else
    api_check = system_command(swift,
                               args:         [QUARANTINE_SCRIPT],
                               print_stderr: false)

    case api_check.exit_status
    when 5
      odebug "This feature requires the macOS 10.10 SDK or higher."
      :no_quarantine
    when 2
      odebug "Quarantine is available."
      :quarantine_available
    else
      odebug "Unknown support status"
      :unknown
    end
  end
end

.detect(file) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



65
66
67
68
69
70
71
72
73
74
75
# File 'cask/quarantine.rb', line 65

def detect(file)
  return if file.nil?

  odebug "Verifying Gatekeeper status of #{file}"

  quarantine_status = !status(file).empty?

  odebug "#{file} is #{quarantine_status ? "quarantined" : "not quarantined"}"

  quarantine_status
end

.propagate(from: nil, to: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Raises:



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'cask/quarantine.rb', line 139

def propagate(from: nil, to: nil)
  return if from.nil? || to.nil?

  raise CaskError, "#{from} was not quarantined properly." unless detect(from)

  odebug "Propagating quarantine from #{from} to #{to}"

  quarantine_status = toggle_no_translocation_bit(status(from))

  resolved_paths = Pathname.glob(to/"**/*", File::FNM_DOTMATCH).reject(&:symlink?)

  system_command!("/usr/bin/xargs",
                  args:  [
                    "-0",
                    "--",
                    "/bin/chmod",
                    "-h",
                    "u+w",
                  ],
                  input: resolved_paths.join("\0"))

  quarantiner = system_command("/usr/bin/xargs",
                               args:         [
                                 "-0",
                                 "--",
                                 xattr,
                                 "-w",
                                 QUARANTINE_ATTRIBUTE,
                                 quarantine_status,
                               ],
                               input:        resolved_paths.join("\0"),
                               print_stderr: false)

  return if quarantiner.success?

  raise CaskQuarantinePropagationError.new(to, quarantiner.stderr)
end

.release!(download_path: nil) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'cask/quarantine.rb', line 95

def release!(download_path: nil)
  return unless detect(download_path)

  odebug "Releasing #{download_path} from quarantine"

  quarantiner = system_command(xattr,
                               args:         [
                                 "-d",
                                 QUARANTINE_ATTRIBUTE,
                                 download_path,
                               ],
                               print_stderr: false)

  return if quarantiner.success?

  raise CaskQuarantineReleaseError.new(download_path, quarantiner.stderr)
end

.status(file) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



77
78
79
80
81
# File 'cask/quarantine.rb', line 77

def status(file)
  system_command(xattr,
                 args:         ["-p", QUARANTINE_ATTRIBUTE, file],
                 print_stderr: false).stdout.rstrip
end

.swiftObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



20
21
22
# File 'cask/quarantine.rb', line 20

def swift
  @swift ||= DevelopmentTools.locate("swift")
end

.toggle_no_translocation_bit(attribute) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



83
84
85
86
87
88
89
90
91
92
93
# File 'cask/quarantine.rb', line 83

def toggle_no_translocation_bit(attribute)
  fields = attribute.split(";")

  # Fields: status, epoch, download agent, event ID
  # Let's toggle the app translocation bit, bit 8
  # http://www.openradar.me/radar?id=5022734169931776

  fields[0] = (fields[0].to_i(16) | 0x0100).to_s(16).rjust(4, "0")

  fields.join(";")
end

.xattrObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



25
26
27
# File 'cask/quarantine.rb', line 25

def xattr
  @xattr ||= DevelopmentTools.locate("xattr")
end