ChocolateStore icon indicating copy to clipboard operation
ChocolateStore copied to clipboard

Can't download mpc-be

Open laggingreflex opened this issue 7 years ago • 2 comments

I get this error when downloading mpc-be

Reading package 'mpc-be'
package URL: 'https://chocolatey.org/api/v2/package/mpc-be/1.5.1.171106'
Skipped: mpc-be.1.5.1.171106.nupkg - File already exists on disk.
Download Failed: https://sourceforge.net/projects/mpcbe/files/MPC-BE/Release%20builds/1.5.1/MPC-BE.1.5.1.x86-installer.zip/download
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.GetResponse()
   at ChocolateStore.PackageCacher.DownloadFile(String url, String destination) in C:\...\ChocolateStore\PackageCacher.cs:line 83
Download Failed: https://sourceforge.net/projects/mpcbe/files/MPC-BE/Release%20builds/1.5.1/MPC-BE.1.5.1.x64-installer.zip/download
System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.
   at System.Net.HttpWebRequest.GetResponse()
   at ChocolateStore.PackageCacher.DownloadFile(String url, String destination) in C:\...\ChocolateStore\PackageCacher.cs:line 83

Installs ok when installed directly

Chocolatey v0.10.8
Installing the following packages:
mpc-be
By installing you accept licenses for the packages.
Progress: Downloading mpc-be 1.5.1.171106... 100%

mpc-be v1.5.1.171106 [Approved]
mpc-be package files install completed. Performing other installation steps.
Downloading mpc-be 64 bit
  from 'https://sourceforge.net/projects/mpcbe/files/MPC-BE/Release%20builds/1.5.1/MPC-BE.1.5.1.x64-installer.zip/download'
Progress: 100% - Completed download of C:\Users\...\AppData\Local\Temp\chocolatey\mpc-be\1.5.1.171106\MPC-BE.1.5.1.x64-installer.zip (12.33 MB).
Download of MPC-BE.1.5.1.x64-installer.zip (12.33 MB) completed.
Hashes match.
Extracting C:\Users\...\AppData\Local\Temp\chocolatey\mpc-be\1.5.1.171106\MPC-BE.1.5.1.x64-installer.zip to C:\ProgramData\chocolatey\lib\mpc-be\tools...
C:\ProgramData\chocolatey\lib\mpc-be\tools
Installing mpc-be...
mpc-be has been installed.
PATH environment variable does not have "C:\Program Files\MPC-BE x64\" in it. Adding...
  mpc-be can be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of mpc-be was successful.
  Software installed to 'C:\Program Files\MPC-BE x64\'

laggingreflex avatar Feb 16 '18 19:02 laggingreflex

It looks like a proxy is required to download the files in this package. It looks like chocolatey has a strategy for doing this in Get-WebFile.ps1 in the chocolatey repository.

I think we would have to implement something similar in our .NET code.

I have no immediate plans to look at this issue further but would accept a pull request if anyone wants to look at it.

BahKoo avatar Feb 27 '18 00:02 BahKoo

Nope, no proxy just two simple things need to occur:

  1. Set up TLS1.2 (the root cause of your failure above)
  2. MUST set the user-agent properly (if you had gotten this far, by default you would only get the SF page as your file without this)

To demonstrate this issue and the solution using dotnet in Powershell:

C:\temp » 
λ  $url='https://sourceforge.net/projects/mpcbe/files/MPC-BE/Release%20builds/1.5.1/MPC-BE.1.5.1.x64-installer.zip/download'

C:\temp »
λ  $path='C:\Temp\MPC-BE.1.5.1.x64-installer.zip'

C:\temp »
λ  Invoke-WebRequest -Uri $url -OutFile $path
[Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At line:1 char:1
+ Invoke-WebRequest -Uri $url -OutFile $path
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], We
   bException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand]

C:\temp »
λ  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

C:\temp »
λ  Invoke-WebRequest -Uri $url -OutFile $path
✘ [FAILURE:  Successful download but upon opening .zip - it is really the Sourceforge HTML redirect page)]

C:\temp »
λ  Invoke-WebRequest -Uri $url -OutFile $path -UserAgent [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome
✔ 'SUCCESS:  Fully usable/proper MPC-BE installer zip file!

So, in CSharp you would first do this:


System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;

...And then simply use any explicit useragent you want (best practice, anyway)....and along with the TLS there is no package you should not be able to download with the only single exception being the one-off's that need a very specific header sent with the request that is usually handled in the Powershell install, anyway.

EDIT

Might as well just post the code to fix it :)

I just compiled it to confirm it works, including with the very nicely done upstream fork from @sr258.

System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls12;
var request = (HttpWebRequest)WebRequest.Create(url);
((HttpWebRequest)request).UserAgent = "ChocolateStore";

CollinChaffin avatar Oct 12 '18 03:10 CollinChaffin