axssl.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /*
  2. * Copyright (c) 2007, Cameron Rich
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * * Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * * Neither the name of the axTLS project nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. /**
  31. * Demonstrate the use of the axTLS library in C# with a set of
  32. * command-line parameters similar to openssl. In fact, openssl clients
  33. * should be able to communicate with axTLS servers and visa-versa.
  34. *
  35. * This code has various bits enabled depending on the configuration. To enable
  36. * the most interesting version, compile with the 'full mode' enabled.
  37. *
  38. * To see what options you have, run the following:
  39. * > axssl.csharp.exe s_server -?
  40. * > axssl.csharp.exe s_client -?
  41. *
  42. * The axtls shared library must be in the same directory or be found
  43. * by the OS.
  44. */
  45. using System;
  46. using System.Net;
  47. using System.Net.Sockets;
  48. using axTLS;
  49. public class axssl
  50. {
  51. /*
  52. * Main()
  53. */
  54. public static void Main(string[] args)
  55. {
  56. if (args.Length == 1 && args[0] == "version")
  57. {
  58. Console.WriteLine("axssl.csharp " + SSLUtil.Version());
  59. Environment.Exit(0);
  60. }
  61. axssl runner = new axssl();
  62. if (args.Length < 1 || (args[0] != "s_server" && args[0] != "s_client"))
  63. runner.print_options(args.Length > 0 ? args[0] : "");
  64. int build_mode = SSLUtil.BuildMode();
  65. if (args[0] == "s_server")
  66. runner.do_server(build_mode, args);
  67. else
  68. runner.do_client(build_mode, args);
  69. }
  70. /*
  71. * do_server()
  72. */
  73. private void do_server(int build_mode, string[] args)
  74. {
  75. int i = 1;
  76. int port = 4433;
  77. uint options = axtls.SSL_DISPLAY_CERTS;
  78. bool quiet = false;
  79. string password = null;
  80. string private_key_file = null;
  81. /* organise the cert/ca_cert lists */
  82. int cert_size = SSLUtil.MaxCerts();
  83. int ca_cert_size = SSLUtil.MaxCACerts();
  84. string[] cert = new string[cert_size];
  85. string[] ca_cert = new string[ca_cert_size];
  86. int cert_index = 0;
  87. int ca_cert_index = 0;
  88. while (i < args.Length)
  89. {
  90. if (args[i] == "-accept")
  91. {
  92. if (i >= args.Length-1)
  93. {
  94. print_server_options(build_mode, args[i]);
  95. }
  96. port = Int32.Parse(args[++i]);
  97. }
  98. else if (args[i] == "-quiet")
  99. {
  100. quiet = true;
  101. options &= ~(uint)axtls.SSL_DISPLAY_CERTS;
  102. }
  103. else if (build_mode >= axtls.SSL_BUILD_SERVER_ONLY)
  104. {
  105. if (args[i] == "-cert")
  106. {
  107. if (i >= args.Length-1 || cert_index >= cert_size)
  108. {
  109. print_server_options(build_mode, args[i]);
  110. }
  111. cert[cert_index++] = args[++i];
  112. }
  113. else if (args[i] == "-key")
  114. {
  115. if (i >= args.Length-1)
  116. {
  117. print_server_options(build_mode, args[i]);
  118. }
  119. private_key_file = args[++i];
  120. options |= axtls.SSL_NO_DEFAULT_KEY;
  121. }
  122. else if (args[i] == "-pass")
  123. {
  124. if (i >= args.Length-1)
  125. {
  126. print_server_options(build_mode, args[i]);
  127. }
  128. password = args[++i];
  129. }
  130. else if (build_mode >= axtls.SSL_BUILD_ENABLE_VERIFICATION)
  131. {
  132. if (args[i] == "-verify")
  133. {
  134. options |= axtls.SSL_CLIENT_AUTHENTICATION;
  135. }
  136. else if (args[i] == "-CAfile")
  137. {
  138. if (i >= args.Length-1 || ca_cert_index >= ca_cert_size)
  139. {
  140. print_server_options(build_mode, args[i]);
  141. }
  142. ca_cert[ca_cert_index++] = args[++i];
  143. }
  144. else if (build_mode == axtls.SSL_BUILD_FULL_MODE)
  145. {
  146. if (args[i] == "-debug")
  147. {
  148. options |= axtls.SSL_DISPLAY_BYTES;
  149. }
  150. else if (args[i] == "-state")
  151. {
  152. options |= axtls.SSL_DISPLAY_STATES;
  153. }
  154. else if (args[i] == "-show-rsa")
  155. {
  156. options |= axtls.SSL_DISPLAY_RSA;
  157. }
  158. else
  159. print_server_options(build_mode, args[i]);
  160. }
  161. else
  162. print_server_options(build_mode, args[i]);
  163. }
  164. else
  165. print_server_options(build_mode, args[i]);
  166. }
  167. else
  168. print_server_options(build_mode, args[i]);
  169. i++;
  170. }
  171. /* Create socket for incoming connections */
  172. IPEndPoint ep = new IPEndPoint(IPAddress.Any, port);
  173. TcpListener server_sock = new TcpListener(ep);
  174. server_sock.Start();
  175. /**********************************************************************
  176. * This is where the interesting stuff happens. Up until now we've
  177. * just been setting up sockets etc. Now we do the SSL handshake.
  178. **********************************************************************/
  179. SSLServer ssl_ctx = new SSLServer(
  180. options, axtls.SSL_DEFAULT_SVR_SESS);
  181. if (ssl_ctx == null)
  182. {
  183. Console.Error.WriteLine("Error: Server context is invalid");
  184. Environment.Exit(1);
  185. }
  186. if (private_key_file != null)
  187. {
  188. int obj_type = axtls.SSL_OBJ_RSA_KEY;
  189. if (private_key_file.EndsWith(".p8"))
  190. obj_type = axtls.SSL_OBJ_PKCS8;
  191. else if (private_key_file.EndsWith(".p12"))
  192. obj_type = axtls.SSL_OBJ_PKCS12;
  193. if (ssl_ctx.ObjLoad(obj_type,
  194. private_key_file, password) != axtls.SSL_OK)
  195. {
  196. Console.Error.WriteLine("Private key '" + private_key_file +
  197. "' is undefined.");
  198. Environment.Exit(1);
  199. }
  200. }
  201. for (i = 0; i < cert_index; i++)
  202. {
  203. if (ssl_ctx.ObjLoad(axtls.SSL_OBJ_X509_CERT,
  204. cert[i], null) != axtls.SSL_OK)
  205. {
  206. Console.WriteLine("Certificate '" + cert[i] +
  207. "' is undefined.");
  208. Environment.Exit(1);
  209. }
  210. }
  211. for (i = 0; i < ca_cert_index; i++)
  212. {
  213. if (ssl_ctx.ObjLoad(axtls.SSL_OBJ_X509_CACERT,
  214. ca_cert[i], null) != axtls.SSL_OK)
  215. {
  216. Console.WriteLine("Certificate '" + cert[i] +
  217. "' is undefined.");
  218. Environment.Exit(1);
  219. }
  220. }
  221. byte[] buf = null;
  222. int res;
  223. for (;;)
  224. {
  225. if (!quiet)
  226. {
  227. Console.WriteLine("ACCEPT");
  228. }
  229. Socket client_sock = server_sock.AcceptSocket();
  230. SSL ssl = ssl_ctx.Connect(client_sock);
  231. /* do the actual SSL handshake */
  232. while ((res = ssl_ctx.Read(ssl, out buf)) == axtls.SSL_OK)
  233. {
  234. /* check when the connection has been established */
  235. if (ssl.HandshakeStatus() == axtls.SSL_OK)
  236. break;
  237. /* could do something else here */
  238. }
  239. if (res == axtls.SSL_OK) /* connection established and ok */
  240. {
  241. if (!quiet)
  242. {
  243. display_session_id(ssl);
  244. display_cipher(ssl);
  245. }
  246. /* now read (and display) whatever the client sends us */
  247. for (;;)
  248. {
  249. /* keep reading until we get something interesting */
  250. while ((res = ssl_ctx.Read(ssl, out buf)) == axtls.SSL_OK)
  251. {
  252. /* could do something else here */
  253. }
  254. if (res < axtls.SSL_OK)
  255. {
  256. if (!quiet)
  257. {
  258. Console.WriteLine("CONNECTION CLOSED");
  259. }
  260. break;
  261. }
  262. /* convert to string */
  263. char[] str = new char[res];
  264. for (i = 0; i < res; i++)
  265. {
  266. str[i] = (char)buf[i];
  267. }
  268. Console.Write(str);
  269. }
  270. }
  271. else if (!quiet)
  272. {
  273. SSLUtil.DisplayError(res);
  274. }
  275. /* client was disconnected or the handshake failed. */
  276. ssl.Dispose();
  277. client_sock.Close();
  278. }
  279. /* ssl_ctx.Dispose(); */
  280. }
  281. /*
  282. * do_client()
  283. */
  284. private void do_client(int build_mode, string[] args)
  285. {
  286. if (build_mode < axtls.SSL_BUILD_ENABLE_CLIENT)
  287. {
  288. print_client_options(build_mode, args[1]);
  289. }
  290. int i = 1, res;
  291. int port = 4433;
  292. bool quiet = false;
  293. string password = null;
  294. int reconnect = 0;
  295. string private_key_file = null;
  296. string hostname = "127.0.0.1";
  297. /* organise the cert/ca_cert lists */
  298. int cert_index = 0;
  299. int ca_cert_index = 0;
  300. int cert_size = SSLUtil.MaxCerts();
  301. int ca_cert_size = SSLUtil.MaxCACerts();
  302. string[] cert = new string[cert_size];
  303. string[] ca_cert = new string[ca_cert_size];
  304. uint options = axtls.SSL_SERVER_VERIFY_LATER|axtls.SSL_DISPLAY_CERTS;
  305. byte[] session_id = null;
  306. while (i < args.Length)
  307. {
  308. if (args[i] == "-connect")
  309. {
  310. string host_port;
  311. if (i >= args.Length-1)
  312. {
  313. print_client_options(build_mode, args[i]);
  314. }
  315. host_port = args[++i];
  316. int index_colon;
  317. if ((index_colon = host_port.IndexOf(':')) < 0)
  318. print_client_options(build_mode, args[i]);
  319. hostname = new string(host_port.ToCharArray(),
  320. 0, index_colon);
  321. port = Int32.Parse(new String(host_port.ToCharArray(),
  322. index_colon+1, host_port.Length-index_colon-1));
  323. }
  324. else if (args[i] == "-cert")
  325. {
  326. if (i >= args.Length-1 || cert_index >= cert_size)
  327. {
  328. print_client_options(build_mode, args[i]);
  329. }
  330. cert[cert_index++] = args[++i];
  331. }
  332. else if (args[i] == "-key")
  333. {
  334. if (i >= args.Length-1)
  335. {
  336. print_client_options(build_mode, args[i]);
  337. }
  338. private_key_file = args[++i];
  339. options |= axtls.SSL_NO_DEFAULT_KEY;
  340. }
  341. else if (args[i] == "-CAfile")
  342. {
  343. if (i >= args.Length-1 || ca_cert_index >= ca_cert_size)
  344. {
  345. print_client_options(build_mode, args[i]);
  346. }
  347. ca_cert[ca_cert_index++] = args[++i];
  348. }
  349. else if (args[i] == "-verify")
  350. {
  351. options &= ~(uint)axtls.SSL_SERVER_VERIFY_LATER;
  352. }
  353. else if (args[i] == "-reconnect")
  354. {
  355. reconnect = 4;
  356. }
  357. else if (args[i] == "-quiet")
  358. {
  359. quiet = true;
  360. options &= ~(uint)axtls.SSL_DISPLAY_CERTS;
  361. }
  362. else if (args[i] == "-pass")
  363. {
  364. if (i >= args.Length-1)
  365. {
  366. print_client_options(build_mode, args[i]);
  367. }
  368. password = args[++i];
  369. }
  370. else if (build_mode == axtls.SSL_BUILD_FULL_MODE)
  371. {
  372. if (args[i] == "-debug")
  373. {
  374. options |= axtls.SSL_DISPLAY_BYTES;
  375. }
  376. else if (args[i] == "-state")
  377. {
  378. options |= axtls.SSL_DISPLAY_STATES;
  379. }
  380. else if (args[i] == "-show-rsa")
  381. {
  382. options |= axtls.SSL_DISPLAY_RSA;
  383. }
  384. else
  385. print_client_options(build_mode, args[i]);
  386. }
  387. else /* don't know what this is */
  388. print_client_options(build_mode, args[i]);
  389. i++;
  390. }
  391. // IPHostEntry hostInfo = Dns.Resolve(hostname);
  392. IPHostEntry hostInfo = Dns.GetHostEntry(hostname);
  393. IPAddress[] addresses = hostInfo.AddressList;
  394. IPEndPoint ep = new IPEndPoint(addresses[0], port);
  395. Socket client_sock = new Socket(AddressFamily.InterNetwork,
  396. SocketType.Stream, ProtocolType.Tcp);
  397. client_sock.Connect(ep);
  398. if (!client_sock.Connected)
  399. {
  400. Console.WriteLine("could not connect");
  401. Environment.Exit(1);
  402. }
  403. if (!quiet)
  404. {
  405. Console.WriteLine("CONNECTED");
  406. }
  407. /**********************************************************************
  408. * This is where the interesting stuff happens. Up until now we've
  409. * just been setting up sockets etc. Now we do the SSL handshake.
  410. **********************************************************************/
  411. SSLClient ssl_ctx = new SSLClient(options,
  412. axtls.SSL_DEFAULT_CLNT_SESS);
  413. if (ssl_ctx == null)
  414. {
  415. Console.Error.WriteLine("Error: Client context is invalid");
  416. Environment.Exit(1);
  417. }
  418. if (private_key_file != null)
  419. {
  420. int obj_type = axtls.SSL_OBJ_RSA_KEY;
  421. if (private_key_file.EndsWith(".p8"))
  422. obj_type = axtls.SSL_OBJ_PKCS8;
  423. else if (private_key_file.EndsWith(".p12"))
  424. obj_type = axtls.SSL_OBJ_PKCS12;
  425. if (ssl_ctx.ObjLoad(obj_type,
  426. private_key_file, password) != axtls.SSL_OK)
  427. {
  428. Console.Error.WriteLine("Private key '" + private_key_file +
  429. "' is undefined.");
  430. Environment.Exit(1);
  431. }
  432. }
  433. for (i = 0; i < cert_index; i++)
  434. {
  435. if (ssl_ctx.ObjLoad(axtls.SSL_OBJ_X509_CERT,
  436. cert[i], null) != axtls.SSL_OK)
  437. {
  438. Console.WriteLine("Certificate '" + cert[i] +
  439. "' is undefined.");
  440. Environment.Exit(1);
  441. }
  442. }
  443. for (i = 0; i < ca_cert_index; i++)
  444. {
  445. if (ssl_ctx.ObjLoad(axtls.SSL_OBJ_X509_CACERT,
  446. ca_cert[i], null) != axtls.SSL_OK)
  447. {
  448. Console.WriteLine("Certificate '" + cert[i] +
  449. "' is undefined.");
  450. Environment.Exit(1);
  451. }
  452. }
  453. SSL ssl = new SSL(new IntPtr(0)); /* keep compiler happy */
  454. /* Try session resumption? */
  455. if (reconnect > 0)
  456. {
  457. while (reconnect-- > 0)
  458. {
  459. ssl = ssl_ctx.Connect(client_sock, session_id);
  460. if ((res = ssl.HandshakeStatus()) != axtls.SSL_OK)
  461. {
  462. if (!quiet)
  463. {
  464. SSLUtil.DisplayError(res);
  465. }
  466. ssl.Dispose();
  467. Environment.Exit(1);
  468. }
  469. display_session_id(ssl);
  470. session_id = ssl.GetSessionId();
  471. if (reconnect > 0)
  472. {
  473. ssl.Dispose();
  474. client_sock.Close();
  475. /* and reconnect */
  476. client_sock = new Socket(AddressFamily.InterNetwork,
  477. SocketType.Stream, ProtocolType.Tcp);
  478. client_sock.Connect(ep);
  479. }
  480. }
  481. }
  482. else
  483. {
  484. ssl = ssl_ctx.Connect(client_sock, null);
  485. }
  486. /* check the return status */
  487. if ((res = ssl.HandshakeStatus()) != axtls.SSL_OK)
  488. {
  489. if (!quiet)
  490. {
  491. SSLUtil.DisplayError(res);
  492. }
  493. Environment.Exit(1);
  494. }
  495. if (!quiet)
  496. {
  497. string common_name =
  498. ssl.GetCertificateDN(axtls.SSL_X509_CERT_COMMON_NAME);
  499. if (common_name != null)
  500. {
  501. Console.WriteLine("Common Name:\t\t\t" + common_name);
  502. }
  503. display_session_id(ssl);
  504. display_cipher(ssl);
  505. }
  506. for (;;)
  507. {
  508. string user_input = Console.ReadLine();
  509. if (user_input == null)
  510. break;
  511. byte[] buf = new byte[user_input.Length+2];
  512. buf[buf.Length-2] = (byte)'\n'; /* add the carriage return */
  513. buf[buf.Length-1] = 0; /* null terminate */
  514. for (i = 0; i < buf.Length-2; i++)
  515. {
  516. buf[i] = (byte)user_input[i];
  517. }
  518. if ((res = ssl_ctx.Write(ssl, buf, buf.Length)) < axtls.SSL_OK)
  519. {
  520. if (!quiet)
  521. {
  522. SSLUtil.DisplayError(res);
  523. }
  524. break;
  525. }
  526. }
  527. ssl_ctx.Dispose();
  528. }
  529. /**
  530. * We've had some sort of command-line error. Print out the basic options.
  531. */
  532. private void print_options(string option)
  533. {
  534. Console.WriteLine("axssl: Error: '" + option +
  535. "' is an invalid command.");
  536. Console.WriteLine("usage: axssl.csharp [s_server|" +
  537. "s_client|version] [args ...]");
  538. Environment.Exit(1);
  539. }
  540. /**
  541. * We've had some sort of command-line error. Print out the server options.
  542. */
  543. private void print_server_options(int build_mode, string option)
  544. {
  545. int cert_size = SSLUtil.MaxCerts();
  546. int ca_cert_size = SSLUtil.MaxCACerts();
  547. Console.WriteLine("unknown option " + option);
  548. Console.WriteLine("usage: s_server [args ...]");
  549. Console.WriteLine(" -accept arg\t- port to accept on (default " +
  550. "is 4433)");
  551. Console.WriteLine(" -quiet\t\t- No server output");
  552. if (build_mode >= axtls.SSL_BUILD_SERVER_ONLY)
  553. {
  554. Console.WriteLine(" -cert arg\t- certificate file to add (in " +
  555. "addition to default) to chain -");
  556. Console.WriteLine("\t\t Can repeat up to " + cert_size + " times");
  557. Console.WriteLine(" -key arg\t- Private key file to use");
  558. Console.WriteLine(" -pass\t\t- private key file pass phrase source");
  559. }
  560. if (build_mode >= axtls.SSL_BUILD_ENABLE_VERIFICATION)
  561. {
  562. Console.WriteLine(" -verify\t- turn on peer certificate " +
  563. "verification");
  564. Console.WriteLine(" -CAfile arg\t- Certificate authority.");
  565. Console.WriteLine("\t\t Can repeat up to " +
  566. ca_cert_size + "times");
  567. }
  568. if (build_mode == axtls.SSL_BUILD_FULL_MODE)
  569. {
  570. Console.WriteLine(" -debug\t\t- Print more output");
  571. Console.WriteLine(" -state\t\t- Show state messages");
  572. Console.WriteLine(" -show-rsa\t- Show RSA state");
  573. }
  574. Environment.Exit(1);
  575. }
  576. /**
  577. * We've had some sort of command-line error. Print out the client options.
  578. */
  579. private void print_client_options(int build_mode, string option)
  580. {
  581. int cert_size = SSLUtil.MaxCerts();
  582. int ca_cert_size = SSLUtil.MaxCACerts();
  583. Console.WriteLine("unknown option " + option);
  584. if (build_mode >= axtls.SSL_BUILD_ENABLE_CLIENT)
  585. {
  586. Console.WriteLine("usage: s_client [args ...]");
  587. Console.WriteLine(" -connect host:port - who to connect to " +
  588. "(default is localhost:4433)");
  589. Console.WriteLine(" -verify\t- turn on peer certificate " +
  590. "verification");
  591. Console.WriteLine(" -cert arg\t- certificate file to use");
  592. Console.WriteLine("\t\t Can repeat up to %d times", cert_size);
  593. Console.WriteLine(" -key arg\t- Private key file to use");
  594. Console.WriteLine(" -CAfile arg\t- Certificate authority.");
  595. Console.WriteLine("\t\t Can repeat up to " + ca_cert_size +
  596. " times");
  597. Console.WriteLine(" -quiet\t\t- No client output");
  598. Console.WriteLine(" -pass\t\t- private key file pass " +
  599. "phrase source");
  600. Console.WriteLine(" -reconnect\t- Drop and re-make the " +
  601. "connection with the same Session-ID");
  602. if (build_mode == axtls.SSL_BUILD_FULL_MODE)
  603. {
  604. Console.WriteLine(" -debug\t\t- Print more output");
  605. Console.WriteLine(" -state\t\t- Show state messages");
  606. Console.WriteLine(" -show-rsa\t- Show RSA state");
  607. }
  608. }
  609. else
  610. {
  611. Console.WriteLine("Change configuration to allow this feature");
  612. }
  613. Environment.Exit(1);
  614. }
  615. /**
  616. * Display what cipher we are using
  617. */
  618. private void display_cipher(SSL ssl)
  619. {
  620. Console.Write("CIPHER is ");
  621. switch (ssl.GetCipherId())
  622. {
  623. case axtls.SSL_AES128_SHA:
  624. Console.WriteLine("AES128-SHA");
  625. break;
  626. case axtls.SSL_AES256_SHA:
  627. Console.WriteLine("AES256-SHA");
  628. break;
  629. case axtls.SSL_RC4_128_SHA:
  630. Console.WriteLine("RC4-SHA");
  631. break;
  632. case axtls.SSL_RC4_128_MD5:
  633. Console.WriteLine("RC4-MD5");
  634. break;
  635. default:
  636. Console.WriteLine("Unknown - " + ssl.GetCipherId());
  637. break;
  638. }
  639. }
  640. /**
  641. * Display what session id we have.
  642. */
  643. private void display_session_id(SSL ssl)
  644. {
  645. byte[] session_id = ssl.GetSessionId();
  646. if (session_id.Length > 0)
  647. {
  648. Console.WriteLine("-----BEGIN SSL SESSION PARAMETERS-----");
  649. foreach (byte b in session_id)
  650. {
  651. Console.Write("{0:x02}", b);
  652. }
  653. Console.WriteLine("\n-----END SSL SESSION PARAMETERS-----");
  654. }
  655. }
  656. }