예제 #1
0
        public SCAMPSOAClient(Uri parsed, X509Certificate2 cert)
        {
            this.parsed = parsed;

            p = new Protocol ();
            p.OnClose += p_OnClose;
            p.OnMessage += p_OnMessage;

            NetUtil.TlsTcpConnect (parsed.Host, parsed.Port, (sender, certificate, chain, sslPolicyErrors) => certificate.GetCertHashString () == cert.Thumbprint, (ex, ssl) => {
                if (ex != null) {
                    Logger.LogError ("Failed TLS connection to {0}: {1}", parsed, ex);
                    p.Close (ex.ToString ());
                } else {
                    lock (state_lock)
                        started = true;
                    p.Start (ssl);
                }
            });
        }
예제 #2
0
        void ProcessConnection(Socket listener, IAsyncResult ar)
        {
            Socket ns = listener.EndAccept (ar);
            ns.NoDelay = true;
            SslStream ssl = new SslStream (new NetworkStream (ns, true));

            ssl.BeginAuthenticateAsServer (cert, (IAsyncResult ar2) => {
                try {
                    ssl.EndAuthenticateAsServer (ar2);
                    Protocol p = new Protocol ();
                    p.OnMessage += (incoming) => {
                        var hdr = incoming.Header;
                        // TODO timeout handling
                        if (hdr ["type"].AsString(null) != "request") {
                            Logger.LogError ("received non-request");
                            incoming.Discard ();
                            return;
                        }
                        if (!hdr.ContainsKey ("request_id")) {
                            Logger.LogError ("Received request with no request_id");
                            incoming.Discard ();
                            return;
                        }
                        var id = hdr ["request_id"];
                        reqh (incoming, (reply) => {
                            reply.Header ["type"] = "reply";
                            reply.Header ["request_id"] = id;
                            p.SendMessage (reply);
                        });
                    };
                    p.OnClose += (error) => {
                        Logger.LogInfo ("scamp connection closed: {0}", error);
                    };
                    p.Start (ssl);
                } catch (Exception ex) {
                    Logger.LogError ("connection server authenticate: {0}", ex);
                }
            }, null);
        }