Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: chrome/installer/mac/sign_versioned_dir.sh.in

Issue 2832073002: Refactor mac signing scripts for development workflow (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/bin/bash -p 1 #!/bin/bash -p
2 2
3 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 3 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be 4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file. 5 # found in the LICENSE file.
6 6
7 # Using codesign, sign the contents of the versioned directory. Namely, this 7 # Using codesign, sign the contents of the versioned directory. Namely, this
8 # includes the framework and helper app. After signing, the signatures are 8 # includes the framework and helper app. After signing, the signatures are
9 # verified. 9 # verified.
10 10
11 set -eu 11 set -eu
12 12
13 # Environment sanitization. Set a known-safe PATH. Clear environment variables 13 # Environment sanitization. Set a known-safe PATH. Clear environment variables
14 # that might impact the interpreter's operation. The |bash -p| invocation 14 # that might impact the interpreter's operation. The |bash -p| invocation
15 # on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among 15 # on the #! line takes the bite out of BASH_ENV, ENV, and SHELLOPTS (among
16 # other features), but clearing them here ensures that they won't impact any 16 # other features), but clearing them here ensures that they won't impact any
17 # shell scripts used as utility programs. SHELLOPTS is read-only and can't be 17 # shell scripts used as utility programs. SHELLOPTS is read-only and can't be
18 # unset, only unexported. 18 # unset, only unexported.
19 export PATH="/usr/bin:/bin:/usr/sbin:/sbin" 19 export PATH="/usr/bin:/bin:/usr/sbin:/sbin"
20 unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT 20 unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT
21 export -n SHELLOPTS 21 export -n SHELLOPTS
22 22
23 ME="$(basename "${0}")" 23 ME="$(basename "${0}")"
24 readonly ME 24 readonly ME
25 25
26 script_dir="$(dirname "${0}")"
27 source "${script_dir}/variables.sh"
28
26 codesign_display_and_verify() { 29 codesign_display_and_verify() {
27 path=${1} 30 path=${1}
28 shift 31 shift
29 32
30 # --verbose can go up to 6 for --display, but that just shows the hash of each 33 # --verbose can go up to 6 for --display, but that just shows the hash of each
31 # ordinary page in the executable, which is more noise than anything else. 34 # ordinary page in the executable, which is more noise than anything else.
32 codesign --display --verbose=5 -r- "${path}" 35 codesign --display --verbose=5 -r- "${path}"
33 codesign --verify --verbose=6 "${@}" "${path}" 36 codesign --verify --verbose=6 "${@}" "${path}"
34 } 37 }
35 38
36 if [[ ${#} -ne 3 ]]; then 39 if [[ ${#} -ne 3 && ${#} -ne 4 ]]; then
37 echo "usage: ${ME} app_path codesign_keychain codesign_id" >& 2 40 echo "usage: ${ME} app_path codesign_keychain codesign_id [--development]" >& 2
38 exit 1 41 exit 1
39 fi 42 fi
40 43
41 app_path="${1}" 44 app_path="${1}"
42 codesign_keychain="${2}" 45 codesign_keychain="${2}"
43 codesign_id="${3}" 46 codesign_id="${3}"
47 is_development=false
48
49 if [[ ${#} == 4 && ${4} == "--development" ]]; then
50 is_development=true
51 fi
44 52
45 versioned_dir="${app_path}/Contents/Versions/@VERSION@" 53 versioned_dir="${app_path}/Contents/Versions/@VERSION@"
46 54
47 # To sign an .app bundle that contains nested code, the nested components 55 # To sign an .app bundle that contains nested code, the nested components
48 # themselves must be signed. Each of these components is signed below. Note 56 # themselves must be signed. Each of these components is signed below. Note
49 # that unless a framework has multiple versions (which is discouraged), signing 57 # that unless a framework has multiple versions (which is discouraged), signing
50 # the entire framework is equivalent to signing the Current version. 58 # the entire framework is equivalent to signing the Current version.
51 # https://developer.apple.com/library/content/technotes/tn2206/_index.html#//app le_ref/doc/uid/DTS40007919-CH1-TNTAG13 59 # https://developer.apple.com/library/content/technotes/tn2206/_index.html#//app le_ref/doc/uid/DTS40007919-CH1-TNTAG13
52 60
53 framework="${versioned_dir}/@MAC_PRODUCT_NAME@ Framework.framework" 61 framework="${versioned_dir}/@MAC_PRODUCT_NAME@ Framework.framework"
54 notification_service="${framework}/XPCServices/AlertNotificationService.xpc" 62 notification_service="${framework}/XPCServices/AlertNotificationService.xpc"
55 crashpad_handler="${framework}/Helpers/crashpad_handler" 63 crashpad_handler="${framework}/Helpers/crashpad_handler"
56 helper_app="${versioned_dir}/@MAC_PRODUCT_NAME@ Helper.app" 64 helper_app="${versioned_dir}/@MAC_PRODUCT_NAME@ Helper.app"
57 app_mode_loader_app="${framework}/Resources/app_mode_loader.app" 65 app_mode_loader_app="${framework}/Resources/app_mode_loader.app"
58 app_mode_loader="${app_mode_loader_app}/Contents/MacOS/app_mode_loader" 66 app_mode_loader="${app_mode_loader_app}/Contents/MacOS/app_mode_loader"
59 67
60 requirement_suffix="\
61 and (certificate leaf = H\"85cee8254216185620ddc8851c7a9fc4dfe120ef\" or \
62 certificate leaf = H\"c9a99324ca3fcb23dbcc36bd5fd4f9753305130a\") \
63 "
64
65 enforcement_flags_app="restrict"
66 enforcement_flags="${enforcement_flags_app},library"
67 68
68 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \ 69 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \
69 "${crashpad_handler}" \ 70 "${crashpad_handler}" \
70 --options "${enforcement_flags}" \ 71 --options "${enforcement_flags_helpers}" \
71 -r="designated => identifier \"crashpad_handler\" \ 72 -r="designated => identifier \"crashpad_handler\" \
72 ${requirement_suffix}" 73 ${requirement_suffix}"
73 74
74 # The app mode loader bundle is modified dynamically at runtime. Just sign the 75 # The app mode loader bundle is modified dynamically at runtime. Just sign the
75 # executable, which shouldn't change. In order to do this, the executable needs 76 # executable, which shouldn't change. In order to do this, the executable needs
76 # to be copied out of the bundle, signed, and then copied back in. The resulting 77 # to be copied out of the bundle, signed, and then copied back in. The resulting
77 # bundle's signature won't validate normally, but if the executable file is 78 # bundle's signature won't validate normally, but if the executable file is
78 # verified in isolation or with --ignore-resources, it will. 79 # verified in isolation or with --ignore-resources, it will.
79 app_mode_loader_tmp="$(mktemp -t app_mode_loader)" 80 app_mode_loader_tmp="$(mktemp -t app_mode_loader)"
80 cp "${app_mode_loader}" "${app_mode_loader_tmp}" 81 cp "${app_mode_loader}" "${app_mode_loader_tmp}"
81 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \ 82 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \
82 "${app_mode_loader_tmp}" \ 83 "${app_mode_loader_tmp}" \
83 --identifier app_mode_loader \ 84 --identifier app_mode_loader \
84 --options "${enforcement_flags}" \ 85 --options "${enforcement_flags_helpers}" \
85 -r="designated => identifier \"app_mode_loader\" \ 86 -r="designated => identifier \"app_mode_loader\" \
86 ${requirement_suffix}" 87 ${requirement_suffix}"
87 cp "${app_mode_loader_tmp}" "${app_mode_loader}" 88 cp "${app_mode_loader_tmp}" "${app_mode_loader}"
88 rm -f "${app_mode_loader_tmp}" 89 rm -f "${app_mode_loader_tmp}"
89 90
90 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \ 91 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \
91 "${notification_service}" \ 92 "${notification_service}" \
92 --options "${enforcement_flags}" \ 93 --options "${enforcement_flags_helpers}" \
93 -r="designated => identifier \"com.google.Chrome.framework.AlertNotification Service\" \ 94 -r="designated => identifier \"com.google.Chrome.framework.AlertNotification Service\" \
94 ${requirement_suffix}" 95 ${requirement_suffix}"
95 96
96 # The framework is a dylib, so ${enforcement_flags} are meaningless. 97 # The framework is a dylib, so ${enforcement_flags_helpers} are meaningless.
97 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \ 98 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \
98 "${framework}" \ 99 "${framework}" \
99 -r="designated => identifier \"com.google.Chrome.framework\" \ 100 -r="designated => identifier \"com.google.Chrome.framework\" \
100 ${requirement_suffix}" 101 ${requirement_suffix}"
101 102
102 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \ 103 codesign --sign "${codesign_id}" --keychain "${codesign_keychain}" \
103 "${helper_app}" \ 104 "${helper_app}" \
104 --options "${enforcement_flags_app}" \ 105 --options "${enforcement_flags_app}" \
105 -r="designated => identifier \"com.google.Chrome.helper\" \ 106 -r="designated => identifier \"com.google.Chrome.helper\" \
106 ${requirement_suffix}" 107 ${requirement_suffix}"
107 108
108 # Show the signatures and verify everything. 109 # Show the signatures and verify everything.
109 codesign_display_and_verify "${crashpad_handler}" --deep 110 codesign_display_and_verify "${crashpad_handler}" --deep
110 codesign_display_and_verify "${app_mode_loader}" --ignore-resources 111 codesign_display_and_verify "${app_mode_loader}" --ignore-resources
111 codesign_display_and_verify "${notification_service}" --deep 112 codesign_display_and_verify "${notification_service}" --deep
112 codesign_display_and_verify "${framework}" --deep 113 codesign_display_and_verify "${framework}" --deep
113 codesign_display_and_verify "${helper_app}" --deep 114 codesign_display_and_verify "${helper_app}" --deep
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698