Browse Source

Added support for RabbitMQ SSL-secured connections

Change-Id: Ie11e926e72ae1e2f2840468afb2a7d1652b3553d
Stan Lagun 5 years ago
parent
commit
a17e216a87
2 changed files with 24 additions and 5 deletions
  1. 1
    1
      WindowsAgent/Program.cs
  2. 23
    4
      WindowsAgent/RabbitMqClient.cs

+ 1
- 1
WindowsAgent/Program.cs View File

@@ -30,7 +30,7 @@ namespace Mirantis.Murano.WindowsAgent
30 30
 		{
31 31
 			base.OnStart(args);
32 32
 
33
-			Log.Info("Version 0.3");
33
+			Log.Info("Version 0.4");
34 34
 
35 35
 			this.rabbitMqClient = new RabbitMqClient();
36 36
 

+ 23
- 4
WindowsAgent/RabbitMqClient.cs View File

@@ -3,6 +3,9 @@ using System.Collections.Generic;
3 3
 using System.Configuration;
4 4
 using System.Linq;
5 5
 using System.Net;
6
+using System.Net.Security;
7
+using System.Security.Authentication;
8
+using System.Security.Cryptography.X509Certificates;
6 9
 using System.Text;
7 10
 using System.Threading.Tasks;
8 11
 using NLog;
@@ -18,13 +21,29 @@ namespace Mirantis.Murano.WindowsAgent
18 21
 
19 22
 		static RabbitMqClient()
20 23
 		{
21
-			connectionFactory = new ConnectionFactory {
24
+		    var ssl = new SslOption {
25
+		        Enabled = bool.Parse(ConfigurationManager.AppSettings["rabbitmq.ssl"] ?? "false"),
26
+		        Version = SslProtocols.Default,
27
+                AcceptablePolicyErrors = bool.Parse(ConfigurationManager.AppSettings["rabbitmq.allowInvalidCA"] ?? "true") ? 
28
+                    SslPolicyErrors.RemoteCertificateNameMismatch : SslPolicyErrors.None
29
+		    };
30
+
31
+		    var sslServerName = ConfigurationManager.AppSettings["rabbitmq.sslServerName"] ?? "";
32
+		    ssl.ServerName = sslServerName;
33
+            if (String.IsNullOrWhiteSpace(sslServerName))
34
+            {
35
+                ssl.AcceptablePolicyErrors |= SslPolicyErrors.RemoteCertificateNameMismatch;
36
+            }
37
+
38
+            connectionFactory = new ConnectionFactory {
22 39
                 HostName = ConfigurationManager.AppSettings["rabbitmq.host"] ?? "localhost",
23 40
                 UserName = ConfigurationManager.AppSettings["rabbitmq.user"] ?? "guest",
24 41
                 Password = ConfigurationManager.AppSettings["rabbitmq.password"] ??"guest",
25
-                Protocol = Protocols.FromEnvironment(),
42
+                Protocol = Protocols.DefaultProtocol,
26 43
                 VirtualHost = ConfigurationManager.AppSettings["rabbitmq.vhost"] ?? "/",
27
-                RequestedHeartbeat = 10
44
+                Port = int.Parse(ConfigurationManager.AppSettings["rabbitmq.port"] ?? "5672"),
45
+                RequestedHeartbeat = 10,
46
+                Ssl = ssl
28 47
             };
29 48
 		}
30 49
 		
@@ -45,7 +64,7 @@ namespace Mirantis.Murano.WindowsAgent
45 64
 				}
46 65
 				var session = connection.CreateModel();
47 66
 				session.BasicQos(0, 1, false);
48
-				//session.QueueDeclare(queueName, true, false, false, null);
67
+				session.QueueDeclare(queueName, true, false, false, null);
49 68
 				var consumer = new QueueingBasicConsumer(session);
50 69
 				var consumeTag = session.BasicConsume(queueName, false, consumer);
51 70
 				var e = (RabbitMQ.Client.Events.BasicDeliverEventArgs) consumer.Queue.Dequeue();

Loading…
Cancel
Save