示例#1
0
    IEnumerator GetChallenged()
    {
        //Get challenge quiz if challenge has been issued by another classmate
        string url = string.Format("http://127.0.0.1:5000/quizzes/questions?quiz_id={0}", PlayerPrefs.GetInt("challengeQuizID"));

        using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
        {
            yield return(webRequest.SendWebRequest());

            QuizDetails1           challengeQuiz   = JsonUtility.FromJson <QuizDetails1>(webRequest.downloadHandler.text);
            List <QuestionDetails> listOfQuestions = new List <QuestionDetails>();
            foreach (QuestionsDetails questions in challengeQuiz.questions)
            {
                listOfQuestions.Add(questions.question);
            }
            challengeDetails = new ChallengeDetails
            {
                quiz = new QuizDetails
                {
                    id        = challengeQuiz.id,
                    questions = listOfQuestions.ToArray()
                }
            };
            challengeDetails.quiz.id = challengeQuiz.id;
            UpdateChallenge();
        }
    }
        public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra)
        {
            if (authmethod == WAMP_CRA)
            {
                WampCraChallengeDetails challengeDetails =
                    extra.OriginalValue.Deserialize <WampCraChallengeDetails>();

                string signature;

                if (challengeDetails.Salt == null)
                {
                    signature =
                        WampCraHelpers.Sign(mAuthenticationKey,
                                            challengeDetails.Challenge);
                }
                else
                {
                    signature =
                        WampCraHelpers.AuthSignature(challengeDetails.Challenge,
                                                     mSecret,
                                                     challengeDetails);
                }

                AuthenticationResponse result =
                    new AuthenticationResponse {
                    Signature = signature
                };

                return(result);
            }
            else
            {
                throw new WampAuthenticationException("don't know how to authenticate using '" + authmethod + "'");
            }
        }
示例#3
0
        public async Task <AuthorizationDetails> GetAuthorizationDetailsAsync(string authorizationDetailsUrl, long orderExpires)
        {
            ACMESharpAuthorization acmeSharpAuthorization =
                await _client.GetAuthorizationDetailsAsync(authorizationDetailsUrl);

            var challengeDetailsList = new List <ChallengeDetails>();

            foreach (ACMESharpChallenge challenge in acmeSharpAuthorization.Challenges)
            {
                string challengeTypeStr = challenge.Type;
                if (ChallengeTypeMethods.TryParseFromString(challengeTypeStr, out ChallengeType challengeType))
                {
                    // FIXME the implementation of the decode method is odd, should fix
                    IACMESharpChallengeValidationDetails acmeSharpChallenge =
                        ACMESharpAuthorizationDecoder.DecodeChallengeValidation(
                            acmeSharpAuthorization, challenge.Type, _client.Signer);
                    var challengeDetails = new ChallengeDetails(challenge, acmeSharpChallenge, orderExpires);
                    challengeDetails.AssertOkResponse();
                    challengeDetailsList.Add(challengeDetails);
                }
                else
                {
                    // tls-alpn-01 or other fancy pants
                    _logger.LogInformation($"Received unrecognized challenge type {challengeTypeStr}, ignoring.");
                }
            }

            return(new AuthorizationDetails(acmeSharpAuthorization)
            {
                Challenges = challengeDetailsList
            });
        }
示例#4
0
 public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra)
 {
     if (authmethod != AuthMethod)
     {
         throw new WampAuthenticationException("don't know how to authenticate using '" + authmethod + "'");
     }
     return(new AuthenticationResponse());
 }
示例#5
0
        private async Task SaveChallengeDetailsAsync(ChallengeDetails httpDetails)
        {
            _logger.LogInformation($"Handling Challenges with HTTP full path of {httpDetails.HttpResourcePath}");

            string id = await _stateStore.SaveChallengeValidationDetailsAsync(httpDetails);

            _challenges[id] = httpDetails;
        }
        public void AuthenticateParametersArePassedToSessionAuthenticator()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            string receivedSignature = null;
            AuthenticateExtraData receivedExtraData = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");
                mockSessionAuthenticator.SetAuthenticate((signature, extra) =>
                {
                    receivedSignature = signature;
                    receivedExtraData = extra;
                });
                return(mockSessionAuthenticator);
            });


            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            string clientAuthMethod = null;

            ChallengeDetails clientChallengeDetails = null;

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            serverProxy.Authenticate("Barack Hussein", new MyAuthenticateExtraData()
            {
                Wife = "Michelle"
            });

            MyAuthenticateExtraData deserializedExtraData =
                receivedExtraData.OriginalValue.Deserialize <MyAuthenticateExtraData>();

            Assert.That(receivedSignature, Is.EqualTo("Barack Hussein"));

            Assert.That(deserializedExtraData.Wife, Is.EqualTo("Michelle"));
        }
        public void ChallengeParametersArePassedToClient()
        {
            MockSessionAuthenticationFactory mockSessionAuthenticationFactory =
                new MockSessionAuthenticationFactory();

            WampPendingClientDetails authenticatorFactoryParameters = null;

            mockSessionAuthenticationFactory.SetGetSessionAuthenticator
                ((clientDetails, transportAuthenticator) =>
            {
                authenticatorFactoryParameters = clientDetails;
                MockSessionAuthenticator mockSessionAuthenticator = new MockSessionAuthenticator();
                mockSessionAuthenticator.SetAuthenticationMethod("ticket");
                mockSessionAuthenticator.SetChallengeDetails
                    (new MyChallenge {
                    President = "Obama"
                });

                return(mockSessionAuthenticator);
            });

            WampAuthenticationPlayground playground =
                new WampAuthenticationPlayground(mockSessionAuthenticationFactory);

            playground.Host.Open();

            string           clientAuthMethod       = null;
            ChallengeDetails clientChallengeDetails = null;

            Mock <IWampClient <JToken> > clientMock = new Mock <IWampClient <JToken> >();

            clientMock.Setup(x => x.Challenge(It.IsAny <string>(), It.IsAny <ChallengeDetails>()))
            .Callback((string authMethod, ChallengeDetails details) =>
            {
                clientAuthMethod       = authMethod;
                clientChallengeDetails = details;
            });

            IWampServerProxy serverProxy =
                playground.CreateRawConnection(clientMock.Object);

            serverProxy.Hello("realm1", new HelloDetailsHack()
            {
                AuthenticationId      = "joe",
                AuthenticationMethods = new string[] { "wampcra", "ticket" }
            });

            MyChallenge deserializedChallengeDetails =
                clientChallengeDetails.OriginalValue.Deserialize <MyChallenge>();

            Assert.That(deserializedChallengeDetails.President, Is.EqualTo("Obama"));
            Assert.That(clientAuthMethod, Is.EqualTo("ticket"));
        }
示例#8
0
        public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra)
        {
            if (authmethod == "ticket")
            {
                Console.WriteLine("authenticating via '" + authmethod + "'");
                AuthenticationResponse result = new AuthenticationResponse {
                    Signature = _tickets[User]
                };
                return(result);
            }

            throw new WampAuthenticationException("don't know how to authenticate using '" + authmethod + "'");
        }
示例#9
0
    IEnumerator GetChallenge()
    {
        //Get challenge quiz if issuing challenge to another classmate
        string url = string.Format("http://127.0.0.1:5000/challenges/?from_student_id={0}&to_student_id={1}", PlayerPrefs.GetString("userID"), PlayerPrefs.GetString("challengeID"));

        using (UnityWebRequest webRequest = UnityWebRequest.Post(url, "null"))
        {
            yield return(webRequest.SendWebRequest());

            challengeDetails = JsonUtility.FromJson <ChallengeDetails>(webRequest.downloadHandler.text);
            UpdateChallenge();
        }
    }
示例#10
0
        public void Challenge(string authMethod, ChallengeDetails extra)
        {
            try
            {
                AuthenticationResponse response = mAuthenticator.Authenticate(authMethod, extra);

                AuthenticateExtraData authenticationExtraData = response.Extra ?? EmptyAuthenticateDetails;

                string authenticationSignature = response.Signature;

                mServerProxy.Authenticate(authenticationSignature, authenticationExtraData);
            }
            catch (WampAuthenticationException ex)
            {
                mServerProxy.Abort(ex.Details, ex.Reason);
                OnConnectionError(ex);
            }
        }
示例#11
0
        public async Task <ActionResult <string> > HandleChallengeAsync(string id)
        {
            string fullPath = Request.Path;

            _logger.LogInformation($"receive challenge request for {fullPath}");
            ChallengeDetails challengeState =
                await _challengeHandler.GetChallengeDetailsByRequestPathAsync(fullPath);

            if (challengeState != null)
            {
                _logger.LogInformation($"find challenge detail for {fullPath}.");
                await _challengeHandler.CompleteChallengeValidationStatusAsync(challengeState.Id);

                return(new ContentResult()
                {
                    Content = challengeState.HttpResourceValue,
                    ContentType = challengeState.HttpResourceContentType
                });
            }
            return(NotFound("NotFound"));
        }
        public async Task <string> SaveChallengeValidationDetailsAsync(ChallengeDetails challengeDetails)
        {
            string id = challengeDetails.Id;

            if (string.IsNullOrEmpty(id))
            {
                if (!string.IsNullOrEmpty(challengeDetails.HttpResourceUrl))
                {
                    id = challengeDetails.HttpResourceUrl;
                }
                else
                {
                    id = Guid.NewGuid().ToString("N");
                }

                challengeDetails.Id = id;
            }

            FSChallengeFormat fsChallengeFormat = await GetFSChallengeFormat();

            if (fsChallengeFormat.Challenges.Count > 64)
            {
                // culling old records
                _logger.LogInformation($"too many saved challenges, culling old records");
                IEnumerable <ChallengeDetails> oldRecords =
                    fsChallengeFormat.Challenges.Values.OrderBy(i => i.Expires).Take(32);
                foreach (ChallengeDetails oldRecord in oldRecords)
                {
                    fsChallengeFormat.Challenges.Remove(oldRecord.Id);
                }
            }

            fsChallengeFormat.Challenges[id] = challengeDetails;
            await SaveFSChallengeFormat(fsChallengeFormat);

            return(id);
        }
 public void Challenge(string authMethod, ChallengeDetails extra)
 {
     Send(mChallenge2, authMethod, extra);
 }
示例#14
0
 public Task <string> SaveChallengeValidationDetailsAsync(ChallengeDetails challengeDetails)
 {
     return(_challengeStore.SaveChallengeValidationDetailsAsync(challengeDetails));
 }
示例#15
0
 public WampMessage <object> Challenge(string authMethod, ChallengeDetails extra)
 {
     return(mSerializer.SerializeRequest(mChallenge2, new object[] { authMethod, extra }));
 }
 public ChallengeMock(string authMethod, ChallengeDetails details)
 {
     mAuthMethod = authMethod;
     mDetails    = details;
 }
 /// <summary>
 /// Just throws exception on CHALLENGE
 /// </summary>
 /// <param name="authmethod"></param>
 /// <param name="extra"></param>
 /// <returns></returns>
 public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra)
 {
     throw new WampAuthenticationNotImplementedException("Authentication was requested but no authenticator was provided");
 }
 public void SetChallengeDetails(ChallengeDetails value)
 {
     base.ChallengeDetails = value;
 }
示例#19
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 protected WampSessionAuthenticator()
 {
     mChallengeDetails = mEmptyChallengeDetails;
 }
 public AuthenticationResponse Authenticate(string authmethod, ChallengeDetails extra)
 {
     mExtra      = extra;
     mAuthMethod = authmethod;
     return(mAuthenticate(authmethod, extra));
 }
示例#21
0
 public void Challenge(string authMethod, ChallengeDetails extra)
 {
     SessionClient.Challenge(authMethod, extra);
 }