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