@@ -80,19 +80,6 @@ public static int my_sni_server_cb(IntPtr ssl, IntPtr ret, IntPtr exArg) {
8080 return 0 ;
8181 }
8282
83- public static string setPath ( string file ) {
84- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
85- {
86- return @"../../certs/" + file ;
87- } else if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
88- {
89- return @"../../../../certs/" + file ;
90- } else
91- {
92- return "" ;
93- }
94- }
95-
9683 public static void Main ( string [ ] args )
9784 {
9885 IntPtr ctx ;
@@ -101,15 +88,15 @@ public static void Main(string[] args)
10188 IntPtr arg_sni ;
10289
10390 /* These paths should be changed for use */
104- string fileCert = setPath ( "server-cert.pem" ) ;
105- string fileKey = setPath ( "server-key.pem" ) ;
106- if ( fileCert == "" || fileKey == "" ) {
91+ string fileCert = wolfssl . setPath ( "server-cert.pem" ) ;
92+ string fileKey = wolfssl . setPath ( "server-key.pem" ) ;
93+ StringBuilder dh2048Pem = new StringBuilder ( wolfssl . setPath ( "dh2048.pem" ) ) ;
94+
95+ if ( fileCert == "" || fileKey == "" || dh2048Pem . Length == 0 ) {
10796 Console . WriteLine ( "Platform not supported." ) ;
10897 return ;
10998 }
11099
111- StringBuilder dhparam = new StringBuilder ( "dh2048.pem" ) ;
112-
113100 StringBuilder buff = new StringBuilder ( 1024 ) ;
114101 StringBuilder reply = new StringBuilder ( "Hello, this is the wolfSSL C# wrapper" ) ;
115102
@@ -134,6 +121,12 @@ public static void Main(string[] args)
134121 return ;
135122 }
136123
124+ if ( ! File . Exists ( dhparam . ToString ( ) ) ) {
125+ Console . WriteLine ( "Could not find dh file" ) ;
126+ wolfssl . CTX_free ( ctx ) ;
127+ return ;
128+ }
129+
137130 if ( wolfssl . CTX_use_certificate_file ( ctx , fileCert , wolfssl . SSL_FILETYPE_PEM ) != wolfssl . SUCCESS )
138131 {
139132 Console . WriteLine ( "Error in setting cert file" ) ;
@@ -197,7 +190,14 @@ public static void Main(string[] args)
197190 return ;
198191 }
199192
200- wolfssl . SetTmpDH_file ( ssl , dhparam , wolfssl . SSL_FILETYPE_PEM ) ;
193+ if ( wolfssl . SetTmpDH_file ( ssl , dh2048Pem , wolfssl . SSL_FILETYPE_PEM ) != wolfssl . SUCCESS )
194+ {
195+ Console . WriteLine ( "Error in setting dh2048Pem" ) ;
196+ Console . WriteLine ( wolfssl . get_error ( ssl ) ) ;
197+ tcp . Stop ( ) ;
198+ clean ( ssl , ctx ) ;
199+ return ;
200+ }
201201
202202 if ( wolfssl . accept ( ssl ) != wolfssl . SUCCESS )
203203 {
0 commit comments