예제 #1
0
 public static TlsClientProtocol ConnectPskTlsClientNonBlocking(string identity, byte[] psk)
 {
     try
     {
         SimplePskIdentity pskIdentity  = new SimplePskIdentity(identity, psk);
         PskTlsClient2     pskTlsClient = new PskTlsClient2(pskIdentity);
         TlsClientProtocol protocol     = new TlsClientProtocol(new SecureRandom());
         protocol.Connect(pskTlsClient);
         return(protocol);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception in TLS protocol connnection '{0}'", ex.Message);
         throw ex;
     }
 }
예제 #2
0
 public static TlsClientProtocol ConnectPskTlsClientNonBlocking(this TcpClient client, string identity, byte[] psk)
 {
     try
     {
         SimplePskIdentity pskIdentity  = new SimplePskIdentity(identity, psk);
         PskTlsClient2     pskTlsClient = new PskTlsClient2(pskIdentity);
         TlsClientProtocol protocol     = new TlsClientProtocol(new SecureRandom());
         protocol.Connect(pskTlsClient);
         return(protocol);
     }
     catch (AggregateException ae)
     {
         string msg = String.Format("AggregateException in TLS protocol connnection '{0}'", ae.Flatten().InnerException.Message);
         Console.WriteLine(msg);
         throw new Exception(msg, ae.Flatten().InnerException);
     }
     catch (Exception ex)
     {
         Console.WriteLine("Exception in TLS protocol connnection '{0}'", ex.Message);
         throw ex;
     }
 }