Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

Implement verification of signing on Windows for release builds

Dmitry Kazakov7e47b0fb66cd
diff --git a/build-tools/ci-scripts/build-windows-package.py b/build-tools/ci-scripts/build-windows-package.py
index d665fea85c..51db1dbe93 100644
--- a/build-tools/ci-scripts/build-windows-package.py
+++ b/build-tools/ci-scripts/build-windows-package.py
@@ -105,7 +105,7 @@ if arguments.build_installers:
shutil.move(os.path.join(installerFolder, 'krita-nsis', installerFileName), os.getcwd())
if signPackages:
- commandToRun = ' '.join([sys.executable,
+ commandToRun = ' '.join([sys.executable, '-u',
os.path.join('ci-notary-service', 'signwindowsbinaries.py'),
'--config', os.environ['KRITACI_WINDOWS_SIGN_CONFIG'],
installerFileName
@@ -119,6 +119,18 @@ if arguments.build_installers:
print("## Failed to sign the installer")
sys.exit(1)
+ if arguments.release_package_naming:
+ try:
+ print("## Verify that the installer is signed")
+ commandToRun = ' '.join([sys.executable, '-u',
+ os.path.join('packaging', 'windows', 'find-libs-with-debug.py'),
+ '-s', '-f', installerFileName
+ ])
+ subprocess.check_call( commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True )
+ except Exception:
+ print("## Failed to verify the installer signature")
+ sys.exit(1)
+
msixFolder = os.path.join(os.getcwd(), '_msix')
os.makedirs(msixFolder)
diff --git a/build-tools/ci-scripts/requirements-windows.txt b/build-tools/ci-scripts/requirements-windows.txt
new file mode 100644
index 0000000000..2e7b6b3264
--- /dev/null
+++ b/build-tools/ci-scripts/requirements-windows.txt
@@ -0,0 +1,10 @@
+#
+# This file is autogenerated by pip-compile with Python 3.13
+# by the following command:
+#
+# pip-compile --generate-hashes --output-file=requirements-windows.txt requirements-windows.txt.in
+#
+pefile==2024.8.26 \
+ --hash=sha256:3ff6c5d8b43e8c37bb6e6dd5085658d658a7a0bdcd20b6a07b1fcfc1c4e9d632 \
+ --hash=sha256:76f8b485dcd3b1bb8166f1128d395fa3d87af26360c2358fb75b80019b957c6f
+ # via -r requirements-windows.txt.in
diff --git a/build-tools/ci-scripts/requirements-windows.txt.in b/build-tools/ci-scripts/requirements-windows.txt.in
new file mode 100644
index 0000000000..5088fdbf33
--- /dev/null
+++ b/build-tools/ci-scripts/requirements-windows.txt.in
@@ -0,0 +1 @@
+pefile
\ No newline at end of file
diff --git a/build-tools/ci-scripts/sign-windows-package-at-notary-service.py b/build-tools/ci-scripts/sign-windows-package-at-notary-service.py
index 5d40be05be..12953e1eea 100644
--- a/build-tools/ci-scripts/sign-windows-package-at-notary-service.py
+++ b/build-tools/ci-scripts/sign-windows-package-at-notary-service.py
@@ -10,6 +10,10 @@ parser.add_argument("pkg_root", action='store', help="Specify the package root")
args = parser.parse_args()
pkg_root = args.pkg_root
+release_package_naming = False
+if 'KRITACI_RELEASE_PACKAGE_NAMING' in os.environ:
+ release_package_naming = (os.environ['KRITACI_RELEASE_PACKAGE_NAMING'].lower() in ['true', '1', 't', 'y', 'yes'])
+
print(f"Signing binaries in {pkg_root}")
if not os.path.isdir(pkg_root):
print(f"ERROR: No packaging dir {pkg_root}")
@@ -32,3 +36,11 @@ with open("files-to-sign.txt", 'w') as toSign:
commandToRun = f"{sys.executable} -u ci-notary-service/signwindowsbinaries.py --config {KRITACI_WINDOWS_SIGN_CONFIG} --files-from files-to-sign.txt"
subprocess.check_call(commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True )
+
+if release_package_naming:
+ print(f"Verify that all executables have a signature in {pkg_root}")
+ commandToRun = f"{sys.executable} -u packaging/windows/find-libs-with-debug.py -s -d {pkg_root}"
+ subprocess.check_call(commandToRun, stdout=sys.stdout, stderr=sys.stderr, shell=True )
+
+
+
diff --git a/build-tools/ci-scripts/windows.yml b/build-tools/ci-scripts/windows.yml
index c6b747fcdf..8e5e2a9b3d 100644
--- a/build-tools/ci-scripts/windows.yml
+++ b/build-tools/ci-scripts/windows.yml
@@ -36,6 +36,7 @@
- . venv\Scripts\Activate.ps1
- pip install -r krita-deps-management/requirements.txt
- pip install -r ci-notary-service/requirements.txt
+ - pip install -r build-tools/ci-scripts/requirements-windows.txt
script:
- git config --global --add safe.directory $CI_PROJECT_DIR
- python -u krita-deps-management/tools/replace-branch-in-seed-file.py krita-deps-management/latest/krita-deps.yml -p -o branch-corrected-deps.yml -d $EFFECTIVE_DEPS_BRANCH_NAME
diff --git a/packaging/windows/find-libs-with-debug.py b/packaging/windows/find-libs-with-debug.py
index af36256aa1..8fbd0bc05e 100644
--- a/packaging/windows/find-libs-with-debug.py
+++ b/packaging/windows/find-libs-with-debug.py
@@ -39,11 +39,15 @@ def has_certificate_entry(filePath):
return pe.OPTIONAL_HEADER.DATA_DIRECTORY[address].Size > 0
parser = argparse.ArgumentParser(description=f'Searches for {', '.join(glob_patterns)} files with DEBUG section present.')
-parser.add_argument('-d', '--directory', default=os.getcwd(), help='Directory to search (default: current directory)')
+parser.add_argument('-d', '--directory', default=None, help='Directory to search (default: current directory)')
+parser.add_argument('-f', '--file', default=None, help='Executable file to check')
if has_pefile:
parser.add_argument('-s', '--signature', action='store_true', default=False, help='Verify that all modules in the directory has signature entry (no signature validation happens)')
args = parser.parse_args()
+if args.directory is None and args.file is None:
+ args.directory = os.getcwd()
+
OBJDUMP = False
for arg in ("objdump", "llvm-objdump"):
commandToRun = f"{arg} --version"
@@ -57,7 +61,9 @@ if not OBJDUMP:
anyLibsWithDebugFound = False
anyUnsignedFound = False
-for file in find_files(args.directory):
+def verify_one_file(file):
+ global anyLibsWithDebugFound
+ global anyUnsignedFound
try:
if has_pefile and args.signature:
if not has_certificate_entry(file):
@@ -71,5 +77,12 @@ for file in find_files(args.directory):
warnings.warn(f"ERROR: Failed to parse: {file}")
raise e
+if args.directory is not None:
+ for file in find_files(args.directory):
+ verify_one_file(file)
+
+if args.file is not None:
+ verify_one_file(args.file)
+
if anyLibsWithDebugFound or anyUnsignedFound:
sys.exit(2)
\ No newline at end of file