@@ -155,6 +155,7 @@ public static void Main(string[] args)
155155
156156 Console . WriteLine ( "Started TCP and waiting for a connection" ) ;
157157 fd = tcp . AcceptSocket ( ) ;
158+
158159 ssl = wolfssl . new_ssl ( ctx ) ;
159160 if ( ssl == IntPtr . Zero )
160161 {
@@ -208,6 +209,16 @@ public static void Main(string[] args)
208209 return ;
209210 }
210211
212+ /* get and print sni used by the client */
213+ if ( haveSNI ( args ) ) {
214+ IntPtr data = IntPtr . Zero ;
215+
216+ ushort size = wolfssl . SNI_GetRequest ( ssl , 0 , ref data ) ;
217+ string dataStr = Marshal . PtrToStringAnsi ( data ) ;
218+ Console . WriteLine ( "(SNI_GetRequest) Size of SNI used by client: " + size ) ;
219+ Console . WriteLine ( "(SNI_GetRequest) SNI used by client: " + dataStr ) ;
220+ }
221+
211222 /* print out results of TLS/SSL accept */
212223 Console . WriteLine ( "SSL version is " + wolfssl . get_version ( ssl ) ) ;
213224 Console . WriteLine ( "SSL cipher suite is " + wolfssl . get_current_cipher ( ssl ) ) ;
@@ -222,6 +233,45 @@ public static void Main(string[] args)
222233 }
223234 Console . WriteLine ( buff ) ;
224235
236+ /* get and print sni from a sample buffer, can be used by using the raw client hello */
237+ if ( haveSNI ( args ) ) {
238+ IntPtr result = Marshal . AllocHGlobal ( 32 ) ;
239+ IntPtr inOutSz = Marshal . AllocHGlobal ( sizeof ( int ) ) ;
240+ Marshal . WriteInt32 ( inOutSz , 32 ) ;
241+ byte [ ] buffer = { /* from TextMate website client hello example */
242+ 0x16 , 0x03 , 0x01 , 0x00 , 0xc6 , 0x01 , 0x00 , 0x00 , 0xc2 , 0x03 , 0x03 , 0x52 ,
243+ 0x8b , 0x7b , 0xca , 0x69 , 0xec , 0x97 , 0xd5 , 0x08 , 0x03 , 0x50 , 0xfe , 0x3b ,
244+ 0x99 , 0xc3 , 0x20 , 0xce , 0xa5 , 0xf6 , 0x99 , 0xa5 , 0x71 , 0xf9 , 0x57 , 0x7f ,
245+ 0x04 , 0x38 , 0xf6 , 0x11 , 0x0b , 0xb8 , 0xd3 , 0x00 , 0x00 , 0x5e , 0x00 , 0xff ,
246+ 0xc0 , 0x24 , 0xc0 , 0x23 , 0xc0 , 0x0a , 0xc0 , 0x09 , 0xc0 , 0x07 , 0xc0 , 0x08 ,
247+ 0xc0 , 0x28 , 0xc0 , 0x27 , 0xc0 , 0x14 , 0xc0 , 0x13 , 0xc0 , 0x11 , 0xc0 , 0x12 ,
248+ 0xc0 , 0x26 , 0xc0 , 0x25 , 0xc0 , 0x2a , 0xc0 , 0x29 , 0xc0 , 0x05 , 0xc0 , 0x04 ,
249+ 0xc0 , 0x02 , 0xc0 , 0x03 , 0xc0 , 0x0f , 0xc0 , 0x0e , 0xc0 , 0x0c , 0xc0 , 0x0d ,
250+ 0x00 , 0x3d , 0x00 , 0x3c , 0x00 , 0x2f , 0x00 , 0x05 , 0x00 , 0x04 , 0x00 , 0x35 ,
251+ 0x00 , 0x0a , 0x00 , 0x67 , 0x00 , 0x6b , 0x00 , 0x33 , 0x00 , 0x39 , 0x00 , 0x16 ,
252+ 0x00 , 0xaf , 0x00 , 0xae , 0x00 , 0x8d , 0x00 , 0x8c , 0x00 , 0x8a , 0x00 , 0x8b ,
253+ 0x00 , 0xb1 , 0x00 , 0xb0 , 0x00 , 0x2c , 0x00 , 0x3b , 0x01 , 0x00 , 0x00 , 0x3b ,
254+ 0x00 , 0x00 , 0x00 , 0x15 , 0x00 , 0x13 , 0x00 , 0x00 , 0x10 , 0x61 , 0x70 , 0x69 ,
255+ 0x2e , 0x74 , 0x65 , 0x78 , 0x74 , 0x6d , 0x61 , 0x74 , 0x65 , 0x2e , 0x6f , 0x72 ,
256+ 0x67 , 0x00 , 0x0a , 0x00 , 0x08 , 0x00 , 0x06 , 0x00 , 0x17 , 0x00 , 0x18 , 0x00 ,
257+ 0x19 , 0x00 , 0x0b , 0x00 , 0x02 , 0x01 , 0x00 , 0x00 , 0x0d , 0x00 , 0x0c , 0x00 ,
258+ 0x0a , 0x05 , 0x01 , 0x04 , 0x01 , 0x02 , 0x01 , 0x04 , 0x03 , 0x02 , 0x03
259+ } ;
260+
261+ int ret = wolfssl . SNI_GetFromBuffer ( buffer , 1024 , 0 , result , inOutSz ) ;
262+
263+ if ( ret != wolfssl . SUCCESS ) {
264+ Console . WriteLine ( "Error on reading SNI from buffer, ret value = " + ret ) ;
265+ tcp . Stop ( ) ;
266+ clean ( ssl , ctx ) ;
267+ return ;
268+ }
269+
270+ string resultStr = Marshal . PtrToStringAnsi ( result ) ;
271+ Console . WriteLine ( "(SNI_GetFromBuffer) SNI used by client: " + resultStr ) ;
272+
273+ }
274+
225275 if ( wolfssl . write ( ssl , reply , reply . Length ) != reply . Length )
226276 {
227277 Console . WriteLine ( "Error in write" ) ;
0 commit comments