Exemplo n.º 1
0
            /// <summary>
            /// Send a ZAP reply to the handler socket
            /// </summary>
            /// <param name="status_code"></param>
            /// <param name="status_text"></param>
            /// <param name="metadata"></param>
            /// <returns></returns>
            public int RequestReply(string status_code, string status_text, byte[] metadata)
            {
                if (Verbose)
                {
                    ZAuth.Info(string.Format("zauth: - ZAP reply status_code={0} status_text={1}", status_code, status_text));
                }

                ZMessage msg = new ZMessage();

                msg.Add(new ZFrame("1.0"));
                msg.Add(new ZFrame(Sequence));
                msg.Add(new ZFrame(status_code));
                msg.Add(new ZFrame(status_text));
                msg.Add(new ZFrame(UserId != null ? UserId : ""));
                // rc = zmsg_addmem(msg, metadata, metasize);
                msg.Add(new ZFrame(metadata));
                handler.SendMessage(msg);
                return(0);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Receive a valid ZAP request from the handler socket
            /// </summary>
            /// <param name="handler"></param>
            /// <param name="request"></param>
            /// <param name="verbose"></param>
            public ZAP(ZSocket handler, ZMessage request, bool verbose)
            {
                //  Store handler socket so we can send a reply easily
                this.handler = handler;
                Verbose      = verbose;

                if (request.Count == 0)
                {
                    return;
                }

                //  Get all standard frames off the handler socket
                Version   = request.Pop().ReadLine();
                Sequence  = request.Pop().ReadLine();
                Domain    = request.Pop().ReadLine();
                Address   = request.Pop().ReadLine();
                Identity  = request.Pop().ReadLine();
                Mechanism = request.Pop().ReadLine();

                Mechanism = string.IsNullOrEmpty(Mechanism) ? "" : Mechanism;
                Version   = string.IsNullOrEmpty(Version) ? "" : Version;
                Sequence  = string.IsNullOrEmpty(Sequence) ? "" : Sequence;
                Domain    = string.IsNullOrEmpty(Domain) ? "" : Domain;
                Address   = string.IsNullOrEmpty(Address) ? "" : Address;
                Identity  = string.IsNullOrEmpty(Identity) ? "" : Identity;


                //  If the version is wrong, we're linked with a bogus libzmq, so die
                if (Version != "1.0")
                {
                    return;
                }

                //  Get mechanism-specific frames
                if (Mechanism == "PLAIN")
                {
                    Username = request.Pop().ReadLine();
                    Password = request.Pop().ReadLine();
                    Username = string.IsNullOrEmpty(Username) ? "" : Username;
                    Password = string.IsNullOrEmpty(Password) ? "" : Password;
                }
                else
                if (Mechanism == "CURVE")
                {
                    ZFrame frame = request.Pop();

                    if (frame.Length != 32)
                    {
                        return;
                    }
                    ZCert cert = new ZCert(frame.Read(), new byte[32]);
                    ClientTxt = cert.PublicTxt;
                }
                else
                if (Mechanism == "GSSAPI")
                {
                    Principal = request.Pop().ReadLine();
                }

                if (Verbose)
                {
                    ZAuth.Info(string.Format("zauth: ZAP request mechanism={0} ipaddress={1}", Mechanism, Address));
                }
            }