diff --git a/BUILD.md b/BUILD.md index c5c91d7..60a85ec 100644 --- a/BUILD.md +++ b/BUILD.md @@ -87,3 +87,95 @@ After that you can launch GPG Sync during development with: ``` python -m pipenv run python dev_scripts\dangerzone ``` + +### If you want to build a .exe + +These instructions include adding folders to the path in Windows. To do this, go to Start and type "advanced system settings", and open "View advanced system settings" in the Control Panel. Click Environment Variables. Under "System variables" double-click on Path. From there you can add and remove folders that are available in the PATH. + +Download and install the [Windows 10 SDK](https://developer.microsoft.com/en-US/windows/downloads/windows-10-sdk/). + +Add the following directories to the path: + +* `C:\Program Files (x86)\Windows Kits\10\bin\10.0.18362.0\x86` +* `C:\Program Files (x86)\Windows Kits\10\Redist\10.0.18362.0\ucrt\DLLs\x86` + +### If you want the .exe to not get falsely flagged as malicious by anti-virus software + +Dangerzone uses PyInstaller to turn the python source code into Windows executable `.exe` file. Apparently, malware developers also use PyInstaller, and some anti-virus vendors have included snippets of PyInstaller code in their virus definitions. To avoid this, you have to compile the Windows PyInstaller bootloader yourself instead of using the pre-compiled one that comes with PyInstaller. + +Here's how to compile the PyInstaller bootloader: + +Download and install [Microsoft Build Tools for Visual Studio 2017](https://www.visualstudio.com/downloads/#build-tools-for-visual-studio-2019). I downloaded `vs_buildtools__1378184674.1581551596.exe`. In the installer, check the box next to "C++ build tools". Click "Individual components", and under "Compilers, build tools and runtimes", check "Windows Universal CRT SDK". Then click install. When installation is done, you may have to reboot your computer. + +Then, enable the 32-bit Visual C++ Toolset on the Command Line like this: + +``` +cd "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build" +vcvars32.bat +``` + +Change to a folder where you keep source code, and clone the PyInstaller git repo and checkout the `v3.6` tag: + +``` +git clone https://github.com/pyinstaller/pyinstaller.git +cd pyinstaller +git tag -v v3.6 +``` + +(Note that ideally you would verify the git tag, but the PGP key that has signed the v3.5 git tag for is not published anywhere, so this isn't possible. See [this issue](https://github.com/pyinstaller/pyinstaller/issues/4430).) + +The next step is to compile the bootloader. We should do this all in dangerzone's pipenv though: + +``` +cd dangerzone +pipenv shell +cd ..\pyinstaller +``` + +Then, compile the bootloader: + +``` +cd bootloader +python waf distclean all --target-arch=32bit --msvc_targets=x86 +``` + +Finally, install the PyInstaller module into your pipenv: + +``` +python setup.py install +exit +``` + +Now the next time you use PyInstaller to build GPG Sync, the `.exe` file should not be flagged as malicious by anti-virus. + +### If you want to build the installer + +* Go to http://nsis.sourceforge.net/Download and download the latest NSIS. I downloaded `nsis-3.05-setup.exe`. +* Add `C:\Program Files (x86)\NSIS` to the path. + +### If you want to sign binaries with Authenticode + +* You'll need a code signing certificate. I got an open source code signing certificate from [Certum](https://www.certum.eu/certum/cert,offer_en_open_source_cs.xml). +* Once you get a code signing key and certificate and covert it to a pfx file, import it into your certificate store. + +## To make a .exe + +Open a command prompt, cd into the dangerzone directory, and run: + +``` +pipenv run pyinstaller install\pyinstaller\pyinstaller.spec +``` + +`dangerzone.exe` and all of their supporting files will get created inside the `dist` folder. + +### To build the installer + +Note that you must have a codesigning certificate installed in order to use the `install\windows\build_exe.bat` script, because it codesigns `dangerzone.exe`, `uninstall.exe`, and `dangerzone-setup.exe`. + +Open a command prompt, cd to the dangerzone directory, and run: + +``` +pipenv run install\build_exe.bat +``` + +This will prompt you to codesign three binaries and execute one unsigned binary. When you're done clicking through everything you will have `dist\dangerzone-setup.exe`. \ No newline at end of file diff --git a/Pipfile b/Pipfile index 0ac87f2..9514a74 100644 --- a/Pipfile +++ b/Pipfile @@ -7,14 +7,17 @@ name = "pypi" PyQt5 = "*" click = "*" appdirs = "*" -pyxdg = {version = "*",platform_system = "== 'Linux'"} -pyobjc-core = {version = "*",platform_system = "== 'Darwin'"} -pyobjc-framework-launchservices = {version = "*",platform_system = "== 'Darwin'"} requests = "*" +pyxdg = {version = "*",sys_platform = "== 'linux'"} +pyobjc-core = {version = "*",sys_platform = "== 'darwin'"} +pyobjc-framework-launchservices = {version = "*",sys_platform = "== 'darwin'"} [dev-packages] black = "*" -pyinstaller = "*" +# Windows pyinstaller we build from source +pyinstaller = {version = "*",sys_platform = "== 'darwin'"} +setuptools = {version = "*",sys_platform = "== 'win32'"} +pywin32 = {version = "*",sys_platform = "== 'win32'"} [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index 87570ae..fa6c48c 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "695116394343f7849640651aff1c6957762111bbe2905e3e4d4473be4d6dfb43" + "sha256": "89bd5b1770c4cab967141570476976c60d97ce9949d9cb5431bef3034aa98a6f" }, "pipfile-spec": 6, "requires": { @@ -61,7 +61,7 @@ "sha256:8ccf44511cbe438fa6562c423c0c5f1dad7cfc0eadd6d8f112840f8845b44fda" ], "index": "pypi", - "markers": "platform_system == 'Darwin'", + "markers": "sys_platform == 'darwin'", "version": "==6.1" }, "pyobjc-framework-cocoa": { @@ -97,7 +97,7 @@ "sha256:944b8ce7fb4215019bb55bd48b46685032d8db3fc2ff8cd80dfe56356cd99fd2" ], "index": "pypi", - "markers": "platform_system == 'Darwin'", + "markers": "sys_platform == 'darwin'", "version": "==6.1" }, "pyqt5": { @@ -139,7 +139,7 @@ "sha256:fe2928d3f532ed32b39c32a482b54136fe766d19936afc96c8f00645f9da1a06" ], "index": "pypi", - "markers": "platform_system == 'Linux'", + "markers": "sys_platform == 'linux'", "version": "==0.26" }, "requests": { @@ -216,8 +216,28 @@ "sha256:3730fa80d088f8bb7084d32480eb87cbb4ddb64123363763cf8f2a1378c1c4b7" ], "index": "pypi", + "markers": "sys_platform == 'darwin'", "version": "==3.6" }, + "pywin32": { + "hashes": [ + "sha256:300a2db938e98c3e7e2093e4491439e62287d0d493fe07cce110db070b54c0be", + "sha256:31f88a89139cb2adc40f8f0e65ee56a8c585f629974f9e07622ba80199057511", + "sha256:371fcc39416d736401f0274dd64c2302728c9e034808e37381b5e1b22be4a6b0", + "sha256:47a3c7551376a865dd8d095a98deba954a98f326c6fe3c72d8726ca6e6b15507", + "sha256:4cdad3e84191194ea6d0dd1b1b9bdda574ff563177d2adf2b4efec2a244fa116", + "sha256:7c1ae32c489dc012930787f06244426f8356e129184a02c25aef163917ce158e", + "sha256:7f18199fbf29ca99dff10e1f09451582ae9e372a892ff03a28528a24d55875bc", + "sha256:9b31e009564fb95db160f154e2aa195ed66bcc4c058ed72850d047141b36f3a2", + "sha256:a929a4af626e530383a579431b70e512e736e9588106715215bf685a3ea508d4", + "sha256:c054c52ba46e7eb6b7d7dfae4dbd987a1bb48ee86debe3f245a2884ece46e295", + "sha256:f27cec5e7f588c3d1051651830ecc00294f90728d19c3bf6916e6dba93ea357c", + "sha256:f4c5be1a293bae0076d93c88f37ee8da68136744588bc5e2be2f299a34ceb7aa" + ], + "index": "pypi", + "markers": "sys_platform == 'win32'", + "version": "==227" + }, "regex": { "hashes": [ "sha256:07b39bf943d3d2fe63d46281d8504f8df0ff3fe4c57e13d1656737950e53e525", @@ -244,6 +264,10 @@ ], "version": "==2020.1.8" }, + "setuptools": { + "sys_platform": "== 'win32'", + "version": "*" + }, "toml": { "hashes": [ "sha256:229f81c57791a41d65e399fc06bf0848bab550a9dfd5ed66df18ce5f05e73d5c", diff --git a/install/macos/build_app.py b/install/macos/build_app.py index 20d0410..b0e7bbb 100755 --- a/install/macos/build_app.py +++ b/install/macos/build_app.py @@ -40,7 +40,7 @@ def main(): shutil.rmtree(dist_path) print("○ Building app bundle") - run(["pyinstaller", "install/macos/pyinstaller.spec", "--clean"]) + run(["pyinstaller", "install/pyinstaller/pyinstaller.spec", "--clean"]) shutil.rmtree(os.path.join(dist_path, "dangerzone")) print(f"○ Finished build app: {app_path}") diff --git a/install/macos/pyinstaller.spec b/install/macos/pyinstaller.spec deleted file mode 100644 index e5f3e26..0000000 --- a/install/macos/pyinstaller.spec +++ /dev/null @@ -1,159 +0,0 @@ -# -*- mode: python -*- -import sys -import os -import inspect - -# Get the version -root = os.path.dirname( - os.path.dirname( - os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) - ) -) -sys.path.insert(0, root) -import dangerzone - -version = dangerzone.dangerzone_version -print("Flock Agent version: {}".format(version)) - -a = Analysis( - ["dangerzone"], - pathex=["."], - binaries=None, - datas=[("../../share", "share"), ("document.icns", ".")], - hiddenimports=[], - hookspath=[], - runtime_hooks=[], - excludes=[], - win_no_prefer_redirects=False, - win_private_assemblies=False, - cipher=None, -) - -pyz = PYZ(a.pure, a.zipped_data, cipher=None) - -exe = EXE( - pyz, - a.scripts, - exclude_binaries=True, - name="dangerzone", - debug=False, - strip=False, - upx=True, - console=False, -) - -coll = COLLECT( - exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name="dangerzone" -) - -app = BUNDLE( - coll, - name="Dangerzone.app", - icon="dangerzone.icns", - bundle_identifier="media.firstlook.dangerzone", - info_plist={ - "NSHighResolutionCapable": True, - "CFBundleShortVersionString": version, - "CFBundleDocumentTypes": [ - { - "CFBundleTypeExtensions": ["pdf"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": ["application/pdf"], - "CFBundleTypeName": "PDF Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["docx", "doc"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": [ - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "application/msword", - ], - "CFBundleTypeName": "Microsoft Word Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["xlsx", "xls"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": [ - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", - "application/vnd.ms-excel", - ], - "CFBundleTypeName": "Microsoft Excel Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["pptx", "ppt"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": [ - "application/vnd.openxmlformats-officedocument.presentationml.presentation", - "application/vnd.ms-powerpoint", - ], - "CFBundleTypeName": "Microsoft PowerPoint Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["odg"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": ["application/vnd.oasis.opendocument.text"], - "CFBundleTypeName": "ODF Text Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["ops"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": [ - "application/vnd.oasis.opendocument.spreadsheet" - ], - "CFBundleTypeName": "ODF Spreadsheet Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["odp"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": [ - "application/vnd.oasis.opendocument.presentation" - ], - "CFBundleTypeName": "ODF Presentation Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["odg"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": [ - "application/vnd.oasis.opendocument.graphics" - ], - "CFBundleTypeName": "ODF Graphics Document", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["jpg", "jpeg"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": ["image/jpeg"], - "CFBundleTypeName": "JPEG Image", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["gif"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": ["image/gif"], - "CFBundleTypeName": "GIF Image", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["png"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": ["image/png"], - "CFBundleTypeName": "PNG Image", - "CFBundleTypeRole": "Viewer", - }, - { - "CFBundleTypeExtensions": ["tif", "tiff"], - "CFBundleTypeIconFile": "document.icns", - "CFBundleTypeMIMETypes": ["image/tiff", "image/x-tiff"], - "CFBundleTypeName": "TIFF Image", - "CFBundleTypeRole": "Viewer", - }, - ], - }, -) diff --git a/install/macos/dangerzone b/install/pyinstaller/dangerzone similarity index 100% rename from install/macos/dangerzone rename to install/pyinstaller/dangerzone diff --git a/install/pyinstaller/pyinstaller.spec b/install/pyinstaller/pyinstaller.spec new file mode 100644 index 0000000..41944fa --- /dev/null +++ b/install/pyinstaller/pyinstaller.spec @@ -0,0 +1,171 @@ +# -*- mode: python -*- +import sys +import os +import inspect +import platform + +p = platform.system() + +# Get the version +root = os.path.dirname( + os.path.dirname( + os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + ) +) +sys.path.insert(0, root) +import dangerzone + +version = dangerzone.dangerzone_version +print("Flock Agent version: {}".format(version)) + +if p == "Darwin": + datas = [("../../share", "share"), ("../macos/document.icns", ".")] +else: + datas = [("../../share", "share")] + +a = Analysis( + ["dangerzone"], + pathex=["."], + binaries=None, + datas=datas, + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=None, +) + +pyz = PYZ(a.pure, a.zipped_data, cipher=None) + +exe = EXE( + pyz, + a.scripts, + exclude_binaries=True, + name="dangerzone", + debug=False, + strip=False, + upx=True, + console=False, +) + +coll = COLLECT( + exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name="dangerzone" +) + +# The macOS app bundle +if p == "Darwin": + app = BUNDLE( + coll, + name="Dangerzone.app", + icon="dangerzone.icns", + bundle_identifier="media.firstlook.dangerzone", + info_plist={ + "NSHighResolutionCapable": True, + "CFBundleShortVersionString": version, + "CFBundleDocumentTypes": [ + { + "CFBundleTypeExtensions": ["pdf"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": ["application/pdf"], + "CFBundleTypeName": "PDF Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["docx", "doc"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + "application/msword", + ], + "CFBundleTypeName": "Microsoft Word Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["xlsx", "xls"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "application/vnd.ms-excel", + ], + "CFBundleTypeName": "Microsoft Excel Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["pptx", "ppt"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.openxmlformats-officedocument.presentationml.presentation", + "application/vnd.ms-powerpoint", + ], + "CFBundleTypeName": "Microsoft PowerPoint Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["odg"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.oasis.opendocument.text" + ], + "CFBundleTypeName": "ODF Text Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["ops"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.oasis.opendocument.spreadsheet" + ], + "CFBundleTypeName": "ODF Spreadsheet Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["odp"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.oasis.opendocument.presentation" + ], + "CFBundleTypeName": "ODF Presentation Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["odg"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": [ + "application/vnd.oasis.opendocument.graphics" + ], + "CFBundleTypeName": "ODF Graphics Document", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["jpg", "jpeg"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": ["image/jpeg"], + "CFBundleTypeName": "JPEG Image", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["gif"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": ["image/gif"], + "CFBundleTypeName": "GIF Image", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["png"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": ["image/png"], + "CFBundleTypeName": "PNG Image", + "CFBundleTypeRole": "Viewer", + }, + { + "CFBundleTypeExtensions": ["tif", "tiff"], + "CFBundleTypeIconFile": "document.icns", + "CFBundleTypeMIMETypes": ["image/tiff", "image/x-tiff"], + "CFBundleTypeName": "TIFF Image", + "CFBundleTypeRole": "Viewer", + }, + ], + }, + )