@@ -17,10 +17,7 @@ class Program
17
17
18
18
static void Main ( string [ ] args )
19
19
{
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 ( ) ;
24
21
25
22
// Wait until the app unloads or is cancelled
26
23
var cts = new CancellationTokenSource ( ) ;
@@ -39,44 +36,13 @@ public static Task WhenCancelled(CancellationToken cancellationToken)
39
36
return tcs . Task ;
40
37
}
41
38
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
-
68
39
/// <summary>
69
40
/// Initializes the DeviceClient and sets up the callback to receive
70
41
/// messages containing temperature information
71
42
/// </summary>
72
- static async Task Init ( bool bypassCertVerification = false )
43
+ static async Task Init ( )
73
44
{
74
45
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
- }
80
46
ITransportSettings [ ] settings = { mqttSetting } ;
81
47
82
48
// Open a connection to the Edge runtime
0 commit comments