Skip to content

Commit 363de19

Browse files
Remove InstallCert (#33)
1 parent 85dc48d commit 363de19

File tree

1 file changed

+2
-36
lines changed
  • content/dotnet-template-azure-iot-edge-module/CSharp

1 file changed

+2
-36
lines changed

content/dotnet-template-azure-iot-edge-module/CSharp/Program.cs

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ class Program
1717

1818
static void Main(string[] args)
1919
{
20-
// Cert verification is not yet fully functional when using Windows OS for the container
21-
bool bypassCertVerification = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
22-
if (!bypassCertVerification) InstallCert();
23-
Init(bypassCertVerification).Wait();
20+
Init().Wait();
2421

2522
// Wait until the app unloads or is cancelled
2623
var cts = new CancellationTokenSource();
@@ -39,44 +36,13 @@ public static Task WhenCancelled(CancellationToken cancellationToken)
3936
return tcs.Task;
4037
}
4138

42-
/// <summary>
43-
/// Add certificate in local cert store for use by client for secure connection to IoT Edge runtime
44-
/// </summary>
45-
static void InstallCert()
46-
{
47-
string certPath = Environment.GetEnvironmentVariable("EdgeModuleCACertificateFile");
48-
if (string.IsNullOrWhiteSpace(certPath))
49-
{
50-
// We cannot proceed further without a proper cert file
51-
Console.WriteLine($"Missing path to certificate collection file: {certPath}");
52-
throw new InvalidOperationException("Missing path to certificate file.");
53-
}
54-
else if (!File.Exists(certPath))
55-
{
56-
// We cannot proceed further without a proper cert file
57-
Console.WriteLine($"Missing path to certificate collection file: {certPath}");
58-
throw new InvalidOperationException("Missing certificate file.");
59-
}
60-
X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
61-
store.Open(OpenFlags.ReadWrite);
62-
store.Add(new X509Certificate2(X509Certificate2.CreateFromCertFile(certPath)));
63-
Console.WriteLine("Added Cert: " + certPath);
64-
store.Close();
65-
}
66-
67-
6839
/// <summary>
6940
/// Initializes the DeviceClient and sets up the callback to receive
7041
/// messages containing temperature information
7142
/// </summary>
72-
static async Task Init(bool bypassCertVerification = false)
43+
static async Task Init()
7344
{
7445
MqttTransportSettings mqttSetting = new MqttTransportSettings(TransportType.Mqtt_Tcp_Only);
75-
// During dev you might want to bypass the cert verification. It is highly recommended to verify certs systematically in production
76-
if (bypassCertVerification)
77-
{
78-
mqttSetting.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
79-
}
8046
ITransportSettings[] settings = { mqttSetting };
8147

8248
// Open a connection to the Edge runtime

0 commit comments

Comments
 (0)