Exemplo n.º 1
0
        public string StoreSessionData(EnrollSessionData sessionData)
        {
            var sessionId = sessionIdGenerator.GenerateSessionId(sessionData.AccountName);

            sessionDataBase[sessionId] = sessionData;
            return(sessionId);
        }
Exemplo n.º 2
0
        /// <exception cref="U2FException" />
        private void VerifyBrowserData(string browserData, string messageType, EnrollSessionData sessionData)
        {
            JObject browserDataObject;

            try
            {
                browserDataObject = JObject.Parse(browserData);
            }
            catch (JsonReaderException e)
            {
                throw new U2FException("browserdata has wrong format", e);
            }

            VerifyBrowserData(browserDataObject, messageType, sessionData);
        }
Exemplo n.º 3
0
        public RegisterRequest GetRegistrationRequest(string accountName, string appId)
        {
            log.Info(">> getRegistrationRequest " + accountName);

            var challenge       = challengeGenerator.GenerateChallenge(accountName);
            var sessionData     = new EnrollSessionData(accountName, appId, challenge);
            var sessionId       = dataStore.StoreSessionData(sessionData);
            var challengeBase64 = WebSafeBase64Converter.ToBase64String(challenge);

            log.Info("-- Output --");
            log.Info("  sessionId: " + sessionId);
            log.Info("  challenge: " + challenge.ToHexString());
            log.Info("<< getRegistrationRequest " + accountName);

            return(new RegisterRequest(U2FConsts.U2Fv2, challengeBase64, appId, sessionId));
        }
Exemplo n.º 4
0
        /// <exception cref="U2FException" />
        private void VerifyBrowserData(JObject browserData, string messageType, EnrollSessionData sessionData)
        {
            // check that the right "typ" parameter is present in the browserdata JSON
            var typeProperty = browserData.Property(TYPE_PARAM);

            if (typeProperty == null)
            {
                throw new U2FException($"bad browserdata: missing '{TYPE_PARAM}' param");
            }
            var type = typeProperty.Value.ToString();

            if (messageType != type)
            {
                throw new U2FException("bad browserdata: bad type " + type);
            }

            var originProperty = browserData.Property(ORIGIN_PARAM);

            if (originProperty != null)
            {
                VerifyOrigin(originProperty.Value.ToString());
            }

            // check that the right challenge is in the browserdata
            var challengeProperty = browserData.Property(CHALLENGE_PARAM);

            if (challengeProperty == null)
            {
                throw new U2FException($"bad browserdata: missing '{CHALLENGE_PARAM}' param");
            }
            var challengeFromBrowserData = WebSafeBase64Converter.FromBase64String(challengeProperty.Value.ToString());

            if (!challengeFromBrowserData.SequenceEqual(sessionData.Challenge))
            {
                throw new U2FException("wrong challenge signed in browserdata");
            }
        }
Exemplo n.º 5
0
 public string StoreSessionData(EnrollSessionData sessionData)
 {
     return(inMemoryStore.StoreSessionData(sessionData));
 }