예제 #1
0
        PositiveDiagnosisState GetLatest()
        {
            var latest = PositiveDiagnoses?.OrderByDescending(p => p.DiagnosisDate)?.FirstOrDefault();

            if (latest == null)
            {
                latest = new PositiveDiagnosisState();
                PositiveDiagnoses.Add(latest);
            }

            return(latest);
        }
예제 #2
0
        private async Task <DiagnosisSubmissionParameter> CreateSubmissionAsync(IEnumerable <TemporaryExposureKey> temporaryExposureKeys, PositiveDiagnosisState pendingDiagnosis)
        {
            loggerService.StartMethod();

            // Filter Temporary exposure keys
            var filteredTemporaryExposureKeys = ExposureNotificationService.FliterTemporaryExposureKeys(temporaryExposureKeys);

            // Create the network keys
            var keys = filteredTemporaryExposureKeys.Select(k => new DiagnosisSubmissionParameter.Key
            {
                KeyData            = Convert.ToBase64String(k.Key),
                RollingStartNumber = (uint)(k.RollingStart - DateTime.UnixEpoch).TotalMinutes / 10,
                RollingPeriod      = (uint)(k.RollingDuration.TotalMinutes / 10),
                TransmissionRisk   = (int)k.TransmissionRiskLevel
            });

            var beforeKey = Utils.SerializeToJson(temporaryExposureKeys.ToList());
            var afterKey  = Utils.SerializeToJson(keys.ToList());

            Debug.WriteLine($"C19R {beforeKey}");
            Debug.WriteLine($"C19R {afterKey}");

            if (keys.Count() == 0)
            {
                loggerService.Error($"Temporary exposure keys is empty.");
                loggerService.EndMethod();
                throw new InvalidDataException();
            }

            // Generate Padding
            var padding = GetPadding();

            loggerService.Info($"userData is {(userData == null ? "" : "not ")}null or empty.");

            // Create the submission
            var submission = new DiagnosisSubmissionParameter()
            {
                UserUuid = userData.UserUuid,
                Keys     = keys.ToArray(),
                Regions  = AppSettings.Instance.SupportedRegions,
                Platform = DeviceInfo.Platform.ToString().ToLowerInvariant(),
                DeviceVerificationPayload = null,
                AppPackageName            = AppInfo.PackageName,
                VerificationPayload       = pendingDiagnosis.DiagnosisUid,
                Padding = padding
            };

            // See if we can add the device verification
            if (DependencyService.Get <IDeviceVerifier>() is IDeviceVerifier verifier)
            {
                submission.DeviceVerificationPayload = await verifier?.VerifyAsync(submission);
            }

            loggerService.Info($"UserUuid is {(string.IsNullOrEmpty(submission.UserUuid) ? "null or empty" : "set")}.");
            loggerService.Info($"DeviceVerificationPayload is {(string.IsNullOrEmpty(submission.DeviceVerificationPayload) ? "null or empty" : "set")}.");
            loggerService.Info($"VerificationPayload is {(string.IsNullOrEmpty(submission.VerificationPayload) ? "null or empty" : "set")}.");

            loggerService.EndMethod();
            return(submission);
        }
예제 #3
0
        private async Task <DiagnosisSubmissionParameter> CreateSubmissionAsync(IEnumerable <TemporaryExposureKey> temporaryExposureKeys, PositiveDiagnosisState pendingDiagnosis)
        {
            // Create the network keys
            var keys = temporaryExposureKeys.Select(k => new DiagnosisSubmissionParameter.Key
            {
                KeyData            = Convert.ToBase64String(k.Key),
                RollingStartNumber = (uint)(k.RollingStart - DateTime.UnixEpoch).TotalMinutes / 10,
                RollingPeriod      = (uint)(k.RollingDuration.TotalMinutes / 10),
                TransmissionRisk   = (int)k.TransmissionRiskLevel
            });

            foreach (var key in keys)
            {
                if (!key.IsValid())
                {
                    throw new InvalidDataException();
                }
            }

            if (keys.ToArray() == null)
            {
                throw new InvalidDataException();
            }

            // Generate Padding
            var padding = GetPadding();

            // Create the submission
            var submission = new DiagnosisSubmissionParameter()
            {
                UserUuid = userData.UserUuid,
                Keys     = keys.ToArray(),
                Regions  = AppSettings.Instance.SupportedRegions,
                Platform = DeviceInfo.Platform.ToString().ToLowerInvariant(),
                DeviceVerificationPayload = null,
                AppPackageName            = AppInfo.PackageName,
                VerificationPayload       = pendingDiagnosis.DiagnosisUid,
                Padding = padding
            };

            // See if we can add the device verification
            if (DependencyService.Get <IDeviceVerifier>() is IDeviceVerifier verifier)
            {
                submission.DeviceVerificationPayload = await verifier?.VerifyAsync(submission);
            }
            return(submission);
        }
        private async Task <DiagnosisSubmissionParameter> CreateSubmissionAsync(IEnumerable <TemporaryExposureKey> temporaryExposureKeys, PositiveDiagnosisState pendingDiagnosis)
        {
            // Create the network keys
            var keys = temporaryExposureKeys.Where(k => k.RollingStart > DateTimeOffset.UtcNow.Date.AddDays(AppConstants.OutOfDateDays)).Select(k => new DiagnosisSubmissionParameter.Key
            {
                KeyData            = Convert.ToBase64String(k.Key),
                RollingStartNumber = (uint)(k.RollingStart - DateTime.UnixEpoch).TotalMinutes / 10,
                RollingPeriod      = (uint)(k.RollingDuration.TotalMinutes / 10),
                TransmissionRisk   = (int)k.TransmissionRiskLevel
            });

            var beforeKey = Utils.SerializeToJson(temporaryExposureKeys.ToList());
            var afterKey  = Utils.SerializeToJson(keys.ToList());

            Debug.WriteLine($"C19R {beforeKey}");
            Debug.WriteLine($"C19R {afterKey}");

            if (keys.Count() == 0)
            {
                throw new InvalidDataException();
            }

            // Generate Padding
            var padding = GetPadding();

            // Create the submission
            var submission = new DiagnosisSubmissionParameter()
            {
                UserUuid = userData.UserUuid,
                Keys     = keys.ToArray(),
                Regions  = AppSettings.Instance.SupportedRegions,
                Platform = DeviceInfo.Platform.ToString().ToLowerInvariant(),
                DeviceVerificationPayload = null,
                AppPackageName            = AppInfo.PackageName,
                VerificationPayload       = pendingDiagnosis.DiagnosisUid,
                Padding = padding
            };

            // See if we can add the device verification
            if (DependencyService.Get <IDeviceVerifier>() is IDeviceVerifier verifier)
            {
                submission.DeviceVerificationPayload = await verifier?.VerifyAsync(submission);
            }
            return(submission);
        }
        private async Task <SelfDiagnosisSubmission> CreateSubmissionAsync(IEnumerable <TemporaryExposureKey> temporaryExposureKeys, PositiveDiagnosisState pendingDiagnosis)
        {
            // Create the network keys
            var keys = temporaryExposureKeys.Select(k => new ExposureKey
            {
                KeyData          = Convert.ToBase64String(k.Key),
                RollingStart     = (long)(k.RollingStart - DateTime.UnixEpoch).TotalMinutes / 10,
                RollingDuration  = (int)(k.RollingDuration.TotalMinutes / 10),
                TransmissionRisk = (int)k.TransmissionRiskLevel
            });

            // Create the submission
            var submission = new SelfDiagnosisSubmission(true)
            {
                SubmissionNumber          = userData.PendingDiagnosis.DiagnosisUid,
                AppPackageName            = AppInfo.PackageName,
                UserUuid                  = userData.UserUuid,
                DeviceVerificationPayload = null,
                Platform                  = DeviceInfo.Platform.ToString().ToLowerInvariant(),
                Regions             = AppSettings.Instance.SupportedRegions,
                Keys                = keys.ToArray(),
                VerificationPayload = pendingDiagnosis.DiagnosisUid,
            };

            // See if we can add the device verification
            if (DependencyService.Get <IDeviceVerifier>() is IDeviceVerifier verifier)
            {
                submission.DeviceVerificationPayload = await verifier?.VerifyAsync(submission);
            }
            return(submission);
        }