News  [SoftwareSite

Latest News
Older News
RSS Feed
 
Complete Projects
Useful Classes
Top Downloads
Message Board
AllAPI.net
 
Send Comments
Software License
Mentalis.org Buttons
Donate
 
Forums -> Security Library Forum
 
Accepting and Sending Hangs  
by Bryan [bstenfors at stenco dot net]
posted on 2003/12/09

Hello I have been trying to do a simple client / server sending and accepting with SSL. I have been getting the first package of data to go through but then it seems to hang. I just downloaded the newest version of 1.0.13.693 and tested my application with the new .dll and it still hangs. Any ideas why and if I could possibly fix it on my own?

Thanks,
Bryan

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2003/12/10

Can you post some code? Does your code work without SSL? [if it doesn't work without SSL, it's a problem in your protocol -- ie. both the client and server are waiting for the other side to send something]

by Thomas
posted on 2003/12/12

Hi.

I guess, I'm having the same problem and posted it some time ago (http://www.mentalis.org/forum/thread.qpx/73).

My application is working fine without ssl support, but when I switch ssl support on, I only get a few packets through and then the connections seems to hang. I tried many combinations of security-protocol-options but couldn' get it work ....

Since the project is a little bit bigger and it is more complicated to get it working, I believe, sending you the source code would not be the best idea, or? But if it can help you to determine the problem, I can send you an ethereal trace of the unencrypted and encrypted traffic, so you can redo the traffic and perhaps you can redo the problem, too .....

Nice greetings,
Thomas

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2003/12/15

Our problem is that we cannot reproduce the behavior you're seeing. Having some code would definitely help. I don't think an SSL trace would help us so much.

by Bryan [bstenfors at stenco dot net]
posted on 2003/12/24

The Code is Below:

Imports MSXML2
Imports System
Imports System.Threading
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Net.Sockets
Imports Org.Mentalis.Security.Ssl
Imports Org.Mentalis.Security.Certificates
Public Class frmControlCenter
Inherits System.Windows.Forms.Form

Private mobjDOMXmlMovieWebRealinIni As MSXML2.DOMDocument

'Strings
Private mstrCertSubject As String
Private mstrCertStore As String
Private mstrUsername As String
Private mstrPassword As String
Private mstrDataSource As String
Private mstrInitialCatalog As String

'SSL Vars
Private mobjServerIPAddress As IPAddress
Private mobjProtocol As SecureProtocol
Private mobjServerSecureSocket As SecureSocket
'Threading Vars
Private mobjThreads As System.Threading.Thread
Private intAlreadyListening As Integer
Private mintAlreadySent As Integer
#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents txtServerInput As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtClientInput As System.Windows.Forms.TextBox
Public WithEvents tmrClient As System.Windows.Forms.Timer
Public WithEvents tmrServer As System.Windows.Forms.Timer
Friend WithEvents cmdSendData As System.Windows.Forms.Button
Friend WithEvents txtDataToSend As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.tmrClient = New System.Windows.Forms.Timer(Me.components)
Me.txtServerInput = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtClientInput = New System.Windows.Forms.TextBox()
Me.tmrServer = New System.Windows.Forms.Timer(Me.components)
Me.cmdSendData = New System.Windows.Forms.Button()
Me.txtDataToSend = New System.Windows.Forms.TextBox()
Me.SuspendLayout()
'
'tmrClient
'
Me.tmrClient.Enabled = True
Me.tmrClient.Interval = 4000
'
'txtServerInput
'
Me.txtServerInput.Location = New System.Drawing.Point(8, 38)
Me.txtServerInput.Multiline = True
Me.txtServerInput.Name = "txtServerInput"
Me.txtServerInput.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtServerInput.Size = New System.Drawing.Size(456, 106)
Me.txtServerInput.TabIndex = 0
Me.txtServerInput.Text = ""
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(8, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(109, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Server Input / Output"
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(8, 168)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(105, 13)
Me.Label2.TabIndex = 3
Me.Label2.Text = "Client Input / Output"
'
'txtClientInput
'
Me.txtClientInput.Location = New System.Drawing.Point(8, 192)
Me.txtClientInput.Multiline = True
Me.txtClientInput.Name = "txtClientInput"
Me.txtClientInput.ScrollBars = System.Windows.Forms.ScrollBars.Both
Me.txtClientInput.Size = New System.Drawing.Size(456, 106)
Me.txtClientInput.TabIndex = 2
Me.txtClientInput.Text = ""
'
'tmrServer
'
Me.tmrServer.Enabled = True
Me.tmrServer.Interval = 3000
'
'cmdSendData
'
Me.cmdSendData.Location = New System.Drawing.Point(144, 8)
Me.cmdSendData.Name = "cmdSendData"
Me.cmdSendData.TabIndex = 4
Me.cmdSendData.Text = "Send Data"
'
'txtDataToSend
'
Me.txtDataToSend.Location = New System.Drawing.Point(232, 8)
Me.txtDataToSend.Name = "txtDataToSend"
Me.txtDataToSend.TabIndex = 5
Me.txtDataToSend.Text = ""
'
'frmControlCenter
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(472, 309)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtDataToSend, Me.cmdSendData, Me.Label2, Me.txtClientInput, Me.Label1, Me.txtServerInput})
Me.Name = "frmControlCenter"
Me.Text = "Movie Web Realin Control Center"
Me.ResumeLayout(False)

End Sub

#End Region
Public Sub Listening()
txtServerInput.Text = ""
'If intAlreadyListening = 0 Then
Dim intPort As Integer
Dim lngIPAddress As Long

Dim objServerIPAddress As IPAddress
Dim objProtocol As SecureProtocol

mobjDOMXmlMovieWebRealinIni = New MSXML2.DOMDocument()
mobjDOMXmlMovieWebRealinIni.async = False
mobjDOMXmlMovieWebRealinIni.resolveExternals = True
mobjDOMXmlMovieWebRealinIni.validateOnParse = False
mobjDOMXmlMovieWebRealinIni.load(gstrIniPath)

mstrCertSubject = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("CERTSUBJECT")(0).text
mstrCertStore = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("CERTSTORE")(0).text
''gstrMovieFoneIP = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("MOVIEFONEIP")(0).text
gstrIP = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("IISIP")(0).text
''gstrNonSSLPort = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("NONSSLPORT")(0).text
gstrSSLPort = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("SSLPORT")(0).text
''gstrUpdateSSLPort = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("UPDATESSLPORT")(0).text

''mstrUsername = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("USERNAME")(0).text
''mstrPassword = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("PASSWORD")(0).text
''mstrDataSource = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("DATASOURCE")(0).text
''mstrInitialCatalog = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("INITIALCATALOG")(0).text

Dim objCertStore As New CertificateStore(mstrCertStore)
Dim objCert As New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))

'''Finding the correct certificate by the Subject Name
''objCert = New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))
''Try
objServerIPAddress = IPAddress.Parse(gstrIP)
'' 'MsgBox(objServerIPAddress.ToString)
''Catch
'' MsgBox("Invalid IP Address")
''End Try
''lngIPAddress = CLng(gstrIP)
intPort = gstrSSLPort

Dim objServerEndPoint As New IPEndPoint(objServerIPAddress, intPort)
Dim objServerSecurityOptions As New SecurityOptions(SecureProtocol.Ssl3, objCert, ConnectionEnd.Server)
objServerSecurityOptions.AllowedAlgorithms = SslAlgorithms.ALL
'objServerSecurityOptions.VerificationType = CredentialVerification.Manual
Dim objServerSecureSocket As New SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, objServerSecurityOptions)
'''objServerSecureSocket.Connect(objServerEndPoint)
''objServerSecureSocket.Poll(1000, SelectMode.SelectRead)
'MsgBox(objServerSecureSocket.LocalEndPoint)

objServerSecureSocket.Bind(objServerEndPoint)
objServerSecureSocket.Listen(10)
'MsgBox(objCert.GetName)
txtServerInput.Text = txtServerInput.Text & vbCrLf & "Listening ...... "

Accepting(objServerSecureSocket)
'mobjServerSecureSocket.Close()
tmrServer.Enabled = False
'intAlreadyListening = 1
'End If
End Sub
Public Sub Accepting(ByVal objServerSecureSocket As SecureSocket)
Dim objSecureSocketReader As SecureSocket
Dim intReceived As Integer
Dim intSizeToReceive As Integer
Dim incomingBuffer As Byte() = incomingBuffer.CreateInstance(GetType(Byte), 1024)
Dim settingBuffer As New Byte()
Dim strQuery As String

'tmrClient.Enabled = True

objSecureSocketReader = objServerSecureSocket.Accept
txtServerInput.Text = txtServerInput.Text & vbCrLf & "Ready to accept"
'tmrServer.Enabled = False
Do While objSecureSocketReader.Connected = True
'Do While Not IsComplete(strQuery)
''Try
'' 'intReceived = objSecureSocketReader.Receive(incomingBuffer, 0, incomingBuffer.Length, SocketFlags.None)
'' intReceived = objSecureSocketReader.Receive(incomingBuffer)
''Catch e As Exception
'' txtServerInput.Text = txtServerInput.Text & vbCrLf & "Error while receiving data from client " & e.Message
''End Try
''If intReceived = 0 Then
'' txtServerInput.Text = txtServerInput.Text & vbCrLf & "Client closed connection too soon."
'' objSecureSocketReader.Close()
''End If
objSecureSocketReader.Receive(incomingBuffer)
strQuery += Encoding.ASCII.GetString(incomingBuffer)
'Loop
incomingBuffer.CreateInstance(GetType(Byte), 1024)
txtServerInput.Text = txtServerInput.Text & vbCrLf & strQuery
'objSecureSocketReader.Shutdown(SocketShutdown.Both)
'objSecureSocketReader.Close()
Loop
End Sub
Public Function IsComplete(ByVal strQuery As String) As Boolean
Return strQuery.IndexOf("d") >= 0
End Function
Public Sub ClientConnector(ByVal strData As String)
'If mintAlreadySent = 0 Then
Dim intPort As Integer
Dim lngIPAddress As Long
Dim strByte As String
Dim objClientIPAddress As IPAddress
Dim objProtocol As SecureProtocol


Dim objCertStore As New CertificateStore(mstrCertStore)
Dim objCert As New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))

'Finding the correct certificate by the Subject Name
'objCert = New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))
Try
objClientIPAddress = IPAddress.Parse(gstrIP)
Catch
MsgBox("Invalid IP Address")
End Try
intPort = gstrSSLPort

Dim objClientEndPoint As New IPEndPoint(objClientIPAddress, intPort)
Dim objClientSecurityOptions As New SecurityOptions(SecureProtocol.Ssl3, objCert, ConnectionEnd.Client)
objClientSecurityOptions.CommonName = gstrIP
objClientSecurityOptions.VerificationType = CredentialVerification.None
objClientSecurityOptions.Flags = SecurityFlags.Default
objClientSecurityOptions.AllowedAlgorithms = SslAlgorithms.ALL
Dim objClientSecureSocket As New SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, objClientSecurityOptions)
'objClientSecureSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Linger, 1)

objClientSecureSocket.Connect(objClientEndPoint)
txtClientInput.Text = txtClientInput.Text & vbCrLf & "Connected: " & objClientSecureSocket.Connected & vbCrLf & " Handle: " & objClientSecureSocket.Handle.ToString
Dim intSent As Integer
Dim objAE As New ASCIIEncoding()
strByte = strData '"Good Bye"
Dim bteBuffer As Byte() = objAE.GetBytes(strByte)
'intSent = objClientSecureSocket.Send(bteBuffer, 1, bteBuffer.Length, SocketFlags.None)
'intSent = objClientSecureSocket.Send(bteBuffer)
Do While intSent <> bteBuffer.Length
intSent += objClientSecureSocket.Send(bteBuffer, intSent, bteBuffer.Length - intSent, SocketFlags.None)
Loop
mintAlreadySent = 1
'objClientSecureSocket.Shutdown(SocketShutdown.Send)
'objClientSecureSocket.Close()
'Else
'Dim intPort As Integer
'Dim lngIPAddress As Long
'Dim strByte As String
'Dim objClientIPAddress As IPAddress
'Dim objProtocol As SecureProtocol


'Dim objCertStore As New CertificateStore(mstrCertStore)
'Dim objCert As New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))

''Finding the correct certificate by the Subject Name
''objCert = New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))
'Try
' objClientIPAddress = IPAddress.Parse(gstrIP)
'Catch
' MsgBox("Invalid IP Address")
'End Try
'intPort = gstrSSLPort

'Dim objClientEndPoint As New IPEndPoint(objClientIPAddress, intPort)
'Dim objClientSecurityOptions As New SecurityOptions(SecureProtocol.Ssl3, objCert, ConnectionEnd.Client)
'objClientSecurityOptions.CommonName = gstrIP
'objClientSecurityOptions.VerificationType = CredentialVerification.None
'objClientSecurityOptions.Flags = SecurityFlags.Default
'objClientSecurityOptions.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS
'Dim objClientSecureSocket As New SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, objClientSecurityOptions)

'objClientSecureSocket.Connect(objClientEndPoint)
'txtClientInput.Text = txtClientInput.Text & vbCrLf & "Connected Again: " & objClientSecureSocket.Connected & vbCrLf & " Handle: " & objClientSecureSocket.Handle.ToString
'Dim intSent As Integer
'Dim objAE As New ASCIIEncoding()
'strByte = strData '"Good Bye"
'Dim bteBuffer As Byte() = objAE.GetBytes(strByte)
''intSent = objClientSecureSocket.Send(bteBuffer, 1, bteBuffer.Length, SocketFlags.None)
''intSent = objClientSecureSocket.Send(bteBuffer)
'Do While intSent <> bteBuffer.Length
' intSent += objClientSecureSocket.Send(bteBuffer, intSent, bteBuffer.Length - intSent, SocketFlags.None)
'Loop
'End If

End Sub
Private Sub tmrClient_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrClient.Tick
'ClientConnector()
'MsgBox("Hello World")
Dim intPort As Integer
Dim lngIPAddress As Long
Dim strByte As String
Dim objClientIPAddress As IPAddress
Dim objProtocol As SecureProtocol


Dim objCertStore As New CertificateStore(mstrCertStore)
Dim objCert As New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))

'Finding the correct certificate by the Subject Name
'objCert = New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))
Try
objClientIPAddress = IPAddress.Parse(gstrIP)
Catch
MsgBox("Invalid IP Address")
End Try
intPort = gstrSSLPort

Dim objClientEndPoint As New IPEndPoint(objClientIPAddress, intPort)
Dim objClientSecurityOptions As New SecurityOptions(SecureProtocol.Ssl3, objCert, ConnectionEnd.Client)
objClientSecurityOptions.CommonName = gstrIP
objClientSecurityOptions.VerificationType = CredentialVerification.None
objClientSecurityOptions.Flags = SecurityFlags.Default
objClientSecurityOptions.AllowedAlgorithms = SslAlgorithms.SECURE_CIPHERS
Dim objClientSecureSocket As New SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, objClientSecurityOptions)

objClientSecureSocket.Connect(objClientEndPoint)
txtClientInput.Text = txtClientInput.Text & vbCrLf & "Connected: " & objClientSecureSocket.Connected & vbCrLf & " Handle: " & objClientSecureSocket.Handle.ToString
Dim intSent As Integer
Dim objAE As New ASCIIEncoding()
strByte = "Good Bye"
Dim bteBuffer As Byte() = objAE.GetBytes(strByte)
'intSent = objClientSecureSocket.Send(bteBuffer, 1, bteBuffer.Length, SocketFlags.None)
'intSent = objClientSecureSocket.Send(bteBuffer)
Do While intSent <> bteBuffer.Length
intSent += objClientSecureSocket.Send(bteBuffer, intSent, bteBuffer.Length - intSent, SocketFlags.None)
Loop
objClientSecureSocket.Shutdown(SocketShutdown.Both)
objClientSecureSocket.Close()
End Sub

Private Sub tmrServer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrServer.Tick
'If intAlreadyListening = 0 Then
mobjThreads = New System.Threading.Thread(AddressOf Listening)
mobjThreads.Start()
intAlreadyListening = 1
'End If
''Listening()
End Sub

Private Sub frmControlCenter_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
''txtServerInput.Text = ""
'''If intAlreadyListening = 0 Then
''Dim intPort As Integer
''Dim lngIPAddress As Long

''Dim objServerIPAddress As IPAddress
''Dim objProtocol As SecureProtocol

''mobjDOMXmlMovieWebRealinIni = New MSXML2.DOMDocument()
''mobjDOMXmlMovieWebRealinIni.async = False
''mobjDOMXmlMovieWebRealinIni.resolveExternals = True
''mobjDOMXmlMovieWebRealinIni.validateOnParse = False
''mobjDOMXmlMovieWebRealinIni.load(gstrIniPath)

''mstrCertSubject = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("CERTSUBJECT")(0).text
''mstrCertStore = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("CERTSTORE")(0).text
''''gstrMovieFoneIP = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("MOVIEFONEIP")(0).text
''gstrIP = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("IISIP")(0).text
''''gstrNonSSLPort = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("NONSSLPORT")(0).text
''gstrSSLPort = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("SSLPORT")(0).text
''''gstrUpdateSSLPort = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("UPDATESSLPORT")(0).text

''''mstrUsername = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("USERNAME")(0).text
''''mstrPassword = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("PASSWORD")(0).text
''''mstrDataSource = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("DATASOURCE")(0).text
''''mstrInitialCatalog = mobjDOMXmlMovieWebRealinIni.getElementsByTagName("INITIALCATALOG")(0).text

''Dim objCertStore As New CertificateStore(mstrCertStore)
''Dim objCert As New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))

'''''Finding the correct certificate by the Subject Name
''''objCert = New Certificate(objCertStore.FindCertificateBySubjectName(mstrCertSubject))
''''Try
''objServerIPAddress = IPAddress.Parse(gstrIP)
'''' 'MsgBox(objServerIPAddress.ToString)
''''Catch
'''' MsgBox("Invalid IP Address")
''''End Try
''''lngIPAddress = CLng(gstrIP)
''intPort = gstrSSLPort

''Dim objServerEndPoint As New IPEndPoint(objServerIPAddress, intPort)
''Dim objServerSecurityOptions As New SecurityOptions(SecureProtocol.Ssl3, objCert, ConnectionEnd.Server)
'''objServerSecurityOptions.VerificationType = CredentialVerification.Manual
''Dim objServerSecureSocket As New SecureSocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, objServerSecurityOptions)
'''''objServerSecureSocket.Connect(objServerEndPoint)
''''objServerSecureSocket.Poll(1000, SelectMode.SelectRead)
'''MsgBox(objServerSecureSocket.LocalEndPoint)

''objServerSecureSocket.Bind(objServerEndPoint)
''objServerSecureSocket.Listen(10)
'''MsgBox(objCert.GetName)
''txtServerInput.Text = txtServerInput.Text & vbCrLf & "Listening ...... "

''Accepting(objServerSecureSocket)
'''mobjServerSecureSocket.Close()
''tmrServer.Enabled = False
'''intAlreadyListening = 1
'''End If
End Sub

Private Sub cmdSendData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSendData.Click
ClientConnector(txtDataToSend.Text)
End Sub

by Pieter Philippaerts [Pieter at mentalis dot org]
posted on 2004/01/12

Ok, thanks, I'll see if I can reproduce the problem here as soon as I've got some free time on my hands.

by Bryan [bstenfors at stenco dot net]
posted on 2004/01/12

Thanks I will be looking for your response.

Thanks again,
Bryan

by Bryan [bstenfors at stenco dot net]
posted on 2004/03/01

Anything going on this question?

Thanks,
Bryan

 

Copyright © 2002-2007, The Mentalis.org Team. All rights reserved.
This site is located at http://www.mentalis.org/
Send comments to the webmaster.