Exemplo n.º 1
0
        public async Task <bool> PostSelfExposureKeys(SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDTO, IEnumerable <ExposureKeyModel> temporaryExposureKeys, BaseWebService service)
        {
            ApiResponse response;
            bool        requestedAnonToken;

            if (AuthenticationState.PersonalData?.AnonymousTokensEnabled == true)
            {
                requestedAnonToken = true;
                response           = await PostSelfExposureKeysWithAnonTokens(selfDiagnosisSubmissionDTO, temporaryExposureKeys, service);
            }
            else
            {
                requestedAnonToken = false;
                response           = await service.Post(selfDiagnosisSubmissionDTO, Conf.URL_PUT_UPLOAD_DIAGNOSIS_KEYS);
            }
            // HandleErrorsSilently happens even if IsSuccessfull is true other places in the code, but here
            // we have an if-else to avoid having to create the redacted key list if we don't have to
            if (!response.IsSuccessfull)
            {
                string redactedKeysJson = RedactedTekListHelper.CreateRedactedTekList(temporaryExposureKeys);
                HandleErrorsSilently(response, new PostExposureKeysErrorHandler(redactedKeysJson));
            }
            else
            {
                HandleErrorsSilently(response);
            }

            ENDeveloperToolsViewModel.UpdatePushKeysInfo(response, selfDiagnosisSubmissionDTO, JsonSerializerSettings, requestedAnonToken);

            return(response.IsSuccessfull);
        }
Exemplo n.º 2
0
 internal static void UpdatePushKeysInfo(ApiResponse response, SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDTO, JsonSerializerSettings settings)
 {
     PushKeysInfo = $"StatusCode: {response.StatusCode}, Time (UTC): {DateTime.UtcNow.ToGreGorianUtcString("yyyy-MM-dd HH:mm:ss")}\n\n";
     ParseKeys(selfDiagnosisSubmissionDTO, settings, ENOperation.PUSH);
     PutInPushKeyInfoInSharedPrefs();
     Debug.WriteLine($"{PushKeysInfo}");
 }
Exemplo n.º 3
0
        public async Task <ApiResponse> UploadKeys(SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDto)
        {
            ApiResponse response =
                await new BaseWebService().Post(selfDiagnosisSubmissionDto, Conf.URL_GATEWAY_STUB_UPLOAD);

            HandleErrorsSilently(response);

            return(response);
        }
        private SelfDiagnosisSubmissionDTO GetMockedSelDiagnosisSubmissionDTO(
            IEnumerable <ExposureKeyModel> temporaryExposureKeys, List <string> countriesList = null)
        {
            Mock <SelfDiagnosisSubmissionDTO> mock = new Mock <SelfDiagnosisSubmissionDTO>()
                                                     .RegisterForJsonSerialization();
            SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDto = mock.Object;

            selfDiagnosisSubmissionDto.Keys = temporaryExposureKeys;
            if (!countriesList.IsNullOrEmpty())
            {
                selfDiagnosisSubmissionDto.VisitedCountries = countriesList;
            }
            selfDiagnosisSubmissionDto.ComputePadding();

            return(selfDiagnosisSubmissionDto);
        }
Exemplo n.º 5
0
        static void ParseKeys(SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDTO, JsonSerializerSettings settings, ENOperation varAssignCheck)
        {
            string jsonBody = JsonConvert.SerializeObject(selfDiagnosisSubmissionDTO, settings);

            JObject parsed           = JObject.Parse(jsonBody);
            JArray  keyArray         = (JArray)parsed["keys"];
            JArray  visitedCountries = (JArray)parsed["visitedCountries"];
            JArray  regions          = (JArray)parsed["regions"];

            PushKeysInfo += $"visitedCountries: {visitedCountries}\n";
            PushKeysInfo += $"regions: {regions}\n";

            keyArray?.ForEach(key =>
            {
                String keyData = $"Key: {EncodingUtils.ConvertByteArrayToString((byte[])key["key"])} ,\n" +
                                 $"rollingStart: {key["rollingStart"]},\n" +
                                 $"rollingDuration: {key["rollingDuration"]},\n" +
                                 $"transmissionRiskLevel: {key["transmissionRiskLevel"]}\n\n";
                PushKeysInfo += keyData;
                Debug.WriteLine(keyData);
            });
        }
Exemplo n.º 6
0
        private static async Task <ApiResponse> PostSelfExposureKeysWithAnonTokens(SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDTO, IEnumerable <ExposureKeyModel> temporaryExposureKeys, BaseWebService service)
        {
            var tokenService = new AnonymousTokenService(CustomNamedCurves.GetByOid(X9ObjectIdentifiers.Prime256v1));
            var token        = await tokenService.GetAnonymousTokenAsync();

            var request = new HttpRequestMessage(HttpMethod.Post, Conf.URL_PUT_UPLOAD_DIAGNOSIS_KEYS);

            request.Headers.Add("Authorization", $"Anonymous {token}");
            string jsonBody = JsonConvert.SerializeObject(selfDiagnosisSubmissionDTO, JsonSerializerSettings);

            request.Content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
            var response = await new HttpClient().SendAsync(request);

            var result = new ApiResponse(Conf.URL_PUT_UPLOAD_DIAGNOSIS_KEYS, HttpMethod.Post);

            result.StatusCode   = (int)response.StatusCode;
            result.ResponseText = await response.Content.ReadAsStringAsync();

            if (!response.IsSuccessStatusCode)
            {
                result.ResponseText = response.ReasonPhrase;
            }
            return(result);
        }
Exemplo n.º 7
0
 public async Task <bool> PostSelfExposureKeys(SelfDiagnosisSubmissionDTO selfDiagnosisSubmissionDTO,
                                               IEnumerable <ExposureKeyModel> temporaryExposureKeys)
 {
     return(await PostSelfExposureKeys(selfDiagnosisSubmissionDTO, temporaryExposureKeys, this));
 }