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

Added "IgnoreInvalidSSLCert" as a recognised parameter and the respectiv... #342

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/OpenRasta.Client/HttpWebResponseBasedResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public HttpWebResponseBasedResponse(HttpWebRequestBasedRequest request, HttpWebR
{
Status = new HttpStatus((int)_response.StatusCode, _response.StatusDescription);
RaiseStatusChanged("Connected.");
if (_response.ContentLength > 0)
if (_response.ContentLength > 0
|| (_response.Headers.Get("Transfer-Encoding") != null && _response.Headers.Get("Transfer-Encoding").Equals("chunked")))
{
_entity = new HttpEntity(new ProgressStream(_response.ContentLength, RaiseProgress, _response.GetResponseStream()));
}
Expand Down
5 changes: 3 additions & 2 deletions src/OpenRasta.Client/Memory/MemoryHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public IClientResponse Send()
{
var response = RedirectIfNeeded(_client.Execute(this), this);

foreach (var handler in Handlers.Where(x => x.Key(response)).Select(x => x.Value)) handler(response);
foreach (var handler in Handlers.Where(x => x.Key(response)).Select(x => x.Value))
handler(response);
return response;
}

Expand Down Expand Up @@ -76,7 +77,7 @@ IClientResponse Execute(IClientRequest request)
{
return new MemoryResponse
{
Status = new HttpStatus(404, "Nout found"),
Status = new HttpStatus(404, "Not found"),
Headers = { { "Content-Length", "0" } }
};
}
Expand Down
1 change: 1 addition & 0 deletions src/OpenRasta.Client/OpenRasta.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<Compile Include="EventHandlerExtensions.cs" />
<Compile Include="HttpEntity.cs" />
<Compile Include="HttpStatus.cs" />
<Compile Include="SslCertificateValidators.cs" />
<Compile Include="WebRequestHttpClient.cs" />
<Compile Include="HttpWebRequestBasedRequest.cs" />
<Compile Include="HttpWebResponseBasedResponse.cs" />
Expand Down
15 changes: 13 additions & 2 deletions src/OpenRasta.Client/ProgressStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,20 @@ public override int Read(byte[] buffer, int offset, int count)

void NotifyProgress(int amount)
{
_total += amount;
if (_size > 0)
{
_total += amount;

_progressNotifier((int)(((double)_total / _size) * 100));
_progressNotifier((int)(((double)_total / _size) * 100));
}
else if (amount > 0)
{
_progressNotifier(50);
}
else
{
_progressNotifier(100);
}
}

public override void Write(byte[] buffer, int offset, int count)
Expand Down
30 changes: 30 additions & 0 deletions src/OpenRasta.Client/SslCertificateValidators.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

namespace OpenRasta.Client
{
/// <summary>
/// Contains validation callbacks for
/// <see cref="RemoteCertificateValidationCallback"/>.
/// </summary>
public static class SslCertificateValidators
{
/// <summary>
/// Validates any SSL certificate, however invalid.
/// </summary>
/// <param name="sender">An object that contains state information for this validation.</param>
/// <param name="certificate">The certificate used to authenticate the remote party.</param>
/// <param name="chain">The chain of certificate authorities associated with the remote certificate.</param>
/// <param name="policyErrors">One or more errors associated with the remote certificate.</param>
/// <returns><code>true</code></returns>
public static bool ValidateAnyRemoteCertificate(
object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
// allow any SSL certificate (self-signed, expired, ...)
return true;
}
}
}
18 changes: 18 additions & 0 deletions src/OpenWrap.Commands/CommandDocumentation.resx
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,22 @@ Note that the NuPack support is only provided for backward compatibility with le
<data name="set-wrap-edge" xml:space="preserve">
<value>Include pre-release packages for the specified dependency.</value>
</data>
<data name="add-remote-ignoreinvalidsslcert" xml:space="preserve">
<value>Ignores invalid SSL certificates and keeps going despite them.</value>
</data>
<data name="add-wrap-ignoreinvalidsslcert" xml:space="preserve">
<value>Ignores invalid SSL certificates and keeps going despite them.</value>
</data>
<data name="nuke-wrap-ignoreinvalidsslcert" xml:space="preserve">
<value>Ignores invalid SSL certificates and keeps going despite them.</value>
</data>
<data name="publish-wrap-ignoreinvalidsslcert" xml:space="preserve">
<value>Ignores invalid SSL certificates and keeps going despite them.</value>
</data>
<data name="set-remote-ignoreinvalidsslcert" xml:space="preserve">
<value>Ignores invalid SSL certificates and keeps going despite them.</value>
</data>
<data name="update-wrap-ignoreinvalidsslcert" xml:space="preserve">
<value>Ignores invalid SSL certificates and keeps going despite them.</value>
</data>
</root>
10 changes: 10 additions & 0 deletions src/OpenWrap.Commands/Remote/AddRemoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using System.Text.RegularExpressions;
using OpenRasta.Client;
using OpenWrap.Collections;
using OpenWrap.Commands.Messages;
using OpenWrap.Commands.Remote.Messages;
Expand All @@ -20,6 +22,9 @@ public class AddRemoteCommand : AbstractRemoteCommand
[CommandInput(Position = 1)]
public string Href { get; set; }

[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput(Position = 0, IsRequired = true)]
public string Name { get; set; }

Expand All @@ -38,6 +43,11 @@ public class AddRemoteCommand : AbstractRemoteCommand
protected override IEnumerable<ICommandOutput> ExecuteCore()
{
var repositories = ConfigurationManager.Load<RemoteRepositories>();
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}

return repositories.ContainsKey(Name)
? Append(repositories)
Expand Down
10 changes: 10 additions & 0 deletions src/OpenWrap.Commands/Remote/SetRemoteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using OpenRasta.Client;
using OpenWrap.Collections;
using OpenWrap.Commands.Errors;
using OpenWrap.Commands.Messages;
Expand All @@ -24,6 +26,9 @@ public class SetRemoteCommand : AbstractRemoteCommand
[CommandInput]
public string Href { get; set; }

[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput(Position = 0, IsRequired = true)]
public string Name { get; set; }

Expand All @@ -45,6 +50,11 @@ public class SetRemoteCommand : AbstractRemoteCommand
protected override IEnumerable<ICommandOutput> ExecuteCore()
{
HandlePrioritySetting(_remotes, _targetRemote);
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}

if (NewName != null)
_targetRemote.Name = NewName;
Expand Down
11 changes: 11 additions & 0 deletions src/OpenWrap.Commands/Wrap/AddWrapCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using OpenRasta.Client;
using OpenWrap.Collections;
using OpenWrap.PackageManagement;
using OpenWrap.PackageModel;
Expand Down Expand Up @@ -32,6 +35,9 @@ public class AddWrapCommand : WrapCommand
public string From { get; set; }

[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput]
public string MaxVersion { get; set; }

[CommandInput]
Expand Down Expand Up @@ -113,6 +119,11 @@ protected override IEnumerable<ICommandOutput> ExecuteCore()
yield return VerifyProjectRepository();

yield return SetupEnvironmentForAdd();
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}
var sourceRepositories = GetSourceRepositories().ToList();

var descriptor = new PackageDescriptor(_targetDescriptor.Value);
Expand Down
11 changes: 11 additions & 0 deletions src/OpenWrap.Commands/Wrap/ListWrapCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using OpenRasta.Client;
using OpenWrap.Collections;
using OpenWrap.Configuration;
using OpenWrap.PackageManagement;
Expand All @@ -14,6 +17,9 @@ public class ListWrapCommand : WrapCommand
string _remote;
bool _remoteSet;

[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput(Position = 0)]
public string Query { get; set; }

Expand Down Expand Up @@ -68,6 +74,11 @@ protected override IEnumerable<ICommandOutput> ExecuteCore()
yield return m;
yield break;
}
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}
if (Project)
{
foreach(var descriptor in HostEnvironment.ScopedDescriptors
Expand Down
11 changes: 11 additions & 0 deletions src/OpenWrap.Commands/Wrap/NukeWrapCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using OpenRasta.Client;
using OpenWrap.Commands.Errors;
using OpenWrap.Repositories;

Expand All @@ -8,6 +11,9 @@ namespace OpenWrap.Commands.Wrap
[Command(Noun = "wrap", Verb = "nuke", Description = "Removes a wrap from a remote repository index.")]
public class NukeWrapCommand : WrapCommand
{
[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput(IsRequired = true, Position = 1)]
public string Name { get; set; }

Expand All @@ -20,6 +26,11 @@ public class NukeWrapCommand : WrapCommand

protected override IEnumerable<ICommandOutput> ExecuteCore()
{
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}
// TODO: HACK HACK HACK
IPackageRepository repo = Remotes.PublishRepositories(Remote).SelectMany(_=>_).FirstOrDefault();
if (repo == null)
Expand Down
12 changes: 11 additions & 1 deletion src/OpenWrap.Commands/Wrap/PublishWrapCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
using OpenRasta.Client;
using OpenFileSystem.IO;
using OpenWrap.Commands.Errors;
using OpenWrap.Commands.Messages;
Expand All @@ -24,6 +26,9 @@ public class PublishWrapCommand : WrapCommand
NetworkCredential _credentials;

[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput]
public string Name { get; set; }

[CommandInput(Position = 1)]
Expand All @@ -42,7 +47,12 @@ protected override IEnumerable<ICommandOutput> ExecuteCore()
{
yield return new Info(String.Format("Publishing package '{0}' to '{1}'", _packageFileName, Remote));

var credentialCookie =_credentials != null
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}
var credentialCookie = _credentials != null
? _authenticationSupport.WithCredentials(_credentials)
: null;
try
Expand Down
12 changes: 12 additions & 0 deletions src/OpenWrap.Commands/Wrap/UpdateWrapCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Security;
using OpenRasta.Client;
using OpenWrap.PackageManagement;
using OpenWrap.PackageManagement.DependencyResolvers;
using OpenWrap.PackageModel;
Expand All @@ -19,6 +22,9 @@ public class UpdateWrapCommand : WrapCommand
[CommandInput]
public string From { get; set; }

[CommandInput]
public bool IgnoreInvalidSSLCert { get; set; }

[CommandInput(Position = 0)]
public string Name { get; set; }

Expand All @@ -40,6 +46,12 @@ public bool System
public string Scope { get; set; }
protected override IEnumerable<ICommandOutput> ExecuteCore()
{
if (IgnoreInvalidSSLCert)
{
ServicePointManager.ServerCertificateValidationCallback
+= new RemoteCertificateValidationCallback(SslCertificateValidators.ValidateAnyRemoteCertificate);
}

var update = Enumerable.Empty<ICommandOutput>();
if (Project)
update = update.Concat(UpdateProjectPackages());
Expand Down