-
Notifications
You must be signed in to change notification settings - Fork 6
Add self-update mechanism (fixes #3) #11
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
349122d
Detect releases
lacostej 35a2e6d
Remove unused code
niezbop a5584f5
Spawn popup when update is available
niezbop 15ac85a
Implement self update mechanism
niezbop 9f94bff
Move Update logic out of Initialize to Updater
niezbop 21ba959
Add menu item to update Uplift
niezbop 19ec6fe
Revert test changes to version
niezbop 76eea13
Make automatic update checks daily
niezbop 6d56908
Remove .vscode/ from git
niezbop 11ca1b2
Fix indentation
niezbop e9977f1
Check SSL certificate
niezbop 5e979fe
Add opt-out check on certificate hash
niezbop 9c94f3f
Keep EditorPrefs in the main thread
niezbop 371fbf5
Add a bunch of certificates to test against
niezbop 9b9eb34
Add license block to Updater
niezbop 7bef6cf
Clean Initialize using section
niezbop 8011314
Explain where we use SSL certificates
niezbop 18aa624
Fix multiple update popups when several releases
niezbop 4d223da
Refactor release loading
niezbop 3cdba70
Add license block to Github.cs
niezbop 2947131
Small style fixes
niezbop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| .db | ||
| Thumbs.db | ||
| /.idea | ||
| /.vscode | ||
| /results.xml | ||
|
|
||
| /Assets/UPackages.meta | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,303 @@ | ||
| // --- BEGIN LICENSE BLOCK --- | ||
| /* | ||
| * Copyright (c) 2017-present WeWantToKnow AS | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to deal | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in all | ||
| * copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| * SOFTWARE. | ||
| */ | ||
| // --- END LICENSE BLOCK --- | ||
|
|
||
| using UnityEngine; | ||
| using UnityEditor; | ||
| using System.IO; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using Uplift.Common; | ||
| using Uplift.GitHubModule; | ||
| using Uplift.Windows; | ||
| using System.Net; | ||
| using System.Linq; | ||
| using System; | ||
| using System.Globalization; | ||
| using System.Net.Security; | ||
| using System.Security.Cryptography.X509Certificates; | ||
| using System.Text; | ||
|
|
||
| namespace Uplift.Updating | ||
| { | ||
| public class Updater : MonoBehaviour | ||
| { | ||
| private static readonly string dateFormat = @"MM\/dd\/yyyy HH:mm"; | ||
| private static readonly CultureInfo provider = CultureInfo.InvariantCulture; | ||
| private static readonly string lastUpdateCheckKey = "UpliftLastUpdateCheck"; | ||
| private static IEnumerator updateCoroutine; | ||
| private static readonly string[] githubCertificatesString = new string[] | ||
| { | ||
| // github.com | ||
| @"-----BEGIN CERTIFICATE----- | ||
| MIIHeTCCBmGgAwIBAgIQC/20CQrXteZAwwsWyVKaJzANBgkqhkiG9w0BAQsFADB1 | ||
| MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 | ||
| d3cuZGlnaWNlcnQuY29tMTQwMgYDVQQDEytEaWdpQ2VydCBTSEEyIEV4dGVuZGVk | ||
| IFZhbGlkYXRpb24gU2VydmVyIENBMB4XDTE2MDMxMDAwMDAwMFoXDTE4MDUxNzEy | ||
| MDAwMFowgf0xHTAbBgNVBA8MFFByaXZhdGUgT3JnYW5pemF0aW9uMRMwEQYLKwYB | ||
| BAGCNzwCAQMTAlVTMRkwFwYLKwYBBAGCNzwCAQITCERlbGF3YXJlMRAwDgYDVQQF | ||
| Ewc1MTU3NTUwMSQwIgYDVQQJExs4OCBDb2xpbiBQIEtlbGx5LCBKciBTdHJlZXQx | ||
| DjAMBgNVBBETBTk0MTA3MQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5p | ||
| YTEWMBQGA1UEBxMNU2FuIEZyYW5jaXNjbzEVMBMGA1UEChMMR2l0SHViLCBJbmMu | ||
| MRMwEQYDVQQDEwpnaXRodWIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB | ||
| CgKCAQEA54hc8pZclxgcupji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BgNVHRMB | ||
| Af8EAjAAMIIBfwYKKwYBBAHWeQIEAgSCAW8EggFrAWkAdgCkuQmQtBhYFIe7E6LM | ||
| Z3AKPDWYBPkb37jjd80OyA3cEAAAAVNhieoeAAAEAwBHMEUCIQCHHSEY/ROK2/sO | ||
| ljbKaNEcKWz6BxHJNPOtjSyuVnSn4QIgJ6RqvYbSX1vKLeX7vpnOfCAfS2Y8lB5R | ||
| NMwk6us2QiAAdgBo9pj4H2SCvjqM7rkoHUz8cVFdZ5PURNEKZ6y7T0/7xAAAAVNh | ||
| iennAAAEAwBHMEUCIQDZpd5S+3to8k7lcDeWBhiJASiYTk2rNAT26lVaM3xhWwIg | ||
| NUqrkIODZpRg+khhp8ag65B8mu0p4JUAmkRDbiYnRvYAdwBWFAaaL9fC7NP14b1E | ||
| sj7HRna5vJkRXMDvlJhV1onQ3QAAAVNhieqZAAAEAwBIMEYCIQDnm3WStlvE99GC | ||
| izSx+UGtGmQk2WTokoPgo1hfiv8zIAIhAPrYeXrBgseA9jUWWoB4IvmcZtshjXso | ||
| nT8MIG1u1zF8MA0GCSqGSIb3DQEBCwUAA4IBAQCLbNtkxuspqycq8h1EpbmAX0wM | ||
| 5DoW7hM/FVdz4LJ3Kmftyk1yd8j/PSxRrAQN2Mr/frKeK8NE1cMji32mJbBqpWtK | ||
| /+wC+avPplBUbNpzP53cuTMF/QssxItPGNP5/OT9Aj1BxA/NofWZKh4ufV7cz3pY | ||
| RDS4BF+EEFQ4l5GY+yp4WJA/xSvYsTHWeWxRD1/nl62/Rd9FN2NkacRVozCxRVle | ||
| FrBHTFxqIP6kDnxiLElBrZngtY07ietaYZVLQN/ETyqLQftsf8TecwTklbjvm8NT | ||
| JqbaIVifYwqwNN+4lRxS3F5lNlA/il12IOgbRioLI62o8G0DaEUQgHNf8vSG | ||
| -----END CERTIFICATE----- | ||
| ", | ||
| // DigiCert High Assurance EV Root CA | ||
| @"-----BEGIN CERTIFICATE----- | ||
| MIIDxTCCAq2gAwIBAg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WONfqe/EW1ntlMMUu4kehDLI6z | ||
| eM7b41N5cdblIZQB2lWHmiRk9opmzN6cN82oNLFpmyPInngiK3BD41VHMWEZ71jF | ||
| hS9OMPagMRYjyOfiZRYzy78aG6A9+MpeizGLYAiJLQwGXFK3xPkKmNEVX58Svnw2 | ||
| Yzi9RKR/5CYrCsSXaQ3pjOLAEFe4yHYSkVXySGnYvCoCWw9E1CAx2/S6cCZdkGCe | ||
| vEsXCS+0yx5DaMkHJ8HSXPfqIbloEpw8nL+e/IBcm2PN7EeqJSdnoDfzAIJ9VNep | ||
| +OkuE6N36B9K | ||
| -----END CERTIFICATE----- | ||
| ", | ||
| // DigiCert SHA2 Extended Validation Server CA | ||
| @"-----BEGIN CERTIFICATE----- | ||
| MIIEtjCCA56gAwIBAgIQDHmpRLCMEZUgkmFf4msdgzANBgkqhkiG9w0BAQsFADBs | ||
| MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 | ||
| d3cuZGlnaWNlcnQuY29tMSswKQYDVQQDEyJEaWdpQ2VydCBIaWdoIEFzc3VyYW5j | ||
| ZSBFViBSb290IENBMB4XDTEzMTAyMjEyMDAwMFoXDTI4MTAyMjEyMDAwMFowdTEL | ||
| MAkGA1UEBhMCVVMxFTATBgNVBAoTDERpZ2lDZXJ0IEluYzEZMBcGA1UECxMQd3d3 | ||
| LmRpZ2ljZXJ0LmNvbTE0MDIGA1UEAxMrRGlnaUNlcnQgU0hBMiBFeHRlbmRlZCBW | ||
| YWxpZGF0aW9uIFNlcnZlciBDQTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC | ||
| ggEBANdTpARR+JmmFkhLZyeqk0nQOe0MsLAAh/FnKIaFjI5j2ryxQDji0/XspQUY | ||
| uD0+xZkXMuwYjPrxDKZkIYXLBxA0sFKIKx9om9KxjxKws9LniB8f7zh3VFNfgHk/ | ||
| LhqqqB5LKw2rt2O5Nbd9FLxZS99RStKh4gzikIKH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kn | ||
| 8TUoE6smftX3eg== | ||
| -----END CERTIFICATE----- | ||
| ", | ||
| // Amazon S3 (provider for the release download) *.s3.amazonaws.com | ||
| @"-----BEGIN CERTIFICATE----- | ||
| MIIFWjCCBEKgAwIBAgIQBVG1kvpTzyBSuLcPJ1zBWTANBgkqhkiG9w0BAQsFADBk | ||
| MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 | ||
| d3cuZGlnaWNlcnQuY29tMSMwIQYDVQQDExpEaWdpQ2VydCBCYWx0aW1vcmUgQ0Et | ||
| MiBHMjAeFw0xNzA5MjIwMDAwMDBaFw0xOTAxMDMxMjAwMDBaMGsxCzAJBgNVBAYT | ||
| AlVTMRMwEQYDVQQIEwpXYXNoaW5ndG9uMRAwDgYDVQQHEwdTZWF0dGxlMRgwFgYD | ||
| VQQKEw9BbWF6b24uY29tIEluYy4xGzAZBgNVBAMMEiouczMuYW1hem9uYXdzLmNv | ||
| bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKK5it42LH/8WFaEE7O9 | ||
| 4XJMg48TengCM25C9O0dUaPGOnZ1+oGf7DNvdo/MGVoAW5hfPX9WqjY30KyuKiFv | ||
| 8uAbyX+9Bzq8KMLjdvGxzYMqbSxeAPSBf1yMdCyDEc8gW+vh2uXO+x9QePgiOAoO | ||
| qujLzyS/p7pSWPUKUH8kpMgP99RPoD/lRNbPAFr3QeJr7D/x3xNTKBHCbpE4SxBH | ||
| QM02GCu2DSYQtgm3hfZmD79BB1Ej4U1vM0hgiOu9eFLwmycbnrnU8sa4DkvmUJlv | ||
| xiIP5PvNweawm/QeoH6Qk/zDF30nr+5Av9IUhE4uAhl1H2OMqPp79SfJ2wxtvmNt | ||
| 3z0CAwEAAaOCAf8wggH7MB8GA1UdIwQYMBaAFMASsih0aEZn6XAldBoARVsGfVxE | ||
| MB0GA1UdDgQWBBSQFZo7H1VA7uODvdTP1I6idMLqyDAvBgNVHREEKDAmghIqLnMz | ||
| LmFtYXpvbmF3cy5jb22CEHMzLmFtYXpvbmF3cy5jb20wDgYDVR0PAQH/BAQDAgWg | ||
| MB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjCBgQYDVR0fBHoweDA6oDig | ||
| NoY0aHR0cDovL2NybDMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0QmFsdGltb3JlQ0Et | ||
| MkcyLmNybDA6oDigNoY0aHR0cDovL2NybDQuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0 | ||
| QmFsdGltb3JlQ0EtMkcyLmNybDBMBgNVHSAERTBDMDcGCWCGSAGG/WwBATAqMCgG | ||
| CCsGAQUFBwIBFhxodHRwczovL3d3dy5kaWdpY2VydC5jb20vQ1BTMAgGBmeBDAEC | ||
| AjB5BggrBgEFBQcBAQRtMGswJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmRpZ2lj | ||
| ZXJ0LmNvbTBDBggrBgEFBQcwAoY3aHR0cDovL2NhY2VydHMuZGlnaWNlcnQuY29t | ||
| L0RpZ2lDZXJ0QmFsdGltb3JlQ0EtMkcyLmNydDAMBgNVHRMBAf8EAjAAMA0GCSqG | ||
| SIb3DQEBCwUAA4IBAQBydwnbmrwTTwhtCckZ9lDGoE+tdDFchjFG59dyzX1I4bHV | ||
| thVUwjEoc3VxngvmKb3cqLcHzXHNdoEdffRtw0IiEerPRsk7Nxh2p1HWR3cu/Hyp | ||
| kqGlObJADiw1DX4UDob735hevqcGN9M0rn9P/AbPK0HCn5uokLDmbeqe6u1YgdJL | ||
| m4skA/WsUsMCfsZY27RiZ+B162+laDD0oRiovOx5zKrzG/3yAFVutz2Bfud3QenU | ||
| 3zt14ttnzFCcMlglW9oqffHMwQ1Smx/30ccDonoa1E02hnNmxeLyBwomPqd/ZYy6 | ||
| zSJW0aSi1DadkZsifpr65AwgSuN5uGEhQas0glsN | ||
| -----END CERTIFICATE----- | ||
| " | ||
| }; | ||
| private static bool trustUnknown; | ||
|
|
||
| public static void UpdateUplift(string url) | ||
| { | ||
| trustUnknown = UpliftPreferences.TrustUnknownCertificates(); | ||
| string unitypackageName = url.Split('/').Last(); | ||
| DirectoryInfo assetsPath = new DirectoryInfo(Application.dataPath); | ||
| string destination = Path.Combine(assetsPath.Parent.FullName, unitypackageName); | ||
|
|
||
| ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallback; | ||
| using (var client = new WebClient()) | ||
| { | ||
| client.DownloadFile(url, destination); | ||
| } | ||
|
|
||
| AssetDatabase.ImportPackage(destination, false); | ||
| } | ||
|
|
||
| public static void CheckForUpdate(bool forceCheck = false) | ||
| { | ||
| if(forceCheck || ShouldCheck()) | ||
| { | ||
| EditorApplication.update += EditorUpdate; | ||
| updateCoroutine = CheckForUpdateRoutine(); | ||
| } | ||
| } | ||
|
|
||
| private static void EditorUpdate() | ||
| { | ||
| updateCoroutine.MoveNext(); | ||
| } | ||
|
|
||
| private static bool ShouldCheck() | ||
| { | ||
| string lastCheck = EditorPrefs.GetString(lastUpdateCheckKey); | ||
| if(string.IsNullOrEmpty(lastCheck)) return true; | ||
|
|
||
| try | ||
| { | ||
| TimeSpan timeFromLastCheck = DateTime.UtcNow - DateTime.ParseExact(lastCheck, dateFormat, provider); | ||
| return timeFromLastCheck > TimeSpan.FromDays(1); | ||
| } | ||
| catch(FormatException e) | ||
| { | ||
| Debug.LogErrorFormat("The date stored for the last check of Uplift ({0}) is not in the correct format:\n{1}", lastCheck, e); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| private static IEnumerator CheckForUpdateRoutine() { | ||
| IEnumerator e = GitHub.LoadReleases("https://api.github.com/repos/DragonBox/uplift/releases"); | ||
| while (e.MoveNext()) yield return e.Current; | ||
|
|
||
| GitHubRelease[] releases = (GitHubRelease[]) e.Current; | ||
|
|
||
| if (releases == null) | ||
| { | ||
| Debug.LogError ("Unable to check for Uplift updates"); | ||
| } | ||
| else if(!releases.Any(release => VersionParser.GreaterThan(release.tag, About.Version))) | ||
| { | ||
| Debug.Log("No udpate for Uplift available"); | ||
| } | ||
| else | ||
| { | ||
| UpdatePopup popup = EditorWindow.GetWindow(typeof(UpdatePopup), true) as UpdatePopup; | ||
| popup.SetReleases(releases.Where(release => VersionParser.GreaterThan(release.tag, About.Version)).ToArray()); | ||
| } | ||
| EditorApplication.update -= EditorUpdate; | ||
| EditorPrefs.SetString( | ||
| lastUpdateCheckKey, | ||
| DateTime.UtcNow.ToString(dateFormat, provider) | ||
| ); | ||
| } | ||
|
|
||
| private static bool CertificateValidationCallback( | ||
| System.Object sender, | ||
| X509Certificate certificate, | ||
| X509Chain chain, | ||
| SslPolicyErrors sslPolicyErrors | ||
| ) | ||
| { | ||
| bool correct = true; | ||
| if(sslPolicyErrors == SslPolicyErrors.None) return true; | ||
|
|
||
| X509Certificate[] githubCertificates = new X509Certificate[githubCertificatesString.Length]; | ||
| for(int i = 0; i < githubCertificatesString.Length; i++) | ||
| { | ||
| githubCertificates[i] = new X509Certificate(); | ||
| githubCertificates[i].Import(Encoding.ASCII.GetBytes(githubCertificatesString[i])); | ||
| } | ||
|
|
||
| if(!(githubCertificates.Any(cert => cert.GetCertHashString() == certificate.GetCertHashString()) || trustUnknown)) | ||
| { | ||
| Debug.LogErrorFormat("The received certificate ({0}) is not known by Uplift. We cannot download the update package. You could update Uplift manually, or go to Preferences and set 'Trust unknown certificates' to true.", certificate.GetCertHashString()); | ||
| Debug.Log("Known certificates are:"); | ||
| foreach(X509Certificate cert in githubCertificates) | ||
| Debug.Log(" -- " + cert.GetCertHashString()); | ||
| return false; | ||
| } | ||
|
|
||
| for (int i=0; i < chain.ChainStatus.Length; i++) { | ||
| if (chain.ChainStatus[i].Status == X509ChainStatusFlags.RevocationStatusUnknown) { | ||
| continue; | ||
| } | ||
| chain.ChainPolicy.RevocationFlag = X509RevocationFlag.EntireChain; | ||
| chain.ChainPolicy.RevocationMode = X509RevocationMode.Online; | ||
| chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan (0, 1, 0); | ||
| chain.ChainPolicy.VerificationFlags = X509VerificationFlags.AllFlags; | ||
| bool chainIsValid = chain.Build ((X509Certificate2)certificate); | ||
| if (!chainIsValid) { | ||
| correct = false; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return correct; | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that prevent update in a different project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure. It could actually. I'll check this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the preferences are project specific!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool.