| 228 | |
| 229 | |
| 230 | class CodeSign(SigningTool): |
| 231 | def __init__( |
| 232 | self, |
| 233 | identity_name: str, |
| 234 | prefix: str = None, |
| 235 | ): |
| 236 | # hardcode to system location to avoid accidental clobber in PATH |
| 237 | super().__init__("/usr/bin/codesign") |
| 238 | self.identity_name = identity_name |
| 239 | self.prefix = prefix |
| 240 | |
| 241 | def get_signing_command( |
| 242 | self, |
| 243 | bundle: str | Path, |
| 244 | entitlements: str | Path | None = None, |
| 245 | ) -> list: |
| 246 | command = [ |
| 247 | self.executable, |
| 248 | "--sign", |
| 249 | self.identity_name, |
| 250 | "--force", |
| 251 | "--options", |
| 252 | "runtime", |
| 253 | ] |
| 254 | if self.prefix: |
| 255 | command.extend(["--prefix", self.prefix]) |
| 256 | if entitlements: |
| 257 | command.extend(["--entitlements", str(entitlements)]) |
| 258 | if logger.getEffectiveLevel() == logging.DEBUG: |
| 259 | command.append("--verbose") |
| 260 | command.append(str(bundle)) |
| 261 | return command |
| 262 | |
| 263 | def sign_bundle( |
| 264 | self, |
| 265 | bundle: str | Path, |
| 266 | entitlements: str | Path | dict | None = None, |
| 267 | ): |
| 268 | if isinstance(entitlements, dict): |
| 269 | with NamedTemporaryFile(suffix=".plist", delete=False) as ent_file: |
| 270 | plist_dump(entitlements, ent_file) |
| 271 | command = self.get_signing_command(bundle, entitlements=ent_file.name) |
| 272 | explained_check_call(command) |
| 273 | os.unlink(ent_file.name) |
| 274 | else: |
| 275 | command = self.get_signing_command(bundle, entitlements=entitlements) |
| 276 | explained_check_call(command) |
| 277 | |
| 278 | |
| 279 | def create_windows_signing_tool(info: dict) -> SigningTool | None: |