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);
        }
Beispiel #2
0
        public static void Deserialize(string _Input, out BindResponse Out)
        {
            StringReader _Reader = new StringReader (_Input);
            JSONReader JSONReader = new JSONReader (_Reader);

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

            switch (token) {

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

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

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

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

            // should we check for EOF here?
        }