def sign(fileNames: [str]) -> bool: if not CraftCore.settings.getboolean("CodeSigning", "Enabled", False): return True if not CraftCore.compiler.isWindows: CraftCore.log.warning( "Code signing is currently only supported on Windows") return True signTool = CraftCore.cache.findApplication("signtool") if not signTool: env = SetupHelper.getMSVCEnv() signTool = CraftCore.cache.findApplication("signtool", env["PATH"]) if not signTool: CraftCore.log.warning( "Code signing requires a VisualStudio installation") return False subjectName = CraftCore.settings.get("CodeSigning", "SubjectName") command = [ signTool, "sign", "/n", subjectName, "/tr", "http://timestamp.digicert.com", "/td", "SHA256", "/fd", "SHA256", "/a" ] if CraftCore.debug.verbose() > 0: command += ["/v"] else: command += ["/q"] for fileName in fileNames: if not system(command + [fileName], logCommand=False): return False return True
def signWindows(fileNames: [str]) -> bool: if not CraftCore.settings.getboolean("CodeSigning", "Enabled", False): return True if not CraftCore.compiler.isWindows: CraftCore.log.warning( "Code signing is currently only supported on Windows") return True signTool = CraftCore.cache.findApplication("signtool", forceCache=True) if not signTool: env = SetupHelper.getMSVCEnv() signTool = CraftCore.cache.findApplication("signtool", env["PATH"], forceCache=True) if not signTool: CraftCore.log.warning( "Code signing requires a VisualStudio installation") return False command = [ signTool, "sign", "/tr", "http://timestamp.digicert.com", "/td", "SHA256", "/fd", "SHA256", "/a" ] certFile = CraftCore.settings.get("CodeSigning", "Certificate", "") subjectName = CraftCore.settings.get("CodeSigning", "CommonName", "") certProtected = CraftCore.settings.getboolean("CodeSigning", "Protected", False) kwargs = dict() if certFile: command += ["/f", certFile] if subjectName: command += ["/n", subjectName] if certProtected: password = CraftChoicePrompt.promptForPassword( message='Enter the password for your package signing certificate', key="WINDOWS_CODE_SIGN_CERTIFICATE_PASSWORD") command += ["/p", password] kwargs["secret"] = [password] if True or CraftCore.debug.verbose() > 0: command += ["/v"] else: command += ["/q"] for args in utils.limitCommandLineLength(command, fileNames): if not utils.system(args, **kwargs): return False return True