示例#1
0
        public async override ValueTask <LogListRoot> GetLogListRootAsync(CancellationToken cancellationToken)
        {
            var logListRoot = default(LogListRoot);

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            if (!LogStoreService.TryGetValue(LogListRootKey, out logListRoot))
            {
                await _logListSemaphore.WaitAsync().ConfigureAwait(false);

                try
                {
                    if (!LogStoreService.TryGetValue(LogListRootKey, out logListRoot))
                    {
                        var logListBytes = await LogListApi.GetLogListWithSigAsync(cancellationToken).ConfigureAwait(false);

                        var isValid = VerifyGoogleSignature(logListBytes.list, logListBytes.sig);

                        if (!isValid)
                        {
                            throw new InvalidDataException("Log list failed signature verification!");
                        }

                        logListRoot = Deserialise <LogListRoot>(logListBytes.list);

                        if (logListRoot?.Operators != null)
                        {
                            LogStoreService.SetValue(LogListRootKey, logListRoot);
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    _logListSemaphore.Release();
                }
            }

            stopwatch.Stop();

            return(logListRoot);
        }
        public async override Task <LogListRoot> GetLogListRootAsync(CancellationToken cancellationToken)
        {
            var logListRoot = default(LogListRoot);

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            if (!LogStoreService.TryGetValue(LogListRootKey, out logListRoot))
            {
                await _logListSemaphore.WaitAsync().ConfigureAwait(false);

                try
                {
                    if (!LogStoreService.TryGetValue(LogListRootKey, out logListRoot))
                    {
                        var logListBytes = await LogListApi.GetLogListWithSigAsync(cancellationToken).ConfigureAwait(false);

                        var logListPublicKey = await LogListApi.GetLogListPublicKeyAsync(cancellationToken).ConfigureAwait(false);

                        if (logListBytes.sig != null || logListPublicKey != null)
                        {
                            var isValid = VerifyLogListSignature(logListBytes.list, logListBytes.sig, logListPublicKey);

                            if (!isValid)
                            {
                                throw new InvalidDataException("Log list failed signature verification!");
                            }
                        }

                        logListRoot = Deserialise <LogListRoot>(logListBytes.list);

                        if (logListRoot?.Operators != null)
                        {
                            LogStoreService.SetValue(LogListRootKey, logListRoot);

                            foreach (var op in logListRoot?.Operators)
                            {
                                Console.WriteLine($"{string.Join(";", op.Email)}");
                                foreach (var log in op.Logs)
                                {
                                    Console.WriteLine($"   {BitConverter.ToString(Convert.FromBase64String(log.LogId)).Replace("-", string.Empty).ToLowerInvariant()} {log.Description}");
                                }
                                Console.WriteLine();
                            }
                        }
                    }
                }
                catch
                {
                    throw;
                }
                finally
                {
                    _logListSemaphore.Release();
                }
            }

            stopwatch.Stop();

            return(logListRoot);
        }