Hello, First: I am using OpenSSL 0.9.8a (pre-compiled binaries from http://nakka.com/soft/npop/download/npopssl/npopssl002mips.zip) on both Windows CE 2.11 and 3.0 (HPC Pro and HPC2000 respectively) with .NET Compact Framework 1.0 SP3. I have successfully been able to use OpenSSL 0.9.8k in a sample HTTPS client on my XP64 desktop with .NET Framework 2.0 with no problems.
I copied the code from my desktop project over to a .NET CF 1.0 project which compiled fine with no errors. When running my compiled sample application on either of my devices, SSL_connect() fails, but other functions used prior to that do not fail. My socket is connected and I get a valid pointer/handle back from SSL_new(). After SSL_connect() fails, I call SSL_get_error() and it gives me a value of 5 (SSL_ERROR_SYSCALL). A call to CE's GetLastError() on the CE 2.11 device consistently gives me an error value of 6 (ERROR_INVALID_HANDLE) and the CE 3.0 device it consistently gives me an error value of 120 (ERROR_CALL_NOT_IMPLEMENTED). >From my debugging experience while working on the desktop version of my sample program, the SSL_ERROR_SYSCALL usually means the underlying socket is disconnected or something related to the socket. Has anyone else had much experience with the CE port or have any suggestions on what might be causing this problem? Here's the code I'm currently using: <DllImport("libeay32.dll", EntryPoint:="BIO_new_socket", SetLastError:=True)> _ Public Shared Function BIO_new_socket(ByVal socket As IntPtr, ByVal flag As Integer) As IntPtr End Function <DllImport("libeay32.dll", EntryPoint:="OPENSSL_add_all_algorithms_noconf", SetLastError:=True)> _ Public Shared Sub OPENSSL_add_all_algorithms_noconf() End Sub <DllImport("ssleay32.dll", EntryPoint:="SSL_connect", SetLastError:=True)> _ Public Shared Function SSL_connect(ByVal sslSocket As IntPtr) As Integer End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_CTX_new", SetLastError:=True)> _ Public Shared Function SSL_CTX_new(ByVal ptr As IntPtr) As IntPtr End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_CTX_free", SetLastError:=True)> _ Public Shared Sub SSL_CTX_free(ByVal ssl As IntPtr) End Sub <DllImport("ssleay32.dll", EntryPoint:="SSL_get_error", SetLastError:=True)> _ Public Shared Function SSL_get_error(ByVal ssl As IntPtr, ByVal ret As Integer) As Integer End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_library_init", SetLastError:=True)> _ Public Shared Function SSL_library_init() As Integer End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_new", SetLastError:=True)> _ Public Shared Function SSL_new(ByVal ptr As IntPtr) As IntPtr End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_read", SetLastError:=True)> _ Public Shared Function SSL_read(ByVal ssl As IntPtr, ByVal buf() As Byte, ByVal num As Integer) As Integer End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_set_bio", SetLastError:=True)> _ Public Shared Sub SSL_set_bio(ByVal ssl As IntPtr, ByVal BioRbio As IntPtr, ByVal BioWbio As IntPtr) End Sub <DllImport("ssleay32.dll", EntryPoint:="SSL_shutdown", SetLastError:=True)> _ Public Shared Function SSL_shutdown(ByVal ssl As IntPtr) As Integer End Function <DllImport("ssleay32.dll", EntryPoint:="SSL_write", SetLastError:=True)> _ Public Shared Function SSL_write(ByVal ssl As IntPtr, ByVal buf() As Byte, ByVal num As Integer) As Integer End Function <DllImport("ssleay32.dll", EntryPoint:="SSLv23_client_method", SetLastError:=True)> _ Public Shared Function SSLv23_client_method() As IntPtr End Function Private Sub foo() Dim request As String = "GET / HTTP/1.1" + vbCrLf + "Connection: Close" + vbCrLf + vbCrLf Dim bRequest() As Byte = System.Text.Encoding.ASCII.GetBytes(request) Dim bReceived(1024) As Byte Dim numBytes As Integer Dim mySocket As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) Dim epHost As New IPEndPoint(Dns.GetHostByName("mail.google.com").AddressList(0), 443) ' random SSL-enforcing server for testing purposes mySocket.Blocking = True mySocket.Connect(epHost) If mySocket.Connected Then SSL_library_init() OPENSSL_add_all_algorithms_noconf() Dim sslCtx As IntPtr = SSL_CTX_new(SSLv23_client_method()) Dim ssl_socket As IntPtr = SSL_new(sslCtx) Dim sbioPtr As IntPtr = BIO_new_socket(mySocket.Handle, 0) SSL_set_bio(ssl_socket, sbioPtr, sbioPtr) Dim connOK As Integer = SSL_connect(ssl_socket) If connOK = 1 Then mySocket.Blocking = True Dim numWritten As Integer = SSL_write(ssl_socket, bRequest, bRequest.Length) If numWritten > 0 Then TextBox1.Text = "" Do numBytes = SSL_read(ssl_socket, bReceived, bReceived.Length) TextBox1.Text += System.Text.Encoding.ASCII.GetString(bReceived, 0, numBytes) Loop While numBytes > 0 If numBytes <= 0 Then Dim errcode As Integer = SSL_get_error(ssl_socket, numBytes) MsgBox("SSL Error: " + errcode.ToString) If errcode = 5 Then MsgBox("GLE = " + Marshal.GetLastWin32Error.ToString) End If End If Else MsgBox("OpenSSL's SSL_write() failed") Dim errcode As Integer = SSL_get_error(ssl_socket, numWritten) MsgBox("SSL Error: " + errcode.ToString) If errcode = 5 Then MsgBox("GLE = " + Marshal.GetLastWin32Error.ToString) End If End If SSL_shutdown(ssl_socket) Else MsgBox("OpenSSL's SSL_connect() failed") Dim errcode As Integer = SSL_get_error(ssl_socket, connOK) MsgBox("SSL Error: " + errcode.ToString) If errcode = 5 Then MsgBox("GLE = " + Marshal.GetLastWin32Error.ToString) End If End If mySocket.Close() Else MsgBox("Socket's connect() failed") End If End Sub -- Brian W.