Пример #1
0
        public void Bind(string Acct, string PIN)
        {
            string Domain = "localhost";
            int Port = 8080;
            WebServiceClient Client = new WebServiceClient(Domain, Port, null);

            OpenRequest OpenRequest = new OpenRequest () ;
            OpenRequest.Account = Account.User (Acct);
            OpenRequest.Domain = Account.Domain (Acct);;
            OpenRequest.HavePasscode = true;
            OpenRequest.HaveDisplay = false;
            OpenRequest.Encryption = Encryption;
            OpenRequest.Authentication = Authentication;
            OpenRequest.Challenge = Cryptography.Nonce ();
            string RequestData = OpenRequest.ToString ();

            // perform the request and wait for response
            string Result = Client.Request(RequestData);

            // Parse the result
            OpenResponse OpenResponse;
            OpenResponse.Deserialize (Result, out OpenResponse);

            if (OpenResponse.Cryptographic != null) {
                foreach (Cryptographic Crypto in OpenResponse.Cryptographic) {
                    CryptographicContext Context = CryptographicContext.MakeCryptographicContext (
                        Crypto.Ticket, Crypto.Secret, Crypto.Authentication, Crypto.Encryption);
                    if (Context != null) {
                        Client.CryptographicContext = Context;
                        break;
                        }
                    }
                if (Client.CryptographicContext == null) {
                    throw new Exception ("No supported algorithm");
                    }
                }

            TicketRequest TicketRequest = new TicketRequest ();
            TicketRequest.ChallengeResponse = Cryptography.ClientChallengeResponse (
                PIN, OpenRequest.Challenge, OpenResponse.Challenge, Cryptography.Authentication.Unknown);

            RequestData = TicketRequest.ToString ();
            Result =  Client.Request(RequestData);

            TicketResponse TicketResponse = new TicketResponse (Result);

            Console.WriteLine ("Result is");
            Console.WriteLine (Result);
        }
Пример #2
0
        public override void Bind(string Domain, string Account, string PIN)
        {
            byte [] Challenge = Cryptography.Nonce();

            OpenRequest OpenRequest = new OpenRequest ();
            OpenRequest.DeviceID = DeviceID;
            OpenRequest.DeviceURI = DeviceURI;
            OpenRequest.DeviceName = DeviceName;

            OpenRequest.Authentication = Authentication;
            OpenRequest.Encryption = Encryption;

            OpenRequest.Domain = Domain;
            OpenRequest.Account = Account;

            OpenRequest.HavePasscode = (PIN != null);
            OpenRequest.HaveDisplay = true;

            OpenRequest.Challenge = Challenge;

            OpenResponse ResponseOut = (OpenResponse) ConnectionBinding.RequestResponse (OpenRequest);

            // Check the server Response to our challenge here

            ConnectionBinding.SetCrypto (ResponseOut.Cryptographic[0]);
            TicketRequest TicketRequest = new TicketRequest ();
            TicketRequest.ChallengeResponse = Cryptography.ClientChallengeResponse(
                        PIN, Challenge, ResponseOut.Challenge, Cryptography.Authentication.Unknown);

            TicketResponse ResponseOut2 =  (TicketResponse) ConnectionBinding.RequestResponse (TicketRequest);

            ConnectionBinding.SetCrypto (ResponseOut2.Cryptographic[0]);

            QueryServers = new QueryServerConnection [ResponseOut2.Service.Count];

            foreach (OBPConnection.Connection Connection in ResponseOut2.Service) {
                QueryServerConnection QueryServerConnection = new QueryServerConnection();

                Console.WriteLine("Got a connection to {0}, type {1}",
                        Connection.Name, Connection.Transport);

                if (Connection.Transport == "WebService") {
                    WebBinding.SetCrypto (Connection.Cryptographic);
                    }
                }

            // Need to add in all the rest of the parameters here

            //DNSBinding = new DirectQueryBinding (Transport.DNS);
            //UDPBinding = new DirectQueryBinding (Transport.UDP);
        }
Пример #3
0
        public static void Deserialize(string _Input, out BindRequest Out)
        {
            StringReader _Reader = new StringReader (_Input);
            JSONReader JSONReader = new JSONReader (_Reader);

            JSONReader.StartObject ();
            string token = JSONReader.ReadToken ();
            Out = null;

            switch (token) {

                case "BindRequest" : {
                    Out = null;
                    throw new Exception ("Can't create abstract type");
                    }

                case "OpenRequest" : {
                    OpenRequest Result = new OpenRequest ();
                    Result.Deserialize (JSONReader);
                    Out = Result;
                    break;
                    }

                default : {
                    throw new Exception ("Not supported");
                    }
                }
            JSONReader.EndObject ();

            // should we check for EOF here?
        }