| OLD | NEW |
| 1 #!/bin/sh | 1 #!/bin/bash -p |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2009 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 application. Inner components are signed as needed, | 7 # Using codesign, sign the contents of the versioned directory. Namely, this |
| 8 # then the outermost bundle is signed, and everything is verified. | 8 # includes the framework and helper app. After signing, the signatures are |
| 9 # verified. |
| 9 | 10 |
| 10 set -e | 11 set -eu |
| 11 | 12 |
| 12 if [ $# -ne 3 ] ; then | 13 # Environment sanitization. Set a known-safe PATH. Clear environment variables |
| 13 echo "usage: ${0} APP_PATH CODESIGN_KEYCHAIN CODESIGN_ID" >& 2 | 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 |
| 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 |
| 18 # unset, only unexported. |
| 19 export PATH="/usr/bin:/bin:/usr/sbin:/sbin" |
| 20 unset BASH_ENV CDPATH ENV GLOBIGNORE IFS POSIXLY_CORRECT |
| 21 export -n SHELLOPTS |
| 22 |
| 23 ME="$(basename "${0}")" |
| 24 readonly ME |
| 25 |
| 26 if [[ ${#} -ne 3 ]]; then |
| 27 echo "usage: ${ME} app_path codesign_keychain codesign_id" >& 2 |
| 14 exit 1 | 28 exit 1 |
| 15 fi | 29 fi |
| 16 | 30 |
| 17 APP_PATH="${1}" | 31 app_path="${1}" |
| 18 CODESIGN_KEYCHAIN="${2}" | 32 codesign_keychain="${2}" |
| 19 CODESIGN_ID="${3}" | 33 codesign_id="${3}" |
| 20 | 34 |
| 21 # Use custom resource rules for the browser application. | 35 versioned_dir="${app_path}/Contents/Versions/@VERSION@" |
| 22 BROWSER_APP_RULES="$(dirname "${0}")/app_resource_rules.plist" | |
| 23 | 36 |
| 24 # An .app bundle to be signed can be signed directly. Normally, signging a | 37 # An .app bundle to be signed can be signed directly. Normally, signging a |
| 25 # framework bundle requires that each version within be signed individually. | 38 # framework bundle requires that each version within be signed individually. |
| 26 # http://developer.apple.com/mac/library/technotes/tn2007/tn2206.html#TNTAG13 | 39 # http://developer.apple.com/mac/library/technotes/tn2007/tn2206.html#TNTAG13 |
| 27 # In Chrome's case, the framework bundle is unversioned, so it too can be | 40 # In Chrome's case, the framework bundle is unversioned, so it too can be |
| 28 # signed directly. See copy_framework_unversioned. | 41 # signed directly. See copy_framework_unversioned. |
| 29 | 42 |
| 30 BROWSER_APP="${APP_PATH}" | 43 framework="${versioned_dir}/@MAC_PRODUCT_NAME@ Framework.framework" |
| 31 FRAMEWORK="${BROWSER_APP}/Contents/Versions/@VERSION@/@MAC_PRODUCT_NAME@ Framewo
rk.framework" | 44 helper_app="${versioned_dir}/@MAC_PRODUCT_NAME@ Helper.app" |
| 32 HELPER_APP="${BROWSER_APP}/Contents/Versions/@VERSION@/@MAC_PRODUCT_NAME@ Helper
.app" | |
| 33 | 45 |
| 34 echo "${0}: signing..." | 46 codesign -s "${codesign_id}" --keychain "${codesign_keychain}" "${framework}" |
| 47 codesign -s "${codesign_id}" --keychain "${codesign_keychain}" "${helper_app}" |
| 35 | 48 |
| 36 # Sign the outer .app last so that its seal includes the signed inner | 49 # Verify everything. |
| 37 # components. | 50 codesign -v "${framework}" |
| 38 | 51 codesign -v "${helper_app}" |
| 39 codesign -s "${CODESIGN_ID}" --keychain "${CODESIGN_KEYCHAIN}" "${FRAMEWORK}" | |
| 40 codesign -s "${CODESIGN_ID}" --keychain "${CODESIGN_KEYCHAIN}" "${HELPER_APP}" | |
| 41 codesign -s "${CODESIGN_ID}" --keychain "${CODESIGN_KEYCHAIN}" \ | |
| 42 "${BROWSER_APP}" --resource-rules "${BROWSER_APP_RULES}" | |
| 43 | |
| 44 # Verify everything to ensure that signing the outer bundle didn't break an | |
| 45 # inner bundle. | |
| 46 | |
| 47 echo "${0}: verifying..." | |
| 48 | |
| 49 codesign -v "${FRAMEWORK}" | |
| 50 codesign -v "${HELPER_APP}" | |
| 51 codesign -v "${BROWSER_APP}" | |
| OLD | NEW |