コード例 #1
0
ファイル: SignOperation.cs プロジェクト: forki/U2FExperiments
        async Task <SignOperationResult?> TrySigningOnceAsync(IKey key, bool isFirstPass, CancellationToken cancellationToken)
        {
            int challengesTried = 0;

            foreach (var request in requests)
            {
                if (IsBlacklisted(request))
                {
                    continue;
                }
                challengesTried += 1;

                var requestSignResult = await TrySignOneRequest(key, isFirstPass, request, cancellationToken);

                if (requestSignResult.HasValue)
                {
                    return(requestSignResult.Value);
                }
            }
            if (challengesTried == 0)
            {
                return(SignOperationResult.Failure(KeyResponseStatus.Failure));
            }

            return(null);
        }
コード例 #2
0
ファイル: SignOperation.cs プロジェクト: forki/U2FExperiments
        async Task <SignOperationResult?> TrySignOneRequest(IKey key, bool isFirstPass, KeySignRequest request,
                                                            CancellationToken cancellationToken)
        {
            try
            {
                var result = await key.SignAsync(request, cancellationToken, isFirstPass);

                log.Info(result.Status.ToString());
                switch (result.Status)
                {
                case KeyResponseStatus.BadKeyHandle:
                    // No use retrying
                    blacklistedKeyHandles.Add(request.KeyHandle);
                    break;

                case KeyResponseStatus.Success:
                    return(SignOperationResult.Success(request, result.Data));
                }
            }
            catch (KeyGoneException)
            {
                // No sense in continuing with this signer, the key isn't physically present anymore
                log.DebugFormat("Key '{0}' is gone", keyId);
                throw;
            }
            catch (TaskCanceledException)
            {
                // Let cancellation bubble up
                throw;
            }
            catch (KeyBusyException)
            {
                // Maybe it won't be busy later
            }
            catch (Exception exception)
            {
                log.Error("Authenticate request failed", exception);
            }
            return(null);
        }