Esempio n. 1
0
        public static TlsServerProtocol ConnectPskTlsServerNonBlocking(Dictionary <string, byte[]> psks)
        {
            try
            {
                TlsPskIdentityManager pskTlsManager = new PskIdentityManager(psks);
                PskTlsServer2         server        = new PskTlsServer2(pskTlsManager);
                TlsServerProtocol     protocol      = new TlsServerProtocol(new SecureRandom());
                protocol.Accept(server);

                return(protocol);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in TLS protocol connnection '{0}'", ex.Message);
                throw ex;
            }
        }
        public static TlsServerProtocol ConnectPskTlsServerNonBlocking(this TcpClient client, Dictionary <string, byte[]> psks)
        {
            try
            {
                TlsPskIdentityManager pskTlsManager = new PskIdentityManager(psks);
                PskTlsServer2         server        = new PskTlsServer2(pskTlsManager);
                TlsServerProtocol     protocol      = new TlsServerProtocol(new SecureRandom());
                protocol.Accept(server);

                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;
            }
        }