Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSIS differential updates support #267

Merged
merged 4 commits into from
Jan 2, 2021
Merged

Conversation

JJ-8
Copy link
Contributor

@JJ-8 JJ-8 commented Dec 25, 2020

This PR will add support for NSIS differential updates for Windows. The differential updates are tested using electron-builder.

Please read the commit body of 9a441a379648842949a6cbce7280f16633e5d588 to get an understanding of what is changed and why.

The hashing algorithm and encoding has changed from sha256-hex to sha512-base64 to match with electron-builder. I don't know if this will cause breaking changes to other update mechanisms. I tried to use sha256-hex, but it seems to be broken in electron-builder. Now it 100% matches the .yml files generated by electron-builder.

Also, I have added documentation for using NSIS differential updates and how to configure electron-builder correctly.

Relates to the following issues:

The NSIS differential update support is tested with electron-builder (https://www.electron.build/)

The AssetService.getHash function is rewritten to match the hash check
of electron-builder:
https://github.com/electron-userland/electron-builder/blob/552f1a4ed6f4bb83c3c548ed962c21142f07a9b4/packages/electron-updater/src/DownloadedUpdateHelper.ts#L161
They use base64 encoding for storing the hash (instead of hex), so now
we have an extra parameter to controll the encoding.

This paramter is used for calculating the hash of a .exe or .zip file.
We also switch to sha512 because the sha256 check does not work correctly
for the differential update support of electron-builder.

Also, the latest.yml (or beta.yml / alpha.yml) now matches the .yml files
that are generated by electron-builder.
This is done for Windows and Mac .yml files.
However, differential updates do not work for MacOS because electron-builder
doesn't properly support it.

For the differential updates to work, you have to upload a blockmap.
So now the .blockmap files are also accepted as uploaded files.
There are some specific requirements for electron-builder to get
differential updates to work.
@DustinBrett
Copy link
Collaborator

Code looks good. Could there be an issue/conflict with pre-existing hashes? If nobody sees a concern I will approve/merge. Thanks for the PR!

The `${os}` will expand to `win` and not `win32` (`win32` is`${platform}`)
If you use `${arch}`, Electron Release Server will automatically pick the right architecture for you.
So we can just add that to the update url.
@JJ-8
Copy link
Contributor Author

JJ-8 commented Jan 1, 2021

The pre-existing hashes won't change. Only new uploads will include the sha512-base64 version.
However, I found the following cases where only sha256-hex is used and not sha512-base64:

This could result in issues, but I don't know if this is also the case.
What we can try, is to not replace the sha256-hex, but only add the sha512-base64. It seems that electron-builder supports sha512-base64 by default, but the Windows build could also have a sha256-hex.
We need to store an additional sha512-base64 hash. However, I haven't looked into the database part and I have no experience with it. And it doesn't guarantee that it will both support the old format and the NSIS differential updates.

I have also fixed some documentation issues.

@DustinBrett
Copy link
Collaborator

Sounds good. I think we can merge this then and if trouble arises adjustments could be made. Thanks again!

@DustinBrett DustinBrett merged commit e09629c into ArekSredzki:master Jan 2, 2021
Monaz4 pushed a commit to Monaz4/electron-release-server that referenced this pull request Mar 20, 2022
NSIS differential updates support
@Lilleri
Copy link

Lilleri commented Nov 8, 2022

Hello, i am using electron-react-boilerplate for my project, and it use electron-builder for the compliation it output a NSIS with his blockmap, i load it in the server and it works except for the differential download, when the application tries to updated itself it fails everytime and it output this.

Cannot download differentially, fallback to full download: Error: sha512 checksum mismatch

i cannot figure out a way to avoid mismatching, i think it should use sha256 as default encoding.

@JJ-8
Copy link
Contributor Author

JJ-8 commented Nov 8, 2022

@Lilleri, why do you think it should use sha256 as default encoding? I think sha512-base64 should be fully supported.

Also, which version of electron-builder are you using? The latest version?

@Lilleri
Copy link

Lilleri commented Nov 8, 2022

i am using electron-builder 23.3.3,
i think we should use it because in the window config project https://www.electron.build/configuration/win.html the only supported sha are sha1, and sha256

@JJ-8
Copy link
Contributor Author

JJ-8 commented Nov 8, 2022

If I check the source code of electron-builder, it still seems that both sha512-base64 and sha256-hex is supported: https://github.com/electron-userland/electron-builder/blob/53327d51101b83641ece9f497577c3ac93d3e91d/packages/builder-util-runtime/src/httpExecutor.ts#L462
I think that if you prevent sending the X-Checksum-Sha2 header, the checkSha2 function should return true and continue checking the sha512-base64 hash. Then the error will not be triggered anymore hopefully.
I have no clue how the X-Checksum-Sha2 header is send.

@TokeyChan
Copy link

Hi! I still get a checksum mismatch when trying to differentially download. Do I need to tell electron-builder to look for the sha512, or have you figured out how to set the X-Checksum-Sha2 header?

Best Regards!

@JJ-8
Copy link
Contributor Author

JJ-8 commented May 4, 2023

Hi @TokeyChan, I had a quick look at the current version of electron-builder and the code hasn't changed: https://github.com/electron-userland/electron-builder/blob/master/packages/builder-util-runtime/src/httpExecutor.ts#L440
So my advice still holds: try to convince it to use sha512 and it should work. I won't have time to figure out the sha2 header so if you really need this, you have to implement it yourself.

Best of luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants