예제 #1
0
        private void DownloadUpdateCompleted(object sender, AsyncCompletedEventArgs e)
        {
            var raiseEventArgs = e;

            if (!e.Cancelled && e.Error == null)
            {
                try
                {
#if !PORTABLE
                    var updateAuthenticode = new Authenticode(_currentUpdateInfo.UpdateFilePath)
                    {
                        RequireThumbprintMatch = true,
                        ThumbprintToMatch      = _currentUpdateInfo.CertificateThumbprint
                    };

                    if (updateAuthenticode.Verify() != Authenticode.StatusValue.Verified)
                    {
                        if (updateAuthenticode.Status == Authenticode.StatusValue.UnhandledException)
                        {
                            throw (updateAuthenticode.Exception);
                        }

                        throw (new Exception(updateAuthenticode.StatusMessage));
                    }
#else
                    using (var md5 = MD5.Create())
                    {
                        using (var stream = File.OpenRead(_currentUpdateInfo.UpdateFilePath))
                        {
                            var hash       = md5.ComputeHash(stream);
                            var hashString = BitConverter.ToString(hash).Replace("-", "");
                            if (!hashString.Equals(_currentUpdateInfo.CertificateThumbprint))
                            {
                                throw new Exception("MD5 Hashes didn't match!");
                            }
                        }
                    }
#endif
                }
                catch (Exception ex)
                {
                    raiseEventArgs = new AsyncCompletedEventArgs(ex, false, null);
                }
            }

            if (raiseEventArgs.Cancelled || raiseEventArgs.Error != null)
            {
                File.Delete(_currentUpdateInfo.UpdateFilePath);
            }

            DownloadUpdateCompletedEventEvent?.Invoke(this, raiseEventArgs);

            _downloadUpdateWebClient.Dispose();
            _downloadUpdateWebClient = null;
        }
예제 #2
0
        private void DownloadUpdateCompleted(object sender, AsyncCompletedEventArgs e)
        {
            AsyncCompletedEventArgs raiseEventArgs = e;

            if (!e.Cancelled && e.Error == null)
            {
                try
                {
                    Authenticode updateAuthenticode = new Authenticode(_currentUpdateInfo.UpdateFilePath);
                    updateAuthenticode.RequireThumbprintMatch = true;
                    updateAuthenticode.ThumbprintToMatch      = _currentUpdateInfo.CertificateThumbprint;

                    if (updateAuthenticode.Verify() != Authenticode.StatusValue.Verified)
                    {
                        if (updateAuthenticode.Status == Authenticode.StatusValue.UnhandledException)
                        {
                            throw (updateAuthenticode.Exception);
                        }
                        else
                        {
                            throw (new Exception(updateAuthenticode.StatusMessage));
                        }
                    }
                }
                catch (Exception ex)
                {
                    raiseEventArgs = new AsyncCompletedEventArgs(ex, false, null);
                }
            }

            if (raiseEventArgs.Cancelled || raiseEventArgs.Error != null)
            {
                File.Delete(_currentUpdateInfo.UpdateFilePath);
            }

            DownloadUpdateCompletedEventEvent?.Invoke(this, raiseEventArgs);

            _downloadUpdateWebClient.Dispose();
            _downloadUpdateWebClient = null;
        }