hungdluit / flowlib

Automatically exported from code.google.com/p/flowlib
0 stars 0 forks source link

Self Signed SSL Certificates #47

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
I am trying to build a bot for a ADCS hub. The hub is using a self signed
SSL certificate and on connecting the following unhanded exception stops
execution:

System.Security.Authentication.AuthenticationException: The remote
certificate is invalid according to the validation procedure.

I tried XMPL which also uses flowlib to see if it was just wrong coding on
my behalf but this is the XMPL dump:

*****************************
Version: 20090108
Is Mono?: False
Is Installed?: True
Connection Mode: 1
IP: 146.232.***.********************************
System.Security.Authentication.AuthenticationException: The remote
certificate is invalid according to the validation procedure.
   at System.Net.Security.SslState.CheckThrow(Boolean authSucessCheck)
   at System.Net.Security.SslState.get_SecureStream()
   at System.Net.Security.SslStream.Write(Byte[] buffer, Int32 offset,
Int32 count)
   at FlowLib.Connections.TcpConnection.Send(Byte[] raw) in
C:\Download\Code\FlowLib\trunk\FlowLib\Connections\TcpConnection.cs:line 608
   at FlowLib.Connections.TcpConnection.Send(IConMessage msg) in
C:\Download\Code\FlowLib\trunk\FlowLib\Connections\TcpConnection.cs:line 585
   at FlowLib.Connections.TcpConnection.SetupRecieveCallback(Socket sock)
in C:\Download\Code\FlowLib\trunk\FlowLib\Connections\TcpConnection.cs:line 467
   at FlowLib.Connections.TcpConnection.OnConnect(IAsyncResult ar) in
C:\Download\Code\FlowLib\trunk\FlowLib\Connections\TcpConnection.cs:line 435
   at System.Net.LazyAsyncResult.Complete(IntPtr userToken)
   at System.Net.ContextAwareResult.CompleteCallback(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
   at System.Net.ContextAwareResult.Complete(IntPtr userToken)
   at System.Net.LazyAsyncResult.ProtectedInvokeCallback(Object result,
IntPtr userToken)
   at System.Net.Sockets.Socket.ConnectCallback()
   at System.Net.Sockets.Socket.RegisteredWaitCallback(Object state,
Boolean timedOut)
   at
System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Objec
t
state, Boolean timedOut)

I did find something which looks like a solution here:
http://blog.jameshiggs.com/2008/05/01/c-how-to-accept-an-invalid-ssl-certificate
-programmatically/

Though I do not have the skill required to implement that into flowlib

Original issue reported on code.google.com by t3rmin...@gmail.com on 6 Nov 2009 at 6:33

GoogleCodeExporter commented 8 years ago
Welcome to the project :)

The reason why you didnt find your solution in Xmpl is because the version you 
tested
doesnt support ADCS. I think the svn version do.

The solution to your problem is to add the following line where you init the 
Hub object:
connection.SecureUpdate += new FmdcEventHandler(connection_SecureUpdate);

Then your connection_SecureUpdate function should look something like this:
void connection_SecureUpdate(object sender, FmdcEventArgs e)
{
    CertificateValidationInfo info = e.Data as CertificateValidationInfo;
    if (info != null)
    {
        info.Accepted = true;
    }
}

Please get back to me on how it works :)

Original comment by blomman84 on 7 Nov 2009 at 11:58

GoogleCodeExporter commented 8 years ago
Hi blomman84,

Thank you for the reply, it is working like a charm! :D

Hope I can contribute to this project in the near future!

Original comment by t3rmin...@gmail.com on 8 Nov 2009 at 12:37

GoogleCodeExporter commented 8 years ago
Happy to hear. Im closing this issue :)

Original comment by blomman84 on 8 Nov 2009 at 12:54