Skip to content

Commit

Permalink
Add initial config for RemoteCertificateValidationCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
rsr-maersk committed Oct 2, 2023
1 parent 4d0b136 commit 3e3fd61
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace MassTransit.ActiveMqTransport.Configuration
{
using System;
using System.Collections.Generic;
using System.Net.Security;


public class ActiveMqHostConfigurator :
Expand All @@ -14,7 +15,9 @@ public ActiveMqHostConfigurator(Uri address)
_settings = new ConfigurationHostSettings(address);

if (_settings.Port == 61617 || _settings.Host.EndsWith("amazonaws.com", StringComparison.OrdinalIgnoreCase))
UseSsl();
UseSsl(s =>
{
});
}

public ActiveMqHostSettings Settings => _settings;
Expand All @@ -28,12 +31,16 @@ public void Password(string password)
{
_settings.Password = password;
}

public void UseSsl()
public void UseSsl(Action<IActiveMqSslConfigurator> configureSsl)
{
_settings.UseSsl = true;
if (_settings.Port == 61616)
_settings.Port = 61617;

var configurator = new ActiveMqSslConfigurator(_settings);
configureSsl(configurator);
_settings.CertificateValidationCallback = configurator.CertificateValidationCallback;
}

public void FailoverHosts(string[] hosts)
Expand Down Expand Up @@ -62,4 +69,26 @@ public void SetQueuePrefetchPolicy(int limit)
_settings.TransportOptions["jms.prefetchPolicy.queuePrefetch"] = limit.ToString();
}
}


public class ActiveMqSslConfigurator : IActiveMqSslConfigurator
{
public ActiveMqSslConfigurator(ConfigurationHostSettings settings)
{
CertificateValidationCallback = settings.CertificateValidationCallback;
}

public RemoteCertificateValidationCallback CertificateValidationCallback { get; set; }
}


public interface IActiveMqSslConfigurator
{
/// <summary>
/// An optional client specified SSL certificate validation callback. If this is not specified,
/// the default callback will be used in conjunction with the <see cref="P:RabbitMQ.Client.SslOption.AcceptablePolicyErrors" /> property to
/// determine if the remote server certificate is valid.
/// </summary>
RemoteCertificateValidationCallback CertificateValidationCallback { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override IBusInstance CreateBus(IBusRegistrationContext context, IEnumera
h.Password(options.Pass);
if (options.UseSsl)
h.UseSsl();
h.UseSsl(s => { });
});

return CreateBus(configurator, context, _configure, specifications);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace MassTransit.ActiveMqTransport.Configuration
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using Apache.NMS;


Expand Down Expand Up @@ -108,5 +109,7 @@ public override string ToString()
Port = Port
}.Uri.ToString();
}

public RemoteCertificateValidationCallback CertificateValidationCallback { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
namespace MassTransit
{
using System;
using System.Collections.Generic;
using ActiveMqTransport.Configuration;


public interface IActiveMqHostConfigurator
Expand All @@ -17,7 +19,7 @@ public interface IActiveMqHostConfigurator
/// <param name="password"></param>
void Password(string password);

void UseSsl();
void UseSsl(Action<IActiveMqSslConfigurator> configureSsl);

/// <summary>
/// Sets a list of hosts to enable the failover transport
Expand Down

0 comments on commit 3e3fd61

Please sign in to comment.